public void saveUntaggedContents(File file) { try { String contents; if (editorPane.getContentType().equals("text/html")) { contents = editorPane.getText(); } else { Document doc = editorPane.getDocument(); contents = doc.getText(0, doc.getLength()); } saveFile(file, contents); saveUntagged.setEnabled(true); loadedFile = file; } catch (Exception e) { throw new RuntimeException(e); } }
private void saveUntaggedContents(File file) { try { String contents; if (editorPane.getContentType().equals("text/html")) { contents = editorPane.getText(); } else { Document doc = editorPane.getDocument(); contents = doc.getText(0, doc.getLength()); } saveFile(file, contents); saveUntagged.setEnabled(true); loadedFile = file; } catch (Exception e) { throw new RuntimeException(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 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); } }
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); } }
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 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); } }
JEditorPane pane = new JEditorPane(); /* ... Other stuff ... */ public void append(String s) { try { Document doc = pane.getDocument(); doc.insertString(doc.getLength(), s, null); } catch(BadLocationException exc) { exc.printStackTrace(); } }
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); } } }
private void removeTags() { if (editorPane.getContentType().equals("text/html")) { editorPane.setText(htmlContents); editorPane.revalidate(); editorPane.repaint(); } else { DefaultStyledDocument doc = (DefaultStyledDocument)editorPane.getDocument(); SimpleAttributeSet attr = new SimpleAttributeSet(); StyleConstants.setForeground(attr, Color.BLACK); StyleConstants.setBackground(attr, Color.WHITE); doc.setCharacterAttributes(0, doc.getLength(), attr, false); } saveTaggedAs.setEnabled(false); }
private void removeTags() { if (editorPane.getContentType().equals("text/html")) { if (htmlContents != null) { editorPane.setText(htmlContents); } editorPane.revalidate(); editorPane.repaint(); } else { DefaultStyledDocument doc = (DefaultStyledDocument)editorPane.getDocument(); SimpleAttributeSet attr = new SimpleAttributeSet(); StyleConstants.setForeground(attr, Color.BLACK); StyleConstants.setBackground(attr, Color.WHITE); doc.setCharacterAttributes(0, doc.getLength(), attr, false); } saveTaggedAs.setEnabled(false); }
if (!editorPane.getContentType().equals("text/html")) { DefaultStyledDocument doc = (DefaultStyledDocument)editorPane.getDocument(); String text = null; try {
if (!editorPane.getContentType().equals("text/html")) { editorPane.setContentType("text/rtf"); Document doc = editorPane.getDocument(); try { doc.insertString(0, text, defaultAttrSet);
if (!editorPane.getContentType().equals("text/html")) { DefaultStyledDocument doc = (DefaultStyledDocument)editorPane.getDocument(); String text = null; try {
JEditorPane editorPane = new JEditorPane(new HTMLEditorKit().getContentType(),text); editorPane.setText(text); Font font = new Font("Segoe UI", Font.PLAIN, 24)); String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() + "pt; }"; ((HTMLDocument)editorPane.getDocument()).getStyleSheet().addRule(bodyRule);