/** * Creates a scroll pane. * * @param comp The component this scroll pane should display. This should * be an instance of {@link RTextArea}, * <code>javax.swing.JLayer</code> (or the older * <code>org.jdesktop.jxlayer.JXLayer</code>), or <code>null</code>. * If this argument is <code>null</code>, you must call * {@link #setViewportView(Component)}, passing in an instance of * one of the types above. * @param lineNumbers Whether line numbers are initially enabled. * @param lineNumberColor The color to use for line numbers. */ public RTextScrollPane(Component comp, boolean lineNumbers, Color lineNumberColor) { super(comp); RTextArea textArea = getFirstRTextAreaDescendant(comp); // Create the gutter for this document. Font defaultFont = new Font("Monospaced", Font.PLAIN, 12); gutter = new Gutter(textArea); gutter.setLineNumberFont(defaultFont); gutter.setLineNumberColor(lineNumberColor); setLineNumbersEnabled(lineNumbers); // Set miscellaneous properties. setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_ALWAYS); setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_AS_NEEDED); }
/** * Constructor. * * @param textArea The parent text area. */ public Gutter(RTextArea textArea) { listener = new TextAreaListener(); lineNumberColor = Color.gray; lineNumberFont = RTextArea.getDefaultFont(); lineNumberingStartIndex = 1; iconRowHeaderInheritsGutterBackground = false; setTextArea(textArea); setLayout(new BorderLayout()); if (this.textArea!=null) { // Enable line numbers our first time through if they give us // a text area. setLineNumbersEnabled(true); if (this.textArea instanceof RSyntaxTextArea) { RSyntaxTextArea rsta = (RSyntaxTextArea)this.textArea; setFoldIndicatorEnabled(rsta.isCodeFoldingEnabled()); } } setBorder(new GutterBorder(0, 0, 0, 1)); // Assume ltr Color bg = null; if (textArea!=null) { bg = textArea.getBackground(); // May return null if image bg } setBackground(bg!=null ? bg : Color.WHITE); }
@Test(expected = BadLocationException.class) public void testAddLineTrackingIcon_3Arg_Invalid() throws Exception { RTextArea textArea = new RTextArea(PLAIN_TEXT); Gutter gutter = new Gutter(textArea); Icon icon = new TestIcon(); String tip = "tip text"; gutter.addLineTrackingIcon(4, icon, tip); }
/** * Sets whether bookmarking is enabled. Note that a bookmarking icon * must be set via {@link #setBookmarkIcon(Icon)} before bookmarks are * truly enabled. * * @param enabled Whether bookmarking is enabled. * @see #isBookmarkingEnabled() * @see #setBookmarkIcon(Icon) */ public void setBookmarkingEnabled(boolean enabled) { iconArea.setBookmarkingEnabled(enabled); if (enabled && !isIconRowHeaderEnabled()) { setIconRowHeaderEnabled(true); } }
gutter.setBackground(gutterBackgroundColor); gutter.setBorderColor(gutterBorderColor); gutter.setActiveLineRangeColor(activeLineRangeColor); gutter.setIconRowHeaderInheritsGutterBackground(iconRowHeaderInheritsGutterBG); gutter.setLineNumberColor(lineNumberColor); String fontName = lineNumberFont!=null ? lineNumberFont : baseFont.getFamily(); baseFont.getSize(); Font font = getFont(fontName, Font.PLAIN, fontSize); gutter.setLineNumberFont(font); gutter.setFoldIndicatorForeground(foldIndicatorFG); gutter.setFoldBackground(foldBG); gutter.setArmedFoldBackground(armedFoldBG);
@Test public void getBookmarks_SomeBookmarks() throws Exception { RTextArea textArea = new RTextArea(PLAIN_TEXT); Gutter gutter = new Gutter(textArea); gutter.setBookmarkingEnabled(true); gutter.setBookmarkIcon(new TestIcon()); Assert.assertTrue(gutter.toggleBookmark(1)); Assert.assertTrue(gutter.toggleBookmark(2)); Assert.assertEquals(2, gutter.getBookmarks().length); // Non-null }
gutter.setBackground( new Color(Integer.parseInt(temaEditor.getString("background_editor"), 16))); gutter.setBorderColor( new Color(Integer.parseInt(temaEditor.getString("borda_barra_lateral"), 16))); gutter.setLineNumberColor( new Color(Integer.parseInt(temaEditor.getString("numeros_das_linhas"), 16))); gutter.setFoldIndicatorForeground( new Color(Integer.parseInt(temaEditor.getString("dobrador_de_codigo"), 16))); gutter.setFoldBackground( new Color(Integer.parseInt(temaEditor.getString("background_editor"), 16)));
@Test public void testSetIconRowHeaderEnabled() { RTextArea textArea = new RTextArea(PLAIN_TEXT); Gutter gutter = new Gutter(textArea); Assert.assertFalse(gutter.isIconRowHeaderEnabled()); gutter.setIconRowHeaderEnabled(true); Assert.assertTrue(gutter.isIconRowHeaderEnabled()); gutter.setIconRowHeaderEnabled(false); Assert.assertFalse(gutter.isIconRowHeaderEnabled()); }
@Test public void testGetLineNumberColor() { RTextArea textArea = new RTextArea(PLAIN_TEXT); Gutter gutter = new Gutter(textArea); Color color = Color.red; gutter.setLineNumberColor(color); Assert.assertEquals(color, gutter.getLineNumberColor()); color = Color.green; gutter.setLineNumberColor(color); Assert.assertEquals(color, gutter.getLineNumberColor()); }
@Test public void testSetLineNumbersEnabled() { RTextArea textArea = new RTextArea(PLAIN_TEXT); Gutter gutter = new Gutter(textArea); Assert.assertTrue(gutter.getLineNumbersEnabled()); gutter.setLineNumbersEnabled(true); Assert.assertTrue(gutter.getLineNumbersEnabled()); }
@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); }
@Test public void testRemoveAllTrackingIcons_Simple() throws Exception { RTextArea textArea = new RTextArea(PLAIN_TEXT); Gutter gutter = new Gutter(textArea); Icon icon = new TestIcon(); textArea.setSize(200, 200); gutter.addLineTrackingIcon(0, icon); Point p = new Point(0, 4); Assert.assertEquals(1, gutter.getTrackingIcons(p).length); gutter.removeAllTrackingIcons(); Assert.assertEquals(0, gutter.getTrackingIcons(p).length); }
@Test public void testSetBorderColor() { RTextArea textArea = new RTextArea(PLAIN_TEXT); Gutter gutter = new Gutter(textArea); Color color = Color.red; gutter.setBorderColor(color); Assert.assertEquals(color, gutter.getBorderColor()); color = Color.green; gutter.setBorderColor(color); Assert.assertEquals(color, gutter.getBorderColor()); }
@Test public void testSetLineNumberFont() { RTextArea textArea = new RTextArea(PLAIN_TEXT); Gutter gutter = new Gutter(textArea); Font font = new Font("Comic Sans", Font.PLAIN, 13); gutter.setLineNumberFont(font); Assert.assertEquals(font, gutter.getLineNumberFont()); font = new Font("Arial", Font.ITALIC, 22); gutter.setLineNumberFont(font); Assert.assertEquals(font, gutter.getLineNumberFont()); }
@Test public void getBookmarks_SomeBookmarks_NoIcon() throws Exception { RTextArea textArea = new RTextArea(PLAIN_TEXT); Gutter gutter = new Gutter(textArea); gutter.setBookmarkingEnabled(true); // Both enabled state and icon are reuqired Assert.assertEquals(0, gutter.getBookmarks().length); // Non-null }
@Test public void testRemoveTrackingIcon_Simple() throws Exception { RTextArea textArea = new RTextArea(PLAIN_TEXT); Gutter gutter = new Gutter(textArea); Icon icon = new TestIcon(); textArea.setSize(200, 200); GutterIconInfo info = gutter.addLineTrackingIcon(0, icon); Point p = new Point(0, 4); Assert.assertEquals(1, gutter.getTrackingIcons(p).length); gutter.removeTrackingIcon(info); Assert.assertEquals(0, gutter.getTrackingIcons(p).length); }
@Test public void testGetFoldBackground() { RTextArea textArea = new RTextArea(PLAIN_TEXT); Gutter gutter = new Gutter(textArea); Color color = Color.red; gutter.setFoldBackground(color); Assert.assertEquals(color, gutter.getFoldBackground()); color = Color.green; gutter.setFoldBackground(color); Assert.assertEquals(color, gutter.getFoldBackground()); }
@Test public void testGetFoldIndicatorForeground() { RTextArea textArea = new RTextArea(PLAIN_TEXT); Gutter gutter = new Gutter(textArea); Color color = Color.red; gutter.setFoldIndicatorForeground(color); Assert.assertEquals(color, gutter.getFoldIndicatorForeground()); color = Color.green; gutter.setFoldIndicatorForeground(color); Assert.assertEquals(color, gutter.getFoldIndicatorForeground()); }
@Test public void testGetActiveLineRangeColor() { RTextArea textArea = new RTextArea(PLAIN_TEXT); Gutter gutter = new Gutter(textArea); Color color = Color.blue; gutter.setActiveLineRangeColor(color); Assert.assertEquals(color, gutter.getActiveLineRangeColor()); color = Color.red; gutter.setActiveLineRangeColor(color); Assert.assertEquals(color, gutter.getActiveLineRangeColor()); }
@Test public void testSetIconRowHeaderInheritsGutterBackground() { RTextArea textArea = new RTextArea(PLAIN_TEXT); Gutter gutter = new Gutter(textArea); Assert.assertFalse(gutter.getIconRowHeaderInheritsGutterBackground()); gutter.setIconRowHeaderInheritsGutterBackground(true); Assert.assertTrue(gutter.getIconRowHeaderInheritsGutterBackground()); }