uic.widgets
Class MainWindow

java.lang.Object
  extended by uic.widgets.AbstractWindow
      extended by uic.widgets.MainWindow

public class MainWindow
extends AbstractWindow

MainWindow is the application window for any application you will create. In the Single Document Interface (which surpasses the Mutiple Document Interface) way of working every MainWindow equals one document. To create a new application you can instanciate a new MainWindow class and put your content in it followed by a call to show() Details like window positioning and size can be ignored, the MainWindow takes care of that.

Notice that closing (the last) main window will exit java automatically.


Nested Class Summary
static class MainWindow.GlassPaneListener
          Class that stops all events to the window when we are in 'help' mode to show a whatIs message.
static class MainWindow.RootPane
          Class that is a rootpane on the MainWindow in order to have the statusBar be correctly placed.
 
Field Summary
protected static int mainWindowCount
           
protected static MetalTheme myTheme
          A UICompiler theme (most of the time) that is created for this window
 
Fields inherited from class uic.widgets.AbstractWindow
internalWindow
 
Constructor Summary
MainWindow()
          Empty constructor to create a new window without a specific name.
MainWindow(String title)
          Create a new window with title.
 
Method Summary
 void cancelHelpMode()
          Cancels the mode started with goToHelpMode.
 void closeWindowSlot()
           
protected  ActionFactory createGui(TranslationInterface translate, String xmlFile)
          Creating an XML based UI can be done by using the returned ActionFactory to add all your actions to.
protected  Window createInternalWindow(Dialog owner, String title, boolean modal)
           
protected  Window createInternalWindow(Frame owner, String title, boolean modal)
           
protected  MetalTheme createLookAndFeel()
          Called from constructor to set a look and feel on the new Frame.
protected  StatusBar createStatusBar()
          Override this method to provide your own StatusBar implementation.
 JFrame getFrame()
          return the top level JFrame which shows the visual MainWindow
 JMenuBar getMenuBar()
          Return the menuBar.
protected  Preferences getPrefs()
          Get presistence preferences object, or null if none available.
 StatusBar getStatusBar()
          return the statusBar.
 JToolBar getToolbar()
          Deprecated.  
 JToolBar getToolBar()
          Returns the toolbar.
 JToolBar getToolBar(String name)
          Returns the toolbar with the specified name.
 void goToHelpMode()
          Go to a mode where the cursor changes to a question mark and clicking on a widget will then trigger a popup with information about the widget.
 void openThemeConfigDialog()
          Open a dialog that allows the user to configure the colors, fonts and various other settings.
protected  boolean queryClose()
          Called before the window is closed, either by the user or indirectly by the session manager.
 void setAllowConfigurationDialog(boolean enable)
          Configure if this window allows a theme-configuration dialog to be shown.
 void setAllowToolBarConfiguration(boolean enable)
          Configure if each toolbar should have a popup where the user can configure what is shown.
 void setAllowToolBarHiding(boolean enable)
          Configure if toolbar hiding widgets should be shown to the user.
 void setBusy(boolean busy)
          Set an hourglass cursor on this window when true.
 void setCaption(String name)
          Set the name that is displayed in the window manager
 int show(Point location, Dimension size)
          Overloaded, see AbstractWindow for details.
 void shutdown()
          Called when the application exits.
static void useUICTheme(boolean enabled)
          To automatically set the UICTheme to the newly created window this should be set before instanciating the first mainWindow.
 
Methods inherited from class uic.widgets.AbstractWindow
getBounds, getDefaultFocusComponent, getDialogSizePanel, getLocation, getRPContainer, getSize, positionDialog, positionDialog, setComponent, setDefaultFocusComponent, show, show
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mainWindowCount

protected static int mainWindowCount

myTheme

protected static MetalTheme myTheme
A UICompiler theme (most of the time) that is created for this window

Constructor Detail

MainWindow

public MainWindow()
Empty constructor to create a new window without a specific name.


MainWindow

public MainWindow(String title)
Create a new window with title.

Method Detail

createInternalWindow

protected Window createInternalWindow(Frame owner,
                                      String title,
                                      boolean modal)
Specified by:
createInternalWindow in class AbstractWindow

createInternalWindow

protected Window createInternalWindow(Dialog owner,
                                      String title,
                                      boolean modal)
Specified by:
createInternalWindow in class AbstractWindow

useUICTheme

public static void useUICTheme(boolean enabled)
To automatically set the UICTheme to the newly created window this should be set before instanciating the first mainWindow. The default is true.

Parameters:
enabled - set UICTheme to new created MainWinow instances.

createLookAndFeel

protected MetalTheme createLookAndFeel()
Called from constructor to set a look and feel on the new Frame.


openThemeConfigDialog

public void openThemeConfigDialog()
                           throws ClassNotFoundException
Open a dialog that allows the user to configure the colors, fonts and various other settings. This method allows the user to configure all open MainWindow instances for their look and feel settings. Pressing OK in the dialog will immediately change this windows settings. Using this method instead of the showConfirmDialog method on the ConfigDialog class will make sure that only one config is present in the JVM at a time. So all windows have the same look.

