1 Clazz.declarePackage ("javax.swing.colorchooser");
\r
2 Clazz.load (["javax.swing.JPanel", "java.awt.Font", "javax.swing.UIManager"], "javax.swing.colorchooser.DefaultPreviewPanel", ["java.awt.Color", "$.Dimension", "javax.swing.JColorChooser", "$.SwingUtilities", "jssun.swing.SwingUtilities2"], function () {
\r
3 c$ = Clazz.decorateAsClass (function () {
\r
4 this.squareSize = 25;
\r
9 this.sampleText = null;
\r
10 this.swatchWidth = 50;
\r
11 this.oldColor = null;
\r
12 Clazz.instantialize (this, arguments);
\r
13 }, javax.swing.colorchooser, "DefaultPreviewPanel", javax.swing.JPanel);
\r
14 Clazz.prepareFields (c$, function () {
\r
15 this.$font = new java.awt.Font ("Dialog", 0, 12);
\r
16 this.sampleText = javax.swing.UIManager.getString ("ColorChooser.sampleText");
\r
18 Clazz.defineMethod (c$, "getColorChooser",
\r
20 return javax.swing.SwingUtilities.getAncestorOfClass (javax.swing.JColorChooser, this);
\r
22 Clazz.overrideMethod (c$, "getPreferredSize",
\r
24 var host = this.getColorChooser ();
\r
27 }var fm = host.getFontMetrics (this.getFont ());
\r
28 var ascent = fm.getAscent ();
\r
29 var height = fm.getHeight ();
\r
30 var width = jssun.swing.SwingUtilities2.stringWidth (host, fm, this.sampleText);
\r
31 var y = height * 3 + this.textGap * 3;
\r
32 var x = this.squareSize * 3 + this.squareGap * 2 + this.swatchWidth + width + this.textGap * 3;
\r
33 return new java.awt.Dimension (x, y);
\r
35 Clazz.overrideMethod (c$, "paintComponent",
\r
37 if (this.oldColor == null) this.oldColor = this.getForeground ();
\r
38 g.setColor (this.getBackground ());
\r
39 g.fillRect (0, 0, this.getWidth (), this.getHeight ());
\r
40 if (this.getComponentOrientation ().isLeftToRight ()) {
\r
41 var squareWidth = this.paintSquares (g, 0);
\r
42 var textWidth = this.paintText (g, squareWidth);
\r
43 this.paintSwatch (g, squareWidth + textWidth);
\r
45 var swatchWidth = this.paintSwatch (g, 0);
\r
46 var textWidth = this.paintText (g, swatchWidth);
\r
47 this.paintSquares (g, swatchWidth + textWidth);
\r
48 }}, "java.awt.Graphics");
\r
49 Clazz.defineMethod (c$, "paintSwatch",
\r
50 function (g, offsetX) {
\r
51 var swatchX = offsetX;
\r
52 g.setColor (this.oldColor);
\r
53 g.fillRect (swatchX, 0, this.swatchWidth, (this.squareSize) + (Clazz.doubleToInt (this.squareGap / 2)));
\r
54 g.setColor (this.getForeground ());
\r
55 g.fillRect (swatchX, (this.squareSize) + (Clazz.doubleToInt (this.squareGap / 2)), this.swatchWidth, (this.squareSize) + (Clazz.doubleToInt (this.squareGap / 2)));
\r
56 return (swatchX + this.swatchWidth);
\r
57 }, "java.awt.Graphics,~N");
\r
58 Clazz.defineMethod (c$, "paintText",
\r
59 function (g, offsetX) {
\r
60 g.setFont (this.getFont ());
\r
61 var host = this.getColorChooser ();
\r
64 }var fm = jssun.swing.SwingUtilities2.getFontMetrics (host, g);
\r
65 var ascent = fm.getAscent ();
\r
66 var height = fm.getHeight ();
\r
67 var width = jssun.swing.SwingUtilities2.stringWidth (host, fm, this.sampleText);
\r
68 var textXOffset = offsetX + this.textGap;
\r
69 var color = this.getForeground ();
\r
71 jssun.swing.SwingUtilities2.drawString (host, g, this.sampleText, textXOffset + (Clazz.doubleToInt (this.textGap / 2)), ascent + 2);
\r
72 g.fillRect (textXOffset, (height) + this.textGap, width + (this.textGap), height + 2);
\r
73 g.setColor (java.awt.Color.black);
\r
74 jssun.swing.SwingUtilities2.drawString (host, g, this.sampleText, textXOffset + (Clazz.doubleToInt (this.textGap / 2)), height + ascent + this.textGap + 2);
\r
75 g.setColor (java.awt.Color.white);
\r
76 g.fillRect (textXOffset, (height + this.textGap) * 2, width + (this.textGap), height + 2);
\r
78 jssun.swing.SwingUtilities2.drawString (host, g, this.sampleText, textXOffset + (Clazz.doubleToInt (this.textGap / 2)), ((height + this.textGap) * 2) + ascent + 2);
\r
79 return width + this.textGap * 3;
\r
80 }, "java.awt.Graphics,~N");
\r
81 Clazz.defineMethod (c$, "paintSquares",
\r
82 function (g, offsetX) {
\r
83 var squareXOffset = offsetX;
\r
84 var color = this.getForeground ();
\r
85 g.setColor (java.awt.Color.white);
\r
86 g.fillRect (squareXOffset, 0, this.squareSize, this.squareSize);
\r
88 g.fillRect (squareXOffset + this.innerGap, this.innerGap, this.squareSize - (this.innerGap * 2), this.squareSize - (this.innerGap * 2));
\r
89 g.setColor (java.awt.Color.white);
\r
90 g.fillRect (squareXOffset + this.innerGap * 2, this.innerGap * 2, this.squareSize - (this.innerGap * 4), this.squareSize - (this.innerGap * 4));
\r
92 g.fillRect (squareXOffset, this.squareSize + this.squareGap, this.squareSize, this.squareSize);
\r
93 g.translate (this.squareSize + this.squareGap, 0);
\r
94 g.setColor (java.awt.Color.black);
\r
95 g.fillRect (squareXOffset, 0, this.squareSize, this.squareSize);
\r
97 g.fillRect (squareXOffset + this.innerGap, this.innerGap, this.squareSize - (this.innerGap * 2), this.squareSize - (this.innerGap * 2));
\r
98 g.setColor (java.awt.Color.white);
\r
99 g.fillRect (squareXOffset + this.innerGap * 2, this.innerGap * 2, this.squareSize - (this.innerGap * 4), this.squareSize - (this.innerGap * 4));
\r
100 g.translate (-(this.squareSize + this.squareGap), 0);
\r
101 g.translate (this.squareSize + this.squareGap, this.squareSize + this.squareGap);
\r
102 g.setColor (java.awt.Color.white);
\r
103 g.fillRect (squareXOffset, 0, this.squareSize, this.squareSize);
\r
104 g.setColor (color);
\r
105 g.fillRect (squareXOffset + this.innerGap, this.innerGap, this.squareSize - (this.innerGap * 2), this.squareSize - (this.innerGap * 2));
\r
106 g.translate (-(this.squareSize + this.squareGap), -(this.squareSize + this.squareGap));
\r
107 g.translate ((this.squareSize + this.squareGap) * 2, 0);
\r
108 g.setColor (java.awt.Color.white);
\r
109 g.fillRect (squareXOffset, 0, this.squareSize, this.squareSize);
\r
110 g.setColor (color);
\r
111 g.fillRect (squareXOffset + this.innerGap, this.innerGap, this.squareSize - (this.innerGap * 2), this.squareSize - (this.innerGap * 2));
\r
112 g.setColor (java.awt.Color.black);
\r
113 g.fillRect (squareXOffset + this.innerGap * 2, this.innerGap * 2, this.squareSize - (this.innerGap * 4), this.squareSize - (this.innerGap * 4));
\r
114 g.translate (-((this.squareSize + this.squareGap) * 2), 0);
\r
115 g.translate ((this.squareSize + this.squareGap) * 2, (this.squareSize + this.squareGap));
\r
116 g.setColor (java.awt.Color.black);
\r
117 g.fillRect (squareXOffset, 0, this.squareSize, this.squareSize);
\r
118 g.setColor (color);
\r
119 g.fillRect (squareXOffset + this.innerGap, this.innerGap, this.squareSize - (this.innerGap * 2), this.squareSize - (this.innerGap * 2));
\r
120 g.translate (-((this.squareSize + this.squareGap) * 2), -(this.squareSize + this.squareGap));
\r
121 return (this.squareSize * 3 + this.squareGap * 2);
\r
122 }, "java.awt.Graphics,~N");
\r