Package org.pushingpixels.flamingo.api.common.icon

Examples of org.pushingpixels.flamingo.api.common.icon.ResizableIcon


      return;
    }
  }

  protected void syncDisabledIcon() {
    ResizableIcon currDisabledIcon = this.commandButton.getDisabledIcon();
    ResizableIcon icon = this.commandButton.getIcon();
    if ((currDisabledIcon == null)
        || (currDisabledIcon instanceof UIResource)) {
      if (icon != null) {
        this.commandButton.setDisabledIcon(new ResizableIconUIResource(
            new FilteredResizableIcon(icon, new ColorConvertOp(
                ColorSpace.getInstance(ColorSpace.CS_GRAY),
                null))));
      } else {
        this.commandButton.setDisabledIcon(null);
      }
    } else {
      // disabled icon coming from app code
      if (icon != null) {
        this.commandButton.getDisabledIcon()
            .setDimension(
                new Dimension(icon.getIconWidth(), icon
                    .getIconHeight()));
      }
    }
  }
View Full Code Here


      }
    }
  }

  protected void syncIconDimension() {
    ResizableIcon icon = this.commandButton.getIcon();
    CommandButtonDisplayState commandButtonState = this.commandButton
        .getDisplayState();

    this.layoutManager = commandButtonState
        .createLayoutManager(this.commandButton);

    if (icon == null)
      return;

    int maxHeight = layoutManager.getPreferredIconSize();
    if (maxHeight < 0) {
      maxHeight = this.commandButton.getIcon().getIconHeight();
    }

    if (commandButtonState != CommandButtonDisplayState.FIT_TO_ICON) {
      Dimension newDim = new Dimension(maxHeight, maxHeight);
      icon.setDimension(newDim);
    }
  }
