150 }
151
152 private void initLAF(CommandContext ctx) {
153 int preferredLAF;
154 if (ctx != null) {
155 preferredLAF = ctx.getPreferredLookAndFeel();
156 } else {
157 // can occur from the test
158 preferredLAF = CommandContext.DEFAULT_LAF;
159 }
160
161 switch (preferredLAF) {
162 case CommandContext.SYSTEM_LAF:
163 try {
164 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
165 } catch (Exception e) {
166 }
167 break;
168 case CommandContext.METAL_LAF:
169 try {
170 Class nimbusClass = Class.forName("javax.swing.plaf.metal.MetalLookAndFeel");
171 UIManager.setLookAndFeel((LookAndFeel) nimbusClass.newInstance());
172 } catch (Throwable e) {
173 }
174 break;
175 case CommandContext.NIMBUS_LAF:
176 try {
177 Class nimbusClass = Class.forName("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
178 UIManager.setLookAndFeel((LookAndFeel) nimbusClass.newInstance());
179 } catch (Throwable e) {
180 }
181 break;
182 // no need to process CommandContext.DEFAULT_LAF - it should equal one of the others constatns
183 }
184
185 }
186
187 /**
188 * Create a desktop using a specified style.
189 * @param style a value indicating the desired desktop style.
190 * @see #MDI_STYLE
191 * @see #SDI_STYLE
192 * @see #TAB_STYLE
193 */
194 public Desktop(int style) {
195 this(style, null);
196 }
197
382 }
383
384
385 /**
386 * Add a new default tool to the desktop. The default can be set via the
387 * system property "javatest.desktop.defaultTool", which should identify
388 * the class name of an appropriate tool manager; if not set, the default
389 * is com.sun.javatest.exec.ExecManager.
390 * @param ip a configuration to be passed to the default tool manager's startTool
391 * method
392 * @see #removeTool
393 */
394 public Tool addDefaultTool(InterviewParameters ip) {
395 for (int i = 0; i < toolManagers.length; i++) {
396 ToolManager mgr = toolManagers[i];
397 if (mgr.getClass().getName().equals(defaultToolManager)) {
398 try {
399 // this is to avoid a class dependency to exec package, which is
400 // normally not allowed in this package
401 Method m = mgr.getClass().getMethod("startTool",
402 new Class[] { InterviewParameters.class} );
403
404 return (Tool) m.invoke(mgr, new Object[] { ip });
405 }
406 catch (NoSuchMethodException e) {
407 // ignore??
408 e.printStackTrace();
409 }
410 catch (IllegalAccessException e) {
411 // ignore??
412 e.printStackTrace();
413 }
414 catch (InvocationTargetException e) {
415 // ignore??
416 unwrap(e).printStackTrace();
417 }
418 }
419 }
420 return null;
421 }
422
432 return true;
433 }
434 return false;
435 }
436
437 /**
438 * Get the set of tool managers associated with this desktop.
439 * The managers are determined from resource files named
440 * "com.sun.javatest.tool.ToolManager.lst" on the main JT Harness classpath.
441 * @return the set of tool managers associated with this desktop
442 */
443 public ToolManager[] getToolManagers() {
444 return toolManagers;
445 }
446
447 /**
448 * Get the instance of a tool manager for this desktop of a specific class.
449 * @param c the class of the desired tool manager.
450 * @return a tool manager of the desired type, or null if none found
451 */
452 public ToolManager getToolManager(Class c) {
453 for (int i = 0; i < toolManagers.length; i++) {
454 ToolManager m = toolManagers[i];
455 if (c.isInstance(m))
456 return m;
457 }
458 return null;
459 }
460
461 /**
462 * Get the instance of a tool manager for this desktop of a specific class.
463 * @param className the name of the class of the desired tool manager.
464 * @return a tool manager of the desired type, or null if none found
465 */
466 public ToolManager getToolManager(String className) {
467 for (int i = 0; i < toolManagers.length; i++) {
468 ToolManager m = toolManagers[i];
469 if (m.getClass().getName().equals(className))
470 return m;
471 }
472 return null;
505 FileHistoryEntry h = i.next();
506 if (h.fileOpener == fo && h.file.equals(f)) {
507 i.remove();
508 break;
509 }
510 }
511
512 // add it to the front of the list
513 fileHistory.addFirst(new FileHistoryEntry(fo, f));
514
515 // throw away old entries in the list
516 while (fileHistory.size() > FILE_HISTORY_MAX_SIZE)
517 fileHistory.removeLast();
518 }
519
520 /**
521 * Get a list of the current entries on the file history associated with this desktop.
522 * @return a list of the current entries on the file history associated with this desktop
523 * @see #addToFileHistory
524 */
525 List getFileHistory()
526 {
527 return fileHistory;
528 }
529
530 /**
531 * Check if the top level windows of the desktop are visible or not.
532 * @return true if the top level windows are visible; otherwise, return false
533 * @see #setVisible
534 */
535 public boolean isVisible() {
536 return (currView == null ? false : currView.isVisible());
537 }
538
539 /**
540 * Set whether or not the top level windows of the desktop should be visible.
541 * @param b If true, the top level windows will be made visible; if false, they
542 * will be hidden.
543 */
544 public void setVisible(final boolean b) {
545 if (!EventQueue.isDispatchThread()) {
1421 // background, per JavaHelp suggestions
1422 Runnable r = new Runnable() {
1423 public void run() {
1424 helpBroker.initPresentation();
1425 }
1426 };
1427 Thread t = new Thread(r);
1428 t.setPriority(Thread.MIN_PRIORITY + 1); // not lowest, but pretty low
1429 t.start();
1430 *
1431 */
1432 }
1433 }
1434
1435 private void initToolManagers() {
1436 // locate init file and load up the managers
1437 //System.err.println("Desktop.initToolManagers");
1438
1439 try {
1440 ManagerLoader ml = new ManagerLoader(ToolManager.class, System.err);
1441 ml.setManagerConstructorArgs(new Class[] { Desktop.class }, new Object[] { this });
1442 Set s = ml.loadManagers(TOOLMGRLIST);
1443 toolManagers = (ToolManager[]) (s.toArray(new ToolManager[s.size()]));
1444 }
1445 catch (IOException e) {
1446 throw new JavaTestError(uif.getI18NResourceBundle(),
1447 "dt.cantAccessResource", new Object[] { TOOLMGRLIST, e } );
1448 }
1449 }
1450
1451 private void ensureViewInitialized() {
1452 if (currView != null)
1453 return;
1454
1455 switch (style) {
1456 case MDI_STYLE:
1457 currView = new MDIDeskView(this);
1458 break;
1459
1460 case SDI_STYLE:
1461 currView = new SDIDeskView(this);
1462 break;
1463
|
150 }
151
152 private void initLAF(CommandContext ctx) {
153 int preferredLAF;
154 if (ctx != null) {
155 preferredLAF = ctx.getPreferredLookAndFeel();
156 } else {
157 // can occur from the test
158 preferredLAF = CommandContext.DEFAULT_LAF;
159 }
160
161 switch (preferredLAF) {
162 case CommandContext.SYSTEM_LAF:
163 try {
164 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
165 } catch (Exception e) {
166 }
167 break;
168 case CommandContext.METAL_LAF:
169 try {
170 Class<?> nimbusClass = Class.forName("javax.swing.plaf.metal.MetalLookAndFeel");
171 UIManager.setLookAndFeel((LookAndFeel) nimbusClass.newInstance());
172 } catch (Throwable e) {
173 }
174 break;
175 case CommandContext.NIMBUS_LAF:
176 try {
177 Class<?> nimbusClass = Class.forName("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
178 UIManager.setLookAndFeel((LookAndFeel) nimbusClass.newInstance());
179 } catch (Throwable e) {
180 }
181 break;
182 // no need to process CommandContext.DEFAULT_LAF - it should equal one of the others constatns
183 }
184
185 }
186
187 /**
188 * Create a desktop using a specified style.
189 * @param style a value indicating the desired desktop style.
190 * @see #MDI_STYLE
191 * @see #SDI_STYLE
192 * @see #TAB_STYLE
193 */
194 public Desktop(int style) {
195 this(style, null);
196 }
197
382 }
383
384
385 /**
386 * Add a new default tool to the desktop. The default can be set via the
387 * system property "javatest.desktop.defaultTool", which should identify
388 * the class name of an appropriate tool manager; if not set, the default
389 * is com.sun.javatest.exec.ExecManager.
390 * @param ip a configuration to be passed to the default tool manager's startTool
391 * method
392 * @see #removeTool
393 */
394 public Tool addDefaultTool(InterviewParameters ip) {
395 for (int i = 0; i < toolManagers.length; i++) {
396 ToolManager mgr = toolManagers[i];
397 if (mgr.getClass().getName().equals(defaultToolManager)) {
398 try {
399 // this is to avoid a class dependency to exec package, which is
400 // normally not allowed in this package
401 Method m = mgr.getClass().getMethod("startTool",
402 new Class<?>[] { InterviewParameters.class} );
403
404 return (Tool) m.invoke(mgr, new Object[] { ip });
405 }
406 catch (NoSuchMethodException e) {
407 // ignore??
408 e.printStackTrace();
409 }
410 catch (IllegalAccessException e) {
411 // ignore??
412 e.printStackTrace();
413 }
414 catch (InvocationTargetException e) {
415 // ignore??
416 unwrap(e).printStackTrace();
417 }
418 }
419 }
420 return null;
421 }
422
432 return true;
433 }
434 return false;
435 }
436
437 /**
438 * Get the set of tool managers associated with this desktop.
439 * The managers are determined from resource files named
440 * "com.sun.javatest.tool.ToolManager.lst" on the main JT Harness classpath.
441 * @return the set of tool managers associated with this desktop
442 */
443 public ToolManager[] getToolManagers() {
444 return toolManagers;
445 }
446
447 /**
448 * Get the instance of a tool manager for this desktop of a specific class.
449 * @param c the class of the desired tool manager.
450 * @return a tool manager of the desired type, or null if none found
451 */
452 public ToolManager getToolManager(Class<?> c) {
453 for (int i = 0; i < toolManagers.length; i++) {
454 ToolManager m = toolManagers[i];
455 if (c.isInstance(m))
456 return m;
457 }
458 return null;
459 }
460
461 /**
462 * Get the instance of a tool manager for this desktop of a specific class.
463 * @param className the name of the class of the desired tool manager.
464 * @return a tool manager of the desired type, or null if none found
465 */
466 public ToolManager getToolManager(String className) {
467 for (int i = 0; i < toolManagers.length; i++) {
468 ToolManager m = toolManagers[i];
469 if (m.getClass().getName().equals(className))
470 return m;
471 }
472 return null;
505 FileHistoryEntry h = i.next();
506 if (h.fileOpener == fo && h.file.equals(f)) {
507 i.remove();
508 break;
509 }
510 }
511
512 // add it to the front of the list
513 fileHistory.addFirst(new FileHistoryEntry(fo, f));
514
515 // throw away old entries in the list
516 while (fileHistory.size() > FILE_HISTORY_MAX_SIZE)
517 fileHistory.removeLast();
518 }
519
520 /**
521 * Get a list of the current entries on the file history associated with this desktop.
522 * @return a list of the current entries on the file history associated with this desktop
523 * @see #addToFileHistory
524 */
525 List<FileHistoryEntry> getFileHistory()
526 {
527 return fileHistory;
528 }
529
530 /**
531 * Check if the top level windows of the desktop are visible or not.
532 * @return true if the top level windows are visible; otherwise, return false
533 * @see #setVisible
534 */
535 public boolean isVisible() {
536 return (currView == null ? false : currView.isVisible());
537 }
538
539 /**
540 * Set whether or not the top level windows of the desktop should be visible.
541 * @param b If true, the top level windows will be made visible; if false, they
542 * will be hidden.
543 */
544 public void setVisible(final boolean b) {
545 if (!EventQueue.isDispatchThread()) {
1421 // background, per JavaHelp suggestions
1422 Runnable r = new Runnable() {
1423 public void run() {
1424 helpBroker.initPresentation();
1425 }
1426 };
1427 Thread t = new Thread(r);
1428 t.setPriority(Thread.MIN_PRIORITY + 1); // not lowest, but pretty low
1429 t.start();
1430 *
1431 */
1432 }
1433 }
1434
1435 private void initToolManagers() {
1436 // locate init file and load up the managers
1437 //System.err.println("Desktop.initToolManagers");
1438
1439 try {
1440 ManagerLoader ml = new ManagerLoader(ToolManager.class, System.err);
1441 ml.setManagerConstructorArgs(new Class<?>[] { Desktop.class }, new Object[] { this });
1442 Set<?> s = ml.loadManagers(TOOLMGRLIST);
1443 toolManagers = s.toArray(new ToolManager[s.size()]);
1444 }
1445 catch (IOException e) {
1446 throw new JavaTestError(uif.getI18NResourceBundle(),
1447 "dt.cantAccessResource", new Object[] { TOOLMGRLIST, e } );
1448 }
1449 }
1450
1451 private void ensureViewInitialized() {
1452 if (currView != null)
1453 return;
1454
1455 switch (style) {
1456 case MDI_STYLE:
1457 currView = new MDIDeskView(this);
1458 break;
1459
1460 case SDI_STYLE:
1461 currView = new SDIDeskView(this);
1462 break;
1463
|