gtkiconfactory.java
来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 429 行 · 第 1/2 页
JAVA
429 行
if (radioButtonMenuItemArrowIcon == null) { radioButtonMenuItemArrowIcon = new DelegatingIcon( "paintRadioButtonMenuItemArrowIcon", 13, 13); } return radioButtonMenuItemArrowIcon; } public static void paintRadioButtonMenuItemArrowIcon(SynthContext context, Graphics g, int x, int y, int w, int h) { // Don't paint anything. We are just reserving space so we align the // menu items correctly. } public static SynthIcon getRadioButtonMenuItemCheckIcon() { if (radioButtonMenuItemCheckIcon == null) { radioButtonMenuItemCheckIcon = new DelegatingIcon( "paintRadioButtonMenuItemCheckIcon", 13, 13); } return radioButtonMenuItemCheckIcon; } public static void paintRadioButtonMenuItemCheckIcon( SynthContext context, Graphics g, int x, int y, int w, int h) { GTKStyle style = (GTKStyle)context.getStyle(); int state = context.getComponentState(); int gtkState = GTKLookAndFeel.synthStateToGTKState( context.getRegion(), state); if ((state & SynthConstants.MOUSE_OVER) != 0) { gtkState = SynthConstants.MOUSE_OVER; } int shadowType = GTKConstants.SHADOW_OUT; if ((state & SynthConstants.SELECTED) != 0) { shadowType = GTKConstants.SHADOW_IN; } ((GTKStyle)context.getStyle()).getEngine( context).paintOption(context, g, gtkState, shadowType, "option", x, y, w, h); } // // ToolBar Handle // public static SynthIcon getToolBarHandleIcon() { return new ToolBarHandleIcon(); } public static void paintToolBarHandleIcon(SynthContext context, Graphics g, int x, int y, int w, int h) { int orientation = ((JToolBar)context.getComponent()).getOrientation() == JToolBar.HORIZONTAL ? GTKConstants.HORIZONTAL : GTKConstants.VERTICAL; GTKStyle style = (GTKStyle)context.getStyle(); int gtkState = GTKLookAndFeel.synthStateToGTKState( context.getRegion(), context.getComponentState()); style.getEngine(context).paintHandle(context, g, gtkState, GTKConstants.SHADOW_OUT, "handlebox", x, y, w, h, orientation); } private static class DelegatingIcon extends SynthIcon implements UIResource { private static final Class[] PARAM_TYPES = new Class[] { SynthContext.class, Graphics.class, int.class, int.class, int.class, int.class }; private int width; private int height; private Object method; DelegatingIcon(String methodName, int width, int height) { this.method = methodName; this.width = width; this.height = height; } public void paintIcon(SynthContext context, Graphics g, int x, int y, int w, int h) { if (context != null) { try { getMethod().invoke(GTKIconFactory.class, new Object[] { context, g, new Integer(x), new Integer(y), new Integer(w), new Integer(h) }); } catch (IllegalAccessException iae) { } catch (InvocationTargetException ite) { } } } public int getIconWidth(SynthContext context) { return width; } public int getIconHeight(SynthContext context) { return height; } private Method getMethod() { if (method instanceof String) { Method[] methods = GTKIconFactory.class.getMethods(); try { method = GTKIconFactory.class.getMethod((String)method, PARAM_TYPES); } catch (NoSuchMethodException nsme) { System.out.println("NSME: " + nsme); } } return (Method)method; } } private static class SynthExpanderIcon extends SynthIcon { private static final Class[] PARAM_TYPES = new Class[] { SynthContext.class, Graphics.class, int.class, int.class, int.class, int.class }; private int width = -1; private int height = -1; private Object method; SynthExpanderIcon(String method) { this.method = method; } public void paintIcon(SynthContext context, Graphics g, int x, int y, int w, int h) { if (context != null) { try { getMethod().invoke(GTKIconFactory.class, new Object[] { context, g, new Integer(x), new Integer(y), new Integer(w), new Integer(h) }); updateSizeIfNecessary(context); } catch (IllegalAccessException iae) { } catch (InvocationTargetException ite) { } } } public int getIconWidth(SynthContext context) { updateSizeIfNecessary(context); return width; } public int getIconHeight(SynthContext context) { updateSizeIfNecessary(context); return height; } private void updateSizeIfNecessary(SynthContext context) { if (width == -1 && context != null) { width = height = context.getStyle().getInt(context, "Tree.expanderSize", 10); } } private Method getMethod() { if (method instanceof String) { Method[] methods = GTKIconFactory.class.getMethods(); try { method = GTKIconFactory.class.getMethod((String)method, PARAM_TYPES); } catch (NoSuchMethodException nsme) { System.out.println("NSME: " + nsme); } } return (Method)method; } } // GTK has a separate widget for the handle box, to mirror this // we create a unique icon per ToolBar and lookup the style for the // HandleBox. private static class ToolBarHandleIcon extends SynthIcon { private SynthStyle style; public void paintIcon(SynthContext context, Graphics g, int x, int y, int w, int h) { if (context != null) { context = getContext(context); paintToolBarHandleIcon(context, g, x, y, w, h); } } public int getIconWidth(SynthContext context) { if (((JToolBar)context.getComponent()).getOrientation() == JToolBar.HORIZONTAL) { return 10; } else { return context.getComponent().getWidth(); } } public int getIconHeight(SynthContext context) { if (((JToolBar)context.getComponent()).getOrientation() == JToolBar.HORIZONTAL) { return context.getComponent().getHeight(); } else { return 10; } } private SynthContext getContext(SynthContext context) { if (style == null) { style = SynthLookAndFeel.getStyleFactory().getStyle( context.getComponent(), GTKRegion.HANDLE_BOX); } return new SynthContext(context.getComponent(), GTKRegion.HANDLE_BOX, style, SynthConstants.ENABLED); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?