001: /*
002: * argun 1.0
003: * Web 2.0 delivery framework
004: * Copyright (C) 2007 Hammurapi Group
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * URL: http://www.hammurapi.biz
021: * e-Mail: support@hammurapi.biz
022: */
023: package biz.hammurapi.web.interaction;
024:
025: import java.awt.GridBagConstraints;
026: import java.awt.GridBagLayout;
027: import java.awt.Insets;
028: import java.awt.event.ActionEvent;
029: import java.awt.event.ActionListener;
030:
031: import javax.swing.JButton;
032: import javax.swing.JEditorPane;
033: import javax.swing.JFrame;
034: import javax.swing.JLabel;
035: import javax.swing.JOptionPane;
036: import javax.swing.JScrollPane;
037: import javax.swing.JTabbedPane;
038: import javax.swing.JTextArea;
039: import javax.swing.JTextField;
040: import javax.swing.JTextPane;
041:
042: /**
043: * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
044: * Builder, which is free for non-commercial use. If Jigloo is being used
045: * commercially (ie, by a corporation, company or business for any purpose
046: * whatever) then you should purchase a license for each developer using Jigloo.
047: * Please visit www.cloudgarden.com for details. Use of Jigloo implies
048: * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
049: * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
050: * ANY CORPORATE OR COMMERCIAL PURPOSE.
051: */
052: public class InteractionElementPropertiesDialog extends
053: javax.swing.JDialog {
054: private JButton okButton;
055:
056: private JButton cancelButton;
057:
058: private JTextArea actionTextArea;
059:
060: private JScrollPane actionScrollPane;
061:
062: private JTextArea guardTextArea;
063:
064: private JScrollPane guardScrollPane;
065:
066: private JLabel nameLabel;
067:
068: private JEditorPane descriptionEditorPane;
069:
070: private JScrollPane descriptionScrollPane;
071:
072: private JTabbedPane tabbedPanel;
073:
074: private JTextField nameField;
075:
076: private InteractionElement data;
077:
078: /**
079: * Auto-generated main method to display this JDialog
080: */
081: public static void main(String[] args) {
082: JFrame frame = new JFrame();
083: frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
084: InteractionElementPropertiesDialog inst = new InteractionElementPropertiesDialog(
085: frame, null);
086: inst.setVisible(true);
087: frame.dispose();
088: //System.exit(0);
089: }
090:
091: public InteractionElementPropertiesDialog(JFrame frame,
092: InteractionElement data) {
093: super (frame);
094: this .data = data;
095: initGUI();
096: nameField.setText(data.getName());
097: descriptionEditorPane.setText(data.getDescription());
098: actionTextArea.setText(data.getAction());
099: guardTextArea.setText(data.getGuard());
100: }
101:
102: private void initGUI() {
103: try {
104: GridBagLayout this Layout = new GridBagLayout();
105: this Layout.rowWeights = new double[] { 0.0, 0.1, 0.0 };
106: this Layout.rowHeights = new int[] { 32, 303, 7 };
107: this Layout.columnWeights = new double[] { 0.0, 0.1, 0.0 };
108: this Layout.columnWidths = new int[] { 45, 354, 7 };
109: getContentPane().setLayout(this Layout);
110: this .setName("Properties");
111: this .setModal(true);
112: this .setTitle("Properties");
113: {
114: nameField = new JTextField();
115: getContentPane().add(
116: nameField,
117: new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0,
118: GridBagConstraints.WEST,
119: GridBagConstraints.HORIZONTAL,
120: new Insets(0, 0, 0, 0), 0, 0));
121: nameField.setText("Step name");
122: nameField.setSize(200, 20);
123: }
124: {
125: okButton = new JButton();
126: getContentPane().add(
127: okButton,
128: new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0,
129: GridBagConstraints.EAST,
130: GridBagConstraints.NONE, new Insets(3,
131: 0, 3, 3), 0, 0));
132: okButton.setText("OK");
133: okButton.addActionListener(new ActionListener() {
134: public void actionPerformed(ActionEvent evt) {
135: okButtonActionPerformed(evt);
136: }
137: });
138: }
139: {
140: cancelButton = new JButton();
141: getContentPane().add(
142: cancelButton,
143: new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0,
144: GridBagConstraints.WEST,
145: GridBagConstraints.NONE, new Insets(3,
146: 0, 3, 3), 0, 0));
147: cancelButton.setText("Cancel");
148: cancelButton.addActionListener(new ActionListener() {
149: public void actionPerformed(ActionEvent evt) {
150: cancelButtonActionPerformed(evt);
151: }
152: });
153: }
154: {
155: tabbedPanel = new JTabbedPane();
156: getContentPane().add(
157: tabbedPanel,
158: new GridBagConstraints(0, 1, 3, 1, 0.0, 0.0,
159: GridBagConstraints.NORTHWEST,
160: GridBagConstraints.BOTH, new Insets(0,
161: 0, 0, 0), 0, 0));
162: {
163: descriptionScrollPane = new JScrollPane();
164: tabbedPanel.addTab("Description", null,
165: descriptionScrollPane, null);
166: descriptionScrollPane
167: .setPreferredSize(new java.awt.Dimension(
168: 360, 159));
169: descriptionScrollPane.setAutoscrolls(true);
170: {
171: descriptionEditorPane = new JTextPane();
172: descriptionScrollPane
173: .setViewportView(descriptionEditorPane);
174: descriptionEditorPane.setText("Description");
175: descriptionEditorPane
176: .setPreferredSize(new java.awt.Dimension(
177: 185, 74));
178: }
179: }
180: {
181: guardScrollPane = new JScrollPane();
182: tabbedPanel.addTab("Guard", null, guardScrollPane,
183: null);
184: {
185: guardTextArea = new JTextArea();
186: guardScrollPane.setViewportView(guardTextArea);
187: guardTextArea
188: .setText("// Put condition code here");
189: guardTextArea.setFont(new java.awt.Font(
190: "Courier New", 0, 11));
191: guardTextArea.setTabSize(4);
192: }
193: }
194: {
195: actionScrollPane = new JScrollPane();
196: tabbedPanel.addTab("Action", null,
197: actionScrollPane, null);
198: {
199: actionTextArea = new JTextArea();
200: actionScrollPane
201: .setViewportView(actionTextArea);
202: actionTextArea
203: .setText("// Put action code here");
204: actionTextArea.setFont(new java.awt.Font(
205: "Courier New", 0, 11));
206: actionTextArea.setTabSize(4);
207: }
208: }
209: }
210: {
211: nameLabel = new JLabel();
212: getContentPane().add(
213: nameLabel,
214: new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
215: GridBagConstraints.CENTER,
216: GridBagConstraints.NONE, new Insets(0,
217: 0, 0, 5), 0, 0));
218: nameLabel.setText("Name");
219: }
220: this .setSize(500, 400);
221: } catch (Exception e) {
222: e.printStackTrace();
223: }
224: }
225:
226: public static boolean compareStrings(String str1, String str2) {
227: if (str1 == str2) {
228: return true;
229: }
230: if (str1 == null || str1.trim().length() == 0) {
231: return str2 == null || str2.trim().length() == 0;
232: }
233:
234: return str1.equals(str2);
235: }
236:
237: private void okButtonActionPerformed(ActionEvent evt) {
238: if (data instanceof Step) {
239: if (nameField.getText() == null
240: || nameField.getText().trim().length() == 0) {
241: JOptionPane.showMessageDialog(this ,
242: "Step name shall not be blank");
243: return;
244: } else if (!compareStrings(nameField.getText(), data
245: .getName())
246: && data.getInteraction().checkDuplicateStepName(
247: nameField.getText())) {
248:
249: JOptionPane.showMessageDialog(this ,
250: "Duplicate step name");
251: return;
252: }
253: }
254:
255: data.setName(nameField.getText());
256: data.setDescription(descriptionEditorPane.getText());
257: data.setAction(actionTextArea.getText());
258: data.setGuard(guardTextArea.getText());
259: data.getInteraction().getApplet().modelChanged();
260: cancelButtonActionPerformed(evt);
261: }
262:
263: private void cancelButtonActionPerformed(ActionEvent evt) {
264: setVisible(false);
265: dispose();
266: }
267: }
|