⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 swedit.java

📁 Text editor implemented in Java using SWT for UI. It is intended to be a minimalist programmer s edi
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
      editor.invokeAction(ST.SELECT_PAGE_UP);      return new CmdReturn(false, true, false);    }    public String toString(){      return "Select Page Up";    }  }  final class SweditSelectWindowStart extends SweditCommand{    public CmdReturn exec(){      editor.invokeAction(ST.SELECT_WINDOW_START);      lastColumn = 1;      return new CmdReturn(false, true, false);    }    public String toString(){      return "Select To Window Start";    }  }  final class SweditSelectWindowEnd extends SweditCommand{    public CmdReturn exec(){      editor.invokeAction(ST.SELECT_WINDOW_END);      lastColumn = -1;      return new CmdReturn(false, true, false);    }    public String toString(){      return "Select To Window End";    }  }  final class SweditSelectTextStart extends SweditCommand{    public CmdReturn exec(){      editor.invokeAction(ST.SELECT_TEXT_START);      lastColumn = 1;      return new CmdReturn(false, true, false);    }    public String toString(){      return "Select To Text Start";    }  }  final class SweditSelectTextEnd extends SweditCommand{    public CmdReturn exec(){      editor.invokeAction(ST.SELECT_TEXT_END);      return new CmdReturn(false, true, false);    }    public String toString(){      return "Select To Text End";    }  }  final class SweditSelectAll extends SweditCommand{    public CmdReturn exec(){      editor.setSelectionRange(0, editor.getCharCount());      return new CmdReturn(false, true, false);    }    public String toString(){      return "Select All";    }  }  final class SweditBlockSelectLineDown extends SweditCommand{    public CmdReturn exec(){      int tempCol = getColumn();      if (getLine() < (editor.getLineCount() - 1)){        if (blockHeight < 1){          blockStart = editor.getCaretOffset();          blockHeight = 2;          blockWidth = 0;        }else{          blockHeight++;        }        editor.invokeAction(ST.LINE_DOWN);        setColumn(tempCol, true);        int blockEnd = tempCol - 1 +                        editor.getOffsetAtLine(                         editor.getLineAtOffset(blockStart) + blockHeight - 1);        editor.redrawRange(blockStart, blockEnd - blockStart, true);      }      return new CmdReturn(true, false, false);    }    public String toString(){      return "Block Select Line Down";    }  }  final class SweditBlockSelectLineUp extends SweditCommand{    public CmdReturn exec(){      if (blockHeight > 1){        int tempCol = getColumn();        editor.invokeAction(ST.LINE_UP);        setColumn(tempCol, false);        int blockEnd = tempCol - 1 +                        editor.getOffsetAtLine(                         editor.getLineAtOffset(blockStart) + blockHeight - 1);        editor.redrawRange(blockStart, blockEnd - blockStart, true);        blockHeight--;      }      return new CmdReturn(true, false, false);    }    public String toString(){      return "Block Select Line Up";    }  }  final class SweditBlockSelectColNext extends SweditCommand{    public CmdReturn exec(){      if (blockHeight < 1){        blockStart = editor.getCaretOffset();        blockHeight = 1;        blockWidth = 0;      }      setColumn(getColumn() + 1, true);       blockWidth++;      lastColumn = getColumn();      int startLine = editor.getLineAtOffset(blockStart);      for (int i=0; i < (blockHeight-1); i++){        int pos = editor.getOffsetAtLine(startLine + i) + lastColumn;        if (endColumn(startLine + i) <= pos){          editor.replaceTextRange(endColumn(startLine + i), 0, " ");        }      }      int blockEnd = lastColumn - 1 +                      editor.getOffsetAtLine(                       editor.getLineAtOffset(blockStart) + blockHeight - 1);      editor.redrawRange(blockStart, blockEnd - blockStart, true);      return new CmdReturn(true, false, false);    }    public String toString(){      return "Block Select Column Next";    }  }  final class SweditBlockSelectColPrev extends SweditCommand{    public CmdReturn exec(){      if((blockWidth > 0) && (blockHeight > 0)){        int blockEnd = lastColumn - 1 +                        editor.getOffsetAtLine(                         editor.getLineAtOffset(blockStart) + blockHeight - 1);        editor.redrawRange(blockStart, blockEnd - blockStart, true);        blockWidth--;        editor.invokeAction(ST.COLUMN_PREVIOUS);        lastColumn = getColumn();      }      return new CmdReturn(true, false, false);    }    public String toString(){      return "Block Select Column Previous";    }  }//=============================================================================  // Print debug information  final class SweditDebug extends SweditCommand{    public CmdReturn exec(){      final MessageBox mb = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);      mb.setText("Debug Info");      int pos = editor.getCaretOffset();      int line = editor.getLineAtOffset(pos);      mb.setMessage("Debug Data:" +                    "\nConfig Loaded " + configLoaded +                    "\nChar Count: " + editor.getCharCount() +                    "\nPos: " + pos +                    "\nColumn: " + getColumn() +                    "\nlastColumn: " + lastColumn +                    "\nEnd Column: " + endColumn(line) +                    "\nLine: " + line +                    "\nLast Line: " + editor.getLineCount() +                    "\nblockStart: " + blockStart +                     "\nblockHeight: " + blockHeight +                    "\nblockWidth: " + blockWidth);      mb.open();      editor.redraw();      return new CmdReturn(false, false, false);    }    public String toString(){      return "Debug Information";    }  }//=============================================================================  // Launch a dialog for finding a string in the document  final class SweditFindString extends SweditCommand{    public CmdReturn exec(){      FindString fs = new FindString();      return new CmdReturn(false, true, false);    }    public String toString(){      return "Find";    }  }//=============================================================================  // Find the next occurrence of the last String defined in the dialog  final class SweditFindNext extends SweditCommand{    public CmdReturn exec(){      findNext();      return new CmdReturn(false, true, false);    }    public String toString(){      return "Find Next";    }  }//=============================================================================  final class SweditReplaceString extends SweditCommand{    public CmdReturn exec(){      replaceString();      return new CmdReturn(false, true, false);    }    public String toString(){      return "Replace";    }  }//=============================================================================  // Match a bracket, brace, or paranthesis  final class SweditMatchBracket extends SweditCommand{    int commandInt;    public CmdReturn exec(){      String open, close;      int startPos;      HashMap brackets = new HashMap();      // Put the close brackets in a set.  Fix the bracket count: ([{      HashSet closBrackets = new HashSet(                               Arrays.asList(new String[] {")", "]", "}"}));      boolean direction = true;        // Store each possible bracket as a key and its match as a value      brackets.put("(", ")");      brackets.put("[", "]");      brackets.put("{", "}");      brackets.put(")", "(");      brackets.put("]", "["); // { this commented bracket fixes the count screwup      brackets.put("}", "{"); // } this commented bracket fixes the count screwup        // If the selection is only one character long, use that character      // as what we're trying to match      if (editor.getSelectionText().length() == 1){        open = editor.getSelectionText();        startPos = editor.getSelectionRange().x;      // Usually, look at the character after the caret.      }else{        open = editor.getTextRange(editor.getCaretOffset(), 1);        startPos = editor.getCaretOffset();      }        // If the character is not a key in the map      if(!brackets.containsKey(open)){        // If we're not at the 0 position        if (editor.getCaretOffset() > 0){          // Get the character before the caret.          open = editor.getTextRange(editor.getCaretOffset() - 1, 1);          startPos = editor.getCaretOffset() - 1;          // If the character is still not a key in the map, give up          if(!brackets.containsKey(open)){            return new CmdReturn(false, true, false);          }        }else{          // Give up          return new CmdReturn(false, true, false);        }      }        // The close is conveniently the value at the open key      close = (String)brackets.get(open);      // If this is a close bracket, the direction is backwards      if (closBrackets.contains(open)){        direction = false;      }        // The class-scoped commandInt is used because the method is called      // multiple times and the data must be tracked.      commandInt = 0;      // direction == true means forward, otherwise backward      if (direction == true){        // Start after the bracket the caret is at, up to the number        // of characters in the doc, one at a time        for(int i=(startPos + 1); i < editor.getCharCount(); i++){          // If the match is found, return          if (compareBracket(i, open, close) == true){            return new CmdReturn(false, true, false);          }        }      }else{        // Start before the bracket the caret is at, down to the        // start of the doc, one at a time backwards        for(int i=(startPos - 1); i >= 0; i--){          // If the match is found, return          if (compareBracket(i, open, close) == true){            return new CmdReturn(false, true, false);          }        }      }      lastColumn = getColumn();      return new CmdReturn(false, true, false);    }    // Check if this is the matching bracket, bearing in mind that there could    // be other open/close pairs inside these brackets    public boolean compareBracket(int pos, String open, String close){      // If the character is the same as where we started      // increment the number of matches we're looking for      if (editor.getTextRange(pos, 1).equals(open)){        commandInt++;      }      // If the character is the match      if (editor.getTextRange(pos, 1).equals(close)){        // If we need more than one match        if (commandInt > 0){          // Decrement the number needed          commandInt--;        // If this is that matching bracket        }else{          // Select the character, scroll it into view and return found (true)          editor.setCaretOffset(pos);          editor.setSelectionRange(pos, 1);          editor.showSelection();          return true;        }      }      // The match was not found      return false;    }    public String toString(){      return "Match Bracket";    }  }//=============================================================================  final class SweditGoToLine extends SweditCommand{    public CmdReturn exec(){      GoToDialog gtd = new GoToDialog();      return new CmdReturn(true, true, false);    }    public String toString(){      return "Go To Line Number";    }  }//=============================================================================  // Switch to the next buffer  final class SweditNextBuffer extends SweditCommand{    public CmdReturn exec(){      Buffer tempBuffer;      // Make sure there is another buff

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -