1 package com.opensymphony.workflow.designer.dialogs; 2 3 import java.awt.*; 4 import java.util.Iterator ; 5 import java.util.Map ; 6 import java.util.Set ; 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 18 public class DialogUtils 19 { 20 private static JTextPane textArea = new JavaTextPane(); 21 22 public static Object getUserSelection(Object [] values, String message, String title, Component parent) 23 { 24 return JOptionPane.showInputDialog(parent, message, title, JOptionPane.QUESTION_MESSAGE, ResourceManager.getIcon("saveas"), values, null); } 32 33 public static String getTextDialog(String 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 value = (Integer )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 getMapDialog(ArgsAware descriptor, String type, String 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 edits = panel.getEdits(); 68 Map args = descriptor.getArgs(); 69 Set keys = args.keySet(); 70 Iterator iter = keys.iterator(); 71 while(iter.hasNext()) 72 { 73 Object key = iter.next(); 74 JTextField field = (JTextField)edits.get(key); 75 String newValue = field.getText(); 76 args.put(key, newValue); 77 } 78 return args; 79 } 80 } 81 | Popular Tags |