Ejemplo n.º 1
0
 public void rotate(int deg) {
   log.debug("rotate({}) with _rotateText {}, _text {}, _icon {}", deg, _rotateText, _text, _icon);
   _degrees = deg;
   if (_rotateText || deg == 0) {
     if (deg == 0) { // restore unrotated whatever
       _rotateText = false;
       if (_text) {
         log.debug("   super.setText(\"{}\");", _unRotatedText);
         super.setText(_unRotatedText);
         if (_popupUtil != null) {
           setOpaque(_popupUtil.hasBackground());
           _popupUtil.setBorder(true);
         }
         if (_icon) {
           String url = _namedIcon.getURL();
           _namedIcon = new NamedIcon(url, url);
         } else {
           _namedIcon = null;
         }
         super.setIcon(_namedIcon);
       } else {
         _namedIcon.rotate(deg, this);
         super.setIcon(_namedIcon);
       }
     } else {
       if (_text & _icon) { // update text over icon
         _namedIcon = makeTextOverlaidIcon(_unRotatedText, _namedIcon);
       } else if (_text) { // update text only icon image
         _namedIcon = makeTextIcon(_unRotatedText);
       }
       _namedIcon.rotate(deg, this);
       super.setIcon(_namedIcon);
       setOpaque(false); // rotations cannot be opaque
     }
   } else {
     if (deg != 0) { // first time text or icon is rotated from horizontal
       if (_text && _icon) { // text overlays icon  e.g. LocoIcon
         _namedIcon = makeTextOverlaidIcon(_unRotatedText, _namedIcon);
         super.setText(null);
         _rotateText = true;
         setOpaque(false);
       } else if (_text) {
         _namedIcon = makeTextIcon(_unRotatedText);
         super.setText(null);
         _rotateText = true;
         setOpaque(false);
       }
       if (_popupUtil != null) {
         _popupUtil.setBorder(false);
       }
       _namedIcon.rotate(deg, this);
       super.setIcon(_namedIcon);
     } else if (_namedIcon != null) {
       _namedIcon.rotate(deg, this);
       super.setIcon(_namedIcon);
     }
   }
   updateSize();
 }
Ejemplo n.º 2
0
 public int maxHeightTrue() {
   int max = 0;
   if (_popupUtil != null && _popupUtil.getFixedHeight() != 0) {
     max = _popupUtil.getFixedHeight();
     max += _popupUtil.getBorderSize() * 2;
     if (max < PositionablePopupUtil.MIN_SIZE) { // don't let item disappear
       _popupUtil.setFixedHeight(PositionablePopupUtil.MIN_SIZE);
     }
   } else {
     // if(_text) {
     if (_text && getText() != null && getFont() != null) {
       max = getFontMetrics(getFont()).getHeight();
     }
     if (_icon && _namedIcon != null) {
       max = Math.max(_namedIcon.getIconHeight(), max);
     }
     if (_text && _popupUtil != null) {
       max += _popupUtil.getMargin() * 2;
       max += _popupUtil.getBorderSize() * 2;
     }
     if (max < PositionablePopupUtil.MIN_SIZE) { // don't let item disappear
       max = PositionablePopupUtil.MIN_SIZE;
     }
   }
   if (debug) {
     log.trace("maxHeight= " + max + " preferred height= " + getPreferredSize().height);
   }
   return max;
 }
Ejemplo n.º 3
0
 public int maxHeight() {
   if (_rotateText && _namedIcon != null) {
     return _namedIcon.getIconHeight();
   }
   if (_popupUtil == null) {
     return maxHeightTrue();
   }
   switch (_popupUtil.getOrientation()) {
     case PositionablePopupUtil.VERTICAL_DOWN:
     case PositionablePopupUtil.VERTICAL_UP:
       return maxWidthTrue();
     default:
       return maxHeightTrue();
   }
 }
Ejemplo n.º 4
0
  @Override
  public Dimension getSize() {
    if (!needsRotate) {
      return super.getSize();
    }

    Dimension size = super.getSize();
    if (_popupUtil == null) {
      return super.getSize();
    }
    switch (_popupUtil.getOrientation()) {
      case PositionablePopupUtil.VERTICAL_DOWN:
      case PositionablePopupUtil.VERTICAL_UP:
        return new Dimension(size.height, size.width);
      default:
        return super.getSize();
    }
  }
