瀏覽代碼

Moves private editor kits to the text components package and makes them public

Change-Id: I398028d98b2bd1902ee8ec26d58f21a4ad87436a
Reviewed-on: http://gerrit.dmdirc.com/757
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.6.3
Gregory Holmes 14 年之前
父節點
當前提交
f80bd498fb

+ 1
- 145
src/com/dmdirc/addons/ui_swing/components/TopicBar.java 查看文件

@@ -29,6 +29,7 @@ import com.dmdirc.addons.ui_swing.SwingController;
29 29
 import com.dmdirc.addons.ui_swing.UIUtilities;
30 30
 import com.dmdirc.addons.ui_swing.actions.NoNewlinesPasteAction;
31 31
 import com.dmdirc.addons.ui_swing.components.frames.ChannelFrame;
32
+import com.dmdirc.addons.ui_swing.components.text.WrapEditorKit;
32 33
 import com.dmdirc.config.IdentityManager;
33 34
 import com.dmdirc.interfaces.ConfigChangeListener;
34 35
 import com.dmdirc.interfaces.TopicChangeListener;
@@ -54,22 +55,10 @@ import javax.swing.event.DocumentEvent;
54 55
 import javax.swing.event.DocumentListener;
55 56
 import javax.swing.event.HyperlinkEvent;
56 57
 import javax.swing.event.HyperlinkListener;
57
-import javax.swing.text.AbstractDocument;
58
-import javax.swing.text.BadLocationException;
59
-import javax.swing.text.BoxView;
60
-import javax.swing.text.ComponentView;
61 58
 import javax.swing.text.DefaultStyledDocument;
62
-import javax.swing.text.Element;
63
-import javax.swing.text.GlyphView;
64
-import javax.swing.text.IconView;
65
-import javax.swing.text.LabelView;
66
-import javax.swing.text.ParagraphView;
67 59
 import javax.swing.text.SimpleAttributeSet;
68 60
 import javax.swing.text.StyleConstants;
69 61
 import javax.swing.text.StyledDocument;
70
-import javax.swing.text.StyledEditorKit;
71
-import javax.swing.text.View;
72
-import javax.swing.text.ViewFactory;
73 62
 
74 63
 import net.miginfocom.swing.MigLayout;
75 64
 
@@ -528,137 +517,4 @@ public class TopicBar extends JComponent implements ActionListener,
528 517
         validateTopic();
529 518
     }
530 519
 }
