--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.g2d.elementclass.button;\r
+\r
+import java.awt.AlphaComposite;\r
+import java.awt.Font;\r
+import java.awt.FontMetrics;\r
+import java.awt.Graphics2D;\r
+import java.awt.geom.AffineTransform;\r
+import java.awt.geom.Line2D;\r
+import java.awt.geom.Rectangle2D;\r
+\r
+\r
+import org.simantics.g2d.element.ElementClass;\r
+import org.simantics.g2d.element.ElementHints;\r
+import org.simantics.g2d.element.ElementUtils;\r
+import org.simantics.g2d.element.IElement;\r
+import org.simantics.g2d.element.SceneGraphNodeKey;\r
+import org.simantics.g2d.element.handler.Clickable;\r
+import org.simantics.g2d.element.handler.SceneGraph;\r
+import org.simantics.g2d.element.handler.Stateful;\r
+import org.simantics.g2d.element.handler.Text;\r
+import org.simantics.g2d.element.handler.Clickable.PressStatus;\r
+import org.simantics.g2d.element.handler.impl.AbstractClickable;\r
+import org.simantics.g2d.element.handler.impl.AbstractTogglable;\r
+import org.simantics.g2d.element.handler.impl.DefaultTransform;\r
+import org.simantics.g2d.element.handler.impl.Resizeable;\r
+import org.simantics.scenegraph.Node;\r
+import org.simantics.scenegraph.g2d.G2DNode;\r
+import org.simantics.scenegraph.g2d.G2DParentNode;\r
+import org.simantics.utils.datastructures.hints.HintListenerAdapter;\r
+import org.simantics.utils.datastructures.hints.IHintObservable;\r
+import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
+\r
+/**\r
+ * @author Toni Kalajainen\r
+ */\r
+public class ButtonClass {\r
+ \r
+\r
+ public static final ElementClass BUTTON_CLASS = \r
+ ElementClass.compile(\r
+ Clickable.INSTANCE,\r
+ Text.INSTANCE,\r
+ Resizeable.UNCONSTRICTED,\r
+ DefaultTransform.INSTANCE,\r
+ ButtonPaint.INSTANCE,\r
+ Stateful.ENABLED_BY_DEFAULT\r
+ );\r
+\r
+ \r
+\r
+ static class ButtonPaint implements SceneGraph {\r
+\r
+ private static final long serialVersionUID = 5484741334876153022L;\r
+\r
+ public static final ButtonPaint INSTANCE = new ButtonPaint();\r
+ \r
+ public static final Key SG_NODE = new SceneGraphNodeKey(Node.class, "SUB_SG_NODE");\r
+ \r
+\r
+ @Override\r
+ public void cleanup(IElement e) {\r
+ Node node = e.removeHint(SG_NODE);\r
+ if (node != null)\r
+ node.remove();\r
+ }\r
+ \r
+ @Override\r
+ public void init(IElement e, G2DParentNode parent) {\r
+ \r
+ ButtonNode node = (ButtonNode) e.getHint(SG_NODE);\r
+ if (node == null) {\r
+ node = parent.addNode(ButtonNode.class);\r
+ e.setHint(SG_NODE, node);\r
+ e.addKeyHintListener(ElementHints.KEY_TEXT, new HintListenerAdapter() {\r
+ \r
+ @Override\r
+ public void hintChanged(IHintObservable sender, Key key, Object oldValue,\r
+ Object newValue) {\r
+ if (sender instanceof IElement) {\r
+ ButtonNode node = (ButtonNode) ((IElement)sender).getHint(SG_NODE);\r
+ node.buttonText = (String)newValue;\r
+ node.repaint();\r
+ }\r
+ \r
+ }\r
+ });\r
+ e.addKeyHintListener(AbstractClickable.PRESS_STATUS_KEY, new HintListenerAdapter() {\r
+ \r
+ @Override\r
+ public void hintChanged(IHintObservable sender, Key key, Object oldValue,\r
+ Object newValue) {\r
+ if (sender instanceof IElement) {\r
+ ButtonNode node = (ButtonNode) ((IElement)sender).getHint(SG_NODE);\r
+ node.status = (PressStatus)newValue;\r
+ node.repaint();\r
+ }\r
+ }\r
+ });\r
+ }\r
+\r
+ Rectangle2D rect = ElementUtils.getElementBounds(e);\r
+ ButtonColorProfile colors = ButtonColorProfile.DEFAULT;\r
+ double height = rect.getHeight();\r
+ boolean enabled = isEnabled(e);\r
+\r
+ // FIXME: context not supported by scenegraph\r
+ PressStatus status = PressStatus.NORMAL;//ElementUtils.getPressStatus(e, ctx);\r
+\r
+ Font font = new Font("Tahoma", 0, (int) height-6);\r
+ Font selFont = new Font("Tahoma", Font.BOLD, (int) height-6);\r
+ Text text = e.getElementClass().getAtMostOneItemOfClass(Text.class);\r
+ String buttonText = null;\r
+ if (text!=null) buttonText = text.getText(e);\r
+ if (buttonText==null) buttonText = "";\r
+ boolean checked = isChecked(e);\r
+\r
+ System.out.println("ButtonClass.init " + e + " " + status + " " + checked);\r
+ node.init(status, rect, enabled, checked, colors, font, selFont, buttonText);\r
+ \r
+// e.addKeyHintListener(AbstractClickable.PRESS_STATUS_KEY, new HintListenerAdapter() {\r
+// \r
+// @Override\r
+// public void hintChanged(IHintObservable sender, Key key, Object oldValue,\r
+// Object newValue) {\r
+// if (sender instanceof IElement) {\r
+// ButtonNode node = (ButtonNode) ((IElement)sender).getHint(SG_NODE);\r
+// node.setPressStatus((PressStatus)newValue);\r
+// node.repaint();\r
+// }\r
+// }\r
+// });\r
+ \r
+ }\r
+ \r
+ public static class ButtonNode extends G2DNode {\r
+ private static final long serialVersionUID = 2291569851866542945L;\r
+ PressStatus status = null;\r
+ Rectangle2D rect = null;\r
+ Boolean enabled = null;\r
+ Boolean checked = null;\r
+ ButtonColorProfile colors = null;\r
+ Font font = null;\r
+ Font selFont = null;\r
+ String buttonText = null;\r
+\r
+ @Override\r
+ public Rectangle2D getBoundsInLocal() {\r
+ return rect;\r
+ }\r
+ \r
+ @SyncField("pressStatus") void setPressStatus(PressStatus pressStatus) { \r
+ this.status = pressStatus; \r
+ }\r
+\r
+ public void init(PressStatus status, Rectangle2D rect, boolean enabled, boolean checked,\r
+ ButtonColorProfile colors, Font font, Font selFont, String buttonText) {\r
+ this.status = status;\r
+ this.rect = rect;\r
+ this.enabled = enabled;\r
+ this.checked = checked;\r
+ this.colors = colors;\r
+ this.font = font;\r
+ this.selFont = selFont;\r
+ this.buttonText = buttonText;\r
+ }\r
+\r
+ @Override\r
+ public void render(Graphics2D g) {\r
+ AffineTransform ot = g.getTransform();\r
+ switch (status) {\r
+ case NORMAL:\r
+ drawNormal(g, rect, enabled, checked, colors, font, selFont, buttonText);\r
+ break;\r
+ case HELD:\r
+ drawHeld(g, rect, enabled, colors, font, selFont, buttonText);\r
+ break;\r
+ case PRESSED:\r
+ drawPressed(g, rect, enabled, colors, font, selFont, buttonText);\r
+ break;\r
+ case HOVER:\r
+ drawHover(g, rect, enabled, colors, font, selFont, buttonText);\r
+ break;\r
+ }\r
+ g.setTransform(ot);\r
+ }\r
+\r
+ protected void drawNormal(Graphics2D g, Rectangle2D rect, boolean enabled, boolean checked, ButtonColorProfile colors, Font font, Font selectedFont, String text)\r
+ {\r
+ if(checked) {\r
+ drawPressed(g, rect, enabled, colors, font, selectedFont, text);\r
+ return;\r
+ }\r
+ g.translate(rect.getX(), rect.getY());\r
+ double width = rect.getWidth();\r
+ double height = rect.getHeight();\r
+\r
+ g.setColor(colors.BACKGROUND);\r
+ g.fill(new Rectangle2D.Double(0, 0, width-1, height-1));\r
+\r
+ g.setColor(colors.BORDER1);\r
+ Line2D line = new Line2D.Double();\r
+ line.setLine(0, 0, width-1, 0); g.draw(line);\r
+ line.setLine(0, 0, 0, height-1); g.draw(line);\r
+\r
+ g.setColor(colors.BORDER2);\r
+ line.setLine(1, height-2, width-2, height-2); g.draw(line);\r
+ line.setLine(width-2, height-2, width-2, 1); g.draw(line);\r
+\r
+ g.setColor(colors.BORDER3);\r
+ line.setLine(0, height-1, width-1, height-1); g.draw(line);\r
+ line.setLine(width-1, height-1, width-1, 0); g.draw(line);\r
+\r
+ if (enabled) {\r
+ g.setColor(colors.TEXT_BLACK);\r
+ FontMetrics fm = g.getFontMetrics(font);\r
+ Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);\r
+ g.clip(clipRect);\r
+ g.setFont(font);\r
+ Rectangle2D stringRect = fm.getStringBounds(text, g);\r
+ float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;\r
+ g.drawString(text, x, (float)height-6);\r
+ } else {\r
+ Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);\r
+ g.clip(clipRect);\r
+ g.setFont(selectedFont);\r
+\r
+ FontMetrics fm = g.getFontMetrics(selectedFont);\r
+ Rectangle2D stringRect = fm.getStringBounds(text, g);\r
+ float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;\r
+\r
+ g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));\r
+ g.setColor(colors.TEXT_WHITE);\r
+ g.drawString(text, x+1, (float)height-6+1);\r
+\r
+ g.setColor(colors.TEXT_BLACK);\r
+ g.drawString(text, x, (float)height-6);\r
+ }\r
+ }\r
+\r
+ protected void drawHeld(Graphics2D g, Rectangle2D rect, boolean enabled, ButtonColorProfile colors, Font font, Font selectedFont, String text)\r
+ {\r
+ g.translate(rect.getX(), rect.getY());\r
+ double width = rect.getWidth();\r
+ double height = rect.getHeight();\r
+\r
+ g.setColor(colors.BACKGROUND);\r
+ g.fill(new Rectangle2D.Double(0, 0, width-1, height-1));\r
+\r
+ Line2D line = new Line2D.Double();\r
+\r
+ g.setColor(colors.BORDER3);\r
+ line.setLine(0, 0, width-2, 0); g.draw(line);\r
+ line.setLine(0, 0, 0, height-2); g.draw(line);\r
+\r
+ g.setColor(colors.BORDER2);\r
+ line.setLine(1, 1, width-3, 1); g.draw(line);\r
+ line.setLine(1, 1, 1, height-3); g.draw(line);\r
+\r
+ g.setColor(colors.BORDER1);\r
+ line.setLine(0, height-1, width-1, height-1); g.draw(line);\r
+ line.setLine(width-1, height-1, width-1, 0); g.draw(line);\r
+\r
+ g.setColor(colors.TEXT_BLACK);\r
+ FontMetrics fm = g.getFontMetrics(font);\r
+ Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);\r
+ g.clip(clipRect);\r
+ g.setFont(font);\r
+ Rectangle2D stringRect = fm.getStringBounds(text, g);\r
+ float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;\r
+ g.drawString(text, x+1, (float)height-6+1);\r
+ }\r
+\r
+\r
+ protected void drawPressed(Graphics2D g, Rectangle2D rect, boolean enabled, ButtonColorProfile colors, Font font, Font selectedFont, String text)\r
+ {\r
+ g.translate(rect.getX(), rect.getY());\r
+ double width = rect.getWidth();\r
+ double height = rect.getHeight();\r
+\r
+ g.setColor(colors.SELECTEDBACKGROUND);\r
+ g.fill(new Rectangle2D.Double(0, 0, width-1, height-1));\r
+\r
+ Line2D line = new Line2D.Double();\r
+\r
+ g.setColor(colors.BORDER3);\r
+ line.setLine(0, 0, width-2, 0); g.draw(line);\r
+ line.setLine(0, 0, 0, height-2); g.draw(line);\r
+\r
+ g.setColor(colors.BORDER2);\r
+ line.setLine(1, 1, width-3, 1); g.draw(line);\r
+ line.setLine(1, 1, 1, height-3); g.draw(line);\r
+\r
+ g.setColor(colors.BORDER1);\r
+ line.setLine(0, height-1, width-1, height-1); g.draw(line);\r
+ line.setLine(width-1, height-1, width-1, 0); g.draw(line);\r
+\r
+ if (enabled) {\r
+ g.setColor(colors.TEXT_BLACK);\r
+\r
+ FontMetrics fm = g.getFontMetrics(font);\r
+ Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);\r
+ g.clip(clipRect);\r
+ g.setFont(font);\r
+ Rectangle2D stringRect = fm.getStringBounds(text, g);\r
+ float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;\r
+ g.drawString(text, x+1, (float)height-6+1);\r
+ } else {\r
+ Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);\r
+ g.clip(clipRect);\r
+ g.setFont(selectedFont);\r
+\r
+ FontMetrics fm = g.getFontMetrics(selectedFont);\r
+ Rectangle2D stringRect = fm.getStringBounds(text, g);\r
+ float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;\r
+\r
+ g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));\r
+ g.setColor(colors.TEXT_WHITE);\r
+ g.drawString(text, x+2, (float)height-6+2);\r
+\r
+ g.setColor(colors.TEXT_BLACK);\r
+ g.drawString(text, x+1, (float)height-6+1);\r
+ }\r
+\r
+ }\r
+\r
+ protected void drawHover(Graphics2D g, Rectangle2D rect, boolean enabled, ButtonColorProfile colors, Font font, Font selectedFont, String text)\r
+ {\r
+ g.translate(rect.getX(), rect.getY());\r
+ double width = rect.getWidth();\r
+ double height = rect.getHeight();\r
+\r
+ g.setColor(colors.HOVERBACKGROUND);\r
+ g.fill(new Rectangle2D.Double(0, 0, width-1, height-1));\r
+\r
+ //g.setStroke(HOVER_STROKE);\r
+\r
+ g.setColor(colors.BORDER1);\r
+ Line2D line = new Line2D.Double();\r
+ line.setLine(0, 0, width-1, 0); g.draw(line);\r
+ line.setLine(0, 0, 0, height-1); g.draw(line);\r
+\r
+ g.setColor(colors.BORDER2);\r
+ line.setLine(1, height-2, width-2, height-2); g.draw(line);\r
+ line.setLine(width-2, height-2, width-2, 1); g.draw(line);\r
+\r
+ g.setColor(colors.BORDER3);\r
+ line.setLine(0, height-1, width-1, height-1); g.draw(line);\r
+ line.setLine(width-1, height-1, width-1, 0); g.draw(line);\r
+\r
+ if (enabled) {\r
+ g.setColor(colors.TEXT_BLACK);\r
+ FontMetrics fm = g.getFontMetrics(font);\r
+ Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);\r
+ g.clip(clipRect);\r
+ g.setFont(font);\r
+ Rectangle2D stringRect = fm.getStringBounds(text, g);\r
+ float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;\r
+ g.drawString(text, x, (float)height-6);\r
+ } else {\r
+ Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);\r
+ g.clip(clipRect);\r
+ g.setFont(selectedFont);\r
+\r
+ FontMetrics fm = g.getFontMetrics(selectedFont);\r
+ Rectangle2D stringRect = fm.getStringBounds(text, g);\r
+ float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;\r
+\r
+ g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));\r
+ g.setColor(colors.TEXT_WHITE);\r
+ g.drawString(text, x+1, (float)height-6+1);\r
+\r
+ g.setColor(colors.TEXT_BLACK);\r
+ g.drawString(text, x, (float)height-6);\r
+ }\r
+ }\r
+ \r
+ }\r
+\r
+ protected ButtonColorProfile getColorProfile(IElement e)\r
+ {\r
+ return ButtonColorProfile.DEFAULT;\r
+ }\r
+\r
+ public boolean isEnabled(IElement e) {\r
+ Stateful enabled = e.getElementClass().getAtMostOneItemOfClass(Stateful.class);\r
+ if (enabled==null) return true;\r
+ return enabled.isEnabled(e);\r
+ }\r
+\r
+ public boolean isChecked(IElement e){\r
+ Boolean b = e.getHint(AbstractTogglable.TOGGLE_KEY);\r
+ if (b == null)\r
+ return false;\r
+ return b;\r
+ \r
+ }\r
+ }\r
+/* \r
+ static class ButtonPaint implements Paint {\r
+\r
+ private static final long serialVersionUID = 7339681670484169461L;\r
+ public static final ButtonPaint INSTANCE = new ButtonPaint();\r
+ @Override\r
+ public void paint(IElement e, ICanvasContext ctx, GraphicsContext elementGC, GraphicsContext controlGC) {\r
+ \r
+// Graphics2D g = elementGC.createClone();\r
+// Rectangle2D rect = elementGC.getBounds();\r
+// ButtonColorProfile colors = ButtonColorProfile.DEFAULT;\r
+// double height = rect.getHeight();\r
+// boolean enabled = isEnabled(e);\r
+// \r
+// PressStatus status = ElementUtils.getPressStatus(e, ctx);\r
+// \r
+// Font font = new Font("Tahoma", 0, (int) height-6);\r
+// Font selFont = new Font("Tahoma", Font.BOLD, (int) height-6); \r
+// Text text = e.getElementClass().getAtMostOneItemOfClass(Text.class); \r
+// String buttonText = null;\r
+// if (text!=null) buttonText = text.getText(e);\r
+// if (buttonText==null) buttonText = "";\r
+// \r
+// switch (status) {\r
+// case NORMAL:\r
+// drawNormal(g, rect, enabled, colors, font, selFont, buttonText);\r
+// break;\r
+// case HELD:\r
+// drawHeld(g, rect, enabled, colors, font, selFont, buttonText);\r
+// break;\r
+// case PRESSED:\r
+// drawPressed(g, rect, enabled, colors, font, selFont, buttonText);\r
+// break;\r
+// case HOVER:\r
+// drawHover(g, rect, enabled, colors, font, selFont, buttonText);\r
+// break;\r
+// }\r
+//\r
+ }\r
+ \r
+ protected ButtonColorProfile getColorProfile(IElement e)\r
+ {\r
+ return ButtonColorProfile.DEFAULT;\r
+ }\r
+ \r
+ protected boolean isToggleButton()\r
+ {\r
+ return false;\r
+ } \r
+ \r
+ public boolean isEnabled(IElement e) {\r
+ Stateful enabled = e.getElementClass().getAtMostOneItemOfClass(Stateful.class);\r
+ if (enabled==null) return true;\r
+ return enabled.isEnabled(e);\r
+ }\r
+ \r
+ protected void drawNormal(Graphics2D g, Rectangle2D rect, boolean enabled, ButtonColorProfile colors, Font font, Font selectedFont, String text)\r
+ { \r
+ g.translate(rect.getX(), rect.getY());\r
+ double width = rect.getWidth();\r
+ double height = rect.getHeight();\r
+ \r
+ g.setColor(colors.BACKGROUND);\r
+ g.fill(new Rectangle2D.Double(0, 0, width-1, height-1));\r
+ \r
+ g.setColor(colors.BORDER1); \r
+ Line2D line = new Line2D.Double();\r
+ line.setLine(0, 0, width-1, 0); g.draw(line);\r
+ line.setLine(0, 0, 0, height-1); g.draw(line);\r
+ \r
+ g.setColor(colors.BORDER2);\r
+ line.setLine(1, height-2, width-2, height-2); g.draw(line);\r
+ line.setLine(width-2, height-2, width-2, 1); g.draw(line);\r
+ \r
+ g.setColor(colors.BORDER3);\r
+ line.setLine(0, height-1, width-1, height-1); g.draw(line);\r
+ line.setLine(width-1, height-1, width-1, 0); g.draw(line);\r
+ \r
+ if (enabled) {\r
+ g.setColor(colors.TEXT_BLACK);\r
+ FontMetrics fm = g.getFontMetrics(font); \r
+ Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);\r
+ g.clip(clipRect); \r
+ g.setFont(font);\r
+ Rectangle2D stringRect = fm.getStringBounds(text, g);\r
+ float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;\r
+ g.drawString(text, x, (float)height-6);\r
+ } else {\r
+ Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);\r
+ g.clip(clipRect);\r
+ g.setFont(selectedFont);\r
+ \r
+ FontMetrics fm = g.getFontMetrics(selectedFont); \r
+ Rectangle2D stringRect = fm.getStringBounds(text, g);\r
+ float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;\r
+ \r
+ g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));\r
+ g.setColor(colors.TEXT_WHITE);\r
+ g.drawString(text, x+1, (float)height-6+1);\r
+ \r
+ g.setColor(colors.TEXT_BLACK);\r
+ g.drawString(text, x, (float)height-6); \r
+ }\r
+ }\r
+ \r
+ protected void drawHeld(Graphics2D g, Rectangle2D rect, boolean enabled, ButtonColorProfile colors, Font font, Font selectedFont, String text)\r
+ {\r
+ g.translate(rect.getX(), rect.getY());\r
+ double width = rect.getWidth();\r
+ double height = rect.getHeight();\r
+ \r
+ g.setColor(colors.BACKGROUND);\r
+ g.fill(new Rectangle2D.Double(0, 0, width-1, height-1));\r
+ \r
+ Line2D line = new Line2D.Double();\r
+ \r
+ g.setColor(colors.BORDER3);\r
+ line.setLine(0, 0, width-2, 0); g.draw(line);\r
+ line.setLine(0, 0, 0, height-2); g.draw(line);\r
+ \r
+ g.setColor(colors.BORDER2);\r
+ line.setLine(1, 1, width-3, 1); g.draw(line);\r
+ line.setLine(1, 1, 1, height-3); g.draw(line);\r
+ \r
+ g.setColor(colors.BORDER1);\r
+ line.setLine(0, height-1, width-1, height-1); g.draw(line);\r
+ line.setLine(width-1, height-1, width-1, 0); g.draw(line);\r
+ \r
+ g.setColor(colors.TEXT_BLACK); \r
+ FontMetrics fm = g.getFontMetrics(font);\r
+ Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);\r
+ g.clip(clipRect);\r
+ g.setFont(font);\r
+ Rectangle2D stringRect = fm.getStringBounds(text, g);\r
+ float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;\r
+ g.drawString(text, x+1, (float)height-6+1);\r
+ }\r
+ \r
+ \r
+ protected void drawPressed(Graphics2D g, Rectangle2D rect, boolean enabled, ButtonColorProfile colors, Font font, Font selectedFont, String text)\r
+ {\r
+ g.translate(rect.getX(), rect.getY());\r
+ double width = rect.getWidth();\r
+ double height = rect.getHeight();\r
+ \r
+ g.setColor(colors.SELECTEDBACKGROUND);\r
+ g.fill(new Rectangle2D.Double(0, 0, width-1, height-1));\r
+ \r
+ Line2D line = new Line2D.Double();\r
+ \r
+ g.setColor(colors.BORDER3);\r
+ line.setLine(0, 0, width-2, 0); g.draw(line);\r
+ line.setLine(0, 0, 0, height-2); g.draw(line); \r
+ \r
+ g.setColor(colors.BORDER2);\r
+ line.setLine(1, 1, width-3, 1); g.draw(line);\r
+ line.setLine(1, 1, 1, height-3); g.draw(line); \r
+ \r
+ g.setColor(colors.BORDER1);\r
+ line.setLine(0, height-1, width-1, height-1); g.draw(line);\r
+ line.setLine(width-1, height-1, width-1, 0); g.draw(line); \r
+\r
+ if (enabled) {\r
+ g.setColor(colors.TEXT_BLACK);\r
+ \r
+ FontMetrics fm = g.getFontMetrics(font);\r
+ Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);\r
+ g.clip(clipRect); \r
+ g.setFont(font);\r
+ Rectangle2D stringRect = fm.getStringBounds(text, g);\r
+ float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;\r
+ g.drawString(text, x+1, (float)height-6+1);\r
+ } else {\r
+ Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);\r
+ g.clip(clipRect);\r
+ g.setFont(selectedFont);\r
+ \r
+ FontMetrics fm = g.getFontMetrics(selectedFont); \r
+ Rectangle2D stringRect = fm.getStringBounds(text, g);\r
+ float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;\r
+ \r
+ g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));\r
+ g.setColor(colors.TEXT_WHITE);\r
+ g.drawString(text, x+2, (float)height-6+2);\r
+ \r
+ g.setColor(colors.TEXT_BLACK);\r
+ g.drawString(text, x+1, (float)height-6+1); \r
+ }\r
+ \r
+ }\r
+ \r
+ protected void drawHover(Graphics2D g, Rectangle2D rect, boolean enabled, ButtonColorProfile colors, Font font, Font selectedFont, String text)\r
+ { \r
+ g.translate(rect.getX(), rect.getY());\r
+ double width = rect.getWidth();\r
+ double height = rect.getHeight();\r
+ \r
+ g.setColor(colors.HOVERBACKGROUND);\r
+ g.fill(new Rectangle2D.Double(0, 0, width-1, height-1));\r
+ \r
+ //g.setStroke(HOVER_STROKE);\r
+ \r
+ g.setColor(colors.BORDER1); \r
+ Line2D line = new Line2D.Double();\r
+ line.setLine(0, 0, width-1, 0); g.draw(line);\r
+ line.setLine(0, 0, 0, height-1); g.draw(line);\r
+ \r
+ g.setColor(colors.BORDER2);\r
+ line.setLine(1, height-2, width-2, height-2); g.draw(line);\r
+ line.setLine(width-2, height-2, width-2, 1); g.draw(line);\r
+ \r
+ g.setColor(colors.BORDER3);\r
+ line.setLine(0, height-1, width-1, height-1); g.draw(line);\r
+ line.setLine(width-1, height-1, width-1, 0); g.draw(line);\r
+ \r
+ if (enabled) {\r
+ g.setColor(colors.TEXT_BLACK);\r
+ FontMetrics fm = g.getFontMetrics(font); \r
+ Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);\r
+ g.clip(clipRect); \r
+ g.setFont(font);\r
+ Rectangle2D stringRect = fm.getStringBounds(text, g);\r
+ float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;\r
+ g.drawString(text, x, (float)height-6);\r
+ } else {\r
+ Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);\r
+ g.clip(clipRect);\r
+ g.setFont(selectedFont);\r
+ \r
+ FontMetrics fm = g.getFontMetrics(selectedFont); \r
+ Rectangle2D stringRect = fm.getStringBounds(text, g);\r
+ float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;\r
+ \r
+ g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));\r
+ g.setColor(colors.TEXT_WHITE);\r
+ g.drawString(text, x+1, (float)height-6+1);\r
+ \r
+ g.setColor(colors.TEXT_BLACK);\r
+ g.drawString(text, x, (float)height-6); \r
+ }\r
+ }\r
+ }\r
+ */\r
+}\r