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


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