1 10 11 package org.enhydra.jawe.wfxml; 12 13 import java.io.*; 14 import java.awt.Component ; 15 import java.awt.Dimension ; 16 import javax.swing.*; 17 import javax.swing.JLabel ; 18 import org.enhydra.jawe.*; 19 import org.enhydra.jawe.xml.XMLButton; 20 import org.enhydra.jawe.xml.XMLElement; 21 import org.enhydra.jawe.xml.XMLUtil; 22 import org.enhydra.jawe.xml.panels.XMLComboPanel; 23 import org.enhydra.jawe.xml.panels.XMLPanel; 24 25 import java.util.*; 26 import org.enhydra.jawe.xml.*; 27 28 import java.awt.Dimension ; 29 import java.awt.event.ActionEvent ; 30 import java.awt.event.ActionListener ; 31 import java.net.URL ; 32 import java.util.List ; 33 import java.util.Vector ; 34 import javax.swing.Box ; 35 import javax.swing.JComboBox ; 36 import javax.swing.JOptionPane ; 37 import javax.swing.JTable ; 38 import javax.swing.table.DefaultTableModel ; 39 import org.enhydra.jawe.JaWE; 40 import org.enhydra.jawe.xml.*; 41 import org.enhydra.jawe.xml.panels.*; 42 import org.w3c.dom.Node ; 43 44 47 public class WfXMLComboPanel extends XMLComboPanel { 48 49 private static final int MAX_URL_HISTORY_SIZE=16; 50 51 private static String URL_HISTORY_FILE_PATH; 52 private static ArrayList urls; 53 54 private Dimension comboBoxDimension=new Dimension (350,20); 55 56 private XMLButton buttonConnect; 57 58 59 public WfXMLComboPanel (XMLElement myOwner) { 60 61 super(myOwner,null,XMLPanel.BOX_LAYOUT,false,true); 62 63 ((JLabel )getComponent(1)).setText(ResourceManager.getLanguageDependentString("RegistryServiceURL")+": "); 64 65 if (URL_HISTORY_FILE_PATH==null) { 66 URL_HISTORY_FILE_PATH=JaWEConstants.JAWE_USER_HOME+JaWEConstants.RURL_FILENAME; 67 File extR=new File(URL_HISTORY_FILE_PATH); 68 if (extR.exists()) { 69 urls=(ArrayList)readFile(URL_HISTORY_FILE_PATH); 70 } 71 if (urls==null) { 72 urls=new ArrayList(); 73 } 74 } 75 76 final JComboBox jcb=super.getComboBox(); 77 for (int i=0; i<urls.size(); i++) { 78 jcb.addItem(urls.get(i)); 79 } 80 if (urls.size()>0) { 81 jcb.setSelectedIndex(0); 82 } 83 jcb.setPreferredSize(comboBoxDimension); 84 String s=XMLUtil.getLanguageDependentString("ConnectKey"); 85 double w=0; 86 try { 87 w=getFontMetrics(getFont()).stringWidth(s); 88 } catch(Exception ex) {} 89 double h=getFontMetrics(getFont()).getHeight(); 90 w+=25; 91 if (w<30) w=30; 92 Dimension dim=new Dimension ((int)w,(int)h); 93 94 buttonConnect=new XMLButton(s,"Connect",dim); 95 buttonConnect.setAlignmentX(Component.LEFT_ALIGNMENT); 96 buttonConnect.setAlignmentY(Component.BOTTOM_ALIGNMENT); 97 98 add(Box.createRigidArea(new Dimension (10,0))); 99 add(buttonConnect); 100 101 buttonConnect.addActionListener(new ActionListener (){ 102 public void actionPerformed(ActionEvent ae){ 103 String selected=(String )jcb.getSelectedItem(); 104 if (selected!=null) { 105 addItemToCombo(selected); 106 } 107 } 108 }); 109 110 } 111 112 public XMLButton getConnectButton () { 113 return buttonConnect; 114 } 115 116 public void setElements () { 117 } 118 119 122 private void addItemToCombo (String url) { 123 if (url==null || url.trim().length()==0) return; 124 JComboBox jcb=getComboBox(); 125 for (int i=0; i<jcb.getItemCount(); i++) { 126 if (jcb.getItemAt(i).toString().equals(url)) { 127 jcb.removeItemAt(i); 128 jcb.insertItemAt(url,0); 129 jcb.setSelectedIndex(0); 130 urls.remove(i); 131 urls.add(0,url); 132 writeFile(urls,URL_HISTORY_FILE_PATH); 133 return; 134 } 135 } 136 jcb.insertItemAt(url,0); 137 urls.add(0,url); 138 if (jcb.getItemCount()>MAX_URL_HISTORY_SIZE) { 139 jcb.removeItemAt(MAX_URL_HISTORY_SIZE); 140 urls.remove(MAX_URL_HISTORY_SIZE); 141 } 142 jcb.setSelectedIndex(0); 143 writeFile(urls,URL_HISTORY_FILE_PATH); 144 } 145 146 private void writeFile (Object obj,String fName) { 147 try { 148 OutputStream fos = new FileOutputStream(fName); 149 ObjectOutputStream oout = new ObjectOutputStream(fos); 150 oout.writeObject(obj); 151 oout.flush(); 152 oout.close(); 153 fos.close(); 154 } catch (Exception ex) { 155 ex.printStackTrace(); 156 } 157 } 158 159 private Object readFile (String fName) { 160 try { 161 InputStream fis = new FileInputStream(fName); 162 ObjectInputStream oin = new ObjectInputStream(fis); 163 Object obj=oin.readObject(); 164 oin.close(); 165 return obj; 166 } catch (Exception ex) { 167 ex.printStackTrace(); 168 return null; 169 } 170 } 171 172 173 } 174 175 | Popular Tags |