KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ist > coach > coachEmfClientComponents > gui > CreateParamsFrame


1 package ist.coach.coachEmfClientComponents.gui;
2
3
4 import javax.swing.JTable JavaDoc;
5 import javax.swing.table.AbstractTableModel JavaDoc;
6
7 import javax.swing.DefaultCellEditor JavaDoc;
8
9 import javax.swing.JScrollPane JavaDoc;
10 import javax.swing.JFrame JavaDoc;
11 import javax.swing.JPanel JavaDoc;
12 import javax.swing.SwingUtilities JavaDoc;
13 import javax.swing.JOptionPane JavaDoc;
14 import javax.swing.JButton JavaDoc;
15 import java.awt.*;
16 import java.awt.event.*;
17
18 public class CreateParamsFrame extends JFrame JavaDoc
19 implements ActionListener, Runnable JavaDoc {
20
21     GuiMaster master;
22     GuiClient gui;
23     String JavaDoc parent_key;
24     String JavaDoc object_type;
25     ParamTableModel myModel;
26     String JavaDoc [] param_name = null;
27
28     public CreateParamsFrame( String JavaDoc object_class,
29                             String JavaDoc parent_key,
30                             GuiMaster master,
31                             GuiClient gui,
32                             int x_pos, int y_pos) {
33
34         super(GuiMessages.options_create);
35         this.master = master;
36         this.parent_key = parent_key;
37         this.gui = gui;
38
39         System.err.println("Create was called for " +
40             object_class + " class with parent " +
41             parent_key);
42         try {
43             // HACK: Introspection used
44
//
45
param_name = (String JavaDoc [])Class.forName(object_class).getDeclaredField("create_arg_name").get(null);
46              object_type = (String JavaDoc)Class.forName(object_class).getDeclaredField("object_type").get(null);
47             //GuiClient.println("Read params:");
48
//for (int i = 0; i < param_name.length; i++)
49
// GuiClient.println("param[" + i + "] = " + param_name[i]);
50
}
51         catch(java.lang.IllegalArgumentException JavaDoc e1) {
52             GuiClient.println("IllegalArgumentException");
53         }
54         catch(java.lang.IllegalAccessException JavaDoc e2) {
55             GuiClient.println("IllegalAccessException");
56         }
57         catch(java.lang.ClassNotFoundException JavaDoc e3) {
58             GuiClient.println("ClassNotFoundException" + e3.getMessage());
59         }
60         catch(java.lang.NoSuchFieldException JavaDoc e4) {
61             GuiClient.println("NoSuchFieldException");
62         }
63
64
65         myModel = new ParamTableModel(param_name);
66         //JTable table = new JTable(myModel);
67
JAttributesTable table = new JAttributesTable(myModel);
68         table.setPreferredScrollableViewportSize(new Dimension(300, 70));
69         table.setCellSelectionEnabled(true);
70
71         //Create the scroll pane and add the table to it.
72
JScrollPane JavaDoc scrollPane = new JScrollPane JavaDoc(table);
73
74         //Set up real input validation for the integer column.
75
// setUpIntegerEditor(table);
76

77         JButton JavaDoc ok_button = new JButton JavaDoc(GuiMessages.ok_str);
78         ok_button.addActionListener(this);
79         ok_button.setToolTipText(GuiMessages.create_tooltip_str);
80
81         JButton JavaDoc cancel_button = new JButton JavaDoc(GuiMessages.cancel_str);
82         cancel_button.addActionListener(this);
83         cancel_button.setToolTipText(GuiMessages.cancel_tooltip_str);
84
85         JPanel JavaDoc submitPanel = new JPanel JavaDoc(new FlowLayout());
86         submitPanel.add(ok_button);
87         submitPanel.add(cancel_button);
88
89         //Add the scroll pane to this window.
90
getContentPane().add(scrollPane, BorderLayout.CENTER);
91         getContentPane().add(submitPanel, BorderLayout.SOUTH);
92
93         setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
94         /*******
95         addWindowListener(new WindowAdapter() {
96             public void windowClosing(WindowEvent e) {
97                 System.exit(0);
98             }
99         });
100         ********/

101         setLocation(x_pos, y_pos);
102         pack();
103         setVisible(true);
104     }
105
106     public void run() {}
107
108     public void actionPerformed(ActionEvent e) {
109
110         if (e.getActionCommand().equals(GuiMessages.ok_str)) {
111
112             Object JavaDoc[] values = new Object JavaDoc[myModel.getRowCount()];
113             for(int i = 0; i < values.length; i++) {
114                 values[i] = myModel.getValueAt(i, 1);
115
116                 //myModel.printDebugData();
117
}
118
119             String JavaDoc new_object_name = master.createByManager(object_type,
120                 param_name, values, parent_key);
121
122             if (new_object_name.length() > 0) {
123                 gui.create(new_object_name, object_type);
124
125                 JOptionPane.showMessageDialog(this,
126                     GuiMessages.reply_ok,
127                     GuiMessages.options_create,
128                     JOptionPane.WARNING_MESSAGE);
129             }
130
131         }
132          this.dispose();
133     }
134
135
136 /***
137     private void setUpIntegerEditor(JTable table) {
138         //Set up the editor for the integer cells.
139         final WholeNumberField integerField = new WholeNumberField(0, 5);
140         integerField.setHorizontalAlignment(WholeNumberField.RIGHT);
141
142         DefaultCellEditor integerEditor =
143             new DefaultCellEditor(integerField) {
144                 //Override DefaultCellEditor's getCellEditorValue method
145                 //to return an Integer, not a String:
146                 public Object getCellEditorValue() {
147                     return new Integer(integerField.getValue());
148                 }
149             };
150         table.setDefaultEditor(Integer.class, integerEditor);
151     }
152 *****/

153
154 }
155
Popular Tags