?? dispatch.java
字號:
package com.xrefactory.jedit;import org.gjt.sp.jedit.*;import java.io.*;import org.gjt.sp.jedit.help.*;import javax.swing.*;import org.gjt.sp.jedit.io.*;import java.awt.*;public class Dispatch { static String currentTag; static int attrLen; static int attrLine; static int attrCol; static int attrOffset; static int attrVal; static int attrLevel; static int attrNumber; static int attrBeep; static int attrSelected; static int attrMType; static int attrBase; static int attrDRefn; static int attrRefn; static int attrIndent; static int attrInterface; static int attrDefinition; static int attrTreeUp; static int attrContinue; static int attrNoFocus; static String attrTreeDeps; static String attrType; static String attrVClass; static String attrSymbol; static String stringVal; static String block; static void clearAttributes() { attrLen = 0; attrLine = 0; attrCol = 0; attrOffset = 0; attrVal = 0; attrLevel = 0; attrNumber = 0; attrBeep = 0; attrSelected = 0; attrMType = 0; attrBase = 0; attrDRefn = 0; attrRefn = 0; attrIndent = 0; attrInterface = 0; attrDefinition = 0; attrTreeUp = 0; attrNoFocus = 0; attrTreeDeps = null; attrType = null; attrVClass = null; } static void browseUrlIfConfirmed(String url, DispatchData data) { // sometimes it throws exception FileNotFoundor or what try { int confirm = JOptionPane.YES_OPTION; if (Opt.askBeforeBrowsingJavadoc()) { confirm = JOptionPane.showConfirmDialog( s.getProbableParent(data.callerComponent), "Browse URL: "+url+"?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); } if (confirm == JOptionPane.YES_OPTION) { s.browseUrl(url, false, s.getParentView(data.callerComponent)); } } catch (Exception e) {} } public static void editorPreCheck(String str) throws XrefException { Buffer buffer = s.getBuffer(); int caret = s.getCaretPosition(); String text = buffer.getText(caret, str.length()); if (! text.equals(str)) { throw new XrefException("expecting string "+str+" at this place, probably not updated references?"); } } public static void editorReplace(String str, String with) throws XrefException { Buffer buffer = s.getBuffer(); int caret = s.getCaretPosition(); String text = buffer.getText(caret, str.length()); if (! text.equals(str)) { throw new XrefException("should replace "+str+" with "+with+", but find "+text+" on this place"); } buffer.remove(caret, str.length()); buffer.insert(caret, with); } static void protocolCheckEq(String s1, String s2) throws Exception { if (! s1.equals(s2)) { throw new XrefException("Internal protocol error, got '"+s1+"' while expecting '"+s2+"'"); } } public static int skipMyXmlIdentifier(XrefCharBuffer ss, int i, int len) { char c; c = ss.buf[i]; while (i<len && (Character.isLetterOrDigit(c) || c=='-')) { i++; c = ss.buf[i]; } return(i); } public static int skipAttribute(XrefCharBuffer ss, int i, int len) { char c; c = ss.buf[i]; if (c=='"') { c = ' '; while (i<len && c!='"' && c!='\n') { i++; c = ss.buf[i]; } if (i<len && c=='"') i++; } else { while (i<len && c!='>' && (! Character.isWhitespace(c))) { i++; c = ss.buf[i]; } } return(i); } public static String unquote(String a) { int len = a.length(); if (len>=2 && a.charAt(0)=='"' && a.charAt(len-1)=='"') { return(a.substring(1,len-1)); } else { return(a); } } public static String getContext(XrefCharBuffer ss, int i, int len) { int j = i+20; String suffix=""; if (j>=len) j=len; else suffix=" ..."; return(ss.substring(i,j)+suffix); } public static int parseXmlTag(XrefCharBuffer ss, int i, int len) throws Exception { int j; char c; String attrib, attrval; i = s.skipBlank(ss, i, len); if (i>=len) throw new XrefException("parsing beyond end of communication string"); if (ss.buf[i]!='<') { throw new XrefException("tag does not start with '<' ("+getContext(ss,i,len)+")"); } i++; j = i; if (ss.buf[i]=='/') { // closing tag i++; } i = skipMyXmlIdentifier(ss, i, len); currentTag = ss.substring(j, i);//&System.err.println("Tag == " + currentTag + "\n"); i = s.skipBlank(ss, i, len); while (ss.buf[i]!='>') { j=i; i=skipMyXmlIdentifier(ss, i, len); attrib = ss.substring(j,i); i = s.skipBlank(ss, i, len); if (ss.buf[i]!='=') throw new XrefException("= expected after attribute " + attrib); i++; j=i; i = skipAttribute(ss, i, len); attrval = ss.substring(j,i); // Integer.parseInt(ss.substring(j,i)); // TODO!!!! do this via some hash table or what // this is pretty inefficient if (false) { } else if (attrib.equals(Protocol.PPCA_VCLASS)) { attrVClass = unquote(attrval); } else if (attrib.equals(Protocol.PPCA_BASE)) { attrBase = Integer.parseInt(attrval); } else if (attrib.equals(Protocol.PPCA_COL)) { attrCol = Integer.parseInt(attrval); } else if (attrib.equals(Protocol.PPCA_DEFINITION)) { attrDefinition = Integer.parseInt(attrval); } else if (attrib.equals(Protocol.PPCA_DEF_REFN)) { attrDRefn = Integer.parseInt(attrval); } else if (attrib.equals(Protocol.PPCA_INDENT)) { attrIndent = Integer.parseInt(attrval); } else if (attrib.equals(Protocol.PPCA_INTERFACE)) { attrInterface = Integer.parseInt(attrval); } else if (attrib.equals(Protocol.PPCA_LEN)) { attrLen = Integer.parseInt(attrval); } else if (attrib.equals(Protocol.PPCA_LINE)) { attrLine = Integer.parseInt(attrval); } else if (attrib.equals(Protocol.PPCA_OFFSET)) { attrOffset = Integer.parseInt(attrval); } else if (attrib.equals(Protocol.PPCA_REFN)) { attrRefn = Integer.parseInt(attrval); } else if (attrib.equals(Protocol.PPCA_SELECTED)) { attrSelected = Integer.parseInt(attrval); } else if (attrib.equals(Protocol.PPCA_TREE_DEPS)) { attrTreeDeps = unquote(attrval); } else if (attrib.equals(Protocol.PPCA_TREE_UP)) { attrTreeUp = Integer.parseInt(attrval); } else if (attrib.equals(Protocol.PPCA_MTYPE)) { attrMType = Integer.parseInt(attrval); } else if (attrib.equals(Protocol.PPCA_TYPE)) { attrType = unquote(attrval); } else if (attrib.equals(Protocol.PPCA_BEEP)) { attrBeep = Integer.parseInt(attrval); } else if (attrib.equals(Protocol.PPCA_VALUE)) { attrVal = Integer.parseInt(attrval); } else if (attrib.equals(Protocol.PPCA_LEVEL)) { attrLevel = Integer.parseInt(attrval); } else if (attrib.equals(Protocol.PPCA_NUMBER)) { attrNumber = Integer.parseInt(attrval); } else if (attrib.equals(Protocol.PPCA_CONTINUE)) { attrContinue = Integer.parseInt(attrval); } else if (attrib.equals(Protocol.PPCA_NO_FOCUS)) { attrNoFocus = Integer.parseInt(attrval); } else if (attrib.equals(Protocol.PPCA_SYMBOL)) { attrSymbol = unquote(attrval); } else if (s.debug) { throw new XrefException("unknown XML attribute '" + attrib + "'"); } i = s.skipBlank(ss, i, len); } i++; return(i); } public static int parseXmlTagHandleMessages(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception { boolean loop = true; while (loop) { clearAttributes(); i = parseXmlTag(ss, i, len); if (false) { } else if (currentTag.equals(Protocol.PPC_ERROR)) { i = dispatchError(ss, i, len, data); } else if (currentTag.equals(Protocol.PPC_FATAL_ERROR)) { i = dispatchFatalError(ss, i, len, data); } else if (currentTag.equals(Protocol.PPC_WARNING)) { i = dispatchWarning(ss, i, len, data); } else if (currentTag.equals(Protocol.PPC_DEBUG_INFORMATION)) { i = dispatchDebugMessage(ss, i, len, data); } else if (currentTag.equals(Protocol.PPC_INFORMATION)) { i = dispatchMessage(ss, i, len, data); } else if (currentTag.equals(Protocol.PPC_BOTTOM_INFORMATION)) { i = dispatchBottomMessage(ss, i, len, data, Protocol.PPC_BOTTOM_INFORMATION); } else if (currentTag.equals(Protocol.PPC_BOTTOM_WARNING)) { i = dispatchBottomMessage(ss, i, len, data, Protocol.PPC_BOTTOM_WARNING); } else if (currentTag.equals(Protocol.PPC_IGNORE)) { i = dispatchIgnore(ss, i, len, data); } else if (currentTag.equals(Protocol.PPC_LICENSE_ERROR)) { i = dispatchLicenseError(ss, i, len, data); } else { loop = false; } if (loop) { i = s.skipBlank(ss, i, len); if (i>=len) loop = false; } } return(i); } public static int dispatchError(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception { String message = ss.substring(i, i+attrLen); i += attrLen; i = parseXmlTagHandleMessages(ss, i, len,data); protocolCheckEq(currentTag, "/"+Protocol.PPC_ERROR); throw new XrefErrorException(message); //&return(i); } public static int dispatchLicenseError(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception { String message = ss.substring(i, i+attrLen); i += attrLen; i = parseXmlTagHandleMessages(ss, i, len,data); protocolCheckEq(currentTag, "/"+Protocol.PPC_LICENSE_ERROR); int answer = JOptionPane.showOptionDialog(s.getProbableParent(data.callerComponent), message, "Xrefactory Warning", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, new String[]{"Browse Url","Continue"}, "Continue" ); if (answer == 0) { s.browseUrl(s.xrefRegistrationUrl, true, s.getParentView(data.callerComponent)); } return(i); } public static int dispatchFatalError(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception { String message = ss.substring(i, i+attrLen); i += attrLen; i = parseXmlTagHandleMessages(ss, i, len,data); protocolCheckEq(currentTag, "/"+Protocol.PPC_FATAL_ERROR); throw new XrefErrorException(message); //&return(i); } public static int dispatchWarning(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception { String message = ss.substring(i, i+attrLen); i += attrLen; i = parseXmlTagHandleMessages(ss, i, len,data); protocolCheckEq(currentTag, "/"+Protocol.PPC_WARNING); JOptionPane.showMessageDialog(s.getProbableParent(data.callerComponent), message, "Xrefactory Warning", JOptionPane.WARNING_MESSAGE); return(i); } public static int dispatchMessage(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception { String message = ss.substring(i, i+attrLen); i += attrLen; i = parseXmlTagHandleMessages(ss, i, len,data); protocolCheckEq(currentTag, "/"+Protocol.PPC_INFORMATION); JOptionPane.showMessageDialog(s.getProbableParent(data.callerComponent), message, "Xrefactory Info", JOptionPane.INFORMATION_MESSAGE); return(i); } public static int dispatchDebugMessage(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception { String message = ss.substring(i, i+attrLen); i += attrLen; i = parseXmlTagHandleMessages(ss, i, len,data); protocolCheckEq(currentTag, "/"+Protocol.PPC_DEBUG_INFORMATION); if (s.debug) { JOptionPane.showMessageDialog(s.getProbableParent(data.callerComponent), message, "Xrefactory Debug Info", JOptionPane.INFORMATION_MESSAGE); } return(i); } public static int dispatchBottomMessage(XrefCharBuffer ss, int i, int len, DispatchData data, String ctag) throws Exception { String message = ss.substring(i, i+attrLen); i += attrLen; if (attrBeep!=0) s.view.getToolkit().beep(); i = parseXmlTagHandleMessages(ss, i, len,data); protocolCheckEq(currentTag, "/"+ctag); //&s.getParentView(data.callerComponent).getStatus().setMessageAndClear(message); SwingUtilities.invokeLater(new s.MessageDisplayer(message,true)); } public static int dispatchAskConfirmation(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception { String message = ss.substring(i, i+attrLen); i += attrLen; i = parseXmlTagHandleMessages(ss, i, len,data); protocolCheckEq(currentTag, "/"+Protocol.PPC_ASK_CONFIRMATION); int confirm = JOptionPane.showConfirmDialog(s.getProbableParent(data.callerComponent), message, "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (confirm != JOptionPane.YES_OPTION) throw new XrefAbortException(); return(i); } public static int dispatchIgnore(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception { String message = ss.substring(i, i+attrLen); i += attrLen; i = parseXmlTagHandleMessages(ss, i, len,data); protocolCheckEq(currentTag, "/"+Protocol.PPC_IGNORE); return(i); } // unused to be deleted
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -