1 package org.columba.core.gui.docking; 2 3 import java.awt.BorderLayout ; 4 import java.awt.Color ; 5 import java.awt.Component ; 6 7 import javax.swing.JComponent ; 8 import javax.swing.JPanel ; 9 import javax.swing.UIManager ; 10 11 import org.columba.core.gui.base.ShadowBorder; 12 import org.flexdock.docking.DockingManager; 13 import org.flexdock.docking.DockingStub; 14 15 class DockingPanel extends JPanel implements DockingStub { 16 17 public static Color ACTIVE_MID_COLOR = UIManager.getColor( 18 "Menu.selectionBackground").brighter(); 19 20 public static Color ACTIVE_FILL_COLOR = UIManager 21 .getColor("Menu.selectionBackground"); 22 23 public static Color ACTIVE_START_COLOR = UIManager 24 .getColor("Menu.selectionBackground"); 25 26 public static Color INACTIVE_FILL_COLOR = UIManager.getColor("control"); 27 28 public static Color INACTIVE_MID_COLOR = UIManager.getColor("control"); 29 30 public static Color INACTIVE_START_COLOR = UIManager 31 .getColor("controlHighlight"); 32 33 public static Color INACTIVE_LABEL_COLOR = UIManager 34 .getColor("Menu.selectionForeground"); 35 36 public static Color ACTIVE_LABEL_COLOR = UIManager 37 .getColor("Menu.selectionForeground"); 38 39 protected TitleBar titlebar; 40 41 private JPanel contentPanel; 42 43 private String dockingId; 44 45 public DockingPanel(String id, String title) { 46 super(); 47 48 this.dockingId = id; 49 50 this.titlebar = new TitleBar(title, INACTIVE_MID_COLOR, 51 INACTIVE_FILL_COLOR); 52 53 setLayout(new BorderLayout ()); 54 55 add(this.titlebar, BorderLayout.NORTH); 56 57 contentPanel = new JPanel (); 58 contentPanel.setLayout(new BorderLayout ()); 59 add(contentPanel, BorderLayout.CENTER); 60 61 setContentPane(createContentPane()); 62 63 setBorder(new ShadowBorder()); 64 65 70 } 71 72 public void setActive(boolean active) { 73 74 if (active) { 75 77 titlebar.setMidColor(ACTIVE_MID_COLOR); 78 titlebar.setFillColor(ACTIVE_FILL_COLOR); 79 80 titlebar.setTitleColor(ACTIVE_LABEL_COLOR, ACTIVE_FILL_COLOR, true); 81 } else { 82 titlebar.setMidColor(INACTIVE_MID_COLOR); 83 titlebar.setFillColor(INACTIVE_FILL_COLOR); 84 85 titlebar.setTitleColor(INACTIVE_LABEL_COLOR, 86 INACTIVE_FILL_COLOR, false); 87 } 88 89 contentPanel.repaint(); 90 titlebar.repaint(); 91 } 92 93 public void dock(DockingPanel otherPanel) { 94 DockingManager.dock(otherPanel, this); 95 } 96 97 public void dock(DockingPanel otherPanel, String region) { 98 DockingManager.dock(otherPanel, this, region); 99 } 100 101 public void dock(DockingPanel otherPanel, String region, float ratio) { 102 DockingManager.dock(otherPanel, this, region, ratio); 103 } 104 105 protected JComponent createContentPane() { 106 JPanel panel = new JPanel (); 107 return panel; 108 } 109 110 public String getTitle() { 111 return titlebar.getTitle(); 112 } 113 114 public void setTitle(String title) { 115 titlebar.setTitle(title); 116 } 117 118 public TitleBar getTitleBar() { 119 return titlebar; 120 } 121 122 public void setContentPane(JComponent comp) { 123 contentPanel.removeAll(); 124 125 if (comp != null) 126 contentPanel.add(comp, BorderLayout.CENTER); 127 128 130 } 135 136 public void setTitleBar(JPanel panel) { 137 add(panel, BorderLayout.NORTH); 138 } 139 140 public Component getDragSource() { 141 return getTitleBar(); 142 } 143 144 public Component getFrameDragSource() { 145 return getTitleBar(); 146 } 147 148 public String getPersistentId() { 149 return dockingId; 150 } 151 152 public String getTabText() { 153 return getTitle(); 154 } 155 156 public void updateUI() { 157 super.updateUI(); 158 159 ACTIVE_MID_COLOR = alpha( 160 UIManager.getColor("Menu.selectionBackground"), 200); 161 162 ACTIVE_FILL_COLOR = alpha(UIManager 163 .getColor("Menu.selectionBackground"), 125); 164 165 ACTIVE_START_COLOR = brighter(UIManager 166 .getColor("Menu.selectionBackground")); 167 168 INACTIVE_FILL_COLOR = UIManager.getColor("control"); 169 170 INACTIVE_MID_COLOR = UIManager.getColor("control"); 171 172 INACTIVE_START_COLOR = UIManager.getColor("control"); 173 174 INACTIVE_LABEL_COLOR = UIManager.getColor("Menu.foreground"); 175 176 ACTIVE_LABEL_COLOR = UIManager.getColor("Menu.selectionForeground"); 177 178 } 179 180 public Color alpha(Color c, int alpha) { 181 return new Color (c.getRed(), c.getGreen(), c.getBlue(), alpha); 182 183 } 184 185 private final static double FACTOR = 0.75; 186 187 public Color darker(Color c) { 188 return new Color (Math.max((int) (c.getRed() * FACTOR), 0), Math.max( 189 (int) (c.getGreen() * FACTOR), 0), Math.max( 190 (int) (c.getBlue() * FACTOR), 0)); 191 } 192 193 private Color brighter(Color c) { 194 int r = c.getRed(); 195 int g = c.getGreen(); 196 int b = c.getBlue(); 197 198 return new Color (Math.min((int) (r / FACTOR), 255), Math.min( 199 (int) (g / FACTOR), 255), Math.min((int) (b / FACTOR), 255)); 200 } 201 202 } 203 | Popular Tags |