Source Code Cross Referenced for ComponentHelper.java in  » Science » weka » weka » gui » 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 » weka » weka.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    This program is free software; you can redistribute it and/or modify
003:         *    it under the terms of the GNU General Public License as published by
004:         *    the Free Software Foundation; either version 2 of the License, or
005:         *    (at your option) any later version.
006:         *
007:         *    This program is distributed in the hope that it will be useful,
008:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
009:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
010:         *    GNU General Public License for more details.
011:         *
012:         *    You should have received a copy of the GNU General Public License
013:         *    along with this program; if not, write to the Free Software
014:         *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
015:         */
016:
017:        /*
018:         * ComponentHelper.java
019:         * Copyright (C) 2005 University of Waikato, Hamilton, New Zealand
020:         *
021:         */
022:
023:        package weka.gui;
024:
025:        import java.awt.Component;
026:        import java.awt.Image;
027:        import java.net.URL;
028:
029:        import javax.swing.ImageIcon;
030:        import javax.swing.JOptionPane;
031:
032:        /**
033:         * A helper class for some common tasks with Dialogs, Icons, etc.
034:         *
035:         *
036:         * @author FracPete (fracpete at waikato dot ac dot nz)
037:         * @version $Revision: 1.3 $ 
038:         */
039:
040:        public class ComponentHelper {
041:            /** the default directories for images */
042:            public final static String[] IMAGES = { "weka/gui/",
043:                    "weka/gui/images/" };
044:
045:            /**
046:             * returns the ImageIcon for a given filename and directory, NULL if not successful
047:             * 
048:             * @param dir           the directory to look in for the file
049:             * @param filename      the file to retrieve
050:             * @return              the imageicon if found, otherwise null
051:             */
052:            public static ImageIcon getImageIcon(String dir, String filename) {
053:                URL url;
054:                ImageIcon result;
055:                int i;
056:
057:                result = null;
058:                url = Loader.getURL(dir, filename);
059:
060:                // try to find the image at default locations
061:                if (url == null) {
062:                    for (i = 0; i < IMAGES.length; i++) {
063:                        url = Loader.getURL(IMAGES[i], filename);
064:                        if (url != null)
065:                            break;
066:                    }
067:                }
068:
069:                if (url != null)
070:                    result = new ImageIcon(url);
071:
072:                return result;
073:            }
074:
075:            /**
076:             * returns the ImageIcon for a given filename, NULL if not successful
077:             *
078:             * @param filename      the file to retrieve
079:             * @return              the imageicon if found, otherwise null
080:             */
081:            public static ImageIcon getImageIcon(String filename) {
082:                return getImageIcon("", filename);
083:            }
084:
085:            /**
086:             * returns the Image for a given directory and filename, NULL if not successful
087:             * 
088:             * @param dir           the directory to look in for the file
089:             * @param filename      the file to retrieve
090:             * @return              the image if found, otherwise null
091:             */
092:            public static Image getImage(String dir, String filename) {
093:                ImageIcon img;
094:                Image result;
095:
096:                result = null;
097:                img = getImageIcon(dir, filename);
098:
099:                if (img != null)
100:                    result = img.getImage();
101:
102:                return result;
103:            }
104:
105:            /**
106:             * returns the Image for a given filename, NULL if not successful
107:             * 
108:             * @param filename      the file to retrieve
109:             * @return              the image if found, otherwise null
110:             */
111:            public static Image getImage(String filename) {
112:                ImageIcon img;
113:                Image result;
114:
115:                result = null;
116:                img = getImageIcon(filename);
117:
118:                if (img != null)
119:                    result = img.getImage();
120:
121:                return result;
122:            }
123:
124:            /**
125:             * displays a message box with the given title, message, buttons and icon
126:             * ant the dimension.
127:             * it returns the pressed button.
128:             * @param parent         the parent component 
129:             * @param title          the title of the message box
130:             * @param msg            the text to display
131:             * @param buttons        the captions of the buttons to display
132:             * @param messageType    the type of message like defined in <code>JOptionPane</code> (the icon is determined on this basis)
133:             * @return               the button that was pressed
134:             * @see JOptionPane
135:             */
136:            public static int showMessageBox(Component parent, String title,
137:                    String msg, int buttons, int messageType) {
138:                String icon;
139:
140:                switch (messageType) {
141:                case JOptionPane.ERROR_MESSAGE:
142:                    icon = "weka/gui/images/error.gif";
143:                    break;
144:                case JOptionPane.INFORMATION_MESSAGE:
145:                    icon = "weka/gui/images/information.gif";
146:                    break;
147:                case JOptionPane.WARNING_MESSAGE:
148:                    icon = "weka/gui/images/information.gif";
149:                    break;
150:                case JOptionPane.QUESTION_MESSAGE:
151:                    icon = "weka/gui/images/question.gif";
152:                    break;
153:                default:
154:                    icon = "weka/gui/images/information.gif";
155:                    break;
156:                }
157:
158:                return JOptionPane.showConfirmDialog(parent, msg, title,
159:                        buttons, messageType, getImageIcon(icon));
160:            }
161:
162:            /**
163:             * pops up an input dialog
164:             * 
165:             * @param parent        the parent of this dialog, can be <code>null</code>
166:             * @param title         the title to display, can be <code>null</code>
167:             * @param msg           the message to display
168:             * @param initialValue  the initial value to display as input
169:             * @return              the entered value, or if cancelled <code>null</code>  
170:             */
171:            public static String showInputBox(Component parent, String title,
172:                    String msg, Object initialValue) {
173:                Object result;
174:
175:                if (title == null)
176:                    title = "Input...";
177:
178:                result = JOptionPane.showInputDialog(parent, msg, title,
179:                        JOptionPane.QUESTION_MESSAGE,
180:                        getImageIcon("question.gif"), null, initialValue);
181:
182:                if (result != null)
183:                    return result.toString();
184:                else
185:                    return null;
186:            }
187:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.