1 package ist.coach.coachEmfClientComponents.gui; 2 3 4 import javax.swing.JTable ; 5 import javax.swing.table.AbstractTableModel ; 6 7 import javax.swing.DefaultCellEditor ; 8 9 import javax.swing.JScrollPane ; 10 import javax.swing.JFrame ; 11 import javax.swing.JPanel ; 12 import javax.swing.SwingUtilities ; 13 import javax.swing.JOptionPane ; 14 import javax.swing.JButton ; 15 import java.awt.*; 16 import java.awt.event.*; 17 18 public class CreateParamsFrame extends JFrame 19 implements ActionListener, Runnable { 20 21 GuiMaster master; 22 GuiClient gui; 23 String parent_key; 24 String object_type; 25 ParamTableModel myModel; 26 String [] param_name = null; 27 28 public CreateParamsFrame( String object_class, 29 String 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 param_name = (String [])Class.forName(object_class).getDeclaredField("create_arg_name").get(null); 46 object_type = (String )Class.forName(object_class).getDeclaredField("object_type").get(null); 47 } 51 catch(java.lang.IllegalArgumentException e1) { 52 GuiClient.println("IllegalArgumentException"); 53 } 54 catch(java.lang.IllegalAccessException e2) { 55 GuiClient.println("IllegalAccessException"); 56 } 57 catch(java.lang.ClassNotFoundException e3) { 58 GuiClient.println("ClassNotFoundException" + e3.getMessage()); 59 } 60 catch(java.lang.NoSuchFieldException e4) { 61 GuiClient.println("NoSuchFieldException"); 62 } 63 64 65 myModel = new ParamTableModel(param_name); 66 JAttributesTable table = new JAttributesTable(myModel); 68 table.setPreferredScrollableViewportSize(new Dimension(300, 70)); 69 table.setCellSelectionEnabled(true); 70 71 JScrollPane scrollPane = new JScrollPane (table); 73 74 77 JButton ok_button = new JButton (GuiMessages.ok_str); 78 ok_button.addActionListener(this); 79 ok_button.setToolTipText(GuiMessages.create_tooltip_str); 80 81 JButton cancel_button = new JButton (GuiMessages.cancel_str); 82 cancel_button.addActionListener(this); 83 cancel_button.setToolTipText(GuiMessages.cancel_tooltip_str); 84 85 JPanel submitPanel = new JPanel (new FlowLayout()); 86 submitPanel.add(ok_button); 87 submitPanel.add(cancel_button); 88 89 getContentPane().add(scrollPane, BorderLayout.CENTER); 91 getContentPane().add(submitPanel, BorderLayout.SOUTH); 92 93 setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 94 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 [] values = new Object [myModel.getRowCount()]; 113 for(int i = 0; i < values.length; i++) { 114 values[i] = myModel.getValueAt(i, 1); 115 116 } 118 119 String 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 153 154 } 155 | Popular Tags |