531
-
532
-/**
533
- * @author Stanislav Lapitsky
534
- * @version 1.0
535
- */
536
-class WrapEditorKit extends StyledEditorKit {
537
-
538
-    private static final long serialVersionUID = 1;
539
-    private ViewFactory defaultFactory = new WrapColumnFactory();
540
-
541
-    /** {@inheritDoc} */
542
-    @Override
543
-    public ViewFactory getViewFactory() {
544
-        return defaultFactory;
545
-    }
546
-}
547
-
548
-/**
549
- * @author Stanislav Lapitsky
550
- * @version 1.0
551
- */
552
-class WrapColumnFactory implements ViewFactory {
553
-
554
-    /** {@inheritDoc} */
555
-    @Override
556
-    public View create(final Element elem) {
557
-        String kind = elem.getName();
558
-        if (kind != null) {
559
-            if (kind.equals(AbstractDocument.ContentElementName)) {
560
-                return new WrapLabelView(elem);
561
-            } else if (kind.equals(AbstractDocument.ParagraphElementName)) {
562
-                return new NoWrapParagraphView(elem);
563
-            } else if (kind.equals(AbstractDocument.SectionElementName)) {
564
-                return new BoxView(elem, View.Y_AXIS);
565
-            } else if (kind.equals(StyleConstants.ComponentElementName)) {
566
-                return new ComponentView(elem);
567
-            } else if (kind.equals(StyleConstants.IconElementName)) {
568
-                return new IconView(elem);
569
-            }
570
-        }
571
-
572
-        // default to text display
573
-        return new LabelView(elem);
574
-    }
575
-}
576
-
577
-/**
578
- * @author Stanislav Lapitsky
579
- * @version 1.0
580
- */
581
-class NoWrapParagraphView extends ParagraphView {
582
-
583
-    /**
584
-     * Creates a new no wrap paragraph view.
585
-     *
586
-     * @param elem Element to view
587
-     */
588
-    public NoWrapParagraphView(final Element elem) {
589
-        super(elem);
590
-    }
591
-
592
-    /** {@inheritDoc} */
593
-    @Override
594
-    public void layout(final int width, final int height) {
595
-        super.layout(Short.MAX_VALUE, height);
596
-    }
597
-
598
-    /** {@inheritDoc} */
599
-    @Override
600
-    public float getMinimumSpan(final int axis) {
601
-        return super.getPreferredSpan(axis);
602
-    }
603
-}
604
-
605
-/**
606
- * @author Stanislav Lapitsky
607
- * @version 1.0
608
- */
609
-class WrapLabelView extends LabelView {
610
-
611
-    /**
612
-     * Creates a new wrap label view.
613
-     *
614
-     * @param elem Element to view
615
-     */
616
-    public WrapLabelView(final Element elem) {
617
-        super(elem);
618
-    }
619
-
620
-    /** {@inheritDoc} */
621
-    @Override
622
-    public int getBreakWeight(final int axis, final float pos, final float len) {
623
-        if (axis == View.X_AXIS) {
624
-            checkPainter();
625
-            int p0 = getStartOffset();
626
-            int p1 = getGlyphPainter().getBoundedPosition(this, p0, pos, len);
627
-            if (p1 == p0) {
628
-                // can't even fit a single character
629
-                return View.BadBreakWeight;
630
-            }
631
-            try {
632
-                //if the view contains line break char return forced break
633
-                if (getDocument().getText(p0, p1 - p0).indexOf("\r") >= 0) {
634
-                    return View.ForcedBreakWeight;
635
-                }
636
-            } catch (BadLocationException ex) {
637
-                //should never happen
638
-            }
639
-        }
640
-        return super.getBreakWeight(axis, pos, len);
641
-    }
642
-
643
-    /** {@inheritDoc} */
644
-    @Override
645
-    public View breakView(final int axis, final int p0, final float pos,
646
-            final float len) {
647
-        if (axis == View.X_AXIS) {
648
-            checkPainter();
649
-            int p1 = getGlyphPainter().getBoundedPosition(this, p0, pos, len);
650
-            try {
651
-                //if the view contains line break char break the view
652
-                int index = getDocument().getText(p0, p1 - p0).indexOf("\r");
653
-                if (index >= 0) {
654
-                    GlyphView v = (GlyphView) createFragment(p0, p0 + index + 1);
655
-                    return v;
656
-                }
657
-            } catch (BadLocationException ex) {
658
-                //should never happen
659
-            }
660
-        }
661
-        return super.breakView(axis, p0, pos, len);
662
-    }
663
-}
664 520
        

+ 42
- 0
src/com/dmdirc/addons/ui_swing/components/text/DMDircHTMLEditorKit.java 查看文件

@@ -0,0 +1,42 @@
1
+/*
2
+ * 
3
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
4
+ * 
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ * 
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ * 
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+
24
+package com.dmdirc.addons.ui_swing.components.text;
25
+
26
+import javax.swing.text.ViewFactory;
27
+import javax.swing.text.html.HTMLEditorKit;
28
+
29
+/**
30
+ * DMDirc html kit, extends HTMLEditor kit to use DMDircHTMLFactory.
31
+ */
32
+public class DMDircHTMLEditorKit extends HTMLEditorKit {
33
+
34
+    private static final long serialVersionUID = 1;
35
+    private ViewFactory defaultFactory = new DMDircHTMLFactory();
36
+
37
+    /** {@inheritDoc} */
38
+    @Override
39
+    public ViewFactory getViewFactory() {
40
+        return defaultFactory;
41
+    }
42
+}

+ 45
- 0
src/com/dmdirc/addons/ui_swing/components/text/DMDircHTMLFactory.java 查看文件

