1 package org.columba.core.gui.base; 2 3 import java.awt.Component ; 4 import java.awt.Container ; 5 import java.awt.Dimension ; 6 import java.awt.Graphics ; 7 import java.awt.Polygon ; 8 import java.awt.Window ; 9 import java.awt.event.MouseAdapter ; 10 import java.awt.event.MouseEvent ; 11 12 import javax.swing.BoxLayout ; 13 import javax.swing.JPanel ; 14 15 public class MoreInfoPanel extends JPanel { 16 17 public Component topComponent; 18 19 protected SpinWidget spinWidget; 20 21 public Component bottomComponent; 22 23 public static final int SPIN_WIDGET_HEIGHT = 14; 24 25 public MoreInfoPanel(Component tc, Component mic) { 26 topComponent = tc; 27 spinWidget = new SpinWidget(); 28 bottomComponent = mic; 29 doMyLayout(); 30 } 31 32 protected void doMyLayout() { 33 setLayout(new BoxLayout (this, BoxLayout.Y_AXIS)); 34 add(topComponent); 35 add(spinWidget); 36 add(bottomComponent); 37 resetBottomVisibility(); 38 } 39 40 protected void resetBottomVisibility() { 41 if ((bottomComponent == null) || (spinWidget == null)) 42 return; 43 bottomComponent.setVisible(spinWidget.isOpen()); 44 revalidate(); 45 if (isShowing()) { 46 Container ancestor = getTopLevelAncestor(); 47 if ((ancestor != null) && (ancestor instanceof Window )) 48 ((Window ) ancestor).pack(); 49 repaint(); 50 } 51 } 52 53 public void showBottom(boolean b) { 54 spinWidget.setOpen(b); 55 } 56 57 public boolean isBottomShowing() { 58 return spinWidget.isOpen(); 59 } 60 61 public class SpinWidget extends JPanel { 62 boolean open; 63 64 Dimension mySize = new Dimension (SPIN_WIDGET_HEIGHT, SPIN_WIDGET_HEIGHT); 65 66 final int HALF_HEIGHT = SPIN_WIDGET_HEIGHT / 2; 67 68 int[] openXPoints = { 1, HALF_HEIGHT, SPIN_WIDGET_HEIGHT - 1 }; 69 70 int[] openYPoints = { HALF_HEIGHT, SPIN_WIDGET_HEIGHT - 1, HALF_HEIGHT }; 71 72 int[] closedXPoints = { 1, 1, HALF_HEIGHT }; 73 74 int[] closedYPoints = { 1, SPIN_WIDGET_HEIGHT - 1, HALF_HEIGHT }; 75 76 Polygon openTriangle = new Polygon (openXPoints, openYPoints, 3); 77 78 Polygon closedTriangle = new Polygon (closedXPoints, closedYPoints, 3); 79 80 public SpinWidget() { 81 setOpen(false); 82 addMouseListener(new MouseAdapter () { 83 public void mouseClicked(MouseEvent e) { 84 handleClick(); 85 } 86 }); 87 } 88 89 public void handleClick() { 90 setOpen(!isOpen()); 91 } 92 93 public boolean isOpen() { 94 return open; 95 } 96 97 public void setOpen(boolean o) { 98 open = o; 99 resetBottomVisibility(); 100 } 101 102 public Dimension getMinimumSize() { 103 return mySize; 104 } 105 106 public Dimension getPreferredSize() { 107 return mySize; 108 } 109 110 public void paint(Graphics g) { 112 if (isOpen()) 113 g.fillPolygon(openTriangle); 114 else 115 g.fillPolygon(closedTriangle); 116 } 117 118 } 119 120 } 121 | Popular Tags |