List of usage examples for java.awt.event ActionEvent getSource
public Object getSource()
From source file:ArcApp.java
public ArcApp() { super(new BorderLayout()); canvas = new MyCanvas(); int width = 600; int height = 55; sliderX = setSlider(0, width, width / 4, width / 2, width / 4); sliderY = setSlider(0, height, height / 4, height / 2, height / 4); sliderWidth = setSlider(0, width, width / 2, width / 2, width / 4); sliderHeight = setSlider(0, height, height / 2, height / 2, height / 4); sliderT0 = setSlider(0, 360, 45, 180, 45); sliderT = setSlider(0, 360, 135, 180, 45); JPanel panel1 = new JPanel(); panel1.setLayout(new GridLayout(3, 3)); panel1.add(new JLabel("Location (x,y): ", JLabel.RIGHT)); panel1.add(sliderX);/*w ww . j a v a 2s . c o m*/ panel1.add(sliderY); panel1.add(new JLabel("Size (w,h): ", JLabel.RIGHT)); panel1.add(sliderWidth); panel1.add(sliderHeight); panel1.add(new JLabel("Angles (Th0, Th): ", JLabel.RIGHT)); panel1.add(sliderT0); panel1.add(sliderT); add(panel1, BorderLayout.NORTH); arcBox = new JComboBox(arcLabels); arcBox.setSelectedIndex(0); arcBox.setAlignmentX(Component.LEFT_ALIGNMENT); arcBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JComboBox cb = (JComboBox) e.getSource(); canvas.arcType = arcTypes[cb.getSelectedIndex()]; canvas.repaint(); } }); fillBox = new JComboBox(colorLabels); fillBox.setSelectedIndex(0); fillBox.setAlignmentX(Component.LEFT_ALIGNMENT); fillBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JComboBox cb = (JComboBox) e.getSource(); canvas.fillColor = colors[cb.getSelectedIndex()]; canvas.repaint(); } }); JPanel panel2 = new JPanel(); panel2.setLayout(new GridLayout(1, 4)); panel2.add(new JLabel("Arc Type: ", JLabel.RIGHT)); panel2.add(arcBox); panel2.add(new JLabel("Fill Type: ", JLabel.RIGHT)); panel2.add(fillBox); add(panel2, BorderLayout.SOUTH); add(canvas, BorderLayout.CENTER); }
From source file:com.seagate.kinetic.monitor.view.KineticSpecifiedNodeView.java
@Override public void actionPerformed(ActionEvent evt) { final Object source = evt.getSource(); if (source == this.orientationComboBox) { choosenNode = this.orientationComboBox.getSelectedItem().toString(); }//from ww w.j a va 2 s.co m }
From source file:Text3DLoad.java
public void actionPerformed(ActionEvent e) { if (e.getSource() == button) { ViewingPlatform v = u.getViewingPlatform(); if (behaviorsOn) { v.setViewPlatformBehavior(null); button.setLabel("add behaviors"); behaviorsOn = false;//from ww w . j a v a 2 s .c om } else { v.setViewPlatformBehavior(orbit); button.setLabel("remove behaviors"); behaviorsOn = true; } } }
From source file:com.jostrobin.battleships.view.panels.PlacementPanel.java
@Override public void actionPerformed(ActionEvent actionEvent) { if (actionEvent.getSource().equals(rotate)) { for (EventListener<Object> listener : rotationListeners) { listener.actionPerformed(null); }/* w w w . j av a 2 s . com*/ } else if (actionEvent.getSource().equals(ready)) { LOG.info("player is ready"); for (EventListener<Object> listener : readyListeners) { listener.actionPerformed(null); } battleField.setSelectable(false); ready.setEnabled(false); deselectShips(); } else if (actionEvent.getSource().equals(random)) { for (EventListener<Object> randomListener : randomListeners) { randomListener.actionPerformed(null); } } }
From source file:ToolBarExample.java
public ToolBarExample() { menuBar = new JMenuBar(); // Create a set of actions to use in both the menu and toolbar DemoAction leftJustifyAction = new DemoAction("Left", new ImageIcon("1.gif"), "Left justify text", 'L'); DemoAction rightJustifyAction = new DemoAction("Right", new ImageIcon("2.gif"), "Right justify text", 'R'); DemoAction centerJustifyAction = new DemoAction("Center", new ImageIcon("3.gif"), "Center justify text", 'M'); DemoAction fullJustifyAction = new DemoAction("Full", new ImageIcon("4.gif"), "Full justify text", 'F'); JMenu formatMenu = new JMenu("Justify"); formatMenu.add(leftJustifyAction);//from w ww . j av a 2s . c o m formatMenu.add(rightJustifyAction); formatMenu.add(centerJustifyAction); formatMenu.add(fullJustifyAction); menuBar.add(formatMenu); toolBar = new JToolBar("Formatting"); toolBar.add(leftJustifyAction); toolBar.add(rightJustifyAction); toolBar.add(centerJustifyAction); toolBar.add(fullJustifyAction); toolBar.addSeparator(); JLabel label = new JLabel("Font"); toolBar.add(label); toolBar.addSeparator(); JComboBox combo = new JComboBox(fonts); combo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { pane.getStyledDocument().insertString(0, "Font [" + ((JComboBox) e.getSource()).getSelectedItem() + "] chosen!\n", null); } catch (Exception ex) { ex.printStackTrace(); } } }); toolBar.add(combo); // Disable one of the Actions fullJustifyAction.setEnabled(false); }
From source file:de.codesourcery.eve.skills.ui.components.ListEditingComponent.java
@SuppressWarnings("unchecked") @Override//w w w. jav a 2 s . c o m public void actionPerformed(ActionEvent event) { final Object src = event.getSource(); if (src == editButton || src == removeButton) { final int index = list.getSelectionModel().getMinSelectionIndex(); if (index != -1) { final T item = (T) model.getElementAt(index); if (src == editButton) { editItem(item); } else if (src == removeButton) { removeItem(item); } else { throw new RuntimeException("Internal error"); } } } else if (src == addButton) { addItem(); } }
From source file:org.n52.oxf.ui.swing.ChartDialog.java
/** * /*from ww w . j a v a 2 s.co m*/ */ public void actionPerformed(ActionEvent e) { try { if (e.getSource().equals(applyButton)) { paramCon.setParameterValue(Parameter.COMMON_NAME_TIME, timePeriodPanel.getChosenTime()); OperationResult opRes = adapter.doOperation( descriptor.getOperationsMetadata().getOperationByName(adapter.getResourceOperationName()), paramCon); observations = featureStore.unmarshalFeatures(opRes); initChartPanel(observations, paramCon); } else if (e.getSource().equals(nowButton)) { GregorianCalendar calendar = new GregorianCalendar(); calendar.setTimeInMillis(System.currentTimeMillis()); Date date = calendar.getTime(); SimpleDateFormat ISO8601FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); String result = ISO8601FORMAT.format(date); //convert into YYYYMMDDTHH:mm:ss+HH:00 //- note the added colon for the Timezone result = result.substring(0, result.length() - 2) + ":" + result.substring(result.length() - 2); ITimePosition endPos = new TimePosition(result); timePeriodPanel.setEndPosition(endPos); } } catch (Exception exc) { exc.printStackTrace(); } }
From source file:edu.purdue.cc.bionet.ui.MoleculeDetailPanel.java
public void actionPerformed(ActionEvent event) { Object source = event.getSource(); if (this.correlationsTable.getSelectedRow() >= 0) { if (source == this.showElementButton) { this.detailWindow.show(this.getMoleculesInRange().get(this.correlationsTable.getSelectedRow())); }// ww w. j av a2s.co m if (source == this.showCorrelationButton) { this.detailWindow.show(this.correlations.getCorrelation(molecule, this.getMoleculesInRange().get(this.correlationsTable.getSelectedRow()))); } } else { JOptionPane.showMessageDialog(this, Settings.getLanguage().get("You must select a molecule from the table to view its details")); } }
From source file:JWSFileChooserDemo.java
public void actionPerformed(ActionEvent e) { //Handle open button action. if (e.getSource() == openButton) { FileOpenService fos = null;/*from w w w . j av a 2 s. c o m*/ FileContents fileContents = null; try { fos = (FileOpenService) ServiceManager.lookup("javax.jnlp.FileOpenService"); } catch (UnavailableServiceException exc) { } if (fos != null) { try { fileContents = fos.openFileDialog(null, null); } catch (Exception exc) { log.append("Open command failed: " + exc.getLocalizedMessage() + newline); log.setCaretPosition(log.getDocument().getLength()); } } if (fileContents != null) { try { //This is where a real application would do something //with the file. log.append("Opened file: " + fileContents.getName() + "." + newline); } catch (IOException exc) { log.append("Problem opening file: " + exc.getLocalizedMessage() + newline); } } else { log.append("User canceled open request." + newline); } log.setCaretPosition(log.getDocument().getLength()); } //Handle save button action. if (e.getSource() == saveButton) { FileSaveService fss = null; FileContents fileContents = null; ByteArrayInputStream is = new ByteArrayInputStream( (new String("Saved by JWSFileChooserDemo").getBytes())); //XXX YIKES! If they select an //XXX existing file, this will //XXX overwrite that file. try { fss = (FileSaveService) ServiceManager.lookup("javax.jnlp.FileSaveService"); } catch (UnavailableServiceException exc) { } if (fss != null) { try { fileContents = fss.saveFileDialog(null, null, is, "JWSFileChooserDemo.txt"); } catch (Exception exc) { log.append("Save command failed: " + exc.getLocalizedMessage() + newline); log.setCaretPosition(log.getDocument().getLength()); } } if (fileContents != null) { try { log.append("Saved file: " + fileContents.getName() + "." + newline); } catch (IOException exc) { log.append("Problem saving file: " + exc.getLocalizedMessage() + newline); } } else { log.append("User canceled save request." + newline); } log.setCaretPosition(log.getDocument().getLength()); } }
From source file:inet.CalculationNetworkEditor.visual.control.listener.BothGraphActions.java
@Override public void actionPerformed(ActionEvent e) { Object objSource = e.getSource(); if (objSource instanceof JButton) { JButton jbtnSource = (JButton) objSource; if ("relocate".equals(jbtnSource.getText())) { System.out.println("jbtn Relocate"); relocateVertexes();/* w w w .j av a 2s .c o m*/ } else if ("visualize".equals(jbtnSource.getText())) { System.out.println("jbtn Visualize"); visualizeStacking(); } } }