use of javax.swing.JPopupMenu in project JMRI by JMRI.
the class LayoutTurntable method showRayPopUp.
protected void showRayPopUp(MouseEvent e, int index) {
if (rayPopup != null) {
rayPopup.removeAll();
} else {
rayPopup = new JPopupMenu();
}
for (RayTrack rt : rayList) {
if (rt.getConnectionIndex() == index) {
JMenuItem jmi = rayPopup.add("Turntable Ray " + index);
jmi.setEnabled(false);
if (rt.getTurnout() != null) {
jmi = rayPopup.add(rt.getTurnout().getDisplayName() + " (" + rt.getTurnoutState() + ")");
jmi.setEnabled(false);
}
rayPopup.show(e.getComponent(), e.getX(), e.getY());
break;
}
}
}
use of javax.swing.JPopupMenu in project JMRI by JMRI.
the class LevelXing method showPopUp.
/**
* Display popup menu for information and editing
*/
protected void showPopUp(MouseEvent e) {
if (popup != null) {
popup.removeAll();
} else {
popup = new JPopupMenu();
}
if (layoutEditor.isEditable()) {
JMenuItem jmi = popup.add(rb.getString("LevelCrossing"));
jmi.setEnabled(false);
jmi = popup.add(ident);
jmi.setEnabled(false);
boolean blockACAssigned = false;
boolean blockBDAssigned = false;
if ((blockNameAC == null) || (blockNameAC.equals(""))) {
jmi = popup.add(Bundle.getMessage("NoBlockX", 1));
} else {
jmi = popup.add(Bundle.getMessage("Block_ID", 1) + ": " + getLayoutBlockAC().getID());
blockACAssigned = true;
}
jmi.setEnabled(false);
if ((blockNameBD == null) || (blockNameBD.equals(""))) {
jmi = popup.add(Bundle.getMessage("NoBlockX", 2));
} else {
jmi = popup.add(Bundle.getMessage("Block_ID", 2) + ": " + getLayoutBlockBD().getID());
blockBDAssigned = true;
}
jmi.setEnabled(false);
if (hidden) {
jmi = popup.add(rb.getString("Hidden"));
} else {
jmi = popup.add(rb.getString("NotHidden"));
}
jmi.setEnabled(false);
popup.add(new JSeparator(JSeparator.HORIZONTAL));
popup.add(new AbstractAction(Bundle.getMessage("ButtonEdit")) {
@Override
public void actionPerformed(ActionEvent e) {
editLevelXing(instance);
}
});
popup.add(new AbstractAction(Bundle.getMessage("ButtonDelete")) {
@Override
public void actionPerformed(ActionEvent e) {
if (layoutEditor.removeLevelXing(instance)) {
// Returned true if user did not cancel
remove();
dispose();
}
}
});
if (blockACAssigned && blockBDAssigned) {
popup.add(new AbstractAction(rb.getString("SetSignals")) {
@Override
public void actionPerformed(ActionEvent e) {
if (tools == null) {
tools = new LayoutEditorTools(layoutEditor);
}
// bring up signals at level crossing tool dialog
tools.setSignalsAtLevelXingFromMenu(instance, layoutEditor.signalIconEditor, layoutEditor.signalFrame);
}
});
}
final String[] boundaryBetween = getBlockBoundaries();
boolean blockBoundaries = false;
if (jmri.InstanceManager.getDefault(LayoutBlockManager.class).isAdvancedRoutingEnabled()) {
if (blockACAssigned && !blockBDAssigned) {
popup.add(new AbstractAction(rb.getString("ViewBlockRouting")) {
@Override
public void actionPerformed(ActionEvent e) {
AbstractAction routeTableAction = new LayoutBlockRouteTableAction("ViewRouting", getLayoutBlockAC());
routeTableAction.actionPerformed(e);
}
});
} else if (!blockACAssigned && blockBDAssigned) {
popup.add(new AbstractAction(rb.getString("ViewBlockRouting")) {
@Override
public void actionPerformed(ActionEvent e) {
AbstractAction routeTableAction = new LayoutBlockRouteTableAction("ViewRouting", getLayoutBlockBD());
routeTableAction.actionPerformed(e);
}
});
} else if (blockACAssigned && blockBDAssigned) {
JMenu viewRouting = new JMenu(rb.getString("ViewBlockRouting"));
viewRouting.add(new AbstractAction(blockNameAC) {
@Override
public void actionPerformed(ActionEvent e) {
AbstractAction routeTableAction = new LayoutBlockRouteTableAction(blockNameAC, getLayoutBlockAC());
routeTableAction.actionPerformed(e);
}
});
viewRouting.add(new AbstractAction(blockNameBD) {
@Override
public void actionPerformed(ActionEvent e) {
AbstractAction routeTableAction = new LayoutBlockRouteTableAction(blockNameBD, getLayoutBlockBD());
routeTableAction.actionPerformed(e);
}
});
popup.add(viewRouting);
}
}
for (int i = 0; i < 4; i++) {
if (boundaryBetween[i] != null) {
blockBoundaries = true;
}
}
if (blockBoundaries) {
popup.add(new AbstractAction(rb.getString("SetSignalMasts")) {
@Override
public void actionPerformed(ActionEvent e) {
if (tools == null) {
tools = new LayoutEditorTools(layoutEditor);
}
tools.setSignalMastsAtLevelXingFromMenu(instance, boundaryBetween, layoutEditor.signalFrame);
}
});
popup.add(new AbstractAction(rb.getString("SetSensors")) {
@Override
public void actionPerformed(ActionEvent e) {
if (tools == null) {
tools = new LayoutEditorTools(layoutEditor);
}
tools.setSensorsAtLevelXingFromMenu(instance, boundaryBetween, layoutEditor.sensorIconEditor, layoutEditor.sensorFrame);
}
});
}
layoutEditor.setShowAlignmentMenu(popup);
popup.show(e.getComponent(), e.getX(), e.getY());
} else if (!viewAdditionalMenu.isEmpty()) {
setAdditionalViewPopUpMenu(popup);
popup.show(e.getComponent(), e.getX(), e.getY());
}
}
use of javax.swing.JPopupMenu in project JMRI by JMRI.
the class LayoutTurntable method showPopUp.
/**
* Display popup menu for information and editing
*/
protected void showPopUp(MouseEvent e) {
if (popup != null) {
popup.removeAll();
} else {
popup = new JPopupMenu();
}
JMenuItem jmi = popup.add(rb.getString("Turntable"));
jmi.setEnabled(false);
popup.add(new JSeparator(JSeparator.HORIZONTAL));
popup.add(new AbstractAction(Bundle.getMessage("ButtonEdit")) {
@Override
public void actionPerformed(ActionEvent e) {
editTurntable(instance);
}
});
popup.add(new AbstractAction(Bundle.getMessage("ButtonDelete")) {
@Override
public void actionPerformed(ActionEvent e) {
if (layoutEditor.removeTurntable(instance)) {
// Returned true if user did not cancel
remove();
dispose();
}
}
});
layoutEditor.setShowAlignmentMenu(popup);
popup.show(e.getComponent(), e.getX(), e.getY());
}
use of javax.swing.JPopupMenu in project JMRI by JMRI.
the class TrackSegment method showPopUp.
/**
* Display popup menu for information and editing.
*/
protected void showPopUp(MouseEvent e) {
if (popup != null) {
popup.removeAll();
} else {
popup = new JPopupMenu();
}
String info = rb.getString("TrackSegment");
if (getArc()) {
if (getCircle()) {
info = info + " (" + Bundle.getMessage("Circle") + ")";
} else {
info = info + " (" + Bundle.getMessage("Ellipse") + ")";
}
} else if (getBezier()) {
info = info + " (" + Bundle.getMessage("Bezier") + ")";
} else {
info = info + " (" + Bundle.getMessage("Line") + ")";
}
JMenuItem jmi = popup.add(info);
jmi.setEnabled(false);
jmi = popup.add(ident);
jmi.setEnabled(false);
if (!dashed) {
jmi = popup.add(rb.getString("Style") + " - " + rb.getString("Solid"));
} else {
jmi = popup.add(rb.getString("Style") + " - " + rb.getString("Dashed"));
}
jmi.setEnabled(false);
if (!mainline) {
jmi = popup.add(rb.getString("NotMainline"));
} else {
jmi = popup.add(rb.getString("Mainline"));
}
jmi.setEnabled(false);
if (blockName.equals("")) {
jmi = popup.add(rb.getString("NoBlock"));
} else {
jmi = popup.add(Bundle.getMessage("BeanNameBlock") + ": " + getLayoutBlock().getID());
}
jmi.setEnabled(false);
if (hidden) {
jmi = popup.add(rb.getString("Hidden"));
} else {
jmi = popup.add(rb.getString("NotHidden"));
}
jmi.setEnabled(false);
popup.add(new JSeparator(JSeparator.HORIZONTAL));
popup.add(new AbstractAction(Bundle.getMessage("ButtonEdit")) {
@Override
public void actionPerformed(ActionEvent e) {
editTrackSegment();
}
});
popup.add(new AbstractAction(Bundle.getMessage("ButtonDelete")) {
@Override
public void actionPerformed(ActionEvent e) {
layoutEditor.removeTrackSegment(instance);
remove();
dispose();
}
});
JMenu lineType = new JMenu(rb.getString("ChangeTo"));
lineType.add(new AbstractAction(Bundle.getMessage("Line")) {
@Override
public void actionPerformed(ActionEvent e) {
changeType(0);
}
});
lineType.add(new AbstractAction(Bundle.getMessage("Circle")) {
@Override
public void actionPerformed(ActionEvent e) {
changeType(1);
}
});
lineType.add(new AbstractAction(Bundle.getMessage("Ellipse")) {
@Override
public void actionPerformed(ActionEvent e) {
changeType(2);
}
});
lineType.add(new AbstractAction(Bundle.getMessage("Bezier")) {
@Override
public void actionPerformed(ActionEvent e) {
changeType(3);
}
});
popup.add(lineType);
if (getArc()) {
popup.add(new AbstractAction(rb.getString("FlipAngle")) {
@Override
public void actionPerformed(ActionEvent e) {
flipAngle();
}
});
}
if (getArc() || getBezier()) {
if (hideConstructionLines()) {
popup.add(new AbstractAction(rb.getString("ShowConstruct")) {
@Override
public void actionPerformed(ActionEvent e) {
hideConstructionLines(SHOWCON);
}
});
} else {
popup.add(new AbstractAction(rb.getString("HideConstruct")) {
@Override
public void actionPerformed(ActionEvent e) {
hideConstructionLines(HIDECON);
}
});
}
}
if ((!blockName.equals("")) && (jmri.InstanceManager.getDefault(LayoutBlockManager.class).isAdvancedRoutingEnabled())) {
popup.add(new AbstractAction(rb.getString("ViewBlockRouting")) {
@Override
public void actionPerformed(ActionEvent e) {
AbstractAction routeTableAction = new LayoutBlockRouteTableAction("ViewRouting", getLayoutBlock());
routeTableAction.actionPerformed(e);
}
});
}
popup.show(e.getComponent(), e.getX(), e.getY());
}
use of javax.swing.JPopupMenu in project jdk8u_jdk by JetBrains.
the class bug8071705 method runActualTest.
private static void runActualTest(GraphicsDevice device, CountDownLatch latch, JFrame frame, boolean[] result) {
Rectangle screenBounds = setLocation(frame, device);
JMenu menu = frame.getJMenuBar().getMenu(0);
menu.doClick();
Point location = menu.getLocationOnScreen();
JPopupMenu pm = menu.getPopupMenu();
Dimension pmSize = pm.getSize();
int yOffset = UIManager.getInt("Menu.submenuPopupOffsetY");
int height = location.y + yOffset + pmSize.height + menu.getHeight();
int available = screenBounds.y + screenBounds.height - height;
if (available > 0) {
Point origin = pm.getLocationOnScreen();
if (origin.y < location.y) {
// growing upward, wrong!
result[0] = false;
} else {
// growing downward, ok!
result[0] = true;
}
} else {
// there is no space, growing upward would be ok, so we pass
result[0] = true;
}
}
Aggregations