KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > versioning > system > cvss > ui > history > Divider


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.versioning.system.cvss.ui.history;
21
22 import javax.swing.*;
23 import java.awt.event.MouseEvent JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25 import java.awt.event.ActionEvent JavaDoc;
26 import java.awt.*;
27
28 /**
29  * Simple component that displays an arrow.
30  *
31  * @author Maros Sandor
32  */

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 JavaDoc listener;
44
45     private int arrowDirection;
46
47     public Divider(ActionListener JavaDoc 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"); // NOI18N
52
selectedArrowColor = UIManager.getColor("TextField.selectionForeground"); // NOI18N
53
arrowColor = UIManager.getColor("TextField.inactiveForeground"); // NOI18N
54
}
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 JavaDoc 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 JavaDoc(this, DIVIDER_CLICKED, "")); // NOI18N
80
}
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