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
28 private static final String BUTTON_START_TOOLTIP = "BUTTON_START_TOOLTIP";
29 public static final String BUTTON_IN_URL = "buttonInUrl";
30
31
32
33
34 private StateButton state = StateButton.STARTABLE;
35
36 private final AtomicReference<JToolTipI18n> tooltip = new AtomicReference<>(
37 new JToolTipI18n(I18nUtil.valueByKey(ButtonStart.BUTTON_START_TOOLTIP))
38 );
39
40 @Override
41 public JToolTip createToolTip() {
42 if (this.state == StateButton.STARTABLE) {
43 this.tooltip.get().setText(I18nUtil.valueByKey(ButtonStart.BUTTON_START_TOOLTIP));
44 } else if (this.state == StateButton.STOPPABLE) {
45 this.tooltip.get().setText(I18nUtil.valueByKey("BUTTON_STOP_TOOLTIP"));
46 } else if (this.state == StateButton.STOPPING) {
47 this.tooltip.get().setText(I18nUtil.valueByKey("BUTTON_STOPPING_TOOLTIP"));
48 }
49 return this.tooltip.get();
50 }
51
52
53
54
55 public ButtonStart() {
56 this.setName(ButtonStart.BUTTON_IN_URL);
57 this.setToolTipText(I18nUtil.valueByKey(ButtonStart.BUTTON_START_TOOLTIP));
58 I18nViewUtil.addComponentForKey(ButtonStart.BUTTON_START_TOOLTIP, this.tooltip.get());
59
60 this.setPreferredSize(new Dimension(18, 16));
61 this.setOpaque(false);
62 this.setContentAreaFilled(false);
63 this.setBorderPainted(false);
64 this.setRolloverEnabled(true);
65 this.setIcons();
66 }
67
68 public void setIcons() {
69
70 if (ComponentOrientation.getOrientation(I18nUtil.getCurrentLocale()).isLeftToRight()) {
71 this.setIcon(UiUtil.ARROW.getIcon());
72 this.setRolloverIcon(UiUtil.ARROW_HOVER.getIcon());
73 this.setPressedIcon(UiUtil.ARROW_PRESSED.getIcon());
74 } else {
75 this.setIcon(UiUtil.ARROW_LEFT.getIcon());
76 this.setRolloverIcon(UiUtil.ARROW_LEFT_HOVER.getIcon());
77 this.setPressedIcon(UiUtil.ARROW_LEFT_PRESSED.getIcon());
78 }
79 }
80
81
82
83
84 public void setInjectionReady() {
85 this.state = StateButton.STARTABLE;
86 this.setRolloverEnabled(true);
87 this.setEnabled(true);
88 this.setIcons();
89 }
90
91
92
93
94 public void setInjectionRunning() {
95 this.state = StateButton.STOPPABLE;
96 this.setRolloverEnabled(false);
97 this.setEnabled(true);
98 this.setIcon(UiUtil.CROSS_RED.getIcon());
99 }
100
101
102
103
104
105 public void setInjectionStopping() {
106 this.state = StateButton.STOPPING;
107 this.setRolloverEnabled(false);
108 this.setEnabled(false);
109 this.setIcon(UiUtil.HOURGLASS.getIcon());
110 }
111
112
113
114
115
116 public StateButton getState() {
117 return this.state;
118 }
119 }