Browse Source

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 years ago
parent
commit
14ee5ff8cf

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

28
 import com.dmdirc.ui.messages.IRCDocumentListener;
28
 import com.dmdirc.ui.messages.IRCDocumentListener;
29
 import com.dmdirc.ui.messages.LinePosition;
29
 import com.dmdirc.ui.messages.LinePosition;
30
 import com.dmdirc.ui.messages.Styliser;
30
 import com.dmdirc.ui.messages.Styliser;
31
+import java.awt.Color;
31
 
32
 
32
 import java.awt.Point;
33
 import java.awt.Point;
33
 import java.awt.Toolkit;
34
 import java.awt.Toolkit;
43
 import javax.swing.BoundedRangeModel;
44
 import javax.swing.BoundedRangeModel;
44
 import javax.swing.DefaultBoundedRangeModel;
45
 import javax.swing.DefaultBoundedRangeModel;
45
 import javax.swing.JComponent;
46
 import javax.swing.JComponent;
47
+import javax.swing.JLabel;
46
 import javax.swing.JScrollBar;
48
 import javax.swing.JScrollBar;
49
+import javax.swing.SwingConstants;
47
 
50
 
48
 import net.miginfocom.swing.MigLayout;
51
 import net.miginfocom.swing.MigLayout;
49
 
52
 
67
     private final IRCDocument document;
70
     private final IRCDocument document;
68
     /** Parent Frame. */
71
     /** Parent Frame. */
69
     private final Window frame;
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
      * Creates a new instance of TextPane.
79
      * Creates a new instance of TextPane.
79
 
86
 
80
         setUI(new TextPaneUI());
87
         setUI(new TextPaneUI());
81
         document = frame.getContainer().getDocument();
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
         canvas = new TextPaneCanvas(this, document);
95
         canvas = new TextPaneCanvas(this, document);
85
         add(canvas, "dock center");
96
         add(canvas, "dock center");
97
+        add(newLineIndicator, "dock south, center, grow");
86
         scrollModel = new DefaultBoundedRangeModel();
98
         scrollModel = new DefaultBoundedRangeModel();
87
         scrollModel.setMaximum(document.getNumLines());
99
         scrollModel.setMaximum(document.getNumLines());
88
         scrollModel.setExtent(0);
100
         scrollModel.setExtent(0);
141
      * scrollbar's current position is set to the end of the document.
153
      * scrollbar's current position is set to the end of the document.
142
      *
154
      *
143
      * @param lines Current number of lines
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
      * @since 0.6
158
      * @since 0.6
146
      */
159
      */
147
     protected void setScrollBarMax(final int lines, final int linesAllowed) {
160
     protected void setScrollBarMax(final int lines, final int linesAllowed) {
173
      */
186
      */
174
     @Override
187
     @Override
175
     public void adjustmentValueChanged(final AdjustmentEvent e) {
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
         scrollModel.setValue(e.getValue());
195
         scrollModel.setValue(e.getValue());
177
     }
196
     }
178
 
197
 
429
             /** {@inheritDoc}. */
448
             /** {@inheritDoc}. */
430
             @Override
449
             @Override
431
             public void run() {
450
             public void run() {
451
+                if (scrollModel.getValue() != line) {
452
+                    newLineIndicator.setVisible(true);
453
+                }
432
                 setScrollBarMax(size, 1);
454
                 setScrollBarMax(size, 1);
433
             }
455
             }
434
         });
456
         });
479
             /** {@inheritDoc}. */
501
             /** {@inheritDoc}. */
480
             @Override
502
             @Override
481
             public void run() {
503
             public void run() {
504
+                if (scrollModel.getValue() != line) {
505
+                    newLineIndicator.setVisible(true);
506
+                }
482
                 setScrollBarMax(size, length);
507
                 setScrollBarMax(size, length);
483
             }
508
             }
484
         });
509
         });

+ 2
- 2
src/com/dmdirc/addons/ui_swing/textpane/TextPaneCanvas.java View File

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

Loading…
Cancel
Save