KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > workflow > designer > swing > MapPanel


1 package com.opensymphony.workflow.designer.swing;
2
3 import java.util.*;
4
5 import javax.swing.*;
6
7 import com.jgoodies.forms.layout.FormLayout;
8 import com.jgoodies.forms.builder.DefaultFormBuilder;
9 import com.opensymphony.workflow.designer.ResourceManager;
10 import com.opensymphony.workflow.designer.UIFactory;
11 import com.opensymphony.workflow.loader.ArgsAware;
12
13 /**
14  * @author Gulei
15  */

16 public class MapPanel extends JPanel
17 {
18   private Map edits = new HashMap();
19
20   public Map getEdits()
21   {
22     return edits;
23   }
24
25   public MapPanel(final ArgsAware descriptor, String JavaDoc type, String JavaDoc owner)
26   {
27     FormLayout layout = new FormLayout("2dlu, left:max(40dlu;pref), 3dlu, pref:grow, 7dlu");
28         DefaultFormBuilder builder = new DefaultFormBuilder(this, layout, ResourceManager.getBundle());
29       builder.setLeadingColumnOffset(1);
30     builder.appendI15dSeparator("info");
31     builder.appendI15d("type", new JLabel(noNull(type)));
32       builder.appendI15d("name", new JLabel(noNull(descriptor.getName())));
33       builder.appendI15d("description", new JLabel(noNull(descriptor.getDescription())));
34         if(owner!=null)
35         {
36             JTextField tf = new JTextField(15);
37             tf.setText(noNull(owner));
38             builder.appendI15d("owner", tf);
39             edits.put("Owner", tf);
40         }
41     Map args = descriptor.getArgs();
42     if(args.size() > 0)
43     {
44       builder.appendI15dSeparator("args");
45     }
46
47     List keys = new ArrayList(args.keySet());
48       Collections.sort(keys, new Comparator()
49       {
50           public int compare(Object JavaDoc o1, Object JavaDoc o2)
51           {
52               String JavaDoc key1 = (String JavaDoc)o1;
53               String JavaDoc key2 = (String JavaDoc)o2;
54               boolean mod1 = descriptor.isArgModifiable(key1);
55               boolean mod2 = descriptor.isArgModifiable(key2);
56               if(mod1 && !mod2) return 1;
57               if(mod2 && !mod1) return -1;
58               String JavaDoc value1 = descriptor.getPalette().getBundle().getString(descriptor.getName() + "." + key1, key1);
59               String JavaDoc value2 = descriptor.getPalette().getBundle().getString(descriptor.getName() + "." + key2, key2);
60               return value1.compareTo(value2);
61           }
62       });
63     Iterator iter = keys.iterator();
64     while(iter.hasNext())
65     {
66       String JavaDoc key = (String JavaDoc)iter.next();
67       JTextField field = descriptor.isArgModifiable(key) ? new JTextField(30) : UIFactory.createReadOnlyTextField(30);
68       if(args.get(key) != null)
69       {
70         field.setText((String JavaDoc)args.get(key));
71       }
72         String JavaDoc value = descriptor.getPalette().getBundle().getString(descriptor.getName() + "." + key, key);
73         builder.append(value, field);
74       edits.put(key, field);
75     }
76   }
77
78   private static String JavaDoc noNull(String JavaDoc s)
79   {
80     return s==null ? "" : s;
81   }
82 }
83
Popular Tags