/** * Adds an icon that tracks an offset in the document, and is displayed * adjacent to the line numbers. This is useful for marking things such * as source code errors. * * @param offs The offset to track. * @param icon The icon to display. This should be small (say 16x16). * @return A tag for this icon. * @throws BadLocationException If <code>offs</code> is an invalid offset * into the text area. * @see #addOffsetTrackingIcon(int, Icon, String) * @see #addLineTrackingIcon(int, Icon) * @see #removeTrackingIcon(GutterIconInfo) */ public GutterIconInfo addOffsetTrackingIcon(int offs, Icon icon) throws BadLocationException { return addOffsetTrackingIcon(offs, icon, null); }
/** * Adds an icon that tracks an offset in the document, and is displayed * adjacent to the line numbers. This is useful for marking things such * as source code errors. * * @param line The line to track (zero-based). * @param icon The icon to display. This should be small (say 16x16). * @param tip An optional tool tip for the icon. * @return A tag for this icon. This can later be used in a call to * {@link #removeTrackingIcon(GutterIconInfo)} to remove this * icon. * @throws BadLocationException If <code>offs</code> is an invalid offset * into the text area. * @see #addLineTrackingIcon(int, Icon) * @see #addOffsetTrackingIcon(int, Icon) * @see #removeTrackingIcon(GutterIconInfo) */ public GutterIconInfo addLineTrackingIcon(int line, Icon icon, String tip) throws BadLocationException { int offs = textArea.getLineStartOffset(line); return addOffsetTrackingIcon(offs, icon, tip); }
@Test(expected = BadLocationException.class) public void testAddOffsetTrackingIcon_2Arg_Invalid() throws Exception { RTextArea textArea = new RTextArea(PLAIN_TEXT); Gutter gutter = new Gutter(textArea); Icon icon = new TestIcon(); gutter.addOffsetTrackingIcon(1024, icon); }
@Test(expected = BadLocationException.class) public void testAddOffsetTrackingIcon_3Arg_Invalid() throws Exception { RTextArea textArea = new RTextArea(PLAIN_TEXT); Gutter gutter = new Gutter(textArea); Icon icon = new TestIcon(); String tip = "tip text"; gutter.addOffsetTrackingIcon(1024, icon, tip); }
/** * Adds an icon that tracks an offset in the document, and is displayed * adjacent to the line numbers. This is useful for marking things such * as source code errors. * * @param offs The offset to track. * @param icon The icon to display. This should be small (say 16x16). * @return A tag for this icon. * @throws BadLocationException If <code>offs</code> is an invalid offset * into the text area. * @see #addOffsetTrackingIcon(int, Icon, String) * @see #addLineTrackingIcon(int, Icon) * @see #removeTrackingIcon(GutterIconInfo) */ public GutterIconInfo addOffsetTrackingIcon(int offs, Icon icon) throws BadLocationException { return addOffsetTrackingIcon(offs, icon, null); }
/** * Adds an icon that tracks an offset in the document, and is displayed * adjacent to the line numbers. This is useful for marking things such * as source code errors. * * @param line The line to track (zero-based). * @param icon The icon to display. This should be small (say 16x16). * @return A tag for this icon. * @throws BadLocationException If <code>offs</code> is an invalid offset * into the text area. * @see #addOffsetTrackingIcon(int, Icon) * @see #removeTrackingIcon(GutterIconInfo) */ public GutterIconInfo addLineTrackingIcon(int line, Icon icon) throws BadLocationException { int offs = textArea.getLineStartOffset(line); return addOffsetTrackingIcon(offs, icon); }
/** * Adds an icon that tracks an offset in the document, and is displayed * adjacent to the line numbers. This is useful for marking things such * as source code errors. * * @param line The line to track (zero-based). * @param icon The icon to display. This should be small (say 16x16). * @return A tag for this icon. * @throws BadLocationException If <code>offs</code> is an invalid offset * into the text area. * @see #addOffsetTrackingIcon(int, Icon) * @see #removeTrackingIcon(GutterIconInfo) */ public GutterIconInfo addLineTrackingIcon(int line, Icon icon) throws BadLocationException { int offs = textArea.getLineStartOffset(line); return addOffsetTrackingIcon(offs, icon); }
@Test public void testAddOffsetTrackingIcon_2Arg_Valid() throws Exception { RTextArea textArea = new RTextArea(PLAIN_TEXT); Gutter gutter = new Gutter(textArea); Icon icon = new TestIcon(); GutterIconInfo gii = gutter.addOffsetTrackingIcon(17, icon); Assert.assertTrue(gii.getIcon() == icon); Assert.assertEquals(17, gii.getMarkedOffset()); Assert.assertNull(gii.getToolTip()); textArea.insert("a", 3); Assert.assertEquals(18, gii.getMarkedOffset()); }
@Test public void testAddOffsetTrackingIcon_3Arg_Valid() throws Exception { RTextArea textArea = new RTextArea(PLAIN_TEXT); Gutter gutter = new Gutter(textArea); Icon icon = new TestIcon(); String tip = "tip text"; GutterIconInfo gii = gutter.addOffsetTrackingIcon(17, icon, tip); Assert.assertTrue(gii.getIcon() == icon); Assert.assertEquals(17, gii.getMarkedOffset()); Assert.assertEquals(tip, gii.getToolTip()); textArea.insert("a", 3); Assert.assertEquals(18, gii.getMarkedOffset()); }
/** * Adds an icon that tracks an offset in the document, and is displayed * adjacent to the line numbers. This is useful for marking things such * as source code errors. * * @param line The line to track (zero-based). * @param icon The icon to display. This should be small (say 16x16). * @param tip An optional tool tip for the icon. * @return A tag for this icon. This can later be used in a call to * {@link #removeTrackingIcon(GutterIconInfo)} to remove this * icon. * @throws BadLocationException If <code>offs</code> is an invalid offset * into the text area. * @see #addLineTrackingIcon(int, Icon) * @see #addOffsetTrackingIcon(int, Icon) * @see #removeTrackingIcon(GutterIconInfo) */ public GutterIconInfo addLineTrackingIcon(int line, Icon icon, String tip) throws BadLocationException { int offs = textArea.getLineStartOffset(line); return addOffsetTrackingIcon(offs, icon, tip); }