1 package ist.coach.coachEmfClientComponents.gui; 2 3 import javax.swing.table.AbstractTableModel ; 5 6 import javax.swing.DefaultCellEditor ; 7 8 import javax.swing.JScrollPane ; 9 import javax.swing.JFrame ; 10 import javax.swing.JPanel ; 11 import javax.swing.SwingUtilities ; 12 import javax.swing.JOptionPane ; 13 import javax.swing.JButton ; 14 import java.awt.*; 15 import java.awt.event.*; 16 import java.util.Hashtable ; 17 import java.util.Vector ; 18 19 23 public class AttributesFrame extends JFrame 24 implements ActionListener{ 25 26 GuiMaster master; 27 String object_type; 29 String visual_object_class; 30 ParamTableModel myModel; 31 String [] param_name = null; 32 boolean[] param_options = null; 33 MOTreeObject tree_object; 34 35 public AttributesFrame( String object_class, 36 MOTreeObject tree_object, 38 Object [] values, 39 GuiMaster master, 40 int x_pos, int y_pos) { 41 42 super(GuiMessages.options_properties); 43 this.master = master; 44 this.tree_object = tree_object; 45 visual_object_class = object_class; 47 48 try { 49 param_name = (String [])Class.forName(object_class).getDeclaredField("attributes_name").get(null); 50 object_type = (String )Class.forName(object_class).getDeclaredField("object_type").get(null); 51 param_options = (boolean [])Class.forName(object_class).getDeclaredField("attributes_readonly").get(null); 52 53 } 54 catch(java.lang.IllegalArgumentException e1) { 55 System.err.println("IllegalArgumentException"); 56 } 57 catch(java.lang.IllegalAccessException e2) { 58 System.err.println("IllegalAccessException"); 59 } 60 catch(java.lang.ClassNotFoundException e3) { 61 System.err.println("ClassNotFoundException" + e3.getMessage()); 62 } 63 catch(java.lang.NoSuchFieldException e4) { 64 System.err.println("NoSuchFieldException"); 65 } 66 67 68 myModel = new ParamTableModel(param_name, values, param_options); 69 JAttributesTable table = new JAttributesTable(myModel); 70 table.setPreferredScrollableViewportSize(new Dimension(300, 70)); 71 table.setCellSelectionEnabled(true); 72 73 JScrollPane scrollPane = new JScrollPane (table); 75 76 JButton update_button = new JButton (GuiMessages.update_str); 77 update_button.addActionListener(this); 78 update_button.setToolTipText(GuiMessages.update_tooltip_str); 79 80 JButton cancel_button = new JButton (GuiMessages.cancel_str); 81 cancel_button.addActionListener(this); 82 cancel_button.setToolTipText(GuiMessages.cancel_tooltip_str); 83 84 JPanel submitPanel = new JPanel (new FlowLayout()); 85 submitPanel.add(update_button); 86 submitPanel.add(cancel_button); 87 88 getContentPane().add(scrollPane, BorderLayout.CENTER); 90 getContentPane().add(submitPanel, BorderLayout.SOUTH); 91 92 setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 93 100 setLocation(x_pos, y_pos); 101 pack(); 102 setVisible(true); 103 } 104 105 public void actionPerformed(ActionEvent e) { 106 107 if (e.getActionCommand().equals(GuiMessages.update_str)) { 108 109 Hashtable updates = new Hashtable (); 110 int table_size = myModel.getRowCount(); 111 for(int i = 0; i < table_size ; i++) { 112 113 if (! myModel.isCellEditable(i, 1)) 114 continue; 115 116 updates.put(myModel.getValueAt(i, 0), 117 myModel.getValueAt(i, 1)); 118 } 119 120 164 Vector retobj = tree_object.translate_updates(updates); 165 166 if (retobj == null || retobj.size() == 0) { 167 JOptionPane.showMessageDialog(this, 168 GuiMessages.update_nothing_error, 169 GuiMessages.options_update, 170 JOptionPane.WARNING_MESSAGE); 171 172 this.dispose(); 173 return; 174 } 175 176 if (master.setAttributes( (String ) myModel.getValueAt(0, 1), retobj)) { 177 JOptionPane.showMessageDialog(this, 178 GuiMessages.reply_ok, 179 GuiMessages.options_update, 180 JOptionPane.WARNING_MESSAGE); 181 182 } 183 else { 184 JOptionPane.showMessageDialog(this, 185 GuiMessages.reply_error, 186 GuiMessages.options_update, 187 JOptionPane.WARNING_MESSAGE); 188 } 189 } 190 this.dispose(); 191 } 192 } 193 | Popular Tags |