Source code: org/integralsource/monsoon/jfc/OptionBox.java
1 /*
2 * Copyright (c) 2001 John Keyes
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to:
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 *
19 * $Id: OptionBox.java,v 1.1 2001/06/16 13:57:07 jbjk Exp $
20 */
21 package org.integralsource.monsoon.jfc;
22
23 /**
24 * Simple option box implementation
25 */
26 public class OptionBox
27 extends javax.swing.JDialog
28 implements java.awt.event.ActionListener
29 {
30
31 // gui components
32 private javax.swing.JTextArea _message;
33 private javax.swing.JButton _ok;
34 private javax.swing.JButton _cancel;
35 private javax.swing.border.TitledBorder _border;
36
37 // store which button was clicked
38 private boolean _isOK;
39
40 /**
41 * Constructor
42 */
43 public OptionBox(java.awt.Dialog dialog) {
44 super(dialog,true);
45 __init();
46 setResizable(false);
47 setLocation(dialog.getLocation().x+30,
48 dialog.getLocation().y+30);
49 }
50
51 /**
52 * Constructor
53 */
54 public OptionBox(java.awt.Frame frame) {
55 super(frame,true);
56 __init();
57 setResizable(false);
58 setLocation(frame.getLocation().x+30,
59 frame.getLocation().y+30);
60 }
61
62 /**
63 * Initialise gui components
64 */
65 private void __init() {
66 java.awt.Container $contentPane = getContentPane();
67 java.awt.GridBagLayout $layout
68 = new java.awt.GridBagLayout();
69 $contentPane.setLayout($layout);
70
71 java.awt.GridBagConstraints $constraints
72 = new java.awt.GridBagConstraints();
73
74 // create an insets
75 java.awt.Insets $insets = new java.awt.Insets(0,0,0,0);
76
77 _message = new javax.swing.JTextArea();
78 _message.setEditable(false);
79 _message.setBackground($contentPane.getBackground());
80 _border = new javax.swing.border.TitledBorder(
81 new javax.swing.border.EtchedBorder(),
82 "Confirmation Required");
83 _border.setTitleColor(java.awt.Color.black);
84 _message.setBorder(_border);
85 $constraints.gridx = 0;
86 $constraints.gridy = 0;
87 $constraints.gridwidth = 2;
88 $constraints.fill = $constraints.BOTH;
89 $constraints.ipadx = 100;
90 $constraints.ipady = 15;
91 $insets.top = 10;
92 $insets.bottom = 5;
93 $insets.left = 10;
94 $insets.right = 10;
95 $constraints.insets = $insets;
96 $layout.setConstraints(_message,$constraints);
97 $contentPane.add(_message);
98
99 javax.swing.JPanel $panel = new javax.swing.JPanel();
100 $panel.setLayout(new java.awt.GridLayout(1,2,5,0));
101
102 _ok = new javax.swing.JButton("OK");
103 _ok.setActionCommand("ok");
104 _ok.addActionListener(this);
105 _ok.addMouseListener(new org.integralsource.monsoon.jfc.ButtonEmphasiser());
106 $panel.add(_ok);
107
108 _cancel = new javax.swing.JButton("Cancel");
109 _cancel.addActionListener(this);
110 _cancel.addMouseListener(new org.integralsource.monsoon.jfc.ButtonEmphasiser());
111 $panel.add(_cancel);
112
113 $constraints.gridy = 1;
114 $constraints.gridwidth = 1;
115 $constraints.weightx = 1.0;
116 $constraints.fill = $constraints.NONE;
117 $constraints.ipadx = 4;
118 $constraints.ipady = 4;
119 $constraints.anchor = $constraints.CENTER;
120 $layout.setConstraints($panel,$constraints);
121 $contentPane.add($panel);
122
123 }
124
125 public void show(java.lang.String title, java.lang.String message) {
126 setTitle(title);
127 _message.setText(message);
128 pack();
129 setVisible(true);
130 }
131
132 /**
133 * Action listener for OK button
134 */
135 public void actionPerformed(java.awt.event.ActionEvent evt) {
136 if("ok".equals(evt.getActionCommand())) {
137 _isOK = true;
138 }
139 setVisible(false);
140 dispose();
141 }
142
143 /**
144 * Return true if OK button clicked, false if Cancel button clicked
145 */
146 public boolean isOK() {
147 return _isOK;
148 }
149
150 }