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

📄 swingset2.java~2~

📁 主要为一个空间信息管理系统
💻 JAVA~2~
📖 第 1 页 / 共 3 页
字号:
    public String getString(String key) {	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;    }    /**     * Returns the resource bundle associated with this demo. Used     * to get accessable and internationalized strings.     */    public ResourceBundle getResourceBundle() {	if(bundle == null) {	    bundle = ResourceBundle.getBundle("resources.swingset");	}	return bundle;    }    /**     * Returns a mnemonic from the resource bundle. Typically used as     * keyboard shortcuts in menu items.     */    public char getMnemonic(String key) {	return (getString(key)).charAt(0);    }    /**     * Creates an icon from an image contained in the "images" directory.     */    public ImageIcon createImageIcon(String filename, String description) {	String path = "/resources/images/" + filename;	return new ImageIcon(getClass().getResource(path));    }    /**     * If DEBUG is defined, prints debug information out to std ouput.     */    public void debug(String s) {	if(DEBUG) {	    System.out.println((debugCounter++) + ": " + s);	}    }    /**     * Stores the current L&F, and calls updateLookAndFeel, below     */    public void setLookAndFeel(String laf) {	if(currentLookAndFeel != laf) {	    currentLookAndFeel = laf;	    themesMenu.setEnabled(laf == metal);	    updateLookAndFeel();	}    }    /**     * Sets the current L&F on each demo module     */    public void updateLookAndFeel() {	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());		    }		});	    }	}    }    /**     * Loads and puts the source code text into JEditorPane in the "Source Code" tab     */    public void setSourceCode(DemoModule demo) {	// 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);	    }	});    }    // *******************************************************    // **************   ToggleButtonToolbar  *****************    // *******************************************************    static Insets zeroInsets = new Insets(1,1,1,1);    protected class ToggleButtonToolBar extends JToolBar {	public ToggleButtonToolBar() {	    super();	}	JToggleButton addToggleButton(Action a) {	    JToggleButton tb = new JToggleButton(		(String)a.getValue(Action.NAME),		(Icon)a.getValue(Action.SMALL_ICON)	    );	    tb.setMargin(zeroInsets);	    tb.setText(null);	    tb.setEnabled(a.isEnabled());	    tb.setToolTipText((String)a.getValue(Action.SHORT_DESCRIPTION));	    tb.setAction(a);	    add(tb);	    return tb;	}    }    // *******************************************************    // *********  ToolBar Panel / Docking Listener ***********    // *******************************************************    class ToolBarPanel extends JPanel implements ContainerListener {	public boolean contains(int x, int y) {	    Component c = getParent();	    if (c != null) {		Rectangle r = c.getBounds();		return (x >= 0) && (x < r.width) && (y >= 0) && (y < r.height);	    }	    else {		return super.contains(x,y);	    }	}	public void componentAdded(ContainerEvent e) {	    Container c = e.getContainer().getParent();	    if (c != null) {		c.getParent().validate();		c.getParent().repaint();	    }	}	public void componentRemoved(ContainerEvent e) {	    Container c = e.getContainer().getParent();	    if (c != null) {		c.getParent().validate();		c.getParent().repaint();	    }	}    }    // *******************************************************    // ******************   Runnables  ***********************    // *******************************************************    /**     * Generic SwingSet2 runnable. This is intended to run on the     * AWT gui event thread so as not to muck things up by doing     * gui work off the gui thread. Accepts a SwingSet2 and an Object     * as arguments, which gives subtypes of this class the two     * "must haves" needed in most runnables for this demo.     */    class SwingSetRunnable implements Runnable {	protected SwingSet2 swingset;	protected Object obj;	public SwingSetRunnable(SwingSet2 swingset, Object obj) {	    this.swingset = swingset;	    this.obj = obj;	}	public void run() {	}    }    // *******************************************************    // ********************   Actions  ***********************    // *******************************************************    public class SwitchToDemoAction extends AbstractAction {	SwingSet2 swingset;	DemoModule demo;	public SwitchToDemoAction(SwingSet2 swingset, DemoModule demo) {	    super(demo.getName(), demo.getIcon());	    this.swingset = swingset;	    this.demo = demo;	}	public void actionPerformed(ActionEvent e) {	    swingset.setDemo(demo);	}    }    class OkAction extends AbstractAction {	JDialog aboutBox;        protected OkAction(JDialog aboutBox) {            super("OkAction");	    this.aboutBox = aboutBox;        }        public void actionPerformed(ActionEvent e) {	    aboutBox.setVisible(false);	}    }    class ChangeLookAndFeelAction extends AbstractAction {	SwingSet2 swingset;	String laf;        protected ChangeLookAndFeelAction(SwingSet2 swingset, String laf) {            super("ChangeTheme");	    this.swingset = swingset;	    this.laf = laf;        }        public void actionPerformed(ActionEvent e) {	    swingset.setLookAndFeel(laf);	}    }    class ActivatePopupMenuAction extends AbstractAction { 	SwingSet2 swingset; 	JPopupMenu popup;	protected ActivatePopupMenuAction(SwingSet2 swingset, JPopupMenu popup) {	    super("ActivatePopupMenu"); 	    this.swingset = swingset; 	    this.popup = popup;	} 	public void actionPerformed(ActionEvent e) { 	    Dimension invokerSize = getSize(); 	    Dimension popupSize = popup.getPreferredSize(); 	    popup.show(swingset, (invokerSize.width - popupSize.width) / 2, 		       (invokerSize.height - popupSize.height) / 2); 	}    }    // Turns on all possible auditory feedback    class OnAudioAction extends AbstractAction {	SwingSet2 swingset;        protected OnAudioAction(SwingSet2 swingset) {            super("Audio On");	    this.swingset = swingset;        }        public void actionPerformed(ActionEvent e) {	    UIManager.put("AuditoryCues.playList",			  UIManager.get("AuditoryCues.allAuditoryCues"));	    swingset.updateLookAndFeel();	}    }    // Turns on the default amount of auditory feedback    class DefaultAudioAction extends AbstractAction {	SwingSet2 swingset;        protected DefaultAudioAction(SwingSet2 swingset) {            super("Audio Default");	    this.swingset = swingset;        }        public void actionPerformed(ActionEvent e) {	    UIManager.put("AuditoryCues.playList",			  UIManager.get("AuditoryCues.defaultCueList"));	    swingset.updateLookAndFeel();	}    }    // Turns off all possible auditory feedback    class OffAudioAction extends AbstractAction {	SwingSet2 swingset;        protected OffAudioAction(SwingSet2 swingset) {            super("Audio Off");	    this.swingset = swingset;        }        public void actionPerformed(ActionEvent e) {	    UIManager.put("AuditoryCues.playList",			  UIManager.get("AuditoryCues.noAuditoryCues"));	    swingset.updateLookAndFeel();	}    }    // Turns on or off the tool tips for the demo.    class ToolTipAction extends AbstractAction {        SwingSet2 swingset;        boolean status;        protected ToolTipAction(SwingSet2 swingset, boolean status) {            super("ToolTip Control");            this.swingset = swingset;            this.status = status;        }        public void actionPerformed(ActionEvent e) {            ToolTipManager.sharedInstance().setEnabled(status);        }    }    class ChangeThemeAction extends AbstractAction {	SwingSet2 swingset;	DefaultMetalTheme theme;        protected ChangeThemeAction(SwingSet2 swingset, DefaultMetalTheme theme) {            super("ChangeTheme");	    this.swingset = swingset;	    this.theme = theme;        }        public void actionPerformed(ActionEvent e) {	    MetalLookAndFeel.setCurrentTheme(theme);	    swingset.updateLookAndFeel();	}    }    class ExitAction extends AbstractAction {	SwingSet2 swingset;        protected ExitAction(SwingSet2 swingset) {            super("ExitAction");	    this.swingset = swingset;        }        public void actionPerformed(ActionEvent e) {	    System.exit(0);        }    }    class AboutAction extends AbstractAction {	SwingSet2 swingset;        protected AboutAction(SwingSet2 swingset) {            super("AboutAction");	    this.swingset = swingset;        }        public void actionPerformed(ActionEvent e) {	    if(aboutBox == null) {		// JPanel panel = new JPanel(new BorderLayout());		JPanel panel = new AboutPanel(swingset);		panel.setLayout(new BorderLayout());		aboutBox = new JDialog(swingset.getFrame(), getString("AboutBox.title"), false);		aboutBox.getContentPane().add(panel, BorderLayout.CENTER);		// JButton button = new JButton(getString("AboutBox.ok_button_text"));		JPanel buttonpanel = new JPanel();		buttonpanel.setOpaque(false);		JButton button = (JButton) buttonpanel.add(		    new JButton(getString("AboutBox.ok_button_text"))		);		panel.add(buttonpanel, BorderLayout.SOUTH);		button.addActionListener(new OkAction(aboutBox));	    }	    aboutBox.pack();	    Point p = swingset.getLocationOnScreen();	    aboutBox.setLocation(p.x + 10, p.y +10);	    aboutBox.show();	}    }    class MultiScreenAction extends AbstractAction {        static final int ALL_SCREENS = -1;        int screen;        protected MultiScreenAction(SwingSet2 swingset, int screen) {            super("MultiScreenAction");            this.screen = screen;        }        public void actionPerformed(ActionEvent e) {            GraphicsDevice[] gds = GraphicsEnvironment.                                   getLocalGraphicsEnvironment().                                   getScreenDevices();            if (screen == ALL_SCREENS) {                for (int i = 0; i < gds.length; i++) {                    SwingSet2 swingset = new SwingSet2(null,                                  gds[i].getDefaultConfiguration());                }            }            else {                SwingSet2 swingset = new SwingSet2(null,                             gds[screen].getDefaultConfiguration());            }        }    }    // *******************************************************    // **********************  Misc  *************************    // *******************************************************    class DemoLoadThread extends Thread {	SwingSet2 swingset;	public DemoLoadThread(SwingSet2 swingset) {	    this.swingset = swingset;	}	public void run() {	    swingset.loadDemos();	}    }    class AboutPanel extends JPanel {	ImageIcon aboutimage = null;	SwingSet2 swingset = null;	public AboutPanel(SwingSet2 swingset) {	    this.swingset = swingset;	    aboutimage = swingset.createImageIcon("About.jpg", "AboutBox.accessible_description");	    setOpaque(false);	}	public void paint(Graphics g) {	    aboutimage.paintIcon(this, g, 0, 0);	    super.paint(g);	}	public Dimension getPreferredSize() {	    return new Dimension(aboutimage.getIconWidth(),				 aboutimage.getIconHeight());	}    }}

⌨️ 快捷键说明

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