瀏覽代碼

Add new line indicator to textpane.

Fixes issue CLIENT-9

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

+ 27
- 2
src/com/dmdirc/addons/ui_swing/textpane/TextPane.java 查看文件

@@ -28,6 +28,7 @@ import com.dmdirc.ui.messages.IRCDocument;
28 28
 import com.dmdirc.ui.messages.IRCDocumentListener;
29 29
 import com.dmdirc.ui.messages.LinePosition;
30 30
 import com.dmdirc.ui.messages.Styliser;
31
+import java.awt.Color;
31 32
 
32 33
 import java.awt.Point;
33 34
 import java.awt.Toolkit;
@@ -43,7 +44,9 @@ import java.awt.event.MouseWheelListener;
43 44
 import javax.swing.BoundedRangeModel;
44 45
 import javax.swing.DefaultBoundedRangeModel;
45 46
 import javax.swing.JComponent;
47
+import javax.swing.JLabel;
46 48
 import javax.swing.JScrollBar;
49
+import javax.swing.SwingConstants;
47 50
 
48 51
 import net.miginfocom.swing.MigLayout;
49 52
 
@@ -67,6 +70,10 @@ public final class TextPane extends JComponent implements MouseWheelListener,
67 70
     private final IRCDocument document;
68 71
     /** Parent Frame. */
69 72
     private final Window frame;
73
+    /** Indicator to show whether new lines have been added. */
74
+    private JLabel newLineIndicator;
75
+    /** Last seen line. */
76
+    private int lastSeenLine = 0;
70 77
 
71 78
     /**
72 79
      * Creates a new instance of TextPane.
@@ -79,10 +86,15 @@ public final class TextPane extends JComponent implements MouseWheelListener,
79 86
 
80 87
         setUI(new TextPaneUI());
81 88
         document = frame.getContainer().getDocument();
89
+        newLineIndicator = new JLabel("", SwingConstants.CENTER);
90
+        newLineIndicator.setBackground(Color.RED);
91
+        newLineIndicator.setForeground(Color.WHITE);
92
+        newLineIndicator.setOpaque(true);
82 93
 
83
-        setLayout(new MigLayout("fill"));
94
+        setLayout(new MigLayout("fill, hidemode 3"));
84 95
         canvas = new TextPaneCanvas(this, document);
85 96
         add(canvas, "dock center");
97
+        add(newLineIndicator, "dock south, center, grow");
86 98
         scrollModel = new DefaultBoundedRangeModel();
87 99
         scrollModel.setMaximum(document.getNumLines());
88 100
         scrollModel.setExtent(0);
@@ -141,7 +153,8 @@ public final class TextPane extends JComponent implements MouseWheelListener,
141 153
      * scrollbar's current position is set to the end of the document.
142 154
      *
143 155
      * @param lines Current number of lines
144
-     * @param linesAllowed The number of lines allowed below the current position
156
+     * @param linesAllowed The number of lines allowed below the
157
+     * current position
145 158
      * @since 0.6
146 159
      */
147 160
     protected void setScrollBarMax(final int lines, final int linesAllowed) {
@@ -173,6 +186,12 @@ public final class TextPane extends JComponent implements MouseWheelListener,
173 186
      */
174 187
     @Override
175 188
     public void adjustmentValueChanged(final AdjustmentEvent e) {
189
+        if (e.getValue() == document.getNumLines()) {
190
+            newLineIndicator.setVisible(false);
191
+            lastSeenLine = e.getValue();
192
+        }
193
+        newLineIndicator.setText("↓ " + (document.getNumLines() - lastSeenLine)
194
+                + " new lines ↓");
176 195
         scrollModel.setValue(e.getValue());
177 196
     }
178 197
 
@@ -429,6 +448,9 @@ public final class TextPane extends JComponent implements MouseWheelListener,
429 448
             /** {@inheritDoc}. */
430 449
             @Override
431 450
             public void run() {
451
+                if (scrollModel.getValue() != line) {
452
+                    newLineIndicator.setVisible(true);
453
+                }
432 454
                 setScrollBarMax(size, 1);
433 455
             }
434 456
         });
@@ -479,6 +501,9 @@ public final class TextPane extends JComponent implements MouseWheelListener,
479 501
             /** {@inheritDoc}. */
480 502
             @Override
481 503
             public void run() {
504
+                if (scrollModel.getValue() != line) {
505
+                    newLineIndicator.setVisible(true);
506
+                }
482 507
                 setScrollBarMax(size, length);
483 508
             }
484 509
         });

+ 2
- 2
src/com/dmdirc/addons/ui_swing/textpane/TextPaneCanvas.java 查看文件

@@ -90,9 +90,9 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
90 90
     private int startLine;
91 91
     /** Selection. */
92 92
     private LinePosition selection;
93
-    /** First visible line. */
93
+    /** First visible line (from the top). */
94 94
     private int firstVisibleLine;
95
-    /** Last visible line. */
95
+    /** Last visible line (from the top). */
96 96
     private int lastVisibleLine;
97 97
     /** Background image. */
98 98
     private Image backgroundImage;

Loading…
取消
儲存