List of usage examples for java.awt.event ActionEvent getActionCommand
public String getActionCommand()
From source file:org.jfree.chart.demo.DynamicDataDemo3.java
/** * Handles a click on the button by adding new (random) data. * * @param e the action event./*from w ww . j a v a2s . c o m*/ */ public void actionPerformed(final ActionEvent e) { for (int i = 0; i < SUBPLOT_COUNT; i++) { if (e.getActionCommand().endsWith(String.valueOf(i))) { final Millisecond now = new Millisecond(); System.out.println("Now = " + now.toString()); this.lastValue[i] = this.lastValue[i] * (0.90 + 0.2 * Math.random()); this.datasets[i].getSeries(0).add(new Millisecond(), this.lastValue[i]); } } if (e.getActionCommand().equals("ADD_ALL")) { final Millisecond now = new Millisecond(); System.out.println("Now = " + now.toString()); for (int i = 0; i < SUBPLOT_COUNT; i++) { this.lastValue[i] = this.lastValue[i] * (0.90 + 0.2 * Math.random()); this.datasets[i].getSeries(0).add(new Millisecond(), this.lastValue[i]); } } }
From source file:org.simbrain.plot.scatterplot.ScatterPlotGui.java
/** @see ActionListener */ public void actionPerformed(ActionEvent arg0) { if (arg0.getActionCommand().equalsIgnoreCase("dialog")) { for (int i = getWorkspaceComponent().getModel().getChartSeriesPaint().size(); i < chart.getXYPlot() .getSeriesCount(); ++i) { getWorkspaceComponent().getModel().getChartSeriesPaint().add(renderer.getSeriesPaint(i)); }// ww w .j a v a2 s . c o m ScatterPlotDialog dialog = new ScatterPlotDialog(chart, getWorkspaceComponent().getModel()); // JDialog dialog = new JDialog(); // dialog.setContentPane(new // ReflectivePropertyEditor(getWorkspaceComponent() // .getModel(), dialog)); dialog.pack(); dialog.setLocationRelativeTo(null); dialog.setVisible(true); } else if (arg0.getActionCommand().equalsIgnoreCase("Delete")) { this.getWorkspaceComponent().getModel().removeDataSource(); } else if (arg0.getActionCommand().equalsIgnoreCase("Add")) { this.getWorkspaceComponent().getModel().addDataSource(); } }
From source file:com.emental.mindraider.ui.dialogs.SearchConceptAnnotation.java
/** * Constructor.//from ww w . j a v a 2 s.c o m */ public SearchConceptAnnotation(AbstractTextAnnotationRenderer renderer) { super("Search Annotation"); this.renderer = renderer; JPanel dialogPanel = new JPanel(); dialogPanel.setBorder(new EmptyBorder(5, 10, 0, 10)); dialogPanel.setLayout(new BorderLayout()); JPanel contentAndButtons = new JPanel(new GridLayout(2, 1)); JPanel contentPanel = new JPanel(new BorderLayout()); // 1a. // TODO add help like in eclipse contentPanel.add(new JLabel(Messages.getString("FtsJDialog.searchString")), BorderLayout.NORTH); // 1b. searchCombo = new JComboBox(history.toArray()); searchCombo.setSelectedItem(""); searchCombo.setPreferredSize(new Dimension(200, 18)); searchCombo.setEditable(true); searchCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if ("comboBoxEdited".equals(e.getActionCommand())) { search(); } } }); contentPanel.add(searchCombo, BorderLayout.SOUTH); contentAndButtons.add(contentPanel); // 2. JPanel p = new JPanel(); p.setLayout(new FlowLayout(FlowLayout.CENTER, 1, 5)); JButton searchButton = new JButton(Messages.getString("FtsJDialog.searchButton")); searchButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { search(); } }); p.add(searchButton); JButton cancelButton = new JButton(Messages.getString("FtsJDialog.cancel")); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); } }); p.add(cancelButton); contentAndButtons.add(p); dialogPanel.add(contentAndButtons, BorderLayout.CENTER); getContentPane().add(dialogPanel, BorderLayout.CENTER); // show pack(); Gfx.centerAndShowWindow(this); }
From source file:assign3.client.WaypointClient.java
public void actionPerformed(ActionEvent e) { try {//from ww w . j a va2 s .c o m if (e.getActionCommand().equals("Remove")) { debug("you clicked Remove Waypoint"); frWps.removeItem(frWps.getSelectedItem()); toWps.removeItem(toWps.getSelectedItem()); } else if (e.getActionCommand().equals("Add")) { debug("you clicked Add Waypoint"); addWaypoint(); distBearIn.setText("Added: " + nameIn.getText()); } else if (e.getActionCommand().equals("Modify")) { debug("you clicked Modify Waypoint"); } else if (e.getActionCommand().equals("GetLatLon")) { debug("you clicked Get Lat/Lon"); } else if (e.getActionCommand().equals("exportToJSON")) { debug("you clicked export to JSON"); String[] names = server.getNames(); //Check this JSONObject obj = new JSONObject(); for (int i = 0; i < names.length; i++) { Waypoint wp = server.get(names[i]); obj.put(names[i], wp.toJson()); } } else if (e.getActionCommand().equals("Distance")) { debug("you clicked Distance and Bearing"); String wpFrom = frWps.getSelectedItem().toString(); String wpTo = toWps.getSelectedItem().toString(); NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(4); String distCalc = nf.format(server.distGC(wpFrom, wpTo)); String dirCalc = nf.format(server.directionGC(wpFrom, wpTo)); server.distGC(frWps.getName(), toWps.getName()); server.directionGC(frWps.getName(), toWps.getName()); distBearIn.setText("Distance from " + wpFrom + " to " + wpTo + " is " + distCalc + " miles, bearing " + dirCalc + "."); } } catch (RemoteException ex) { System.out.println("Server connection error."); } catch (Exception e1) { e1.printStackTrace(); } }
From source file:br.com.criativasoft.opendevice.samples.ui.SimpleChart.java
public SimpleChart(final String title, final StreamConnection connection) { super(title); dataset = new DynamicTimeSeriesCollection(SERIES, COUNT, new Second()); dataset.setTimeBase(new Second(0, 0, 0, 1, 1, Calendar.getInstance().get(Calendar.YEAR))); // Init.//from ww w .j a v a2 s. co m // for (int i = 0; i < SERIES; i++){ // dataset.addSeries(new float[]{0}, i, "Serie " + (i+1)); // } dataset.addSeries(new float[] { 0, 0, 0 }, 0, "Raw"); dataset.addSeries(new float[] { 0, 0, 0 }, 1, "Software"); dataset.addSeries(new float[] { 0, 0, 0 }, 2, "Hardware"); this.connection = connection; // connection.setStreamReader(new FixedStreamReader(1)); JFreeChart chart = createChart(dataset); final JButton run = new JButton(START); run.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); JButton source = (JButton) e.getSource(); try { if (cmd.equals(START)) { connection.addListener(SimpleChart.this); if (!connection.isConnected()) connection.connect(); source.setText(STOP); source.setActionCommand(STOP); } else { connection.removeListener(SimpleChart.this); source.setText(START); source.setActionCommand(START); } } catch (ConnectionException e1) { e1.printStackTrace(); } } }); final JComboBox combo = new JComboBox(); if (connection instanceof UsbConnection) { Collection<String> portNames = UsbConnection.listAvailablePortNames(); for (String name : portNames) { combo.addItem(name); } } combo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Object selectedItem = combo.getSelectedItem(); } }); this.add(new ChartPanel(chart), BorderLayout.CENTER); JPanel btnPanel = new JPanel(new FlowLayout()); btnPanel.add(run); btnPanel.add(combo); this.add(btnPanel, BorderLayout.SOUTH); }
From source file:com.game.ui.views.MapEditor.java
@Override public void actionPerformed(ActionEvent ae) { if (ae.getActionCommand().equalsIgnoreCase("Save Map")) { UserDialog dialog = new UserDialog("Pls Enter the Map Name.", this); String mapName = dialog.getValue(); if (StringUtils.isNotBlank(mapName)) { GameBean.mapInfo.setMapName(mapName); File file = new File(Configuration.PATH_FOR_MAP); MapInformationWrapper wrapper = null; if (file.exists()) { try { wrapper = GameUtils.readMapInformation(Configuration.PATH_FOR_MAP); } catch (Exception ex) { ex.printStackTrace(); }/*from w ww. j av a2s .co m*/ } else { wrapper = new MapInformationWrapper(); } if (wrapper != null) { try { wrapper.getMapList().add(GameBean.mapInfo); GameUtils.writeMapInformation(wrapper, Configuration.PATH_FOR_MAP); JOptionPane.showMessageDialog(this, "Saved Successfully.."); } catch (Exception ex) { ex.printStackTrace(); } } } } else { JButton src = (JButton) ae.getSource(); String location = src.getActionCommand(); GameBean.mapInfo.getPathMap().put(Integer.parseInt(location), null); GameBean.mapInfo.getStartPointInfo().remove(new Integer(location)); new ComplexDialog(location); TileInformation info = GameBean.mapInfo.getPathMap().get(Integer.parseInt(location)); if (info != null) { if (info.isStartTile()) { src.setBackground(Configuration.startPointColor); } else if (info.isEndTile()) { src.setBackground(Configuration.endPointColor); } else if (info.getEnemy() != null) { src.setBackground(Configuration.enemyColor); } else { src.setBackground(Configuration.pathColor); } } else { Color color = UIManager.getColor("Button.background"); src.setBackground(color); } } }
From source file:org.jfree.chart.demo.DynamicDataDemo2.java
/** * Handles a click on the button by adding new (random) data. * * @param e the action event.//w w w .j a v a 2 s . c o m */ public void actionPerformed(final ActionEvent e) { boolean add1 = false; boolean add2 = false; if (e.getActionCommand().equals("ADD_DATA_1")) { add1 = true; } else if (e.getActionCommand().equals("ADD_DATA_2")) { add2 = true; } else if (e.getActionCommand().equals("ADD_BOTH")) { add1 = true; add2 = true; } if (add1) { final double factor = 0.90 + 0.2 * Math.random(); this.lastValue1 = this.lastValue1 * factor; final Millisecond now = new Millisecond(); System.out.println("Now = " + now.toString()); this.series1.add(new Millisecond(), this.lastValue1); } if (add2) { final double factor = 0.90 + 0.2 * Math.random(); this.lastValue2 = this.lastValue2 * factor; final Millisecond now = new Millisecond(); System.out.println("Now = " + now.toString()); this.series2.add(new Millisecond(), this.lastValue2); } }
From source file:mulavito.samples.GraphAlgorithmDemo.java
@Override public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); if (cmd.equals("about")) { String html = "<html><h1>" + getTitle() + "</h1>"; html += "WWW: http://mulavito.sf.net"; html += "<h3>Demo Authors</h3>"; html += "in alphabetical order:"; html += "<ul>"; html += "<li>Michael Duelli"; html += "</ul>"; html += "</html>"; JOptionPane.showMessageDialog(this, html); } else if (cmd.equals("graph")) { graphpanel.setLayerStack(SampleGraphDocument.createConnectedDemo(1).getMlg()); } else if (cmd.equals("autosize")) { graphpanel.autoZoomToFit();//from w ww . j a v a2 s . c om } else { MyL layer = graphpanel.getLayerStack().iterator().next(); PickedState<MyV> pickedVertices = graphpanel.getViewer(layer).getPickedVertexState(); PickedState<MyE> pickedEdges = graphpanel.getViewer(layer).getPickedEdgeState(); List<MyV> vertices = new ArrayList<MyV>(layer.getVertices()); UniformStream rnd = new UniformStream(); int srcId = rnd.nextInt(vertices.size() - 1); int dstId; do { dstId = rnd.nextInt(vertices.size() - 1); } while (dstId == srcId); MyV source = vertices.get(srcId); MyV target = vertices.get(dstId); Transformer<MyE, Number> nev = new Transformer<MyE, Number>() { @Override public Number transform(MyE input) { return 1.0; } }; List<List<MyE>> paths = null; if (cmd.equals("eppstein")) { Eppstein<MyV, MyE> algo = new Eppstein<MyV, MyE>(layer, nev); int k = 3; paths = algo.getShortestPaths(source, target, k); } else if (cmd.equals("yen")) { Yen<MyV, MyE> algo = new Yen<MyV, MyE>(layer, nev); int k = 3; paths = algo.getShortestPaths(source, target, k); } else if (cmd.equals("suurballe-tarjan")) { SuurballeTarjan<MyV, MyE> algo = new SuurballeTarjan<MyV, MyE>(layer, nev); paths = algo.getDisjointPaths(source, target); } pickedVertices.clear(); pickedEdges.clear(); if (paths != null) { pickedVertices.pick(source, true); pickedVertices.pick(target, true); for (List<MyE> p : paths) for (MyE edge : p) pickedEdges.pick(edge, true); normalOutput("algo=" + cmd + ", src=" + source + ", dst=" + target + ":" + paths + "\n"); } graphpanel.updateUI(); } }
From source file:Seek.java
public void actionPerformed(ActionEvent ae) { String command = ae.getActionCommand(); if (command.equals("Forward")) { int dest = fpc.skip(1); System.err.println("Step forward " + dest + " frame."); } else if (command.equals("Backward")) { int dest = fpc.skip(-1); System.err.println("Step backward " + dest + " frame."); } else if (command.equals("Random")) { if (totalFrames == FramePositioningControl.FRAME_UNKNOWN) System.err.println("Cannot jump to a random frame."); else {/*from w w w. j a v a2 s . c o m*/ int randomFrame = (int) (totalFrames * Math.random()); randomFrame = fpc.seek(randomFrame); System.err.println("Jump to a random frame: " + randomFrame); } } int currentFrame = fpc.mapTimeToFrame(p.getMediaTime()); if (currentFrame != FramePositioningControl.FRAME_UNKNOWN) System.err.println("Current frame: " + currentFrame); }
From source file:br.com.elotech.sits.config.form.ConfigForm.java
@Override public void actionPerformed(ActionEvent e) { String actionCommand = e.getActionCommand(); if (actionCommand.equals(BTN_SAVE)) { save();//w w w . j a v a 2 s.c om } else if (actionCommand.equals(BTN_CANCEL)) { close(); } }