private void buildContentPanel() { editorPane = new JEditorPane (); editorPane.setContentType("text/rtf"); editorPane.addKeyListener(new InputListener()); // defaultAttrSet = ((StyledEditorKit)editorPane.getEditorKit()).getInputAttributes(); StyleConstants.setFontFamily(defaultAttrSet, "Lucida Sans"); Document doc = new DefaultStyledDocument(); editorPane.setDocument(doc); try { doc.insertString(0, initText, defaultAttrSet); } catch (Exception ex) { throw new RuntimeException(ex); } JScrollPane scrollPane = new JScrollPane(editorPane); frame.getContentPane().add(scrollPane, BorderLayout.CENTER); editorPane.setEditable(true); }
private void buildContentPanel() { editorPane = new JEditorPane (); editorPane.setContentType("text/rtf"); editorPane.addKeyListener(new InputListener()); // defaultAttrSet = ((StyledEditorKit)editorPane.getEditorKit()).getInputAttributes(); StyleConstants.setFontFamily(defaultAttrSet, "Lucinda Sans"); Document doc = new DefaultStyledDocument(); editorPane.setDocument(doc); try { doc.insertString(0, initText, defaultAttrSet); } catch (Exception ex) { throw new RuntimeException(ex); } JScrollPane scrollPane = new JScrollPane(editorPane); frame.getContentPane().add(scrollPane, BorderLayout.CENTER); editorPane.setEditable(true); }
private void newAutocomplete(KeyEvent e) { final JTextComponent input = (JTextComponent)e.getSource(); final String inputText = input.getText(); final String nameStart = inputText.substring(0, input.getSelectionStart()) + e.getKeyChar(); if (findAutocompleteName(nameStart)) { // Assert this.autocompleteName != null final String name = this.autocompleteName; SwingUtilities.invokeLater(() -> { try { input.getDocument().insertString( nameStart.length(), name.substring(nameStart.length()), null); input.select(nameStart.length(), name.length()); } catch (BadLocationException ex) { log.warn("Could not autocomplete name.", ex); } }); } }
@Override public String doInBackground() { if (openfired != null) { // Get the input stream and read from it try (InputStream in = openfired.getInputStream()) { int c; while ((c = in.read()) != -1) { try { StyleConstants.setFontFamily(styles, "courier new"); pane.getDocument().insertString(pane.getDocument().getLength(), "" + (char)c, styles); } catch (BadLocationException e) { // Ignore. } } } catch (IOException e) { e.printStackTrace(); } } return "ok"; } };
@Override public String doInBackground() { if (openfired != null) { // Get the input stream and read from it try (InputStream in = openfired.getErrorStream()) { int c; while ((c = in.read()) != -1) { try { StyleConstants.setForeground(styles, Color.red); pane.getDocument().insertString(pane.getDocument().getLength(), "" + (char)c, styles); } catch (BadLocationException e) { // Ignore. } } } catch (IOException e) { e.printStackTrace(); } } return "ok"; } };
public void redraw() { String text = editorPane.getText(); taggedContents = null; untaggedContents = null; if (!editorPane.getContentType().equals("text/html")) { editorPane.setContentType("text/rtf"); Document doc = editorPane.getDocument(); try { doc.insertString(0, text, defaultAttrSet); } catch (Exception e) { throw new RuntimeException(e); } editorPane.revalidate(); editorPane.repaint(); editorPane.setEditable(true); htmlContents = null; } else { editorPane.setEditable(false); htmlContents = editorPane.getText(); } saveUntagged.setEnabled(false); saveTaggedAs.setEnabled(false); }
private void clearDocument() { editorPane.setContentType("text/rtf"); Document doc = new DefaultStyledDocument(); editorPane.setDocument(doc); // defaultAttrSet = ((StyledEditorKit)editorPane.getEditorKit()).getInputAttributes(); // StyleConstants.setFontFamily(defaultAttrSet, "Lucinda Sans Unicode"); log.info("attr: "+defaultAttrSet); try { doc.insertString(0, " ", defaultAttrSet); } catch (Exception ex) { throw new RuntimeException(ex); } editorPane.setEditable(true); editorPane.revalidate(); editorPane.repaint(); saveUntagged.setEnabled(false); saveTaggedAs.setEnabled(false); taggedContents = null; htmlContents = null; loadedFile = null; }
public void clearDocument() { editorPane.setContentType("text/rtf"); Document doc = new DefaultStyledDocument(); editorPane.setDocument(doc); // defaultAttrSet = ((StyledEditorKit)editorPane.getEditorKit()).getInputAttributes(); // StyleConstants.setFontFamily(defaultAttrSet, "Lucinda Sans Unicode"); log.info("attr: "+defaultAttrSet); try { doc.insertString(0, " ", defaultAttrSet); } catch (Exception ex) { throw new RuntimeException(ex); } editorPane.setEditable(true); editorPane.revalidate(); editorPane.repaint(); saveUntagged.setEnabled(false); saveTaggedAs.setEnabled(false); taggedContents = null; untaggedContents = null; htmlContents = null; loadedFile = null; }
private void insertComponent(JComponent comp) { try { tokenPane.getDocument().insertString(tokenPane.getDocument().getLength(), " ", null); } catch (BadLocationException ex1) { // Ignore } try { tokenPane.setCaretPosition(tokenPane.getDocument().getLength() - 1); } catch (Exception ex) { tokenPane.setCaretPosition(0); } tokenPane.insertComponent(comp); }
private void updateMeasures(Component component) { measuresEditor.setText(""); try (CloseableIterator<ScannerReport.Measure> it = reader.readComponentMeasures(component.getRef())) { while (it.hasNext()) { ScannerReport.Measure measure = it.next(); measuresEditor.getDocument().insertString(measuresEditor.getDocument().getEndPosition().getOffset(), measure + "\n", null); } } catch (Exception e) { throw new IllegalStateException("Can't read measures for " + getNodeName(component), e); } }
private void updateSymbols(Component component) { symbolEditor.setText(""); try (CloseableIterator<ScannerReport.Symbol> it = reader.readComponentSymbols(component.getRef())) { while (it.hasNext()) { ScannerReport.Symbol symbol = it.next(); symbolEditor.getDocument().insertString(symbolEditor.getDocument().getEndPosition().getOffset(), symbol + "\n", null); } } catch (Exception e) { throw new IllegalStateException("Can't read symbol references for " + getNodeName(component), e); } }
Document doc = editorPane.getDocument(); try { doc.insertString(0, text, defaultAttrSet); } catch (Exception e) { throw new RuntimeException(e);
private void updateHighlighting(Component component) { highlightingEditor.setText(""); try (CloseableIterator<ScannerReport.SyntaxHighlightingRule> it = reader.readComponentSyntaxHighlighting(component.getRef())) { while (it.hasNext()) { ScannerReport.SyntaxHighlightingRule rule = it.next(); highlightingEditor.getDocument().insertString(highlightingEditor.getDocument().getEndPosition().getOffset(), rule + "\n", null); } } catch (Exception e) { throw new IllegalStateException("Can't read syntax highlighting for " + getNodeName(component), e); } }
private void updateCoverage(Component component) { coverageEditor.setText(""); try (CloseableIterator<ScannerReport.LineCoverage> it = reader.readComponentCoverage(component.getRef())) { while (it.hasNext()) { ScannerReport.LineCoverage coverage = it.next(); coverageEditor.getDocument().insertString(coverageEditor.getDocument().getEndPosition().getOffset(), coverage + "\n", null); } } catch (Exception e) { throw new IllegalStateException("Can't read code coverage for " + getNodeName(component), e); } }
private void updateScm(Component component) { scmEditor.setText(""); Changesets changesets = reader.readChangesets(component.getRef()); if (changesets == null) { return; } List<Integer> changesetIndexByLine = changesets.getChangesetIndexByLineList(); try { int index = 0; for (Changeset changeset : changesets.getChangesetList()) { scmEditor.getDocument().insertString(scmEditor.getDocument().getEndPosition().getOffset(), Integer.toString(index) + "\n", null); scmEditor.getDocument().insertString(scmEditor.getDocument().getEndPosition().getOffset(), changeset + "\n", null); index++; } scmEditor.getDocument().insertString(scmEditor.getDocument().getEndPosition().getOffset(), "\n", null); int line = 1; for (Integer idx : changesetIndexByLine) { scmEditor.getDocument().insertString(scmEditor.getDocument().getEndPosition().getOffset(), Integer.toString(line) + ": " + idx + "\n", null); line++; } } catch (Exception e) { throw new IllegalStateException("Can't read SCM for " + getNodeName(component), e); } }
private void updateIssues(Component component) { issuesEditor.setText(""); try (CloseableIterator<Issue> it = reader.readComponentIssues(component.getRef())) { while (it.hasNext()) { Issue issue = it.next(); int offset = issuesEditor.getDocument().getEndPosition().getOffset(); issuesEditor.getDocument().insertString(offset, issue.toString(), null); } } catch (Exception e) { throw new IllegalStateException("Can't read issues for " + getNodeName(component), e); } }
private void updateExternalIssues(Component component) { externalIssuesEditor.setText(""); try (CloseableIterator<ScannerReport.ExternalIssue> it = reader.readComponentExternalIssues(component.getRef())) { while (it.hasNext()) { ScannerReport.ExternalIssue issue = it.next(); int offset = externalIssuesEditor.getDocument().getEndPosition().getOffset(); externalIssuesEditor.getDocument().insertString(offset, issue.toString(), null); } } catch (Exception e) { throw new IllegalStateException("Can't read external issues for " + getNodeName(component), e); } }
private void updateCpdTextBlocks(Component component) { cpdTextBlocksEditor.setText(""); if (reader.hasCoverage(component.getRef())) { try (CloseableIterator<ScannerReport.CpdTextBlock> it = reader.readCpdTextBlocks(component.getRef())) { while (it.hasNext()) { ScannerReport.CpdTextBlock textBlock = it.next(); cpdTextBlocksEditor.getDocument().insertString(cpdTextBlocksEditor.getDocument().getEndPosition().getOffset(), textBlock + "\n", null); } } catch (Exception e) { throw new IllegalStateException("Can't read CPD text blocks for " + getNodeName(component), e); } } }
private void updateDuplications(Component component) { duplicationEditor.setText(""); if (reader.hasCoverage(component.getRef())) { try (CloseableIterator<ScannerReport.Duplication> it = reader.readComponentDuplications(component.getRef())) { while (it.hasNext()) { ScannerReport.Duplication dup = it.next(); duplicationEditor.getDocument().insertString(duplicationEditor.getDocument().getEndPosition().getOffset(), dup + "\n", null); } } catch (Exception e) { throw new IllegalStateException("Can't read duplications for " + getNodeName(component), e); } } }
private void updateSignificantCode(Component component) { significantCodeEditor.setText(""); if (reader.hasCoverage(component.getRef())) { try (CloseableIterator<ScannerReport.LineSgnificantCode> it = reader.readComponentSignificantCode(component.getRef())) { if (it != null) { while (it.hasNext()) { ScannerReport.LineSgnificantCode textBlock = it.next(); significantCodeEditor.getDocument().insertString(significantCodeEditor.getDocument().getEndPosition().getOffset(), textBlock + "\n", null); } } } catch (Exception e) { throw new IllegalStateException("Can't read significant code for " + getNodeName(component), e); } } }