1
2
3
4
5
6
7
8
9
10
11 package com.jsql.view.swing.panel.address;
12
13 import com.jsql.util.I18nUtil;
14 import com.jsql.view.swing.manager.util.StateButton;
15 import com.jsql.view.swing.text.JToolTipI18n;
16 import com.jsql.view.swing.util.I18nViewUtil;
17 import com.jsql.view.swing.util.UiUtil;
18
19 import javax.swing.*;
20 import java.awt.*;
21 import java.util.concurrent.atomic.AtomicReference;
22
23
24
25
26 public class ButtonStart extends JButton {
27 private static final String BUTTON_START_TOOLTIP = "BUTTON_START_TOOLTIP";
28
29
30
31
32 private StateButton state = StateButton.STARTABLE;
33
34 private final AtomicReference<JToolTipI18n> tooltip = new AtomicReference<>(
35 new JToolTipI18n(I18nUtil.valueByKey(ButtonStart.BUTTON_START_TOOLTIP))
36 );
37
38 @Override
39 public JToolTip createToolTip() {
40 if (this.state == StateButton.STARTABLE) {
41 this.tooltip.get().setText(I18nUtil.valueByKey(ButtonStart.BUTTON_START_TOOLTIP));
42 } else if (this.state == StateButton.STOPPABLE) {
43 this.tooltip.get().setText(I18nUtil.valueByKey("BUTTON_STOP_TOOLTIP"));
44 } else if (this.state == StateButton.STOPPING) {
45 this.tooltip.get().setText(I18nUtil.valueByKey("BUTTON_STOPPING_TOOLTIP"));
46 }
47 return this.tooltip.get();
48 }
49
50
51
52
53 public ButtonStart() {
54 this.setName("buttonInUrl");
55 this.setToolTipText(I18nUtil.valueByKey(ButtonStart.BUTTON_START_TOOLTIP));
56 I18nViewUtil.addComponentForKey(ButtonStart.BUTTON_START_TOOLTIP, this.tooltip.get());
57
58 this.setPreferredSize(new Dimension(18, 16));
59 this.setOpaque(false);
60 this.setContentAreaFilled(false);
61 this.setBorderPainted(false);
62 this.setRolloverEnabled(true);
63 this.setIcons();
64 }
65
66 public void setIcons() {
67
68 if (ComponentOrientation.getOrientation(I18nUtil.getCurrentLocale()).isLeftToRight()) {
69 this.setIcon(UiUtil.ARROW.getIcon());
70 this.setRolloverIcon(UiUtil.ARROW_HOVER.getIcon());
71 this.setPressedIcon(UiUtil.ARROW_PRESSED.getIcon());
72 } else {
73 this.setIcon(UiUtil.ARROW_LEFT.getIcon());
74 this.setRolloverIcon(UiUtil.ARROW_LEFT_HOVER.getIcon());
75 this.setPressedIcon(UiUtil.ARROW_LEFT_PRESSED.getIcon());
76 }
77 }
78
79
80
81
82 public void setInjectionReady() {
83 this.state = StateButton.STARTABLE;
84 this.setRolloverEnabled(true);
85 this.setEnabled(true);
86 this.setIcons();
87 }
88
89
90
91
92 public void setInjectionRunning() {
93 this.state = StateButton.STOPPABLE;
94 this.setRolloverEnabled(false);
95 this.setEnabled(true);
96 this.setIcon(UiUtil.CROSS_RED.getIcon());
97 }
98
99
100
101
102
103 public void setInjectionStopping() {
104 this.state = StateButton.STOPPING;
105 this.setRolloverEnabled(false);
106 this.setEnabled(false);
107 this.setIcon(UiUtil.HOURGLASS.getIcon());
108 }
109
110
111
112
113
114 public StateButton getState() {
115 return this.state;
116 }
117 }