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,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
      *

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

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

Loading…
Cancel
Save