📄 s.java
字号:
package com.xrefactory.jedit;import org.gjt.sp.jedit.*;import org.gjt.sp.jedit.textarea.*;import java.awt.*;import javax.swing.*;import java.util.*;import java.io.*;import org.gjt.sp.jedit.gui.*;import org.gjt.sp.jedit.io.*;import org.gjt.sp.jedit.help.*;import java.net.*;import java.awt.event.*;import javax.swing.border.*;public class s { public static boolean debug = false; public static class Position { View view; String file; int offset; Position(View view, String file, int offset) { this.view=view; this.file=file; this.offset=offset; } } public static class FocusRequester implements Runnable { Component component; public void run() { component.requestFocus(); } FocusRequester(Component component) { this.component = component; } } public static class MessageDisplayer implements Runnable { String message; boolean temporary; public void run() { if (view!=null && view.getStatus()!=null) { if (temporary) { view.getStatus().setMessageAndClear(message); } else { view.getStatus().setMessage(message); } } } MessageDisplayer(String message, boolean temporary) { this.message = message; this.temporary = temporary; } } public static class TagReportDisplayer implements Runnable { String report; Component caller; public void run() { JDialog pp = getParentDialog(caller); if (pp!=null) { new TagReportDialog(report, pp); } else { JFrame ff = getParentFrame(caller); new TagReportDialog(report, ff); } } TagReportDisplayer(String report, Component caller) { this.report = report; this.caller = caller; } } public static final String xrefRegistrationUrl = "http://www.xref-tech.com/license.html"; public static final String xrefTaskDirUrl = "http://www.xref-tech.com/xrefactory/downloads/jedit/"; public static final String dockableClassTreeWindowName = "xrefactory.class-tree-viewer"; public static final String dockableUrlBrowserWindowName = "xrefactory.urlviewer"; public static final String dockableBrowserWindowName = "xrefactory.browser"; public static final String dockableRetrieverWindowName = "xrefactory.retriever"; public static final String tryInstallXrefOption = "xrefactory.try-install-xref.prop"; public static final String configurationFileOption = "xrefactory.configuration-file.prop"; // options public static final String optCompletionFgColor = "xrefactory.completion-fgcolor"; public static final String optCompletionSymbolFgColor = "xrefactory.completion-symbol-fgcolor"; public static final String optCompletionBgColor = "xrefactory.completion-bgcolor"; public static final String optCompletionBgColor2 = "xrefactory.completion-bgcolor2"; public static final String optCompletionFont = "xrefactory.completion-font"; public static final String optCompletionSymbolFont = "xrefactory.completion-symbol-font"; public static final String optCompletionFqtLevel = "xrefactory.completion-fqtlevel"; public static final String optCompletionCaseSensitive = "xrefactory.completion-cases"; public static final String optCompletionDelPendingId = "xrefactory.completion-del-pending-id"; public static final String optCompletionInsParenthesis = "xrefactory.completion-ins-parenthesis"; public static final String optCompletionOldDialog = "xrefactory.completion-old-dialog"; public static final String optBrowserFgColor = "xrefactory.browser-fgcolor"; public static final String optBrowserBgColor = "xrefactory.browser-bgcolor"; public static final String optBrowserSelectionColor = "xrefactory.browser-selcolor"; public static final String optBrowserSymbolColor = "xrefactory.browser-symcolor"; public static final String optBrowserNmSymbolColor = "xrefactory.browser-nmsymcolor"; public static final String optBrowserFont = "xrefactory.browser-font"; public static final String optBrowserToolBarPos = "xrefactory.browser-toolbar-position"; public static final String optBrowserSrcWithRefs = "xrefactory.browser-src-code-in-references"; public static final String optBrowserPickButton = "xrefactory.browser-pick-button"; public static final String optBrowserRetrieveButton = "xrefactory.browser-retrieve-button"; public static final String optRetrieverFgColor = "xrefactory.retriever-fgcolor"; public static final String optRetrieverBgColor = "xrefactory.retriever-bgcolor"; public static final String optRetrieverFont = "xrefactory.retriever-font"; public static final String optRetrieverSearchButton = "xrefactory.retriever-search"; public static final String optRetrieverBackButton = "xrefactory.retriever-back"; public static final String optRetrieverForwardButton = "xrefactory.retriever-forward"; public static final String optRefactoryCommentMovingLevel = "xrefactory.refactoring-comment-move"; public static final String optRefactoryPreferImportOnDemand = "xrefactory.refactoring-imports-on-demand"; // public static final String projectAutoDetectionName = "None (Automatic Project Detection)"; public static final String answerNoAndDoNotAskAnymore ="No and do not display this dialog anymore"; public static final String xrefTmpFilesPrefix = "xrefactory"; public static final String xrefTmpFilesSuffix = ".tmp"; public static final String xrefLogFileSingleName = "xrefactory.log"; public static String tagFilesDirectory = "/"; public static String tagProcessingReportFile = null; public static final int MAX_COMPLETION_HISTORY = 100; public static final int MAX_FILE_SIZE_FOR_READ = 20000000; public static final int MAX_FILE_SIZE_FOR_REPORT = 2000000; public static final int XREF_MAX_TREE_DEEP = 500; public static final int XREF_DOWNLOAD_BUFFER_SIZE = 1024; public static final String XREF_NON_MEMBER_SYMBOL_NAME = "NOT MEMBER SYMBOLS"; // this is the only entry point to jEdit! public static View view; public static String activeProject; // this is the entry point on currently opened browsing dialog public static BrowserTopPanel xbrowser=null; public static HelpViewer xHelpViewer=null; public static ExtractMethodDialog.ExtractMethodPanel xExtractMethod=null; public static String completionIdAfterCaret; public static String completionIdBeforeCaret; public static String targetFile = ""; public static int targetLine = 0; public static boolean panic = false; public static boolean xrefTaskYetChecked = false; public static BrowserTask xbTask = null; public static String xrefTaskUrl; public static String rootDir; public static String slash; public static String classPathSeparator; public static String pluginInstallationPath; public static String tmpDirectoryPath; public static String osName; public static String archName; public static String jdkClassPath; public static String javaHome; public static String homeDir; public static String configurationFile; public static String xrefTaskPath; public static String javaVersion; public static int currentTmpFileCounter = 0; public static int tmpFileStep = 1; public static final int OS_OTHER = 0; public static final int OS_WINDOWS = 1; public static final int OS_OS2 = 2; public static int osCode = OS_OTHER; public static Color light_gray = new Color(0xd0, 0xd0, 0xd0); public static Color completionBgDefaultColor = new Color(255,240,200); public static Color completionBgDefaultColor2 = new Color(235,220,180); public static Color completionSelectionColor = new Color(200,200,255); public static Font defaultFont = new Font("Monospaced", Font.PLAIN, 12); public static Font defaultComplSymFont = new Font("Monospaced", Font.BOLD, 12); public static Font browserDefaultFont = new Font(null, Font.PLAIN, 10); public static Font optionsBrowseButtonFont = new Font(null, Font.PLAIN, 10); // clas tree fonts and colors public static Font ctTopLevelFont = new Font(null, Font.PLAIN, 12); public static Font ctItalicBoldFont = new Font(null, Font.BOLD|Font.ITALIC, 10); public static Font ctItalicFont = new Font(null, Font.ITALIC, 10); public static Font ctBoldFont = new Font(null, Font.BOLD, 10); public static Font ctNormalFont = new Font(null, Font.PLAIN, 10); public static Color ctBgColor = Color.white; public static Color ctFgColor = Color.black; public static Color ctSelectionColor = Color.blue; public static Color ctSymbolColor = Color.red; public static Color ctNmSymbolColor = s.light_gray; public static EmptyBorder emptyBorder = new EmptyBorder(0,0,0,0); // public static void setupCtreeFontsAndColors() { Font res = jEdit.getFontProperty(s.optBrowserFont, ctNormalFont); ctNormalFont = new Font(res.getName(), Font.PLAIN, res.getSize()); ctBoldFont = new Font(res.getName(), Font.BOLD, res.getSize()); ctItalicFont = new Font(res.getName(), Font.ITALIC, res.getSize()); ctItalicBoldFont = new Font(res.getName(), Font.ITALIC | Font.BOLD, res.getSize()); ctTopLevelFont = new Font(res.getName(), Font.BOLD, res.getSize()+2); ctBgColor = jEdit.getColorProperty(s.optBrowserBgColor, ctBgColor); ctFgColor = jEdit.getColorProperty(s.optBrowserFgColor, ctFgColor); ctSelectionColor = jEdit.getColorProperty(s.optBrowserSelectionColor, ctSelectionColor); ctSymbolColor = jEdit.getColorProperty(s.optBrowserSymbolColor, ctSymbolColor); ctNmSymbolColor = jEdit.getColorProperty(s.optBrowserNmSymbolColor, ctNmSymbolColor); } public static void updateBrowserVisage() { View [] vs = jEdit.getViews(); for(int i=0; i<vs.length; i++) { BrowserTopPanel bb = getBrowser(vs[i]); if (bb!=null) { bb.referencesPanel.reflist.setBackground(ctBgColor); bb.referencesPanel.reflist.setForeground(ctFgColor); bb.referencesPanel.reflist.setFont(ctNormalFont); bb.treePanel.xtree.setBackground(ctBgColor); } DockableBrowser db = getDockableBrowser(vs[i]); if (db!=null) { db.repositionToolBar(); } DockableClassTree ct = getClassTreeViewer(vs[i]); if (ct!=null) { ct.repositionToolBar(); ct.tree.setBackground(ctBgColor); } } } // static public File getNewTmpFileName() { File res; assertt(tmpFileStep!=0); do { res = new File(tmpDirectoryPath + xrefTmpFilesPrefix + currentTmpFileCounter + xrefTmpFilesSuffix); currentTmpFileCounter += tmpFileStep; } while (res.exists()); return(res); } static class tmpFileNameFilter implements FileFilter { long offset; public boolean accept(File f) { String name = f.getName(); int len = name.length(); //&System.err.println("checking filername " + name + " == " + f.getAbsolutePath()); if (len>10 && name.substring(0, xrefTmpFilesPrefix.length()).equals(xrefTmpFilesPrefix) && name.substring(len-xrefTmpFilesSuffix.length()).equals(xrefTmpFilesSuffix)) { long testtime = System.currentTimeMillis()-offset; //&System.err.println("checking " + f.lastModified() + " to " + testtime); if (f.lastModified() < testtime) { return(true); } } return(false); } tmpFileNameFilter(long offset) { this.offset = offset; } } static public void cleanOldTmpFiles() { File tmp = new File(tmpDirectoryPath); File[] files = tmp.listFiles(new tmpFileNameFilter(48L*60*60*1000)); if (files.length > 0) { int confirm = JOptionPane.showConfirmDialog(null, "There are some old temporary files generated by Xrefactory, can I delete them?", "Xrefactory temporary files", JOptionPane.YES_NO_OPTION); if (confirm == JOptionPane.YES_OPTION) { files = tmp.listFiles(new tmpFileNameFilter(24L*60*60*1000)); for(int i=0; i<files.length; i++) { //&System.err.println("deleting " + files[i].getAbsolutePath()); files[i].delete(); } } } } public static boolean browserIsDisplayed() { return(view.getDockableWindowManager().isDockableWindowVisible( dockableBrowserWindowName)); //&return(xbrowser!=null && xbrowser.isShowing()); } public static boolean browserIsDisplayed(Component cc) { View v = getParentView(cc); return(v.getDockableWindowManager().isDockableWindowVisible( dockableBrowserWindowName)); //&return(xbrowser!=null && xbrowser.isShowing()); } public static DockableClassTree getClassTreeViewer(View view) { return((DockableClassTree)view.getDockableWindowManager().getDockable(dockableClassTreeWindowName)); } public static DockableBrowser getDockableBrowser(View view) { DockableBrowser db = (DockableBrowser) view.getDockableWindowManager().getDockable(dockableBrowserWindowName); return db; } public static BrowserTopPanel getBrowser(View view) { DockableBrowser db = (DockableBrowser) view.getDockableWindowManager().getDockable(dockableBrowserWindowName); if (db != null) return(db.browser); return xbrowser; } public static void beforePushBrowserFiltersUpdates() { Opt.browserTreeFilter = 2; if (! Opt.referencePushingsKeepBrowserFilter()) { Opt.browserRefListFilter = 0; } } public static void browserNeedsToUpdate(View view) { BrowserTopPanel browser = getBrowser(view); if (browser!=null) browser.needToUpdate(); } public static void showAndUpdateBrowser(View view) { view.getDockableWindowManager().showDockableWindow(dockableBrowserWindowName); browserNeedsToUpdate(view); } // TODO all this stuff should be parametrized by view public static String getFileName() { return(view.getBuffer().getPath()); } public static int getCaretPosition() { return(view.getTextArea().getCaretPosition()); } public static JEditTextArea getTextArea() { return(view.getTextArea()); } public static Buffer getBuffer() { return(view.getBuffer()); } // TODO, you should skip commentaries here! public static String inferDefaultSourcePath() { int i,j, count; char cc; File ff = new File(getBuffer().getPath()).getParentFile(); String path = ff.getAbsolutePath(); String pp = getTextArea().getText(); if (pp.length()>7 && pp.substring(0,7).equals("package")) { i = "package".length(); } else { i = pp.indexOf("\npackage"); if (i== -1) return(path); i += "\npackage".length(); } while (Character.isSpaceChar(pp.charAt(i))) i++; j=i; count=0; while (Character.isLetterOrDigit((cc=pp.charAt(j))) || Character.isSpaceChar(cc) || cc=='.') { if (Character.isLetterOrDigit(cc) || cc=='.') count++; j++; } if (count >= path.length()) return(path); int ressize = path.length()-count; while (ff.getAbsolutePath().length() > ressize) { ff = ff.getParentFile(); } return(ff.getAbsolutePath()); } public static void fileSetExecPermission(String fname) { if (osName.toLowerCase().indexOf("linux") != -1 || osName.toLowerCase().indexOf("sunos") != -1 || osName.toLowerCase().indexOf("mac-os-x") != -1 || osName.toLowerCase().indexOf("unix") != -1) { String[] chmodcmd = {"chmod", "a+x", fname}; try { Runtime.getRuntime().exec(chmodcmd); } catch (Exception e) {} } } public static void downloadXrefTask(String url, String file) { int n, progressi, progressn; if (debug) System.err.println("Downloading "+url+" into "+file); Progress progress = Progress.crNew(null, "Downloading xref task"); FileOutputStream oo = null; InputStream ii = null; try { URLConnection con = new URL(url).openConnection(); ii = con.getInputStream(); File of = new File(file); if (! of.getParentFile().exists()) { of.getParentFile().mkdir(); } oo = new FileOutputStream(of); byte buffer[] = new byte[XREF_DOWNLOAD_BUFFER_SIZE]; progressi = 0; progressn = con.getContentLength(); n = 1; while (n >= 0) { n = ii.read(buffer, 0, XREF_DOWNLOAD_BUFFER_SIZE); if (n > 0) { oo.write(buffer, 0, n);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -