gtkdefaultengine.java
来自「JAVA 所有包」· Java 代码 · 共 1,177 行 · 第 1/3 页
JAVA
1,177 行
g.drawLine(1, 1, 1, h - 1); g.drawLine(1, 1, w - 3, 1); } } else { g.setColor(upperLeft); g.drawLine(0, 0, w - 2, 0); if (paintWhite) { g.setColor(white); g.drawLine(0, 1, w - 3, 1); } } if ((tabIndex + 1) != selectedIndex) { g.setColor(innerRight); g.drawLine(w - 2, 2, w - 2, h - 1); g.setColor(bottomRight); g.drawLine(w - 1, 1, w - 1, h - 1); } } else if (placement == PositionType.TOP) { // Fill the background. paintBackground(g, context, region, state, background, 0, 0, w, h - 1); if (tabIndex == selectedIndex || tabIndex == 0) { g.setColor(upperLeft); g.drawLine(0, 0, 0, h - 2); g.setColor(bottomRight); g.drawLine(1, h - 1, w - 2, h - 1); g.setColor(innerRight); g.drawLine(2, h - 2, w - 2, h - 2); if (paintWhite) { g.setColor(white); g.drawLine(1, 0, 1, h - 2); } } else { g.setColor(bottomRight); g.drawLine(0, h - 1, w - 2, h - 1); g.setColor(innerRight); g.drawLine(0, h - 2, w - 2, h - 2); if (paintWhite) { g.setColor(white); g.drawLine(0, 0, 0, h - 2); } } if ((tabIndex + 1) != selectedIndex) { g.setColor(bottomRight); g.drawLine(w - 1, 0, w - 1, h - 2); g.setColor(innerRight); g.drawLine(w - 2, 0, w - 2, h - 2); } } else if (placement == PositionType.RIGHT) { // Fill the background. paintBackground(g, context, region, state, background, 1, 0, w, h); if (tabIndex == selectedIndex || tabIndex == 0) { g.setColor(upperLeft); g.drawLine(1, 0, w - 1, 0); g.drawLine(0, 1, 0, h - 2); if (paintWhite) { g.setColor(white); g.drawLine(1, 1, w, 1); g.drawLine(1, 1, 1, h - 3); } } else { g.setColor(upperLeft); g.drawLine(0, 0, 0, h - 2); if (paintWhite) { g.setColor(white); g.drawLine(1, 1, 1, h - 3); } } if ((tabIndex + 1) != selectedIndex) { g.setColor(bottomRight); g.drawLine(1, h - 1, w - 1, h - 1); g.setColor(innerRight); g.drawLine(2, h - 2, w - 1, h - 2); } } else if (placement == PositionType.LEFT) { // Fill the background. paintBackground(g, context, region, state, background, 0, 0, w - 1, h); if (tabIndex == selectedIndex || tabIndex == 0) { g.setColor(upperLeft); g.drawLine(0, 0, w - 2, 0); g.setColor(bottomRight); g.drawLine(w - 1, 1, w - 1, h - 2); g.setColor(innerRight); g.drawLine(w - 2, 2, w - 2, h - 2); if (paintWhite) { g.setColor(white); g.drawLine(0, 1, w - 2, 1); g.drawLine(w - 2, 1, w - 2, h - 3); } } else { g.setColor(bottomRight); g.drawLine(w - 1, 0, w - 1, h - 2); g.setColor(innerRight); g.drawLine(w - 2, 0, w - 2, h - 2); if (paintWhite) { g.setColor(white); g.drawLine(w - 2, 1, w - 2, h - 3); } } if ((tabIndex + 1) != selectedIndex) { g.setColor(bottomRight); g.drawLine(0, h - 1, w - 2, h - 1); g.setColor(innerRight); g.drawLine(0, h - 2, w - 2, h - 2); } } g.translate(-x, -y); } public void paintFlatBox(Graphics g, SynthContext context, Region id, int state, ShadowType shadowType, String key, int x, int y, int w, int h, ColorType colorType) { GTKStyle style = (GTKStyle)context.getStyle(); g.setColor(style.getGTKColor(context, state, colorType)); if (key == "cell_odd") { g.fillRect(x, y, w, h); } else { paintBackground(g, context, id, state, g.getColor(), x, y, w, h); } if (key == "tooltip") { g.setColor(Color.BLACK); g.drawRect(x, y, w - 1, h - 1); } } public void paintFocus(Graphics g, SynthContext context, Region id, int state, String key, int x, int y, int w, int h) { GTKStyle style = (GTKStyle)context.getStyle(); int[] pattern = (int[])style.getClassSpecificValue( context, "focus-line-pattern"); int size = style.getClassSpecificIntValue(context, "focus-line-width", 1); if (pattern == null) { pattern = DEFAULT_FOCUS_PATTERN; } if (size <= 0) { return; } g.setColor(getFocusColor(context, state)); _paintFocus(g, x, y, w, h, pattern, size); } void _paintFocus(Graphics g, int x, int y, int w, int h, int[] pattern, int size) { g.translate(x, y); // PENDING: This will need to be optimized int initial = size / 2; int offset = initial; int index = 0; int max1 = w - size; int max2 = max1 + h - size; int max3 = max2 + w - size; int max4 = max3 + h; while (offset < max4) { int next = offset + pattern[index]; if (index % 2 == 0) { if (offset < max1) { // top g.fillRect(offset, 0, Math.min(next, w) - offset, size); offset = Math.min(next, max1); } if (offset != next && offset < max2) { // right g.fillRect(w - size, offset - max1, size, Math.min(max2, next) - offset); offset = Math.min(max2, next); } if (offset != next && offset < max3) { // bottom int x2 = w - (offset - max2); int temp = Math.min(next - offset, max3 - offset); g.fillRect(x2 - temp, h - size, temp, size); offset += temp; } if (offset != next) { int y2 = h - (offset - max3); int temp = Math.min(next - offset, max4 - offset); g.fillRect(0, y2 - temp, size, temp); offset += temp; } } else { offset = next; } index = (index + 1) % pattern.length; } g.translate(-x, -y); } Color getFocusColor(SynthContext context, int state) { return ((GTKStyle)context.getStyle()).getGTKColor( context, state, ColorType.FOREGROUND); } public void paintHandle(Graphics g, SynthContext context, Region id, int paintState, ShadowType shadowType, String info, int x, int y, int w, int h, Orientation orientation) { paintBox(g, context, id, paintState, shadowType, info, x, y, w, h); g.translate(x, y); GTKStyle style = (GTKStyle)context.getStyle(); Color lightColor = style.getGTKColor(context, paintState, GTKColorType.LIGHT); Color darkColor = style.getGTKColor(context, paintState, GTKColorType.DARK); Color blackColor = style.getGTKColor(context, paintState, GTKColorType.BLACK); int startX; int startY; if (info == "paned") { JSplitPane splitPane = (JSplitPane)context.getComponent(); int markerLength = 7 * 3 + 6 * 2; // 7 markers width of 3 // + 6 spacers width of 2. if (orientation == Orientation.HORIZONTAL) { // Components are above/below. startX = w / 2 - markerLength / 2; startY = splitPane.getDividerSize() / 2 - 1; } else { // Components are left/right startX = splitPane.getDividerSize() / 2 - 1; startY = h / 2 - markerLength / 2; } for (int i = 0; i < 7; i++) { // Add length of one marker and spacing. if (orientation == Orientation.HORIZONTAL) { startX += 5; } else { startY += 5; } g.setColor(lightColor); g.fillRect(startX, startY, 2, 2); g.setColor(blackColor); g.fillRect(startX + 1, startY + 1, 2, 2); g.setColor(darkColor); g.fillRect(startX + 1, startY + 1, 1, 1); } } else if (info == "handlebox") { JToolBar tb = (JToolBar)context.getComponent(); startX = 2; startY = 2; if (tb.getOrientation() == JToolBar.HORIZONTAL) { while (startY < h) { g.setColor(darkColor); g.fillRect(startX + 1, startY + 1, 2, 2); g.fillRect(startX + 4, startY + 2, 2, 2); g.setColor(lightColor); g.fillRect(startX, startY, 2, 2); g.fillRect(startX + 3, startY + 1, 2, 2); startY += 3; } } else { boolean toggle = true; while (startX < w) { g.setColor(darkColor); g.fillRect(startX + 1, startY + 1, 2, 2); g.fillRect(startX + 1, startY + 4, 2, 2); g.setColor(lightColor); g.fillRect(startX, startY, 2, 2); g.fillRect(startX, startY + 3, 2, 2); startX += 3; if (toggle) { startY++; toggle = false; } else { startY--; toggle = true; } } } // Fix up the shadow. paintShadow(g, context, id, paintState, shadowType, info, 0, 0, w, h); } g.translate(-x, -y); } public void paintOption(Graphics g, SynthContext context, Region id, int paintState, ShadowType shadowType, String info, int x, int y, int w, int h) { g.translate(x, y); int componentState = context.getComponentState(); int centerY = h / 2 - 1; GTKStyle style = (GTKStyle)context.getStyle(); // We need to use the state from the context since the state passed // in may have been modified. int optionState = ((componentState & SynthConstants.PRESSED) == 0) ? SynthConstants.ENABLED : SynthConstants.PRESSED; g.setColor(style.getGTKColor(context, optionState, GTKColorType.TEXT_BACKGROUND)); if (context.getRegion() != Region.RADIO_BUTTON_MENU_ITEM) { // Paint center portion. g.fillRect(3, centerY - 3, 9, 9); g.fillRect(13, centerY - 1, 1, 4); g.fillRect(12, centerY + 3, 1, 2); g.fillRect(9, centerY + 6, 2, 1); g.fillRect(5, centerY + 7, 4, 1); // Paint dark shadow. g.setColor(style.getGTKColor(context, SynthConstants.ENABLED, GTKColorType.DARK)); g.fillRect(5, centerY - 5, 4, 1); g.fillRect(3, centerY - 4, 3, 1); g.fillRect(2, centerY - 3, 1, 2); g.fillRect(1, centerY - 1, 1, 4); g.fillRect(2, centerY + 4, 1, 1); g.fillRect(3, centerY + 5, 2, 1); g.fillRect(5, centerY + 6, 4, 1); g.fillRect(9, centerY + 5, 2, 1); g.fillRect(11, centerY + 3, 1, 2); g.fillRect(12, centerY - 1, 1, 4); g.fillRect(11, centerY - 3, 1, 2); g.fillRect(10, centerY - 4, 1, 1); // Paint black shadow. g.setColor(style.getGTKColor(context, paintState, GTKColorType.BLACK)); g.fillRect(5, centerY - 4, 5, 1); g.fillRect(10, centerY - 3, 1, 1); g.fillRect(3, centerY - 3, 2, 1); g.fillRect(3, centerY - 2, 1, 1); g.fillRect(2, centerY - 1, 1, 5); g.fillRect(3, centerY + 4, 1, 1); } // Fill in center if selected. if ((componentState & SynthConstants.SELECTED) != 0) { g.setColor(style.getGTKColor(context, SynthConstants.ENABLED, GTKColorType.FOREGROUND)); g.fillRect(5, centerY, 5, 3); g.fillRect(6, centerY - 1, 3, 1); g.fillRect(6, centerY + 3, 3, 1); } g.translate(-x, -y); } public void paintShadow(Graphics g, SynthContext context, Region id, int state, ShadowType shadowType, String info, int x, int y, int w, int h) { if (info == "buttondefault") { // YES, this appears to be special cased. g.setColor(((GTKStyle)context.getStyle()).getGTKColor(context, state, GTKColorType.BLACK)); g.drawRect(x, y, w - 1, h - 1); return; } GTKStyle style = (GTKStyle)context.getStyle(); JComponent c = context.getComponent(); int xThickness = style.getXThickness(); int yThickness = style.getYThickness(); if (info == "trough" || (info == "spinbutton" && c instanceof JButton)) { // YES, this appears to be special cased. xThickness = yThickness = 1; } if (xThickness < 0 && yThickness < 0) { // nothing to paint. return; } Color upperLeft = null, innerLeft = null, bottomRight = null, innerRight = null; switch (shadowType) { case IN: if (info == "spinbutton" && c instanceof JButton) { upperLeft = style.getGTKColor(context, state, GTKColorType.DARK); innerRight = upperLeft; bottomRight = style.getGTKColor(context, state, GTKColorType.BLACK); } else { upperLeft = style.getGTKColor(context, state,
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?