1 19 20 package org.netbeans.modules.tasklist.usertasks.editors; 21 22 import java.beans.PropertyEditorSupport ; 23 24 import javax.swing.JProgressBar ; 25 import javax.swing.UIManager ; 26 import org.openide.util.Exceptions; 27 import org.openide.util.NbBundle; 28 29 32 public class PercentsPropertyEditor extends PropertyEditorSupport { 33 private static String [] TAGS = { 34 "0", "5", "10", "15", "20", "25", "30", "35", "40", "45", "50", "55", "60", "65", "70", "75", "80", "85", "90", "95", "100" }; 37 38 private static JProgressBar progressBar; 39 40 static { 41 progressBar = new JProgressBar (); 42 progressBar.setStringPainted(true); 43 progressBar.setBackground(UIManager.getColor("Table.background")); } 45 46 public boolean isPaintable() { 47 return true; 48 } 49 50 public void paintValue(java.awt.Graphics gfx, java.awt.Rectangle box) { 51 int n = ((Integer ) getValue()).intValue(); 52 progressBar.setValue(n); 53 progressBar.setString(n + "%"); 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 text) throws java.lang.IllegalArgumentException { 65 try { 66 setValue(new Integer (text)); 67 } catch (NumberFormatException e) { 68 IllegalArgumentException iae = 69 new java.lang.IllegalArgumentException ( 70 NbBundle.getMessage(PercentsPropertyEditor.class, 71 "NotANumber")); Exceptions.attachLocalizedMessage(iae, iae.getMessage()); 73 throw iae; 74 } 75 } 76 77 public String [] getTags() { 78 return TAGS; 79 } 80 } 81 | Popular Tags |