001package jmri.jmrit.display.controlPanelEditor.shape;
002
003import java.awt.Shape;
004import java.awt.event.ActionEvent;
005import java.awt.geom.RoundRectangle2D;
006import javax.swing.JPopupMenu;
007import jmri.jmrit.display.Editor;
008import jmri.jmrit.display.Positionable;
009
010/**
011 * PositionableRoundRect adds corner radii to PositionableShapes.
012 *
013 * @author Pete cresman Copyright (c) 2012
014 */
015public class PositionableRoundRect extends PositionableRectangle {
016
017    protected int _radius = 40;
018
019    public PositionableRoundRect(Editor editor) {
020        super(editor);
021    }
022
023    public PositionableRoundRect(Editor editor, Shape shape) {
024        super(editor, shape);
025    }
026
027    public void setCornerRadius(int r) {
028        _radius = r;
029        invalidateShape();
030    }
031
032    public int getCornerRadius() {
033        return _radius;
034    }
035
036    @Override
037    protected Shape makeShape() {
038        return new RoundRectangle2D.Double(0, 0, _width, _height, _radius, _radius);
039    }
040
041    @Override
042    public Positionable deepClone() {
043        PositionableRoundRect pos = new PositionableRoundRect(_editor);
044        pos._radius = _radius;
045        return finishClone(pos);
046    }
047
048    @Override
049    protected Positionable finishClone(PositionableShape pos) {
050        return super.finishClone(pos);
051    }
052
053    @Override
054    public boolean setEditItemMenu(JPopupMenu popup) {
055        String txt = Bundle.getMessage("editShape", Bundle.getMessage("roundRect"));
056        popup.add(new javax.swing.AbstractAction(txt) {
057            @Override
058            public void actionPerformed(ActionEvent e) {
059                makeEditFrame(false);
060            }
061        });
062        return true;
063    }
064    
065    @Override
066    protected DrawFrame makeEditFrame(boolean create) {
067        _editFrame = new DrawRoundRect("editShape", "roundRect", this, getEditor(), create);
068        _editFrame.setDisplayParams(this);
069        return _editFrame;
070    }
071}