/** * 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. 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, String) * @see #addOffsetTrackingIcon(int, Icon) * @see #removeTrackingIcon(GutterIconInfo) */ public GutterIconInfo addLineTrackingIcon(int line, Icon icon) throws BadLocationException { return addLineTrackingIcon(line, icon, null); }
@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); }
@Test(expected = BadLocationException.class) public void testAddLineTrackingIcon_2Arg_Invalid() throws Exception { RTextArea textArea = new RTextArea(PLAIN_TEXT); Gutter gutter = new Gutter(textArea); Icon icon = new TestIcon(); gutter.addLineTrackingIcon(4, 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. 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, String) * @see #addOffsetTrackingIcon(int, Icon) * @see #removeTrackingIcon(GutterIconInfo) */ public GutterIconInfo addLineTrackingIcon(int line, Icon icon) throws BadLocationException { return addLineTrackingIcon(line, icon, null); }
@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 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 testAddLineTrackingIcon_2Arg_Valid() throws Exception { RTextArea textArea = new RTextArea(PLAIN_TEXT); Gutter gutter = new Gutter(textArea); Icon icon = new TestIcon(); GutterIconInfo gii = gutter.addLineTrackingIcon(1, icon); int line1Start = textArea.getText().indexOf('\n') + 1; Assert.assertTrue(gii.getIcon() == icon); Assert.assertEquals(line1Start, gii.getMarkedOffset()); Assert.assertNull(gii.getToolTip()); textArea.insert("a", 0); line1Start = textArea.getText().indexOf('\n') + 1; // Should have advanced 1 Assert.assertEquals(line1Start, gii.getMarkedOffset()); }
@Test public void testAddLineTrackingIcon_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.addLineTrackingIcon(1, icon, tip); int line1Start = textArea.getText().indexOf('\n') + 1; Assert.assertTrue(gii.getIcon() == icon); Assert.assertEquals(line1Start, gii.getMarkedOffset()); Assert.assertEquals(tip, gii.getToolTip()); textArea.insert("a", 0); line1Start = textArea.getText().indexOf('\n') + 1; // Should have advanced 1 Assert.assertEquals(line1Start, gii.getMarkedOffset()); }
private void adicionaPontoDeParada(int indiceDaLinha) { if (!existePontoDeParadaNaLinha(indiceDaLinha)) { try { Gutter gutter = RSyntaxUtilities.getGutter(this); GutterIconInfo gutterInfo = gutter.addLineTrackingIcon(indiceDaLinha - 1, iconePontoDeParadaDesativado); pontosDeParada.add(new IconePontoDeParada(gutterInfo, false));//os pontos são sempre criados como desativados } catch (BadLocationException e) { // } } } }
/** * Adds an error message. * * @param line the line the message belongs to * @param message the message text */ public void addCodeErrorMessage(int line, String message) { // numberView.addCodeErrorMessage(line, message); //editor.getParagraphs().get(line - 1).setErrorView(true); parent.getMainCanvas().getMessageBox(). addMessage("Can't compile code:", message, null, MessageType.ERROR); BufferedImage errorImage = ImageUtils.createCompatibleImage(10, 10); Graphics2D g2 = errorImage.createGraphics(); g2.fillRect(0, 0, 10, 10); g2.dispose(); ImageIcon icon = new ImageIcon(errorImage); try { getScrollPane().getGutter().addLineTrackingIcon(line, icon); } catch (BadLocationException ex) { Logger.getLogger(VCodeEditor.class.getName()). log(Level.SEVERE, null, ex); } }
private void alternaStatusDoPontoDeParada(IconePontoDeParada pontoDeParada) throws BadLocationException { if (pontoDeParada != null) { Gutter gutter = RSyntaxUtilities.getGutter(this); gutter.removeTrackingIcon(pontoDeParada.getGutterInfo());//remove o ícone antigo para criar um outro no mesmo lugar do gutter boolean novoEstado = !pontoDeParada.estaAtivado();//alterna o estado int linha = getLineOfOffset(pontoDeParada.getGutterInfo().getMarkedOffset()); GutterIconInfo novoGutterInfo = gutter.addLineTrackingIcon(linha, novoEstado ? iconePontoDeParadaAtivado : iconePontoDeParadaDesativado); pontoDeParada.setaStatus(novoEstado, novoGutterInfo); disparaPontosDeParadaAtualizados(); } }
private void destacarErroExecucao(int linha, int coluna) { try { int line = Math.max(0, linha - 1); trackingIconDoErro = scrollPane.getGutter().addLineTrackingIcon(line, IconFactory.createIcon(IconFactory.CAMINHO_ICONES_PEQUENOS, "stop.png")); if (tagErro != null) { textArea.removeLineHighlight(tagErro); } int linhaAtual = textArea.getLineOfOffset(textArea.getCaretPosition()); if (linhaAtual == line) { textArea.setHighlightCurrentLine(false); } tagErro = textArea.addLineHighlight(line, corErro); ultimaLinhaErro = line; ultimaColunaErro = coluna; rolarAtePosicao(line, coluna); int posicao = textArea.getLineStartOffset(line); textArea.getFoldManager().ensureOffsetNotInClosedFold(posicao); } catch (BadLocationException ex) { PortugolStudio.getInstancia().getTratadorExcecoes().exibirExcecao(ex); } } private GutterIconInfo trackingIconDoErro;