use of javax.swing.JPopupMenu in project JMRI by JMRI.
the class ControlPanelEditor method showPopUp.
/**
* Create popup for a Positionable object Popup items common to all
* positionable objects are done before and after the items that pertain
* only to specific Positionable types.
*/
@Override
protected void showPopUp(Positionable p, MouseEvent event) {
if (!((JComponent) p).isVisible()) {
// component must be showing on the screen to determine its location
return;
}
JPopupMenu popup = new JPopupMenu();
PositionablePopupUtil util = p.getPopupUtility();
if (p.isEditable()) {
// items common to all
if (p.doViemMenu()) {
popup.add(p.getNameString());
setPositionableMenu(p, popup);
if (p.isPositionable()) {
setShowCoordinatesMenu(p, popup);
setShowAlignmentMenu(p, popup);
}
setDisplayLevelMenu(p, popup);
setHiddenMenu(p, popup);
popup.addSeparator();
setCopyMenu(p, popup);
}
// items with defaults or using overrides
boolean popupSet = false;
// popupSet |= p.setRotateOrthogonalMenu(popup);
popupSet |= p.setRotateMenu(popup);
popupSet |= p.setScaleMenu(popup);
if (popupSet) {
popup.addSeparator();
popupSet = false;
}
popupSet = p.setEditItemMenu(popup);
if (popupSet) {
popup.addSeparator();
popupSet = false;
}
if (p instanceof PositionableLabel) {
PositionableLabel pl = (PositionableLabel) p;
/* if (pl.isIcon() && "javax.swing.JLabel".equals(pl.getClass().getSuperclass().getName()) ) {
popupSet |= setTextAttributes(pl, popup); // only for plain icons
} Add backgrounds & text over icons later */
if (!pl.isIcon()) {
popupSet |= setTextAttributes(pl, popup);
if (p instanceof MemoryIcon) {
popupSet |= p.setTextEditMenu(popup);
}
} else if (p instanceof SensorIcon) {
popup.add(CoordinateEdit.getTextEditAction(p, "OverlayText"));
if (pl.isText()) {
popupSet |= setTextAttributes(p, popup);
}
} else {
popupSet = p.setTextEditMenu(popup);
}
} else if (p instanceof PositionableJPanel) {
popupSet |= setTextAttributes(p, popup);
}
if (p instanceof LinkingObject) {
((LinkingObject) p).setLinkMenu(popup);
}
if (popupSet) {
popup.addSeparator();
popupSet = false;
}
p.setDisableControlMenu(popup);
if (util != null) {
util.setAdditionalEditPopUpMenu(popup);
}
// for Positionables with unique settings
p.showPopUp(popup);
if (p.doViemMenu()) {
setShowTooltipMenu(p, popup);
setRemoveMenu(p, popup);
}
} else {
if (p instanceof LocoIcon) {
setCopyMenu(p, popup);
}
p.showPopUp(popup);
if (util != null) {
util.setAdditionalViewPopUpMenu(popup);
}
}
popup.show((Component) p, p.getWidth() / 2 + (int) ((getPaintScale() - 1.0) * p.getX()), p.getHeight() / 2 + (int) ((getPaintScale() - 1.0) * p.getY()));
_currentSelection = null;
}
use of javax.swing.JPopupMenu in project JMRI by JMRI.
the class TrackSegment method showBezierPopUp.
/**
* Display popup menu for information and editing.
*/
protected void showBezierPopUp(MouseEvent e, int hitPointType) {
int bezierControlPointIndex = hitPointType - BEZIER_CONTROL_POINT_OFFSET_MIN;
if (popup != null) {
popup.removeAll();
} else {
popup = new JPopupMenu();
}
JMenuItem jmi = popup.add(rb.getString("BezierControlPoint") + " #" + bezierControlPointIndex);
jmi.setEnabled(false);
popup.add(new JSeparator(JSeparator.HORIZONTAL));
if (bezierControlPoints.size() < BEZIER_CONTROL_POINT_OFFSET_MAX - BEZIER_CONTROL_POINT_OFFSET_MIN) {
popup.add(new AbstractAction(rb.getString("AddBezierControlPointAfter")) {
@Override
public void actionPerformed(ActionEvent e) {
addBezierControlPointAfter(bezierControlPointIndex);
}
});
popup.add(new AbstractAction(rb.getString("AddBezierControlPointBefore")) {
@Override
public void actionPerformed(ActionEvent e) {
addBezierControlPointBefore(bezierControlPointIndex);
}
});
}
if (bezierControlPoints.size() > 2) {
popup.add(new AbstractAction(rb.getString("DeleteBezierControlPoint") + " #" + bezierControlPointIndex) {
@Override
public void actionPerformed(ActionEvent e) {
deleteBezierControlPoint(bezierControlPointIndex);
}
});
}
popup.show(e.getComponent(), e.getX(), e.getY());
}
use of javax.swing.JPopupMenu in project JMRI by JMRI.
the class PanelEditor method showMultiSelectPopUp.
protected void showMultiSelectPopUp(final MouseEvent event, Positionable p) {
JPopupMenu popup = new JPopupMenu();
// changed "edit" to "copy"
JMenuItem copy = new JMenuItem(Bundle.getMessage("ButtonCopy"));
if (p.isPositionable()) {
setShowAlignmentMenu(p, popup);
}
copy.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
_multiItemCopyGroup = new ArrayList<Positionable>();
// must make a copy or pasteItem() will hang
if (_selectionGroup != null) {
for (Positionable comp : _selectionGroup) {
_multiItemCopyGroup.add(comp);
}
}
}
});
// adding Lock Position for all
setMultiItemsPositionableMenu(popup);
// selected items
setRemoveMenu(p, popup);
//showAddItemPopUp(event, popup); // no need to Add when group selected
popup.add(copy);
popup.show(event.getComponent(), event.getX(), event.getY());
}
use of javax.swing.JPopupMenu in project JMRI by JMRI.
the class PanelEditor method pasteItemPopUp.
protected void pasteItemPopUp(final MouseEvent event) {
if (!isEditable()) {
return;
}
if (_multiItemCopyGroup == null) {
return;
}
JPopupMenu popup = new JPopupMenu();
JMenuItem edit = new JMenuItem("Paste");
edit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
pasteItem(event);
}
});
setBackgroundMenu(popup);
showAddItemPopUp(event, popup);
popup.add(edit);
popup.show(event.getComponent(), event.getX(), event.getY());
}
use of javax.swing.JPopupMenu in project JMRI by JMRI.
the class PanelEditor method backgroundPopUp.
protected void backgroundPopUp(MouseEvent event) {
if (!isEditable()) {
return;
}
JPopupMenu popup = new JPopupMenu();
setBackgroundMenu(popup);
showAddItemPopUp(event, popup);
popup.show(event.getComponent(), event.getX(), event.getY());
}
Aggregations