KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > abe > RoundExpandCollapseButton


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * RoundExpandCollapseButton.java
22  *
23  * Created on June 19, 2006, 1:00 AM
24  *
25  * To change this template, choose Tools | Template Manager
26  * and open the template in the editor.
27  */

28
29 package org.netbeans.modules.xml.schema.abe;
30
31 import java.awt.Color JavaDoc;
32 import java.awt.Dimension JavaDoc;
33 import java.awt.Graphics JavaDoc;
34 import java.awt.Graphics2D JavaDoc;
35 import java.awt.Image JavaDoc;
36 import java.awt.event.MouseAdapter JavaDoc;
37 import java.awt.event.MouseEvent JavaDoc;
38 import java.net.URL JavaDoc;
39 import javax.swing.JButton JavaDoc;
40
41 /**
42  *
43  * @author girix
44  */

45 public class RoundExpandCollapseButton extends JButton JavaDoc{
46     private static final long serialVersionUID = 7526472295622776147L;
47     public static final int WIDTH = 15;
48     public static final int HEIGHT = 15;
49     boolean mouseOverMe = false;
50     /** Creates a new instance of RoundExpandCollapseButton */
51     public RoundExpandCollapseButton(String JavaDoc str, boolean autoChangeState) {
52         super(str);
53         setOpaque(false);
54         addMouseListener(new MouseAdapter JavaDoc(){
55             public void mouseExited(MouseEvent JavaDoc e) {
56                 super.mouseExited(e);
57                 mouseOverMe = false;
58                 repaint();
59             }
60
61             public void mouseEntered(MouseEvent JavaDoc e) {
62                 super.mouseEntered(e);
63                 mouseOverMe = true;
64                 repaint();
65             }
66             
67         });
68     }
69     
70     public void paint(Graphics JavaDoc g){
71         //super.paintComponent(g);
72
Graphics2D JavaDoc g2d = (Graphics2D JavaDoc) g;
73         //clear stuff drawn by parent
74
//g.clearRect(0, 0, getWidth(), getHeight());
75
//g.setColor(Color.GRAY);
76

77         
78         if (super.getText().equals("+")){
79             //draw >
80
String JavaDoc str = "/org/netbeans/modules/xml/schema/abe/resources/";
81             str += mouseOverMe ? "expandButtonMouseOver.png" : "expandButton.png";
82             str = dragMode ? "/org/netbeans/modules/xml/schema/abe/resources/expandButtonDrag.png" : str;
83             URL JavaDoc url = RoundExpandCollapseButton.class.getResource(str);
84             Image JavaDoc img = new javax.swing.ImageIcon JavaDoc(url).getImage();
85             g2d.drawImage(img, 4, 4, null);
86         }else{
87             //draw <
88
String JavaDoc str = "/org/netbeans/modules/xml/schema/abe/resources/";
89             str += mouseOverMe ? "collapseButtonMouseOver.png" : "collapseButton.png";
90             str = dragMode ? "/org/netbeans/modules/xml/schema/abe/resources/collapseButtonDrag.png" : str;
91             URL JavaDoc url = RoundExpandCollapseButton.class.getResource(str);
92             Image JavaDoc img = new javax.swing.ImageIcon JavaDoc(url).getImage();
93             g2d.drawImage(img, 4, 4, null);
94         }
95         
96         
97         
98         
99     }
100     
101     public Dimension JavaDoc getPreferredSize(){
102         Dimension JavaDoc dim = new Dimension JavaDoc(WIDTH, HEIGHT);
103         return dim;
104     }
105     
106     public Dimension JavaDoc getMinimumSize(){
107         return getPreferredSize();
108     }
109     
110     
111     public Dimension JavaDoc getMaximumSize(){
112         return getPreferredSize();
113     }
114     
115     boolean dragMode = false;
116     public void setDragMode(boolean dragMode){
117         this.dragMode = dragMode;
118         repaint();
119     }
120 }
121
Popular Tags