List of usage examples for java.awt.event ActionEvent getSource
public Object getSource()
From source file:com.bryan.gui.HotelBrokerApp.java
@Override public void actionPerformed(ActionEvent event) { if (event.getSource() == gui.getSearchCityButton()) { gui.getAvailableHotelLabel().setText("Available Hotel"); gui.getChooseHotelComboBox().setEnabled(true); DefaultComboBoxModel model = new DefaultComboBoxModel( DBUtil.getHotelByCity(gui.getChooseCityComboBox().getSelectedItem().toString()).toArray()); gui.getChooseHotelComboBox().setModel(model); gui.getSearchHotelButton().setEnabled(true); } else if (event.getSource() == gui.getSearchHotelButton()) { gui.getCheckingPanel().setVisible(true); gui.getMakeBookingButton().setEnabled(false); // create hotel client and connect to related hotel server; if (hotelClient != null) { hotelClient.closeClientSocket(); hotelClient = null;//from w ww. j a v a2s . c o m } hotelClient = new HotelClient("hotel client"); String city = gui.getChooseCityComboBox().getSelectedItem().toString(); String hotelName = gui.getChooseHotelComboBox().getSelectedItem().toString().split(" ")[0]; selectedHotel = DBUtil.getHotelByCityAndName(city, hotelName); hotelClient.runClient(selectedHotel); //hotelClient.sendMessageToServerAndGetReturn(gui.getChooseHotelComboBox().getSelectedItem().toString()); } else if (event.getSource() == gui.getCheckAvailabilityButton()) { Date checkIn = null; try { checkIn = formatter.parse(gui.getCheckInDateText().getText()); if (checkIn.getTime() < formatter.parse(formatter.format(new Date())).getTime()) { gui.displayMessageInDialog( "Check-In date should not before today: " + formatter.format(new Date())); return; } } catch (Exception e) { gui.displayMessageInDialog("Check-In date format incorrect: Should be like '2015-03-30'"); return; } int numOfNights; try { numOfNights = Integer.parseInt(gui.getNumberOfNightsText().getText()); if (numOfNights <= 0) { gui.displayMessageInDialog("Number of Nights should be positive integer"); return; } } catch (Exception e) { gui.displayMessageInDialog("Number of Nights should be positive integer"); return; } int numOfRooms; try { numOfRooms = Integer.parseInt(gui.getNumberOfRoomsText().getText()); if (numOfRooms <= 0) { gui.displayMessageInDialog("Number of Rooms should be positive integer"); return; } } catch (Exception e) { gui.displayMessageInDialog("Number of Rooms should be positive integer"); return; } String city = gui.getChooseCityComboBox().getSelectedItem().toString(); String hotelName = gui.getChooseHotelComboBox().getSelectedItem().toString().split(" ")[0]; JSONObject sendData = new JSONObject(); sendData.put("city", city); sendData.put("hotelName", hotelName); String result = hotelClient.sendMessageToServerAndGetReturn( CommProtocol.GETHOTEL.getProtocol() + "-" + sendData.toString()); String[] resultArr = result.split("-", 2); if (!resultArr[0].equals(CommProtocol.SUCCESS.getProtocol())) { gui.displayMessageInDialog("Data processing occurs error in server side, please try later"); return; } JSONObject receivedData = new JSONObject(resultArr[1]); Hotel hotel = new Hotel(receivedData.getInt(("id")), receivedData.getString("city"), receivedData.getString("name"), receivedData.getInt("port"), receivedData.getDouble("price")); sendData = new JSONObject(); sendData.put("hotelId", hotel.getId()); sendData.put("checkIn", formatter.format(checkIn)); sendData.put("numOfNights", numOfNights); sendData.put("numOfRooms", numOfRooms); result = hotelClient.sendMessageToServerAndGetReturn( CommProtocol.CHECKING_AVAILABILITY.getProtocol() + "-" + sendData.toString()); resultArr = result.split("-", 2); if (!resultArr[0].equals(CommProtocol.SUCCESS.getProtocol())) { gui.displayMessageInDialog("Data processing occurs error in server side, please try later"); return; } receivedData = new JSONObject(resultArr[1]); if (!receivedData.getBoolean("roomAvailability")) { gui.displayMessageInDialog( "Sorry, requested rooms is/are NOT available, please change your booking condition"); return; } else { gui.displayMessageInDialog("Requested Rooms is/are available"); gui.getMakeBookingButton().setEnabled(true); } } else if (event.getSource() == gui.getMakeBookingButton()) { gui.getBookingPanel().setVisible(true); } else if (event.getSource() == gui.getConfirmBookingButton()) { String checkIn = gui.getCheckInDateText().getText(); int numOfNights = Integer.parseInt(gui.getNumberOfNightsText().getText()); int numOfRooms = Integer.parseInt(gui.getNumberOfRoomsText().getText()); String firstName = gui.getFirstNameText().getText(); if (!firstName.matches("^[A-Za-z]+$")) { gui.displayMessageInDialog("First name can only contain alphabetic letter"); return; } String lastName = gui.getLastNameText().getText(); if (!lastName.matches("^[A-Za-z]+$")) { gui.displayMessageInDialog("Last name can only contain alphabetic letter"); return; } String state = gui.getStateComboBox().getSelectedItem().toString(); String streetAddress = gui.getStreetAddressText().getText(); String suburb = gui.getSuburbText().getText(); int postCode = Integer.parseInt(gui.getPostCodeText().getText()); if (postCode < 1000 || postCode > 9999) { gui.displayMessageInDialog("Post code must be 4 digit number"); return; } String email = gui.getEmailText().getText(); if (!email.matches("^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}$")) { gui.displayMessageInDialog("Email format incorrect, should be like example@gmail.com"); return; } String phoneNumber = gui.getPhoneNumberText().getText(); String creditCard = gui.getCreditCardText().getText(); if (!creditCard.matches("\\d{16}")) { gui.displayMessageInDialog("Credit card format incorrect, should be 16 digit number"); return; } JSONObject sendData = new JSONObject(); sendData.put("hotelId", selectedHotel.getId()); sendData.put("checkIn", checkIn); sendData.put("numOfNights", numOfNights); sendData.put("numOfRooms", numOfRooms); sendData.put("firstName", firstName); sendData.put("lastName", lastName); sendData.put("state", state); sendData.put("address", streetAddress); sendData.put("suburb", suburb); sendData.put("postCode", postCode); sendData.put("email", email); sendData.put("phone", phoneNumber); sendData.put("creditCard", creditCard); String result = hotelClient.sendMessageToServerAndGetReturn( CommProtocol.BOOKING.getProtocol() + "-" + sendData.toString()); String[] resultArr = result.split("-", 2); if (!resultArr[0].equals(CommProtocol.SUCCESS.getProtocol())) { gui.displayMessageInDialog("Data processing occurs error in server side, please try later"); return; } JSONObject receivedData = new JSONObject(resultArr[1]); if (!receivedData.getBoolean("bookingStatus")) { gui.displayMessageInDialog("Sorry, booking has been failed! Room just been booked"); return; } else { gui.displayMessageInDialog("Congratulations! Booking successed!"); return; } } else if (event.getSource() == gui.getStartAgainButton()) { String result = hotelClient.sendMessageToServerAndGetReturn( CommProtocol.CONNECTION_INTERRUPT.getProtocol() + "-Connection interrupt"); System.out.println("=========start again:" + result); hotelClient.closeClientSocket(); hotelClient = null; gui.initChoosePanel(); gui.hideCheckingPanelAndCleanFields(); gui.hideBookingPanelAndCleanFields(); } }
From source file:de.tntinteractive.portalsammler.gui.MainDialog.java
private JButton createConfigButton() { final JButton button = new JButton("Konfiguration..."); button.addActionListener(new ActionListener() { @Override/*ww w.j a v a 2 s . c o m*/ public void actionPerformed(final ActionEvent e) { final JPopupMenu menu = MainDialog.this.createConfigMenu(); final JButton source = (JButton) e.getSource(); menu.show(source, 0, source.getHeight()); } }); return button; }
From source file:com.moneydance.modules.features.mdvenmoimporter.VenmoImporterWindow.java
public void actionPerformed(ActionEvent evt) { Object src = evt.getSource(); if (src == btnCancel) { extension.closeConsole();/*from w w w . java 2s . co m*/ } else if (src == btnSave) { saveSettings(); extension.closeConsole(); } else if (src == btnDownloadTransactions) { saveSettings(); downloadVenmoTransactions(); extension.closeConsole(); } else if (src == btnDelete) { deleteAllSettings(); extension.closeConsole(); } }
From source file:latexstudio.editor.DropboxRevisionsTopComponent.java
public void updateRevisionsList(String path) { DbxClient client = DbxUtil.getDbxClient(); List<DbxEntry.File> entries = null; if (path != null) { try {/*from www . ja va2s. c o m*/ entries = client.getRevisions(path); } catch (DbxException ex) { DbxUtil.showDbxAccessDeniedPrompt(); } } dlm.clear(); DefaultTableModel model = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { return column == REVIEW_COLUMN; } }; model.addColumn(REVISION_COLUMN_NAME); model.addColumn(MODIFIED_COLUMN_NAME); model.addColumn(FILE_SIZE_COLUMN_NAME); model.addColumn(REVIEW_COLUMN_NAME); if (entries != null && entries.size() > 0) { for (DbxEntry.File dbxEntry : entries) { dlm.addElement(new DbxEntryRevision(dbxEntry)); model.addRow(new Object[] { dbxEntry.rev, dbxEntry.lastModified, dbxEntry.humanSize, REVIEW_BUTTON_LABEL }); } } Action showVersion = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { // Resolving which row has been double-clicked JTable table = (JTable) e.getSource(); int row = Integer.valueOf(e.getActionCommand()); // Finding revision using information from the clicked row String revisionNumber = table.getValueAt(row, REVISION_COLUMN).toString(); loadRevision(revisionNumber); } }; jTable1.setModel(model); ButtonColumn buttonColumn = new ButtonColumn(jTable1, showVersion, REVIEW_COLUMN); buttonColumn.setMnemonic(KeyEvent.VK_D); }
From source file:com.sshtools.common.ui.HostsTab.java
/** * * * @param evt// w w w .ja v a 2 s . c o m */ public void actionPerformed(ActionEvent evt) { if (evt.getSource() == remove) { model.removeHostAt(hosts.getSelectedIndex()); } /*else if (evt.getSource() == deny) { int i = hosts.getSelectedIndex(); HostWrapper w = model.getHostAt(i); w.allow = false; model.updateHostAt(i); }*/ setAvailableActions(); }
From source file:SimpleSoundCapture.java
public void actionPerformed(ActionEvent e) { Object obj = e.getSource(); if (obj.equals(playB)) { if (playB.getText().startsWith("Play")) { playback.start();/*from w w w . ja v a2 s . c o m*/ captB.setEnabled(false); playB.setText("Stop"); } else { playback.stop(); captB.setEnabled(true); playB.setText("Play"); } } else if (obj.equals(captB)) { if (captB.getText().startsWith("Record")) { capture.start(); playB.setEnabled(false); captB.setText("Stop"); } else { capture.stop(); playB.setEnabled(true); } } }
From source file:edu.scripps.fl.pubchem.xmltool.gui.PubChemXMLCreatorGUI.java
public void actionPerformed(ActionEvent e) { try {// w w w. ja v a 2s.c om setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); if (e.getSource() == jbnFileTemplate) { gc.fileChooser(jtfFileTemplate, ".xml", "open"); jtfFileTemplate.setEnabled(true); } else if (e.getSource() == jbnFileExcel) { gc.fileChooser(jtfFileExcel, ".xlsx", "open"); } else if (e.getSource() == jbnRunCreator) { String stringTemplate = jtfFileTemplate.getText(); InputStream fileTemplate; if (stringTemplate.equals(template) | stringTemplate.equals("")) { URL url = getClass().getClassLoader().getResource("blank.xml"); fileTemplate = url.openStream(); } else fileTemplate = new FileInputStream(jtfFileTemplate.getText()); File fileExcel = new File(jtfFileExcel.getText()); File fileOutput = File.createTempFile("pubchem", ".xml"); fileOutput.deleteOnExit(); PubChemAssay assay = new PubChemXMLCreatorController().createPubChemXML(fileTemplate, fileExcel, fileOutput); String message = assay.getMessage(); if (!message.equals("")) { int nn = JOptionPane.showOptionDialog(this, notError + message + "\nWould you like to edit your Excel Workbook?", SwingGUI.APP_NAME, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); if (nn == JOptionPane.YES_OPTION) { log.info("Opening Excel Workbook with Desktop: " + fileExcel); Desktop.getDesktop().open(fileExcel); } else { log.info("Opening XML file: " + fileOutput); Desktop.getDesktop().open(fileOutput); } } else { log.info("Opening XML file: " + fileOutput); Desktop.getDesktop().open(fileOutput); } } else if (e.getSource() == jbnReportCreator) { File fileExcel = new File(jtfFileExcel.getText()); File filePDFOutput = File.createTempFile("PubChem_PDF_Report", ".pdf"); File fileWordOutput = File.createTempFile("PubChem_Word_Report", ".docx"); filePDFOutput.deleteOnExit(); fileWordOutput.deleteOnExit(); ArrayList<PubChemAssay> assay = new ReportController().createReport(pcDep, fileExcel, filePDFOutput, fileWordOutput, isInternal); String message = null; for (PubChemAssay xx : assay) { message = xx.getMessage(); if (!message.equals("")) { int nn = JOptionPane.showOptionDialog(this, notError + message + "\nWould you like to edit your Excel Workbook?", SwingGUI.APP_NAME, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); if (nn == JOptionPane.YES_OPTION) { log.info("Opening Excel Workbook with Desktop: " + fileExcel); Desktop.getDesktop().open(fileExcel); } else { gc.openPDF(isInternal, filePDFOutput, this); Desktop.getDesktop().open(fileWordOutput); } } else { 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:GUIManagerQuery.java
/*************************************************************************** * Respond to button presses from the user indicating the desire for * information such as a list of players. **************************************************************************/ public void actionPerformed(ActionEvent e) { int type;//from w w w. jav a2s . co m String[] cons; //////////////////////////////////////////////////////////////// // Handle hints - simplest case [no need to check content types] //////////////////////////////////////////////////////////////// if (e.getSource() == hintsButton) { results.setText(ManagerQuery.getHints()); } ///////////////////////////////////////////////////////////////////// // Players, processors, or datasources. Need to check the contents // field and if it has text in there then use that as a qualifier // in the search for classes. However if empty then generate a // complete list of all classes of the required type. User may // enter multiple content types either comma or space separated, // hence use of StringTokenizer. //////////////////////////////////////////////////////////////////// else { if (e.getSource() == playersButton) type = ManagerQuery.HANDLERS; else if (e.getSource() == processorsButton) type = ManagerQuery.PROCESSORS; else type = ManagerQuery.DATASOURCES; String contents = contentsField.getText(); if (contents == null || contents.length() == 0) cons = null; else { StringTokenizer tokenizer = new StringTokenizer(contents, " ,\t;"); cons = new String[tokenizer.countTokens()]; for (int i = 0; i < cons.length; i++) cons[i] = tokenizer.nextToken(); } if (cons != null && cons.length > 0) results.setText(ManagerQuery.getHandlersOrProcessors(cons, type)); else if (type == ManagerQuery.HANDLERS) results.setText(ManagerQuery.getHandlers()); else if (type == ManagerQuery.PROCESSORS) results.setText(ManagerQuery.getProcessors()); else results.setText(ManagerQuery.getDataSources()); } }
From source file:KjellDirdalNotepad.java
private void buildChildMenus() { int i;/* w w w. ja v a2s . co m*/ ChildMenuItem menu; JInternalFrame[] array = desktop.getAllFrames(); add(cascade); add(tile); if (array.length > 0) addSeparator(); cascade.setEnabled(array.length > 0); tile.setEnabled(array.length > 0); for (i = 0; i < array.length; i++) { menu = new ChildMenuItem(array[i]); menu.setState(i == 0); menu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { JInternalFrame frame = ((ChildMenuItem) ae.getSource()).getFrame(); frame.moveToFront(); try { frame.setSelected(true); } catch (PropertyVetoException e) { e.printStackTrace(); } } }); menu.setIcon(array[i].getFrameIcon()); add(menu); } }
From source file:it.imtech.configuration.ChooseServer.java
/** * Creates new form ChooseServer//from w w w . j a va 2s . co m */ public ChooseServer(XMLConfiguration config) { initComponents(); bundle = ResourceBundle.getBundle(Globals.RESOURCES, Globals.CURRENT_LOCALE, Globals.loader); Server[] servers = getServersFromConfig(config, bundle); choose_server.setModel(new javax.swing.DefaultComboBoxModel(servers)); choose_server.setSelectedItem(servers[0]); choose_server.setMinimumSize(new Dimension(400, 20)); getLanguagesFromConfig(config, bundle); choose_language.setModel(new javax.swing.DefaultComboBoxModel(Globals.LANGUAGES)); choose_language.setSelectedItem(this.selected_lang); choose_language.setMinimumSize(new Dimension(400, 20)); updateLanguage(); MigLayout choose_layout = new MigLayout("fillx, insets 10 20 10 50"); main_panel = new JPanel(choose_layout); main_panel.add(label_server_1, "wrap 20"); main_panel.add(label_server_2, "wrap 30"); main_panel.add(label_server_3, "wrap 5"); main_panel.add(choose_server, "wrap 10"); main_panel.add(label_server_4, "wrap 5"); main_panel.add(choose_language, "wrap 10"); this.setLayout(new BorderLayout()); this.add(BorderLayout.CENTER, main_panel); //Gestione eventi choose_language.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { JComboBox comboBox = (JComboBox) event.getSource(); Language selected = (Language) comboBox.getSelectedItem(); selected_lang = selected; Globals.CURRENT_LOCALE = new Locale(selected.getCode()); updateLanguage(); Utility.setDefaultLangCurrent(); } }); this.setPreferredSize(this.getPreferredSize()); this.validate(); this.repaint(); }