Changeset 32689 for main

Show
Ignore:
Timestamp:
16.12.2018 19:57:11 (6 months ago)
Author:
ak19
Message:

If not testing, don't need GLI's GUI components to be assigned names. Leaves GLI more efficient when run as GLI proper, while GLI will do a bit more work when running GLI for testing.

Location:
main/trunk/gli/src/org/greenstone/gatherer
Files:
1 added
4 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java

    r32686 r32689  
    5656import org.greenstone.gatherer.gui.WarningDialog; 
    5757import org.greenstone.gatherer.gui.FedoraLogin; 
     58import org.greenstone.gatherer.gui.TestingPreparation; 
    5859import org.greenstone.gatherer.metadata.FilenameEncoding; 
    5960import org.greenstone.gatherer.remote.RemoteGreenstoneServer; 
     
    235236        } 
    236237 
     238        if(go.testing_mode) { 
     239            TestingPreparation.TEST_MODE = true; 
     240        } 
     241         
    237242        init(go.gsdl_path, go.gsdl3_path, go.gsdl3_src_path,  
    238243        go.fedora_info, 
     
    755760        } 
    756761    }*/ 
    757         g_man.setName("GUIManager"); // g_man has a name "frame0" assigned automatically 
    758         // setNamesRecursively won't assign a name if one is already set 
    759         // Setting explicitly since GUIManager is preferred for its name 
    760         GUIManager.setNamesRecursively("", g_man); 
    761         GUIManager.printComponentNames(g_man, ""); 
     762 
     763        // if we're tutorial testing GLI, want names assigned to the GUI components 
     764        if(TestingPreparation.TEST_MODE) { 
     765            g_man.setName("GUIManager"); // g_man has a name "frame0" assigned automatically 
     766            // setNamesRecursively won't assign a name if one is already set 
     767            // Setting explicitly since GUIManager is preferred for its name 
     768            TestingPreparation.setNamesRecursively("", g_man); 
     769            TestingPreparation.printComponentNames(g_man, ""); 
     770        } 
    762771         
    763772        // If there was a collection left open last time, reopen it  
  • main/trunk/gli/src/org/greenstone/gatherer/GetOpt.java

    r20924 r32689  
    3434public class GetOpt 
    3535{ 
    36     public boolean debug = false;  
     36    public boolean testing_mode = false; // true if running GLI for tutorial testing: want names assigned to GUI components 
     37     
     38    public boolean debug = false; 
    3739    public boolean feedback_enabled = false; 
    3840    public boolean no_load = false; 
     
    128130            System.exit(0); 
    129131            } 
     132            // Run GLI in testing mode. Will assign names to GUI Components 
     133            else if(argument_name.equals(StaticStrings.TESTING_ARGUMENT)) { 
     134            testing_mode = true; 
     135            } 
    130136            // Run GLI in debug mode. Produces debug log plus extra 
    131137            // messages. 
  • main/trunk/gli/src/org/greenstone/gatherer/gui/GUIManager.java

    r32686 r32689  
    144144    } 
    145145 
    146     /* 
    147       For GUI swing testing of GLI, it's very handy for components to have names 
    148       I use the GLI classname as name or if it's not a GLI class, then: 
    149        - if a member var of a GLI class, then GLIclassName.memberVarName 
    150        - else GLIClassName.swingComponentName 
    151       Google: "Java swing automatically setName" 
    152       -> https://stackoverflow.com/questions/3628218/strategy-for-naming-swing-components 
    153          https://stackoverflow.com/questions/1782598/with-java-reflection-how-to-instantiate-a-new-object-then-call-a-method-on-it 
    154       - https://stackoverflow.com/questions/4163500/how-to-automatic-set-name-attr-of-gui-components/4164479#4164479 
    155       - https://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.wb.swing.doc.user%2Fhtml%2Fwizards%2Fswing%2Fautomatic_databinding.html 
    156       - https://stackoverflow.com/questions/28639294/in-java-how-to-get-name-of-component-which-is-clicked 
    157     */ 
    158     public static void setNamesRecursively(String prefix, Component root) { 
    159      
    160     // root starts off as GLI's JFrame, so we know that all its GUI children are specifically JComponents 
    161      
    162     // https://docs.oracle.com/javase/7/docs/api/index.html?java/lang/reflect/package-summary.html 
    163     String className = root.getClass().getSimpleName(); 
    164      
    165     String packageName = root.getClass().getPackage().getName(); 
    166     if(!packageName.contains("org.greenstone.gatherer.gui")) { 
    167         if(root.getName() == null || root.getName().equals("")) { // if name not already set 
    168         if(!prefix.equals("")){ 
    169             // TODO: fix this 
    170             root.setName(prefix + "." + className); 
    171         } 
    172         else { 
    173             root.setName(className); 
    174         } 
    175         } // else swing Component name already set 
    176          
    177     } else { // root is in GLI GUI package, use its classname for name 
    178          
    179         if(root.getName() == null || root.getName().equals("")) { 
    180         root.setName(className); 
    181         } 
    182         prefix = className; 
    183          
    184         // check member vars 
    185         Field[] memberVars = root.getClass().getDeclaredFields(); // private to public member vars, but not inherited ones       
    186         for(int i = 0; i < memberVars.length; i++) { 
    187         memberVars[i].setAccessible(true); // make private/protected etc fields accessible 
    188          
    189         // https://www.tutorialspoint.com/java/lang/class_isinstance.htm 
    190         Class jCompClass = Container.class; 
    191         Class memberVarClass = memberVars[i].getType(); 
    192  
    193         // memberVarClass is a JComponen (subclass) 
    194         if(jCompClass.isAssignableFrom(memberVarClass)) { 
    195              
    196             // get the actual member variable denoted by memberVars[i] 
    197             // on the current JComponent instance 'root'. 
    198             // We now know this member var to be a JComponent 
    199             // Having the actual member variable of the instantiated instance, 
    200             // we can call setName on it 
    201             try { 
    202             Container memberComponent = (Container)memberVars[i].get(root); 
    203              
    204             if(memberComponent != null) { 
    205  
    206                 // member var is a JComponent but not of GLI package, so locally instantiated 
    207                 if(!memberVarClass.getPackage().getName().contains("org.greenstone.gatherer.gui")) { 
    208                 String memberprefix = prefix + "." + memberVars[i].getName(); // append member var name 
    209                 // now can call setName() on the actual member variable 
    210                 memberComponent.setName(memberprefix); 
    211                 setNamesRecursively(memberprefix, memberComponent); 
    212                 } 
    213  
    214                 //else  the member variable is a GLI GUI class, use its className as prefix for child components 
    215                 // Skip this step to avoid circular references to our own member vars 
    216                 /*else { // member variable is a GLI GUI class, use its className as prefix for child components 
    217                 String memberprefix = memberVarClass.getSimpleName(); 
    218                 memberComponent.setName(memberprefix); 
    219                 setNamesRecursively(memberprefix, memberComponent); 
    220                 }*/ 
    221              
    222                  
    223             } 
    224             } catch(Exception e) { 
    225             e.printStackTrace(); 
    226             } 
    227         } 
    228         // else not a JComponent, skip 
    229         }        
    230     } 
    231  
    232      
    233     // https://stackoverflow.com/questions/33927349/could-someone-please-explain-note-this-method-should-be-called-under-awt-tree 
    234     // No worries about AWT tree lock: setNamesRecursively is called by openGUI 
    235     // which is specifically called by GathererProg on the Event Dispatch Thread (EDT) 
    236     Component[] children = ((Container)root).getComponents(); 
    237     for(int i = 0; i < children.length; i++) { 
    238         // if we haven't already set a name for any child JComponents with the above, 
    239         // then the following will do so now 
    240         setNamesRecursively(className, children[i]); 
    241     } 
    242      
    243     } 
    244  
    245     public static void printComponentNames(Component root, String tabbing) { 
    246     System.err.println(tabbing + root.getName()); 
    247     Component[] children = ((Container)root).getComponents(); 
    248     // recursive call 
    249     for(int i = 0; i < children.length; i++) { 
    250         printComponentNames(children[i], tabbing + "  "); 
    251     } 
    252     } 
    253146 
    254147    public void windowGainedFocus(WindowEvent e) 
  • main/trunk/gli/src/org/greenstone/gatherer/util/StaticStrings.java

    r31565 r32689  
    270270    static final public String TEXT_NODE = "#text"; 
    271271    static final public String TEXT_STR = "text"; 
     272    static final public String TESTING_ARGUMENT = "-testing_mode"; 
    272273    static final public String TIMESTAMP_ARGUMENT = "&uq="; 
    273274    static final public String TITLE_ELEMENT = "Title";