Parcourir la source

issue 1811: Background Images in the text pane

Change-Id: Ibb88c32e235a22cccef74ddf78e74761a45f5fca
Reviewed-on: http://gerrit.dmdirc.com/400
Reviewed-by: Shane Mc Cormack <shane@dmdirc.com>
Tested-by: Gregory Holmes <greboid@dmdirc.com>
tags/0.6.3
Gregory Holmes il y a 14 ans
Parent
révision
8145fb5d5e

+ 1
- 1
src/com/dmdirc/addons/ui_swing/components/frames/TextFrame.java Voir le fichier

@@ -505,7 +505,7 @@ public abstract class TextFrame extends JInternalFrame implements Window,
505 505
      * Initialises the components for this frame.
506 506
      */
507 507
     private void initComponents() {
508
-        setTextPane(new TextPane(getContainer()));
508
+        setTextPane(new TextPane(this));
509 509
 
510 510
         getTextPane().addMouseListener(this);
511 511
         getTextPane().addKeyListener(this);

+ 2
- 1
src/com/dmdirc/addons/ui_swing/plugin.config Voir le fichier

@@ -33,4 +33,5 @@ defaults:
33 33
     showtopicbar=true
34 34
     shownicklist=true
35 35
     showfulltopic=false
36
-    hideEmptyTopicBar=false
36
+    hideEmptyTopicBar=false
37
+    textpanebackground=

+ 8
- 8
src/com/dmdirc/addons/ui_swing/textpane/TextPane.java Voir le fichier

@@ -22,7 +22,7 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_swing.textpane;
24 24
 
25
-import com.dmdirc.FrameContainer;
25
+import com.dmdirc.ui.interfaces.Window;
26 26
 
27 27
 import java.awt.Point;
28 28
 import java.awt.Toolkit;
@@ -61,18 +61,18 @@ public final class TextPane extends JComponent implements AdjustmentListener,
61 61
     /** IRCDocument. */
62 62
     private final IRCDocument document;
63 63
     /** Parent Frame. */
64
-    private final FrameContainer frame;
64
+    private final Window frame;
65 65
 
66 66
     /** 
67 67
      * Creates a new instance of TextPane. 
68 68
      *
69 69
      * @param frame Parent Frame
70 70
      */
71
-    public TextPane(final FrameContainer frame) {
71
+    public TextPane(final Window frame) {
72 72
         super();
73
-        setUI(new TextPaneUI());
74
-
75 73
         this.frame = frame;
74
+        
75
+        setUI(new TextPaneUI());
76 76
         document = new IRCDocument(frame.getConfigManager());
77 77
         frame.getConfigManager().addChangeListener("ui", "textPaneFontName",
78 78
                 document);
@@ -430,11 +430,11 @@ public final class TextPane extends JComponent implements AdjustmentListener,
430 430
     }
431 431
 
432 432
     /**
433
-     * Retrives the parent framecontainer for this textpane.
433
+     * Retrives the parent window for this textpane.
434 434
      * 
435
-     * @return Parent frame container
435
+     * @return Parent window
436 436
      */
437
-    public FrameContainer getFrameContainer() {
437
+    public Window getWindow() {
438 438
         return frame;
439 439
     }
440 440
 }

+ 56
- 3
src/com/dmdirc/addons/ui_swing/textpane/TextPaneCanvas.java Voir le fichier

@@ -22,11 +22,16 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_swing.textpane;
24 24
 
25
+import com.dmdirc.addons.ui_swing.UIUtilities;
26
+import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
27
+import com.dmdirc.config.ConfigManager;
28
+import com.dmdirc.interfaces.ConfigChangeListener;
25 29
 import com.dmdirc.ui.messages.IRCTextAttribute;
26 30
 
27 31
 import java.awt.Cursor;
28 32
 import java.awt.Graphics;
29 33
 import java.awt.Graphics2D;
34
+import java.awt.Image;
30 35
 import java.awt.Point;
31 36
 import java.awt.Rectangle;
32 37
 import java.awt.Shape;
@@ -52,7 +57,7 @@ import javax.swing.event.MouseInputListener;
52 57
 
53 58
 /** Canvas object to draw text. */
54 59
 class TextPaneCanvas extends JPanel implements MouseInputListener,
55
-        ComponentListener, AdjustmentListener {
60
+        ComponentListener, AdjustmentListener, ConfigChangeListener {
56 61
 
57 62
     /**
58 63
      * A version number for this class. It should be changed whenever the
@@ -84,6 +89,12 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
84 89
     private int lastVisibleLine;
85 90
     /** Cached canvas. */
86 91
     private BufferedImage buffer;
92
+    /** Background image. */
93
+    private Image backgroundImage;
94
+    /** Config Manager. */
95
+    private  ConfigManager manager;
96
+    /** Config domain. */
97
+    private  String domain;
87 98
 
88 99
     /**
89 100
      * Creates a new text pane canvas.
@@ -94,8 +105,11 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
94 105
     public TextPaneCanvas(final TextPane parent, final IRCDocument document) {
95 106
         super();
96 107
         this.document = document;
97
-        startLine = 0;
98 108
         textPane = parent;
109
+        this.manager = parent.getWindow().getConfigManager();
110
+        this.domain = ((TextFrame) parent.getWindow()).getController().
111
+                getDomain();
112
+        startLine = 0;
99 113
         setDoubleBuffered(true);
100 114
         setOpaque(true);
101 115
         textLayouts = new HashMap<TextLayout, LineInfo>();
@@ -104,6 +118,9 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
104 118
         addMouseListener(this);
105 119
         addMouseMotionListener(this);
106 120
         addComponentListener(this);
121
+        manager.addChangeListener(domain, "textpanebackground", this);
122
+
123
+        updateCachedSettings();
107 124
     }
108 125
 
109 126
     /**
@@ -138,6 +155,36 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
138 155
         }
139 156
     }
140 157
 
158
+    /**
159
+     * Paints the background, either from the config setting or the background
160
+     * colour of the textpane.
161
+     *
162
+     * @param g Graphics object to draw onto
163
+     */
164
+    private void paintBackground(final Graphics2D g) {
165
+        if (backgroundImage != null) {
166
+            g.drawImage(backgroundImage, 0,
167
+                    0, getBounds().width, getBounds().height, null);
168
+        } else {
169
+            g.fill(getBounds());
170
+        }
171
+    }
172
+
173
+    private void updateCachedSettings() {
174
+        final String backgroundPath = manager.getOption(domain,
175
+                "textpanebackground");
176
+        UIUtilities.invokeLater(new Runnable() {
177
+
178
+            /** {@inheritDoc} */
179
+            @Override
180
+            public void run() {
181
+                backgroundImage = backgroundPath.isEmpty() ? null : Toolkit.
182
+                getDefaultToolkit().getImage(backgroundPath);
183
+                repaint();
184
+            }
185
+        });
186
+    }
187
+
141 188
     /**
142 189
      * Calculates the position of the lines and highlights.
143 190
      */
@@ -169,7 +216,7 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
169 216
         LineBreakMeasurer lineMeasurer;
170 217
 
171 218
         g.setColor(textPane.getBackground());
172
-        g.fill(getBounds());
219
+        paintBackground(g);
173 220
 
174 221
         textLayouts.clear();
175 222
         positions.clear();
@@ -909,4 +956,10 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
909 956
     public void componentHidden(final ComponentEvent e) {
910 957
         //Ignore
911 958
     }
959
+
960
+    /** {@inheritDoc} */
961
+    @Override
962
+    public void configChanged(final String domain, final String key) {
963
+        updateCachedSettings();
964
+    }
912 965
 }

Chargement…
Annuler
Enregistrer