📄 guiutilities.java
字号:
* from the <code><i>name</i>.message</code> property. * @param comp The component to display the dialog for * @param name The name of the dialog * @param def The text to display by default in the input field */ public static String input(Component comp, String name, Object def) { return input(comp,name,null,def); } //}}} //{{{ inputProperty() method /** * Displays an input dialog box and returns any text the user entered. * The title of the dialog is fetched from * the <code><i>name</i>.title</code> property. The message is fetched * from the <code><i>name</i>.message</code> property. * @param comp The component to display the dialog for * @param name The name of the dialog * @param def The property whose text to display in the input field */ public static String inputProperty(Component comp, String name, String def) { return inputProperty(comp,name,null,def); } //}}} //{{{ input() method /** * Displays an input dialog box and returns any text the user entered. * The title of the dialog is fetched from * the <code><i>name</i>.title</code> property. The message is fetched * from the <code><i>name</i>.message</code> property. * @param comp The component to display the dialog for * @param name The name of the dialog * @param def The text to display by default in the input field * @param args Positional parameters to be substituted into the * message text * @since jEdit 3.1pre3 */ public static String input(Component comp, String name, Object[] args, Object def) { hideSplashScreen(); String retVal = (String)JOptionPane.showInputDialog(comp, jEdit.getProperty(name.concat(".message"),args), jEdit.getProperty(name.concat(".title")), JOptionPane.QUESTION_MESSAGE,null,null,def); return retVal; } //}}} //{{{ inputProperty() method /** * Displays an input dialog box and returns any text the user entered. * The title of the dialog is fetched from * the <code><i>name</i>.title</code> property. The message is fetched * from the <code><i>name</i>.message</code> property. * @param comp The component to display the dialog for * @param name The name of the dialog * @param args Positional parameters to be substituted into the * message text * @param def The property whose text to display in the input field * @since jEdit 3.1pre3 */ public static String inputProperty(Component comp, String name, Object[] args, String def) { hideSplashScreen(); String retVal = (String)JOptionPane.showInputDialog(comp, jEdit.getProperty(name.concat(".message"),args), jEdit.getProperty(name.concat(".title")), JOptionPane.QUESTION_MESSAGE, null,null,jEdit.getProperty(def)); if(retVal != null) jEdit.setProperty(def,retVal); return retVal; } //}}} //{{{ confirm() method /** * Displays a confirm dialog box and returns the button pushed by the * user. The title of the dialog is fetched from the * <code><i>name</i>.title</code> property. The message is fetched * from the <code><i>name</i>.message</code> property. * @param comp The component to display the dialog for * @param name The name of the dialog * @param args Positional parameters to be substituted into the * message text * @param buttons The buttons to display - for example, * JOptionPane.YES_NO_CANCEL_OPTION * @param type The dialog type - for example, * JOptionPane.WARNING_MESSAGE * @since jEdit 3.1pre3 */ public static int confirm(Component comp, String name, Object[] args, int buttons, int type) { hideSplashScreen(); return JOptionPane.showConfirmDialog(comp, jEdit.getProperty(name + ".message",args), jEdit.getProperty(name + ".title"),buttons,type); } //}}} //{{{ showVFSFileDialog() method /** * Displays a VFS file selection dialog box. * @param view The view * @param path The initial directory to display. May be null * @param type The dialog type. One of * {@link org.gjt.sp.jedit.browser.VFSBrowser#OPEN_DIALOG}, * {@link org.gjt.sp.jedit.browser.VFSBrowser#SAVE_DIALOG}, or * {@link org.gjt.sp.jedit.browser.VFSBrowser#CHOOSE_DIRECTORY_DIALOG}. * @param multipleSelection True if multiple selection should be allowed * @return The selected file(s) * @since jEdit 2.6pre2 */ public static String[] showVFSFileDialog(View view, String path, int type, boolean multipleSelection) { hideSplashScreen(); VFSFileChooserDialog fileChooser = new VFSFileChooserDialog( view,path,type,multipleSelection); String[] selectedFiles = fileChooser.getSelectedFiles(); if(selectedFiles == null) return null; return selectedFiles; } //}}} //}}} //{{{ Colors and styles //{{{ parseColor() method /** * Converts a color name to a color object. The name must either be * a known string, such as `red', `green', etc (complete list is in * the <code>java.awt.Color</code> class) or a hex color value * prefixed with `#', for example `#ff0088'. * @param name The color name */ public static Color parseColor(String name) { return parseColor(name, Color.black); } //}}} //{{{ parseColor() method public static Color parseColor(String name, Color defaultColor) { if(name == null) return defaultColor; else if(name.startsWith("#")) { try { return Color.decode(name); } catch(NumberFormatException nf) { return defaultColor; } } else if("red".equals(name)) return Color.red; else if("green".equals(name)) return Color.green; else if("blue".equals(name)) return Color.blue; else if("yellow".equals(name)) return Color.yellow; else if("orange".equals(name)) return Color.orange; else if("white".equals(name)) return Color.white; else if("lightGray".equals(name)) return Color.lightGray; else if("gray".equals(name)) return Color.gray; else if("darkGray".equals(name)) return Color.darkGray; else if("black".equals(name)) return Color.black; else if("cyan".equals(name)) return Color.cyan; else if("magenta".equals(name)) return Color.magenta; else if("pink".equals(name)) return Color.pink; else return defaultColor; } //}}} //{{{ getColorHexString() method /** * Converts a color object to its hex value. The hex value * prefixed is with `#', for example `#ff0088'. * @param c The color object */ public static String getColorHexString(Color c) { String colString = Integer.toHexString(c.getRGB() & 0xffffff); return "#000000".substring(0,7 - colString.length()).concat(colString); } //}}} //{{{ parseStyle() method /** * Converts a style string to a style object. * @param str The style string * @param family Style strings only specify font style, not font family * @param size Style strings only specify font style, not font family * @exception IllegalArgumentException if the style is invalid * @since jEdit 3.2pre6 */ public static SyntaxStyle parseStyle(String str, String family, int size) throws IllegalArgumentException { return parseStyle(str,family,size,true); } //}}} //{{{ parseStyle() method /** * Converts a style string to a style object. * @param str The style string * @param family Style strings only specify font style, not font family * @param size Style strings only specify font style, not font family * @param color If false, the styles will be monochrome * @exception IllegalArgumentException if the style is invalid * @since jEdit 4.0pre4 */ public static SyntaxStyle parseStyle(String str, String family, int size, boolean color) throws IllegalArgumentException { Color fgColor = Color.black; Color bgColor = null; boolean italic = false; boolean bold = false; StringTokenizer st = new StringTokenizer(str); while(st.hasMoreTokens()) { String s = st.nextToken(); if(s.startsWith("color:")) { if(color) fgColor = GUIUtilities.parseColor(s.substring(6), Color.black); } else if(s.startsWith("bgColor:")) { if(color) bgColor = GUIUtilities.parseColor(s.substring(8), null); } else if(s.startsWith("style:")) { for(int i = 6; i < s.length(); i++) { if(s.charAt(i) == 'i') italic = true; else if(s.charAt(i) == 'b') bold = true; else throw new IllegalArgumentException( "Invalid style: " + s); } } else throw new IllegalArgumentException( "Invalid directive: " + s); } return new SyntaxStyle(fgColor,bgColor, new Font(family, (italic ? Font.ITALIC : 0) | (bold ? Font.BOLD : 0), size)); } //}}} //{{{ getStyleString() method /** * Converts a style into it's string representation. * @param style The style */ public static String getStyleString(SyntaxStyle style) { StringBuffer buf = new StringBuffer(); if(style.getForegroundColor() != null) { buf.append("color:" + getColorHexString(style.getForegroundColor())); } if(style.getBackgroundColor() != null) { buf.append(" bgColor:" + getColorHexString(style.getBackgroundColor())); } if(!style.getFont().isPlain()) { buf.append(" style:" + (style.getFont().isItalic() ? "i" : "") + (style.getFont().isBold() ? "b" : "")); } return buf.toString(); } //}}} //{{{ loadStyles() method /** * Loads the syntax styles from the properties, giving them the specified * base font family and size. * @param family The font family * @param size The font size * @since jEdit 3.2pre6 */ public static SyntaxStyle[] loadStyles(String family, int size) { return loadStyles(family,size,true); } //}}} //{{{ loadStyles() method /** * Loads the syntax styles from the properties, giving them the specified * base font family and size. * @param family The font family * @param size The font size * @param color If false, the styles will be monochrome * @since jEdit 4.0pre4 */ public static SyntaxStyle[] loadStyles(String family, int size, boolean color) { SyntaxStyle[] styles = new SyntaxStyle[Token.ID_COUNT]; try { styles[Token.COMMENT1] = GUIUtilities.parseStyle( jEdit.getProperty("view.style.comment1"), family,size,color); styles[Token.COMMENT2] = GUIUtilities.parseStyle( jEdit.getProperty("view.style.comment2"), family, size,color); styles[Token.LITERAL1] = GUIUtilities.parseStyle( jEdit.getProperty("view.style.literal1"), family,size,color); styles[Token.LITERAL2] = GUIUtilities.parseStyle( jEdit.getProperty("view.style.literal2"), family,size,color); styles[Token.LABEL] = GUIUtilities.parseStyle( jEdit.getProperty("view.style.label"), family,size,color); styles[Token.KEYWORD1] = GUIUtilities.parseStyle( jEdit.getProperty("view.style.keyword1"), family,size,color); styles[Token.KEYWORD2] = GUIUtilities.parseStyle( jEdit.getProperty("view.style.keyword2"), family,size,color); styles[Token.KEYWORD3] = GUIUtilities.parseStyle( jEdit.getProperty("view.style.keyword3"), family,size,color); styles[Token.FUNCTION] = GUIUtilities.parseStyle( jEdit.getProperty("view.style.function"), family,size,color); styles[Token.MARKUP] = GUIUtilities.parseStyle( jEdit.getProperty("view.style.markup"), family,size,color); styles[Token.OPERATOR] = GUIUtilities.parseStyle( jEdit.getProperty("view.style.operator"), family,size,color); styles[Token.DIGIT] = GUIUtilities.parseStyle( jEdit.getProperty("view.style.digit"), family,size,color); styles[Token.INVALID] = GUIUtilities.parseStyle( jEdit.getProperty("view.style.invalid"), family,size,color); } catch(Exception e) { Log.log(Log.ERROR,GUIUtilities.class,e); } return styles; } //}}} //}}} //{{{ Loading, saving window geometry //{{{ loadGeometry() method /** * Loads a windows's geometry from the properties. * The geometry is loaded from the <code><i>name</i>.x</code>, * <code><i>name</i>.y</code>, <code><i>name</i>.width</code> and * <code><i>name</i>.height</code> properties. * * @param win The window * @param name The window name */ public static void loadGeometry(Window win, String name) { int x, y, width, height; Dimension size = win.getSize(); Dimension screen = win.getToolkit().getScreenSize(); width = jEdit.getIntegerProperty(name + ".width",size.width); height = jEdit.getIntegerProperty(name + ".height",size.height); Component parent = win.getParent(); if(parent == null) { x = (screen.width - width) / 2; y = (screen.height - height) / 2; } else { Rectangle bounds = parent.getBounds(); x = bounds.x + (bounds.width - width) / 2; y = bounds.y + (bounds.height - height) / 2; } x = jEdit.getIntegerProperty(name + ".x",x); y = jEdit.getIntegerProperty(name + ".y",y); // Make sure the window is displayed in visible region Rectangle osbounds = OperatingSystem.getScreenBounds(); if(x < osbounds.x || x+width > osbounds.width) { if (width > osbounds.width) width = osbounds.width; x = (osbounds.width - width) / 2; } if(y < osbounds.y || y+height > osbounds.height) { if (height >= osbounds.height) height = osbounds.height; y = (osbounds.height - height) / 2; } Rectangle desired = new Rectangle(x,y,width,height);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -