Source Code Cross Referenced for XMLCParameterViewer.java in  » J2EE » enhydra-IDE-plugin » org » enhydra » kelp » common » properties » 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 » J2EE » enhydra IDE plugin » org.enhydra.kelp.common.properties 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Enhydra Java Application Server Project
003:         *
004:         * The contents of this file are subject to the Enhydra Public License
005:         * Version 1.1 (the "License"); you may not use this file except in
006:         * compliance with the License. You may obtain a copy of the License on
007:         * the Enhydra web site ( http://www.enhydra.org/ ).
008:         *
009:         * Software distributed under the License is distributed on an "AS IS"
010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011:         * the License for the specific terms governing rights and limitations
012:         * under the License.
013:         *
014:         * The Initial Developer of the Enhydra Application Server is Lutris
015:         * Technologies, Inc. The Enhydra Application Server and portions created
016:         * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017:         * All Rights Reserved.
018:         *
019:         * Contributor(s):
020:         *
021:         */
022:        package org.enhydra.kelp.common.properties;
023:
024:        // ToolBox imports
025:        import org.enhydra.tool.common.DialogPanel;
026:        import org.enhydra.tool.common.SwingUtil;
027:
028:        // Kelp imports
029:        import org.enhydra.kelp.common.PropUtil;
030:
031:        // Standard imports
032:        import java.awt.*;
033:        import java.awt.event.ActionEvent;
034:        import java.awt.event.ActionListener;
035:        import java.beans.Beans;
036:        import java.util.Vector;
037:        import javax.swing.*;
038:        import javax.swing.event.ListSelectionEvent;
039:        import javax.swing.event.ListSelectionListener;
040:        import java.util.ResourceBundle;
041:
042:        //
043:        public class XMLCParameterViewer extends DialogPanel {
044:
045:            //
046:            static ResourceBundle res = ResourceBundle
047:                    .getBundle("org.enhydra.kelp.common.Res"); // nores
048:            private DefaultListModel listModel = null;
049:            private LocalListListener listListener = null;
050:            private LocalButtonListener buttonListener = null;
051:            private BorderLayout layoutRoot = null;
052:            private GridBagLayout layoutTab = null;
053:            private GridBagLayout layoutEdit = null;
054:            private GridBagLayout layoutControl = null;
055:            private JTabbedPane tab = null;
056:            private JPanel panelTab = null;
057:            private JPanel panelEdit = null;
058:            private JPanel panelControl = null;
059:            private JButton buttonAdd = null;
060:            private JButton buttonEdit = null;
061:            private JButton buttonRemove = null;
062:            private JButton buttonUp = null;
063:            private JButton buttonDown = null;
064:            private JButton buttonOK = null;
065:            private JButton buttonCancel = null;
066:            private JScrollPane scroll = null;
067:            private JList list = null;
068:
069:            public static void main(String[] args) {
070:                SwingUtil.setLookAndFeelToSystem();
071:                XMLCParameterViewer viewer = null;
072:
073:                viewer = new XMLCParameterViewer();
074:                viewer.showDialog();
075:                System.exit(0);
076:            }
077:
078:            public XMLCParameterViewer() {
079:                try {
080:                    jbInit();
081:                    pmInit();
082:                } catch (Exception ex) {
083:                    ex.printStackTrace();
084:                }
085:            }
086:
087:            public String getParameters() {
088:                String out = new String();
089:                String[] params = new String[0];
090:
091:                params = new String[listModel.getSize()];
092:                for (int i = 0; i < params.length; i++) {
093:                    params[i] = listModel.getElementAt(i).toString();
094:                }
095:                params = PropUtil.cleanXMLCParameters(params);
096:                out = PropUtil.XMLCParametersToString(params);
097:                return out;
098:            }
099:
100:            public void setParameters(String paramLine) {
101:                String[] params = new String[0];
102:
103:                params = PropUtil.XMLCParametersToArray(paramLine);
104:                params = PropUtil.cleanXMLCParameters(params);
105:                listModel.removeAllElements();
106:                for (int i = 0; i < params.length; i++) {
107:                    listModel.addElement(params[i]);
108:                }
109:                list.setModel(listModel);
110:                list.updateUI();
111:            }
112:
113:            //
114:            //
115:            protected void clearDialog() {
116:                super .clearDialog();
117:            }
118:
119:            //
120:            //
121:            private void refreshEditButtons() {
122:                int index = list.getSelectedIndex();
123:
124:                buttonRemove.setEnabled(index > -1);
125:                buttonEdit.setEnabled(index > -1);
126:                buttonUp.setEnabled(index > 0);
127:                buttonDown.setEnabled((index > -1)
128:                        && (index < (listModel.getSize() - 1)));
129:            }
130:
131:            private void removeSelection() {
132:                int index = list.getSelectedIndex();
133:
134:                if (index > -1) {
135:                    listModel.removeElementAt(index);
136:                }
137:            }
138:
139:            private void moveSelection(int direction) {
140:                int index = list.getSelectedIndex();
141:
142:                if (index > -1) {
143:                    String selection = null;
144:
145:                    selection = listModel.getElementAt(index).toString();
146:                    listModel.removeElementAt(index);
147:                    listModel.insertElementAt(selection, index + direction);
148:                }
149:            }
150:
151:            private void add() {
152:                XMLCParameterEditor editor = null;
153:                String selection = new String();
154:
155:                editor = new XMLCParameterEditor();
156:                if (showEditor(editor) == XMLCParameterEditor.OK_OPTION) {
157:                    selection = editor.getParameter();
158:                    if (selection.trim().length() > 0) {
159:                        listModel.addElement(selection);
160:                        list.setSelectedIndex(listModel.getSize() - 1);
161:                    }
162:                }
163:            }
164:
165:            private void editSelection() {
166:                XMLCParameterEditor editor = null;
167:                int index = list.getSelectedIndex();
168:
169:                if (index > -1) {
170:                    String selection = null;
171:
172:                    selection = listModel.getElementAt(index).toString();
173:                    editor = new XMLCParameterEditor();
174:                    editor.setParameter(selection);
175:                    if (showEditor(editor) == XMLCParameterEditor.OK_OPTION) {
176:                        selection = editor.getParameter();
177:                        listModel.setElementAt(selection, index);
178:                    }
179:                }
180:            }
181:
182:            private int showEditor(XMLCParameterEditor editor) {
183:                int option = XMLCParameterEditor.CANCEL_OPTION;
184:
185:                editor.setOwner((Window) getTopLevelAncestor());
186:                editor.setModal(true);
187:                return editor.showDialog();
188:            }
189:
190:            private void pmInit() {
191:                listModel = new DefaultListModel();
192:                listListener = new LocalListListener();
193:                buttonListener = new LocalButtonListener();
194:                list.addListSelectionListener(listListener);
195:                list.requestDefaultFocus();
196:                list.setModel(listModel);
197:                list.setCellRenderer(new ToolTipCellRenderer());
198:                list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
199:                buttonAdd.addActionListener(buttonListener);
200:                buttonEdit.addActionListener(buttonListener);
201:                buttonRemove.addActionListener(buttonListener);
202:                buttonUp.addActionListener(buttonListener);
203:                buttonDown.addActionListener(buttonListener);
204:                buttonOK.addActionListener(buttonListener);
205:                buttonCancel.addActionListener(buttonListener);
206:                refreshEditButtons();
207:                setTitle(res.getString("XMLC_Parameters"));
208:                setModal(true);
209:            }
210:
211:            private void jbInit() throws Exception {
212:                layoutRoot = (BorderLayout) Beans.instantiate(getClass()
213:                        .getClassLoader(), BorderLayout.class.getName());
214:                layoutTab = (GridBagLayout) Beans.instantiate(getClass()
215:                        .getClassLoader(), GridBagLayout.class.getName());
216:                layoutEdit = (GridBagLayout) Beans.instantiate(getClass()
217:                        .getClassLoader(), GridBagLayout.class.getName());
218:                layoutControl = (GridBagLayout) Beans.instantiate(getClass()
219:                        .getClassLoader(), GridBagLayout.class.getName());
220:                tab = (JTabbedPane) Beans.instantiate(getClass()
221:                        .getClassLoader(), JTabbedPane.class.getName());
222:                panelTab = (JPanel) Beans.instantiate(getClass()
223:                        .getClassLoader(), JPanel.class.getName());
224:                panelEdit = (JPanel) Beans.instantiate(getClass()
225:                        .getClassLoader(), JPanel.class.getName());
226:                panelControl = (JPanel) Beans.instantiate(getClass()
227:                        .getClassLoader(), JPanel.class.getName());
228:                buttonAdd = (JButton) Beans.instantiate(getClass()
229:                        .getClassLoader(), JButton.class.getName());
230:                buttonEdit = (JButton) Beans.instantiate(getClass()
231:                        .getClassLoader(), JButton.class.getName());
232:                buttonRemove = (JButton) Beans.instantiate(getClass()
233:                        .getClassLoader(), JButton.class.getName());
234:                buttonUp = (JButton) Beans.instantiate(getClass()
235:                        .getClassLoader(), JButton.class.getName());
236:                buttonDown = (JButton) Beans.instantiate(getClass()
237:                        .getClassLoader(), JButton.class.getName());
238:                list = (JList) Beans.instantiate(getClass().getClassLoader(),
239:                        JList.class.getName());
240:                buttonOK = (JButton) Beans.instantiate(getClass()
241:                        .getClassLoader(), JButton.class.getName());
242:                buttonCancel = (JButton) Beans.instantiate(getClass()
243:                        .getClassLoader(), JButton.class.getName());
244:                buttonAdd.setPreferredSize(new Dimension(100, 27));
245:                buttonAdd.setMnemonic('A');
246:                buttonAdd.setText(res.getString("buttonAdd_Text"));
247:                buttonEdit.setPreferredSize(new Dimension(100, 27));
248:                buttonEdit.setMnemonic('E');
249:                buttonEdit.setText(res.getString("Edit"));
250:                buttonRemove.setPreferredSize(new Dimension(100, 27));
251:                buttonRemove.setMnemonic('R');
252:                buttonRemove.setText(res.getString("Remove"));
253:                buttonUp.setPreferredSize(new Dimension(100, 27));
254:                buttonUp.setMnemonic('U');
255:                buttonUp.setText(res.getString("buttonUp_Text"));
256:                buttonDown.setPreferredSize(new Dimension(100, 27));
257:                buttonDown.setMnemonic('D');
258:                buttonDown.setText(res.getString("buttonDown_Text"));
259:                buttonOK.setPreferredSize(new Dimension(100, 27));
260:                buttonOK.setText(res.getString("OK"));
261:                buttonOK.setDefaultCapable(true);
262:                buttonCancel.setPreferredSize(new Dimension(100, 27));
263:                buttonCancel.setText(res.getString("Cancel"));
264:                scroll = new JScrollPane(list);
265:                panelEdit.setLayout(layoutEdit);
266:                tab.setPreferredSize(new Dimension(400, 300));
267:                panelEdit.add(buttonAdd, new GridBagConstraints(0, 0, 1, 1,
268:                        0.0, 0.0, GridBagConstraints.CENTER,
269:                        GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
270:                panelEdit.add(buttonEdit, new GridBagConstraints(0, 1, 1, 1,
271:                        0.0, 0.0, GridBagConstraints.CENTER,
272:                        GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
273:                panelEdit
274:                        .add(buttonRemove, new GridBagConstraints(0, 2, 1, 1,
275:                                0.0, 0.0, GridBagConstraints.CENTER,
276:                                GridBagConstraints.NONE,
277:                                new Insets(5, 5, 20, 5), 0, 0));
278:                panelEdit
279:                        .add(buttonUp, new GridBagConstraints(0, 3, 1, 1, 0.0,
280:                                0.0, GridBagConstraints.CENTER,
281:                                GridBagConstraints.NONE,
282:                                new Insets(20, 5, 5, 5), 0, 0));
283:                panelEdit.add(buttonDown, new GridBagConstraints(0, 4, 1, 1,
284:                        0.0, 0.0, GridBagConstraints.CENTER,
285:                        GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
286:                panelTab.setLayout(layoutTab);
287:                panelTab.add(scroll, new GridBagConstraints(0, 0, 1, 1, 0.3,
288:                        0.1, GridBagConstraints.CENTER,
289:                        GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
290:                panelTab.add(panelEdit, new GridBagConstraints(1, 0, 1, 1, 0.1,
291:                        0.1, GridBagConstraints.CENTER,
292:                        GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
293:                tab.add(panelTab, res.getString("Parameters"));
294:                panelControl.setLayout(layoutControl);
295:                panelControl.add(buttonOK, new GridBagConstraints(0, 0, 1, 1,
296:                        0.0, 0.0, GridBagConstraints.CENTER,
297:                        GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
298:                panelControl.add(buttonCancel, new GridBagConstraints(1, 0, 1,
299:                        1, 0.0, 0.0, GridBagConstraints.CENTER,
300:                        GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
301:                this .setLayout(layoutRoot);
302:                this .add(tab, BorderLayout.NORTH);
303:                this .add(panelControl, BorderLayout.SOUTH);
304:            }
305:
306:            //
307:            private class ToolTipCellRenderer extends DefaultListCellRenderer {
308:                public Component getListCellRendererComponent(JList list,
309:                        Object value, int index, boolean isSelected,
310:                        boolean cellHasFocus) {
311:                    Component c = null;
312:
313:                    c = super .getListCellRendererComponent(list, value, index,
314:                            isSelected, cellHasFocus);
315:                    if (c instanceof  JComponent) {
316:                        JComponent jc = (JComponent) c;
317:
318:                        jc.setToolTipText(value.toString());
319:                    }
320:                    return c;
321:                }
322:
323:            }
324:
325:            //
326:            private class LocalButtonListener implements  ActionListener {
327:                public void actionPerformed(ActionEvent e) {
328:                    Object source = e.getSource();
329:
330:                    if (source == buttonAdd) {
331:                        add();
332:                    } else if (source == buttonEdit) {
333:                        editSelection();
334:                    } else if (source == buttonRemove) {
335:                        removeSelection();
336:                        refreshEditButtons();
337:                    } else if (source == buttonUp) {
338:                        moveSelection(-1);
339:                        refreshEditButtons();
340:                    } else if (source == buttonDown) {
341:                        moveSelection(1);
342:                        refreshEditButtons();
343:                    } else if (source == buttonOK) {
344:                        setOption(DialogPanel.OK_OPTION);
345:                        clearDialog();
346:                    } else if (source == buttonCancel) {
347:                        setOption(DialogPanel.CANCEL_OPTION);
348:                        clearDialog();
349:                    }
350:                }
351:
352:            }
353:
354:            //
355:            private class LocalListListener implements  ListSelectionListener {
356:                public void valueChanged(ListSelectionEvent event) {
357:                    if (event.getValueIsAdjusting()) {
358:
359:                        // do nothing
360:                    } else {
361:                        refreshEditButtons();
362:                    }
363:                }
364:
365:            }
366:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.