1 19 package org.netbeans.modules.uihandler; 20 21 import java.awt.AlphaComposite ; 22 import java.awt.Color ; 23 import java.awt.Component ; 24 import java.awt.Graphics2D ; 25 import java.awt.RenderingHints ; 26 import java.awt.event.ActionEvent ; 27 import java.awt.event.ActionListener ; 28 import java.awt.geom.Arc2D ; 29 import java.awt.geom.Area ; 30 import java.awt.image.BufferedImage ; 31 import java.beans.PropertyChangeEvent ; 32 import java.beans.PropertyChangeListener ; 33 import javax.swing.Icon ; 34 import javax.swing.ImageIcon ; 35 import javax.swing.JButton ; 36 import javax.swing.SwingUtilities ; 37 import javax.swing.Timer ; 38 import org.openide.util.HelpCtx; 39 import org.openide.util.NbBundle; 40 import org.openide.util.Utilities; 41 import org.openide.util.WeakListeners; 42 import org.openide.util.actions.CallableSystemAction; 43 44 public final class SubmitAction extends CallableSystemAction 45 implements Runnable { 46 47 public void performAction() { 48 Installer.RP.post(this); 49 } 50 51 public void run() { 52 Installer.displaySummary("WELCOME_URL", true); } 54 55 56 public String getName() { 57 return NbBundle.getMessage(SubmitAction.class, "CTL_SubmitAction"); 58 } 59 60 protected String iconResource() { 61 return "org/netbeans/modules/uihandler/project.png"; 62 } 63 64 public HelpCtx getHelpCtx() { 65 return HelpCtx.DEFAULT_HELP; 66 } 67 68 protected boolean asynchronous() { 69 return false; 70 } 71 72 @Override 73 public Component getToolbarPresenter() { 74 return new NrButton(); 75 } 76 77 private static final class NrButton extends JButton 78 implements PropertyChangeListener , Runnable , ActionListener { 79 private PropertyChangeListener weakL; 80 81 private ImageIcon tacho; 82 private ImageIcon tachoOk; 83 private Timer timer; 84 85 public NrButton() { 86 weakL = WeakListeners.propertyChange(this, null); 87 UIHandler.registerCallback(weakL); 88 89 timer = new Timer (100, this); 90 91 tacho = new ImageIcon (Utilities.loadImage("org/netbeans/modules/uihandler/tachometer.png")); 92 tachoOk = new ImageIcon (Utilities.loadImage("org/netbeans/modules/uihandler/tachometer-ok.png")); 93 setIcon(tacho); 94 setToolTipText(NbBundle.getMessage(SubmitAction.class, "CTL_SubmitAction")); 95 96 addActionListener(SubmitAction.get(SubmitAction.class)); 97 } 98 99 public void propertyChange(PropertyChangeEvent arg0) { 100 SwingUtilities.invokeLater(this); 101 } 102 103 public void run() { 104 setIcon(tachoOk); 105 timer.restart(); 106 107 setToolTipText(NbBundle.getMessage(SubmitAction.class, "MSG_SubmitAction", Installer.getLogsSize())); } 109 110 public void actionPerformed(ActionEvent arg0) { 111 setIcon(tacho); 112 timer.stop(); 113 } 114 115 @Override 116 protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { 117 if ("PreferredIconSize".equals(propertyName)) { run(); 119 } 120 super.firePropertyChange(propertyName, oldValue, newValue); 121 } 122 123 124 @Override 125 public void setIcon(Icon original) { 126 int size = 16; 127 Object prop = getClientProperty("PreferredIconSize"); 129 if (prop instanceof Integer ) { 130 if (((Integer ) prop).intValue() == 24) { 131 size = 24; 132 } 133 } 134 135 136 BufferedImage img = new BufferedImage (size, size, BufferedImage.TYPE_INT_ARGB); 137 Graphics2D imgG = (Graphics2D ) img.getGraphics(); 138 imgG.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 139 140 imgG.drawImage(((ImageIcon )original).getImage(), 0, 0, size, size, null); 141 142 int half = size / 2; 143 final Arc2D bigger = new Arc2D.Double (); 144 bigger.setArcByCenter(half, half, half, 90, -(360.0 / 1000.0) * Installer.getLogsSize(), Arc2D.PIE); 145 final Arc2D smaller = new Arc2D.Double (); 146 smaller.setArcByCenter(half, half, size == 24 ? 5.0 : 3.0, 0, 360, Arc2D.PIE); 147 148 int s = Installer.getLogsSize(); 149 if (s < 800) { 150 imgG.setColor(Color.RED.darker().darker()); 151 } else if (s < 990) { 152 imgG.setColor(Color.ORANGE); 153 } else { 154 imgG.setColor(Color.RED); 155 } 156 imgG.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); 157 158 Area minus = new Area (bigger); 159 minus.subtract(new Area (smaller)); 160 imgG.fill(minus); 161 162 super.setIcon(new ImageIcon (img)); 163 } 164 } } 166 | Popular Tags |