Browse Source

UI changes to cope with non-static Styliser

Change-Id: Ibd3ed7eb66077c6bef0744c6f9a8c3e6b5f1961c
Reviewed-on: http://gerrit.dmdirc.com/527
Automatic-Compile: Gregory Holmes <greboid@dmdirc.com>
Reviewed-by: Gregory Holmes <greboid@dmdirc.com>
tags/0.6.3
Chris Smith 14 years ago
parent
commit
1b3fad9550

+ 1
- 1
src/com/dmdirc/addons/ui_swing/components/TopicBar.java View File

@@ -225,7 +225,7 @@ public class TopicBar extends JComponent implements ActionListener,
225 225
         }
226 226
         topicText.setText("");
227 227
         if (channel.getCurrentTopic() != null) {
228
-            Styliser.addStyledString((StyledDocument) topicText.getDocument(),
228
+            channel.getStyliser().addStyledString((StyledDocument) topicText.getDocument(),
229 229
                     new String[]{Styliser.CODE_HEXCOLOUR + ColourManager.getHex(
230 230
                         foregroundColour) + channel.getCurrentTopic().getTopic(),},
231 231
                     as);

+ 1
- 1
src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/TopicHistoryPane.java View File

@@ -76,7 +76,7 @@ public class TopicHistoryPane extends JPanel implements ListSelectionListener {
76 76
         scrollPane.getVerticalScrollBar().setUnitIncrement(15);
77 77
 
78 78
         for (Topic topic : topics) {
79
-            topicHistory.getModel().addRow(new Object[]{new TopicLabel(topic),});
79
+            topicHistory.getModel().addRow(new Object[]{new TopicLabel(channel, topic),});
80 80
         }
81 81
         topicHistory.getSelectionModel().setSelectionInterval(0, 0);
82 82
 

+ 12
- 5
src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/TopicLabel.java View File

@@ -23,14 +23,14 @@
23 23
 
24 24
 package com.dmdirc.addons.ui_swing.dialogs.channelsetting;
25 25
 
26
+import com.dmdirc.Channel;
26 27
 import com.dmdirc.Topic;
27 28
 import com.dmdirc.addons.ui_swing.components.text.OldTextLabel;
28
-import com.dmdirc.ui.messages.Styliser;
29
-import java.awt.Color;
30 29
 
30
+import java.awt.Color;
31 31
 import java.util.Date;
32
-import javax.swing.JEditorPane;
33 32
 
33
+import javax.swing.JEditorPane;
34 34
 import javax.swing.JPanel;
35 35
 import javax.swing.JSeparator;
36 36
 import javax.swing.UIManager;
@@ -54,6 +54,8 @@ public class TopicLabel extends JPanel {
54 54
     private static final long serialVersionUID = 1;
55 55
     /** Topic this label represents. */
56 56
     private final Topic topic;
57
+    /** The channel to which this label belongs. */
58
+    private final Channel channel;
57 59
     /** Topic field. */
58 60
     private JEditorPane pane;
59 61
     /** Empty Attrib set. */
@@ -62,13 +64,18 @@ public class TopicLabel extends JPanel {
62 64
     /**
63 65
      * Instantiates a new topic label based on the specified topic.
64 66
      *
67
+     * @param channel The channel to which this label belongs
65 68
      * @param topic Specified topic
69
+     * @since 0.6.3
66 70
      */
67
-    public TopicLabel(final Topic topic) {
71
+    public TopicLabel(final Channel channel, final Topic topic) {
68 72
         if (topic == null) {
69 73
             throw new IllegalArgumentException();
70 74
         }
75
+        
71 76
         this.topic = topic;
77
+        this.channel = channel;
78
+
72 79
         super.setBackground(UIManager.getColor("Table.background"));
73 80
         super.setForeground(UIManager.getColor("Table.foreground"));
74 81
 
@@ -109,7 +116,7 @@ public class TopicLabel extends JPanel {
109 116
         setLayout(new MigLayout("fill, ins 0, debug", "[]0[]", "[]0[]"));
110 117
 
111 118
         if (!topic.getTopic().isEmpty()) {
112
-            Styliser.addStyledString((StyledDocument) pane.getDocument(),
119
+            channel.getStyliser().addStyledString((StyledDocument) pane.getDocument(),
113 120
                     new String[]{topic.getTopic(),},
114 121
                     as);
115 122
             add(pane, "wmax 450, grow, push, wrap, gapleft 5, gapleft 5");

+ 21
- 19
src/com/dmdirc/addons/ui_swing/textpane/IRCDocument.java View File

@@ -22,18 +22,18 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_swing.textpane;
24 24
 
25
-import com.dmdirc.config.ConfigManager;
25
+import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.interfaces.ConfigChangeListener;
27 27
 import com.dmdirc.util.RollingList;
28
-import java.awt.Font;
29 28
 
29
+import java.awt.Font;
30 30
 import java.io.Serializable;
31 31
 import java.text.AttributedCharacterIterator;
32 32
 import java.text.AttributedString;
33 33
 import java.util.ArrayList;
34 34
 import java.util.List;
35
-import javax.swing.UIManager;
36 35
 
36
+import javax.swing.UIManager;
37 37
 import javax.swing.event.EventListenerList;
38 38
 
39 39
 /**
@@ -55,8 +55,8 @@ public final class IRCDocument implements Serializable, ConfigChangeListener {
55 55
     private RollingList<Line> cachedLines;
56 56
     /** Cached attributed strings. */
57 57
     private RollingList<AttributedString> cachedStrings;
58
-    /** Configuration manager. */
59
-    private ConfigManager config;
58
+    /** Container that owns this document. */
59
+    private final FrameContainer container;
60 60
     /** Font size. */
61 61
     private int fontSize;
62 62
     /** Font name. */
@@ -65,20 +65,22 @@ public final class IRCDocument implements Serializable, ConfigChangeListener {
65 65
     /** 
66 66
      * Creates a new instance of IRCDocument.
67 67
      * 
68
-     * @param config Document's config manager
68
+     * @param container The container that owns this document
69
+     * @since 0.6.3
69 70
      */
70
-    public IRCDocument(final ConfigManager config) {
71
-        this.config = config;
71
+    public IRCDocument(final FrameContainer container) {
72
+        this.container = container;
73
+
72 74
         lines = new ArrayList<Line>();
73 75
         listeners = new EventListenerList();
74 76
 
75 77
         cachedLines = new RollingList<Line>(50);
76 78
         cachedStrings = new RollingList<AttributedString>(50);
77 79
 
78
-        setCachedSettings();
80
+        container.getConfigManager().addChangeListener("ui", "textPaneFontSize", this);
81
+        container.getConfigManager().addChangeListener("ui", "textPaneFontName", this);
79 82
 
80
-        config.addChangeListener("ui", "textPaneFontSize", this);
81
-        config.addChangeListener("ui", "textPaneFontName", this);
83
+        setCachedSettings();
82 84
     }
83 85
 
84 86
     /**
@@ -112,7 +114,7 @@ public final class IRCDocument implements Serializable, ConfigChangeListener {
112 114
      */
113 115
     public void addText(final String[] text) {
114 116
         synchronized (lines) {
115
-            lines.add(new Line(text, fontSize, fontName));
117
+            lines.add(new Line(container.getStyliser(), text, fontSize, fontName));
116 118
             fireLineAdded(lines.indexOf(text));
117 119
         }
118 120
     }
@@ -125,7 +127,7 @@ public final class IRCDocument implements Serializable, ConfigChangeListener {
125 127
      */
126 128
     public void addText(final String[] text, final int lineHeight) {
127 129
         synchronized (lines) {
128
-            lines.add(new Line(text, lineHeight, fontName));
130
+            lines.add(new Line(container.getStyliser(), text, lineHeight, fontName));
129 131
             fireLineAdded(lines.indexOf(text));
130 132
         }
131 133
     }
@@ -139,7 +141,7 @@ public final class IRCDocument implements Serializable, ConfigChangeListener {
139 141
         synchronized (lines) {
140 142
             final int start = lines.size();
141 143
             for (String[] string : text) {
142
-                lines.add(new Line(string, fontSize, fontName));
144
+                lines.add(new Line(container.getStyliser(), string, fontSize, fontName));
143 145
             }
144 146
             fireLinesAdded(start, text.size());
145 147
         }
@@ -158,7 +160,7 @@ public final class IRCDocument implements Serializable, ConfigChangeListener {
158 160
             for (int i = 0; i < text.size(); i++) {
159 161
                 final String[] string = text.get(i);
160 162
                 final int lineHeight = lineHeights.get(i);
161
-                lines.add(new Line(string, lineHeight, fontName));
163
+                lines.add(new Line(container.getStyliser(), string, lineHeight, fontName));
162 164
             }
163 165
             fireLinesAdded(start, text.size());
164 166
         }
@@ -339,13 +341,13 @@ public final class IRCDocument implements Serializable, ConfigChangeListener {
339 341
 
340 342
     private void setCachedSettings() {
341 343
         final Font defaultFont = UIManager.getFont("TextPane.font");
342
-        if (config.hasOptionString("ui", "textPaneFontName")) {
343
-            fontName = config.getOption("ui", "textPaneFontName");
344
+        if (container.getConfigManager().hasOptionString("ui", "textPaneFontName")) {
345
+            fontName = container.getConfigManager().getOption("ui", "textPaneFontName");
344 346
         } else {
345 347
             fontName = defaultFont.getName();
346 348
         }
347
-        if (config.hasOptionString("ui", "textPaneFontSize")) {
348
-            fontSize = config.getOptionInt("ui", "textPaneFontSize");
349
+        if (container.getConfigManager().hasOptionString("ui", "textPaneFontSize")) {
350
+            fontSize = container.getConfigManager().getOptionInt("ui", "textPaneFontSize");
349 351
         } else {
350 352
             fontSize = defaultFont.getSize();
351 353
         }

+ 7
- 4
src/com/dmdirc/addons/ui_swing/textpane/Line.java View File

@@ -36,18 +36,21 @@ import java.util.Arrays;
36 36
 class Line {
37 37
 
38 38
     private final String[] lineParts;
39
+    private final Styliser styliser;
39 40
     private int fontSize;
40 41
     private String fontName;
41 42
 
42 43
     /**
43 44
      * Creates a new line with a specified height.
44 45
      *
46
+     * @param styliser The styliser to use to style this line
45 47
      * @param lineParts Parts of the line
46 48
      * @param fontSize The height for this line
47
-     * @param fontName
49
+     * @param fontName The name of the font to use for this line
48 50
      */
49
-    public Line(final String[] lineParts, final int fontSize,
50
-            final String fontName) {
51
+    public Line(final Styliser styliser, final String[] lineParts,
52
+            final int fontSize, final String fontName) {
53
+        this.styliser = styliser;
51 54
         this.lineParts = lineParts;
52 55
         this.fontName = fontName;
53 56
         this.fontSize = fontSize;
@@ -136,7 +139,7 @@ class Line {
136 139
      * @return AttributedString representing the specified StyledDocument
137 140
      */
138 141
     public AttributedString getStyled() {
139
-        final ExtendedAttributedString string = Utils.getAttributedString(lineParts,
142
+        final ExtendedAttributedString string = Utils.getAttributedString(styliser, lineParts,
140 143
                 fontName, fontSize);
141 144
         fontSize = string.getMaxLineHeight();
142 145
         return string.getAttributedString();

+ 1
- 1
src/com/dmdirc/addons/ui_swing/textpane/TextPane.java View File

@@ -73,7 +73,7 @@ public final class TextPane extends JComponent implements AdjustmentListener,
73 73
         this.frame = frame;
74 74
         
75 75
         setUI(new TextPaneUI());
76
-        document = new IRCDocument(frame.getConfigManager());
76
+        document = new IRCDocument(frame.getContainer());
77 77
         frame.getConfigManager().addChangeListener("ui", "textPaneFontName",
78 78
                 document);
79 79
         frame.getConfigManager().addChangeListener("ui", "textPaneFontSize",

Loading…
Cancel
Save