001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Vadim L. Bogdanov
020: * @version $Revision$
021: */package javax.swing.plaf.metal;
022:
023: import java.beans.PropertyChangeEvent;
024: import java.beans.PropertyChangeListener;
025:
026: import javax.swing.JComponent;
027: import javax.swing.JInternalFrame;
028: import javax.swing.LookAndFeel;
029: import javax.swing.plaf.ComponentUI;
030: import javax.swing.plaf.basic.BasicInternalFrameUI;
031:
032: public class MetalInternalFrameUI extends BasicInternalFrameUI {
033: protected static String IS_PALETTE = "JInternalFrame.isPalette";
034:
035: private static String IS_OPTION_DIALOG = "JInternalFrame.optionDialog";
036:
037: private MetalInternalFramePropertyChangeListener metalPropertyChangeListener;
038: private MetalInternalFrameTitlePane titlePane;
039:
040: private class MetalInternalFramePropertyChangeListener implements
041: PropertyChangeListener {
042: public MetalInternalFramePropertyChangeListener() {
043: }
044:
045: public void propertyChange(final PropertyChangeEvent e) {
046: if (IS_PALETTE.equals(e.getPropertyName())) {
047: setPalette(((Boolean) e.getNewValue()).booleanValue());
048: } else if (IS_OPTION_DIALOG.equals(e.getPropertyName())) {
049: setBorder();
050: }
051: }
052: }
053:
054: public MetalInternalFrameUI(final JInternalFrame frame) {
055: super (frame);
056: }
057:
058: protected JComponent createNorthPane(final JInternalFrame f) {
059: titlePane = new MetalInternalFrameTitlePane(f);
060: return titlePane;
061: }
062:
063: protected void uninstallComponents() {
064: // nothing else to do
065: super .uninstallComponents();
066: }
067:
068: protected void installKeyboardActions() {
069: // Note: may be we don't need to call super here
070: // because we don't have menu in title pane
071: super .installKeyboardActions();
072: }
073:
074: protected void uninstallKeyboardActions() {
075: // Note: may be we don't need to call super here
076: // because we don't have menu in title pane
077: super .uninstallKeyboardActions();
078: }
079:
080: protected void installListeners() {
081: super .installListeners();
082:
083: if (metalPropertyChangeListener == null) {
084: metalPropertyChangeListener = new MetalInternalFramePropertyChangeListener();
085: }
086: frame.addPropertyChangeListener(metalPropertyChangeListener);
087: }
088:
089: protected void uninstallListeners() {
090: frame.removePropertyChangeListener(metalPropertyChangeListener);
091:
092: super .uninstallListeners();
093: }
094:
095: public void installUI(final JComponent c) {
096: super .installUI(c);
097:
098: setPalette(isPropertySet(IS_PALETTE));
099: }
100:
101: public void uninstallUI(final JComponent c) {
102: // Note: nothing else?
103: super .uninstallUI(c);
104: }
105:
106: public static ComponentUI createUI(final JComponent c) {
107: return new MetalInternalFrameUI((JInternalFrame) c);
108: }
109:
110: public void setPalette(final boolean b) {
111: titlePane.setPalette(b);
112:
113: setBorder();
114: // the layer isn't changed
115: }
116:
117: private void setBorder() {
118: if (titlePane.isPalette) {
119: LookAndFeel.installBorder(frame,
120: "InternalFrame.paletteBorder");
121: } else if (isPropertySet(IS_OPTION_DIALOG)) {
122: LookAndFeel.installBorder(frame,
123: "InternalFrame.optionDialogBorder");
124: } else {
125: LookAndFeel.installBorder(frame, "InternalFrame.border");
126: }
127: }
128:
129: private boolean isPropertySet(final String propertyName) {
130: Boolean b = (Boolean) frame.getClientProperty(propertyName);
131: return b != null && b.booleanValue();
132: }
133: }
|