|
@@ -25,6 +25,7 @@ package com.dmdirc.addons.ui_swing.components;
|
25
|
25
|
*/
|
26
|
26
|
import com.dmdirc.addons.ui_swing.UIUtilities;
|
27
|
27
|
import com.dmdirc.addons.ui_swing.components.text.TextLabel;
|
|
28
|
+import com.dmdirc.ui.IconManager;
|
28
|
29
|
|
29
|
30
|
import java.awt.Color;
|
30
|
31
|
import java.awt.event.MouseEvent;
|
|
@@ -34,6 +35,7 @@ import java.util.Map;
|
34
|
35
|
|
35
|
36
|
import javax.swing.BorderFactory;
|
36
|
37
|
import javax.swing.JComponent;
|
|
38
|
+import javax.swing.JLabel;
|
37
|
39
|
import javax.swing.JPanel;
|
38
|
40
|
import javax.swing.text.SimpleAttributeSet;
|
39
|
41
|
import javax.swing.text.StyleConstants;
|
|
@@ -56,9 +58,13 @@ public class ToolTipPanel extends JPanel implements MouseListener {
|
56
|
58
|
*/
|
57
|
59
|
private static final long serialVersionUID = -8929794537312606692L;
|
58
|
60
|
/** Default tooltip. */
|
59
|
|
- private final String defaultHelp;
|
|
61
|
+ private String defaultHelp;
|
60
|
62
|
/** Tooltip display. */
|
61
|
63
|
private TextLabel tooltip;
|
|
64
|
+ /** Error icon. */
|
|
65
|
+ private JLabel icon;
|
|
66
|
+ /** Whether or not this is a warning. */
|
|
67
|
+ private String warning = null;
|
62
|
68
|
/** Map of registered components to their tooltips. */
|
63
|
69
|
private final Map<JComponent, String> tooltips;
|
64
|
70
|
|
|
@@ -68,10 +74,11 @@ public class ToolTipPanel extends JPanel implements MouseListener {
|
68
|
74
|
* @param defaultHelp Default help message when idle
|
69
|
75
|
*/
|
70
|
76
|
public ToolTipPanel(final String defaultHelp) {
|
71
|
|
- super(new MigLayout());
|
|
77
|
+ super(new MigLayout("hidemode 3"));
|
72
|
78
|
|
73
|
79
|
this.defaultHelp = defaultHelp;
|
74
|
80
|
this.tooltips = new HashMap<JComponent, String>();
|
|
81
|
+ this.icon = new JLabel(IconManager.getIconManager().getIcon("warning"));
|
75
|
82
|
|
76
|
83
|
setBackground(Color.WHITE);
|
77
|
84
|
setBorder(BorderFactory.createEtchedBorder());
|
|
@@ -79,6 +86,7 @@ public class ToolTipPanel extends JPanel implements MouseListener {
|
79
|
86
|
tooltip = new TextLabel();
|
80
|
87
|
reset();
|
81
|
88
|
|
|
89
|
+ add(icon, "aligny top");
|
82
|
90
|
add(tooltip, "grow, push");
|
83
|
91
|
}
|
84
|
92
|
|
|
@@ -86,11 +94,18 @@ public class ToolTipPanel extends JPanel implements MouseListener {
|
86
|
94
|
* Resets the content of the tooltip.
|
87
|
95
|
*/
|
88
|
96
|
protected void reset() {
|
89
|
|
- tooltip.setText(defaultHelp);
|
90
|
97
|
SimpleAttributeSet sas = new SimpleAttributeSet();
|
91
|
|
- StyleConstants.setItalic(sas, true);
|
92
|
|
- tooltip.getDocument().setParagraphAttributes(0, defaultHelp.length(),
|
93
|
|
- sas, true);
|
|
98
|
+
|
|
99
|
+ if (warning == null || warning.isEmpty()) {
|
|
100
|
+ tooltip.setText(defaultHelp);
|
|
101
|
+ icon.setVisible(false);
|
|
102
|
+ StyleConstants.setItalic(sas, true);
|
|
103
|
+ } else {
|
|
104
|
+ icon.setVisible(true);
|
|
105
|
+ tooltip.setText(warning);
|
|
106
|
+ }
|
|
107
|
+ tooltip.getDocument().setParagraphAttributes(0, tooltip.getDocument().
|
|
108
|
+ getLength(), sas, true);
|
94
|
109
|
}
|
95
|
110
|
|
96
|
111
|
/**
|
|
@@ -102,15 +117,29 @@ public class ToolTipPanel extends JPanel implements MouseListener {
|
102
|
117
|
if (tooltip == null) {
|
103
|
118
|
return;
|
104
|
119
|
}
|
|
120
|
+
|
105
|
121
|
tooltip.setText(text);
|
106
|
122
|
if (tooltip.getDocument() == null || text == null) {
|
107
|
123
|
return;
|
108
|
124
|
}
|
|
125
|
+
|
|
126
|
+ icon.setVisible(false);
|
109
|
127
|
SimpleAttributeSet sas = new SimpleAttributeSet();
|
110
|
128
|
StyleConstants.setItalic(sas, false);
|
111
|
129
|
tooltip.getDocument().setParagraphAttributes(0, text.length(), sas, true);
|
112
|
130
|
}
|
113
|
131
|
|
|
132
|
+ /**
|
|
133
|
+ * Sets whether or not this tooltip should be rendered as a warning.
|
|
134
|
+ *
|
|
135
|
+ * @param warning Warning string, null or empty to reset.
|
|
136
|
+ * @since 0.6.3
|
|
137
|
+ */
|
|
138
|
+ public void setWarning(final String warning) {
|
|
139
|
+ this.warning = warning;
|
|
140
|
+ reset();
|
|
141
|
+ }
|
|
142
|
+
|
114
|
143
|
/**
|
115
|
144
|
* Registers a component with this tooltip handler.
|
116
|
145
|
*
|