1 package jimm.datavision.gui; 2 import jimm.datavision.gui.cmd.SectionResizeCommand; 3 import java.awt.*; 4 import java.awt.event.*; 5 import javax.swing.*; 6 import javax.swing.event.*; 7 import javax.swing.border.BevelBorder ; 8 9 14 class SectionResizer extends JPanel implements MouseInputListener { 15 16 public static final int HEIGHT = 6; 17 18 protected static final Color BEVEL_HILIGHT = new Color(0xdd, 0xdd, 0xdd); 19 protected static final Color SPLITTER_COLOR = new Color(0x99, 0x99, 0x99); 20 protected static final Color BEVEL_SHADOW = new Color(0x66, 0x66, 0x66); 21 protected static final Color GHOST_COLOR = 22 new Color(0x99, 0x99, 0xff, 0x80); 23 protected static boolean someoneDragging = false; 24 25 protected SectionWidget target; 26 protected Point start; 27 protected int minY; 28 protected Point mousePos; 29 protected JPanel dragGhost; 30 protected int localY; 31 protected JLayeredPane parentWhileDragging; 32 protected int parentWhileDraggingScreenY; 33 protected SectionResizeCommand sectionResizeCommand; 34 35 42 SectionResizer(SectionWidget target, JLayeredPane parentWhileDragging) { 43 super(); 44 this.target = target; 45 this.parentWhileDragging = parentWhileDragging; 46 setBackground(SPLITTER_COLOR); 47 setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED, 48 BEVEL_HILIGHT, BEVEL_SHADOW)); 49 addMouseListener(this); 50 addMouseMotionListener(this); 51 } 52 53 58 public void mouseClicked(MouseEvent e) {} 59 60 65 public void mouseEntered(MouseEvent e) { 66 if (!someoneDragging) 67 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); 68 } 69 70 75 public void mouseExited(MouseEvent e) { 76 if (!someoneDragging) 77 setCursor(null); 78 } 79 80 85 public void mouseMoved(MouseEvent e) {} 86 87 92 public void mousePressed(MouseEvent e) { 93 if (target.designer.isPlacingNewTextField()) { 94 target.designer.rejectNewTextField(); 95 return; 96 } 97 98 mousePos = e.getPoint(); 100 localY = mousePos.y; 101 java.awt.Point screenPos = getLocationOnScreen(); 102 mousePos.translate(screenPos.x, screenPos.y); 103 104 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); 105 someoneDragging = true; 106 107 start = new Point(mousePos); 108 parentWhileDraggingScreenY = 109 parentWhileDragging.getLocationOnScreen().y; 110 minY = target.getLocationOnScreen().y - parentWhileDraggingScreenY 111 + target.getMinSectionHeight(); 112 113 dragGhost = new JPanel(); 114 dragGhost.setBackground(GHOST_COLOR); 115 parentWhileDragging.add(dragGhost, JLayeredPane.DRAG_LAYER); 116 dragGhost.setBounds(0, start.y - localY - parentWhileDraggingScreenY, 117 parentWhileDragging.getWidth(), HEIGHT); 118 119 sectionResizeCommand = new SectionResizeCommand(target); 120 } 121 122 127 public void mouseDragged(MouseEvent e) { 128 java.awt.Point ePos = e.getPoint(); 130 java.awt.Point screenPos = getLocationOnScreen(); 131 ePos.translate(screenPos.x, screenPos.y); 132 133 if (mousePos == null || ePos.y == mousePos.y) 134 return; 136 int newY = ePos.y - localY - parentWhileDraggingScreenY; 137 if (newY < minY) 139 newY = minY; 140 141 dragGhost.setLocation(0, newY); 142 mousePos = ePos; 143 } 144 145 151 public void mouseReleased(MouseEvent e) { 152 someoneDragging = false; 153 154 java.awt.Point ePos = e.getPoint(); 156 java.awt.Point screenPos = getLocationOnScreen(); 157 ePos.translate(screenPos.x, screenPos.y); 158 159 parentWhileDragging.remove(dragGhost); 160 161 target.resizeBy(ePos.y - start.y - localY, sectionResizeCommand); 164 165 parentWhileDragging.repaint(); 168 } 169 170 } 171 | Popular Tags |