public void actionPerformed(ActionEvent ae) { JTextComponent tComp = (JTextComponent) ae.getSource(); if (tComp.getDocument() instanceof StyledDocument) { doc = (StyledDocument) tComp.getDocument(); try { doc.getText(0, doc.getLength(), segment); } catch (Exception e) { // should NEVER reach here e.printStackTrace(); } int offset = tComp.getCaretPosition(); int index = findTabLocation(offset); buffer.delete(0, buffer.length()); buffer.append('\n'); if (index > -1) { for (int i = 0; i < index + 4; i++) { buffer.append(' '); } } try { doc.insertString(offset, buffer.toString(), doc.getDefaultRootElement().getAttributes()); } catch (BadLocationException ble) { ble.printStackTrace(); } } }
public int findTabLocation(int offset) { // find first { boolean cont = true; while (offset > -1 && cont) { Element el = doc.getCharacterElement(offset); Object color = el.getAttributes().getAttribute(StyleConstants.Foreground); if (!COMMENT_COLOR.equals(color)) { cont = segment.array[offset] != '{' && segment.array[offset] != '}'; } offset -= cont ? 1 : 0; } if (offset > -1 && segment.array[offset] == '{') { while (offset > -1 && !Character.isWhitespace(segment.array[offset--])) { } } int index = offset < 0 || segment.array[offset] == '}' ? -4 : 0; if (offset > -1) { Element top = doc.getDefaultRootElement(); offset = top.getElement(top.getElementIndex(offset)).getStartOffset(); while (Character.isWhitespace(segment.array[offset++])) { index++; } } return index; } }
public String getText() { int caretPosition = editorPane.getStyledDocument().getLength(); Element root = editorPane.getStyledDocument().getDefaultRootElement(); String text = "1" + System.getProperty("line.separator"); for (int i = 2; i < root.getElementIndex(caretPosition) + 2; i++) { text += i + System.getProperty("line.separator"); } return text; }
public void actionPerformed(ActionEvent ae) { JTextComponent tComp = (JTextComponent)ae.getSource(); if (tComp.getDocument() instanceof StyledDocument) { doc = (StyledDocument)tComp.getDocument(); try { doc.getText(0, doc.getLength(), segment); } catch (Exception e) { // should NEVER reach here e.printStackTrace(); } int offset = tComp.getCaretPosition(); int index = findTabLocation(offset); buffer.delete(0, buffer.length()); buffer.append('\n'); if (index > -1) { for (int i = 0; i < index + 4; i++) { buffer.append(' '); } } try { doc.insertString(offset, buffer.toString(), doc.getDefaultRootElement().getAttributes()); } catch (BadLocationException ble) { ble.printStackTrace(); } } }
public void actionPerformed(ActionEvent ae) { JTextComponent tComp = (JTextComponent) ae.getSource(); if (tComp.getDocument() instanceof StyledDocument) { doc = (StyledDocument) tComp.getDocument(); try { doc.getText(0, doc.getLength(), segment); } catch (Exception e) { // should NEVER reach here e.printStackTrace(); } int offset = tComp.getCaretPosition(); int index = findTabLocation(offset); buffer.delete(0, buffer.length()); buffer.append('\n'); if (index > -1) { for (int i = 0; i < index + 4; i++) { buffer.append(' '); } } try { doc.insertString(offset, buffer.toString(), doc.getDefaultRootElement().getAttributes()); } catch (BadLocationException ble) { ble.printStackTrace(); } } }
public void actionPerformed(ActionEvent ae) { JTextComponent tComp = (JTextComponent) ae.getSource(); if (tComp.getDocument() instanceof StyledDocument) { doc = (StyledDocument) tComp.getDocument(); try { doc.getText(0, doc.getLength(), segment); } catch (Exception e) { // should NEVER reach here e.printStackTrace(); } int offset = tComp.getCaretPosition(); int index = findTabLocation(offset); buffer.delete(0, buffer.length()); buffer.append('\n'); if (index > -1) { for (int i = 0; i < index + 4; i++) { buffer.append(' '); } } try { doc.insertString(offset, buffer.toString(), doc.getDefaultRootElement().getAttributes()); } catch (BadLocationException ble) { ble.printStackTrace(); } } }
public void actionPerformed(ActionEvent ae) { JTextComponent tComp = (JTextComponent)ae.getSource(); if (tComp.getDocument() instanceof StyledDocument) { doc = (StyledDocument)tComp.getDocument(); try { doc.getText(0, doc.getLength(), segment); } catch (Exception e) { // should NEVER reach here e.printStackTrace(); } int offset = tComp.getCaretPosition(); int index = findTabLocation(offset); buffer.delete(0, buffer.length()); buffer.append('\n'); if (index > -1) { for (int i = 0; i < index + 4; i++) { buffer.append(' '); } } try { doc.insertString(offset, buffer.toString(), doc.getDefaultRootElement().getAttributes()); } catch (BadLocationException ble) { ble.printStackTrace(); } } }
public void actionPerformed(ActionEvent ae) { JTextComponent tComp = (JTextComponent)ae.getSource(); if (tComp.getDocument() instanceof StyledDocument) { doc = (StyledDocument)tComp.getDocument(); try { doc.getText(0, doc.getLength(), segment); } catch (Exception e) { // should NEVER reach here e.printStackTrace(); } int offset = tComp.getCaretPosition(); int index = findTabLocation(offset); buffer.delete(0, buffer.length()); buffer.append('\n'); if (index > -1) { for (int i = 0; i < index + 4; i++) { buffer.append(' '); } } try { doc.insertString(offset, buffer.toString(), doc.getDefaultRootElement().getAttributes()); } catch (BadLocationException ble) { ble.printStackTrace(); } } }
/** Find the root element of all lines. * All conforming NetBeans documents * should return a valid element. * * @param doc styled document (expecting NetBeans document) * @return the root element * @exception NullPointerException If the <code>doc</code> parameter * is <code>null</code>. */ public static Element findLineRootElement(StyledDocument doc) { checkDocParameter(doc); Element e = doc.getParagraphElement(0).getParentElement(); if (e == null) { // try default root (should work for text/plain) e = doc.getDefaultRootElement(); } return e; }
/** Find the root element of all lines. * All conforming NetBeans documents * should return a valid element. * * @param doc styled document (expecting NetBeans document) * @return the root element * @exception NullPointerException If the <code>doc</code> parameter * is <code>null</code>. */ public static Element findLineRootElement (StyledDocument doc) { checkDocParameter(doc); Element e = doc.getParagraphElement (0).getParentElement (); if (e == null) { // try default root (should work for text/plain) e = doc.getDefaultRootElement (); } return e; }
/** Find the root element of all lines. * All conforming NetBeans documents * should return a valid element. * * @param doc styled document (expecting NetBeans document) * @return the root element * @exception NullPointerException If the <code>doc</code> parameter * is <code>null</code>. */ public static Element findLineRootElement (StyledDocument doc) { checkDocParameter(doc); Element e = doc.getParagraphElement (0).getParentElement (); if (e == null) { // try default root (should work for text/plain) e = doc.getDefaultRootElement (); } return e; }
public int findTabLocation(int offset) { // find first { boolean cont = true; while (offset > -1 && cont) { Element el = doc.getCharacterElement(offset); Object color = el.getAttributes().getAttribute(StyleConstants.Foreground); if (!COMMENT_COLOR.equals(color)) { cont = segment.array[offset] != '{' && segment.array[offset] != '}'; } offset -= cont ? 1 : 0; } if (offset > -1 && segment.array[offset] == '{') { while (offset > -1 && !Character.isWhitespace(segment.array[offset--])) { } } int index = offset < 0 || segment.array[offset] == '}' ? -4 : 0; if (offset > -1) { Element top = doc.getDefaultRootElement(); offset = top.getElement(top.getElementIndex(offset)).getStartOffset(); while (Character.isWhitespace(segment.array[offset++])) { index++; } } return index; } }
public int findTabLocation(int offset) { // find first { boolean cont = true; while (offset > -1 && cont) { Element el = doc.getCharacterElement(offset); Object color = el.getAttributes().getAttribute(StyleConstants.Foreground); if (!COMMENT_COLOR.equals(color)) { cont = segment.array[offset] != '{' && segment.array[offset] != '}'; } offset -= cont ? 1 : 0; } if (offset > -1 && segment.array[offset] == '{') { while (offset > -1 && !Character.isWhitespace(segment.array[offset--])){ } } int index = offset < 0 || segment.array[offset] == '}' ? -4 : 0; if (offset > -1) { Element top = doc.getDefaultRootElement(); offset = top.getElement(top.getElementIndex(offset)).getStartOffset(); while (Character.isWhitespace(segment.array[offset++])) { index++; } } return index; } }
public int findTabLocation(int offset) { // find first { boolean cont = true; while (offset > -1 && cont) { Element el = doc.getCharacterElement(offset); Object color = el.getAttributes().getAttribute(StyleConstants.Foreground); if (!COMMENT_COLOR.equals(color)) { cont = segment.array[offset] != '{' && segment.array[offset] != '}'; } offset -= cont ? 1 : 0; } if (offset > -1 && segment.array[offset] == '{') { while (offset > -1 && !Character.isWhitespace(segment.array[offset--])){ } } int index = offset < 0 || segment.array[offset] == '}' ? -4 : 0; if (offset > -1) { Element top = doc.getDefaultRootElement(); offset = top.getElement(top.getElementIndex(offset)).getStartOffset(); while (Character.isWhitespace(segment.array[offset++])) { index++; } } return index; } }
public int findTabLocation(int offset) { // find first { boolean cont = true; while (offset > -1 && cont) { Element el = doc.getCharacterElement(offset); Object color = el.getAttributes().getAttribute(StyleConstants.Foreground); if (!COMMENT_COLOR.equals(color)) { cont = segment.array[offset] != '{' && segment.array[offset] != '}'; } offset -= cont ? 1 : 0; } if (offset > -1 && segment.array[offset] == '{') { while (offset > -1 && !Character.isWhitespace(segment.array[offset--])) { } } int index = offset < 0 || segment.array[offset] == '}' ? -4 : 0; if (offset > -1) { Element top = doc.getDefaultRootElement(); offset = top.getElement(top.getElementIndex(offset)).getStartOffset(); while (Character.isWhitespace(segment.array[offset++])) { index++; } } return index; } }
public int findTabLocation(int offset) { // find first { boolean cont = true; while (offset > -1 && cont) { Element el = doc.getCharacterElement(offset); Object color = el.getAttributes().getAttribute(StyleConstants.Foreground); if (!COMMENT_COLOR.equals(color)) { cont = segment.array[offset] != '{' && segment.array[offset] != '}'; } offset -= cont ? 1 : 0; } if (offset > -1 && segment.array[offset] == '{') { while (offset > -1 && !Character.isWhitespace(segment.array[offset--])){ } } int index = offset < 0 || segment.array[offset] == '}' ? -4 : 0; if (offset > -1) { Element top = doc.getDefaultRootElement(); offset = top.getElement(top.getElementIndex(offset)).getStartOffset(); while (Character.isWhitespace(segment.array[offset++])) { index++; } } return index; } }
Element root=_doc.getDefaultRootElement(); int nbl =root.getElementCount();