Source code: org/altara/mars/swingui/EditorDialog.java
1 /* MARS Network Monitor Swing User Interface
2 Copyright (C) 1999 Brian H. Trammell
3 Copyright (C) 2002 Leapfrog Research & Development, LLC
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, it is available at
17 http:///www.gnu.org/copyleft/gpl.html, or by writing to the
18 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
20 */
21
22 package org.altara.mars.swingui;
23
24 import org.altara.util.*;
25 import org.altara.mars.*;
26 import org.altara.mars.engine.*;
27 import java.util.*;
28 import java.awt.*;
29 import java.awt.event.*;
30 import javax.swing.*;
31 import javax.swing.tree.*;
32 import javax.swing.event.*;
33
34 public class EditorDialog extends JDialog {
35
36 public EditorDialog (Frame owner, Editor editor) {
37 super(owner,editor.getEditorTitle());
38
39 getContentPane().setLayout(new BorderLayout(8,8));
40 getContentPane().add((Component)editor,BorderLayout.CENTER);
41 getContentPane().add(createButtonBar(editor),BorderLayout.SOUTH);
42 this.pack();
43 this.show();
44 }
45
46 public Box createButtonBar(final Editor editor) {
47 Action okAction = new AbstractAction("OK") {
48 public void actionPerformed(ActionEvent ae) {
49 try {
50 editor.commit();
51 dispose();
52 } catch (Exception ex) {
53 JOptionPane.showMessageDialog(EditorDialog.this,
54 "Invalid input: "+ex.getMessage()+
55 "\nPlease correct the input error and try again.",
56 "Input Error",JOptionPane.ERROR_MESSAGE);
57 //ex.printStackTrace();
58 }
59 }
60 };
61
62 Action cancelAction = new AbstractAction("Cancel") {
63 public void actionPerformed(ActionEvent ae) {
64 dispose();
65 }
66 };
67
68 Box buttonBox = Box.createHorizontalBox();
69 buttonBox.add(Box.createHorizontalGlue());
70 buttonBox.add(new JButton(cancelAction));
71 buttonBox.add(new JButton(okAction));
72 return buttonBox;
73 }
74 }