View Full Code Here

    int title1Width = (this.titlePart1 == null) ? 0 : fm
        .stringWidth(this.titlePart1);
    int title2Width = (this.titlePart2 == null) ? 0 : fm
        .stringWidth(this.titlePart2);

    ResizableIcon icon = commandButton.getIcon();
    int iconWidth = (icon == null) ? 0 : icon.getIconWidth();
    int width = Math.max(iconWidth, Math.max(title1Width, title2Width
        + 4
        * layoutHGap
        + jsep.getPreferredSize().width
        + (FlamingoUtilities.hasPopupAction(commandButton) ? 1 + fm
            .getHeight() / 2 : 0)));

    boolean hasIcon = (commandButton.getIcon() != null);
    boolean hasText = (this.titlePart1 != null);
    boolean hasPopupIcon = FlamingoUtilities.hasPopupAction(commandButton);

    // start height with the top inset
    int height = borderInsets.top;
    // icon?
    if (hasIcon) {
      // padding above the icon
      height += layoutVGap;
      // icon height
      height += icon.getIconHeight();
      // padding below the icon
      height += layoutVGap;
    }
    // text?
    if (hasText) {
View Full Code Here

  @Override
  public Point getKeyTipAnchorCenterPoint(AbstractCommandButton commandButton) {
    Insets ins = commandButton.getInsets();
    int height = commandButton.getHeight();
    ResizableIcon buttonIcon = commandButton.getIcon();
    if (buttonIcon != null) {
      // bottom-right corner of the icon area
      return new Point(ins.left + buttonIcon.getIconWidth(),
          (height + buttonIcon.getIconHeight()) / 2);
    } else {
      // bottom-left corner of the button
      return new Point(ins.left, 3 * height / 4);
    }
  }
View Full Code Here

      if (width > prefWidth) {
        shiftX = (width - prefWidth) / 2;
      }
    }

    ResizableIcon buttonIcon = commandButton.getIcon();
    String buttonText = commandButton.getText();
    String buttonExtraText = commandButton.getExtraText();

    boolean hasIcon = (buttonIcon != null);
    boolean hasText = (buttonText != null) || (buttonExtraText != null);
    boolean hasPopupIcon = FlamingoUtilities.hasPopupAction(commandButton);

    boolean ltr = commandButton.getComponentOrientation().isLeftToRight();

    FontMetrics fm = g.getFontMetrics();
    int labelHeight = fm.getAscent() + fm.getDescent();

    JCommandButton.CommandButtonKind buttonKind = (commandButton instanceof JCommandButton) ? ((JCommandButton) commandButton)
        .getCommandButtonKind()
        : JCommandButton.CommandButtonKind.ACTION_ONLY;
    int layoutHGap = FlamingoUtilities.getHLayoutGap(commandButton);

    if (ltr) {
      int x = ins.left + shiftX - layoutHGap;

      // icon
      if (hasIcon) {
        x += layoutHGap;

        int iconHeight = buttonIcon.getIconHeight();
        int iconWidth = buttonIcon.getIconWidth();

        result.iconRect.x = x;
        result.iconRect.y = (height - iconHeight) / 2;
        result.iconRect.width = iconWidth;
        result.iconRect.height = iconHeight;

        x += (iconWidth + layoutHGap);
      }

      // text
      if (hasText) {
        x += layoutHGap;

        TextLayoutInfo lineLayoutInfo = new TextLayoutInfo();
        lineLayoutInfo.text = commandButton.getText();
        lineLayoutInfo.textRect = new Rectangle();

        lineLayoutInfo.textRect.x = x;
        lineLayoutInfo.textRect.y = (height - 2 * labelHeight) / 2;
        lineLayoutInfo.textRect.width = (buttonText == null) ? 0
            : (int) fm.getStringBounds(buttonText, g).getWidth();
        lineLayoutInfo.textRect.height = labelHeight;

        result.textLayoutInfoList = new ArrayList<TextLayoutInfo>();
        result.textLayoutInfoList.add(lineLayoutInfo);

        String extraText = commandButton.getExtraText();

        TextLayoutInfo extraLineLayoutInfo = new TextLayoutInfo();
        extraLineLayoutInfo.text = extraText;
        extraLineLayoutInfo.textRect = new Rectangle();

        extraLineLayoutInfo.textRect.x = x;
        extraLineLayoutInfo.textRect.y = lineLayoutInfo.textRect.y
            + labelHeight;
        extraLineLayoutInfo.textRect.width = (extraText == null) ? 0
            : (int) fm.getStringBounds(extraText, g).getWidth();
        extraLineLayoutInfo.textRect.height = labelHeight;

        result.extraTextLayoutInfoList = new ArrayList<TextLayoutInfo>();
        result.extraTextLayoutInfoList.add(extraLineLayoutInfo);

        x += Math.max(lineLayoutInfo.textRect.width,
            extraLineLayoutInfo.textRect.width);

        x += layoutHGap;
      }

      if (hasPopupIcon) {
        x += 2 * layoutHGap;

        result.popupActionRect.x = x;
        result.popupActionRect.y = (height - labelHeight) / 2 - 1;
        result.popupActionRect.width = 1 + labelHeight / 2;
        result.popupActionRect.height = labelHeight + 2;
        x += result.popupActionRect.width;

        x += 2 * layoutHGap;
      }

      int xBorderBetweenActionAndPopup = 0;
      int verticalSeparatorWidth = new JSeparator(JSeparator.VERTICAL)
          .getPreferredSize().width;
      // compute the action and popup click areas
      switch (buttonKind) {
      case ACTION_ONLY:
        result.actionClickArea.x = 0;
        result.actionClickArea.y = 0;
        result.actionClickArea.width = width;
        result.actionClickArea.height = height;
        result.isTextInActionArea = true;
        break;
      case POPUP_ONLY:
        result.popupClickArea.x = 0;
        result.popupClickArea.y = 0;
        result.popupClickArea.width = width;
        result.popupClickArea.height = height;
        result.isTextInActionArea = false;
        break;
      case ACTION_AND_POPUP_MAIN_ACTION:
        // 1. break before popup icon if button has text or icon
        // 2. no break (all popup) if button has no text and no icon
        if (hasText || hasIcon) {
          // shift popup action rectangle to the right to
          // accomodate the vertical separator
          result.popupActionRect.x += verticalSeparatorWidth;

          xBorderBetweenActionAndPopup = result.popupActionRect.x - 2
              * layoutHGap;

          result.actionClickArea.x = 0;
          result.actionClickArea.y = 0;
          result.actionClickArea.width = xBorderBetweenActionAndPopup;
          result.actionClickArea.height = height;

          result.popupClickArea.x = xBorderBetweenActionAndPopup;
          result.popupClickArea.y = 0;
          result.popupClickArea.width = width
              - xBorderBetweenActionAndPopup;
          result.popupClickArea.height = height;

          result.separatorOrientation = CommandButtonSeparatorOrientation.VERTICAL;
          result.separatorArea = new Rectangle();
          result.separatorArea.x = xBorderBetweenActionAndPopup;
          result.separatorArea.y = 0;
          result.separatorArea.width = verticalSeparatorWidth;
          result.separatorArea.height = height;

          result.isTextInActionArea = true;
        } else {
          result.popupClickArea.x = 0;
          result.popupClickArea.y = 0;
          result.popupClickArea.width = width;
          result.popupClickArea.height = height;

          result.isTextInActionArea = true;
        }
        break;
      case ACTION_AND_POPUP_MAIN_POPUP:
        // 1. break after icon if button has icon
        // 2. no break (all popup) if button has no icon
        if (hasIcon) {
          // shift text rectangles and popup action rectangle to the
          // right
          // to accomodate the vertical separator
          if (result.textLayoutInfoList != null) {
            for (TextLayoutInfo textLayoutInfo : result.textLayoutInfoList) {
              textLayoutInfo.textRect.x += verticalSeparatorWidth;
            }
          }
          if (result.extraTextLayoutInfoList != null) {
            for (TextLayoutInfo extraTextLayoutInfo : result.extraTextLayoutInfoList) {
              extraTextLayoutInfo.textRect.x += verticalSeparatorWidth;
            }
          }
          result.popupActionRect.x += verticalSeparatorWidth;

          xBorderBetweenActionAndPopup = result.iconRect.x
              + result.iconRect.width + layoutHGap;

          result.actionClickArea.x = 0;
          result.actionClickArea.y = 0;
          result.actionClickArea.width = xBorderBetweenActionAndPopup;
          result.actionClickArea.height = height;

          result.popupClickArea.x = xBorderBetweenActionAndPopup;
          result.popupClickArea.y = 0;
          result.popupClickArea.width = width
              - xBorderBetweenActionAndPopup;
          result.popupClickArea.height = height;

          result.separatorOrientation = CommandButtonSeparatorOrientation.VERTICAL;
          result.separatorArea = new Rectangle();
          result.separatorArea.x = xBorderBetweenActionAndPopup;
          result.separatorArea.y = 0;
          result.separatorArea.width = verticalSeparatorWidth;
          result.separatorArea.height = height;

          result.isTextInActionArea = true;
        } else {
          result.popupClickArea.x = 0;
          result.popupClickArea.y = 0;
          result.popupClickArea.width = width;
          result.popupClickArea.height = height;

          result.isTextInActionArea = true;
        }
        break;
      }
    } else {
      int x = width - ins.right - shiftX + layoutHGap;

      // icon
      if (hasIcon) {
        x -= layoutHGap;

        int iconHeight = buttonIcon.getIconHeight();
        int iconWidth = buttonIcon.getIconWidth();

        result.iconRect.x = x - iconWidth;
        result.iconRect.y = (height - iconHeight) / 2;
        result.iconRect.width = iconWidth;
        result.iconRect.height = iconHeight;
View Full Code Here

   * Installs subcomponents on the associated command button.
   */
  protected void installComponents() {
    this.updatePopupActionIcon();

    ResizableIcon buttonIcon = this.commandButton.getIcon();
    if (buttonIcon instanceof AsynchronousLoading) {
      ((AsynchronousLoading) buttonIcon)
          .addAsynchronousLoadListener(new AsynchronousLoadListener() {
            @Override
                        public void completed(boolean success) {
View Full Code Here

      return;
    }
  }

  protected void syncDisabledIcon() {
    ResizableIcon currDisabledIcon = this.commandButton.getDisabledIcon();
    ResizableIcon icon = this.commandButton.getIcon();
    if ((currDisabledIcon == null)
        || (currDisabledIcon instanceof UIResource)) {
      if (icon != null) {
        this.commandButton.setDisabledIcon(new ResizableIconUIResource(
            new FilteredResizableIcon(icon, new ColorConvertOp(
                ColorSpace.getInstance(ColorSpace.CS_GRAY),
                null))));
      } else {
        this.commandButton.setDisabledIcon(null);
      }
    } else {
      // disabled icon coming from app code
      if (icon != null) {
        this.commandButton.getDisabledIcon()
            .setDimension(
                new Dimension(icon.getIconWidth(), icon
                    .getIconHeight()));
      }
    }
  }
View Full Code Here

   * @see #getApplicationIcon()
   * @param applicationIcon
   *            the application icon to set
   */
  public synchronized void setApplicationIcon(ResizableIcon applicationIcon) {
    ResizableIcon old = getUI().getApplicationIcon();
    getUI().setApplicationIcon(applicationIcon);
    firePropertyChange(PROPERTY_APPLICATION_ICON, old, this.applicationIcon);
    // TODO set the application menu button icon
    // JRibbonApplicationMenuButton button = getApplicationMenuButton();
    // if (button != null) {
View Full Code Here

      }
    }
  }

  protected void syncIconDimension() {
    ResizableIcon icon = this.commandButton.getIcon();
    CommandButtonDisplayState commandButtonState = this.commandButton
        .getDisplayState();

    this.layoutManager = commandButtonState
        .createLayoutManager(this.commandButton);

    if (icon == null)
      return;

    int maxHeight = layoutManager.getPreferredIconSize();
    if (maxHeight < 0) {
      maxHeight = this.commandButton.getIcon().getIconHeight();
    }

    if (commandButtonState != CommandButtonDisplayState.FIT_TO_ICON) {
      Dimension newDim = new Dimension(maxHeight, maxHeight);
      icon.setDimension(newDim);
    }
  }
View Full Code Here

     * @see #AbstractRibbonBand(String, ResizableIcon, ActionListener,
     *      AbstractBandControlPanel)
     * @see #getIcon()
     */
    public void setIcon(ResizableIcon icon) {
        ResizableIcon old = this.icon;
        this.icon = icon;
        this.firePropertyChange("icon", old, this.icon);
    }
View Full Code Here

TOP

Related Classes of org.pushingpixels.flamingo.api.common.icon.ResizableIcon

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.