Browse Source

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 years ago
parent
commit
f87e5d0188

+ 4
- 2
src/com/dmdirc/addons/ui_swing/components/text/DMDircHTMLEditorKit.java View File

24
 
24
 
25
 import com.dmdirc.util.URLBuilder;
25
 import com.dmdirc.util.URLBuilder;
26
 
26
 
27
+import javax.annotation.Nullable;
27
 import javax.swing.text.ViewFactory;
28
 import javax.swing.text.ViewFactory;
28
 import javax.swing.text.html.HTMLEditorKit;
29
 import javax.swing.text.html.HTMLEditorKit;
29
 
30
 
38
     /**
39
     /**
39
      * Creates a new instance of {@link DMDircHTMLEditorKit}.
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
         defaultFactory = new DMDircHTMLFactory(urlBuilder);
46
         defaultFactory = new DMDircHTMLFactory(urlBuilder);
45
     }
47
     }
46
 
48
 

+ 10
- 2
src/com/dmdirc/addons/ui_swing/components/text/DMDircHTMLFactory.java View File

24
 
24
 
25
 import com.dmdirc.util.URLBuilder;
25
 import com.dmdirc.util.URLBuilder;
26
 
26
 
27
+import javax.annotation.Nullable;
27
 import javax.swing.text.Element;
28
 import javax.swing.text.Element;
28
 import javax.swing.text.View;
29
 import javax.swing.text.View;
29
 import javax.swing.text.html.HTMLEditorKit.HTMLFactory;
30
 import javax.swing.text.html.HTMLEditorKit.HTMLFactory;
35
 public class DMDircHTMLFactory extends HTMLFactory {
36
 public class DMDircHTMLFactory extends HTMLFactory {
36
 
37
 
37
     /** The URL builder to use to construct image URLs. */
38
     /** The URL builder to use to construct image URLs. */
39
+    @Nullable
38
     private final URLBuilder urlBuilder;
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
         this.urlBuilder = urlBuilder;
49
         this.urlBuilder = urlBuilder;
42
     }
50
     }
43
 
51
 
45
     @Override
53
     @Override
46
     public View create(final Element elem) {
54
     public View create(final Element elem) {
47
         final View view = super.create(elem);
55
         final View view = super.create(elem);
48
-        if (view instanceof ImageView) {
56
+        if (view instanceof ImageView && urlBuilder != null) {
49
             return new DMDircImageView(urlBuilder, elem);
57
             return new DMDircImageView(urlBuilder, elem);
50
         }
58
         }
51
         return view;
59
         return view;

+ 29
- 1
src/com/dmdirc/addons/ui_swing/components/text/TextLabel.java View File

28
 import java.awt.Font;
28
 import java.awt.Font;
29
 import java.awt.Insets;
29
 import java.awt.Insets;
30
 
30
 
31
+import javax.annotation.Nullable;
31
 import javax.swing.JTextPane;
32
 import javax.swing.JTextPane;
32
 import javax.swing.UIManager;
33
 import javax.swing.UIManager;
33
 import javax.swing.plaf.basic.BasicTextPaneUI;
34
 import javax.swing.plaf.basic.BasicTextPaneUI;
54
 
55
 
55
     /**
56
     /**
56
      * Creates a new instance of TextLabel.
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
     public TextLabel() {
62
     public TextLabel() {
59
         this(null, true);
63
         this(null, true);
62
     /**
66
     /**
63
      * Creates a new instance of TextLabel.
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
      * @param justified Justify the text?
72
      * @param justified Justify the text?
66
      */
73
      */
67
     public TextLabel(final boolean justified) {
74
     public TextLabel(final boolean justified) {
71
     /**
78
     /**
72
      * Creates a new instance of TextLabel.
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
      * @param text Text to display
84
      * @param text Text to display
75
      */
85
      */
76
     public TextLabel(final String text) {
86
     public TextLabel(final String text) {
80
     /**
90
     /**
81
      * Creates a new instance of TextLabel.
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
      * @param text Text to display
96
      * @param text Text to display
84
      * @param justified Justify the text?
97
      * @param justified Justify the text?
85
      */
98
      */
86
     public TextLabel(final String text, final boolean justified) {
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
         super(new DefaultStyledDocument());
115
         super(new DefaultStyledDocument());
88
-        setEditorKit(new DMDircHTMLEditorKit(URLBuilder.getInstance()));
116
+        setEditorKit(new DMDircHTMLEditorKit(urlBuilder));
89
         setUI(new BasicTextPaneUI());
117
         setUI(new BasicTextPaneUI());
90
 
118
 
91
         final StyleSheet styleSheet = ((HTMLDocument) getDocument()).
119
         final StyleSheet styleSheet = ((HTMLDocument) getDocument()).

Loading…
Cancel
Save