?? javatextpane.java
字號:
* @param adjustment amount (either positive or negative) to adjust this position. * @return the DocPosition, adjusted properly. */ public DocPosition adjustPosition(int adjustment) { position += adjustment; return this; } /** * Two DocPositions are equal iff they have the same internal position. * * @return if this DocPosition represents the same position as another. */ public boolean equals(Object obj) { if(obj instanceof DocPosition) { DocPosition d = (DocPosition)(obj); if(this.position == d.position) { return true; } else { return false; } } else { return false; } } /** * A string representation useful for debugging. * * @return A string representing the position. */ public String toString() { return "" + position; } } /** * A comparator appropriate for use with Collections of * DocPositions. */ class DocPositionComparator implements Comparator { /** * Does this Comparator equal another? * Since all DocPositionComparators are the same, they * are all equal. * * @return true for DocPositionComparators, false otherwise. */ public boolean equals(Object obj) { if(obj instanceof DocPositionComparator) { return true; } else { return false; } } /** * Compare two DocPositions * * @param o1 first DocPosition * @param o2 second DocPosition * @return negative if first < second, 0 if equal, positive if first > second */ public int compare(Object o1, Object o2) { if(o1 instanceof DocPosition && o2 instanceof DocPosition) { DocPosition d1 = (DocPosition)(o1); DocPosition d2 = (DocPosition)(o2); return (d1.getPosition() - d2.getPosition()); } else if(o1 instanceof DocPosition) { return -1; } else if(o2 instanceof DocPosition) { return 1; } else if(o1.hashCode() < o2.hashCode()) { return -1; } else if(o2.hashCode() > o1.hashCode()) { return 1; } else { return 0; } } } /** * A reader interface for an abstract document. Since * the syntax highlighting packages only accept Stings and * Readers, this must be used. * Since the close() method does nothing and a seek() method * has been added, this allows us to get some performance * improvements through reuse. It can be used even after the * lexer explicitly closes it by seeking to the place that * we want to read next, and reseting the lexer. */ class DocumentReader extends Reader { /** * Modifying the document while the reader is working is like * pulling the rug out from under the reader. Alerting the * reader with this method (in a nice thread safe way, this * should not be called at the same time as a read) allows * the reader to compensate. */ public void update(int position, int adjustment) { if(position < this.position) { if(this.position < position - adjustment) { this.position = position; } else { this.position += adjustment; } } } /** * Current position in the document. Incremented * whenever a character is read. */ private long position = 0; /** Saved position used in the mark and reset methods. */ private long mark = -1; /** The document that we are working with. */ private AbstractDocument document; /** * Construct a reader on the given document. * * @param document the document to be read. */ public DocumentReader(AbstractDocument document) { this.document = document; } /** * Has no effect. This reader can be used even after * it has been closed. */ public void close() { } /** * Save a position for reset. * * @param readAheadLimit ignored. */ public void mark(int readAheadLimit) { mark = position; } /** * This reader support mark and reset. * * @return true */ public boolean markSupported() { return true; } /** * Read a single character. * * @return the character or -1 if the end of the document has been reached. */ public int read() { if(position < document.getLength()) { try { char c = document.getText((int)position, 1).charAt(0); position++; return c; } catch(BadLocationException x) { return -1; } } else { return -1; } } /** * Read and fill the buffer. * This method will always fill the buffer unless the end of the document is reached. * * @param cbuf the buffer to fill. * @return the number of characters read or -1 if no more characters are available in the document. */ public int read(char[] cbuf) { return read(cbuf, 0, cbuf.length); } /** * Read and fill the buffer. * This method will always fill the buffer unless the end of the document is reached. * * @param cbuf the buffer to fill. * @param off offset into the buffer to begin the fill. * @param len maximum number of characters to put in the buffer. * @return the number of characters read or -1 if no more characters are available in the document. */ public int read(char[] cbuf, int off, int len) { if(position < document.getLength()) { int length = len; if(position + length >= document.getLength()) { length = document.getLength() - (int)position; } if(off + length >= cbuf.length) { length = cbuf.length - off; } try { String s = document.getText((int)position, length); position += length; for(int i = 0; i < length; i++) { cbuf[off + i] = s.charAt(i); } return length; } catch(BadLocationException x) { return -1; } } else { return -1; } } /** * @return true */ public boolean ready() { return true; } /** * Reset this reader to the last mark, or the beginning of the document if a mark has not been set. */ public void reset() { if(mark == -1) { position = 0; } else { position = mark; } mark = -1; } /** * Skip characters of input. * This method will always skip the maximum number of characters unless * the end of the file is reached. * * @param n number of characters to skip. * @return the actual number of characters skipped. */ public long skip(long n) { if(position + n <= document.getLength()) { position += n; return n; } else { long oldPos = position; position = document.getLength(); return (document.getLength() - oldPos); } } /** * Seek to the given position in the document. * * @param n the offset to which to seek. */ public void seek(long n) { if(n <= document.getLength()) { position = n; } else { position = document.getLength(); } } } private static void initStyles() { Style style; style = styleContext.addStyle("body", null); StyleConstants.setFontFamily(style, "Monospaced"); StyleConstants.setFontSize(style, 12); StyleConstants.setBackground(style, Color.white); StyleConstants.setForeground(style, Color.black); StyleConstants.setBold(style, false); StyleConstants.setItalic(style, false); style = styleContext.addStyle("tag", null); StyleConstants.setFontFamily(style, "Monospaced"); StyleConstants.setFontSize(style, 12); StyleConstants.setBackground(style, Color.white); StyleConstants.setForeground(style, Color.blue); StyleConstants.setBold(style, true); StyleConstants.setItalic(style, false); style = styleContext.addStyle("endtag", null); StyleConstants.setFontFamily(style, "Monospaced"); StyleConstants.setFontSize(style, 12); StyleConstants.setBackground(style, Color.white); StyleConstants.setForeground(style, Color.blue); StyleConstants.setBold(style, false); StyleConstants.setItalic(style, false); style = styleContext.addStyle("reference", null); StyleConstants.setFontFamily(style, "Monospaced"); StyleConstants.setFontSize(style, 12); StyleConstants.setBackground(style, Color.white); StyleConstants.setForeground(style, Color.black); StyleConstants.setBold(style, false); StyleConstants.setItalic(style, false); style = styleContext.addStyle("name", null); StyleConstants.setFontFamily(style, "Monospaced"); StyleConstants.setFontSize(style, 12); StyleConstants.setBackground(style, Color.white); StyleConstants.setForeground(style, new Color(0xB03060)/*Color.maroon*/); StyleConstants.setBold(style, true); StyleConstants.setItalic(style, false); style = styleContext.addStyle("value", null); StyleConstants.setFontFamily(style, "Monospaced"); StyleConstants.setFontSize(style, 12); StyleConstants.setBackground(style, Color.white); StyleConstants.setForeground(style, new Color(0xB03060)/*Color.maroon*/); StyleConstants.setBold(style, false); StyleConstants.setItalic(style, true); style = styleContext.addStyle("tag", null); StyleConstants.setFontFamily(style, "Monospaced"); StyleConstants.setFontSize(style, 12); StyleConstants.setBackground(style, Color.white); StyleConstants.setForeground(style, Color.black); StyleConstants.setBold(style, true); StyleConstants.setItalic(style, false); style = styleContext.addStyle("reservedWord", null); StyleConstants.setFontFamily(style, "Monospaced"); StyleConstants.setFontSize(style, 12); StyleConstants.setBackground(style, Color.white); StyleConstants.setForeground(style, Color.blue); StyleConstants.setBold(style, false); StyleConstants.setItalic(style, false); style = styleContext.addStyle("identifier", null); StyleConstants.setFontFamily(style, "Monospaced"); StyleConstants.setFontSize(style, 12); StyleConstants.setBackground(style, Color.white); StyleConstants.setForeground(style, Color.black); StyleConstants.setBold(style, false); StyleConstants.setItalic(style, false); style = styleContext.addStyle("literal", null); StyleConstants.setFontFamily(style, "Monospaced"); StyleConstants.setFontSize(style, 12); StyleConstants.setBackground(style, Color.white); StyleConstants.setForeground(style, new Color(0xB03060)/*Color.maroon*/); StyleConstants.setBold(style, false); StyleConstants.setItalic(style, false); style = styleContext.addStyle("separator", null); StyleConstants.setFontFamily(style, "Monospaced"); StyleConstants.setFontSize(style, 12); StyleConstants.setBackground(style, Color.white); StyleConstants.setForeground(style, new Color(0x000080)/*Color.navy*/); StyleConstants.setBold(style, false); StyleConstants.setItalic(style, false); style = styleContext.addStyle("operator", null); StyleConstants.setFontFamily(style, "Monospaced"); StyleConstants.setFontSize(style, 12); StyleConstants.setBackground(style, Color.white); StyleConstants.setForeground(style, Color.black); StyleConstants.setBold(style, true); StyleConstants.setItalic(style, false); style = styleContext.addStyle("comment", null); StyleConstants.setFontFamily(style, "Monospaced"); StyleConstants.setFontSize(style, 12); StyleConstants.setBackground(style, Color.white); StyleConstants.setForeground(style, Color.green.darker()); StyleConstants.setBold(style, false); StyleConstants.setItalic(style, false); style = styleContext.addStyle("preprocessor", null); StyleConstants.setFontFamily(style, "Monospaced"); StyleConstants.setFontSize(style, 12); StyleConstants.setBackground(style, Color.white); StyleConstants.setForeground(style, new Color(0xA020F0).darker()/*Color.purple*/); StyleConstants.setBold(style, false); StyleConstants.setItalic(style, false); style = styleContext.addStyle("whitespace", null); StyleConstants.setFontFamily(style, "Monospaced"); StyleConstants.setFontSize(style, 12); StyleConstants.setBackground(style, Color.white); StyleConstants.setForeground(style, Color.black); StyleConstants.setBold(style, false); StyleConstants.setItalic(style, false); style = styleContext.addStyle("error", null); StyleConstants.setFontFamily(style, "Monospaced"); StyleConstants.setFontSize(style, 12); StyleConstants.setBackground(style, Color.white); StyleConstants.setForeground(style, Color.red); StyleConstants.setBold(style, false); StyleConstants.setItalic(style, false); style = styleContext.addStyle("unknown", null); StyleConstants.setFontFamily(style, "Monospaced"); StyleConstants.setFontSize(style, 12); StyleConstants.setBackground(style, Color.white); StyleConstants.setForeground(style, Color.orange); StyleConstants.setBold(style, false); StyleConstants.setItalic(style, false); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -