1 19 20 package org.netbeans.swing.plaf.gtk; 21 22 import java.awt.Color ; 23 import java.awt.Component ; 24 import java.awt.Font ; 25 import java.awt.Graphics ; 26 import java.awt.GraphicsConfiguration ; 27 import java.awt.GraphicsEnvironment ; 28 import java.awt.Image ; 29 import java.awt.Transparency ; 30 import java.lang.reflect.Method ; 31 import javax.swing.BorderFactory ; 32 import javax.swing.Icon ; 33 import javax.swing.JComponent ; 34 import javax.swing.JTree ; 35 import javax.swing.LookAndFeel ; 36 import javax.swing.UIDefaults ; 37 import javax.swing.UIManager ; 38 import javax.swing.plaf.FontUIResource ; 39 import javax.swing.plaf.synth.Region ; 40 import javax.swing.plaf.synth.SynthConstants ; 41 import javax.swing.plaf.synth.SynthContext ; 42 import javax.swing.plaf.synth.SynthLookAndFeel ; 43 import javax.swing.plaf.synth.SynthStyle ; 44 import org.netbeans.swing.plaf.LFCustoms; 45 import org.netbeans.swing.plaf.util.UIUtils; 46 47 51 public class GtkLFCustoms extends LFCustoms { 52 private Object light = new ThemeValue (ThemeValue.REGION_PANEL, ThemeValue.WHITE, Color.GRAY); 53 private Object control = new ThemeValue (ThemeValue.REGION_PANEL, ThemeValue.MID, Color.GRAY); 54 private Object controlFont = new ThemeValue (ThemeValue.REGION_TAB, new FontUIResource ("Dialog", Font.PLAIN, 11)); 56 57 59 60 public Object [] createApplicationSpecificKeysAndValues () { 61 64 Object selBg = ThemeValue.functioning() ? new ThemeValue (ThemeValue.REGION_BUTTON, ThemeValue.DARK, Color.CYAN) : (Object ) Color.CYAN; 65 Object selFg = ThemeValue.functioning() ? new ThemeValue (ThemeValue.REGION_BUTTON, ThemeValue.TEXT_FOREGROUND, Color.BLACK) : (Object ) Color.BLACK; 66 67 Object fb = new Color (144, 144, 255); 68 Object tabBg = ThemeValue.functioning() ? new ThemeValue (ThemeValue.REGION_INTFRAME, ThemeValue.DARK, fb) : (Object ) fb; 69 70 if (!ThemeValue.functioning()) { 71 Integer i = (Integer ) UIManager.get("customFontSize"); int sz = 11; 73 if (i != null) { 74 sz = i.intValue(); 75 } 76 controlFont = new Font ("Dialog", Font.PLAIN, sz); } 78 79 Color borderColor = (Color ) UIManager.get("InternalFrame.borderShadow"); 80 if (borderColor == null) { 81 borderColor = new Color (144,150,162); 82 } 83 84 Object [] result = { 85 PROPSHEET_SELECTION_BACKGROUND, selBg, 86 PROPSHEET_SELECTION_FOREGROUND, selFg, 87 PROPSHEET_SELECTED_SET_BACKGROUND, selBg, 88 PROPSHEET_SELECTED_SET_FOREGROUND, selFg, 89 PROPSHEET_BUTTON_COLOR, selFg, 90 91 PROPSHEET_SET_BACKGROUND, ThemeValue.functioning() ? (Object ) control : (Object ) Color.CYAN, 92 PROPSHEET_DISABLED_FOREGROUND, new Color (161,161,146), 93 "Table.selectionBackground", selBg, "Table.selectionForeground", selFg, PROPSHEET_BACKGROUND, Color.WHITE, 96 "window", light, 97 98 VIEW_TAB_OUTER_BORDER, BorderFactory.createEmptyBorder(), 99 VIEW_TAB_TABS_BORDER, BorderFactory.createEmptyBorder(), 100 VIEW_TAB_CONTENT_BORDER, BorderFactory.createMatteBorder(0,1,1,1,borderColor), 101 EDITOR_TAB_OUTER_BORDER, BorderFactory.createEmptyBorder(), 102 EDITOR_TAB_CONTENT_BORDER, BorderFactory.createMatteBorder(0,1,1,1,borderColor), 103 EDITOR_TAB_TABS_BORDER, BorderFactory.createEmptyBorder(), 104 105 EDITOR_STATUS_LEFT_BORDER, new InsetBorder (false, true), 106 EDITOR_STATUS_RIGHT_BORDER, new InsetBorder (false, false), 107 EDITOR_STATUS_ONLYONEBORDER, new InsetBorder (false, false), 108 EDITOR_STATUS_INNER_BORDER, new InsetBorder (false, true), 109 110 OUTPUT_BACKGROUND, control, 111 OUTPUT_HYPERLINK_FOREGROUND, selFg, 112 OUTPUT_SELECTION_BACKGROUND, selBg, 113 114 "controlFont", controlFont, 116 EDITOR_TAB_DISPLAYER_UI, 118 "org.netbeans.swing.tabcontrol.plaf.GtkEditorTabDisplayerUI", VIEW_TAB_DISPLAYER_UI, 120 "org.netbeans.swing.tabcontrol.plaf.GtkViewTabDisplayerUI", SLIDING_TAB_BUTTON_UI, "org.netbeans.swing.tabcontrol.plaf.SlidingTabDisplayerButtonUI", SLIDING_BUTTON_UI, "org.netbeans.swing.tabcontrol.plaf.GtkSlidingButtonUI", 124 DESKTOP_BACKGROUND, ThemeValue.functioning() ? new ThemeValue (ThemeValue.REGION_BUTTON, ThemeValue.LIGHT, Color.GRAY) : (Object ) Color.GRAY, 125 EXPLORER_MINISTATUSBAR_BORDER, BorderFactory.createEmptyBorder(), 126 127 129 PROGRESS_CANCEL_BUTTON_ICON, UIUtils.loadImage("org/netbeans/swing/plaf/resources/cancel_task_linux_mac.png"), 130 "winclassic_tab_sel_gradient", tabBg, 131 }; 132 return result; 133 } 134 135 public Object [] createLookAndFeelCustomizationKeysAndValues() { 136 JTree tree = new JTree (); 137 Icon treeExpandedIcon = SynthIconWrapper.createSynthIconWrapper("Tree.expandedIcon", tree, Region.TREE); 138 if (treeExpandedIcon == null) { 140 treeExpandedIcon = new GTKExpandedIcon(); 141 } 142 Icon treeCollapsedIcon = SynthIconWrapper.createSynthIconWrapper("Tree.collapsedIcon", tree, Region.TREE); 143 if (treeCollapsedIcon == null) { 145 treeCollapsedIcon = new GTKCollapsedIcon(); 146 } 147 148 if (ThemeValue.functioning()) { 149 return new Object [] { 150 "control", control, 154 "controlHighlight", new ThemeValue (ThemeValue.REGION_PANEL, ThemeValue.LIGHT, Color.LIGHT_GRAY), "controlShadow", new ThemeValue (ThemeValue.REGION_PANEL, ThemeValue.DARK, Color.DARK_GRAY), "controlDkShadow", new ThemeValue (ThemeValue.REGION_PANEL, ThemeValue.BLACK, Color.BLACK), "controlLtHighlight", new ThemeValue (ThemeValue.REGION_PANEL, ThemeValue.WHITE, Color.WHITE), "textText", new ThemeValue (ThemeValue.REGION_PANEL, ThemeValue.TEXT_FOREGROUND, Color.BLACK), "text", new ThemeValue (ThemeValue.REGION_PANEL, ThemeValue.TEXT_BACKGROUND, Color.GRAY), 161 "tab_unsel_fill", control, 163 "SplitPane.dividerSize", new Integer (2), 165 SYSTEMFONT, controlFont, USERFONT, controlFont, MENUFONT, controlFont, LISTFONT, controlFont, "Label.font", controlFont, "Panel.font", controlFont, 172 175 "FileChooserUI", "javax.swing.plaf.metal.MetalFileChooserUI", "FileView.computerIcon", javax.swing.plaf.metal.MetalIconFactory.getTreeComputerIcon(), "FileView.hardDriveIcon", javax.swing.plaf.metal.MetalIconFactory.getTreeHardDriveIcon(), "FileView.floppyDriveIcon", javax.swing.plaf.metal.MetalIconFactory.getTreeFloppyDriveIcon(), "FileChooser.newFolderIcon", javax.swing.plaf.metal.MetalIconFactory.getFileChooserNewFolderIcon(), "FileChooser.upFolderIcon", javax.swing.plaf.metal.MetalIconFactory.getFileChooserUpFolderIcon(), "FileChooser.homeFolderIcon", javax.swing.plaf.metal.MetalIconFactory.getFileChooserHomeFolderIcon(), "FileChooser.detailsViewIcon", javax.swing.plaf.metal.MetalIconFactory.getFileChooserDetailViewIcon(), "FileChooser.listViewIcon", javax.swing.plaf.metal.MetalIconFactory.getFileChooserListViewIcon(), "FileChooser.usesSingleFilePane", Boolean.TRUE, "FileChooser.ancestorInputMap", new UIDefaults.LazyInputMap (new Object [] { 187 "ESCAPE", "cancelSelection", "F2", "editFileName", "F5", "refresh", "BACK_SPACE", "Go Up", "ENTER", "approveSelection" }), 193 "Tree.expandedIcon", treeExpandedIcon, 195 "Tree.collapsedIcon", treeCollapsedIcon, 196 }; 197 } else { 198 Object [] result = new Object [] { 199 TOOLBAR_UI, new UIDefaults.ProxyLazyValue ("org.netbeans.swing.plaf.gtk.GtkToolbarUI"), }; 201 return result; 202 } 203 } 204 205 208 private static final class SynthIconWrapper implements Icon { 209 210 215 public static Icon createSynthIconWrapper (String iconID, JComponent comp, Region region) { 216 LookAndFeel laf = UIManager.getLookAndFeel(); 217 218 if (!(laf instanceof SynthLookAndFeel )) { 219 return null; 220 } 221 222 SynthStyle style = ((SynthLookAndFeel )laf).getStyleFactory().getStyle(comp, region); 223 SynthContext context = new SynthContext (comp, region, style, SynthConstants.ENABLED); 224 Icon synthIcon = style.getIcon(context, iconID); 225 226 if (synthIcon == null) { 227 return null; 228 } 229 230 Method paintMethod; 231 try { 232 paintMethod = synthIcon.getClass().getMethod( 233 "paintIcon", SynthContext .class, Graphics .class, 234 Integer.TYPE, Integer.TYPE, Integer.TYPE, Integer.TYPE); 235 paintMethod.setAccessible(true); 236 } catch (Exception e) { 237 return null; 239 } 240 241 GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment(). 242 getDefaultScreenDevice().getDefaultConfiguration(); 243 244 Image img = gc.createCompatibleImage(synthIcon.getIconWidth(), 246 synthIcon.getIconHeight(), Transparency.BITMASK); 247 248 return new SynthIconWrapper(synthIcon, context, paintMethod, img); 249 } 250 251 private Icon original; 252 253 private Method paintMethod; 254 255 private SynthContext context; 256 257 private Image image; 258 259 private SynthIconWrapper(Icon original, SynthContext context, Method paintMethod, Image image) { 260 this.original = original; 261 this.paintMethod = paintMethod; 262 this.context = context; 263 this.image = image; 264 } 265 266 public void paintIcon(Component c, Graphics g, int x, int y) { 267 try { 268 paintMethod.invoke(original, context, image.getGraphics(), 0, 0, 269 getIconWidth(), getIconHeight()); 270 } catch (Exception ex) { 271 return; 273 } 274 g.drawImage(image, x, y, null); 275 } 276 277 public int getIconWidth() { 278 return original.getIconWidth(); 279 } 280 281 public int getIconHeight() { 282 return original.getIconHeight(); 283 } 284 } 285 286 287 288 private static abstract class GTKIcon implements Icon { 289 private static final int SIZE = 11; 290 public int getIconWidth() { 291 return GTKIcon.SIZE; 292 } 293 294 public int getIconHeight() { 295 return GTKIcon.SIZE; 296 } 297 } 298 299 304 private static final class GTKCollapsedIcon extends GTKIcon { 305 public void paintIcon(Component c, Graphics g, int x, int y) { 306 g.translate(x, y); 307 int mid, height, thick, i, j, up, down; 308 int size = Math.min(getIconWidth(),getIconHeight()); 309 mid = (size / 2); 310 height = size / 2 + 1; 311 thick = Math.max(1, size / 7); 312 313 i = size / 2 - height / 2 - 1; 314 315 g.setColor((Color ) UIManager.get("Button.background")); 317 for (j = height - 1; j > 0; j--) { 318 g.drawLine(i, mid - j + 1, i, mid + j - 1); 319 i++; 320 } 321 322 g.setColor((Color ) UIManager.get("Button.foreground")); 323 i = size / 2 - height / 2 - 1; 324 down = thick - 1; 325 for (up = 0; up < thick; up++) { 327 g.drawLine(i + up, 0 - down, i + up, size + down); 328 down--; 329 } 330 i++; 331 332 for (j = height - 1; j > 0; j--) { 334 for (up = 0; up < thick; up++) { 335 g.drawLine(i, mid - j + 1 - up, i, mid - j + 1 - up); 336 g.drawLine(i, mid + j - 1 + up, i, mid + j - 1 + up); 337 } 338 i++; 339 } 340 341 if (thick > 1) { 343 for (up = thick - 2; up >= 0; up--) { 344 g.drawLine(i, mid - up, i, mid + up); 345 i++; 346 } 347 } 348 349 g.translate(-x, -y); 350 } 351 } 352 353 358 private static final class GTKExpandedIcon extends GTKIcon { 359 public void paintIcon(Component c, Graphics g, int x, int y) { 360 g.translate(x, y); 361 int mid, height, thick, i, j, up, down; 362 int size = Math.min(getIconWidth(),getIconHeight()); 363 mid = (size / 2); 364 height = size / 2 + 1; 365 thick = Math.max(1, size / 7); 366 367 j = size / 2 - height / 2 - 1; 368 g.setColor((Color ) UIManager.get("Button.background")); 370 for (i = height - 1; i > 0; i--) { 371 g.drawLine(mid - i + 1, j, mid + i - 1, j); 372 j++; 373 } 374 375 g.setColor((Color ) UIManager.get("Button.foreground")); 376 j = size / 2 - height / 2 - 1; 377 down = thick - 1; 378 for (up = 0; up < thick; up++) { 380 g.drawLine(0 - down, j + up, size + down, j + up); 381 down--; 382 } 383 j++; 384 385 for (i = height - 1; i > 0; i--) { 387 for (up = 0; up < thick; up++ ) { 388 g.drawLine(mid - i + 1 - up, j, mid - i + 1 - up, j); 389 g.drawLine(mid + i - 1 + up, j, mid + i - 1 + up, j); 390 } 391 j++; 392 } 393 394 if (thick > 1) { 396 for (up = thick - 2; up >= 0; up--) { 397 g.drawLine(mid - up, j, mid + up, j); 398 j++; 399 } 400 } 401 402 g.translate(-x, -y); 403 } 404 } 405 406 407 } 408 | Popular Tags |