KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > usertasks > editors > PercentsPropertyEditor


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.tasklist.usertasks.editors;
21
22 import java.beans.PropertyEditorSupport JavaDoc;
23
24 import javax.swing.JProgressBar JavaDoc;
25 import javax.swing.UIManager JavaDoc;
26 import org.openide.util.Exceptions;
27 import org.openide.util.NbBundle;
28
29 /**
30  * PropertyEditor for percents field.
31  */

32 public class PercentsPropertyEditor extends PropertyEditorSupport JavaDoc {
33     private static String JavaDoc[] TAGS = {
34         "0", "5", "10", "15", "20", "25", "30", "35", "40", "45", "50", // NOI18N
35
"55", "60", "65", "70", "75", "80", "85", "90", "95", "100" // NOI18N
36
};
37
38     private static JProgressBar JavaDoc progressBar;
39     
40     static {
41         progressBar = new JProgressBar JavaDoc();
42         progressBar.setStringPainted(true);
43         progressBar.setBackground(UIManager.getColor("Table.background")); // NOI18N
44
}
45     
46     public boolean isPaintable() {
47         return true;
48     }
49
50     public void paintValue(java.awt.Graphics JavaDoc gfx, java.awt.Rectangle JavaDoc box) {
51         int n = ((Integer JavaDoc) getValue()).intValue();
52         progressBar.setValue(n);
53         progressBar.setString(n + "%"); // NOI18N
54
int height = box.height > 15 ? 15 : box.height;
55         int width = box.width > 100 ? 100 : box.width;
56         int y = (box.height - height) / 2;
57         progressBar.setSize(width, height);
58         
59         gfx.translate(box.x, box.y + y);
60         progressBar.paint(gfx);
61         gfx.translate(-box.x, -box.y - y);
62     }
63     
64     public void setAsText(String JavaDoc text) throws java.lang.IllegalArgumentException JavaDoc {
65         try {
66             setValue(new Integer JavaDoc(text));
67         } catch (NumberFormatException JavaDoc e) {
68             IllegalArgumentException JavaDoc iae =
69                 new java.lang.IllegalArgumentException JavaDoc(
70                     NbBundle.getMessage(PercentsPropertyEditor.class,
71                     "NotANumber")); // NOI18N
72
Exceptions.attachLocalizedMessage(iae, iae.getMessage());
73             throw iae;
74         }
75     }
76     
77     public String JavaDoc[] getTags() {
78         return TAGS;
79     }
80 }
81
Popular Tags