1 30 package com.genimen.djeneric.tools.modeler.dialogs; 31 32 import java.awt.BorderLayout ; 33 import java.awt.Dimension ; 34 import java.awt.event.ActionEvent ; 35 import java.awt.event.KeyEvent ; 36 37 import javax.swing.DefaultComboBoxModel ; 38 import javax.swing.JButton ; 39 import javax.swing.JLabel ; 40 import javax.swing.JList ; 41 import javax.swing.JPanel ; 42 import javax.swing.JScrollPane ; 43 import javax.swing.JTextField ; 44 import javax.swing.event.ListSelectionEvent ; 45 46 import com.genimen.djeneric.language.Messages; 47 import com.genimen.djeneric.repository.DjPackage; 48 import com.genimen.djeneric.repository.DjPersistenceManager; 49 import com.genimen.djeneric.ui.DjVerticalFlowLayout; 50 import com.genimen.djeneric.ui.Util; 51 import com.genimen.djeneric.util.DjLogger; 52 53 public class PackageEditorPanel extends JPanel 54 { 55 private static final long serialVersionUID = 1L; 56 BorderLayout borderLayout1 = new BorderLayout (); 57 JPanel jPanel3 = new JPanel (); 58 JButton _butCreate = new JButton (); 59 JButton _butRemove = new JButton (); 60 BorderLayout borderLayout3 = new BorderLayout (); 61 JScrollPane jScrollPane1 = new JScrollPane (); 62 DjVerticalFlowLayout verticalFlowLayout1 = new DjVerticalFlowLayout(); 63 JList _lstPackages = new JList (); 64 DjPersistenceManager _mgr; 65 JPanel jPanel1 = new JPanel (); 66 JLabel _lblPackage = new JLabel (); 67 JTextField _edtName = new JTextField (); 68 BorderLayout borderLayout2 = new BorderLayout (); 69 JPanel jPanel2 = new JPanel (); 70 BorderLayout borderLayout4 = new BorderLayout (); 71 72 public PackageEditorPanel(DjPersistenceManager mgr) 73 { 74 _mgr = mgr; 75 76 try 77 { 78 jbInit(); 79 updateModel(null); 80 81 } 82 catch (Exception ex) 83 { 84 DjLogger.log(ex); 85 } 86 } 87 88 private void updateModel(DjPackage selectThisOne) 89 { 90 _lstPackages.setModel(new DefaultComboBoxModel (_mgr.getPackages())); 91 if (selectThisOne != null) _lstPackages.setSelectedValue(selectThisOne, true); 92 } 93 94 void jbInit() throws Exception 95 { 96 this.setLayout(borderLayout1); 97 _butCreate.setText(Messages.getString("global.Create")); 98 _butCreate.addActionListener(new PackageEditorPanel__butCreate_actionAdapter(this)); 99 _butRemove.setText(Messages.getString("global.Delete")); 100 _butRemove.addActionListener(new PackageEditorPanel__butRemove_actionAdapter(this)); 101 jPanel3.setLayout(verticalFlowLayout1); 102 _lblPackage.setText(Messages.getString("PackageEditorPanel.PackageName")); 103 jPanel1.setLayout(borderLayout2); 104 _edtName.setFont(new java.awt.Font ("Monospaced", 0, 11)); 105 _edtName.setPreferredSize(new Dimension (200, 21)); 106 _edtName.setText(""); 107 _edtName.addKeyListener(new PackageEditorPanel__edtName_keyAdapter(this)); 108 _lstPackages.setFont(new java.awt.Font ("Monospaced", 0, 11)); 109 _lstPackages.addListSelectionListener(new PackageEditorPanel__lstPackages_listSelectionAdapter(this)); 110 jPanel2.setLayout(borderLayout4); 111 jPanel3.add(_butCreate, null); 112 jPanel3.add(_butRemove, null); 113 this.add(jPanel2, BorderLayout.CENTER); 114 jPanel2.add(jScrollPane1, BorderLayout.CENTER); 115 jPanel2.add(jPanel1, BorderLayout.SOUTH); 116 jScrollPane1.getViewport().add(_lstPackages, null); 117 this.add(jPanel3, BorderLayout.EAST); 118 jPanel1.add(_lblPackage, BorderLayout.NORTH); 119 jPanel1.add(_edtName, BorderLayout.CENTER); 120 121 Util.sizeButtons(jPanel3); 122 } 123 124 void _butCreate_actionPerformed(ActionEvent e) 125 { 126 DjPackage newPack = new DjPackage(Messages.getString("PackageEditorPanel.NewPackage")); 127 _mgr.addPackage(newPack); 128 updateModel(newPack); 129 _edtName.requestFocus(); 130 _edtName.selectAll(); 131 } 132 133 void _butRemove_actionPerformed(ActionEvent e) 134 { 135 DjPackage sel = (DjPackage) _lstPackages.getSelectedValue(); 136 if (sel != null) _mgr.removePackage(sel); 137 updateModel(null); 138 } 139 140 void _lstPackages_valueChanged(ListSelectionEvent e) 141 { 142 String name = ""; 143 DjPackage sel = (DjPackage) _lstPackages.getSelectedValue(); 144 if (sel != null) name = sel.getName(); 145 _edtName.setText(name); 146 } 147 148 void _edtName_keyReleased(KeyEvent e) 149 { 150 DjPackage sel = (DjPackage) _lstPackages.getSelectedValue(); 151 if (sel != null && _edtName.getText().trim().length() > 0) 152 { 153 sel.setName(_edtName.getText().trim()); 154 _lstPackages.repaint(); 155 } 156 else _edtName.setText(""); 157 158 } 159 160 } 161 162 class PackageEditorPanel__butCreate_actionAdapter implements java.awt.event.ActionListener 163 { 164 PackageEditorPanel adaptee; 165 166 PackageEditorPanel__butCreate_actionAdapter(PackageEditorPanel adaptee) 167 { 168 this.adaptee = adaptee; 169 } 170 171 public void actionPerformed(ActionEvent e) 172 { 173 adaptee._butCreate_actionPerformed(e); 174 } 175 } 176 177 class PackageEditorPanel__butRemove_actionAdapter implements java.awt.event.ActionListener 178 { 179 PackageEditorPanel adaptee; 180 181 PackageEditorPanel__butRemove_actionAdapter(PackageEditorPanel adaptee) 182 { 183 this.adaptee = adaptee; 184 } 185 186 public void actionPerformed(ActionEvent e) 187 { 188 adaptee._butRemove_actionPerformed(e); 189 } 190 } 191 192 class PackageEditorPanel__lstPackages_listSelectionAdapter implements javax.swing.event.ListSelectionListener 193 { 194 PackageEditorPanel adaptee; 195 196 PackageEditorPanel__lstPackages_listSelectionAdapter(PackageEditorPanel adaptee) 197 { 198 this.adaptee = adaptee; 199 } 200 201 public void valueChanged(ListSelectionEvent e) 202 { 203 adaptee._lstPackages_valueChanged(e); 204 } 205 } 206 207 class PackageEditorPanel__edtName_keyAdapter extends java.awt.event.KeyAdapter 208 { 209 PackageEditorPanel adaptee; 210 211 PackageEditorPanel__edtName_keyAdapter(PackageEditorPanel adaptee) 212 { 213 this.adaptee = adaptee; 214 } 215 216 public void keyReleased(KeyEvent e) 217 { 218 adaptee._edtName_keyReleased(e); 219 } 220 } | Popular Tags |