@Test public void testAddTab() throws BadLocationException { System.out.println("AddTab"); String insert = ""; ins.insertTabAtPos(0); String code = pane.getText(); String after = " "; assertEquals(after, code); pane = new JTextPane(); ins = new TabInserter(pane); insert = "0123"; pane.getStyledDocument().insertString(0, insert, null); ins.insertTabAtPos(2); String comp = "01234567|"; after = "01 23"; code = pane.getText(); assertEquals(after, code); }
public void insertTabAtPos(int pos) throws BadLocationException { int distToLineBeginning = JTextPaneToolbox.getDistanceToClosestLineBeginning(pane, pos); int nextTabPos = 0; while(nextTabPos <= distToLineBeginning) { nextTabPos += spacesPerTab; } int distToNextTabPos = nextTabPos - distToLineBeginning; String spacesToInsert = ""; for(int i = 0; i < distToNextTabPos; ++i) spacesToInsert += " "; pane.getStyledDocument().insertString(pos, spacesToInsert, null); tabPositions.add(pos); }
TabInserter { public void insertTabAtPos(int pos) throws BadLocationException { int distToLineBeginning = JTextPaneToolbox.getDistanceToClosestLineBeginning(pane, pos); int nextTabPos = 0; while(nextTabPos <= distToLineBeginning) { nextTabPos += spacesPerTab; } int distToNextTabPos = nextTabPos - distToLineBeginning; String spacesToInsert = ""; for(int i = 0; i < distToNextTabPos; ++i) spacesToInsert += " "; pane.getStyledDocument().insertString(pos, spacesToInsert, null); tabPositions.add(pos); } }
TabInserter { public void insertTabAtPos(int pos) throws BadLocationException { int distToLineBeginning = JTextPaneToolbox.getDistanceToClosestLineBeginning(pane, pos); int nextTabPos = 0; while(nextTabPos <= distToLineBeginning) { nextTabPos += spacesPerTab; } int distToNextTabPos = nextTabPos - distToLineBeginning; String spacesToInsert = ""; for(int i = 0; i < distToNextTabPos; ++i) spacesToInsert += " "; pane.getStyledDocument().insertString(pos, spacesToInsert, null); tabPositions.add(pos); } TabInserter(JTextPane pane); }
TabInserter { public void insertTabAtPos(int pos) throws BadLocationException { int distToLineBeginning = JTextPaneToolbox.getDistanceToClosestLineBeginning(pane, pos); int nextTabPos = 0; while(nextTabPos <= distToLineBeginning) { nextTabPos += spacesPerTab; } int distToNextTabPos = nextTabPos - distToLineBeginning; String spacesToInsert = ""; for(int i = 0; i < distToNextTabPos; ++i) spacesToInsert += " "; pane.getStyledDocument().insertString(pos, spacesToInsert, null); tabPositions.add(pos); } TabInserter(JTextPane pane); void insertTabAtPos(int pos); void removeTabAtPos(int pos); int getSpacesPerTab(); void setAmountSpacesPerTab(int numberTabs); }
TabInserter { public void insertTabAtPos(int pos) throws BadLocationException { int distToLineBeginning = JTextPaneToolbox.getDistanceToClosestLineBeginning(pane, pos); int nextTabPos = 0; while(nextTabPos <= distToLineBeginning) { nextTabPos += spacesPerTab; } int distToNextTabPos = nextTabPos - distToLineBeginning; String spacesToInsert = ""; for(int i = 0; i < distToNextTabPos; ++i) spacesToInsert += " "; pane.getStyledDocument().insertString(pos, spacesToInsert, null); tabPositions.add(pos); } TabInserter(JTextPane pane); void insertTabAtPos(int pos); void removeTabAtPos(int pos); int getSpacesPerTab(); void setAmountSpacesPerTab(int numberTabs);  }