com.sun.javatest.tool
Class Desktop

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

public class Desktop
extends java.lang.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
static int MDI_STYLE
          A constant to indicate the MDI-style desktop: a single window for the desktop, containing multiple internal windows, one per tool.
static int SDI_STYLE
          A constant to indicate the SDI-style desktop: multiple top-level windows, one per tool.
static int TAB_STYLE
          A constant to indicate the tabbed-style desktop: a single window for the desktop, using a tabbed pane for the tools.
 
Constructor Summary
Desktop()
          Create a desktop using a style determined according to the user's preferences.
Desktop(CommandContext ctx)
          New desktop, using preferred style and given context.
Desktop(int style)
          Create a desktop using a specified style.
Desktop(int style, CommandContext ctx)
           
 
Method Summary
 void addDefaultTool()
          Add a new default tool to the desktop.
 Tool addDefaultTool(InterviewParameters ip)
          Add a new default tool to the desktop.
 void addToFileHistory(java.io.File f, FileOpener fo)
          Add a file and a corresponding file opener to the file history that appears on the File menu.
 void addTool(Tool t)
          Add a new tool to the desktop.
 void checkToolsAndExitIfOK(javax.swing.JFrame parent)
          Check all the tools on the desktop to see if they have open state that should be saved or processes running.
 boolean containsTool(Tool t)
          Check if a tool is present on the desktop.
 java.awt.Container createDialog(Tool tool, java.lang.String uiKey, java.lang.String title, javax.swing.JMenuBar menuBar, java.awt.Container body, java.awt.Rectangle bounds, int type)
          Create a dialog.
 void dispose()
          Dispose of any resources used by this object.
 java.awt.Component getDialogParent()
          Get a parent component for a dialog to use.
 javax.swing.JFrame[] getFrames()
          Get the top level frames that make up this desktop.
 javax.help.HelpBroker getHelpBroker()
          Get the Help Broker used by the Help menu amd context sensitive help.
 javax.swing.Icon getLogo()
          Get an icon containing the JT Harness logo.
static int getPreferredStyle()
          Get a value indicating the user's preferred desktop style, as recorded in the user's preferences.
 boolean getRestoreOnStart()
          Check whether or not the desk view should restore saved tools state when the Harness is starting.
 boolean getSaveOnExit()
          Check whether or not the desktop will save its state when the VM exits.
 Tool getSelectedTool()
          Get the currently selected tool on the desktop.
 int getStyle()
          Get a value indicating the current style of the desktop.
 ToolManager getToolManager(java.lang.Class c)
          Get the instance of a tool manager for this desktop of a specific class.
 ToolManager getToolManager(java.lang.String className)
          Get the instance of a tool manager for this desktop of a specific class.
 ToolManager[] getToolManagers()
          Get the set of tool managers associated with this desktop.
 Tool[] getTools()
          Get the set of tools currently on the desktop.
 boolean isEmpty()
          Check whether the desktop is empty of any tools.
 boolean isFirstTime()
          Determine if this is the first time that JT Harness has been run.
 boolean isOKToAutoExit()
          Check if it is OK to automatically exit JT Harness.
 boolean isOKToClose(Tool t, javax.swing.JFrame parent)
          Check if it is OK to close a tool.
 boolean isOKToExit(javax.swing.JFrame parent)
          Check if it is OK to close all tools and exit the desktop.
 boolean isToolOwnerForDialog(Tool tool, java.awt.Container dialog)
          Check if the tool's parent Window is the owner of a dialog.
 boolean isVisible()
          Check if the top level windows of the desktop are visible or not.
 void log(I18NResourceBundle i18n, java.lang.String key)
          Print a text message to the desktop logfile.
 void log(I18NResourceBundle i18n, java.lang.String key, java.lang.Object arg)
          Print a text message to the desktop logfile.
 void log(I18NResourceBundle i18n, java.lang.String key, java.lang.Object[] args)
          Print a text message to the desktop logfile.
 void print(java.awt.print.Printable printable)
           
 void printSetup()
           
 void removeTool(Tool t)
          Remove a tool from the desktop.
 void restore()
          Restore the desktop from information in a saved desktop file.
 void restore(java.io.File file)
          Restore the desktop from information in a specified file.
 void restoreHistory()
           
 void save()
          Save the current state of the desktop in the user's standard desktop file.
 void save(java.io.File f)
          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 setSelectedTool(Tool t)
          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 showPreferences(javax.swing.JFrame parent)
          Show a Preferences window.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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:
Constant Field Values

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:
Constant Field Values

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:
Constant Field Values
Constructor Detail

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:
MDI_STYLE, SDI_STYLE, TAB_STYLE
Method Detail

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(int), MDI_STYLE, SDI_STYLE, TAB_STYLE

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:
MDI_STYLE, SDI_STYLE, TAB_STYLE

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:
getStyle(), MDI_STYLE, SDI_STYLE, TAB_STYLE

getHelpBroker

public javax.help.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:
isFirstTime()

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(com.sun.javatest.tool.Tool)

removeTool

public void removeTool(Tool t)
Remove a tool from the desktop.

Parameters:
t - the tool to be removed
See Also:
addTool(com.sun.javatest.tool.Tool)

getSelectedTool

public Tool getSelectedTool()
Get the currently selected tool on the desktop.

Returns:
the currently selected tool on the desktop
See Also:
setSelectedTool(com.sun.javatest.tool.Tool)

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:
getSelectedTool()

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:
removeTool(com.sun.javatest.tool.Tool)

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:
removeTool(com.sun.javatest.tool.Tool)

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(java.lang.Class 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(java.lang.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 javax.swing.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 java.awt.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(java.io.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(boolean)

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 java.awt.Container createDialog(Tool tool,
                                       java.lang.String uiKey,
                                       java.lang.String title,
                                       javax.swing.JMenuBar menuBar,
                                       java.awt.Container body,
                                       java.awt.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,
                                    java.awt.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(javax.swing.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:
isOKToExit(javax.swing.JFrame)

isOKToClose

public boolean isOKToClose(Tool t,
                           javax.swing.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(javax.swing.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(java.io.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(java.io.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(javax.swing.JFrame parent)
Show a Preferences window.

Parameters:
parent - the parent frame to be used for the preferences dialog

getLogo

public javax.swing.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,
                java.lang.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,
                java.lang.String key,
                java.lang.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,
                java.lang.String key,
                java.lang.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(boolean)

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:
getSaveOnExit()

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(boolean)

setRestoreOnStart

public void setRestoreOnStart(boolean restoreOnStart)
Specify whether or not the desk view should restore saved tools state when the Harness is starting.

Parameters:
b - true if the desk will restore its tools when the Harness is starting, and false otherwise
See Also:
getRestoreOnStart()

printSetup

public void printSetup()

print

public void print(java.awt.print.Printable printable)


Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.