1 14 package org.compiere.plaf; 15 16 import java.awt.Color ; 17 import java.awt.Dimension ; 18 import java.awt.Font ; 19 import java.awt.Insets ; 20 import java.awt.Toolkit ; 21 import java.awt.Window ; 22 import java.awt.event.WindowEvent ; 23 import java.lang.reflect.Method ; 24 import java.lang.reflect.Modifier ; 25 import java.util.ArrayList ; 26 import java.util.Arrays ; 27 import java.util.ResourceBundle ; 28 29 import javax.swing.ImageIcon ; 30 import javax.swing.JFrame ; 31 import javax.swing.JOptionPane ; 32 import javax.swing.LookAndFeel ; 33 import javax.swing.SwingUtilities ; 34 import javax.swing.UIManager ; 35 import javax.swing.plaf.metal.MetalLookAndFeel ; 36 import javax.swing.plaf.metal.MetalTheme ; 37 38 import org.compiere.swing.CButton; 39 import org.compiere.util.Ini; 40 import org.compiere.util.ValueNamePair; 41 42 49 public final class CompierePLAF 50 { 51 52 public static final String VERSION = "R1.2.0"; 53 54 public static final String BACKGROUND = "CompiereBackground"; 55 56 public static final String BACKGROUND_FILL = "CompiereBackgroundFill"; 57 58 public static final String TABLEVEL = "CompiereTabLevel"; 59 60 61 62 67 public static Color getFieldBackground_Normal() 68 { 69 return ColorBlind.getDichromatColor(UIManager.getColor("text")); 71 } 73 77 public static Color getFieldBackground_Error() 78 { 79 return ColorBlind.getDichromatColor(CompiereTheme.error); 80 } 82 86 public static Color getFieldBackground_Mandatory() 87 { 88 return ColorBlind.getDichromatColor(CompiereTheme.mandatory); 89 } 91 95 public static Color getFieldBackground_Inactive() 96 { 97 return ColorBlind.getDichromatColor(CompiereTheme.inactive); 98 } 100 105 public static Color getFormBackground() 106 { 107 return ColorBlind.getDichromatColor(UIManager.getColor("control")); 108 } 110 115 public static Color getInfoBackground() 116 { 117 return ColorBlind.getDichromatColor(CompiereTheme.info); 118 } 120 121 122 123 128 public static Color getTextColor_Normal() 129 { 130 return ColorBlind.getDichromatColor(UIManager.getColor("textText")); 131 } 133 137 public static Color getTextColor_OK() 138 { 139 return ColorBlind.getDichromatColor(CompiereTheme.txt_ok); 140 } 142 146 public static Color getTextColor_Issue() 147 { 148 return ColorBlind.getDichromatColor(CompiereTheme.txt_error); 149 } 151 156 public static Color getTextColor_Label() 157 { 158 return ColorBlind.getDichromatColor(UIManager.getColor("controlText")); 159 } 161 162 public static Color getPrimary1() 163 { 164 return ColorBlind.getDichromatColor(CompiereTheme.primary1); 165 } 166 public static Color getPrimary2() 167 { 168 return ColorBlind.getDichromatColor(CompiereTheme.primary2); 169 } 170 public static Color getPrimary3() 171 { 172 return ColorBlind.getDichromatColor(CompiereTheme.primary3); 173 } 174 public static Color getSecondary1() 175 { 176 return ColorBlind.getDichromatColor(CompiereTheme.secondary1); 177 } 178 public static Color getSecondary2() 179 { 180 return ColorBlind.getDichromatColor(CompiereTheme.secondary2); 181 } 182 public static Color getSecondary3() 183 { 184 return ColorBlind.getDichromatColor(CompiereTheme.secondary3); 185 } 186 187 188 189 190 194 public static Font getFont_Header() 195 { 196 return CompiereTheme.windowFont; 197 } 200 204 public static Font getFont_Field() 205 { 206 return CompiereTheme.userFont; 207 } 210 214 public static Font getFont_Label() 215 { 216 return CompiereTheme.controlFont; 217 } 220 224 public static Font getFont_Small() 225 { 226 return CompiereTheme.smallFont; 227 } 229 230 231 232 public static final String DEFAULT_PLAF = CompiereLookAndFeel.NAME; 233 234 public static final String DEFAULT_THEME = ""; 235 236 237 private static ValueNamePair[] s_looks = null; 238 239 private static ValueNamePair s_defaultPLAF = null; 240 241 private static ValueNamePair[] s_themes = null; 242 243 private static ValueNamePair s_vp_compiereTheme = null; 244 private static ValueNamePair s_vp_metalTheme = null; 245 private static ValueNamePair s_vp_kunststoffTheme = null; 246 247 256 static 257 { 258 ArrayList plafList = new ArrayList (); 259 ValueNamePair vp = new ValueNamePair("org.compiere.plaf.CompiereLookAndFeel", CompiereLookAndFeel.NAME); 260 plafList.add (vp); 261 ArrayList themeList = new ArrayList (); 263 vp = new ValueNamePair("org.compiere.plaf.CompiereTheme", CompiereTheme.NAME); 264 themeList.add (vp); 265 s_vp_compiereTheme = vp; 266 vp = new ValueNamePair("javax.swing.plaf.metal.DefaultMetalTheme", "Steel"); 267 s_vp_metalTheme = vp; 268 themeList.add (vp); 269 270 try 272 { 273 Class c = Class.forName("com.incors.plaf.kunststoff.KunststoffLookAndFeel"); 274 vp = new ValueNamePair("com.incors.plaf.kunststoff.KunststoffLookAndFeel", "Kunststoff"); 275 plafList.add(vp); 276 vp = new ValueNamePair("com.incors.plaf.kunststoff.KunststoffTheme", "Kuststoff"); 277 themeList.add(vp); 278 s_vp_kunststoffTheme = vp; 279 } 280 catch (Exception e) 281 { 282 } 284 285 316 317 for (int i = 0; i < plafList.size(); i++) 319 { 320 vp = (ValueNamePair)plafList.get(i); 321 UIManager.installLookAndFeel(vp.getName(), vp.getValue()); 322 } 323 324 plafList = new ArrayList (); 326 UIManager.LookAndFeelInfo [] lfInfo = UIManager.getInstalledLookAndFeels(); 327 for (int i = 0; i < lfInfo.length; i++) 328 { 329 vp = new ValueNamePair (lfInfo[i].getClassName(), lfInfo[i].getName()); 330 plafList.add(vp); 331 if (lfInfo[i].getName().equals(DEFAULT_PLAF)) 332 s_defaultPLAF = vp; 333 } 334 s_looks = new ValueNamePair[plafList.size()]; 335 plafList.toArray(s_looks); 336 337 s_themes = new ValueNamePair[themeList.size()]; 339 themeList.toArray(s_themes); 340 } 344 345 349 public static ValueNamePair[] getPLAFs() 350 { 351 return s_looks; 352 } 354 358 public static ValueNamePair[] getThemes () 359 { 360 if (UIManager.getLookAndFeel() instanceof MetalLookAndFeel ) 361 return s_themes; 362 return new ValueNamePair[0]; 363 } 365 366 367 371 public static void setPLAF (Window win) 372 { 373 String look = Ini.getProperty(Ini.P_UI_LOOK); 374 String lookTheme = Ini.getProperty(Ini.P_UI_THEME); 375 ValueNamePair plaf = null; 377 for (int i = 0; i < s_looks.length; i++) 378 { 379 if (s_looks[i].getName().equals(look)) 380 { 381 plaf = s_looks[i]; 382 break; 383 } 384 } 385 ValueNamePair theme = null; 387 for (int i = 0; i < s_themes.length; i++) 388 { 389 if (s_themes[i].getName().equals(lookTheme)) 390 { 391 theme = s_themes[i]; 392 break; 393 } 394 } 395 setPLAF (plaf == null ? s_defaultPLAF : plaf, theme, win); 397 } 399 406 public static void setPLAF (ValueNamePair plaf, ValueNamePair theme, Window win) 407 { 408 if (plaf == null) 409 return; 410 System.out.println("PLAF = " + plaf + (theme == null ? "" : (" - " + theme))); 411 412 try 414 { 415 UIManager.setLookAndFeel(plaf.getValue()); 416 } 417 catch (Exception e) 418 { 419 System.err.println("CompierePLAF.setPLAF - " + e.getMessage()); 420 } 421 LookAndFeel laf = UIManager.getLookAndFeel(); 422 Ini.setProperty(Ini.P_UI_LOOK, plaf.getName()); 423 424 Ini.setProperty(Ini.P_UI_THEME, ""); 426 if (theme == null && laf instanceof MetalLookAndFeel ) 428 { 429 String className = laf.getClass().getName(); 430 if (className.equals("javax.swing.plaf.metal.MetalLookAndFeel")) 431 theme = s_vp_metalTheme; 432 else if (className.equals("org.compiere.plaf.CompiereLookAndFeel")) 433 theme = s_vp_compiereTheme; 434 else if (className.equals("com.incors.plaf.kunststoff.KunststoffLookAndFeel")) 435 theme = s_vp_kunststoffTheme; 436 } 437 if (theme != null && laf instanceof MetalLookAndFeel && theme.getValue().length() > 0) 438 { 439 try 440 { 441 Class c = Class.forName(theme.getValue()); 442 MetalTheme t = (MetalTheme )c.newInstance(); 443 if (laf instanceof CompiereLookAndFeel) 444 CompiereLookAndFeel.setCurrentTheme(t); 445 else 446 MetalLookAndFeel.setCurrentTheme(t); 447 CompiereTheme.setTheme(t); Ini.setProperty(Ini.P_UI_THEME, theme.getName()); 450 } 451 catch (Exception e) 452 { 453 System.err.println("CompierePLAF.setPLAF Theme - " + e.getMessage()); 454 } 455 } 456 updateUI (win); 457 } 460 464 public static void updateUI (Window win) 465 { 466 if (win == null) 467 return; 468 Window c = win; 469 do 470 { 471 SwingUtilities.updateComponentTreeUI(c); 472 c.invalidate(); 473 c.pack(); 474 c.validate(); 475 c.repaint(); 476 c = c.getOwner(); 477 } 478 while (c != null); 479 } 481 485 public static void reset (Window win) 486 { 487 CompiereTheme.reset (Ini.getProperties()); CompierePLAF.setPLAF (win); 490 } 492 495 public static void printPLAFDefaults () 496 { 497 System.out.println(UIManager.getLookAndFeel()); 498 Object [] keys = UIManager.getLookAndFeelDefaults().keySet().toArray(); 499 Arrays.sort(keys); 500 char lastStart = ' '; 501 for (int i = 0; i < keys.length; i++) 502 { 503 StringBuffer sb = new StringBuffer (); 504 sb.append(keys[i]).append(" = ").append(UIManager.get(keys[i])); 505 if (keys[i].toString().charAt(0) != lastStart) 506 { 507 System.out.println(); 508 lastStart = keys[i].toString().charAt(0); 509 } 510 System.out.println(sb); 511 } 512 } 514 518 public static boolean isActive() 519 { 520 return UIManager.getLookAndFeel() instanceof CompiereLookAndFeel; 521 } 523 524 525 static ResourceBundle s_res = ResourceBundle.getBundle("org.compiere.plaf.PlafRes"); 526 527 531 public static CButton getOKButton() 532 { 533 CButton b = new CButton(); 534 b.setIcon(new ImageIcon (CompierePLAF.class.getResource("icons/Ok24.gif"))); 535 b.setMargin(new Insets (0,10,0,10)); 536 b.setToolTipText (s_res.getString("OK")); 537 return b; 538 } 540 544 public static CButton getCancelButton() 545 { 546 CButton b = new CButton(); 547 b.setIcon(new ImageIcon (CompierePLAF.class.getResource("icons/Cancel24.gif"))); 548 b.setMargin(new Insets (0,10,0,10)); 549 b.setToolTipText (s_res.getString("Cancel")); 550 return b; 551 } 553 557 public static void showCenterScreen (Window window) 558 { 559 window.pack(); 560 Dimension sSize = Toolkit.getDefaultToolkit().getScreenSize(); 561 Dimension wSize = window.getSize(); 562 window.setLocation(((sSize.width-wSize.width)/2), ((sSize.height-wSize.height)/2)); 563 window.toFront(); 564 window.setVisible(true); 565 } 567 568 569 573 public static void main (String [] args) 574 { 575 String jVersion = System.getProperty("java.version"); 576 if (!(jVersion.startsWith("1.4"))) 577 { 578 JOptionPane.showMessageDialog (null, 579 "Require Java Version 1.4 or up - Not " + jVersion, 580 "CompierePLAF - Version Conflict", 581 JOptionPane.ERROR_MESSAGE); 582 System.exit(1); 583 } 584 585 Ini.loadProperties (true); 587 CompiereTheme.load (); 588 setPLAF (null); 589 if (args.length == 0) 591 { 592 CompierePLAFFrame frame = new CompierePLAFFrame(); 593 return; 594 } 595 596 String className = args[0]; 597 Class startClass = null; 599 try 600 { 601 startClass = Class.forName(className); 602 } 603 catch (Exception e) 604 { 605 System.err.println("Did not find: " + className); 606 e.printStackTrace(); 607 System.exit(1); 608 } 609 610 try 612 { 613 Method [] methods = startClass.getMethods(); 614 for (int i = 0; i < methods.length; i++) 615 { 616 if (Modifier.isStatic(methods[i].getModifiers()) && methods[i].getName().equals("main")) 617 { 618 String [] startArgs = new String [args.length-1]; 619 for (int ii = 1; ii < args.length; ii++) 620 startArgs[ii-i] = args[ii]; 621 methods[i].invoke(null, new Object [] {startArgs}); 622 } 623 return; 624 } 625 } 626 catch (Exception ee) 627 { 628 System.err.println("Problems invoking main"); 629 ee.printStackTrace(); 630 } 631 632 try 634 { 635 startClass.newInstance(); 636 } 637 catch (Exception e) 638 { 639 System.err.println("Cannot start: " + className); 640 e.printStackTrace(); 641 System.exit(1); 642 } 643 } 645 } 647 650 class CompierePLAFFrame extends JFrame  651 { 652 655 public CompierePLAFFrame() 656 { 657 super("CompierePLAF"); 658 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 659 setIconImage(Toolkit.getDefaultToolkit().getImage(CompierePLAF.class.getResource("icons/CL16.gif"))); 660 CompierePLAF.showCenterScreen(this); 661 } 663 667 protected void processWindowEvent (WindowEvent e) 668 { 669 super.processWindowEvent(e); 670 if (e.getID() == WindowEvent.WINDOW_OPENED) 671 { 672 CompierePLAFEditor ed = new CompierePLAFEditor(this, true); 673 dispose(); 674 } 675 } } | Popular Tags |