Source Code Cross Referenced for AddResourceDialog.java in  » Project-Management » memoranda » net » sf » memoranda » ui » 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 » Project Management » memoranda » net.sf.memoranda.ui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sf.memoranda.ui;
002:
003:        import java.awt.BorderLayout;
004:        import java.awt.Color;
005:        import java.awt.Dimension;
006:        import java.awt.FlowLayout;
007:        import java.awt.Frame;
008:        import java.awt.GridBagConstraints;
009:        import java.awt.GridBagLayout;
010:        import java.awt.Insets;
011:        import java.awt.event.ActionEvent;
012:
013:        import javax.swing.BorderFactory;
014:        import javax.swing.ButtonGroup;
015:        import javax.swing.ImageIcon;
016:        import javax.swing.JButton;
017:        import javax.swing.JDialog;
018:        import javax.swing.JFileChooser;
019:        import javax.swing.JLabel;
020:        import javax.swing.JPanel;
021:        import javax.swing.JRadioButton;
022:        import javax.swing.JCheckBox;
023:        import javax.swing.JTextField;
024:        import javax.swing.UIManager;
025:        import javax.swing.event.CaretEvent;
026:
027:        import net.sf.memoranda.util.Local;
028:
029:        /*$Id: AddResourceDialog.java,v 1.12 2007/03/20 06:21:46 alexeya Exp $*/
030:        public class AddResourceDialog extends JDialog {
031:            JPanel dialogTitlePanel = new JPanel(
032:                    new FlowLayout(FlowLayout.LEFT));
033:            JLabel header = new JLabel();
034:            ButtonGroup buttonGroup1 = new ButtonGroup();
035:            JPanel areaPanel = new JPanel(new GridBagLayout());
036:            GridBagConstraints gbc;
037:            public JRadioButton localFileRB = new JRadioButton();
038:            public JCheckBox projectFileCB = new JCheckBox(
039:                    "Copy file to memoranda", false);
040:            JLabel jLabel1 = new JLabel();
041:            public JTextField pathField = new JTextField();
042:            JButton browseB = new JButton();
043:            JLabel jLabel2 = new JLabel();
044:            public JRadioButton inetShortcutRB = new JRadioButton();
045:            public JTextField urlField = new JTextField();
046:            JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT,
047:                    15, 15));
048:            JButton okB = new JButton();
049:            JButton cancelB = new JButton();
050:            public boolean CANCELLED = true;
051:
052:            public AddResourceDialog(Frame frame, String title) {
053:                super (frame, title, true);
054:                try {
055:                    jbInit();
056:                    pack();
057:                } catch (Exception ex) {
058:                    new ExceptionDialog(ex);
059:                    ex.printStackTrace();
060:                }
061:            }
062:
063:            /**
064:             * setup user interface and init dialog
065:             */
066:
067:            void jbInit() throws Exception {
068:                this .setResizable(false);
069:                dialogTitlePanel.setBackground(Color.WHITE);
070:                dialogTitlePanel.setBorder(BorderFactory.createEmptyBorder(0,
071:                        5, 0, 5));
072:                header.setFont(new java.awt.Font("Dialog", 0, 20));
073:                header.setForeground(new Color(0, 0, 124));
074:                header.setText(Local.getString("New resource"));
075:                header
076:                        .setIcon(new ImageIcon(
077:                                net.sf.memoranda.ui.AddResourceDialog.class
078:                                        .getResource("resources/icons/resource48.png")));
079:                dialogTitlePanel.add(header);
080:                this .getContentPane().add(dialogTitlePanel, BorderLayout.NORTH);
081:
082:                buttonGroup1.add(localFileRB);
083:                buttonGroup1.add(inetShortcutRB);
084:                localFileRB.setSelected(true);
085:                localFileRB.setText(Local.getString("Local file"));
086:                localFileRB
087:                        .addActionListener(new java.awt.event.ActionListener() {
088:                            public void actionPerformed(ActionEvent e) {
089:                                localFileRB_actionPerformed(e);
090:                            }
091:                        });
092:                gbc = new GridBagConstraints();
093:                gbc.gridwidth = 2;
094:                gbc.gridx = 0;
095:                gbc.gridy = 0;
096:                gbc.insets = new Insets(10, 15, 5, 15);
097:                gbc.anchor = GridBagConstraints.WEST;
098:                gbc.fill = GridBagConstraints.HORIZONTAL;
099:                areaPanel.add(localFileRB, gbc);
100:
101:                gbc = new GridBagConstraints();
102:                gbc.gridwidth = 2;
103:                gbc.gridx = 2;
104:                gbc.gridy = 0;
105:                gbc.insets = new Insets(10, 15, 5, 15);
106:                gbc.anchor = GridBagConstraints.WEST;
107:                gbc.fill = GridBagConstraints.HORIZONTAL;
108:                areaPanel.add(projectFileCB, gbc);
109:
110:                jLabel1.setText(Local.getString("Path") + ": ");
111:                gbc = new GridBagConstraints();
112:                gbc.gridx = 0;
113:                gbc.gridy = 1;
114:                gbc.insets = new Insets(5, 20, 5, 5);
115:                gbc.anchor = GridBagConstraints.WEST;
116:                gbc.fill = GridBagConstraints.HORIZONTAL;
117:                areaPanel.add(jLabel1, gbc);
118:                pathField.setMinimumSize(new Dimension(4, 24));
119:                pathField.setPreferredSize(new Dimension(250, 24));
120:                pathField
121:                        .addCaretListener(new javax.swing.event.CaretListener() {
122:                            public void caretUpdate(CaretEvent e) {
123:                                pathField_caretUpdate(e);
124:                            }
125:                        });
126:                gbc = new GridBagConstraints();
127:                gbc.gridx = 1;
128:                gbc.gridy = 1;
129:                gbc.insets = new Insets(5, 5, 5, 5);
130:                gbc.anchor = GridBagConstraints.WEST;
131:                gbc.fill = GridBagConstraints.HORIZONTAL;
132:                areaPanel.add(pathField, gbc);
133:                browseB.setText(Local.getString("Browse"));
134:                browseB.addActionListener(new java.awt.event.ActionListener() {
135:                    public void actionPerformed(ActionEvent e) {
136:                        browseB_actionPerformed(e);
137:                    }
138:                });
139:                gbc = new GridBagConstraints();
140:                gbc.gridx = 2;
141:                gbc.gridy = 1;
142:                gbc.insets = new Insets(5, 10, 5, 15);
143:                gbc.anchor = GridBagConstraints.WEST;
144:                areaPanel.add(browseB, gbc);
145:                inetShortcutRB.setText(Local.getString("Internet shortcut"));
146:                inetShortcutRB
147:                        .addActionListener(new java.awt.event.ActionListener() {
148:                            public void actionPerformed(ActionEvent e) {
149:                                inetShortcutRB_actionPerformed(e);
150:                            }
151:                        });
152:                gbc = new GridBagConstraints();
153:                gbc.gridx = 0;
154:                gbc.gridy = 2;
155:                gbc.gridwidth = 2;
156:                gbc.insets = new Insets(5, 15, 5, 15);
157:                gbc.anchor = GridBagConstraints.WEST;
158:                areaPanel.add(inetShortcutRB, gbc);
159:                jLabel2.setText(Local.getString("URL") + ":  ");
160:                gbc = new GridBagConstraints();
161:                gbc.gridx = 0;
162:                gbc.gridy = 3;
163:                gbc.insets = new Insets(5, 20, 5, 15);
164:                gbc.anchor = GridBagConstraints.WEST;
165:                areaPanel.add(jLabel2, gbc);
166:                urlField.setMinimumSize(new Dimension(4, 24));
167:                urlField.setPreferredSize(new Dimension(335, 24));
168:                urlField
169:                        .addCaretListener(new javax.swing.event.CaretListener() {
170:                            public void caretUpdate(CaretEvent e) {
171:                                urlField_caretUpdate(e);
172:                            }
173:                        });
174:                gbc = new GridBagConstraints();
175:                gbc.gridx = 1;
176:                gbc.gridy = 3;
177:                gbc.gridwidth = 2;
178:                gbc.insets = new Insets(5, 5, 0, 15);
179:                gbc.anchor = GridBagConstraints.WEST;
180:                gbc.fill = GridBagConstraints.HORIZONTAL;
181:                areaPanel.add(urlField, gbc);
182:                this .getContentPane().add(areaPanel, BorderLayout.CENTER);
183:
184:                okB.setEnabled(false);
185:                okB.setMaximumSize(new Dimension(100, 26));
186:                okB.setMinimumSize(new Dimension(100, 26));
187:                okB.setPreferredSize(new Dimension(100, 26));
188:                okB.setText(Local.getString("Ok"));
189:                okB.addActionListener(new java.awt.event.ActionListener() {
190:                    public void actionPerformed(ActionEvent e) {
191:                        okB_actionPerformed(e);
192:                    }
193:                });
194:                this .getRootPane().setDefaultButton(okB);
195:                cancelB.setMaximumSize(new Dimension(100, 26));
196:                cancelB.setMinimumSize(new Dimension(100, 26));
197:                cancelB.setPreferredSize(new Dimension(100, 26));
198:                cancelB.setText(Local.getString("Cancel"));
199:                cancelB.addActionListener(new java.awt.event.ActionListener() {
200:                    public void actionPerformed(ActionEvent e) {
201:                        cancelB_actionPerformed(e);
202:                    }
203:                });
204:                buttonsPanel.add(okB);
205:                buttonsPanel.add(cancelB);
206:                enableFields();
207:                this .getContentPane().add(buttonsPanel, BorderLayout.SOUTH);
208:            }
209:
210:            /**
211:             * set CANCELLED variable to false so we can know the user 
212:             * pressed the ok buton and close this dialog.
213:             */
214:
215:            void okB_actionPerformed(ActionEvent e) {
216:                CANCELLED = false;
217:                this .dispose();
218:            }
219:
220:            /**
221:             * close the dialog window
222:             */
223:
224:            void cancelB_actionPerformed(ActionEvent e) {
225:                this .dispose();
226:            }
227:
228:            /**
229:             * enable localRB fields. Request focus for the text field 
230:             * so the user can start typing and set the pathField text selected
231:             */
232:
233:            void localFileRB_actionPerformed(ActionEvent e) {
234:                enableFields();
235:                checkOkEnabled();
236:                urlField.select(0, 0);
237:                pathField.select(0, pathField.getText().length());
238:                pathField.requestFocus();
239:            }
240:
241:            /**
242:             * enable inetShorcutRB fields. Request focus for the text field 
243:             * so the user can start typing and set the urlField text selected
244:             */
245:
246:            void inetShortcutRB_actionPerformed(ActionEvent e) {
247:                enableFields();
248:                checkOkEnabled();
249:                pathField.select(0, 0);
250:                urlField.select(0, urlField.getText().length());
251:                urlField.requestFocus();
252:            }
253:
254:            /**
255:             * setup the JFileChooser so the user can select the resource file
256:             */
257:
258:            void browseB_actionPerformed(ActionEvent e) {
259:                // Fix until Sun's JVM supports more locales...
260:                UIManager.put("FileChooser.lookInLabelText", Local
261:                        .getString("Look in:"));
262:                UIManager.put("FileChooser.upFolderToolTipText", Local
263:                        .getString("Up One Level"));
264:                UIManager.put("FileChooser.newFolderToolTipText", Local
265:                        .getString("Create New Folder"));
266:                UIManager.put("FileChooser.listViewButtonToolTipText", Local
267:                        .getString("List"));
268:                UIManager.put("FileChooser.detailsViewButtonToolTipText", Local
269:                        .getString("Details"));
270:                UIManager.put("FileChooser.fileNameLabelText", Local
271:                        .getString("File Name:"));
272:                UIManager.put("FileChooser.filesOfTypeLabelText", Local
273:                        .getString("Files of Type:"));
274:                UIManager.put("FileChooser.openButtonText", Local
275:                        .getString("Open"));
276:                UIManager.put("FileChooser.openButtonToolTipText", Local
277:                        .getString("Open selected file"));
278:                UIManager.put("FileChooser.cancelButtonText", Local
279:                        .getString("Cancel"));
280:                UIManager.put("FileChooser.cancelButtonToolTipText", Local
281:                        .getString("Cancel"));
282:
283:                JFileChooser chooser = new JFileChooser();
284:                chooser.setFileHidingEnabled(false);
285:                chooser.setDialogTitle(Local.getString("Add resource"));
286:                chooser.setAcceptAllFileFilterUsed(true);
287:                chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
288:                chooser.setPreferredSize(new Dimension(550, 375));
289:                /*java.io.File lastSel = (java.io.File) Context.get("LAST_SELECTED_RESOURCE_FILE");
290:                if (lastSel != null)
291:                    chooser.setCurrentDirectory(lastSel);*/
292:                if (chooser.showOpenDialog(this ) != JFileChooser.APPROVE_OPTION)
293:                    return;
294:                /*try {
295:                    Context.put("LAST_SELECTED_RESOURCE_FILE", chooser.getSelectedFile());
296:                }
297:                catch (Exception ex) {}*/
298:                pathField.setText(chooser.getSelectedFile().getPath());
299:                checkOkEnabled();
300:            }
301:
302:            /**
303:             * disable the ok button if pathField is empty
304:             */
305:
306:            void pathField_caretUpdate(CaretEvent e) {
307:                checkOkEnabled();
308:            }
309:
310:            /**
311:             * disable the ok button if urlField is empty
312:             */
313:
314:            void urlField_caretUpdate(CaretEvent e) {
315:                checkOkEnabled();
316:            }
317:
318:            /**
319:             * do not enable the ok button until the text field is not empty.
320:             */
321:
322:            void checkOkEnabled() {
323:                okB.setEnabled((localFileRB.isSelected() && pathField.getText()
324:                        .length() > 0)
325:                        || (inetShortcutRB.isSelected() && urlField.getText()
326:                                .length() > 0));
327:            }
328:
329:            /** 
330:             * enable and disable fields when user selects the radio buttons options
331:             */
332:
333:            void enableFields() {
334:                pathField.setEnabled(localFileRB.isSelected());
335:                jLabel1.setEnabled(localFileRB.isSelected());
336:                browseB.setEnabled(localFileRB.isSelected());
337:                projectFileCB.setEnabled(localFileRB.isSelected());
338:
339:                urlField.setEnabled(inetShortcutRB.isSelected());
340:                jLabel2.setEnabled(inetShortcutRB.isSelected());
341:            }
342:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.