Browse Source

ErrorManager now outputs a trace along with the message to System.err is there are no ready error listeners

Fixed an assertion from the previous commit
TextPane passes a frame when stylising strings

git-svn-id: http://svn.dmdirc.com/trunk@2425 00569f92-eb28-0410-84fd-f71c24880f
tags/0.5.5
Gregory Holmes 16 years ago
parent
commit
5cc131f190

+ 1
- 1
src/com/dmdirc/actions/ActionManager.java View File

@@ -104,7 +104,7 @@ public final class ActionManager {
104 104
      */
105 105
     public static void registerWrapper(final ActionWrapper wrapper) {
106 106
         Logger.doAssertion(wrapper != null && wrapper.getGroupName() != null
107
-                 && wrapper.getGroupName().isEmpty());
107
+                 && !wrapper.getGroupName().isEmpty());
108 108
         
109 109
         actionWrappers.add(wrapper);
110 110
     }

+ 8
- 1
src/com/dmdirc/commandparser/commands/global/Debug.java View File

@@ -280,9 +280,16 @@ public class Debug extends GlobalCommand implements IntelligentCommand {
280 280
     }
281 281
     
282 282
     /** Reverse value comparator for a map entry. */
283
-    private static class ValueComparator implements 
283
+    private static class ValueComparator implements
284 284
             Comparator<Entry<String, Integer>>, Serializable {
285 285
         
286
+        /**
287
+         * A version number for this class. It should be changed whenever the
288
+         * class structure is changed (or anything else that would prevent
289
+         * serialized objects being unserialized with the new class).
290
+         */
291
+        private static final long serialVersionUID = 1;
292
+        
286 293
         /** Instantiates a new ValueComparator. */
287 294
         public ValueComparator() {
288 295
             super();

+ 6
- 0
src/com/dmdirc/logger/ErrorManager.java View File

@@ -266,6 +266,9 @@ public final class ErrorManager implements Serializable {
266 266
         if (firedListeners == 0) {
267 267
             System.err.println("An error has occurred: " + error.getLevel()
268 268
             + ": " + error.getMessage());
269
+            for (String line : error.getTrace()) {
270
+                System.err.println("\t" + line);
271
+            }
269 272
         }
270 273
     }
271 274
     
@@ -289,6 +292,9 @@ public final class ErrorManager implements Serializable {
289 292
          
290 293
         if (firedListeners == 0) {
291 294
             System.err.println("A fatal has occurred: " + error.getMessage());
295
+            for (String line : error.getTrace()) {
296
+                System.err.println("\t" + line);
297
+            }
292 298
         }
293 299
     }
294 300
     

+ 1
- 1
src/com/dmdirc/ui/swing/components/Frame.java View File

@@ -224,7 +224,7 @@ public abstract class Frame extends JInternalFrame implements Window,
224 224
      * Initialises the components for this frame.
225 225
      */
226 226
     private void initComponents() {
227
-        setTextPane(new TextPane());
227
+        setTextPane(new TextPane(getContainer()));
228 228
         
229 229
         getTextPane().addMouseListener(this);
230 230
         getTextPane().addKeyListener(this);

+ 37
- 17
src/com/dmdirc/ui/swing/textpane/TextPane.java View File

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.ui.swing.textpane;
24 24
 
25
+import com.dmdirc.FrameContainer;
25 26
 import com.dmdirc.logger.ErrorLevel;
26 27
 import com.dmdirc.logger.Logger;
27 28
 import com.dmdirc.ui.messages.IRCTextAttribute;
@@ -66,7 +67,7 @@ public final class TextPane extends JComponent implements AdjustmentListener,
66 67
      * structure is changed (or anything else that would prevent serialized
67 68
      * objects being unserialized with the new class).
68 69
      */
69
-    private static final long serialVersionUID = 4;
70
+    private static final long serialVersionUID = 5;
70 71
     
71 72
     /** Scrollbar for the component. */
72 73
     private final JScrollBar scrollBar;
@@ -74,14 +75,21 @@ public final class TextPane extends JComponent implements AdjustmentListener,
74 75
     private final TextPaneCanvas canvas;
75 76
     /** IRCDocument. */
76 77
     private final IRCDocument document;
77
-    
78
+    /** Parent Frame. */
79
+    private final FrameContainer frame;
78 80
     /** Listener list. */
79 81
     private final EventListenerList textPaneListeners;
80 82
     
81
-    /** Creates a new instance of TextPane. */
82
-    public TextPane() {
83
+    /** 
84
+     * Creates a new instance of TextPane. 
85
+     *
86
+     * @param frame Parent Frame
87
+     */
88
+    public TextPane(final FrameContainer frame) {
83 89
         super();
84 90
         
91
+        this.frame = frame;
92
+        
85 93
         textPaneListeners = new EventListenerList();
86 94
         
87 95
         document = new IRCDocument();
@@ -135,7 +143,7 @@ public final class TextPane extends JComponent implements AdjustmentListener,
135 143
      */
136 144
     public void addStyledString(final String[] strings) {
137 145
         final AttributedString text = styledDocumentToAttributedString(
138
-                Styliser.getStyledString(strings, null));
146
+                Styliser.getStyledString(strings, frame));
139 147
         
140 148
         if (text.getIterator().getEndIndex() == 0) {
141 149
             addText(new AttributedString("\n"));
@@ -151,12 +159,15 @@ public final class TextPane extends JComponent implements AdjustmentListener,
151 159
      *
152 160
      * @return AttributedString representing the specified StyledDocument
153 161
      */
154
-    public static AttributedString styledDocumentToAttributedString(final StyledDocument doc) {
155
-        //Now lets get hacky, loop through the styled document and add all styles to an attributedString
162
+    public static AttributedString styledDocumentToAttributedString(
163
+            final StyledDocument doc) {
164
+        //Now lets get hacky, loop through the styled document and add all 
165
+        //styles to an attributedString
156 166
         AttributedString attString = null;
157 167
         final Element line = doc.getParagraphElement(0);
158 168
         try {
159
-            attString = new AttributedString(line.getDocument().getText(0, line.getDocument().getLength()));
169
+            attString = new AttributedString(line.getDocument().getText(0, 
170
+                    line.getDocument().getLength()));
160 171
         } catch (BadLocationException ex) {
161 172
             Logger.userError(ErrorLevel.MEDIUM,
162 173
                     "Unable to insert styled string: " + ex.getMessage());
@@ -173,39 +184,48 @@ public final class TextPane extends JComponent implements AdjustmentListener,
173 184
                 if (attrib == IRCTextAttribute.HYPERLINK) {
174 185
                     //Hyperlink
175 186
                     attString.addAttribute(IRCTextAttribute.HYPERLINK,
176
-                            as.getAttribute(attrib), element.getStartOffset(), element.getEndOffset());
187
+                            as.getAttribute(attrib), element.getStartOffset(), 
188
+                            element.getEndOffset());
177 189
                 } else if (attrib == IRCTextAttribute.NICKNAME) {
178 190
                     //Nicknames
179 191
                     attString.addAttribute(IRCTextAttribute.NICKNAME,
180
-                            as.getAttribute(attrib), element.getStartOffset(), element.getEndOffset());
192
+                            as.getAttribute(attrib), element.getStartOffset(), 
193
+                            element.getEndOffset());
181 194
                 } else if (attrib == IRCTextAttribute.CHANNEL) {
182 195
                     //Channels
183 196
                     attString.addAttribute(IRCTextAttribute.CHANNEL,
184
-                            as.getAttribute(attrib), element.getStartOffset(), element.getEndOffset());
197
+                            as.getAttribute(attrib), element.getStartOffset(), 
198
+                            element.getEndOffset());
185 199
                 } else if (attrib == ColorConstants.Foreground) {
186 200
                     //Foreground
187 201
                     attString.addAttribute(TextAttribute.FOREGROUND,
188
-                            as.getAttribute(attrib), element.getStartOffset(), element.getEndOffset());
202
+                            as.getAttribute(attrib), element.getStartOffset(), 
203
+                            element.getEndOffset());
189 204
                 } else if (attrib == ColorConstants.Background) {
190 205
                     //Background
191 206
                     attString.addAttribute(TextAttribute.BACKGROUND,
192
-                            as.getAttribute(attrib), element.getStartOffset(), element.getEndOffset());
207
+                            as.getAttribute(attrib), element.getStartOffset(), 
208
+                            element.getEndOffset());
193 209
                 } else if (attrib == FontConstants.Bold) {
194 210
                     //Bold
195 211
                     attString.addAttribute(TextAttribute.WEIGHT,
196
-                            TextAttribute.WEIGHT_BOLD, element.getStartOffset(), element.getEndOffset());
212
+                            TextAttribute.WEIGHT_BOLD, element.getStartOffset(), 
213
+                            element.getEndOffset());
197 214
                 } else if (attrib == FontConstants.Family) {
198 215
                     //Family
199 216
                     attString.addAttribute(TextAttribute.FAMILY,
200
-                            as.getAttribute(attrib), element.getStartOffset(), element.getEndOffset());
217
+                            as.getAttribute(attrib), element.getStartOffset(), 
218
+                            element.getEndOffset());
201 219
                 } else if (attrib == FontConstants.Italic) {
202 220
                     //italics
203 221
                     attString.addAttribute(TextAttribute.POSTURE,
204
-                            TextAttribute.POSTURE_OBLIQUE, element.getStartOffset(), element.getEndOffset());
222
+                            TextAttribute.POSTURE_OBLIQUE, element.getStartOffset(), 
223
+                            element.getEndOffset());
205 224
                 } else if (attrib == CharacterConstants.Underline) {
206 225
                     //Underline
207 226
                     attString.addAttribute(TextAttribute.UNDERLINE,
208
-                            TextAttribute.UNDERLINE_ON, element.getStartOffset(), element.getEndOffset());
227
+                            TextAttribute.UNDERLINE_ON, element.getStartOffset(), 
228
+                            element.getEndOffset());
209 229
                 }
210 230
             }
211 231
         }

Loading…
Cancel
Save