X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=site%2Fj2s%2Fjavax%2Fswing%2Fcolorchooser%2FDefaultPreviewPanel.js;fp=site%2Fj2s%2Fjavax%2Fswing%2Fcolorchooser%2FDefaultPreviewPanel.js;h=333bf9bed36321471143465baf5c2d84cbf5ac1c;hb=4231d40261fef32ce4570a6bbad0d35df44e8baf;hp=0000000000000000000000000000000000000000;hpb=c07eb2c5794833bd0241000d6844d783fe10cb82;p=jalview.git diff --git a/site/j2s/javax/swing/colorchooser/DefaultPreviewPanel.js b/site/j2s/javax/swing/colorchooser/DefaultPreviewPanel.js new file mode 100644 index 0000000..333bf9b --- /dev/null +++ b/site/j2s/javax/swing/colorchooser/DefaultPreviewPanel.js @@ -0,0 +1,123 @@ +Clazz.declarePackage ("javax.swing.colorchooser"); +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 () { +c$ = Clazz.decorateAsClass (function () { +this.squareSize = 25; +this.squareGap = 5; +this.innerGap = 5; +this.textGap = 5; +this.$font = null; +this.sampleText = null; +this.swatchWidth = 50; +this.oldColor = null; +Clazz.instantialize (this, arguments); +}, javax.swing.colorchooser, "DefaultPreviewPanel", javax.swing.JPanel); +Clazz.prepareFields (c$, function () { +this.$font = new java.awt.Font ("Dialog", 0, 12); +this.sampleText = javax.swing.UIManager.getString ("ColorChooser.sampleText"); +}); +Clazz.defineMethod (c$, "getColorChooser", + function () { +return javax.swing.SwingUtilities.getAncestorOfClass (javax.swing.JColorChooser, this); +}); +Clazz.overrideMethod (c$, "getPreferredSize", +function () { +var host = this.getColorChooser (); +if (host == null) { +host = this; +}var fm = host.getFontMetrics (this.getFont ()); +var ascent = fm.getAscent (); +var height = fm.getHeight (); +var width = jssun.swing.SwingUtilities2.stringWidth (host, fm, this.sampleText); +var y = height * 3 + this.textGap * 3; +var x = this.squareSize * 3 + this.squareGap * 2 + this.swatchWidth + width + this.textGap * 3; +return new java.awt.Dimension (x, y); +}); +Clazz.overrideMethod (c$, "paintComponent", +function (g) { +if (this.oldColor == null) this.oldColor = this.getForeground (); +g.setColor (this.getBackground ()); +g.fillRect (0, 0, this.getWidth (), this.getHeight ()); +if (this.getComponentOrientation ().isLeftToRight ()) { +var squareWidth = this.paintSquares (g, 0); +var textWidth = this.paintText (g, squareWidth); +this.paintSwatch (g, squareWidth + textWidth); +} else { +var swatchWidth = this.paintSwatch (g, 0); +var textWidth = this.paintText (g, swatchWidth); +this.paintSquares (g, swatchWidth + textWidth); +}}, "java.awt.Graphics"); +Clazz.defineMethod (c$, "paintSwatch", + function (g, offsetX) { +var swatchX = offsetX; +g.setColor (this.oldColor); +g.fillRect (swatchX, 0, this.swatchWidth, (this.squareSize) + (Clazz.doubleToInt (this.squareGap / 2))); +g.setColor (this.getForeground ()); +g.fillRect (swatchX, (this.squareSize) + (Clazz.doubleToInt (this.squareGap / 2)), this.swatchWidth, (this.squareSize) + (Clazz.doubleToInt (this.squareGap / 2))); +return (swatchX + this.swatchWidth); +}, "java.awt.Graphics,~N"); +Clazz.defineMethod (c$, "paintText", + function (g, offsetX) { +g.setFont (this.getFont ()); +var host = this.getColorChooser (); +if (host == null) { +host = this; +}var fm = jssun.swing.SwingUtilities2.getFontMetrics (host, g); +var ascent = fm.getAscent (); +var height = fm.getHeight (); +var width = jssun.swing.SwingUtilities2.stringWidth (host, fm, this.sampleText); +var textXOffset = offsetX + this.textGap; +var color = this.getForeground (); +g.setColor (color); +jssun.swing.SwingUtilities2.drawString (host, g, this.sampleText, textXOffset + (Clazz.doubleToInt (this.textGap / 2)), ascent + 2); +g.fillRect (textXOffset, (height) + this.textGap, width + (this.textGap), height + 2); +g.setColor (java.awt.Color.black); +jssun.swing.SwingUtilities2.drawString (host, g, this.sampleText, textXOffset + (Clazz.doubleToInt (this.textGap / 2)), height + ascent + this.textGap + 2); +g.setColor (java.awt.Color.white); +g.fillRect (textXOffset, (height + this.textGap) * 2, width + (this.textGap), height + 2); +g.setColor (color); +jssun.swing.SwingUtilities2.drawString (host, g, this.sampleText, textXOffset + (Clazz.doubleToInt (this.textGap / 2)), ((height + this.textGap) * 2) + ascent + 2); +return width + this.textGap * 3; +}, "java.awt.Graphics,~N"); +Clazz.defineMethod (c$, "paintSquares", + function (g, offsetX) { +var squareXOffset = offsetX; +var color = this.getForeground (); +g.setColor (java.awt.Color.white); +g.fillRect (squareXOffset, 0, this.squareSize, this.squareSize); +g.setColor (color); +g.fillRect (squareXOffset + this.innerGap, this.innerGap, this.squareSize - (this.innerGap * 2), this.squareSize - (this.innerGap * 2)); +g.setColor (java.awt.Color.white); +g.fillRect (squareXOffset + this.innerGap * 2, this.innerGap * 2, this.squareSize - (this.innerGap * 4), this.squareSize - (this.innerGap * 4)); +g.setColor (color); +g.fillRect (squareXOffset, this.squareSize + this.squareGap, this.squareSize, this.squareSize); +g.translate (this.squareSize + this.squareGap, 0); +g.setColor (java.awt.Color.black); +g.fillRect (squareXOffset, 0, this.squareSize, this.squareSize); +g.setColor (color); +g.fillRect (squareXOffset + this.innerGap, this.innerGap, this.squareSize - (this.innerGap * 2), this.squareSize - (this.innerGap * 2)); +g.setColor (java.awt.Color.white); +g.fillRect (squareXOffset + this.innerGap * 2, this.innerGap * 2, this.squareSize - (this.innerGap * 4), this.squareSize - (this.innerGap * 4)); +g.translate (-(this.squareSize + this.squareGap), 0); +g.translate (this.squareSize + this.squareGap, this.squareSize + this.squareGap); +g.setColor (java.awt.Color.white); +g.fillRect (squareXOffset, 0, this.squareSize, this.squareSize); +g.setColor (color); +g.fillRect (squareXOffset + this.innerGap, this.innerGap, this.squareSize - (this.innerGap * 2), this.squareSize - (this.innerGap * 2)); +g.translate (-(this.squareSize + this.squareGap), -(this.squareSize + this.squareGap)); +g.translate ((this.squareSize + this.squareGap) * 2, 0); +g.setColor (java.awt.Color.white); +g.fillRect (squareXOffset, 0, this.squareSize, this.squareSize); +g.setColor (color); +g.fillRect (squareXOffset + this.innerGap, this.innerGap, this.squareSize - (this.innerGap * 2), this.squareSize - (this.innerGap * 2)); +g.setColor (java.awt.Color.black); +g.fillRect (squareXOffset + this.innerGap * 2, this.innerGap * 2, this.squareSize - (this.innerGap * 4), this.squareSize - (this.innerGap * 4)); +g.translate (-((this.squareSize + this.squareGap) * 2), 0); +g.translate ((this.squareSize + this.squareGap) * 2, (this.squareSize + this.squareGap)); +g.setColor (java.awt.Color.black); +g.fillRect (squareXOffset, 0, this.squareSize, this.squareSize); +g.setColor (color); +g.fillRect (squareXOffset + this.innerGap, this.innerGap, this.squareSize - (this.innerGap * 2), this.squareSize - (this.innerGap * 2)); +g.translate (-((this.squareSize + this.squareGap) * 2), -(this.squareSize + this.squareGap)); +return (this.squareSize * 3 + this.squareGap * 2); +}, "java.awt.Graphics,~N"); +});