jdk/src/share/classes/com/sun/java/swing/plaf/motif/MotifInternalFrameTitlePane.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 455 11d2fe22f245
child 5506 202f599c92aa
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 455
diff changeset
     2
 * Copyright 1997-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.java.swing.plaf.motif;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.event.InternalFrameEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.plaf.basic.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.EventListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.beans.VetoableChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.beans.PropertyVetoException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * Class that manages a Motif title bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
public class MotifInternalFrameTitlePane
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    extends BasicInternalFrameTitlePane implements LayoutManager, ActionListener, PropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    SystemButton systemButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    MinimizeButton minimizeButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    MaximizeButton maximizeButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    JPopupMenu systemMenu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    Title title;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    Color color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    Color highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    Color shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    // The width and height of a title pane button
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public final static int BUTTON_SIZE = 19;  // 17 + 1 pixel border
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    public MotifInternalFrameTitlePane(JInternalFrame frame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        super(frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    protected void installDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        setFont(UIManager.getFont("InternalFrame.titleFont"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        setPreferredSize(new Dimension(100, BUTTON_SIZE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    protected void uninstallListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        // Get around protected method in superclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        super.uninstallListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    protected PropertyChangeListener createPropertyChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    protected LayoutManager createLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    JPopupMenu getSystemMenu() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        return systemMenu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    protected void assembleSystemMenu() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        systemMenu = new JPopupMenu();
455
11d2fe22f245 6693507: There are unnecessary compilation warnings in the com.sun.java.swing.plaf.motif package
rupashka
parents: 2
diff changeset
    89
        JMenuItem mi = systemMenu.add(new JMenuItem(restoreAction));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        mi.setMnemonic('R');
455
11d2fe22f245 6693507: There are unnecessary compilation warnings in the com.sun.java.swing.plaf.motif package
rupashka
parents: 2
diff changeset
    91
        mi = systemMenu.add(new JMenuItem(moveAction));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        mi.setMnemonic('M');
455
11d2fe22f245 6693507: There are unnecessary compilation warnings in the com.sun.java.swing.plaf.motif package
rupashka
parents: 2
diff changeset
    93
        mi = systemMenu.add(new JMenuItem(sizeAction));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        mi.setMnemonic('S');
455
11d2fe22f245 6693507: There are unnecessary compilation warnings in the com.sun.java.swing.plaf.motif package
rupashka
parents: 2
diff changeset
    95
        mi = systemMenu.add(new JMenuItem(iconifyAction));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        mi.setMnemonic('n');
455
11d2fe22f245 6693507: There are unnecessary compilation warnings in the com.sun.java.swing.plaf.motif package
rupashka
parents: 2
diff changeset
    97
        mi = systemMenu.add(new JMenuItem(maximizeAction));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        mi.setMnemonic('x');
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        systemMenu.add(new JSeparator());
455
11d2fe22f245 6693507: There are unnecessary compilation warnings in the com.sun.java.swing.plaf.motif package
rupashka
parents: 2
diff changeset
   100
        mi = systemMenu.add(new JMenuItem(closeAction));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        mi.setMnemonic('C');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        systemButton = new SystemButton();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        systemButton.addActionListener(new ActionListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                systemMenu.show(systemButton, 0, BUTTON_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        systemButton.addMouseListener(new MouseAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            public void mousePressed(MouseEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                    frame.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                } catch (PropertyVetoException pve) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                if ((evt.getClickCount() == 2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                    closeAction.actionPerformed(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                        ActionEvent(evt.getSource(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                            ActionEvent.ACTION_PERFORMED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                            null, evt.getWhen(), 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                    systemMenu.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    protected void createButtons() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        minimizeButton = new MinimizeButton();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        minimizeButton.addActionListener(iconifyAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        maximizeButton = new MaximizeButton();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        maximizeButton.addActionListener(maximizeAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    protected void addSubComponents() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        title = new Title(frame.getTitle());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        title.setFont(getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        add(systemButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        add(title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        add(minimizeButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        add(maximizeButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public void paintComponent(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    void setColors(Color c, Color h, Color s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        color = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        highlight = h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        shadow = s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    public void propertyChange(PropertyChangeEvent evt) {
455
11d2fe22f245 6693507: There are unnecessary compilation warnings in the com.sun.java.swing.plaf.motif package
rupashka
parents: 2
diff changeset
   160
        String prop = evt.getPropertyName();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        JInternalFrame f = (JInternalFrame)evt.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        boolean value = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        if (JInternalFrame.IS_SELECTED_PROPERTY.equals(prop)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        } else if (prop.equals("maximizable")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            if ((Boolean)evt.getNewValue() == Boolean.TRUE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                add(maximizeButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                remove(maximizeButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        } else if (prop.equals("iconable")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            if ((Boolean)evt.getNewValue() == Boolean.TRUE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                add(minimizeButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                remove(minimizeButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        } else if (prop.equals(JInternalFrame.TITLE_PROPERTY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        enableActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    public void addLayoutComponent(String name, Component c) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    public void removeLayoutComponent(Component c) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public Dimension preferredLayoutSize(Container c)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        return minimumLayoutSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public Dimension minimumLayoutSize(Container c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        return new Dimension(100, BUTTON_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    public void layoutContainer(Container c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        int w = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        systemButton.setBounds(0, 0, BUTTON_SIZE, BUTTON_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        int x = w - BUTTON_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        if(frame.isMaximizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            maximizeButton.setBounds(x, 0, BUTTON_SIZE, BUTTON_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            x -= BUTTON_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        } else if(maximizeButton.getParent() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            maximizeButton.getParent().remove(maximizeButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        if(frame.isIconifiable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            minimizeButton.setBounds(x, 0, BUTTON_SIZE, BUTTON_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            x -= BUTTON_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        } else if(minimizeButton.getParent() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            minimizeButton.getParent().remove(minimizeButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        title.setBounds(BUTTON_SIZE, 0, x, BUTTON_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    protected void showSystemMenu(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
      systemMenu.show(systemButton, 0, BUTTON_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    protected void hideSystemMenu(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
      systemMenu.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    static Dimension buttonDimension = new Dimension(BUTTON_SIZE, BUTTON_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    private abstract class FrameButton extends JButton {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        FrameButton() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            setFocusPainted(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            setBorderPainted(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        public boolean isFocusTraversable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        public void requestFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            // ignore request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        public Dimension getMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            return buttonDimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            return buttonDimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        public void paintComponent(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            Dimension d = getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            int maxX = d.width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            int maxY = d.height - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            // draw background
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            g.setColor(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            g.fillRect(1, 1, d.width, d.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            // draw border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            boolean pressed = getModel().isPressed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            g.setColor(pressed ? shadow : highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            g.drawLine(0, 0, maxX, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            g.drawLine(0, 0, 0, maxY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            g.setColor(pressed ? highlight : shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            g.drawLine(1, maxY, maxX, maxY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            g.drawLine(maxX, 1, maxX, maxY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    private class MinimizeButton extends FrameButton {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        public void paintComponent(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            super.paintComponent(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            g.drawLine(7, 8, 7, 11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            g.drawLine(7, 8, 10, 8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            g.drawLine(8, 11, 10, 11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            g.drawLine(11, 9, 11, 11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    private class MaximizeButton extends FrameButton {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        public void paintComponent(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            super.paintComponent(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            int max = BUTTON_SIZE - 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            boolean isMaxed = frame.isMaximum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            g.setColor(isMaxed ? shadow : highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            g.drawLine(4, 4, 4, max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            g.drawLine(4, 4, max, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            g.setColor(isMaxed ? highlight : shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            g.drawLine(5, max, max, max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            g.drawLine(max, 5, max, max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    private class SystemButton extends FrameButton {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        public boolean isFocusTraversable() { return false; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        public void requestFocus() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        public void paintComponent(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            super.paintComponent(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            g.drawLine(4, 8, 4, 11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            g.drawLine(4, 8, BUTTON_SIZE - 5, 8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            g.drawLine(5, 11, BUTTON_SIZE - 5, 11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            g.drawLine(BUTTON_SIZE - 5, 9, BUTTON_SIZE - 5, 11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    private class Title extends FrameButton {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        Title(String title) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            setText(title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            setHorizontalAlignment(SwingConstants.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            setBorder(BorderFactory.createBevelBorder(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                BevelBorder.RAISED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                UIManager.getColor("activeCaptionBorder"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                UIManager.getColor("inactiveCaptionBorder")));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            // Forward mouse events to titlebar for moves.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            addMouseMotionListener(new MouseMotionListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                public void mouseDragged(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                    forwardEventToParent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                public void mouseMoved(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                    forwardEventToParent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            addMouseListener(new MouseListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                public void mouseClicked(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                    forwardEventToParent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                public void mousePressed(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                    forwardEventToParent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                public void mouseReleased(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                    forwardEventToParent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                public void mouseEntered(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                    forwardEventToParent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                public void mouseExited(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                    forwardEventToParent(e);
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        void forwardEventToParent(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            getParent().dispatchEvent(new MouseEvent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                getParent(), e.getID(), e.getWhen(), e.getModifiers(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                e.getX(), e.getY(),  e.getXOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                e.getYOnScreen(), e.getClickCount(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                e.isPopupTrigger(),  MouseEvent.NOBUTTON));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        public void paintComponent(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            super.paintComponent(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            if (frame.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                g.setColor(UIManager.getColor("activeCaptionText"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                g.setColor(UIManager.getColor("inactiveCaptionText"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            Dimension d = getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            String frameTitle = frame.getTitle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            if (frameTitle != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                MotifGraphicsUtils.drawStringInRect(frame, g, frameTitle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                                                    0, 0, d.width, d.height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                                                    SwingConstants.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
}