1 25 26 package net.yagga.miniinstaller.gui; 27 28 import java.awt.*; 29 import java.io.*; 30 import javax.swing.*; 31 import java.awt.event.*; 32 import net.yagga.util.Ut; 33 34 public class InputPanel extends JPanel implements ActionListener, 35 InstallPanel, KeyListener{ 36 37 JTextArea taText = new JTextArea(); 39 TitledBorderBean tit1=new TitledBorderBean(); 40 41 String title; 42 String text; 43 String defVal; 44 boolean browse; 45 boolean fileOrDir; 46 String inputValue=""; 47 CanFwdListener canFwdListener; 48 JPanel jPanel1 = new JPanel(); 49 TitledBorderBean titledBorderBean1 = new TitledBorderBean(); 50 JButton btBrowse = new JButton(); 51 JTextField tfInput = new JTextField(); 52 GridBagLayout gridBagLayout1 = new GridBagLayout(); 53 GridBagLayout gridBagLayout2 = new GridBagLayout(); 54 JLabel lbTitle = new JLabel(); 55 56 public InputPanel(String title, String text, String defVal, boolean fileOrText, boolean fileOrDir, CanFwdListener cfl) { 57 canFwdListener=cfl; 58 this.title=title; 59 this.text=text; 60 this.browse=fileOrText; 61 this.fileOrDir=fileOrDir; 62 this.defVal=defVal; 63 64 try { 65 jbInit(); 66 } 67 catch (Exception ex) { 68 ex.printStackTrace(); 69 } 70 } 71 72 void jbInit() throws Exception { 73 taText.setText(text); 74 taText.setEditable(false); 75 taText.setWrapStyleWord(true); 76 taText.setLineWrap(true); 77 taText.setOpaque(false); 78 taText.setFont(GuiProperties.textFont); 79 this.setBackground(SystemColor.control); 80 if(!browse) 83 btBrowse.setVisible(false); 84 btBrowse.setOpaque(false); 85 titledBorderBean1.setTitle(title); 86 titledBorderBean1.setTitleFont(GuiProperties.makeItalic(GuiProperties.textFont)); 87 btBrowse.addActionListener(this); 89 btBrowse.setText("Browse..."); 90 btBrowse.setForeground(InstallFrame.BTN_COL); 91 tfInput.setText(defVal); 92 tfInput.addKeyListener(this); 93 tfInput.setColumns(5); 94 this.setLayout(gridBagLayout2); 96 jPanel1.setLayout(gridBagLayout1); 97 jPanel1.setOpaque(false); 98 99 lbTitle.setText(title); 100 lbTitle.setFont(GuiProperties.smallTitleFont); 101 this.add(taText, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0 102 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(8, 7, 8, 7), 0, 170)); 103 this.add(jPanel1, new GridBagConstraints(0, 2, 1, 1, 1.0, 0.0 104 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(8, 8, 8, 8), 0, 0)); 105 jPanel1.add(tfInput, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0 106 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 2, 5), 0, 0)); 107 jPanel1.add(btBrowse, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0 108 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 0, 2, 5), 0, 0)); 109 tit1.setTitle("test"); 110 javax.swing.border.EtchedBorder eBorder=new javax.swing.border.EtchedBorder (); 111 titledBorderBean1.setBorder(eBorder); 112 jPanel1.setBorder(titledBorderBean1); 113 this.add(lbTitle, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0 114 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); 115 refresh(); 116 } 117 118 public void refresh(){ 119 this.setBackground(InstallFrame.BK_COL); 120 jPanel1.setBackground(InstallFrame.BK_COL); 121 this.setMaximumSize(InstallFrame.panelDim); 122 this.setPreferredSize(InstallFrame.panelDim); 123 this.setMinimumSize(InstallFrame.panelDim); 124 taText.setForeground(InstallFrame.FG_COL); 125 titledBorderBean1.setTitleColor(InstallFrame.FG_COL); 126 lbTitle.setForeground(InstallFrame.FG_COL); 127 128 this.checkEnable(); 130 this.invalidate(); 131 } 132 133 134 String getValue(){ 135 String f=tfInput.getText(); 137 if(browse && (f.endsWith("\\") || f.endsWith("/"))) 138 return f.substring(0,f.length()-1); 139 140 return f; 141 } 142 143 public void actionPerformed(ActionEvent e){ 144 145 if(e.getSource()==btBrowse){ 146 JFileChooser jfc; 147 if(defVal.equals("")) 148 jfc=new JFileChooser("."); 149 else 150 jfc=new JFileChooser(defVal); 151 152 if(fileOrDir) 153 jfc.setFileSelectionMode(jfc.FILES_ONLY); 154 else 155 jfc.setFileSelectionMode(jfc.DIRECTORIES_ONLY); 156 157 jfc.setBackground(InstallFrame.BK_COL); 159 jfc.setOpaque(true); 160 InstallFrame.deepSet(jfc,false); 161 162 int returnVal=jfc.showOpenDialog(this); 163 try{ 164 if(returnVal==JFileChooser.APPROVE_OPTION) 165 inputValue=(jfc.getSelectedFile().getCanonicalPath()); 166 tfInput.setText(inputValue); 167 checkEnable(); 168 }catch(IOException ioe){ 169 } 170 } 171 } 172 173 176 public void keyPressed(KeyEvent e){ 177 checkEnable(); 178 } 179 public void keyReleased(KeyEvent e){ 180 checkEnable(); 181 } 182 public void keyTyped(KeyEvent e){ 183 checkEnable(); 184 } 185 186 private void checkEnable(){ 187 if(tfInput.getText().length()>0) 189 canFwdListener.canFwd(); 190 } 191 192 193 } 194 195 | Popular Tags |