KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > plaf > metal > MetalInternalFrameUI


1 /*
2  * @(#)MetalInternalFrameUI.java 1.30 03/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 javax.swing.plaf.metal;
9
10 import java.awt.*;
11 import java.awt.event.*;
12 import javax.swing.*;
13 import javax.swing.event.*;
14 import javax.swing.border.*;
15 import javax.swing.plaf.basic.*;
16 import java.util.EventListener JavaDoc;
17 import java.beans.PropertyChangeListener JavaDoc;
18 import java.beans.PropertyChangeEvent JavaDoc;
19 import java.beans.PropertyVetoException JavaDoc;
20 import javax.swing.plaf.*;
21
22 /**
23  * Metal implementation of JInternalFrame.
24  * <p>
25  *
26  * @version 1.30 12/19/03
27  * @author Steve Wilson
28  */

29 public class MetalInternalFrameUI extends BasicInternalFrameUI {
30
31   private MetalInternalFrameTitlePane JavaDoc titlePane;
32
33   private static final PropertyChangeListener JavaDoc metalPropertyChangeListener =
34         new MetalPropertyChangeHandler();
35
36   private static final Border handyEmptyBorder = new EmptyBorder(0,0,0,0);
37   
38   protected static String JavaDoc IS_PALETTE = "JInternalFrame.isPalette";
39
40   private static String JavaDoc FRAME_TYPE = "JInternalFrame.frameType";
41   private static String JavaDoc NORMAL_FRAME = "normal";
42   private static String JavaDoc PALETTE_FRAME = "palette";
43   private static String JavaDoc OPTION_DIALOG = "optionDialog";
44
45   public MetalInternalFrameUI(JInternalFrame b) {
46     super(b);
47   }
48
49   public static ComponentUI createUI(JComponent c) {
50       return new MetalInternalFrameUI JavaDoc( (JInternalFrame) c);
51   }
52
53   public void installUI(JComponent c) {
54     super.installUI(c);
55
56     Object JavaDoc paletteProp = c.getClientProperty( IS_PALETTE );
57     if ( paletteProp != null ) {
58     setPalette( ((Boolean JavaDoc)paletteProp).booleanValue() );
59     }
60
61     Container content = frame.getContentPane();
62     stripContentBorder(content);
63     //c.setOpaque(false);
64
}
65   
66   public void uninstallUI(JComponent c) {
67       frame = (JInternalFrame)c;
68
69       Container cont = ((JInternalFrame)(c)).getContentPane();
70       if (cont instanceof JComponent) {
71     JComponent content = (JComponent)cont;
72     if ( content.getBorder() == handyEmptyBorder) {
73       content.setBorder(null);
74     }
75       }
76       super.uninstallUI(c);
77   }
78
79     protected void installListeners() {
80         super.installListeners();
81         frame.addPropertyChangeListener(metalPropertyChangeListener);
82     }
83
84     protected void uninstallListeners() {
85         frame.removePropertyChangeListener(metalPropertyChangeListener);
86         super.uninstallListeners();
87     }
88
89   protected void installKeyboardActions(){
90       super.installKeyboardActions();
91       ActionMap map = SwingUtilities.getUIActionMap(frame);
92       if (map != null) {
93       // BasicInternalFrameUI creates an action with the same name, we override
94
// it as Metal frames do not have system menus.
95
map.remove("showSystemMenu");
96       }
97   }
98
99   protected void uninstallKeyboardActions(){
100       super.uninstallKeyboardActions();
101   }
102
103     protected void uninstallComponents() {
104         titlePane = null;
105         super.uninstallComponents();
106     }
107
108   private void stripContentBorder(Object JavaDoc c) {
109         if ( c instanceof JComponent ) {
110             JComponent contentComp = (JComponent)c;
111             Border contentBorder = contentComp.getBorder();
112         if (contentBorder == null || contentBorder instanceof UIResource) {
113             contentComp.setBorder( handyEmptyBorder );
114             }
115         }
116   }
117
118     
119   protected JComponent createNorthPane(JInternalFrame w) {
120     titlePane = new MetalInternalFrameTitlePane JavaDoc(w);
121     return titlePane;
122   }
123
124
125   private void setFrameType( String JavaDoc frameType )
126   {
127       if ( frameType.equals( OPTION_DIALOG ) )
128       {
129           LookAndFeel.installBorder(frame, "InternalFrame.optionDialogBorder");
130       titlePane.setPalette( false );
131       }
132       else if ( frameType.equals( PALETTE_FRAME ) )
133       {
134           LookAndFeel.installBorder(frame, "InternalFrame.paletteBorder");
135       titlePane.setPalette( true );
136       }
137       else
138       {
139           LookAndFeel.installBorder(frame, "InternalFrame.border");
140       titlePane.setPalette( false );
141       }
142   }
143
144   // this should be deprecated - jcs
145
public void setPalette(boolean isPalette) {
146     if (isPalette) {
147         LookAndFeel.installBorder(frame, "InternalFrame.paletteBorder");
148     } else {
149         LookAndFeel.installBorder(frame, "InternalFrame.border");
150     }
151     titlePane.setPalette(isPalette);
152
153   }
154
155   private static class MetalPropertyChangeHandler implements
156         PropertyChangeListener JavaDoc
157   {
158       public void propertyChange(PropertyChangeEvent JavaDoc e)
159       {
160       String JavaDoc name = e.getPropertyName();
161           JInternalFrame jif = (JInternalFrame)e.getSource();
162
163           if (!(jif.getUI() instanceof MetalInternalFrameUI JavaDoc)) {
164               return;
165           }
166
167           MetalInternalFrameUI JavaDoc ui = (MetalInternalFrameUI JavaDoc)jif.getUI();
168
169       if ( name.equals( FRAME_TYPE ) )
170       {
171           if ( e.getNewValue() instanceof String JavaDoc )
172           {
173           ui.setFrameType( (String JavaDoc) e.getNewValue() );
174           }
175       }
176       else if ( name.equals( IS_PALETTE ) )
177       {
178           if ( e.getNewValue() != null )
179           {
180               ui.setPalette( ((Boolean JavaDoc)e.getNewValue()).booleanValue() );
181           }
182           else
183           {
184           ui.setPalette( false );
185           }
186       } else if ( name.equals( JInternalFrame.CONTENT_PANE_PROPERTY ) ) {
187               ui.stripContentBorder(e.getNewValue());
188           }
189       }
190   } // end class MetalPropertyChangeHandler
191
}
192
193
Popular Tags