Java Code Examples for javax.swing.text.StyleConstants#ResolveAttribute
The following examples show how to use
javax.swing.text.StyleConstants#ResolveAttribute .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ElementTreePanel.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("LeakingThisInConstructor") public ElementTreePanel(JTextComponent editor) { this.editor = editor; Document document = editor.getDocument(); // Create the tree. treeModel = new ElementTreeModel(document); tree = new JTree(treeModel) { @Override public String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { // Should only happen for the root if (!(value instanceof Element)) { return value.toString(); } Element e = (Element) value; AttributeSet as = e.getAttributes().copyAttributes(); String asString; if (as != null) { StringBuilder retBuffer = new StringBuilder("["); Enumeration names = as.getAttributeNames(); while (names.hasMoreElements()) { Object nextName = names.nextElement(); if (nextName != StyleConstants.ResolveAttribute) { retBuffer.append(" "); retBuffer.append(nextName); retBuffer.append("="); retBuffer.append(as.getAttribute(nextName)); } } retBuffer.append(" ]"); asString = retBuffer.toString(); } else { asString = "[ ]"; } if (e.isLeaf()) { return e.getName() + " [" + e.getStartOffset() + ", " + e. getEndOffset() + "] Attributes: " + asString; } return e.getName() + " [" + e.getStartOffset() + ", " + e. getEndOffset() + "] Attributes: " + asString; } }; tree.addTreeSelectionListener(this); tree.setDragEnabled(true); // Don't show the root, it is fake. tree.setRootVisible(false); // Since the display value of every node after the insertion point // changes every time the text changes and we don't generate a change // event for all those nodes the display value can become off. // This can be seen as '...' instead of the complete string value. // This is a temporary workaround, increase the needed size by 15, // hoping that will be enough. tree.setCellRenderer(new DefaultTreeCellRenderer() { @Override public Dimension getPreferredSize() { Dimension retValue = super.getPreferredSize(); if (retValue != null) { retValue.width += 15; } return retValue; } }); // become a listener on the document to update the tree. document.addDocumentListener(this); // become a PropertyChangeListener to know when the Document has // changed. editor.addPropertyChangeListener(this); // Become a CaretListener editor.addCaretListener(this); // configure the panel and frame containing it. setLayout(new BorderLayout()); add(new JScrollPane(tree), BorderLayout.CENTER); // Add a label above tree to describe what is being shown JLabel label = new JLabel("Elements that make up the current document", SwingConstants.CENTER); label.setFont(new Font("Dialog", Font.BOLD, 14)); add(label, BorderLayout.NORTH); setPreferredSize(new Dimension(400, 400)); }
Example 2
Source File: ElementTreePanel.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("LeakingThisInConstructor") public ElementTreePanel(JTextComponent editor) { this.editor = editor; Document document = editor.getDocument(); // Create the tree. treeModel = new ElementTreeModel(document); tree = new JTree(treeModel) { @Override public String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { // Should only happen for the root if (!(value instanceof Element)) { return value.toString(); } Element e = (Element) value; AttributeSet as = e.getAttributes().copyAttributes(); String asString; if (as != null) { StringBuilder retBuffer = new StringBuilder("["); Enumeration names = as.getAttributeNames(); while (names.hasMoreElements()) { Object nextName = names.nextElement(); if (nextName != StyleConstants.ResolveAttribute) { retBuffer.append(" "); retBuffer.append(nextName); retBuffer.append("="); retBuffer.append(as.getAttribute(nextName)); } } retBuffer.append(" ]"); asString = retBuffer.toString(); } else { asString = "[ ]"; } if (e.isLeaf()) { return e.getName() + " [" + e.getStartOffset() + ", " + e. getEndOffset() + "] Attributes: " + asString; } return e.getName() + " [" + e.getStartOffset() + ", " + e. getEndOffset() + "] Attributes: " + asString; } }; tree.addTreeSelectionListener(this); tree.setDragEnabled(true); // Don't show the root, it is fake. tree.setRootVisible(false); // Since the display value of every node after the insertion point // changes every time the text changes and we don't generate a change // event for all those nodes the display value can become off. // This can be seen as '...' instead of the complete string value. // This is a temporary workaround, increase the needed size by 15, // hoping that will be enough. tree.setCellRenderer(new DefaultTreeCellRenderer() { @Override public Dimension getPreferredSize() { Dimension retValue = super.getPreferredSize(); if (retValue != null) { retValue.width += 15; } return retValue; } }); // become a listener on the document to update the tree. document.addDocumentListener(this); // become a PropertyChangeListener to know when the Document has // changed. editor.addPropertyChangeListener(this); // Become a CaretListener editor.addCaretListener(this); // configure the panel and frame containing it. setLayout(new BorderLayout()); add(new JScrollPane(tree), BorderLayout.CENTER); // Add a label above tree to describe what is being shown JLabel label = new JLabel("Elements that make up the current document", SwingConstants.CENTER); label.setFont(new Font("Dialog", Font.BOLD, 14)); add(label, BorderLayout.NORTH); setPreferredSize(new Dimension(400, 400)); }
Example 3
Source File: ElementTreePanel.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("LeakingThisInConstructor") public ElementTreePanel(JTextComponent editor) { this.editor = editor; Document document = editor.getDocument(); // Create the tree. treeModel = new ElementTreeModel(document); tree = new JTree(treeModel) { @Override public String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { // Should only happen for the root if (!(value instanceof Element)) { return value.toString(); } Element e = (Element) value; AttributeSet as = e.getAttributes().copyAttributes(); String asString; if (as != null) { StringBuilder retBuffer = new StringBuilder("["); Enumeration names = as.getAttributeNames(); while (names.hasMoreElements()) { Object nextName = names.nextElement(); if (nextName != StyleConstants.ResolveAttribute) { retBuffer.append(" "); retBuffer.append(nextName); retBuffer.append("="); retBuffer.append(as.getAttribute(nextName)); } } retBuffer.append(" ]"); asString = retBuffer.toString(); } else { asString = "[ ]"; } if (e.isLeaf()) { return e.getName() + " [" + e.getStartOffset() + ", " + e. getEndOffset() + "] Attributes: " + asString; } return e.getName() + " [" + e.getStartOffset() + ", " + e. getEndOffset() + "] Attributes: " + asString; } }; tree.addTreeSelectionListener(this); tree.setDragEnabled(true); // Don't show the root, it is fake. tree.setRootVisible(false); // Since the display value of every node after the insertion point // changes every time the text changes and we don't generate a change // event for all those nodes the display value can become off. // This can be seen as '...' instead of the complete string value. // This is a temporary workaround, increase the needed size by 15, // hoping that will be enough. tree.setCellRenderer(new DefaultTreeCellRenderer() { @Override public Dimension getPreferredSize() { Dimension retValue = super.getPreferredSize(); if (retValue != null) { retValue.width += 15; } return retValue; } }); // become a listener on the document to update the tree. document.addDocumentListener(this); // become a PropertyChangeListener to know when the Document has // changed. editor.addPropertyChangeListener(this); // Become a CaretListener editor.addCaretListener(this); // configure the panel and frame containing it. setLayout(new BorderLayout()); add(new JScrollPane(tree), BorderLayout.CENTER); // Add a label above tree to describe what is being shown JLabel label = new JLabel("Elements that make up the current document", SwingConstants.CENTER); label.setFont(new Font("Dialog", Font.BOLD, 14)); add(label, BorderLayout.NORTH); setPreferredSize(new Dimension(400, 400)); }
Example 4
Source File: ElementTreePanel.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("LeakingThisInConstructor") public ElementTreePanel(JTextComponent editor) { this.editor = editor; Document document = editor.getDocument(); // Create the tree. treeModel = new ElementTreeModel(document); tree = new JTree(treeModel) { @Override public String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { // Should only happen for the root if (!(value instanceof Element)) { return value.toString(); } Element e = (Element) value; AttributeSet as = e.getAttributes().copyAttributes(); String asString; if (as != null) { StringBuilder retBuffer = new StringBuilder("["); Enumeration names = as.getAttributeNames(); while (names.hasMoreElements()) { Object nextName = names.nextElement(); if (nextName != StyleConstants.ResolveAttribute) { retBuffer.append(" "); retBuffer.append(nextName); retBuffer.append("="); retBuffer.append(as.getAttribute(nextName)); } } retBuffer.append(" ]"); asString = retBuffer.toString(); } else { asString = "[ ]"; } if (e.isLeaf()) { return e.getName() + " [" + e.getStartOffset() + ", " + e. getEndOffset() + "] Attributes: " + asString; } return e.getName() + " [" + e.getStartOffset() + ", " + e. getEndOffset() + "] Attributes: " + asString; } }; tree.addTreeSelectionListener(this); tree.setDragEnabled(true); // Don't show the root, it is fake. tree.setRootVisible(false); // Since the display value of every node after the insertion point // changes every time the text changes and we don't generate a change // event for all those nodes the display value can become off. // This can be seen as '...' instead of the complete string value. // This is a temporary workaround, increase the needed size by 15, // hoping that will be enough. tree.setCellRenderer(new DefaultTreeCellRenderer() { @Override public Dimension getPreferredSize() { Dimension retValue = super.getPreferredSize(); if (retValue != null) { retValue.width += 15; } return retValue; } }); // become a listener on the document to update the tree. document.addDocumentListener(this); // become a PropertyChangeListener to know when the Document has // changed. editor.addPropertyChangeListener(this); // Become a CaretListener editor.addCaretListener(this); // configure the panel and frame containing it. setLayout(new BorderLayout()); add(new JScrollPane(tree), BorderLayout.CENTER); // Add a label above tree to describe what is being shown JLabel label = new JLabel("Elements that make up the current document", SwingConstants.CENTER); label.setFont(new Font("Dialog", Font.BOLD, 14)); add(label, BorderLayout.NORTH); setPreferredSize(new Dimension(400, 400)); }
Example 5
Source File: ElementTreePanel.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("LeakingThisInConstructor") public ElementTreePanel(JTextComponent editor) { this.editor = editor; Document document = editor.getDocument(); // Create the tree. treeModel = new ElementTreeModel(document); tree = new JTree(treeModel) { @Override public String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { // Should only happen for the root if (!(value instanceof Element)) { return value.toString(); } Element e = (Element) value; AttributeSet as = e.getAttributes().copyAttributes(); String asString; if (as != null) { StringBuilder retBuffer = new StringBuilder("["); Enumeration names = as.getAttributeNames(); while (names.hasMoreElements()) { Object nextName = names.nextElement(); if (nextName != StyleConstants.ResolveAttribute) { retBuffer.append(" "); retBuffer.append(nextName); retBuffer.append("="); retBuffer.append(as.getAttribute(nextName)); } } retBuffer.append(" ]"); asString = retBuffer.toString(); } else { asString = "[ ]"; } if (e.isLeaf()) { return e.getName() + " [" + e.getStartOffset() + ", " + e. getEndOffset() + "] Attributes: " + asString; } return e.getName() + " [" + e.getStartOffset() + ", " + e. getEndOffset() + "] Attributes: " + asString; } }; tree.addTreeSelectionListener(this); tree.setDragEnabled(true); // Don't show the root, it is fake. tree.setRootVisible(false); // Since the display value of every node after the insertion point // changes every time the text changes and we don't generate a change // event for all those nodes the display value can become off. // This can be seen as '...' instead of the complete string value. // This is a temporary workaround, increase the needed size by 15, // hoping that will be enough. tree.setCellRenderer(new DefaultTreeCellRenderer() { @Override public Dimension getPreferredSize() { Dimension retValue = super.getPreferredSize(); if (retValue != null) { retValue.width += 15; } return retValue; } }); // become a listener on the document to update the tree. document.addDocumentListener(this); // become a PropertyChangeListener to know when the Document has // changed. editor.addPropertyChangeListener(this); // Become a CaretListener editor.addCaretListener(this); // configure the panel and frame containing it. setLayout(new BorderLayout()); add(new JScrollPane(tree), BorderLayout.CENTER); // Add a label above tree to describe what is being shown JLabel label = new JLabel("Elements that make up the current document", SwingConstants.CENTER); label.setFont(new Font("Dialog", Font.BOLD, 14)); add(label, BorderLayout.NORTH); setPreferredSize(new Dimension(400, 400)); }
Example 6
Source File: ElementTreePanel.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("LeakingThisInConstructor") public ElementTreePanel(JTextComponent editor) { this.editor = editor; Document document = editor.getDocument(); // Create the tree. treeModel = new ElementTreeModel(document); tree = new JTree(treeModel) { @Override public String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { // Should only happen for the root if (!(value instanceof Element)) { return value.toString(); } Element e = (Element) value; AttributeSet as = e.getAttributes().copyAttributes(); String asString; if (as != null) { StringBuilder retBuffer = new StringBuilder("["); Enumeration names = as.getAttributeNames(); while (names.hasMoreElements()) { Object nextName = names.nextElement(); if (nextName != StyleConstants.ResolveAttribute) { retBuffer.append(" "); retBuffer.append(nextName); retBuffer.append("="); retBuffer.append(as.getAttribute(nextName)); } } retBuffer.append(" ]"); asString = retBuffer.toString(); } else { asString = "[ ]"; } if (e.isLeaf()) { return e.getName() + " [" + e.getStartOffset() + ", " + e. getEndOffset() + "] Attributes: " + asString; } return e.getName() + " [" + e.getStartOffset() + ", " + e. getEndOffset() + "] Attributes: " + asString; } }; tree.addTreeSelectionListener(this); tree.setDragEnabled(true); // Don't show the root, it is fake. tree.setRootVisible(false); // Since the display value of every node after the insertion point // changes every time the text changes and we don't generate a change // event for all those nodes the display value can become off. // This can be seen as '...' instead of the complete string value. // This is a temporary workaround, increase the needed size by 15, // hoping that will be enough. tree.setCellRenderer(new DefaultTreeCellRenderer() { @Override public Dimension getPreferredSize() { Dimension retValue = super.getPreferredSize(); if (retValue != null) { retValue.width += 15; } return retValue; } }); // become a listener on the document to update the tree. document.addDocumentListener(this); // become a PropertyChangeListener to know when the Document has // changed. editor.addPropertyChangeListener(this); // Become a CaretListener editor.addCaretListener(this); // configure the panel and frame containing it. setLayout(new BorderLayout()); add(new JScrollPane(tree), BorderLayout.CENTER); // Add a label above tree to describe what is being shown JLabel label = new JLabel("Elements that make up the current document", SwingConstants.CENTER); label.setFont(new Font("Dialog", Font.BOLD, 14)); add(label, BorderLayout.NORTH); setPreferredSize(new Dimension(400, 400)); }
Example 7
Source File: ElementTreePanel.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("LeakingThisInConstructor") public ElementTreePanel(JTextComponent editor) { this.editor = editor; Document document = editor.getDocument(); // Create the tree. treeModel = new ElementTreeModel(document); tree = new JTree(treeModel) { @Override public String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { // Should only happen for the root if (!(value instanceof Element)) { return value.toString(); } Element e = (Element) value; AttributeSet as = e.getAttributes().copyAttributes(); String asString; if (as != null) { StringBuilder retBuffer = new StringBuilder("["); Enumeration names = as.getAttributeNames(); while (names.hasMoreElements()) { Object nextName = names.nextElement(); if (nextName != StyleConstants.ResolveAttribute) { retBuffer.append(" "); retBuffer.append(nextName); retBuffer.append("="); retBuffer.append(as.getAttribute(nextName)); } } retBuffer.append(" ]"); asString = retBuffer.toString(); } else { asString = "[ ]"; } if (e.isLeaf()) { return e.getName() + " [" + e.getStartOffset() + ", " + e. getEndOffset() + "] Attributes: " + asString; } return e.getName() + " [" + e.getStartOffset() + ", " + e. getEndOffset() + "] Attributes: " + asString; } }; tree.addTreeSelectionListener(this); tree.setDragEnabled(true); // Don't show the root, it is fake. tree.setRootVisible(false); // Since the display value of every node after the insertion point // changes every time the text changes and we don't generate a change // event for all those nodes the display value can become off. // This can be seen as '...' instead of the complete string value. // This is a temporary workaround, increase the needed size by 15, // hoping that will be enough. tree.setCellRenderer(new DefaultTreeCellRenderer() { @Override public Dimension getPreferredSize() { Dimension retValue = super.getPreferredSize(); if (retValue != null) { retValue.width += 15; } return retValue; } }); // become a listener on the document to update the tree. document.addDocumentListener(this); // become a PropertyChangeListener to know when the Document has // changed. editor.addPropertyChangeListener(this); // Become a CaretListener editor.addCaretListener(this); // configure the panel and frame containing it. setLayout(new BorderLayout()); add(new JScrollPane(tree), BorderLayout.CENTER); // Add a label above tree to describe what is being shown JLabel label = new JLabel("Elements that make up the current document", SwingConstants.CENTER); label.setFont(new Font("Dialog", Font.BOLD, 14)); add(label, BorderLayout.NORTH); setPreferredSize(new Dimension(400, 400)); }
Example 8
Source File: ElementTreePanel.java From hottub with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("LeakingThisInConstructor") public ElementTreePanel(JTextComponent editor) { this.editor = editor; Document document = editor.getDocument(); // Create the tree. treeModel = new ElementTreeModel(document); tree = new JTree(treeModel) { @Override public String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { // Should only happen for the root if (!(value instanceof Element)) { return value.toString(); } Element e = (Element) value; AttributeSet as = e.getAttributes().copyAttributes(); String asString; if (as != null) { StringBuilder retBuffer = new StringBuilder("["); Enumeration names = as.getAttributeNames(); while (names.hasMoreElements()) { Object nextName = names.nextElement(); if (nextName != StyleConstants.ResolveAttribute) { retBuffer.append(" "); retBuffer.append(nextName); retBuffer.append("="); retBuffer.append(as.getAttribute(nextName)); } } retBuffer.append(" ]"); asString = retBuffer.toString(); } else { asString = "[ ]"; } if (e.isLeaf()) { return e.getName() + " [" + e.getStartOffset() + ", " + e. getEndOffset() + "] Attributes: " + asString; } return e.getName() + " [" + e.getStartOffset() + ", " + e. getEndOffset() + "] Attributes: " + asString; } }; tree.addTreeSelectionListener(this); tree.setDragEnabled(true); // Don't show the root, it is fake. tree.setRootVisible(false); // Since the display value of every node after the insertion point // changes every time the text changes and we don't generate a change // event for all those nodes the display value can become off. // This can be seen as '...' instead of the complete string value. // This is a temporary workaround, increase the needed size by 15, // hoping that will be enough. tree.setCellRenderer(new DefaultTreeCellRenderer() { @Override public Dimension getPreferredSize() { Dimension retValue = super.getPreferredSize(); if (retValue != null) { retValue.width += 15; } return retValue; } }); // become a listener on the document to update the tree. document.addDocumentListener(this); // become a PropertyChangeListener to know when the Document has // changed. editor.addPropertyChangeListener(this); // Become a CaretListener editor.addCaretListener(this); // configure the panel and frame containing it. setLayout(new BorderLayout()); add(new JScrollPane(tree), BorderLayout.CENTER); // Add a label above tree to describe what is being shown JLabel label = new JLabel("Elements that make up the current document", SwingConstants.CENTER); label.setFont(new Font("Dialog", Font.BOLD, 14)); add(label, BorderLayout.NORTH); setPreferredSize(new Dimension(400, 400)); }
Example 9
Source File: ElementTreePanel.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("LeakingThisInConstructor") public ElementTreePanel(JTextComponent editor) { this.editor = editor; Document document = editor.getDocument(); // Create the tree. treeModel = new ElementTreeModel(document); tree = new JTree(treeModel) { @Override public String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { // Should only happen for the root if (!(value instanceof Element)) { return value.toString(); } Element e = (Element) value; AttributeSet as = e.getAttributes().copyAttributes(); String asString; if (as != null) { StringBuilder retBuffer = new StringBuilder("["); Enumeration names = as.getAttributeNames(); while (names.hasMoreElements()) { Object nextName = names.nextElement(); if (nextName != StyleConstants.ResolveAttribute) { retBuffer.append(" "); retBuffer.append(nextName); retBuffer.append("="); retBuffer.append(as.getAttribute(nextName)); } } retBuffer.append(" ]"); asString = retBuffer.toString(); } else { asString = "[ ]"; } if (e.isLeaf()) { return e.getName() + " [" + e.getStartOffset() + ", " + e. getEndOffset() + "] Attributes: " + asString; } return e.getName() + " [" + e.getStartOffset() + ", " + e. getEndOffset() + "] Attributes: " + asString; } }; tree.addTreeSelectionListener(this); tree.setDragEnabled(true); // Don't show the root, it is fake. tree.setRootVisible(false); // Since the display value of every node after the insertion point // changes every time the text changes and we don't generate a change // event for all those nodes the display value can become off. // This can be seen as '...' instead of the complete string value. // This is a temporary workaround, increase the needed size by 15, // hoping that will be enough. tree.setCellRenderer(new DefaultTreeCellRenderer() { @Override public Dimension getPreferredSize() { Dimension retValue = super.getPreferredSize(); if (retValue != null) { retValue.width += 15; } return retValue; } }); // become a listener on the document to update the tree. document.addDocumentListener(this); // become a PropertyChangeListener to know when the Document has // changed. editor.addPropertyChangeListener(this); // Become a CaretListener editor.addCaretListener(this); // configure the panel and frame containing it. setLayout(new BorderLayout()); add(new JScrollPane(tree), BorderLayout.CENTER); // Add a label above tree to describe what is being shown JLabel label = new JLabel("Elements that make up the current document", SwingConstants.CENTER); label.setFont(new Font("Dialog", Font.BOLD, 14)); add(label, BorderLayout.NORTH); setPreferredSize(new Dimension(400, 400)); }
Example 10
Source File: ElementTreePanel.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("LeakingThisInConstructor") public ElementTreePanel(JTextComponent editor) { this.editor = editor; Document document = editor.getDocument(); // Create the tree. treeModel = new ElementTreeModel(document); tree = new JTree(treeModel) { @Override public String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { // Should only happen for the root if (!(value instanceof Element)) { return value.toString(); } Element e = (Element) value; AttributeSet as = e.getAttributes().copyAttributes(); String asString; if (as != null) { StringBuilder retBuffer = new StringBuilder("["); Enumeration names = as.getAttributeNames(); while (names.hasMoreElements()) { Object nextName = names.nextElement(); if (nextName != StyleConstants.ResolveAttribute) { retBuffer.append(" "); retBuffer.append(nextName); retBuffer.append("="); retBuffer.append(as.getAttribute(nextName)); } } retBuffer.append(" ]"); asString = retBuffer.toString(); } else { asString = "[ ]"; } if (e.isLeaf()) { return e.getName() + " [" + e.getStartOffset() + ", " + e. getEndOffset() + "] Attributes: " + asString; } return e.getName() + " [" + e.getStartOffset() + ", " + e. getEndOffset() + "] Attributes: " + asString; } }; tree.addTreeSelectionListener(this); tree.setDragEnabled(true); // Don't show the root, it is fake. tree.setRootVisible(false); // Since the display value of every node after the insertion point // changes every time the text changes and we don't generate a change // event for all those nodes the display value can become off. // This can be seen as '...' instead of the complete string value. // This is a temporary workaround, increase the needed size by 15, // hoping that will be enough. tree.setCellRenderer(new DefaultTreeCellRenderer() { @Override public Dimension getPreferredSize() { Dimension retValue = super.getPreferredSize(); if (retValue != null) { retValue.width += 15; } return retValue; } }); // become a listener on the document to update the tree. document.addDocumentListener(this); // become a PropertyChangeListener to know when the Document has // changed. editor.addPropertyChangeListener(this); // Become a CaretListener editor.addCaretListener(this); // configure the panel and frame containing it. setLayout(new BorderLayout()); add(new JScrollPane(tree), BorderLayout.CENTER); // Add a label above tree to describe what is being shown JLabel label = new JLabel("Elements that make up the current document", SwingConstants.CENTER); label.setFont(new Font("Dialog", Font.BOLD, 14)); add(label, BorderLayout.NORTH); setPreferredSize(new Dimension(400, 400)); }
Example 11
Source File: ElementTreePanel.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("LeakingThisInConstructor") public ElementTreePanel(JTextComponent editor) { this.editor = editor; Document document = editor.getDocument(); // Create the tree. treeModel = new ElementTreeModel(document); tree = new JTree(treeModel) { @Override public String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { // Should only happen for the root if (!(value instanceof Element)) { return value.toString(); } Element e = (Element) value; AttributeSet as = e.getAttributes().copyAttributes(); String asString; if (as != null) { StringBuilder retBuffer = new StringBuilder("["); Enumeration names = as.getAttributeNames(); while (names.hasMoreElements()) { Object nextName = names.nextElement(); if (nextName != StyleConstants.ResolveAttribute) { retBuffer.append(" "); retBuffer.append(nextName); retBuffer.append("="); retBuffer.append(as.getAttribute(nextName)); } } retBuffer.append(" ]"); asString = retBuffer.toString(); } else { asString = "[ ]"; } if (e.isLeaf()) { return e.getName() + " [" + e.getStartOffset() + ", " + e. getEndOffset() + "] Attributes: " + asString; } return e.getName() + " [" + e.getStartOffset() + ", " + e. getEndOffset() + "] Attributes: " + asString; } }; tree.addTreeSelectionListener(this); tree.setDragEnabled(true); // Don't show the root, it is fake. tree.setRootVisible(false); // Since the display value of every node after the insertion point // changes every time the text changes and we don't generate a change // event for all those nodes the display value can become off. // This can be seen as '...' instead of the complete string value. // This is a temporary workaround, increase the needed size by 15, // hoping that will be enough. tree.setCellRenderer(new DefaultTreeCellRenderer() { @Override public Dimension getPreferredSize() { Dimension retValue = super.getPreferredSize(); if (retValue != null) { retValue.width += 15; } return retValue; } }); // become a listener on the document to update the tree. document.addDocumentListener(this); // become a PropertyChangeListener to know when the Document has // changed. editor.addPropertyChangeListener(this); // Become a CaretListener editor.addCaretListener(this); // configure the panel and frame containing it. setLayout(new BorderLayout()); add(new JScrollPane(tree), BorderLayout.CENTER); // Add a label above tree to describe what is being shown JLabel label = new JLabel("Elements that make up the current document", SwingConstants.CENTER); label.setFont(new Font("Dialog", Font.BOLD, 14)); add(label, BorderLayout.NORTH); setPreferredSize(new Dimension(400, 400)); }
Example 12
Source File: ElementTreePanel.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("LeakingThisInConstructor") public ElementTreePanel(JTextComponent editor) { this.editor = editor; Document document = editor.getDocument(); // Create the tree. treeModel = new ElementTreeModel(document); tree = new JTree(treeModel) { @Override public String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { // Should only happen for the root if (!(value instanceof Element)) { return value.toString(); } Element e = (Element) value; AttributeSet as = e.getAttributes().copyAttributes(); String asString; if (as != null) { StringBuilder retBuffer = new StringBuilder("["); Enumeration names = as.getAttributeNames(); while (names.hasMoreElements()) { Object nextName = names.nextElement(); if (nextName != StyleConstants.ResolveAttribute) { retBuffer.append(" "); retBuffer.append(nextName); retBuffer.append("="); retBuffer.append(as.getAttribute(nextName)); } } retBuffer.append(" ]"); asString = retBuffer.toString(); } else { asString = "[ ]"; } if (e.isLeaf()) { return e.getName() + " [" + e.getStartOffset() + ", " + e. getEndOffset() + "] Attributes: " + asString; } return e.getName() + " [" + e.getStartOffset() + ", " + e. getEndOffset() + "] Attributes: " + asString; } }; tree.addTreeSelectionListener(this); tree.setDragEnabled(true); // Don't show the root, it is fake. tree.setRootVisible(false); // Since the display value of every node after the insertion point // changes every time the text changes and we don't generate a change // event for all those nodes the display value can become off. // This can be seen as '...' instead of the complete string value. // This is a temporary workaround, increase the needed size by 15, // hoping that will be enough. tree.setCellRenderer(new DefaultTreeCellRenderer() { @Override public Dimension getPreferredSize() { Dimension retValue = super.getPreferredSize(); if (retValue != null) { retValue.width += 15; } return retValue; } }); // become a listener on the document to update the tree. document.addDocumentListener(this); // become a PropertyChangeListener to know when the Document has // changed. editor.addPropertyChangeListener(this); // Become a CaretListener editor.addCaretListener(this); // configure the panel and frame containing it. setLayout(new BorderLayout()); add(new JScrollPane(tree), BorderLayout.CENTER); // Add a label above tree to describe what is being shown JLabel label = new JLabel("Elements that make up the current document", SwingConstants.CENTER); label.setFont(new Font("Dialog", Font.BOLD, 14)); add(label, BorderLayout.NORTH); setPreferredSize(new Dimension(400, 400)); }
Example 13
Source File: ElementTreePanel.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("LeakingThisInConstructor") public ElementTreePanel(JTextComponent editor) { this.editor = editor; Document document = editor.getDocument(); // Create the tree. treeModel = new ElementTreeModel(document); tree = new JTree(treeModel) { @Override public String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { // Should only happen for the root if (!(value instanceof Element)) { return value.toString(); } Element e = (Element) value; AttributeSet as = e.getAttributes().copyAttributes(); String asString; if (as != null) { StringBuilder retBuffer = new StringBuilder("["); Enumeration names = as.getAttributeNames(); while (names.hasMoreElements()) { Object nextName = names.nextElement(); if (nextName != StyleConstants.ResolveAttribute) { retBuffer.append(" "); retBuffer.append(nextName); retBuffer.append("="); retBuffer.append(as.getAttribute(nextName)); } } retBuffer.append(" ]"); asString = retBuffer.toString(); } else { asString = "[ ]"; } if (e.isLeaf()) { return e.getName() + " [" + e.getStartOffset() + ", " + e. getEndOffset() + "] Attributes: " + asString; } return e.getName() + " [" + e.getStartOffset() + ", " + e. getEndOffset() + "] Attributes: " + asString; } }; tree.addTreeSelectionListener(this); tree.setDragEnabled(true); // Don't show the root, it is fake. tree.setRootVisible(false); // Since the display value of every node after the insertion point // changes every time the text changes and we don't generate a change // event for all those nodes the display value can become off. // This can be seen as '...' instead of the complete string value. // This is a temporary workaround, increase the needed size by 15, // hoping that will be enough. tree.setCellRenderer(new DefaultTreeCellRenderer() { @Override public Dimension getPreferredSize() { Dimension retValue = super.getPreferredSize(); if (retValue != null) { retValue.width += 15; } return retValue; } }); // become a listener on the document to update the tree. document.addDocumentListener(this); // become a PropertyChangeListener to know when the Document has // changed. editor.addPropertyChangeListener(this); // Become a CaretListener editor.addCaretListener(this); // configure the panel and frame containing it. setLayout(new BorderLayout()); add(new JScrollPane(tree), BorderLayout.CENTER); // Add a label above tree to describe what is being shown JLabel label = new JLabel("Elements that make up the current document", SwingConstants.CENTER); label.setFont(new Font("Dialog", Font.BOLD, 14)); add(label, BorderLayout.NORTH); setPreferredSize(new Dimension(400, 400)); }