예제 #1
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;
 }
예제 #2
0
  protected void addIconsToPanel(HashMap<String, NamedIcon> iconMap) {
    if (iconMap == null) {
      log.warn("iconMap is null for type " + _itemType + " family " + _family);
      return;
    }
    GridBagLayout gridbag = new GridBagLayout();
    _iconPanel.setLayout(gridbag);

    int numCol = 4;
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.CENTER;
    c.weightx = 1.0;
    c.weighty = 1.0;
    c.gridwidth = 1;
    c.gridheight = 1;
    c.gridx = -1;
    c.gridy = 0;

    int cnt = iconMap.size();
    Iterator<Entry<String, NamedIcon>> it = iconMap.entrySet().iterator();
    while (it.hasNext()) {
      Entry<String, NamedIcon> entry = it.next();
      NamedIcon icon = new NamedIcon(entry.getValue()); // make copy for possible reduction
      icon.reduceTo(100, 100, 0.2);
      JPanel panel = new JPanel(new FlowLayout());
      String borderName = getIconBorderName(entry.getKey());
      panel.setBorder(
          BorderFactory.createTitledBorder(
              BorderFactory.createLineBorder(Color.black), borderName));
      JLabel image = new JLabel(icon);
      if (icon.getIconWidth() < 1 || icon.getIconHeight() < 1) {
        image.setText(Bundle.getMessage("invisibleIcon"));
        image.setForeground(Color.lightGray);
      }
      image.setToolTipText(icon.getName());
      panel.add(image);
      int width = Math.max(100, panel.getPreferredSize().width);
      panel.setPreferredSize(new java.awt.Dimension(width, panel.getPreferredSize().height));
      c.gridx += 1;
      if (c.gridx >= numCol) { // start next row
        c.gridy++;
        c.gridx = 0;
        if (cnt < numCol - 1) { // last row
          JPanel p = new JPanel(new FlowLayout());
          p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
          p.add(Box.createHorizontalStrut(100));
          gridbag.setConstraints(p, c);
          // if (log.isDebugEnabled()) log.debug("addIconsToPanel: gridx= "+c.gridx+" gridy=
          // "+c.gridy);
          _iconPanel.add(p);
          c.gridx = 1;
        }
      }
      cnt--;
      gridbag.setConstraints(panel, c);
      _iconPanel.add(panel);
    }
  }
예제 #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();
   }
 }
예제 #4
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;
  }