1 7 8 package javax.swing.plaf.metal; 9 10 import java.awt.*; 11 import java.net.URL ; 12 import java.util.*; 13 import javax.swing.*; 14 import javax.swing.plaf.*; 15 import com.sun.java.swing.SwingUtilities2; 16 import sun.swing.PrintColorUIResource; 17 18 31 public class OceanTheme extends DefaultMetalTheme { 32 private static final ColorUIResource PRIMARY1 = 33 new ColorUIResource(0x6382BF); 34 private static final ColorUIResource PRIMARY2 = 35 new ColorUIResource(0xA3B8CC); 36 private static final ColorUIResource PRIMARY3 = 37 new ColorUIResource(0xB8CFE5); 38 private static final ColorUIResource SECONDARY1 = 39 new ColorUIResource(0x7A8A99); 40 private static final ColorUIResource SECONDARY2 = 41 new ColorUIResource(0xB8CFE5); 42 private static final ColorUIResource SECONDARY3 = 43 new ColorUIResource(0xEEEEEE); 44 45 private static final ColorUIResource CONTROL_TEXT_COLOR = 46 new PrintColorUIResource(0x333333, Color.BLACK); 47 private static final ColorUIResource INACTIVE_CONTROL_TEXT_COLOR = 48 new ColorUIResource(0x999999); 49 private static final ColorUIResource MENU_DISABLED_FOREGROUND = 50 new ColorUIResource(0x999999); 51 private static final ColorUIResource OCEAN_BLACK = 52 new PrintColorUIResource(0x333333, Color.BLACK); 53 54 private static class COIcon extends IconUIResource { 57 private Icon rtl; 58 59 public COIcon(Icon ltr, Icon rtl) { 60 super(ltr); 61 this.rtl = rtl; 62 } 63 64 public void paintIcon(Component c, Graphics g, int x, int y) { 65 if (MetalUtils.isLeftToRight(c)) { 66 super.paintIcon(c, g, x, y); 67 } else { 68 rtl.paintIcon(c, g, x, y); 69 } 70 } 71 } 72 73 private static class IFIcon extends IconUIResource { 76 private Icon pressed; 77 78 public IFIcon(Icon normal, Icon pressed) { 79 super(normal); 80 this.pressed = pressed; 81 } 82 83 public void paintIcon(Component c, Graphics g, int x, int y) { 84 ButtonModel model = ((AbstractButton)c).getModel(); 85 if (model.isPressed() && model.isArmed()) { 86 pressed.paintIcon(c, g, x, y); 87 } else { 88 super.paintIcon(c, g, x, y); 89 } 90 } 91 } 92 93 96 public OceanTheme() { 97 } 98 99 105 public void addCustomEntriesToTable(UIDefaults table) { 106 Object focusBorder = new UIDefaults.ProxyLazyValue( 107 "javax.swing.plaf.BorderUIResource$LineBorderUIResource", 108 new Object [] {getPrimary1()}); 109 java.util.List buttonGradient = Arrays.asList( 111 new Object [] {new Float (.3f), new Float (0f), 112 new ColorUIResource(0xDDE8F3), getWhite(), getSecondary2() }); 113 114 Color cccccc = new ColorUIResource(0xCCCCCC); 122 Color dadada = new ColorUIResource(0xDADADA); 123 Color c8ddf2 = new ColorUIResource(0xC8DDF2); 124 Object directoryIcon = getIconResource("icons/ocean/directory.gif"); 125 Object fileIcon = getIconResource("icons/ocean/file.gif"); 126 java.util.List sliderGradient = Arrays.asList(new Object [] { 127 new Float (.3f), new Float (.2f), 128 c8ddf2, getWhite(), new ColorUIResource(SECONDARY2) }); 129 130 Object [] defaults = new Object [] { 131 "Button.gradient", buttonGradient, 132 "Button.rollover", Boolean.TRUE, 133 "Button.toolBarBorderBackground", INACTIVE_CONTROL_TEXT_COLOR, 134 "Button.disabledToolBarBorderBackground", cccccc, 135 "Button.rolloverIconType", "ocean", 136 137 "CheckBox.rollover", Boolean.TRUE, 138 "CheckBox.gradient", buttonGradient, 139 140 "CheckBoxMenuItem.gradient", buttonGradient, 141 142 "FileChooser.homeFolderIcon", 144 getIconResource("icons/ocean/homeFolder.gif"), 145 "FileChooser.newFolderIcon", 147 getIconResource("icons/ocean/newFolder.gif"), 148 "FileChooser.upFolderIcon", 150 getIconResource("icons/ocean/upFolder.gif"), 151 152 "FileView.computerIcon", 154 getIconResource("icons/ocean/computer.gif"), 155 "FileView.directoryIcon", directoryIcon, 156 "FileView.hardDriveIcon", 158 getIconResource("icons/ocean/hardDrive.gif"), 159 "FileView.fileIcon", fileIcon, 160 "FileView.floppyDriveIcon", 162 getIconResource("icons/ocean/floppy.gif"), 163 164 "Label.disabledForeground", getInactiveControlTextColor(), 165 166 "Menu.opaque", Boolean.FALSE, 167 168 "MenuBar.gradient", Arrays.asList(new Object [] { 169 new Float (1f), new Float (0f), 170 getWhite(), dadada, 171 new ColorUIResource(dadada) }), 172 "MenuBar.borderColor", cccccc, 173 174 "InternalFrame.activeTitleGradient", buttonGradient, 175 "InternalFrame.closeIcon", 177 new UIDefaults.LazyValue() { 178 public Object createValue(UIDefaults table) { 179 return new IFIcon(getHastenedIcon("icons/ocean/close.gif", table), 180 getHastenedIcon("icons/ocean/close-pressed.gif", table)); 181 } 182 }, 183 "InternalFrame.iconifyIcon", 185 new UIDefaults.LazyValue() { 186 public Object createValue(UIDefaults table) { 187 return new IFIcon(getHastenedIcon("icons/ocean/iconify.gif", table), 188 getHastenedIcon("icons/ocean/iconify-pressed.gif", table)); 189 } 190 }, 191 "InternalFrame.minimizeIcon", 193 new UIDefaults.LazyValue() { 194 public Object createValue(UIDefaults table) { 195 return new IFIcon(getHastenedIcon("icons/ocean/minimize.gif", table), 196 getHastenedIcon("icons/ocean/minimize-pressed.gif", table)); 197 } 198 }, 199 "InternalFrame.icon", 201 getIconResource("icons/ocean/menu.gif"), 202 "InternalFrame.maximizeIcon", 204 new UIDefaults.LazyValue() { 205 public Object createValue(UIDefaults table) { 206 return new IFIcon(getHastenedIcon("icons/ocean/maximize.gif", table), 207 getHastenedIcon("icons/ocean/maximize-pressed.gif", table)); 208 } 209 }, 210 "InternalFrame.paletteCloseIcon", 212 new UIDefaults.LazyValue() { 213 public Object createValue(UIDefaults table) { 214 return new IFIcon(getHastenedIcon("icons/ocean/paletteClose.gif", table), 215 getHastenedIcon("icons/ocean/paletteClose-pressed.gif", table)); 216 } 217 }, 218 219 "List.focusCellHighlightBorder", focusBorder, 220 221 "MenuBarUI", "javax.swing.plaf.metal.MetalMenuBarUI", 222 223 "OptionPane.errorIcon", 224 getIconResource("icons/ocean/error.png"), 225 "OptionPane.informationIcon", 226 getIconResource("icons/ocean/info.png"), 227 "OptionPane.questionIcon", 228 getIconResource("icons/ocean/question.png"), 229 "OptionPane.warningIcon", 230 getIconResource("icons/ocean/warning.png"), 231 232 "RadioButton.gradient", buttonGradient, 233 "RadioButton.rollover", Boolean.TRUE, 234 235 "RadioButtonMenuItem.gradient", buttonGradient, 236 237 "ScrollBar.gradient", buttonGradient, 238 239 "Slider.altTrackColor", new ColorUIResource(0xD2E2EF), 240 "Slider.gradient", sliderGradient, 241 "Slider.focusGradient", sliderGradient, 242 243 "SplitPane.oneTouchButtonsOpaque", Boolean.FALSE, 244 "SplitPane.dividerFocusColor", c8ddf2, 245 246 "TabbedPane.borderHightlightColor", getPrimary1(), 247 "TabbedPane.contentAreaColor", c8ddf2, 248 "TabbedPane.contentBorderInsets", new Insets(4, 2, 3, 3), 249 "TabbedPane.selected", c8ddf2, 250 "TabbedPane.tabAreaBackground", dadada, 251 "TabbedPane.tabAreaInsets", new Insets(2, 2, 0, 6), 252 "TabbedPane.unselectedBackground", SECONDARY3, 253 254 "Table.focusCellHighlightBorder", focusBorder, 255 "Table.gridColor", SECONDARY1, 256 257 "ToggleButton.gradient", buttonGradient, 258 259 "ToolBar.borderColor", cccccc, 260 "ToolBar.isRollover", Boolean.TRUE, 261 262 "Tree.closedIcon", directoryIcon, 263 264 "Tree.collapsedIcon", 265 new UIDefaults.LazyValue() { 266 public Object createValue(UIDefaults table) { 267 return new COIcon(getHastenedIcon("icons/ocean/collapsed.gif", table), 268 getHastenedIcon("icons/ocean/collapsed-rtl.gif", table)); 269 } 270 }, 271 272 "Tree.expandedIcon", 273 getIconResource("icons/ocean/expanded.gif"), 274 "Tree.leafIcon", fileIcon, 275 "Tree.openIcon", directoryIcon, 276 "Tree.selectionBorderColor", getPrimary1() 277 }; 278 table.putDefaults(defaults); 279 } 280 281 284 boolean isSystemTheme() { 285 return true; 286 } 287 288 293 public String getName() { 294 return "Ocean"; 295 } 296 297 304 protected ColorUIResource getPrimary1() { 305 return PRIMARY1; 306 } 307 308 315 protected ColorUIResource getPrimary2() { 316 return PRIMARY2; 317 } 318 319 326 protected ColorUIResource getPrimary3() { 327 return PRIMARY3; 328 } 329 330 337 protected ColorUIResource getSecondary1() { 338 return SECONDARY1; 339 } 340 341 348 protected ColorUIResource getSecondary2() { 349 return SECONDARY2; 350 } 351 352 359 protected ColorUIResource getSecondary3() { 360 return SECONDARY3; 361 } 362 363 372 protected ColorUIResource getBlack() { 373 return OCEAN_BLACK; 374 } 375 376 383 public ColorUIResource getDesktopColor() { 384 return MetalTheme.white; 385 } 386 387 394 public ColorUIResource getInactiveControlTextColor() { 395 return INACTIVE_CONTROL_TEXT_COLOR; 396 } 397 398 405 public ColorUIResource getControlTextColor() { 406 return CONTROL_TEXT_COLOR; 407 } 408 409 416 public ColorUIResource getMenuDisabledForeground() { 417 return MENU_DISABLED_FOREGROUND; 418 } 419 420 private Object getIconResource(String iconID) { 421 return SwingUtilities2.makeIcon(getClass(), OceanTheme .class, iconID); 422 } 423 424 private Icon getHastenedIcon(String iconID, UIDefaults table) { 427 Object res = getIconResource(iconID); 428 return (Icon)((UIDefaults.LazyValue)res).createValue(table); 429 } 430 } 431 | Popular Tags |