- Timestamp:
- 2018-12-16T19:57:11+13:00 (5 years ago)
- Location:
- main/trunk/gli/src/org/greenstone/gatherer
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java
r32686 r32689 56 56 import org.greenstone.gatherer.gui.WarningDialog; 57 57 import org.greenstone.gatherer.gui.FedoraLogin; 58 import org.greenstone.gatherer.gui.TestingPreparation; 58 59 import org.greenstone.gatherer.metadata.FilenameEncoding; 59 60 import org.greenstone.gatherer.remote.RemoteGreenstoneServer; … … 235 236 } 236 237 238 if(go.testing_mode) { 239 TestingPreparation.TEST_MODE = true; 240 } 241 237 242 init(go.gsdl_path, go.gsdl3_path, go.gsdl3_src_path, 238 243 go.fedora_info, … … 755 760 } 756 761 }*/ 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 } 762 771 763 772 // If there was a collection left open last time, reopen it -
main/trunk/gli/src/org/greenstone/gatherer/GetOpt.java
r20924 r32689 34 34 public class GetOpt 35 35 { 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; 37 39 public boolean feedback_enabled = false; 38 40 public boolean no_load = false; … … 128 130 System.exit(0); 129 131 } 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 } 130 136 // Run GLI in debug mode. Produces debug log plus extra 131 137 // messages. -
main/trunk/gli/src/org/greenstone/gatherer/gui/GUIManager.java
r32686 r32689 144 144 } 145 145 146 /*147 For GUI swing testing of GLI, it's very handy for components to have names148 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.memberVarName150 - else GLIClassName.swingComponentName151 Google: "Java swing automatically setName"152 -> https://stackoverflow.com/questions/3628218/strategy-for-naming-swing-components153 https://stackoverflow.com/questions/1782598/with-java-reflection-how-to-instantiate-a-new-object-then-call-a-method-on-it154 - https://stackoverflow.com/questions/4163500/how-to-automatic-set-name-attr-of-gui-components/4164479#4164479155 - https://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.wb.swing.doc.user%2Fhtml%2Fwizards%2Fswing%2Fautomatic_databinding.html156 - https://stackoverflow.com/questions/28639294/in-java-how-to-get-name-of-component-which-is-clicked157 */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 JComponents161 162 // https://docs.oracle.com/javase/7/docs/api/index.html?java/lang/reflect/package-summary.html163 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 set168 if(!prefix.equals("")){169 // TODO: fix this170 root.setName(prefix + "." + className);171 }172 else {173 root.setName(className);174 }175 } // else swing Component name already set176 177 } else { // root is in GLI GUI package, use its classname for name178 179 if(root.getName() == null || root.getName().equals("")) {180 root.setName(className);181 }182 prefix = className;183 184 // check member vars185 Field[] memberVars = root.getClass().getDeclaredFields(); // private to public member vars, but not inherited ones186 for(int i = 0; i < memberVars.length; i++) {187 memberVars[i].setAccessible(true); // make private/protected etc fields accessible188 189 // https://www.tutorialspoint.com/java/lang/class_isinstance.htm190 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 JComponent199 // Having the actual member variable of the instantiated instance,200 // we can call setName on it201 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 instantiated207 if(!memberVarClass.getPackage().getName().contains("org.greenstone.gatherer.gui")) {208 String memberprefix = prefix + "." + memberVars[i].getName(); // append member var name209 // now can call setName() on the actual member variable210 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 components215 // Skip this step to avoid circular references to our own member vars216 /*else { // member variable is a GLI GUI class, use its className as prefix for child components217 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, skip229 }230 }231 232 233 // https://stackoverflow.com/questions/33927349/could-someone-please-explain-note-this-method-should-be-called-under-awt-tree234 // No worries about AWT tree lock: setNamesRecursively is called by openGUI235 // 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 now240 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 call249 for(int i = 0; i < children.length; i++) {250 printComponentNames(children[i], tabbing + " ");251 }252 }253 146 254 147 public void windowGainedFocus(WindowEvent e) -
main/trunk/gli/src/org/greenstone/gatherer/util/StaticStrings.java
r31565 r32689 270 270 static final public String TEXT_NODE = "#text"; 271 271 static final public String TEXT_STR = "text"; 272 static final public String TESTING_ARGUMENT = "-testing_mode"; 272 273 static final public String TIMESTAMP_ARGUMENT = "&uq="; 273 274 static final public String TITLE_ELEMENT = "Title";
Note:
See TracChangeset
for help on using the changeset viewer.