KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > workflow > designer > dialogs > DialogUtils


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