1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.g2d.elementclass.button;
\r
14 import java.awt.AlphaComposite;
\r
15 import java.awt.Font;
\r
16 import java.awt.FontMetrics;
\r
17 import java.awt.Graphics2D;
\r
18 import java.awt.geom.AffineTransform;
\r
19 import java.awt.geom.Line2D;
\r
20 import java.awt.geom.Rectangle2D;
\r
23 import org.simantics.g2d.element.ElementClass;
\r
24 import org.simantics.g2d.element.ElementHints;
\r
25 import org.simantics.g2d.element.ElementUtils;
\r
26 import org.simantics.g2d.element.IElement;
\r
27 import org.simantics.g2d.element.SceneGraphNodeKey;
\r
28 import org.simantics.g2d.element.handler.Clickable;
\r
29 import org.simantics.g2d.element.handler.SceneGraph;
\r
30 import org.simantics.g2d.element.handler.Stateful;
\r
31 import org.simantics.g2d.element.handler.Text;
\r
32 import org.simantics.g2d.element.handler.Clickable.PressStatus;
\r
33 import org.simantics.g2d.element.handler.impl.AbstractClickable;
\r
34 import org.simantics.g2d.element.handler.impl.AbstractTogglable;
\r
35 import org.simantics.g2d.element.handler.impl.DefaultTransform;
\r
36 import org.simantics.g2d.element.handler.impl.Resizeable;
\r
37 import org.simantics.scenegraph.Node;
\r
38 import org.simantics.scenegraph.g2d.G2DNode;
\r
39 import org.simantics.scenegraph.g2d.G2DParentNode;
\r
40 import org.simantics.utils.datastructures.hints.HintListenerAdapter;
\r
41 import org.simantics.utils.datastructures.hints.IHintObservable;
\r
42 import org.simantics.utils.datastructures.hints.IHintContext.Key;
\r
45 * @author Toni Kalajainen
\r
47 public class ButtonClass {
\r
50 public static final ElementClass BUTTON_CLASS =
\r
51 ElementClass.compile(
\r
54 Resizeable.UNCONSTRICTED,
\r
55 DefaultTransform.INSTANCE,
\r
56 ButtonPaint.INSTANCE,
\r
57 Stateful.ENABLED_BY_DEFAULT
\r
62 static class ButtonPaint implements SceneGraph {
\r
64 private static final long serialVersionUID = 5484741334876153022L;
\r
66 public static final ButtonPaint INSTANCE = new ButtonPaint();
\r
68 public static final Key SG_NODE = new SceneGraphNodeKey(Node.class, "SUB_SG_NODE");
\r
72 public void cleanup(IElement e) {
\r
73 Node node = e.removeHint(SG_NODE);
\r
79 public void init(IElement e, G2DParentNode parent) {
\r
81 ButtonNode node = (ButtonNode) e.getHint(SG_NODE);
\r
83 node = parent.addNode(ButtonNode.class);
\r
84 e.setHint(SG_NODE, node);
\r
85 e.addKeyHintListener(ElementHints.KEY_TEXT, new HintListenerAdapter() {
\r
88 public void hintChanged(IHintObservable sender, Key key, Object oldValue,
\r
90 if (sender instanceof IElement) {
\r
91 ButtonNode node = (ButtonNode) ((IElement)sender).getHint(SG_NODE);
\r
92 node.buttonText = (String)newValue;
\r
98 e.addKeyHintListener(AbstractClickable.PRESS_STATUS_KEY, new HintListenerAdapter() {
\r
101 public void hintChanged(IHintObservable sender, Key key, Object oldValue,
\r
103 if (sender instanceof IElement) {
\r
104 ButtonNode node = (ButtonNode) ((IElement)sender).getHint(SG_NODE);
\r
105 node.status = (PressStatus)newValue;
\r
112 Rectangle2D rect = ElementUtils.getElementBounds(e);
\r
113 ButtonColorProfile colors = ButtonColorProfile.DEFAULT;
\r
114 double height = rect.getHeight();
\r
115 boolean enabled = isEnabled(e);
\r
117 // FIXME: context not supported by scenegraph
\r
118 PressStatus status = PressStatus.NORMAL;//ElementUtils.getPressStatus(e, ctx);
\r
120 Font font = new Font("Tahoma", 0, (int) height-6);
\r
121 Font selFont = new Font("Tahoma", Font.BOLD, (int) height-6);
\r
122 Text text = e.getElementClass().getAtMostOneItemOfClass(Text.class);
\r
123 String buttonText = null;
\r
124 if (text!=null) buttonText = text.getText(e);
\r
125 if (buttonText==null) buttonText = "";
\r
126 boolean checked = isChecked(e);
\r
128 System.out.println("ButtonClass.init " + e + " " + status + " " + checked);
\r
129 node.init(status, rect, enabled, checked, colors, font, selFont, buttonText);
\r
131 // e.addKeyHintListener(AbstractClickable.PRESS_STATUS_KEY, new HintListenerAdapter() {
\r
134 // public void hintChanged(IHintObservable sender, Key key, Object oldValue,
\r
135 // Object newValue) {
\r
136 // if (sender instanceof IElement) {
\r
137 // ButtonNode node = (ButtonNode) ((IElement)sender).getHint(SG_NODE);
\r
138 // node.setPressStatus((PressStatus)newValue);
\r
146 public static class ButtonNode extends G2DNode {
\r
147 private static final long serialVersionUID = 2291569851866542945L;
\r
148 PressStatus status = null;
\r
149 Rectangle2D rect = null;
\r
150 Boolean enabled = null;
\r
151 Boolean checked = null;
\r
152 ButtonColorProfile colors = null;
\r
154 Font selFont = null;
\r
155 String buttonText = null;
\r
158 public Rectangle2D getBoundsInLocal() {
\r
162 @SyncField("pressStatus") void setPressStatus(PressStatus pressStatus) {
\r
163 this.status = pressStatus;
\r
166 public void init(PressStatus status, Rectangle2D rect, boolean enabled, boolean checked,
\r
167 ButtonColorProfile colors, Font font, Font selFont, String buttonText) {
\r
168 this.status = status;
\r
170 this.enabled = enabled;
\r
171 this.checked = checked;
\r
172 this.colors = colors;
\r
174 this.selFont = selFont;
\r
175 this.buttonText = buttonText;
\r
179 public void render(Graphics2D g) {
\r
180 AffineTransform ot = g.getTransform();
\r
183 drawNormal(g, rect, enabled, checked, colors, font, selFont, buttonText);
\r
186 drawHeld(g, rect, enabled, colors, font, selFont, buttonText);
\r
189 drawPressed(g, rect, enabled, colors, font, selFont, buttonText);
\r
192 drawHover(g, rect, enabled, colors, font, selFont, buttonText);
\r
195 g.setTransform(ot);
\r
198 protected void drawNormal(Graphics2D g, Rectangle2D rect, boolean enabled, boolean checked, ButtonColorProfile colors, Font font, Font selectedFont, String text)
\r
201 drawPressed(g, rect, enabled, colors, font, selectedFont, text);
\r
204 g.translate(rect.getX(), rect.getY());
\r
205 double width = rect.getWidth();
\r
206 double height = rect.getHeight();
\r
208 g.setColor(colors.BACKGROUND);
\r
209 g.fill(new Rectangle2D.Double(0, 0, width-1, height-1));
\r
211 g.setColor(colors.BORDER1);
\r
212 Line2D line = new Line2D.Double();
\r
213 line.setLine(0, 0, width-1, 0); g.draw(line);
\r
214 line.setLine(0, 0, 0, height-1); g.draw(line);
\r
216 g.setColor(colors.BORDER2);
\r
217 line.setLine(1, height-2, width-2, height-2); g.draw(line);
\r
218 line.setLine(width-2, height-2, width-2, 1); g.draw(line);
\r
220 g.setColor(colors.BORDER3);
\r
221 line.setLine(0, height-1, width-1, height-1); g.draw(line);
\r
222 line.setLine(width-1, height-1, width-1, 0); g.draw(line);
\r
225 g.setColor(colors.TEXT_BLACK);
\r
226 FontMetrics fm = g.getFontMetrics(font);
\r
227 Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);
\r
230 Rectangle2D stringRect = fm.getStringBounds(text, g);
\r
231 float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;
\r
232 g.drawString(text, x, (float)height-6);
\r
234 Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);
\r
236 g.setFont(selectedFont);
\r
238 FontMetrics fm = g.getFontMetrics(selectedFont);
\r
239 Rectangle2D stringRect = fm.getStringBounds(text, g);
\r
240 float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;
\r
242 g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
\r
243 g.setColor(colors.TEXT_WHITE);
\r
244 g.drawString(text, x+1, (float)height-6+1);
\r
246 g.setColor(colors.TEXT_BLACK);
\r
247 g.drawString(text, x, (float)height-6);
\r
251 protected void drawHeld(Graphics2D g, Rectangle2D rect, boolean enabled, ButtonColorProfile colors, Font font, Font selectedFont, String text)
\r
253 g.translate(rect.getX(), rect.getY());
\r
254 double width = rect.getWidth();
\r
255 double height = rect.getHeight();
\r
257 g.setColor(colors.BACKGROUND);
\r
258 g.fill(new Rectangle2D.Double(0, 0, width-1, height-1));
\r
260 Line2D line = new Line2D.Double();
\r
262 g.setColor(colors.BORDER3);
\r
263 line.setLine(0, 0, width-2, 0); g.draw(line);
\r
264 line.setLine(0, 0, 0, height-2); g.draw(line);
\r
266 g.setColor(colors.BORDER2);
\r
267 line.setLine(1, 1, width-3, 1); g.draw(line);
\r
268 line.setLine(1, 1, 1, height-3); g.draw(line);
\r
270 g.setColor(colors.BORDER1);
\r
271 line.setLine(0, height-1, width-1, height-1); g.draw(line);
\r
272 line.setLine(width-1, height-1, width-1, 0); g.draw(line);
\r
274 g.setColor(colors.TEXT_BLACK);
\r
275 FontMetrics fm = g.getFontMetrics(font);
\r
276 Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);
\r
279 Rectangle2D stringRect = fm.getStringBounds(text, g);
\r
280 float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;
\r
281 g.drawString(text, x+1, (float)height-6+1);
\r
285 protected void drawPressed(Graphics2D g, Rectangle2D rect, boolean enabled, ButtonColorProfile colors, Font font, Font selectedFont, String text)
\r
287 g.translate(rect.getX(), rect.getY());
\r
288 double width = rect.getWidth();
\r
289 double height = rect.getHeight();
\r
291 g.setColor(colors.SELECTEDBACKGROUND);
\r
292 g.fill(new Rectangle2D.Double(0, 0, width-1, height-1));
\r
294 Line2D line = new Line2D.Double();
\r
296 g.setColor(colors.BORDER3);
\r
297 line.setLine(0, 0, width-2, 0); g.draw(line);
\r
298 line.setLine(0, 0, 0, height-2); g.draw(line);
\r
300 g.setColor(colors.BORDER2);
\r
301 line.setLine(1, 1, width-3, 1); g.draw(line);
\r
302 line.setLine(1, 1, 1, height-3); g.draw(line);
\r
304 g.setColor(colors.BORDER1);
\r
305 line.setLine(0, height-1, width-1, height-1); g.draw(line);
\r
306 line.setLine(width-1, height-1, width-1, 0); g.draw(line);
\r
309 g.setColor(colors.TEXT_BLACK);
\r
311 FontMetrics fm = g.getFontMetrics(font);
\r
312 Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);
\r
315 Rectangle2D stringRect = fm.getStringBounds(text, g);
\r
316 float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;
\r
317 g.drawString(text, x+1, (float)height-6+1);
\r
319 Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);
\r
321 g.setFont(selectedFont);
\r
323 FontMetrics fm = g.getFontMetrics(selectedFont);
\r
324 Rectangle2D stringRect = fm.getStringBounds(text, g);
\r
325 float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;
\r
327 g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
\r
328 g.setColor(colors.TEXT_WHITE);
\r
329 g.drawString(text, x+2, (float)height-6+2);
\r
331 g.setColor(colors.TEXT_BLACK);
\r
332 g.drawString(text, x+1, (float)height-6+1);
\r
337 protected void drawHover(Graphics2D g, Rectangle2D rect, boolean enabled, ButtonColorProfile colors, Font font, Font selectedFont, String text)
\r
339 g.translate(rect.getX(), rect.getY());
\r
340 double width = rect.getWidth();
\r
341 double height = rect.getHeight();
\r
343 g.setColor(colors.HOVERBACKGROUND);
\r
344 g.fill(new Rectangle2D.Double(0, 0, width-1, height-1));
\r
346 //g.setStroke(HOVER_STROKE);
\r
348 g.setColor(colors.BORDER1);
\r
349 Line2D line = new Line2D.Double();
\r
350 line.setLine(0, 0, width-1, 0); g.draw(line);
\r
351 line.setLine(0, 0, 0, height-1); g.draw(line);
\r
353 g.setColor(colors.BORDER2);
\r
354 line.setLine(1, height-2, width-2, height-2); g.draw(line);
\r
355 line.setLine(width-2, height-2, width-2, 1); g.draw(line);
\r
357 g.setColor(colors.BORDER3);
\r
358 line.setLine(0, height-1, width-1, height-1); g.draw(line);
\r
359 line.setLine(width-1, height-1, width-1, 0); g.draw(line);
\r
362 g.setColor(colors.TEXT_BLACK);
\r
363 FontMetrics fm = g.getFontMetrics(font);
\r
364 Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);
\r
367 Rectangle2D stringRect = fm.getStringBounds(text, g);
\r
368 float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;
\r
369 g.drawString(text, x, (float)height-6);
\r
371 Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);
\r
373 g.setFont(selectedFont);
\r
375 FontMetrics fm = g.getFontMetrics(selectedFont);
\r
376 Rectangle2D stringRect = fm.getStringBounds(text, g);
\r
377 float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;
\r
379 g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
\r
380 g.setColor(colors.TEXT_WHITE);
\r
381 g.drawString(text, x+1, (float)height-6+1);
\r
383 g.setColor(colors.TEXT_BLACK);
\r
384 g.drawString(text, x, (float)height-6);
\r
390 protected ButtonColorProfile getColorProfile(IElement e)
\r
392 return ButtonColorProfile.DEFAULT;
\r
395 public boolean isEnabled(IElement e) {
\r
396 Stateful enabled = e.getElementClass().getAtMostOneItemOfClass(Stateful.class);
\r
397 if (enabled==null) return true;
\r
398 return enabled.isEnabled(e);
\r
401 public boolean isChecked(IElement e){
\r
402 Boolean b = e.getHint(AbstractTogglable.TOGGLE_KEY);
\r
410 static class ButtonPaint implements Paint {
\r
412 private static final long serialVersionUID = 7339681670484169461L;
\r
413 public static final ButtonPaint INSTANCE = new ButtonPaint();
\r
415 public void paint(IElement e, ICanvasContext ctx, GraphicsContext elementGC, GraphicsContext controlGC) {
\r
417 // Graphics2D g = elementGC.createClone();
\r
418 // Rectangle2D rect = elementGC.getBounds();
\r
419 // ButtonColorProfile colors = ButtonColorProfile.DEFAULT;
\r
420 // double height = rect.getHeight();
\r
421 // boolean enabled = isEnabled(e);
\r
423 // PressStatus status = ElementUtils.getPressStatus(e, ctx);
\r
425 // Font font = new Font("Tahoma", 0, (int) height-6);
\r
426 // Font selFont = new Font("Tahoma", Font.BOLD, (int) height-6);
\r
427 // Text text = e.getElementClass().getAtMostOneItemOfClass(Text.class);
\r
428 // String buttonText = null;
\r
429 // if (text!=null) buttonText = text.getText(e);
\r
430 // if (buttonText==null) buttonText = "";
\r
432 // switch (status) {
\r
434 // drawNormal(g, rect, enabled, colors, font, selFont, buttonText);
\r
437 // drawHeld(g, rect, enabled, colors, font, selFont, buttonText);
\r
440 // drawPressed(g, rect, enabled, colors, font, selFont, buttonText);
\r
443 // drawHover(g, rect, enabled, colors, font, selFont, buttonText);
\r
449 protected ButtonColorProfile getColorProfile(IElement e)
\r
451 return ButtonColorProfile.DEFAULT;
\r
454 protected boolean isToggleButton()
\r
459 public boolean isEnabled(IElement e) {
\r
460 Stateful enabled = e.getElementClass().getAtMostOneItemOfClass(Stateful.class);
\r
461 if (enabled==null) return true;
\r
462 return enabled.isEnabled(e);
\r
465 protected void drawNormal(Graphics2D g, Rectangle2D rect, boolean enabled, ButtonColorProfile colors, Font font, Font selectedFont, String text)
\r
467 g.translate(rect.getX(), rect.getY());
\r
468 double width = rect.getWidth();
\r
469 double height = rect.getHeight();
\r
471 g.setColor(colors.BACKGROUND);
\r
472 g.fill(new Rectangle2D.Double(0, 0, width-1, height-1));
\r
474 g.setColor(colors.BORDER1);
\r
475 Line2D line = new Line2D.Double();
\r
476 line.setLine(0, 0, width-1, 0); g.draw(line);
\r
477 line.setLine(0, 0, 0, height-1); g.draw(line);
\r
479 g.setColor(colors.BORDER2);
\r
480 line.setLine(1, height-2, width-2, height-2); g.draw(line);
\r
481 line.setLine(width-2, height-2, width-2, 1); g.draw(line);
\r
483 g.setColor(colors.BORDER3);
\r
484 line.setLine(0, height-1, width-1, height-1); g.draw(line);
\r
485 line.setLine(width-1, height-1, width-1, 0); g.draw(line);
\r
488 g.setColor(colors.TEXT_BLACK);
\r
489 FontMetrics fm = g.getFontMetrics(font);
\r
490 Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);
\r
493 Rectangle2D stringRect = fm.getStringBounds(text, g);
\r
494 float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;
\r
495 g.drawString(text, x, (float)height-6);
\r
497 Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);
\r
499 g.setFont(selectedFont);
\r
501 FontMetrics fm = g.getFontMetrics(selectedFont);
\r
502 Rectangle2D stringRect = fm.getStringBounds(text, g);
\r
503 float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;
\r
505 g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
\r
506 g.setColor(colors.TEXT_WHITE);
\r
507 g.drawString(text, x+1, (float)height-6+1);
\r
509 g.setColor(colors.TEXT_BLACK);
\r
510 g.drawString(text, x, (float)height-6);
\r
514 protected void drawHeld(Graphics2D g, Rectangle2D rect, boolean enabled, ButtonColorProfile colors, Font font, Font selectedFont, String text)
\r
516 g.translate(rect.getX(), rect.getY());
\r
517 double width = rect.getWidth();
\r
518 double height = rect.getHeight();
\r
520 g.setColor(colors.BACKGROUND);
\r
521 g.fill(new Rectangle2D.Double(0, 0, width-1, height-1));
\r
523 Line2D line = new Line2D.Double();
\r
525 g.setColor(colors.BORDER3);
\r
526 line.setLine(0, 0, width-2, 0); g.draw(line);
\r
527 line.setLine(0, 0, 0, height-2); g.draw(line);
\r
529 g.setColor(colors.BORDER2);
\r
530 line.setLine(1, 1, width-3, 1); g.draw(line);
\r
531 line.setLine(1, 1, 1, height-3); g.draw(line);
\r
533 g.setColor(colors.BORDER1);
\r
534 line.setLine(0, height-1, width-1, height-1); g.draw(line);
\r
535 line.setLine(width-1, height-1, width-1, 0); g.draw(line);
\r
537 g.setColor(colors.TEXT_BLACK);
\r
538 FontMetrics fm = g.getFontMetrics(font);
\r
539 Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);
\r
542 Rectangle2D stringRect = fm.getStringBounds(text, g);
\r
543 float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;
\r
544 g.drawString(text, x+1, (float)height-6+1);
\r
548 protected void drawPressed(Graphics2D g, Rectangle2D rect, boolean enabled, ButtonColorProfile colors, Font font, Font selectedFont, String text)
\r
550 g.translate(rect.getX(), rect.getY());
\r
551 double width = rect.getWidth();
\r
552 double height = rect.getHeight();
\r
554 g.setColor(colors.SELECTEDBACKGROUND);
\r
555 g.fill(new Rectangle2D.Double(0, 0, width-1, height-1));
\r
557 Line2D line = new Line2D.Double();
\r
559 g.setColor(colors.BORDER3);
\r
560 line.setLine(0, 0, width-2, 0); g.draw(line);
\r
561 line.setLine(0, 0, 0, height-2); g.draw(line);
\r
563 g.setColor(colors.BORDER2);
\r
564 line.setLine(1, 1, width-3, 1); g.draw(line);
\r
565 line.setLine(1, 1, 1, height-3); g.draw(line);
\r
567 g.setColor(colors.BORDER1);
\r
568 line.setLine(0, height-1, width-1, height-1); g.draw(line);
\r
569 line.setLine(width-1, height-1, width-1, 0); g.draw(line);
\r
572 g.setColor(colors.TEXT_BLACK);
\r
574 FontMetrics fm = g.getFontMetrics(font);
\r
575 Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);
\r
578 Rectangle2D stringRect = fm.getStringBounds(text, g);
\r
579 float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;
\r
580 g.drawString(text, x+1, (float)height-6+1);
\r
582 Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);
\r
584 g.setFont(selectedFont);
\r
586 FontMetrics fm = g.getFontMetrics(selectedFont);
\r
587 Rectangle2D stringRect = fm.getStringBounds(text, g);
\r
588 float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;
\r
590 g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
\r
591 g.setColor(colors.TEXT_WHITE);
\r
592 g.drawString(text, x+2, (float)height-6+2);
\r
594 g.setColor(colors.TEXT_BLACK);
\r
595 g.drawString(text, x+1, (float)height-6+1);
\r
600 protected void drawHover(Graphics2D g, Rectangle2D rect, boolean enabled, ButtonColorProfile colors, Font font, Font selectedFont, String text)
\r
602 g.translate(rect.getX(), rect.getY());
\r
603 double width = rect.getWidth();
\r
604 double height = rect.getHeight();
\r
606 g.setColor(colors.HOVERBACKGROUND);
\r
607 g.fill(new Rectangle2D.Double(0, 0, width-1, height-1));
\r
609 //g.setStroke(HOVER_STROKE);
\r
611 g.setColor(colors.BORDER1);
\r
612 Line2D line = new Line2D.Double();
\r
613 line.setLine(0, 0, width-1, 0); g.draw(line);
\r
614 line.setLine(0, 0, 0, height-1); g.draw(line);
\r
616 g.setColor(colors.BORDER2);
\r
617 line.setLine(1, height-2, width-2, height-2); g.draw(line);
\r
618 line.setLine(width-2, height-2, width-2, 1); g.draw(line);
\r
620 g.setColor(colors.BORDER3);
\r
621 line.setLine(0, height-1, width-1, height-1); g.draw(line);
\r
622 line.setLine(width-1, height-1, width-1, 0); g.draw(line);
\r
625 g.setColor(colors.TEXT_BLACK);
\r
626 FontMetrics fm = g.getFontMetrics(font);
\r
627 Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);
\r
630 Rectangle2D stringRect = fm.getStringBounds(text, g);
\r
631 float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;
\r
632 g.drawString(text, x, (float)height-6);
\r
634 Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);
\r
636 g.setFont(selectedFont);
\r
638 FontMetrics fm = g.getFontMetrics(selectedFont);
\r
639 Rectangle2D stringRect = fm.getStringBounds(text, g);
\r
640 float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;
\r
642 g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
\r
643 g.setColor(colors.TEXT_WHITE);
\r
644 g.drawString(text, x+1, (float)height-6+1);
\r
646 g.setColor(colors.TEXT_BLACK);
\r
647 g.drawString(text, x, (float)height-6);
\r