1 19 package org.netbeans.modules.subversion.ui.history; 20 21 import javax.swing.*; 22 import java.awt.Color ; 23 import java.awt.Dimension ; 24 import java.awt.Graphics ; 25 import java.awt.event.ActionListener ; 26 import java.awt.event.MouseEvent ; 27 import java.awt.event.ActionEvent ; 28 29 32 class Divider extends JPanel { 33 34 public static final int DIVIDER_CLICKED = 1; 35 public static final int DOWN = 0; 36 public static final int UP = 1; 37 38 private Color bkg; 39 private Color sbkg; 40 private Color arrowColor; 41 private Color selectedArrowColor; 42 private ActionListener listener; 43 44 private int arrowDirection; 45 46 public Divider(ActionListener listener) { 47 this.listener = listener; 48 enableEvents(MouseEvent.MOUSE_ENTERED | MouseEvent.MOUSE_EXITED | MouseEvent.MOUSE_CLICKED); 49 bkg = getBackground(); 50 sbkg = UIManager.getColor("TextField.selectionBackground"); selectedArrowColor = UIManager.getColor("TextField.selectionForeground"); arrowColor = UIManager.getColor("TextField.inactiveForeground"); } 54 55 public Dimension getPreferredSize() { 56 return new Dimension (Integer.MAX_VALUE, 6); 57 } 58 59 public Dimension getMaximumSize() { 60 return new Dimension (Integer.MAX_VALUE, 6); 61 } 62 63 public void setArrowDirection(int direction) { 64 arrowDirection = direction; 65 } 66 67 protected void processMouseEvent(MouseEvent e) { 68 super.processMouseEvent(e); 69 if (e.getID() == MouseEvent.MOUSE_ENTERED) { 70 setBackground(sbkg); 71 repaint(); 72 } 73 if (e.getID() == MouseEvent.MOUSE_EXITED) { 74 setBackground(bkg); 75 repaint(); 76 } 77 if (e.getID() == MouseEvent.MOUSE_CLICKED) { 78 listener.actionPerformed(new ActionEvent (this, DIVIDER_CLICKED, "")); } 80 } 81 82 protected void paintComponent(Graphics g) { 83 super.paintComponent(g); 84 Dimension dim = getSize(); 85 if (getBackground().equals(bkg)) { 86 g.setColor(arrowColor); 87 } else { 88 g.setColor(selectedArrowColor); 89 } 90 91 int mid = dim.width / 2; 92 if (arrowDirection == DOWN) { 93 g.drawLine(mid - 4, 1, mid + 4, 1); 94 g.drawLine(mid - 3, 2, mid + 3, 2); 95 g.drawLine(mid - 2, 3, mid + 2, 3); 96 g.drawLine(mid - 1, 4, mid + 1, 4); 97 } 98 else if (arrowDirection == UP) { 99 g.drawLine(mid - 4, 4, mid + 4, 4); 100 g.drawLine(mid - 3, 3, mid + 3, 3); 101 g.drawLine(mid - 2, 2, mid + 2, 2); 102 g.drawLine(mid - 1, 1, mid + 1, 1); 103 } 104 } 105 } 106 | Popular Tags |