1 package de.webman.wminstaller.app; 2 3 import javax.swing.*; 4 import java.awt.*; 5 import java.awt.event.*; 6 import java.io.File ; 7 import java.util.*; 8 import java.beans.*; 9 10 import de.webman.wminstaller.screens.*; 11 12 16 public class Installer 17 { 18 19 20 private JFrame f = new JFrame("Webman Setup und Installation"); 21 private Container fcp = f.getContentPane(); 22 23 private CardsPanel headarea = new CardsPanel( this); 24 private CardsPanel cardarea = new CardsPanel( this); 25 private CardsPanel naviarea = new CardsPanel( this); 26 27 private int lastCard = -1; 28 private int currentCard = 0; 29 30 private File baseDir = null; 31 private File dataDir = null; 32 33 private HashMap dict = new HashMap(); 34 private PropertyChangeSupport pcl = null; 35 36 37 38 41 public Installer() { 42 pcl = new PropertyChangeSupport(this); 43 } 44 45 public Installer( File baseDir) { 46 this(); 47 this.baseDir = baseDir; 48 49 try{ 50 dataDir = new File (getCWD(baseDir), "data"); 51 if (!isDirectory(dataDir)) 52 dataDir = null; 53 } 54 catch( SecurityException e) { 55 dataDir = null; 56 } 57 } 58 59 public File getBaseDir() { 60 return baseDir; 61 } 62 63 public File getDataDir() { 64 System.out.println("Datadir: " + dataDir); 65 return dataDir; 66 } 67 68 74 public HashMap getDictionary() { 75 return dict; 76 } 77 78 82 public PropertyChangeSupport getPCL() { 83 return pcl; 84 } 85 86 87 88 91 public void build() { 92 93 fcp.setLayout( new BoxLayout( fcp, BoxLayout.Y_AXIS)); 94 fcp.add(headarea); 95 fcp.add(Box.createVerticalStrut( 10)); 97 fcp.add(Box.createVerticalGlue()); 98 fcp.add(cardarea); 99 fcp.add(Box.createVerticalStrut( 30)); 100 fcp.add(Box.createVerticalGlue()); 101 fcp.add(naviarea); 102 104 new ScreenWelcome(this, InstallerScreen.BUTTONS_START); 105 new ScreenDirChooser(this, InstallerScreen.BUTTONS_MIDDLE); 106 new ScreenDBSetup(this, InstallerScreen.BUTTONS_MIDDLE); 107 new ScreenWMSetup(this, InstallerScreen.BUTTONS_MIDDLE); 108 new ScreenFinish(this, InstallerScreen.BUTTONS_FINISH); 109 new ScreenDone(this, InstallerScreen.BUTTONS_END); 110 111 stepTo( 0 ); 112 } 113 114 123 public int addScreen(String title, Component panel, Component navigator) { 124 lastCard++; 125 126 JPanel head = new JPanel( new BorderLayout()); 127 128 if (title == null) 129 title = ""; 130 StringTokenizer st = new StringTokenizer(title, "\n", false); 131 int numLines = st.countTokens(); 132 JPanel lines = new JPanel(new GridLayout(numLines, 1, 2, 2)); 133 while (st.hasMoreTokens()) { 134 lines.add(new JLabel(st.nextToken(), javax.swing.SwingConstants.LEFT)); 135 } 136 if (numLines > 0) 137 head.add(lines, BorderLayout.NORTH); 138 139 if (panel instanceof javax.swing.JScrollPane ) 140 ((JScrollPane)panel).setPreferredSize(new Dimension(250, 200)); 141 142 headarea.add(head, "" + lastCard); 143 cardarea.add(panel, "" + lastCard); 144 naviarea.add(navigator, "" + lastCard); 145 146 return lastCard; 147 } 148 149 150 153 private void fireStepEvent(String direct, int oldidx, int newidx) { 154 pcl.firePropertyChange(new PropertyChangeEvent(this, direct, 155 new Integer (oldidx), new Integer (newidx))); 156 } 157 158 public void leave( int exitCode) { 159 System.exit(exitCode); 160 } 161 162 public void stepForward() { 163 int oldCard = currentCard; 164 currentCard++; 165 fireStepEvent(EventConstants.LEAVE_SCREEN, oldCard, currentCard); 166 fireStepEvent(EventConstants.ENTER_SCREEN, oldCard, currentCard); 167 stepTo(); 168 } 169 170 public void stepBackward() { 171 int oldCard = currentCard; 172 currentCard--; 173 fireStepEvent(EventConstants.LEAVE_SCREEN, oldCard, currentCard); 174 fireStepEvent(EventConstants.ENTER_SCREEN, oldCard, currentCard); 175 stepTo(); 176 } 177 178 public void stepFinish() { 179 int oldCard = currentCard; 180 currentCard = lastCard; 181 fireStepEvent(EventConstants.LEAVE_SCREEN, oldCard, currentCard); 182 fireStepEvent(EventConstants.ENTER_SCREEN, oldCard, currentCard); 183 stepTo(); 184 } 185 186 public void stepTo(int i) { 187 int oldCard = currentCard; 188 currentCard = i; 189 fireStepEvent(EventConstants.LEAVE_SCREEN, oldCard, currentCard); 190 fireStepEvent(EventConstants.ENTER_SCREEN, oldCard, currentCard); 191 stepTo(); 192 } 193 194 private void stepTo() { 195 if (lastCard < 0) 196 return; 197 if (currentCard < 0) { 198 currentCard = 0; 199 } 200 if (currentCard > lastCard) { 201 currentCard = lastCard; 202 } 203 204 naviarea.setVisible( false ); 205 cardarea.setVisible( false ); 206 headarea.setVisible( false ); 207 208 headarea.showCard( currentCard); 209 cardarea.showCard( currentCard); 210 naviarea.showCard( currentCard); 211 212 headarea.setVisible( true ); 213 cardarea.setVisible( true ); 214 naviarea.setVisible( true ); 215 } 216 217 public void show() { 218 f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE); 220 f.pack(); 221 222 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 223 f.setLocation( 224 new Point( 225 (int) (Math.abs( screenSize.getWidth() - f.getWidth()) / 2), 226 (int) (Math.abs( screenSize.getHeight() - f.getHeight()) / 2) 227 ) 228 ); 229 f.setVisible(true); 231 } 232 233 234 235 238 250 private File getCWD(File file) { 251 252 String str = file.toString(); 253 int pos = str.lastIndexOf("!"); 254 255 257 if (pos < 0) 258 return new File (str); 259 260 261 262 int slash_pos = str.lastIndexOf(File.separatorChar, pos); 263 264 265 if (slash_pos < 0) 266 throw new IllegalArgumentException ("file path needs to be a valid \"file:/\" url"); 267 268 return new File (str.substring(0, slash_pos)); 269 } 270 271 272 277 public static final String FILE_SCHEME = "file:"; 278 private boolean isDirectory(File file) { 279 String t = file.toString(); 280 if (t.startsWith(FILE_SCHEME)) { 281 String t2 = t.substring(FILE_SCHEME.length()); 282 if ("nt".equals(System.getProperty("system"))) { 283 284 } 285 286 return new File (t2).isDirectory(); 287 } 288 289 return file.isDirectory(); 290 } 291 292 } 293 294 | Popular Tags |