gtkpainter.java
来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,426 行 · 第 1/4 页
JAVA
1,426 行
JSeparator.HORIZONTAL) { engine.paintHline(context, g, SynthConstants.ENABLED, "hseparator", x, y, w, h); } else { engine.paintVline(context, g, SynthConstants.ENABLED, "vseparator", x, y, w, h); } } // // SLIDER // private Insets getSliderInsets(SynthContext context, Insets insets) { GTKStyle style = (GTKStyle)context.getStyle(); int xThickness = style.getXThickness(); int yThickness = style.getYThickness(); insets.top = insets.bottom = yThickness; insets.right = insets.left = xThickness; return insets; } private Insets getSliderTrackInsets(SynthContext context, Insets insets) { GTKStyle style = (GTKStyle)context.getStyle(); int focusSize = style.getClassSpecificIntValue(context, "focus-line-width", 1); int focusPad = style.getClassSpecificIntValue(context, "focus-padding", 1); insets.top = insets.bottom = insets.left = insets.right = focusSize + focusPad; return insets; } public void paintSliderTrackBackground(SynthContext context, Graphics g, int x, int y, int w,int h) { GTKEngine engine = getEngine(context); GTKStyle style = (GTKStyle)context.getStyle(); int state = context.getComponentState(); int gtkState = GTKLookAndFeel.synthStateToGTKState(context.getRegion(), state); engine.paintBox(context, g, gtkState, GTKConstants.SHADOW_IN, "trough", x, y, w, h); if ((state & SynthConstants.FOCUSED) == SynthConstants.FOCUSED) { int focusSize = style.getClassSpecificIntValue(context, "focus-line-width", 1); focusSize += style.getClassSpecificIntValue(context, "focus-padding", 1); x -= focusSize; y -= focusSize; w += 2 * focusSize; h += 2 * focusSize; engine.paintFocus(context, g, SynthConstants.ENABLED, "trough", x, y, w, h); } } public void paintSliderThumbBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { GTKEngine engine = getEngine(context); if (orientation == JSlider.HORIZONTAL) { orientation = GTKConstants.HORIZONTAL; } else { orientation = GTKConstants.VERTICAL; } engine.paintSlider(context, g, GTKLookAndFeel.synthStateToGTKState( context.getRegion(), context.getComponentState()), GTKConstants.SHADOW_OUT, "slider", x, y, w, h, orientation); } // // SPINNER // public void paintSpinnerBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { // This is handled in paintTextFieldBackground } private Insets getSpinnerInsets(SynthContext context, Insets insets) { // Spinner's have no insets, the text field gets the insets. return insets; } private Insets getSpinnerButtonInsets(SynthContext context, Insets insets) { insets.top = insets.bottom = 1; insets.right = insets.left = 1; return insets; } // // SPLIT_PANE_DIVIDER // public void paintSplitPaneDividerBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { GTKEngine engine = getEngine(context); int orientation; if (((JSplitPane)context.getComponent()).getOrientation() == JSplitPane.VERTICAL_SPLIT) { orientation = GTKConstants.HORIZONTAL; } else { orientation = GTKConstants.VERTICAL; } engine.paintHandle(context, g, GTKLookAndFeel.synthStateToGTKState( context.getRegion(), context.getComponentState()), GTKConstants.UNDEFINED, "paned", x, y, w, h, orientation); } public void paintSplitPaneDragDivider(SynthContext context, Graphics g,int x, int y, int w, int h, int orientation) { paintSplitPaneDividerForeground(context, g, x, y, w, h, orientation); } public void paintSplitPaneDividerForeground(SynthContext context, Graphics g,int x, int y, int w, int h, int orientation) { g.setColor(context.getStyle().getColor(context, GTKColorType.BACKGROUND)); g.fillRect(x, y, w, h); paintSplitPaneDividerBackground(context, g, x, y, w, h); } // // TABBED_PANE // private Insets getTabbedPaneInsets(SynthContext context, Insets insets) { GTKStyle style = (GTKStyle)context.getStyle(); int xThickness = style.getXThickness(); int yThickness = style.getYThickness(); insets.top = insets.bottom = yThickness; insets.right = insets.left = xThickness; return insets; } // // TABBED_PANE_CONTENT // private Insets getTabbedPaneContentInsets(SynthContext context, Insets insets) { GTKStyle style = (GTKStyle)context.getStyle(); int xThickness = style.getXThickness(); int yThickness = style.getYThickness(); insets.top = insets.bottom = yThickness; insets.right = insets.left = xThickness; return insets; } public void paintTabbedPaneContentBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { GTKEngine engine = getEngine(context); JTabbedPane tabPane = (JTabbedPane)context.getComponent(); GTKStyle style = (GTKStyle)context.getStyle(); Region region = context.getRegion(); int placement = GTKLookAndFeel.SwingOrientationConstantToGTK( tabPane.getTabPlacement()); int start = 0; int size = 0; int selectedIndex = tabPane.getSelectedIndex(); if (selectedIndex != -1) { Rectangle tabBounds = tabPane.getBoundsAt(selectedIndex); if (placement == GTKConstants.TOP || placement == GTKConstants.BOTTOM) { start = tabBounds.x - 1; size = tabBounds.width; } else { start = tabBounds.y - 1; size = tabBounds.height; } } engine.paintBoxGap(context, g, GTKLookAndFeel.synthStateToGTKState( context.getRegion(), context.getComponentState()), GTKConstants.SHADOW_OUT, "notebook", x, y, w, h, placement, start, size); } // // TABBED_PANE_TAB // private Insets getTabbedPaneTabInsets(SynthContext context, Insets insets) { GTKStyle style = (GTKStyle)context.getStyle(); int xThickness = style.getXThickness(); int yThickness = style.getYThickness(); int focusSize = 0; int pad = 2; focusSize = style.getClassSpecificIntValue(context, "focus-line-width",1); insets.left = insets.right = focusSize + pad + xThickness; insets.top = insets.bottom = focusSize + pad + yThickness; return insets; } public void paintTabbedPaneTabBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int tabIndex) { GTKEngine engine = getEngine(context); GTKStyle style = (GTKStyle)context.getStyle(); int state = context.getComponentState(); int selectedIndex = ((JTabbedPane)context.getComponent()). getSelectedIndex(); int offset = (selectedIndex == tabIndex) ? 0 : 2; int side; state = GTKLookAndFeel.synthStateToGTKState(context.getRegion(), state); switch (((JTabbedPane)context.getComponent()).getTabPlacement()) { case SwingConstants.TOP: side = GTKConstants.BOTTOM; y += offset; h -= offset; break; case SwingConstants.BOTTOM: h -= offset; side = GTKConstants.TOP; break; case SwingConstants.LEFT: x += offset; w -= offset; side = GTKConstants.RIGHT; break; default: w -= offset; side = GTKConstants.LEFT; break; } engine.paintExtension(context, g, state, GTKConstants.SHADOW_OUT, "tab", x, y, w, h, side, tabIndex); } // // TEXT_AREA // public void paintTextAreaBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { GTKEngine engine = getEngine(context); GTKStyle style = (GTKStyle)context.getStyle(); int state = context.getComponentState(); engine.paintFlatBoxText(context, g, state, "base", x, y, w, h); } // // TEXT_FIELD // // NOTE: comobobox and FormattedTextField calls this too. private void paintTextFieldBackground(SynthContext context, GTKEngine engine, Graphics g, int x, int y, int w, int h) { GTKStyle style = (GTKStyle)context.getStyle(); boolean interiorFocus = style.getClassSpecificBoolValue(context, "interior-focus", true); int state = context.getComponentState(); int gtkState = GTKLookAndFeel.synthStateToGTKState( context.getRegion(), state); int focusSize; int xThickness = style.getXThickness(); int yThickness = style.getYThickness(); paintTextBackground(context, engine, g, x, y, w, h); state = GTKLookAndFeel.synthStateToGTKState(context.getRegion(),state); if (!interiorFocus && (state & SynthConstants.FOCUSED) == SynthConstants.FOCUSED) { focusSize = style.getClassSpecificIntValue(context, "focus-line-width",1); x += focusSize; y += focusSize; w -= 2 * focusSize; h -= 2 * focusSize; } else { focusSize = 0; } engine.paintShadow(context, g, SynthConstants.ENABLED, GTKConstants.SHADOW_IN, "entry", x, y, w, h); g.setColor(style.getGTKColor(context.getComponent(), context.getRegion(), SynthConstants.ENABLED, GTKColorType.TEXT_BACKGROUND)); g.fillRect(x + xThickness, y + yThickness, w - (2 * xThickness), h - (2 * yThickness)); engine.paintFlatBoxText(context, g, SynthConstants.ENABLED, "entry_bg", x + xThickness, y + yThickness, w - (2 * xThickness), h - (2 * yThickness)); if (focusSize > 0) { x -= focusSize; y -= focusSize; w += 2 * focusSize; h += 2 * focusSize; engine.paintFocus(context, g, gtkState, "entry", x, y, w, h); } } // NOTE: this is called for ComboBox, and FormattedTextField. too. private Insets getTextFieldInsets(SynthContext context, Insets insets) { GTKStyle style = (GTKStyle)context.getStyle(); int xThickness = style.getXThickness(); int yThickness = style.getYThickness(); boolean interiorFocus = style.getClassSpecificBoolValue(context, "interior-focus", true); int focusSize = 0; if (!interiorFocus) { focusSize = style.getClassSpecificIntValue(context, "focus-line-width",1); } insets.left = insets.right = focusSize + xThickness + 2; insets.top = insets.bottom = focusSize + yThickness + 2; return insets; } private void paintTextBackground(SynthContext context, GTKEngine engine, Graphics g, int x, int y, int w,int h) { // Text is odd, the background is filled in with // TEXT_BACKGROUND JComponent c = context.getComponent(); // Text is odd in that it uses the TEXT_BACKGROUND vs BACKGROUND. if (c.isOpaque() && c.getBackground() instanceof ColorUIResource) { g.setColor(((GTKStyle)context.getStyle()).getGTKColor( context.getComponent(), context.getRegion(), SynthConstants.ENABLED, GTKColorType.TEXT_BACKGROUND)); g.fillRect(x, y, w, h); } } // // OPTION_Pane // private Insets getOptionPaneInsets(SynthContext context, Insets insets) { insets.left = insets.right = insets.top = insets.bottom = 6; return insets; } // // TOGGLE_BUTTON // public void paintToggleButtonBackground(SynthContext context,
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?