1 package cve.staticLayout; 2 3 import cve.environment.*; 4 import cve.core.elementEEL.*; 5 import cve.util.ConfigurationRead; 6 7 import java.awt.event.*; 8 import java.awt.*; 9 import javax.swing.*; 10 import javax.swing.event.*; 11 12 import java.io.File ; 13 import java.io.IOException ; 14 import java.io.*; 15 import java.util.*; 16 17 import org.apache.log4j.Logger; 18 19 import interactionGraphics.*; 20 21 28 public class ChoiceEnvironment extends GenericFrame 29 implements ListSelectionListener,ActionListener,MouseListener { 30 31 35 private Vector session=new Vector(); 36 37 40 private JList listSes,listEle; 41 42 45 private JButton esegui; 46 47 50 private JButton annulla; 51 52 56 private DefaultListModel model=new DefaultListModel(); 57 58 63 private Vector classes=new Vector(); 64 65 70 private Vector icons=new Vector(); 71 72 76 private int size_width = 800; 77 private int size_heigth= 800;; 78 79 private JSplitPane SplitVertical; 80 81 84 IEnvironmentEEL envEEL; 85 86 89 private Cve cveFrame; 90 91 96 public ChoiceEnvironment(String Title, String iconPath) { 97 super(Title, iconPath); 98 Cve.errLog.debug(""); 99 }; 100 101 public void init(JFrame cveFrame) { 102 Cve.errLog.debug(""); 104 this.cveFrame=(Cve)cveFrame; 105 Container contentPane=getContentPane(); 106 contentPane.setLayout ( new BorderLayout() ); 107 108 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 111 setLocation(((screenSize.width*10)/100),((screenSize.width*10)/100)); 112 113 setSize(size_width,size_heigth); 115 JPanel pan1=new JPanel(); 116 pan1.setLayout ( new GridLayout(1,1) ); 117 118 Collection containerEnv=ConfigurationRead.getEnvironmentContainer(); 120 Iterator itContainer=containerEnv.iterator(); 121 if (itContainer!=null){ 122 while (itContainer.hasNext()){ 123 String nameContainer=(String )itContainer.next(); 124 session.add(nameContainer); 125 } 126 } 127 128 listSes = new JList(session); 130 listSes.addListSelectionListener(this); 131 listSes.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 132 JScrollPane listScrollPane = new JScrollPane(listSes); 133 listSes.setPreferredSize(new Dimension(300, 300)); 134 pan1.add(listScrollPane); 135 137 listEle = new JList(model); 139 listEle.addMouseListener(this); 140 listEle.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 141 JScrollPane listScrollPane1 = new JScrollPane(listEle); 142 listEle.setPreferredSize(new Dimension(300, 300)); 143 pan1.add(listScrollPane1); 144 146 147 SplitVertical = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); 148 SplitVertical.setLeftComponent( listScrollPane ); 149 SplitVertical.setRightComponent( listScrollPane1 ); 150 SplitVertical.setOneTouchExpandable( true ); 151 SplitVertical.setDividerLocation( 250 ); 152 SplitVertical.setResizeWeight( 0 ); 153 154 pan1.add(SplitVertical,"Center"); 155 156 JPanel pan=new JPanel(new FlowLayout()); 157 158 ImageIcon iconopen = new ImageIcon(ConfigurationRead.getCveRoot() + "//resource//OPEN.gif"); 159 esegui=new JButton("OK",iconopen); 160 esegui.setEnabled(false); 161 esegui.addActionListener(this); 162 163 ImageIcon iconcancel = new ImageIcon(ConfigurationRead.getCveRoot() + "//resource//CANCEL.gif"); 164 annulla=new JButton("Cancel", iconcancel); 165 annulla.addActionListener(this); 166 167 pan.add(esegui); 168 pan.add(annulla); 169 contentPane.add(pan1,BorderLayout.CENTER); 170 contentPane.add(pan,BorderLayout.SOUTH); 171 pack(); 172 show(); 173 setVisible(true); 174 } 175 176 182 public void valueChanged(ListSelectionEvent e) { 183 Cve.errLog.debug(""); 184 if (e.getValueIsAdjusting() == false) { 185 186 if (listSes.getSelectedIndex() == -1) { 188 esegui.setEnabled(false); 190 } 191 192 model.removeAllElements(); 195 196 classes.clear(); 198 199 icons.clear(); 201 202 java.util.List itemEnv=ConfigurationRead.getEnvironmentItem(listSes.getSelectedIndex()); 203 204 java.util.List itemEnvClass=ConfigurationRead.getEnvironmentItemClass(listSes.getSelectedIndex()); 205 java.util.List itemEnvIcon=ConfigurationRead.getEnvironmentItemIcon(listSes.getSelectedIndex()); 206 207 Iterator itItem=itemEnv.iterator(); 208 Iterator itItemClass=itemEnvClass.iterator(); 209 Iterator itItemIcon=itemEnvIcon.iterator(); 210 211 if (itItem!=null){ 212 while (itItem.hasNext()){ 213 String nameItem=(String )itItem.next(); 215 model.addElement(nameItem); 216 217 String nameClass=(String )itItemClass.next(); 221 classes.addElement(nameClass); 222 223 String pathImage=(String )itItemIcon.next(); 224 icons.addElement(pathImage); 225 } 226 } 227 228 esegui.setEnabled(false); 229 } 230 } 231 232 235 public void mouseReleased(MouseEvent me){} 236 237 240 public void mouseExited(MouseEvent me){} 241 242 245 public void mouseEntered(MouseEvent me){} 246 247 250 public void mouseClicked(MouseEvent me){} 251 252 258 public void mousePressed(MouseEvent me){ 259 Cve.errLog.debug(""); 260 if (me.getModifiers()==me.BUTTON1_MASK ){ 261 262 if (listEle.getSelectedIndex() >= 0){ 264 esegui.setEnabled(true); 265 } else { 266 esegui.setEnabled(false); 267 } 268 } 269 if (me.getModifiers()==me.BUTTON3_MASK ){ 270 System.out.println(" @staticLayout.ChoiceEnvironment: mousePressed : BUTTON3_MASK (Rigth)"); 271 272 if (esegui.isEnabled()==true){ 273 loadEnv(); 274 } 275 } 276 } 277 278 284 public void actionPerformed(ActionEvent e) { 285 Cve.errLog.debug(""); 286 if (e.getActionCommand().equals("OK")) { 287 loadEnv(); 288 } else { Cve.setChoiceEnvOpen(false); 290 this.dispose(); 291 } 292 } 293 294 298 private void loadEnv() { 299 305 Cve.errLog.debug(""); 306 String nameClass = (String )classes.get(listEle.getSelectedIndex()); 307 String pathIcon = (String )icons.get(listEle.getSelectedIndex()); 308 String titleEnv = (String )model.get(listEle.getSelectedIndex()); 309 Class env=null; 311 try { 312 env = Class.forName(nameClass); 313 } catch (ClassNotFoundException ex) { 314 Cve.errLog.error(ex.toString()); 315 } 316 try { 318 Make_env envobj = (Make_env)env.newInstance(); 319 320 envobj.setIconEnv(pathIcon); 322 323 envobj.setTitle(titleEnv); 325 326 envobj.createEnv(); 328 329 envEEL=envobj.getEnvironmentEEL(); 330 cveFrame.setEnvironment(envEEL); 331 } catch (Exception exc) { 332 Cve.errLog.error(exc.toString()); 333 } 334 335 Cve.setChoiceEnvOpen(false); 336 this.dispose(); 337 } 338 339 } | Popular Tags |