Please note that the config dialog is packaged in the optional package of UICompiler, the uic-optional.jar needs to be in the classpath for this to succeed.

Throws:
IllegalStateException - if the mainwindow was altered to not use the UICTheme.
ClassNotFoundException - if the uic-optional.jar is missing from the classpath.
Since:
2.0

getFrame

public JFrame getFrame()
return the top level JFrame which shows the visual MainWindow

Returns:
the top level JFrame which shows the visual MainWindow

show

public int show(Point location,
                Dimension size)
Overloaded, see AbstractWindow for details.

Overrides:
show in class AbstractWindow
Parameters:
location - the x and y coordinates on the screen where the dialog should appear, can be null to use parents position.
size - a size hint for the dialog, can be null to use default based on the preferredSize.
Returns:
always 1

getPrefs

protected Preferences getPrefs()
Get presistence preferences object, or null if none available.


getToolbar

public JToolBar getToolbar()
Deprecated. 

Deprecated, use getToolBar() instead

Returns:
the toolbar

getToolBar

public JToolBar getToolBar()
Returns the toolbar. If the toolbar does not exist one will be created.

Returns:
the toolbar

getToolBar

public JToolBar getToolBar(String name)
Returns the toolbar with the specified name. If the toolbar does not exist one will be created.

Returns:
the toolbar

createGui

protected ActionFactory createGui(TranslationInterface translate,
                                  String xmlFile)
Creating an XML based UI can be done by using the returned ActionFactory to add all your actions to. The format of the xmlFile is explained in ActionFactory. The file should be made available to the JVM in the classpath, or in the current directory. It is also possible to provide an absolute filename (starting with C:\ or / on unix), but that is not advised.

For example:

      public class ReportWriter extends MainWindow {
          public ReportWriter() {
              Translate myTranslator = new Translate("reportwriter");
              ActionFactory af = createGui(myTranslator, "reportwriter");
              // init actions here
          }
      }
By placing a "reportwriter.rc" in the root of your jar your menus and toolbars will automatically be build.
Additionally; placing the reportwriter.properties file in the root of your jar allows you to provide translations for your actions and menu names.

Parameters:
translate - a translator object which is used to translate strings found in the XML file, or null for the defaultTranslator
xmlFile - the name of the file used to construct the UI from.
See Also:
ActionFactory, Translate

getMenuBar

public JMenuBar getMenuBar()
Return the menuBar. When none is found, one will be created.

Returns:
the menubar for this MainWindow

getStatusBar

public StatusBar getStatusBar()
return the statusBar. When none is found, one will be created.

Returns:
the statusBar for this MainWindow

createStatusBar

protected StatusBar createStatusBar()
Override this method to provide your own StatusBar implementation.


setBusy

public void setBusy(boolean busy)
Set an hourglass cursor on this window when true.


setCaption

public void setCaption(String name)
Set the name that is displayed in the window manager


setAllowConfigurationDialog

public void setAllowConfigurationDialog(boolean enable)
Configure if this window allows a theme-configuration dialog to be shown.

Parameters:
enable - Set true to add a menu entry for the standard configuration dialog which allows the user to set fonts, colors, etc. Notice that this option is normally not enabled, since it requires the uic-optional jar to be in your path. This only works when called before createGui(uic.TranslationInterface, java.lang.String) is called.
Throws:
IllegalStateException - if called after the createGui has been called.

setAllowToolBarConfiguration

public void setAllowToolBarConfiguration(boolean enable)
Configure if each toolbar should have a popup where the user can configure what is shown. The popup to configure if the user-configuration context-menu should be shown. This menu allows options like only icons or icons/text for icons.

Parameters:
enable - Set true to allow menu items which allow the user to configure toolbars on the context menus

setAllowToolBarHiding

public void setAllowToolBarHiding(boolean enable)
Configure if toolbar hiding widgets should be shown to the user.

Parameters:
enable - If true, show the checkboxes to show/hide toolbars on both regular and context menus This only works when called before createGui(uic.TranslationInterface, java.lang.String) is called.
Throws:
IllegalStateException - if called after the createGui has been called.

closeWindowSlot

public void closeWindowSlot()

queryClose

protected boolean queryClose()
Called before the window is closed, either by the user or indirectly by the session manager. The purpose of this function is to prepare the window in a way that it is safe to close it, i.e. without the user losing some data. Default implementation returns true. Returning false will cancel the closing


shutdown

public void shutdown()
Called when the application exits. The purpose of this function is to exit the JVM, and will only be called when all MainWindow instances have quit. The default implementation is a single 'System.exit(0);', but it is wise to call this method (using super.shutdown()) at the end if you plan to override it.


goToHelpMode

public void goToHelpMode()
Go to a mode where the cursor changes to a question mark and clicking on a widget will then trigger a popup with information about the widget. The text shown has to be registered first, see UICWhatsThis.add(java.awt.Component, java.lang.String)

See Also:
UICWhatsThis.add(java.awt.Component, java.lang.String)

cancelHelpMode

public void cancelHelpMode()
Cancels the mode started with goToHelpMode.

See Also:
goToHelpMode()


Copyright © 2002-2004 Thomas Zander Available under the Free Apache licence