Methods Summary |
---|
public DemoModule | addDemo(DemoModule demo)Add a demo to the toolbar
demosVector.addElement(demo);
// do the following on the gui thread
SwingUtilities.invokeLater(new SwingSetRunnable(this, demo) {
public void run() {
SwitchToDemoAction action = new SwitchToDemoAction(swingset, (DemoModule) obj);
JToggleButton tb = swingset.getToolBar().addToggleButton(action);
swingset.getToolBarGroup().add(tb);
if(swingset.getToolBarGroup().getSelection() == null) {
tb.setSelected(true);
}
tb.setText(null);
tb.setToolTipText(((DemoModule)obj).getToolTip());
if(demos[demos.length-1].equals(obj.getClass().getName())) {
setStatus(getString("Status.popupMenuAccessible"));
}
}
});
return demo;
|
public javax.swing.JMenuItem | createAudioMenuItem(javax.swing.JMenu menu, java.lang.String label, java.lang.String mnemonic, java.lang.String accessibleDescription, javax.swing.Action action)Create the theme's audio submenu
JRadioButtonMenuItem mi = (JRadioButtonMenuItem) menu.add(new JRadioButtonMenuItem(getString(label)));
audioMenuGroup.add(mi);
mi.setMnemonic(getMnemonic(mnemonic));
mi.getAccessibleContext().setAccessibleDescription(getString(accessibleDescription));
mi.addActionListener(action);
return mi;
|
public static javax.swing.JFrame | createFrame(java.awt.GraphicsConfiguration gc)Create a frame for SwingSet2 to reside in if brought up
as an application.
JFrame frame = new JFrame(gc);
if (numSSs == 0) {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} else {
WindowListener l = new WindowAdapter() {
public void windowClosing(WindowEvent e) {
numSSs--;
swingSets.remove(this);
}
};
frame.addWindowListener(l);
}
return frame;
|
public javax.swing.ImageIcon | createImageIcon(java.lang.String filename, java.lang.String description)Creates an icon from an image contained in the "images" directory.
String path = "/resources/images/" + filename;
return new ImageIcon(getClass().getResource(path));
|
public javax.swing.JMenuItem | createLafMenuItem(javax.swing.JMenu menu, java.lang.String label, java.lang.String mnemonic, java.lang.String accessibleDescription, java.lang.String laf)Creates a JRadioButtonMenuItem for the Look and Feel menu
JMenuItem mi = (JRadioButtonMenuItem) menu.add(new JRadioButtonMenuItem(getString(label)));
lafMenuGroup.add(mi);
mi.setMnemonic(getMnemonic(mnemonic));
mi.getAccessibleContext().setAccessibleDescription(getString(accessibleDescription));
mi.addActionListener(new ChangeLookAndFeelAction(this, laf));
mi.setEnabled(isAvailableLookAndFeel(laf));
return mi;
|
public javax.swing.JMenuItem | createMenuItem(javax.swing.JMenu menu, java.lang.String label, java.lang.String mnemonic, java.lang.String accessibleDescription, javax.swing.Action action)Creates a generic menu item
JMenuItem mi = (JMenuItem) menu.add(new JMenuItem(getString(label)));
mi.setMnemonic(getMnemonic(mnemonic));
mi.getAccessibleContext().setAccessibleDescription(getString(accessibleDescription));
mi.addActionListener(action);
if(action == null) {
mi.setEnabled(false);
}
return mi;
|
public javax.swing.JMenuBar | createMenus()Create menus
JMenuItem mi;
// ***** create the menubar ****
JMenuBar menuBar = new JMenuBar();
menuBar.getAccessibleContext().setAccessibleName(
getString("MenuBar.accessible_description"));
// ***** create File menu
JMenu fileMenu = (JMenu) menuBar.add(new JMenu(getString("FileMenu.file_label")));
fileMenu.setMnemonic(getMnemonic("FileMenu.file_mnemonic"));
fileMenu.getAccessibleContext().setAccessibleDescription(getString("FileMenu.accessible_description"));
createMenuItem(fileMenu, "FileMenu.about_label", "FileMenu.about_mnemonic",
"FileMenu.about_accessible_description", new AboutAction(this));
fileMenu.addSeparator();
createMenuItem(fileMenu, "FileMenu.open_label", "FileMenu.open_mnemonic",
"FileMenu.open_accessible_description", null);
createMenuItem(fileMenu, "FileMenu.save_label", "FileMenu.save_mnemonic",
"FileMenu.save_accessible_description", null);
createMenuItem(fileMenu, "FileMenu.save_as_label", "FileMenu.save_as_mnemonic",
"FileMenu.save_as_accessible_description", null);
if(!isApplet()) {
fileMenu.addSeparator();
createMenuItem(fileMenu, "FileMenu.exit_label", "FileMenu.exit_mnemonic",
"FileMenu.exit_accessible_description", new ExitAction(this)
);
}
// Create these menu items for the first SwingSet only.
if (numSSs == 0) {
// ***** create laf switcher menu
lafMenu = (JMenu) menuBar.add(new JMenu(getString("LafMenu.laf_label")));
lafMenu.setMnemonic(getMnemonic("LafMenu.laf_mnemonic"));
lafMenu.getAccessibleContext().setAccessibleDescription(
getString("LafMenu.laf_accessible_description"));
mi = createLafMenuItem(lafMenu, "LafMenu.java_label", "LafMenu.java_mnemonic",
"LafMenu.java_accessible_description", metal);
mi.setSelected(true); // this is the default l&f
createLafMenuItem(lafMenu, "LafMenu.mac_label", "LafMenu.mac_mnemonic",
"LafMenu.mac_accessible_description", mac);
createLafMenuItem(lafMenu, "LafMenu.motif_label", "LafMenu.motif_mnemonic",
"LafMenu.motif_accessible_description", motif);
createLafMenuItem(lafMenu, "LafMenu.windows_label", "LafMenu.windows_mnemonic",
"LafMenu.windows_accessible_description", windows);
createLafMenuItem(lafMenu, "LafMenu.gtk_label", "LafMenu.gtk_mnemonic",
"LafMenu.gtk_accessible_description", gtk);
// ***** create themes menu
themesMenu = (JMenu) menuBar.add(new JMenu(getString("ThemesMenu.themes_label")));
themesMenu.setMnemonic(getMnemonic("ThemesMenu.themes_mnemonic"));
themesMenu.getAccessibleContext().setAccessibleDescription(
getString("ThemesMenu.themes_accessible_description"));
// ***** create the audio submenu under the theme menu
audioMenu = (JMenu) themesMenu.add(new JMenu(getString("AudioMenu.audio_label")));
audioMenu.setMnemonic(getMnemonic("AudioMenu.audio_mnemonic"));
audioMenu.getAccessibleContext().setAccessibleDescription(
getString("AudioMenu.audio_accessible_description"));
createAudioMenuItem(audioMenu, "AudioMenu.on_label",
"AudioMenu.on_mnemonic",
"AudioMenu.on_accessible_description",
new OnAudioAction(this));
mi = createAudioMenuItem(audioMenu, "AudioMenu.default_label",
"AudioMenu.default_mnemonic",
"AudioMenu.default_accessible_description",
new DefaultAudioAction(this));
mi.setSelected(true); // This is the default feedback setting
createAudioMenuItem(audioMenu, "AudioMenu.off_label",
"AudioMenu.off_mnemonic",
"AudioMenu.off_accessible_description",
new OffAudioAction(this));
// *** now back to adding color/font themes to the theme menu
mi = createThemesMenuItem(themesMenu, "ThemesMenu.default_label", "ThemesMenu.default_mnemonic",
"ThemesMenu.default_accessible_description", new DefaultMetalTheme());
mi.setSelected(true); // This is the default theme
createThemesMenuItem(themesMenu, "ThemesMenu.aqua_label", "ThemesMenu.aqua_mnemonic",
"ThemesMenu.aqua_accessible_description", new AquaTheme());
createThemesMenuItem(themesMenu, "ThemesMenu.charcoal_label", "ThemesMenu.charcoal_mnemonic",
"ThemesMenu.charcoal_accessible_description", new CharcoalTheme());
createThemesMenuItem(themesMenu, "ThemesMenu.contrast_label", "ThemesMenu.contrast_mnemonic",
"ThemesMenu.contrast_accessible_description", new ContrastTheme());
createThemesMenuItem(themesMenu, "ThemesMenu.emerald_label", "ThemesMenu.emerald_mnemonic",
"ThemesMenu.emerald_accessible_description", new EmeraldTheme());
createThemesMenuItem(themesMenu, "ThemesMenu.ruby_label", "ThemesMenu.ruby_mnemonic",
"ThemesMenu.ruby_accessible_description", new RubyTheme());
// ***** create the tooltip menu.
toolTipMenu = (JMenu) menuBar.add(new JMenu(
getString("ToolTipMenu.tooltip_label")));
toolTipMenu.setMnemonic(getMnemonic("ToolTipMenu.tooltip_mnemonic"));
toolTipMenu.getAccessibleContext().setAccessibleDescription(
getString("ToolTipMenu.tooltip_accessible_description"));
// ***** create tool tip submenu items.
mi = createToolTipMenuItem(toolTipMenu, "ToolTipMenu.on_label",
"ToolTipMenu.on_mnemonic",
"ToolTipMenu.on_accessible_description",
new ToolTipAction(this, true));
mi.setSelected(true);
createToolTipMenuItem(toolTipMenu, "ToolTipMenu.off_label",
"ToolTipMenu.off_mnemonic",
"ToolTipMenu.off_accessible_description",
new ToolTipAction(this, false));
}
// ***** create the multiscreen menu, if we have multiple screens
if (!isApplet()) {
GraphicsDevice[] screens = GraphicsEnvironment.
getLocalGraphicsEnvironment().
getScreenDevices();
if (screens.length > 1) {
JMenu multiScreenMenu = (JMenu) menuBar.add(new JMenu(
getString("MultiMenu.multi_label")));
multiScreenMenu.setMnemonic(getMnemonic("MultiMenu.multi_mnemonic"));
multiScreenMenu.getAccessibleContext().setAccessibleDescription(
getString("MultiMenu.multi_accessible_description"));
createMultiscreenMenuItem(multiScreenMenu, MultiScreenAction.ALL_SCREENS);
for (int i = 0; i < screens.length; i++) {
createMultiscreenMenuItem(multiScreenMenu, i);
}
}
}
return menuBar;
|
public javax.swing.JMenuItem | createMultiscreenMenuItem(javax.swing.JMenu menu, int screen)Creates a multi-screen menu item
JMenuItem mi = null;
if (screen == MultiScreenAction.ALL_SCREENS) {
mi = (JMenuItem) menu.add(new JMenuItem(getString("MultiMenu.all_label")));
mi.setMnemonic(getMnemonic("MultiMenu.all_mnemonic"));
mi.getAccessibleContext().setAccessibleDescription(getString(
"MultiMenu.all_accessible_description"));
}
else {
mi = (JMenuItem) menu.add(new JMenuItem(getString("MultiMenu.single_label") + " " +
screen));
mi.setMnemonic(KeyEvent.VK_0 + screen);
mi.getAccessibleContext().setAccessibleDescription(getString(
"MultiMenu.single_accessible_description") + " " + screen);
}
mi.addActionListener(new MultiScreenAction(this, screen));
return mi;
|
public javax.swing.JPopupMenu | createPopupMenu()
JPopupMenu popup = new JPopupMenu("JPopupMenu demo");
createPopupMenuItem(popup, "LafMenu.java_label", "LafMenu.java_mnemonic",
"LafMenu.java_accessible_description", metal);
createPopupMenuItem(popup, "LafMenu.mac_label", "LafMenu.mac_mnemonic",
"LafMenu.mac_accessible_description", mac);
createPopupMenuItem(popup, "LafMenu.motif_label", "LafMenu.motif_mnemonic",
"LafMenu.motif_accessible_description", motif);
createPopupMenuItem(popup, "LafMenu.windows_label", "LafMenu.windows_mnemonic",
"LafMenu.windows_accessible_description", windows);
createPopupMenuItem(popup, "LafMenu.gtk_label", "LafMenu.gtk_mnemonic",
"LafMenu.gtk_accessible_description", gtk);
// register key binding to activate popup menu
InputMap map = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
map.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, InputEvent.CTRL_MASK),
"postMenuAction");
getActionMap().put("postMenuAction", new ActivatePopupMenuAction(this, popup));
return popup;
|
public javax.swing.JMenuItem | createPopupMenuItem(javax.swing.JPopupMenu menu, java.lang.String label, java.lang.String mnemonic, java.lang.String accessibleDescription, java.lang.String laf)Creates a JMenuItem for the Look and Feel popup menu
JMenuItem mi = menu.add(new JMenuItem(getString(label)));
popupMenuGroup.add(mi);
mi.setMnemonic(getMnemonic(mnemonic));
mi.getAccessibleContext().setAccessibleDescription(getString(accessibleDescription));
mi.addActionListener(new ChangeLookAndFeelAction(this, laf));
mi.setEnabled(isAvailableLookAndFeel(laf));
return mi;
|
public void | createSplashScreen()Show the spash screen while the rest of the demo loads
splashLabel = new JLabel(createImageIcon("Splash.jpg", "Splash.accessible_description"));
if(!isApplet()) {
splashScreen = new JWindow(getFrame());
splashScreen.getContentPane().add(splashLabel);
splashScreen.pack();
Rectangle screenRect = getFrame().getGraphicsConfiguration().getBounds();
splashScreen.setLocation(
screenRect.x + screenRect.width/2 - splashScreen.getSize().width/2,
screenRect.y + screenRect.height/2 - splashScreen.getSize().height/2);
}
|
public javax.swing.JMenuItem | createThemesMenuItem(javax.swing.JMenu menu, java.lang.String label, java.lang.String mnemonic, java.lang.String accessibleDescription, javax.swing.plaf.metal.DefaultMetalTheme theme)Creates a JRadioButtonMenuItem for the Themes menu
JRadioButtonMenuItem mi = (JRadioButtonMenuItem) menu.add(new JRadioButtonMenuItem(getString(label)));
themesMenuGroup.add(mi);
mi.setMnemonic(getMnemonic(mnemonic));
mi.getAccessibleContext().setAccessibleDescription(getString(accessibleDescription));
mi.addActionListener(new ChangeThemeAction(this, theme));
return mi;
|
public javax.swing.JMenuItem | createToolTipMenuItem(javax.swing.JMenu menu, java.lang.String label, java.lang.String mnemonic, java.lang.String accessibleDescription, javax.swing.Action action)Create the tool tip submenu
JRadioButtonMenuItem mi = (JRadioButtonMenuItem)menu.add(
new JRadioButtonMenuItem(getString(label)));
toolTipMenuGroup.add(mi);
mi.setMnemonic(getMnemonic(mnemonic));
mi.getAccessibleContext().setAccessibleDescription(getString(
accessibleDescription));
mi.addActionListener(action);
return mi;
|
public void | debug(java.lang.String s)If DEBUG is defined, prints debug information out to std ouput.
if(DEBUG) {
System.out.println((debugCounter++) + ": " + s);
}
|
public SwingSet2Applet | getApplet()Returns the applet instance
return applet;
|
public java.awt.Container | getContentPane()Returns the content pane wether we're in an applet
or application
if(contentPane == null) {
if(getFrame() != null) {
contentPane = getFrame().getContentPane();
} else if (getApplet() != null) {
contentPane = getApplet().getContentPane();
}
}
return contentPane;
|
public javax.swing.JFrame | getFrame()Returns the frame instance
return frame;
|
public javax.swing.JMenuBar | getMenuBar()Returns the menubar
return menuBar;
|
public char | getMnemonic(java.lang.String key)Returns a mnemonic from the resource bundle. Typically used as
keyboard shortcuts in menu items.
return (getString(key)).charAt(0);
|
public java.util.ResourceBundle | getResourceBundle()Returns the resource bundle associated with this demo. Used
to get accessable and internationalized strings.
if(bundle == null) {
bundle = ResourceBundle.getBundle("resources.swingset");
}
return bundle;
|
public java.lang.String | getString(java.lang.String key)This method returns a string from the demo's resource bundle.
String value = null;
try {
value = getResourceBundle().getString(key);
} catch (MissingResourceException e) {
System.out.println("java.util.MissingResourceException: Couldn't find value for: " + key);
}
if(value == null) {
value = "Could not find resource: " + key + " ";
}
return value;
|
public SwingSet2$ToggleButtonToolBar | getToolBar()Returns the toolbar
return toolbar;
|
public javax.swing.ButtonGroup | getToolBarGroup()Returns the toolbar button group
return toolbarGroup;
|
public void | hideSplash()pop down the spash screen
if(!isApplet()) {
splashScreen.setVisible(false);
splashScreen = null;
splashLabel = null;
}
|
public void | initializeDemo()
JPanel top = new JPanel();
top.setLayout(new BorderLayout());
add(top, BorderLayout.NORTH);
menuBar = createMenus();
top.add(menuBar, BorderLayout.NORTH);
// creates popup menu accessible via keyboard
popupMenu = createPopupMenu();
ToolBarPanel toolbarPanel = new ToolBarPanel();
toolbarPanel.setLayout(new BorderLayout());
toolbar = new ToggleButtonToolBar();
toolbarPanel.add(toolbar, BorderLayout.CENTER);
top.add(toolbarPanel, BorderLayout.SOUTH);
toolbarPanel.addContainerListener(toolbarPanel);
tabbedPane = new JTabbedPane();
add(tabbedPane, BorderLayout.CENTER);
tabbedPane.getModel().addChangeListener(new TabListener());
statusField = new JTextField("");
statusField.setEditable(false);
add(statusField, BorderLayout.SOUTH);
demoPanel = new JPanel();
demoPanel.setLayout(new BorderLayout());
demoPanel.setBorder(new EtchedBorder());
tabbedPane.addTab("Hi There!", demoPanel);
// Add html src code viewer
demoSrcPane = new JEditorPane("text/html", getString("SourceCode.loading"));
demoSrcPane.setEditable(false);
JScrollPane scroller = new JScrollPane();
scroller.getViewport().add(demoSrcPane);
tabbedPane.addTab(
getString("TabbedPane.src_label"),
null,
scroller,
getString("TabbedPane.src_tooltip")
);
|
public boolean | isApplet()Determines if this is an applet or application
return (applet != null);
|
protected boolean | isAvailableLookAndFeel(java.lang.String laf)A utility function that layers on top of the LookAndFeel's
isSupportedLookAndFeel() method. Returns true if the LookAndFeel
is supported. Returns false if the LookAndFeel is not supported
and/or if there is any kind of error checking if the LookAndFeel
is supported.
The L&F menu will use this method to detemine whether the various
L&F options should be active or inactive.
try {
Class lnfClass = Class.forName(laf);
LookAndFeel newLAF = (LookAndFeel)(lnfClass.newInstance());
return newLAF.isSupportedLookAndFeel();
} catch(Exception e) { // If ANYTHING weird happens, return false
return false;
}
|
void | loadDemo(java.lang.String classname)Loads a demo from a classname
setStatus(getString("Status.loading") + getString(classname + ".name"));
DemoModule demo = null;
try {
Class demoClass = Class.forName(classname);
Constructor demoConstructor = demoClass.getConstructor(new Class[]{SwingSet2.class});
demo = (DemoModule) demoConstructor.newInstance(new Object[]{this});
addDemo(demo);
} catch (Exception e) {
System.out.println("Error occurred loading demo: " + classname);
}
|
void | loadDemos()
for(int i = 0; i < demos.length;) {
if(isApplet() && demos[i].equals("FileChooserDemo")) {
// don't load the file chooser demo if we are
// an applet
} else {
loadDemo(demos[i]);
}
i++;
}
|
public static void | main(java.lang.String[] args)SwingSet2 Main. Called only if we're an application, not an applet.
// Create SwingSet on the default monitor
SwingSet2 swingset = new SwingSet2(null, GraphicsEnvironment.
getLocalGraphicsEnvironment().
getDefaultScreenDevice().
getDefaultConfiguration());
|
public void | preloadFirstDemo()Load the first demo. This is done separately from the remaining demos
so that we can get SwingSet2 up and available to the user quickly.
DemoModule demo = addDemo(new InternalFrameDemo(this));
setDemo(demo);
|
public void | setDemo(DemoModule demo)Sets the current demo
currentDemo = demo;
// Ensure panel's UI is current before making visible
JComponent currentDemoPanel = demo.getDemoPanel();
SwingUtilities.updateComponentTreeUI(currentDemoPanel);
demoPanel.removeAll();
demoPanel.add(currentDemoPanel, BorderLayout.CENTER);
tabbedPane.setSelectedIndex(0);
tabbedPane.setTitleAt(0, demo.getName());
tabbedPane.setToolTipTextAt(0, demo.getToolTip());
|
public void | setLookAndFeel(java.lang.String laf)Stores the current L&F, and calls updateLookAndFeel, below
if(currentLookAndFeel != laf) {
currentLookAndFeel = laf;
themesMenu.setEnabled(laf == metal);
updateLookAndFeel();
}
|
public void | setSourceCode(DemoModule demo)Loads and puts the source code text into JEditorPane in the "Source Code" tab
// do the following on the gui thread
SwingUtilities.invokeLater(new SwingSetRunnable(this, demo) {
public void run() {
swingset.demoSrcPane.setText(((DemoModule)obj).getSourceCode());
swingset.demoSrcPane.setCaretPosition(0);
}
});
|
public void | setStatus(java.lang.String s)Set the status
// do the following on the gui thread
SwingUtilities.invokeLater(new SwingSetRunnable(this, s) {
public void run() {
swingset.statusField.setText((String) obj);
}
});
|
public void | showSplashScreen()
if(!isApplet()) {
splashScreen.show();
} else {
add(splashLabel, BorderLayout.CENTER);
validate();
repaint();
}
|
public void | showSwingSet2()Bring up the SwingSet2 demo by showing the frame (only
applicable if coming up as an application, not an applet);
if(!isApplet() && getFrame() != null) {
// put swingset in a frame and show it
JFrame f = getFrame();
f.setTitle(getString("Frame.title"));
f.getContentPane().add(this, BorderLayout.CENTER);
f.pack();
Rectangle screenRect = f.getGraphicsConfiguration().getBounds();
Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(
f.getGraphicsConfiguration());
// Make sure we don't place the demo off the screen.
int centerWidth = screenRect.width < f.getSize().width ?
screenRect.x :
screenRect.x + screenRect.width/2 - f.getSize().width/2;
int centerHeight = screenRect.height < f.getSize().height ?
screenRect.y :
screenRect.y + screenRect.height/2 - f.getSize().height/2;
centerHeight = centerHeight < screenInsets.top ?
screenInsets.top : centerHeight;
f.setLocation(centerWidth, centerHeight);
f.show();
numSSs++;
swingSets.add(this);
}
|
public void | updateLookAndFeel()Sets the current L&F on each demo module
try {
UIManager.setLookAndFeel(currentLookAndFeel);
for (Iterator itr = swingSets.iterator(); itr.hasNext(); ) {
SwingSet2 ss = (SwingSet2)itr.next();
SwingUtilities.updateComponentTreeUI(ss);
}
// update LAF for the toplevel frame, too
if (!isApplet()) {
SwingUtilities.updateComponentTreeUI(getFrame());
} else {
SwingUtilities.updateComponentTreeUI(getApplet());
}
SwingUtilities.updateComponentTreeUI(popupMenu);
} catch (Exception ex) {
System.out.println("Failed loading L&F: " + currentLookAndFeel);
System.out.println(ex);
}
// lazily update update the UI's for the remaining demos
for (int i = 0; i < demosVector.size(); i++) {
DemoModule demo = (DemoModule) demosVector.elementAt(i);
if(currentDemo != demo) {
// do the following on the gui thread
SwingUtilities.invokeLater(new SwingSetRunnable(this, demo) {
public void run() {
SwingUtilities.updateComponentTreeUI(((DemoModule)obj).getDemoPanel());
}
});
}
}
|