⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guiutilities.java

📁 Linux下面最好用的程序、文本编辑工具之一。
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
			win.addWindowListener(new WindowHandler());		} //}}}		//{{{ ComponentHandler class		class ComponentHandler extends ComponentAdapter		{			//{{{ componentMoved() method			public void componentMoved(ComponentEvent evt)			{				if(System.currentTimeMillis() - start < 1000)				{					Rectangle r = win.getBounds();					if(!windowOpened && r.equals(required))						return;					if(!r.equals(desired))					{						Log.log(Log.DEBUG,GUIUtilities.class,							"Window resize blocked: " + win.getBounds());						win.setBounds(desired);					}				}				win.removeComponentListener(this);			} //}}}			//{{{ componentResized() method			public void componentResized(ComponentEvent evt)			{				if(System.currentTimeMillis() - start < 1000)				{					Rectangle r = win.getBounds();					if(!windowOpened && r.equals(required))						return;					if(!r.equals(desired))					{ 						Log.log(Log.DEBUG,GUIUtilities.class, 							"Window resize blocked: " + win.getBounds());						win.setBounds(desired);					}				}				win.removeComponentListener(this);			} //}}}		} //}}}		//{{{ WindowHandler class		class WindowHandler extends WindowAdapter		{			//{{{ windowOpened() method			public void windowOpened(WindowEvent evt)			{				windowOpened = true;				Rectangle r = win.getBounds(); 				Log.log(Log.DEBUG,GUIUtilities.class,"Window " 					+ name + ": bounds after opening: " + r);				jEdit.setIntegerProperty(name + ".dx",					r.x - required.x);				jEdit.setIntegerProperty(name + ".dy",					r.y - required.y);				jEdit.setIntegerProperty(name + ".d-width",					r.width - required.width);				jEdit.setIntegerProperty(name + ".d-height",					r.height - required.height);				win.removeWindowListener(this);			} //}}}		} //}}}	} //}}}	//{{{ 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)		{			jEdit.setIntegerProperty(name + ".extendedState",				getExtendedState((Frame)win));		}		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);	} //}}}	//{{{ getExtendedState() method	/**	 * On Java 1.4, calls <code>Frame.getExtendedState()</code>.	 * On Java 1.3, returns 0.	 * @since jEdit 4.2pre1	 */	public static int getExtendedState(Frame frame)	{		if(OperatingSystem.hasJava14())		{			try			{				java.lang.reflect.Method meth =					Frame.class.getMethod("getExtendedState",					new Class[0]);				Integer extState = (Integer)meth.invoke(frame,					new Object[0]);				return extState.intValue();			}			catch(Exception e)			{				Log.log(Log.ERROR,GUIUtilities.class,e);			}		}		return 0;	} //}}}	//{{{ setExtendedState() method	/**	 * On Java 1.4, calls <code>Frame.setExtendedState()</code>.	 * On Java 1.3, does nothing.	 * @since jEdit 4.2pre1	 */	public static void setExtendedState(Frame frame, int extState)	{		if(OperatingSystem.hasJava14())		{			try			{				java.lang.reflect.Method meth =					Frame.class.getMethod("setExtendedState",					new Class[] {int.class});				meth.invoke(frame, new Object[] {					new Integer(extState)});			}			catch(Exception e)			{				Log.log(Log.ERROR,GUIUtilities.class,e);			}		}	} //}}}	//{{{ centerOnScreen() method	/**	 * Centers the given window on the screen. This method is needed because	 * JDK 1.3 does not have a <code>JWindow.setLocationRelativeTo()</code>	 * method.	 * @since jEdit 4.2pre3	 */	public static void centerOnScreen(Window win)	{		GraphicsDevice gd = GraphicsEnvironment			.getLocalGraphicsEnvironment()			.getDefaultScreenDevice();		Rectangle gcbounds = gd.getDefaultConfiguration().getBounds();		int x = gcbounds.x + (gcbounds.width - win.getWidth()) / 2;		int y = gcbounds.y + (gcbounds.height - win.getHeight()) / 2;		win.setLocation(x,y);	} //}}}	//}}}	//{{{ 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)			{				SwingUtilities.invokeLater(new Runnable()				{					public void run()					{						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.ALT_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)			{				if(point)					y = (win.getHeight() - size.height - offsetY + extraOffset);				else					y = -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;	} //}}}	//{{{ getComponentParent() method	/**	 * Finds a parent of the specified component.	 * @param comp The component	 * @param clazz Looks for a parent with this class (exact match, not	 * derived).	 * @since jEdit 4.2pre1	 */	public static Component getComponentParent(Component comp, Class clazz)	{		for(;;)		{			if(comp == null)				break;			if(comp instanceof JComponent)			{				Component real = (Component)((JComponent)comp)					.getClientProperty("KORTE_REAL_FRAME");				if(real != null)					comp = real;			}			if(comp.getClass().equals(clazz))				return comp;			else if(comp instanceof JPopupMenu)				comp = ((JPopupMenu)comp).getInvoker();			else if(comp instanceof FloatingWindowContainer)			{				comp = ((FloatingWindowContainer)comp)					.getDockableWindowManager();			}			else				comp = comp.getParent();		}		return null;	} //}}}	//{{{ getView() method	/**	 * Finds the view parent of the specified component.	 * @since jEdit 4.0pre2	 */	public static View getView(Component comp)	{		return (View)getComponentParent(comp,View.class);	} //}}}	//{{{ Package-private members	//{{{ init() method	static void init()	{		// don't do this in static{} since we need jEdit.initMisc()		// run first so we have the jeditresource: protocol		NEW_BUFFER_ICON = loadIcon("new.gif");		DIRTY_BUFFER_ICON = loadIcon("dirty.gif");		READ_ONLY_BUFFER_ICON = loadIcon("readonly.gif");		NORMAL_BUFFER_ICON = loadIcon("normal.gif");		WINDOW_ICON = loadIcon("jedit-icon.gif");	} //}}}	//{{{ 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 static String iconPath = "jeditresource:/org/gjt/sp/jedit/icons/";	private static String defaultIconPath = "jeditresource:/org/gjt/sp/jedit/icons/";	private GUIUtilities() {}	//}}}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -