⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 swingset2.java~5~

📁 主要为一个空间信息管理系统
💻 JAVA~5~
📖 第 1 页 / 共 3 页
字号:
/* * 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 */package com.sunking.swing;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 ******************    // *******************************************************    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")	);    }    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 JMenuBar createMenus() {	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);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -