|
@@ -23,7 +23,7 @@
|
23
|
23
|
package com.dmdirc.ui.swing.textpane;
|
24
|
24
|
|
25
|
25
|
import com.dmdirc.ui.messages.IRCTextAttribute;
|
26
|
|
-
|
|
26
|
+
|
27
|
27
|
import java.awt.Cursor;
|
28
|
28
|
import java.awt.Graphics;
|
29
|
29
|
import java.awt.Graphics2D;
|
|
@@ -71,14 +71,8 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
|
71
|
71
|
private final int lineHeight;
|
72
|
72
|
/** position of the scrollbar. */
|
73
|
73
|
private int scrollBarPosition;
|
74
|
|
- /** Start line of the selection. */
|
75
|
|
- private int selStartLine;
|
76
|
|
- /** Start character of the selection. */
|
77
|
|
- private int selStartChar;
|
78
|
|
- /** End line of the selection. */
|
79
|
|
- private int selEndLine;
|
80
|
|
- /** End character of the selection. */
|
81
|
|
- private int selEndChar;
|
|
74
|
+ /** Selection. */
|
|
75
|
+ private LinePosition selection;
|
82
|
76
|
/** First visible line. */
|
83
|
77
|
private int firstVisibleLine;
|
84
|
78
|
/** Last visible line. */
|
|
@@ -167,26 +161,27 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
|
167
|
161
|
lastVisibleLine = startLine;
|
168
|
162
|
firstVisibleLine = startLine;
|
169
|
163
|
|
170
|
|
- if (selStartLine > selEndLine) {
|
|
164
|
+ if (selection.getStartLine() > selection.getEndLine()) {
|
171
|
165
|
// Swap both
|
172
|
|
- useStartLine = selEndLine;
|
173
|
|
- useStartChar = selEndChar;
|
174
|
|
- useEndLine = selStartLine;
|
175
|
|
- useEndChar = selStartChar;
|
|
166
|
+ useStartLine = selection.getEndLine();
|
|
167
|
+ useStartChar = selection.getEndPos();
|
|
168
|
+ useEndLine = selection.getStartLine();
|
|
169
|
+ useEndChar = selection.getStartPos();
|
176
|
170
|
}
|
177
|
|
- else if (selStartLine == selEndLine && selStartChar > selEndChar) {
|
|
171
|
+ else if (selection.getStartLine() == selection.getEndLine() &&
|
|
172
|
+ selection.getStartPos() > selection.getEndPos()) {
|
178
|
173
|
// Just swap the chars
|
179
|
|
- useStartLine = selStartLine;
|
180
|
|
- useStartChar = selEndChar;
|
181
|
|
- useEndLine = selEndLine;
|
182
|
|
- useEndChar = selStartChar;
|
|
174
|
+ useStartLine = selection.getStartLine();
|
|
175
|
+ useStartChar = selection.getEndPos();
|
|
176
|
+ useEndLine = selection.getEndLine();
|
|
177
|
+ useEndChar = selection.getStartPos();
|
183
|
178
|
}
|
184
|
179
|
else {
|
185
|
180
|
// Swap nothing
|
186
|
|
- useStartLine = selStartLine;
|
187
|
|
- useStartChar = selStartChar;
|
188
|
|
- useEndLine = selEndLine;
|
189
|
|
- useEndChar = selEndChar;
|
|
181
|
+ useStartLine = selection.getStartLine();
|
|
182
|
+ useStartChar = selection.getStartPos();
|
|
183
|
+ useEndLine = selection.getEndLine();
|
|
184
|
+ useEndChar = selection.getEndPos();
|
190
|
185
|
}
|
191
|
186
|
|
192
|
187
|
// Iterate through the lines
|
|
@@ -431,16 +426,16 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
|
431
|
426
|
}
|
432
|
427
|
|
433
|
428
|
if (e.getClickCount() == 2) {
|
434
|
|
- selStartLine = lineInfo.getLine();
|
435
|
|
- selEndLine = lineInfo.getLine();
|
436
|
|
- selStartChar = start;
|
437
|
|
- selEndChar = end;
|
|
429
|
+ selection.setStartLine(lineInfo.getLine());
|
|
430
|
+ selection.setEndLine(lineInfo.getLine());
|
|
431
|
+ selection.setStartPos(start);
|
|
432
|
+ selection.setEndPos(end);
|
438
|
433
|
}
|
439
|
434
|
else if (e.getClickCount() == 3) {
|
440
|
|
- selStartLine = lineInfo.getLine();
|
441
|
|
- selEndLine = lineInfo.getLine();
|
442
|
|
- selStartChar = 0;
|
443
|
|
- selEndChar = clickedText.length();
|
|
435
|
+ selection.setStartLine(lineInfo.getLine());
|
|
436
|
+ selection.setEndLine(lineInfo.getLine());
|
|
437
|
+ selection.setStartPos(0);
|
|
438
|
+ selection.setEndPos(clickedText.length());
|
444
|
439
|
}
|
445
|
440
|
}
|
446
|
441
|
|
|
@@ -653,7 +648,7 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
|
653
|
648
|
final AttributedCharacterIterator iterator = document.
|
654
|
649
|
getStyledIterator(lineInfo.getLine());
|
655
|
650
|
if (lineInfo.getIndex() < iterator.getBeginIndex() ||
|
656
|
|
- lineInfo.getIndex() > iterator.getEndIndex()) {
|
|
651
|
+ lineInfo.getIndex() > iterator.getEndIndex()) {
|
657
|
652
|
return;
|
658
|
653
|
}
|
659
|
654
|
iterator.setIndex(lineInfo.getIndex());
|
|
@@ -724,11 +719,11 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
|
724
|
719
|
}
|
725
|
720
|
if (info.getLine() != -1 && info.getPart() != -1) {
|
726
|
721
|
if (type == MouseEventType.CLICK) {
|
727
|
|
- selStartLine = info.getLine();
|
728
|
|
- selStartChar = info.getIndex();
|
|
722
|
+ selection.setStartLine(info.getLine());
|
|
723
|
+ selection.setStartPos(info.getIndex());
|
729
|
724
|
}
|
730
|
|
- selEndLine = info.getLine();
|
731
|
|
- selEndChar = info.getIndex();
|
|
725
|
+ selection.setEndLine(info.getLine());
|
|
726
|
+ selection.setEndPos(info.getIndex());
|
732
|
727
|
|
733
|
728
|
repaint();
|
734
|
729
|
}
|
|
@@ -800,27 +795,32 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
|
800
|
795
|
* @return Selected range info
|
801
|
796
|
*/
|
802
|
797
|
protected LinePosition getSelectedRange() {
|
803
|
|
- if (selStartLine > selEndLine) {
|
|
798
|
+ if (selection.getStartLine() > selection.getEndLine()) {
|
804
|
799
|
// Swap both
|
805
|
|
- return new LinePosition(selEndLine, selEndChar, selStartLine,
|
806
|
|
- selStartChar);
|
|
800
|
+ return new LinePosition(selection.getEndLine(),
|
|
801
|
+ selection.getEndPos(), selection.
|
|
802
|
+ getStartLine(),
|
|
803
|
+ selection.getStartPos());
|
807
|
804
|
}
|
808
|
|
- else if (selStartLine == selEndLine && selStartChar > selEndChar) {
|
|
805
|
+ else if (selection.getStartLine() == selection.getEndLine() &&
|
|
806
|
+ selection.getStartPos() > selection.getEndPos()) {
|
809
|
807
|
// Just swap the chars
|
810
|
|
- return new LinePosition(selStartLine, selEndChar, selEndLine,
|
811
|
|
- selStartChar);
|
|
808
|
+ return new LinePosition(selection.getStartLine(), selection.
|
|
809
|
+ getEndPos(), selection.getEndLine(),
|
|
810
|
+ selection.getStartPos());
|
812
|
811
|
}
|
813
|
812
|
else {
|
814
|
813
|
// Swap nothing
|
815
|
|
- return new LinePosition(selStartLine, selStartChar, selEndLine,
|
816
|
|
- selEndChar);
|
|
814
|
+ return new LinePosition(selection.getStartLine(), selection.
|
|
815
|
+ getStartPos(), selection.getEndLine(),
|
|
816
|
+ selection.getEndPos());
|
817
|
817
|
}
|
818
|
818
|
}
|
819
|
819
|
|
820
|
820
|
/** Clears the selection. */
|
821
|
821
|
protected void clearSelection() {
|
822
|
|
- selEndLine = selStartLine;
|
823
|
|
- selEndChar = selStartChar;
|
|
822
|
+ selection.setEndLine(selection.getStartLine());
|
|
823
|
+ selection.setEndPos(selection.getStartPos());
|
824
|
824
|
if (isVisible()) {
|
825
|
825
|
repaint();
|
826
|
826
|
}
|
|
@@ -832,10 +832,7 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
|
832
|
832
|
* @param position Line position
|
833
|
833
|
*/
|
834
|
834
|
public void setSelectedRange(final LinePosition position) {
|
835
|
|
- selStartLine = position.getStartLine();
|
836
|
|
- selStartChar = position.getStartPos();
|
837
|
|
- selEndLine = position.getEndLine();
|
838
|
|
- selEndChar = position.getEndPos();
|
|
835
|
+ selection = new LinePosition(position);
|
839
|
836
|
if (isVisible()) {
|
840
|
837
|
repaint();
|
841
|
838
|
}
|