Salome HOME
Modifications to respect PMD rules.
[tools/siman.git] / Workspace / Siman / src / org / splat / launcher / ToolButton.java
1 package org.splat.launcher;
2
3 import java.awt.Button;
4 import java.awt.Color;
5 import java.awt.Cursor;
6 import java.awt.Graphics;
7 import java.awt.Image;
8
9 public class ToolButton extends Button {
10
11         private transient final Image _icon;
12         private transient int _orx; // X of the icon top left corner
13         private transient int _ory; // Y of the icon top left corner
14         private transient final String _link;
15         private transient final String _target;
16
17         private static final long serialVersionUID = 5723786125423445749L;
18
19         // ==============================================================================================================================
20         // Constructors
21         // ==============================================================================================================================
22
23         public ToolButton(final int size, final Image icon, final String link) {
24                 this(size, icon, link, null);
25         }
26
27         public ToolButton(final int size, final Image icon, final String link,
28                         final String target) {
29                 super();
30                 _orx = 24; // icon.getWidth(this); seems returning 0 before being painted
31                 _ory = 24; // icon.getHeight(this); seems returning 0 before being painted
32                 if (_orx < size) {
33                         _orx = (size - _orx) / 2;
34                 } else {
35                         _orx = 0;
36                 }
37                 if (_ory < size) {
38                         _ory = (size - _ory) / 2;
39                 } else {
40                         _ory = 0;
41                 }
42
43                 this._icon = icon;
44                 this._link = link;
45                 this._target = target;
46                 this.setSize(size, size);
47                 this.setCursor(new Cursor(Cursor.HAND_CURSOR));
48         }
49
50         // ==============================================================================================================================
51         // Overridden functions
52         // ==============================================================================================================================
53
54         @Override
55         public void paint(final Graphics screen) {
56                 screen.drawImage(_icon, _orx, _ory, new Color(205, 229, 255), this);
57         }
58
59         // ==============================================================================================================================
60         // Member functions
61         // ==============================================================================================================================
62
63         public String getTool() {
64                 return _link;
65         }
66
67         public String getTarget() {
68                 return _target;
69         }
70 }