KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > java > swing > plaf > windows > WindowsInternalFrameUI


1 /*
2  * @(#)WindowsInternalFrameUI.java 1.25 06/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.java.swing.plaf.windows;
9
10 import java.awt.*;
11 import java.beans.*;
12 import javax.swing.*;
13 import javax.swing.border.*;
14 import javax.swing.plaf.basic.*;
15 import javax.swing.plaf.ComponentUI JavaDoc;
16
17 import com.sun.java.swing.plaf.windows.TMSchema.*;
18 import com.sun.java.swing.plaf.windows.XPStyle.Skin;
19
20 /**
21  * Windows rendition of the component.
22  * <p>
23  * <strong>Warning:</strong>
24  * Serialized objects of this class will not be compatible with
25  * future Swing releases. The current serialization support is appropriate
26  * for short term storage or RMI between applications running the same
27  * version of Swing. A future release of Swing will provide support for
28  * long term persistence.
29  */

30 public class WindowsInternalFrameUI extends BasicInternalFrameUI
31 {
32     XPStyle xp = XPStyle.getXP();
33
34     public void installDefaults() {
35         super.installDefaults();
36
37     if (xp != null) {
38         frame.setBorder(new XPBorder());
39     } else {
40         frame.setBorder(UIManager.getBorder("InternalFrame.border"));
41     }
42     }
43
44     public void installUI(JComponent c) {
45     super.installUI(c);
46
47         LookAndFeel.installProperty(c, "opaque",
48                     xp == null? Boolean.TRUE : Boolean.FALSE);
49     }
50
51     public void uninstallDefaults() {
52         frame.setBorder(null);
53         super.uninstallDefaults();
54     }
55
56     public static ComponentUI JavaDoc createUI(JComponent b) {
57         return new WindowsInternalFrameUI((JInternalFrame)b);
58     }
59
60     public WindowsInternalFrameUI(JInternalFrame w){
61     super(w);
62     }
63
64     protected DesktopManager createDesktopManager(){
65         return new WindowsDesktopManager();
66     }
67
68     protected JComponent createNorthPane(JInternalFrame w) {
69         titlePane = new WindowsInternalFrameTitlePane(w);
70         return titlePane;
71     }
72
73     private class XPBorder extends AbstractBorder {
74         private Skin leftSkin = xp.getSkin(frame, Part.WP_FRAMELEFT);
75         private Skin rightSkin = xp.getSkin(frame, Part.WP_FRAMERIGHT);
76         private Skin bottomSkin = xp.getSkin(frame, Part.WP_FRAMEBOTTOM);
77
78     /**
79      * @param x the x position of the painted border
80      * @param y the y position of the painted border
81      * @param width the width of the painted border
82      * @param height the height of the painted border
83      */

84     public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
85             State state = ((JInternalFrame)c).isSelected() ? State.ACTIVE : State.INACTIVE;
86         int topBorderHeight = (titlePane != null) ? titlePane.getSize().height : 0;
87
88         bottomSkin.paintSkin(g, 0, height-bottomSkin.getHeight(),
89                  width, bottomSkin.getHeight(),
90                                  state);
91
92         leftSkin.paintSkin(g, 0, topBorderHeight-1,
93                    leftSkin.getWidth(), height-topBorderHeight-bottomSkin.getHeight()+2,
94                                state);
95
96         rightSkin.paintSkin(g, width-rightSkin.getWidth(), topBorderHeight-1,
97                 rightSkin.getWidth(), height-topBorderHeight-bottomSkin.getHeight()+2,
98                                 state);
99
100     }
101
102     public Insets getBorderInsets(Component c) {
103         return getBorderInsets(c, new Insets(0, 0, 0, 0));
104     }
105
106     public Insets getBorderInsets(Component c, Insets insets) {
107         insets.top = 4;
108         insets.left = leftSkin.getWidth();
109         insets.right = rightSkin.getWidth();
110         insets.bottom = bottomSkin.getHeight();
111
112         return insets;
113     }
114
115     public boolean isBorderOpaque() {
116         return true;
117     }
118     }
119
120 }
121
Popular Tags