Example #1
0
  /**
   * Paints the specified component according to the Look and Feel.
   *
   * <p>This method is not used by Synth Look and Feel. Painting is handled by the {@link
   * #paint(SynthContext,Graphics)} method.
   *
   * @param g the {@code Graphics} object used for painting
   * @param c the component being painted
   * @see #paint(SynthContext,Graphics)
   */
  @Override
  public void paint(Graphics g, JComponent c) {
    SynthContext context = getContext(c);

    paint(context, g);
    context.dispose();
  }
Example #2
0
  static void updateStyle(JTextComponent comp, SynthContext context, String prefix) {
    SynthStyle style = context.getStyle();

    Color color = comp.getCaretColor();
    if (color == null || color instanceof UIResource) {
      comp.setCaretColor((Color) style.get(context, prefix + ".caretForeground"));
    }

    Color fg = comp.getForeground();
    if (fg == null || fg instanceof UIResource) {
      fg = style.getColorForState(context, ColorType.TEXT_FOREGROUND);
      if (fg != null) {
        comp.setForeground(fg);
      }
    }

    Object ar = style.get(context, prefix + ".caretAspectRatio");
    if (ar instanceof Number) {
      comp.putClientProperty("caretAspectRatio", ar);
    }

    context.setComponentState(SELECTED | FOCUSED);

    Color s = comp.getSelectionColor();
    if (s == null || s instanceof UIResource) {
      comp.setSelectionColor(style.getColor(context, ColorType.TEXT_BACKGROUND));
    }

    Color sfg = comp.getSelectedTextColor();
    if (sfg == null || sfg instanceof UIResource) {
      comp.setSelectedTextColor(style.getColor(context, ColorType.TEXT_FOREGROUND));
    }

    context.setComponentState(DISABLED);

    Color dfg = comp.getDisabledTextColor();
    if (dfg == null || dfg instanceof UIResource) {
      comp.setDisabledTextColor(style.getColor(context, ColorType.TEXT_FOREGROUND));
    }

    Insets margin = comp.getMargin();
    if (margin == null || margin instanceof UIResource) {
      margin = (Insets) style.get(context, prefix + ".margin");

      if (margin == null) {
        // Some places assume margins are non-null.
        margin = SynthLookAndFeel.EMPTY_UIRESOURCE_INSETS;
      }
      comp.setMargin(margin);
    }

    Caret caret = comp.getCaret();
    if (caret instanceof UIResource) {
      Object o = style.get(context, prefix + ".caretBlinkRate");
      if (o != null && o instanceof Integer) {
        Integer rate = (Integer) o;
        caret.setBlinkRate(rate.intValue());
      }
    }
  }
Example #3
0
  /** {@inheritDoc} */
  @Override
  public Dimension getMaximumSize(JComponent c) {
    if (c.getComponentCount() > 0 && c.getLayout() != null) {
      return null;
    }

    AbstractButton b = (AbstractButton) c;
    SynthContext ss = getContext(c);
    Dimension size =
        ss.getStyle()
            .getGraphicsUtils(ss)
            .getMaximumSize(
                ss,
                ss.getStyle().getFont(ss),
                b.getText(),
                getSizingIcon(b),
                b.getHorizontalAlignment(),
                b.getVerticalAlignment(),
                b.getHorizontalTextPosition(),
                b.getVerticalTextPosition(),
                b.getIconTextGap(),
                b.getDisplayedMnemonicIndex());

    return size;
  }
Example #4
0
  private void updateStyle(JComponent c) {
    SynthContext context = getContext(list, ENABLED);
    SynthStyle oldStyle = style;

    style = SynthLookAndFeel.updateStyle(context, this);

    if (style != oldStyle) {
      context.setComponentState(SELECTED);
      Color sbg = list.getSelectionBackground();
      if (sbg == null || sbg instanceof UIResource) {
        list.setSelectionBackground(style.getColor(context, ColorType.TEXT_BACKGROUND));
      }

      Color sfg = list.getSelectionForeground();
      if (sfg == null || sfg instanceof UIResource) {
        list.setSelectionForeground(style.getColor(context, ColorType.TEXT_FOREGROUND));
      }

      useListColors = style.getBoolean(context, "List.rendererUseListColors", true);
      useUIBorder = style.getBoolean(context, "List.rendererUseUIBorder", true);

      int height = style.getInt(context, "List.cellHeight", -1);
      if (height != -1) {
        list.setFixedCellHeight(height);
      }
      if (oldStyle != null) {
        uninstallKeyboardActions();
        installKeyboardActions();
      }
    }
    context.dispose();
  }