Ejemplo n.º 5
0
  @Override
  protected void paintComponent(Graphics g) {
    if (_popupUtil == null) {
      super.paintComponent(g);
    } else {
      Graphics2D gr = (Graphics2D) g.create();

      switch (_popupUtil.getOrientation()) {
        case PositionablePopupUtil.VERTICAL_UP:
          gr.translate(0, getSize().getHeight());
          gr.transform(AffineTransform.getQuadrantRotateInstance(-1));
          break;
        case PositionablePopupUtil.VERTICAL_DOWN:
          gr.transform(AffineTransform.getQuadrantRotateInstance(1));
          gr.translate(0, -getSize().getWidth());
          break;
        default:
      }

      needsRotate = true;
      super.paintComponent(gr);
      needsRotate = false;
    }
  }
Ejemplo n.º 6
0
 public int maxWidthTrue() {
   int max = 0;
   if (_popupUtil != null && _popupUtil.getFixedWidth() != 0) {
     max = _popupUtil.getFixedWidth();
     max += _popupUtil.getBorderSize() * 2;
     if (max < PositionablePopupUtil.MIN_SIZE) { // don't let item disappear
       _popupUtil.setFixedWidth(PositionablePopupUtil.MIN_SIZE);
       max = PositionablePopupUtil.MIN_SIZE;
     }
   } else {
     if (_text && getText() != null) {
       if (getText().trim().length() == 0) {
         // show width of 1 blank character
         if (getFont() != null) {
           max = getFontMetrics(getFont()).stringWidth("0");
         }
       } else {
         max = getFontMetrics(getFont()).stringWidth(getText());
       }
     }
     if (_icon && _namedIcon != null) {
       max = Math.max(_namedIcon.getIconWidth(), max);
     }
     if (_text && _popupUtil != null) {
       max += _popupUtil.getMargin() * 2;
       max += _popupUtil.getBorderSize() * 2;
     }
     if (max < PositionablePopupUtil.MIN_SIZE) { // don't let item disappear
       max = PositionablePopupUtil.MIN_SIZE;
     }
   }
   if (debug) {
     log.trace("maxWidth= " + max + " preferred width= " + getPreferredSize().width);
   }
   return max;
 }
