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.JPanel ; 14 import javax.swing.JTextField ; 15 16 public abstract class SplashForm extends JPanel 17 { 18 protected final JLabel _splashFileLabel = new JLabel (); 19 protected final JLabel _waitForWindowLabel = new JLabel (); 20 protected final JLabel _timeoutLabel = new JLabel (); 21 protected final JCheckBox _timeoutErrCheck = new JCheckBox (); 22 protected final JTextField _splashFileField = new JTextField (); 23 protected final JTextField _timeoutField = new JTextField (); 24 protected final JButton _splashFileButton = new JButton (); 25 protected final JCheckBox _splashCheck = new JCheckBox (); 26 protected final JCheckBox _waitForWindowCheck = new JCheckBox (); 27 28 31 public SplashForm() 32 { 33 initializePanel(); 34 } 35 36 42 void addFillComponents( Container panel, int[] cols, int[] rows ) 43 { 44 Dimension filler = new Dimension (10,10); 45 46 boolean filled_cell_11 = false; 47 CellConstraints cc = new CellConstraints(); 48 if ( cols.length > 0 && rows.length > 0 ) 49 { 50 if ( cols[0] == 1 && rows[0] == 1 ) 51 { 52 53 panel.add( Box.createRigidArea( filler ), cc.xy(1,1) ); 54 filled_cell_11 = true; 55 } 56 } 57 58 for( int index = 0; index < cols.length; index++ ) 59 { 60 if ( cols[index] == 1 && filled_cell_11 ) 61 { 62 continue; 63 } 64 panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) ); 65 } 66 67 for( int index = 0; index < rows.length; index++ ) 68 { 69 if ( rows[index] == 1 && filled_cell_11 ) 70 { 71 continue; 72 } 73 panel.add( Box.createRigidArea( filler ), cc.xy(1,rows[index]) ); 74 } 75 76 } 77 78 84 public ImageIcon loadImage( String imageName ) 85 { 86 try 87 { 88 ClassLoader classloader = getClass().getClassLoader(); 89 java.net.URL url = classloader.getResource( imageName ); 90 if ( url != null ) 91 { 92 ImageIcon icon = new ImageIcon ( url ); 93 return icon; 94 } 95 } 96 catch( Exception e ) 97 { 98 e.printStackTrace(); 99 } 100 throw new IllegalArgumentException ( "Unable to load image: " + imageName ); 101 } 102 103 public JPanel createPanel() 104 { 105 JPanel jpanel1 = new JPanel (); 106 FormLayout formlayout1 = new FormLayout("FILL:7DLU:NONE,RIGHT:MAX(65DLU;DEFAULT):NONE,FILL:3DLU:NONE,FILL:60DLU:NONE,FILL:DEFAULT:GROW(1.0),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:3DLU:NONE,CENTER:DEFAULT:NONE,CENTER:9DLU:NONE"); 107 CellConstraints cc = new CellConstraints(); 108 jpanel1.setLayout(formlayout1); 109 110 _splashFileLabel.setIcon(loadImage("images/asterix.gif")); 111 _splashFileLabel.setName("splashFileLabel"); 112 _splashFileLabel.setText(Messages.getString("splashFile")); 113 jpanel1.add(_splashFileLabel,cc.xy(2,4)); 114 115 _waitForWindowLabel.setName("waitForWindowLabel"); 116 _waitForWindowLabel.setText(Messages.getString("waitForWindow")); 117 jpanel1.add(_waitForWindowLabel,cc.xy(2,6)); 118 119 _timeoutLabel.setIcon(loadImage("images/asterix.gif")); 120 _timeoutLabel.setName("timeoutLabel"); 121 _timeoutLabel.setText(Messages.getString("timeout")); 122 jpanel1.add(_timeoutLabel,cc.xy(2,8)); 123 124 _timeoutErrCheck.setActionCommand("Signal error on timeout"); 125 _timeoutErrCheck.setName("timeoutErrCheck"); 126 _timeoutErrCheck.setText(Messages.getString("timeoutErr")); 127 _timeoutErrCheck.setToolTipText(Messages.getString("timeoutErrTip")); 128 jpanel1.add(_timeoutErrCheck,cc.xywh(4,10,2,1)); 129 130 _splashFileField.setName("splashFileField"); 131 _splashFileField.setToolTipText(Messages.getString("splashFileTip")); 132 jpanel1.add(_splashFileField,cc.xywh(4,4,2,1)); 133 134 _timeoutField.setName("timeoutField"); 135 _timeoutField.setToolTipText(Messages.getString("timeoutTip")); 136 jpanel1.add(_timeoutField,cc.xy(4,8)); 137 138 _splashFileButton.setIcon(loadImage("images/open16.png")); 139 _splashFileButton.setName("splashFileButton"); 140 jpanel1.add(_splashFileButton,cc.xy(7,4)); 141 142 _splashCheck.setActionCommand("Enable splash screen"); 143 _splashCheck.setName("splashCheck"); 144 _splashCheck.setText(Messages.getString("enableSplash")); 145 jpanel1.add(_splashCheck,cc.xywh(4,2,2,1)); 146 147 _waitForWindowCheck.setActionCommand("Close splash screen when an application window appears"); 148 _waitForWindowCheck.setName("waitForWindowCheck"); 149 _waitForWindowCheck.setText(Messages.getString("waitForWindowText")); 150 jpanel1.add(_waitForWindowCheck,cc.xywh(4,6,2,1)); 151 152 addFillComponents(jpanel1,new int[]{ 1,2,3,4,5,6,7,8 },new int[]{ 1,2,3,4,5,6,7,8,9,10,11 }); 153 return jpanel1; 154 } 155 156 159 protected void initializePanel() 160 { 161 setLayout(new BorderLayout ()); 162 add(createPanel(), BorderLayout.CENTER); 163 } 164 165 166 } 167 | Popular Tags |