Esempio n. 1
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);
    }
  }
Esempio n. 2
0
 public PositionableLabel(NamedIcon s, Editor editor) {
   super(s);
   _editor = editor;
   _icon = true;
   _namedIcon = s;
   debug = log.isDebugEnabled();
   if (debug) {
     log.debug("PositionableLabel ctor (icon) " + s.getName());
   }
   setPopupUtility(new PositionablePopupUtil(this, this));
 }