コード例 #1
0
ファイル: GTKStyle.java プロジェクト: susotajuraj/jdk8u-jdk
  private Icon getStockIcon(SynthContext context, String key, int type) {
    TextDirection direction = TextDirection.LTR;

    if (context != null) {
      ComponentOrientation co = context.getComponent().getComponentOrientation();

      if (co != null && !co.isLeftToRight()) {
        direction = TextDirection.RTL;
      }
    }

    // First try loading a theme-specific icon using the native
    // GTK libraries (native GTK handles the resizing for us).
    Icon icon = getStyleSpecificIcon(key, direction, type);
    if (icon != null) {
      return icon;
    }

    // In a failure case where native GTK (unexpectedly) returns a
    // null icon, we can try loading a default icon as a fallback.
    String propName =
        ICON_PROPERTY_PREFIX
            + key
            + '.'
            + type
            + '.'
            + (direction == TextDirection.RTL ? "rtl" : "ltr");
    Image img = (Image) Toolkit.getDefaultToolkit().getDesktopProperty(propName);
    if (img != null) {
      return new ImageIcon(img);
    }

    // In an extreme failure situation, just return null (callers are
    // already prepared to handle a null icon, so the worst that can
    // happen is that an icon won't be included in the button/dialog).
    return null;
  }
コード例 #2
0
ファイル: GTKStyle.java プロジェクト: susotajuraj/jdk8u-jdk
 private Icon getStyleSpecificIcon(String key, TextDirection direction, int type) {
   UNIXToolkit tk = (UNIXToolkit) Toolkit.getDefaultToolkit();
   Image img = tk.getStockIcon(widgetType, key, type, direction.ordinal(), null);
   return (img != null) ? new ImageIcon(img) : null;
 }