1 2 24 package org.enhydra.tool.archive.wizard; 25 26 import org.enhydra.tool.archive.ArchiveException; 28 import org.enhydra.tool.archive.JarPlan; 29 import org.enhydra.tool.common.PathHandle; 30 31 import javax.swing.*; 33 import javax.swing.border.*; 34 import java.awt.event.ActionEvent ; 35 import java.awt.event.ActionListener ; 36 import java.awt.event.ItemEvent ; 37 import java.awt.event.ItemListener ; 38 import java.awt.*; 39 import java.beans.*; 40 import java.io.File ; 41 import java.util.ResourceBundle ; 42 43 47 public class ArchiveSelectionPanel extends ArchivePanel { 48 49 transient private GridBagLayout layoutMain; 51 transient private BorderLayout layoutDescription; 52 transient private JComboBox comboArchive; 53 transient private JLabel labelArchive; 54 transient private JPanel panelDescription; 55 transient private JTextArea textDescription; 56 transient private LocalItemListener itemListener = null; 57 transient private ArchiveType selection = null; 58 transient private JPanel panelFiller; 59 60 64 public ArchiveSelectionPanel() { 65 try { 66 jbInit(); 67 pmInit(); 68 } catch (Exception ex) { 69 ex.printStackTrace(); 70 } 71 } 72 73 public void validatePlan() throws ArchiveException { 74 75 } 77 78 public void readPlan(JarPlan plan) throws ArchiveException { 79 80 } 82 83 public void writePlan(JarPlan plan) throws ArchiveException { 84 85 } 87 88 94 public String getPageTitle() { 95 return "Archive Type"; 96 } 97 98 104 public String getInstructions() { 105 StringBuffer buf = new StringBuffer (); 106 107 buf.append("Choose an archive type and view a description of "); 108 buf.append("your selection."); 109 return buf.toString(); 110 } 111 112 118 public ArchiveType getSelection() { 119 return selection; 120 } 121 122 126 132 private void jbInit() throws Exception { 133 panelDescription = 134 (JPanel) Beans.instantiate(getClass().getClassLoader(), 135 JPanel.class.getName()); 136 labelArchive = (JLabel) Beans.instantiate(getClass().getClassLoader(), 137 JLabel.class.getName()); 138 textDescription = 139 (JTextArea) Beans.instantiate(getClass().getClassLoader(), 140 JTextArea.class.getName()); 141 comboArchive = 142 (JComboBox) Beans.instantiate(getClass().getClassLoader(), 143 JComboBox.class.getName()); 144 layoutMain = 145 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 146 GridBagLayout.class.getName()); 147 layoutDescription = 148 (BorderLayout) Beans.instantiate(getClass().getClassLoader(), 149 BorderLayout.class.getName()); 150 panelFiller = (JPanel) Beans.instantiate(getClass().getClassLoader(), 151 JPanel.class.getName()); 152 labelArchive.setMaximumSize(new Dimension(80, 20)); 153 labelArchive.setMinimumSize(new Dimension(80, 20)); 154 labelArchive.setPreferredSize(new Dimension(80, 20)); 155 labelArchive.setLabelFor(comboArchive); 156 labelArchive.setText("Archive type:"); 157 textDescription.setDisabledTextColor(SystemColor.controlText); 158 textDescription.setBackground(SystemColor.text); 159 textDescription.setBounds(2, 2, 2, 2); 160 textDescription.setMargin(new Insets(5, 5, 5, 5)); 161 textDescription.setEnabled(false); 162 textDescription.setEditable(false); 163 textDescription.setWrapStyleWord(true); 164 textDescription.setFont(labelArchive.getFont()); 165 textDescription.setLineWrap(true); 166 panelDescription.setLayout(layoutDescription); 167 panelDescription.setBorder(BorderFactory.createEtchedBorder()); 168 panelDescription.setMaximumSize(new Dimension(220, 70)); 169 panelDescription.setMinimumSize(new Dimension(220, 70)); 170 panelDescription.setPreferredSize(new Dimension(220, 70)); 171 comboArchive.setMaximumSize(new Dimension(100, 21)); 172 comboArchive.setMinimumSize(new Dimension(100, 21)); 173 comboArchive.setPreferredSize(new Dimension(100, 21)); 174 panelDescription.add(textDescription, BorderLayout.CENTER); 175 this.setLayout(layoutMain); 176 this.add(panelFiller, 177 new GridBagConstraints(3, 0, 1, 1, 0.1, 0.1, 178 GridBagConstraints.CENTER, 179 GridBagConstraints.BOTH, 180 new Insets(0, 0, 0, 0), 0, 0)); 181 this.add(comboArchive, 182 new GridBagConstraints(1, 0, 2, 1, 0.5, 0.5, 183 GridBagConstraints.WEST, 184 GridBagConstraints.NONE, 185 new Insets(5, 5, 5, 5), 100, 0)); 186 this.add(labelArchive, 187 new GridBagConstraints(0, 0, 1, 1, 0.5, 0.5, 188 GridBagConstraints.WEST, 189 GridBagConstraints.NONE, 190 new Insets(5, 10, 5, 0), 60, 15)); 191 this.add(panelDescription, 192 new GridBagConstraints(0, 1, 4, 1, 0.5, 0.5, 193 GridBagConstraints.NORTHWEST, 194 GridBagConstraints.VERTICAL, 195 new Insets(5, 5, 5, 5), 150, 80)); 196 } 197 198 private void pmInit() { 199 ArchiveType[] types = null; 200 201 types = ArchiveType.getAllTypes(); 202 comboArchive.removeAllItems(); 203 for (int i = 0; i < types.length; i++) { 204 comboArchive.addItem(types[i]); 205 } 206 if (types.length > 0) { 207 textDescription.setText(types[0].getDescription()); 208 selection = types[0]; 209 } 210 comboArchive.repaint(); 211 itemListener = new LocalItemListener(); 212 comboArchive.addItemListener(itemListener); 213 } 214 215 private class LocalItemListener implements ItemListener { 216 public void itemStateChanged(ItemEvent event) { 217 Object item = comboArchive.getSelectedItem(); 218 219 if (item instanceof ArchiveType) { 220 selection = (ArchiveType) item; 221 System.setProperty("user.dir", getWorkingRoot()); 222 textDescription.setText(selection.getDescription()); 223 } else { 224 selection = null; 225 textDescription.setText(new String ()); 226 } 227 } 228 229 } 230 } 231 | Popular Tags |