1 package net.sf.launch4j.form; 2 3 import com.jgoodies.forms.layout.CellConstraints; 4 import com.jgoodies.forms.layout.FormLayout; 5 import java.awt.BorderLayout ; 6 import java.awt.Container ; 7 import java.awt.Dimension ; 8 import javax.swing.Box ; 9 import javax.swing.ImageIcon ; 10 import javax.swing.JButton ; 11 import javax.swing.JCheckBox ; 12 import javax.swing.JLabel ; 13 import javax.swing.JList ; 14 import javax.swing.JPanel ; 15 import javax.swing.JScrollPane ; 16 import javax.swing.JTextField ; 17 18 public abstract class ClassPathForm extends JPanel 19 { 20 protected final JTextField _classpathField = new JTextField (); 21 protected final JLabel _classpathFieldLabel = new JLabel (); 22 protected final JLabel _classpathListLabel = new JLabel (); 23 protected final JList _classpathList = new JList (); 24 protected final JLabel _mainclassLabel = new JLabel (); 25 protected final JTextField _mainclassField = new JTextField (); 26 protected final JButton _acceptClasspathButton = new JButton (); 27 protected final JButton _removeClasspathButton = new JButton (); 28 protected final JButton _importClasspathButton = new JButton (); 29 protected final JButton _classpathUpButton = new JButton (); 30 protected final JButton _classpathDownButton = new JButton (); 31 protected final JCheckBox _classpathCheck = new JCheckBox (); 32 protected final JButton _newClasspathButton = new JButton (); 33 34 37 public ClassPathForm() 38 { 39 initializePanel(); 40 } 41 42 48 void addFillComponents( Container panel, int[] cols, int[] rows ) 49 { 50 Dimension filler = new Dimension (10,10); 51 52 boolean filled_cell_11 = false; 53 CellConstraints cc = new CellConstraints(); 54 if ( cols.length > 0 && rows.length > 0 ) 55 { 56 if ( cols[0] == 1 && rows[0] == 1 ) 57 { 58 59 panel.add( Box.createRigidArea( filler ), cc.xy(1,1) ); 60 filled_cell_11 = true; 61 } 62 } 63 64 for( int index = 0; index < cols.length; index++ ) 65 { 66 if ( cols[index] == 1 && filled_cell_11 ) 67 { 68 continue; 69 } 70 panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) ); 71 } 72 73 for( int index = 0; index < rows.length; index++ ) 74 { 75 if ( rows[index] == 1 && filled_cell_11 ) 76 { 77 continue; 78 } 79 panel.add( Box.createRigidArea( filler ), cc.xy(1,rows[index]) ); 80 } 81 82 } 83 84 90 public ImageIcon loadImage( String imageName ) 91 { 92 try 93 { 94 ClassLoader classloader = getClass().getClassLoader(); 95 java.net.URL url = classloader.getResource( imageName ); 96 if ( url != null ) 97 { 98 ImageIcon icon = new ImageIcon ( url ); 99 return icon; 100 } 101 } 102 catch( Exception e ) 103 { 104 e.printStackTrace(); 105 } 106 throw new IllegalArgumentException ( "Unable to load image: " + imageName ); 107 } 108 109 public JPanel createPanel() 110 { 111 JPanel jpanel1 = new JPanel (); 112 FormLayout formlayout1 = new FormLayout("FILL:7DLU:NONE,RIGHT:MAX(65DLU;DEFAULT):NONE,FILL:3DLU:NONE,FILL:DEFAULT:GROW(1.0),FILL:3DLU:NONE,FILL:DEFAULT:NONE,FILL:3DLU:NONE,FILL:DEFAULT:NONE,FILL:3DLU:NONE,FILL:DEFAULT:NONE,FILL:3DLU:NONE,FILL:26PX:NONE,FILL:7DLU:NONE","CENTER:9DLU:NONE,CENTER:DEFAULT:NONE,CENTER:3DLU:NONE,CENTER:DEFAULT:NONE,CENTER:3DLU:NONE,CENTER:DEFAULT:NONE,CENTER:3DLU:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:GROW(1.0),CENTER:3DLU:NONE,CENTER:DEFAULT:NONE,CENTER:3DLU:NONE,CENTER:DEFAULT:NONE,CENTER:9DLU:NONE"); 113 CellConstraints cc = new CellConstraints(); 114 jpanel1.setLayout(formlayout1); 115 116 _classpathField.setName("classpathField"); 117 jpanel1.add(_classpathField,cc.xywh(4,11,7,1)); 118 119 _classpathFieldLabel.setIcon(loadImage("images/asterix.gif")); 120 _classpathFieldLabel.setName("classpathFieldLabel"); 121 _classpathFieldLabel.setText(Messages.getString("editClassPath")); 122 jpanel1.add(_classpathFieldLabel,cc.xy(2,11)); 123 124 _classpathListLabel.setName("classpathListLabel"); 125 _classpathListLabel.setText(Messages.getString("classPath")); 126 jpanel1.add(_classpathListLabel,cc.xy(2,6)); 127 128 _classpathList.setName("classpathList"); 129 JScrollPane jscrollpane1 = new JScrollPane (); 130 jscrollpane1.setViewportView(_classpathList); 131 jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); 132 jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); 133 jpanel1.add(jscrollpane1,cc.xywh(4,6,7,4)); 134 135 _mainclassLabel.setIcon(loadImage("images/asterix.gif")); 136 _mainclassLabel.setName("mainclassLabel"); 137 _mainclassLabel.setText(Messages.getString("mainClass")); 138 jpanel1.add(_mainclassLabel,cc.xy(2,4)); 139 140 _mainclassField.setName("mainclassField"); 141 jpanel1.add(_mainclassField,cc.xywh(4,4,7,1)); 142 143 _acceptClasspathButton.setActionCommand("Add"); 144 _acceptClasspathButton.setIcon(loadImage("images/ok16.png")); 145 _acceptClasspathButton.setName("acceptClasspathButton"); 146 _acceptClasspathButton.setText(Messages.getString("accept")); 147 jpanel1.add(_acceptClasspathButton,cc.xy(8,13)); 148 149 _removeClasspathButton.setActionCommand("Remove"); 150 _removeClasspathButton.setIcon(loadImage("images/cancel16.png")); 151 _removeClasspathButton.setName("removeClasspathButton"); 152 _removeClasspathButton.setText(Messages.getString("remove")); 153 jpanel1.add(_removeClasspathButton,cc.xy(10,13)); 154 155 _importClasspathButton.setIcon(loadImage("images/open16.png")); 156 _importClasspathButton.setName("importClasspathButton"); 157 _importClasspathButton.setToolTipText(Messages.getString("importClassPath")); 158 jpanel1.add(_importClasspathButton,cc.xy(12,4)); 159 160 _classpathUpButton.setIcon(loadImage("images/up16.png")); 161 _classpathUpButton.setName("classpathUpButton"); 162 jpanel1.add(_classpathUpButton,cc.xy(12,6)); 163 164 _classpathDownButton.setIcon(loadImage("images/down16.png")); 165 _classpathDownButton.setName("classpathDownButton"); 166 jpanel1.add(_classpathDownButton,cc.xy(12,8)); 167 168 _classpathCheck.setActionCommand("Custom classpath"); 169 _classpathCheck.setName("classpathCheck"); 170 _classpathCheck.setText(Messages.getString("customClassPath")); 171 jpanel1.add(_classpathCheck,cc.xy(4,2)); 172 173 _newClasspathButton.setActionCommand("New"); 174 _newClasspathButton.setIcon(loadImage("images/new16.png")); 175 _newClasspathButton.setName("newClasspathButton"); 176 _newClasspathButton.setText(Messages.getString("new")); 177 jpanel1.add(_newClasspathButton,cc.xy(6,13)); 178 179 addFillComponents(jpanel1,new int[]{ 1,2,3,4,5,6,7,8,9,10,11,12,13 },new int[]{ 1,2,3,4,5,6,7,8,9,10,11,12,13,14 }); 180 return jpanel1; 181 } 182 183 186 protected void initializePanel() 187 { 188 setLayout(new BorderLayout ()); 189 add(createPanel(), BorderLayout.CENTER); 190 } 191 192 193 } 194 | Popular Tags |