]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/button/ButtonClass.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / elementclass / button / ButtonClass.java
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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.g2d.elementclass.button;\r
13 \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
21 \r
22 \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
43 \r
44 /**\r
45  * @author Toni Kalajainen\r
46  */\r
47 public class ButtonClass {\r
48         \r
49 \r
50         public static final ElementClass BUTTON_CLASS = \r
51                 ElementClass.compile(\r
52                                 Clickable.INSTANCE,\r
53                                 Text.INSTANCE,\r
54                                 Resizeable.UNCONSTRICTED,\r
55                                 DefaultTransform.INSTANCE,\r
56                                 ButtonPaint.INSTANCE,\r
57                                 Stateful.ENABLED_BY_DEFAULT\r
58                 );\r
59 \r
60         \r
61 \r
62         static class ButtonPaint implements SceneGraph {\r
63 \r
64                 private static final long serialVersionUID = 5484741334876153022L;\r
65 \r
66                 public static final ButtonPaint INSTANCE = new ButtonPaint();\r
67                 \r
68                 public static final Key SG_NODE = new SceneGraphNodeKey(Node.class, "SUB_SG_NODE");\r
69                 \r
70 \r
71                 @Override\r
72                 public void cleanup(IElement e) {\r
73                         Node node = e.removeHint(SG_NODE);\r
74             if (node != null)\r
75                 node.remove();\r
76                 }\r
77                 \r
78                 @Override\r
79         public void init(IElement e, G2DParentNode parent) {\r
80                         \r
81             ButtonNode node = (ButtonNode) e.getHint(SG_NODE);\r
82             if (node == null) {\r
83                 node = parent.addNode(ButtonNode.class);\r
84                 e.setHint(SG_NODE, node);\r
85                 e.addKeyHintListener(ElementHints.KEY_TEXT, new HintListenerAdapter() {\r
86                                 \r
87                                 @Override\r
88                                 public void hintChanged(IHintObservable sender, Key key, Object oldValue,\r
89                                                 Object newValue) {\r
90                                         if (sender instanceof IElement) {\r
91                                                 ButtonNode node = (ButtonNode) ((IElement)sender).getHint(SG_NODE);\r
92                                                 node.buttonText = (String)newValue;\r
93                                                 node.repaint();\r
94                                         }\r
95                                         \r
96                                 }\r
97                         });\r
98                 e.addKeyHintListener(AbstractClickable.PRESS_STATUS_KEY, new HintListenerAdapter() {\r
99                                         \r
100                                         @Override\r
101                                         public void hintChanged(IHintObservable sender, Key key, Object oldValue,\r
102                                                         Object newValue) {\r
103                                                 if (sender instanceof IElement) {\r
104                                                         ButtonNode node = (ButtonNode) ((IElement)sender).getHint(SG_NODE);\r
105                                                         node.status = (PressStatus)newValue;\r
106                                                         node.repaint();\r
107                                                 }\r
108                                         }\r
109                                 });\r
110             }\r
111 \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
116 \r
117             // FIXME: context not supported by scenegraph\r
118             PressStatus                 status = PressStatus.NORMAL;//ElementUtils.getPressStatus(e, ctx);\r
119 \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
127 \r
128             System.out.println("ButtonClass.init " + e + " " + status + " " + checked);\r
129             node.init(status, rect, enabled, checked, colors, font, selFont, buttonText);\r
130             \r
131 //            e.addKeyHintListener(AbstractClickable.PRESS_STATUS_KEY, new HintListenerAdapter() {\r
132 //                              \r
133 //                              @Override\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
139 //                                              node.repaint();\r
140 //                                      }\r
141 //                              }\r
142 //                      });\r
143           \r
144         }\r
145                 \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
153             Font font = null;\r
154             Font selFont = null;\r
155             String buttonText = null;\r
156 \r
157             @Override\r
158             public Rectangle2D getBoundsInLocal() {\r
159                 return rect;\r
160             }\r
161             \r
162             @SyncField("pressStatus") void setPressStatus(PressStatus pressStatus) { \r
163                 this.status = pressStatus; \r
164             }\r
165 \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
169                 this.rect = rect;\r
170                 this.enabled = enabled;\r
171                 this.checked = checked;\r
172                 this.colors = colors;\r
173                 this.font = font;\r
174                 this.selFont = selFont;\r
175                 this.buttonText = buttonText;\r
176             }\r
177 \r
178             @Override\r
179             public void render(Graphics2D g) {\r
180                 AffineTransform ot = g.getTransform();\r
181                 switch (status) {\r
182                     case NORMAL:\r
183                         drawNormal(g, rect, enabled, checked, colors, font, selFont, buttonText);\r
184                         break;\r
185                     case HELD:\r
186                         drawHeld(g, rect, enabled, colors, font, selFont, buttonText);\r
187                         break;\r
188                     case PRESSED:\r
189                         drawPressed(g, rect, enabled, colors, font, selFont, buttonText);\r
190                         break;\r
191                     case HOVER:\r
192                         drawHover(g, rect, enabled, colors, font, selFont, buttonText);\r
193                         break;\r
194                 }\r
195                 g.setTransform(ot);\r
196             }\r
197 \r
198             protected void drawNormal(Graphics2D g, Rectangle2D rect, boolean enabled, boolean checked, ButtonColorProfile colors, Font font, Font selectedFont, String text)\r
199             {\r
200                 if(checked) {\r
201                     drawPressed(g, rect, enabled, colors, font, selectedFont, text);\r
202                     return;\r
203                 }\r
204                 g.translate(rect.getX(), rect.getY());\r
205                 double width = rect.getWidth();\r
206                 double height = rect.getHeight();\r
207 \r
208                 g.setColor(colors.BACKGROUND);\r
209                 g.fill(new Rectangle2D.Double(0, 0, width-1, height-1));\r
210 \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
215 \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
219 \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
223 \r
224                 if (enabled) {\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
228                     g.clip(clipRect);\r
229                     g.setFont(font);\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
233                 } else {\r
234                     Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);\r
235                     g.clip(clipRect);\r
236                     g.setFont(selectedFont);\r
237 \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
241 \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
245 \r
246                     g.setColor(colors.TEXT_BLACK);\r
247                     g.drawString(text, x, (float)height-6);\r
248                 }\r
249             }\r
250 \r
251             protected void drawHeld(Graphics2D g, Rectangle2D rect, boolean enabled, ButtonColorProfile colors, Font font, Font selectedFont, String text)\r
252             {\r
253                 g.translate(rect.getX(), rect.getY());\r
254                 double width = rect.getWidth();\r
255                 double height = rect.getHeight();\r
256 \r
257                 g.setColor(colors.BACKGROUND);\r
258                 g.fill(new Rectangle2D.Double(0, 0, width-1, height-1));\r
259 \r
260                 Line2D line = new Line2D.Double();\r
261 \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
265 \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
269 \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
273 \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
277                 g.clip(clipRect);\r
278                 g.setFont(font);\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
282             }\r
283 \r
284 \r
285             protected void drawPressed(Graphics2D g, Rectangle2D rect, boolean enabled, ButtonColorProfile colors, Font font, Font selectedFont, String text)\r
286             {\r
287                 g.translate(rect.getX(), rect.getY());\r
288                 double width = rect.getWidth();\r
289                 double height = rect.getHeight();\r
290 \r
291                 g.setColor(colors.SELECTEDBACKGROUND);\r
292                 g.fill(new Rectangle2D.Double(0, 0, width-1, height-1));\r
293 \r
294                 Line2D line = new Line2D.Double();\r
295 \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
299 \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
303 \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
307 \r
308                 if (enabled) {\r
309                     g.setColor(colors.TEXT_BLACK);\r
310 \r
311                     FontMetrics fm = g.getFontMetrics(font);\r
312                     Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);\r
313                     g.clip(clipRect);\r
314                     g.setFont(font);\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
318                 } else {\r
319                     Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);\r
320                     g.clip(clipRect);\r
321                     g.setFont(selectedFont);\r
322 \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
326 \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
330 \r
331                     g.setColor(colors.TEXT_BLACK);\r
332                     g.drawString(text, x+1, (float)height-6+1);\r
333                 }\r
334 \r
335             }\r
336 \r
337             protected void drawHover(Graphics2D g, Rectangle2D rect, boolean enabled, ButtonColorProfile colors, Font font, Font selectedFont, String text)\r
338             {\r
339                 g.translate(rect.getX(), rect.getY());\r
340                 double width = rect.getWidth();\r
341                 double height = rect.getHeight();\r
342 \r
343                 g.setColor(colors.HOVERBACKGROUND);\r
344                 g.fill(new Rectangle2D.Double(0, 0, width-1, height-1));\r
345 \r
346                 //g.setStroke(HOVER_STROKE);\r
347 \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
352 \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
356 \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
360 \r
361                 if (enabled) {\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
365                     g.clip(clipRect);\r
366                     g.setFont(font);\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
370                 } else {\r
371                     Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);\r
372                     g.clip(clipRect);\r
373                     g.setFont(selectedFont);\r
374 \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
378 \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
382 \r
383                     g.setColor(colors.TEXT_BLACK);\r
384                     g.drawString(text, x, (float)height-6);\r
385                 }\r
386             }\r
387             \r
388         }\r
389 \r
390         protected ButtonColorProfile getColorProfile(IElement e)\r
391         {\r
392             return ButtonColorProfile.DEFAULT;\r
393         }\r
394 \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
399         }\r
400 \r
401         public boolean isChecked(IElement e){\r
402             Boolean b = e.getHint(AbstractTogglable.TOGGLE_KEY);\r
403             if (b == null)\r
404                 return false;\r
405             return b;\r
406         \r
407                 }\r
408         }\r
409 /*      \r
410         static class ButtonPaint implements Paint {\r
411 \r
412                 private static final long serialVersionUID = 7339681670484169461L;\r
413                 public static final ButtonPaint INSTANCE = new ButtonPaint();\r
414                 @Override\r
415                 public void paint(IElement e, ICanvasContext ctx, GraphicsContext elementGC, GraphicsContext controlGC) {\r
416                         \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
422 //                      \r
423 //                      PressStatus                     status = ElementUtils.getPressStatus(e, ctx);\r
424 //                      \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
431 //                      \r
432 //                      switch (status) {\r
433 //                      case NORMAL:\r
434 //                              drawNormal(g, rect, enabled, colors, font, selFont, buttonText);\r
435 //                              break;\r
436 //                      case HELD:\r
437 //                              drawHeld(g, rect, enabled, colors, font, selFont, buttonText);\r
438 //                              break;\r
439 //                      case PRESSED:\r
440 //                              drawPressed(g, rect, enabled, colors, font, selFont, buttonText);\r
441 //                              break;\r
442 //                      case HOVER:\r
443 //                              drawHover(g, rect, enabled, colors, font, selFont, buttonText);\r
444 //                              break;\r
445 //                      }\r
446 //\r
447                 }\r
448                 \r
449                 protected ButtonColorProfile getColorProfile(IElement e)\r
450                 {\r
451                         return ButtonColorProfile.DEFAULT;\r
452                 }\r
453                 \r
454                 protected boolean isToggleButton()\r
455                 {\r
456                         return false;\r
457                 }               \r
458                 \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
463                 }\r
464                 \r
465                 protected void drawNormal(Graphics2D g, Rectangle2D rect, boolean enabled, ButtonColorProfile colors, Font font, Font selectedFont, String text)\r
466                 {                       \r
467                         g.translate(rect.getX(), rect.getY());\r
468                         double width = rect.getWidth();\r
469                         double height = rect.getHeight();\r
470                         \r
471                         g.setColor(colors.BACKGROUND);\r
472                         g.fill(new Rectangle2D.Double(0, 0, width-1, height-1));\r
473                         \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
478                         \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
482                         \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
486                                                 \r
487                         if (enabled) {\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
491                                 g.clip(clipRect);                                       \r
492                                 g.setFont(font);\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
496                         } else {\r
497                                 Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);\r
498                                 g.clip(clipRect);\r
499                                 g.setFont(selectedFont);\r
500                                                                 \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
504                                         \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
508                                         \r
509                                 g.setColor(colors.TEXT_BLACK);\r
510                                 g.drawString(text, x, (float)height-6);                         \r
511                         }\r
512                 }\r
513                 \r
514                 protected void drawHeld(Graphics2D g, Rectangle2D rect, boolean enabled, ButtonColorProfile colors, Font font, Font selectedFont, String text)\r
515                 {\r
516                         g.translate(rect.getX(), rect.getY());\r
517                         double width = rect.getWidth();\r
518                         double height = rect.getHeight();\r
519                         \r
520                         g.setColor(colors.BACKGROUND);\r
521                         g.fill(new Rectangle2D.Double(0, 0, width-1, height-1));\r
522                         \r
523                         Line2D line = new Line2D.Double();\r
524                         \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
528                         \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
532                         \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
536                         \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
540                         g.clip(clipRect);\r
541                         g.setFont(font);\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
545                 }\r
546                 \r
547                 \r
548                 protected void drawPressed(Graphics2D g, Rectangle2D rect, boolean enabled, ButtonColorProfile colors, Font font, Font selectedFont, String text)\r
549                 {\r
550                         g.translate(rect.getX(), rect.getY());\r
551                         double width = rect.getWidth();\r
552                         double height = rect.getHeight();\r
553                         \r
554                         g.setColor(colors.SELECTEDBACKGROUND);\r
555                         g.fill(new Rectangle2D.Double(0, 0, width-1, height-1));\r
556                         \r
557                         Line2D line = new Line2D.Double();\r
558                         \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
562                         \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
566                         \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
570 \r
571                         if (enabled) {\r
572                                 g.setColor(colors.TEXT_BLACK);\r
573                                 \r
574                                 FontMetrics fm = g.getFontMetrics(font);\r
575                                 Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);\r
576                                 g.clip(clipRect);                               \r
577                                 g.setFont(font);\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
581                         } else {\r
582                                 Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);\r
583                                 g.clip(clipRect);\r
584                                 g.setFont(selectedFont);\r
585                                                                 \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
589                                         \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
593                                         \r
594                                 g.setColor(colors.TEXT_BLACK);\r
595                                 g.drawString(text, x+1, (float)height-6+1);                             \r
596                         }\r
597                                 \r
598                 }\r
599                 \r
600                 protected void drawHover(Graphics2D g, Rectangle2D rect, boolean enabled, ButtonColorProfile colors, Font font, Font selectedFont, String text)\r
601                 {                       \r
602                         g.translate(rect.getX(), rect.getY());\r
603                         double width = rect.getWidth();\r
604                         double height = rect.getHeight();\r
605                         \r
606                         g.setColor(colors.HOVERBACKGROUND);\r
607                         g.fill(new Rectangle2D.Double(0, 0, width-1, height-1));\r
608                         \r
609                         //g.setStroke(HOVER_STROKE);\r
610                         \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
615                         \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
619                         \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
623                                                 \r
624                         if (enabled) {\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
628                                 g.clip(clipRect);                                       \r
629                                 g.setFont(font);\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
633                         } else {\r
634                                 Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);\r
635                                 g.clip(clipRect);\r
636                                 g.setFont(selectedFont);\r
637                                                                 \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
641                                         \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
645                                         \r
646                                 g.setColor(colors.TEXT_BLACK);\r
647                                 g.drawString(text, x, (float)height-6);                         \r
648                         }\r
649                 }\r
650         }\r
651         */\r
652 }\r