
com.globalmentor.swing.AbstractFramedSwingApplication Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of globalmentor-swing Show documentation
Show all versions of globalmentor-swing Show documentation
GlobalMentor Java Swing library.
The newest version!
/*
* Copyright © 1996-2009 GlobalMentor, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.globalmentor.swing;
import java.awt.Component;
import java.awt.Frame;
import java.net.URI;
/**
* A Swing application uses one main application frame.
* @author Garret Wilson
*/
public abstract class AbstractFramedSwingApplication extends AbstractSwingApplication {
/**
* The main application frame, or null
if the application frame has not yet been created.
*/
private Frame applicationFrame;
/**
* @return The main application frame, or null
if the application frame has not yet been created.
*/
public Frame getApplicationFrame() {
return applicationFrame;
}
/**
* Sets the main application frame.
* @param frame The main frame for the application.
*/
protected void setApplicationFrame(final Frame frame) {
applicationFrame = frame;
}
/**
* URI constructor.
* @param uri The URI identifying the application.
* @param name The name of the application.
*/
public AbstractFramedSwingApplication(final URI uri, final String name) {
this(uri, name, NO_ARGUMENTS); //construct the class with no arguments
}
/**
* URI and arguments constructor.
* @param uri The URI identifying the application.
* @param name The name of the application.
* @param args The command line arguments.
*/
public AbstractFramedSwingApplication(final URI uri, final String name, final String[] args) {
super(uri, name, args); //construct the parent class
applicationFrame = null; //show that we do not yet have an application frame
}
/**
* The main application method. This version creates the main application frame and displays it.
* @return The application status.
* @see #createApplicationFrame()
*/
public int main() {
final Frame applicationFrame = createApplicationFrame(); //create the application frame
setApplicationFrame(applicationFrame); //set the application frame
applicationFrame.setVisible(true); //show the frame
return 0;
}
/**
* Creates the main frame for the application.
* @return The main application frame
*/
protected abstract Frame createApplicationFrame();
/**
* Displays an error message to the user for a throwable object. This version uses the application frame if no parent component is given.
* @param parentComponent The Frame
in which the dialog is displayed, or null
if a parent Frame
, if any, of the
* parentComponent
should be used.
* @param title The error message dialog title, or null
for the default application throwable error title.
* @param throwable The condition that caused the error.
* @see #getApplicationFrame()
*/
public void displayError(final Component parentComponent, final String title, final Throwable throwable) {
//use the application frame if a parent component was not given
super.displayError(parentComponent != null ? parentComponent : getApplicationFrame(), title, throwable);
}
/**
* Displays an error message to the user.
*
* This version uses the default error display method.
*
* @param parentComponent The Frame
in which the dialog is displayed, or null
if a parent Frame
, if any, of the
* parentComponent
should be used.
* @param title The error message dialog title, or null
for the default application error title.
* @param message The error to display.
* @see #getApplicationFrame()
*/
public void displayError(final Component parentComponent, final String title, final String message) {
//use the application frame if a parent component was not given
super.displayError(parentComponent != null ? parentComponent : getApplicationFrame(), title, message);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy