1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
| /**
* Extended button without an animation
* @param text button text
* @param graphic button icon
* @param notifyImage mini icon
*/
public MiniIconAnimationButton(String text,
Node graphic,
ImageView notifyImage) {
this(text, graphic, notifyImage, AnimationType.NONE);
}
/**
* Extended button with an animation
* @param text button text
* @param graphic button icon
* @param notifyImage mini icon
* @param type animation type for mini icon
*/
public MiniIconAnimationButton(String text,
Node graphic,
ImageView notifyImage,
AnimationType type) { ... }```
### 2.2 AnimationType
There are three animation types for this button.
- NONE means that there is no animation. The mini-icon is just shown in the upper right corner.
- JUMP means that the mini-icon moves up and down frequently.
- BLINK means that the mini-icon changes the opacity from visible to invisible and back.
```java
/**
* Type of animation
*/
public enum AnimationType { NONE, JUMP, BLINK };```
### 2.3 add the controls to the stack
The button is an extension of the StackPane to position the button in the back and the mini-icon in the front. The mini-icon is placed on the upper right and 4 pixels away from the edges.
```java
/**
* add the button to the background and the mini-icon to the front
*/
private void stackControls() {
StackPane.setAlignment(imageView, Pos.TOP_RIGHT);
StackPane.setMargin(imageView, new Insets(4, 4, 4, 4)) ;
getChildren().addAll(button, imageView);
}```
### 2.4 bind the size of the mini-icon to the button size
The mini-icon should be smaller than the button self. I decided to make the mini-icon a quater of the size of the button. To resize the icon if the button is resized I add an ChangeListener to the binding.
```java
/**
* bind the size of the mini-icon to the button size
*/
private void addImageViewSizeBindings() {
final ReadOnlyDoubleProperty widthProperty = button.widthProperty();
final ReadOnlyDoubleProperty heightProperty = button.heightProperty();
final DoubleBinding widthBinding = widthProperty.divide(4.0);
final DoubleBinding heightBinding = heightProperty.divide(4.0);
imageView.setFitWidth(widthBinding.doubleValue());
imageView.setFitHeight(heightBinding.doubleValue());
widthBinding.addListener(new ChangeListener() {
@Override
public void changed(ObservableValue o, Object oldVal, Object newVal) {
imageView.setFitWidth(widthBinding.doubleValue());
}
});
heightBinding.addListener(new ChangeListener() {
@Override
public void changed(ObservableValue o, Object oldVal, Object newVal) {
imageView.setFitHeight(heightBinding.doubleValue());
}
});
}
|