Ejemplo n.º 7
0
  /**
   * create a text image whose bit map can be rotated
   *
   * @param text
   * @return
   */
  private NamedIcon makeTextIcon(String text) {
    if (text == null || text.equals("")) {
      text = " ";
    }
    int width = getFontMetrics(getFont()).stringWidth(text);
    int height = getFontMetrics(getFont()).getHeight();
    int hOffset = 0;
    int vOffset = getFontMetrics(getFont()).getAscent();
    if (_popupUtil != null) {
      if (_popupUtil.getFixedWidth() != 0) {
        switch (_popupUtil.getJustification()) {
          case PositionablePopupUtil.LEFT:
            hOffset = _popupUtil.getBorderSize();
            break;
          case PositionablePopupUtil.RIGHT:
            hOffset = _popupUtil.getFixedWidth() - width;
            hOffset += _popupUtil.getBorderSize();
            break;
          default:
            hOffset = Math.max((_popupUtil.getFixedWidth() - width) / 2, 0);
            hOffset += _popupUtil.getBorderSize();
            break;
        }
        width = _popupUtil.getFixedWidth() + 2 * _popupUtil.getBorderSize();
      } else {
        width += 2 * (_popupUtil.getMargin() + _popupUtil.getBorderSize());
        hOffset += _popupUtil.getMargin() + _popupUtil.getBorderSize();
      }
      if (_popupUtil.getFixedHeight() != 0) {
        vOffset = Math.max(vOffset + (_popupUtil.getFixedHeight() - height) / 2, 0);
        vOffset += _popupUtil.getBorderSize();
        height = _popupUtil.getFixedHeight() + 2 * _popupUtil.getBorderSize();
      } else {
        height += 2 * (_popupUtil.getMargin() + _popupUtil.getBorderSize());
        vOffset += _popupUtil.getMargin() + _popupUtil.getBorderSize();
      }
    }
    BufferedImage bufIm = new BufferedImage(width + 2, height + 2, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = bufIm.createGraphics();
    g2d.setFont(getFont());
    g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setRenderingHint(
        RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
    g2d.setRenderingHint(
        RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);

    if (_popupUtil != null) {
      if (_popupUtil.hasBackground()) {
        g2d.setColor(_popupUtil.getBackground());
        g2d.fillRect(0, 0, width, height);
      }
      if (_popupUtil.getBorderSize() != 0) {
        g2d.setColor(_popupUtil.getBorderColor());
        g2d.setStroke(new java.awt.BasicStroke(2 * _popupUtil.getBorderSize()));
        g2d.drawRect(0, 0, width, height);
      }
    }
    g2d.setColor(getForeground());
    g2d.drawString(text, hOffset, vOffset);
    NamedIcon icon = new NamedIcon(bufIm);
    g2d.dispose();
    return icon;
  }
Ejemplo n.º 8
0
  /** Create an image of icon with text overlaid */
  protected NamedIcon makeTextOverlaidIcon(String text, NamedIcon ic) {
    String url = ic.getURL();
    NamedIcon icon = new NamedIcon(url, url);
    int textWidth = getFontMetrics(getFont()).stringWidth(text);
    int iconWidth = icon.getIconWidth();
    int textHeight = getFontMetrics(getFont()).getHeight();
    int iconHeight = icon.getIconHeight();

    int width = Math.max(textWidth, iconWidth);
    int height = Math.max(textHeight, iconHeight);
    int hOffset = Math.max((textWidth - iconWidth) / 2, 0);
    int vOffset = Math.max((textHeight - iconHeight) / 2, 0);

    if (_popupUtil != null) {
      if (_popupUtil.getFixedWidth() != 0) {
        switch (_popupUtil.getJustification()) {
          case PositionablePopupUtil.LEFT:
            hOffset = _popupUtil.getBorderSize();
            break;
          case PositionablePopupUtil.RIGHT:
            hOffset = _popupUtil.getFixedWidth() - width;
            hOffset += _popupUtil.getBorderSize();
            break;
          default:
            hOffset = Math.max((_popupUtil.getFixedWidth() - width) / 2, 0);
            hOffset += _popupUtil.getBorderSize();
            break;
        }
        width = _popupUtil.getFixedWidth() + 2 * _popupUtil.getBorderSize();
      } else {
        width += 2 * (_popupUtil.getMargin() + _popupUtil.getBorderSize());
        hOffset += _popupUtil.getMargin() + _popupUtil.getBorderSize();
      }
      if (_popupUtil.getFixedHeight() != 0) {
        vOffset = Math.max(vOffset + (_popupUtil.getFixedHeight() - height) / 2, 0);
        vOffset += _popupUtil.getBorderSize();
        height = _popupUtil.getFixedHeight() + 2 * _popupUtil.getBorderSize();
      } else {
        height += 2 * (_popupUtil.getMargin() + _popupUtil.getBorderSize());
        vOffset += _popupUtil.getMargin() + _popupUtil.getBorderSize();
      }
    }

    BufferedImage bufIm = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = bufIm.createGraphics();
    g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setRenderingHint(
        RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
    g2d.setRenderingHint(
        RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);

    if (_popupUtil != null) {
      if (_popupUtil.hasBackground()) {
        g2d.setColor(_popupUtil.getBackground());
        g2d.fillRect(0, 0, width, height);
      }
      if (_popupUtil.getBorderSize() != 0) {
        g2d.setColor(_popupUtil.getBorderColor());
        g2d.setStroke(new java.awt.BasicStroke(2 * _popupUtil.getBorderSize()));
        g2d.drawRect(0, 0, width, height);
      }
    }

    g2d.drawImage(
        icon.getImage(), AffineTransform.getTranslateInstance(hOffset, vOffset + 1), this);
    g2d.setFont(getFont());

    hOffset = Math.max((width - textWidth) / 2, 0);
    vOffset = Math.max((height - textHeight) / 2, 0) + getFontMetrics(getFont()).getAscent();
    g2d.setColor(getForeground());
    g2d.drawString(text, hOffset, vOffset);

    icon = new NamedIcon(bufIm);
    g2d.dispose();
    icon.setURL(url);
    return icon;
  }