]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/button/ButtonClass.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / elementclass / button / ButtonClass.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.g2d.elementclass.button;
13
14 import java.awt.AlphaComposite;
15 import java.awt.Font;
16 import java.awt.FontMetrics;
17 import java.awt.Graphics2D;
18 import java.awt.geom.AffineTransform;
19 import java.awt.geom.Line2D;
20 import java.awt.geom.Rectangle2D;
21
22
23 import org.simantics.g2d.element.ElementClass;
24 import org.simantics.g2d.element.ElementHints;
25 import org.simantics.g2d.element.ElementUtils;
26 import org.simantics.g2d.element.IElement;
27 import org.simantics.g2d.element.SceneGraphNodeKey;
28 import org.simantics.g2d.element.handler.Clickable;
29 import org.simantics.g2d.element.handler.SceneGraph;
30 import org.simantics.g2d.element.handler.Stateful;
31 import org.simantics.g2d.element.handler.Text;
32 import org.simantics.g2d.element.handler.Clickable.PressStatus;
33 import org.simantics.g2d.element.handler.impl.AbstractClickable;
34 import org.simantics.g2d.element.handler.impl.AbstractTogglable;
35 import org.simantics.g2d.element.handler.impl.DefaultTransform;
36 import org.simantics.g2d.element.handler.impl.Resizeable;
37 import org.simantics.scenegraph.Node;
38 import org.simantics.scenegraph.g2d.G2DNode;
39 import org.simantics.scenegraph.g2d.G2DParentNode;
40 import org.simantics.utils.datastructures.hints.HintListenerAdapter;
41 import org.simantics.utils.datastructures.hints.IHintObservable;
42 import org.simantics.utils.datastructures.hints.IHintContext.Key;
43
44 /**
45  * @author Toni Kalajainen
46  */
47 public class ButtonClass {
48         
49
50         public static final ElementClass BUTTON_CLASS = 
51                 ElementClass.compile(
52                                 Clickable.INSTANCE,
53                                 Text.INSTANCE,
54                                 Resizeable.UNCONSTRICTED,
55                                 DefaultTransform.INSTANCE,
56                                 ButtonPaint.INSTANCE,
57                                 Stateful.ENABLED_BY_DEFAULT
58                 );
59
60         
61
62         static class ButtonPaint implements SceneGraph {
63
64                 private static final long serialVersionUID = 5484741334876153022L;
65
66                 public static final ButtonPaint INSTANCE = new ButtonPaint();
67                 
68                 public static final Key SG_NODE = new SceneGraphNodeKey(Node.class, "SUB_SG_NODE");
69                 
70
71                 @Override
72                 public void cleanup(IElement e) {
73                         Node node = e.removeHint(SG_NODE);
74             if (node != null)
75                 node.remove();
76                 }
77                 
78                 @Override
79         public void init(IElement e, G2DParentNode parent) {
80                         
81             ButtonNode node = (ButtonNode) e.getHint(SG_NODE);
82             if (node == null) {
83                 node = parent.addNode(ButtonNode.class);
84                 e.setHint(SG_NODE, node);
85                 e.addKeyHintListener(ElementHints.KEY_TEXT, new HintListenerAdapter() {
86                                 
87                                 @Override
88                                 public void hintChanged(IHintObservable sender, Key key, Object oldValue,
89                                                 Object newValue) {
90                                         if (sender instanceof IElement) {
91                                                 ButtonNode node = (ButtonNode) ((IElement)sender).getHint(SG_NODE);
92                                                 node.buttonText = (String)newValue;
93                                                 node.repaint();
94                                         }
95                                         
96                                 }
97                         });
98                 e.addKeyHintListener(AbstractClickable.PRESS_STATUS_KEY, new HintListenerAdapter() {
99                                         
100                                         @Override
101                                         public void hintChanged(IHintObservable sender, Key key, Object oldValue,
102                                                         Object newValue) {
103                                                 if (sender instanceof IElement) {
104                                                         ButtonNode node = (ButtonNode) ((IElement)sender).getHint(SG_NODE);
105                                                         node.status = (PressStatus)newValue;
106                                                         node.repaint();
107                                                 }
108                                         }
109                                 });
110             }
111
112             Rectangle2D                 rect = ElementUtils.getElementBounds(e);
113             ButtonColorProfile  colors = ButtonColorProfile.DEFAULT;
114             double                              height = rect.getHeight();
115             boolean                             enabled = isEnabled(e);
116
117             // FIXME: context not supported by scenegraph
118             PressStatus                 status = PressStatus.NORMAL;//ElementUtils.getPressStatus(e, ctx);
119
120             Font                                font = new Font("Tahoma", 0, (int) height-6);
121             Font                                selFont = new Font("Tahoma", Font.BOLD, (int) height-6);
122             Text                                text = e.getElementClass().getAtMostOneItemOfClass(Text.class);
123             String                              buttonText = null;
124             if (text!=null) buttonText = text.getText(e);
125             if (buttonText==null) buttonText = "";
126             boolean checked = isChecked(e);
127
128             System.out.println("ButtonClass.init " + e + " " + status + " " + checked);
129             node.init(status, rect, enabled, checked, colors, font, selFont, buttonText);
130             
131 //            e.addKeyHintListener(AbstractClickable.PRESS_STATUS_KEY, new HintListenerAdapter() {
132 //                              
133 //                              @Override
134 //                              public void hintChanged(IHintObservable sender, Key key, Object oldValue,
135 //                                              Object newValue) {
136 //                                      if (sender instanceof IElement) {
137 //                                              ButtonNode node = (ButtonNode) ((IElement)sender).getHint(SG_NODE);
138 //                                              node.setPressStatus((PressStatus)newValue);
139 //                                              node.repaint();
140 //                                      }
141 //                              }
142 //                      });
143           
144         }
145                 
146                 public static class ButtonNode extends G2DNode {
147                         private static final long serialVersionUID = 2291569851866542945L;
148                         PressStatus status = null;
149             Rectangle2D rect = null;
150             Boolean enabled = null;
151             Boolean checked = null;
152             ButtonColorProfile colors = null;
153             Font font = null;
154             Font selFont = null;
155             String buttonText = null;
156
157             @Override
158             public Rectangle2D getBoundsInLocal() {
159                 return rect;
160             }
161             
162             @SyncField("pressStatus") void setPressStatus(PressStatus pressStatus) { 
163                 this.status = pressStatus; 
164             }
165
166             public void init(PressStatus status, Rectangle2D rect, boolean enabled, boolean checked,
167                     ButtonColorProfile colors, Font font, Font selFont, String buttonText) {
168                 this.status = status;
169                 this.rect = rect;
170                 this.enabled = enabled;
171                 this.checked = checked;
172                 this.colors = colors;
173                 this.font = font;
174                 this.selFont = selFont;
175                 this.buttonText = buttonText;
176             }
177
178             @Override
179             public void render(Graphics2D g) {
180                 AffineTransform ot = g.getTransform();
181                 switch (status) {
182                     case NORMAL:
183                         drawNormal(g, rect, enabled, checked, colors, font, selFont, buttonText);
184                         break;
185                     case HELD:
186                         drawHeld(g, rect, enabled, colors, font, selFont, buttonText);
187                         break;
188                     case PRESSED:
189                         drawPressed(g, rect, enabled, colors, font, selFont, buttonText);
190                         break;
191                     case HOVER:
192                         drawHover(g, rect, enabled, colors, font, selFont, buttonText);
193                         break;
194                 }
195                 g.setTransform(ot);
196             }
197
198             protected void drawNormal(Graphics2D g, Rectangle2D rect, boolean enabled, boolean checked, ButtonColorProfile colors, Font font, Font selectedFont, String text)
199             {
200                 if(checked) {
201                     drawPressed(g, rect, enabled, colors, font, selectedFont, text);
202                     return;
203                 }
204                 g.translate(rect.getX(), rect.getY());
205                 double width = rect.getWidth();
206                 double height = rect.getHeight();
207
208                 g.setColor(colors.BACKGROUND);
209                 g.fill(new Rectangle2D.Double(0, 0, width-1, height-1));
210
211                 g.setColor(colors.BORDER1);
212                 Line2D line = new Line2D.Double();
213                 line.setLine(0, 0, width-1, 0);         g.draw(line);
214                 line.setLine(0, 0, 0, height-1);        g.draw(line);
215
216                 g.setColor(colors.BORDER2);
217                 line.setLine(1, height-2, width-2, height-2);   g.draw(line);
218                 line.setLine(width-2, height-2, width-2, 1);    g.draw(line);
219
220                 g.setColor(colors.BORDER3);
221                 line.setLine(0, height-1, width-1, height-1);   g.draw(line);
222                 line.setLine(width-1, height-1, width-1, 0);    g.draw(line);
223
224                 if (enabled) {
225                     g.setColor(colors.TEXT_BLACK);
226                     FontMetrics fm = g.getFontMetrics(font);
227                     Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);
228                     g.clip(clipRect);
229                     g.setFont(font);
230                     Rectangle2D stringRect = fm.getStringBounds(text, g);
231                     float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;
232                     g.drawString(text, x, (float)height-6);
233                 } else {
234                     Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);
235                     g.clip(clipRect);
236                     g.setFont(selectedFont);
237
238                     FontMetrics fm = g.getFontMetrics(selectedFont);
239                     Rectangle2D stringRect = fm.getStringBounds(text, g);
240                     float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;
241
242                     g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
243                     g.setColor(colors.TEXT_WHITE);
244                     g.drawString(text, x+1, (float)height-6+1);
245
246                     g.setColor(colors.TEXT_BLACK);
247                     g.drawString(text, x, (float)height-6);
248                 }
249             }
250
251             protected void drawHeld(Graphics2D g, Rectangle2D rect, boolean enabled, ButtonColorProfile colors, Font font, Font selectedFont, String text)
252             {
253                 g.translate(rect.getX(), rect.getY());
254                 double width = rect.getWidth();
255                 double height = rect.getHeight();
256
257                 g.setColor(colors.BACKGROUND);
258                 g.fill(new Rectangle2D.Double(0, 0, width-1, height-1));
259
260                 Line2D line = new Line2D.Double();
261
262                 g.setColor(colors.BORDER3);
263                 line.setLine(0, 0, width-2, 0); g.draw(line);
264                 line.setLine(0, 0, 0, height-2); g.draw(line);
265
266                 g.setColor(colors.BORDER2);
267                 line.setLine(1, 1, width-3, 1); g.draw(line);
268                 line.setLine(1, 1, 1, height-3); g.draw(line);
269
270                 g.setColor(colors.BORDER1);
271                 line.setLine(0, height-1, width-1, height-1); g.draw(line);
272                 line.setLine(width-1, height-1, width-1, 0); g.draw(line);
273
274                 g.setColor(colors.TEXT_BLACK);
275                 FontMetrics fm = g.getFontMetrics(font);
276                 Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);
277                 g.clip(clipRect);
278                 g.setFont(font);
279                 Rectangle2D     stringRect = fm.getStringBounds(text, g);
280                 float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;
281                 g.drawString(text, x+1, (float)height-6+1);
282             }
283
284
285             protected void drawPressed(Graphics2D g, Rectangle2D rect, boolean enabled, ButtonColorProfile colors, Font font, Font selectedFont, String text)
286             {
287                 g.translate(rect.getX(), rect.getY());
288                 double width = rect.getWidth();
289                 double height = rect.getHeight();
290
291                 g.setColor(colors.SELECTEDBACKGROUND);
292                 g.fill(new Rectangle2D.Double(0, 0, width-1, height-1));
293
294                 Line2D line = new Line2D.Double();
295
296                 g.setColor(colors.BORDER3);
297                 line.setLine(0, 0, width-2, 0); g.draw(line);
298                 line.setLine(0, 0, 0, height-2); g.draw(line);
299
300                 g.setColor(colors.BORDER2);
301                 line.setLine(1, 1, width-3, 1); g.draw(line);
302                 line.setLine(1, 1, 1, height-3); g.draw(line);
303
304                 g.setColor(colors.BORDER1);
305                 line.setLine(0, height-1, width-1, height-1); g.draw(line);
306                 line.setLine(width-1, height-1, width-1, 0); g.draw(line);
307
308                 if (enabled) {
309                     g.setColor(colors.TEXT_BLACK);
310
311                     FontMetrics fm = g.getFontMetrics(font);
312                     Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);
313                     g.clip(clipRect);
314                     g.setFont(font);
315                     Rectangle2D stringRect = fm.getStringBounds(text, g);
316                     float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;
317                     g.drawString(text, x+1, (float)height-6+1);
318                 } else {
319                     Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);
320                     g.clip(clipRect);
321                     g.setFont(selectedFont);
322
323                     FontMetrics fm = g.getFontMetrics(selectedFont);
324                     Rectangle2D stringRect = fm.getStringBounds(text, g);
325                     float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;
326
327                     g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
328                     g.setColor(colors.TEXT_WHITE);
329                     g.drawString(text, x+2, (float)height-6+2);
330
331                     g.setColor(colors.TEXT_BLACK);
332                     g.drawString(text, x+1, (float)height-6+1);
333                 }
334
335             }
336
337             protected void drawHover(Graphics2D g, Rectangle2D rect, boolean enabled, ButtonColorProfile colors, Font font, Font selectedFont, String text)
338             {
339                 g.translate(rect.getX(), rect.getY());
340                 double width = rect.getWidth();
341                 double height = rect.getHeight();
342
343                 g.setColor(colors.HOVERBACKGROUND);
344                 g.fill(new Rectangle2D.Double(0, 0, width-1, height-1));
345
346                 //g.setStroke(HOVER_STROKE);
347
348                 g.setColor(colors.BORDER1);
349                 Line2D line = new Line2D.Double();
350                 line.setLine(0, 0, width-1, 0);         g.draw(line);
351                 line.setLine(0, 0, 0, height-1);        g.draw(line);
352
353                 g.setColor(colors.BORDER2);
354                 line.setLine(1, height-2, width-2, height-2);   g.draw(line);
355                 line.setLine(width-2, height-2, width-2, 1);    g.draw(line);
356
357                 g.setColor(colors.BORDER3);
358                 line.setLine(0, height-1, width-1, height-1);   g.draw(line);
359                 line.setLine(width-1, height-1, width-1, 0);    g.draw(line);
360
361                 if (enabled) {
362                     g.setColor(colors.TEXT_BLACK);
363                     FontMetrics fm = g.getFontMetrics(font);
364                     Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);
365                     g.clip(clipRect);
366                     g.setFont(font);
367                     Rectangle2D stringRect = fm.getStringBounds(text, g);
368                     float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;
369                     g.drawString(text, x, (float)height-6);
370                 } else {
371                     Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);
372                     g.clip(clipRect);
373                     g.setFont(selectedFont);
374
375                     FontMetrics fm = g.getFontMetrics(selectedFont);
376                     Rectangle2D stringRect = fm.getStringBounds(text, g);
377                     float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;
378
379                     g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
380                     g.setColor(colors.TEXT_WHITE);
381                     g.drawString(text, x+1, (float)height-6+1);
382
383                     g.setColor(colors.TEXT_BLACK);
384                     g.drawString(text, x, (float)height-6);
385                 }
386             }
387             
388         }
389
390         protected ButtonColorProfile getColorProfile(IElement e)
391         {
392             return ButtonColorProfile.DEFAULT;
393         }
394
395         public boolean isEnabled(IElement e) {
396             Stateful enabled = e.getElementClass().getAtMostOneItemOfClass(Stateful.class);
397             if (enabled==null) return true;
398             return enabled.isEnabled(e);
399         }
400
401         public boolean isChecked(IElement e){
402             Boolean b = e.getHint(AbstractTogglable.TOGGLE_KEY);
403             if (b == null)
404                 return false;
405             return b;
406         
407                 }
408         }
409 /*      
410         static class ButtonPaint implements Paint {
411
412                 private static final long serialVersionUID = 7339681670484169461L;
413                 public static final ButtonPaint INSTANCE = new ButtonPaint();
414                 @Override
415                 public void paint(IElement e, ICanvasContext ctx, GraphicsContext elementGC, GraphicsContext controlGC) {
416                         
417 //                      Graphics2D                      g = elementGC.createClone();
418 //                      Rectangle2D                     rect = elementGC.getBounds();
419 //                      ButtonColorProfile      colors = ButtonColorProfile.DEFAULT;
420 //                      double                          height = rect.getHeight();
421 //                      boolean                         enabled = isEnabled(e);
422 //                      
423 //                      PressStatus                     status = ElementUtils.getPressStatus(e, ctx);
424 //                      
425 //                      Font                            font = new Font("Tahoma", 0, (int) height-6);
426 //                      Font                            selFont = new Font("Tahoma", Font.BOLD, (int) height-6);                        
427 //                      Text                            text = e.getElementClass().getAtMostOneItemOfClass(Text.class);                 
428 //                      String                          buttonText = null;
429 //                      if (text!=null) buttonText = text.getText(e);
430 //                      if (buttonText==null) buttonText = "";
431 //                      
432 //                      switch (status) {
433 //                      case NORMAL:
434 //                              drawNormal(g, rect, enabled, colors, font, selFont, buttonText);
435 //                              break;
436 //                      case HELD:
437 //                              drawHeld(g, rect, enabled, colors, font, selFont, buttonText);
438 //                              break;
439 //                      case PRESSED:
440 //                              drawPressed(g, rect, enabled, colors, font, selFont, buttonText);
441 //                              break;
442 //                      case HOVER:
443 //                              drawHover(g, rect, enabled, colors, font, selFont, buttonText);
444 //                              break;
445 //                      }
446 //
447                 }
448                 
449                 protected ButtonColorProfile getColorProfile(IElement e)
450                 {
451                         return ButtonColorProfile.DEFAULT;
452                 }
453                 
454                 protected boolean isToggleButton()
455                 {
456                         return false;
457                 }               
458                 
459                 public boolean isEnabled(IElement e) {
460                         Stateful enabled = e.getElementClass().getAtMostOneItemOfClass(Stateful.class);
461                         if (enabled==null) return true;
462                         return enabled.isEnabled(e);
463                 }
464                 
465                 protected void drawNormal(Graphics2D g, Rectangle2D rect, boolean enabled, ButtonColorProfile colors, Font font, Font selectedFont, String text)
466                 {                       
467                         g.translate(rect.getX(), rect.getY());
468                         double width = rect.getWidth();
469                         double height = rect.getHeight();
470                         
471                         g.setColor(colors.BACKGROUND);
472                         g.fill(new Rectangle2D.Double(0, 0, width-1, height-1));
473                         
474                         g.setColor(colors.BORDER1);                                             
475                         Line2D line = new Line2D.Double();
476                         line.setLine(0, 0, width-1, 0);         g.draw(line);
477                         line.setLine(0, 0, 0, height-1);        g.draw(line);
478                         
479                         g.setColor(colors.BORDER2);
480                         line.setLine(1, height-2, width-2, height-2);   g.draw(line);
481                         line.setLine(width-2, height-2, width-2, 1);    g.draw(line);
482                         
483                         g.setColor(colors.BORDER3);
484                         line.setLine(0, height-1, width-1, height-1);   g.draw(line);
485                         line.setLine(width-1, height-1, width-1, 0);    g.draw(line);
486                                                 
487                         if (enabled) {
488                                 g.setColor(colors.TEXT_BLACK);
489                                 FontMetrics fm = g.getFontMetrics(font); 
490                                 Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);
491                                 g.clip(clipRect);                                       
492                                 g.setFont(font);
493                                 Rectangle2D     stringRect = fm.getStringBounds(text, g);
494                                 float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;
495                                 g.drawString(text, x, (float)height-6);
496                         } else {
497                                 Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);
498                                 g.clip(clipRect);
499                                 g.setFont(selectedFont);
500                                                                 
501                                 FontMetrics fm = g.getFontMetrics(selectedFont); 
502                                 Rectangle2D     stringRect = fm.getStringBounds(text, g);
503                                 float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;
504                                         
505                                 g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
506                                 g.setColor(colors.TEXT_WHITE);
507                                 g.drawString(text, x+1, (float)height-6+1);
508                                         
509                                 g.setColor(colors.TEXT_BLACK);
510                                 g.drawString(text, x, (float)height-6);                         
511                         }
512                 }
513                 
514                 protected void drawHeld(Graphics2D g, Rectangle2D rect, boolean enabled, ButtonColorProfile colors, Font font, Font selectedFont, String text)
515                 {
516                         g.translate(rect.getX(), rect.getY());
517                         double width = rect.getWidth();
518                         double height = rect.getHeight();
519                         
520                         g.setColor(colors.BACKGROUND);
521                         g.fill(new Rectangle2D.Double(0, 0, width-1, height-1));
522                         
523                         Line2D line = new Line2D.Double();
524                         
525                         g.setColor(colors.BORDER3);
526                         line.setLine(0, 0, width-2, 0); g.draw(line);
527                         line.setLine(0, 0, 0, height-2); g.draw(line);
528                         
529                         g.setColor(colors.BORDER2);
530                         line.setLine(1, 1, width-3, 1); g.draw(line);
531                         line.setLine(1, 1, 1, height-3); g.draw(line);
532                         
533                         g.setColor(colors.BORDER1);
534                         line.setLine(0, height-1, width-1, height-1); g.draw(line);
535                         line.setLine(width-1, height-1, width-1, 0); g.draw(line);
536                         
537                         g.setColor(colors.TEXT_BLACK);                          
538                         FontMetrics fm = g.getFontMetrics(font);
539                         Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);
540                         g.clip(clipRect);
541                         g.setFont(font);
542                         Rectangle2D     stringRect = fm.getStringBounds(text, g);
543                         float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;
544                         g.drawString(text, x+1, (float)height-6+1);
545                 }
546                 
547                 
548                 protected void drawPressed(Graphics2D g, Rectangle2D rect, boolean enabled, ButtonColorProfile colors, Font font, Font selectedFont, String text)
549                 {
550                         g.translate(rect.getX(), rect.getY());
551                         double width = rect.getWidth();
552                         double height = rect.getHeight();
553                         
554                         g.setColor(colors.SELECTEDBACKGROUND);
555                         g.fill(new Rectangle2D.Double(0, 0, width-1, height-1));
556                         
557                         Line2D line = new Line2D.Double();
558                         
559                         g.setColor(colors.BORDER3);
560                         line.setLine(0, 0, width-2, 0); g.draw(line);
561                         line.setLine(0, 0, 0, height-2); g.draw(line);                  
562                         
563                         g.setColor(colors.BORDER2);
564                         line.setLine(1, 1, width-3, 1); g.draw(line);
565                         line.setLine(1, 1, 1, height-3); g.draw(line);                                          
566                         
567                         g.setColor(colors.BORDER1);
568                         line.setLine(0, height-1, width-1, height-1); g.draw(line);
569                         line.setLine(width-1, height-1, width-1, 0); g.draw(line);                                              
570
571                         if (enabled) {
572                                 g.setColor(colors.TEXT_BLACK);
573                                 
574                                 FontMetrics fm = g.getFontMetrics(font);
575                                 Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);
576                                 g.clip(clipRect);                               
577                                 g.setFont(font);
578                                 Rectangle2D     stringRect = fm.getStringBounds(text, g);
579                                 float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;
580                                 g.drawString(text, x+1, (float)height-6+1);
581                         } else {
582                                 Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);
583                                 g.clip(clipRect);
584                                 g.setFont(selectedFont);
585                                                                 
586                                 FontMetrics fm = g.getFontMetrics(selectedFont); 
587                                 Rectangle2D     stringRect = fm.getStringBounds(text, g);
588                                 float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;
589                                         
590                                 g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
591                                 g.setColor(colors.TEXT_WHITE);
592                                 g.drawString(text, x+2, (float)height-6+2);
593                                         
594                                 g.setColor(colors.TEXT_BLACK);
595                                 g.drawString(text, x+1, (float)height-6+1);                             
596                         }
597                                 
598                 }
599                 
600                 protected void drawHover(Graphics2D g, Rectangle2D rect, boolean enabled, ButtonColorProfile colors, Font font, Font selectedFont, String text)
601                 {                       
602                         g.translate(rect.getX(), rect.getY());
603                         double width = rect.getWidth();
604                         double height = rect.getHeight();
605                         
606                         g.setColor(colors.HOVERBACKGROUND);
607                         g.fill(new Rectangle2D.Double(0, 0, width-1, height-1));
608                         
609                         //g.setStroke(HOVER_STROKE);
610                         
611                         g.setColor(colors.BORDER1);                                             
612                         Line2D line = new Line2D.Double();
613                         line.setLine(0, 0, width-1, 0);         g.draw(line);
614                         line.setLine(0, 0, 0, height-1);        g.draw(line);
615                         
616                         g.setColor(colors.BORDER2);
617                         line.setLine(1, height-2, width-2, height-2);   g.draw(line);
618                         line.setLine(width-2, height-2, width-2, 1);    g.draw(line);
619                         
620                         g.setColor(colors.BORDER3);
621                         line.setLine(0, height-1, width-1, height-1);   g.draw(line);
622                         line.setLine(width-1, height-1, width-1, 0);    g.draw(line);
623                                                 
624                         if (enabled) {
625                                 g.setColor(colors.TEXT_BLACK);
626                                 FontMetrics fm = g.getFontMetrics(font); 
627                                 Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);
628                                 g.clip(clipRect);                                       
629                                 g.setFont(font);
630                                 Rectangle2D     stringRect = fm.getStringBounds(text, g);
631                                 float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;
632                                 g.drawString(text, x, (float)height-6);
633                         } else {
634                                 Rectangle2D clipRect = new Rectangle2D.Double(2, 2, width-4, height-4);
635                                 g.clip(clipRect);
636                                 g.setFont(selectedFont);
637                                                                 
638                                 FontMetrics fm = g.getFontMetrics(selectedFont); 
639                                 Rectangle2D     stringRect = fm.getStringBounds(text, g);
640                                 float x = ((float)((width - 4) / 2)) - ((float)stringRect.getWidth()) / 2;
641                                         
642                                 g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
643                                 g.setColor(colors.TEXT_WHITE);
644                                 g.drawString(text, x+1, (float)height-6+1);
645                                         
646                                 g.setColor(colors.TEXT_BLACK);
647                                 g.drawString(text, x, (float)height-6);                         
648                         }
649                 }
650         }
651         */
652 }