blob: f02932e3f1259f4c4b7333c13767639630b24e0b [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2002-2003 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package javax.swing.plaf.synth;
27
28import java.awt.*;
29import java.awt.event.ActionEvent;
30import java.beans.PropertyChangeEvent;
31import java.beans.PropertyChangeListener;
32import javax.swing.*;
33import javax.swing.plaf.*;
34import javax.swing.plaf.basic.BasicRootPaneUI;
35import sun.swing.plaf.synth.SynthUI;
36
37/**
38 * Synth's RootPaneUI.
39 *
40 * @author Scott Violet
41 */
42class SynthRootPaneUI extends BasicRootPaneUI implements SynthUI {
43 private SynthStyle style;
44
45 public static ComponentUI createUI(JComponent c) {
46 return new SynthRootPaneUI();
47 }
48
49 protected void installDefaults(JRootPane c){
50 updateStyle(c);
51 }
52
53 protected void uninstallDefaults(JRootPane root) {
54 SynthContext context = getContext(root, ENABLED);
55
56 style.uninstallDefaults(context);
57 context.dispose();
58 style = null;
59 }
60
61 public SynthContext getContext(JComponent c) {
62 return getContext(c, getComponentState(c));
63 }
64
65 private SynthContext getContext(JComponent c, int state) {
66 return SynthContext.getContext(SynthContext.class, c,
67 SynthLookAndFeel.getRegion(c), style, state);
68 }
69
70 private Region getRegion(JComponent c) {
71 return SynthLookAndFeel.getRegion(c);
72 }
73
74 private int getComponentState(JComponent c) {
75 return SynthLookAndFeel.getComponentState(c);
76 }
77
78 private void updateStyle(JComponent c) {
79 SynthContext context = getContext(c, ENABLED);
80 SynthStyle oldStyle = style;
81 style = SynthLookAndFeel.updateStyle(context, this);
82 if (style != oldStyle) {
83 if (oldStyle != null) {
84 uninstallKeyboardActions((JRootPane)c);
85 installKeyboardActions((JRootPane)c);
86 }
87 }
88 context.dispose();
89 }
90
91 public void update(Graphics g, JComponent c) {
92 SynthContext context = getContext(c);
93
94 SynthLookAndFeel.update(context, g);
95 context.getPainter().paintRootPaneBackground(context,
96 g, 0, 0, c.getWidth(), c.getHeight());
97 paint(context, g);
98 context.dispose();
99 }
100
101 public void paint(Graphics g, JComponent c) {
102 SynthContext context = getContext(c);
103
104 paint(context, g);
105 context.dispose();
106 }
107
108 protected void paint(SynthContext context, Graphics g) {
109 }
110
111 public void paintBorder(SynthContext context, Graphics g, int x,
112 int y, int w, int h) {
113 context.getPainter().paintRootPaneBorder(context, g, x, y, w, h);
114 }
115
116 /**
117 * Invoked when a property changes on the root pane. If the event
118 * indicates the <code>defaultButton</code> has changed, this will
119 * reinstall the keyboard actions.
120 */
121 public void propertyChange(PropertyChangeEvent e) {
122 if (SynthLookAndFeel.shouldUpdateStyle(e)) {
123 updateStyle((JRootPane)e.getSource());
124 }
125 super.propertyChange(e);
126 }
127}