Class Desktop

java.lang.Object
com.sun.javatest.tool.Desktop

public class Desktop extends Object
Desktop is the host for a series of Tools, which may be displayed as in a number of styles, provided by a DeskView.

Much of the functionality of a desktop is provided by the current view, and because of that, many of the methods here simply call through to the underlying current view object.

See Also:
  • DeskView
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    A constant to indicate the MDI-style desktop: a single window for the desktop, containing multiple internal windows, one per tool.
    static final int
    A constant to indicate the SDI-style desktop: multiple top-level windows, one per tool.
    static final int
    A constant to indicate the tabbed-style desktop: a single window for the desktop, using a tabbed pane for the tools.
    static final String
    If this system property is defined then its value is expected to contain comma-separated list of ToolManager subclasses to load, which would be put in use instead of those contained in the dedicated file.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a desktop using a style determined according to the user's preferences.
    Desktop(int style)
    Create a desktop using a specified style.
    Desktop(int style, CommandContext ctx)
     
    New desktop, using preferred style and given context.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Add a new default tool to the desktop.
    Add a new default tool to the desktop.
    void
    Add a file and a corresponding file opener to the file history that appears on the File menu.
    void
    Add a new tool to the desktop.
    void
    Check all the tools on the desktop to see if they have open state that should be saved or processes running.
    boolean
    Check if a tool is present on the desktop.
    createDialog(Tool tool, String uiKey, String title, JMenuBar menuBar, Container body, Rectangle bounds, int type)
    Create a dialog.
    void
    Dispose of any resources used by this object.
    Get a parent component for a dialog to use.
    Get the top level frames that make up this desktop.
    com.sun.javatest.tool.jthelp.HelpBroker
    Get the Help Broker used by the Help menu amd context sensitive help.
    Get an icon containing the JT Harness logo.
    static int
    Get a value indicating the user's preferred desktop style, as recorded in the user's preferences.
    boolean
    Check whether or not the desk view should restore saved tools state when the Harness is starting.
    boolean
    Check whether or not the desktop will save its state when the VM exits.
    Get the currently selected tool on the desktop.
    int
    Get a value indicating the current style of the desktop.
    Get the instance of a tool manager for this desktop of a specific class.
    Get the instance of a tool manager for this desktop of a specific class.
    Get the set of tool managers associated with this desktop.
    Get the set of tools currently on the desktop.
    boolean
    Check whether the desktop is empty of any tools.
    boolean
    Determine if this is the first time that JT Harness has been run.
    boolean
    Check if it is OK to automatically exit JT Harness.
    boolean
    isOKToClose(Tool t, JFrame parent)
    Check if it is OK to close a tool.
    boolean
    Check if it is OK to close all tools and exit the desktop.
    boolean
    Check if the tool's parent Window is the owner of a dialog.
    boolean
    Check if the top level windows of the desktop are visible or not.
    void
    Print a text message to the desktop logfile.
    void
    log(I18NResourceBundle i18n, String key, Object arg)
    Print a text message to the desktop logfile.
    void
    log(I18NResourceBundle i18n, String key, Object... args)
    Print a text message to the desktop logfile.
    void
    print(Printable printable)
     
    void
     
    void
    Remove a tool from the desktop.
    void
    Restore the desktop from information in a saved desktop file.
    void
    restore(File file)
    Restore the desktop from information in a specified file.
    void
     
    void
    Save the current state of the desktop in the user's standard desktop file.
    void
    Save the current state of the desktop in a specified desktop file.
    void
    setFirstTime(boolean b)
    Set the flag indicating whether or not this is the first time that JT Harness has been run.
    void
    setRestoreOnStart(boolean restoreOnStart)
    Specify whether or not the desk view should restore saved tools state when the Harness is starting.
    void
    setSaveOnExit(boolean b)
    Specify whether or not the desktop will save its state when the VM exits.
    void
    Set the currently selected tool on the desktop.
    void
    setStyle(int style)
    Set the current style of the desktop.
    void
    setVisible(boolean b)
    Set whether or not the top level windows of the desktop should be visible.
    void
    Show a Preferences window.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • TAB_STYLE

      public static final int TAB_STYLE
      A constant to indicate the tabbed-style desktop: a single window for the desktop, using a tabbed pane for the tools.
      See Also:
    • MDI_STYLE

      public static final int MDI_STYLE
      A constant to indicate the MDI-style desktop: a single window for the desktop, containing multiple internal windows, one per tool.
      See Also:
    • SDI_STYLE

      public static final int SDI_STYLE
      A constant to indicate the SDI-style desktop: multiple top-level windows, one per tool.
      See Also:
    • TOOL_MANAGERS_TO_LOAD

      public static final String TOOL_MANAGERS_TO_LOAD
      If this system property is defined then its value is expected to contain comma-separated list of ToolManager subclasses to load, which would be put in use instead of those contained in the dedicated file.
      See Also:
  • Constructor Details

    • Desktop

      public Desktop()
      Create a desktop using a style determined according to the user's preferences.
    • Desktop

      public Desktop(CommandContext ctx)
      New desktop, using preferred style and given context.
    • Desktop

      public Desktop(int style, CommandContext ctx)
    • Desktop

      public Desktop(int style)
      Create a desktop using a specified style.
      Parameters:
      style - a value indicating the desired desktop style.
      See Also:
  • Method Details

    • getPreferredStyle

      public static int getPreferredStyle()
      Get a value indicating the user's preferred desktop style, as recorded in the user's preferences.
      Returns:
      a value indicating the user's preferred desktop style
      See Also:
    • getStyle

      public int getStyle()
      Get a value indicating the current style of the desktop.
      Returns:
      a value indicating the current style of the desktop
      See Also:
    • setStyle

      public void setStyle(int style)
      Set the current style of the desktop.
      Parameters:
      style - a value indicating the current style of the desktop
      See Also:
    • getHelpBroker

      public com.sun.javatest.tool.jthelp.HelpBroker getHelpBroker()
      Get the Help Broker used by the Help menu amd context sensitive help.
      Returns:
      the help broker
    • isFirstTime

      public boolean isFirstTime()
      Determine if this is the first time that JT Harness has been run. This is determined by checking if a saved desktop exists from a prior run of JT Harness.
      Returns:
      true if this appears to be the first time the user has run JT Harness, and false otherwise
    • setFirstTime

      public void setFirstTime(boolean b)
      Set the flag indicating whether or not this is the first time that JT Harness has been run.
      Parameters:
      b - true if JT Harness should behave as though this is th first time JT Harness has been run
      See Also:
    • isEmpty

      public boolean isEmpty()
      Check whether the desktop is empty of any tools.
      Returns:
      true if there are no tools on the desktop, and false otherwise
    • getTools

      public Tool[] getTools()
      Get the set of tools currently on the desktop.
      Returns:
      the set of tools currently on the desktop
    • addTool

      public void addTool(Tool t)
      Add a new tool to the desktop.
      Parameters:
      t - the tool to be added
      See Also:
    • removeTool

      public void removeTool(Tool t)
      Remove a tool from the desktop.
      Parameters:
      t - the tool to be removed
      See Also:
    • getSelectedTool

      public Tool getSelectedTool()
      Get the currently selected tool on the desktop.
      Returns:
      the currently selected tool on the desktop
      See Also:
    • setSelectedTool

      public void setSelectedTool(Tool t)
      Set the currently selected tool on the desktop.
      Parameters:
      t - the the tool to be selected on the desktop
      See Also:
    • addDefaultTool

      public void addDefaultTool()
      Add a new default tool to the desktop. The default can be set via the system property "javatest.desktop.defaultTool", which should identify the class name of an appropriate tool manager; if not set, the default is com.sun.javatest.exec.ExecManager.
      See Also:
    • addDefaultTool

      public Tool addDefaultTool(InterviewParameters ip)
      Add a new default tool to the desktop. The default can be set via the system property "javatest.desktop.defaultTool", which should identify the class name of an appropriate tool manager; if not set, the default is com.sun.javatest.exec.ExecManager.
      Parameters:
      ip - a configuration to be passed to the default tool manager's startTool method
      See Also:
    • containsTool

      public boolean containsTool(Tool t)
      Check if a tool is present on the desktop.
      Parameters:
      t - the tool for which to check
      Returns:
      true if the specified tool exists on the desktop, and false otherwise
    • getToolManagers

      public ToolManager[] getToolManagers()
      Get the set of tool managers associated with this desktop. The managers are determined from resource files named "com.sun.javatest.tool.ToolManager.lst" on the main JT Harness classpath.
      Returns:
      the set of tool managers associated with this desktop
    • getToolManager

      public ToolManager getToolManager(Class<? extends ToolManager> c)
      Get the instance of a tool manager for this desktop of a specific class.
      Parameters:
      c - the class of the desired tool manager.
      Returns:
      a tool manager of the desired type, or null if none found
    • getToolManager

      public ToolManager getToolManager(String className)
      Get the instance of a tool manager for this desktop of a specific class.
      Parameters:
      className - the name of the class of the desired tool manager.
      Returns:
      a tool manager of the desired type, or null if none found
    • getFrames

      public JFrame[] getFrames()
      Get the top level frames that make up this desktop. TAB and MDI style desktops just have a single frame; An SDI style desktop may have more than one frame.
      Returns:
      the top level frames of this desktop
    • getDialogParent

      public Component getDialogParent()
      Get a parent component for a dialog to use.
      Returns:
      Component which can be used as a parent, or null if none is available.
    • addToFileHistory

      public void addToFileHistory(File f, FileOpener fo)
      Add a file and a corresponding file opener to the file history that appears on the File menu.
      Parameters:
      f - The file to be added
      fo - A FileOpener object to be used to open the file if necessary
    • isVisible

      public boolean isVisible()
      Check if the top level windows of the desktop are visible or not.
      Returns:
      true if the top level windows are visible; otherwise, return false
      See Also:
    • setVisible

      public void setVisible(boolean b)
      Set whether or not the top level windows of the desktop should be visible.
      Parameters:
      b - If true, the top level windows will be made visible; if false, they will be hidden.
    • createDialog

      public Container createDialog(Tool tool, String uiKey, String title, JMenuBar menuBar, Container body, Rectangle bounds, int type)
      Create a dialog.
      Parameters:
      tool - the parent tool for the dialog
      uiKey - a string which is to be used as the base name for any resources that may be required
      title - the title for the dialog
      menuBar - the menu bar for the dialog
      body - the body component for the dialog
      bounds - the size and position for the dialog
      Returns:
      a JDialog or JInternalDialog built from the supplied values.
    • isToolOwnerForDialog

      public boolean isToolOwnerForDialog(Tool tool, Container dialog)
      Check if the tool's parent Window is the owner of a dialog. This may become false if the desktop style is changed after the dialog was created.
      Parameters:
      tool - the tool from which to determine the parent Window
      dialog - the dialog to be checked
      Returns:
      true if the tool's parent Window is the owner of the dialog, and false otherwise.
    • checkToolsAndExitIfOK

      public void checkToolsAndExitIfOK(JFrame parent)
      Check all the tools on the desktop to see if they have open state that should be saved or processes running. If there is open state or active processes, a confirmation dialog will be displayed. If the user confirms OK, or if there was no need to show the confirmation dialog, the desktop will be saved and disposed.
      Parameters:
      parent - A parent frame to be used if a confirmation dialog is necessary
      See Also:
    • isOKToClose

      public boolean isOKToClose(Tool t, JFrame parent)
      Check if it is OK to close a tool. If the tool has important state that needs to be saved, or any processes running, a confirmation dialog will be shown, to allow the user to cancel the operation if necessary.
      Parameters:
      t - The tool to be checked
      parent - A parent frame to be used if a confirmation dialog is necessary
      Returns:
      true if it is OK to close the tool
    • isOKToExit

      public boolean isOKToExit(JFrame parent)
      Check if it is OK to close all tools and exit the desktop. If any tools have important state that needs to be saved, or active tasks running, a confirmation dialog will be shown to allow the user to cancel the operation in progress.
      Parameters:
      parent - A parent frame to be used if a confirmation dialog is necessary
      Returns:
      true if it is OK to exit the desktop, and false otherwise.
    • isOKToAutoExit

      public boolean isOKToAutoExit()
      Check if it is OK to automatically exit JT Harness. A warning dialog is posted to the user for a reasonable but short while allowing the user to cancel the exit.
      Returns:
      true if the user does not respond within the available time, or if the user allows the request; and false otherwise
    • save

      public void save()
      Save the current state of the desktop in the user's standard desktop file.
    • save

      public void save(File f)
      Save the current state of the desktop in a specified desktop file.
      Parameters:
      f - the file in which to save the desktop
    • restore

      public void restore()
      Restore the desktop from information in a saved desktop file. If no such file exists, or if no tools are successfully started from the info in the file, add a default tool. The work will automatically performed on the main AWT EventQueue thread.
    • restore

      public void restore(File file)
      Restore the desktop from information in a specified file. If no such file exists, or if no tools are successfully started from the info in the file, add a default tool. The work will automatically performed on the main AWT EventQueue thread.
      Parameters:
      file - the file from which to load the data
    • restoreHistory

      public void restoreHistory()
    • showPreferences

      public void showPreferences(JFrame parent)
      Show a Preferences window.
      Parameters:
      parent - the parent frame to be used for the preferences dialog
    • getLogo

      public Icon getLogo()
      Get an icon containing the JT Harness logo.
      Returns:
      an icon containing the JT Harness logo
    • dispose

      public void dispose()
      Dispose of any resources used by this object.
    • log

      public void log(I18NResourceBundle i18n, String key)
      Print a text message to the desktop logfile. A single line of text which is as short as possible is highly recommended for readability purposes.
      Parameters:
      i18n - a resource bundle containing the localized messages
      key - a key into the resource bundle for the required message
      Since:
      3.0.1
    • log

      public void log(I18NResourceBundle i18n, String key, Object arg)
      Print a text message to the desktop logfile. A single line of text which is as short as possible is highly recommended for readability purposes.
      Parameters:
      i18n - a resource bundle containing the localized messages
      key - a key into the resource bundle for the required message
      arg - An argument to be formatted into the specified message. If this is a Throwable, its stack trace will be included in the log.
      Since:
      3.0.1
    • log

      public void log(I18NResourceBundle i18n, String key, Object... args)
      Print a text message to the desktop logfile. A single line of text which is as short as possible is highly recommended for readability purposes.
      Parameters:
      i18n - a resource bundle containing the localized messages
      key - a key into the resource bundle for the required message
      args - An array of arguments to be formatted into the specified message. If the first arg is a Throwable, its stack trace will be included in the log.
      Since:
      3.0.1
    • getSaveOnExit

      public boolean getSaveOnExit()
      Check whether or not the desktop will save its state when the VM exits.
      Returns:
      true if the desktop will save its state when the VM exits, and false otherwise
      See Also:
    • setSaveOnExit

      public void setSaveOnExit(boolean b)
      Specify whether or not the desktop will save its state when the VM exits.
      Parameters:
      b - true if the desktop should save its state when the VM exits, and false otherwise
      See Also:
    • getRestoreOnStart

      public boolean getRestoreOnStart()
      Check whether or not the desk view should restore saved tools state when the Harness is starting.
      Returns:
      true if the desk will restore its tools when the Harness is starting, and false otherwise
      See Also:
    • setRestoreOnStart

      public void setRestoreOnStart(boolean restoreOnStart)
      Specify whether or not the desk view should restore saved tools state when the Harness is starting.
      Parameters:
      restoreOnStart - true if the desk will restore its tools when the Harness is starting, and false otherwise
      See Also:
    • printSetup

      public void printSetup()
    • print

      public void print(Printable printable)