Example #5
0
  /**
   * Notifies this UI delegate to repaint the specified component. This method paints the component
   * background, then calls the {@link #paint(SynthContext,Graphics)} method.
   *
   * <p>In general, this method does not need to be overridden by subclasses. All Look and Feel
   * rendering code should reside in the {@code paint} method.
   *
   * @param g the {@code Graphics} object used for painting
   * @param c the component being painted
   * @see #paint(SynthContext,Graphics)
   */
  @Override
  public void update(Graphics g, JComponent c) {
    SynthContext context = getContext(c);

    SynthLookAndFeel.update(context, g);
    context.getPainter().paintScrollPaneBackground(context, g, 0, 0, c.getWidth(), c.getHeight());
    paint(context, g);
  }
  public void update(Graphics g, JComponent c) {
    SynthContext context = getContext(c);

    SynthLookAndFeel.update(context, g);
    paintBackground(context, g, c);
    paint(context, g);
    context.dispose();
  }
Example #7
0
  /** Returns the amount to shift the text/icon when painting. */
  private int getTextShiftOffset(SynthContext state) {
    AbstractButton button = (AbstractButton) state.getComponent();
    ButtonModel model = button.getModel();

    if (model.isArmed() && model.isPressed() && button.getPressedIcon() == null) {
      return state.getStyle().getInt(state, getPropertyPrefix() + "textShiftOffset", 0);
    }
    return 0;
  }
Example #8
0
 @Override
 public void installDefaults(SynthContext context) {
   super.installDefaults(context);
   if (!context.getRegion().isSubregion()) {
     context
         .getComponent()
         .putClientProperty(SwingUtilities2.AA_TEXT_PROPERTY_KEY, GTKLookAndFeel.aaTextInfo);
   }
 }
Example #9
0
  private void updateStyle(JTable c) {
    SynthContext context = getContext(c, ENABLED);
    SynthStyle oldStyle = style;
    style = SynthLookAndFeel.updateStyle(context, this);
    if (style != oldStyle) {
      context.setComponentState(ENABLED | SELECTED);

      Color sbg = table.getSelectionBackground();
      if (sbg == null || sbg instanceof UIResource) {
        table.setSelectionBackground(style.getColor(context, ColorType.TEXT_BACKGROUND));
      }

      Color sfg = table.getSelectionForeground();
      if (sfg == null || sfg instanceof UIResource) {
        table.setSelectionForeground(style.getColor(context, ColorType.TEXT_FOREGROUND));
      }

      context.setComponentState(ENABLED);

      Color gridColor = table.getGridColor();
      if (gridColor == null || gridColor instanceof UIResource) {
        gridColor = (Color) style.get(context, "Table.gridColor");
        if (gridColor == null) {
          gridColor = style.getColor(context, ColorType.FOREGROUND);
        }
        table.setGridColor(gridColor == null ? new ColorUIResource(Color.GRAY) : gridColor);
      }

      useTableColors = style.getBoolean(context, "Table.rendererUseTableColors", true);
      useUIBorder = style.getBoolean(context, "Table.rendererUseUIBorder", true);

      Object rowHeight = style.get(context, "Table.rowHeight");
      if (rowHeight != null) {
        LookAndFeel.installProperty(table, "rowHeight", rowHeight);
      }
      boolean showGrid = style.getBoolean(context, "Table.showGrid", true);
      if (!showGrid) {
        table.setShowGrid(false);
      }
      Dimension d = table.getIntercellSpacing();
      //            if (d == null || d instanceof UIResource) {
      if (d != null) {
        d = (Dimension) style.get(context, "Table.intercellSpacing");
      }
      alternateColor = (Color) style.get(context, "Table.alternateRowColor");
      if (d != null) {
        table.setIntercellSpacing(d);
      }

      if (oldStyle != null) {
        uninstallKeyboardActions();
        installKeyboardActions();
      }
    }
    context.dispose();
  }
