1 25 26 package net.yagga.miniinstaller.gui; 27 28 import net.yagga.miniinstaller.*; 29 import net.yagga.util.Ut; 30 import net.yagga.util.ResourceMgr; 31 import java.awt.*; 32 import javax.swing.*; 33 34 import javax.swing.plaf.metal.*; 35 import javax.swing.plaf.basic.*; 36 import javax.swing.plaf.multi.*; 37 38 39 49 public class InstallFrame extends JFrame implements CanFwdListener, FinalExecuter{ 50 51 private String mac = "com.sun.java.swing.plaf.mac.MacLookAndFeel"; 53 private String metal = "javax.swing.plaf.metal.MetalLookAndFeel"; 54 private String motif = "com.sun.java.swing.plaf.motif.MotifLookAndFeel"; 55 private String windows = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"; 56 57 BorderLayout borderLayout1 = new BorderLayout(); 58 59 NavPanel navPanel=null; 60 TitlePanel titlePanel=null; 61 StepPanel stepPanel=null; 62 63 private static final int DEF_X=750; 64 private static final int DEF_Y=300; 65 66 private String title; 67 private String panelTitle; 68 69 public static Dimension panelDim=new Dimension(DEF_X,DEF_Y); 70 public static Color BK_COL=SystemColor.control; 71 public static Color FG_COL=Color.black; 72 public static Color TIT_COL=Color.black; 73 public static Color TITLE_COL=Color.black; 74 public static Color STEP_COL=Color.black; 75 public static Color BTN_COL=SystemColor.controlText; 76 77 78 81 private final static String COL_BG="BK"; 82 private final static String COL_TITLE="TITLE"; 83 private final static String COL_SMALL_TITLE="SMALL_TITLE"; 84 private final static String COL_TEXT="TEXT"; 85 private final static String COL_STEP="STEP"; 86 private final static String COL_BTN="BTN"; 87 88 89 private final static String FONT_TITLE="TITLE"; 90 private final static String FONT_STEP="STEP"; 91 private final static String FONT_TEXT="TEXT"; 92 private final static String FONT_SMALL_TITLE="SMALL_TITLE"; 93 94 95 private boolean canRefresh=false; 96 97 private boolean executeShell=false; 98 99 private boolean stepVisible=true; 100 101 private MiniInstaller installer; 102 103 104 private InstallFrame thisFrame=null; 105 106 107 public InstallFrame(MiniInstaller mi, String title) { 108 super(title); 109 installer=mi; 110 this.title=title; 111 GuiProperties.init(); 112 this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); 113 114 this.addWindowListener(new java.awt.event.WindowAdapter (){ 115 public void windowClosing(java.awt.event.WindowEvent e){ 116 exit(); 117 } 118 }); 119 thisFrame=this; 120 } 121 122 123 public void setVisible(boolean vis){ 124 canRefresh=vis; 125 if(!vis) 126 super.setVisible(false); 127 else{ 128 super.setVisible(false); 129 rebuild(); 130 super.setVisible(true); 131 } 132 } 133 134 137 public void rebuild(){ 138 try{ 139 jbInit(); 140 }catch(Exception e){ 142 } 143 } 144 145 private void jbInit() throws Exception { 146 JPanel pane=new JPanel(); 147 148 this.setContentPane(pane); 149 pane.setDoubleBuffered(true); 150 this.setResizable(false); 152 this.setTitle(title); 153 this.setResizable(true); 154 this.getContentPane().setLayout(borderLayout1); 155 navPanel=new NavPanel(this); 157 158 this.getContentPane().add(navPanel,BorderLayout.SOUTH); 159 titlePanel=new TitlePanel(panelTitle); 160 161 162 this.getContentPane().add(titlePanel,BorderLayout.NORTH); 163 addPanel(new VoidPanel()); 164 165 stepPanel=new StepPanel(installer.getSteps()); 166 if(stepVisible){ 167 this.getContentPane().add(stepPanel,BorderLayout.WEST); 168 } 169 this.setIconImage(ResourceMgr.retrieveImageIcon("img/miniinst_icon.gif").getImage()); 170 this.pack(); 171 this.doLayout(); 172 stepPanel.resetStep(); 173 } 175 176 187 public void setLookAndFeel(String laf){ 188 String lafClass=null; 189 if(laf.equals("windows")) 190 lafClass=windows; 191 else if(laf.equals("metal")) 192 lafClass=metal; 193 else if(laf.equals("motif")) 194 lafClass=motif; 195 else if(laf.equals("mac")) 196 lafClass=mac; 197 else 198 Ut.infoln("Error Unsupported look and feel:'"+laf+"'"); 199 200 try{ 201 UIManager.setLookAndFeel(lafClass); 202 SwingUtilities.invokeLater(updateUI); 203 }catch(Exception ulafe){ 204 Ut.infoln("Error UnsuppLAF:"+lafClass+"="+ulafe); 205 } 206 } 207 208 public void updateDims(Dimension d){ 209 panelDim=d; 210 if(canRefresh) 211 refresh(); 212 } 213 214 public void setCol(String what, int r, int g, int b){ 215 if(what.equals(COL_BG)) 216 BK_COL=new Color(r,g,b); 217 else if(what.equals(COL_TITLE)) 218 TITLE_COL=new Color(r,g,b); 219 else if(what.equals(COL_TEXT)) 220 FG_COL=new Color(r,g,b); 221 else if(what.equals(COL_SMALL_TITLE)) 222 TIT_COL=new Color(r,g,b); 223 else if(what.equals(COL_STEP)) 224 STEP_COL=new Color(r,g,b); 225 else if(what.equals(COL_BTN)) 226 BTN_COL=new Color(r,g,b); 227 if(canRefresh) 228 refresh(); 229 } 230 231 public void setFont(String font, String face, int style, int size){ 232 if(font.equals(FONT_TITLE)) 233 GuiProperties.setTitleFont(face,style,size); 234 else if(font.equals(FONT_TEXT)) 235 GuiProperties.setTextFont(face,style,size); 236 else if(font.equals(FONT_SMALL_TITLE)) 237 GuiProperties.setSmallTitleFont(face,style,size); 238 else if(font.equals(FONT_STEP)) 239 GuiProperties.setStepFont(face,style,size); 240 else 241 Ut.error("Unknown font to set:'"+font+"'"); 242 } 243 244 public void setName(String n){ 245 if(titlePanel!=null) 246 titlePanel.setTitle(n); 247 panelTitle=n; 248 } 249 250 public void doStep(){ 251 if(stepPanel!=null) 252 stepPanel.incStep(); 253 } 254 public void revertStep(){ 255 stepPanel.decStep(); 256 } 257 public void revertStep(int to){ 258 stepPanel.goStep(to); 259 } 260 public void changeTitle(String t){ 261 title=t; 262 setTitle(title); 263 } 264 public void refresh(){ 265 if(panel!=null){ 266 panel.refresh(); 267 } 268 navPanel.refresh(); 269 titlePanel.refresh(); 270 stepPanel.refresh(); 271 this.pack(); 272 } 273 274 277 InstallPanel panel=null; 278 InputPanel input=null; 279 UnzipPanel unzip=null; 280 281 public void doFinal(String title,String msg, String shellCommand, String shellCaption){ 282 reset(); 283 if(shellCaption==null && shellCommand!=null) 284 shellCaption="Execute "+shellCommand; 285 addPanel(new FinalPanel(this,title,msg,shellCaption)); 286 navPanel.makeFinalPage(); 287 } 288 289 public void doWrite(String title,String msg){ 290 doWrite(title,msg,true); 291 } 292 293 public void doWrite(String title,String msg,boolean go){ 294 reset(); 295 addPanel(new WritePanel(title,msg,null)); 296 if(go) 297 enableAllButtons(); 298 else 299 enableAllButtonsButFwd(); 300 } 301 302 public void doStart(String title,String msg,boolean isImage){ 303 reset(); 304 305 if(isImage) 306 addPanel(new WritePanel(title,null,msg)); 307 else 308 addPanel(new WritePanel(title,msg,null)); 309 310 enableAllButtonsButBk(); 311 } 312 313 public void doAlert(String msg,boolean block){ 314 reset(); 315 addPanel(new WritePanel(msg,WritePanel.ICON_ALERT)); 316 if(!block) 317 enableAllButtons(); 318 else 319 enableAllButtonsButFwd(); 320 } 321 322 public void setStepVisible(boolean show){ 323 if(stepPanel!=null){ 324 Ut.infoln("Hide/show panel :"+show); 325 stepPanel.setVisible(show); 326 } 327 stepVisible=show; 328 if(canRefresh){ 329 if(stepVisible){ 330 this.getContentPane().add(stepPanel,BorderLayout.WEST); 331 } 332 333 } 334 } 335 336 public void doDisplay(String msg){ 337 reset(); 338 addPanel(new DisplayPanel(msg)); 339 enableAllButtons(); 340 } 341 342 public void doShow(String imgFile){ 343 reset(); 344 addPanel(new WritePanel(null,imgFile)); 347 enableAllButtons(); 348 } 349 350 public void doUnzip(String title, String zipf, String ddir){ 351 reset(); 352 unzip=new UnzipPanel(title,zipf,ddir,this); 353 addPanel(unzip); 354 enableAllButtonsButFwd(); 355 } 356 357 public void setProgress(int i){ 358 unzip.setProgress(i); 359 } 362 363 public void doInput(String title, String msg, String defValue ){ 364 reset(); 365 input=new InputPanel(title,msg,defValue,false,false,this); 366 addPanel(input); 367 if(defValue.equals("")) 368 enableAllButtonsButFwd(); 369 } 370 374 public void doInputFile(String title, String msg, String defValue, boolean file){ 375 reset(); 376 input=new InputPanel(title,msg,defValue,true,file,this); 377 addPanel(input); 378 if(defValue.equals("")) 379 enableAllButtonsButFwd(); 380 } 381 382 383 public String getInput(){ 384 return input.getValue(); 385 } 386 387 390 private void reset(){ 391 input=null; 392 unzip=null; 393 } 394 395 private void enableAllButtons(){ 396 navPanel.enableButtons(true,true,true); 397 } 398 private void enableAllButtonsButFwd(){ 399 navPanel.enableButtons(true,true,false); 400 } 401 private void enableAllButtonsButBk(){ 402 navPanel.enableButtons(true,false,true); 403 } 404 405 private void addPanel(InstallPanel p){ 406 407 if(panel!=null) 408 this.getContentPane().remove((JPanel)panel); 409 this.getContentPane().add((JPanel)p,BorderLayout.CENTER); 410 panel=p; 411 412 413 423 424 this.pack(); 425 this.doLayout(); 426 } 427 430 public void exit(){ 431 if(installer.isLastStep()) 433 installer.exit(); 434 else{ 435 436 if(_showOptionDialog(navPanel, "Are you sure you want to exit "+Version.name+"?", 437 "Exiting Installer",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE, null, null, null) 438 ==JOptionPane.YES_OPTION){ 439 440 this.dispose(); 441 installer.exit(); 442 } 443 } 444 } 445 446 450 static void deepSet(JComponent jc, boolean opaque){ 451 if(opaque) 452 jc.setOpaque(false); 453 else 454 jc.setBackground(BK_COL); 455 456 jc.setFont(GuiProperties.textFont); 457 if(jc instanceof JButton) 458 jc.setForeground(BTN_COL); 459 else 460 jc.setForeground(FG_COL); 461 int n=jc.getComponentCount(); 462 for(int i=0;i<n;i++){ 463 Component c=jc.getComponent(i); 464 if(c instanceof JComponent) 465 deepSet((JComponent)c,opaque); 466 } 467 } 468 469 473 private int _showOptionDialog(Component parentComponent, Object message, 474 String title, int optionType, 475 int messageType, Icon icon, 476 Object [] options, Object initialValue) { 477 JOptionPane pane = new JOptionPane(message, messageType, 478 optionType, icon, 479 options, initialValue); 480 481 pane.setBackground(this.BK_COL); 482 pane.setOpaque(true); 483 pane.setInitialValue(initialValue); 484 485 deepSet(pane,true); 487 488 JDialog dialog = pane.createDialog(parentComponent, title); 489 dialog.setBackground(BK_COL); 490 dialog.getContentPane().setBackground(BK_COL); 491 dialog.invalidate(); 492 493 pane.selectInitialValue(); 494 495 dialog.show(); 496 497 Object selectedValue = pane.getValue(); 498 499 if(selectedValue == null) 500 return JOptionPane.CLOSED_OPTION; 501 if(options == null) { 502 if(selectedValue instanceof Integer ) 503 return ((Integer )selectedValue).intValue(); 504 return JOptionPane.CLOSED_OPTION; 505 } 506 for(int counter = 0, maxCounter = options.length; 507 counter < maxCounter; counter++) { 508 if(options[counter].equals(selectedValue)) 509 return counter; 510 } 511 return JOptionPane.CLOSED_OPTION; 512 } 513 514 public void bk(){ 515 if(installer.isLastStep()){ 516 installer.back(); 517 navPanel.revertFinalPage(); 519 } 520 else 521 installer.back(); 522 523 } 528 529 public void fwd(){ 530 installer.goOn(); 531 } 532 535 public void canFwd(){ 536 enableAllButtons(); 537 } 538 544 public void executeShellOnExit(boolean execute){ 545 executeShell=execute; 547 } 548 549 public boolean shouldExecuteShell(){ 550 return executeShell; 551 } 552 553 554 Runnable updateUI = new Runnable () { 555 public void run() { 556 SwingUtilities.updateComponentTreeUI(thisFrame); 557 } 558 }; 559 } 560 561 | Popular Tags |