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