gtkpainter.java
来自「java jdk 1.4的源码」· Java 代码 · 共 1,333 行 · 第 1/4 页
JAVA
1,333 行
private void paintButtonBackground(SynthContext context, GTKEngine engine, Graphics g, int x, int y, int w, int h, String detail) { // paing the default shadow int state = context.getComponentState(); int gtkState = GTKLookAndFeel.synthStateToGTKState( context.getRegion(), state); GTKStyle style = (GTKStyle)context.getStyle(); boolean interiorFocus = style.getClassSpecificBoolValue(context, "interior-focus", true); int focusSize = style.getClassSpecificIntValue(context, "focus-line-width",1); int focusPad = style.getClassSpecificIntValue(context, "focus-padding", 1); int totalFocusSize = focusSize + focusPad; int xThickness = style.getXThickness(); int yThickness = style.getYThickness(); Component component = context.getComponent(); // Paint the default indicator if ((component instanceof JButton) && ((JButton)component).isDefaultCapable()) { Insets defaultInsets = (Insets)style.getClassSpecificInsetsValue( context, "default-border", BUTTON_DEFAULT_BORDER_INSETS); if ((state & SynthConstants.DEFAULT) == SynthConstants.DEFAULT) { engine.paintBox(context, g, SynthConstants.ENABLED, GTKConstants.SHADOW_IN, "buttondefault", x, y, w, h); } x += defaultInsets.left; y += defaultInsets.top; w -= (defaultInsets.left + defaultInsets.right); h -= (defaultInsets.top + defaultInsets.bottom); } // Render the box. if (!interiorFocus && (state & SynthConstants.FOCUSED) == SynthConstants.FOCUSED) { x += totalFocusSize; y += totalFocusSize; w -= 2 * totalFocusSize; h -= 2 * totalFocusSize; } if (!(component.getParent() instanceof JToolBar) || gtkState != SynthConstants.ENABLED) { int shadowType; if ((state & SynthConstants.PRESSED) == SynthConstants.PRESSED) { shadowType = GTKConstants.SHADOW_IN; } else { shadowType = GTKConstants.SHADOW_OUT; } engine.paintBox(context, g, gtkState, shadowType, detail, x, y, w, h); } // focus if ((state & SynthConstants.FOCUSED) == SynthConstants.FOCUSED) { if (interiorFocus) { x += xThickness + focusPad; y += yThickness + focusPad; w -= 2 * (xThickness + focusPad); h -= 2 * (yThickness + focusPad); } else { x -= totalFocusSize; y -= totalFocusSize; w += 2 * totalFocusSize; h += 2 * totalFocusSize; } engine.paintFocus(context, g, gtkState, detail, x, y, w, h); } } // // ARROW_BUTTON // private void paintArrowButtonForeground(SynthContext context, GTKEngine engine, Graphics g, int x, int y, int w, int h) { int state = GTKLookAndFeel.synthStateToGTKState( Region.ARROW_BUTTON, context.getComponentState()); int shadowType; if (state == SynthConstants.PRESSED) { shadowType = GTKConstants.SHADOW_OUT; } else { shadowType = GTKConstants.SHADOW_IN; } int direction = ((SynthArrowButton)context.getComponent()). getDirection(); switch (direction) { case SwingConstants.NORTH: direction = GTKConstants.ARROW_UP; break; case SwingConstants.SOUTH: direction = GTKConstants.ARROW_DOWN; break; case SwingConstants.EAST: direction = GTKConstants.ARROW_RIGHT; break; case SwingConstants.WEST: direction = GTKConstants.ARROW_LEFT; break; } Component c = context.getComponent(); String name = c.getName(); String detail = "arrow"; if (name == "ScrollBar.button") { if (c.getParent() instanceof JScrollBar) { if (((JScrollBar)c.getParent()).getOrientation() == SwingConstants.HORIZONTAL) { detail = "hscrollbar"; } else { detail = "vscrollbar"; } } } // Note quite sure what their algorithm is, but this works pretty // good. int size = Math.min(w / 2, h / 2); x += (w - size) / 2; y += (h - size) / 2; engine.paintArrow(context, g, state, shadowType, direction, detail, x, y, size, size); } private void paintArrowButtonBackground(SynthContext context, GTKEngine engine, Graphics g, int x, int y, int w, int h) { Component c = context.getComponent(); String name = c.getName(); String detail = "button"; if (name == "ScrollBar.button") { if (c.getParent() instanceof JScrollBar) { if (((JScrollBar)c.getParent()).getOrientation() == SwingConstants.HORIZONTAL) { detail = "hscrollbar"; } else { detail = "vscrollbar"; } } } else if ("Spinner.previousButton" == name || "Spinner.nextButton" == name) { detail = "spinbutton"; } paintButtonBackground(context, engine, g, x, y, w, h, detail); } // // CHECK_BUTTON // private void paintCheckButtonBackground(SynthContext context, GTKEngine engine, Graphics g, int x, int y, int w, int h) { int gtkState = GTKLookAndFeel.synthStateToGTKState( context.getRegion(), context.getComponentState()); if ((gtkState & SynthConstants.MOUSE_OVER) != 0) { engine.paintFlatBoxNormal(context, g, SynthConstants.MOUSE_OVER, "checkbutton", x, y, w, h); } } // // CHECK_BUTTON_MENU_ITEM // public void paintCheckButtonMenuItemBackground(SynthContext context, GTKEngine engine, Graphics g, int x, int y, int w, int h) { int gtkState = GTKLookAndFeel.synthStateToGTKState( context.getRegion(), context.getComponentState()); if ((context.getComponentState() & SynthConstants.MOUSE_OVER) != 0) { engine.paintBox(context, g, gtkState, GTKConstants.SHADOW_OUT, "menuitem", x, y, w, h); } } // // LIST // private void paintListBackground(SynthContext context, GTKEngine engine, Graphics g, int x, int y, int w, int h) { int state = GTKLookAndFeel.synthStateToGTKState( Region.LIST, context.getComponentState()); if (context.getComponent().getName() == "ComboBox.list") { // Paint it's shadow. } engine.paintFlatBoxText(context, g, state, "base", x, y, w, h); } // // MENU_BAR // private Insets getMenuBarInsets(SynthContext context, Insets insets) { GTKStyle style = (GTKStyle)context.getStyle(); int internalPadding = style.getClassSpecificIntValue(context, "internal-padding", 1); int xThickness = style.getXThickness(); int yThickness = style.getYThickness(); insets.top = insets.bottom = internalPadding + yThickness; insets.left = insets.right = internalPadding + xThickness; return insets; } private void paintMenuBarBackground(SynthContext context, GTKEngine engine, Graphics g, int x, int y, int w, int h) { GTKStyle style = (GTKStyle)context.getStyle(); int shadowType = style.getClassSpecificIntValue(context, "shadow-type", GTKConstants.SHADOW_OUT); int gtkState = GTKLookAndFeel.synthStateToGTKState( context.getRegion(), context.getComponentState()); engine.paintBox(context, g, gtkState, shadowType, "menubar", x, y, w, h); } // // MENU // private void paintMenuBackground(SynthContext context, GTKEngine engine, Graphics g, int x, int y, int w, int h) { int gtkState = GTKLookAndFeel.synthStateToGTKState( context.getRegion(), context.getComponentState()); if (gtkState == SynthConstants.MOUSE_OVER) { engine.paintBox(context, g, gtkState, GTKConstants.SHADOW_OUT, "menuitem", x, y, w, h); } } // // MENU_ITEM // private Insets getMenuItemInsets(SynthContext context, Insets insets) { GTKStyle style = (GTKStyle)context.getStyle(); int internalPadding = style.getClassSpecificIntValue(context, "internal-padding", 1); int xThickness = style.getXThickness(); int yThickness = style.getYThickness(); insets.top = insets.bottom = internalPadding + yThickness; insets.left = insets.right = internalPadding + xThickness; return insets; } private void paintMenuItemBackground(SynthContext context, GTKEngine engine, Graphics g, int x, int y, int w, int h) { int gtkState = GTKLookAndFeel.synthStateToGTKState( context.getRegion(), context.getComponentState()); if ((context.getComponentState() & SynthConstants.MOUSE_OVER) != 0) { engine.paintBox(context, g, gtkState, GTKConstants.SHADOW_OUT, "menuitem", x, y, w, h); } } private Insets getPopupMenuInsets(SynthContext context, Insets insets) { insets.left = insets.right = insets.top = insets.bottom = 2; return insets; } private void paintPopupMenuBackground(SynthContext context, GTKEngine engine, Graphics g, int x, int y, int w, int h) { int gtkState = GTKLookAndFeel.synthStateToGTKState( context.getRegion(), context.getComponentState()); engine.paintBox(context, g, gtkState, GTKConstants.SHADOW_OUT, "menu", x, y, w, h); GTKStyle style = (GTKStyle)context.getStyle(); int xThickness = style.getXThickness(); int yThickness = style.getYThickness(); engine.paintBackground(context, g, gtkState, style.getGTKColor( context.getComponent(), context.getRegion(), gtkState, GTKColorType.BACKGROUND), x + xThickness, y + yThickness, w - xThickness - xThickness, h - yThickness - yThickness); } // // PROGRESS_BAR // private Insets getProgressBarInsets(SynthContext context, Insets insets) { GTKStyle style = (GTKStyle)context.getStyle(); insets.left = insets.right = style.getXThickness(); insets.top = insets.bottom = style.getYThickness(); return insets; } private void paintProgressBarBackground(SynthContext context, GTKEngine engine, Graphics g, int x, int y, int w, int h) { GTKStyle style = (GTKStyle)context.getStyle(); w -= style.getXThickness(); h -= style.getYThickness(); // Draw the trough. engine.paintBox(context, g, SynthConstants.ENABLED, GTKConstants.SHADOW_IN, "trough", x, y, w, h); } private void paintProgressBarForeground(SynthContext context, GTKEngine engine, Graphics g, int x, int y, int w, int h) { // Draw the actual progress of the progress bar. if (w != 0 || h != 0) { engine.paintBox(context, g, SynthConstants.ENABLED, GTKConstants.SHADOW_OUT, "bar", x, y, w, h); } } private void paintScrollPaneBackground(SynthContext context, GTKEngine engine, Graphics g, int x, int y, int w, int h) { engine.paintShadow(context, g, SynthConstants.ENABLED, GTKConstants.SHADOW_IN, "scrolled_window", x, y, w, h); }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?