001: package org.columba.core.gui.docking;
002:
003: import java.awt.BorderLayout;
004: import java.awt.Color;
005: import java.awt.Component;
006:
007: import javax.swing.JComponent;
008: import javax.swing.JPanel;
009: import javax.swing.UIManager;
010:
011: import org.columba.core.gui.base.ShadowBorder;
012: import org.flexdock.docking.DockingManager;
013: import org.flexdock.docking.DockingStub;
014:
015: class DockingPanel extends JPanel implements DockingStub {
016:
017: public static Color ACTIVE_MID_COLOR = UIManager.getColor(
018: "Menu.selectionBackground").brighter();
019:
020: public static Color ACTIVE_FILL_COLOR = UIManager
021: .getColor("Menu.selectionBackground");
022:
023: public static Color ACTIVE_START_COLOR = UIManager
024: .getColor("Menu.selectionBackground");
025:
026: public static Color INACTIVE_FILL_COLOR = UIManager
027: .getColor("control");
028:
029: public static Color INACTIVE_MID_COLOR = UIManager
030: .getColor("control");
031:
032: public static Color INACTIVE_START_COLOR = UIManager
033: .getColor("controlHighlight");
034:
035: public static Color INACTIVE_LABEL_COLOR = UIManager
036: .getColor("Menu.selectionForeground");
037:
038: public static Color ACTIVE_LABEL_COLOR = UIManager
039: .getColor("Menu.selectionForeground");
040:
041: protected TitleBar titlebar;
042:
043: private JPanel contentPanel;
044:
045: private String dockingId;
046:
047: public DockingPanel(String id, String title) {
048: super ();
049:
050: this .dockingId = id;
051:
052: this .titlebar = new TitleBar(title, INACTIVE_MID_COLOR,
053: INACTIVE_FILL_COLOR);
054:
055: setLayout(new BorderLayout());
056:
057: add(this .titlebar, BorderLayout.NORTH);
058:
059: contentPanel = new JPanel();
060: contentPanel.setLayout(new BorderLayout());
061: add(contentPanel, BorderLayout.CENTER);
062:
063: setContentPane(createContentPane());
064:
065: setBorder(new ShadowBorder());
066:
067: // titlebar.setMidColor(INACTIVE_MID_COLOR);
068: // titlebar.setFillColor(INACTIVE_FILL_COLOR);
069: //
070: // titlebar.setTitleColor(INACTIVE_LABEL_COLOR, INACTIVE_MID_COLOR, false);
071:
072: }
073:
074: public void setActive(boolean active) {
075:
076: if (active) {
077: // contentPanel.setBorder(new LineBorder(ACTIVE_BORDER_COLOR, 1));
078:
079: titlebar.setMidColor(ACTIVE_MID_COLOR);
080: titlebar.setFillColor(ACTIVE_FILL_COLOR);
081:
082: titlebar.setTitleColor(ACTIVE_LABEL_COLOR,
083: ACTIVE_FILL_COLOR, true);
084: } else {
085: titlebar.setMidColor(INACTIVE_MID_COLOR);
086: titlebar.setFillColor(INACTIVE_FILL_COLOR);
087:
088: titlebar.setTitleColor(INACTIVE_LABEL_COLOR,
089: INACTIVE_FILL_COLOR, false);
090: }
091:
092: contentPanel.repaint();
093: titlebar.repaint();
094: }
095:
096: public void dock(DockingPanel otherPanel) {
097: DockingManager.dock(otherPanel, this );
098: }
099:
100: public void dock(DockingPanel otherPanel, String region) {
101: DockingManager.dock(otherPanel, this , region);
102: }
103:
104: public void dock(DockingPanel otherPanel, String region, float ratio) {
105: DockingManager.dock(otherPanel, this , region, ratio);
106: }
107:
108: protected JComponent createContentPane() {
109: JPanel panel = new JPanel();
110: return panel;
111: }
112:
113: public String getTitle() {
114: return titlebar.getTitle();
115: }
116:
117: public void setTitle(String title) {
118: titlebar.setTitle(title);
119: }
120:
121: public TitleBar getTitleBar() {
122: return titlebar;
123: }
124:
125: public void setContentPane(JComponent comp) {
126: contentPanel.removeAll();
127:
128: if (comp != null)
129: contentPanel.add(comp, BorderLayout.CENTER);
130:
131: // this.contentPane = comp;
132:
133: // Color color = UIManager.getColor("controlDkShadow");
134: //
135: // if (comp != null)
136: // contentPane.setBorder(new LineBorder(color));
137: }
138:
139: public void setTitleBar(JPanel panel) {
140: add(panel, BorderLayout.NORTH);
141: }
142:
143: public Component getDragSource() {
144: return getTitleBar();
145: }
146:
147: public Component getFrameDragSource() {
148: return getTitleBar();
149: }
150:
151: public String getPersistentId() {
152: return dockingId;
153: }
154:
155: public String getTabText() {
156: return getTitle();
157: }
158:
159: public void updateUI() {
160: super .updateUI();
161:
162: ACTIVE_MID_COLOR = alpha(UIManager
163: .getColor("Menu.selectionBackground"), 200);
164:
165: ACTIVE_FILL_COLOR = alpha(UIManager
166: .getColor("Menu.selectionBackground"), 125);
167:
168: ACTIVE_START_COLOR = brighter(UIManager
169: .getColor("Menu.selectionBackground"));
170:
171: INACTIVE_FILL_COLOR = UIManager.getColor("control");
172:
173: INACTIVE_MID_COLOR = UIManager.getColor("control");
174:
175: INACTIVE_START_COLOR = UIManager.getColor("control");
176:
177: INACTIVE_LABEL_COLOR = UIManager.getColor("Menu.foreground");
178:
179: ACTIVE_LABEL_COLOR = UIManager
180: .getColor("Menu.selectionForeground");
181:
182: }
183:
184: public Color alpha(Color c, int alpha) {
185: return new Color(c.getRed(), c.getGreen(), c.getBlue(), alpha);
186:
187: }
188:
189: private final static double FACTOR = 0.75;
190:
191: public Color darker(Color c) {
192: return new Color(Math.max((int) (c.getRed() * FACTOR), 0), Math
193: .max((int) (c.getGreen() * FACTOR), 0), Math.max(
194: (int) (c.getBlue() * FACTOR), 0));
195: }
196:
197: private Color brighter(Color c) {
198: int r = c.getRed();
199: int g = c.getGreen();
200: int b = c.getBlue();
201:
202: return new Color(Math.min((int) (r / FACTOR), 255), Math.min(
203: (int) (g / FACTOR), 255), Math.min((int) (b / FACTOR),
204: 255));
205: }
206:
207: }
|