Przeglądaj źródła

Added a class to represent a selected range in the textpane

Added some static methods in TextPane for getting text from lines
Fixed an unchecked type conversion in the parser

git-svn-id: http://svn.dmdirc.com/trunk@3486 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Gregory Holmes 16 lat temu
rodzic
commit
bc435fe04e

+ 1
- 1
src/com/dmdirc/parser/ProcessQuit.java Wyświetl plik

@@ -55,7 +55,7 @@ public class ProcessQuit extends IRCProcessor {
55 55
 		String sReason = "";
56 56
 		if (token.length > 2) { sReason = token[token.length-1]; }
57 57
 		
58
-		ArrayList<ChannelInfo> channelList = new ArrayList(myParser.getChannels());
58
+		ArrayList<ChannelInfo> channelList = new ArrayList<ChannelInfo>(myParser.getChannels());
59 59
 		for (ChannelInfo iChannel : channelList) {
60 60
 			iChannelClient = iChannel.getUser(iClient);
61 61
 			if (iChannelClient != null) {

+ 4
- 3
src/com/dmdirc/ui/swing/components/SwingSearchBar.java Wyświetl plik

@@ -28,6 +28,7 @@ import com.dmdirc.ui.interfaces.SearchBar;
28 28
 import com.dmdirc.ui.messages.ColourManager;
29 29
 import com.dmdirc.ui.swing.MainFrame;
30 30
 import com.dmdirc.ui.swing.actions.SearchAction;
31
+import com.dmdirc.ui.swing.textpane.LinePosition;
31 32
 import com.dmdirc.ui.swing.textpane.TextPane;
32 33
 
33 34
 import java.awt.event.ActionEvent;
@@ -274,7 +275,7 @@ public final class SwingSearchBar extends JPanel implements ActionListener,
274 275
                 } else {
275 276
                     //found, select and return found
276 277
                     textPane.setScrollBarPosition(line);
277
-                    textPane.setSelectedTexT(line, position, line, position + text.length());
278
+                    textPane.setSelectedTexT(new LinePosition(line, position, line, position + text.length()));
278 279
                     index = position;
279 280
                     return true;
280 281
                 }
@@ -339,7 +340,7 @@ public final class SwingSearchBar extends JPanel implements ActionListener,
339 340
                 } else {
340 341
                     //found, select and return found
341 342
                     textPane.setScrollBarPosition(line);
342
-                    textPane.setSelectedTexT(line, position, line, position + text.length());
343
+                    textPane.setSelectedTexT(new LinePosition(line, position, line, position + text.length()));
343 344
                     position = position + text.length();
344 345
                     index = position;
345 346
                     return true;
@@ -377,7 +378,7 @@ public final class SwingSearchBar extends JPanel implements ActionListener,
377 378
                 lineText = textPane.getTextFromLine(i).toLowerCase(Locale.getDefault());
378 379
                 position = lineText.indexOf(text.toLowerCase(Locale.getDefault()));
379 380
             }
380
-            if (position != -1 && textPane.getSelectedRange()[0] != i) {
381
+            if (position != -1 && textPane.getSelectedRange().getStartLine() != i) {
381 382
                 foundText = true;
382 383
                 break;
383 384
             }

+ 3
- 3
src/com/dmdirc/ui/swing/components/TextFrame.java Wyświetl plik

@@ -47,6 +47,7 @@ import com.dmdirc.ui.swing.actions.HyperlinkCopyAction;
47 47
 import com.dmdirc.ui.swing.actions.NicknameCopyAction;
48 48
 import com.dmdirc.ui.swing.actions.SearchAction;
49 49
 import com.dmdirc.ui.swing.actions.TextPaneCopyAction;
50
+import com.dmdirc.ui.swing.textpane.LineInfo;
50 51
 import com.dmdirc.ui.swing.textpane.TextPane;
51 52
 import com.dmdirc.ui.swing.textpane.TextPane.ClickType;
52 53
 import com.dmdirc.ui.swing.textpane.TextPanePageUpAction;
@@ -562,10 +563,9 @@ public abstract class TextFrame extends JInternalFrame implements Window,
562 563
             final MouseClickType type) {
563 564
         final Point point = getTextPane().getMousePosition();
564 565
         if (e.getSource() == getTextPane() && point != null) {
565
-            final int[] lineInfo = getTextPane().getClickPosition(point);
566
+            final LineInfo lineInfo = getTextPane().getClickPosition(point);
566 567
             final ClickType clickType = getTextPane().getClickType(lineInfo);
567
-            final String attribute = (String) getTextPane().
568
-                    getAttributeValueAtPoint(lineInfo);
568
+            final String attribute = (String) getTextPane().getAttributeValueAtPoint(lineInfo);
569 569
             if (e.isPopupTrigger()) {
570 570
                 showPopupMenuInternal(clickType, point, attribute);
571 571
             } else {

+ 23
- 0
src/com/dmdirc/ui/swing/textpane/LineInfo.java Wyświetl plik

@@ -31,6 +31,8 @@ public final class LineInfo {
31 31
     private final int line;
32 32
     /** What part of a line. */
33 33
     private final int part;
34
+    /** Character index? */
35
+    private final int index;
34 36
     
35 37
     /** 
36 38
      * Creates a new instance of LineInfo. 
@@ -39,8 +41,20 @@ public final class LineInfo {
39 41
      * @param part line wrap number
40 42
      */
41 43
     public LineInfo(final int line, final int part) {
44
+        this(line, part, -1);
45
+    }
46
+    
47
+    /** 
48
+     * Creates a new instance of LineInfo. 
49
+     *
50
+     * @param line Line number
51
+     * @param part line wrap number
52
+     * @param index Position index
53
+     */
54
+    public LineInfo(final int line, final int part, final int index) {
42 55
         this.line = line;
43 56
         this.part = part;
57
+        this.index = index;
44 58
     }
45 59
     
46 60
     /**
@@ -60,4 +74,13 @@ public final class LineInfo {
60 74
     public int getPart() {
61 75
         return part;
62 76
     }
77
+    
78
+    /**
79
+     * Returns the index for this line.
80
+     * 
81
+     * @return Index for the line of -1
82
+     */
83
+    public int getIndex() {
84
+        return index;
85
+    }
63 86
 }

+ 126
- 0
src/com/dmdirc/ui/swing/textpane/LinePosition.java Wyświetl plik

@@ -0,0 +1,126 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ * 
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ * 
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ * 
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.ui.swing.textpane;
24
+
25
+/**
26
+ * Holds information about a range of text.
27
+ */
28
+public class LinePosition {
29
+
30
+    /** Starting line. */
31
+    private int startLine;
32
+    /** Ending line. */
33
+    private int endLine;
34
+    /** Starting position. */
35
+    private int startPos;
36
+    /** Ending position. */
37
+    private int endPos;
38
+
39
+    /**
40
+     * Constructs a new line position.
41
+     * 
42
+     * @param startLine Starting line
43
+     * @param endLine Ending line
44
+     * @param startPos Starting position
45
+     * @param endPos Ending position
46
+     */
47
+    public LinePosition(final int startLine, final int startPos,
48
+            final int endLine, final int endPos) {
49
+        this.startLine = startLine;
50
+        this.endLine = endLine;
51
+        this.startPos = startPos;
52
+        this.endPos = endPos;
53
+    }
54
+
55
+    /**
56
+     * Returns the end line for this position.
57
+     * 
58
+     * @return End line
59
+     */
60
+    public int getEndLine() {
61
+        return endLine;
62
+    }
63
+
64
+    /**
65
+     * Returns the end position for this position.
66
+     * 
67
+     * @return End position
68
+     */
69
+    public int getEndPos() {
70
+        return endPos;
71
+    }
72
+
73
+    /**
74
+     * Returns the start line for this position.
75
+     * 
76
+     * @return Start line
77
+     */
78
+    public int getStartLine() {
79
+        return startLine;
80
+    }
81
+
82
+    /**
83
+     * Returns the start position for this position.
84
+     * 
85
+     * @return Start position
86
+     */
87
+    public int getStartPos() {
88
+        return startPos;
89
+    }
90
+    
91
+    /**
92
+     * Sets the positions end line.
93
+     * 
94
+     * @param endLine new end line
95
+     */
96
+    public void setEndLine(int endLine) {
97
+        this.endLine = endLine;
98
+    }
99
+
100
+    /**
101
+     * Sets the positions end line.
102
+     * 
103
+     * @param endPos new end line
104
+     */
105
+    public void setEndPos(int endPos) {
106
+        this.endPos = endPos;
107
+    }
108
+
109
+    /**
110
+     * Sets the positions start line.
111
+     * 
112
+     * @param startLine new start line
113
+     */
114
+    public void setStartLine(int startLine) {
115
+        this.startLine = startLine;
116
+    }
117
+
118
+    /**
119
+     * Sets the positions start position.
120
+     * 
121
+     * @param startPos new start position
122
+     */
123
+    public void setStartPos(int startPos) {
124
+        this.startPos = startPos;
125
+    }
126
+}

+ 99
- 48
src/com/dmdirc/ui/swing/textpane/TextPane.java Wyświetl plik

@@ -305,13 +305,21 @@ public final class TextPane extends JComponent implements AdjustmentListener,
305 305
         }
306 306
     }
307 307
     
308
-    /** {@inheritDoc}. */
308
+    /** 
309
+     * {@inheritDoc}
310
+     * 
311
+     * @param e Mouse wheel event
312
+     */
309 313
     @Override
310 314
     public void adjustmentValueChanged(final AdjustmentEvent e) {
311 315
         setScrollBarPosition(e.getValue());
312 316
     }
313 317
     
314
-    /** {@inheritDoc}. */
318
+    /** 
319
+     * {@inheritDoc}
320
+     * 
321
+     * @param e Mouse wheel event
322
+     */
315 323
     @Override
316 324
     public void mouseWheelMoved(final MouseWheelEvent e) {
317 325
         if (scrollBar.isEnabled()) {
@@ -331,36 +339,41 @@ public final class TextPane extends JComponent implements AdjustmentListener,
331 339
      *
332 340
      * @return line number, line part, position in whole line
333 341
      */
334
-    public int[] getClickPosition(final Point point) {
342
+    public LineInfo getClickPosition(final Point point) {
335 343
         return canvas.getClickPosition(point);
336 344
     }
337 345
     
338 346
     /**
339 347
      * Returns the selected text.
348
+     * 
349
+     *     *    <li>0 = start line</li>
350
+     *    <li>1 = start char</li>
351
+     *    <li>2 = end line</li>
352
+     *    <li>3 = end char</li>
340 353
      *
341 354
      * @return Selected text
342 355
      */
343 356
     public String getSelectedText() {
344 357
         final StringBuffer selectedText = new StringBuffer();
345
-        final int[] selectedRange = canvas.getSelectedRange();
358
+        final LinePosition selectedRange = canvas.getSelectedRange();
346 359
         
347
-        for (int i = selectedRange[0]; i <= selectedRange[2]; i++) {
348
-            if (i != selectedRange[0]) {
360
+        for (int i = selectedRange.getStartLine(); i <= selectedRange.getEndLine(); i++) {
361
+            if (i != selectedRange.getStartLine()) {
349 362
                 selectedText.append('\n');
350 363
             }
351 364
             if (document.getLine(i) == null) {
352 365
                 return "";
353 366
             }
354 367
             final AttributedCharacterIterator iterator = document.getLine(i).getIterator();
355
-            if (selectedRange[2] == selectedRange[0]) {
368
+            if (selectedRange.getEndLine() == selectedRange.getStartLine()) {
356 369
                 //loop through range
357
-                selectedText.append(getTextFromLine(iterator, selectedRange[1], selectedRange[3]));
358
-            } else if (i == selectedRange[0]) {
370
+                selectedText.append(getTextFromLine(iterator, selectedRange.getStartPos(), selectedRange.getEndPos()));
371
+            } else if (i == selectedRange.getStartLine()) {
359 372
                 //loop from start of range to the end
360
-                selectedText.append(getTextFromLine(iterator, selectedRange[1], iterator.getEndIndex()));
361
-            } else if (i == selectedRange[2]) {
373
+                selectedText.append(getTextFromLine(iterator, selectedRange.getStartPos(), iterator.getEndIndex()));
374
+            } else if (i == selectedRange.getEndLine()) {
362 375
                 //loop from start to end of range
363
-                selectedText.append(getTextFromLine(iterator, 0, selectedRange[3]));
376
+                selectedText.append(getTextFromLine(iterator, 0, selectedRange.getEndPos()));
364 377
             } else {
365 378
                 //loop the whole line
366 379
                 selectedText.append(getTextFromLine(iterator, 0, iterator.getEndIndex()));
@@ -374,14 +387,8 @@ public final class TextPane extends JComponent implements AdjustmentListener,
374 387
      * Returns the selected range.
375 388
      *
376 389
      * @return selected range
377
-     *  <ul>
378
-     *    <li>0 = start line</li>
379
-     *    <li>1 = start char</li>
380
-     *    <li>2 = end line</li>
381
-     *    <li>3 = end char</li>
382
-     *  </ul>
383 390
      */
384
-    public int[] getSelectedRange() {
391
+    public LinePosition getSelectedRange() {
385 392
         return canvas.getSelectedRange();
386 393
     }
387 394
     
@@ -391,21 +398,17 @@ public final class TextPane extends JComponent implements AdjustmentListener,
391 398
      * @return true iif there is a selected range
392 399
      */
393 400
     public boolean hasSelectedRange() {
394
-        final int[] selectedRange = canvas.getSelectedRange();
395
-        return !(selectedRange[0] == selectedRange[2] && selectedRange[1] == selectedRange[3]);
401
+        final LinePosition selectedRange = canvas.getSelectedRange();
402
+        return !(selectedRange.getStartLine() == selectedRange.getEndLine() && selectedRange.getStartPos() == selectedRange.getEndPos());
396 403
     }
397 404
     
398 405
     /**
399 406
      * Selects the specified region of text.
400 407
      *
401
-     * @param startLine Start line
402
-     * @param startChar Start char
403
-     * @param endLine End line
404
-     * @param endChar End char
408
+     * @param position Line position
405 409
      */
406
-    public void setSelectedTexT(final int startLine, final int startChar,
407
-            final int endLine, final int endChar) {
408
-        canvas.setSelectedRange(startLine, startChar, endLine, endChar);
410
+    public void setSelectedTexT(final LinePosition position) {
411
+        canvas.setSelectedRange(position);
409 412
     }
410 413
     
411 414
     /**
@@ -417,7 +420,20 @@ public final class TextPane extends JComponent implements AdjustmentListener,
417 420
      */
418 421
     public String getTextFromLine(final int line) {
419 422
         final AttributedCharacterIterator iterator = document.getLine(line).getIterator();
420
-        return getTextFromLine(iterator, 0, iterator.getEndIndex());
423
+        return getTextFromLine(iterator, 0, iterator.getEndIndex(), document);
424
+    }
425
+    
426
+    /**
427
+     * Returns the entire text from the specified line.
428
+     *
429
+     * @param line line to retrieve text from
430
+     * @param document Document to retrieve text from
431
+     * 
432
+     * @return Text from the line
433
+     */
434
+    public static String getTextFromLine(final int line, final IRCDocument document) {
435
+        final AttributedCharacterIterator iterator = document.getLine(line).getIterator();
436
+        return getTextFromLine(iterator, 0, iterator.getEndIndex(), document);
421 437
     }
422 438
     
423 439
     /**
@@ -431,7 +447,22 @@ public final class TextPane extends JComponent implements AdjustmentListener,
431 447
      */
432 448
     public String getTextFromLine(final int line, final int start,
433 449
             final int end) {
434
-        return getTextFromLine(document.getLine(line).getIterator(), start, end);
450
+        return getTextFromLine(document.getLine(line).getIterator(), start, end, document);
451
+    }
452
+    
453
+    /**
454
+     * Returns the range of text from the specified iterator.
455
+     *
456
+     * @param line line to retrieve text from
457
+     * @param start Start index in the iterator
458
+     * @param end End index in the iterator
459
+     * @param document Document to retrieve text from
460
+     *
461
+     * @return Text in the range from the line
462
+     */
463
+    public static String getTextFromLine(final int line, final int start,
464
+            final int end, final IRCDocument document) {
465
+        return getTextFromLine(document.getLine(line).getIterator(), start, end, document);
435 466
     }
436 467
     
437 468
     /**
@@ -442,13 +473,19 @@ public final class TextPane extends JComponent implements AdjustmentListener,
442 473
      * @return Text in the range from the line
443 474
      */
444 475
     public String getTextFromLine(final AttributedCharacterIterator iterator) {
445
-        final int end = iterator.getEndIndex();
446
-        final int start = iterator.getBeginIndex();
447
-        final StringBuffer text = new StringBuffer();
448
-        for (iterator.setIndex(start); iterator.getIndex() < end; iterator.next()) {
449
-            text.append(iterator.current());
450
-        }
451
-        return text.toString();
476
+        return getTextFromLine(iterator, iterator.getBeginIndex(), iterator.getEndIndex(), document);
477
+    }
478
+    
479
+    /**
480
+     * Returns the range of text from the specified iterator.
481
+     *
482
+     * @param iterator iterator to get text from
483
+     * @param document Document to retrieve text from
484
+     *
485
+     * @return Text in the range from the line
486
+     */
487
+    public static String getTextFromLine(final AttributedCharacterIterator iterator, final IRCDocument document) {
488
+        return getTextFromLine(iterator, iterator.getBeginIndex(), iterator.getEndIndex(), document);
452 489
     }
453 490
     
454 491
     /**
@@ -462,6 +499,21 @@ public final class TextPane extends JComponent implements AdjustmentListener,
462 499
      */
463 500
     public String getTextFromLine(final AttributedCharacterIterator iterator,
464 501
             final int start, final int end) {
502
+        return getTextFromLine(iterator, start, end, document);
503
+    }
504
+    
505
+    /**
506
+     * Returns the range of text from the specified iterator.
507
+     *
508
+     * @param iterator iterator to get text from
509
+     * @param start Start index in the iterator
510
+     * @param end End index in the iterator
511
+     * @param document Document to retrieve text from
512
+     *
513
+     * @return Text in the range from the line
514
+     */
515
+    public static String getTextFromLine(final AttributedCharacterIterator iterator,
516
+            final int start, final int end, final IRCDocument document) {
465 517
         final StringBuffer text = new StringBuffer();
466 518
         for (iterator.setIndex(start); iterator.getIndex() < end; iterator.next()) {
467 519
             text.append(iterator.current());
@@ -476,7 +528,7 @@ public final class TextPane extends JComponent implements AdjustmentListener,
476 528
      * 
477 529
      * @return Click type for specified position
478 530
      */
479
-    public ClickType getClickType(final int[] lineInfo) {
531
+    public ClickType getClickType(final LineInfo lineInfo) {
480 532
         return canvas.getClickType(lineInfo);
481 533
     }
482 534
     
@@ -503,7 +555,7 @@ public final class TextPane extends JComponent implements AdjustmentListener,
503 555
      * 
504 556
      * @return Specified value
505 557
      */
506
-    public Object getAttributeValueAtPoint(int[] lineInfo) {
558
+    public Object getAttributeValueAtPoint(LineInfo lineInfo) {
507 559
         return canvas.getAttributeValueAtPoint(lineInfo);
508 560
     }
509 561
     
@@ -538,20 +590,19 @@ public final class TextPane extends JComponent implements AdjustmentListener,
538 590
             return;
539 591
         }
540 592
         final int trimmedLines = document.getNumLines() - numLines;
541
-        final int[] selectedRange = getSelectedRange();
593
+        final LinePosition selectedRange = getSelectedRange();
542 594
         
543
-        selectedRange[0] -= trimmedLines;
544
-        selectedRange[2] -= trimmedLines;
595
+        selectedRange.setStartLine(selectedRange.getStartLine() - trimmedLines);
596
+        selectedRange.setEndLine(selectedRange.getEndLine() - trimmedLines);
545 597
         
546
-        if (selectedRange[0] < 0) {
547
-            selectedRange[0] = 0;
598
+        if (selectedRange.getStartLine() < 0) {
599
+            selectedRange.setStartLine(0);
548 600
         }
549
-        if (selectedRange[2] < 0) {
550
-            selectedRange[2] = 0;
601
+        if (selectedRange.getEndLine() < 0) {
602
+            selectedRange.setEndLine(0);
551 603
         }
552 604
         
553
-        setSelectedTexT(selectedRange[0], selectedRange[1], 
554
-                selectedRange[2], selectedRange[3]);
605
+        setSelectedTexT(selectedRange);
555 606
         document.trim(numLines);
556 607
     }
557 608
     

+ 40
- 50
src/com/dmdirc/ui/swing/textpane/TextPaneCanvas.java Wyświetl plik

@@ -388,28 +388,28 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
388 388
         final int start;
389 389
         final int end;
390 390
         
391
-        final int[] lineInfo = getClickPosition(getMousePosition());
391
+        final LineInfo lineInfo = getClickPosition(getMousePosition());
392 392
         
393
-        if (lineInfo[0] != -1) {
394
-            clickedText = textPane.getTextFromLine(lineInfo[0]);
393
+        if (lineInfo.getLine() != -1) {
394
+            clickedText = textPane.getTextFromLine(lineInfo.getLine());
395 395
             
396
-            if (lineInfo[2] == -1) {
396
+            if (lineInfo.getIndex() == -1) {
397 397
                 start = -1;
398 398
                 end = -1;
399 399
             } else {
400
-                final int[] extent = getSurroundingWordIndexes(clickedText, lineInfo[2]);
400
+                final int[] extent = getSurroundingWordIndexes(clickedText, lineInfo.getIndex());
401 401
                 start = extent[0];
402 402
                 end = extent[1];
403 403
             }
404 404
             
405 405
             if (e.getClickCount() == 2) {
406
-                selStartLine = lineInfo[0];
407
-                selEndLine = lineInfo[0];
406
+                selStartLine = lineInfo.getLine();
407
+                selEndLine = lineInfo.getLine();
408 408
                 selStartChar = start;
409 409
                 selEndChar = end;
410 410
             } else if (e.getClickCount() == 3) {
411
-                selStartLine = lineInfo[0];
412
-                selEndLine = lineInfo[0];
411
+                selStartLine = lineInfo.getLine();
412
+                selEndLine = lineInfo.getLine();
413 413
                 selStartChar = 0;
414 414
                 selEndChar = clickedText.length();
415 415
             }
@@ -426,10 +426,10 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
426 426
      * 
427 427
      * @return Click type for specified position
428 428
      */
429
-    public ClickType getClickType(final int[] lineInfo) {
430
-        if (lineInfo[0] != -1) {
431
-            final AttributedCharacterIterator iterator = document.getLine(lineInfo[0]).getIterator();
432
-            iterator.setIndex(lineInfo[2]);
429
+    public ClickType getClickType(final LineInfo lineInfo) {
430
+        if (lineInfo.getLine() != -1) {
431
+            final AttributedCharacterIterator iterator = document.getLine(lineInfo.getLine()).getIterator();
432
+            iterator.setIndex(lineInfo.getIndex());
433 433
             Object linkattr = iterator.getAttributes().get(IRCTextAttribute.HYPERLINK);
434 434
             if (linkattr instanceof String) {
435 435
                 return ClickType.HYPERLINK;
@@ -454,10 +454,10 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
454 454
      * 
455 455
      * @return Specified value
456 456
      */
457
-    public Object getAttributeValueAtPoint(int[] lineInfo) {
458
-        if (lineInfo[0] != -1) {
459
-            final AttributedCharacterIterator iterator = document.getLine(lineInfo[0]).getIterator();
460
-            iterator.setIndex(lineInfo[2]);
457
+    public Object getAttributeValueAtPoint(LineInfo lineInfo) {
458
+        if (lineInfo.getLine() != -1) {
459
+            final AttributedCharacterIterator iterator = document.getLine(lineInfo.getLine()).getIterator();
460
+            iterator.setIndex(lineInfo.getIndex());
461 461
             Object linkattr = iterator.getAttributes().get(IRCTextAttribute.HYPERLINK);
462 462
             if (linkattr instanceof String) {
463 463
                 return linkattr;
@@ -583,14 +583,14 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
583 583
     
584 584
     /** Checks for a link under the cursor and sets appropriately. */
585 585
     private void checkForLink() {
586
-        final int[] info = getClickPosition(getMousePosition());
586
+        final LineInfo info = getClickPosition(getMousePosition());
587 587
         
588
-        if (info[0] != -1 && document.getLine(info[0]) != null) {
589
-            final AttributedCharacterIterator iterator = document.getLine(info[0]).getIterator();
590
-            if (info[2] < iterator.getBeginIndex() || info[2] > iterator.getEndIndex()) {
588
+        if (info.getLine() != -1 && document.getLine(info.getLine()) != null) {
589
+            final AttributedCharacterIterator iterator = document.getLine(info.getLine()).getIterator();
590
+            if (info.getIndex() < iterator.getBeginIndex() || info.getIndex() > iterator.getEndIndex()) {
591 591
                 return;
592 592
             }
593
-            iterator.setIndex(info[2]);
593
+            iterator.setIndex(info.getIndex());
594 594
             Object linkattr = iterator.getAttributes().get(IRCTextAttribute.HYPERLINK);
595 595
             if (linkattr instanceof String) {
596 596
                 setCursor(HAND_CURSOR);
@@ -631,14 +631,14 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
631 631
                     }
632 632
                 }
633 633
             } else {
634
-                final int[] info = getClickPosition(point);
635
-                if (info[0] != -1 && info[1] != -1) {
634
+                final LineInfo info = getClickPosition(point);
635
+                if (info.getIndex() != -1 && info.getPart() != -1) {
636 636
                     if (type == MouseEventType.CLICK) {
637
-                        selStartLine = info[0];
638
-                        selStartChar = info[2];
637
+                        selStartLine = info.getLine();
638
+                        selStartChar = info.getIndex();
639 639
                     }
640
-                    selEndLine = info[0];
641
-                    selEndChar = info[2];
640
+                    selEndLine = info.getLine();
641
+                    selEndChar = info.getIndex();
642 642
                     
643 643
                     if (isVisible()) {
644 644
                         repaint();
@@ -656,7 +656,7 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
656 656
      *
657 657
      * @return line number, line part, position in whole line
658 658
      */
659
-    public int[] getClickPosition(final Point point) {
659
+    public LineInfo getClickPosition(final Point point) {
660 660
         int lineNumber = -1;
661 661
         int linePart = -1;
662 662
         int pos = 0;
@@ -682,30 +682,24 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
682 682
             }
683 683
         }
684 684
         
685
-        return new int[]{lineNumber, linePart, pos};
685
+        return new LineInfo(lineNumber, linePart, pos);
686 686
     }
687 687
     
688 688
     /**
689 689
      * Returns the selected range info.
690
-     *  <ul>
691
-     *    <li>0 = start line</li>
692
-     *    <li>1 = start char</li>
693
-     *    <li>2 = end line</li>
694
-     *    <li>3 = end char</li>
695
-     *  </ul>
696 690
      *
697 691
      * @return Selected range info
698 692
      */
699
-    protected int[] getSelectedRange() {
693
+    protected LinePosition getSelectedRange() {
700 694
         if (selStartLine > selEndLine) {
701 695
             // Swap both
702
-            return new int[]{selEndLine, selEndChar, selStartLine, selStartChar, };
696
+            return new LinePosition(selEndLine, selEndChar, selStartLine, selStartChar);
703 697
         } else if (selStartLine == selEndLine && selStartChar > selEndChar) {
704 698
             // Just swap the chars
705
-            return new int[]{selStartLine, selEndChar, selEndLine, selStartChar, };
699
+            return new LinePosition(selStartLine, selEndChar, selEndLine, selStartChar);
706 700
         } else {
707 701
             // Swap nothing
708
-            return new int[]{selStartLine, selStartChar, selEndLine, selEndChar, };
702
+            return new LinePosition(selStartLine, selStartChar, selEndLine, selEndChar);
709 703
         }
710 704
     }
711 705
     
@@ -721,17 +715,13 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
721 715
     /**
722 716
      * Selects the specified region of text.
723 717
      *
724
-     * @param startLine Start line
725
-     * @param startChar Start char
726
-     * @param endLine End line
727
-     * @param endChar End char
718
+     * @param position Line position
728 719
      */
729
-    public void setSelectedRange(final int startLine, final int startChar,
730
-            final int endLine, final int endChar) {
731
-        selStartLine = startLine;
732
-        selStartChar = startChar;
733
-        selEndLine = endLine;
734
-        selEndChar = endChar;
720
+    public void setSelectedRange(final LinePosition position) {
721
+        selStartLine = position.getStartLine();
722
+        selStartChar = position.getStartPos();
723
+        selEndLine = position.getEndLine();
724
+        selEndChar = position.getEndPos();
735 725
         if (isVisible()) {
736 726
             repaint();
737 727
         }

Ładowanie…
Anuluj
Zapisz