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