Source Code Cross Referenced for BasePropertiesDialog.java in  » UML » MetaBoss » com » metaboss » applications » designstudio » 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 » UML » MetaBoss » com.metaboss.applications.designstudio 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002:        // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003:        // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004:        // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005:        // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006:        // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007:        // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008:        // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009:        // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010:        // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011:        // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012:        // POSSIBILITY OF SUCH DAMAGE.
013:        //
014:        // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015:        package com.metaboss.applications.designstudio;
016:
017:        import java.awt.BorderLayout;
018:        import java.awt.Color;
019:        import java.awt.Dimension;
020:        import java.awt.FlowLayout;
021:        import java.awt.Font;
022:        import java.awt.Graphics;
023:        import java.awt.GridBagConstraints;
024:        import java.awt.GridBagLayout;
025:        import java.awt.GridLayout;
026:        import java.awt.Insets;
027:        import java.awt.Point;
028:        import java.awt.Rectangle;
029:        import java.awt.Toolkit;
030:        import java.awt.event.ActionEvent;
031:        import java.awt.event.ActionListener;
032:        import java.awt.event.ComponentAdapter;
033:        import java.awt.event.ComponentEvent;
034:        import java.awt.event.ItemEvent;
035:        import java.awt.event.ItemListener;
036:        import java.awt.event.KeyEvent;
037:        import java.io.File;
038:        import java.io.FileInputStream;
039:        import java.io.FileOutputStream;
040:        import java.util.Properties;
041:        import java.util.StringTokenizer;
042:
043:        import javax.swing.ActionMap;
044:        import javax.swing.InputMap;
045:        import javax.swing.JButton;
046:        import javax.swing.JCheckBox;
047:        import javax.swing.JComboBox;
048:        import javax.swing.JComponent;
049:        import javax.swing.JDialog;
050:        import javax.swing.JLabel;
051:        import javax.swing.JPanel;
052:        import javax.swing.JScrollPane;
053:        import javax.swing.JSpinner;
054:        import javax.swing.JTextArea;
055:        import javax.swing.JTextField;
056:        import javax.swing.KeyStroke;
057:        import javax.swing.border.Border;
058:        import javax.swing.border.EmptyBorder;
059:
060:        import com.metaboss.applications.designstudio.complexfield.ComplexBox;
061:        import com.metaboss.applications.designstudio.components.EditorButton;
062:        import com.metaboss.applications.designstudio.components.EtchedLineBorder;
063:        import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
064:
065:        /*		Base class for properties dialogs		*/
066:
067:        public class BasePropertiesDialog extends JDialog {
068:            public static Border createEditorBorder() {
069:                return new EmptyBorder(2, 2, 1, 1);
070:            }
071:
072:            // static members
073:            public static int MR_OK = 0;
074:            public static int MR_CANCEL = 1;
075:
076:            public static final String DIALOG_POSITION = "DialogBounds";
077:
078:            // protected members
079:            protected Properties mPreferences = new Properties();
080:            protected int mModalResult = MR_CANCEL;
081:            protected String mTitle = "";
082:            protected boolean mLoading = true;
083:            protected ModelElement mOldNameModelElement = null;
084:            protected Rectangle mLoadDialogRectangle = null;
085:            protected boolean mModified = false;
086:            protected Dimension mMinSize = null;
087:            // Actions
088:            protected OKAction mOKAction = new OKAction();
089:            protected CancelAction mCancelAction = new CancelAction();
090:            // UI components
091:            protected JTextField mNameField = new JTextField();
092:            protected JPanel mContentPane = new JPanel();
093:            protected JButton mCancelButton = new JButton(mCancelAction);
094:            protected JButton mOKButton = new JButton(mOKAction);
095:            protected JPanel mClient = new JPanel();
096:            protected JPanel mCaptionBar = new JPanel();
097:            protected JPanel mButtonBar = new ResizerPanel(this );
098:            protected JPanel mButtonBarGrid = new JPanel();
099:            protected GridLayout mButtonBarGridLayout = new GridLayout();
100:            protected BorderLayout mBorderLayout = new BorderLayout();
101:            protected GridBagLayout mClientGridBagLayout = new GridBagLayout();
102:            protected FlowLayout mButtonBarFlowLayout = new FlowLayout();
103:            protected GridLayout mCaptionGridLayout = new GridLayout();
104:            protected JLabel mCaptionLabel = new JLabel();
105:
106:            public BasePropertiesDialog(String pTitle, boolean pModal,
107:                    Dimension pSize) {
108:                super (Application.mainFrame, pTitle, pModal);
109:
110:                mTitle = pTitle;
111:                mMinSize = pSize;
112:
113:                initialisePreferences();
114:                loadPreferences();
115:                initializeChildControls();
116:                pack();
117:                initialiseDialogPosition(pSize);
118:                setResizable(false);
119:
120:                InputMap lMap = mContentPane
121:                        .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
122:                lMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,
123:                        KeyEvent.CTRL_MASK), "ok");
124:                lMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "ok");
125:                lMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
126:                        "cancel");
127:
128:                ActionMap lActionMap = mContentPane.getActionMap();
129:                lActionMap.put("ok", mOKAction);
130:                lActionMap.put("cancel", mCancelAction);
131:
132:                addComponentListener(new PropertiesDialogArapter());
133:            }
134:
135:            // add Text field
136:            public void addTextField(JPanel lPanel, String pCaption,
137:                    JTextField lField, int nLine, boolean pRequired) {
138:                addCaption(lPanel, pCaption, nLine, pRequired);
139:                lPanel.add(lField, new GridBagConstraints(1, nLine, 1, 1, 1.0,
140:                        0.0, GridBagConstraints.WEST,
141:                        GridBagConstraints.HORIZONTAL, new Insets(4, 0, 4, 20),
142:                        20, 0));
143:            }
144:
145:            public void addTextField(String pCaption, JTextField lField,
146:                    int nLine, boolean pRequired) {
147:                addTextField(mClient, pCaption, lField, nLine, pRequired);
148:            }
149:
150:            // add short Text field
151:            public void addShortTextField(JPanel lPanel, String pCaption,
152:                    JTextField lField, int nLine, int nWidth, boolean pRequired) {
153:                addCaption(lPanel, pCaption, nLine, pRequired);
154:                lPanel.add(lField, new GridBagConstraints(1, nLine, 1, 1, 1.0,
155:                        0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
156:                        new Insets(4, 0, 4, 20), nWidth, 0));
157:            }
158:
159:            public void addShortTextField(String pCaption, JTextField lField,
160:                    int nLine, int nWidth, boolean pRequired) {
161:                addShortTextField(mClient, pCaption, lField, nLine, nWidth,
162:                        pRequired);
163:            }
164:
165:            // add ComboBox field
166:            public void addComboBox(JPanel lPanel, String pCaption,
167:                    JComboBox lField, int nLine, boolean pRequired) {
168:                addCaption(lPanel, pCaption, nLine, pRequired);
169:                lPanel.add(lField, new GridBagConstraints(1, nLine, 1, 1, 1.0,
170:                        0.0, GridBagConstraints.WEST,
171:                        GridBagConstraints.HORIZONTAL, new Insets(4, 0, 4, 20),
172:                        20, 0));
173:            }
174:
175:            public void addComboBox(String pCaption, JComboBox lField,
176:                    int nLine, boolean pRequired) {
177:                addComboBox(mClient, pCaption, lField, nLine, pRequired);
178:            }
179:
180:            // add ComboBox field
181:            public void addShortComboBox(JPanel lPanel, String pCaption,
182:                    JComboBox lField, int nLine, int pWidth, boolean pRequired) {
183:                addCaption(lPanel, pCaption, nLine, pRequired);
184:                lPanel.add(lField, new GridBagConstraints(1, nLine, 1, 1, 1.0,
185:                        0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
186:                        new Insets(4, 0, 4, 20), pWidth, 0));
187:            }
188:
189:            public void addShortComboBox(String pCaption, JComboBox lField,
190:                    int nLine, int pWidth, boolean pRequired) {
191:                addShortComboBox(mClient, pCaption, lField, nLine, pWidth,
192:                        pRequired);
193:            }
194:
195:            // add Text area
196:            public void addTextArea(JPanel lPanel, String pCaption,
197:                    JTextArea lField, int nLine, boolean pRequired) {
198:                addCaption(lPanel, pCaption, nLine, pRequired);
199:                lPanel.add(new JScrollPane(lField), new GridBagConstraints(1,
200:                        nLine, 1, 1, 1.0, 0.0, GridBagConstraints.WEST,
201:                        GridBagConstraints.HORIZONTAL, new Insets(4, 0, 4, 20),
202:                        0, 80));
203:
204:                lField.setWrapStyleWord(true);
205:                lField.setLineWrap(true);
206:            }
207:
208:            public void addTextArea(String pCaption, JTextArea lField,
209:                    int nLine, boolean pRequired) {
210:                addTextArea(mClient, pCaption, lField, nLine, pRequired);
211:            }
212:
213:            // add CheckBox
214:            public void addCheckBox(JPanel lPanel, String pCaption,
215:                    JCheckBox lField, int nLine, boolean pRequired) {
216:                lField.setText(pCaption);
217:                lPanel.add(lField, new GridBagConstraints(1, nLine, 1, 1, 1.0,
218:                        0.0, GridBagConstraints.WEST,
219:                        GridBagConstraints.HORIZONTAL, new Insets(4, 0, 4, 20),
220:                        20, 0));
221:            }
222:
223:            public void addCheckBox(String pCaption, JCheckBox lField,
224:                    int nLine, boolean pRequired) {
225:                addCheckBox(mClient, pCaption, lField, nLine, pRequired);
226:            }
227:
228:            // add Spinner Field
229:            public void addSpinner(JPanel lPanel, String pCaption,
230:                    JSpinner lSpinner, int nLine, int pWidth, boolean pRequired) {
231:                addCaption(lPanel, pCaption, nLine, pRequired);
232:                lPanel.add(lSpinner, new GridBagConstraints(1, nLine, 1, 1,
233:                        1.0, 0.0, GridBagConstraints.WEST,
234:                        GridBagConstraints.NONE, new Insets(4, 0, 4, 20),
235:                        pWidth, 0));
236:            }
237:
238:            public void addSpinner(String pCaption, JSpinner lSpinner,
239:                    int nLine, int pWidth, boolean pRequired) {
240:                addSpinner(mClient, pCaption, lSpinner, nLine, pWidth,
241:                        pRequired);
242:            }
243:
244:            // add Complex Field field
245:            public void addComplexField(JPanel lPanel, ComplexBox lField,
246:                    int nLine, boolean pRequired) {
247:                addCaption(lPanel, lField.getCaption() + ": ", nLine, pRequired);
248:                lPanel.add(lField, new GridBagConstraints(1, nLine, 1, 1, 1.0,
249:                        0.0, GridBagConstraints.WEST,
250:                        GridBagConstraints.HORIZONTAL, new Insets(4, 0, 4, 20),
251:                        20, 0));
252:            }
253:
254:            public void addComplexField(ComplexBox lField, int nLine,
255:                    boolean pRequired) {
256:                addComplexField(mClient, lField, nLine, pRequired);
257:            }
258:
259:            // add Complex Field field with editor button
260:            public void addComplexFieldWithEdit(JPanel pPanel,
261:                    ComplexBox pField, int nLine, boolean pRequired) {
262:                addCaption(pPanel, pField.getCaption() + ": ", nLine, pRequired);
263:
264:                JPanel lLocalPanel = new JPanel();
265:                EditorButton lButton = new EditorButton();
266:
267:                lButton.setEnabled(pField.getSelectedUserObject() != null);
268:                lLocalPanel.setLayout(new BorderLayout());
269:                lLocalPanel.add(pField, BorderLayout.CENTER);
270:                lLocalPanel.add(lButton, BorderLayout.EAST);
271:                pPanel.add(lLocalPanel, new GridBagConstraints(1, nLine, 1, 1,
272:                        1.0, 0.0, GridBagConstraints.WEST,
273:                        GridBagConstraints.HORIZONTAL, new Insets(4, 0, 4, 20),
274:                        20, 0));
275:
276:                lButton.addActionListener(new EditButtonActionListener(pField));
277:                pField.addActionListener(new ComlexFieldChangedListener(pField,
278:                        lButton));
279:            }
280:
281:            public void addComplexFieldWithEdit(ComplexBox pField, int nLine,
282:                    boolean pRequired) {
283:                addComplexFieldWithEdit(mClient, pField, nLine, pRequired);
284:            }
285:
286:            // return modal result
287:            public int getModalResult() {
288:                if (!isVisible())
289:                    setVisible(true);
290:                return mModalResult;
291:            }
292:
293:            // check fields data
294:            public boolean checkProperties() {
295:                return true;
296:            }
297:
298:            // load service module properties
299:            public void loadProperties(ModelElement pObject) throws Exception {
300:                try {
301:                    mCaptionLabel.setText("Edit " + mTitle + " Properties");
302:                    if (pObject != null)
303:                        setTitle(pObject.getRef());
304:                    mOldNameModelElement = getNameElement();
305:                    checkNameField();
306:                } finally {
307:                    mLoading = false;
308:                }
309:            }
310:
311:            // save service module proeprties
312:            public void saveProperties(ModelElement pObject) throws Exception {
313:                //???
314:            }
315:
316:            public void ok() {
317:                if (checkProperties()) {
318:                    setVisible(false);
319:                    mModalResult = MR_OK;
320:                }
321:            }
322:
323:            public void cancel() {
324:                setVisible(false);
325:                mModalResult = MR_CANCEL;
326:            }
327:
328:            public void setVisible(boolean b) {
329:                super .setVisible(b);
330:                if (!b) {
331:                    savePreferences();
332:                    storePreferences();
333:                    removeListeneres();
334:                }
335:            }
336:
337:            protected void removeListeneres() {
338:                //??
339:            }
340:
341:            // initialize child controls
342:            protected void initializeChildControls() {
343:                setContentPane(mContentPane);
344:
345:                mContentPane.setLayout(mBorderLayout);
346:                mButtonBar.setLayout(mButtonBarFlowLayout);
347:                mButtonBarGrid.setLayout(mButtonBarGridLayout);
348:                mButtonBarGridLayout.setColumns(2);
349:                mButtonBarGridLayout.setHgap(6);
350:                mClient.setLayout(mClientGridBagLayout);
351:                mCaptionBar.setLayout(mCaptionGridLayout);
352:                mCaptionBar.setBackground(Color.white);
353:
354:                mButtonBarGrid.add(mOKButton);
355:                mButtonBarGrid.add(mCancelButton);
356:                mButtonBar.add(mButtonBarGrid);
357:                mCaptionBar.add(mCaptionLabel);
358:                mCaptionLabel.setText("New " + mTitle);
359:
360:                mCaptionLabel.setIcon(Application.METABOSS_ICON);
361:                mCaptionLabel.setFont(Application.DEFAULT_FONT_BOLD);
362:
363:                mContentPane.add(mClient, BorderLayout.CENTER);
364:                mContentPane.add(mCaptionBar, BorderLayout.NORTH);
365:                mContentPane.add(mButtonBar, BorderLayout.SOUTH);
366:
367:                mButtonBar.setBorder(new EtchedLineBorder(
368:                        EtchedLineBorder.TOP_BORDER));
369:            }
370:
371:            // Initialise Dialog Position And Bounds
372:            protected void initialiseDialogPosition(Dimension pSize) {
373:                Point xLocation = null;
374:                if (mLoadDialogRectangle != null) {
375:                    pSize = new Dimension(mLoadDialogRectangle.width,
376:                            mLoadDialogRectangle.height);
377:                    xLocation = new Point(mLoadDialogRectangle.x,
378:                            mLoadDialogRectangle.y);
379:                }
380:
381:                Point lMainFrameLocation = Application.mainFrame.getLocation();
382:                Dimension screenSize = Application.mainFrame.getSize();
383:                Dimension frameSize = new Dimension(pSize.width, pSize.height);
384:
385:                if (lMainFrameLocation.x <= 0) {
386:                    lMainFrameLocation.x = 0;
387:                    lMainFrameLocation.y = 0;
388:                    screenSize = Toolkit.getDefaultToolkit().getScreenSize();
389:                }
390:
391:                Dimension lOldFrameSize = new Dimension(frameSize);
392:                if (frameSize.height > screenSize.height)
393:                    frameSize.height = screenSize.height;
394:                if (frameSize.width > screenSize.width)
395:                    frameSize.width = screenSize.width;
396:
397:                setSize(lOldFrameSize);
398:                if (xLocation != null) {
399:                    screenSize = Toolkit.getDefaultToolkit().getScreenSize();
400:                    if ((xLocation.x + lOldFrameSize.width) > screenSize.width)
401:                        xLocation.x = screenSize.width - lOldFrameSize.width;
402:                    if (xLocation.x < 0)
403:                        xLocation.x = 0;
404:                    if ((xLocation.y + lOldFrameSize.height) > screenSize.height)
405:                        xLocation.y = screenSize.height - lOldFrameSize.height;
406:                    if (xLocation.y < 0)
407:                        xLocation.y = 0;
408:                    setLocation(xLocation);
409:                } else {
410:                    setLocation(((screenSize.width - frameSize.width) / 2)
411:                            + lMainFrameLocation.x,
412:                            ((screenSize.height - frameSize.height) / 2)
413:                                    + lMainFrameLocation.y);
414:                    setPropertyNoModified(DIALOG_POSITION,
415:                            rectangleToString(getBounds()));
416:                }
417:            }
418:
419:            // add label
420:            protected void addCaption(JPanel lPanel, String pCaption,
421:                    int nLine, boolean pRequired) {
422:                JLabel lCaptionLabel = new JLabel(pCaption);
423:                if (pRequired)
424:                    lCaptionLabel.setFont(lCaptionLabel.getFont().deriveFont(
425:                            Font.BOLD));
426:                lPanel
427:                        .add(lCaptionLabel, new GridBagConstraints(0, nLine, 1,
428:                                1, 0.0, 0.0, GridBagConstraints.EAST,
429:                                GridBagConstraints.NONE,
430:                                new Insets(4, 20, 4, 0), 0, 0));
431:            }
432:
433:            // get Name field Model Element
434:            protected ModelElement getNameElement() {
435:                return null;
436:            }
437:
438:            protected JTextField getNameField() {
439:                return mNameField;
440:            }
441:
442:            // preset name combobox name 
443:            protected void checkNameField() {
444:                try {
445:                    JTextField lField = getNameField();
446:                    ModelElement lModelElement = getNameElement();
447:
448:                    if (lModelElement != null && lField != null
449:                            && lField.getText().length() == 0) {
450:                        lField.setText(lModelElement.getName());
451:                    }
452:                } catch (Exception e) {
453:                    //???
454:                }
455:            }
456:
457:            // process StorageTechnology change
458:            protected void processNameModelElementChange() {
459:                if (mLoading)
460:                    return;
461:                try {
462:                    JTextField lField = getNameField();
463:                    ModelElement lModelElement = getNameElement();
464:
465:                    if (mOldNameModelElement != null && lModelElement != null
466:                            && lField != null) {
467:                        if (lField.getText().equals(
468:                                mOldNameModelElement.getName()))
469:                            lField.setText(lModelElement.getName());
470:                    } else
471:                        checkNameField();
472:
473:                    mOldNameModelElement = lModelElement;
474:                } catch (Exception e) {
475:                    //???
476:                }
477:            }
478:
479:            // Gets the mininimum size of this component.
480:            public Dimension getMinimumSize() {
481:                return mMinSize;
482:            }
483:
484:            // initialise properties class
485:            protected void initialisePreferences() {
486:                String lPreferencesFileName = getPreferencesFileName();
487:                try {
488:                    File lPropFile = new File(lPreferencesFileName);
489:                    if (lPropFile.isFile() && lPropFile.exists()
490:                            && lPropFile.canRead())
491:                        mPreferences.load(new FileInputStream(lPropFile));
492:                    else {
493:                        File lUserPreferencesDirectory = new File(
494:                                getPreferencesDirectoryName());
495:                        if (!lUserPreferencesDirectory.exists())
496:                            lUserPreferencesDirectory.mkdirs();
497:                    }
498:                } catch (java.io.FileNotFoundException e) {
499:                    e.printStackTrace();
500:                } catch (java.io.IOException e) {
501:                    e.printStackTrace();
502:                }
503:            }
504:
505:            // store preferences values
506:            protected void storePreferences() {
507:                if (mPreferences != null && mModified) {
508:                    try {
509:                        String lPreferencesFileName = getPreferencesFileName();
510:                        mPreferences.store(new FileOutputStream(
511:                                lPreferencesFileName, false),
512:                                "User Prefrences for the " + getTitle()
513:                                        + " dialog");
514:                        mModified = false;
515:                    } catch (java.io.FileNotFoundException e) {
516:                        e.printStackTrace();
517:                    } catch (java.io.IOException e) {
518:                        e.printStackTrace();
519:                    }
520:                }
521:            }
522:
523:            // load dialog properties
524:            protected void loadPreferences() {
525:                String lBoundsSetting = getProperty(DIALOG_POSITION);
526:                StringTokenizer lBoundsTokenizer = (lBoundsSetting != null) ? new StringTokenizer(
527:                        lBoundsSetting, ",", false)
528:                        : null;
529:                mLoadDialogRectangle = (lBoundsTokenizer != null) ? new Rectangle(
530:                        Integer.parseInt(lBoundsTokenizer.nextToken()), Integer
531:                                .parseInt(lBoundsTokenizer.nextToken()),
532:                        Integer.parseInt(lBoundsTokenizer.nextToken()), Integer
533:                                .parseInt(lBoundsTokenizer.nextToken()))
534:                        : null;
535:            }
536:
537:            // save dialog properties
538:            protected void savePreferences() {
539:                setProperty(DIALOG_POSITION, rectangleToString(getBounds()));
540:            }
541:
542:            // return form properties file name
543:            protected String getPreferencesFileName() {
544:                return getPreferencesDirectoryName()
545:                        + System.getProperty("file.separator")
546:                        + this .getClass().getName() + ".prop";
547:            }
548:
549:            // return form properties file directory name
550:            protected String getPreferencesDirectoryName() {
551:                return System.getProperty("user.home")
552:                        + System.getProperty("file.separator") + "softaris"
553:                        + System.getProperty("file.separator")
554:                        + Application.sApplicationName;
555:            }
556:
557:            /** Retrieves specifeid user property or null if specified property has not been found */
558:            public String getProperty(String pKey) {
559:                if (mPreferences == null)
560:                    throw new RuntimeException(
561:                            "UserPreferences singleton is not initialised");
562:                return mPreferences.getProperty(pKey);
563:            }
564:
565:            /** Retrieves specifeid user property or default value if specified property has not been found */
566:            public String getProperty(String pKey, String pDefaultValue) {
567:                if (mPreferences == null)
568:                    throw new RuntimeException(
569:                            "UserPreferences singleton is not initialised");
570:                return mPreferences.getProperty(pKey, pDefaultValue);
571:            }
572:
573:            /** Sets specified property to the specified value.
574:             *  @return previous value associated with the key or null if none given */
575:            public String setProperty(String pKey, String pValue) {
576:                if (mPreferences == null)
577:                    throw new RuntimeException(
578:                            "UserPreferences singleton is not initialised");
579:                String pOldValue = (String) mPreferences.setProperty(pKey,
580:                        pValue);
581:                // Maintain modified flag
582:                if ((pOldValue == null) || (!pOldValue.equals(pValue)))
583:                    mModified = true;
584:                return pOldValue;
585:            }
586:
587:            /** Sets specified property to the specified value.
588:             *  @return previous value associated with the key or null if none given */
589:            public String setPropertyNoModified(String pKey, String pValue) {
590:                if (mPreferences == null)
591:                    throw new RuntimeException(
592:                            "UserPreferences singleton is not initialised");
593:                return (String) mPreferences.setProperty(pKey, pValue);
594:            }
595:
596:            // convert rectangle to string  
597:            protected String rectangleToString(Rectangle lRectangle) {
598:                return Integer.toString((int) lRectangle.getX()) + ","
599:                        + Integer.toString((int) lRectangle.getY()) + ","
600:                        + Integer.toString((int) lRectangle.getWidth()) + ","
601:                        + Integer.toString((int) lRectangle.getHeight());
602:            }
603:
604:            /*				Auxilary classes				*/
605:
606:            /*     Name Element Change Listener class       */
607:
608:            public class NameElementChangeListener implements  ItemListener {
609:                public void itemStateChanged(ItemEvent e) {
610:                    processNameModelElementChange();
611:                }
612:            }
613:
614:            /*     Class for the panel with resize element       */
615:
616:            public class ResizerPanel extends JPanel {
617:                JDialog mDialog = null;
618:
619:                public ResizerPanel(JDialog pDialog) {
620:                    super ();
621:                    mDialog = pDialog;
622:                }
623:
624:                // paint panel
625:                public void paintComponent(Graphics g) {
626:                    super .paintComponent(g);
627:
628:                    if (mDialog != null && mDialog.isResizable()) {
629:                        Rectangle lRect = getBounds();
630:                        Point lEndPoint = new Point(lRect.width, lRect.height);
631:                        Color lColor = getBackground();
632:                        Color lColorBright = lColor.brighter();
633:                        Color lColorDark = lColor.darker();
634:
635:                        drawResizeLine(g, lColorBright, lColorDark, lEndPoint,
636:                                13);
637:                        drawResizeLine(g, lColorBright, lColorDark, lEndPoint,
638:                                9);
639:                        drawResizeLine(g, lColorBright, lColorDark, lEndPoint,
640:                                5);
641:                    }
642:                }
643:
644:                // draw line
645:                protected void drawResizeLine(Graphics g, Color aColorBright,
646:                        Color aColorDark, Point aEndPoint, int aDelta) {
647:                    g.setColor(aColorBright);
648:                    g.drawLine(aEndPoint.x - aDelta, aEndPoint.y, aEndPoint.x,
649:                            aEndPoint.y - aDelta);
650:                    g.setColor(aColorDark);
651:                    g.drawLine(aEndPoint.x - (aDelta - 1), aEndPoint.y,
652:                            aEndPoint.x, aEndPoint.y - (aDelta - 1));
653:                    g.drawLine(aEndPoint.x - (aDelta - 2), aEndPoint.y,
654:                            aEndPoint.x, aEndPoint.y - (aDelta - 2));
655:                }
656:            }
657:
658:            /*          Dialog's events adapter class              */
659:
660:            public class PropertiesDialogArapter extends ComponentAdapter {
661:                protected boolean mMoved = false;
662:                protected boolean mFlag = false;
663:
664:                public void componentResized(ComponentEvent e) {
665:                    if (mFlag)
666:                        return;
667:
668:                    mFlag = true;
669:                    try {
670:                        JDialog lDialog = (JDialog) e.getComponent();
671:                        Dimension lMinSize = lDialog.getMinimumSize();
672:                        Dimension lSize = lDialog.getSize();
673:
674:                        if (lSize.width < lMinSize.width
675:                                || lSize.height < lMinSize.height) {
676:                            Dimension lNewSize = new Dimension(Math.max(
677:                                    lSize.width, lMinSize.width), Math.max(
678:                                    lSize.height, lMinSize.height));
679:                            if (mMoved) {
680:                                Point lLocation = lDialog.getLocation();
681:                                lLocation.x -= (lNewSize.width - lSize.width);
682:                                lLocation.y -= (lNewSize.height - lSize.height);
683:                                lDialog.setLocation(lLocation);
684:                                mMoved = false;
685:                            }
686:                            lDialog.setSize(lNewSize);
687:                        }
688:                    } finally {
689:                        mFlag = false;
690:                    }
691:                }
692:
693:                public void componentMoved(ComponentEvent e) {
694:                    if (mFlag)
695:                        return;
696:                    if (isMinSize(e))
697:                        mMoved = true;
698:                }
699:
700:                // check dialog's sise reached minimum values 
701:                protected boolean isMinSize(ComponentEvent e) {
702:                    JDialog lDialog = (JDialog) e.getComponent();
703:                    Dimension lMinSize = lDialog.getMinimumSize();
704:                    Dimension lSize = lDialog.getSize();
705:                    return (lSize.width < lMinSize.width || lSize.height < lMinSize.height);
706:                }
707:            }
708:
709:            /*          Edit Button Action Listener         */
710:
711:            public class EditButtonActionListener implements  ActionListener {
712:                protected ComplexBox mField = null;
713:
714:                public EditButtonActionListener(ComplexBox pField) {
715:                    mField = pField;
716:                }
717:
718:                public void actionPerformed(ActionEvent e) {
719:                    if (mField != null) {
720:                        BaseUserObject lSelectedObject = mField
721:                                .getSelectedUserObject();
722:                        if (lSelectedObject != null) {
723:                            try {
724:                                lSelectedObject.editObject();
725:                            } catch (Exception ex) {
726:                                ex.printStackTrace();
727:                            }
728:                        }
729:                    }
730:                }
731:            }
732:
733:            /*       Complex Field Selection Changed Action Listener class      */
734:
735:            public class ComlexFieldChangedListener implements  ActionListener {
736:                protected ComplexBox mField = null;
737:                protected EditorButton mButton = null;
738:
739:                public ComlexFieldChangedListener(ComplexBox pField,
740:                        EditorButton pButton) {
741:                    mField = pField;
742:                    mButton = pButton;
743:                }
744:
745:                public void actionPerformed(ActionEvent e) {
746:                    mButton.setEnabled(mField.getSelectedUserObject() != null);
747:                }
748:            }
749:
750:            /*					Actions						*/
751:
752:            /*				OK Action class					*/
753:
754:            public class OKAction extends BaseAction {
755:                public OKAction() {
756:                    super ("OK", null, null);
757:                }
758:
759:                public void actionPerformed(ActionEvent arg0) {
760:                    ok();
761:                }
762:            }
763:
764:            /*				Cancel Action class				*/
765:
766:            public class CancelAction extends BaseAction {
767:                public CancelAction() {
768:                    super ("Cancel", null, null);
769:                }
770:
771:                public void actionPerformed(ActionEvent arg0) {
772:                    cancel();
773:                }
774:            }
775:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.