0N/A/*
3835N/A * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A *
0N/A * Redistribution and use in source and binary forms, with or without
0N/A * modification, are permitted provided that the following conditions
0N/A * are met:
0N/A *
0N/A * - Redistributions of source code must retain the above copyright
0N/A * notice, this list of conditions and the following disclaimer.
0N/A *
0N/A * - Redistributions in binary form must reproduce the above copyright
0N/A * notice, this list of conditions and the following disclaimer in the
0N/A * documentation and/or other materials provided with the distribution.
0N/A *
2362N/A * - Neither the name of Oracle nor the names of its
0N/A * contributors may be used to endorse or promote products derived
0N/A * from this software without specific prior written permission.
0N/A *
0N/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
0N/A * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
0N/A * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
0N/A * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
0N/A * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
0N/A * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
0N/A * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
0N/A * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
0N/A * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
0N/A * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
0N/A * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0N/A */
0N/A
4378N/A/*
4378N/A * This source code is provided to illustrate the usage of a given feature
4378N/A * or technique and has been deliberately simplified. Additional steps
4378N/A * required for a production-quality application, such as security checks,
4378N/A * input validation and proper error handling, might not be present in
4378N/A * this sample code.
4378N/A */
4378N/A
4378N/A
0N/A
3835N/Aimport java.awt.Dimension;
3835N/Aimport java.awt.Toolkit;
3835N/Aimport java.awt.event.ActionEvent;
3835N/Aimport java.awt.event.ActionListener;
3835N/Aimport java.awt.event.WindowAdapter;
3835N/Aimport java.awt.event.WindowEvent;
3835N/Aimport java.io.InputStream;
3835N/Aimport javax.swing.ButtonGroup;
3835N/Aimport javax.swing.JCheckBoxMenuItem;
3835N/Aimport javax.swing.JComponent;
3835N/Aimport javax.swing.JDesktopPane;
3835N/Aimport javax.swing.JFileChooser;
3835N/Aimport javax.swing.JFrame;
3835N/Aimport javax.swing.JInternalFrame;
3835N/Aimport javax.swing.JMenu;
3835N/Aimport javax.swing.JMenuBar;
3835N/Aimport javax.swing.JMenuItem;
3835N/Aimport javax.swing.JOptionPane;
3835N/Aimport javax.swing.JRadioButtonMenuItem;
3835N/Aimport javax.swing.UIManager;
3835N/Aimport javax.swing.plaf.metal.DefaultMetalTheme;
3835N/Aimport javax.swing.plaf.metal.MetalTheme;
3835N/Aimport javax.swing.plaf.metal.OceanTheme;
0N/A
0N/A
0N/A/**
3835N/A * This is the main container frame for the Metalworks demo app
3835N/A *
3835N/A * @author Steve Wilson
3835N/A * @author Alexander Kouznetsov
3835N/A */
3835N/A@SuppressWarnings("serial")
3835N/Apublic final class MetalworksFrame extends JFrame {
0N/A
0N/A JMenuBar menuBar;
0N/A JDesktopPane desktop;
0N/A JInternalFrame toolPalette;
0N/A JCheckBoxMenuItem showToolPaletteMenuItem;
3835N/A static final Integer DOCLAYER = 5;
3835N/A static final Integer TOOLLAYER = 6;
3835N/A static final Integer HELPLAYER = 7;
3835N/A static final String ABOUTMSG = "Metalworks \n \nAn application written to "
3835N/A + "show off the Java Look & Feel. \n \nWritten by the JavaSoft "
3835N/A + "Look & Feel Team \n Michael Albers\n Tom Santos\n "
3835N/A + "Jeff Shapiro\n Steve Wilson";
0N/A
0N/A public MetalworksFrame() {
0N/A super("Metalworks");
0N/A final int inset = 50;
0N/A Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
3835N/A setBounds(inset, inset, screenSize.width - inset * 2, screenSize.height - inset
3835N/A * 2);
0N/A buildContent();
0N/A buildMenus();
0N/A this.addWindowListener(new WindowAdapter() {
3835N/A
3835N/A @Override
3835N/A public void windowClosing(WindowEvent e) {
3835N/A quit();
3835N/A }
3835N/A });
3835N/A UIManager.addPropertyChangeListener(new UISwitchListener(
3835N/A (JComponent) getRootPane()));
0N/A }
0N/A
0N/A protected void buildMenus() {
0N/A menuBar = new JMenuBar();
0N/A menuBar.setOpaque(true);
0N/A JMenu file = buildFileMenu();
0N/A JMenu edit = buildEditMenu();
0N/A JMenu views = buildViewsMenu();
0N/A JMenu speed = buildSpeedMenu();
0N/A JMenu help = buildHelpMenu();
0N/A
0N/A // load a theme from a text file
0N/A MetalTheme myTheme = null;
0N/A try {
3835N/A InputStream istream = getClass().getResourceAsStream(
3835N/A "/resources/MyTheme.theme");
3835N/A myTheme = new PropertiesMetalTheme(istream);
3835N/A } catch (NullPointerException e) {
3835N/A System.out.println(e);
3835N/A }
0N/A
0N/A // build an array of themes
0N/A MetalTheme[] themes = { new OceanTheme(),
3835N/A new DefaultMetalTheme(),
3835N/A new GreenMetalTheme(),
3835N/A new AquaMetalTheme(),
3835N/A new KhakiMetalTheme(),
3835N/A new DemoMetalTheme(),
3835N/A new ContrastMetalTheme(),
3835N/A new BigContrastMetalTheme(),
3835N/A myTheme };
0N/A
0N/A // put the themes in a menu
0N/A JMenu themeMenu = new MetalThemeMenu("Theme", themes);
0N/A
0N/A menuBar.add(file);
0N/A menuBar.add(edit);
0N/A menuBar.add(views);
0N/A menuBar.add(themeMenu);
0N/A menuBar.add(speed);
0N/A menuBar.add(help);
0N/A setJMenuBar(menuBar);
0N/A }
0N/A
0N/A protected JMenu buildFileMenu() {
0N/A JMenu file = new JMenu("File");
0N/A JMenuItem newWin = new JMenuItem("New");
0N/A JMenuItem open = new JMenuItem("Open");
0N/A JMenuItem quit = new JMenuItem("Quit");
0N/A
0N/A newWin.addActionListener(new ActionListener() {
3835N/A
3835N/A public void actionPerformed(ActionEvent e) {
3835N/A newDocument();
3835N/A }
3835N/A });
0N/A
0N/A open.addActionListener(new ActionListener() {
3835N/A
3835N/A public void actionPerformed(ActionEvent e) {
3835N/A openDocument();
3835N/A }
3835N/A });
0N/A
0N/A quit.addActionListener(new ActionListener() {
3835N/A
3835N/A public void actionPerformed(ActionEvent e) {
3835N/A quit();
3835N/A }
3835N/A });
0N/A
0N/A file.add(newWin);
0N/A file.add(open);
0N/A file.addSeparator();
0N/A file.add(quit);
0N/A return file;
0N/A }
0N/A
0N/A protected JMenu buildEditMenu() {
0N/A JMenu edit = new JMenu("Edit");
0N/A JMenuItem undo = new JMenuItem("Undo");
0N/A JMenuItem copy = new JMenuItem("Copy");
0N/A JMenuItem cut = new JMenuItem("Cut");
0N/A JMenuItem paste = new JMenuItem("Paste");
0N/A JMenuItem prefs = new JMenuItem("Preferences...");
0N/A
0N/A undo.setEnabled(false);
0N/A copy.setEnabled(false);
0N/A cut.setEnabled(false);
0N/A paste.setEnabled(false);
0N/A
0N/A prefs.addActionListener(new ActionListener() {
3835N/A
3835N/A public void actionPerformed(ActionEvent e) {
3835N/A openPrefsWindow();
3835N/A }
3835N/A });
0N/A
0N/A edit.add(undo);
0N/A edit.addSeparator();
0N/A edit.add(cut);
0N/A edit.add(copy);
0N/A edit.add(paste);
0N/A edit.addSeparator();
0N/A edit.add(prefs);
0N/A return edit;
0N/A }
0N/A
0N/A protected JMenu buildViewsMenu() {
0N/A JMenu views = new JMenu("Views");
0N/A
0N/A JMenuItem inBox = new JMenuItem("Open In-Box");
0N/A JMenuItem outBox = new JMenuItem("Open Out-Box");
0N/A outBox.setEnabled(false);
0N/A
0N/A inBox.addActionListener(new ActionListener() {
3835N/A
3835N/A public void actionPerformed(ActionEvent e) {
3835N/A openInBox();
3835N/A }
3835N/A });
0N/A
0N/A views.add(inBox);
0N/A views.add(outBox);
0N/A return views;
0N/A }
0N/A
3835N/A protected JMenu buildSpeedMenu() {
0N/A JMenu speed = new JMenu("Drag");
0N/A
0N/A JRadioButtonMenuItem live = new JRadioButtonMenuItem("Live");
0N/A JRadioButtonMenuItem outline = new JRadioButtonMenuItem("Outline");
0N/A
0N/A JRadioButtonMenuItem slow = new JRadioButtonMenuItem("Old and Slow");
0N/A
0N/A ButtonGroup group = new ButtonGroup();
0N/A
0N/A group.add(live);
0N/A group.add(outline);
0N/A group.add(slow);
0N/A
0N/A live.setSelected(true);
0N/A
3835N/A slow.addActionListener(new ActionListener() {
3835N/A
3835N/A public void actionPerformed(ActionEvent e) {
3835N/A // for right now I'm saying if you set the mode
3835N/A // to something other than a specified mode
3835N/A // it will revert to the old way
3835N/A // This is mostly for comparison's sake
3835N/A desktop.setDragMode(-1);
3835N/A }
3835N/A });
0N/A
3835N/A live.addActionListener(new ActionListener() {
3835N/A
3835N/A public void actionPerformed(ActionEvent e) {
3835N/A desktop.setDragMode(JDesktopPane.LIVE_DRAG_MODE);
3835N/A }
3835N/A });
0N/A
3835N/A outline.addActionListener(new ActionListener() {
3835N/A
3835N/A public void actionPerformed(ActionEvent e) {
3835N/A desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
3835N/A }
3835N/A });
0N/A
0N/A
0N/A speed.add(live);
0N/A speed.add(outline);
0N/A speed.add(slow);
0N/A return speed;
3835N/A }
0N/A
0N/A protected JMenu buildHelpMenu() {
0N/A JMenu help = new JMenu("Help");
0N/A JMenuItem about = new JMenuItem("About Metalworks...");
0N/A JMenuItem openHelp = new JMenuItem("Open Help Window");
0N/A
0N/A about.addActionListener(new ActionListener() {
3835N/A
0N/A public void actionPerformed(ActionEvent e) {
0N/A showAboutBox();
0N/A }
0N/A });
0N/A
0N/A openHelp.addActionListener(new ActionListener() {
3835N/A
3835N/A public void actionPerformed(ActionEvent e) {
3835N/A openHelpWindow();
3835N/A }
3835N/A });
0N/A
0N/A help.add(about);
0N/A help.add(openHelp);
0N/A
0N/A return help;
0N/A }
0N/A
0N/A protected void buildContent() {
0N/A desktop = new JDesktopPane();
0N/A getContentPane().add(desktop);
0N/A }
0N/A
0N/A public void quit() {
0N/A System.exit(0);
0N/A }
0N/A
0N/A public void newDocument() {
0N/A JInternalFrame doc = new MetalworksDocumentFrame();
0N/A desktop.add(doc, DOCLAYER);
0N/A try {
0N/A doc.setVisible(true);
0N/A doc.setSelected(true);
3835N/A } catch (java.beans.PropertyVetoException e2) {
3835N/A }
0N/A }
0N/A
0N/A public void openDocument() {
0N/A JFileChooser chooser = new JFileChooser();
0N/A chooser.showOpenDialog(this);
0N/A }
0N/A
0N/A public void openHelpWindow() {
0N/A JInternalFrame help = new MetalworksHelp();
0N/A desktop.add(help, HELPLAYER);
0N/A try {
0N/A help.setVisible(true);
0N/A help.setSelected(true);
3835N/A } catch (java.beans.PropertyVetoException e2) {
3835N/A }
0N/A }
0N/A
0N/A public void showAboutBox() {
0N/A JOptionPane.showMessageDialog(this, ABOUTMSG);
0N/A }
0N/A
0N/A public void openPrefsWindow() {
0N/A MetalworksPrefs dialog = new MetalworksPrefs(this);
3835N/A dialog.setVisible(true);
0N/A
0N/A }
0N/A
0N/A public void openInBox() {
0N/A JInternalFrame doc = new MetalworksInBox();
0N/A desktop.add(doc, DOCLAYER);
0N/A try {
0N/A doc.setVisible(true);
0N/A doc.setSelected(true);
3835N/A } catch (java.beans.PropertyVetoException e2) {
3835N/A }
0N/A }
0N/A}