📄 guiutilities.java
字号:
win.setBounds(desired); if((win instanceof Frame) && OperatingSystem.hasJava14()) { int extState = jEdit.getIntegerProperty(name + ".extendedState", Frame.NORMAL); try { java.lang.reflect.Method meth = Frame.class.getMethod("setExtendedState", new Class[] {int.class}); meth.invoke(win, new Object[] { new Integer(extState)}); } catch(Exception e) { Log.log(Log.ERROR,GUIUtilities.class,e); } } } //}}} //{{{ saveGeometry() method /** * Saves a window's geometry to the properties. * The geometry is saved to 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 saveGeometry(Window win, String name) { if((win instanceof Frame) && OperatingSystem.hasJava14()) { try { java.lang.reflect.Method meth = Frame.class.getMethod("getExtendedState", new Class[0]); Integer extState = (Integer)meth.invoke(win, new Object[0]); jEdit.setIntegerProperty(name + ".extendedState", extState.intValue()); if(extState.intValue() != Frame.NORMAL) return; } catch(Exception e) { Log.log(Log.ERROR,GUIUtilities.class,e); } } Rectangle bounds = win.getBounds(); jEdit.setIntegerProperty(name + ".x",bounds.x); jEdit.setIntegerProperty(name + ".y",bounds.y); jEdit.setIntegerProperty(name + ".width",bounds.width); jEdit.setIntegerProperty(name + ".height",bounds.height); } //}}} //}}} //{{{ hideSplashScreen() method /** * Ensures that the splash screen is not visible. This should be * called before displaying any dialog boxes or windows at * startup. */ public static void hideSplashScreen() { if(splash != null) { splash.dispose(); splash = null; } } //}}} //{{{ createMultilineLabel() method /** * Creates a component that displays a multiple line message. This * is implemented by assembling a number of <code>JLabels</code> in * a <code>JPanel</code>. * @param str The string, with lines delimited by newline * (<code>\n</code>) characters. * @since jEdit 4.1pre3 */ public static JComponent createMultilineLabel(String str) { JPanel panel = new JPanel(new VariableGridLayout( VariableGridLayout.FIXED_NUM_COLUMNS,1,1,1)); int lastOffset = 0; for(;;) { int index = str.indexOf('\n',lastOffset); if(index == -1) break; else { panel.add(new JLabel(str.substring(lastOffset,index))); lastOffset = index + 1; } } if(lastOffset != str.length()) panel.add(new JLabel(str.substring(lastOffset))); return panel; } //}}} //{{{ requestFocus() method /** * Focuses on the specified component as soon as the window becomes * active. * @param win The window * @param comp The component */ public static void requestFocus(final Window win, final Component comp) { win.addWindowListener(new WindowAdapter() { public void windowActivated(WindowEvent evt) { comp.requestFocus(); win.removeWindowListener(this); } }); } //}}} //{{{ isPopupTrigger() method /** * Returns if the specified event is the popup trigger event. * This implements precisely defined behavior, as opposed to * MouseEvent.isPopupTrigger(). * @param evt The event * @since jEdit 3.2pre8 */ public static boolean isPopupTrigger(MouseEvent evt) { return isRightButton(evt.getModifiers()); } //}}} //{{{ isMiddleButton() method /** * @param modifiers The modifiers flag from a mouse event * @since jEdit 4.1pre9 */ public static boolean isMiddleButton(int modifiers) { if (OperatingSystem.isMacOS()) { if((modifiers & MouseEvent.BUTTON1_MASK) != 0) return ((modifiers & MouseEvent.META_MASK) != 0); if(!OperatingSystem.hasJava14()) return ((modifiers & MouseEvent.BUTTON3_MASK) != 0); else return ((modifiers & MouseEvent.BUTTON2_MASK) != 0); } else return ((modifiers & MouseEvent.BUTTON2_MASK) != 0); } //}}} //{{{ isRightButton() method /** * @param modifiers The modifiers flag from a mouse event * @since jEdit 4.1pre9 */ public static boolean isRightButton(int modifiers) { if (OperatingSystem.isMacOS()) { if((modifiers & MouseEvent.BUTTON1_MASK) != 0) return ((modifiers & MouseEvent.CTRL_MASK) != 0); if(!OperatingSystem.hasJava14()) return ((modifiers & MouseEvent.BUTTON2_MASK) != 0); else return ((modifiers & MouseEvent.BUTTON3_MASK) != 0); } else return ((modifiers & MouseEvent.BUTTON3_MASK) != 0); } //}}} //{{{ showPopupMenu() method /** * Shows the specified popup menu, ensuring it is displayed within * the bounds of the screen. * @param popup The popup menu * @param comp The component to show it for * @param x The x co-ordinate * @param y The y co-ordinate * @since jEdit 4.0pre1 */ public static void showPopupMenu(JPopupMenu popup, Component comp, int x, int y) { showPopupMenu(popup,comp,x,y,true); } //}}} //{{{ showPopupMenu() method /** * Shows the specified popup menu, ensuring it is displayed within * the bounds of the screen. * @param popup The popup menu * @param comp The component to show it for * @param x The x co-ordinate * @param y The y co-ordinate * @param point If true, then the popup originates from a single point; * otherwise it will originate from the component itself. This affects * positioning in the case where the popup does not fit onscreen. * * @since jEdit 4.1pre1 */ public static void showPopupMenu(JPopupMenu popup, Component comp, int x, int y, boolean point) { int offsetX = 0; int offsetY = 0; int extraOffset = (point ? 1 : 0); Component win = comp; while(!(win instanceof Window || win == null)) { offsetX += win.getX(); offsetY += win.getY(); win = win.getParent(); } if(win != null) { Dimension size = popup.getPreferredSize(); Rectangle screenSize = win.getGraphicsConfiguration() .getBounds(); if(x + offsetX + size.width + win.getX() > screenSize.width && x + offsetX + win.getX() >= size.width) { //System.err.println("x overflow"); if(point) x -= (size.width + extraOffset); else x = (win.getWidth() - size.width - offsetX + extraOffset); } else { x += extraOffset; } //System.err.println("y=" + y + ",offsetY=" + offsetY // + ",size.height=" + size.height // + ",win.height=" + win.getHeight()); if(y + offsetY + size.height + win.getY() > screenSize.height && y + offsetY + win.getY() >= size.height) { //System.err.println("y overflow"); if(point) y = (win.getHeight() - size.height - offsetY + extraOffset); else y = comp.getY() - size.height - 1; } else { y += extraOffset; } popup.show(comp,x,y); } else popup.show(comp,x + extraOffset,y + extraOffset); } //}}} //{{{ isAncestorOf() method /** * Returns if the first component is an ancestor of the * second by traversing up the component hierarchy. * * @param comp1 The ancestor * @param comp2 The component to check * @since jEdit 4.1pre5 */ public static boolean isAncestorOf(Component comp1, Component comp2) { while(comp2 != null) { if(comp1 == comp2) return true; else comp2 = comp2.getParent(); } return false; } //}}} //{{{ getParentDialog() method /** * Traverses the given component's parent tree looking for an * instance of JDialog, and return it. If not found, return null. * @param c The component */ public static JDialog getParentDialog(Component c) { Component p = c.getParent(); while (p != null && !(p instanceof JDialog)) p = p.getParent(); return (p instanceof JDialog) ? (JDialog) p : null; } //}}} //{{{ getView() method /** * Finds the view parent of the specified component. * @since jEdit 4.0pre2 */ public static View getView(Component comp) { for(;;) { if(comp instanceof JComponent) { Component real = (Component)((JComponent)comp) .getClientProperty("KORTE_REAL_FRAME"); if(real != null) comp = real; } if(comp instanceof View) return (View)comp; else if(comp instanceof JPopupMenu) comp = ((JPopupMenu)comp).getInvoker(); else if(comp != null) comp = comp.getParent(); else break; } return null; } //}}} //{{{ Package-private members //{{{ showSplashScreen() method static void showSplashScreen() { splash = new SplashScreen(); } //}}} //{{{ advanceSplashProgress() method static void advanceSplashProgress() { if(splash != null) splash.advance(); } //}}} //}}} //{{{ Private members private static SplashScreen splash; private static Hashtable icons; private GUIUtilities() {} //{{{ loadPluginsMenu() method private static void loadPluginsMenu(JMenuBar mbar) { // Query plugins for menu items Vector pluginMenuItems = new Vector(); EditPlugin[] pluginArray = jEdit.getPlugins(); for(int i = 0; i < pluginArray.length; i++) { try { EditPlugin plugin = pluginArray[i]; plugin.createMenuItems(pluginMenuItems); } catch(Throwable t) { Log.log(Log.ERROR,GUIUtilities.class, "Error creating menu items" + " for plugin"); Log.log(Log.ERROR,GUIUtilities.class,t); } } JMenu menu = new EnhancedMenu("plugins"); ((EnhancedMenu)menu).init(); if(pluginMenuItems.isEmpty()) { menu.add(GUIUtilities.loadMenuItem("no-plugins")); mbar.add(menu); return; } int maxItems = jEdit.getIntegerProperty("menu.spillover",20); // Sort them MiscUtilities.quicksort(pluginMenuItems, new MiscUtilities.MenuItemCompare()); if(pluginMenuItems.size() < maxItems) { for(int i = 0; i < pluginMenuItems.size(); i++) { menu.add((JMenuItem)pluginMenuItems.get(i)); } mbar.add(menu); } else { int menuCount = 1; menu.setText(menu.getText() + " " + menuCount); for(int i = 0; i < pluginMenuItems.size(); i++) { menu.add((JMenuItem)pluginMenuItems.get(i)); if(menu.getMenuComponentCount() == maxItems) { mbar.add(menu); menu = new JMenu(String.valueOf( ++menuCount)); } } if(menu.getMenuComponentCount() != 0) mbar.add(menu); } } //}}} //}}}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -