📄 gtkpainter.java
字号:
// // TREE // public void paintTreeBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { // As far as I can tell, these don't call into the ENGINE. fillArea(context, g, x, y, w, h, GTKColorType.TEXT_BACKGROUND); } // // VIEWPORT // public void paintViewportBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { // As far as I can tell, these don't call into the ENGINE. // Also note that you don't want this to call into the ENGINE // as if it where to paint a background JViewport wouldn't scroll // correctly. fillArea(context, g, x, y, w, h, GTKColorType.TEXT_BACKGROUND); } void paintFocus(SynthContext context, Graphics g, Region id, int state, String detail, int x, int y, int w, int h) { int gtkState = GTKLookAndFeel.synthStateToGTKState(id, state); synchronized (UNIXToolkit.GTK_LOCK) { if (! ENGINE.paintCachedImage(g, x, y, w, h, id, gtkState, "focus")) { ENGINE.startPainting(g, x, y, w, h, id, gtkState, "focus"); ENGINE.paintFocus(g, context, id, gtkState, detail, x, y, w, h); ENGINE.finishPainting(); } } } void paintMetacityElement(SynthContext context, Graphics g, int gtkState, String detail, int x, int y, int w, int h, ShadowType shadow, ArrowType direction) { synchronized (UNIXToolkit.GTK_LOCK) { if (! ENGINE.paintCachedImage( g, x, y, w, h, gtkState, detail, shadow, direction)) { ENGINE.startPainting( g, x, y, w, h, gtkState, detail, shadow, direction); if (detail == "metacity-arrow") { ENGINE.paintArrow(g, context, Region.INTERNAL_FRAME_TITLE_PANE, gtkState, shadow, direction, "", x, y, w, h); } else if (detail == "metacity-box") { ENGINE.paintBox(g, context, Region.INTERNAL_FRAME_TITLE_PANE, gtkState, shadow, "", x, y, w, h); } else if (detail == "metacity-vline") { ENGINE.paintVline(g, context, Region.INTERNAL_FRAME_TITLE_PANE, gtkState, "", x, y, w, h); } ENGINE.finishPainting(); } } } void paintIcon(SynthContext context, Graphics g, Method paintMethod, int x, int y, int w, int h) { int state = context.getComponentState(); synchronized (UNIXToolkit.GTK_LOCK) { if (! ENGINE.paintCachedImage(g, x, y, w, h, state, paintMethod)) { ENGINE.startPainting(g, x, y, w, h, state, paintMethod); try { paintMethod.invoke(this, context, g, state, x, y, w, h); } catch (IllegalAccessException iae) { assert false; } catch (InvocationTargetException ite) { assert false; } ENGINE.finishPainting(); } } } void paintIcon(SynthContext context, Graphics g, Method paintMethod, int x, int y, int w, int h, Object direction) { int state = context.getComponentState(); synchronized (UNIXToolkit.GTK_LOCK) { if (! ENGINE.paintCachedImage(g, x, y, w, h, state, paintMethod, direction)) { ENGINE.startPainting(g, x, y, w, h, state, paintMethod, direction); try { paintMethod.invoke(this, context, g, state, x, y, w, h, direction); } catch (IllegalAccessException iae) { assert false; } catch (InvocationTargetException ite) { assert false; } ENGINE.finishPainting(); } } } // All icon painting methods are called from under GTK_LOCK public void paintTreeExpandedIcon(SynthContext context, Graphics g, int state, int x, int y, int w, int h) { ENGINE.paintExpander(g, context, Region.TREE, GTKLookAndFeel.synthStateToGTKState(context.getRegion(), state), ExpanderStyle.EXPANDED, "treeview", x, y, w, h); } public void paintTreeCollapsedIcon(SynthContext context, Graphics g, int state, int x, int y, int w, int h) { ENGINE.paintExpander(g, context, Region.TREE, GTKLookAndFeel.synthStateToGTKState(context.getRegion(), state), ExpanderStyle.COLLAPSED, "treeview", x, y, w, h); } public void paintCheckBoxIcon(SynthContext context, Graphics g, int state, int x, int y, int w, int h) { ShadowType shadowType = ShadowType.OUT; if (((JCheckBox)context.getComponent()).isSelected()) { shadowType = ShadowType.IN; } ENGINE.paintCheck(g, context, Region.CHECK_BOX, GTKLookAndFeel.synthStateToGTKState(context.getRegion(), state), shadowType, "checkbutton", x, y, w, h); } public void paintRadioButtonIcon(SynthContext context, Graphics g, int state, int x, int y, int w, int h) { int gtkState = GTKLookAndFeel.synthStateToGTKState( context.getRegion(), state); ShadowType shadowType = ShadowType.OUT; // RadioButton painting appears to be special cased to pass // SELECTED into the ENGINE even though text colors are PRESSED. if ((state & SynthConstants.SELECTED) != 0) { gtkState = SynthConstants.SELECTED; } if (gtkState == SynthConstants.SELECTED) { shadowType = ShadowType.IN; } ENGINE.paintOption(g, context, Region.RADIO_BUTTON, gtkState, shadowType, "radiobutton", x, y, w, h); } public void paintMenuArrowIcon(SynthContext context, Graphics g, int state, int x, int y, int w, int h, ArrowType dir) { int gtkState = GTKLookAndFeel.synthStateToGTKState( context.getRegion(), state); ShadowType shadow = ShadowType.OUT; if (gtkState == SynthConstants.MOUSE_OVER) { shadow = ShadowType.IN; } ENGINE.paintArrow(g, context, Region.MENU_ITEM, gtkState, shadow, dir, "menuitem", x + 3, y + 3, 7, 7); } public void paintMenuItemArrowIcon(SynthContext context, Graphics g, int state, 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 void paintCheckBoxMenuItemArrowIcon(SynthContext context, Graphics g, int state, 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 void paintRadioButtonMenuItemArrowIcon(SynthContext context, Graphics g, int state, 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 void paintCheckBoxMenuItemCheckIcon(SynthContext context, Graphics g, int state, int x, int y, int w, int h) { ShadowType shadowType = ShadowType.OUT; int gtkState = GTKLookAndFeel.synthStateToGTKState( context.getRegion(), state); if ((state & SynthConstants.MOUSE_OVER) != 0) { gtkState = SynthConstants.MOUSE_OVER; } if ((state & SynthConstants.SELECTED) != 0) { shadowType = ShadowType.IN; } ENGINE.paintCheck(g, context, Region.CHECK_BOX_MENU_ITEM, gtkState, shadowType, "check", x, y, w, h); } public void paintRadioButtonMenuItemCheckIcon(SynthContext context, Graphics g, int state, int x, int y, int w, int h) { int gtkState = GTKLookAndFeel.synthStateToGTKState( context.getRegion(), state); if ((state & SynthConstants.MOUSE_OVER) != 0) { gtkState = SynthConstants.MOUSE_OVER; } ShadowType shadowType = ShadowType.OUT; if ((state & SynthConstants.SELECTED) != 0) { shadowType = ShadowType.IN; } ENGINE.paintOption(g, context, Region.RADIO_BUTTON_MENU_ITEM, gtkState, shadowType, "option", x, y, w, h); } public void paintToolBarHandleIcon(SynthContext context, Graphics g, int state, int x, int y, int w, int h, Orientation orientation) { int gtkState = GTKLookAndFeel.synthStateToGTKState( context.getRegion(), state); // The orientation parameter passed down by Synth refers to the // orientation of the toolbar, but the one we pass to GTK refers // to the orientation of the handle. Therefore, we need to swap // the value here: horizontal toolbars have vertical handles, and // vice versa. orientation = (orientation == Orientation.HORIZONTAL) ? Orientation.VERTICAL : Orientation.HORIZONTAL; ENGINE.paintHandle(g, context, Region.TOOL_BAR, gtkState, ShadowType.OUT, "handlebox", x, y, w, h, orientation); } public void paintAscendingSortIcon(SynthContext context, Graphics g, int state, int x, int y, int w, int h) { ENGINE.paintArrow(g, context, Region.TABLE, SynthConstants.ENABLED, ShadowType.IN, ArrowType.UP, "arrow", x, y, w, h); } public void paintDescendingSortIcon(SynthContext context, Graphics g, int state, int x, int y, int w, int h) { ENGINE.paintArrow(g, context, Region.TABLE, SynthConstants.ENABLED, ShadowType.IN, ArrowType.DOWN, "arrow", x, y, w, h); } /* * Fill an area with color determined from this context's Style using the * specified GTKColorType */ private void fillArea(SynthContext context, Graphics g, int x, int y, int w, int h, ColorType colorType) { if (context.getComponent().isOpaque()) { Region id = context.getRegion(); int gtkState = GTKLookAndFeel.synthStateToGTKState(id, context.getComponentState()); GTKStyle style = (GTKStyle)context.getStyle(); g.setColor(style.getGTKColor(context, gtkState, colorType)); g.fillRect(x, y, w, h); } } // Refer to GTKLookAndFeel for details on this. static class ListTableFocusBorder extends AbstractBorder implements UIResource { private boolean selectedCell; public static ListTableFocusBorder getSelectedCellBorder() { return new ListTableFocusBorder(true); } public static ListTableFocusBorder getUnselectedCellBorder() { return new ListTableFocusBorder(false); } public ListTableFocusBorder(boolean selectedCell) { this.selectedCell = selectedCell; } private SynthContext getContext(Component c) { SynthContext context = null; Component parent = c; while(parent != null && !(parent instanceof JTable) && !(parent instanceof JList)) { parent = parent.getParent(); } ComponentUI ui = null; if (parent instanceof JTable) { ui = ((JTable)parent).getUI(); } else if (parent instanceof JList) { ui = ((JList)parent).getUI(); } if (ui instanceof SynthUI) { context = ((SynthUI)ui).getContext((JComponent)parent); } return context; } public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { SynthContext context = getContext(c); int state = (selectedCell? SynthConstants.SELECTED: SynthConstants.FOCUSED | SynthConstants.ENABLED); if (context != null) { GTKPainter.INSTANCE.paintFocus(context, g, Region.TABLE, state, "", x, y, w, h); } else { if (ENGINE instanceof GTKDefaultEngine) { g.setColor(Color.BLACK); ((GTKDefaultEngine)ENGINE)._paintFocus( g, x, y, w, h, GTKDefaultEngine.DEFAULT_FOCUS_PATTERN, 1); } } } public Insets getBorderInsets(Component c) { int size = 1; SynthContext context = getContext(c); if (context != null) { size = ((GTKStyle)context.getStyle()).getClassSpecificIntValue( context, "focus-line-width", 1); } return new Insets(size, size, size, size); } public Insets getBorderInsets(Component c, Insets i) { Insets ins = getBorderInsets(c); if (i == null) { return ins; } i.left = ins.left; i.right = ins.right; i.top = ins.top; i.bottom = ins.bottom; return i; } public boolean isBorderOpaque() { return true; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -