Ejemplo n.º 1
0
 /** ****** popup AbstractAction.actionPerformed method overrides ******** */
 protected void rotateOrthogonal() {
   active.setRotation(active.getRotation() + 1, this);
   error.setRotation(error.getRotation() + 1, this);
   displayState();
   // bug fix, must repaint icons that have same width and height
   repaint();
 }
Ejemplo n.º 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);
    }
  }
Ejemplo n.º 3
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.º 4
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.º 5
0
 public void setScale(double s) {
   if (_namedIcon != null) {
     _namedIcon.scale(s, this);
     super.setIcon(_namedIcon);
     updateSize();
   }
 }
Ejemplo n.º 6
0
 protected void editIcon() {
   String url = _iconEditor.getIcon("plainIcon").getURL();
   _namedIcon = NamedIcon.getIconByName(url);
   super.setIcon(_namedIcon);
   updateSize();
   _iconEditorFrame.dispose();
   _iconEditorFrame = null;
   _iconEditor = null;
   invalidate();
 }
Ejemplo n.º 7
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));
 }
Ejemplo n.º 8
0
 public static NamedIcon cloneIcon(NamedIcon icon, PositionableLabel pos) {
   if (icon.getURL() != null) {
     return new NamedIcon(icon, pos);
   } else {
     NamedIcon clone = new NamedIcon(icon.getImage());
     clone.scale(icon.getScale(), pos);
     clone.rotate(icon.getDegrees(), pos);
     return clone;
   }
 }
Ejemplo n.º 9
0
 protected boolean mapsAreEqual(HashMap<String, NamedIcon> map1, HashMap<String, NamedIcon> map2) {
   if (map1.size() != map2.size()) {
     return false;
   }
   Iterator<Entry<String, NamedIcon>> iter = map1.entrySet().iterator();
   while (iter.hasNext()) {
     Entry<String, NamedIcon> ent = iter.next();
     NamedIcon icon = map2.get(ent.getKey());
     if (log.isDebugEnabled()) {
       log.debug(
           "key= "
               + ent.getKey()
               + ", url1= "
               + icon.getURL()
               + ", url2= "
               + ent.getValue().getURL());
     }
     if (icon == null || !icon.getURL().equals(ent.getValue().getURL())) {
       return false;
     }
   }
   return true;
 }
Ejemplo n.º 10
0
 private NamedIcon loadTurnoutIcon(
     String state, int rotation, TurnoutIcon l, Element element, String name, Editor ed) {
   NamedIcon icon = null;
   if (element.getAttribute(state) != null) {
     String iconName = element.getAttribute(state).getValue();
     icon = NamedIcon.getIconByName(iconName);
     if (icon == null) {
       icon = ed.loadFailed("Turnout \"" + name + "\" icon \"" + state + "\" ", iconName);
       if (icon == null) {
         log.info("Turnout \"" + name + "\" icon \"" + state + "\" removed for url= " + iconName);
       }
     } else {
       icon.setRotation(rotation, l);
     }
   } else {
     log.warn("did not locate " + state + " icon file for Turnout " + name);
   }
   if (icon == null) {
     log.info("Turnout Icon \"" + name + "\": icon \"" + state + "\" removed");
   } else {
     l.setIcon(_nameMap.get(state), icon);
   }
   return icon;
 }
Ejemplo n.º 11
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.º 12
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.º 13
0
 public void rotate(int deg) {
   active.rotate(deg, this);
   error.rotate(deg, this);
   displayState();
 }
Ejemplo n.º 14
0
 public void setScale(double s) {
   active.scale(s, this);
   error.scale(s, this);
   displayState();
 }
Ejemplo n.º 15
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;
  }
Ejemplo n.º 16
0
 protected void rotateOrthogonal() {
   _namedIcon.setRotation(_namedIcon.getRotation() + 1, this);
   super.setIcon(_namedIcon);
   updateSize();
   repaint();
 }