1 23 package org.enhydra.kelp.common.importer; 24 25 import org.enhydra.kelp.common.ValidationException; 27 import org.enhydra.kelp.common.ValidationUtil; 28 import org.enhydra.kelp.common.xmlc.MapPanel; 29 import org.enhydra.kelp.common.xmlc.MapDialog; 30 31 import javax.swing.*; 33 import javax.swing.border.*; 34 import java.awt.*; 35 import java.beans.*; 36 import java.io.File ; 37 import java.awt.event.*; 38 import java.util.ResourceBundle ; 39 40 46 public class ImportMapPanel extends ImporterPanel { 47 static ResourceBundle res = 48 ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); transient private MapPanel mapPanel; 50 transient private JPanel panelPack; 51 transient private JTextField textPack; 52 53 transient private JPanel panelEdit; 55 transient private GridBagLayout layoutMain; 56 transient private GridBagLayout layoutPack; 57 transient private TitledBorder borderPack; 58 transient private JButton buttonEdit; 59 transient private GridBagLayout layoutEdit; 60 61 66 public ImportMapPanel() { 67 try { 68 jbInit(); 69 pmInit(); 70 } catch (Exception ex) { 71 ex.printStackTrace(); 72 } 73 } 74 75 82 public void readOptions() { 83 String pack = null; 84 String map[][] = new String [0][2]; 85 86 pack = getPaths().getPackage(); 87 if (pack != null) { 88 textPack.setText(pack); 89 } 90 map = getPaths().getPackageMap(); 91 mapPanel.setMap(map); 92 } 93 94 100 public void activated() { 101 initPacks(); 102 } 103 104 111 public void writeOptions() throws ValidationException { 112 String pack = new String (); 113 String [][] map = new String [0][2]; 114 115 if (getPaths() == null) { 116 throw new ValidationException(res.getString("ImportPaths_not_set")); 117 } 118 pack = textPack.getText().trim(); 119 getPaths().setPackage(pack); 120 map = mapPanel.getMap(); 121 getPaths().setPackageMap(map); 122 } 123 124 132 public void validateOptions() throws ValidationException { 133 String value = new String (); 134 135 value = textPack.getText().trim(); 137 if (!ValidationUtil.isJavaPackage(value)) { 138 throw new ValidationException(res.getString("Root_invalid_java")); 139 } 140 } 141 142 148 public String getPageTitle() { 149 return res.getString("Package_details"); 150 } 151 152 159 public String getInstructions() { 160 StringBuffer buf = new StringBuffer (); 161 162 buf.append(res.getString("Enter_package_details")); 163 buf.append(res.getString("All_the_application")); 164 buf.append(res.getString("defined_at_or_below")); 165 buf.append(res.getString("The_package_map_is")); 166 buf.append(res.getString("for_source_files")); 167 return buf.toString(); 168 } 169 170 173 181 private void jbInit() throws Exception { 182 textPack = (JTextField) Beans.instantiate(getClass().getClassLoader(), 183 JTextField.class.getName()); 184 panelPack = (JPanel) Beans.instantiate(getClass().getClassLoader(), 185 JPanel.class.getName()); 186 mapPanel = (MapPanel) Beans.instantiate(getClass().getClassLoader(), 187 MapPanel.class.getName()); 188 layoutPack = 189 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 190 GridBagLayout.class.getName()); 191 layoutMain = 192 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 193 GridBagLayout.class.getName()); 194 panelEdit = (JPanel) Beans.instantiate(getClass().getClassLoader(), 195 JPanel.class.getName()); 196 buttonEdit = (JButton) Beans.instantiate(getClass().getClassLoader(), 197 JButton.class.getName()); 198 layoutEdit = 199 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 200 GridBagLayout.class.getName()); 201 panelPack.setLayout(layoutPack); 202 buttonEdit.setText(res.getString("buttonEdit_Text")); 203 buttonEdit.addActionListener(new java.awt.event.ActionListener () { 204 public void actionPerformed(ActionEvent e) { 205 editPackageMap(); 206 } 207 208 }); 209 panelEdit.setLayout(layoutEdit); 210 panelEdit.add(buttonEdit, 211 new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, 212 GridBagConstraints.CENTER, 213 GridBagConstraints.BOTH, 214 new Insets(5, 5, 5, 5), 0, 0)); 215 panelPack.add(textPack, 216 new GridBagConstraints(0, 0, 1, 1, 0.1, 0.1, 217 GridBagConstraints.WEST, 218 GridBagConstraints.HORIZONTAL, 219 new Insets(5, 5, 5, 5), 0, 0)); 220 this.setLayout(layoutMain); 221 this.add(panelPack, 222 new GridBagConstraints(0, 0, 1, 1, 0.1, 0.0, 223 GridBagConstraints.CENTER, 224 GridBagConstraints.BOTH, 225 new Insets(5, 5, 5, 5), 0, 0)); 226 this.add(mapPanel, 227 new GridBagConstraints(0, 1, 1, 1, 0.1, 0.1, 228 GridBagConstraints.CENTER, 229 GridBagConstraints.BOTH, 230 new Insets(5, 5, 5, 5), 0, 0)); 231 this.add(panelEdit, 232 new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, 233 GridBagConstraints.CENTER, 234 GridBagConstraints.BOTH, 235 new Insets(5, 5, 5, 5), 0, 0)); 236 } 237 238 244 private void pmInit() { 245 Border border = BorderFactory.createEtchedBorder(); 246 247 borderPack = BorderFactory.createTitledBorder(border); 248 borderPack.setTitle(res.getString("borderPack_Title")); 249 panelPack.setBorder(borderPack); 250 textPack.setText(new String ()); 251 } 252 253 259 private void initPacks() { 260 String pack = null; 261 String [][] map = new String [0][2]; 262 263 if (textPack.getText().trim().length() == 0) { 264 pack = getPaths().getDefaultPackage(); 265 if (pack != null) { 266 try { 267 getPaths().setPackage(pack); 268 } catch (ValidationException e) { 269 e.printStackTrace(); 270 } 271 textPack.setText(pack); 272 } 273 } 274 if (mapPanel.getMap().length == 0) { 275 getPaths().initPackageMap(false); 276 map = getPaths().getPackageMap(); 277 mapPanel.setMap(map); 278 } 279 } 280 281 private void editPackageMap() { 282 MapDialog dialog = 283 new MapDialog(((JDialog) this.getTopLevelAncestor()), 284 res.getString("Edit_Package_Map"), true); 285 286 getPaths().getProject().setPackageMap(mapPanel.getMap()); 287 dialog.setProject(getPaths().getProject()); 288 dialog.show(); 289 mapPanel.setMap(getPaths().getProject().getPackageMap()); 290 getPaths().setPackageMap(mapPanel.getMap()); 291 } 292 293 } 294 | Popular Tags |