/** * Returns the <code>GTKStyle</code> to use based on the <code>Region</code> id * * @param c this parameter isn't used, may be null. * @param id of the region to get the style. */ public synchronized SynthStyle getStyle(JComponent c, Region id) { WidgetType wt = GTKNativeEngine.getWidgetType(c, id); Object key = null; if (id == Region.SCROLL_BAR) { // The style/insets of a scrollbar can depend on a number of // factors (see GTKStyle.getScrollBarInsets()) so use a // complex key here. if (c != null) { JScrollBar sb = (JScrollBar) c; boolean sp = (sb.getParent() instanceof JScrollPane); boolean horiz = (sb.getOrientation() == JScrollBar.HORIZONTAL); boolean ltr = sb.getComponentOrientation().isLeftToRight(); boolean focusable = sb.isFocusable(); key = new ComplexKey(wt, sp, horiz, ltr, focusable); } } else if (id == Region.CHECK_BOX || id == Region.RADIO_BUTTON) { // The style/insets of a checkbox or radiobutton can depend // on the component orientation, so use a complex key here. if (c != null) { boolean ltr = c.getComponentOrientation().isLeftToRight(); key = new ComplexKey(wt, ltr); } } else if (id == Region.BUTTON) { // The style/insets of a button can depend on whether it is // default capable or in a toolbar, so use a complex key here. if (c != null) { JButton btn = (JButton) c; boolean toolButton = (btn.getParent() instanceof JToolBar); boolean defaultCapable = btn.isDefaultCapable(); key = new ComplexKey(wt, toolButton, defaultCapable); } } if (key == null) { // Otherwise, just use the WidgetType as the key. key = wt; } GTKStyle result = stylesCache.get(key); if (result == null) { result = isNativeGtk ? new GTKNativeStyle(defaultFont, wt) : new GTKDefaultStyle(defaultFont); stylesCache.put(key, result); } return result; }
@Nullable private static JScrollBar findHorizontalScrollBar(Component c) { if (c == null) return null; if (c instanceof JScrollPane) { return ((JScrollPane) c).getHorizontalScrollBar(); } if (isDiagramViewComponent(c)) { final JComponent view = (JComponent) c; for (int i = 0; i < view.getComponentCount(); i++) { if (view.getComponent(i) instanceof JScrollBar) { final JScrollBar scrollBar = (JScrollBar) view.getComponent(i); if (scrollBar.getOrientation() == Adjustable.HORIZONTAL) { return scrollBar; } } } } return findHorizontalScrollBar(c.getParent()); }
@Override public void paint(Graphics2D g, int x, int y, int width, int height, Integer object) { g = (Graphics2D) g.create(x, y, width, height); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f)); g.setStroke(BASIC_STROKE); boolean dark = UIUtil.isUnderDarcula(); int offset = object != null ? object + 11 : 11; Color start = getColor(dark ? 95 + offset : 251 - offset); Color stop = getColor(dark ? 80 + offset : 215 - offset); Paint paint; if (Adjustable.VERTICAL == myScrollBar.getOrientation()) { x = 2; y = 1; width -= 3; height -= 2; if (myPainter instanceof ExtraErrorStripePainter) { ExtraErrorStripePainter extra = (ExtraErrorStripePainter) myPainter; int gap = extra.getMinimalThickness() - 1; x += gap; width -= gap; } paint = UIUtil.getGradientPaint(x, 0, start, x + width, 0, stop); } else { x = 1; y = 2; width -= 2; height -= 3; paint = UIUtil.getGradientPaint(0, y, start, 0, y + height, stop); } int arc = JBUI.scale(3); g.setPaint(paint); g.fillRoundRect(x + 1, y + 1, width - 2, height - 2, arc, arc); g.setColor(getColor(dark ? 85 : 201)); g.drawRoundRect(x, y, width - 1, height - 1, arc, arc); g.dispose(); }
@Override public Object get(SynthContext context, Object key) { // See if this is a class specific value. String classKey = CLASS_SPECIFIC_MAP.get(key); if (classKey != null) { Object value = getClassSpecificValue(classKey); if (value != null) { return value; } } // Is it a specific value ? if (key == "ScrollPane.viewportBorderInsets") { return getThicknessInsets(context, new Insets(0, 0, 0, 0)); } else if (key == "Slider.tickColor") { return getColorForState(context, ColorType.FOREGROUND); } else if (key == "ScrollBar.minimumThumbSize") { int len = getClassSpecificIntValue(context, "min-slider-length", 21); JScrollBar sb = (JScrollBar) context.getComponent(); if (sb.getOrientation() == JScrollBar.HORIZONTAL) { return new DimensionUIResource(len, 0); } else { return new DimensionUIResource(0, len); } } else if (key == "Separator.thickness") { JSeparator sep = (JSeparator) context.getComponent(); if (sep.getOrientation() == JSeparator.HORIZONTAL) { return getYThickness(); } else { return getXThickness(); } } else if (key == "ToolBar.separatorSize") { int size = getClassSpecificIntValue(WidgetType.TOOL_BAR, "space-size", 12); return new DimensionUIResource(size, size); } else if (key == "ScrollBar.buttonSize") { JScrollBar sb = (JScrollBar) context.getComponent().getParent(); boolean horiz = (sb.getOrientation() == JScrollBar.HORIZONTAL); WidgetType wt = horiz ? WidgetType.HSCROLL_BAR : WidgetType.VSCROLL_BAR; int sliderWidth = getClassSpecificIntValue(wt, "slider-width", 14); int stepperSize = getClassSpecificIntValue(wt, "stepper-size", 14); return horiz ? new DimensionUIResource(stepperSize, sliderWidth) : new DimensionUIResource(sliderWidth, stepperSize); } else if (key == "ArrowButton.size") { String name = context.getComponent().getName(); if (name != null && name.startsWith("Spinner")) { // Believe it or not, the size of a spinner arrow button is // dependent upon the size of the spinner's font. These // calculations come from gtkspinbutton.c (version 2.8.20), // spin_button_get_arrow_size() method. String pangoFontName; synchronized (sun.awt.UNIXToolkit.GTK_LOCK) { pangoFontName = nativeGetPangoFontName(WidgetType.SPINNER.ordinal()); } int arrowSize = (pangoFontName != null) ? PangoFonts.getFontSize(pangoFontName) : 10; return (arrowSize + (getXThickness() * 2)); } // For all other kinds of arrow buttons (e.g. combobox arrow // buttons), we will simply fall back on the value of // ArrowButton.size as defined in the UIDefaults for // GTKLookAndFeel when we call UIManager.get() below... } else if ("CheckBox.iconTextGap".equals(key) || "RadioButton.iconTextGap".equals(key)) { // The iconTextGap value needs to include "indicator-spacing" // and it also needs to leave enough space for the focus line, // which falls between the indicator icon and the text. // See getRadioInsets() and 6489585 for more details. int indicatorSpacing = getClassSpecificIntValue(context, "indicator-spacing", 2); int focusSize = getClassSpecificIntValue(context, "focus-line-width", 1); int focusPad = getClassSpecificIntValue(context, "focus-padding", 1); return indicatorSpacing + focusSize + focusPad; } // Is it a stock icon ? GTKStockIcon stockIcon = null; synchronized (ICONS_MAP) { stockIcon = ICONS_MAP.get(key); } if (stockIcon != null) { return stockIcon; } // Is it another kind of value ? if (key != "engine") { // For backward compatibility we'll fallback to the UIManager. // We don't go to the UIManager for engine as the engine is GTK // specific. Object value = UIManager.get(key); if (key == "Table.rowHeight") { int focusLineWidth = getClassSpecificIntValue(context, "focus-line-width", 0); if (value == null && focusLineWidth > 0) { value = Integer.valueOf(16 + 2 * focusLineWidth); } } return value; } // Don't call super, we don't want to pick up defaults from // SynthStyle. return null; }
private ContextMenuSource createContextSource() { return new ScrollBarContextMenuSource(scrollBar.getOrientation()); }