@@ -0,0 +1,45 @@
1
+/*
2
+ * 
3
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
4
+ * 
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ * 
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ * 
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+
24
+package com.dmdirc.addons.ui_swing.components.text;
25
+
26
+import javax.swing.text.Element;
27
+import javax.swing.text.View;
28
+import javax.swing.text.html.HTMLEditorKit.HTMLFactory;
29
+import javax.swing.text.html.ImageView;
30
+
31
+/**
32
+ * DMDircHTML factory extends HTMLFactory to use DMDircImageView.
33
+ */
34
+public class DMDircHTMLFactory extends HTMLFactory {
35
+
36
+    /** {@inheritDoc} */
37
+    @Override
38
+    public View create(Element elem) {
39
+        final View view = super.create(elem);
40
+        if (view instanceof ImageView) {
41
+            return new DMDircImageView(elem);
42
+        }
43
+        return view;
44
+    }
45
+}

+ 60
- 0
src/com/dmdirc/addons/ui_swing/components/text/DMDircImageView.java 查看文件

@@ -0,0 +1,60 @@
1
+/*
2
+ * 
3
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
4
+ * 
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ * 
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ * 
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+
24
+package com.dmdirc.addons.ui_swing.components.text;
25
+
26
+import com.dmdirc.util.URLBuilder;
27
+
28
+import java.net.URL;
29
+
30
+import javax.swing.text.Element;
31
+import javax.swing.text.html.HTML;
32
+import javax.swing.text.html.ImageView;
33
+
34
+/**
35
+ * DMDirc image view, extends default image view but uses DMDirc URLBuilder.
36
+ */
37
+public class DMDircImageView extends ImageView {
38
+
39
+    /**
40
+     * Creates a new DMDirc image view.
41
+     *
42
+     * @param elem element to view
43
+     */
44
+    public DMDircImageView(final Element elem) {
45
+        super(elem);
46
+    }
47
+
48
+    /**
49
+     * {@inheritDoc}
50
+     *
51
+     * @return URL to resource
52
+     */
53
+    @Override
54
+    public URL getImageURL() {
55
+        final String src = (String) getElement().getAttributes().
56
+                getAttribute(HTML.Attribute.SRC);
57
+
58
+        return src == null ? null : URLBuilder.buildURL(src);
59
+    }
60
+}

+ 37
- 0
src/com/dmdirc/addons/ui_swing/components/text/NoWrapParagraphView.java 查看文件

@@ -0,0 +1,37 @@
1
+/*
2
+ * @author Stanislav Lapitsky
3
+ * @version 1.0
4
+ */
5
+
6
+package com.dmdirc.addons.ui_swing.components.text;
7
+
8
+import javax.swing.text.Element;
9
+import javax.swing.text.ParagraphView;
10
+
11
+/**
12
+ * @author Stanislav Lapitsky
13
+ * @version 1.0
14
+ */
15
+public class NoWrapParagraphView extends ParagraphView {
16
+
17
+    /**
18
+     * Creates a new no wrap paragraph view.
19
+     *
20
+     * @param elem Element to view
21
+     */
22
+    public NoWrapParagraphView(final Element elem) {
23
+        super(elem);
24
+    }
25
+
26
+    /** {@inheritDoc} */
27
+    @Override
28
+    public void layout(final int width, final int height) {
29
+        super.layout(Short.MAX_VALUE, height);
30
+    }
31
+
32
+    /** {@inheritDoc} */
33
+    @Override
34
+    public float getMinimumSpan(final int axis) {
35
+        return super.getPreferredSpan(axis);
36
+    }
37
+}

+ 0
- 69
src/com/dmdirc/addons/ui_swing/components/text/TextLabel.java 查看文件

@@ -22,28 +22,18 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_swing.components.text;
24 24
 
25
-import com.dmdirc.util.URLBuilder;
26
-
27 25
 import java.awt.Color;
28 26
 import java.awt.Font;
29 27
 import java.awt.Insets;
30
-import java.net.URL;
31 28
 
32 29
 import javax.swing.JTextPane;
33 30
 import javax.swing.UIManager;
34 31
 import javax.swing.plaf.basic.BasicTextPaneUI;
35 32
 import javax.swing.text.DefaultStyledDocument;
