1 package org.columba.core.gui.docking; 2 3 import java.awt.BorderLayout ; 4 import java.awt.Color ; 5 import java.awt.Component ; 6 import java.awt.Graphics ; 7 import java.awt.Graphics2D ; 8 import java.awt.event.ActionEvent ; 9 import java.beans.PropertyChangeEvent ; 10 import java.beans.PropertyChangeListener ; 11 12 import javax.swing.AbstractAction ; 13 import javax.swing.ImageIcon ; 14 import javax.swing.JButton ; 15 import javax.swing.JComponent ; 16 import javax.swing.JPopupMenu ; 17 import javax.swing.UIManager ; 18 19 import org.flexdock.docking.DockingManager; 20 import org.flexdock.docking.defaults.AbstractDockable; 21 import org.flexdock.util.DockingUtility; 22 23 public class DockableView extends AbstractDockable implements 24 PropertyChangeListener { 25 26 public static Color INACTIVE_LABEL_COLOR = UIManager 27 .getColor("Menu.foreground"); 28 29 public static Color ACTIVE_LABEL_COLOR = UIManager 30 .getColor("Menu.selectionForeground"); 31 32 private DockingPanel panel; 33 34 private JComponent dragInitiator; 35 36 private TitleBar titleBar; 37 38 private JPopupMenu menu; 39 40 protected JButton menuButton; 41 42 public DockableView(String id, String title) { 43 super(id); 44 45 panel = new DockingPanel(id, title); 46 47 titleBar = panel.getTitleBar(); 48 49 menuButton = titleBar.addButton(new MenuIcon(), new MenuAction(this 50 .getPersistentId()), BorderLayout.WEST); 51 titleBar.addButton(new CloseIcon(), new CloseAction(this 56 .getPersistentId()), BorderLayout.EAST); 57 58 dragInitiator = panel.getTitleBar(); 59 setTabText(panel.getTitle()); 60 61 getDragSources().add(dragInitiator); 62 getFrameDragSources().add(dragInitiator); 63 64 DockingManager.registerDockable(this); 65 DockableRegistry.getInstance().register(this); 66 67 addPropertyChangeListener(this); 68 } 69 70 public void setPopupMenu(final JPopupMenu menu) { 71 if (menu == null) 72 throw new IllegalArgumentException ("menu == null"); 73 74 this.menu = menu; 75 } 76 77 public boolean isActive() { 78 return getDockingProperties().isActive().booleanValue(); 79 } 80 81 public void setTitle(String title) { 82 TitleBar titleBar = (TitleBar) panel.getTitleBar(); 83 titleBar.setTitle(title); 84 } 85 86 public String getTitle() { 87 TitleBar titleBar = (TitleBar) panel.getTitleBar(); 88 return titleBar.getTitle(); 89 } 90 91 public void setContentPane(JComponent c) { 92 this.panel.setContentPane(c); 93 94 } 95 96 public Component getComponent() { 97 return panel; 98 } 99 100 class MenuAction extends AbstractAction { 101 String id; 102 103 MenuAction(String id) { 104 this.id = id; 105 106 putValue(AbstractAction.NAME, "m"); 107 } 108 109 public void actionPerformed(ActionEvent e) { 110 if ( menu != null) 113 menu.show(menuButton, 0, menuButton.getHeight()); 114 115 } 117 } 118 119 class CloseAction extends AbstractAction { 120 String id; 121 122 CloseAction(String id) { 123 this.id = id; 124 125 putValue(AbstractAction.NAME, "x"); 126 } 127 128 public void actionPerformed(ActionEvent e) { 129 DockingManager.close(DockableView.this); 130 } 131 } 132 133 class MaximizeAction extends AbstractAction { 134 String id; 135 136 MaximizeAction(String id) { 137 this.id = id; 138 139 putValue(AbstractAction.NAME, "m"); 140 } 141 142 public void actionPerformed(ActionEvent e) { 143 } 145 } 146 147 class PinAction extends AbstractAction { 148 String id; 149 150 PinAction(String id) { 151 this.id = id; 152 153 putValue(AbstractAction.NAME, "P"); 154 155 } 156 157 public void actionPerformed(ActionEvent e) { 158 boolean minimize = DockingUtility.isMinimized(DockableView.this) ? false 159 : true; 160 DockingManager.setMinimized(DockableView.this, minimize); 161 162 } 163 } 164 165 public void propertyChange(PropertyChangeEvent evt) { 166 167 panel.setActive(isActive()); 168 169 } 170 171 class CloseIcon extends ImageIcon { 172 173 private CloseIcon() { 174 super(); 175 } 176 177 public void paintIcon(Component c, Graphics g, int x, int y) { 178 Graphics2D g2 = (Graphics2D ) g; 179 180 int w = c.getWidth(); 181 int h = c.getHeight(); 182 183 if (isActive()) 184 g2.setColor(ACTIVE_LABEL_COLOR); 185 else 186 g2.setColor(INACTIVE_LABEL_COLOR); 187 188 g2.drawLine(x + 2, y + 2, w - 4, h - 4); 189 g2.drawLine(w - 4, y + 2, x + 2, h - 4); 190 191 } 192 193 196 public int getIconHeight() { 197 return 6; 198 } 199 200 203 public int getIconWidth() { 204 return 6; 205 } 206 207 } 208 209 class PinIcon extends ImageIcon { 210 211 private PinIcon() { 212 super(); 213 } 214 215 public void paintIcon(Component c, Graphics g, int x, int y) { 216 Graphics2D g2 = (Graphics2D ) g; 217 218 if (isActive()) 219 g2.setColor(ACTIVE_LABEL_COLOR); 220 else 221 g2.setColor(INACTIVE_LABEL_COLOR); 222 g2.drawRect(3, 2, 4, 4); 223 224 g2.drawLine(2, 2 + 4, 2 + 4 + 2, 2 + 4); 225 g2.drawLine(5, 6, 5, 8); 226 227 } 228 229 232 public int getIconHeight() { 233 return 8; 234 } 235 236 239 public int getIconWidth() { 240 return 8; 241 } 242 243 } 244 245 class MaximizeIcon extends ImageIcon { 246 247 private MaximizeIcon() { 248 super(); 249 } 250 251 public void paintIcon(Component c, Graphics g, int x, int y) { 252 Graphics2D g2 = (Graphics2D ) g; 253 254 255 256 if (isActive()) 257 g2.setColor(ACTIVE_LABEL_COLOR); 258 else 259 g2.setColor(INACTIVE_LABEL_COLOR); 260 g2.drawRect(2, 3, 5, 5); 261 262 g2.drawLine(3 + 1, 1, 3 + 6, 1); 263 g2.drawLine(3 + 6, 1, 3 + 6, 1 + 6 - 1); 264 265 } 266 267 270 public int getIconHeight() { 271 return 8; 272 } 273 274 277 public int getIconWidth() { 278 return 8; 279 } 280 281 } 282 283 class MenuIcon extends ImageIcon { 284 285 private MenuIcon() { 286 super(); 287 } 288 289 public void paintIcon(Component c, Graphics g, int x, int y) { 290 Graphics2D g2 = (Graphics2D ) g; 291 292 int[] xp = new int[3]; 293 int[] yp = new int[3]; 294 295 int w = c.getWidth(); 296 int h = c.getHeight(); 297 298 xp[0] = x + 1; 299 xp[1] = x + w - 3; 300 xp[2] = x + 1 + 4; 301 302 yp[0] = y + 3; 303 yp[1] = y + 3; 304 yp[2] = y + 3 + (int) (h - 1) / 2 - 1; 305 306 if (isActive()) 307 g2.setColor(ACTIVE_LABEL_COLOR); 308 else 309 g2.setColor(INACTIVE_LABEL_COLOR); 310 g2.drawPolygon(xp, yp, 3); 311 312 } 313 314 317 public int getIconHeight() { 318 return 6; 319 } 320 321 324 public int getIconWidth() { 325 return 10; 326 } 327 328 } 329 330 } 331 | Popular Tags |