1 19 20 21 package org.netbeans.beaninfo.editors; 22 23 24 import java.awt.BorderLayout ; 25 import java.awt.Color ; 26 import java.awt.Component ; 27 import java.awt.Dimension ; 28 import java.awt.Graphics ; 29 import java.awt.FontMetrics ; 30 import java.awt.Graphics2D ; 31 import java.awt.Rectangle ; 32 import java.awt.RenderingHints ; 33 import java.awt.SystemColor ; 34 import java.awt.Toolkit ; 35 import java.beans.PropertyChangeEvent ; 36 import java.beans.PropertyChangeListener ; 37 import java.beans.PropertyChangeSupport ; 38 import java.beans.PropertyEditor ; 39 import java.text.MessageFormat ; 40 import java.util.Enumeration ; 41 import java.util.HashMap ; 42 import java.util.Map ; 43 import javax.swing.border.EmptyBorder ; 44 import javax.swing.colorchooser.AbstractColorChooserPanel ; 45 import javax.swing.colorchooser.ColorSelectionModel ; 46 import javax.swing.colorchooser.DefaultColorSelectionModel ; 47 import javax.swing.event.*; 48 import javax.swing.Icon ; 49 import javax.swing.JColorChooser ; 50 import javax.swing.JList ; 51 import javax.swing.JPanel ; 52 import javax.swing.JScrollPane ; 53 import javax.swing.ListCellRenderer ; 54 import javax.swing.UIDefaults ; 55 import javax.swing.UIManager ; 56 import org.netbeans.core.UIExceptions; 57 import org.openide.explorer.propertysheet.editors.XMLPropertyEditor; 58 import org.openide.util.NbBundle; 59 60 61 66 public final class ColorEditor implements PropertyEditor , XMLPropertyEditor { 67 68 70 71 public static final int AWT_PALETTE = 1; 72 73 public static final int SYSTEM_PALETTE = 2; 74 75 public static final int SWING_PALETTE = 3; 76 77 78 private static String awtColorNames[]; 79 80 81 private static final Color awtColors[] = { 82 Color.white, Color.lightGray, Color.gray, Color.darkGray, 83 Color.black, Color.red, Color.pink, Color.orange, Color.yellow, 84 Color.green, Color.magenta, Color.cyan, Color.blue }; 85 86 88 private static final String awtGenerate[] = { 89 "white", "lightGray", "gray", "darkGray", "black", "red", "pink", "orange", "yellow", "green", "magenta", "cyan", "blue" }; 93 94 private static String systemColorNames[]; 95 96 98 private static final String systemGenerate[] = { 99 "activeCaption", "activeCaptionBorder", "activeCaptionText", "control", "controlDkShadow", "controlHighlight", "controlLtHighlight", "controlShadow", "controlText", "desktop", "inactiveCaption", "inactiveCaptionBorder", "inactiveCaptionText", "info", "infoText", "menu", "menuText", "scrollbar", "text", "textHighlight", "textHighlightText", "textInactiveText", "textText", "window", "windowBorder", "windowText"}; 109 110 private static final Color systemColors[] = { 111 SystemColor.activeCaption, SystemColor.activeCaptionBorder, 112 SystemColor.activeCaptionText, SystemColor.control, 113 SystemColor.controlDkShadow, SystemColor.controlHighlight, 114 SystemColor.controlLtHighlight, SystemColor.controlShadow, 115 SystemColor.controlText, SystemColor.desktop, 116 SystemColor.inactiveCaption, SystemColor.inactiveCaptionBorder, 117 SystemColor.inactiveCaptionText, SystemColor.info, 118 SystemColor.infoText, SystemColor.menu, 119 SystemColor.menuText, SystemColor.scrollbar, SystemColor.text, 120 SystemColor.textHighlight, SystemColor.textHighlightText, 121 SystemColor.textInactiveText, SystemColor.textText, 122 SystemColor.window, SystemColor.windowBorder, 123 SystemColor.windowText}; 124 125 127 private static String swingColorNames[]; 128 129 130 private static Color swingColors[]; 131 132 static final boolean GTK = "GTK".equals(UIManager.getLookAndFeel().getID()); static final boolean AQUA = "Aqua".equals(UIManager.getLookAndFeel().getID()); 135 private static final boolean antialias = Boolean.getBoolean("nb.cellrenderer.antialiasing") ||Boolean.getBoolean("swing.aatext") ||(GTK && gtkShouldAntialias()) ||AQUA; 139 140 private static Boolean gtkAA; 141 private static Map hintsMap; 142 143 144 146 static { 147 UIManager.addPropertyChangeListener(new PropertyChangeListener () { 148 public void propertyChange(PropertyChangeEvent evt) { 149 swingColorNames = null; 150 swingColors = null; 151 } 152 }); 153 154 swingColorNames = null; 155 swingColors = null; 156 } 157 158 160 161 private SuperColor superColor; 162 163 private PropertyChangeSupport support; 164 165 166 167 public static JColorChooser getStaticChooser(ColorEditor ce) { 168 JColorChooser staticChooser = new JColorChooser (new DefaultColorSelectionModel (Color.white) 169 { 170 public void setSelectedColor(Color color) { 171 if (color instanceof SuperColor) { 172 super.setSelectedColor((SuperColor) color); 173 } 174 else if (color instanceof Color ) { 175 super.setSelectedColor(new SuperColor(color)); 176 } 177 } 178 } ) 179 { 180 public void setColor (Color c) { 181 if (c == null) return; 182 super.setColor (c); 183 } 184 }; 185 staticChooser.addChooserPanel ( 186 new NbColorChooserPanel (AWT_PALETTE, getAWTColorNames(), awtColors, 187 getString ("CTL_AWTPalette"), ce) 188 ); 189 initSwingConstants(); 190 staticChooser.addChooserPanel ( 191 new NbColorChooserPanel (SWING_PALETTE, swingColorNames, swingColors, 192 getString ("CTL_SwingPalette"), ce) 193 ); 194 staticChooser.addChooserPanel ( 195 new NbColorChooserPanel (SYSTEM_PALETTE, getSystemColorNames(), systemColors, 196 getString ("CTL_SystemPalette"), ce) 197 ); 198 return staticChooser; 199 } 200 201 203 204 public ColorEditor() { 205 support = new PropertyChangeSupport (this); 206 } 207 208 209 211 213 public Object getValue () { 214 if (superColor != null) { 215 if (superColor.getID () != null) { 216 return superColor; 217 } else { 218 return superColor.getColor (); 219 } 220 221 } else { 222 return null; 223 } 224 } 225 226 229 public void setValue (Object object) { 230 if(object != null) { 231 if (object instanceof SuperColor) { 232 superColor = (SuperColor) object; 233 } 234 else if (object instanceof Color ) { 235 superColor = new SuperColor((Color ) object); 236 } 237 } 238 else { 239 superColor = null; 240 } 241 242 support.firePropertyChange ("", null, null); } 244 245 246 public String getAsText () { 247 if (superColor == null) 248 return "null"; return superColor.getAsText (); 250 } 251 252 253 public void setAsText(String text) throws IllegalArgumentException { 254 if(text == null) { 255 throw new IllegalArgumentException ("null parameter"); } 257 258 text = text.trim(); 259 260 if("null".equals(text)) { setValue(null); 262 return; 263 } 264 265 try { int len = text.length(); 267 if (len > 0) { 268 int start = -1; 269 int end = -1; 270 271 char c1 = text.charAt(0); 272 char c2 = text.charAt(len-1); 273 if (c1 == '[' && c2 == ']') { 274 start = 1; 275 end = len - 1; 276 } 277 else if (c1 >= '0' && c1 <= '9' && c2 >= '0' && c2 <= '9') { 278 start = 0; 279 end = len; 280 } 281 282 if (start >= 0) { 283 int index1 = text.indexOf(','); 284 int index2 = index1 < 0 ? -1 : text.indexOf(',', index1+1); 285 286 if (index1 >= 0 && index2 >= 0) { 287 int red = Integer.parseInt(text.substring( 288 start, index1).trim()); 289 int green = Integer.parseInt(text.substring( 290 index1 + 1, index2).trim()); 291 int blue = Integer.parseInt(text.substring( 292 index2 + 1, end).trim()); 293 294 try { 295 setValue(new SuperColor(null, 296 0, 297 new Color (red, green, blue))); 298 return; 299 } catch( IllegalArgumentException iaE ) { 300 UIExceptions.annotateUser(iaE, null, 301 iaE.getLocalizedMessage(), 302 null, null); 303 throw iaE; 304 } 305 } 306 } 307 } 308 } catch(NumberFormatException nfe) { 309 } 311 312 int index; 313 int palette = 0; 314 Color color = null; 315 316 if((index = getIndex(getAWTColorNames(), text)) >= 0) { 317 palette = AWT_PALETTE; 318 color = awtColors[index]; 319 } 320 321 if(index < 0 && ((index = getIndex(getSystemColorNames(), text)) >= 0)) { 322 palette = SYSTEM_PALETTE; 323 color = systemColors[index]; 324 } 325 326 if(index < 0) { 327 initSwingConstants(); 328 if((index = getIndex(swingColorNames, text)) >= 0) { 329 palette = SWING_PALETTE; 330 color = swingColors[index]; 331 } 332 } 333 334 if(index < 0) { 335 String msg = MessageFormat.format ( 336 NbBundle.getMessage (ColorEditor.class, "FMT_IllegalEntry"), 337 new Object []{text}); 338 IllegalArgumentException iae = new IllegalArgumentException (text); 339 UIExceptions.annotateUser(iae, text, msg, null, null); 340 throw iae; 341 } 342 343 setValue(new SuperColor(text, palette, color)); 344 } 345 346 347 public String getJavaInitializationString() { 348 if (superColor == null) 349 return "null"; if (superColor.getID() == null) 351 return "new java.awt.Color(" + superColor.getRed() + ", " + superColor.getGreen() + ", " + superColor.getBlue() + ")"; 354 switch (superColor.getPalette()) { 355 default: 356 case AWT_PALETTE: 357 return "java.awt.Color." + awtGenerate [getIndex (getAWTColorNames(), superColor.getID())]; case SYSTEM_PALETTE: 359 return "java.awt.SystemColor." + systemGenerate [getIndex (getSystemColorNames(), superColor.getID())]; case SWING_PALETTE: 361 if (superColor.getID() == null) return "new java.awt.Color(" + superColor.getRed() + ", " + superColor.getGreen() + ", " + superColor.getBlue() + ")"; return "javax.swing.UIManager.getDefaults().getColor(\"" + superColor.getID() + "\")"; } 366 } 367 368 369 public String [] getTags() { 370 if (superColor == null) { 371 return getAWTColorNames(); 372 } 373 switch (superColor.getPalette()) { 374 case AWT_PALETTE: 375 return getAWTColorNames(); 376 case SYSTEM_PALETTE: 377 return getSystemColorNames(); 378 case SWING_PALETTE: 379 initSwingConstants(); 380 return swingColorNames; 381 default: 382 return null; 383 } 384 } 385 386 388 public boolean isPaintable () { 389 return true; 390 } 391 392 393 public void paintValue(Graphics g, Rectangle rectangle) { 394 int px; 395 396 ((Graphics2D )g).setRenderingHints (getHints ()); 397 398 if (this.superColor != null) { 399 Color color = g.getColor(); 400 g.drawRect(rectangle.x, rectangle.y + rectangle.height / 2 - 5 , 10, 10); 401 g.setColor(this.superColor); 402 g.fillRect(rectangle.x + 1, rectangle.y + rectangle.height / 2 - 4 , 9, 9); 403 g.setColor(color); 404 px = 18; 405 } 406 else px = 0; 407 408 FontMetrics fm = g.getFontMetrics(); 409 g.drawString(getAsText(), rectangle.x + px, rectangle.y + 410 (rectangle.height - fm.getHeight()) / 2 + fm.getAscent()); 411 } 412 413 416 public boolean supportsCustomEditor () { 417 return true; 418 } 419 420 422 public Component getCustomEditor () { 423 return new NbColorChooser (this, getStaticChooser(this)); 424 } 425 426 427 public void addPropertyChangeListener (PropertyChangeListener propertyChangeListener) { 428 support.addPropertyChangeListener (propertyChangeListener); 429 } 430 431 432 public void removePropertyChangeListener (PropertyChangeListener propertyChangeListener) { 433 support.removePropertyChangeListener (propertyChangeListener); 434 } 435 436 438 private static synchronized String [] getAWTColorNames() { 439 if(awtColorNames == null) { 440 awtColorNames = new String [] { 441 getString("LAB_White"), 442 getString("LAB_LightGray"), 443 getString("LAB_Gray"), 444 getString("LAB_DarkGray"), 445 getString("LAB_Black"), 446 getString("LAB_Red"), 447 getString("LAB_Pink"), 448 getString("LAB_Orange"), 449 getString("LAB_Yellow"), 450 getString("LAB_Green"), 451 getString("LAB_Magenta"), 452 getString("LAB_Cyan"), 453 getString("LAB_Blue") 454 }; 455 } 456 457 return awtColorNames; 458 } 459 460 461 private static synchronized String [] getSystemColorNames() { 462 if(systemColorNames == null) { 463 systemColorNames = new String [] { 464 getString("LAB_ActiveCaption"), 465 getString("LAB_ActiveCaptionBorder"), 466 getString("LAB_ActiveCaptionText"), 467 getString("LAB_Control"), 468 getString("LAB_ControlDkShadow"), 469 getString("LAB_ControlHighlight"), 470 getString("LAB_ControlLtHighlight"), 471 getString("LAB_ControlShadow"), 472 getString("LAB_ControlText"), 473 getString("LAB_Desktop"), 474 getString("LAB_InactiveCaption"), 475 getString("LAB_InactiveCaptionBorder"), 476 getString("LAB_InactiveCaptionText"), 477 getString("LAB_Info"), 478 getString("LAB_InfoText"), 479 getString("LAB_Menu"), 480 getString("LAB_MenuText"), 481 getString("LAB_Scrollbar"), 482 getString("LAB_Text"), 483 getString("LAB_TextHighlight"), 484 getString("LAB_TextHighlightText"), 485 getString("LAB_TextInactiveText"), 486 getString("LAB_TextText"), 487 getString("LAB_Window"), 488 getString("LAB_WindowBorder"), 489 getString("LAB_WindowText") 490 }; 491 } 492 493 return systemColorNames; 494 } 495 496 498 private static String getString(String key) { 499 return NbBundle.getBundle(ColorEditor.class).getString(key); 500 } 501 502 503 private static int getIndex (Object [] names, Object name) { 504 for(int i = 0; i < names.length; i++) { 505 if(name.equals(names[i])) { 506 return i; 507 } 508 } 509 510 return -1; 511 } 512 513 514 private static void initSwingConstants() { 515 if (swingColorNames != null) 516 return; 517 518 UIDefaults def = UIManager.getDefaults (); 519 Enumeration e = def.keys (); 520 521 java.util.TreeSet <String > names = new java.util.TreeSet <String >(); 522 523 while (e.hasMoreElements ()) { 524 Object k = e.nextElement (); 525 if (! (k instanceof String )) 526 continue; 527 Object v = def.get (k); 528 if (! (v instanceof Color )) 529 continue; 530 names.add((String )k); 531 } 532 533 swingColorNames = new String [names.size ()]; 534 names.toArray(swingColorNames); 535 swingColors = new Color [swingColorNames.length]; 536 537 int i, k = swingColorNames.length; 538 for (i = 0; i < k; i++) 539 swingColors [i] = (Color ) def.get (swingColorNames [i]); 540 } 541 542 private SuperColor getSuperColor () { 543 return superColor; 544 } 545 546 547 549 private static class NbColorChooser extends JPanel implements ChangeListener { 550 551 private final ColorEditor editor; 552 553 private final ColorSelectionModel selectionModel; 554 555 static final long serialVersionUID =-6230228701104365037L; 556 557 558 559 public NbColorChooser (final ColorEditor editor, 560 final JColorChooser chooser) { 561 this.editor = editor; 562 selectionModel = chooser.getSelectionModel(); 563 setLayout (new BorderLayout ()); 564 add (chooser, BorderLayout.CENTER); 565 chooser.setColor ((Color )editor.getValue ()); 566 selectionModel.addChangeListener (this); 567 568 getAccessibleContext().setAccessibleDescription(getString("ACSD_CustomColorEditor")); 569 } 570 571 572 public void removeNotify () { 573 super.removeNotify(); 574 selectionModel.removeChangeListener (this); 575 } 576 577 578 public Dimension getPreferredSize () { 579 Dimension s = super.getPreferredSize (); 580 return new Dimension (s.width + 50, s.height + 10); 581 } 582 583 584 public void stateChanged (ChangeEvent evt) { 585 editor.setValue(selectionModel.getSelectedColor()); 586 } 587 588 } 590 591 592 static class SuperColor extends Color { 593 594 static final long serialVersionUID = 6147637669184334151L; 595 596 597 private String id = null; 598 599 private int palette = 0; 600 601 private Color color; 602 603 SuperColor (Color color) { 604 super (color.getRed (), color.getGreen (), color.getBlue ()); 605 this.color = color; 606 607 614 } 615 616 SuperColor (String id, int palette, Color color) { 617 super (color.getRed (), color.getGreen (), color.getBlue ()); 618 this.color = color; 619 this.id = id; 620 this.palette = palette; 621 } 622 623 624 public boolean equals(Object obj) { 625 boolean superEquals = super.equals(obj); 626 String objID = null; 627 int objPalette = -1; 628 629 if (obj instanceof SuperColor) { 630 objID = ((SuperColor)obj).getID(); 631 objPalette = ((SuperColor)obj).getPalette(); 632 } 633 else return superEquals; 634 635 if (objID != null) { 636 return superEquals && objID.equals(getID()) && (objPalette == getPalette()); 637 } 638 else { 639 return superEquals && (null == getID()) && (objPalette == getPalette()); 640 } 641 } 642 643 644 private String getID () { 645 return id; 646 } 647 648 649 private int getPalette () { 650 return palette; 651 } 652 653 654 private Color getColor () { 655 return this.color; 656 } 657 658 659 private String getAsText () { 660 if (id != null) return id; 661 return "[" + getRed () + "," + getGreen () + "," + getBlue () + "]"; } 663 } 665 666 private static final class NbColorChooserPanel extends AbstractColorChooserPanel 667 implements ListSelectionListener { 668 669 static final long serialVersionUID = -2792992315444428631L; 670 671 private JList list; 672 673 674 String [] names; 675 676 Color [] colors; 677 678 int palette; 679 680 ColorEditor ce; 681 682 683 private String displayName; 684 685 686 688 NbColorChooserPanel (final int palette, final String [] names, 689 final Color [] colors, final String displayName, final ColorEditor ce) { 690 this.names = names; 691 this.colors = colors; 692 this.palette = palette; 693 this.displayName = displayName; 694 this.ce = ce; 695 } 696 697 698 protected void buildChooser () { 699 setLayout (new BorderLayout ()); 700 add (BorderLayout.CENTER, 701 new JScrollPane (list = new JList (names))); 702 list.setCellRenderer (new MyListCellRenderer ()); 703 list.addListSelectionListener (this); 704 705 list.getAccessibleContext().setAccessibleName(displayName); 706 } 707 708 709 public void updateChooser () { 710 SuperColor sc = ce.getSuperColor (); 711 712 if (sc != null && palette == sc.getPalette ()) { 713 int i = getIndex (names, sc.getID ()); 714 list.setSelectedIndex (i); 715 } else 716 list.clearSelection (); 717 } 718 719 720 public String getDisplayName() { 721 return displayName; 722 } 723 724 725 public Icon getSmallDisplayIcon() { 726 return null; 727 } 728 729 730 public Icon getLargeDisplayIcon() { 731 return null; 732 } 733 734 735 public void valueChanged(ListSelectionEvent e) { 736 if (!list.isSelectionEmpty ()) { 737 int i = list.getSelectedIndex (); 738 getColorSelectionModel().setSelectedColor( 739 new SuperColor (names [i], palette, colors [i])); 740 } 741 } 742 743 744 public void setColor (final Color newColor) { 745 getColorSelectionModel().setSelectedColor(newColor); 746 } 747 748 749 public Color getColor () { 750 return getColorFromModel(); 751 } 752 753 754 755 private final class MyListCellRenderer extends JPanel implements ListCellRenderer { 756 757 758 private boolean selected; 759 760 private boolean hasFocus; 761 762 private int index; 763 764 765 static final long serialVersionUID =-8877709520578055594L; 766 767 768 769 public MyListCellRenderer () { 770 this.setOpaque (true); 771 this.setBorder (new EmptyBorder (1, 1, 1, 1)); 772 } 773 774 778 public Dimension getPreferredSize () { 779 try { 780 FontMetrics fontMetrics = this.getFontMetrics(this.getFont()); 781 return new Dimension ( 782 fontMetrics.stringWidth (names [index]) + 30, 783 fontMetrics.getHeight () + 4 784 ); 785 } catch (NullPointerException e) { 786 return new Dimension (10, 10); 787 } 788 } 789 790 791 public void paint (Graphics g) { 792 ((Graphics2D )g).setRenderingHints (getHints ()); 793 794 Dimension rectangle = this.getSize (); 795 Color color = g.getColor (); 796 797 if(selected) { 798 g.setColor (UIManager.getColor ("List.selectionBackground")); } else { 800 g.setColor (UIManager.getColor ("List.background")); } 802 803 g.fillRect (0, 0, rectangle.width - 1, rectangle.height - 1); 804 805 if (hasFocus) { 806 g.setColor (Color.black); 807 g.drawRect (0, 0, rectangle.width - 1, rectangle.height - 1); 808 } 809 810 g.setColor (Color.black); 811 g.drawRect (6, rectangle.height / 2 - 5 , 10, 10); 812 g.setColor (colors [index]); 813 g.fillRect (7, rectangle.height / 2 - 4 , 9, 9); 814 815 if(selected) { 816 g.setColor (UIManager.getColor ("List.selectionForeground")); } else { 818 g.setColor (UIManager.getColor ("List.foreground")); } 820 821 FontMetrics fm = g.getFontMetrics (); 822 g.drawString (names [index], 22, (rectangle.height - fm.getHeight ()) / 2 + fm.getAscent ()); 823 g.setColor (color); 824 } 825 826 829 public Component getListCellRendererComponent ( 830 JList list, 831 Object value, int index, boolean isSelected, boolean cellHasFocus ) { 836 this.index = index; 837 selected = isSelected; 838 hasFocus = cellHasFocus; 839 getAccessibleContext().setAccessibleName(names[index]); 840 return this; 841 } 842 } } 845 848 849 public static final String XML_COLOR = "Color"; 851 852 public static final String ATTR_TYPE = "type"; 854 public static final String ATTR_RED = "red"; 856 public static final String ATTR_GREEN = "green"; 858 public static final String ATTR_BLUE = "blue"; 860 public static final String ATTR_ID = "id"; 862 public static final String ATTR_PALETTE = "palette"; 864 865 public static final String VALUE_PALETTE = "palette"; 867 public static final String VALUE_RGB = "rgb"; 869 public static final String VALUE_NULL = "null"; 871 872 879 public void readFromXML (org.w3c.dom.Node element) throws java.io.IOException { 880 if (!XML_COLOR.equals (element.getNodeName ())) { 881 throw new java.io.IOException (); 882 } 883 org.w3c.dom.NamedNodeMap attributes = element.getAttributes (); 884 try { 885 String type = attributes.getNamedItem (ATTR_TYPE).getNodeValue (); 886 if (VALUE_NULL.equals(type)) { 887 setValue(null); 888 } else { 889 String red = attributes.getNamedItem (ATTR_RED).getNodeValue (); 890 String green = attributes.getNamedItem (ATTR_GREEN).getNodeValue (); 891 String blue = attributes.getNamedItem (ATTR_BLUE).getNodeValue (); 892 if (VALUE_PALETTE.equals (type)) { 893 String id = attributes.getNamedItem (ATTR_ID).getNodeValue (); 894 String palette = attributes.getNamedItem (ATTR_PALETTE).getNodeValue (); 895 setValue (new SuperColor (id, Integer.parseInt (palette), new Color (Integer.parseInt (red, 16), Integer.parseInt (green, 16), Integer.parseInt (blue, 16)))); 896 } else { 897 setValue (new SuperColor (new Color (Integer.parseInt (red, 16), Integer.parseInt (green, 16), Integer.parseInt (blue, 16)))); 898 } 899 } 900 } catch (NullPointerException e) { 901 throw new java.io.IOException (); 902 } 903 } 904 905 911 public org.w3c.dom.Node storeToXML(org.w3c.dom.Document doc) { 912 org.w3c.dom.Element el = doc.createElement (XML_COLOR); 913 el.setAttribute (ATTR_TYPE, (superColor == null) ? VALUE_NULL : ((superColor.getID () == null) ? VALUE_RGB : VALUE_PALETTE)); 914 if (superColor != null) { 915 el.setAttribute (ATTR_RED, Integer.toHexString (superColor.getRed ())); 916 el.setAttribute (ATTR_GREEN, Integer.toHexString (superColor.getGreen ())); 917 el.setAttribute (ATTR_BLUE, Integer.toHexString (superColor.getBlue ())); 918 if (superColor.getID () != null) { 919 el.setAttribute (ATTR_ID, superColor.getID ()); 920 el.setAttribute (ATTR_PALETTE, Integer.toString (superColor.getPalette ())); 921 } 922 } 923 return el; 924 } 925 926 public static final boolean gtkShouldAntialias() { 927 if (gtkAA == null) { 928 Object o = Toolkit.getDefaultToolkit().getDesktopProperty("gnome.Xft/Antialias"); gtkAA = Boolean.valueOf(Integer.valueOf(1).equals(o)); 930 } 931 932 return gtkAA.booleanValue(); 933 } 934 935 private static Map getHints () { 937 if (hintsMap == null) { 938 hintsMap = (Map )(Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints")); if (hintsMap == null) { 940 hintsMap = new HashMap (); 941 if (antialias) { 942 hintsMap.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); 943 } 944 } 945 } 946 return hintsMap; 947 } 948 } 949 | Popular Tags |