/*
* Copyright (c) 2003 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.35 03/01/23
*/
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.border.*;
import javax.swing.colorchooser.*;
import javax.swing.filechooser.*;
import javax.accessibility.*;
import javax.swing.plaf.metal.DefaultMetalTheme;
import javax.swing.plaf.metal.MetalLookAndFeel;
import java.lang.reflect.*;
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.util.*;
import java.io.*;
import java.applet.*;
import java.net.*;
/**
* A demo that shows all of the Swing components.
*
* @version 1.35 01/23/03
* @author Jeff Dinkins
*/
public class SwingSet2 extends JPanel {
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++;
}
}
// 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 JMenuBar menuBar = null;
private JMenu lafMenu = null;
private JMenu themesMenu = null;
private JMenu audioMenu = null;
private JMenu 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) {
// 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 ******************
// *****