Exemple #1
0
  private Insets getScrollBarInsets(SynthContext context, Insets insets) {
    int troughBorder = getClassSpecificIntValue(context, "trough-border", 1);
    insets.left = insets.right = insets.top = insets.bottom = troughBorder;

    JComponent c = context.getComponent();
    if (c.getParent() instanceof JScrollPane) {
      // This scrollbar is part of a scrollpane; use only the
      // "scrollbar-spacing" style property to determine the padding
      // between the scrollbar and its parent scrollpane.
      int spacing = getClassSpecificIntValue(WidgetType.SCROLL_PANE, "scrollbar-spacing", 3);
      if (((JScrollBar) c).getOrientation() == JScrollBar.HORIZONTAL) {
        insets.top += spacing;
      } else {
        if (c.getComponentOrientation().isLeftToRight()) {
          insets.left += spacing;
        } else {
          insets.right += spacing;
        }
      }
    } else {
      // This is a standalone scrollbar; leave enough room for the
      // focus line in addition to the trough border.
      if (c.isFocusable()) {
        int focusSize = getClassSpecificIntValue(context, "focus-line-width", 1);
        int focusPad = getClassSpecificIntValue(context, "focus-padding", 1);
        int totalFocus = focusSize + focusPad;
        insets.left += totalFocus;
        insets.right += totalFocus;
        insets.top += totalFocus;
        insets.bottom += totalFocus;
      }
    }
    return insets;
  }
  /**
   * 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;
  }