use of javax.swing.JRadioButtonMenuItem in project energy3d by concord-consortium.
the class PopupMenuForDoor method getPopupMenu.
static JPopupMenu getPopupMenu() {
if (popupMenuForDoor == null) {
final JMenuItem miSize = new JMenuItem("Size...");
miSize.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 Door)) {
return;
}
final Door door = (Door) selectedPart;
final HousePart container = door.getContainer();
final Foundation foundation = door.getTopContainer();
final String partInfo = door.toString().substring(0, selectedPart.toString().indexOf(')') + 1);
final JPanel gui = new JPanel(new BorderLayout());
final JPanel inputPanel = new JPanel(new GridLayout(2, 2, 5, 5));
gui.add(inputPanel, BorderLayout.CENTER);
inputPanel.add(new JLabel("Width (m): "));
final JTextField widthField = new JTextField(threeDecimalsFormat.format(door.getDoorWidth()));
inputPanel.add(widthField);
inputPanel.add(new JLabel("Height (m): "));
final JTextField heightField = new JTextField(threeDecimalsFormat.format(door.getDoorHeight()));
inputPanel.add(heightField);
inputPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
final JPanel scopePanel = new JPanel();
scopePanel.setLayout(new BoxLayout(scopePanel, BoxLayout.Y_AXIS));
scopePanel.setBorder(BorderFactory.createTitledBorder("Apply to:"));
final JRadioButton rb1 = new JRadioButton("Only this Door", true);
final JRadioButton rb2 = new JRadioButton("All Doors on this Wall");
final JRadioButton rb3 = new JRadioButton("All Doors of this Building");
scopePanel.add(rb1);
scopePanel.add(rb2);
scopePanel.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;
}
gui.add(scopePanel, BorderLayout.NORTH);
final Object[] options = new Object[] { "OK", "Cancel", "Apply" };
final JOptionPane optionPane = new JOptionPane(new Object[] { "Set Size for " + partInfo, gui }, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options, options[2]);
final JDialog dialog = optionPane.createDialog(MainFrame.getInstance(), "Door Size");
while (true) {
dialog.setVisible(true);
final Object choice = optionPane.getValue();
if (choice == options[1] || choice == null) {
break;
} else {
boolean ok = true;
double w = 0, h = 0;
try {
w = Double.parseDouble(widthField.getText());
h = Double.parseDouble(heightField.getText());
} catch (final NumberFormatException x) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Invalid input!", "Error", JOptionPane.ERROR_MESSAGE);
ok = false;
}
if (ok) {
double wmax = 10;
if (container instanceof Wall) {
wmax = ((Wall) container).getWallWidth() * 0.99;
}
double hmax = 10;
if (container instanceof Wall) {
hmax = ((Wall) container).getWallHeight() * 0.99;
}
if (w < 0.1 || w > wmax) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Width must be between 0.1 and " + (int) wmax + " m.", "Range Error", JOptionPane.ERROR_MESSAGE);
} else if (h < 0.1 || h > hmax) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Height must be between 0.1 and " + (int) hmax + " m.", "Range Error", JOptionPane.ERROR_MESSAGE);
} else {
boolean changed = Math.abs(w - door.getDoorWidth()) > 0.000001 || Math.abs(h - door.getDoorHeight()) > 0.000001;
if (rb1.isSelected()) {
if (changed) {
final SetPartSizeCommand c = new SetPartSizeCommand(door);
door.setDoorWidth(w);
door.setDoorHeight(h);
door.draw();
door.getContainer().draw();
SceneManager.getInstance().refresh();
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 0;
} else if (rb2.isSelected()) {
if (!changed) {
if (door.getContainer() instanceof Wall) {
final Wall wall = (Wall) door.getContainer();
for (final Door x : wall.getDoors()) {
if (Math.abs(w - x.getDoorWidth()) > 0.000001 || Math.abs(h - x.getDoorHeight()) > 0.000001) {
changed = true;
break;
}
}
}
}
if (changed) {
if (door.getContainer() instanceof Wall) {
final Wall wall = (Wall) door.getContainer();
final ChangeDoorSizeOnWallCommand c = new ChangeDoorSizeOnWallCommand(wall);
wall.setDoorSize(w, h);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
}
selectedScopeIndex = 1;
} else if (rb3.isSelected()) {
if (!changed) {
for (final Door x : foundation.getDoors()) {
if (Math.abs(w - x.getDoorWidth()) > 0.000001 || Math.abs(h - x.getDoorHeight()) > 0.000001) {
changed = true;
break;
}
}
}
if (changed) {
final SetSizeForDoorsOnFoundationCommand c = new SetSizeForDoorsOnFoundationCommand(foundation);
foundation.setSizeForDoors(w, h);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 2;
}
if (changed) {
updateAfterEdit();
}
if (choice == options[0]) {
break;
}
}
}
}
}
}
});
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().createWallTextureMenuItem(Door.TEXTURE_01, "icons/door_01.png");
textureGroup.add(rbmiTexture01);
textureMenu.add(rbmiTexture01);
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 Door.TEXTURE_01:
Util.selectSilently(rbmiTexture01, true);
break;
}
}
@Override
public void menuDeselected(final MenuEvent e) {
textureMenu.setEnabled(true);
}
@Override
public void menuCanceled(final MenuEvent e) {
textureMenu.setEnabled(true);
}
});
popupMenuForDoor = createPopupMenu(false, false, null);
popupMenuForDoor.addSeparator();
popupMenuForDoor.add(miSize);
popupMenuForDoor.add(colorAction);
popupMenuForDoor.add(textureMenu);
popupMenuForDoor.add(createInsulationMenuItem(true));
popupMenuForDoor.add(createVolumetricHeatCapacityMenuItem());
popupMenuForDoor.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 Door) {
new EnergyDailyAnalysis().show("Daily Energy for Door");
}
}
});
popupMenuForDoor.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 Door) {
new EnergyAnnualAnalysis().show("Annual Energy for Door");
}
}
});
popupMenuForDoor.add(mi);
}
return popupMenuForDoor;
}
use of javax.swing.JRadioButtonMenuItem in project gate-core by GateNLP.
the class MainFrame method initGuiComponents.
protected void initGuiComponents() {
this.getContentPane().setLayout(new BorderLayout());
Integer width = Gate.getUserConfig().getInt(GateConstants.MAIN_FRAME_WIDTH, 1024);
Integer height = Gate.getUserConfig().getInt(GateConstants.MAIN_FRAME_HEIGHT, 768);
Rectangle maxDimensions = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
this.setSize(new Dimension(Math.min(width, maxDimensions.width), Math.min(height, maxDimensions.height)));
if (Gate.getUserConfig().getBoolean(GateConstants.MAIN_FRAME_MAXIMIZED))
setExtendedState(JFrame.MAXIMIZED_BOTH);
setIconImages(Arrays.asList(new Image[] { new GATEVersionIcon(256, 256).getImage(), new GATEVersionIcon(128, 128).getImage(), new GATEVersionIcon(64, 64).getImage(), new GATEVersionIcon(48, 48).getImage(), new GATEVersionIcon(32, 32).getImage(), new GATEIcon(22, 22).getImage(), new GATEIcon(16, 16).getImage() }));
resourcesTree = new ResourcesTree();
resourcesTree.setModel(resourcesTreeModel);
resourcesTree.setRowHeight(0);
resourcesTree.setEditable(true);
ResourcesTreeCellRenderer treeCellRenderer = new ResourcesTreeCellRenderer();
resourcesTree.setCellRenderer(treeCellRenderer);
resourcesTree.setCellEditor(new ResourcesTreeCellEditor(resourcesTree, treeCellRenderer));
resourcesTree.setInvokesStopCellEditing(true);
resourcesTree.setRowHeight(0);
// expand all nodes
resourcesTree.expandRow(0);
resourcesTree.expandRow(1);
resourcesTree.expandRow(2);
resourcesTree.expandRow(3);
resourcesTree.expandRow(4);
resourcesTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
resourcesTree.setEnabled(true);
ToolTipManager.sharedInstance().registerComponent(resourcesTree);
resourcesTreeScroll = new JScrollPane(resourcesTree);
resourcesTree.setDragEnabled(true);
resourcesTree.setTransferHandler(new TransferHandler() {
// drag and drop that export a list of the selected documents
@Override
public int getSourceActions(JComponent c) {
return COPY;
}
@Override
protected Transferable createTransferable(JComponent c) {
TreePath[] paths = resourcesTree.getSelectionPaths();
if (paths == null) {
return new StringSelection("");
}
Handle handle;
List<String> documentsNames = new ArrayList<String>();
for (TreePath path : paths) {
if (path != null) {
Object value = path.getLastPathComponent();
value = ((DefaultMutableTreeNode) value).getUserObject();
if (value instanceof Handle) {
handle = (Handle) value;
if (handle.getTarget() instanceof Document) {
documentsNames.add(((Document) handle.getTarget()).getName());
}
}
}
}
return new StringSelection("ResourcesTree" + Arrays.toString(documentsNames.toArray()));
}
@Override
protected void exportDone(JComponent c, Transferable data, int action) {
}
@Override
public boolean canImport(JComponent c, DataFlavor[] flavors) {
return false;
}
@Override
public boolean importData(JComponent c, Transferable t) {
return false;
}
});
lowerScroll = new JScrollPane();
JPanel lowerPane = new JPanel();
lowerPane.setLayout(new OverlayLayout(lowerPane));
JPanel animationPane = new JPanel();
animationPane.setOpaque(false);
animationPane.setLayout(new BoxLayout(animationPane, BoxLayout.X_AXIS));
JPanel vBox = new JPanel();
vBox.setLayout(new BoxLayout(vBox, BoxLayout.Y_AXIS));
vBox.setOpaque(false);
JPanel hBox = new JPanel();
hBox.setLayout(new BoxLayout(hBox, BoxLayout.X_AXIS));
hBox.setOpaque(false);
vBox.add(Box.createVerticalGlue());
vBox.add(animationPane);
hBox.add(vBox);
hBox.add(Box.createHorizontalGlue());
lowerPane.add(hBox);
lowerPane.add(lowerScroll);
animator = new CartoonMinder(animationPane);
Thread thread = new Thread(Thread.currentThread().getThreadGroup(), animator, "MainFrame animation");
thread.setDaemon(true);
thread.setPriority(Thread.MIN_PRIORITY);
thread.start();
leftSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, resourcesTreeScroll, lowerPane);
leftSplit.setResizeWeight(0.7);
leftSplit.setContinuousLayout(true);
leftSplit.setOneTouchExpandable(true);
// Create a new logArea and redirect the Out and Err output to it.
logArea = new LogArea();
// Out has been redirected to the logArea
Out.prln("GATE " + Main.version + " build " + Main.build + " started at " + new Date().toString());
Out.prln("and using Java " + System.getProperty("java.version") + " " + System.getProperty("java.vendor") + " on " + System.getProperty("os.name") + " " + System.getProperty("os.arch") + " " + System.getProperty("os.version") + ".");
mainTabbedPane = new XJTabbedPane(JTabbedPane.TOP);
mainTabbedPane.insertTab("Messages", null, logArea.getComponentToDisplay(), "GATE log", 0);
logHighlighter = new TabHighlighter(mainTabbedPane, logArea.getComponentToDisplay(), Color.red);
mainSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftSplit, mainTabbedPane);
mainSplit.setDividerLocation(leftSplit.getPreferredSize().width + 10);
this.getContentPane().add(mainSplit, BorderLayout.CENTER);
mainSplit.setContinuousLayout(true);
mainSplit.setOneTouchExpandable(true);
// status and progress bars
statusBar = new JLabel("Welcome to GATE!");
statusBar.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
UIManager.put("ProgressBar.cellSpacing", 0);
progressBar = new JProgressBar(JProgressBar.HORIZONTAL);
progressBar.setBorder(BorderFactory.createEmptyBorder());
progressBar.setForeground(new Color(150, 75, 150));
progressBar.setStringPainted(false);
globalProgressBar = new JProgressBar(JProgressBar.HORIZONTAL);
globalProgressBar.setBorder(BorderFactory.createEmptyBorder());
globalProgressBar.setForeground(new Color(150, 75, 150));
globalProgressBar.setStringPainted(true);
JPanel southBox = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.BOTH;
gbc.anchor = GridBagConstraints.WEST;
gbc.weightx = 1;
southBox.add(statusBar, gbc);
gbc.insets = new Insets(0, 3, 0, 3);
gbc.anchor = GridBagConstraints.EAST;
gbc.weightx = 0;
southBox.add(progressBar, gbc);
southBox.add(globalProgressBar, gbc);
this.getContentPane().add(southBox, BorderLayout.SOUTH);
progressBar.setVisible(false);
globalProgressBar.setVisible(false);
// extra stuff
newResourceDialog = new NewResourceDialog(this, "Resource parameters", true);
// build the Help->About dialog
JPanel splashBox = new JPanel();
splashBox.setBackground(Color.WHITE);
splashBox.setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
constraints.weightx = 1;
constraints.insets = new Insets(2, 2, 2, 2);
constraints.gridy = 0;
constraints.fill = GridBagConstraints.BOTH;
JLabel gifLbl = new JLabel(getIcon("splash"));
splashBox.add(gifLbl, constraints);
constraints.gridy = 2;
constraints.gridwidth = 2;
constraints.fill = GridBagConstraints.HORIZONTAL;
String splashHtml;
try {
splashHtml = Files.getGateResourceAsString("splash.html");
} catch (IOException e) {
splashHtml = "GATE";
log.error("Couldn't get splash.html resource.", e);
}
JLabel htmlLbl = new JLabel(splashHtml);
htmlLbl.setHorizontalAlignment(SwingConstants.CENTER);
splashBox.add(htmlLbl, constraints);
constraints.gridy = 3;
htmlLbl = new JLabel("<HTML><FONT color=\"blue\">Version <B>" + Main.version + "</B></FONT>" + ", <FONT color=\"red\">build <B>" + Main.build + "</B></FONT>" + "<P><B>JVM version</B>: " + System.getProperty("java.version") + " from " + System.getProperty("java.vendor") + "</HTML>");
constraints.fill = GridBagConstraints.HORIZONTAL;
splashBox.add(htmlLbl, constraints);
constraints.gridy = 4;
constraints.gridwidth = 2;
constraints.fill = GridBagConstraints.NONE;
final JButton okButton = new JButton("OK");
okButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
splash.setVisible(false);
}
});
okButton.setBackground(Color.white);
splashBox.add(okButton, constraints);
splash = new Splash(this, splashBox);
// make Enter and Escape keys closing the splash window
splash.getRootPane().setDefaultButton(okButton);
InputMap inputMap = ((JComponent) splash.getContentPane()).getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
ActionMap actionMap = ((JComponent) splash.getContentPane()).getActionMap();
inputMap.put(KeyStroke.getKeyStroke("ENTER"), "Apply");
actionMap.put("Apply", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
okButton.doClick();
}
});
inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), "Cancel");
actionMap.put("Cancel", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
okButton.doClick();
}
});
// MENUS
menuBar = new JMenuBar();
JMenu fileMenu = new XJMenu("File", null, this);
fileMenu.setMnemonic(KeyEvent.VK_F);
LiveMenu newAPPMenu = new LiveMenu(LiveMenu.APP);
newAPPMenu.setText("New Application");
newAPPMenu.setIcon(getIcon("applications"));
fileMenu.add(newAPPMenu);
LiveMenu newLRMenu = new LiveMenu(LiveMenu.LR);
newLRMenu.setText("New Language Resource");
newLRMenu.setIcon(getIcon("lrs"));
fileMenu.add(newLRMenu);
LiveMenu newPRMenu = new LiveMenu(LiveMenu.PR);
newPRMenu.setText("New Processing Resource");
newPRMenu.setIcon(getIcon("prs"));
fileMenu.add(newPRMenu);
final JMenu dsMenu = new XJMenu("Datastores", "Repositories for large data", this);
dsMenu.setIcon(getIcon("datastores"));
dsMenu.add(new XJMenuItem(new NewDSAction(), this));
dsMenu.add(new XJMenuItem(new OpenDSAction(), this));
fileMenu.add(dsMenu);
fileMenu.addSeparator();
fileMenu.add(new ReadyMadeMenu());
fileMenu.add(new XJMenuItem(new LoadResourceFromFileAction(), this));
RecentAppsMenu recentAppsMenu = new RecentAppsMenu();
fileMenu.add(recentAppsMenu);
/*final JMenu loadANNIEMenu = new XJMenu("Load ANNIE System",
"Application that adds morphosyntaxic and semantic annotations", this);
loadANNIEMenu.setIcon(getIcon("annie-application"));
loadANNIEMenu.add(new XJMenuItem(new LoadANNIEWithDefaultsAction(), this));
loadANNIEMenu
.add(new XJMenuItem(new LoadANNIEWithoutDefaultsAction(), this));
fileMenu.add(loadANNIEMenu);
// LingPipe action
fileMenu.add(new XJMenuItem(new LoadApplicationAction(
"Load LingPipe System", "LingPipe", "resources/lingpipe.gapp"),
this));
// OpenNLP action
fileMenu.add(new XJMenuItem(new LoadApplicationAction(
"Load OpenNLP System", "OpenNLP", "resources/opennlp.gapp"), this));
*/
fileMenu.add(new XJMenuItem(new ManagePluginsAction(), this));
if (!Gate.runningOnMac()) {
fileMenu.addSeparator();
fileMenu.add(new XJMenuItem(new ExitGateAction(), this));
}
menuBar.add(fileMenu);
JMenu optionsMenu = new XJMenu("Options", null, this);
optionsMenu.setMnemonic(KeyEvent.VK_O);
boolean optionsMenuHasEntries = false;
optionsDialog = new OptionsDialog(MainFrame.this);
if (!Gate.runningOnMac()) {
optionsMenu.add(new XJMenuItem(new AbstractAction("Configuration") {
private static final long serialVersionUID = 1L;
{
putValue(SHORT_DESCRIPTION, "Edit GATE options");
}
@Override
public void actionPerformed(ActionEvent evt) {
optionsDialog.showDialog();
optionsDialog.dispose();
}
}, this));
optionsMenuHasEntries = true;
}
if (optionsMenuHasEntries) {
menuBar.add(optionsMenu);
}
ToolsMenu toolsMenu = new ToolsMenu("Tools", null, this);
toolsMenu.setMnemonic(KeyEvent.VK_T);
toolsMenu.add(new XJMenuItem(new NewAnnotDiffAction(), this));
try {
// Check if log4j is present on the classpath, in order to avoid failures
// in cases when running the GATE GUI in the same JVM with a system which
// uses SLF4J and the log4j bridge.
// The log4j-over-slf4j bridge does not include org.apache.log4j.Appender, so
// if the class is not present we assume the lack of a log4j jar in the classpath
// and do not populate the menu.
Class.forName("org.apache.log4j.Appender");
final JMenuItem reportClearMenuItem = new XJMenuItem(new AbstractAction("Clear Profiling History") {
{
putValue(SHORT_DESCRIPTION, "Clear profiling history otherwise the report is cumulative.");
}
@Override
public void actionPerformed(ActionEvent evt) {
// create a new log file
File logFile = new File(System.getProperty("java.io.tmpdir"), "gate-benchmark-log.txt");
logFile.deleteOnExit();
if (logFile.exists() && !logFile.delete()) {
log.info("Error when deleting the file:\n" + logFile.getAbsolutePath());
}
}
}, this);
JMenu reportMenu = new XJMenu("Profiling Reports", "Generates profiling reports from processing resources", this);
reportMenu.setIcon(getIcon("gazetteer"));
reportMenu.add(new XJMenuItem(new AbstractAction("Start Profiling Applications") {
{
putValue(SHORT_DESCRIPTION, "Toggles the profiling of processing resources");
}
// stores the value held by the benchmarking switch before we started
// this profiling run.
boolean benchmarkWasEnabled;
@Override
public void actionPerformed(ActionEvent evt) {
if (getValue(NAME).equals("Start Profiling Applications")) {
reportClearMenuItem.setEnabled(false);
// store old value of benchmark switch
benchmarkWasEnabled = Benchmark.isBenchmarkingEnabled();
Benchmark.setBenchmarkingEnabled(true);
Layout layout = new PatternLayout("%m%n");
File logFile = new File(System.getProperty("java.io.tmpdir"), "gate-benchmark-log.txt");
logFile.deleteOnExit();
Appender appender;
try {
appender = new FileAppender(layout, logFile.getAbsolutePath(), true);
} catch (IOException e) {
e.printStackTrace();
return;
}
appender.setName("gate-benchmark");
Benchmark.logger.addAppender(appender);
putValue(NAME, "Stop Profiling Applications");
} else {
// reset old value of benchmark switch - i.e. if benchmarking was
// disabled before the user selected "start profiling" then we
// disable it again now, but if it was already enabled before they
// started profiling then we assume it was turned on explicitly and
// leave it alone.
Benchmark.setBenchmarkingEnabled(benchmarkWasEnabled);
Benchmark.logger.removeAppender("gate-benchmark");
putValue(NAME, "Start Profiling Applications");
reportClearMenuItem.setEnabled(true);
}
}
}, this));
reportMenu.add(reportClearMenuItem);
reportMenu.add(new XJMenuItem(new AbstractAction("Help on this tool") {
@Override
public void actionPerformed(ActionEvent e) {
showHelpFrame("chap:profiling", "Profiling Processing Resources");
}
}, this));
reportMenu.addSeparator();
final JCheckBoxMenuItem reportZeroTimesCheckBox = new JCheckBoxMenuItem();
reportZeroTimesCheckBox.setAction(new AbstractAction("Report Zero Time Entries") {
@Override
public void actionPerformed(ActionEvent evt) {
Gate.getUserConfig().put(MainFrame.class.getName() + ".reportzerotime", reportZeroTimesCheckBox.isSelected());
}
});
reportZeroTimesCheckBox.setSelected(Gate.getUserConfig().getBoolean(MainFrame.class.getName() + ".reportzerotimes"));
ButtonGroup group = new ButtonGroup();
final JRadioButtonMenuItem reportSortExecution = new JRadioButtonMenuItem();
reportSortExecution.setAction(new AbstractAction("Sort by Execution") {
@Override
public void actionPerformed(ActionEvent evt) {
Gate.getUserConfig().put(MainFrame.class.getName() + ".reportsorttime", false);
}
});
reportSortExecution.setSelected(!Gate.getUserConfig().getBoolean(MainFrame.class.getName() + ".reportsorttime"));
group.add(reportSortExecution);
final JRadioButtonMenuItem reportSortTime = new JRadioButtonMenuItem();
reportSortTime.setAction(new AbstractAction("Sort by Time") {
@Override
public void actionPerformed(ActionEvent evt) {
Gate.getUserConfig().put(MainFrame.class.getName() + ".reportsorttime", true);
}
});
reportSortTime.setSelected(Gate.getUserConfig().getBoolean(MainFrame.class.getName() + ".reportsorttime"));
group.add(reportSortTime);
reportMenu.add(new XJMenuItem(new AbstractAction("Report on Processing Resources") {
{
putValue(SHORT_DESCRIPTION, "Report time taken by each processing resource");
}
@Override
public void actionPerformed(ActionEvent evt) {
PRTimeReporter report = new PRTimeReporter();
report.setBenchmarkFile(new File(System.getProperty("java.io.tmpdir"), "gate-benchmark-log.txt"));
report.setSuppressZeroTimeEntries(!reportZeroTimesCheckBox.isSelected());
report.setSortOrder(reportSortTime.isSelected() ? PRTimeReporter.SORT_TIME_TAKEN : PRTimeReporter.SORT_EXEC_ORDER);
try {
report.executeReport();
} catch (BenchmarkReportException e) {
e.printStackTrace();
return;
}
showHelpFrame("file://" + report.getReportFile(), "processing times report");
}
}, this));
reportMenu.add(reportZeroTimesCheckBox);
reportMenu.add(reportSortTime);
reportMenu.add(reportSortExecution);
reportMenu.addSeparator();
reportMenu.add(new XJMenuItem(new AbstractAction("Report on Documents Processed") {
{
putValue(SHORT_DESCRIPTION, "Report most time consuming documents");
}
@Override
public void actionPerformed(ActionEvent evt) {
DocTimeReporter report = new DocTimeReporter();
report.setBenchmarkFile(new File(System.getProperty("java.io.tmpdir"), "gate-benchmark-log.txt"));
String maxDocs = Gate.getUserConfig().getString(MainFrame.class.getName() + ".reportmaxdocs");
if (maxDocs != null) {
report.setMaxDocumentInReport((maxDocs.equals("All")) ? DocTimeReporter.ALL_DOCS : Integer.parseInt(maxDocs));
}
String prRegex = Gate.getUserConfig().getString(MainFrame.class.getName() + ".reportprregex");
if (prRegex != null) {
report.setPRMatchingRegex((prRegex.equals("")) ? DocTimeReporter.MATCH_ALL_PR_REGEX : prRegex);
}
try {
report.executeReport();
} catch (BenchmarkReportException e) {
e.printStackTrace();
return;
}
showHelpFrame("file://" + report.getReportFile(), "documents time report");
}
}, this));
String maxDocs = Gate.getUserConfig().getString(MainFrame.class.getName() + ".reportmaxdocs");
if (maxDocs == null) {
maxDocs = "10";
}
reportMenu.add(new XJMenuItem(new AbstractAction("Set Max Documents (" + maxDocs + ")") {
@Override
public void actionPerformed(ActionEvent evt) {
Object response = JOptionPane.showInputDialog(instance, "Set the maximum of documents to report", "Report options", JOptionPane.QUESTION_MESSAGE, null, new Object[] { "All", "10", "20", "30", "40", "50", "100" }, "10");
if (response != null) {
Gate.getUserConfig().put(MainFrame.class.getName() + ".reportmaxdocs", response);
putValue(NAME, "Set Max Documents (" + response + ")");
}
}
}, this));
String prRegex = Gate.getUserConfig().getString(MainFrame.class.getName() + ".reportprregex");
if (prRegex == null || prRegex.equals("")) {
prRegex = "All";
}
reportMenu.add(new XJMenuItem(new AbstractAction("Set PR Matching Regex (" + prRegex + ")") {
@Override
public void actionPerformed(ActionEvent evt) {
Object response = JOptionPane.showInputDialog(instance, "Set the processing resource regex filter\n" + "Leave empty to not filter", "Report options", JOptionPane.QUESTION_MESSAGE);
if (response != null) {
Gate.getUserConfig().put(MainFrame.class.getName() + ".reportprregex", response);
if (response.equals("")) {
response = "All";
}
putValue(NAME, "Set PR Matching Regex (" + response + ")");
}
}
}, this));
toolsMenu.add(reportMenu);
} catch (ClassNotFoundException e) {
log.warn("log4j.jar not found on the classpath, disabling profiling reports.");
}
toolsMenu.add(new XJMenuItem(new NewBootStrapAction(), this));
final JMenu corpusEvalMenu = new XJMenu("Corpus Benchmark", "Compares processed and human-annotated annotations", this);
corpusEvalMenu.setIcon(getIcon("corpus-benchmark"));
toolsMenu.add(corpusEvalMenu);
corpusEvalMenu.add(new XJMenuItem(new NewCorpusEvalAction(), this));
corpusEvalMenu.addSeparator();
corpusEvalMenu.add(new XJMenuItem(new GenerateStoredCorpusEvalAction(), this));
corpusEvalMenu.addSeparator();
corpusEvalMenu.add(new XJMenuItem(new StoredMarkedCorpusEvalAction(), this));
corpusEvalMenu.add(new XJMenuItem(new CleanMarkedCorpusEvalAction(), this));
corpusEvalMenu.addSeparator();
verboseModeItem = new JCheckBoxMenuItem(new VerboseModeCorpusEvalToolAction());
corpusEvalMenu.add(verboseModeItem);
toolsMenu.staticItemsAdded();
menuBar.add(toolsMenu);
JMenu helpMenu = new XJMenu("Help", null, MainFrame.this);
helpMenu.setMnemonic(KeyEvent.VK_H);
helpMenu.add(new XJMenuItem(new HelpUserGuideAction(), this));
helpMenu.add(new XJMenuItem(new HelpUserGuideInContextAction(), this));
helpMenu.add(new XJMenuItem(new AbstractAction("Keyboard Shortcuts") {
@Override
public void actionPerformed(ActionEvent e) {
showHelpFrame("sec:developer:keyboard", "shortcuts");
}
}, this));
helpMenu.addSeparator();
helpMenu.add(new XJMenuItem(new AbstractAction("Using GATE Developer") {
{
this.putValue(Action.SHORT_DESCRIPTION, "To read first");
}
@Override
public void actionPerformed(ActionEvent e) {
showHelpFrame("chap:developer", "Using GATE Developer");
}
}, this));
helpMenu.add(new XJMenuItem(new AbstractAction("Demo Movies") {
{
this.putValue(Action.SHORT_DESCRIPTION, "Movie tutorials");
}
@Override
public void actionPerformed(ActionEvent e) {
showHelpFrame("http://gate.ac.uk/demos/developer-videos/", "movies");
}
}, this));
helpMenu.add(new XJMenuItem(new HelpMailingListAction(), this));
helpMenu.addSeparator();
JCheckBoxMenuItem toggleToolTipsCheckBoxMenuItem = new JCheckBoxMenuItem(new ToggleToolTipsAction());
javax.swing.ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
if (Gate.getUserConfig().getBoolean(MainFrame.class.getName() + ".hidetooltips")) {
toolTipManager.setEnabled(false);
toggleToolTipsCheckBoxMenuItem.setSelected(false);
} else {
toolTipManager.setEnabled(true);
toggleToolTipsCheckBoxMenuItem.setSelected(true);
}
helpMenu.add(toggleToolTipsCheckBoxMenuItem);
helpMenu.add(new XJMenuItem(new AbstractAction("What's New") {
{
this.putValue(Action.SHORT_DESCRIPTION, "List new features and important changes");
}
@Override
public void actionPerformed(ActionEvent e) {
showHelpFrame("chap:changes", "changes");
}
}, this));
if (!Gate.runningOnMac()) {
helpMenu.add(new XJMenuItem(new HelpAboutAction(), this));
}
menuBar.add(helpMenu);
this.setJMenuBar(menuBar);
// popups
lrsPopup = new XJPopupMenu();
LiveMenu lrsMenu = new LiveMenu(LiveMenu.LR);
lrsMenu.setText("New");
lrsPopup.add(lrsMenu);
guiRoots.add(lrsPopup);
guiRoots.add(lrsMenu);
prsPopup = new XJPopupMenu();
LiveMenu prsMenu = new LiveMenu(LiveMenu.PR);
prsMenu.setText("New");
prsPopup.add(prsMenu);
guiRoots.add(prsPopup);
guiRoots.add(prsMenu);
dssPopup = new XJPopupMenu();
dssPopup.add(new NewDSAction());
dssPopup.add(new OpenDSAction());
guiRoots.add(dssPopup);
// TOOLBAR
toolbar = new JToolBar(JToolBar.HORIZONTAL);
toolbar.setFloatable(false);
JButton button = new JButton(new LoadResourceFromFileAction());
button.setToolTipText(button.getText());
button.setText("");
toolbar.add(button);
toolbar.addSeparator();
try {
JButton annieMenu = new JButton(new LoadApplicationAction("ANNIE", "annie-application", new ResourceReference(new URI("creole://uk.ac.gate.plugins;annie;" + gate.Main.version + "/resources/" + ANNIEConstants.DEFAULT_FILE))));
annieMenu.setText("");
annieMenu.setToolTipText("Load ANNIE");
toolbar.add(annieMenu);
toolbar.addSeparator();
} catch (URISyntaxException e) {
// should be impossible
}
LiveMenu tbNewLRMenu = new LiveMenu(LiveMenu.LR);
JMenuButton menuButton = new JMenuButton(tbNewLRMenu);
menuButton.setToolTipText("New Language Resource");
menuButton.setIcon(getIcon("lrs"));
toolbar.add(menuButton);
LiveMenu tbNewPRMenu = new LiveMenu(LiveMenu.PR);
menuButton = new JMenuButton(tbNewPRMenu);
menuButton.setToolTipText("New Processing Resource");
menuButton.setIcon(getIcon("prs"));
toolbar.add(menuButton);
LiveMenu tbNewAppMenu = new LiveMenu(LiveMenu.APP);
menuButton = new JMenuButton(tbNewAppMenu);
menuButton.setToolTipText("New Application");
menuButton.setIcon(getIcon("applications"));
toolbar.add(menuButton);
toolbar.addSeparator();
JPopupMenu tbDsMenu = new JPopupMenu();
tbDsMenu.add(new NewDSAction());
tbDsMenu.add(new OpenDSAction());
menuButton = new JMenuButton(tbDsMenu);
menuButton.setToolTipText("Datastores");
menuButton.setIcon(getIcon("datastores"));
toolbar.add(menuButton);
toolbar.addSeparator();
button = new JButton(new ManagePluginsAction());
button.setToolTipText(button.getText());
button.setText("");
toolbar.add(button);
toolbar.addSeparator();
button = new JButton(new NewAnnotDiffAction());
button.setToolTipText(button.getText());
button.setText("");
toolbar.add(button);
toolbar.add(Box.createHorizontalGlue());
this.getContentPane().add(toolbar, BorderLayout.NORTH);
}
use of javax.swing.JRadioButtonMenuItem in project jsql-injection by ron190.
the class NodeModelTable method buildMenu.
@Override
protected void buildMenu(JPopupMenu2 tablePopupMenu, final TreePath path) {
JMenuItem menuItemCheckAll = new JMenuItem(I18nView.valueByKey("COLUMNS_CHECK_ALL"), 'C');
I18nView.addComponentForKey("COLUMNS_CHECK_ALL", menuItemCheckAll);
JMenuItem menuItemUncheckAll = new JMenuItem(I18nView.valueByKey("COLUMNS_UNCHECK_ALL"), 'U');
I18nView.addComponentForKey("COLUMNS_UNCHECK_ALL", menuItemUncheckAll);
menuItemCheckAll.setIcon(HelperUi.ICON_EMPTY);
menuItemUncheckAll.setIcon(HelperUi.ICON_EMPTY);
if (!this.isLoaded()) {
menuItemCheckAll.setEnabled(false);
menuItemUncheckAll.setEnabled(false);
}
class ActionCheckbox implements ActionListener {
private boolean isCheckboxesSelected;
ActionCheckbox(boolean isCheckboxesSelected) {
this.isCheckboxesSelected = isCheckboxesSelected;
}
@Override
public void actionPerformed(ActionEvent arg0) {
final DefaultMutableTreeNode currentTableNode = (DefaultMutableTreeNode) path.getLastPathComponent();
final AbstractNodeModel currentTableModel = (AbstractNodeModel) currentTableNode.getUserObject();
DefaultTreeModel treeModel = (DefaultTreeModel) MediatorGui.treeDatabase().getModel();
int tableChildCount = treeModel.getChildCount(currentTableNode);
for (int i = 0; i < tableChildCount; i++) {
DefaultMutableTreeNode currentChild = (DefaultMutableTreeNode) treeModel.getChild(currentTableNode, i);
if (currentChild.getUserObject() instanceof AbstractNodeModel) {
AbstractNodeModel columnTreeNodeModel = (AbstractNodeModel) currentChild.getUserObject();
columnTreeNodeModel.setSelected(this.isCheckboxesSelected);
currentTableModel.setContainingSelection(this.isCheckboxesSelected);
}
}
treeModel.nodeChanged(currentTableNode);
}
}
class ActionCheckAll extends ActionCheckbox {
ActionCheckAll() {
super(true);
}
}
class ActionUncheckAll extends ActionCheckbox {
ActionUncheckAll() {
super(false);
}
}
menuItemCheckAll.addActionListener(new ActionCheckAll());
menuItemUncheckAll.addActionListener(new ActionUncheckAll());
menuItemCheckAll.setIcon(HelperUi.ICON_EMPTY);
menuItemUncheckAll.setIcon(HelperUi.ICON_EMPTY);
tablePopupMenu.add(new JSeparator());
tablePopupMenu.add(menuItemCheckAll);
tablePopupMenu.add(menuItemUncheckAll);
JMenu menuCustomLoad = new JMenu("Custom load");
ButtonGroup buttonGroupLoadRows = new ButtonGroup();
JMenuItem menuItemLoadAllRows = new JRadioButtonMenuItem("Load all rows (default)", true);
JMenuItem menuItemLoadOneRow = new JRadioButtonMenuItem("Load first row only");
JMenuItem menuItemDump = new JCheckBoxMenuItem("Dump to a file");
JPanel panelCustomFromRow = new JPanel(new BorderLayout());
final JTextField inputCustomFromRow = new JPopupTextField("no.", "1").getProxy();
inputCustomFromRow.setHorizontalAlignment(JTextField.TRAILING);
Dimension d = new Dimension((int) inputCustomFromRow.getPreferredSize().getWidth() + 50, (int) inputCustomFromRow.getPreferredSize().getHeight());
inputCustomFromRow.setPreferredSize(d);
final JCheckBox radioCustomFromRow = new JCheckBox("<html><pre style=\"font-family:'Segoe UI';padding-left: 1px;\">Load from row no.	</pre></html>");
radioCustomFromRow.setBorder(BorderFactory.createEmptyBorder(0, 6, 0, 0));
radioCustomFromRow.setIcon(new CheckBoxMenuItemIconCustom());
radioCustomFromRow.setFocusPainted(false);
panelCustomFromRow.add(radioCustomFromRow, BorderLayout.LINE_START);
panelCustomFromRow.add(inputCustomFromRow, BorderLayout.CENTER);
JPanel panelCustomToRow = new JPanel(new BorderLayout());
final JTextField inputCustomToRow = new JPopupTextField("no.", "65565").getProxy();
inputCustomToRow.setHorizontalAlignment(JTextField.TRAILING);
inputCustomToRow.setPreferredSize(d);
final JCheckBox radioCustomToRow = new JCheckBox("<html><pre style=\"font-family:'Segoe UI';padding-left: 1px;\">Load to row no.						</pre></html>");
radioCustomToRow.setBorder(BorderFactory.createEmptyBorder(0, 6, 0, 0));
radioCustomToRow.setIcon(new CheckBoxMenuItemIconCustom());
radioCustomToRow.setFocusPainted(false);
panelCustomToRow.add(radioCustomToRow, BorderLayout.LINE_START);
panelCustomToRow.add(inputCustomToRow, BorderLayout.CENTER);
JPanel panelCustomFromChar = new JPanel(new BorderLayout());
final JTextField inputCustomFromChar = new JPopupTextField("no.", "1").getProxy();
inputCustomFromChar.setHorizontalAlignment(JTextField.TRAILING);
inputCustomFromChar.setPreferredSize(d);
final JCheckBox radioCustomFromChar = new JCheckBox("<html><pre style=\"font-family:'Segoe UI';padding-left: 1px;\">Load from char no.</pre></html>");
radioCustomFromChar.setBorder(BorderFactory.createEmptyBorder(0, 6, 0, 0));
radioCustomFromChar.setIcon(new CheckBoxMenuItemIconCustom());
radioCustomFromChar.setFocusPainted(false);
panelCustomFromChar.add(radioCustomFromChar, BorderLayout.LINE_START);
panelCustomFromChar.add(inputCustomFromChar, BorderLayout.CENTER);
JPanel panelCustomToChar = new JPanel(new BorderLayout());
final JTextField inputCustomToChar = new JPopupTextField("no.", "65565").getProxy();
inputCustomToChar.setHorizontalAlignment(JTextField.TRAILING);
inputCustomToChar.setPreferredSize(d);
final JCheckBox radioCustomToChar = new JCheckBox("<html><pre style=\"font-family:'Segoe UI';padding-left: 1px;\">Load to char no.					</pre></html>");
radioCustomToChar.setBorder(BorderFactory.createEmptyBorder(0, 6, 0, 0));
radioCustomToChar.setIcon(new CheckBoxMenuItemIconCustom());
radioCustomToChar.setFocusPainted(false);
panelCustomToChar.add(radioCustomToChar, BorderLayout.LINE_START);
panelCustomToChar.add(inputCustomToChar, BorderLayout.CENTER);
buttonGroupLoadRows.add(menuItemLoadAllRows);
buttonGroupLoadRows.add(menuItemLoadOneRow);
menuCustomLoad.add(menuItemLoadAllRows);
menuCustomLoad.add(menuItemLoadOneRow);
menuCustomLoad.add(new JSeparator());
menuCustomLoad.add(panelCustomFromRow);
menuCustomLoad.add(panelCustomToRow);
menuCustomLoad.add(panelCustomFromChar);
menuCustomLoad.add(panelCustomToChar);
menuCustomLoad.add(new JSeparator());
menuCustomLoad.add(menuItemDump);
for (JMenuItem menuItem : new JMenuItem[] { menuItemLoadAllRows, menuItemLoadOneRow }) {
menuItem.setUI(new BasicRadioButtonMenuItemUI() {
@Override
protected void doClick(MenuSelectionManager msm) {
this.menuItem.doClick(0);
}
});
}
menuItemDump.setUI(new BasicCheckBoxMenuItemUI() {
@Override
protected void doClick(MenuSelectionManager msm) {
this.menuItem.doClick(0);
}
});
// tablePopupMenu.add(new JSeparator());
// tablePopupMenu.add(menuCustomLoad);
tablePopupMenu.setButtonGroupLoadRows(buttonGroupLoadRows);
tablePopupMenu.setRadioCustomFromChar(radioCustomFromChar);
tablePopupMenu.setRadioCustomToChar(radioCustomToChar);
tablePopupMenu.setRadioCustomFromRow(radioCustomFromRow);
tablePopupMenu.setRadioCustomToRow(radioCustomToRow);
}
use of javax.swing.JRadioButtonMenuItem in project energy3d by concord-consortium.
the class AnnualAnalysis method createOptionsMenu.
JMenu createOptionsMenu(final JDialog dialog, final List<HousePart> selectedParts, final boolean selectAll, final boolean exportStoredResults) {
final JMenuItem miClear = new JMenuItem("Clear Previous Results");
final JMenuItem miView = new JMenuItem("View Raw Data...");
final JMenuItem miExportStoredResults = new JMenuItem("Export Stored Hourly Results");
final JMenu menu = new JMenu("Options");
menu.addMenuListener(new MenuListener() {
@Override
public void menuSelected(final MenuEvent e) {
miClear.setEnabled(graph.hasRecords());
miView.setEnabled(graph.hasData());
miExportStoredResults.setEnabled(Scene.getInstance().getSolarResults() != null);
}
@Override
public void menuDeselected(final MenuEvent e) {
}
@Override
public void menuCanceled(final MenuEvent e) {
}
});
final JMenu chartMenu = new JMenu("Chart");
final ButtonGroup chartGroup = new ButtonGroup();
menu.add(chartMenu);
final JRadioButtonMenuItem miLine = new JRadioButtonMenuItem("Line");
miLine.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
graph.setGraphType(Graph.LINE_CHART);
graph.repaint();
}
}
});
chartMenu.add(miLine);
chartGroup.add(miLine);
miLine.setSelected(graph.getGraphType() == Graph.LINE_CHART);
final JRadioButtonMenuItem miArea = new JRadioButtonMenuItem("Area");
miArea.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
graph.setGraphType(Graph.AREA_CHART);
graph.repaint();
}
}
});
chartMenu.add(miArea);
chartGroup.add(miArea);
miArea.setSelected(graph.getGraphType() == Graph.AREA_CHART);
miClear.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final int i = JOptionPane.showConfirmDialog(dialog, "Are you sure that you want to clear all the previous results\nrelated to the selected object?", "Confirmation", JOptionPane.YES_NO_OPTION);
if (i != JOptionPane.YES_OPTION) {
return;
}
graph.clearRecords();
graph.repaint();
TimeSeriesLogger.getInstance().logClearGraphData(graph.getClass().getSimpleName());
}
});
menu.add(miClear);
miView.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
if (selectedParts == null) {
DataViewer.viewRawData(dialog, graph, selectAll);
} else {
DataViewer.viewRawData(dialog, graph, selectedParts);
}
}
});
menu.add(miView);
final JMenuItem miCopyImage = new JMenuItem("Copy Image");
miCopyImage.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
new ClipImage().copyImageToClipboard(graph);
}
});
menu.add(miCopyImage);
if (exportStoredResults) {
miExportStoredResults.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final double[][] solarResults = Scene.getInstance().getSolarResults();
if (solarResults != null) {
double sum = 0;
// Hack to fix the results in case we make a mistake that can be quickly remedied
final double scale = 1;
for (int i = 0; i < solarResults.length; i++) {
for (int j = 0; j < solarResults[i].length; j++) {
solarResults[i][j] *= scale;
sum += solarResults[i][j];
}
}
sum *= 365.0 / 12.0;
String s = "";
for (int i = 0; i < solarResults.length; i++) {
s += "\"" + AnnualGraph.THREE_LETTER_MONTH[i] + "\": \"";
for (int j = 0; j < solarResults[i].length; j++) {
s += EnergyPanel.FIVE_DECIMALS.format(solarResults[i][j]).replaceAll(",", "") + " ";
}
s = s.trim() + "\",\n\t";
}
s = s.substring(0, s.length() - 1);
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(s), null);
JOptionPane.showMessageDialog(dialog, "A total of " + EnergyPanel.TWO_DECIMALS.format(sum) + " KWh was copied to the clipboard.", "Export", JOptionPane.INFORMATION_MESSAGE);
}
}
});
menu.add(miExportStoredResults);
}
return menu;
}
use of javax.swing.JRadioButtonMenuItem in project energy3d by concord-consortium.
the class DailyAnalysis method createOptionsMenu.
JMenu createOptionsMenu(final JDialog dialog, final List<HousePart> selectedParts, final boolean selectAll) {
final JMenuItem miClear = new JMenuItem("Clear Previous Results");
final JMenuItem miView = new JMenuItem("View Raw Data...");
final JMenu menu = new JMenu("Options");
menu.addMenuListener(new MenuListener() {
@Override
public void menuSelected(final MenuEvent e) {
miClear.setEnabled(graph.hasRecords());
miView.setEnabled(graph.hasData());
}
@Override
public void menuDeselected(final MenuEvent e) {
}
@Override
public void menuCanceled(final MenuEvent e) {
}
});
final JMenu chartMenu = new JMenu("Chart");
final ButtonGroup chartGroup = new ButtonGroup();
menu.add(chartMenu);
final JRadioButtonMenuItem miLine = new JRadioButtonMenuItem("Line");
miLine.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
graph.setGraphType(Graph.LINE_CHART);
graph.repaint();
}
}
});
chartMenu.add(miLine);
chartGroup.add(miLine);
miLine.setSelected(graph.getGraphType() == Graph.LINE_CHART);
final JRadioButtonMenuItem miArea = new JRadioButtonMenuItem("Area");
miArea.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
graph.setGraphType(Graph.AREA_CHART);
graph.repaint();
}
}
});
chartMenu.add(miArea);
chartGroup.add(miArea);
miArea.setSelected(graph.getGraphType() == Graph.AREA_CHART);
final JCheckBoxMenuItem miMilitaryTime = new JCheckBoxMenuItem("Military Time");
miMilitaryTime.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (graph instanceof DailyGraph) {
((DailyGraph) graph).setMilitaryTime(miMilitaryTime.isSelected());
graph.repaint();
}
}
});
menu.add(miMilitaryTime);
miClear.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final int i = JOptionPane.showConfirmDialog(dialog, "Are you sure that you want to clear all the previous results\nrelated to the selected object?", "Confirmation", JOptionPane.YES_NO_OPTION);
if (i != JOptionPane.YES_OPTION) {
return;
}
graph.clearRecords();
graph.repaint();
TimeSeriesLogger.getInstance().logClearGraphData(graph.getClass().getSimpleName());
}
});
menu.add(miClear);
miView.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
if (selectedParts == null) {
DataViewer.viewRawData(dialog, graph, selectAll);
} else {
DataViewer.viewRawData(dialog, graph, selectedParts);
}
}
});
menu.add(miView);
final JMenuItem miCopyImage = new JMenuItem("Copy Image");
miCopyImage.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
new ClipImage().copyImageToClipboard(graph);
}
});
menu.add(miCopyImage);
return menu;
}
Aggregations