Esempio n. 1
0
  /**
   * 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;
  }
Esempio n. 2
0
  @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;
  }