Changeset 1139


Ignore:
Timestamp:
Jul 2, 2011, 3:41:23 PM (6 years ago)
Author:
joerg
Message:

created object for the rows of a document for more fine grained syncs

Location:
trunk/src
Files:
1 added
26 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/jlatexeditor/Doc.java

    r996 r1139  
    4242    private DocState(SCEDocument document) {
    4343      // build a balanced binary tree from the rows of the document
    44       SCEDocumentRow[] rows = document.getRows();
     44      SCEDocumentRow[] rows = document.getRowsModel().getRows();
    4545
    4646      int start = 0;
  • trunk/src/jlatexeditor/ErrorView.java

    r1135 r1139  
    225225    int column = 0;
    226226    if (error.getTextBefore() != null) {
    227       String line = pane.getDocument().getRow(error.getLineStart()-1);
     227      String line = pane.getDocument().getRowsModel().getRowAsString(error.getLineStart()-1);
    228228
    229229      int i = line.indexOf(error.getTextBefore());
  • trunk/src/jlatexeditor/JLatexEditorJFrame.java

    r1093 r1139  
    891891  public boolean hasDocumentClass(SCEDocument document) {
    892892    // search in the first 100 lines
    893     for (int lineNr=0; lineNr<100 && lineNr<document.getRowsCount(); lineNr++) {
     893    SCEDocumentRow[] rows = document.getRowsModel().getRows();
     894    for (int lineNr = 0; lineNr < 100 && lineNr < rows.length; lineNr++) {
    894895      // ignore comments
    895       String line = document.getRow(lineNr).replaceAll("%.*", "");
     896      String line = rows[lineNr].toString().replaceAll("%.*", "");
    896897
    897898      if (line.contains("\\documentclass") || line.contains("\\input") || line.contains("\\include")) {
     
    10831084      SCEPane pane = getActiveEditor().getTextPane();
    10841085      SCEDocument document = pane.getDocument();
    1085       document.setSelectionRange(document.createDocumentPosition(0,0), document.createDocumentPosition(document.getRowsCount()-1, 0));
     1086      document.setSelectionRange(document.createDocumentPosition(0,0), document.createDocumentPosition(document.getRowsModel().getRowsCount()-1, 0));
    10861087      pane.repaint();
    10871088    } else
  • trunk/src/jlatexeditor/addon/ColumnRealigner.java

    r1128 r1139  
    3535
    3636      // search for column definition after begin command
    37       String restOfLine = doc.getRow(row).substring(col + 1);
     37      String restOfLine = doc.getRowsModel().getRowAsString(row).substring(col + 1);
    3838      if (restOfLine.startsWith("{")) {
    3939        int openBraces = 0;
  • trunk/src/jlatexeditor/addon/EnvironmentUtils.java

    r1101 r1139  
    8181      rowNr = caret.getRow();
    8282
    83       String row = document.getRow(rowNr).substring(0, caret.getColumn());
     83      String row = document.getRowsModel().getRowAsString(rowNr, 0, caret.getColumn());
    8484      parseEnvs(openEnvStack, closeEnvStack, rowNr, row);
    8585    }
     
    9090        // search above cursor
    9191        for(rowNr--; rowNr >= 0; rowNr--) {
    92           String row = document.getRow(rowNr);
     92          String row = document.getRowsModel().getRowAsString(rowNr);
    9393          parseEnvs(openEnvStack, closeEnvStack, rowNr, row);
    9494          if (!openEnvStack.isEmpty()) break;
     
    169169      rowNr = caret.getRow();
    170170
    171       String row = document.getRow(rowNr).substring(caret.getColumn());
     171      String row = document.getRowsModel().getRowAsString(rowNr).substring(caret.getColumn());
    172172      parseEnvs(closeEnvStack, openEnvStack, rowNr, row);
    173173    }
     
    177177      if (closeEnvStack.size() == 0) {
    178178        // search above cursor
    179         for(rowNr++; rowNr < document.getRowsCount(); rowNr++) {
    180           String row = document.getRow(rowNr);
     179        for(rowNr++; rowNr < document.getRowsModel().getRowsCount(); rowNr++) {
     180          String row = document.getRowsModel().getRowAsString(rowNr);
    181181          parseEnvs(closeEnvStack, openEnvStack, rowNr, row);
    182182          if (!closeEnvStack.isEmpty()) break;
  • trunk/src/jlatexeditor/bib/BibCodeHelper.java

    r1019 r1139  
    2828    }
    2929
    30     SCEDocumentRow[] rows = pane.getDocument().getRows();
     30    SCEDocumentRow[] rows = pane.getDocument().getRowsModel().getRows();
    3131    int row = pane.getCaret().getRow();
    3232    int column = pane.getCaret().getColumn();
  • trunk/src/jlatexeditor/bib/BibSyntaxHighlighting.java

    r1054 r1139  
    11package jlatexeditor.bib;
    22
    3 import jlatexeditor.JLatexEditorJFrame;
    43import jlatexeditor.codehelper.BackgroundParser;
    5 import jlatexeditor.codehelper.BibParser;
    64import jlatexeditor.syntaxhighlighting.LatexStyles;
    75import jlatexeditor.syntaxhighlighting.LatexSyntaxHighlighting;
     
    5553  public void reset() {
    5654    // get the actual document rows
    57     int rowsCount = document.getRowsCount();
    58     SCEDocumentRow rows[] = document.getRows();
     55    SCEDocumentRow rows[] = document.getRowsModel().getRows();
    5956
    6057    // reset all states states and mark rows as modified
    61     for (int row_nr = 0; row_nr < rowsCount; row_nr++) {
    62       rows[row_nr].modified = true;
    63       rows[row_nr].parserStateStack = null;
     58    for (SCEDocumentRow row : rows) {
     59      row.modified = true;
     60      row.parserStateStack = null;
    6461    }
    6562
     
    10299  private void parse() {
    103100    // get the actual document rows
    104     int rowsCount = document.getRowsCount();
    105     SCEDocumentRow rows[] = document.getRows();
     101    SCEDocumentRow rows[] = document.getRowsModel().getRows();
    106102
    107103    // find the rows that were modified since last parse
    108     for (int row_nr = 0; row_nr < rowsCount; row_nr++) {
     104    for (int row_nr = 0; row_nr < rows.length; row_nr++) {
    109105      SCEDocumentRow row = rows[row_nr];
    110106      if (!row.modified) continue;
     
    112108      // has this row a known states state?
    113109      if (row.parserStateStack != null) {
    114         parseRow(row_nr, rowsCount, rows);
     110        parseRow(row_nr, rows.length, rows);
    115111      } else {
    116         parseRow(row_nr - 1, rowsCount, rows);
     112        parseRow(row_nr - 1, rows.length, rows);
    117113      }
    118114    }
  • trunk/src/jlatexeditor/changelog/ChangeLogSyntaxHighlighting.java

    r1048 r1139  
    5050  public void reset() {
    5151    // get the actual document rows
    52     int rowsCount = document.getRowsCount();
    53     SCEDocumentRow rows[] = document.getRows();
     52    SCEDocumentRow rows[] = document.getRowsModel().getRows();
    5453
    5554    // reset all states states and mark rows as modified
    56     for (int row_nr = 0; row_nr < rowsCount; row_nr++) {
    57       rows[row_nr].modified = true;
    58       rows[row_nr].parserStateStack = null;
     55    for (SCEDocumentRow row : rows) {
     56      row.modified = true;
     57      row.parserStateStack = null;
    5958    }
    6059
     
    9796  private void parse() {
    9897    // get the actual document rows
    99     int rowsCount = document.getRowsCount();
    100     SCEDocumentRow rows[] = document.getRows();
     98    SCEDocumentRows rowsModel = document.getRowsModel();
     99    SCEDocumentRow rows[] = rowsModel.getRows();
    101100
    102101    // find the rows that were modified since last parse
    103     for (int row_nr = 0; row_nr < rowsCount; row_nr++) {
     102    for (int row_nr = 0; row_nr < rows.length; row_nr++) {
    104103      SCEDocumentRow row = rows[row_nr];
    105104      if (!row.modified) continue;
     
    107106
    108107      if (row_nr == 1) {
    109         document.setStyle(ChangeLogStyles.HEADLINE1, row_nr, 0, row.length);
     108        rowsModel.setStyle(ChangeLogStyles.HEADLINE1, row_nr, 0, row.length);
    110109        continue;
    111110      }
     
    117116
    118117      if ((words = commentPattern.findInRow(rowString, row_nr)) != null) {
    119         document.setStyle(ChangeLogStyles.COMMENT, words.get(0));
     118        rowsModel.setStyle(ChangeLogStyles.COMMENT, words.get(0));
    120119      } else
    121120      if ((words = header1Pattern.findInRow(rowString, row_nr)) != null) {
    122         document.setStyle(ChangeLogStyles.UNIMPORTANT, words.get(0));
     121        rowsModel.setStyle(ChangeLogStyles.UNIMPORTANT, words.get(0));
    123122      } else
    124123      if ((words = header2Pattern.findInRow(rowString, row_nr)) != null) {
    125         document.setStyle(ChangeLogStyles.UNIMPORTANT, words.get(0));
    126         document.setStyle(ChangeLogStyles.HEADLINE2, words.get(1));
    127         document.setStyle(ChangeLogStyles.UNIMPORTANT, words.get(2));
     124        rowsModel.setStyle(ChangeLogStyles.UNIMPORTANT, words.get(0));
     125        rowsModel.setStyle(ChangeLogStyles.HEADLINE2, words.get(1));
     126        rowsModel.setStyle(ChangeLogStyles.UNIMPORTANT, words.get(2));
    128127      } else
    129128      if ((words = item1Pattern.findInRow(rowString, row_nr)) != null) {
    130         document.setStyle(ChangeLogStyles.TEXT, words.get(0));
    131         document.setStyle(ChangeLogStyles.ITEM1, words.get(1));
     129        rowsModel.setStyle(ChangeLogStyles.TEXT, words.get(0));
     130        rowsModel.setStyle(ChangeLogStyles.ITEM1, words.get(1));
    132131        item = true;
    133132      } else
    134133      if ((words = item2Pattern.findInRow(rowString, row_nr)) != null) {
    135         document.setStyle(ChangeLogStyles.TEXT, words.get(0));
    136         document.setStyle(ChangeLogStyles.ITEM2, words.get(1));
     134        rowsModel.setStyle(ChangeLogStyles.TEXT, words.get(0));
     135        rowsModel.setStyle(ChangeLogStyles.ITEM2, words.get(1));
    137136        item = true;
    138137      } else
    139138      if ((words = item3Pattern.findInRow(rowString, row_nr)) != null) {
    140         document.setStyle(ChangeLogStyles.TEXT, words.get(0));
    141         document.setStyle(ChangeLogStyles.ITEM3, words.get(1));
     139        rowsModel.setStyle(ChangeLogStyles.TEXT, words.get(0));
     140        rowsModel.setStyle(ChangeLogStyles.ITEM3, words.get(1));
    142141        item = true;
    143142      } else
    144143      if ((words = linePattern.findInRow(rowString, row_nr)) != null) {
    145         document.setStyle(ChangeLogStyles.TEXT, words.get(0));
     144        rowsModel.setStyle(ChangeLogStyles.TEXT, words.get(0));
    146145      }
    147146
    148147      if (item) {
    149148        for (List<WordWithPos> words2 : viaPattern.findAllInRow(rowString, row_nr)) {
    150           document.setStyle(ChangeLogStyles.SHORTCUT, words2.get(0));
     149          rowsModel.setStyle(ChangeLogStyles.SHORTCUT, words2.get(0));
    151150          if (words2.size() > 1) {
    152             document.setStyle(ChangeLogStyles.MENU, words2.get(2));
     151            rowsModel.setStyle(ChangeLogStyles.MENU, words2.get(2));
    153152          }
    154153        }
    155154        for (List<WordWithPos> words2 : stringPattern.findAllInRow(rowString, row_nr)) {
    156           document.setStyle(ChangeLogStyles.STRING, words2.get(0));
     155          rowsModel.setStyle(ChangeLogStyles.STRING, words2.get(0));
    157156        }
    158157      }
  • trunk/src/jlatexeditor/codehelper/LatexLineBreakListener.java

    r1131 r1139  
    2727
    2828    if (row > 0) {
    29       String lastLine = doc.getRow(row - 1);
     29      String lastLine = doc.getRowsModel().getRowAsString(row - 1);
    3030      boolean indent = false;
    3131      boolean closeEnv = false;
     
    7777      if (closeEnv) {
    7878        SCEPosition oldPos = new SCEDocumentPosition(caret.getRow(), caret.getColumn());
    79         String currLine = doc.getRow(row);
     79        String currLine = doc.getRowsModel().getRowAsString(row);
    8080        String nextIndentation = currLine.substring(0, Math.max(0, currLine.length() - 2));
    8181        pane.insert("\n" + nextIndentation + "\\end{" + envName + '}');
  • trunk/src/jlatexeditor/errorhighlighting/LatexErrorHighlighting.java

    r744 r1139  
    7676        if (error.getType() != LatexCompileError.TYPE_ERROR) continue;
    7777
    78         String row = document.getRow(errorRow);
     78        String row = document.getRowsModel().getRowAsString(errorRow);
    7979
    8080        int errorColumn = 0;
  • trunk/src/jlatexeditor/gproperties/GPropertiesSyntaxHighlighting.java

    r1048 r1139  
    4343  public void reset() {
    4444    // get the actual document rows
    45     int rowsCount = document.getRowsCount();
    46     SCEDocumentRow rows[] = document.getRows();
     45    SCEDocumentRow rows[] = document.getRowsModel().getRows();
    4746
    4847    // reset all states states and mark rows as modified
    49     for (int row_nr = 0; row_nr < rowsCount; row_nr++) {
     48    for (int row_nr = 0; row_nr < rows.length; row_nr++) {
    5049      rows[row_nr].modified = true;
    5150      rows[row_nr].parserStateStack = null;
     
    9089  private void parse() {
    9190    // get the actual document rows
    92     int rowsCount = document.getRowsCount();
    93     SCEDocumentRow rows[] = document.getRows();
     91    SCEDocumentRow rows[] = document.getRowsModel().getRows();
    9492
    9593    // find the rows that were modified since last parse
    96     for (int row_nr = 0; row_nr < rowsCount; row_nr++) {
     94    for (int row_nr = 0; row_nr < rows.length; row_nr++) {
    9795      SCEDocumentRow row = rows[row_nr];
    9896      if (!row.modified) continue;
     
    10098      // has this row a known states state?
    10199      if (row.parserStateStack != null) {
    102         parseRow(row_nr, rowsCount, rows);
     100        parseRow(row_nr, rows.length, rows);
    103101      } else {
    104         parseRow(row_nr - 1, rowsCount, rows);
     102        parseRow(row_nr - 1, rows.length, rows);
    105103      }
    106104    }
  • trunk/src/jlatexeditor/performance/Performance.java

    r1117 r1139  
    6262    Random random = new Random(8923489);
    6363    for (int i = 0; i < 200000; i++) {
    64       int row = random.nextInt(document.getRowsCount());
    65       int column = random.nextInt(document.getRowLength(row) + 1);
     64      int row = random.nextInt(document.getRowsModel().getRowsCount());
     65      int column = random.nextInt(document.getRowsModel().getRowLength(row) + 1);
    6666      caret.moveTo(row, column, false);
    6767
  • trunk/src/jlatexeditor/quickhelp/LatexQuickHelp.java

    r1124 r1139  
    102102   */
    103103  public String findCommand(int row, int column) {
    104     String line = document.getRow(row);
     104    String line = document.getRowsModel().getRowAsString(row);
    105105
    106106    List<WordWithPos> groups = commandPattern.find(line, row, column);
  • trunk/src/jlatexeditor/syntaxhighlighting/LatexSyntaxHighlighting.java

    r1138 r1139  
    6767  public void reset() {
    6868    // get the actual document rows
    69     int rowsCount = document.getRowsCount();
    70     SCEDocumentRow rows[] = document.getRows();
     69    SCEDocumentRow rows[] = document.getRowsModel().getRows();
    7170
    7271    // reset all states states and mark rows as modified
    73     for (int row_nr = 0; row_nr < rowsCount; row_nr++) {
    74       rows[row_nr].modified = true;
    75       rows[row_nr].parserStateStack = null;
     72    for (SCEDocumentRow row : rows) {
     73      row.modified = true;
     74      row.parserStateStack = null;
    7675    }
    7776
     
    114113  private void parse() {
    115114    // get the actual document rows
    116     int rowsCount = document.getRowsCount();
    117     SCEDocumentRow rows[] = document.getRows();
     115    SCEDocumentRow rows[] = document.getRowsModel().getRows();
    118116
    119117    // find the rows that were modified since last parse
    120     for (int row_nr = 0; row_nr < rowsCount; row_nr++) {
     118    for (int row_nr = 0; row_nr < rows.length; row_nr++) {
    121119      SCEDocumentRow row = rows[row_nr];
    122120      if (!row.modified) continue;
     
    124122      // has this row a known states state?
    125123      if (row.parserStateStack != null) {
    126         parseRow(row_nr, rowsCount, rows);
     124        parseRow(row_nr, rows.length, rows);
    127125      } else {
    128         parseRow(row_nr - 1, rowsCount, rows);
     126        parseRow(row_nr - 1, rows.length, rows);
    129127      }
    130128    }
     
    361359
    362360        // extract word from row that shell be checked for misspellings
    363         String rowString = document.getRow(row_nr);
     361        String rowString = document.getRowsModel().getRowAsString(row_nr);
    364362
    365363        // for each term in this row
  • trunk/src/sce/codehelper/CodeHelperPane.java

    r1050 r1139  
    144144  private int findPrefixStart(int row, int column) {
    145145    // get the command name
    146     SCEDocumentRow documentRow = document.getRows()[row];
     146    SCEDocumentRow documentRow = document.getRowsModel().getRow(row);
    147147
    148148    int commandStart = pane.findSplitterInRow(row, column, -1);
     
    352352            int colAfter  = argumentRange.getEndPosition().getColumn();
    353353            int rowNr = argumentRange.getStartPosition().getRow();
    354             SCEDocumentRow row = document.getRows()[rowNr];
     354            SCEDocumentRow row = document.getRowsModel().getRow(rowNr);
    355355            if (colBefore >= 0 && colAfter < row.length &&
    356356                row.chars[colBefore].character == '[' && row.chars[colAfter].character == ']') {
     
    384384        int colAfter  = argumentRange.getEndPosition().getColumn();
    385385        int rowNr = argumentRange.getStartPosition().getRow();
    386         SCEDocumentRow row = document.getRows()[rowNr];
     386        SCEDocumentRow row = document.getRowsModel().getRow(rowNr);
    387387        if (colBefore >= 0 && colAfter < row.length &&
    388388            row.chars[colBefore].character != '[' || row.chars[colAfter].character != ']') {
     
    423423
    424424  public void keyPressed(KeyEvent e) {
    425     //int row = caret.getRow();
     425    //int row = caret.getRowAsString();
    426426    //int column = caret.getColumn();
    427427
     
    440440
    441441      int index = column-1;
    442       String rowString = document.getRow(row);
     442      String rowString = document.getRowAsString(row);
    443443      while(index > 0) {
    444444        char c = rowString.charAt(index);
     
    698698          }
    699699
    700           String word = document.getRow(caret.getRow(), 0, caret.getColumn());
     700          String word = document.getRowsModel().getRowAsString(caret.getRow(), 0, caret.getColumn());
    701701          Matcher matcher = pattern.matcher(word);
    702702          if (matcher.find()) {
  • trunk/src/sce/codehelper/PatternPair.java

    r1127 r1139  
    3838    SCECaret caret = pane.getCaret();
    3939
    40     return find(pane.getDocument().getRow(caret.getRow()), caret.getRow(), caret.getColumn());
     40    return find(pane.getDocument().getRowsModel().getRowAsString(caret.getRow()), caret.getRow(), caret.getColumn());
    4141  }
    4242
    4343  public List<WordWithPos> find(SCEPane pane, SCEPosition pos) {
    44     return find(pane.getDocument().getRow(pos.getRow()), pos.getRow(), pos.getColumn());
     44    return find(pane.getDocument().getRowsModel().getRowAsString(pos.getRow()), pos.getRow(), pos.getColumn());
    4545  }
    4646
  • trunk/src/sce/component/SCECaret.java

    r1057 r1139  
    7979   */
    8080  public void move(int direction, boolean keepSelection) {
     81    SCEDocumentRows rowsModel = document.getRowsModel();
     82
    8183    if (direction == DIRECTION_UP) moveToVirt(getRow() - 1, virtualColumn, keepSelection, false);
    8284    if (direction == DIRECTION_DOWN) moveToVirt(getRow() + 1, virtualColumn, keepSelection, false);
    8385    if (direction == DIRECTION_LEFT) {
    8486      if (getColumn() == 0 && getRow() > 0) {
    85         moveTo(getRow() - 1, document.getRowLength(getRow() - 1), keepSelection);
     87        moveTo(getRow() - 1, rowsModel.getRowLength(getRow() - 1), keepSelection);
    8688      } else {
    8789        moveTo(getRow(), getColumn() - 1, keepSelection);
     
    8991    }
    9092    if (direction == DIRECTION_RIGHT) {
    91       if (getColumn() == document.getRowLength(getRow()) && getRow() < document.getRowsCount() - 1) {
     93      if (getColumn() == rowsModel.getRowLength(getRow()) && getRow() < rowsModel.getRowsCount() - 1) {
    9294        moveTo(getRow() + 1, 0, keepSelection);
    9395      } else {
     
    134136
    135137    // set new position
    136     int new_row = Math.max(Math.min(row, document.getRowsCount() - 1), 0);
    137     int new_column = Math.max(Math.min(column, document.getRowLength(new_row)), 0);
     138    int new_row = Math.max(Math.min(row, document.getRowsModel().getRowsCount() - 1), 0);
     139    int new_column = Math.max(Math.min(column, document.getRowsModel().getRowLength(new_row)), 0);
    138140    position.setPosition(new_row, new_column);
    139141
  • trunk/src/sce/component/SCECharInputStream.java

    r744 r1139  
    2626
    2727    public FromDocument(SCEDocument document) {
    28       this(document.getRows(), document.getRowsCount(), 0, 0);
     28      this(document.getRowsModel().getRows(), 0, 0);
    2929    }
    3030
    31     public FromDocument(SCEDocumentRow rows[], int rows_count, int row_nr, int column_nr) {
    32       this.rows_count = rows_count;
     31    public FromDocument(SCEDocumentRow rows[], int row_nr, int column_nr) {
     32      this.rows_count = rows.length;
    3333      this.rows = rows;
    3434
  • trunk/src/sce/component/SCEDiff.java

    r1072 r1139  
    209209    SCEDocument diffDocument = right.getDocument();
    210210
    211     int paneRows = paneDocument.getRowsCount();
    212     int diffRows = diffDocument.getRowsCount();
     211    int paneRows = paneDocument.getRowsModel().getRowsCount();
     212    int diffRows = diffDocument.getRowsModel().getRowsCount();
    213213
    214214    modifications = Diff.diff(diffDocument.getText(), paneDocument.getText());
     
    307307
    308308  private TokenList[] getRows(SCEDocument document) {
    309     SCEDocumentRow[] sceRows = document.getRows();
     309    SCEDocumentRow[] sceRows = document.getRowsModel().getRows();
    310310
    311311    TokenList rows[] = new TokenList[sceRows.length];
  • trunk/src/sce/component/SCEDocument.java

    r1057 r1139  
    2020
    2121public class SCEDocument {
    22   // optimization
    23   private int capacityIncrement = 20;
    24 
    2522  // text data
    26   private int rowsCount = 1;
    27   private SCEDocumentRow[] rows = null;
     23  private SCEDocumentRows rows;
    2824
    2925  // the available attributes
     
    3329  private SCEDocumentPosition selectionStart = null;
    3430  private SCEDocumentPosition selectionEnd = null;
    35 
    36   // limited edit range
    37   private SCEDocumentPosition editRangeStart = null;
    38   private SCEDocumentPosition editRangeEnd = null;
    3931
    4032  // editable?
     
    5850  public SCEDocument() {
    5951    // initialize text data
    60     rowsCount = 1;
    61     rows = new SCEDocumentRow[capacityIncrement];
    62     for (int row_nr = 0; row_nr < rows.length; row_nr++) {
    63       rows[row_nr] = new SCEDocumentRow();
    64       rows[row_nr].row_nr = row_nr;
    65     }
     52    rows = new SCEDocumentRows();
    6653
    6754    // create an array for available text styles and add default styles
     
    8370   */
    8471  public void clear() {
    85     rowsCount = 1;
    86     for (SCEDocumentRow row : rows) row.length = 0;
    87   }
    88 
    89   /**
    90    * Returns the number of rows in this document.
    91    *
    92    * @return the number of rows
    93    */
    94   public int getRowsCount() {
    95     return rowsCount;
    96   }
    97 
    98   /**
    99    * Returns the rows of the document.
    100    * Be carefull, this is internal representation!
     72    rows.clear();
     73  }
     74
     75  /**
     76   * Returns the rows in this document.
    10177   *
    10278   * @return the rows
    10379   */
    104   public SCEDocumentRow[] getRows() {
    105     SCEDocumentRow[] usedRows = new SCEDocumentRow[rowsCount];
    106     System.arraycopy(rows, 0, usedRows, 0, rowsCount);
    107     return usedRows;
    108   }
    109 
    110   /**
    111    * Returns the length of a certain row.
    112    *
    113    * @param row_nr the row number
    114    * @return the length of the row
    115    */
    116   public int getRowLength(int row_nr) {
    117     if (row_nr >= rowsCount) return 0;
    118     return rows[row_nr].length;
     80  public SCEDocumentRows getRowsModel() {
     81    return rows;
    11982  }
    12083
     
    12689  public SCECharInputStream getSCECharInputStream() {
    12790    return new SCECharInputStream.FromDocument(this);
    128   }
    129 
    130   /**
    131    * Returns the row as string.
    132    *
    133    * @param row_nr the row number
    134    * @return the string
    135    */
    136   public String getRow(int row_nr) {
    137     if (row_nr >= rowsCount) return "";
    138     return rows[row_nr].toString();
    139   }
    140 
    141   public String getRow(int row_nr, int col_start, int col_end) {
    142     if (row_nr >= rowsCount) return "";
    143     return rows[row_nr].toString(col_start, col_end);
    14491  }
    14592
     
    175122   */
    176123  public String getText() {
    177     StringBuffer textBuffer = new StringBuffer(getRow(0));
    178     for (int row_nr = 1; row_nr < rowsCount; row_nr++) {
    179       textBuffer.append("\n");
    180       textBuffer.append(getRow(row_nr));
    181     }
    182     return textBuffer.toString();
     124    return rows.getText();
    183125  }
    184126
     
    191133   */
    192134  public String getText(SCEPosition start, SCEPosition end) {
    193     String text;
    194 
    195     int startRow = start.getRow();
    196     int endRow = end.getRow();
    197     if (startRow == endRow) {
    198       text = getRow(startRow).substring(start.getColumn(), end.getColumn());
    199     } else {
    200       text = getRow(startRow).substring(start.getColumn());
    201       for (int row_nr = startRow + 1; row_nr < endRow; row_nr++) {
    202         text += "\n" + getRow(row_nr);
    203       }
    204       text += "\n" + getRow(endRow).substring(0, end.getColumn());
    205     }
    206 
    207     return text;
     135    return rows.getText(start, end);
    208136  }
    209137
     
    216144   */
    217145  public SCEDocumentPosition createDocumentPosition(int row_nr, int column_nr) {
    218     return createDocumentPosition(row_nr, column_nr, 0);
     146    return rows.createDocumentPosition(row_nr, column_nr);
    219147  }
    220148
     
    228156   */
    229157  public SCEDocumentPosition createDocumentPosition(int row_nr, int column_nr, int rel_column) {
    230     // if the document is empty
    231     if (rowsCount <= 1 && rows[0].length == 0) return new SCEDocumentPosition(0, 0);
    232 
    233     // wrong position?
    234     if (row_nr >= rowsCount) row_nr = rowsCount - 1;
    235     if (column_nr <= 0) return new SCEDocumentPosition(rows[row_nr], column_nr);
    236     if (column_nr >= rows[row_nr].length) {
    237       return new SCEDocumentPosition(rows[row_nr], column_nr - rows[row_nr].length + 1);
    238     }
    239 
    240     return new SCEDocumentPosition(rows[row_nr].chars[column_nr], 0, rel_column);
     158    return rows.createDocumentPosition(row_nr, column_nr, rel_column);
    241159  }
    242160
     
    249167   */
    250168  public void setDocumentPosition(SCEDocumentPosition position, int row_nr, int column_nr) {
    251     position.setPosition(rows[row_nr].chars[column_nr]);
     169    rows.setDocumentPosition(position, row_nr, column_nr);
    252170  }
    253171
     
    336254   */
    337255  public void setEditRange(SCEDocumentPosition start, SCEDocumentPosition end, boolean undo) {
    338     SCEDocumentEvent event = new SCEDocumentEvent();
    339     event.setEventType(SCEDocumentEvent.EVENT_EDITRANGE | (undo ? SCEDocumentEvent.EVENT_UNDO : 0));
    340 
    341     if (start == null || end == null) {
    342       editRangeStart = null;
    343       editRangeEnd = null;
    344 
    345       // Inform the listeners about the change (range is null)
    346       documentChanged(event);
    347 
    348       return;
    349     }
    350 
    351     editRangeStart = createDocumentPosition(start.getRow(), start.getColumn() - 1);
    352     editRangeEnd = createDocumentPosition(end.getRow(), end.getColumn() + 1);
    353 
    354     // Inform the listeners about the change
    355     event.setRange(start.getRow(), start.getColumn(), end.getRow(), end.getColumn());
    356     documentChanged(event);
     256    documentChanged(rows.setEditRange(start, end, undo));
    357257  }
    358258
     
    363263   */
    364264  public boolean hasEditRange() {
    365     return editRangeStart != null && editRangeEnd != null;
     265    return rows.hasEditRange();
    366266  }
    367267
     
    372272   */
    373273  public SCEDocumentPosition getEditRangeStart() {
    374     return new SCEDocumentPosition(editRangeStart.getRow(), editRangeStart.getColumn() + 1);
     274    return rows.getEditRangeStart();
    375275  }
    376276
     
    381281   */
    382282  public SCEDocumentPosition getEditRangeEnd() {
    383     return new SCEDocumentPosition(editRangeEnd.getRow(), editRangeEnd.getColumn() - 1);
     283    return rows.getEditRangeEnd();
    384284  }
    385285
     
    390290   */
    391291  public String getEditRangeText() {
    392     if (!hasEditRange()) return null;
    393     return getText(getEditRangeStart(), getEditRangeEnd());
     292    return rows.getEditRangeText();
    394293  }
    395294
     
    416315   * @return the attributed test
    417316   */
    418   public synchronized AttributedString getRowAttributed(int row_nr) {
    419     if (row_nr >= rowsCount) return null;
    420     return getRowAttributed(row_nr, 0, getRowLength(row_nr));
    421   }
    422 
    423   public synchronized AttributedString getRowAttributed(int row_nr, int col_start, int col_end) {
    424     if (row_nr >= rowsCount) return null;
    425 
    426     SCEDocumentRow row = rows[row_nr];
    427     col_end = Math.min(col_end, row.length);
    428     if (col_start >= col_end) return null;
    429 
    430     // create the attributedString
    431     String string = getRow(row_nr, col_start, col_end);
    432     if (string == null || string.length() == 0) return null;
    433     AttributedString attributedString = new AttributedString(string);
    434 
    435     // add the attributes
    436     for (int column_nr = col_start; column_nr < col_end; column_nr++) {
    437       int begin_index = column_nr - col_start;
    438       while (column_nr < col_end - 1 &&
    439               row.chars[column_nr].style == row.chars[column_nr + 1].style &&
    440               row.chars[column_nr].overlayStyle == row.chars[column_nr + 1].overlayStyle) column_nr++;
    441       int end_index = column_nr + 1 - col_start;
    442       attributedString.addAttributes(stylesMap[row.chars[begin_index + col_start].style], begin_index, end_index);
    443       attributedString.addAttributes(stylesMap[row.chars[begin_index + col_start].overlayStyle], begin_index, end_index);
    444     }
    445 
    446     // pay attention to selection
    447     if (hasSelection() && row_nr >= selectionStart.getRow() && row_nr <= selectionEnd.getRow()) {
    448       for (int column_nr = col_start; column_nr < col_end; column_nr++) {
    449         if (row_nr == selectionStart.getRow() && column_nr < selectionStart.getColumn()) continue;
    450         if (row_nr == selectionEnd.getRow() && column_nr >= selectionEnd.getColumn()) continue;
    451 
    452         // background must be set here too to override other background colors
    453         attributedString.addAttribute(TextAttribute.BACKGROUND, SCEPane.selectionHighlightColor, column_nr - col_start, column_nr + 1 - col_start);
    454         attributedString.addAttribute(TextAttribute.FOREGROUND, Color.WHITE, column_nr - col_start, column_nr + 1 - col_start);
    455       }
    456     }
    457 
    458     return attributedString;
     317  public AttributedString getRowAttributed(int row_nr) {
     318    return rows.getRowAttributed(row_nr, selectionStart, selectionEnd, stylesMap);
     319  }
     320
     321  public AttributedString getRowAttributed(int row_nr, int col_start, int col_end) {
     322    return rows.getRowAttributed(row_nr, col_start, col_end, selectionStart, selectionEnd, stylesMap);
    459323  }
    460324
     
    467331   */
    468332  public synchronized void insert(String text, int row_nr, int column_nr) {
    469     // is this position within the edit range?
    470     if (hasEditRange()) {
    471       SCEDocumentPosition position = new SCEDocumentPosition(row_nr, column_nr);
    472       if (position.compareTo(editRangeStart) <= 0 || position.compareTo(editRangeEnd) >= 0) {
    473         // this is not allowed
    474         return;
    475       }
    476     }
    477 
    478333    insert(text, row_nr, column_nr, SCEDocumentEvent.UPDATE_VIEW);
    479334  }
     
    489344  public synchronized void insert(String text, int row_nr, int column_nr, int eventID) {
    490345    if (!editable) return;
    491     if (row_nr >= rowsCount) return;
    492346
    493347    // remember row and column
    494348    SCEDocumentPosition position = new SCEDocumentPosition(row_nr, column_nr);
    495349
    496     // convert the text into a character array
    497     char charText[] = text.toCharArray();
    498 
    499     // is there a rowbreak within the text?
    500     if (text.indexOf('\n') == -1) {
    501       insert(charText, 0, charText.length, row_nr, column_nr);
    502       column_nr += charText.length;
    503     } else {
    504       // count the newrow characters
    505       int newlineCount = 0;
    506       for (char aCharText : charText) {
    507         if (aCharText == '\n') newlineCount++;
    508       }
    509       // insert some new rows
    510       insertRows(row_nr + 1, newlineCount);
    511 
    512       // special handling of first and last row
    513       insert(rows[row_nr].chars, column_nr, rows[row_nr].length - column_nr, row_nr + newlineCount, 0);
    514       rows[row_nr].length = column_nr;
    515 
    516       // insert row by row
    517       int textRowStart = 0;
    518       int textRowEnd = 0;
    519       while ((textRowEnd = text.indexOf('\n', textRowStart)) != -1) {
    520         insert(charText, textRowStart, textRowEnd - textRowStart, row_nr, column_nr);
    521 
    522         // go to next row
    523         textRowStart = textRowEnd + 1;
    524         row_nr++;
    525         column_nr = 0;
    526       }
    527       insert(charText, textRowStart, text.length() - textRowStart, row_nr, column_nr);
    528       column_nr += text.length() - textRowStart;
    529     }
     350    SCEDocumentPosition endPosition = rows.insert(text, row_nr, column_nr);
     351    if(endPosition == null) return;
    530352
    531353    // Inform the listeners about the change
     
    533355      SCEDocumentEvent event = new SCEDocumentEvent();
    534356      event.setEventType(eventID | SCEDocumentEvent.EVENT_INSERT);
    535       event.setRange(position.getRow(), position.getColumn(), row_nr, column_nr);
     357      event.setRange(position.getRow(), position.getColumn(), endPosition.getRow(), endPosition.getColumn());
    536358      event.setText(text);
    537359      documentChanged(event);
    538360    }
    539   }
    540 
    541   /**
    542    * Inserts the text (without '\n' character) at the given position.
    543    *
    544    * @param chars     the text as document characters
    545    * @param offset    the offset within the array
    546    * @param length    the length the length of the data
    547    * @param row_nr    the row
    548    * @param column_nr the column
    549    */
    550   private void insert(SCEDocumentChar[] chars, int offset, int length, int row_nr, int column_nr) {
    551     if (chars == null || length <= 0) return;
    552 
    553     prepereInsert(row_nr, column_nr, length);
    554     // insert new data
    555     rows[row_nr].setCharacters(chars, offset, length, column_nr);
    556 
    557     // the row has been modified
    558     setModified(row_nr);
    559   }
    560 
    561   /**
    562    * Inserts the text (without '\n' character) at the given position.
    563    *
    564    * @param charText  the text as char array
    565    * @param offset    the offset within the array
    566    * @param length    the length the length of the data
    567    * @param row_nr    the row
    568    * @param column_nr the column
    569    */
    570   private void insert(char[] charText, int offset, int length, int row_nr, int column_nr) {
    571     if (charText == null || length <= 0) return;
    572 
    573     prepereInsert(row_nr, column_nr, length);
    574     // insert new data
    575     rows[row_nr].setCharacters(charText, offset, length, column_nr);
    576 
    577     // the row has been modified
    578     setModified(row_nr);
    579   }
    580 
    581   /**
    582    * Prepers a insert by shifting the data.
    583    *
    584    * @param row_nr    the row
    585    * @param column_nr the column
    586    * @param length    the length
    587    */
    588   private void prepereInsert(int row_nr, int column_nr, int length) {
    589     // do we have enough space left?
    590     if (rows[row_nr].length + length >= rows[row_nr].chars.length) {
    591       rows[row_nr].increaseMaxCharacters(length + capacityIncrement);
    592     }
    593 
    594     // shift the data
    595     rows[row_nr].moveCharacters(column_nr, column_nr + length);
    596361  }
    597362
     
    609374   */
    610375  public void remove(int startRow, int startColumn, int endRow, int endColumn) {
    611     // is this position within the edit range?
    612     if (hasEditRange()) {
    613       SCEDocumentPosition startPosition = new SCEDocumentPosition(startRow, startColumn);
    614       SCEDocumentPosition endPosition = new SCEDocumentPosition(endRow, endColumn);
    615 
    616       if (startPosition.compareTo(editRangeStart) <= 0 || endPosition.compareTo(editRangeEnd) >= 0) {
    617         // this is not allowed
    618         return;
    619       }
    620     }
    621 
    622376    remove(startRow, startColumn, endRow, endColumn, SCEDocumentEvent.UPDATE_VIEW);
    623377  }
     
    635389    if (!editable) return;
    636390
    637     // error handling = do nothing
    638     if (startRow < 0 || startColumn < 0) return;
    639     if (startRow > endRow || (startRow == endRow && startColumn > endColumn)) return;
    640     if (endRow >= rowsCount) return;
    641     if (startColumn > rows[startRow].length || endColumn > rows[endRow].length) return;
    642 
    643391    // copy the text that will be removed
    644392    SCEDocumentPosition start = new SCEDocumentPosition(startRow, startColumn);
     
    646394    String text = getText(start, end);
    647395
    648     // do we have enough space left?
    649     int length = rows[endRow].length - endColumn;
    650     if (startColumn + length >= rows[startRow].chars.length) {
    651       rows[startRow].increaseMaxCharacters(length + capacityIncrement);
    652     }
    653 
    654     // insert the text of the last row into the first row
    655     rows[startRow].setCharacters(rows[endRow].chars, endColumn, length, startColumn);
    656     rows[startRow].length = startColumn + rows[endRow].length - endColumn;
    657     // the row has been modified
    658     setModified(startRow);
    659 
    660     // remove the rows between
    661     int deleteCount = endRow - startRow;
    662     System.arraycopy(rows, endRow + 1, rows, startRow + 1, rowsCount - endRow - 1);
    663     rowsCount -= deleteCount;
    664     // recreate the doublicated rows
    665     for (int row_nr = rowsCount; row_nr < rowsCount + deleteCount; row_nr++) rows[row_nr] = new SCEDocumentRow();
    666     // set the new row numbers
    667     for (int row_nr = startRow; row_nr < rowsCount + deleteCount; row_nr++) rows[row_nr].row_nr = row_nr;
     396    if(!rows.remove(startRow, startColumn, endRow, endColumn)) return;
    668397
    669398    // Inform the listeners about the change
     
    715444
    716445  /**
    717    * Sets the row property modified to true.
    718    *
    719    * @param row_nr the row
    720    */
    721   public void setModified(int row_nr) {
    722     rows[row_nr].modified = true;
    723   }
    724 
    725   /**
    726    * Inserts a new row at the given position.
    727    *
    728    * @param row   the row number
    729    * @param count number of rows to insert
    730    */
    731   private void insertRows(int row, int count) {
    732     // do we have enough space left?
    733     if (rowsCount + count >= rows.length) increaseMaxRows(count + capacityIncrement);
    734 
    735     // shift text data
    736     System.arraycopy(rows, row, rows, row + count, rowsCount - row);
    737 
    738     // init new rows with null
    739     for (int row_nr = row; row_nr < row + count; row_nr++) rows[row_nr] = new SCEDocumentRow();
    740     // increase rows count
    741     rowsCount += count;
    742     // new line numbers
    743     for (int row_nr = row; row_nr < rowsCount; row_nr++) rows[row_nr].row_nr = row_nr;
    744   }
    745 
    746   /**
    747    * Sets the style of the text.
    748    *
    749    * @param style  the style id
    750    * @param row    the row
    751    * @param column the column
    752    * @param length the number of characters to set
    753    */
    754   public void setStyle(byte style, int row, int column, int length) {
    755     if (row >= rowsCount || column + length > rows[row].length) return;
    756 
    757     for (int column_nr = column; column_nr < column + length; column_nr++) {
    758       rows[row].chars[column_nr].style = style;
    759     }
    760   }
    761 
    762   /**
    763    * Sets the style for a certain word.
    764    *
    765    * @param style style
    766    * @param wordWithPos word with position information
    767    */
    768   public void setStyle(byte style, WordWithPos wordWithPos) {
    769     setStyle(style, wordWithPos.getStartPos(), wordWithPos.getEndPos());
    770   }
    771 
    772   /**
    773    * Sets the style of the text.
    774    *
    775    * @param style         the style id
    776    * @param startPosition the start position
    777    * @param endPosition   the end position
    778    */
    779   public void setStyle(byte style, SCEDocumentPosition startPosition, SCEDocumentPosition endPosition) {
    780     int rowStart = startPosition.getRow();
    781     int columnStart = startPosition.getColumn();
    782     int rowEnd = endPosition.getRow();
    783     int columnEnd = endPosition.getColumn();
    784 
    785     while (rowStart < rowEnd) {
    786       setStyle(style, rowStart, columnStart, rows[rowStart].length - columnStart);
    787       rowStart++;
    788       columnStart = 0;
    789     }
    790     setStyle(style, rowStart, columnStart, columnEnd - columnStart);
    791   }
    792 
    793   /**
    794    * Allocate more rows.
    795    *
    796    * @param count the number of rows to add
    797    */
    798   private void increaseMaxRows(int count) {
    799     SCEDocumentRow newRows[] = new SCEDocumentRow[rows.length + count];
    800     System.arraycopy(rows, 0, newRows, 0, rows.length);
    801     for (int row_nr = rows.length; row_nr < newRows.length; row_nr++) {
    802       newRows[row_nr] = new SCEDocumentRow();
    803       newRows[row_nr].row_nr = row_nr;
    804     }
    805     rows = newRows;
    806   }
    807 
    808   /**
    809446   * Sets if this document should be editable.
    810447   *
     
    923560
    924561    // replace all occurrences in all rows
     562    SCEDocumentRow[] rows = this.rows.getRows();
    925563    for (int i = 0; i < rows.length; i++) {
    926564      String rowString = rows[i].toString();
  • trunk/src/sce/component/SCEDocumentRow.java

    r744 r1139  
    66
    77import sce.syntaxhighlighting.ParserStateStack;
     8
     9import java.awt.*;
     10import java.awt.font.TextAttribute;
     11import java.text.AttributedString;
     12import java.util.Map;
    813
    914public class SCEDocumentRow {
     
    102107  }
    103108
    104   public char[] toCharArray(int col_start, int col_end) {
     109  public synchronized char[] toCharArray(int col_start, int col_end) {
     110    col_end = Math.min(col_end, length);
    105111    if (col_end <= col_start) return new char[0];
    106112
     
    110116    }
    111117    return textChars;
     118  }
     119
     120  /**
     121   * Returns the row as attributed string.
     122   *
     123   * @return the attributed test
     124   */
     125  public synchronized AttributedString getRowAttributed(
     126          SCEDocumentPosition selectionStart, SCEDocumentPosition selectionEnd,
     127          Map<? extends TextAttribute, ?>[] stylesMap)
     128  {
     129    return getRowAttributed(0, length, selectionStart, selectionEnd, stylesMap);
     130  }
     131
     132  public synchronized AttributedString getRowAttributed(
     133          int col_start, int col_end,
     134          SCEDocumentPosition selectionStart, SCEDocumentPosition selectionEnd,
     135          Map<? extends TextAttribute, ?>[] stylesMap)
     136  {
     137    col_end = Math.min(col_end, length);
     138    if (col_start >= col_end) return null;
     139
     140    // create the attributedString
     141    String string = toString(col_start, col_end);
     142    if (string == null || string.length() == 0) return null;
     143    AttributedString attributedString = new AttributedString(string);
     144
     145    // add the attributes
     146    for (int column_nr = col_start; column_nr < col_end; column_nr++) {
     147      int begin_index = column_nr - col_start;
     148      while (column_nr < col_end - 1 &&
     149              chars[column_nr].style == chars[column_nr + 1].style &&
     150              chars[column_nr].overlayStyle == chars[column_nr + 1].overlayStyle) column_nr++;
     151      int end_index = column_nr + 1 - col_start;
     152      attributedString.addAttributes(stylesMap[chars[begin_index + col_start].style], begin_index, end_index);
     153      attributedString.addAttributes(stylesMap[chars[begin_index + col_start].overlayStyle], begin_index, end_index);
     154    }
     155
     156    // pay attention to selection
     157    boolean hasSelection = selectionStart != null && selectionEnd != null;
     158    if (hasSelection && row_nr >= selectionStart.getRow() && row_nr <= selectionEnd.getRow()) {
     159      for (int column_nr = col_start; column_nr < col_end; column_nr++) {
     160        if (row_nr == selectionStart.getRow() && column_nr < selectionStart.getColumn()) continue;
     161        if (row_nr == selectionEnd.getRow() && column_nr >= selectionEnd.getColumn()) continue;
     162
     163        // background must be set here too to override other background colors
     164        attributedString.addAttribute(TextAttribute.BACKGROUND, SCEPane.selectionHighlightColor, column_nr - col_start, column_nr + 1 - col_start);
     165        attributedString.addAttribute(TextAttribute.FOREGROUND, Color.WHITE, column_nr - col_start, column_nr + 1 - col_start);
     166      }
     167    }
     168
     169    return attributedString;
    112170  }
    113171
  • trunk/src/sce/component/SCEPane.java

    r1129 r1139  
    66
    77import javax.swing.*;
    8 import javax.swing.text.TextAction;
    98import java.awt.*;
    109import java.awt.datatransfer.DataFlavor;
    1110import java.awt.datatransfer.StringSelection;
    1211import java.awt.datatransfer.Transferable;
    13 import java.awt.event.ActionEvent;
    1412import java.awt.event.FocusEvent;
    1513import java.awt.event.FocusListener;
    16 import java.beans.PropertyChangeListener;
    1714import java.text.AttributedString;
    1815import java.util.ArrayList;
     
    486483
    487484  private boolean removeComment(String commentPrefix, int row) {
    488     String rowString = document.getRow(row);
     485    String rowString = document.getRowsModel().getRowAsString(row);
    489486    if (rowString.startsWith(commentPrefix)) {
    490487      document.remove(row, 0, row, commentPrefix.length());
     
    688685   * Finds the next splitter in the given row and direction.
    689686   *
    690    * @param row       row
     687   * @param row_nr       row
    691688   * @param column    column
    692689   * @param direction -1 / 1
    693690   * @return splitter column
    694691   */
    695   public int findSplitterInRow(int row, int column, int direction) {
    696     String text = document.getRow(row);
     692  public int findSplitterInRow(int row_nr, int column, int direction) {
     693    SCEDocumentRow row = document.getRowsModel().getRow(row_nr);
     694    String text = row.toString();
    697695
    698696    int position = direction == -1 ? column - 1 : column;
    699697    if (position < 0) return 0;
    700     if (position >= document.getRowLength(row)) return document.getRowLength(row);
     698    if (position >= row.length) return row.length;
    701699
    702700    CT ct = getCharTypeAt(text, position);
    703701
    704     while (position >= 0 && position < document.getRowLength(row)) {
     702    while (position >= 0 && position < row.length) {
    705703      if (ct != getCharTypeAt(text, position)) break;
    706704      position += direction;
     
    741739   */
    742740  public SCEPosition findSplitterPosition(int row, int column, int direction) {
     741    SCEDocumentRows rowsModel = document.getRowsModel();
    743742    switch (direction) {
    744743      case -1:
    745744        if (column == 0 && row > 0) {
    746           return new SCEDocumentPosition(row - 1, document.getRowLength(row - 1));
     745          return new SCEDocumentPosition(row - 1, rowsModel.getRowLength(row - 1));
    747746        } else {
    748747          return new SCEDocumentPosition(row, findSplitterInRow(row, column, -1));
    749748        }
    750749      case 1:
    751         if (column == document.getRowLength(row) && row < document.getRowsCount() - 1) {
     750        if (column == rowsModel.getRowLength(row) && row < rowsModel.getRowsCount() - 1) {
    752751          return new SCEDocumentPosition(row + 1, 0);
    753752        } else {
     
    827826    // update the component size
    828827    if (getParent() != null) {
     828      SCEDocumentRow[] rows = document.getRowsModel().getRows();
    829829      Dimension dimension = new Dimension();
    830       for (int row_nr = 0; row_nr < document.getRowsCount(); row_nr++) {
    831         dimension.width = Math.max(document.getRowLength(row_nr) * characterWidth + lineNumberSpacer + 30, dimension.width);
     830      for (SCEDocumentRow row : rows) {
     831        dimension.width = Math.max(row.length * characterWidth + lineNumberSpacer + 30, dimension.width);
    832832      }
    833       dimension.height = document.getRowsCount() * lineHeight + 30;
     833      dimension.height = rows.length * lineHeight + 30;
    834834      preferredSize = dimension;
    835835      getParent().doLayout();
  • trunk/src/sce/component/SCEPaneUI.java

    r1129 r1139  
    197197
    198198      // is the caret at the last column of the line?
    199       if (caret.getColumn() == document.getRowLength(caret.getRow())) {
     199      if (caret.getColumn() == document.getRowsModel().getRowLength(caret.getRow())) {
    200200        document.remove(caret.getRow(), caret.getColumn(), caret.getRow() + 1, 0);
    201201      } else {
     
    240240        } else {
    241241          // move caret to the first non-space character
    242           char[] chars = document.getRow(caret.getRow()).toCharArray();
     242          char[] chars = document.getRowsModel().getRow(caret.getRow()).toCharArray();
    243243          for (int i = 0; i < chars.length; i++) {
    244244            if (chars[i] != ' ' && chars[i] != '\t') {
     
    251251      }
    252252      if (keyCode == KeyEvent.VK_END) {
    253         int rowLength = document.getRowLength(caret.getRow());
     253        int rowLength = document.getRowsModel().getRowLength(caret.getRow());
    254254        if (caret.getColumn() != rowLength) {
    255255          caret.moveTo(caret.getRow(), rowLength, keepSelection);
    256256        } else {
    257257          // move caret to first non-space character
    258           char[] chars = document.getRow(caret.getRow()).toCharArray();
     258          char[] chars = document.getRowsModel().getRow(caret.getRow()).toCharArray();
    259259          for (int i = rowLength; i > 0; i--) {
    260260            if (chars[i - 1] != ' ' && chars[i - 1] != '\t') {
     
    274274      int column = caret.getColumn();
    275275
    276       String line = document.getRow(row).substring(0, column);
     276      String line = document.getRowsModel().getRowAsString(row, 0, column);
    277277      document.insert("\n", row, column);
    278278      // take over indentation of last line
     
    362362
    363363  private void removeIndentation(int row) {
    364     String rowString = document.getRow(row);
     364    String rowString = document.getRowsModel().getRowAsString(row);
    365365    if (rowString.startsWith("  ")) {
    366366      document.remove(row, 0, row, 2);
     
    378378
    379379  public void handleCommand(String command, boolean isShiftDown) {
     380    SCEDocumentRows rowsModel = document.getRowsModel();
     381
    380382    // caret movement
    381383    boolean viewUp = command.equals("move view up");
     
    402404    }
    403405    if (command.equals("jump to end")) {
    404       int row = document.getRowsCount() - 1;
    405       int column = document.getRowLength(row);
     406      int row = rowsModel.getRowsCount() - 1;
     407      int column = rowsModel.getRowLength(row);
    406408      caret.moveTo(row, column, isShiftDown);
    407409    }
    408410
    409411    if (command.equals("remove line")) { // control+Y
    410       if (caret.getRow() < document.getRowsCount() - 1) {
     412      if (caret.getRow() < rowsModel.getRowsCount() - 1) {
    411413        document.remove(caret.getRow(), 0, caret.getRow() + 1, 0);
    412414      } else if (caret.getRow() > 0) {
    413         document.remove(caret.getRow() - 1, document.getRowLength(caret.getRow() - 1), caret.getRow(), document.getRowLength(caret.getRow()));
     415        document.remove(caret.getRow() - 1, rowsModel.getRowLength(caret.getRow() - 1), caret.getRow(), rowsModel.getRowLength(caret.getRow()));
    414416        caret.moveTo(caret.getRow() - 1, caret.getColumn(), false);
    415417      } else {
    416         document.remove(0, 0, 0, document.getRowLength(0));
     418        document.remove(0, 0, 0, rowsModel.getRowLength(0));
    417419        caret.moveTo(0, 0, false);
    418420      }
     
    423425    }
    424426    if (command.equals("remove line behind caret")) { // control+K
    425       document.remove(caret.getRow(), caret.getColumn(), caret.getRow(), document.getRowLength(caret.getRow()));
     427      document.remove(caret.getRow(), caret.getColumn(), caret.getRow(), rowsModel.getRowLength(caret.getRow()));
    426428    }
    427429    if (command.equals("remove word before caret")) { // control+backspace
     
    442444  public void mousePressed(MouseEvent e) {
    443445    SCEDocumentPosition position = pane.viewToModel(e.getX(), e.getY());
     446    SCEDocumentRows rowsModel = document.getRowsModel();
    444447
    445448    // hide quick help
     
    467470          SCEDocumentPosition startPosition = document.createDocumentPosition(caret.getRow(), 0);
    468471          SCEDocumentPosition endPosition = document.createDocumentPosition(caret.getRow() + 1, 0);
    469           if (caret.getRow() >= document.getRowsCount() - 1) {
    470             endPosition = document.createDocumentPosition(caret.getRow(), document.getRowLength(caret.getRow()));
     472          if (caret.getRow() >= rowsModel.getRowsCount() - 1) {
     473            endPosition = document.createDocumentPosition(caret.getRow(), rowsModel.getRowLength(caret.getRow()));
    471474          }
    472475          document.setSelectionRange(startPosition, endPosition);
  • trunk/src/sce/component/SCESearch.java

    r1050 r1139  
    218218
    219219    if (highlightSelection && selection != null) {
    220       int rows = pane.getDocument().getRowsCount();
     220      int rows = pane.getDocument().getRowsModel().getRowsCount();
    221221      SCEDocumentPosition endDocPos = new SCEDocumentPosition(rows, 0);
    222222
     
    528528
    529529      SCEDocument document = editor.getTextPane().getDocument();
    530       SCEDocumentRow[] documentRows = document.getRows();
     530      SCEDocumentRow[] documentRows = document.getRowsModel().getRows();
    531531
    532532      StringBuilder builder = new StringBuilder(100000);
  • trunk/src/sce/component/SourceCodeEditor.java

    r1058 r1139  
    234234      return diff.getVirtualLines();
    235235    } else {
    236       return textPane.getDocument().getRowsCount();
     236      return textPane.getDocument().getRowsModel().getRowsCount();
    237237    }
    238238  }
  • trunk/src/sce/syntaxhighlighting/BracketHighlighting.java

    r744 r1139  
    6464
    6565    SCEDocument document = pane.getDocument();
    66     String line = document.getRow(row);
     66    String line = document.getRowsModel().getRowAsString(row);
    6767    if (column > 0 && (line.charAt(column - 1) == '}' || line.charAt(column - 1) == ')')) {
    6868      // search backwards
     
    7272      int level = 0;
    7373      for (int srow = row; srow >= Math.max(0, row - 40); srow--) {
    74         line = document.getRow(srow);
     74        line = document.getRowsModel().getRowAsString(srow);
    7575        int startColumn = srow == row ? column - 1 : line.length() - 1;
    7676        for (int scolumn = startColumn; scolumn >= 0; scolumn--) {
     
    108108
    109109      int level = 0;
    110       for (int srow = row; srow <= Math.min(document.getRowsCount() - 1, row + 40); srow++) {
    111         line = document.getRow(srow);
     110      for (int srow = row; srow <= Math.min(document.getRowsModel().getRowsCount() - 1, row + 40); srow++) {
     111        line = document.getRowsModel().getRowAsString(srow);
    112112        int startColumn = srow == row ? column : 0;
    113113        for (int scolumn = startColumn; scolumn < line.length(); scolumn++) {
     
    123123            level++;
    124124          } else if (level == 0) {
    125             srow = document.getRowsCount();
     125            srow = document.getRowsModel().getRowsCount();
    126126            break;
    127127          }
Note: See TracChangeset for help on using the changeset viewer.