use of javax.swing.event.MenuListener in project energy3d by concord-consortium.
the class PopupMenuForWall method getPopupMenuForWall.
static JPopupMenu getPopupMenuForWall() {
if (popupMenuForWall == null) {
final JMenuItem miPaste = new JMenuItem("Paste");
miPaste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, Config.isMac() ? KeyEvent.META_MASK : InputEvent.CTRL_MASK));
miPaste.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
SceneManager.getTaskManager().update(new Callable<Object>() {
@Override
public Object call() throws Exception {
Scene.getInstance().pasteToPickedLocationOnWall();
Scene.getInstance().setEdited(true);
return null;
}
});
}
});
final JMenuItem miClear = new JMenuItem("Clear");
miClear.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
SceneManager.getTaskManager().update(new Callable<Object>() {
@Override
public Object call() throws Exception {
Scene.getInstance().removeAllChildren(SceneManager.getInstance().getSelectedPart());
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
MainPanel.getInstance().getEnergyButton().setSelected(false);
Scene.getInstance().setEdited(true);
}
});
return null;
}
});
}
});
final JMenuItem miDeleteAllConnectedWalls = new JMenuItem("Delete All Connected Walls");
miDeleteAllConnectedWalls.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Wall) {
Scene.getInstance().deleteAllConnectedWalls((Wall) selectedPart);
}
}
});
final JMenuItem miThickness = new JMenuItem("Thickness...");
miThickness.addActionListener(new ActionListener() {
// remember the scope selection as the next action will likely be applied to the same scope
private int selectedScopeIndex = 0;
@Override
public void actionPerformed(final ActionEvent e) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (!(selectedPart instanceof Wall)) {
return;
}
final String partInfo = selectedPart.toString().substring(0, selectedPart.toString().indexOf(')') + 1);
final Wall w = (Wall) selectedPart;
final String title = "<html>Thickness of " + partInfo + "</html>";
final String footnote = "<html><hr><font size=2>Thickness of wall is in meters.<hr></html>";
final JPanel gui = new JPanel(new BorderLayout());
final JPanel panel = new JPanel();
gui.add(panel, BorderLayout.CENTER);
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setBorder(BorderFactory.createTitledBorder("Apply to:"));
final JRadioButton rb1 = new JRadioButton("Only this Wall", true);
final JRadioButton rb2 = new JRadioButton("All Walls on This Foundation");
final JRadioButton rb3 = new JRadioButton("All Walls");
panel.add(rb1);
panel.add(rb2);
panel.add(rb3);
final ButtonGroup bg = new ButtonGroup();
bg.add(rb1);
bg.add(rb2);
bg.add(rb3);
switch(selectedScopeIndex) {
case 0:
rb1.setSelected(true);
break;
case 1:
rb2.setSelected(true);
break;
case 2:
rb3.setSelected(true);
break;
}
final JTextField inputField = new JTextField(EnergyPanel.TWO_DECIMALS.format(w.getThickness() * Scene.getInstance().getAnnotationScale()));
gui.add(inputField, BorderLayout.SOUTH);
final Object[] options = new Object[] { "OK", "Cancel", "Apply" };
final JOptionPane optionPane = new JOptionPane(new Object[] { title, footnote, gui }, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options, options[2]);
final JDialog dialog = optionPane.createDialog(MainFrame.getInstance(), "Wall Thickness");
while (true) {
inputField.selectAll();
inputField.requestFocusInWindow();
dialog.setVisible(true);
final Object choice = optionPane.getValue();
if (choice == options[1] || choice == null) {
break;
} else {
double val = 0;
boolean ok = true;
try {
val = Double.parseDouble(inputField.getText());
} catch (final NumberFormatException exception) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), inputField.getText() + " is an invalid value!", "Error", JOptionPane.ERROR_MESSAGE);
ok = false;
}
if (ok) {
if (val < 0.1 || val > 10) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "The thickness of a wall must be between 0.1 and 10 meters.", "Range Error", JOptionPane.ERROR_MESSAGE);
} else {
val /= Scene.getInstance().getAnnotationScale();
Wall.setDefaultThickess(val);
boolean changed = Math.abs(val - w.getThickness()) > 0.000001;
if (rb1.isSelected()) {
if (changed) {
final ChangeWallThicknessCommand c = new ChangeWallThicknessCommand(w);
w.setThickness(val);
w.draw();
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 0;
} else if (rb2.isSelected()) {
final Foundation foundation = w.getTopContainer();
if (!changed) {
for (final Wall x : foundation.getWalls()) {
if (Math.abs(val - x.getThickness()) > 0.000001) {
changed = true;
break;
}
}
}
if (changed) {
final ChangeFoundationWallThicknessCommand c = new ChangeFoundationWallThicknessCommand(foundation);
foundation.setThicknessOfWalls(val);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 1;
} else if (rb3.isSelected()) {
if (!changed) {
for (final Wall x : Scene.getInstance().getAllWalls()) {
if (Math.abs(val - x.getThickness()) > 0.000001) {
changed = true;
break;
}
}
}
if (changed) {
final ChangeThicknessForAllWallsCommand c = new ChangeThicknessForAllWallsCommand(w);
Scene.getInstance().setThicknessForAllWalls(val);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 2;
}
if (changed) {
updateAfterEdit();
}
if (choice == options[0]) {
break;
}
}
}
}
}
}
});
final JMenuItem miHeight = new JMenuItem("Height...");
miHeight.addActionListener(new ActionListener() {
// remember the scope selection as the next action will likely be applied to the same scope
private int selectedScopeIndex = 0;
private boolean changed;
private double val;
@Override
public void actionPerformed(final ActionEvent e) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (!(selectedPart instanceof Wall)) {
return;
}
final String partInfo = selectedPart.toString().substring(0, selectedPart.toString().indexOf(')') + 1);
final Wall w = (Wall) selectedPart;
final String title = "<html>Height of " + partInfo + "</html>";
final String footnote = "<html><hr><font size=2>Height of wall is in meters.<hr></html>";
final JPanel gui = new JPanel(new BorderLayout());
final JPanel panel = new JPanel();
gui.add(panel, BorderLayout.CENTER);
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setBorder(BorderFactory.createTitledBorder("Apply to:"));
final JRadioButton rb1 = new JRadioButton("Only this Wall", true);
final JRadioButton rb2 = new JRadioButton("All Walls Connected to This One (Direct and Indirect)");
final JRadioButton rb3 = new JRadioButton("All Walls on This Foundation");
final JRadioButton rb4 = new JRadioButton("All Walls");
panel.add(rb1);
panel.add(rb2);
panel.add(rb3);
panel.add(rb4);
final ButtonGroup bg = new ButtonGroup();
bg.add(rb1);
bg.add(rb2);
bg.add(rb3);
bg.add(rb4);
switch(selectedScopeIndex) {
case 0:
rb1.setSelected(true);
break;
case 1:
rb2.setSelected(true);
break;
case 2:
rb3.setSelected(true);
break;
case 3:
rb4.setSelected(true);
break;
}
final JTextField inputField = new JTextField(EnergyPanel.TWO_DECIMALS.format(w.getHeight() * Scene.getInstance().getAnnotationScale()));
gui.add(inputField, BorderLayout.SOUTH);
final Object[] options = new Object[] { "OK", "Cancel", "Apply" };
final JOptionPane optionPane = new JOptionPane(new Object[] { title, footnote, gui }, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options, options[2]);
final JDialog dialog = optionPane.createDialog(MainFrame.getInstance(), "Wall Height");
while (true) {
inputField.selectAll();
inputField.requestFocusInWindow();
dialog.setVisible(true);
final Object choice = optionPane.getValue();
if (choice == options[1] || choice == null) {
break;
} else {
boolean ok = true;
try {
val = Double.parseDouble(inputField.getText());
} catch (final NumberFormatException exception) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), inputField.getText() + " is an invalid value!", "Error", JOptionPane.ERROR_MESSAGE);
ok = false;
}
if (ok) {
if (val < 1 || val > 1000) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "The height of a wall must be between 1 and 1000 meters.", "Range Error", JOptionPane.ERROR_MESSAGE);
} else {
val /= Scene.getInstance().getAnnotationScale();
changed = Math.abs(val - w.getHeight()) > 0.000001;
if (rb1.isSelected()) {
if (changed) {
final ChangeWallHeightCommand c = new ChangeWallHeightCommand(w);
w.setHeight(val, true);
Scene.getInstance().redrawAllWallsNow();
SceneManager.getInstance().getUndoManager().addEdit(c);
final Foundation foundation = w.getTopContainer();
if (foundation.hasSolarReceiver()) {
foundation.drawSolarReceiver();
for (final HousePart x : Scene.getInstance().getParts()) {
if (x instanceof FresnelReflector) {
final FresnelReflector reflector = (FresnelReflector) x;
if (foundation == reflector.getReceiver() && reflector.isSunBeamVisible()) {
reflector.drawSunBeam();
}
} else if (x instanceof Mirror) {
final Mirror heliostat = (Mirror) x;
if (foundation == heliostat.getReceiver() && heliostat.isSunBeamVisible()) {
heliostat.drawSunBeam();
}
}
}
}
}
selectedScopeIndex = 0;
} else if (rb2.isSelected()) {
if (!changed) {
w.visitNeighbors(new WallVisitor() {
@Override
public void visit(final Wall currentWall, final Snap prev, final Snap next) {
if (Math.abs(val - currentWall.getHeight()) > 0.000001) {
changed = true;
}
}
});
}
if (changed) {
final ChangeHeightForConnectedWallsCommand c = new ChangeHeightForConnectedWallsCommand(w);
Scene.getInstance().setHeightOfConnectedWalls(w, val);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 1;
} else if (rb3.isSelected()) {
final Foundation foundation = w.getTopContainer();
if (!changed) {
for (final Wall x : foundation.getWalls()) {
if (Math.abs(val - x.getHeight()) > 0.000001) {
changed = true;
break;
}
}
}
if (changed) {
final ChangeFoundationWallHeightCommand c = new ChangeFoundationWallHeightCommand(foundation);
foundation.setHeightOfWalls(val);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 2;
} else if (rb4.isSelected()) {
if (!changed) {
for (final Wall x : Scene.getInstance().getAllWalls()) {
if (Math.abs(val - x.getHeight()) > 0.000001) {
changed = true;
break;
}
}
}
if (changed) {
final ChangeHeightForAllWallsCommand c = new ChangeHeightForAllWallsCommand(w);
Scene.getInstance().setHeightForAllWalls(val);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 3;
}
if (changed) {
updateAfterEdit();
}
if (choice == options[0]) {
break;
}
}
}
}
}
}
});
final JCheckBoxMenuItem miOutline = new JCheckBoxMenuItem("Outline...", true);
miOutline.addActionListener(new ActionListener() {
// remember the scope selection as the next action will likely be applied to the same scope
private int selectedScopeIndex = 0;
@Override
public void actionPerformed(final ActionEvent e) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (!(selectedPart instanceof Wall)) {
return;
}
final String partInfo = selectedPart.toString().substring(0, selectedPart.toString().indexOf(')') + 1);
final Wall w = (Wall) selectedPart;
final String title = "<html>Outline of " + partInfo + "</html>";
final String footnote = "<html>Hiding outline may create a continuous effect of a polygon<br>formed by many walls.</html>";
final JPanel gui = new JPanel(new BorderLayout());
final JPanel panel = new JPanel();
gui.add(panel, BorderLayout.CENTER);
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setBorder(BorderFactory.createTitledBorder("Apply to:"));
final JRadioButton rb1 = new JRadioButton("Only this Wall", true);
final JRadioButton rb2 = new JRadioButton("All Walls Connected to This One (Direct and Indirect)");
final JRadioButton rb3 = new JRadioButton("All Walls on This Foundation");
final JRadioButton rb4 = new JRadioButton("All Walls");
panel.add(rb1);
panel.add(rb2);
panel.add(rb3);
panel.add(rb4);
final ButtonGroup bg = new ButtonGroup();
bg.add(rb1);
bg.add(rb2);
bg.add(rb3);
bg.add(rb4);
switch(selectedScopeIndex) {
case 0:
rb1.setSelected(true);
break;
case 1:
rb2.setSelected(true);
break;
case 2:
rb3.setSelected(true);
break;
case 3:
rb4.setSelected(true);
break;
}
final Object[] options = new Object[] { "OK", "Cancel", "Apply" };
final JOptionPane optionPane = new JOptionPane(new Object[] { title, footnote, gui }, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options, options[2]);
final JDialog dialog = optionPane.createDialog(MainFrame.getInstance(), "Wall Outline");
while (true) {
dialog.setVisible(true);
final Object choice = optionPane.getValue();
if (choice == options[1] || choice == null) {
break;
} else {
if (rb1.isSelected()) {
// final ChangeWallHeightCommand c = new ChangeWallHeightCommand(w);
w.showOutline(miOutline.isSelected());
w.draw();
// SceneManager.getInstance().getUndoManager().addEdit(c);
selectedScopeIndex = 0;
} else if (rb2.isSelected()) {
// final ChangeHeightForConnectedWallsCommand c = new ChangeHeightForConnectedWallsCommand(w);
Scene.getInstance().showOutlineOfConnectedWalls(w, miOutline.isSelected());
// SceneManager.getInstance().getUndoManager().addEdit(c);
selectedScopeIndex = 1;
} else if (rb3.isSelected()) {
final Foundation foundation = w.getTopContainer();
// final ChangeFoundationWallHeightCommand c = new ChangeFoundationWallHeightCommand(foundation);
foundation.showOutlineOfWalls(miOutline.isSelected());
// SceneManager.getInstance().getUndoManager().addEdit(c);
selectedScopeIndex = 2;
} else if (rb4.isSelected()) {
// final ChangeHeightForAllWallsCommand c = new ChangeHeightForAllWallsCommand(w);
Scene.getInstance().showOutlineForAllWalls(miOutline.isSelected());
// SceneManager.getInstance().getUndoManager().addEdit(c);
selectedScopeIndex = 3;
}
updateAfterEdit();
if (choice == options[0]) {
break;
}
}
}
}
});
popupMenuForWall = createPopupMenu(false, false, new Runnable() {
@Override
public void run() {
final HousePart copyBuffer = Scene.getInstance().getCopyBuffer();
miPaste.setEnabled(copyBuffer instanceof Window || copyBuffer instanceof SolarPanel || copyBuffer instanceof Rack);
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Wall) {
final Wall w = (Wall) selectedPart;
Util.selectSilently(miOutline, w.outlineShown());
}
}
});
popupMenuForWall.add(miPaste);
popupMenuForWall.add(miDeleteAllConnectedWalls);
popupMenuForWall.add(miClear);
popupMenuForWall.addSeparator();
popupMenuForWall.add(colorAction);
popupMenuForWall.add(miOutline);
popupMenuForWall.add(miThickness);
popupMenuForWall.add(miHeight);
popupMenuForWall.add(createInsulationMenuItem(false));
popupMenuForWall.add(createVolumetricHeatCapacityMenuItem());
popupMenuForWall.addSeparator();
final JMenu textureMenu = new JMenu("Texture");
popupMenuForWall.add(textureMenu);
final ButtonGroup textureGroup = new ButtonGroup();
final JRadioButtonMenuItem rbmiTextureNone = new JRadioButtonMenuItem("No Texture");
rbmiTextureNone.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
final ChangeBuildingTextureCommand c = new ChangeBuildingTextureCommand();
Scene.getInstance().setTextureMode(TextureMode.None);
Scene.getInstance().setEdited(true);
if (MainPanel.getInstance().getEnergyButton().isSelected()) {
MainPanel.getInstance().getEnergyButton().setSelected(false);
}
SceneManager.getInstance().getUndoManager().addEdit(c);
}
}
});
textureGroup.add(rbmiTextureNone);
textureMenu.add(rbmiTextureNone);
final JRadioButtonMenuItem rbmiTextureOutline = new JRadioButtonMenuItem("Outline Texture");
rbmiTextureOutline.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
final ChangeBuildingTextureCommand c = new ChangeBuildingTextureCommand();
Scene.getInstance().setTextureMode(TextureMode.Simple);
Scene.getInstance().setEdited(true);
if (MainPanel.getInstance().getEnergyButton().isSelected()) {
MainPanel.getInstance().getEnergyButton().setSelected(false);
}
SceneManager.getInstance().getUndoManager().addEdit(c);
}
}
});
textureGroup.add(rbmiTextureOutline);
textureMenu.add(rbmiTextureOutline);
textureMenu.addSeparator();
final JRadioButtonMenuItem rbmiTexture01 = MainFrame.getInstance().createWallTextureMenuItem(Wall.TEXTURE_01, "icons/wall_01.png");
final JRadioButtonMenuItem rbmiTexture02 = MainFrame.getInstance().createWallTextureMenuItem(Wall.TEXTURE_02, "icons/wall_02.png");
final JRadioButtonMenuItem rbmiTexture03 = MainFrame.getInstance().createWallTextureMenuItem(Wall.TEXTURE_03, "icons/wall_03.png");
final JRadioButtonMenuItem rbmiTexture04 = MainFrame.getInstance().createWallTextureMenuItem(Wall.TEXTURE_04, "icons/wall_04.png");
final JRadioButtonMenuItem rbmiTexture05 = MainFrame.getInstance().createWallTextureMenuItem(Wall.TEXTURE_05, "icons/wall_05.png");
final JRadioButtonMenuItem rbmiTexture06 = MainFrame.getInstance().createWallTextureMenuItem(Wall.TEXTURE_06, "icons/wall_06.png");
textureGroup.add(rbmiTexture01);
textureGroup.add(rbmiTexture02);
textureGroup.add(rbmiTexture03);
textureGroup.add(rbmiTexture04);
textureGroup.add(rbmiTexture05);
textureGroup.add(rbmiTexture06);
textureMenu.add(rbmiTexture01);
textureMenu.add(rbmiTexture02);
textureMenu.add(rbmiTexture03);
textureMenu.add(rbmiTexture04);
textureMenu.add(rbmiTexture05);
textureMenu.add(rbmiTexture06);
textureMenu.addMenuListener(new MenuListener() {
@Override
public void menuSelected(final MenuEvent e) {
if (Scene.getInstance().getTextureMode() == TextureMode.None) {
Util.selectSilently(rbmiTextureNone, true);
return;
}
if (Scene.getInstance().getTextureMode() == TextureMode.Simple) {
Util.selectSilently(rbmiTextureOutline, true);
return;
}
switch(Scene.getInstance().getWallTextureType()) {
case Wall.TEXTURE_01:
Util.selectSilently(rbmiTexture01, true);
break;
case Wall.TEXTURE_02:
Util.selectSilently(rbmiTexture02, true);
break;
case Wall.TEXTURE_03:
Util.selectSilently(rbmiTexture03, true);
break;
case Wall.TEXTURE_04:
Util.selectSilently(rbmiTexture04, true);
break;
case Wall.TEXTURE_05:
Util.selectSilently(rbmiTexture05, true);
break;
case Wall.TEXTURE_06:
Util.selectSilently(rbmiTexture06, true);
break;
}
}
@Override
public void menuDeselected(final MenuEvent e) {
textureMenu.setEnabled(true);
}
@Override
public void menuCanceled(final MenuEvent e) {
textureMenu.setEnabled(true);
}
});
final JMenu typeMenu = new JMenu("Type");
popupMenuForWall.add(typeMenu);
popupMenuForWall.addSeparator();
final ButtonGroup typeGroup = new ButtonGroup();
final JRadioButtonMenuItem rbmiSolidWall = new JRadioButtonMenuItem("Solid Wall");
rbmiSolidWall.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Wall) {
final Wall wall = (Wall) selectedPart;
final ChangeWallTypeCommand c = new ChangeWallTypeCommand(wall);
wall.setType(Wall.SOLID_WALL);
wall.draw();
Scene.getInstance().setEdited(true);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
}
}
});
typeMenu.add(rbmiSolidWall);
typeGroup.add(rbmiSolidWall);
final JRadioButtonMenuItem rbmiEmpty = new JRadioButtonMenuItem("Empty");
rbmiEmpty.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Wall) {
final Wall wall = (Wall) selectedPart;
final ChangeWallTypeCommand c = new ChangeWallTypeCommand(wall);
wall.setType(Wall.EMPTY);
wall.draw();
Scene.getInstance().setEdited(true);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
}
}
});
typeMenu.add(rbmiEmpty);
typeGroup.add(rbmiEmpty);
final JRadioButtonMenuItem rbmiEdges = new JRadioButtonMenuItem("Vertical Edges");
rbmiEdges.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Wall) {
final Wall wall = (Wall) selectedPart;
final ChangeWallTypeCommand c = new ChangeWallTypeCommand(wall);
wall.setType(Wall.VERTICAL_EDGES_ONLY);
wall.draw();
Scene.getInstance().setEdited(true);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
}
}
});
typeMenu.add(rbmiEdges);
typeGroup.add(rbmiEdges);
final JRadioButtonMenuItem rbmiColumns = new JRadioButtonMenuItem("Columns");
rbmiColumns.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Wall) {
final Wall wall = (Wall) selectedPart;
final ChangeWallTypeCommand c = new ChangeWallTypeCommand(wall);
wall.setType(Wall.COLUMNS_ONLY);
wall.draw();
Scene.getInstance().setEdited(true);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
}
}
});
typeMenu.add(rbmiColumns);
typeGroup.add(rbmiColumns);
final JRadioButtonMenuItem rbmiRails = new JRadioButtonMenuItem("Rails");
rbmiRails.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Wall) {
final Wall wall = (Wall) selectedPart;
final ChangeWallTypeCommand c = new ChangeWallTypeCommand(wall);
wall.setType(Wall.RAILS_ONLY);
wall.draw();
Scene.getInstance().setEdited(true);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
}
}
});
typeMenu.add(rbmiRails);
typeGroup.add(rbmiRails);
final JRadioButtonMenuItem rbmiColumnsAndRailings = new JRadioButtonMenuItem("Columns & Railings");
rbmiColumnsAndRailings.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Wall) {
final Wall wall = (Wall) selectedPart;
final ChangeWallTypeCommand c = new ChangeWallTypeCommand(wall);
wall.setType(Wall.COLUMNS_RAILS);
wall.draw();
Scene.getInstance().setEdited(true);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
}
}
});
typeMenu.add(rbmiColumnsAndRailings);
typeGroup.add(rbmiColumnsAndRailings);
final JRadioButtonMenuItem rbmiFence = new JRadioButtonMenuItem("Fence");
rbmiFence.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Wall) {
final Wall wall = (Wall) selectedPart;
final ChangeWallTypeCommand c = new ChangeWallTypeCommand(wall);
wall.setType(Wall.FENCE);
wall.draw();
Scene.getInstance().setEdited(true);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
}
}
});
typeMenu.add(rbmiFence);
typeGroup.add(rbmiFence);
final JRadioButtonMenuItem rbmiSteelFrame = new JRadioButtonMenuItem("Steel Frame");
rbmiSteelFrame.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Wall) {
final Wall wall = (Wall) selectedPart;
final ChangeWallTypeCommand c = new ChangeWallTypeCommand(wall);
wall.setType(Wall.STEEL_FRAME);
wall.draw();
Scene.getInstance().setEdited(true);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
}
}
});
typeMenu.add(rbmiSteelFrame);
typeGroup.add(rbmiSteelFrame);
typeMenu.addMenuListener(new MenuListener() {
@Override
public void menuSelected(final MenuEvent e) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Wall) {
final Wall wall = (Wall) selectedPart;
switch(wall.getType()) {
case Wall.SOLID_WALL:
Util.selectSilently(rbmiSolidWall, true);
break;
case Wall.EMPTY:
Util.selectSilently(rbmiEmpty, true);
break;
case Wall.VERTICAL_EDGES_ONLY:
Util.selectSilently(rbmiEdges, true);
break;
case Wall.COLUMNS_ONLY:
Util.selectSilently(rbmiColumns, true);
break;
case Wall.RAILS_ONLY:
Util.selectSilently(rbmiRails, true);
break;
case Wall.COLUMNS_RAILS:
Util.selectSilently(rbmiColumnsAndRailings, true);
break;
case Wall.STEEL_FRAME:
Util.selectSilently(rbmiSteelFrame, true);
break;
}
}
}
@Override
public void menuDeselected(final MenuEvent e) {
typeMenu.setEnabled(true);
}
@Override
public void menuCanceled(final MenuEvent e) {
typeMenu.setEnabled(true);
}
});
JMenuItem mi = new JMenuItem("Daily Energy Analysis...");
mi.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
if (EnergyPanel.getInstance().adjustCellSize()) {
return;
}
if (SceneManager.getInstance().getSelectedPart() instanceof Wall) {
new EnergyDailyAnalysis().show("Daily Energy for Wall");
}
}
});
popupMenuForWall.add(mi);
mi = new JMenuItem("Annual Energy Analysis...");
mi.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
if (EnergyPanel.getInstance().adjustCellSize()) {
return;
}
if (SceneManager.getInstance().getSelectedPart() instanceof Wall) {
new EnergyAnnualAnalysis().show("Annual Energy for Wall");
}
}
});
popupMenuForWall.add(mi);
}
return popupMenuForWall;
}
use of javax.swing.event.MenuListener in project energy3d by concord-consortium.
the class PopupMenuForRoof method getPopupMenu.
static JPopupMenu getPopupMenu(final MouseEvent e) {
if (e.isShiftDown()) {
SceneManager.getTaskManager().update(new Callable<Object>() {
@Override
public Object call() throws Exception {
Scene.getInstance().pasteToPickedLocationOnRoof();
Scene.getInstance().setEdited(true);
return null;
}
});
return null;
}
if (popupMenuForRoof == null) {
final JMenuItem miPaste = new JMenuItem("Paste");
miPaste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, Config.isMac() ? KeyEvent.META_MASK : InputEvent.CTRL_MASK));
miPaste.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
SceneManager.getTaskManager().update(new Callable<Object>() {
@Override
public Object call() throws Exception {
Scene.getInstance().pasteToPickedLocationOnRoof();
Scene.getInstance().setEdited(true);
return null;
}
});
}
});
final JMenuItem miClear = new JMenuItem("Clear");
miClear.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
SceneManager.getTaskManager().update(new Callable<Object>() {
@Override
public Object call() throws Exception {
Scene.getInstance().removeAllChildren(SceneManager.getInstance().getSelectedPart());
Scene.getInstance().setEdited(true);
return null;
}
});
}
});
final JMenuItem miOverhang = new JMenuItem("Overhang Length...");
miOverhang.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (!(selectedPart instanceof Roof)) {
return;
}
final Roof roof = (Roof) selectedPart;
while (true) {
SceneManager.getInstance().refresh(1);
final String newValue = JOptionPane.showInputDialog(MainFrame.getInstance(), "Overhang Length (m)", roof.getOverhangLength() * Scene.getInstance().getAnnotationScale());
if (newValue == null) {
break;
} else {
try {
double val = Double.parseDouble(newValue);
final double min = Roof.OVERHANG_MIN * Scene.getInstance().getAnnotationScale() * 10;
if (val < min && val >= 0) {
val = min;
}
if (val < 0 || val > 10) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Overhang value must be between " + min + " and 10.", "Error", JOptionPane.ERROR_MESSAGE);
} else {
if (Math.abs(val - roof.getOverhangLength() * Scene.getInstance().getAnnotationScale()) > 0.000001) {
final ChangeRoofOverhangCommand c = new ChangeRoofOverhangCommand(roof);
roof.setOverhangLength(val / Scene.getInstance().getAnnotationScale());
roof.draw();
final Foundation f = roof.getTopContainer();
f.drawChildren();
SceneManager.getInstance().refresh();
updateAfterEdit();
SceneManager.getInstance().getUndoManager().addEdit(c);
}
break;
}
} catch (final NumberFormatException exception) {
exception.printStackTrace();
JOptionPane.showMessageDialog(MainFrame.getInstance(), newValue + " is an invalid value!", "Error", JOptionPane.ERROR_MESSAGE);
}
}
}
}
});
final JMenu typeMenu = new JMenu("Type");
final ButtonGroup typeGroup = new ButtonGroup();
final JRadioButtonMenuItem rbmiSolid = new JRadioButtonMenuItem("Solid");
rbmiSolid.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Roof) {
final Roof roof = (Roof) selectedPart;
final ChangeRoofTypeCommand c = new ChangeRoofTypeCommand(roof);
roof.setType(Roof.SOLID);
roof.draw();
SceneManager.getInstance().refresh();
Scene.getInstance().setEdited(true);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
}
}
});
typeMenu.add(rbmiSolid);
typeGroup.add(rbmiSolid);
final JRadioButtonMenuItem rbmiTransparent = new JRadioButtonMenuItem("Transparent");
rbmiTransparent.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Roof) {
final Roof roof = (Roof) selectedPart;
final ChangeRoofTypeCommand c = new ChangeRoofTypeCommand(roof);
roof.setType(Roof.TRANSPARENT);
roof.draw();
SceneManager.getInstance().refresh();
Scene.getInstance().setEdited(true);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
}
}
});
typeMenu.add(rbmiTransparent);
typeGroup.add(rbmiTransparent);
typeMenu.addMenuListener(new MenuListener() {
@Override
public void menuSelected(final MenuEvent e) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Roof) {
final Roof roof = (Roof) selectedPart;
switch(roof.getType()) {
case Roof.SOLID:
Util.selectSilently(rbmiSolid, true);
break;
case Roof.TRANSPARENT:
Util.selectSilently(rbmiTransparent, true);
break;
}
}
}
@Override
public void menuDeselected(final MenuEvent e) {
typeMenu.setEnabled(true);
}
@Override
public void menuCanceled(final MenuEvent e) {
typeMenu.setEnabled(true);
}
});
final JMenu textureMenu = new JMenu("Texture");
final ButtonGroup textureGroup = new ButtonGroup();
final JRadioButtonMenuItem rbmiTextureNone = new JRadioButtonMenuItem("No Texture");
rbmiTextureNone.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
final ChangeBuildingTextureCommand c = new ChangeBuildingTextureCommand();
Scene.getInstance().setTextureMode(TextureMode.None);
Scene.getInstance().setEdited(true);
if (MainPanel.getInstance().getEnergyButton().isSelected()) {
MainPanel.getInstance().getEnergyButton().setSelected(false);
}
SceneManager.getInstance().getUndoManager().addEdit(c);
}
}
});
textureGroup.add(rbmiTextureNone);
textureMenu.add(rbmiTextureNone);
final JRadioButtonMenuItem rbmiTextureOutline = new JRadioButtonMenuItem("Outline Texture");
rbmiTextureOutline.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
final ChangeBuildingTextureCommand c = new ChangeBuildingTextureCommand();
Scene.getInstance().setTextureMode(TextureMode.Simple);
Scene.getInstance().setEdited(true);
if (MainPanel.getInstance().getEnergyButton().isSelected()) {
MainPanel.getInstance().getEnergyButton().setSelected(false);
}
SceneManager.getInstance().getUndoManager().addEdit(c);
}
}
});
textureGroup.add(rbmiTextureOutline);
textureMenu.add(rbmiTextureOutline);
textureMenu.addSeparator();
final JRadioButtonMenuItem rbmiTexture01 = MainFrame.getInstance().createRoofTextureMenuItem(Roof.TEXTURE_01, "icons/roof_01.png");
final JRadioButtonMenuItem rbmiTexture02 = MainFrame.getInstance().createRoofTextureMenuItem(Roof.TEXTURE_02, "icons/roof_02.png");
final JRadioButtonMenuItem rbmiTexture03 = MainFrame.getInstance().createRoofTextureMenuItem(Roof.TEXTURE_03, "icons/roof_03.png");
final JRadioButtonMenuItem rbmiTexture04 = MainFrame.getInstance().createRoofTextureMenuItem(Roof.TEXTURE_04, "icons/roof_04.png");
final JRadioButtonMenuItem rbmiTexture05 = MainFrame.getInstance().createRoofTextureMenuItem(Roof.TEXTURE_05, "icons/roof_05.png");
final JRadioButtonMenuItem rbmiTexture06 = MainFrame.getInstance().createRoofTextureMenuItem(Roof.TEXTURE_06, "icons/roof_06.png");
textureGroup.add(rbmiTexture01);
textureGroup.add(rbmiTexture02);
textureGroup.add(rbmiTexture03);
textureGroup.add(rbmiTexture04);
textureGroup.add(rbmiTexture05);
textureGroup.add(rbmiTexture06);
textureMenu.add(rbmiTexture01);
textureMenu.add(rbmiTexture02);
textureMenu.add(rbmiTexture03);
textureMenu.add(rbmiTexture04);
textureMenu.add(rbmiTexture05);
textureMenu.add(rbmiTexture06);
textureMenu.addMenuListener(new MenuListener() {
@Override
public void menuSelected(final MenuEvent e) {
if (Scene.getInstance().getTextureMode() == TextureMode.None) {
Util.selectSilently(rbmiTextureNone, true);
return;
}
if (Scene.getInstance().getTextureMode() == TextureMode.Simple) {
Util.selectSilently(rbmiTextureOutline, true);
return;
}
switch(Scene.getInstance().getRoofTextureType()) {
case Roof.TEXTURE_01:
Util.selectSilently(rbmiTexture01, true);
break;
case Roof.TEXTURE_02:
Util.selectSilently(rbmiTexture02, true);
break;
case Roof.TEXTURE_03:
Util.selectSilently(rbmiTexture03, true);
break;
case Roof.TEXTURE_04:
Util.selectSilently(rbmiTexture04, true);
break;
case Roof.TEXTURE_05:
Util.selectSilently(rbmiTexture05, true);
break;
case Roof.TEXTURE_06:
Util.selectSilently(rbmiTexture06, true);
break;
}
}
@Override
public void menuDeselected(final MenuEvent e) {
textureMenu.setEnabled(true);
}
@Override
public void menuCanceled(final MenuEvent e) {
textureMenu.setEnabled(true);
}
});
popupMenuForRoof = createPopupMenu(false, false, new Runnable() {
@Override
public void run() {
final HousePart copyBuffer = Scene.getInstance().getCopyBuffer();
miPaste.setEnabled(copyBuffer instanceof SolarPanel || copyBuffer instanceof Window || copyBuffer instanceof Rack);
}
});
popupMenuForRoof.add(miPaste);
popupMenuForRoof.add(miClear);
popupMenuForRoof.addSeparator();
popupMenuForRoof.add(miOverhang);
popupMenuForRoof.add(colorAction);
popupMenuForRoof.add(createInsulationMenuItem(false));
popupMenuForRoof.add(createVolumetricHeatCapacityMenuItem());
popupMenuForRoof.addSeparator();
popupMenuForRoof.add(typeMenu);
popupMenuForRoof.add(textureMenu);
popupMenuForRoof.addSeparator();
JMenuItem mi = new JMenuItem("Daily Energy Analysis...");
mi.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
if (EnergyPanel.getInstance().adjustCellSize()) {
return;
}
if (SceneManager.getInstance().getSelectedPart() instanceof Roof) {
new EnergyDailyAnalysis().show("Daily Energy for Roof");
}
}
});
popupMenuForRoof.add(mi);
mi = new JMenuItem("Annual Energy Analysis...");
mi.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
if (EnergyPanel.getInstance().adjustCellSize()) {
return;
}
if (SceneManager.getInstance().getSelectedPart() instanceof Roof) {
new EnergyAnnualAnalysis().show("Annual Energy for Roof");
}
}
});
popupMenuForRoof.add(mi);
}
return popupMenuForRoof;
}
use of javax.swing.event.MenuListener in project omegat by omegat-org.
the class MainWindowMenu method initComponents.
/**
* Initialize menu items.
*/
@SuppressWarnings("serial")
JMenuBar initComponents() {
mainMenu = new JMenuBar();
mainMenu.add(projectMenu = createMenu("TF_MENU_FILE"));
mainMenu.add(editMenu = createMenu("TF_MENU_EDIT"));
mainMenu.add(gotoMenu = createMenu("MW_GOTOMENU"));
mainMenu.add(viewMenu = createMenu("MW_VIEW_MENU"));
mainMenu.add(toolsMenu = createMenu("TF_MENU_TOOLS"));
mainMenu.add(optionsMenu = createMenu("MW_OPTIONSMENU"));
mainMenu.add(helpMenu = createMenu("TF_MENU_HELP"));
projectMenu.add(projectNewMenuItem = createMenuItem("TF_MENU_FILE_CREATE"));
projectMenu.add(projectTeamNewMenuItem = createMenuItem("TF_MENU_FILE_TEAM_CREATE"));
projectMenu.add(projectOpenMenuItem = createMenuItem("TF_MENU_FILE_OPEN"));
projectMenu.add(projectOpenRecentMenuItem = createMenu("TF_MENU_FILE_OPEN_RECENT"));
projectMenu.add(projectImportMenuItem = createMenuItem("TF_MENU_FILE_IMPORT"));
projectMenu.add(projectWikiImportMenuItem = createMenuItem("TF_MENU_WIKI_IMPORT"));
projectMenu.add(projectReloadMenuItem = createMenuItem("TF_MENU_PROJECT_RELOAD"));
projectMenu.add(projectCloseMenuItem = createMenuItem("TF_MENU_FILE_CLOSE"));
projectMenu.addSeparator();
projectMenu.add(projectSaveMenuItem = createMenuItem("TF_MENU_FILE_SAVE"));
projectMenu.addSeparator();
projectMenu.add(projectCommitSourceFiles = createMenuItem("TF_MENU_FILE_COMMIT"));
projectMenu.add(projectCommitTargetFiles = createMenuItem("TF_MENU_FILE_TARGET"));
projectMenu.addSeparator();
projectMenu.add(projectCompileMenuItem = createMenuItem("TF_MENU_FILE_COMPILE"));
projectMenu.add(projectSingleCompileMenuItem = createMenuItem("TF_MENU_FILE_SINGLE_COMPILE"));
projectMenu.addSeparator();
projectMenu.add(projectMedOpenMenuItem = createMenuItem("TF_MENU_FILE_MED_OPEN"));
projectMenu.add(projectMedCreateMenuItem = createMenuItem("TF_MENU_FILE_MED_CREATE"));
projectMenu.addSeparator();
projectMenu.add(projectEditMenuItem = createMenuItem("MW_PROJECTMENU_EDIT"));
projectMenu.add(viewFileListMenuItem = createMenuItem("TF_MENU_FILE_PROJWIN"));
projectMenu.add(projectAccessProjectFilesMenu = createMenu("TF_MENU_FILE_ACCESS_PROJECT_FILES"));
projectAccessProjectFilesMenu.add(projectAccessRootMenuItem = createMenuItem("TF_MENU_FILE_ACCESS_ROOT"));
projectAccessProjectFilesMenu.add(projectAccessDictionaryMenuItem = createMenuItem("TF_MENU_FILE_ACCESS_DICTIONARY"));
projectAccessProjectFilesMenu.add(projectAccessGlossaryMenuItem = createMenuItem("TF_MENU_FILE_ACCESS_GLOSSARY"));
projectAccessProjectFilesMenu.add(projectAccessSourceMenuItem = createMenuItem("TF_MENU_FILE_ACCESS_SOURCE"));
projectAccessProjectFilesMenu.add(projectAccessTargetMenuItem = createMenuItem("TF_MENU_FILE_ACCESS_TARGET"));
projectAccessProjectFilesMenu.add(projectAccessTMMenuItem = createMenuItem("TF_MENU_FILE_ACCESS_TM"));
projectAccessProjectFilesMenu.addSeparator();
projectAccessProjectFilesMenu.add(projectAccessCurrentSourceDocumentMenuItem = createMenuItem("TF_MENU_FILE_ACCESS_CURRENT_SOURCE_DOCUMENT"));
projectAccessProjectFilesMenu.add(projectAccessCurrentTargetDocumentMenuItem = createMenuItem("TF_MENU_FILE_ACCESS_CURRENT_TARGET_DOCUMENT"));
projectAccessProjectFilesMenu.add(projectAccessWriteableGlossaryMenuItem = createMenuItem("TF_MENU_FILE_ACCESS_WRITEABLE_GLOSSARY"));
projectAccessProjectFilesMenu.addMenuListener(new MenuListener() {
@Override
public void menuSelected(MenuEvent e) {
if (Core.getProject().isProjectLoaded()) {
String sourcePath = Core.getEditor().getCurrentFile();
projectAccessCurrentSourceDocumentMenuItem.setEnabled(!StringUtil.isEmpty(sourcePath) && new File(Core.getProject().getProjectProperties().getSourceRoot(), sourcePath).isFile());
String targetPath = Core.getEditor().getCurrentTargetFile();
projectAccessCurrentTargetDocumentMenuItem.setEnabled(!StringUtil.isEmpty(targetPath) && new File(Core.getProject().getProjectProperties().getTargetRoot(), targetPath).isFile());
String glossaryPath = Core.getProject().getProjectProperties().getWriteableGlossary();
projectAccessWriteableGlossaryMenuItem.setEnabled(!StringUtil.isEmpty(glossaryPath) && new File(glossaryPath).isFile());
}
}
@Override
public void menuDeselected(MenuEvent e) {
}
@Override
public void menuCanceled(MenuEvent e) {
}
});
projectExitMenuItem = createMenuItem("TF_MENU_FILE_QUIT");
// all except MacOSX
if (!Platform.isMacOSX()) {
projectMenu.addSeparator();
projectMenu.add(projectExitMenuItem);
}
editMenu.add(editUndoMenuItem = createMenuItem("TF_MENU_EDIT_UNDO"));
editMenu.add(editRedoMenuItem = createMenuItem("TF_MENU_EDIT_REDO"));
editMenu.addSeparator();
editMenu.add(editOverwriteTranslationMenuItem = createMenuItem("TF_MENU_EDIT_RECYCLE"));
editMenu.add(editInsertTranslationMenuItem = createMenuItem("TF_MENU_EDIT_INSERT"));
editMenu.addSeparator();
editMenu.add(editOverwriteMachineTranslationMenuItem = createMenuItem("TF_MENU_EDIT_OVERWRITE_MACHITE_TRANSLATION"));
editMenu.addSeparator();
editMenu.add(editOverwriteSourceMenuItem = createMenuItem("TF_MENU_EDIT_SOURCE_OVERWRITE"));
editMenu.add(editInsertSourceMenuItem = createMenuItem("TF_MENU_EDIT_SOURCE_INSERT"));
editMenu.addSeparator();
editMenu.add(editTagPainterMenuItem = createMenuItem("TF_MENU_EDIT_TAGPAINT"));
editMenu.add(editTagNextMissedMenuItem = createMenuItem("TF_MENU_EDIT_TAG_NEXT_MISSED"));
editMenu.addSeparator();
editMenu.add(editExportSelectionMenuItem = createMenuItem("TF_MENU_EDIT_EXPORT_SELECTION"));
editMenu.add(editCreateGlossaryEntryMenuItem = createMenuItem("TF_MENU_EDIT_CREATE_GLOSSARY_ENTRY"));
editMenu.addSeparator();
editMenu.add(editFindInProjectMenuItem = createMenuItem("TF_MENU_EDIT_FIND"));
editMenu.add(editReplaceInProjectMenuItem = createMenuItem("TF_MENU_EDIT_REPLACE"));
editMenu.addSeparator();
editMenu.add(switchCaseSubMenu = createMenu("TF_EDIT_MENU_SWITCH_CASE"));
editMenu.add(selectFuzzySubMenu = createMenu("TF_MENU_EDIT_COMPARE"));
selectFuzzySubMenu.add(editSelectFuzzyPrevMenuItem = createMenuItem("TF_MENU_EDIT_COMPARE_PREV"));
selectFuzzySubMenu.add(editSelectFuzzyNextMenuItem = createMenuItem("TF_MENU_EDIT_COMPARE_NEXT"));
selectFuzzySubMenu.addSeparator();
selectFuzzySubMenu.add(editSelectFuzzy1MenuItem = createMenuItem("TF_MENU_EDIT_COMPARE_1"));
selectFuzzySubMenu.add(editSelectFuzzy2MenuItem = createMenuItem("TF_MENU_EDIT_COMPARE_2"));
selectFuzzySubMenu.add(editSelectFuzzy3MenuItem = createMenuItem("TF_MENU_EDIT_COMPARE_3"));
selectFuzzySubMenu.add(editSelectFuzzy4MenuItem = createMenuItem("TF_MENU_EDIT_COMPARE_4"));
selectFuzzySubMenu.add(editSelectFuzzy5MenuItem = createMenuItem("TF_MENU_EDIT_COMPARE_5"));
editMenu.add(insertCharsSubMenu = createMenu("TF_MENU_EDIT_INSERT_CHARS"));
insertCharsSubMenu.add(insertCharsLRM = createMenuItem("TF_MENU_EDIT_INSERT_CHARS_LRM"));
insertCharsSubMenu.add(insertCharsRLM = createMenuItem("TF_MENU_EDIT_INSERT_CHARS_RLM"));
insertCharsSubMenu.addSeparator();
insertCharsSubMenu.add(insertCharsLRE = createMenuItem("TF_MENU_EDIT_INSERT_CHARS_LRE"));
insertCharsSubMenu.add(insertCharsRLE = createMenuItem("TF_MENU_EDIT_INSERT_CHARS_RLE"));
insertCharsSubMenu.add(insertCharsPDF = createMenuItem("TF_MENU_EDIT_INSERT_CHARS_PDF"));
editMenu.addSeparator();
editMenu.add(editMultipleDefault = createMenuItem("MULT_MENU_DEFAULT"));
editMenu.add(editMultipleAlternate = createMenuItem("MULT_MENU_MULTIPLE"));
editMenu.addSeparator();
editMenu.add(editRegisterUntranslatedMenuItem = createMenuItem("TF_MENU_EDIT_UNTRANSLATED_TRANSLATION"));
editMenu.add(editRegisterEmptyMenuItem = createMenuItem("TF_MENU_EDIT_EMPTY_TRANSLATION"));
editMenu.add(editRegisterIdenticalMenuItem = createMenuItem("TF_MENU_EDIT_IDENTICAL_TRANSLATION"));
switchCaseSubMenu.add(lowerCaseMenuItem = createMenuItem("TF_EDIT_MENU_SWITCH_CASE_TO_LOWER"));
switchCaseSubMenu.add(upperCaseMenuItem = createMenuItem("TF_EDIT_MENU_SWITCH_CASE_TO_UPPER"));
switchCaseSubMenu.add(titleCaseMenuItem = createMenuItem("TF_EDIT_MENU_SWITCH_CASE_TO_TITLE"));
switchCaseSubMenu.add(sentenceCaseMenuItem = createMenuItem("TF_EDIT_MENU_SWITCH_CASE_TO_SENTENCE"));
switchCaseSubMenu.addSeparator();
switchCaseSubMenu.add(cycleSwitchCaseMenuItem = createMenuItem("TF_EDIT_MENU_SWITCH_CASE_CYCLE"));
gotoMenu.add(gotoNextUntranslatedMenuItem = createMenuItem("TF_MENU_EDIT_UNTRANS"));
gotoMenu.add(gotoNextTranslatedMenuItem = createMenuItem("TF_MENU_EDIT_TRANS"));
gotoMenu.add(gotoNextSegmentMenuItem = createMenuItem("TF_MENU_EDIT_NEXT"));
gotoMenu.add(gotoPreviousSegmentMenuItem = createMenuItem("TF_MENU_EDIT_PREV"));
gotoMenu.add(gotoSegmentMenuItem = createMenuItem("TF_MENU_EDIT_GOTO"));
gotoMenu.add(gotoNextNoteMenuItem = createMenuItem("TF_MENU_EDIT_NEXT_NOTE"));
gotoMenu.add(gotoPreviousNoteMenuItem = createMenuItem("TF_MENU_EDIT_PREV_NOTE"));
gotoMenu.add(gotoNextUniqueMenuItem = createMenuItem("TF_MENU_GOTO_NEXT_UNIQUE"));
gotoMenu.add(gotoMatchSourceSegment = createMenuItem("TF_MENU_GOTO_SELECTED_MATCH_SOURCE"));
gotoMenu.addSeparator();
gotoMenu.add(gotoHistoryForwardMenuItem = createMenuItem("TF_MENU_GOTO_FORWARD_IN_HISTORY"));
gotoMenu.add(gotoHistoryBackMenuItem = createMenuItem("TF_MENU_GOTO_BACK_IN_HISTORY"));
viewMenu.add(viewMarkTranslatedSegmentsCheckBoxMenuItem = createCheckboxMenuItem("TF_MENU_DISPLAY_MARK_TRANSLATED"));
viewMenu.add(viewMarkUntranslatedSegmentsCheckBoxMenuItem = createCheckboxMenuItem("TF_MENU_DISPLAY_MARK_UNTRANSLATED"));
viewMenu.add(viewDisplaySegmentSourceCheckBoxMenuItem = createCheckboxMenuItem("MW_VIEW_MENU_DISPLAY_SEGMENT_SOURCES"));
viewMenu.add(viewMarkNonUniqueSegmentsCheckBoxMenuItem = createCheckboxMenuItem("MW_VIEW_MENU_MARK_NON_UNIQUE_SEGMENTS"));
viewMenu.add(viewMarkNotedSegmentsCheckBoxMenuItem = createCheckboxMenuItem("MW_VIEW_MENU_MARK_NOTED_SEGMENTS"));
viewMenu.add(viewMarkNBSPCheckBoxMenuItem = createCheckboxMenuItem("MW_VIEW_MENU_MARK_NBSP"));
viewMenu.add(viewMarkWhitespaceCheckBoxMenuItem = createCheckboxMenuItem("MW_VIEW_MENU_MARK_WHITESPACE"));
viewMenu.add(viewMarkBidiCheckBoxMenuItem = createCheckboxMenuItem("MW_VIEW_MENU_MARK_BIDI"));
viewMenu.add(viewMarkAutoPopulatedCheckBoxMenuItem = createCheckboxMenuItem("MW_VIEW_MENU_MARK_AUTOPOPULATED"));
viewMenu.add(viewMarkGlossaryMatchesCheckBoxMenuItem = createCheckboxMenuItem("MW_VIEW_GLOSSARY_MARK"));
viewMenu.add(viewMarkLanguageCheckerCheckBoxMenuItem = createCheckboxMenuItem("LT_OPTIONS_MENU_ENABLED"));
viewMenu.add(viewMarkFontFallbackCheckBoxMenuItem = createCheckboxMenuItem("MW_VIEW_MENU_MARK_FONT_FALLBACK"));
viewMenu.add(viewModificationInfoMenu = createMenu("MW_VIEW_MENU_MODIFICATION_INFO"));
ButtonGroup viewModificationInfoMenuBG = new ButtonGroup();
viewModificationInfoMenu.add(viewDisplayModificationInfoNoneRadioButtonMenuItem = createRadioButtonMenuItem("MW_VIEW_MENU_MODIFICATION_INFO_NONE", viewModificationInfoMenuBG));
viewModificationInfoMenu.add(viewDisplayModificationInfoSelectedRadioButtonMenuItem = createRadioButtonMenuItem("MW_VIEW_MENU_MODIFICATION_INFO_SELECTED", viewModificationInfoMenuBG));
viewModificationInfoMenu.add(viewDisplayModificationInfoAllRadioButtonMenuItem = createRadioButtonMenuItem("MW_VIEW_MENU_MODIFICATION_INFO_ALL", viewModificationInfoMenuBG));
viewMarkTranslatedSegmentsCheckBoxMenuItem.setIcon(MainMenuIcons.newColorIcon(Styles.EditorColor.COLOR_TRANSLATED.getColor()));
viewMarkUntranslatedSegmentsCheckBoxMenuItem.setIcon(MainMenuIcons.newColorIcon(Styles.EditorColor.COLOR_UNTRANSLATED.getColor()));
viewDisplaySegmentSourceCheckBoxMenuItem.setIcon(MainMenuIcons.newColorIcon(Styles.EditorColor.COLOR_SOURCE.getColor()));
viewMarkNonUniqueSegmentsCheckBoxMenuItem.setIcon(MainMenuIcons.newTextIcon(Styles.EditorColor.COLOR_NON_UNIQUE.getColor(), 'M'));
viewMarkNotedSegmentsCheckBoxMenuItem.setIcon(MainMenuIcons.newColorIcon(Styles.EditorColor.COLOR_NOTED.getColor()));
viewMarkNBSPCheckBoxMenuItem.setIcon(MainMenuIcons.newColorIcon(Styles.EditorColor.COLOR_NBSP.getColor()));
viewMarkWhitespaceCheckBoxMenuItem.setIcon(MainMenuIcons.newColorIcon(Styles.EditorColor.COLOR_WHITESPACE.getColor()));
viewMarkBidiCheckBoxMenuItem.setIcon(MainMenuIcons.newColorIcon(Styles.EditorColor.COLOR_BIDIMARKERS.getColor()));
viewModificationInfoMenu.setIcon(MainMenuIcons.newBlankIcon());
viewMarkAutoPopulatedCheckBoxMenuItem.setIcon(MainMenuIcons.newColorIcon(Styles.EditorColor.COLOR_MARK_COMES_FROM_TM_XAUTO.getColor()));
viewMarkGlossaryMatchesCheckBoxMenuItem.setIcon(MainMenuIcons.newColorIcon(Styles.EditorColor.COLOR_TRANSTIPS.getColor()));
viewMarkLanguageCheckerCheckBoxMenuItem.setIcon(MainMenuIcons.newColorIcon(Styles.EditorColor.COLOR_LANGUAGE_TOOLS.getColor()));
viewMarkFontFallbackCheckBoxMenuItem.setIcon(MainMenuIcons.newTextIcon(UIManager.getColor("Label.foreground"), new Font("Serif", Font.ITALIC, 16), 'F'));
viewMenu.addSeparator();
viewMenu.add(viewRestoreGUIMenuItem = createMenuItem("MW_OPTIONSMENU_RESTORE_GUI"));
toolsMenu.add(toolsCheckIssuesMenuItem = createMenuItem("TF_MENU_TOOLS_CHECK_ISSUES"));
toolsMenu.add(toolsCheckIssuesCurrentFileMenuItem = createMenuItem("TF_MENU_TOOLS_CHECK_ISSUES_CURRENT_FILE"));
toolsMenu.add(toolsShowStatisticsStandardMenuItem = createMenuItem("TF_MENU_TOOLS_STATISTICS_STANDARD"));
toolsMenu.add(toolsShowStatisticsMatchesMenuItem = createMenuItem("TF_MENU_TOOLS_STATISTICS_MATCHES"));
toolsMenu.add(toolsShowStatisticsMatchesPerFileMenuItem = createMenuItem("TF_MENU_TOOLS_STATISTICS_MATCHES_PER_FILE"));
toolsMenu.addSeparator();
toolsMenu.add(toolsAlignFilesMenuItem = createMenuItem("TF_MENU_TOOLS_ALIGN_FILES"));
optionsPreferencesMenuItem = createMenuItem("MW_OPTIONSMENU_PREFERENCES");
if (!Platform.isMacOSX()) {
optionsMenu.add(optionsPreferencesMenuItem);
optionsMenu.addSeparator();
}
optionsMenu.add(optionsMachineTranslateMenu = createMenu("TF_OPTIONSMENU_MACHINETRANSLATE"));
optionsMachineTranslateMenu.add(optionsMTAutoFetchCheckboxMenuItem = createCheckboxMenuItem("MT_AUTO_FETCH"));
optionsMachineTranslateMenu.addSeparator();
optionsMenu.add(optionsGlossaryMenu = createMenu("TF_OPTIONSMENU_GLOSSARY"));
optionsGlossaryMenu.addSeparator();
// TaaS options come next (but are added from elsewhere)
optionsMenu.add(optionsDictionaryMenu = createMenu("TF_OPTIONSMENU_DICTIONARY"));
optionsDictionaryMenu.add(optionsDictionaryFuzzyMatchingCheckBoxMenuItem = createCheckboxMenuItem("TF_OPTIONSMENU_DICTIONARY_FUZZY"));
optionsMenu.add(optionsAutoCompleteMenu = createMenu("MW_OPTIONSMENU_AUTOCOMPLETE"));
// add any autocomplete view configuration menu items below
optionsAutoCompleteMenu.add(optionsAutoCompleteShowAutomaticallyItem = createCheckboxMenuItem("MW_OPTIONSMENU_AUTOCOMPLETE_SHOW_AUTOMATICALLY"));
optionsAutoCompleteMenu.add(optionsAutoCompleteHistoryCompletionMenuItem = createCheckboxMenuItem("MW_OPTIONSMENU_AUTOCOMPLETE_HISTORY_COMPLETION"));
optionsAutoCompleteMenu.add(optionsAutoCompleteHistoryPredictionMenuItem = createCheckboxMenuItem("MW_OPTIONSMENU_AUTOCOMPLETE_HISTORY_PREDICTION"));
optionsMenu.addSeparator();
optionsMenu.add(optionsSetupFileFiltersMenuItem = createMenuItem("TF_MENU_DISPLAY_FILTERS"));
optionsMenu.add(optionsSentsegMenuItem = createMenuItem("MW_OPTIONSMENU_SENTSEG"));
optionsMenu.add(optionsWorkflowMenuItem = createMenuItem("MW_OPTIONSMENU_WORKFLOW"));
optionsMenu.addSeparator();
optionsMenu.add(optionsAccessConfigDirMenuItem = createMenuItem("MW_OPTIONSMENU_ACCESS_CONFIG_DIR"));
optionsMenu.addSeparator();
helpMenu.add(helpContentsMenuItem = createMenuItem("TF_MENU_HELP_CONTENTS"));
helpMenu.add(helpAboutMenuItem = createMenuItem("TF_MENU_HELP_ABOUT"));
helpMenu.add(helpLastChangesMenuItem = createMenuItem("TF_MENU_HELP_LAST_CHANGES"));
helpMenu.add(helpLogMenuItem = createMenuItem("TF_MENU_HELP_LOG"));
setActionCommands();
PropertiesShortcuts.getMainMenuShortcuts().bindKeyStrokes(mainMenu);
String key = "findInProjectReuseLastWindow";
KeyStroke stroke = PropertiesShortcuts.getMainMenuShortcuts().getKeyStroke(key);
mainWindow.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(stroke, key);
mainWindow.getRootPane().getActionMap().put(key, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
Log.logInfoRB("LOG_MENU_CLICK", key);
mainWindowMenuHandler.findInProjectReuseLastWindow();
}
});
if (Platform.isMacOSX()) {
initMacSpecific();
}
CoreEvents.registerApplicationEventListener(new IApplicationEventListener() {
public void onApplicationStartup() {
updateCheckboxesOnStart();
onProjectStatusChanged(false);
}
public void onApplicationShutdown() {
}
});
CoreEvents.registerProjectChangeListener(e -> onProjectStatusChanged(Core.getProject().isProjectLoaded()));
Preferences.addPropertyChangeListener(e -> {
if (e.getNewValue() instanceof Boolean) {
JMenuItem item = getItemForPreference(e.getPropertyName());
if (item != null) {
item.setSelected((Boolean) e.getNewValue());
}
}
});
return mainMenu;
}
use of javax.swing.event.MenuListener in project triplea by triplea-game.
the class GameMenu method addNotificationSettings.
private void addNotificationSettings() {
final JMenu notificationMenu = new JMenu();
notificationMenu.setMnemonic(KeyEvent.VK_U);
notificationMenu.setText("User Notifications");
final JCheckBoxMenuItem showEndOfTurnReport = new JCheckBoxMenuItem("Show End of Turn Report");
showEndOfTurnReport.setMnemonic(KeyEvent.VK_R);
final JCheckBoxMenuItem showTriggeredNotifications = new JCheckBoxMenuItem("Show Triggered Notifications");
showTriggeredNotifications.setMnemonic(KeyEvent.VK_T);
final JCheckBoxMenuItem showTriggerChanceSuccessful = new JCheckBoxMenuItem("Show Trigger/Condition Chance Roll Successful");
showTriggerChanceSuccessful.setMnemonic(KeyEvent.VK_S);
final JCheckBoxMenuItem showTriggerChanceFailure = new JCheckBoxMenuItem("Show Trigger/Condition Chance Roll Failure");
showTriggerChanceFailure.setMnemonic(KeyEvent.VK_F);
notificationMenu.addMenuListener(new MenuListener() {
@Override
public void menuSelected(final MenuEvent e) {
showEndOfTurnReport.setSelected(uiContext.getShowEndOfTurnReport());
showTriggeredNotifications.setSelected(uiContext.getShowTriggeredNotifications());
showTriggerChanceSuccessful.setSelected(uiContext.getShowTriggerChanceSuccessful());
showTriggerChanceFailure.setSelected(uiContext.getShowTriggerChanceFailure());
}
@Override
public void menuDeselected(final MenuEvent e) {
}
@Override
public void menuCanceled(final MenuEvent e) {
}
});
showEndOfTurnReport.addActionListener(e -> uiContext.setShowEndOfTurnReport(showEndOfTurnReport.isSelected()));
showTriggeredNotifications.addActionListener(e -> uiContext.setShowTriggeredNotifications(showTriggeredNotifications.isSelected()));
showTriggerChanceSuccessful.addActionListener(e -> uiContext.setShowTriggerChanceSuccessful(showTriggerChanceSuccessful.isSelected()));
showTriggerChanceFailure.addActionListener(e -> uiContext.setShowTriggerChanceFailure(showTriggerChanceFailure.isSelected()));
notificationMenu.add(showEndOfTurnReport);
notificationMenu.add(showTriggeredNotifications);
notificationMenu.add(showTriggerChanceSuccessful);
notificationMenu.add(showTriggerChanceFailure);
add(notificationMenu);
}
use of javax.swing.event.MenuListener in project airavata by apache.
the class XBayaMenuItem method createFileMenu.
private void createFileMenu() {
createOpenWorkflowMenuItem();
createSaveWorkflowItem();
createSaveAsWorkflowItem();
createSaveAllWorkflowItem();
createSaveWorkflowtoRegistryItem();
createImportWorkflowItemFromFileSystem();
createImportWorkflowItemFromRegistry();
createExportJythonScriptItem();
createExportBpelScriptItem();
createSaveWorkflowImageItem();
createExportODEScriptsItem();
clearWorkflowItem = createClearWorkflowItem();
newWorkflowTabItem = createNewWorkflowTabMenuItem();
closeWorkflowItem = createCloseWorkflowTabItem();
closeAllWorkflowItem = createCloseAllWorkflowTabItem();
nextWorkflowTabItem = createNextWorkflowTabItem();
urlItem = createURLRegistryItem();
// createRegisterHostDesc();
// createRegisterServiceDesc();
// createRegisterApplicationDesc();
xbayaMenuItem = new JMenu("XBaya");
xbayaMenuItem.setMnemonic(KeyEvent.VK_X);
// JMenu newMenu = new JMenu("New");
// newMenu.add(newWorkflowTabItem);
// newMenu.addSeparator();
//
// newMenu.add(this.registerApplicationDesc);
// newMenu.addSeparator();
// JMenu regAddSubMenuItem = new JMenu("Registry additions");
// newMenu.add(regAddSubMenuItem);
// regAddSubMenuItem.add(this.registerHostDesc);
// regAddSubMenuItem.add(this.registerServiceDesc);
//
// xbayaMenuItem.add(newMenu);
xbayaMenuItem.add(newWorkflowTabItem);
// xbayaMenuItem.add(registerHostDesc);
// xbayaMenuItem.add(this.registerServiceDesc);
// xbayaMenuItem.add(registerApplicationDesc);
xbayaMenuItem.add(importWorkflowItemFromRegistry);
xbayaMenuItem.add(saveWorkflowtoRegistryItem);
xbayaMenuItem.addSeparator();
xbayaMenuItem.add(this.openWorkflowItem);
xbayaMenuItem.addSeparator();
xbayaMenuItem.add(clearWorkflowItem);
xbayaMenuItem.add(closeWorkflowItem);
xbayaMenuItem.add(closeAllWorkflowItem);
// This menu item did not seem useful at all
// xbayaMenuItem.add(this.nextWorkflowTabItem);
xbayaMenuItem.addSeparator();
xbayaMenuItem.add(this.saveWorkflowItem);
xbayaMenuItem.add(this.saveAsWorkflowItem);
xbayaMenuItem.add(this.saveAllWorkflowItem);
// JMenu importMenu = new JMenu("Import");
// importMenu.add(importWorkflowItemFromFileSystem);
// importMenu.add(importWorkflowItemFromRegistry);
// importMenu.addSeparator();
// importMenu.add(urlItem);
// JMenu exportMenu = new JMenu("Export");
// exportMenu.add(saveWorkflowtoRegistryItem);
// exportMenu.addSeparator();
// exportMenu.add(exportJythonItem);
// exportMenu.add(exportBpelItem);
// exportMenu.add(exportODEScriptsItem);
// exportMenu.addSeparator();
// exportMenu.add(saveImageItem);
//
// xbayaMenuItem.add(importMenu);
// xbayaMenuItem.add(exportMenu);
xbayaMenuItem.addSeparator();
xbayaMenuItem.add(exitItem);
xbayaMenuItem.addMenuListener(new MenuListener() {
@Override
public void menuSelected(MenuEvent e) {
GraphCanvas graphCanvas = engine.getGUI().getGraphCanvas();
saveAsWorkflowItem.setEnabled(isWorkflowTabPresent() && graphCanvas.getWorkflowFile() != null);
saveWorkflowItem.setEnabled(isSaveShouldBeActive());
saveAllWorkflowItem.setEnabled(engine.getGUI().getGraphCanvases().size() > 0);
saveWorkflowtoRegistryItem.setEnabled(isWorkflowTabPresent());
exportJythonItem.setEnabled(isWorkflowTabPresent());
exportBpelItem.setEnabled(isWorkflowTabPresent());
exportODEScriptsItem.setEnabled(isWorkflowTabPresent());
saveImageItem.setEnabled(isWorkflowTabPresent());
}
@Override
public void menuDeselected(MenuEvent e) {
}
@Override
public void menuCanceled(MenuEvent e) {
}
});
executionModeChanged(engine.getConfiguration());
}
Aggregations