KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > 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 package org.netbeans.modules.subversion.ui.history;
20
21 import javax.swing.*;
22 import java.awt.Color JavaDoc;
23 import java.awt.Dimension JavaDoc;
24 import java.awt.Graphics JavaDoc;
25 import java.awt.event.ActionListener JavaDoc;
26 import java.awt.event.MouseEvent JavaDoc;
27 import java.awt.event.ActionEvent JavaDoc;
28
29 /**
30  * @author Maros Sandor
31  */

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 JavaDoc bkg;
39     private Color JavaDoc sbkg;
40     private Color JavaDoc arrowColor;
41     private Color JavaDoc selectedArrowColor;
42     private ActionListener JavaDoc listener;
43
44     private int arrowDirection;
45
46     public Divider(ActionListener JavaDoc 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"); // NOI18N
51
selectedArrowColor = UIManager.getColor("TextField.selectionForeground"); // NOI18N
52
arrowColor = UIManager.getColor("TextField.inactiveForeground"); // NOI18N
53
}
54
55     public Dimension JavaDoc getPreferredSize() {
56         return new Dimension JavaDoc(Integer.MAX_VALUE, 6);
57     }
58
59     public Dimension JavaDoc getMaximumSize() {
60         return new Dimension JavaDoc(Integer.MAX_VALUE, 6);
61     }
62
63     public void setArrowDirection(int direction) {
64         arrowDirection = direction;
65     }
66
67     protected void processMouseEvent(MouseEvent JavaDoc 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 JavaDoc(this, DIVIDER_CLICKED, "")); // NOI18N
79
}
80     }
81
82     protected void paintComponent(Graphics JavaDoc g) {
83         super.paintComponent(g);
84         Dimension JavaDoc 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