Example #10
0
  /** @inheritDoc */
  @Override
  protected void uninstallDefaults() {
    super.uninstallDefaults();

    SynthContext context = getContext(list, ENABLED);

    style.uninstallDefaults(context);
    context.dispose();
    style = null;
  }
Example #11
0
 private void paintDragDivider(Graphics g, int x, int y, int w, int h) {
   SynthContext context = getContext(splitPane, Region.SPLIT_PANE_DIVIDER);
   context.setComponentState(((context.getComponentState() | MOUSE_OVER) ^ MOUSE_OVER) | PRESSED);
   Shape oldClip = g.getClip();
   g.clipRect(x, y, w, h);
   context
       .getPainter()
       .paintSplitPaneDragDivider(context, g, x, y, w, h, splitPane.getOrientation());
   g.setClip(oldClip);
   context.dispose();
 }
Example #12
0
 @Override
 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
   JComponent jc = (JComponent) c;
   SynthContext context = getContext(jc);
   SynthStyle style = context.getStyle();
   if (style == null) {
     assert false : "SynthBorder is being used outside after the " + " UI has been uninstalled";
     return;
   }
   context.getPainter().paintViewportBorder(context, g, x, y, width, height);
 }
Example #13
0
  /** {@inheritDoc} */
  @Override
  public int getBaseline(JComponent c, int width, int height) {
    if (c == null) {
      throw new NullPointerException("Component must be non-null");
    }
    if (width < 0 || height < 0) {
      throw new IllegalArgumentException("Width and height must be >= 0");
    }
    AbstractButton b = (AbstractButton) c;
    String text = b.getText();
    if (text == null || "".equals(text)) {
      return -1;
    }
    Insets i = b.getInsets();
    Rectangle viewRect = new Rectangle();
    Rectangle textRect = new Rectangle();
    Rectangle iconRect = new Rectangle();
    viewRect.x = i.left;
    viewRect.y = i.top;
    viewRect.width = width - (i.right + viewRect.x);
    viewRect.height = height - (i.bottom + viewRect.y);

    // layout the text and icon
    SynthContext context = getContext(b);
    FontMetrics fm = context.getComponent().getFontMetrics(context.getStyle().getFont(context));
    context
        .getStyle()
        .getGraphicsUtils(context)
        .layoutText(
            context,
            fm,
            b.getText(),
            b.getIcon(),
            b.getHorizontalAlignment(),
            b.getVerticalAlignment(),
            b.getHorizontalTextPosition(),
            b.getVerticalTextPosition(),
            viewRect,
            iconRect,
            textRect,
            b.getIconTextGap());
    View view = (View) b.getClientProperty(BasicHTML.propertyKey);
    int baseline;
    if (view != null) {
      baseline = BasicHTML.getHTMLBaseline(view, textRect.width, textRect.height);
      if (baseline >= 0) {
        baseline += textRect.y;
      }
    } else {
      baseline = textRect.y + fm.getAscent();
    }
    return baseline;
  }
Example #14
0
  /** Uninstalls the UI defaults. */
  @Override
  protected void uninstallDefaults() {
    SynthContext context = getContext(splitPane, ENABLED);

    style.uninstallDefaults(context);
    context.dispose();
    style = null;

    context = getContext(splitPane, Region.SPLIT_PANE_DIVIDER, ENABLED);
    dividerStyle.uninstallDefaults(context);
    context.dispose();
    dividerStyle = null;

    super.uninstallDefaults();
  }
  protected void uninstallDefaults() {
    SynthContext context = getContext(getComponent(), ENABLED);
    JComponent c = getComponent();
    c.putClientProperty("caretAspectRatio", null);

    style.uninstallDefaults(context);
    context.dispose();
    style = null;

    Object clientProperty = c.getClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES);
    if (clientProperty == localTrue) {
      getComponent().putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.FALSE);
    }
    super.uninstallDefaults();
  }
Example #16
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;
  }
