KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > uihandler > SubmitAction


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 package org.netbeans.modules.uihandler;
20
21 import java.awt.AlphaComposite JavaDoc;
22 import java.awt.Color JavaDoc;
23 import java.awt.Component JavaDoc;
24 import java.awt.Graphics2D JavaDoc;
25 import java.awt.RenderingHints JavaDoc;
26 import java.awt.event.ActionEvent JavaDoc;
27 import java.awt.event.ActionListener JavaDoc;
28 import java.awt.geom.Arc2D JavaDoc;
29 import java.awt.geom.Area JavaDoc;
30 import java.awt.image.BufferedImage JavaDoc;
31 import java.beans.PropertyChangeEvent JavaDoc;
32 import java.beans.PropertyChangeListener JavaDoc;
33 import javax.swing.Icon JavaDoc;
34 import javax.swing.ImageIcon JavaDoc;
35 import javax.swing.JButton JavaDoc;
36 import javax.swing.SwingUtilities JavaDoc;
37 import javax.swing.Timer JavaDoc;
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 JavaDoc {
46     
47     public void performAction() {
48         Installer.RP.post(this);
49     }
50     
51     public void run() {
52         Installer.displaySummary("WELCOME_URL", true); // NOI18N
53
}
54     
55     
56     public String JavaDoc getName() {
57         return NbBundle.getMessage(SubmitAction.class, "CTL_SubmitAction");
58     }
59     
60     protected String JavaDoc 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 JavaDoc
73     public Component JavaDoc getToolbarPresenter() {
74         return new NrButton();
75     }
76    
77     private static final class NrButton extends JButton JavaDoc
78     implements PropertyChangeListener JavaDoc, Runnable JavaDoc, ActionListener JavaDoc {
79         private PropertyChangeListener JavaDoc weakL;
80         
81         private ImageIcon JavaDoc tacho;
82         private ImageIcon JavaDoc tachoOk;
83         private Timer JavaDoc timer;
84         
85         public NrButton() {
86             weakL = WeakListeners.propertyChange(this, null);
87             UIHandler.registerCallback(weakL);
88             
89             timer = new Timer JavaDoc(100, this);
90             
91             tacho = new ImageIcon JavaDoc(Utilities.loadImage("org/netbeans/modules/uihandler/tachometer.png"));
92             tachoOk = new ImageIcon JavaDoc(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 JavaDoc 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())); // NOI18N
108
}
109     
110         public void actionPerformed(ActionEvent JavaDoc arg0) {
111             setIcon(tacho);
112             timer.stop();
113         }
114     
115         @Override JavaDoc
116         protected void firePropertyChange(String JavaDoc propertyName, Object JavaDoc oldValue, Object JavaDoc newValue) {
117             if ("PreferredIconSize".equals(propertyName)) { // NOI18N
118
run();
119             }
120             super.firePropertyChange(propertyName, oldValue, newValue);
121         }
122         
123         
124         @Override JavaDoc
125         public void setIcon(Icon JavaDoc original) {
126             int size = 16;
127             Object JavaDoc prop = getClientProperty("PreferredIconSize"); //NOI18N
128

129             if (prop instanceof Integer JavaDoc) {
130                 if (((Integer JavaDoc) prop).intValue() == 24) {
131                     size = 24;
132                 }
133             }
134             
135             
136             BufferedImage JavaDoc img = new BufferedImage JavaDoc(size, size, BufferedImage.TYPE_INT_ARGB);
137             Graphics2D JavaDoc imgG = (Graphics2D JavaDoc) img.getGraphics();
138             imgG.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
139
140             imgG.drawImage(((ImageIcon JavaDoc)original).getImage(), 0, 0, size, size, null);
141             
142             int half = size / 2;
143             final Arc2D JavaDoc bigger = new Arc2D.Double JavaDoc();
144             bigger.setArcByCenter(half, half, half, 90, -(360.0 / 1000.0) * Installer.getLogsSize(), Arc2D.PIE);
145             final Arc2D JavaDoc smaller = new Arc2D.Double JavaDoc();
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 JavaDoc minus = new Area JavaDoc(bigger);
159             minus.subtract(new Area JavaDoc(smaller));
160             imgG.fill(minus);
161             
162             super.setIcon(new ImageIcon JavaDoc(img));
163         }
164     } // end of NrButton
165
}
166
Popular Tags