jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthDesktopIconUI.java
author alexsch
Fri, 15 Apr 2016 19:15:12 +0400
changeset 37698 4d798c873df0
parent 25859 3317bb8137f4
permissions -rw-r--r--
8132791: No access to SynthContext.getContext() Reviewed-by: serb, ssadetsky
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
     2
 * Copyright (c) 2002, 2014, Oracle and/or its affiliates. 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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4848
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4848
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4848
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4848
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4848
diff changeset
    23
 * questions.
2
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 javax.swing.plaf.synth;
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.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.plaf.basic.BasicDesktopIconUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 7668
diff changeset
    37
 * Provides the Synth L&F UI delegate for a minimized internal frame on a desktop.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * @author Joshua Outwater
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    40
 * @since 1.7
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    42
public class SynthDesktopIconUI extends BasicDesktopIconUI
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    43
                                implements SynthUI, PropertyChangeListener {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private SynthStyle style;
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    45
    private Handler handler = new Handler();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    47
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    48
     * Creates a new UI object for the given component.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    49
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    50
     * @param c component to create UI object for
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    51
     * @return the UI object
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    52
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public static ComponentUI createUI(JComponent c)    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        return new SynthDesktopIconUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    57
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 7668
diff changeset
    58
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    59
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    60
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    protected void installComponents() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        if (UIManager.getBoolean("InternalFrame.useTaskBar")) {
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
    63
            @SuppressWarnings("serial") // anonymous class
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
    64
            JToggleButton tmp = new JToggleButton(frame.getTitle(), frame.getFrameIcon()) {
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    65
                @Override public String getToolTipText() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                    return getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    69
                @Override public JPopupMenu getComponentPopupMenu() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                    return frame.getComponentPopupMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            };
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
    73
            iconPane = tmp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            ToolTipManager.sharedInstance().registerComponent(iconPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            iconPane.setFont(desktopIcon.getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            iconPane.setBackground(desktopIcon.getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            iconPane.setForeground(desktopIcon.getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            iconPane = new SynthInternalFrameTitlePane(frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            iconPane.setName("InternalFrame.northPane");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        desktopIcon.setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        desktopIcon.add(iconPane, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    86
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 7668
diff changeset
    87
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    88
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    89
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    protected void installListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        super.installListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        desktopIcon.addPropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        if (iconPane instanceof JToggleButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            frame.addPropertyChangeListener(this);
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    96
            ((JToggleButton)iconPane).addActionListener(handler);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   100
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 7668
diff changeset
   101
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   102
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   103
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    protected void uninstallListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        if (iconPane instanceof JToggleButton) {
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   106
            ((JToggleButton)iconPane).removeActionListener(handler);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            frame.removePropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        desktopIcon.removePropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        super.uninstallListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   113
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 7668
diff changeset
   114
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   115
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   116
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    protected void installDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        updateStyle(desktopIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    private void updateStyle(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        SynthContext context = getContext(c, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        style = SynthLookAndFeel.updateStyle(context, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   126
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 7668
diff changeset
   127
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   128
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   129
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    protected void uninstallDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        SynthContext context = getContext(desktopIcon, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        style.uninstallDefaults(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        style = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   136
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 7668
diff changeset
   137
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   138
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   139
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public SynthContext getContext(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        return getContext(c, getComponentState(c));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    private SynthContext getContext(JComponent c, int state) {
25100
d527cc827d7d 8043627: NPE in SynthContext in plugin mode
malenkov
parents: 23697
diff changeset
   145
        return SynthContext.getContext(c, style, state);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    private int getComponentState(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        return SynthLookAndFeel.getComponentState(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   152
    /**
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   153
     * Notifies this UI delegate to repaint the specified component.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   154
     * This method paints the component background, then calls
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   155
     * the {@link #paint(SynthContext,Graphics)} method.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   156
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   157
     * <p>In general, this method does not need to be overridden by subclasses.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   158
     * All Look and Feel rendering code should reside in the {@code paint} method.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   159
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   160
     * @param g the {@code Graphics} object used for painting
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   161
     * @param c the component being painted
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   162
     * @see #paint(SynthContext,Graphics)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   163
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   164
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public void update(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        SynthLookAndFeel.update(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        context.getPainter().paintDesktopIconBackground(context, g, 0, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                                                  c.getWidth(), c.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   174
    /**
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   175
     * Paints the specified component according to the Look and Feel.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   176
     * <p>This method is not used by Synth Look and Feel.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   177
     * Painting is handled by the {@link #paint(SynthContext,Graphics)} method.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   178
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   179
     * @param g the {@code Graphics} object used for painting
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   180
     * @param c the component being painted
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   181
     * @see #paint(SynthContext,Graphics)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   182
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   183
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    public void paint(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   190
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   191
     * Paints the specified component. This implementation does nothing.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   192
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   193
     * @param context context for the component being painted
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   194
     * @param g the {@code Graphics} object used for painting
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   195
     * @see #update(Graphics,JComponent)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   196
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    protected void paint(SynthContext context, Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   200
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 7668
diff changeset
   201
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   202
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   203
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public void paintBorder(SynthContext context, Graphics g, int x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                            int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        context.getPainter().paintDesktopIconBorder(context, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public void propertyChange(PropertyChangeEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        if (evt.getSource() instanceof JInternalFrame.JDesktopIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            if (SynthLookAndFeel.shouldUpdateStyle(evt)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                updateStyle((JInternalFrame.JDesktopIcon)evt.getSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        } else if (evt.getSource() instanceof JInternalFrame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            JInternalFrame frame = (JInternalFrame)evt.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            if (iconPane instanceof JToggleButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                JToggleButton button = (JToggleButton)iconPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                String prop = evt.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                if (prop == "title") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                    button.setText((String)evt.getNewValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                } else if (prop == "frameIcon") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                    button.setIcon((Icon)evt.getNewValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                } else if (prop == JInternalFrame.IS_ICON_PROPERTY ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                           prop == JInternalFrame.IS_SELECTED_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                    button.setSelected(!frame.isIcon() && frame.isSelected());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   230
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   231
    private final class Handler implements ActionListener {
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   232
        public void actionPerformed(ActionEvent evt) {
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   233
            if (evt.getSource() instanceof JToggleButton) {
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   234
                // Either iconify the frame or deiconify and activate it.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   235
                JToggleButton button = (JToggleButton)evt.getSource();
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   236
                try {
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   237
                    boolean selected = button.isSelected();
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   238
                    if (!selected && !frame.isIconifiable()) {
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   239
                        button.setSelected(true);
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   240
                    } else {
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   241
                        frame.setIcon(!selected);
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   242
                        if (selected) {
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   243
                            frame.setSelected(true);
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   244
                        }
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   245
                    }
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   246
                } catch (PropertyVetoException e2) {
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   247
                }
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   248
            }
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   249
        }
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   250
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
}