Example #17
0
  private Insets getButtonInsets(SynthContext context, Insets insets) {
    // The following calculations are derived from gtkbutton.c
    // (GTK+ version 2.8.20), gtk_button_size_allocate() method.
    int CHILD_SPACING = 1;
    int focusSize = getClassSpecificIntValue(context, "focus-line-width", 1);
    int focusPad = getClassSpecificIntValue(context, "focus-padding", 1);
    int xThickness = getXThickness();
    int yThickness = getYThickness();
    int w = focusSize + focusPad + xThickness + CHILD_SPACING;
    int h = focusSize + focusPad + yThickness + CHILD_SPACING;
    insets.left = insets.right = w;
    insets.top = insets.bottom = h;

    Component component = context.getComponent();
    if ((component instanceof JButton)
        && !(component.getParent() instanceof JToolBar)
        && ((JButton) component).isDefaultCapable()) {
      // Include the default border insets, but only for JButtons
      // that are default capable.  Note that
      // JButton.getDefaultCapable() returns true by default, but
      // GtkToolButtons are never default capable, so we skip this
      // step if the button is contained in a toolbar.
      Insets defaultInsets =
          getClassSpecificInsetsValue(context, "default-border", BUTTON_DEFAULT_BORDER_INSETS);
      insets.left += defaultInsets.left;
      insets.right += defaultInsets.right;
      insets.top += defaultInsets.top;
      insets.bottom += defaultInsets.bottom;
    }

    return insets;
  }
  private void updateStyle(JTextComponent comp) {
    SynthContext context = getContext(comp, ENABLED);
    SynthStyle oldStyle = style;

    style = SynthLookAndFeel.updateStyle(context, this);

    if (style != oldStyle) {
      SynthTextFieldUI.updateStyle(comp, context, getPropertyPrefix());

      if (oldStyle != null) {
        uninstallKeyboardActions();
        installKeyboardActions();
      }
    }
    context.dispose();
  }
Example #19
0
 private Insets getSeparatorInsets(SynthContext context, Insets insets) {
   int horizPadding = 0;
   if (context.getRegion() == Region.POPUP_MENU_SEPARATOR) {
     horizPadding = getClassSpecificIntValue(context, "horizontal-padding", 3);
   }
   insets.right = insets.left = getXThickness() + horizPadding;
   insets.top = insets.bottom = getYThickness();
   return insets;
 }
Example #20
0
  private void updateStyle(JSplitPane splitPane) {
    SynthContext context = getContext(splitPane, Region.SPLIT_PANE_DIVIDER, ENABLED);
    SynthStyle oldDividerStyle = dividerStyle;
    dividerStyle = SynthLookAndFeel.updateStyle(context, this);
    context.dispose();

    context = getContext(splitPane, ENABLED);
    SynthStyle oldStyle = style;

    style = SynthLookAndFeel.updateStyle(context, this);

    if (style != oldStyle) {
      Object value = style.get(context, "SplitPane.size");
      if (value == null) {
        value = Integer.valueOf(6);
      }
      LookAndFeel.installProperty(splitPane, "dividerSize", value);

      value = style.get(context, "SplitPane.oneTouchExpandable");
      if (value != null) {
        LookAndFeel.installProperty(splitPane, "oneTouchExpandable", value);
      }

      if (divider != null) {
        splitPane.remove(divider);
        divider.setDividerSize(splitPane.getDividerSize());
      }
      if (oldStyle != null) {
        uninstallKeyboardActions();
        installKeyboardActions();
      }
    }
    if (style != oldStyle || dividerStyle != oldDividerStyle) {
      // Only way to force BasicSplitPaneDivider to reread the
      // necessary properties.
      if (divider != null) {
        splitPane.remove(divider);
      }
      divider = createDefaultDivider();
      divider.setBasicSplitPaneUI(this);
      splitPane.add(divider, JSplitPane.DIVIDER);
    }
    context.dispose();
  }
Example #21
0
  /** {@inheritDoc} */
  @Override
  protected void uninstallDefaults() {
    table.setDefaultRenderer(Date.class, dateRenderer);
    table.setDefaultRenderer(Number.class, numberRenderer);
    table.setDefaultRenderer(Double.class, doubleRender);
    table.setDefaultRenderer(Float.class, floatRenderer);
    table.setDefaultRenderer(Icon.class, iconRenderer);
    table.setDefaultRenderer(ImageIcon.class, imageIconRenderer);
    table.setDefaultRenderer(Boolean.class, booleanRenderer);
    table.setDefaultRenderer(Object.class, objectRenderer);

    if (table.getTransferHandler() instanceof UIResource) {
      table.setTransferHandler(null);
    }
    SynthContext context = getContext(table, ENABLED);
    style.uninstallDefaults(context);
    context.dispose();
    style = null;
  }
