01: package com.opensymphony.workflow.designer.dialogs;
02:
03: import java.awt.*;
04: import java.util.Iterator;
05: import java.util.Map;
06: import java.util.Set;
07:
08: import javax.swing.*;
09:
10: import com.opensymphony.workflow.designer.swing.MapPanel;
11: import com.opensymphony.workflow.designer.swing.JavaTextPane;
12: import com.opensymphony.workflow.designer.ResourceManager;
13: import com.opensymphony.workflow.loader.ArgsAware;
14:
15: /**
16: * @author Gulei
17: */
18: public class DialogUtils {
19: private static JTextPane textArea = new JavaTextPane();
20:
21: public static Object getUserSelection(Object[] values,
22: String message, String title, Component parent) {
23: return JOptionPane.showInputDialog(parent, // parent component
24: message, // dialog message
25: title, // dialog title
26: JOptionPane.QUESTION_MESSAGE, // question message type
27: ResourceManager.getIcon("saveas"), // icon
28: values, // selections
29: null); // initial select
30: }
31:
32: public static String getTextDialog(String initialValue,
33: Component parent) {
34: JPanel panel = new JPanel(new GridLayout(1, 1));
35: textArea.setText(initialValue != null ? initialValue.trim()
36: : "");
37: panel.add(new JScrollPane(textArea));
38:
39: JOptionPane pane = new JOptionPane(panel,
40: JOptionPane.QUESTION_MESSAGE,
41: JOptionPane.OK_CANCEL_OPTION);
42: JDialog dialog = pane.createDialog(parent, ResourceManager
43: .getString("specify.properties"));
44: dialog.setSize(450, 190);
45: dialog.setResizable(true);
46: dialog.show();
47:
48: Integer value = (Integer) pane.getValue();
49: if (value == null) {
50: return null;
51: }
52: if (value.intValue() != JOptionPane.OK_OPTION) {
53: return null;
54: }
55: return textArea.getText().trim();
56: }
57:
58: public static Map getMapDialog(ArgsAware descriptor, String type,
59: String owner, Component parent) {
60: BaseDialog dialog = new BaseDialog((Frame) parent,
61: ResourceManager.getString("specify.properties"), true);
62: dialog.getBanner().setSubtitle(
63: ResourceManager.getString("specify.properties.long"));
64: MapPanel panel = new MapPanel(descriptor, type, owner);
65: dialog.getContentPane().add(panel);
66: dialog.setResizable(true);
67:
68: boolean result = dialog.ask(parent);
69: if (!result)
70: return null;
71:
72: Map edits = panel.getEdits();
73: Map args = descriptor.getArgs();
74: Set keys = args.keySet();
75: Iterator iter = keys.iterator();
76: while (iter.hasNext()) {
77: Object key = iter.next();
78: JTextField field = (JTextField) edits.get(key);
79: String newValue = field.getText();
80: args.put(key, newValue);
81: }
82: return args;
83: }
84: }
|