/*
* Copyright (c) 2004 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* -Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* -Redistribution in binary form must reproduct the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the distribution.
*
* Neither the name of Sun Microsystems, Inc. or the names of contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
* OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT
* BE LIABLE FOR ANY DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT
* OF OR RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN
* IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that Software is not designed, licensed or intended for
* use in the design, construction, operation or maintenance of any nuclear
* facility.
*/
/*
* @(#)SwingSet2.java 1.42 03/12/19
*/
import com.jidesoft.action.*;
import com.jidesoft.plaf.LookAndFeelFactory;
import com.jidesoft.swing.ContentContainer;
import com.jidesoft.swing.JideMenu;
import com.jidesoft.swing.JideToggleButton;
import com.jidesoft.utils.Lm;
import javax.swing.*;
import javax.swing.border.EtchedBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.plaf.metal.MetalLookAndFeel;
import javax.swing.plaf.metal.MetalTheme;
import java.awt.*;
import java.awt.event.*;
import java.lang.reflect.Constructor;
import java.util.Iterator;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.Vector;
/**
* A demo that shows all of the Swing components.
*
* @author Jeff Dinkins
* @version 1.42 12/19/03
*/
public class SwingSet2 extends ContentContainer implements DockableBarHolder {
String[] demos = {
"ButtonDemo",
"ColorChooserDemo",
"ComboBoxDemo",
"FileChooserDemo",
"HtmlDemo",
"ListDemo",
"OptionPaneDemo",
"ProgressBarDemo",
"ScrollPaneDemo",
"SliderDemo",
"SplitPaneDemo",
"TabbedPaneDemo",
"TableDemo",
"ToolTipDemo",
"TreeDemo"
};
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++;
}
Lm.setParent((JFrame) this.getTopLevelAncestor());
Lm.showPopupMessageBox("Please note: " +
"
This is a modified version of SwingSet2 demo coming along with any JDK release. " +
"
It is meant to show how to migrate from existing applicatoin to use JIDE Action Framework. " +
"
For more details, please refer to JIDE Action Framework Developer Guide - Migrating from Existing Application.");
}
// Possible Look & Feels
private static final String mac =
"com.sun.java.swing.plaf.mac.MacLookAndFeel";
private static final String metal =
"javax.swing.plaf.metal.MetalLookAndFeel";
private static final String motif =
"com.sun.java.swing.plaf.motif.MotifLookAndFeel";
private static final String windows =
"com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
private static final String gtk =
"com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
// The current Look & Feel
private static String currentLookAndFeel = metal;
// List of demos
private Vector demosVector = new Vector();
// The preferred size of the demo
private static final int PREFERRED_WIDTH = 720;
private static final int PREFERRED_HEIGHT = 640;
// Box spacers
private Dimension HGAP = new Dimension(1, 5);
private Dimension VGAP = new Dimension(5, 1);
// Resource bundle for internationalized and accessible text
private ResourceBundle bundle = null;
// A place to hold on to the visible demo
private DemoModule currentDemo = null;
private JPanel demoPanel = null;
// About Box
private JDialog aboutBox = null;
// Status Bar
private JTextField statusField = null;
// Tool Bar
private ToggleButtonToolBar toolbar = null;
private ButtonGroup toolbarGroup = new ButtonGroup();
// Menus
private CommandBar menuBar = null;
private JideMenu lafMenu = null;
private JideMenu themesMenu = null;
private JideMenu audioMenu = null;
private JideMenu toolTipMenu = null;
private ButtonGroup lafMenuGroup = new ButtonGroup();
private ButtonGroup themesMenuGroup = new ButtonGroup();
private ButtonGroup audioMenuGroup = new ButtonGroup();
private ButtonGroup toolTipMenuGroup = new ButtonGroup();
// Popup menu
private JPopupMenu popupMenu = null;
private ButtonGroup popupMenuGroup = new ButtonGroup();
// Used only if swingset is an application
private JFrame frame = null;
private JWindow splashScreen = null;
// Used only if swingset is an applet
private SwingSet2Applet applet = null;
// To debug or not to debug, that is the question
private boolean DEBUG = true;
private int debugCounter = 0;
// The tab pane that holds the demo
private JTabbedPane tabbedPane = null;
private JEditorPane demoSrcPane = null;
private JLabel splashLabel = null;
// contentPane cache, saved from the applet or application frame
Container contentPane = null;
// number of swingsets - for multiscreen
// keep track of the number of SwingSets created - we only want to exit
// the program when the last one has been closed.
private static int numSSs = 0;
private static Vector swingSets = new Vector();
public SwingSet2(SwingSet2Applet applet) {
this(applet, null);
}
/**
* SwingSet2 Constructor
*/
public SwingSet2(SwingSet2Applet applet, GraphicsConfiguration gc) {
try {
UIManager.setLookAndFeel("com.jtattoo.plaf.acryl.AcrylLookAndFeel");
// UIManager.setLookAndFeel("com.jtattoo.plaf.hifi.HiFiLookAndFeel");
// UIManager.setLookAndFeel(WindowsLookAndFeel.class.getName());
}
catch (ClassNotFoundException e) {
}
catch (InstantiationException e) {
}
catch (IllegalAccessException e) {
}
catch (UnsupportedLookAndFeelException e) {
}
LookAndFeelFactory.installJideExtension(LookAndFeelFactory.OFFICE2003_STYLE);
// Note that the applet may null if this is started as an application
this.applet = applet;
// Create Frame here for app-mode so the splash screen can get the
// GraphicsConfiguration from it in createSplashScreen()
if (!isApplet()) {
frame = createFrame(gc);
}
// setLayout(new BorderLayout());
setLayout(new BorderLayout());
// set the preferred size of the demo
setPreferredSize(new Dimension(PREFERRED_WIDTH, PREFERRED_HEIGHT));
// Create and throw the splash screen up. Since this will
// physically throw bits on the screen, we need to do this
// on the GUI thread using invokeLater.
createSplashScreen();
// do the following on the gui thread
SwingUtilities.invokeLater(new Runnable() {
public void run() {
showSplashScreen();
}
});
initializeDemo();
preloadFirstDemo();
// Show the demo and take down the splash screen. Note that
// we again must do this on the GUI thread using invokeLater.
SwingUtilities.invokeLater(new Runnable() {
public void run() {
showSwingSet2();
hideSplash();
}
});
// Start loading the rest of the demo in the background
DemoLoadThread demoLoader = new DemoLoadThread(this);
demoLoader.start();
}
/**
* SwingSet2 Main. Called only if we're an application, not an applet.
*/
public static void main(String[] args) {
// Create SwingSet on the default monitor
SwingSet2 swingset = new SwingSet2(null, GraphicsEnvironment.
getLocalGraphicsEnvironment().
getDefaultScreenDevice().
getDefaultConfiguration());
}
// *******************************************************
// *************** Demo Loading Methods ******************
// *******************************************************
public void initializeDemo() {
menuBar = createMenus();
popupMenu = createPopupMenu();
toolbar = new ToggleButtonToolBar();
// DockableBarManager
_dockableBarManager = new DefaultDockableBarManager(frame, this);
_dockableBarManager.setProfileKey("swingset2");
_dockableBarManager.addDockableBar(menuBar);
_dockableBarManager.addDockableBar(toolbar);
_dockableBarManager.getMainContainer().setLayout(new BorderLayout());
tabbedPane = new JTabbedPane();
_dockableBarManager.getMainContainer().add(tabbedPane, BorderLayout.CENTER);
tabbedPane.getModel().addChangeListener(new TabListener());
statusField = new JTextField("");
statusField.setEditable(false);
// let's not add status field for now.
// 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"));
getDockableBarManager().loadLayoutData();
}
DemoModule currentTabDemo = null;
class TabListener implements ChangeListener {
public void stateChanged(ChangeEvent e) {
SingleSelectionModel model = (SingleSelectionModel) e.getSource();
boolean srcSelected = model.getSelectedIndex() == 1;
if (currentTabDemo != currentDemo && demoSrcPane != null && srcSelected) {
demoSrcPane.setText(getString("SourceCode.loading"));
repaint();
}
if (currentTabDemo != currentDemo && srcSelected) {
currentTabDemo = currentDemo;
setSourceCode(currentDemo);
}
}
}
/**
* Create menus
*/
public CommandBar createMenus() {
JMenuItem mi;
// ***** create the menubar ****
CommandBar menuBar = new CommandMenuBar("Menu Bar");
menuBar.setStretch(true);
menuBar.getAccessibleContext().setAccessibleName(getString("MenuBar.accessible_description"));
// ***** create File menu
JideMenu fileMenu = (JideMenu) menuBar.add(new JideMenu(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 = (JideMenu) menuBar.add(new JideMenu(getString("LafMenu.laf_label")));
lafMenu.setMnemonic(getMnemonic("LafMenu.laf_mnemonic"));
lafMenu.getAccessibleContext().setAccessibleDescription(getString("LafMenu.laf_accessible_description"));
createLafMenuItem(lafMenu, "LafMenu.java_label", "LafMenu.java_mnemonic",
"LafMenu.java_accessible_description", metal);
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);
UIManager.LookAndFeelInfo[] lafInfo = UIManager.
getInstalledLookAndFeels();
for (int counter = 0; counter < lafInfo.length; counter++) {
if (lafInfo[counter].getName().toLowerCase().indexOf("windows") != -1) {
mi = createLafMenuItem(lafMenu, "LafMenu.windows_label", "LafMenu.windows_mnemonic",
"LafMenu.windows_accessible_description", windows);
mi.setSelected(true); // this is the default l&f
}
}
for (int counter = 0; counter < lafInfo.length; counter++) {
if (lafInfo[counter].getName().toLowerCase().indexOf("gtk") != -1) {
createLafMenuItem(lafMenu, "LafMenu.gtk_label",
"LafMenu.gtk_mnemonic",
"LafMenu.gtk_accessible_description", gtk);
break;
}
}
// ***** create themes menu
themesMenu = (JideMenu) menuBar.add(new JideMenu(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 = (JideMenu) themesMenu.add(new JideMenu(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
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 = (JideMenu) menuBar.add(new JideMenu(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) {
JideMenu multiScreenMenu = (JideMenu) menuBar.add(new JideMenu(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;
}
/**
* Create the tool tip submenu
*/
public JMenuItem createToolTipMenuItem(JideMenu menu, String label,
String mnemonic,
String accessibleDescription,
Action action) {
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;
}
/**
* Create the theme's audio submenu
*/
public JMenuItem createAudioMenuItem(JideMenu menu, String label,
String mnemonic,
String accessibleDescription,
Action action) {
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;
}
/**
* Creates a generic menu item
*/
public JMenuItem createMenuItem(JideMenu menu, String label, String mnemonic,
String accessibleDescription, Action action) {
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;
}
/**
* Creates a JRadioButtonMenuItem for the Themes menu
*/
public JMenuItem createThemesMenuItem(JideMenu menu, String label, String mnemonic,
String accessibleDescription, MetalTheme theme) {
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;
}
/**
* Creates a JRadioButtonMenuItem for the Look and Feel menu
*/
public JMenuItem createLafMenuItem(JideMenu menu, String label, String mnemonic,
String accessibleDescription, String laf) {
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;
}
/**
* Creates a multi-screen menu item
*/
public JMenuItem createMultiscreenMenuItem(JideMenu menu, int screen) {
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 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_F10, InputEvent.SHIFT_MASK),
"postMenuAction");
getActionMap().put("postMenuAction", new ActivatePopupMenuAction(this, popup));
return popup;
}
/**
* Creates a JMenuItem for the Look and Feel popup menu
*/
public JMenuItem createPopupMenuItem(JPopupMenu menu, String label, String mnemonic,
String accessibleDescription, String laf) {
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;
}
/**
* 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.
*/
public void preloadFirstDemo() {
DemoModule demo = addDemo(new InternalFrameDemo(this));
setDemo(demo);
}
/**
* Add a demo to the toolbar
*/
public DemoModule addDemo(DemoModule demo) {
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);
JideToggleButton 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;
}
/**
* Sets the current demo
*/
public void setDemo(DemoModule 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());
}
/**
* Bring up the SwingSet2 demo by showing the frame (only applicable if coming up as an application, not an
* applet);
*/
public void showSwingSet2() {
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);
}
}
/**
* Show the spash screen while the rest of the demo loads
*/
public void createSplashScreen() {
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 void showSplashScreen() {
if (!isApplet()) {
splashScreen.show();
}
else {
add(splashLabel, BorderLayout.CENTER);
validate();
repaint();
}
}
/**
* pop down the spash screen
*/
public void hideSplash() {
if (!isApplet()) {
splashScreen.setVisible(false);
splashScreen = null;
splashLabel = null;
}
}
// *******************************************************
// ****************** Utility Methods ********************
// *******************************************************
/**
* Loads a demo from a classname
*/
void loadDemo(String 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);
}
}
/**
* 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.
*