001: /*
002: * Copyright 2005 Patrick Gotthardt
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package com.pagosoft.plaf;
017:
018: import com.pagosoft.swing.ShadowBorder;
019:
020: import javax.swing.*;
021: import javax.swing.border.*;
022: import javax.swing.plaf.*;
023: import javax.swing.plaf.basic.*;
024: import java.awt.*;
025: import java.awt.event.*;
026: import java.beans.PropertyChangeEvent;
027: import java.beans.PropertyChangeListener;
028:
029: public class PgsSplitPaneUI extends BasicSplitPaneUI {
030: public static ComponentUI createUI(JComponent x) {
031: return new PgsSplitPaneUI();
032: }
033:
034: private SplitPaneContainerListener splitPaneContainerListener;
035: private MyPropertyChangeHandler propertyChangeHandler;
036:
037: public void installDefaults() {
038: super .installDefaults();
039:
040: maybeSetShadowBorder(splitPane.getLeftComponent());
041: maybeSetShadowBorder(splitPane.getRightComponent());
042: }
043:
044: public void uninstallDefaults() {
045: super .uninstallDefaults();
046:
047: maybeRemoveShadowBorder(splitPane.getLeftComponent());
048: maybeRemoveShadowBorder(splitPane.getRightComponent());
049: }
050:
051: protected boolean isShadowBorder() {
052: if (splitPane.getClientProperty("pgs.shadowBorder") != null) {
053: return Boolean.TRUE.equals(splitPane
054: .getClientProperty("pgs.shadowBorder"));
055: }
056: return PlafOptions.isShadowBorderUsed();
057: }
058:
059: protected void maybeSetShadowBorder(Component c) {
060: if ((c instanceof JComponent) && isShadowBorder()) {
061: JComponent comp = (JComponent) c;
062: comp.putClientProperty("pgs.savedBorder", comp.getBorder());
063: if (comp.getBorder() instanceof BorderUIResource) {
064: comp.setBorder(ShadowBorder.getInstance());
065: } else {
066: comp.setBorder(BorderFactory.createCompoundBorder(
067: ShadowBorder.getInstance(), comp.getBorder()));
068: }
069: }
070: }
071:
072: protected void maybeRemoveShadowBorder(Component c) {
073: if ((c instanceof JComponent) && !isShadowBorder()) {
074: ((JComponent) c).setBorder((Border) ((JComponent) c)
075: .getClientProperty("pgs.savedBorder"));
076: }
077: }
078:
079: public void installListeners() {
080: super .installListeners();
081: if (splitPaneContainerListener == null) {
082: splitPaneContainerListener = new SplitPaneContainerListener();
083: }
084: if (propertyChangeHandler == null) {
085: propertyChangeHandler = new MyPropertyChangeHandler();
086: }
087: splitPane.addContainerListener(splitPaneContainerListener);
088: splitPane.addPropertyChangeListener("pgs.shadowBorder",
089: propertyChangeHandler);
090: }
091:
092: public void uninstallListeners() {
093: super .uninstallListeners();
094: splitPane.removeContainerListener(splitPaneContainerListener);
095: splitPane.removePropertyChangeListener("pgs.shadowBorder",
096: propertyChangeHandler);
097: }
098:
099: public BasicSplitPaneDivider createDefaultDivider() {
100: return new PgsSplitPaneDivider(this );
101: }
102:
103: protected class SplitPaneContainerListener implements
104: ContainerListener {
105: public void componentAdded(ContainerEvent e) {
106: maybeSetShadowBorder(e.getChild());
107: }
108:
109: public void componentRemoved(ContainerEvent e) {
110: maybeRemoveShadowBorder(e.getChild());
111: }
112: }
113:
114: protected class MyPropertyChangeHandler implements
115: PropertyChangeListener {
116: public void propertyChange(PropertyChangeEvent e) {
117: if (!e.getNewValue().equals(e.getOldValue())) {
118: boolean use;
119: if (e.getOldValue() != null) {
120: use = ((Boolean) e.getOldValue()).booleanValue();
121: } else {
122: use = PlafOptions.isShadowBorderUsed();
123: }
124: if (use) {
125: maybeRemoveShadowBorder(splitPane
126: .getLeftComponent());
127: maybeRemoveShadowBorder(splitPane
128: .getRightComponent());
129: }
130:
131: use = ((Boolean) e.getNewValue()).booleanValue();
132: if (use) {
133: maybeSetShadowBorder(splitPane.getLeftComponent());
134: maybeSetShadowBorder(splitPane.getRightComponent());
135: }
136: }
137: }
138: }
139: }
|