List of usage examples for java.awt.event ActionEvent getSource
public Object getSource()
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./* ww w . j a va 2s . 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:org.cytoscape.dyn.internal.graphMetrics.SaveChartDialog.java
@Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if (e.getSource() == cancelButton) { this.setVisible(false); this.dispose(); } else if (e.getSource() == saveChartButton) { JFileChooser saveFileDialog = new JFileChooser(); saveFileDialog// w ww . j a va 2 s . c o m .addChoosableFileFilter(new ExtensionFileFilter(".jpeg", ".jpg", "Jpeg images (.jpeg, .jpg)")); saveFileDialog.addChoosableFileFilter( new ExtensionFileFilter(".png", "Portable Network Graphic images (.png)")); saveFileDialog .addChoosableFileFilter(new ExtensionFileFilter(".svg", "Scalable Vector Graphics (.svg)")); int save = saveFileDialog.showSaveDialog(this); if (save == JFileChooser.APPROVE_OPTION) { File file = saveFileDialog.getSelectedFile(); int width = ((SpinnerNumberModel) widthSpinner.getModel()).getNumber().intValue(); int height = ((SpinnerNumberModel) heightSpinner.getModel()).getNumber().intValue(); ExtensionFileFilter filter = null; try { filter = (ExtensionFileFilter) saveFileDialog.getFileFilter(); if (!filter.hasExtension(file)) { file = filter.appendExtension(file); } } catch (ClassCastException ex) { // Try to infer the type of file by its extension FileFilter[] filters = saveFileDialog.getChoosableFileFilters(); for (int i = 0; i < filters.length; ++i) { if (filters[i] instanceof ExtensionFileFilter) { filter = (ExtensionFileFilter) filters[i]; if (filter.hasExtension(file)) { break; } filter = null; } } if (filter == null) { // Could not infer the type JOptionPane.showMessageDialog(null, "File type not specified!\nWhen giving file name, please also select one of the supported file types.", "Error", JOptionPane.ERROR_MESSAGE); return; } } // Save the chart to the specified file name try { String ext = filter.getExtension(); if (ext.equals("jpeg")) { ChartUtilities.saveChartAsJPEG(file, chart, width, height); } else if (ext.equals("png")) { ChartUtilities.saveChartAsPNG(file, chart, width, height); } else { VectorGraphics graphics = new SVGGraphics2D(file, new Dimension(width, height)); graphics.startExport(); chart.draw(graphics, new Rectangle2D.Double(0, 0, width, height)); graphics.endExport(); } } catch (IOException ex) { JOptionPane.showMessageDialog(null, "An error occurred while creating or writing to the file.", "Error", JOptionPane.ERROR_MESSAGE); return; } this.setVisible(false); this.dispose(); } else if (save == JFileChooser.ERROR_OPTION) { JOptionPane.showMessageDialog(null, "An error occurred while initializing the window.", "Error", JOptionPane.ERROR_MESSAGE); } } }
From source file:uk.co.petertribble.jkstat.gui.KstatBaseChartFrame.java
public void actionPerformed(ActionEvent e) { if (e.getSource() == exitItem) { kbc.stopLoop();//from w ww .j a v a 2 s. c om setVisible(false); dispose(); } else if (e.getSource() == saveItem) { saveImage(); } else if (e.getSource() == sleepItem1) { setDelay(1); } else if (e.getSource() == sleepItem2) { setDelay(2); } else if (e.getSource() == sleepItem5) { setDelay(5); } else if (e.getSource() == sleepItem10) { setDelay(10); } else if (e.getSource() instanceof JCheckBoxMenuItem) { JCheckBoxMenuItem jmi = (JCheckBoxMenuItem) e.getSource(); String stat = jmi.getText(); if (jmi.isSelected()) { kbc.addStatistic(stat); } else { kbc.removeStatistic(stat); } } }
From source file:PopupDemo.java
public void actionPerformed(ActionEvent e) { System.out.println("actionPerformed, event=" + e + ", mod=" + getMods(e)); System.out.println(" command=" + e.getActionCommand()); System.out.println(" param=" + e.paramString()); System.out.println(" source=" + e.getSource()); }
From source file:endrov.typeTimeRemap.TimeRemapWindow.java
public void actionPerformed(ActionEvent e) { if (e.getSource() == objectCombo) { loadData();// w w w . ja v a 2s. co m } if (e.getSource() == bAdd) { addEntry(EvDecimal.ZERO, EvDecimal.ZERO); fillGraphpart(); fillDatapart(); storeData(); } else if (e.getSource() == bRefresh) { loadData(); } for (int i = 0; i < inputVector.size(); i++) if (inputVector.get(i).bDelete == e.getSource()) { //TODO non-optimal. keep track of entry in map. then push through change right away storeData(); inputVector.remove(i); fillGraphpart(); fillDatapart(); } }
From source file:edu.purdue.cc.bionet.ui.CorrelationDetailPanel.java
/** * The actionPerformed method of the ActionListener interface. * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) * // ww w.ja va 2 s . c o m * @param event The event which triggered this action. */ public void actionPerformed(ActionEvent event) { Object source = event.getSource(); if (source == this.firstMoleculeButton) { this.detailWindow.show(this.correlation.getFirst()); } else if (source == this.secondMoleculeButton) { this.detailWindow.show(this.correlation.getSecond()); } }
From source file:edu.scripps.fl.pubchem.xmltool.gui.PubChemXMLExtractorGUI.java
public void actionPerformed(ActionEvent e) { try {//from w w w .jav a 2 s . c o m setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); if (e.getSource() == jbnFileXML) gc.fileChooser(jtfFileXML, "", "open"); else if (e.getSource() == jbnRunExtractor) { URL template = templateForExcel(); File fileExcelOutput = extract(template); if (fileExcelOutput != null) { log.info("Opening excel file through Desktop: " + fileExcelOutput); Desktop.getDesktop().open(fileExcelOutput); } } else if (e.getSource() == jbnCreateReport) { URL template = getClass().getClassLoader().getResource("ExcelTemplate.xlsx"); File fileExcelOutput = extract(template); if (fileExcelOutput != null) { log.info("Opening report through Desktop: " + fileExcelOutput); String fileName = FilenameUtils.removeExtension(fileExcelOutput.getAbsolutePath()); File filePDFOutput = new File(fileName + ".pdf"); File fileWordOutput = new File(fileName + ".docx"); filePDFOutput.deleteOnExit(); fileWordOutput.deleteOnExit(); new ReportController().createReport(pcDep, fileExcelOutput, filePDFOutput, fileWordOutput, isInternal); gc.openPDF(isInternal, filePDFOutput, this); Desktop.getDesktop().open(fileWordOutput); } } setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } catch (Throwable throwable) { SwingGUI.handleError(this, throwable); } }
From source file:de.mpg.mpi_inf.bioinf.netanalyzer.ui.SaveChartDialog.java
public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source == btnCancel) { // Cancel button pressed -> close the window this.setVisible(false); this.dispose(); } else if (source == btnSave) { // Save button pressed -> choose file name and save the chart int saveIt = saveFileDialog.showSaveDialog(this); if (saveIt == JFileChooser.APPROVE_OPTION) { // Choose file name File file = saveFileDialog.getSelectedFile(); int width = getChosenWidth(); int height = getChosenHeight(); ExtensionFileFilter filter = null; try { filter = (ExtensionFileFilter) saveFileDialog.getFileFilter(); if (!filter.hasExtension(file)) { file = filter.appendExtension(file); }//from w w w . j av a 2 s . c om } catch (ClassCastException ex) { // Try to infer the type of file by its extension FileFilter[] filters = saveFileDialog.getChoosableFileFilters(); for (int i = 0; i < filters.length; ++i) { if (filters[i] instanceof ExtensionFileFilter) { filter = (ExtensionFileFilter) filters[i]; if (filter.hasExtension(file)) { break; } filter = null; } } if (filter == null) { // Could not infer the type Utils.showErrorBox(this, Messages.DT_IOERROR, Messages.SM_AMBIGUOUSFTYPE); return; } } // Save the chart to the specified file name try { if (Utils.canSave(file, this)) { String ext = filter.getExtension(); if (ext.equals("jpeg")) { JFreeChartConn.saveAsJpeg(file, chart, width, height); } else if (ext.equals("png")) { JFreeChartConn.saveAsPng(file, chart, width, height); } else { // ext.equals("svg") JFreeChartConn.saveAsSvg(file, chart, width, height); } } } catch (IOException ex) { Utils.showErrorBox(this, Messages.DT_IOERROR, Messages.SM_OERROR); return; } this.setVisible(false); this.dispose(); } else if (saveIt == JFileChooser.ERROR_OPTION) { Utils.showErrorBox(this, Messages.DT_GUIERROR, Messages.SM_GUIERROR); } } }
From source file:com.fedroot.dacs.swing.DacsNoticePresentationDialog.java
/** * Called by constructors to initialize the dialog. *//*from w ww. ja v a 2 s. c om*/ @Override protected void dialogInit() { if (labels == null) { setLocale(Locale.getDefault()); } ActionListener actionListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source == acceptButton) { pressed_ACCEPT = true; DacsNoticePresentationDialog.this.setVisible(false); } else if (source == declineButton) { pressed_ACCEPT = false; DacsNoticePresentationDialog.this.setVisible(false); } else { pressed_ACCEPT = false; DacsNoticePresentationDialog.this.setVisible(false); } } }; acceptButton = new JButton(labels.getString("dialog.accept")); declineButton = new JButton(labels.getString("dialog.decline")); super.dialogInit(); JPanel inputpane = new JPanel(new FlowLayout()); inputpane.add(acceptButton); inputpane.add(declineButton); acceptButton.addActionListener(actionListener); inputpane.add(acceptButton); declineButton.addActionListener(actionListener); inputpane.add(declineButton); htmlpane = new JEditorPane(); // htmlpane.setContentType("image/png"); htmlpane.setEditable(false); // initialize htmlpane with something setDocumentContent("text/html", "<html><body><img src=\"http://fedroot.com/images/rick-and-frog.jpg\" width=400 height=300></body></html>"); // not set when called from super() setDocumentContent(this.content); JScrollPane presentation = new JScrollPane(htmlpane); JPanel pane = new JPanel(); pane.setLayout(new BorderLayout()); pane.add(presentation, BorderLayout.CENTER); pane.add(inputpane, BorderLayout.SOUTH); Container container = getContentPane(); container.add(pane); container.setSize(600, 400); pack(); }
From source file:eu.hydrologis.jgrass.charting.impl.JGrassXYBarChart.java
/** * Actions called be registered Objects/* www .j av a 2 s . c o m*/ * * @param e the action event. */ public void actionPerformed(ActionEvent e) { // if the hide Checkboxes are toggled if (e.getSource() instanceof JCheckBox) { int series = -1; for (int i = 0; i < chartSeries.length; i++) { if (e.getActionCommand().equals(chartSeries[i].getDescription())) { series = i; } } if (series >= 0) { boolean visible = this.renderer.getItemVisible(series, 0); this.renderer.setSeriesVisible(series, new Boolean(!visible)); } } }