Source Code Cross Referenced for NodeStatusButton.java in  » Science » Cougaar12_4 » org » cougaar » tools » csmart » ui » console » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » Cougaar12_4 » org.cougaar.tools.csmart.ui.console 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * <copyright>
003:         *  
004:         *  Copyright 2000-2004 BBNT Solutions, LLC
005:         *  under sponsorship of the Defense Advanced Research Projects
006:         *  Agency (DARPA).
007:         * 
008:         *  You can redistribute this software and/or modify it under the
009:         *  terms of the Cougaar Open Source License as published on the
010:         *  Cougaar Open Source Website (www.cougaar.org).
011:         * 
012:         *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013:         *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014:         *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015:         *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016:         *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017:         *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018:         *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019:         *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020:         *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021:         *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022:         *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023:         *  
024:         * </copyright>
025:         */
026:
027:        package org.cougaar.tools.csmart.ui.console;
028:
029:        import javax.swing.*;
030:        import java.awt.*;
031:        import java.net.URL;
032:        import java.util.Observable;
033:        import java.util.Observer;
034:
035:        public class NodeStatusButton extends JRadioButton implements  Observer {
036:
037:            public static int STATUS_BUSY = 0;
038:            public static int STATUS_HIGH_BUSY = 1;
039:            public static int STATUS_MEDIUM_HIGH_BUSY = 2;
040:            public static int STATUS_MEDIUM_BUSY = 3;
041:            public static int STATUS_MEDIUM_LOW_BUSY = 4;
042:            public static int STATUS_LOW_BUSY = 5;
043:            public static int STATUS_NODE_CREATED = 6;
044:            public static int STATUS_NODE_DESTROYED = 7;
045:            public static int STATUS_NO_ANSWER = 8;
046:            public static int STATUS_UNKNOWN = 9;
047:            public static int STATUS_STD_ERROR = 10;
048:            public static int STATUS_NOTIFY = 11;
049:            public static int STATUS_MAX = 11;
050:
051:            // status button colors
052:            public static Color busyStatus = new Color(230, 255, 230); // shades of green
053:            public static Color highBusyStatus = new Color(175, 255, 175);
054:            public static Color mediumHighBusyStatus = new Color(0, 255, 0);
055:            public static Color mediumBusyStatus = new Color(0, 235, 0);
056:            public static Color mediumLowBusyStatus = new Color(0, 215, 0);
057:            public static Color lowBusyStatus = new Color(0, 195, 0);
058:            public static Color nodeCreatedStatus = new Color(0, 175, 0);
059:            public static Color nodeDestroyedStatus = new Color(215, 0, 0); // red
060:            public static Color noAnswerStatus = new Color(245, 245, 0); // yellow
061:            public static Color unknownStatus = new Color(180, 180, 180); //gray
062:            public static Color[] statusColors = { busyStatus, highBusyStatus,
063:                    mediumHighBusyStatus, mediumBusyStatus,
064:                    mediumLowBusyStatus, lowBusyStatus, nodeCreatedStatus,
065:                    nodeDestroyedStatus, noAnswerStatus, unknownStatus, };
066:
067:            private static String[] descriptions = { "Extremely busy",
068:                    "Very busy", "Busy", "Somewhat busy", "Somewhat idle",
069:                    "Idle", "Node created", "Node destroyed", "No answer",
070:                    "Unknown", };
071:
072:            private Image img = null; // error image
073:            private NodeStatusButtonModel model = new NodeStatusButtonModel();
074:
075:            /**
076:             * Creates a new <code>NodeStatusButton</code> icon.
077:             * @param icon  Icon for this button.
078:             */
079:            public NodeStatusButton(Icon icon) {
080:                super (icon);
081:                model.addObserver(this );
082:            }
083:
084:            /**
085:             * Updates the state of the button, based on the contents of the model.
086:             *
087:             * @param o the Oberved model that caused the change.
088:             * @param arg Unique argument to identify the exact change.
089:             */
090:            public void update(Observable o, Object arg) {
091:                if (arg.equals(model.CLEAR_ERROR_EVENT)) {
092:                    img = null;
093:                    setIcon(new ColoredCircle(statusColors[model.getStatus()],
094:                            20, null));
095:                    setSelectedIcon(new SelectedColoredCircle(
096:                            statusColors[model.getStatus()], 20, null));
097:                }
098:
099:                if (arg.equals(model.NOTIFY_SET_WARNING)) {
100:                    URL iconURL = getClass().getResource("Bang.gif");
101:                    if (iconURL != null) {
102:                        ImageIcon icon = new ImageIcon(iconURL);
103:                        img = icon.getImage();
104:                    }
105:                }
106:
107:                if (arg.equals(model.NOTIFY_EVENT)) {
108:                    Color statusColor = statusColors[model.getStatus()];
109:                    setIcon(new ColoredCircle(statusColor, 20, img));
110:                    setSelectedIcon(new SelectedColoredCircle(statusColor, 20,
111:                            img));
112:                    String s = getToolTipText(null);
113:                    if (s != null) {
114:                        int index = s.lastIndexOf("), ");
115:                        if (index != -1) {
116:                            s = s.substring(0, index + 3)
117:                                    + descriptions[model.getStatus()];
118:                            setToolTipText(s);
119:                        }
120:                    }
121:                }
122:            }
123:
124:            /**
125:             * Gets a list of all Status Descriptions.
126:             *
127:             * @return <code>String</code> array of all descriptions.
128:             */
129:            public static String[] getStatusDescriptions() {
130:                return descriptions;
131:            }
132:
133:            /**
134:             * Get a list of all possible status colors.
135:             * @return array of <code>Color</code>s
136:             */
137:            public static Color[] getStatusColors() {
138:                return statusColors;
139:            }
140:
141:            /**
142:             * Gets a handle to the model for this button.
143:             *
144:             * @return <code>NodeStatusButtonModel</code> object
145:             */
146:            public NodeStatusButtonModel getMyModel() {
147:                return model;
148:            }
149:
150:            public class NodeStatusButtonModel extends Observable {
151:
152:                public String CLEAR_ERROR_EVENT = "Clear";
153:                public String NOTIFY_SET_WARNING = "Warning";
154:                public String NOTIFY_EVENT = "Notify";
155:
156:                private int status = STATUS_UNKNOWN;
157:                private boolean notifyOnStandardError = false;
158:
159:                public NodeStatusButtonModel() {
160:                }
161:
162:                /**
163:                 * Gets the current status of the button.
164:                 *
165:                 * @return current status
166:                 */
167:                public int getStatus() {
168:                    return this .status;
169:                }
170:
171:                /**
172:                 * Sets the current status of the button
173:                 *
174:                 * @param newStatus -- The new status
175:                 */
176:                public void setStatus(int newStatus) {
177:                    if (newStatus < 0 || newStatus > STATUS_MAX)
178:                        return; // invalid status
179:                    // if there's an error, add the warning icon
180:                    if (newStatus == STATUS_NOTIFY
181:                            || (newStatus == STATUS_STD_ERROR && notifyOnStandardError)) {
182:                        setChanged();
183:                        notifyObservers(NOTIFY_SET_WARNING);
184:                    } else if (newStatus != STATUS_STD_ERROR) {
185:                        status = newStatus;
186:                    }
187:                    setChanged();
188:                    notifyObservers(NOTIFY_EVENT);
189:                }
190:
191:                /**
192:                 * Gets the description for the current status
193:                 *
194:                 * @return Current status description
195:                 */
196:                public String getStatusDescription() {
197:                    return descriptions[status];
198:                }
199:
200:                /**
201:                 * Remove error icon from the button.
202:                 */
203:                public void clearError() {
204:                    setChanged();
205:                    notifyObservers(CLEAR_ERROR_EVENT);
206:                }
207:
208:                /**
209:                 * Set whether to display warning icon when output is received on standard error.
210:                 *
211:                 * @param notifyOnStandardError  - State to set.
212:                 */
213:                public void setNotifyOnStandardError(
214:                        boolean notifyOnStandardError) {
215:                    this .notifyOnStandardError = notifyOnStandardError;
216:                }
217:
218:                /**
219:                 * Get the current state of the NotifyOnStandardError flag.
220:                 *
221:                 * @return Current state of NotifyOnStandardError
222:                 */
223:                public boolean getNotifyOnStandardError() {
224:                    return notifyOnStandardError;
225:                }
226:            }
227:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.