Example #22
0
    public void paintIcon(SynthContext context, Graphics g, int x, int y, int w, int h) {
      Icon icon = getIcon(context);

      if (icon != null) {
        if (context == null) {
          icon.paintIcon(null, g, x, y);
        } else {
          icon.paintIcon(context.getComponent(), g, x, y);
        }
      }
    }
Example #23
0
  protected Color getColorForState(SynthContext context, ColorType type) {
    if (type == ColorType.FOCUS || type == GTKColorType.BLACK) {
      return BLACK_COLOR;
    } else if (type == GTKColorType.WHITE) {
      return WHITE_COLOR;
    }

    Region id = context.getRegion();
    int state = context.getComponentState();
    state = GTKLookAndFeel.synthStateToGTKState(id, state);

    if (type == ColorType.TEXT_FOREGROUND
        && (id == Region.BUTTON
            || id == Region.CHECK_BOX
            || id == Region.CHECK_BOX_MENU_ITEM
            || id == Region.MENU
            || id == Region.MENU_ITEM
            || id == Region.RADIO_BUTTON
            || id == Region.RADIO_BUTTON_MENU_ITEM
            || id == Region.TABBED_PANE_TAB
            || id == Region.TOGGLE_BUTTON
            || id == Region.TOOL_TIP
            || id == Region.MENU_ITEM_ACCELERATOR
            || id == Region.TABBED_PANE_TAB)) {
      type = ColorType.FOREGROUND;
    } else if (id == Region.TABLE
        || id == Region.LIST
        || id == Region.TREE
        || id == Region.TREE_CELL) {
      if (type == ColorType.FOREGROUND) {
        type = ColorType.TEXT_FOREGROUND;
        if (state == SynthConstants.PRESSED) {
          state = SynthConstants.SELECTED;
        }
      } else if (type == ColorType.BACKGROUND) {
        type = ColorType.TEXT_BACKGROUND;
      }
    }

    return getStyleSpecificColor(context, state, type);
  }
Example #24
0
  /**
   * Paints the specified component.
   *
   * @param context context for the component being painted
   * @param g the {@code Graphics} object used for painting
   * @see #update(Graphics,JComponent)
   */
  protected void paint(SynthContext context, Graphics g) {
    AbstractButton b = (AbstractButton) context.getComponent();

    g.setColor(context.getStyle().getColor(context, ColorType.TEXT_FOREGROUND));
    g.setFont(style.getFont(context));
    context
        .getStyle()
        .getGraphicsUtils(context)
        .paintText(
            context,
            g,
            b.getText(),
            getIcon(b),
            b.getHorizontalAlignment(),
            b.getVerticalAlignment(),
            b.getHorizontalTextPosition(),
            b.getVerticalTextPosition(),
            b.getIconTextGap(),
            b.getDisplayedMnemonicIndex(),
            getTextShiftOffset(context));
  }
Example #25
0
  @Override
  public Color getColor(SynthContext context, ColorType type) {
    JComponent c = context.getComponent();
    Region id = context.getRegion();
    int state = context.getComponentState();

    if (c.getName() == "Table.cellRenderer") {
      if (type == ColorType.BACKGROUND) {
        return c.getBackground();
      }
      if (type == ColorType.FOREGROUND) {
        return c.getForeground();
      }
    }

    if (id == Region.LABEL && type == ColorType.TEXT_FOREGROUND) {
      type = ColorType.FOREGROUND;
    }

    // For the enabled state, prefer the widget's colors
    if (!id.isSubregion() && (state & SynthConstants.ENABLED) != 0) {
      if (type == ColorType.BACKGROUND) {
        return c.getBackground();
      } else if (type == ColorType.FOREGROUND) {
        return c.getForeground();
      } else if (type == ColorType.TEXT_FOREGROUND) {
        // If getForeground returns a non-UIResource it means the
        // developer has explicitly set the foreground, use it over
        // that of TEXT_FOREGROUND as that is typically the expected
        // behavior.
        Color color = c.getForeground();
        if (color != null && !(color instanceof UIResource)) {
          return color;
        }
      }
    }
    return getColorForState(context, type);
  }