36
-import javax.swing.text.Element;
37 33
 import javax.swing.text.SimpleAttributeSet;
38 34
 import javax.swing.text.StyleConstants;
39 35
 import javax.swing.text.StyledDocument;
40
-import javax.swing.text.View;
41
-import javax.swing.text.ViewFactory;
42
-import javax.swing.text.html.HTML;
43 36
 import javax.swing.text.html.HTMLDocument;
44
-import javax.swing.text.html.HTMLEditorKit;
45
-import javax.swing.text.html.HTMLEditorKit.HTMLFactory;
46
-import javax.swing.text.html.ImageView;
47 37
 import javax.swing.text.html.StyleSheet;
48 38
 
49 39
 /**
@@ -126,62 +116,3 @@ public class TextLabel extends JTextPane {
126 116
         }
127 117
     }
128 118
 }
129
-
130
-/**
131
- * DMDirc html kit, extends HTMLEditor kit to use DMDircHTMLFactory.
132
- */
133
-class DMDircHTMLEditorKit extends HTMLEditorKit {
134
-
135
-    private static final long serialVersionUID = 1;
136
-    private ViewFactory defaultFactory = new DMDircHTMLFactory();
137
-
138
-    /** {@inheritDoc} */
139
-    @Override
140
-    public ViewFactory getViewFactory() {
141
-        return defaultFactory;
142
-    }
143
-}
144
-
145
-/**
146
- * DMDircHTML factory extends HTMLFactory to use DMDircImageView.
147
- */
148
-class DMDircHTMLFactory extends HTMLFactory {
149
-
150
-    /** {@inheritDoc} */
151
-    @Override
152
-    public View create(Element elem) {
153
-        final View view = super.create(elem);
154
-        if (view instanceof ImageView) {
155
-            return new DMDircImageView(elem);
156
-        }
157
-        return view;
158
-    }
159
-}
160
-
161
-/**
162
- * DMDirc image view, extends default image view but uses DMDirc URLBuilder.
163
- */
164
-class DMDircImageView extends ImageView {
165
-
166
-    /**
167
-     * Creates a new DMDirc image view.
168
-     *
169
-     * @param elem element to view
170
-     */
171
-    public DMDircImageView(final Element elem) {
172
-        super(elem);
173
-    }
174
-
175
-    /**
176
-     * {@inheritDoc}
177
-     *
178
-     * @return URL to resource
179
-     */
180
-    @Override
181
-    public URL getImageURL() {
182
-        final String src = (String) getElement().getAttributes().
183
-                getAttribute(HTML.Attribute.SRC);
184
-
185
-        return src == null ? null : URLBuilder.buildURL(src);
186
-    }
187
-}

+ 45
- 0
src/com/dmdirc/addons/ui_swing/components/text/WrapColumnFactory.java 查看文件

@@ -0,0 +1,45 @@
1
+/*
2
+ * @author Stanislav Lapitsky
3
+ * @version 1.0
4
+ */
5
+
6
+package com.dmdirc.addons.ui_swing.components.text;
7
+
8
+import javax.swing.text.AbstractDocument;
9
+import javax.swing.text.BoxView;
10
+import javax.swing.text.ComponentView;
11
+import javax.swing.text.Element;
12
+import javax.swing.text.IconView;
13
+import javax.swing.text.LabelView;
14
+import javax.swing.text.StyleConstants;
15
+import javax.swing.text.View;
16
+import javax.swing.text.ViewFactory;
17
+
18
+/**
19
+ * @author Stanislav Lapitsky
20
+ * @version 1.0
21
+ */
22
+public class WrapColumnFactory implements ViewFactory {
23
+
24
+    /** {@inheritDoc} */
25
+    @Override
26
+    public View create(final Element elem) {
27
+        String kind = elem.getName();
28
+        if (kind != null) {
29
+            if (kind.equals(AbstractDocument.ContentElementName)) {
30
+                return new WrapLabelView(elem);
31
+            } else if (kind.equals(AbstractDocument.ParagraphElementName)) {
32
+                return new NoWrapParagraphView(elem);
33
+            } else if (kind.equals(AbstractDocument.SectionElementName)) {
34
+                return new BoxView(elem, View.Y_AXIS);
35
+            } else if (kind.equals(StyleConstants.ComponentElementName)) {
36
+                return new ComponentView(elem);
37
+            } else if (kind.equals(StyleConstants.IconElementName)) {
38
+                return new IconView(elem);
39
+            }
40
+        }
41
+
42
+        // default to text display
43
+        return new LabelView(elem);
44
+    }
45
+}

