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
         }
225
         }
226
         topicText.setText("");
226
         topicText.setText("");
227
         if (channel.getCurrentTopic() != null) {
227
         if (channel.getCurrentTopic() != null) {
228
-            Styliser.addStyledString((StyledDocument) topicText.getDocument(),
228
+            channel.getStyliser().addStyledString((StyledDocument) topicText.getDocument(),
229
                     new String[]{Styliser.CODE_HEXCOLOUR + ColourManager.getHex(
229
                     new String[]{Styliser.CODE_HEXCOLOUR + ColourManager.getHex(
230
                         foregroundColour) + channel.getCurrentTopic().getTopic(),},
230
                         foregroundColour) + channel.getCurrentTopic().getTopic(),},
231
                     as);
231
                     as);

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

76
         scrollPane.getVerticalScrollBar().setUnitIncrement(15);
76
         scrollPane.getVerticalScrollBar().setUnitIncrement(15);
77
 
77
 
78
         for (Topic topic : topics) {
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
         topicHistory.getSelectionModel().setSelectionInterval(0, 0);
81
         topicHistory.getSelectionModel().setSelectionInterval(0, 0);
82
 
82
 

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

23
 
23
 
24
 package com.dmdirc.addons.ui_swing.dialogs.channelsetting;
24
 package com.dmdirc.addons.ui_swing.dialogs.channelsetting;
25
 
25
 
26
+import com.dmdirc.Channel;
26
 import com.dmdirc.Topic;
27
 import com.dmdirc.Topic;
27
 import com.dmdirc.addons.ui_swing.components.text.OldTextLabel;
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
 import java.util.Date;
31
 import java.util.Date;
32
-import javax.swing.JEditorPane;
33
 
32
 
33
+import javax.swing.JEditorPane;
34
 import javax.swing.JPanel;
34
 import javax.swing.JPanel;
35
 import javax.swing.JSeparator;
35
 import javax.swing.JSeparator;
36
 import javax.swing.UIManager;
36
 import javax.swing.UIManager;
54
     private static final long serialVersionUID = 1;
54
     private static final long serialVersionUID = 1;
55
     /** Topic this label represents. */
55
     /** Topic this label represents. */
56
     private final Topic topic;
56
     private final Topic topic;
57
+    /** The channel to which this label belongs. */
58
+    private final Channel channel;
57
     /** Topic field. */
59
     /** Topic field. */
58
     private JEditorPane pane;
60
     private JEditorPane pane;
59
     /** Empty Attrib set. */
61
     /** Empty Attrib set. */
62
     /**
64
     /**
63
      * Instantiates a new topic label based on the specified topic.
65
      * Instantiates a new topic label based on the specified topic.
64
      *
66
      *
67
+     * @param channel The channel to which this label belongs
65
      * @param topic Specified topic
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
         if (topic == null) {
72
         if (topic == null) {
69
             throw new IllegalArgumentException();
73
             throw new IllegalArgumentException();
70
         }
74
         }
75
+        
71
         this.topic = topic;
76
         this.topic = topic;
77
+        this.channel = channel;
78
+
72
         super.setBackground(UIManager.getColor("Table.background"));
79
         super.setBackground(UIManager.getColor("Table.background"));
73
         super.setForeground(UIManager.getColor("Table.foreground"));
80
         super.setForeground(UIManager.getColor("Table.foreground"));
74
 
81
 
109
         setLayout(new MigLayout("fill, ins 0, debug", "[]0[]", "[]0[]"));
116
         setLayout(new MigLayout("fill, ins 0, debug", "[]0[]", "[]0[]"));
110
 
117
 
111
         if (!topic.getTopic().isEmpty()) {
118
         if (!topic.getTopic().isEmpty()) {
112
-            Styliser.addStyledString((StyledDocument) pane.getDocument(),
119
+            channel.getStyliser().addStyledString((StyledDocument) pane.getDocument(),
113
                     new String[]{topic.getTopic(),},
120
                     new String[]{topic.getTopic(),},
114
                     as);
121
                     as);
115
             add(pane, "wmax 450, grow, push, wrap, gapleft 5, gapleft 5");
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
 
22
 
23
 package com.dmdirc.addons.ui_swing.textpane;
23
 package com.dmdirc.addons.ui_swing.textpane;
24
 
24
 
25
-import com.dmdirc.config.ConfigManager;
25
+import com.dmdirc.FrameContainer;
26
 import com.dmdirc.interfaces.ConfigChangeListener;
26
 import com.dmdirc.interfaces.ConfigChangeListener;
27
 import com.dmdirc.util.RollingList;
27
 import com.dmdirc.util.RollingList;
28
-import java.awt.Font;
29
 
28
 
29
+import java.awt.Font;
30
 import java.io.Serializable;
30
 import java.io.Serializable;
31
 import java.text.AttributedCharacterIterator;
31
 import java.text.AttributedCharacterIterator;
32
 import java.text.AttributedString;
32
 import java.text.AttributedString;
33
 import java.util.ArrayList;
33
 import java.util.ArrayList;
34
 import java.util.List;
34
 import java.util.List;
35
-import javax.swing.UIManager;
36
 
35
 
36
+import javax.swing.UIManager;
37
 import javax.swing.event.EventListenerList;
37
 import javax.swing.event.EventListenerList;
38
 
38
 
39
 /**
39
 /**
55
     private RollingList<Line> cachedLines;
55
     private RollingList<Line> cachedLines;
56
     /** Cached attributed strings. */
56
     /** Cached attributed strings. */
57
     private RollingList<AttributedString> cachedStrings;
57
     private RollingList<AttributedString> cachedStrings;
58
-    /** Configuration manager. */
59
-    private ConfigManager config;
58
+    /** Container that owns this document. */
59
+    private final FrameContainer container;
60
     /** Font size. */
60
     /** Font size. */
61
     private int fontSize;
61
     private int fontSize;
62
     /** Font name. */
62
     /** Font name. */
65
     /** 
65
     /** 
66
      * Creates a new instance of IRCDocument.
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
         lines = new ArrayList<Line>();
74
         lines = new ArrayList<Line>();
73
         listeners = new EventListenerList();
75
         listeners = new EventListenerList();
74
 
76
 
75
         cachedLines = new RollingList<Line>(50);
77
         cachedLines = new RollingList<Line>(50);
76
         cachedStrings = new RollingList<AttributedString>(50);
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
      */
114
      */
113
     public void addText(final String[] text) {
115
     public void addText(final String[] text) {
114
         synchronized (lines) {
116
         synchronized (lines) {
115
-            lines.add(new Line(text, fontSize, fontName));
117
+            lines.add(new Line(container.getStyliser(), text, fontSize, fontName));
116
             fireLineAdded(lines.indexOf(text));
118
             fireLineAdded(lines.indexOf(text));
117
         }
119
         }
118
     }
120
     }
125
      */
127
      */
126
     public void addText(final String[] text, final int lineHeight) {
128
     public void addText(final String[] text, final int lineHeight) {
127
         synchronized (lines) {
129
         synchronized (lines) {
128
-            lines.add(new Line(text, lineHeight, fontName));
130
+            lines.add(new Line(container.getStyliser(), text, lineHeight, fontName));
129
             fireLineAdded(lines.indexOf(text));
131
             fireLineAdded(lines.indexOf(text));
130
         }
132
         }
131
     }
133
     }
139
         synchronized (lines) {
141
         synchronized (lines) {
140
             final int start = lines.size();
142
             final int start = lines.size();
141
             for (String[] string : text) {
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
             fireLinesAdded(start, text.size());
146
             fireLinesAdded(start, text.size());
145
         }
147
         }
158
             for (int i = 0; i < text.size(); i++) {
160
             for (int i = 0; i < text.size(); i++) {
159
                 final String[] string = text.get(i);
161
                 final String[] string = text.get(i);
160
                 final int lineHeight = lineHeights.get(i);
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
             fireLinesAdded(start, text.size());
165
             fireLinesAdded(start, text.size());
164
         }
166
         }
339
 
341
 
340
     private void setCachedSettings() {
342
     private void setCachedSettings() {
341
         final Font defaultFont = UIManager.getFont("TextPane.font");
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
         } else {
346
         } else {
345
             fontName = defaultFont.getName();
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
         } else {
351
         } else {
350
             fontSize = defaultFont.getSize();
352
             fontSize = defaultFont.getSize();
351
         }
353
         }

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

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

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

73
         this.frame = frame;
73
         this.frame = frame;
74
         
74
         
75
         setUI(new TextPaneUI());
75
         setUI(new TextPaneUI());
76
-        document = new IRCDocument(frame.getConfigManager());
76
+        document = new IRCDocument(frame.getContainer());
77
         frame.getConfigManager().addChangeListener("ui", "textPaneFontName",
77
         frame.getConfigManager().addChangeListener("ui", "textPaneFontName",
78
                 document);
78
                 document);
79
         frame.getConfigManager().addChangeListener("ui", "textPaneFontSize",
79
         frame.getConfigManager().addChangeListener("ui", "textPaneFontSize",

Loading…
Cancel
Save