Source Code Cross Referenced for ConvertTypeDialog.java in  » Content-Management-System » contelligent » de » finix » contelligent » client » gui » directory » 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 » Content Management System » contelligent » de.finix.contelligent.client.gui.directory 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2006 C:1 Financial Services GmbH
003:         *
004:         * This software is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License Version 2.1, as published by the Free Software Foundation.
007:         *
008:         * This software is distributed in the hope that it will be useful,
009:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
010:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011:         * Lesser General Public License for more details.
012:         *
013:         * You should have received a copy of the GNU Lesser General Public
014:         * License along with this library; if not, write to the Free Software
015:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016:         */
017:
018:        package de.finix.contelligent.client.gui.directory;
019:
020:        import java.awt.Color;
021:        import java.awt.Frame;
022:        import java.awt.event.FocusAdapter;
023:        import java.awt.event.FocusEvent;
024:        import java.awt.event.KeyAdapter;
025:        import java.awt.event.KeyEvent;
026:        import java.awt.event.WindowAdapter;
027:        import java.awt.event.WindowEvent;
028:        import java.beans.PropertyChangeEvent;
029:        import java.beans.PropertyChangeListener;
030:        import java.util.Collections;
031:        import java.util.Comparator;
032:        import java.util.Iterator;
033:        import java.util.Vector;
034:        import java.util.logging.Logger;
035:
036:        import javax.swing.JComboBox;
037:        import javax.swing.JLabel;
038:        import javax.swing.JList;
039:        import javax.swing.JOptionPane;
040:        import javax.swing.ListCellRenderer;
041:
042:        import de.finix.contelligent.client.base.Type;
043:        import de.finix.contelligent.client.base.TypeFactory;
044:        import de.finix.contelligent.client.i18n.Resources;
045:        import de.finix.contelligent.client.util.EscapeDialog;
046:
047:        public class ConvertTypeDialog extends EscapeDialog {
048:
049:            private static Logger logger = Logger
050:                    .getLogger(ConvertTypeDialog.class.getName());
051:
052:            private String type = null;
053:
054:            private JComboBox typeBox;
055:
056:            private JOptionPane optionPane;
057:
058:            private String incrementalSearchString = "";
059:
060:            private Vector typeList;
061:
062:            private String packageIdentifier = "";
063:
064:            public ConvertTypeDialog(Frame frame, String preselectedTypeName) {
065:                super (frame, true);
066:
067:                addFocusListener(new FocusAdapter() {
068:                    public void focusGained(FocusEvent e) {
069:                        toFront();
070:                    }
071:                });
072:
073:                setTitle(Resources.getLocalString("convert_type_title"));
074:                JLabel warningLabel = new JLabel(Resources
075:                        .getLocalString("convert_type_message"));
076:
077:                typeList = new Vector(TypeFactory.getInstance()
078:                        .getComposedTypes().values());
079:                Collections.sort(typeList, new Comparator() {
080:                    public int compare(Object o1, Object o2) {
081:                        String s1 = ((Type) o1).getName();
082:                        String s2 = ((Type) o2).getName();
083:                        return (s1.compareToIgnoreCase(s2));
084:                    }
085:
086:                    public boolean equals(Object obj) {
087:                        if (obj == this )
088:                            return true;
089:                        return false;
090:                    }
091:
092:                    public int hashCode() {
093:                        return -1;
094:                    }
095:                });
096:
097:                typeBox = new JComboBox(typeList);
098:                typeBox.setBackground(Color.white);
099:                typeBox.setRenderer(new ComboBoxRenderer());
100:                typeBox.addFocusListener(new FocusAdapter() {
101:                    public void focusLost(FocusEvent e) {
102:                        incrementalSearchString = "";
103:                    }
104:                });
105:
106:                typeBox.addKeyListener(new KeyAdapter() {
107:                    public void keyReleased(KeyEvent e) {
108:                        if (e.getKeyCode() == KeyEvent.VK_DELETE
109:                                || e.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
110:                            if (incrementalSearchString.length() == 1) {
111:                                incrementalSearchString = "";
112:                            } else if (incrementalSearchString.length() > 1) {
113:                                incrementalSearchString = incrementalSearchString
114:                                        .substring(0, incrementalSearchString
115:                                                .length() - 1);
116:                            }
117:                            searchIncremental();
118:                            e.consume();
119:                        } else if (!e.isActionKey() && !e.isControlDown()) {
120:                            char c = e.getKeyChar();
121:                            if (Character.isLetterOrDigit(c)
122:                                    || Character.isSpaceChar(c)) {
123:                                incrementalSearchString = incrementalSearchString
124:                                        + c;
125:                                searchIncremental();
126:                                e.consume();
127:                            }
128:                        }
129:                    }
130:                });
131:                if (preselectedTypeName != null) {
132:                    typeBox
133:                            .setSelectedIndex(findIndexForTypeStartingWith(preselectedTypeName));
134:                }
135:
136:                Object[] array = { warningLabel, typeBox };
137:
138:                optionPane = new JOptionPane(array,
139:                        JOptionPane.QUESTION_MESSAGE,
140:                        JOptionPane.OK_CANCEL_OPTION);
141:
142:                setContentPane(optionPane);
143:                setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
144:
145:                addWindowListener(new WindowAdapter() {
146:                    public void windowClosing(WindowEvent we) {
147:                        /*
148:                         * Instead of directly closing the window, we're going to change
149:                         * the JOptionPane's value property.
150:                         */
151:                        optionPane.setValue(new Integer(
152:                                JOptionPane.CLOSED_OPTION));
153:                    }
154:                });
155:
156:                optionPane
157:                        .addPropertyChangeListener(new PropertyChangeListener() {
158:                            public void propertyChange(PropertyChangeEvent e) {
159:                                String prop = e.getPropertyName();
160:
161:                                if (isVisible()
162:                                        && (e.getSource() == optionPane)
163:                                        && (prop
164:                                                .equals(JOptionPane.VALUE_PROPERTY) || prop
165:                                                .equals(JOptionPane.INPUT_VALUE_PROPERTY))) {
166:                                    Object value = optionPane.getValue();
167:
168:                                    if (value == JOptionPane.UNINITIALIZED_VALUE) {
169:                                        // ignore reset
170:                                        return;
171:                                    }
172:
173:                                    int option = JOptionPane.CANCEL_OPTION;
174:                                    if (value instanceof  Integer) {
175:                                        option = ((Integer) value).intValue();
176:                                    }
177:                                    if (option == JOptionPane.OK_OPTION) {
178:                                        // Check input
179:                                        boolean validName = true;
180:                                        if (validName) {
181:                                            type = ((Type) typeBox
182:                                                    .getSelectedItem())
183:                                                    .getName();
184:                                            setVisible(false);
185:                                        } else {
186:                                            // Reset the JOptionPane's value.
187:                                            // If you don't do this, then if the user
188:                                            // presses the same button next time, no
189:                                            // property change event will be fired.
190:                                            optionPane
191:                                                    .setValue(JOptionPane.UNINITIALIZED_VALUE);
192:                                        }
193:                                    } else { // user closed dialog or clicked cancel
194:                                        type = null;
195:                                        setVisible(false);
196:                                    }
197:                                }
198:                            }
199:                        });
200:            }
201:
202:            public int getOption() {
203:                if (optionPane.getValue() instanceof  Integer
204:                        && ((Integer) optionPane.getValue()).intValue() == JOptionPane.OK_OPTION) {
205:                    return JOptionPane.OK_OPTION;
206:                } else {
207:                    return JOptionPane.CANCEL_OPTION;
208:                }
209:            }
210:
211:            public String getType() {
212:                return type;
213:            }
214:
215:            private void searchIncremental() {
216:                if (typeList != null) {
217:                    if (incrementalSearchString.length() == 0) {
218:                        typeBox.setSelectedIndex(0);
219:                    } else {
220:                        incrementalSearchString = incrementalSearchString
221:                                .toLowerCase();
222:                        typeBox
223:                                .setSelectedIndex(findIndexForTypeStartingWith(incrementalSearchString));
224:                    }
225:                }
226:            }
227:
228:            private int findIndexForTypeStartingWith(String searchString) {
229:                int i = 0;
230:                for (Iterator it = typeList.iterator(); it.hasNext(); i++) {
231:                    Type type = (Type) it.next();
232:                    String name = type.getName();
233:                    if (name.toLowerCase().startsWith(searchString)) {
234:                        typeBox.setSelectedIndex(i);
235:                        return i;
236:                    }
237:                }
238:                return 0;
239:            }
240:
241:            class ComboBoxRenderer extends JLabel implements  ListCellRenderer {
242:
243:                public ComboBoxRenderer() {
244:                    setOpaque(true);
245:                    setHorizontalAlignment(LEFT);
246:                    setVerticalAlignment(CENTER);
247:                }
248:
249:                public java.awt.Component getListCellRendererComponent(
250:                        JList list, Object value, int index,
251:                        boolean isSelected, boolean cellHasFocus) {
252:
253:                    if (isSelected) {
254:                        setBackground(list.getSelectionBackground());
255:                        setForeground(list.getSelectionForeground());
256:                    } else {
257:                        setBackground(Color.white);
258:                        setForeground(list.getForeground());
259:                    }
260:
261:                    Type type = (Type) value;
262:                    setIcon(type.getIcon());
263:                    setText(type.getName());
264:
265:                    return this;
266:                }
267:            }
268:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.