📄 abstractguiapplication.java~1~
字号:
}
}
/*****************************************************************************/
/**
* Gets called from the OSXAdapter; this method is needed by the Mac OS X
* JVM. This is a hook for the standard Apple application menu. This
* method displays the application's About dialog.
*
* @see #getAboutDialog()
*/
public void about() {
try {
getAboutDialog().setVisible(true);
}
catch (Exception e) {
displayException(e);
}
}
/*****************************************************************************/
/**
* Adds an action to this application's action map.
*
* @param key The key with which to fetch the action via
* <code>getAction</code>.
* @param action The action to add.
* @see #createActions
* @see #getAction
*/
public void addAction(String key, Action action) {
if (action == null) {
throw new NullPointerException("action cannot be null");
}
else if (key == null) {
throw new NullPointerException("key cannot be null");
}
if (actionMap == null) {
actionMap = new HashMap();
}
actionMap.put(key, action);
}
/*****************************************************************************/
/**
* Adds a toolbar to this GUI application. Note that this should only
* be used for toolbars other than the main toolbar.
*
* @param toolBar The toolbar to add.
* @param pos The position at which to add it (one of
* <code>BorderLayout.NORTH</code>, etc.).
*/
public void addToolBar(JToolBar toolBar, String pos) {
int count = toolBarPanels.length;
JPanel[] newPanels = new JPanel[count + 1];
System.arraycopy(toolBarPanels, 0, newPanels, 0, count);
newPanels[count] = new JPanel(new BorderLayout());
toolBarPanels = newPanels;
toolBarPanels[count - 1].remove(mainContentPanel);
toolBarPanels[count - 1].add(toolBarPanels[count]);
toolBarPanels[count].add(toolBar, pos);
toolBarPanels[count].add(mainContentPanel);
}
/*****************************************************************************/
/**
* Creates the About dialog this application uses.
*
* @return The About dialog.
* @see #getAboutDialog
*/
protected AboutDialog createAboutDialog() {
return new AboutDialog(this);
}
/*****************************************************************************/
/**
* Creates the actions used by this application. Implementations should
* override this method and add actions used by their application via
* <code>addAction</code>.
*
* @param prefs The preferences for this GUI application. This may
* contain information such as accelerators, etc.
* @see #addAction
* @see #getAction
*/
protected void createActions(GUIApplicationPreferences prefs) {
}
/*****************************************************************************/
/**
* Creates the panel that contains the main content (via the
* <code>actualContentPane</code>. This factory is here so subclasses
* such as <code>AbstractPluggableGUIApplication</code> can add
* functionality (such as the ability to add GUI plugins to this panel).
*
* @param actualContentPane The panel that will contain the program's
* content. This panel should be added to the returned panel.
* @return The panel.
*/
JPanel createMainContentPanel(JPanel actualContentPane) {
JPanel mcp = new JPanel(new GridLayout(1, 1));
mcp.add(actualContentPane);
return mcp;
}
/*****************************************************************************/
/**
* Creates and returns the menu bar used in this application.
*
* @param prefs This GUI application's preferences.
* @return The menu bar.
*/
protected abstract JMenuBar createMenuBar(
GUIApplicationPreferences prefs);
/*****************************************************************************/
/**
* Creates and returns the splash screen to display while this GUI
* application is loading.
*
* @return The splash screen. If <code>null</code> is returned, no splash
* screen is displayed.
*/
protected abstract SplashScreen createSplashScreen();
/*****************************************************************************/
/**
* Creates and returns the status bar to be used by this application. This
* method is called in this <code>GUIApplication</code>'s constructor.
*
* @param prefs This GUI application's preferences.
* @return The status bar.
*/
protected abstract StatusBar createStatusBar(
GUIApplicationPreferences prefs);
/*****************************************************************************/
/**
* Creates and returns the toolbar to be used by this application. This
* method is called in this <code>GUIApplication</code>'s constructor.
*
* @param prefs This GUI application's preferences.
* @return The toolbar.
*/
protected abstract CustomizableToolBar createToolBar(
GUIApplicationPreferences prefs);
/*****************************************************************************/
/**
* Displays a dialog box telling the user that an <code>Exception</code>
* was thrown. This method can be overridden to customize how
* the user is informed of an <code>Exception</code>.
*
* @param t The exception/throwable that occured.
*/
public void displayException(Throwable t) {
displayException(this, t);
}
/*****************************************************************************/
/**
* Displays a dialog box telling the user that an <code>Exception</code>
* was thrown. This method can be overridden to customize how
* the user is informed of an <code>Exception</code>.
* This version of the method allows a window spawned from the
* main GUI application window to be the owner of the displayed
* exception.
*
* @param owner The dialog that threw the Exception.
* @param t The exception/throwable that occured.
*/
public void displayException(Dialog owner, Throwable t) {
ExceptionDialog ed = new ExceptionDialog(owner, t);
ed.setLocationRelativeTo(owner);
ed.setVisible(true);
}
/*****************************************************************************/
/**
* Displays a dialog box telling the user that an <code>Exception</code>
* was thrown. This method can be overridden to customize how
* the user is informed of an <code>Exception</code>.
* This version of the method allows a window spawned from the
* main GUI application window to be the owner of the displayed
* exception.
*
* @param owner The child frame that threw the Exception.
* @param t The exception/throwable that occured.
*/
public void displayException(Frame owner, Throwable t) {
ExceptionDialog ed = new ExceptionDialog(owner, t);
ed.setLocationRelativeTo(owner);
ed.setVisible(true);
}
/*****************************************************************************/
/**
* Called when the user attempts to close the application, whether from
* an "Exit" menu item, closing the main application window, or any other
* means. Applications should override this method to do any cleanup
* before the application exits. You can also prevent the application
* from closing based on the application's state in this method.<p>
*
* The default implementation simply calls <code>System.exit(0)</code>.
*/
public void doExit() {
System.exit(0);
}
/*****************************************************************************/
/**
* Returns the About dialog for this application.
*
* @return The About dialog.
* @see org.fife.ui.AboutDialog
* @see #createAboutDialog
*/
public AboutDialog getAboutDialog() {
if (aboutDialog == null) {
aboutDialog = createAboutDialog();
}
return aboutDialog;
}
/*****************************************************************************/
/**
* Returns one of this application's actions.
*
* @return The action, or <code>null</code> if no action exists for the
* specified key.
* @see #addAction
* @see #createActions
*/
public Action getAction(String key) {
return (Action) actionMap.get(key);
}
/*****************************************************************************/
/**
* Returns the actions of this GUI application as an array.
*
* @return The actions. <code>null</code> is returned if the action
* map has not yet been initialized.
* @see #getAction
*/
public Action[] getActions() {
if (actionMap == null) {
return null;
}
Set keySet = actionMap.keySet();
int size = keySet.size();
Action[] array = new Action[size];
int j = 0;
for (Iterator i = keySet.iterator(); i.hasNext(); ) {
array[j++] = (Action) actionMap.get( (String) i.next());
}
// Sanity check.
if (j != size) {
throw new InternalError("Error in getActions!");
}
return array;
}
/*****************************************************************************/
/**
* This method is overridden to throw an exception; you should be adding
* components via this class's <code>add</code> methods.
*
* @return Nothing, an exception is thrown.
* @throws UnsupportedOperationException always.
* @see #setContentPane
*/
public Container getContentPane() {
//throw new UnsupportedOperationException("Use the add() methods!");
return actualContentPane;
}
/*****************************************************************************/
/**
* Returns the Help dialog for this application, or <code>null</code>
* if this application does not have a Help dialog.
*
* @return The Help dialog.
*/
public abstract HelpDialog getHelpDialog();
/*****************************************************************************/
/**
* Returns the directory in which this GUI application is installed (i.e.,
* the location if the JAR file containing the main method).
*
* @return The directory.
*/
public String getInstallLocation() {
return installLocation;
}
/*****************************************************************************/
/**
* Returns the language used by this GUI application, in a
* <code>Locale</code>-friendly language string; e.g., <code>en</code>
* or <code>es</code>.
*
* @return The language being used by this application.
*/
public String getLanguage() {
return language;
}
/*****************************************************************************/
/**
* Returns an array of info. for JAR files containing 3rd party Look and
* Feels. These JAR files will be added to the <code>UIManager</code>'s
* classpath so that these LnFs can be used in this GUI application.<p>
*
* Your application should override this method if you want to provide the
* user with 3rd party Look and Feel choices, especially if you want them
* to be able to update the Look and Feel on the fly. The default
* implementation returns <code>null</code>, meaning there are no 3rd party
* Look and Feels.
*
* @return An array of information on JAR files containing Look and Feels.
*/
protected ExtendedLookAndFeelInfo[] get3rdPartyLookAndFeelInfo() {
return null;
}
/*****************************************************************************/
/**
* Returns an integer constant representing the OS. This can be handy for
* special case situations such as Mac OS-X (special application
* registration) or Windows (allow mixed case, etc.).
*
* @return An integer constant representing the OS.
*/
public int getOS() {
if (os == 0) {
String osName = System.getProperty("os.name").toLowerCase();
if (osName == null) {
os = OS_OTHER;
}
else if (osName.indexOf("windows") > -1) {
os = OS_WINDOWS;
}
else if (osName.indexOf("mac os x") > -1) {
os = OS_MAC_OSX;
}
else if (osName.indexOf("linux") > -1) {
os = OS_LINUX;
}
else {
os = OS_OTHER;
}
}
return os;
}
/*****************************************************************************/
/**
* Returns the name of the preferences class for this application. This
* class must be a subclass of <code>GUIApplicationPreferences</code>.
*
* @return The class name, or <code>null</code> if this GUI application
* does not save preferences.
*/
protected abstract String getPreferencesClassName();
/*****************************************************************************/
/**
* Returns the resource bundle associated with this application.
*
* @return The resource bundle.
*/
public ResourceBundle getResourceBundle() {
if (resourceBundle == null) {
resourceBundle = ResourceBundle.getBundle(
getResourceBundleClassName());
// Locale currentLocale=new Locale("zh","CN");
// resourceBundle=ResourceBundle.getBundle("",currentLocale);
}
return resourceBundle;
}
/*****************************************************************************/
/**
* Returns the fully-qualified class name of the resource bundle for this
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -