Selaa lähdekoodia

Make URLBuilders optional in text labels.

All existing usages will omit a URL Builder, but there doesn't appear to be
any places where it's actually needed.

Change-Id: Ic803610ec59bc5818dab83558889f2f99d312050
Reviewed-on: http://gerrit.dmdirc.com/3111
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.8
Chris Smith 10 vuotta sitten
vanhempi
commit
f87e5d0188

+ 4
- 2
src/com/dmdirc/addons/ui_swing/components/text/DMDircHTMLEditorKit.java Näytä tiedosto

@@ -24,6 +24,7 @@ package com.dmdirc.addons.ui_swing.components.text;
24 24
 
25 25
 import com.dmdirc.util.URLBuilder;
26 26
 
27
+import javax.annotation.Nullable;
27 28
 import javax.swing.text.ViewFactory;
28 29
 import javax.swing.text.html.HTMLEditorKit;
29 30
 
@@ -38,9 +39,10 @@ public class DMDircHTMLEditorKit extends HTMLEditorKit {
38 39
     /**
39 40
      * Creates a new instance of {@link DMDircHTMLEditorKit}.
40 41
      *
41
-     * @param urlBuilder The URL builder to use to construct image URLs.
42
+     * @param urlBuilder The URL builder to use to construct image URLs. If {@code null}, then only
43
+     * standard URLs will be handled (not DMDirc-specific ones).
42 44
      */
43
-    public DMDircHTMLEditorKit(final URLBuilder urlBuilder) {
45
+    public DMDircHTMLEditorKit(@Nullable final URLBuilder urlBuilder) {
44 46
         defaultFactory = new DMDircHTMLFactory(urlBuilder);
45 47
     }
46 48
 

+ 10
- 2
src/com/dmdirc/addons/ui_swing/components/text/DMDircHTMLFactory.java Näytä tiedosto

@@ -24,6 +24,7 @@ package com.dmdirc.addons.ui_swing.components.text;
24 24
 
25 25
 import com.dmdirc.util.URLBuilder;
26 26
 
27
+import javax.annotation.Nullable;
27 28
 import javax.swing.text.Element;
28 29
 import javax.swing.text.View;
29 30
 import javax.swing.text.html.HTMLEditorKit.HTMLFactory;
@@ -35,9 +36,16 @@ import javax.swing.text.html.ImageView;
35 36
 public class DMDircHTMLFactory extends HTMLFactory {
36 37
 
37 38
     /** The URL builder to use to construct image URLs. */
39
+    @Nullable
38 40
     private final URLBuilder urlBuilder;
39 41
 
40
-    public DMDircHTMLFactory(final URLBuilder urlBuilder) {
42
+    /**
43
+     * Creates a new instance of {@link DMDircHTMLFactory}.
44
+     *
45
+     * @param urlBuilder The URL builder to use for images. If {@code null}, then only standard
46
+     * URLs will be handled in image views (not DMDirc-specific ones).
47
+     */
48
+    public DMDircHTMLFactory(@Nullable final URLBuilder urlBuilder) {
41 49
         this.urlBuilder = urlBuilder;
42 50
     }
43 51
 
@@ -45,7 +53,7 @@ public class DMDircHTMLFactory extends HTMLFactory {
45 53
     @Override
46 54
     public View create(final Element elem) {
47 55
         final View view = super.create(elem);
48
-        if (view instanceof ImageView) {
56
+        if (view instanceof ImageView && urlBuilder != null) {
49 57
             return new DMDircImageView(urlBuilder, elem);
50 58
         }
51 59
         return view;

+ 29
- 1
src/com/dmdirc/addons/ui_swing/components/text/TextLabel.java Näytä tiedosto

@@ -28,6 +28,7 @@ import java.awt.Color;
28 28
 import java.awt.Font;
29 29
 import java.awt.Insets;
30 30
 
31
+import javax.annotation.Nullable;
31 32
 import javax.swing.JTextPane;
32 33
 import javax.swing.UIManager;
33 34
 import javax.swing.plaf.basic.BasicTextPaneUI;
@@ -54,6 +55,9 @@ public class TextLabel extends JTextPane {
54 55
 
55 56
     /**
56 57
      * Creates a new instance of TextLabel.
58
+     *
59
+     * <p>Labels constructed without a {@link URLBuilder} will not be able to resolve
60
+     * DMDirc-specific URLs in image tags.
57 61
      */
58 62
     public TextLabel() {
59 63
         this(null, true);
@@ -62,6 +66,9 @@ public class TextLabel extends JTextPane {
62 66
     /**
63 67
      * Creates a new instance of TextLabel.
64 68
      *
69
+     * <p>Labels constructed without a {@link URLBuilder} will not be able to resolve
70
+     * DMDirc-specific URLs in image tags.
71
+     *
65 72
      * @param justified Justify the text?
66 73
      */
67 74
     public TextLabel(final boolean justified) {
@@ -71,6 +78,9 @@ public class TextLabel extends JTextPane {
71 78
     /**
72 79
      * Creates a new instance of TextLabel.
73 80
      *
81
+     * <p>Labels constructed without a {@link URLBuilder} will not be able to resolve
82
+     * DMDirc-specific URLs in image tags.
83
+     *
74 84
      * @param text Text to display
75 85
      */
76 86
     public TextLabel(final String text) {
@@ -80,12 +90,30 @@ public class TextLabel extends JTextPane {
80 90
     /**
81 91
      * Creates a new instance of TextLabel.
82 92
      *
93
+     * <p>Labels constructed without a {@link URLBuilder} will not be able to resolve
94
+     * DMDirc-specific URLs in image tags.
95
+     *
83 96
      * @param text Text to display
84 97
      * @param justified Justify the text?
85 98
      */
86 99
     public TextLabel(final String text, final boolean justified) {
100
+        this(null, text, justified);
101
+    }
102
+
103
+    /**
104
+     * Creates a new instance of TextLabel.
105
+     *
106
+     * @param urlBuilder The URL builder to use for embedded image URLs. If {@code null}, then only
107
+     * standard URLs will be handled in image tags (not DMDirc-specific ones).
108
+     * @param text Text to display
109
+     * @param justified Justify the text?
110
+     */
111
+    public TextLabel(
112
+            @Nullable final URLBuilder urlBuilder,
113
+            final String text,
114
+            final boolean justified) {
87 115
         super(new DefaultStyledDocument());
88
-        setEditorKit(new DMDircHTMLEditorKit(URLBuilder.getInstance()));
116
+        setEditorKit(new DMDircHTMLEditorKit(urlBuilder));
89 117
         setUI(new BasicTextPaneUI());
90 118
 
91 119
         final StyleSheet styleSheet = ((HTMLDocument) getDocument()).

Loading…
Peruuta
Tallenna