List of usage examples for javax.swing JOptionPane QUESTION_MESSAGE
int QUESTION_MESSAGE
To view the source code for javax.swing JOptionPane QUESTION_MESSAGE.
Click Source Link
From source file:dk.dma.epd.common.prototype.gui.route.RoutePropertiesDialogCommon.java
/** * Called when Delete is clicked//w ww .j a va2s. c o m */ private void onDelete() { // Check that there is a selection if (selectedWp < 0) { return; } // If the route has two way points or less, delete the entire route if (route.getWaypoints().size() < 3) { // ... but get confirmation first int result = JOptionPane.showConfirmDialog(parent, "A route must have at least two waypoints.\nDo you want to delete the route?", "Delete Route?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (result == JOptionPane.YES_OPTION) { EPD.getInstance().getRouteManager() .removeRoute(EPD.getInstance().getRouteManager().getRouteIndex(route)); EPD.getInstance().getRouteManager().notifyListeners(RoutesUpdateEvent.ROUTE_REMOVED); dispose(); } } else { // Update the locked list boolean[] newLocked = new boolean[locked.length - 1]; for (int x = 0; x < newLocked.length; x++) { newLocked[x] = locked[x + (x >= selectedWp ? 1 : 0)]; } locked = newLocked; // Delete the selected way point route.deleteWaypoint(selectedWp); adjustStartTime(); routeTableModel.fireTableDataChanged(); EPD.getInstance().getRouteManager().notifyListeners(RoutesUpdateEvent.ROUTE_WAYPOINT_DELETED); } }
From source file:edu.ku.brc.specify.config.init.secwiz.DatabasePanel.java
/** * Check the engine and charset.//from w ww.j a v a 2 s. co m * @param props the props * @return true if it exists */ protected boolean checkEngineCharSet(final Properties props) { final String databaseName = props.getProperty(DBNAME); DBMSUserMgr mgr = null; try { String itUsername = props.getProperty(DBUSERNAME); String itPassword = props.getProperty(DBPWD); String hostName = props.getProperty(HOSTNAME); if (!DBConnection.getInstance().isEmbedded()) { mgr = DBMSUserMgr.getInstance(); if (mgr.connectToDBMS(itUsername, itPassword, hostName)) { if (!mgr.verifyEngineAndCharSet(databaseName)) { String errMsg = mgr.getErrorMsg(); if (errMsg != null) { Object[] options = { getResourceString("CLOSE") }; JOptionPane.showOptionDialog(getTopWindow(), errMsg, getResourceString("DEL_CUR_DB_TITLE"), JOptionPane.OK_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); } return false; } return true; } } else { return true; } } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(SpecifyDBSecurityWizard.class, ex); } finally { if (mgr != null) { mgr.close(); } } return false; }
From source file:com.net2plan.gui.utils.viewEditTopolTables.specificTables.AdvancedJTable_multicastDemand.java
private List<JComponent> getExtraOptions(final int row, final Object itemId) { List<JComponent> options = new LinkedList<JComponent>(); final int numRows = model.getRowCount(); final NetPlan netPlan = callback.getDesign(); final List<MulticastDemand> visibleRows = getVisibleElementsInTable(); JMenuItem offeredTrafficToAll = new JMenuItem("Set offered traffic to all"); offeredTrafficToAll.addActionListener(new ActionListener() { @Override/*from w ww.j av a 2 s .c o m*/ public void actionPerformed(ActionEvent e) { double h_d; while (true) { String str = JOptionPane.showInputDialog(null, "Offered traffic volume", "Set traffic value to all table multicast demands", JOptionPane.QUESTION_MESSAGE); if (str == null) return; try { h_d = Double.parseDouble(str); if (h_d < 0) throw new RuntimeException(); break; } catch (Throwable ex) { ErrorHandling.showErrorDialog( "Non-valid multicast demand offered traffic value. Please, introduce a non-negative number", "Error setting link length"); } } try { for (MulticastDemand demand : visibleRows) demand.setOfferedTraffic(h_d); callback.updateVisualizationAfterChanges( Collections.singleton(NetworkElementType.MULTICAST_DEMAND)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Unable to set offered traffic to all multicast demands"); } } }); options.add(offeredTrafficToAll); if (itemId != null && netPlan.isMultilayer()) { final long demandId = (long) itemId; final MulticastDemand demand = netPlan.getMulticastDemandFromId(demandId); if (demand.isCoupled()) { JMenuItem decoupleDemandItem = new JMenuItem("Decouple multicast demand"); decoupleDemandItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { demand.decouple(); model.setValueAt("", row, COLUMN_COUPLEDTOLINKS); callback.getVisualizationState().resetPickedState(); callback.updateVisualizationAfterChanges( Sets.newHashSet(NetworkElementType.MULTICAST_DEMAND, NetworkElementType.LINK)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } }); options.add(decoupleDemandItem); } if (numRows > 1) { JMenuItem decoupleAllDemandsItem = null; JMenuItem createUpperLayerLinksFromDemandsItem = null; final Set<MulticastDemand> coupledDemands = visibleRows.stream().filter(e -> e.isCoupled()) .collect(Collectors.toSet()); if (!coupledDemands.isEmpty()) { decoupleAllDemandsItem = new JMenuItem("Decouple all table demands"); decoupleAllDemandsItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { for (MulticastDemand d : coupledDemands) d.decouple(); int numRows = model.getRowCount(); for (int i = 0; i < numRows; i++) model.setValueAt("", i, COLUMN_COUPLEDTOLINKS); callback.getVisualizationState().resetPickedState(); callback.updateVisualizationAfterChanges( Sets.newHashSet(NetworkElementType.MULTICAST_DEMAND, NetworkElementType.LINK)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } }); } if (coupledDemands.size() < visibleRows.size()) { createUpperLayerLinksFromDemandsItem = new JMenuItem( "Create upper layer links from uncoupled demands"); createUpperLayerLinksFromDemandsItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { List<Long> layerIds = netPlan.getNetworkLayerIds(); final JComboBox layerSelector = new WiderJComboBox(); for (long layerId : layerIds) { if (layerId == netPlan.getNetworkLayerDefault().getId()) continue; final String layerName = netPlan.getNetworkLayerFromId(layerId).getName(); String layerLabel = "Layer " + layerId; if (!layerName.isEmpty()) layerLabel += " (" + layerName + ")"; layerSelector.addItem(StringLabeller.of(layerId, layerLabel)); } layerSelector.setSelectedIndex(0); JPanel pane = new JPanel(); pane.add(new JLabel("Select layer: ")); pane.add(layerSelector); while (true) { int result = JOptionPane.showConfirmDialog(null, pane, "Please select the upper layer to create links", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (result != JOptionPane.OK_OPTION) return; try { long layerId = (long) ((StringLabeller) layerSelector.getSelectedItem()) .getObject(); NetworkLayer layer = netPlan.getNetworkLayerFromId(layerId); for (MulticastDemand demand : visibleRows) if (!demand.isCoupled()) demand.coupleToNewLinksCreated(layer); callback.getVisualizationState() .recomputeCanvasTopologyBecauseOfLinkOrNodeAdditionsOrRemovals(); callback.updateVisualizationAfterChanges(Sets.newHashSet( NetworkElementType.MULTICAST_DEMAND, NetworkElementType.LINK)); callback.getUndoRedoNavigationManager().addNetPlanChange(); break; } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Error creating upper layer links"); } } } }); } if (!options.isEmpty() && (decoupleAllDemandsItem != null || createUpperLayerLinksFromDemandsItem != null)) { options.add(new JPopupMenu.Separator()); if (decoupleAllDemandsItem != null) options.add(decoupleAllDemandsItem); if (createUpperLayerLinksFromDemandsItem != null) options.add(createUpperLayerLinksFromDemandsItem); } } } return options; }
From source file:com.iucosoft.eavertizare.gui.MainJFrame.java
private void jButtonDeleteFirmaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDeleteFirmaActionPerformed int index = jListFirma.getSelectedIndex(); if (index != -1) { Object numeFirma = jListFirma.getModel().getElementAt(index); firma = firmaDao.findByName((String) numeFirma); int rez = JOptionPane.showConfirmDialog(this, "Esti sigur vrei sa sterg firma ?", "Question", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); switch (rez) { case JOptionPane.YES_OPTION: int idConfiguratie = firma.getConfiguratii().getId(); firmaDao.dropTableClients(firma.getTabelaClientiLocal()); System.out.println("conf id = " + idConfiguratie); firmaDao.delete(firma.getId()); configuratiiDao.delete(idConfiguratie); JOptionPane.showMessageDialog(this, "Firma stersa cu success", "Succes", JOptionPane.INFORMATION_MESSAGE); break; case JOptionPane.NO_OPTION: case JOptionPane.CLOSED_OPTION: break; }//from w ww. jav a2s . c o m refreshFrame(); } else { JOptionPane.showMessageDialog(this, "Selectati firma!", "Info", JOptionPane.INFORMATION_MESSAGE); } }
From source file:de.quadrillenschule.azocamsyncd.astromode.gui.AstroModeJPanel.java
private void removeallJobsjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeallJobsjButtonActionPerformed if (JOptionPane.showConfirmDialog(parentFrame, "Really remove all jobs?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { for (PhotoSerie ps : jobList) { try { SmartPhoneWrapper.remove(ps); } catch (IOException ex) { Logger.getLogger(AstroModeJPanel.class.getName()).log(Level.SEVERE, null, ex); }//from ww w . j av a2 s. com } } }
From source file:org.fhaes.fhsamplesize.view.FHSampleSize.java
/** * Open a JFileChooser and return the file that the user specified for saving. Takes a parameter that specifies the type of file. Either * TAB or PNG./*from w w w . ja va2 s . co m*/ * * @return */ private File getFileFromSaveDialog(String fileTypeToSave) { String lastVisitedFolder = App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null); JFileChooser fc = new JFileChooser(lastVisitedFolder); File outputFile; if (fileTypeToSave == "TAB") { TABFilter filterTAB = new TABFilter(); fc.addChoosableFileFilter(filterTAB); fc.setFileFilter(filterTAB); fc.setDialogTitle("Export table as text file..."); } else if (fileTypeToSave == "PDF") { PDFFilter filterPDF = new PDFFilter(); fc.addChoosableFileFilter(filterPDF); fc.setFileFilter(filterPDF); fc.setDialogTitle("Export chart as PDF..."); } fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setMultiSelectionEnabled(false); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { outputFile = fc.getSelectedFile(); if (FileUtils.getExtension(outputFile.getAbsolutePath()) == "") { log.debug("Output file extension not set by user"); if (fc.getFileFilter().getDescription().equals(new CSVFileFilter().getDescription())) { log.debug("Adding csv extension to output file name"); outputFile = new File(outputFile.getAbsolutePath() + ".csv"); } else if (fc.getFileFilter().getDescription().equals(new PDFFilter().getDescription())) { log.debug("Adding pdf extension to output file name"); outputFile = new File(outputFile.getAbsolutePath() + ".pdf"); } } else { log.debug("Output file extension set my user to '" + FileUtils.getExtension(outputFile.getAbsolutePath()) + "'"); } App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, outputFile.getAbsolutePath()); } else { return null; } if (outputFile.exists()) { Object[] options = { "Overwrite", "No", "Cancel" }; // notes about parameters: null (don't use custom icon), options (the titles of buttons), options[0] (default button title) int response = JOptionPane.showOptionDialog(App.mainFrame, "The file '" + outputFile.getName() + "' already exists. Are you sure you want to overwrite?", "Confirm", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (response != JOptionPane.YES_OPTION) return null; } return outputFile; }
From source file:ElectionGUI.java
private void createElectionBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createElectionBtnActionPerformed //Confirmation of discarding an election2D that is not saved boolean discard = true; if (election2D != null && !saved) { int response = JOptionPane.showConfirmDialog(null, "Current " + "election is not saved, are you sure you want to create " + "a new election?" + eol + "Press \"No\" to save current " + "election in a file.", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.NO_OPTION) { discard = false;/* w w w . ja v a2s . c o m*/ systemTxt.append("-Election creation cancelled." + eol); } } if (discard) { //Input validation String err = ""; try { int x = Integer.parseInt(nTxtField.getText()); if (x < 1 || x > 1000) { throw (new Exception()); } n = x; } catch (Exception e) { nTxtField.setBackground(Color.cyan); err = err + "-Error: Value " + nTxtField.getText() + " is not " + "a valid voter population size. Enter a valid " + "integer (max 1000)." + eol; } try { int x = Integer.parseInt(mTxtField.getText()); if (x < 1 || x > 1000) { throw (new Exception()); } m = x; } catch (Exception e) { mTxtField.setBackground(Color.cyan); err = err + "-Error: Value " + mTxtField.getText() + " is not " + "a valid candidate population size. Enter a valid " + "integer (max 1000)." + eol; } try { int x = Integer.parseInt(kTxtField.getText()); if (x < 1 || x > 100 || x > m) { throw (new Exception()); } k = x; } catch (Exception e) { kTxtField.setBackground(Color.cyan); err = err + "-Error: Value " + kTxtField.getText() + " is not " + "a valid committee size. Maximum size is the minimum " + "between 100 and the candidate population." + eol; } try { int x = Integer.parseInt(xLimitTxtField.getText()); if (x < 1 || x > 100) { throw (new Exception()); } xLimit = x; } catch (Exception e) { xLimitTxtField.setBackground(Color.cyan); err = err + "-Error: Maximum x-Axis value goes up to 100." + eol; } try { int x = Integer.parseInt(yLimitTxtField.getText()); if (x < 1 || x > 100) { throw (new Exception()); } yLimit = x; } catch (Exception e) { yLimitTxtField.setBackground(Color.cyan); err = err + "-Error: Maximum y-Axis value goes up to 100." + eol; } try { int x = Integer.parseInt(nClusterTxtField.getText()); if (x < 1 || x > 20) { throw (new Exception()); } nClusters = x; } catch (Exception e) { nClusterTxtField.setBackground(Color.cyan); err = err + "-Error: Maximum number of voter clusters is 20." + eol; } try { int x = Integer.parseInt(mClusterTxtField.getText()); if (x < 1 || x > 20) { throw (new Exception()); } mClusters = x; } catch (Exception e) { mClusterTxtField.setBackground(Color.cyan); err = err + "-Error: Maximum number of candidate clusters " + "is 20." + eol; } if (err != "") { systemTxt.append(err); } else { nTxtField.setBackground(Color.white); mTxtField.setBackground(Color.white); kTxtField.setBackground(Color.white); xLimitTxtField.setBackground(Color.white); yLimitTxtField.setBackground(Color.white); nClusterTxtField.setBackground(Color.white); mClusterTxtField.setBackground(Color.white); ArrayList<Voter> voters = new ArrayList(); ArrayList<Candidate> candidates = new ArrayList(); int tempN = n; int tempM = m; boolean finalCluster = false; boolean cancelled = false; String card = "square"; for (int i = 0; i < nClusters; i++) { String title = "Voter Cluster " + (i + 1) + "/" + nClusters; String footnote = "Voters remaining: " + tempN; if (i + 1 == nClusters) { finalCluster = true; } DistributionDialog dd = new DistributionDialog(this, true, tempN, xLimit, yLimit, Person.personType.VOTER, title, footnote, finalCluster, card); dd.setVisible(true); if (dd.isCancelled()) { cancelled = true; break; } tempN = tempN - dd.getClusterSize(); voters.addAll((ArrayList<Voter>) (ArrayList<?>) dd.getIndividuals()); card = dd.getCard(); } finalCluster = false; if (!cancelled) { for (int i = 0; i < mClusters; i++) { String title = "Candidate Cluster " + (i + 1) + "/" + mClusters; String footnote = "Candidates remaining: " + tempM; if (i + 1 == mClusters) { finalCluster = true; } DistributionDialog dd = new DistributionDialog(this, true, tempM, xLimit, yLimit, Person.personType.CANDIDATE, title, footnote, finalCluster, card); dd.setVisible(true); if (dd.isCancelled()) { cancelled = true; break; } tempM = tempM - dd.getClusterSize(); candidates.addAll((ArrayList<Candidate>) (ArrayList<?>) dd.getIndividuals()); card = dd.getCard(); } } if (!cancelled) { for (int i = 0; i < voters.size(); i++) { voters.get(i).setName("v" + i); } for (int i = 0; i < candidates.size(); i++) { candidates.get(i).setName("c" + i); } election2D = new Election(k, voters, candidates, true); clearGraphPanels(); plotResultsBtn.setEnabled(true); saveElectionBtn.setEnabled(true); consistencyBtn.setEnabled(false); systemTxt.append("-New election created." + eol); saved = false; } else { systemTxt.append("-Election creation cancelled." + eol); } } } }
From source file:com.net2plan.gui.utils.viewEditTopolTables.specificTables.AdvancedJTable_node.java
private List<JComponent> getExtraOptions(final int row, final Object itemId) { List<JComponent> options = new LinkedList<JComponent>(); final int numRows = model.getRowCount(); final List<Node> tableVisibleNodes = getVisibleElementsInTable(); if (itemId != null) { JMenuItem switchCoordinates_thisNode = new JMenuItem("Switch node coordinates from (x,y) to (y,x)"); switchCoordinates_thisNode.addActionListener(new ActionListener() { @Override//from w w w .j a va 2s. com public void actionPerformed(ActionEvent e) { NetPlan netPlan = callback.getDesign(); Node node = netPlan.getNodeFromId((long) itemId); Point2D currentPosition = node.getXYPositionMap(); node.setXYPositionMap(new Point2D.Double(currentPosition.getY(), currentPosition.getX())); callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.NODE)); callback.runCanvasOperation(ITopologyCanvas.CanvasOperation.ZOOM_ALL); callback.getUndoRedoNavigationManager().addNetPlanChange(); } }); options.add(switchCoordinates_thisNode); JMenuItem xyPositionFromAttributes_thisNode = new JMenuItem("Set node coordinates from attributes"); xyPositionFromAttributes_thisNode.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { NetPlan netPlan = callback.getDesign(); Set<String> attributeSet = new LinkedHashSet<String>(); Node node = netPlan.getNodeFromId((long) itemId); attributeSet.addAll(node.getAttributes().keySet()); try { if (attributeSet.isEmpty()) throw new Exception("No attribute to select"); final JComboBox latSelector = new WiderJComboBox(); final JComboBox lonSelector = new WiderJComboBox(); for (String attribute : attributeSet) { latSelector.addItem(attribute); lonSelector.addItem(attribute); } JPanel pane = new JPanel(new MigLayout("", "[][grow]", "[][]")); pane.add(new JLabel("X-coordinate / Longitude: ")); pane.add(lonSelector, "growx, wrap"); pane.add(new JLabel("Y-coordinate / Latitude: ")); pane.add(latSelector, "growx, wrap"); while (true) { int result = JOptionPane.showConfirmDialog(null, pane, "Please select the attributes for coordinates", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (result != JOptionPane.OK_OPTION) return; try { String latAttribute = latSelector.getSelectedItem().toString(); String lonAttribute = lonSelector.getSelectedItem().toString(); node.setXYPositionMap( new Point2D.Double(Double.parseDouble(node.getAttribute(lonAttribute)), Double.parseDouble(node.getAttribute(latAttribute)))); callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.NODE)); callback.getUndoRedoNavigationManager().addNetPlanChange(); break; } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Error retrieving coordinates from attributes"); break; } } callback.runCanvasOperation(ITopologyCanvas.CanvasOperation.ZOOM_ALL); } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Error retrieving coordinates from attributes"); } } }); options.add(xyPositionFromAttributes_thisNode); JMenuItem nameFromAttribute_thisNode = new JMenuItem("Set node name from attribute"); nameFromAttribute_thisNode.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { NetPlan netPlan = callback.getDesign(); Set<String> attributeSet = new LinkedHashSet<String>(); long nodeId = (long) itemId; attributeSet.addAll(netPlan.getNodeFromId(nodeId).getAttributes().keySet()); try { if (attributeSet.isEmpty()) throw new Exception("No attribute to select"); final JComboBox selector = new WiderJComboBox(); for (String attribute : attributeSet) selector.addItem(attribute); JPanel pane = new JPanel(new MigLayout("", "[][grow]", "[]")); pane.add(new JLabel("Name: ")); pane.add(selector, "growx, wrap"); while (true) { int result = JOptionPane.showConfirmDialog(null, pane, "Please select the attribute for name", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (result != JOptionPane.OK_OPTION) return; try { String name = selector.getSelectedItem().toString(); netPlan.getNodeFromId(nodeId) .setName(netPlan.getNodeFromId(nodeId).getAttribute(name)); callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.NODE)); callback.getUndoRedoNavigationManager().addNetPlanChange(); break; } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Error retrieving name from attribute"); break; } } } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Error retrieving name from attribute"); } } }); options.add(nameFromAttribute_thisNode); } if (numRows > 1) { if (!options.isEmpty()) options.add(new JPopupMenu.Separator()); JMenuItem switchCoordinates_allNodes = new JMenuItem( "Switch all table node coordinates from (x,y) to (y,x)"); switchCoordinates_allNodes.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { for (Node n : tableVisibleNodes) { Point2D currentPosition = n.getXYPositionMap(); double newX = currentPosition.getY(); double newY = currentPosition.getX(); Point2D newPosition = new Point2D.Double(newX, newY); n.setXYPositionMap(newPosition); } callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.NODE)); callback.runCanvasOperation(ITopologyCanvas.CanvasOperation.ZOOM_ALL); callback.getUndoRedoNavigationManager().addNetPlanChange(); } }); options.add(switchCoordinates_allNodes); JMenuItem xyPositionFromAttributes_allNodes = new JMenuItem( "Set all table node coordinates from attributes"); xyPositionFromAttributes_allNodes.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Set<String> attributeSet = new LinkedHashSet<String>(); for (Node node : tableVisibleNodes) attributeSet.addAll(node.getAttributes().keySet()); try { if (attributeSet.isEmpty()) throw new Exception("No attribute to select"); final JComboBox latSelector = new WiderJComboBox(); final JComboBox lonSelector = new WiderJComboBox(); for (String attribute : attributeSet) { latSelector.addItem(attribute); lonSelector.addItem(attribute); } JPanel pane = new JPanel(new MigLayout("", "[][grow]", "[][]")); pane.add(new JLabel("X-coordinate / Longitude: ")); pane.add(lonSelector, "growx, wrap"); pane.add(new JLabel("Y-coordinate / Latitude: ")); pane.add(latSelector, "growx, wrap"); while (true) { int result = JOptionPane.showConfirmDialog(null, pane, "Please select the attributes for coordinates", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (result != JOptionPane.OK_OPTION) return; try { String latAttribute = latSelector.getSelectedItem().toString(); String lonAttribute = lonSelector.getSelectedItem().toString(); for (Node node : tableVisibleNodes) node.setXYPositionMap( new Point2D.Double(Double.parseDouble(node.getAttribute(lonAttribute)), Double.parseDouble(node.getAttribute(latAttribute)))); callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.NODE)); callback.getUndoRedoNavigationManager().addNetPlanChange(); break; } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Error retrieving coordinates from attributes"); break; } } callback.runCanvasOperation(ITopologyCanvas.CanvasOperation.ZOOM_ALL); } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Error retrieving coordinates from attributes"); } } }); options.add(xyPositionFromAttributes_allNodes); JMenuItem nameFromAttribute_allNodes = new JMenuItem("Set all table node names from attribute"); nameFromAttribute_allNodes.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Set<String> attributeSet = new LinkedHashSet<String>(); for (Node node : tableVisibleNodes) attributeSet.addAll(node.getAttributes().keySet()); try { if (attributeSet.isEmpty()) throw new Exception("No attribute to select"); final JComboBox selector = new WiderJComboBox(); for (String attribute : attributeSet) selector.addItem(attribute); JPanel pane = new JPanel(new MigLayout("", "[][grow]", "[]")); pane.add(new JLabel("Name: ")); pane.add(selector, "growx, wrap"); while (true) { int result = JOptionPane.showConfirmDialog(null, pane, "Please select the attribute for name", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (result != JOptionPane.OK_OPTION) return; try { String name = selector.getSelectedItem().toString(); for (Node node : tableVisibleNodes) node.setName(node.getAttribute(name) != null ? node.getAttribute(name) : ""); callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.NODE)); callback.getUndoRedoNavigationManager().addNetPlanChange(); break; } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Error retrieving name from attribute"); break; } } } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Error retrieving name from attribute"); } } }); options.add(nameFromAttribute_allNodes); } return options; }
From source file:corelyzer.ui.CorelyzerGLCanvas.java
private void handleClastMouseReleased(final MouseEvent e) { if (selectedTrackSection != -1) { Point releasePos = e.getPoint(); float[] releaseScenePos = { 0.0f, 0.0f }; float[] releaseAbsPos = { 0.0f, 0.0f }; convertMousePointToSceneSpace(releasePos, releaseScenePos); if (!SceneGraph.getDepthOrientation()) { float t = scenePos[0]; scenePos[0] = scenePos[1];/* w w w .j a v a 2 s .com*/ scenePos[1] = -t; } SceneGraph.addClastPoint2(scenePos[0], scenePos[1]); convertScenePointToAbsolute(scenePos, releaseAbsPos); CorelyzerApp.getApp().getToolFrame().setClastLowerRight(releaseAbsPos); float[] clastUpperLeft = CorelyzerApp.getApp().getToolFrame().getClastUpperLeft(); String trackname = CorelyzerApp.getApp().getTrackListModel().getElementAt(selectedTrackIndex) .toString(); String secname = CorelyzerApp.getApp().getSectionListModel().getElementAt(selectedTrackSectionIndex) .toString(); String sessionname = CoreGraph.getInstance().getCurrentSession().getName(); // Different kinds of annotations AnnotationTypeDirectory dir = AnnotationTypeDirectory.getLocalAnnotationTypeDirectory(); if (dir == null) { System.out.println("Null AnnotationTypeDirectory abort."); return; } Enumeration<String> keys = dir.keys(); Vector<String> annotationOptions = new Vector<String>(); annotationOptions.add("Cancel"); while (keys.hasMoreElements()) { annotationOptions.add(keys.nextElement()); } Object[] options = annotationOptions.toArray(); int sel = JOptionPane.showOptionDialog(getPopupParent(), "Which kind of Annotation?", "Annotation Form Selector", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (sel < 0) { return; } try { this.handleAnnotationEvent(options[sel].toString(), sessionname, trackname, secname, clastUpperLeft, releaseAbsPos); } catch (ClassNotFoundException e1) { e1.printStackTrace(); } catch (IllegalAccessException e1) { e1.printStackTrace(); } catch (InstantiationException e1) { e1.printStackTrace(); } } }
From source file:ca.uhn.hl7v2.testpanel.controller.Controller.java
public int showDialogYesNo(String message) { return JOptionPane.showConfirmDialog(provideViewFrameIfItExists(), message, DIALOG_TITLE, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); }