📄 swedit.java
字号:
end = text.length(); break; } }while (text.charAt(end - 2) == '\\'); style.foreground = colors.quote; style.start = start + styleEvent.lineOffset; style.length = end - start; } // Whitespace (i.e. spaces and tabs) is the easiest. }else if (Character.isWhitespace(currChar)){ end = start; // Set a zero width for now // Loop until there is a non-whitespace charcter while (Character.isWhitespace(text.charAt(end))){ end++; // Increment the end // Stop if the end of the line is reached. if (end >= text.length()){ end = text.length(); break; } } // It may seem silly to have a style for whitespace that is normal. // However, it is necessary because of block selection, which is // handled later in the function. style.foreground = colors.normal; style.start = start + styleEvent.lineOffset; style.length = end - start; // Slash }else if (currChar == '/'){ boolean alone = false; // Don't go past the end of the text if ((start + 1) < text.length()){ // If this slash is followed by a 2nd, it is a C++ style comment if (text.charAt(start + 1) == '/'){ end = text.length(); style.foreground = colors.comment; style.start = start + styleEvent.lineOffset; style.length = end - start; // If this slash is followed by a *, it is a C style comment // %%% Only the first line is dealth with, the rest will be // %%% incorrectly highlighted with standard rules. }else if (text.charAt(start + 1) == '*'){ end = -1; if ((start + 2) < text.length()){ end = text.indexOf("*/", start + 2) + 2; } if (end < 2){ end = text.length(); } style.foreground = colors.comment; style.start = start + styleEvent.lineOffset; style.length = end - start; // The slash is alone, check it later }else{ alone = true; } }else{ // The slash is the last character on the line, check it later alone = true; } // If this slash is alone or the last character on the line, check to // see if it's an operator if (alone){ end = start + 1; if (Syntax.operators[syndex].contains("/")){ style.foreground = colors.operator; style.start = start + styleEvent.lineOffset; style.length = 1; } } // Letters, digits, and the pound sign }else if (Character.isLetterOrDigit(currChar) || (currChar == '#')){ // Loop through looking for the end of the word for (i=start+1; i < text.length(); i++){ // The end is when it's no longer a letter or digit or underscore if (!Character.isLetterOrDigit(text.charAt(i)) && (text.charAt(i) != '_')){ break; } } end = i; style = new StyleRange(); style.start = start + styleEvent.lineOffset; style.length = end - start; // Get the actual word word = text.substring(start, end); // See if it's a keyword if (Syntax.keywords[syndex].contains(word)){ style.foreground = colors.keyword; // or a variable type (which most languages consider keywords, but // SWediT highlights them differently) }else if (Syntax.varTypes[syndex].contains(word)){ style.foreground = colors.varType; // or just normal }else{ style.foreground = colors.normal; } // All remaining possible characters. At this point, the only things // left are operators and brackets []{}() }else{ end = start + 1; style = new StyleRange(); style.start = start + styleEvent.lineOffset; style.length = end - start; word = text.substring(start, end); // See if it's an operator if (Syntax.operators[syndex].contains(word)){ style.foreground = colors.operator; // or a bracket }else if (Syntax.brackets[syndex].contains(word)){ style.foreground = colors.bracket; // or just normal }else{ style.foreground = colors.normal; } } // Move the index forward to find the next word (watch out for invalid data) start = end; if (start < 0){ break; } // Handle block selection highlighting. There are basically five possibilities. // (1) the style range does not include the block selection at all. if ((startBlockCol >= (style.start + style.length)) || (style.start >= endBlockCol)){ ranges.add(style); }else{ if (startBlockCol <= style.start){ if (endBlockCol >= (style.start + style.length)){ // (2) block selection starts before the style range, and ends after it style.background = colors.block; style.foreground = colors.normal; ranges.add(style); }else{ // (3) block selection starts before the style range, but ends before // the style range ends, cutting the style into 2 pieces // Remember the original style info Color oldColor = style.foreground; int oldLength = style.length; // Set the StyleRange up for the block selection portion style.length = endBlockCol - style.start; int newLength = style.length; style.background = colors.block; style.foreground = colors.normal; ranges.add(style); // Set up a new style for the original style portion style = new StyleRange(); style.foreground = oldColor; style.start = endBlockCol; style.length = oldLength - newLength; ranges.add(style); } }else{ if (endBlockCol >= (style.start + style.length)){ // (4) block selection starts after the style starts and ends after // it ends, cutting the style into 2 pieces. // Remember the original style info int oldLength = style.length; Color oldColor = style.foreground; // Set the StyleRange up for the original style portion style.length = startBlockCol - style.start; int newLength = style.length; ranges.add(style); // Set up a new style for the block selection portion style = new StyleRange(); style.background = colors.block; style.foreground = colors.normal; style.start = startBlockCol; style.length = oldLength - newLength; ranges.add(style); }else{ // (5) block selection starts after the style starts and ends before // it ends, cutting the style into 3 pieces. // Remember the original style info int oldLength = style.length; Color oldColor = style.foreground; // Set the StyleRange up for the 1st original style portion style.length = startBlockCol - style.start; int newLength = style.length; ranges.add(style); // Set up a new style for the block selection portion style = new StyleRange(); style.background = colors.block; style.foreground = colors.normal; style.start = startBlockCol; style.length = blockWidth; // Set up a new style for the 2nd original style portion ranges.add(style); newLength += blockWidth; style = new StyleRange(); style.foreground = oldColor; style.start = endBlockCol; style.length = oldLength - newLength; ranges.add(style); } } } } // If there are any style ranges defined, send them on with the event // after converting the ArrayList to an Array. if (ranges.size() > 0){ styleEvent.styles = (StyleRange[])ranges.toArray(new StyleRange[0]); } } // end of lineGetStyle//=============================================================================// Very simple line highlighting method, thanks to SWT's built in// LineBackgroundListener / Event.public void lineGetBackground(LineBackgroundEvent event){ if (editor.getLineAtOffset(event.lineOffset) == getLine()){ // If the cursor is on this line, set this line's background color to the // line highlighting color. event.lineBackground = colors.line; }else{ // Otherwise do nothing at all. event.lineBackground = null; }}//============================================================================= // The verifyKey catches ALL key strokes interprets them. public void verifyKey(VerifyEvent event){ // %%% Debug info for every key press/* System.out.println("KeyEvent Char: " + event.character + "(" + (int)event.character + ")" + " Code: " + event.keyCode + " Mods: " + event.stateMask + " Pos: " + editor.getCaretOffset() + " Char Count: " + editor.getCharCount());*/ // Under no circumstances should any keystrokes be sent on to the // editor in raw form event.doit=false; // Put the three pieces of data about the keystroke into a SweditKey // object. This forms a key for the Map that links key presses to // command objects. Retreive the command and store it; not a hundred // percent necessary; we could call runCommand with this as a parameter. // Seperating it just makes it a little easier to follow and debug. SweditKey keystroke = new SweditKey(event.character, event.keyCode, event.stateMask); SweditCommand command = (SweditCommand)keys.get(keystroke); runCommand(command); } // End of verifyKey//============================================================================= public void runCommand(SweditCommand command){ // No point in running a command that doesn't exist if (command == null){ return; } // Some of the commands can cause Exceptions, usually an ArrayOutOfBounds. // Hopefully, the code catches these conditions before an exception gets // thrown, but they are caught in case the code misses one. CmdReturn result; int lastLine = getLine(); try{ // Execute the command result = command.exec(); }catch(Exception e){ exceptionMessage("Exception on command \"" + command + "\" :\n" + e + "\nPos: " + editor.getCaretOffset() + "\nChar Count: " + editor.getCharCount() + "\nColumn: " + getColumn() + "\nlastColumn: " + lastColumn + "\nblockHeight: " + blockHeight + "\nblockWidth: " + blockWidth); return; } // Return if the quit flag is true; that would mean these widgets have // all been diposed and any operations on them will cause exceptions if (result.quitFlag){ return; } try{ // If the selection is to be cleared if (result.clearSelection == true){ // Set the selection length to zero (don't move the caret) editor.setSelectionRange(editor.getCaretOffset(), 0); // showSelection method moves selection (in this case just the caret) // into view by moving the scroll bars. Note that this might not put // the scolls bar exactly where you want them. editor.showSelection(); } // Display the current line number on the menu bar int line = getLine(); linePos.setText("Line: " + (line + 1) + " / " + editor.getLineCount()); // Display the column number on the menu bar colPos.setText("Column: " + String.valueOf(getColumn())); // If the block selection is to be cleared if (result.clearBlock == true){ blockStart = 0; blockWidth = 0; // If there is in fact a block already, the screen must be redrawn if (blockHeight > 0){ blockHeight = 0; editor.redraw(); } } if (line != lastLine){ editor.redrawRange(editor.getOffsetAtLine(line), endColumn(line) - editor.getOffsetAtLine(line), true); if (lastLine < editor.getLineCount()){ editor.redrawRange(editor.getOffsetAtLine(lastLine), endColumn(lastLine) - editor.getOffsetAtLine(lastLine), true); } } // Almost done; just catch any exceptions that might have been thrown. In // theory, the code should prevent exceptions from being thrown in the // first place, but it pays to be carefull. }catch(Exception e){ exceptionMessage("Exception after command \"" + command + "\" :\n" + e + "\nPos: " + editor.getCaretOffset() + "\nChar Count: " + editor.getCharCount() + "\nColumn: " + getColumn() + "\nlastColumn: " + lastColumn + "\nblockHeight: " + blockHeight + "\nblockWidth: " + blockWidth); } } // End of runCommand//============================================================================= // Load properties from a file public void loadProperties(String propertiesFilename){ props = new Properties(); try{ // use the File class constructor to get the proper file name, after // making sure it's not something stupid like null or no text. if ((propertiesFilename != null) && !propertiesFilename.equals("")){ File file = new File (propertiesFilename); // Make sure the file exists, then create a stream and use the // properties object's built in load function. if (file.exists()){ FileInputStream fis = new FileInputStream (file); props.load(fis); fis.close (); // Theses properties are stored in global variables because they are // used several times. There may be other properties that are only // accessed once, in which case they are paresed where they are used. configLoaded = Boolean.valueOf(props.getProperty("Config_Loaded", "false")).booleanValue(); askAboutTabs = Boolean.valueOf(props.getProperty("Ask_About_Tabs", "true")).booleanValue(); expandTabs = Boolean.valueOf(props.getProperty("Expand_Tabs", "true")).booleanValue(); debugMode = Boolean.valueOf(props.getProperty("Debug_Mode", "false")).booleanValue(); dosFormatDefault = Boolean.valueOf(props.getProperty("DOS_Format", "false")).booleanValue(); dosFormat = dosFormatDefault; } } }catch(Exception e){ exceptionMessage("Exception loading Properties File \"" +
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -