Browse Source

Swing prefs UI renders warning messages from prefs categories

Fixes issue 3574

Change-Id: Ie97f963e04ea08825d2b1bc8988a803ed17e3b12
Reviewed-on: http://gerrit.dmdirc.com/569
Automatic-Compile: Gregory Holmes <greboid@dmdirc.com>
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.6.3
Gregory Holmes 14 years ago
parent
commit
73de4ff0bc

+ 35
- 6
src/com/dmdirc/addons/ui_swing/components/ToolTipPanel.java View File

25
  */
25
  */
26
 import com.dmdirc.addons.ui_swing.UIUtilities;
26
 import com.dmdirc.addons.ui_swing.UIUtilities;
27
 import com.dmdirc.addons.ui_swing.components.text.TextLabel;
27
 import com.dmdirc.addons.ui_swing.components.text.TextLabel;
28
+import com.dmdirc.ui.IconManager;
28
 
29
 
29
 import java.awt.Color;
30
 import java.awt.Color;
30
 import java.awt.event.MouseEvent;
31
 import java.awt.event.MouseEvent;
34
 
35
 
35
 import javax.swing.BorderFactory;
36
 import javax.swing.BorderFactory;
36
 import javax.swing.JComponent;
37
 import javax.swing.JComponent;
38
+import javax.swing.JLabel;
37
 import javax.swing.JPanel;
39
 import javax.swing.JPanel;
38
 import javax.swing.text.SimpleAttributeSet;
40
 import javax.swing.text.SimpleAttributeSet;
39
 import javax.swing.text.StyleConstants;
41
 import javax.swing.text.StyleConstants;
56
      */
58
      */
57
     private static final long serialVersionUID = -8929794537312606692L;
59
     private static final long serialVersionUID = -8929794537312606692L;
58
     /** Default tooltip. */
60
     /** Default tooltip. */
59
-    private final String defaultHelp;
61
+    private String defaultHelp;
60
     /** Tooltip display. */
62
     /** Tooltip display. */
61
     private TextLabel tooltip;
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
     /** Map of registered components to their tooltips. */
68
     /** Map of registered components to their tooltips. */
63
     private final Map<JComponent, String> tooltips;
69
     private final Map<JComponent, String> tooltips;
64
 
70
 
68
      * @param defaultHelp Default help message when idle
74
      * @param defaultHelp Default help message when idle
69
      */
75
      */
70
     public ToolTipPanel(final String defaultHelp) {
76
     public ToolTipPanel(final String defaultHelp) {
71
-        super(new MigLayout());
77
+        super(new MigLayout("hidemode 3"));
72
 
78
 
73
         this.defaultHelp = defaultHelp;
79
         this.defaultHelp = defaultHelp;
74
         this.tooltips = new HashMap<JComponent, String>();
80
         this.tooltips = new HashMap<JComponent, String>();
81
+        this.icon = new JLabel(IconManager.getIconManager().getIcon("warning"));
75
 
82
 
76
         setBackground(Color.WHITE);
83
         setBackground(Color.WHITE);
77
         setBorder(BorderFactory.createEtchedBorder());
84
         setBorder(BorderFactory.createEtchedBorder());
79
         tooltip = new TextLabel();
86
         tooltip = new TextLabel();
80
         reset();
87
         reset();
81
 
88
 
89
+        add(icon, "aligny top");
82
         add(tooltip, "grow, push");
90
         add(tooltip, "grow, push");
83
     }
91
     }
84
 
92
 
86
      * Resets the content of the tooltip.
94
      * Resets the content of the tooltip.
87
      */
95
      */
88
     protected void reset() {
96
     protected void reset() {
89
-        tooltip.setText(defaultHelp);
90
         SimpleAttributeSet sas = new SimpleAttributeSet();
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
         if (tooltip == null) {
117
         if (tooltip == null) {
103
             return;
118
             return;
104
         }
119
         }
120
+        
105
         tooltip.setText(text);
121
         tooltip.setText(text);
106
         if (tooltip.getDocument() == null || text == null) {
122
         if (tooltip.getDocument() == null || text == null) {
107
             return;
123
             return;
108
         }
124
         }
125
+
126
+        icon.setVisible(false);
109
         SimpleAttributeSet sas = new SimpleAttributeSet();
127
         SimpleAttributeSet sas = new SimpleAttributeSet();
110
         StyleConstants.setItalic(sas, false);
128
         StyleConstants.setItalic(sas, false);
111
         tooltip.getDocument().setParagraphAttributes(0, text.length(), sas, true);
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
      * Registers a component with this tooltip handler.
144
      * Registers a component with this tooltip handler.
116
      *
145
      *

+ 9
- 2
src/com/dmdirc/addons/ui_swing/dialogs/prefs/CategoryPanel.java View File

29
 import com.dmdirc.addons.ui_swing.components.ToolTipPanel;
29
 import com.dmdirc.addons.ui_swing.components.ToolTipPanel;
30
 import com.dmdirc.config.prefs.PreferencesCategory;
30
 import com.dmdirc.config.prefs.PreferencesCategory;
31
 
31
 
32
+import java.awt.Color;
32
 import java.awt.Window;
33
 import java.awt.Window;
33
 import java.util.Collections;
34
 import java.util.Collections;
34
 import java.util.HashMap;
35
 import java.util.HashMap;
116
         title = new TitlePanel(BorderFactory.createEtchedBorder(),
117
         title = new TitlePanel(BorderFactory.createEtchedBorder(),
117
                 "Preferences");
118
                 "Preferences");
118
         tooltip = new ToolTipPanel("Hover over a setting to see a " +
119
         tooltip = new ToolTipPanel("Hover over a setting to see a " +
119
-                "description, if available.");
120
+                    "description, if available.");
120
 
121
 
121
         add(title, "pushx, growx, h 45!");
122
         add(title, "pushx, growx, h 45!");
122
         add(scrollPane, "grow, push");
123
         add(scrollPane, "grow, push");
123
-        add(tooltip, "pushx, growx, h 65!");
124
+        add(tooltip, "pushx, growx, h 70!");
124
 
125
 
125
         panels.put(null, loading);
126
         panels.put(null, loading);
126
         setCategory(category);
127
         setCategory(category);
193
     public void setCategory(final PreferencesCategory category) {
194
     public void setCategory(final PreferencesCategory category) {
194
         this.category = category;
195
         this.category = category;
195
 
196
 
197
+        if (category != null) {
198
+            tooltip.setWarning(category.getWarning());
199
+        } else {
200
+            tooltip.setWarning(null);
201
+        }
202
+
196
         if (!panels.containsKey(category)) {
203
         if (!panels.containsKey(category)) {
197
             UIUtilities.invokeAndWait(new Runnable() {
204
             UIUtilities.invokeAndWait(new Runnable() {
198
 
205
 

Loading…
Cancel
Save