Source Code Cross Referenced for DElementDialog.java in  » J2EE » enhydra » discRack » presentation » 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 » discRack.presentation 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package discRack.presentation;
002:
003:        import discRack.*;
004:        import discRack.presentation.delements.*;
005:        import discRack.presentation.dpanels.*;
006:        import discRack.business.person.*;
007:
008:        import javax.swing.*;
009:        import java.awt.*;
010:        import java.awt.event.*;
011:
012:        import java.util.*;
013:        import java.net.URL;
014:
015:        /**
016:         * The dialog for showing objects derived from {@link DPanel} classes. The
017:         * given DPanel object must have it's owner, which type is a class
018:         * derived from the {@link DSimpleElement} class.
019:         * <p> The dialog enables editing of all editable fields contained
020:         * within given panel and after user presses OK button, the new values
021:         * contained within edited fields are set to corresponding members of
022:         * panel's owner.
023:         *
024:         * @author Sasa Bojanic
025:         * @version 1.0
026:         */
027:        public class DElementDialog extends JDialog {
028:            private DPanel panelToEdit = new DPanel();
029:            private JButton buttonOK;
030:            private JButton buttonCancel;
031:
032:            private WindowListener wl = new WindowAdapter() {
033:                public void windowClosing(WindowEvent e) {
034:                    isCanceled = true;
035:                    dispose();
036:                }
037:            };
038:
039:            /** Set to true if cancel hasn't been pressed */
040:            private boolean isCanceled = false;
041:
042:            /**
043:             * Constructs a new modal instance which parent is <code>parent</code> and
044:             * proceeds a title of dialog.
045:             *
046:             * @param parent Parent frame.
047:             * @param title  Dialog title.
048:             */
049:            public DElementDialog(JFrame parent, String title) {
050:                super (parent, title, true);
051:                initDialog();
052:            }
053:
054:            /**
055:             * Constructs a new modal instance which parent is <code>parent</code> and
056:             * proceeds a title of dialog.
057:             *
058:             * @param parent Parent dialog.
059:             * @param title  Dialog title.
060:             */
061:            public DElementDialog(JDialog parent, String title) {
062:                super (parent, title, true);
063:                initDialog();
064:            }
065:
066:            /**
067:             * @return <tt>true</tt> if cancel hasn't been pressed,
068:             *         <tt>false</tt> otherwise.
069:             */
070:            public boolean isCanceled() {
071:                return isCanceled;
072:            }
073:
074:            /**
075:             * Displays dialog and adds specified panel to it, along
076:             * with OK and/or Cancel button. The dialog allows user to edit
077:             * the panel field(s) that represents corresponding member of
078:             * it's owner class. After user presses OK, the content of
079:             * panel field(s) is transfered to the corresponding owner
080:             * class member.
081:             *
082:             * @param elementPanel The panel with visual presentation of it's
083:             *                     owner members.
084:             */
085:            public void editDElement(DPanel elementPanel,
086:                    boolean hasCancelButton) {
087:
088:                Container cp = getContentPane();
089:                cp.remove(panelToEdit);
090:                panelToEdit = elementPanel;
091:                cp.add(panelToEdit, 0);
092:                pack();
093:
094:                if (hasCancelButton) {
095:                    buttonCancel.setVisible(true);
096:                } else {
097:                    buttonCancel.setVisible(false);
098:                    buttonOK.requestFocus();
099:                }
100:
101:                setLocationRelativeTo(getParent());
102:                pack();
103:                show();
104:                try {
105:                    if (panelToEdit instanceof  DGroupPanel) {
106:                        if (panelToEdit.getComponent(0).isEnabled()) {
107:                            panelToEdit.getComponent(0).requestFocus();
108:                        } else {
109:                            panelToEdit.getComponent(1).requestFocus();
110:                        }
111:                    }
112:
113:                } catch (Exception ex) {
114:                    panelToEdit.requestFocus();
115:                }
116:
117:            }
118:
119:            private void initDialog() {
120:                try {
121:                    JPanel buttonPanel = new JPanel();
122:
123:                    buttonPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
124:                    buttonPanel.setAlignmentY(Component.TOP_ALIGNMENT);
125:
126:                    buttonOK = new JButton("OK");
127:                    URL u = ResourceManager.getResource("OKImage");
128:                    if (u != null) {
129:                        buttonOK.setIcon(new ImageIcon(u));
130:                    }
131:
132:                    buttonCancel = new JButton("Cancel");
133:                    u = ResourceManager.getResource("CancelImage");
134:                    if (u != null) {
135:                        buttonCancel.setIcon(new ImageIcon(u));
136:                    }
137:
138:                    buttonPanel.add(buttonOK);
139:                    buttonPanel.add(buttonCancel);
140:
141:                    Container cp = getContentPane();
142:                    cp.setLayout(new BoxLayout(cp, BoxLayout.Y_AXIS));
143:
144:                    cp.add(panelToEdit);
145:                    cp.add(buttonPanel);
146:
147:                    // action listener for confirming
148:                    buttonOK.addActionListener(new ActionListener() {
149:                        public void actionPerformed(ActionEvent ae) {
150:                            if (canApplyChanges()) {
151:                                applyChanges();
152:                                dispose();
153:                            }
154:                        }
155:                    });
156:
157:                    // action listener for canceling
158:                    buttonCancel.addActionListener(new ActionListener() {
159:                        public void actionPerformed(ActionEvent ae) {
160:                            isCanceled = true;
161:                            dispose();
162:                        }
163:                    });
164:
165:                    addWindowListener(wl);
166:
167:                    getRootPane()
168:                            .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
169:                            .put(
170:                                    KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,
171:                                            0, false), "Cancel");
172:                    getRootPane().getActionMap().put("Cancel",
173:                            new AbstractAction() {
174:                                public void actionPerformed(ActionEvent e) {
175:                                    isCanceled = true;
176:                                    dispose();
177:                                }
178:                            });
179:
180:                } catch (Exception e) {
181:                    e.printStackTrace();
182:                }
183:                setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
184:                setResizable(false);
185:                setLocationRelativeTo(getParent());
186:                buttonOK.setDefaultCapable(true);
187:                getRootPane().setDefaultButton(buttonOK);
188:
189:            }
190:
191:            public boolean canApplyChanges() {
192:                if (panelToEdit.checkRequired()) {
193:                    if (!panelToEdit.getOwner().setDODSElements(panelToEdit)) {
194:                        return false;
195:                    } else {
196:                        return true;
197:                    }
198:                } else {
199:                    return false;
200:                }
201:            }
202:
203:            public void applyChanges() {
204:                panelToEdit.setElements();
205:            }
206:
207:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.