+ 25
- 0
src/com/dmdirc/addons/ui_swing/components/text/WrapEditorKit.java 查看文件

@@ -0,0 +1,25 @@
1
+/*
2
+ * @author Stanislav Lapitsky
3
+ * @version 1.0
4
+ */
5
+
6
+package com.dmdirc.addons.ui_swing.components.text;
7
+
8
+import javax.swing.text.StyledEditorKit;
9
+import javax.swing.text.ViewFactory;
10
+
11
+/**
12
+ * @author Stanislav Lapitsky
13
+ * @version 1.0
14
+ */
15
+public class WrapEditorKit extends StyledEditorKit {
16
+
17
+    private static final long serialVersionUID = 1;
18
+    private ViewFactory defaultFactory = new WrapColumnFactory();
19
+
20
+    /** {@inheritDoc} */
21
+    @Override
22
+    public ViewFactory getViewFactory() {
23
+        return defaultFactory;
24
+    }
25
+}

+ 71
- 0
src/com/dmdirc/addons/ui_swing/components/text/WrapLabelView.java 查看文件

@@ -0,0 +1,71 @@
1
+/*
2
+ * @author Stanislav Lapitsky
3
+ * @version 1.0
4
+ */
5
+package com.dmdirc.addons.ui_swing.components.text;
6
+
7
+import javax.swing.text.BadLocationException;
8
+import javax.swing.text.Element;
9
+import javax.swing.text.GlyphView;
10
+import javax.swing.text.LabelView;
11
+import javax.swing.text.View;
12
+
13
+/**
14
+ * @author Stanislav Lapitsky
15
+ * @version 1.0
16
+ */
17
+public class WrapLabelView extends LabelView {
18
+
19
+    /**
20
+     * Creates a new wrap label view.
21
+     *
22
+     * @param elem Element to view
23
+     */
24
+    public WrapLabelView(final Element elem) {
25
+        super(elem);
26
+    }
27
+
28
+    /** {@inheritDoc} */
29
+    @Override
30
+    public int getBreakWeight(final int axis, final float pos, final float len) {
31
+        if (axis == View.X_AXIS) {
32
+            checkPainter();
33
+            int p0 = getStartOffset();
34
+            int p1 = getGlyphPainter().getBoundedPosition(this, p0, pos, len);
35
+            if (p1 == p0) {
36
+                // can't even fit a single character
37
+                return View.BadBreakWeight;
38
+            }
39
+            try {
40
+                //if the view contains line break char return forced break
41
+                if (getDocument().getText(p0, p1 - p0).indexOf("\r") >= 0) {
42
+                    return View.ForcedBreakWeight;
43
+                }
44
+            } catch (BadLocationException ex) {
45
+                //should never happen
46
+            }
47
+        }
48
+        return super.getBreakWeight(axis, pos, len);
49
+    }
50
+
51
+    /** {@inheritDoc} */
52
+    @Override
53
+    public View breakView(final int axis, final int p0, final float pos,
54
+            final float len) {
55
+        if (axis == View.X_AXIS) {
56
+            checkPainter();
57
+            int p1 = getGlyphPainter().getBoundedPosition(this, p0, pos, len);
58
+            try {
59
+                //if the view contains line break char break the view
60
+                int index = getDocument().getText(p0, p1 - p0).indexOf("\r");
61
+                if (index >= 0) {
62
+                    GlyphView v = (GlyphView) createFragment(p0, p0 + index + 1);
63
+                    return v;
64
+                }
65
+            } catch (BadLocationException ex) {
66
+                //should never happen
67
+            }
68
+        }
69
+        return super.breakView(axis, p0, pos, len);
70
+    }
71
+}

Loading…
取消
儲存