1 14 package org.compiere.plaf; 15 16 import java.awt.AlphaComposite ; 17 import java.awt.BasicStroke ; 18 import java.awt.Color ; 19 import java.awt.Container ; 20 import java.awt.GradientPaint ; 21 import java.awt.Graphics ; 22 import java.awt.Graphics2D ; 23 import java.awt.Point ; 24 import java.awt.Rectangle ; 25 import java.awt.TexturePaint ; 26 import java.awt.Window ; 27 import java.awt.image.BufferedImage ; 28 import java.io.Serializable ; 29 import java.net.URL ; 30 import java.util.ResourceBundle ; 31 32 import javax.swing.JComponent ; 33 import javax.swing.JDialog ; 34 import javax.swing.JFrame ; 35 import javax.swing.JPanel ; 36 import javax.swing.JWindow ; 37 import javax.swing.SwingConstants ; 38 import javax.swing.UIManager ; 39 import javax.swing.plaf.ColorUIResource ; 40 41 import org.compiere.util.KeyNamePair; 42 import org.compiere.util.ValueNamePair; 43 44 50 public class CompiereColor implements Serializable 51 { 52 53 public static final String TYPE_FLAT = "F"; 54 55 public static final String TYPE_GRADIENT = "G"; 56 57 public static final String TYPE_LINES = "L"; 58 59 public static final String TYPE_TEXTURE = "T"; 60 61 62 private static ResourceBundle s_res = ResourceBundle.getBundle("org.compiere.plaf.PlafRes"); 63 64 65 public static final String [] TYPE_VALUES = new String [] { 66 TYPE_FLAT, TYPE_GRADIENT, TYPE_LINES, TYPE_TEXTURE 67 }; 68 69 public static final String [] TYPE_NAMES = new String [] { 70 s_res.getString("BackColType_Flat"), 71 s_res.getString("BackColType_Gradient"), 72 s_res.getString("BackColType_Lines"), 73 s_res.getString("BackColType_Texture") 74 }; 75 76 public static final ValueNamePair[] TYPES = new ValueNamePair[] { 77 new ValueNamePair(TYPE_VALUES[0], TYPE_NAMES[0]), 78 new ValueNamePair(TYPE_VALUES[1], TYPE_NAMES[1]), 79 new ValueNamePair(TYPE_VALUES[2], TYPE_NAMES[2]), 80 new ValueNamePair(TYPE_VALUES[3], TYPE_NAMES[3]) 81 }; 82 83 84 public static final int[] GRADIENT_SP_VALUES = new int[] { 85 SwingConstants.NORTH, SwingConstants.NORTH_EAST, 86 SwingConstants.EAST, SwingConstants.SOUTH_EAST, 87 SwingConstants.SOUTH, SwingConstants.SOUTH_WEST, 88 SwingConstants.WEST, SwingConstants.NORTH_WEST 89 }; 90 91 public static final String [] GRADIENT_SP_NAMES = new String [] { 92 "North", "North-East", 93 "East", "South-East", 94 "South", "South-West", 95 "West", "North-West" 96 }; 97 98 public static final KeyNamePair[] GRADIENT_SP = new KeyNamePair[] { 99 new KeyNamePair(GRADIENT_SP_VALUES[0], GRADIENT_SP_NAMES[0]), 100 new KeyNamePair(GRADIENT_SP_VALUES[1], GRADIENT_SP_NAMES[1]), 101 new KeyNamePair(GRADIENT_SP_VALUES[2], GRADIENT_SP_NAMES[2]), 102 new KeyNamePair(GRADIENT_SP_VALUES[3], GRADIENT_SP_NAMES[3]), 103 new KeyNamePair(GRADIENT_SP_VALUES[4], GRADIENT_SP_NAMES[4]), 104 new KeyNamePair(GRADIENT_SP_VALUES[5], GRADIENT_SP_NAMES[5]), 105 new KeyNamePair(GRADIENT_SP_VALUES[6], GRADIENT_SP_NAMES[6]), 106 new KeyNamePair(GRADIENT_SP_VALUES[7], GRADIENT_SP_NAMES[7]) 107 }; 108 109 private static final String EXCEPTION_TEXT = "Arguments cannot be NULL"; 110 111 112 113 117 public static void setBackground (JComponent c) 118 { 119 setBackground (c, CompierePanelUI.getDefaultBackground()); 120 } 122 127 public static void setBackground (JComponent c, CompiereColor cc) 128 { 129 c.putClientProperty(CompierePLAF.BACKGROUND, cc); 130 } 132 137 public static CompiereColor getBackground (JComponent c) 138 { 139 CompiereColor bg = null; 140 try 141 { 142 bg = (CompiereColor)c.getClientProperty(CompierePLAF.BACKGROUND); 143 } 144 catch (Exception e) 145 { 146 System.err.println("CompiereColor - ClientProperty: " + e.getMessage()); 147 } 148 return bg; 149 } 151 155 public static void setBackground (Window win) 156 { 157 setBackground (win, CompierePanelUI.getDefaultBackground()); 158 } 160 165 public static void setBackground (Window win, CompiereColor cc) 166 { 167 if (win instanceof JDialog ) 168 { 169 ((JPanel )((JDialog )win).getContentPane()).putClientProperty(CompierePLAF.BACKGROUND, cc); 170 } 172 else if (win instanceof JFrame ) 173 { 174 ((JPanel )((JFrame )win).getContentPane()).putClientProperty(CompierePLAF.BACKGROUND, cc); 175 } 177 else if (win instanceof JWindow ) 178 { 179 ((JPanel )((JWindow )win).getContentPane()).putClientProperty(CompierePLAF.BACKGROUND, cc); 180 } 182 } 184 189 public static void setDefaultBackground (CompiereColor bg) 190 { 191 CompierePanelUI.setDefaultBackground(bg); 192 } 194 199 public static CompiereColor getDefaultBackground() 200 { 201 return CompierePanelUI.getDefaultBackground(); 202 } 204 209 public static void setSetDefault (boolean setDefault) 210 { 211 CompierePanelUI.setSetDefault(setDefault); 212 } 214 219 public static boolean isSetDefault() 220 { 221 return CompierePanelUI.isSetDefault(); 222 } 224 229 public static CompiereColor parse (String attributes) 230 { 231 CompiereColor cc = new CompiereColor (); 232 try 233 { 234 if (attributes != null && attributes.length() > 0) 235 cc.parseAttributres (attributes); 236 } 237 catch (Exception e) 238 { 239 System.err.println("CompiereColor.parse(" + attributes + ") - " + e.toString()); 240 } 241 return cc; 242 } 244 245 246 249 public CompiereColor() 250 { 251 this (TYPE_GRADIENT); 252 } 254 258 public CompiereColor (String type) 259 { 260 if (type == null) 261 new java.lang.IllegalArgumentException (EXCEPTION_TEXT); 262 if (type.equals(TYPE_FLAT) || type.equals(TYPE_GRADIENT) 263 || type.equals(TYPE_TEXTURE) || type.equals(TYPE_LINES)) 264 { 265 m_type = type; 266 } 267 else 268 new java.lang.IllegalArgumentException ("Invalid Type"); 269 } 271 275 public CompiereColor (Color bg) 276 { 277 this (bg, true); 278 } 280 285 public CompiereColor (Color bg, boolean flat) 286 { 287 if (bg == null) 288 new java.lang.IllegalArgumentException (EXCEPTION_TEXT); 289 m_type = flat ? TYPE_FLAT : TYPE_GRADIENT; 290 m_primaryColor = bg; 291 } 293 300 public CompiereColor (Color upperColor, Color lowerColor, int startPoint, int repeatDistance) 301 { 302 if (upperColor == null || lowerColor == null) 303 new java.lang.IllegalArgumentException (EXCEPTION_TEXT); 304 m_type = TYPE_GRADIENT; 305 m_primaryColor = upperColor; 306 m_secondaryColor = lowerColor; 307 m_startPoint = startPoint; 308 m_repeatDistance = repeatDistance; 309 } 311 317 public CompiereColor (Color upperColor, Color lowerColor) 318 { 319 this (upperColor, lowerColor, SwingConstants.NORTH_WEST, 100); 320 } 322 329 public CompiereColor (URL textureURL, Color taint, float compositeAlpha) 330 { 331 if (textureURL == null || taint == null) 332 new java.lang.IllegalArgumentException (EXCEPTION_TEXT); 333 m_type = TYPE_TEXTURE; 334 m_textureURL = textureURL; 335 m_primaryColor = taint; 336 m_compositeAlpha = compositeAlpha; 337 } 339 346 public CompiereColor (String textureURL, Color taint, float compositeAlpha) 347 { 348 if (textureURL == null || taint == null) 349 new java.lang.IllegalArgumentException (EXCEPTION_TEXT); 350 m_type = TYPE_TEXTURE; 351 setTextureURL(textureURL); 352 m_primaryColor = taint; 353 m_compositeAlpha = compositeAlpha; 354 } 356 364 public CompiereColor (Color lineColor, Color backColor, float lineWidth, int lineDistance) 365 { 366 if (lineColor == null || backColor == null) 367 new java.lang.IllegalArgumentException (EXCEPTION_TEXT); 368 m_type = TYPE_LINES; 369 m_primaryColor = backColor; 370 m_secondaryColor = lineColor; 371 m_lineWidth = lineWidth; 372 m_lineDistance = lineDistance; 373 } 375 379 public CompiereColor (CompiereColor cc) 380 { 381 if (cc == null) 382 return; 383 setColor(cc); 384 } 386 387 388 389 private String m_type = TYPE_GRADIENT; 390 391 392 private Color m_primaryColor = UIManager.getColor("Panel.background"); 393 394 private Color m_secondaryColor = Color.white; 395 396 397 private URL m_textureURL = null; 398 399 private BufferedImage m_image = null; 400 401 private float m_compositeAlpha = 0.7f; 402 403 404 private float m_lineWidth = 1.0f; 405 406 private int m_lineDistance = 5; 407 408 409 private int m_startPoint = SwingConstants.NORTH_WEST; 410 411 private int m_repeatDistance = 100; 412 413 414 private ColorBackground m_back = null; 415 416 417 private boolean m_dirty = true; 418 419 420 421 425 public String getType() 426 { 427 return m_type; 428 } 430 434 public boolean isFlat() 435 { 436 return TYPE_FLAT.equals(getType()); 437 } 439 443 public boolean isGradient() 444 { 445 return TYPE_GRADIENT.equals(getType()); 446 } 448 452 public boolean isLine() 453 { 454 return TYPE_LINES.equals(getType()); 455 } 457 461 public boolean isTexture() 462 { 463 return TYPE_TEXTURE.equals(getType()); 464 } 466 467 468 472 public Color getFlatColor() 473 { 474 return m_primaryColor; 475 } 477 481 public void setFlatColor(Color color) 482 { 483 if (!isFlat() || color == null) 484 return; 485 m_primaryColor = color; 486 m_dirty = true; 487 } 489 490 491 495 public Color getGradientUpperColor() 496 { 497 if (!isGradient()) 498 return null; 499 return m_primaryColor; 500 } 502 506 public void setGradientUpperColor(Color color) 507 { 508 if (!isGradient() || color == null) 509 return; 510 m_primaryColor = color; 511 m_dirty = true; 512 } 514 518 public Color getGradientLowerColor() 519 { 520 if (!isGradient()) 521 return null; 522 return m_secondaryColor; 523 } 525 529 public void setGradientLowerColor(Color color) 530 { 531 if (!isGradient() || color == null) 532 return; 533 m_secondaryColor = color; 534 m_dirty = true; 535 } 537 542 public int getGradientStartPoint () 543 { 544 if (!isGradient()) 545 return 0; 546 return m_startPoint; 547 } 549 554 public void setGradientStartPoint (int startPoint) 555 { 556 if (!isGradient()) 557 return; 558 m_startPoint = startPoint; 559 m_dirty = true; 560 } 562 566 public int getGradientRepeatDistance () 567 { 568 if (!isGradient()) 569 return 0; 570 return m_repeatDistance; 571 } 573 578 public void setGradientRepeatDistance (int repeatDistance) 579 { 580 if (!isGradient()) 581 return; 582 m_repeatDistance = repeatDistance; 583 m_dirty = true; 584 } 586 591 public void setGradientRepeatDistance (String repeatDistanceString) 592 { 593 if (!isGradient()) 594 return; 595 try 596 { 597 setGradientRepeatDistance(Integer.parseInt(repeatDistanceString)); 598 } 599 catch (Exception e) 600 { 601 System.err.println("CompiereColor.setGradientRepeatDistance - Parsing=" 602 + repeatDistanceString + " - " + e.getMessage()); 603 } 604 } 606 607 608 612 public URL getTextureURL() 613 { 614 if (!isTexture()) 615 return null; 616 if (m_textureURL == null) 617 m_textureURL = CompiereColor.class.getResource("Compiere200x100.gif"); 618 return m_textureURL; 619 } 621 625 public BufferedImage getTextureImage() 626 { 627 if (m_image == null) 628 { 629 URL url = getTextureURL(); 630 m_image = CompiereUtils.loadBufferedImage(url, BufferedImage.TYPE_INT_ARGB_PRE); 631 } 632 return m_image; 633 } 635 639 public void setTextureURL(URL url) 640 { 641 if (!isTexture() || url == null) 642 return; 643 m_textureURL = url; 644 m_image = null; 645 m_dirty = true; 646 } 648 652 public void setTextureURL(String urlString) 653 { 654 if (!isTexture() || urlString == null) 655 return; 656 try 657 { 658 setTextureURL (new URL (urlString)); 659 } 660 catch (Exception e) 661 { 662 System.err.println("CompiereColor.setTextureURL - Parsing URL=" 663 + urlString + " - " + e.getMessage()); 664 } 665 } 667 671 public Color getTextureTaintColor() 672 { 673 if (!isTexture()) 674 return null; 675 return m_primaryColor; 676 } 678 682 public void setTextureTaintColor(Color color) 683 { 684 if (!isTexture() || color == null) 685 return; 686 m_primaryColor = color; 687 m_dirty = true; 688 } 690 694 public float getTextureCompositeAlpha() 695 { 696 if (!isTexture()) 697 return 0f; 698 return m_compositeAlpha; 699 } 701 705 public void setTextureCompositeAlpha(float alpha) 706 { 707 if (!isTexture()) 708 return; 709 m_compositeAlpha = alpha; 710 m_dirty = true; 711 } 713 717 public void setTextureCompositeAlpha(String alphaString) 718 { 719 if (!isTexture() || alphaString == null) 720 return; 721 try 722 { 723 setTextureCompositeAlpha(Float.parseFloat(alphaString)); 724 } 725 catch (Exception e) 726 { 727 System.err.println("CompiereColor.setTextureCompositeAlpha - Parsing=" 728 + alphaString + " - " + e.getMessage()); 729 } 730 } 732 733 734 738 public Color getLineColor() 739 { 740 if (!isLine()) 741 return null; 742 return m_secondaryColor; 743 } 745 749 public void setLineColor(Color color) 750 { 751 if (!isLine() || color == null) 752 return; 753 m_secondaryColor = color; 754 m_dirty = true; 755 } 757 761 public Color getLineBackColor() 762 { 763 if (!isLine()) 764 return null; 765 return m_primaryColor; 766 } 768 772 public void setLineBackColor(Color color) 773 { 774 if (!isLine() || color == null) 775 return; 776 m_primaryColor = color; 777 m_dirty = true; 778 } 780 784 public float getLineWidth() 785 { 786 if (!isLine()) 787 return 0f; 788 return m_lineWidth; 789 } 791 795 public void setLineWidth(float width) 796 { 797 if (!isLine()) 798 return; 799 m_lineWidth = width; 800 m_dirty = true; 801 } 803 807 public void setLineWidth(String widthString) 808 { 809 if (!isLine() || widthString == null) 810 return; 811 try 812 { 813 setLineWidth(Float.parseFloat(widthString)); 814 } 815 catch (Exception e) 816 { 817 System.err.println("CompiereColor.setLineWidth - Parsing=" 818 + widthString + " - " + e.getMessage()); 819 } 820 } 822 826 public int getLineDistance() 827 { 828 if (!isLine()) 829 return 0; 830 return m_lineDistance; 831 } 833 837 public void setLineDistance(int distance) 838 { 839 if (!isLine()) 840 return; 841 m_lineDistance = distance; 842 m_dirty = true; 843 } 845 849 public void setLineDistance(String distanceString) 850 { 851 if (!isLine()) 852 return; 853 try 854 { 855 setLineDistance(Integer.parseInt(distanceString)); 856 } 857 catch (Exception e) 858 { 859 System.err.println("CompiereColor.setLineDistance - Parsing=" 860 + distanceString + " - " + e.getMessage()); 861 } 862 } 864 868 protected void setPrimaryColor (Color color) 869 { 870 if (color != null) 871 m_primaryColor = color; 872 } 874 878 public void setColor (CompiereColor cc) 879 { 880 if (cc == null) 881 return; 882 m_type = cc.getType(); 883 if (cc.isFlat()) 885 m_primaryColor = cc.getFlatColor(); 886 else if (cc.isGradient()) 887 { 888 m_primaryColor = cc.getGradientUpperColor(); 889 m_secondaryColor = cc.getGradientLowerColor(); 890 m_startPoint = cc.getGradientStartPoint(); 891 m_repeatDistance = cc.getGradientRepeatDistance(); 892 } 893 else if (cc.isTexture()) 894 { 895 setTextureURL(cc.getTextureURL()); 896 m_primaryColor = cc.getTextureTaintColor(); 897 m_compositeAlpha = cc.getTextureCompositeAlpha(); 898 } 899 else if (cc.isLine()) 900 { 901 m_primaryColor = cc.getLineBackColor(); 902 m_secondaryColor = cc.getLineColor(); 903 m_lineWidth = cc.getLineWidth(); 904 m_lineDistance = cc.getLineDistance(); 905 } 906 else 907 System.err.println("CompiereColor.setColor - Invalid Color"); 908 m_dirty = true; 910 } 912 913 914 919 public void paint (Graphics g, JComponent c) 920 { 921 getColorBackground(c).paint (g, c); 922 } 924 933 public void paintRect (Graphics g, JComponent c, int x, int y, int w, int h) 934 { 935 getColorBackground(c).paintRect (g,c, x,y, w,h); 936 } 938 943 private ColorBackground getColorBackground (JComponent c) 944 { 945 if (m_back == null) 946 { 947 Rectangle bounds = c.getBounds(); 948 Container container = c.getParent(); 949 while (container != null) 950 { 951 bounds = container.getBounds(bounds); 952 container = container.getParent(); 953 } 954 m_back = new ColorBackground (bounds); 955 } 956 return m_back; 957 } 959 960 961 965 public String toString() 966 { 967 StringBuffer sb = new StringBuffer ("CompiereColor["); 968 if (isFlat()) 969 sb.append("Flat") 970 .append(" ").append(CompiereTheme.getColorAsString(getFlatColor())); 971 else if (isGradient()) 972 sb.append("Gradient") 973 .append(" Upper=").append(CompiereTheme.getColorAsString(getGradientUpperColor())) 974 .append(",Lower=").append(CompiereTheme.getColorAsString(getGradientLowerColor())) 975 .append(",Start=").append(getGradientStartPoint()) 976 .append(",RDistance=").append(getGradientRepeatDistance()); 977 else if (isLine()) 978 sb.append("Line") 979 .append(" Color=").append(CompiereTheme.getColorAsString(getLineColor())) 980 .append(",BackColor=").append(CompiereTheme.getColorAsString(getLineBackColor())) 981 .append(",Width=").append(getLineWidth()) 982 .append(",Distance=").append(getLineDistance()); 983 else if (isTexture()) 984 sb.append("Texture") 985 .append(" GraphURL=").append(getTextureURL()) 986 .append(",Taint=").append(CompiereTheme.getColorAsString(getTextureTaintColor())) 987 .append(",Alpha=").append(getTextureCompositeAlpha()); 988 sb.append("]"); 989 return sb.toString(); 990 } 992 996 private void parseAttributres (String str) 997 { 998 if (str.indexOf("[Flat ") != -1) 999 { 1000 m_type = TYPE_FLAT; 1001 m_primaryColor = CompiereTheme.parseColor(str, 1002 new ColorUIResource (m_primaryColor)); 1003 } 1004 else if (str.indexOf("[Gradient ") != -1) 1005 { 1006 m_type = TYPE_GRADIENT; 1007 m_primaryColor = CompiereTheme.parseColor(str.substring(str.indexOf(" Upper=")+7, str.indexOf(",Lower=")), 1008 new ColorUIResource (m_primaryColor)); 1009 m_secondaryColor = CompiereTheme.parseColor(str.substring(str.indexOf(",Lower=")+7, str.indexOf(",Start=")), 1010 new ColorUIResource (m_secondaryColor)); 1011 m_startPoint = Integer.parseInt(str.substring(str.indexOf(",Start=")+7, str.indexOf(",RDistance="))); 1012 setGradientRepeatDistance(str.substring(str.indexOf(",RDistance=")+11, str.lastIndexOf("]"))); 1013 } 1014 else if (str.indexOf("[Line ") != -1) 1015 { 1016 m_type = TYPE_LINES; 1017 m_primaryColor = CompiereTheme.parseColor(str.substring(str.indexOf(" Color=")+7, str.indexOf(",BackColor=")), 1018 new ColorUIResource (m_primaryColor)); 1019 m_secondaryColor = CompiereTheme.parseColor(str.substring(str.indexOf(",BackColor=")+11, str.indexOf(",Width=")), 1020 new ColorUIResource (m_secondaryColor)); 1021 setLineWidth(str.substring(str.indexOf(",Width=")+7, str.indexOf(",Distance="))); 1022 setLineDistance(str.substring(str.indexOf(",Distance=")+10, str.lastIndexOf("]"))); 1023 } 1024 else if (str.indexOf("[Texture ") != -1) 1025 { 1026 m_type = TYPE_TEXTURE; 1027 setTextureURL (str.substring(str.indexOf(" GraphURL=")+10, str.indexOf(",Taint="))); 1028 m_primaryColor = CompiereTheme.parseColor(str.substring(str.indexOf(",Taint=")+7, str.indexOf(",Alpha=")), 1029 new ColorUIResource (m_primaryColor)); 1030 setTextureCompositeAlpha (str.substring(str.indexOf(",Alpha=")+7, str.lastIndexOf("]"))); 1031 } 1032 } 1034 1038 boolean isDirty() 1039 { 1040 return m_dirty; 1041 } 1043 1047 void setDirty (boolean dirty) 1048 { 1049 m_dirty = dirty; 1050 } 1052 1053 1054 1063public class ColorBackground 1064{ 1065 1069 public ColorBackground (Rectangle bounds) 1070 { 1071 createColorBackground (bounds); 1072 fillColorBackground (); 1073 } 1075 private int m_height = 200; 1076 private int m_width = 200; 1077 private BufferedImage m_back; 1078 private int m_colorBlind = ColorBlind.getColorType(); 1079 1080 1084 private void createColorBackground (Rectangle bounds) 1085 { 1086 m_height = Math.max(bounds.y + bounds.height, m_height); 1087 m_width = Math.max(bounds.x + bounds.width, m_width); 1088 m_back = new BufferedImage (m_width, m_height, BufferedImage.TYPE_INT_ARGB_PRE); 1089 } 1091 1092 1095 public void fillColorBackground () 1096 { 1097 Graphics2D g2D = m_back.createGraphics(); 1098 1099 if (isGradient()) 1100 { 1101 Point start = null; 1102 Point end = null; 1103 int r = 1; switch (m_startPoint) 1105 { 1106 case SwingConstants.NORTH_WEST: 1107 start = new Point (0, 0); 1108 if (m_repeatDistance > 0) 1109 end = new Point (m_repeatDistance, m_repeatDistance); 1110 else 1112 end = new Point (m_width/r, m_height/r); 1113 break; 1114 case SwingConstants.WEST: 1115 start = new Point (0, m_height/2); 1116 if (m_repeatDistance > 0) 1117 end = new Point (m_repeatDistance, m_height/2); 1118 else 1120 end = new Point (m_width/r, m_height/2); 1121 break; 1122 case SwingConstants.SOUTH_WEST: 1123 start = new Point (0, m_height); 1124 if (m_repeatDistance > 0) 1125 end = new Point (m_repeatDistance, m_height-m_repeatDistance); 1126 else 1128 end = new Point (m_width/r, m_height-(m_height/r)); 1129 break; 1130 case SwingConstants.SOUTH: 1131 start = new Point (0, m_height); 1132 if (m_repeatDistance > 0) 1133 end = new Point (0, m_height-m_repeatDistance); 1134 else 1136 end = new Point (0, m_height-(m_height/r)); 1137 break; 1138 case SwingConstants.SOUTH_EAST: 1139 start = new Point (m_width, m_height); 1140 if (m_repeatDistance > 0) 1141 end = new Point (m_width-m_repeatDistance, m_height-m_repeatDistance); 1142 else 1144 end = new Point (m_width-(m_width/r), m_height-(m_height/r)); 1145 break; 1146 case SwingConstants.EAST: 1147 start = new Point (m_width, m_height/2); 1148 if (m_repeatDistance > 0) 1149 end = new Point (m_width-m_repeatDistance, m_height/2); 1150 else 1152 end = new Point (m_width-(m_width/r), m_height/2); 1153 break; 1154 case SwingConstants.NORTH_EAST: 1155 start = new Point (m_width, 0); 1156 if (m_repeatDistance > 0) 1157 end = new Point (m_width-m_repeatDistance, m_repeatDistance); 1158 else 1160 end = new Point (m_width-(m_width/r), m_height/r); 1161 break; 1162 default: 1163 case SwingConstants.NORTH: 1164 start = new Point (0, 0); 1165 if (m_repeatDistance > 0) 1166 end = new Point (0, m_repeatDistance); 1167 else 1169 end = new Point (0, m_height/r); 1170 } 1171 GradientPaint paint = new GradientPaint ( 1172 start, 1173 ColorBlind.getDichromatColor(getGradientUpperColor()), 1174 end, 1175 ColorBlind.getDichromatColor(getGradientLowerColor()), 1176 true); g2D.setPaint(paint); 1178 g2D.fillRect(0, 0, m_width, m_height); 1179 } 1180 else if (isTexture()) 1181 { 1182 BufferedImage image = getTextureImage(); 1183 if (image == null) 1184 { 1185 g2D.setPaint(ColorBlind.getDichromatColor(getFlatColor())); 1186 g2D.fillRect(0, 0, m_width, m_height); 1187 } 1188 else 1189 { 1190 Rectangle anchor = new Rectangle (0,0, image.getWidth(), image.getHeight()); 1191 TexturePaint texture = new TexturePaint (image, anchor); 1192 g2D.setPaint(texture); 1193 g2D.fillRect(0, 0, m_width, m_height); 1194 g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getTextureCompositeAlpha())); 1195 g2D.setPaint(ColorBlind.getDichromatColor(getTextureTaintColor())); 1196 g2D.fillRect(0, 0, m_width, m_height); 1197 } 1198 } 1199 else if (isLine()) 1200 { 1201 g2D.setPaint(ColorBlind.getDichromatColor(getLineBackColor())); 1203 g2D.fillRect(0, 0, m_width, m_height); 1204 g2D.setPaint(ColorBlind.getDichromatColor(getLineColor())); 1206 g2D.setStroke(new BasicStroke (getLineWidth())); 1207 for (int y = 0; y < m_height; y += getLineDistance()) 1208 g2D.drawLine(0, y, m_width, y); 1209 } 1210 else { 1212 g2D.setPaint(ColorBlind.getDichromatColor(getFlatColor())); 1213 g2D.fillRect(0, 0, m_width, m_height); 1214 } 1215 setDirty (false); 1216 } 1218 1223 public void paint (Graphics g, JComponent c) 1224 { 1225 Rectangle bounds = c.getBounds(); 1226 check (bounds); 1227 int h = c.getHeight(); 1229 int w = c.getWidth(); 1230 g.drawImage (m_back, 1232 0, 0, w, h, bounds.x, bounds.y, bounds.x+w, bounds.y+h, c); 1237 } 1239 1248 public void paintRect (Graphics g, JComponent c, int x, int y, int w, int h) 1249 { 1250 Rectangle bounds = c.getBounds(); 1251 check (bounds); 1252 g.drawImage (m_back, 1254 x, y, x+w, h+y, x, y, x+w, y+h, c); 1259 } 1261 1265 private void check (Rectangle bounds) 1266 { 1267 if (ColorBlind.getColorType() != m_colorBlind) 1269 { 1270 m_colorBlind = ColorBlind.getColorType(); 1271 setDirty(true); 1272 } 1273 if ((m_height < (bounds.y + bounds.height)) 1275 || (m_width < (bounds.x + bounds.width))) 1276 { 1277 createColorBackground (bounds); 1278 fillColorBackground(); 1279 } 1280 else if (isDirty()) 1281 fillColorBackground(); 1282 } 1284} 1286} | Popular Tags |