Example #26
0
  /**
   * Returns the color for the specified state.
   *
   * @param context SynthContext identifying requestor
   * @param state to get the color for
   * @param type of the color
   * @return Color to render with
   */
  Color getGTKColor(SynthContext context, int state, ColorType type) {
    if (context != null) {
      JComponent c = context.getComponent();
      Region id = context.getRegion();

      state = GTKLookAndFeel.synthStateToGTKState(id, state);
      if (!id.isSubregion() && (state & SynthConstants.ENABLED) != 0) {
        if (type == ColorType.BACKGROUND || type == ColorType.TEXT_BACKGROUND) {
          Color bg = c.getBackground();
          if (!(bg instanceof UIResource)) {
            return bg;
          }
        } else if (type == ColorType.FOREGROUND || type == ColorType.TEXT_FOREGROUND) {
          Color fg = c.getForeground();
          if (!(fg instanceof UIResource)) {
            return fg;
          }
        }
      }
    }

    return getStyleSpecificColor(context, state, type);
  }
Example #27
0
    private Icon getIcon(SynthContext context) {
      if (context != null) {
        ComponentOrientation co = context.getComponent().getComponentOrientation();
        SynthStyle style = context.getStyle();

        if (style != this.style) {
          this.style = style;
          loadedLTR = loadedRTL = false;
        }
        if (co == null || co.isLeftToRight()) {
          if (!loadedLTR) {
            loadedLTR = true;
            ltrIcon = ((GTKStyle) context.getStyle()).getStockIcon(context, key, size);
          }
          return ltrIcon;
        } else if (!loadedRTL) {
          loadedRTL = true;
          rtlIcon = ((GTKStyle) context.getStyle()).getStockIcon(context, key, size);
        }
        return rtlIcon;
      }
      return ltrIcon;
    }
Example #28
0
 /**
  * Returns the value to initialize the opacity property of the Component to. A Style should NOT
  * assume the opacity will remain this value, the developer may reset it or override it.
  *
  * @param context SynthContext identifying requestor
  * @return opaque Whether or not the JComponent is opaque.
  */
 @Override
 public boolean isOpaque(SynthContext context) {
   Region region = context.getRegion();
   if (region == Region.COMBO_BOX
       || region == Region.DESKTOP_PANE
       || region == Region.DESKTOP_ICON
       || region == Region.EDITOR_PANE
       || region == Region.FORMATTED_TEXT_FIELD
       || region == Region.INTERNAL_FRAME
       || region == Region.LIST
       || region == Region.MENU_BAR
       || region == Region.PANEL
       || region == Region.PASSWORD_FIELD
       || region == Region.POPUP_MENU
       || region == Region.PROGRESS_BAR
       || region == Region.ROOT_PANE
       || region == Region.SCROLL_PANE
       || region == Region.SPINNER
       || region == Region.SPLIT_PANE_DIVIDER
       || region == Region.TABLE
       || region == Region.TEXT_AREA
       || region == Region.TEXT_FIELD
       || region == Region.TEXT_PANE
       || region == Region.TOOL_BAR_DRAG_WINDOW
       || region == Region.TOOL_TIP
       || region == Region.TREE
       || region == Region.VIEWPORT) {
     return true;
   }
   Component c = context.getComponent();
   String name = c.getName();
   if (name == "ComboBox.renderer" || name == "ComboBox.listRenderer") {
     return true;
   }
   return false;
 }
Example #29
0
  /*
   * This is used for both RADIO_BUTTON and CHECK_BOX.
   */
  private Insets getRadioInsets(SynthContext context, Insets insets) {
    // The following calculations are derived from gtkcheckbutton.c
    // (GTK+ version 2.8.20), gtk_check_button_size_allocate() method.
    int focusSize = getClassSpecificIntValue(context, "focus-line-width", 1);
    int focusPad = getClassSpecificIntValue(context, "focus-padding", 1);
    int totalFocus = focusSize + focusPad;

    // Note: GTKIconFactory.DelegateIcon will have already included the
    // "indicator-spacing" value in the size of the indicator icon,
    // which explains why we use zero as the left inset (or right inset
    // in the RTL case); see 6489585 for more details.
    insets.top = totalFocus;
    insets.bottom = totalFocus;
    if (context.getComponent().getComponentOrientation().isLeftToRight()) {
      insets.left = 0;
      insets.right = totalFocus;
    } else {
      insets.left = totalFocus;
      insets.right = 0;
    }

    return insets;
  }
Example #30
0
  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;
  }