1 21 22 package org.armedbear.j; 23 24 import java.awt.Color ; 25 import java.awt.Font ; 26 import java.awt.FontMetrics ; 27 import java.awt.Toolkit ; 28 import javax.swing.BorderFactory ; 29 import javax.swing.UIDefaults ; 30 import javax.swing.UIManager ; 31 import javax.swing.plaf.ColorUIResource ; 32 import javax.swing.plaf.FontUIResource ; 33 import javax.swing.plaf.metal.DefaultMetalTheme ; 34 import javax.swing.plaf.metal.MetalLookAndFeel ; 35 36 public final class DefaultLookAndFeel extends DefaultMetalTheme 37 { 38 private static final Preferences preferences = Editor.preferences(); 39 40 private final ColorUIResource primary1 = new ColorUIResource (0, 0, 0); 42 private FontUIResource plainFont; 43 44 public static void setLookAndFeel() 45 { 46 String lookAndFeelClassName = 48 "javax.swing.plaf.metal.MetalLookAndFeel"; 49 50 Editor.lookAndFeel = 51 preferences.getStringProperty(Property.LOOK_AND_FEEL); 52 53 if (Editor.lookAndFeel == null) { 54 if (Platform.isPlatformMacOSX()) 55 Editor.lookAndFeel = "Aqua"; 56 } 57 58 if (Editor.lookAndFeel != null) { 59 if (Editor.lookAndFeel.equals("Metal")) { 61 ; } else if (Editor.lookAndFeel.equals("Motif")) { 63 lookAndFeelClassName = 64 "com.sun.java.swing.plaf.motif.MotifLookAndFeel"; 65 } else if (Editor.lookAndFeel.equals("Windows")) { 66 lookAndFeelClassName = 67 "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"; 68 } else if (Editor.lookAndFeel.equals("Aqua")) { 69 lookAndFeelClassName = "com.apple.mrj.swing.MacLookAndFeel"; 70 } else { 76 Editor.lookAndFeel = null; 78 } 79 } 80 if (Editor.lookAndFeel == null) { 81 MetalLookAndFeel.setCurrentTheme(new DefaultLookAndFeel()); 83 UIManager.put("Tree.collapsedIcon", 84 Utilities.getIconFromFile("collapsed.png")); 85 UIManager.put("Tree.expandedIcon", 86 Utilities.getIconFromFile("expanded.png")); 87 } else { 88 MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme ()); 89 } 90 try { 91 UIManager.setLookAndFeel(lookAndFeelClassName); 92 } 93 catch (Exception e) {} 94 UIManager.put("ToolBarUI", "org.armedbear.j.ToolBarUI"); 96 UIManager.put("ButtonUI", "org.armedbear.j.ButtonUI"); 97 UIManager.put("LabelUI", "org.armedbear.j.LabelUI"); 98 } 99 100 private DefaultLookAndFeel() 101 { 102 String name = preferences.getStringProperty(Property.DIALOG_FONT_NAME); 103 int size = preferences.getIntegerProperty(Property.DIALOG_FONT_SIZE); 104 Font font = new Font (name, Font.PLAIN, size); 105 plainFont = new FontUIResource (font); 106 } 107 108 public void addCustomEntriesToTable(UIDefaults table) 109 { 110 table.put("Button.border", BorderFactory.createRaisedBevelBorder()); 111 table.put("TextField.border", BorderFactory.createLoweredBevelBorder()); 112 table.put("SplitPaneUI", "javax.swing.plaf.basic.BasicSplitPaneUI"); 113 table.put("ScrollBarUI", "org.armedbear.j.ScrollBarUI"); 114 table.put("TreeUI", "javax.swing.plaf.basic.BasicTreeUI"); 115 table.put("SplitPane.dividerSize", new Integer (3)); 116 table.put("ScrollBar.background", new Color (0xe0e0e0)); 117 table.put("ScrollBar.foreground", new Color (0xc0c0c0)); 118 table.put("ScrollBar.track", new Color (0xe0e0e0)); 119 table.put("ScrollBar.trackHighlight", Color.black); 120 table.put("ScrollBar.thumb", new Color (0xc0c0c0)); 121 table.put("ScrollBar.thumbHighlight", Color.white); 122 table.put("ScrollBar.thumbDarkShadow", Color.black); 123 table.put("ScrollBar.thumbShadow", new Color (0x808080)); 124 table.put("ScrollBar.width", new Integer (16)); 125 table.put("Button.textIconGap", new Integer (1)); 126 table.put("ToolTipUI", "org.armedbear.j.ToolTipUI"); 127 } 128 129 protected ColorUIResource getPrimary1() 130 { 131 return primary1; 132 } 133 134 public FontUIResource getControlTextFont() 135 { 136 return plainFont; 137 } 138 139 public FontUIResource getSystemTextFont() 140 { 141 return plainFont; 142 } 143 144 public FontUIResource getUserTextFont() 145 { 146 return plainFont; 147 } 148 149 public FontUIResource getMenuTextFont() 150 { 151 return plainFont; 152 } 153 154 public FontUIResource getWindowTitleFont() 155 { 156 return plainFont; 157 } 158 159 public FontUIResource getSubTextFont() 160 { 161 return plainFont; 162 } 163 } 164 | Popular Tags |