src/demo/share/jfc/Metalworks/MetalworksFrame.java
author ysuenaga
Wed, 13 Nov 2019 10:27:06 +0900
changeset 59045 846fee5ea75e
parent 47216 71c04702a3d5
permissions -rw-r--r--
8233785: Incorrect JDK version is reported in hs_err log Reviewed-by: dholmes, stuefe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
8961
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
     2
 * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * Redistribution and use in source and binary forms, with or without
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * modification, are permitted provided that the following conditions
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * are met:
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *   - Redistributions of source code must retain the above copyright
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *     notice, this list of conditions and the following disclaimer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *   - Redistributions in binary form must reproduce the above copyright
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *     notice, this list of conditions and the following disclaimer in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *     documentation and/or other materials provided with the distribution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    15
 *   - Neither the name of Oracle nor the names of its
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *     contributors may be used to endorse or promote products derived
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 *     from this software without specific prior written permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
10292
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8961
diff changeset
    32
/*
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8961
diff changeset
    33
 * This source code is provided to illustrate the usage of a given feature
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8961
diff changeset
    34
 * or technique and has been deliberately simplified. Additional steps
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8961
diff changeset
    35
 * required for a production-quality application, such as security checks,
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8961
diff changeset
    36
 * input validation and proper error handling, might not be present in
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8961
diff changeset
    37
 * this sample code.
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8961
diff changeset
    38
 */
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8961
diff changeset
    39
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8961
diff changeset
    40
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
8961
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    42
import java.awt.Dimension;
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    43
import java.awt.Toolkit;
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    44
import java.awt.event.ActionEvent;
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    45
import java.awt.event.ActionListener;
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    46
import java.awt.event.WindowAdapter;
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    47
import java.awt.event.WindowEvent;
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    48
import java.io.InputStream;
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    49
import javax.swing.ButtonGroup;
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    50
import javax.swing.JCheckBoxMenuItem;
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    51
import javax.swing.JComponent;
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    52
import javax.swing.JDesktopPane;
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    53
import javax.swing.JFileChooser;
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    54
import javax.swing.JFrame;
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    55
import javax.swing.JInternalFrame;
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    56
import javax.swing.JMenu;
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    57
import javax.swing.JMenuBar;
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    58
import javax.swing.JMenuItem;
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    59
import javax.swing.JOptionPane;
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    60
import javax.swing.JRadioButtonMenuItem;
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    61
import javax.swing.UIManager;
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    62
import javax.swing.plaf.metal.DefaultMetalTheme;
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    63
import javax.swing.plaf.metal.MetalTheme;
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    64
import javax.swing.plaf.metal.OceanTheme;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
/**
8961
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    68
 * This is the main container frame for the Metalworks demo app
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    69
 *
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    70
 * @author Steve Wilson
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    71
 * @author Alexander Kouznetsov
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    72
 */
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    73
@SuppressWarnings("serial")
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    74
public final class MetalworksFrame extends JFrame {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    JMenuBar menuBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    JDesktopPane desktop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    JInternalFrame toolPalette;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    JCheckBoxMenuItem showToolPaletteMenuItem;
8961
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    80
    static final Integer DOCLAYER = 5;
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    81
    static final Integer TOOLLAYER = 6;
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    82
    static final Integer HELPLAYER = 7;
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    83
    static final String ABOUTMSG = "Metalworks \n \nAn application written to "
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    84
            + "show off the Java Look & Feel. \n \nWritten by the JavaSoft "
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    85
            + "Look & Feel Team \n  Michael Albers\n  Tom Santos\n  "
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    86
            + "Jeff Shapiro\n  Steve Wilson";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public MetalworksFrame() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        super("Metalworks");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        final int inset = 50;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
8961
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    92
        setBounds(inset, inset, screenSize.width - inset * 2, screenSize.height - inset
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    93
                * 2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        buildContent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        buildMenus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        this.addWindowListener(new WindowAdapter() {
8961
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    97
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    98
            @Override
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
    99
            public void windowClosing(WindowEvent e) {
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   100
                quit();
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   101
            }
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   102
        });
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   103
        UIManager.addPropertyChangeListener(new UISwitchListener(
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   104
                (JComponent) getRootPane()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    protected void buildMenus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        menuBar = new JMenuBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        menuBar.setOpaque(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        JMenu file = buildFileMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        JMenu edit = buildEditMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        JMenu views = buildViewsMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        JMenu speed = buildSpeedMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        JMenu help = buildHelpMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        // load a theme from a text file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        MetalTheme myTheme = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        try {
8961
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   119
            InputStream istream = getClass().getResourceAsStream(
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   120
                    "/resources/MyTheme.theme");
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   121
            myTheme = new PropertiesMetalTheme(istream);
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   122
        } catch (NullPointerException e) {
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   123
            System.out.println(e);
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   124
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        // build an array of themes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        MetalTheme[] themes = { new OceanTheme(),
8961
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   128
            new DefaultMetalTheme(),
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   129
            new GreenMetalTheme(),
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   130
            new AquaMetalTheme(),
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   131
            new KhakiMetalTheme(),
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   132
            new DemoMetalTheme(),
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   133
            new ContrastMetalTheme(),
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   134
            new BigContrastMetalTheme(),
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   135
            myTheme };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        // put the themes in a menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        JMenu themeMenu = new MetalThemeMenu("Theme", themes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        menuBar.add(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        menuBar.add(edit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        menuBar.add(views);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        menuBar.add(themeMenu);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        menuBar.add(speed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        menuBar.add(help);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        setJMenuBar(menuBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    protected JMenu buildFileMenu() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        JMenu file = new JMenu("File");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        JMenuItem newWin = new JMenuItem("New");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        JMenuItem open = new JMenuItem("Open");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        JMenuItem quit = new JMenuItem("Quit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        newWin.addActionListener(new ActionListener() {
8961
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   156
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   157
            public void actionPerformed(ActionEvent e) {
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   158
                newDocument();
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   159
            }
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   160
        });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        open.addActionListener(new ActionListener() {
8961
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   163
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   164
            public void actionPerformed(ActionEvent e) {
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   165
                openDocument();
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   166
            }
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   167
        });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        quit.addActionListener(new ActionListener() {
8961
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   170
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   171
            public void actionPerformed(ActionEvent e) {
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   172
                quit();
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   173
            }
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   174
        });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        file.add(newWin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        file.add(open);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        file.addSeparator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        file.add(quit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        return file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    protected JMenu buildEditMenu() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        JMenu edit = new JMenu("Edit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        JMenuItem undo = new JMenuItem("Undo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        JMenuItem copy = new JMenuItem("Copy");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        JMenuItem cut = new JMenuItem("Cut");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        JMenuItem paste = new JMenuItem("Paste");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        JMenuItem prefs = new JMenuItem("Preferences...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        undo.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        copy.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        cut.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        paste.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        prefs.addActionListener(new ActionListener() {
8961
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   197
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   198
            public void actionPerformed(ActionEvent e) {
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   199
                openPrefsWindow();
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   200
            }
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   201
        });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        edit.add(undo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        edit.addSeparator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        edit.add(cut);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        edit.add(copy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        edit.add(paste);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        edit.addSeparator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        edit.add(prefs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        return edit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    protected JMenu buildViewsMenu() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        JMenu views = new JMenu("Views");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        JMenuItem inBox = new JMenuItem("Open In-Box");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        JMenuItem outBox = new JMenuItem("Open Out-Box");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        outBox.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        inBox.addActionListener(new ActionListener() {
8961
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   221
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   222
            public void actionPerformed(ActionEvent e) {
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   223
                openInBox();
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   224
            }
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   225
        });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        views.add(inBox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        views.add(outBox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        return views;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
8961
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   232
    protected JMenu buildSpeedMenu() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        JMenu speed = new JMenu("Drag");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        JRadioButtonMenuItem live = new JRadioButtonMenuItem("Live");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        JRadioButtonMenuItem outline = new JRadioButtonMenuItem("Outline");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        JRadioButtonMenuItem slow = new JRadioButtonMenuItem("Old and Slow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        ButtonGroup group = new ButtonGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        group.add(live);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        group.add(outline);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        group.add(slow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        live.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
8961
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   248
        slow.addActionListener(new ActionListener() {
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   249
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   250
            public void actionPerformed(ActionEvent e) {
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   251
                // for right now I'm saying if you set the mode
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   252
                // to something other than a specified mode
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   253
                // it will revert to the old way
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   254
                // This is mostly for comparison's sake
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   255
                desktop.setDragMode(-1);
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   256
            }
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   257
        });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
8961
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   259
        live.addActionListener(new ActionListener() {
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   260
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   261
            public void actionPerformed(ActionEvent e) {
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   262
                desktop.setDragMode(JDesktopPane.LIVE_DRAG_MODE);
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   263
            }
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   264
        });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
8961
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   266
        outline.addActionListener(new ActionListener() {
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   267
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   268
            public void actionPerformed(ActionEvent e) {
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   269
                desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   270
            }
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   271
        });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        speed.add(live);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        speed.add(outline);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        speed.add(slow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        return speed;
8961
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   278
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    protected JMenu buildHelpMenu() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        JMenu help = new JMenu("Help");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        JMenuItem about = new JMenuItem("About Metalworks...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        JMenuItem openHelp = new JMenuItem("Open Help Window");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        about.addActionListener(new ActionListener() {
8961
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   286
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                showAboutBox();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        openHelp.addActionListener(new ActionListener() {
8961
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   293
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   294
            public void actionPerformed(ActionEvent e) {
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   295
                openHelpWindow();
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   296
            }
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   297
        });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        help.add(about);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        help.add(openHelp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        return help;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    protected void buildContent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        desktop = new JDesktopPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        getContentPane().add(desktop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    public void quit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        System.exit(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    public void newDocument() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        JInternalFrame doc = new MetalworksDocumentFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        desktop.add(doc, DOCLAYER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            doc.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            doc.setSelected(true);
8961
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   320
        } catch (java.beans.PropertyVetoException e2) {
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   321
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    public void openDocument() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        JFileChooser chooser = new JFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        chooser.showOpenDialog(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    public void openHelpWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        JInternalFrame help = new MetalworksHelp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        desktop.add(help, HELPLAYER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            help.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            help.setSelected(true);
8961
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   335
        } catch (java.beans.PropertyVetoException e2) {
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   336
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    public void showAboutBox() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        JOptionPane.showMessageDialog(this, ABOUTMSG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    public void openPrefsWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        MetalworksPrefs dialog = new MetalworksPrefs(this);
8961
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   345
        dialog.setVisible(true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    public void openInBox() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        JInternalFrame doc = new MetalworksInBox();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        desktop.add(doc, DOCLAYER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            doc.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            doc.setSelected(true);
8961
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   355
        } catch (java.beans.PropertyVetoException e2) {
6e8562ef340d 7027696: /jfc/Metalworks demo needs to be improved
mrkam
parents: 5506
diff changeset
   356
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
}