List of usage examples for javax.swing JOptionPane OK_CANCEL_OPTION
int OK_CANCEL_OPTION
To view the source code for javax.swing JOptionPane OK_CANCEL_OPTION.
Click Source Link
showConfirmDialog
. From source file:de.whiledo.iliasdownloader2.swing.service.MainController.java
protected void chooseServer() { final TwoObjectsX<String, String> serverAndClientId = new TwoObjectsX<String, String>( iliasProperties.getIliasServerURL(), iliasProperties.getIliasClient()); final boolean noConfigDoneYet = serverAndClientId.getObjectA() == null || serverAndClientId.getObjectA().trim().isEmpty(); final JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); final JLabel labelServer = new JLabel("Server: " + serverAndClientId.getObjectA()); final JLabel labelClientId = new JLabel("Client Id: " + serverAndClientId.getObjectB()); JComboBox<LoginType> comboboxLoginType = null; JComboBox<DownloadMethod> comboboxDownloadMethod = null; final Runnable findOutClientId = new Runnable() { @Override// w ww .j a va 2 s. c o m public void run() { try { String s = IliasUtil.findClientByLoginPageOrWebserviceURL(serverAndClientId.getObjectA()); serverAndClientId.setObjectB(s); labelClientId.setText("Client Id: " + s); } catch (Exception e1) { showError("Client Id konnte nicht ermittelt werden", e1); } } }; final Runnable promptInputServer = new Runnable() { @Override public void run() { String s = JOptionPane.showInputDialog(panel, "Geben Sie die Ilias Loginseitenadresse oder Webserviceadresse ein", serverAndClientId.getObjectA()); if (s != null) { try { s = IliasUtil.findSOAPWebserviceByLoginPage(s.trim()); if (!s.toLowerCase().startsWith("https://")) { JOptionPane.showMessageDialog(mainFrame, "Achtung! Die von Ihnen angegebene Adresse beginnt nicht mit 'https://'.\nDie Verbindung ist daher nicht ausreichend gesichert. Ein Angreifer knnte Ihre Ilias Daten und Ihr Passwort abgreifen", "Achtung, nicht geschtzt", JOptionPane.WARNING_MESSAGE); } serverAndClientId.setObjectA(s); labelServer.setText("Server: " + serverAndClientId.getObjectA()); if (noConfigDoneYet) { findOutClientId.run(); } } catch (IliasException e1) { showError( "Bitte geben Sie die Adresse der Ilias Loginseite oder die des Webservice an. Die Adresse der Loginseite muss 'login.php' enthalten", e1); } } } }; { JPanel panel2 = new JPanel(new BorderLayout()); panel2.add(labelServer, BorderLayout.NORTH); panel2.add(labelClientId, BorderLayout.SOUTH); panel.add(panel2, BorderLayout.NORTH); } { JPanel panel2 = new JPanel(new BorderLayout()); JPanel panel3 = new JPanel(new GridLayout()); { JButton b = new JButton("Server ndern"); b.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { promptInputServer.run(); } }); panel3.add(b); b = new JButton("Client Id ndern"); b.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String s = JOptionPane.showInputDialog(panel, "Client Id eingeben", serverAndClientId.getObjectB()); if (s != null) { serverAndClientId.setObjectB(s); labelClientId.setText("Client Id: " + serverAndClientId.getObjectB()); } } }); panel3.add(b); b = new JButton("Client Id automatisch ermitteln"); b.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { findOutClientId.run(); } }); panel3.add(b); } panel2.add(panel3, BorderLayout.NORTH); panel3 = new JPanel(new GridLayout(0, 2, 5, 2)); { panel3.add(new JLabel("Loginmethode: ")); comboboxLoginType = new JComboBox<LoginType>(); FunctionsX.setComboBoxLayoutString(comboboxLoginType, new ObjectDoInterface<LoginType, String>() { @Override public String doSomething(LoginType loginType) { switch (loginType) { case DEFAULT: return "Standard"; case LDAP: return "LDAP"; case CAS: return "CAS"; default: return "<Fehler>"; } } }); val model = ((DefaultComboBoxModel<LoginType>) comboboxLoginType.getModel()); for (LoginType loginType : LoginType.values()) { model.addElement(loginType); } model.setSelectedItem(iliasProperties.getLoginType()); panel3.add(comboboxLoginType); JLabel label = new JLabel("Dateien herunterladen ber:"); label.setToolTipText("Die restliche Kommunikation luft immer ber den SOAP Webservice"); panel3.add(label); comboboxDownloadMethod = new JComboBox<DownloadMethod>(); FunctionsX.setComboBoxLayoutString(comboboxDownloadMethod, new ObjectDoInterface<DownloadMethod, String>() { @Override public String doSomething(DownloadMethod downloadMethod) { switch (downloadMethod) { case WEBSERVICE: return "SOAP Webservice (Standard)"; case WEBDAV: return "WEBDAV"; default: return "<Fehler>"; } } }); val model2 = ((DefaultComboBoxModel<DownloadMethod>) comboboxDownloadMethod.getModel()); for (DownloadMethod downloadMethod : DownloadMethod.values()) { model2.addElement(downloadMethod); } model2.setSelectedItem(iliasProperties.getDownloadMethod()); panel3.add(comboboxDownloadMethod); } panel2.add(panel3, BorderLayout.WEST); panel.add(panel2, BorderLayout.SOUTH); } if (noConfigDoneYet) { promptInputServer.run(); } if (JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog(mainFrame, panel, "Server konfigurieren", JOptionPane.OK_CANCEL_OPTION)) { if (syncService != null) { syncService.logoutIfLoggedIn(); } iliasProperties.setIliasServerURL(serverAndClientId.getObjectA()); iliasProperties.setIliasClient(serverAndClientId.getObjectB()); iliasProperties.setLoginType((LoginType) comboboxLoginType.getSelectedItem()); iliasProperties.setDownloadMethod((DownloadMethod) comboboxDownloadMethod.getSelectedItem()); saveProperties(iliasProperties); updateTitleCaption(); } }
From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java
/** * Displays a dialog that allows the user to edit the properties for the * current chart.//from w ww.j a v a 2 s .co m */ private void attemptEditChartProperties() { ChartPropertyEditPanel panel = new ChartPropertyEditPanel(chart); int result = JOptionPane.showConfirmDialog(this, panel, localizationResources.getString("Chart_Properties"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (result == JOptionPane.OK_OPTION) { panel.updateChartProperties(chart); } }
From source file:com.net2plan.gui.utils.viewEditTopolTables.specificTables.AdvancedJTable_link.java
private List<JComponent> getExtraOptions(final int row, final Object itemId) { List<JComponent> options = new LinkedList<JComponent>(); final List<Link> rowVisibleLinks = getVisibleElementsInTable(); final NetPlan netPlan = callback.getDesign(); if (itemId != null) { final long linkId = (long) itemId; JMenuItem lengthToEuclidean_thisLink = new JMenuItem("Set link length to node-pair Euclidean distance"); lengthToEuclidean_thisLink.addActionListener(new ActionListener() { @Override/*from www. j av a 2 s . c o m*/ public void actionPerformed(ActionEvent e) { Link link = netPlan.getLinkFromId(linkId); Node originNode = link.getOriginNode(); Node destinationNode = link.getDestinationNode(); double euclideanDistance = netPlan.getNodePairEuclideanDistance(originNode, destinationNode); link.setLengthInKm(euclideanDistance); callback.updateVisualizationAfterChanges(Collections.singleton(NetworkElementType.LINK)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } }); options.add(lengthToEuclidean_thisLink); JMenuItem lengthToHaversine_allNodes = new JMenuItem( "Set link length to node-pair Haversine distance (longitude-latitude) in km"); lengthToHaversine_allNodes.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Link link = netPlan.getLinkFromId(linkId); Node originNode = link.getOriginNode(); Node destinationNode = link.getDestinationNode(); double haversineDistanceInKm = netPlan.getNodePairHaversineDistanceInKm(originNode, destinationNode); link.setLengthInKm(haversineDistanceInKm); callback.updateVisualizationAfterChanges(Collections.singleton(NetworkElementType.LINK)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } }); options.add(lengthToHaversine_allNodes); JMenuItem scaleLinkLength_thisLink = new JMenuItem("Scale link length"); scaleLinkLength_thisLink.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { double scaleFactor; while (true) { String str = JOptionPane.showInputDialog(null, "(Multiplicative) Scale factor", "Scale link length", JOptionPane.QUESTION_MESSAGE); if (str == null) return; try { scaleFactor = Double.parseDouble(str); if (scaleFactor < 0) throw new RuntimeException(); break; } catch (Throwable ex) { ErrorHandling.showErrorDialog( "Non-valid scale value. Please, introduce a non-negative number", "Error setting scale factor"); } } netPlan.getLinkFromId(linkId) .setLengthInKm(netPlan.getLinkFromId(linkId).getLengthInKm() * scaleFactor); callback.updateVisualizationAfterChanges(Collections.singleton(NetworkElementType.LINK)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } }); options.add(scaleLinkLength_thisLink); if (netPlan.isMultilayer()) { Link link = netPlan.getLinkFromId(linkId); if (link.getCoupledDemand() != null) { JMenuItem decoupleLinkItem = new JMenuItem("Decouple link (if coupled to unicast demand)"); decoupleLinkItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { netPlan.getLinkFromId(linkId).getCoupledDemand().decouple(); model.setValueAt("", row, 20); callback.getVisualizationState().resetPickedState(); callback.updateVisualizationAfterChanges( Sets.newHashSet(NetworkElementType.LINK, NetworkElementType.DEMAND)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } }); options.add(decoupleLinkItem); } else { JMenuItem createLowerLayerDemandFromLinkItem = new JMenuItem( "Create lower layer demand from link"); createLowerLayerDemandFromLinkItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Collection<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 lower layer to create the demand", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (result != JOptionPane.OK_OPTION) return; try { long layerId = (long) ((StringLabeller) layerSelector.getSelectedItem()) .getObject(); Link link = netPlan.getLinkFromId(linkId); netPlan.addDemand(link.getOriginNode(), link.getDestinationNode(), link.getCapacity(), link.getAttributes(), netPlan.getNetworkLayerFromId(layerId)); callback.getVisualizationState().resetPickedState(); callback.updateVisualizationAfterChanges( Sets.newHashSet(NetworkElementType.DEMAND)); callback.getUndoRedoNavigationManager().addNetPlanChange(); break; } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Error creating lower layer demand from link"); } } } }); options.add(createLowerLayerDemandFromLinkItem); JMenuItem coupleLinkToDemand = new JMenuItem("Couple link to lower layer demand"); coupleLinkToDemand.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Collection<Long> layerIds = netPlan.getNetworkLayerIds(); final JComboBox layerSelector = new WiderJComboBox(); final JComboBox demandSelector = 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.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (layerSelector.getSelectedIndex() >= 0) { long selectedLayerId = (Long) ((StringLabeller) layerSelector .getSelectedItem()).getObject(); demandSelector.removeAllItems(); for (Demand demand : netPlan .getDemands(netPlan.getNetworkLayerFromId(selectedLayerId))) { if (demand.isCoupled()) continue; long ingressNodeId = demand.getIngressNode().getId(); long egressNodeId = demand.getEgressNode().getId(); String ingressNodeName = demand.getIngressNode().getName(); String egressNodeName = demand.getEgressNode().getName(); demandSelector.addItem(StringLabeller.unmodifiableOf(demand.getId(), "d" + demand.getId() + " [n" + ingressNodeId + " (" + ingressNodeName + ") -> n" + egressNodeId + " (" + egressNodeName + ")]")); } } if (demandSelector.getItemCount() == 0) { demandSelector.setEnabled(false); } else { demandSelector.setSelectedIndex(0); demandSelector.setEnabled(true); } } }); layerSelector.setSelectedIndex(-1); layerSelector.setSelectedIndex(0); JPanel pane = new JPanel(new MigLayout("", "[][grow]", "[][]")); pane.add(new JLabel("Select layer: ")); pane.add(layerSelector, "growx, wrap"); pane.add(new JLabel("Select demand: ")); pane.add(demandSelector, "growx, wrap"); while (true) { int result = JOptionPane.showConfirmDialog(null, pane, "Please select the lower layer demand", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (result != JOptionPane.OK_OPTION) return; try { long demandId; try { demandId = (long) ((StringLabeller) demandSelector.getSelectedItem()) .getObject(); } catch (Throwable ex) { throw new RuntimeException("No demand was selected"); } netPlan.getDemandFromId(demandId) .coupleToUpperLayerLink(netPlan.getLinkFromId(linkId)); callback.getVisualizationState().resetPickedState(); callback.updateVisualizationAfterChanges( Sets.newHashSet(NetworkElementType.LINK, NetworkElementType.DEMAND)); callback.getUndoRedoNavigationManager().addNetPlanChange(); break; } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Error coupling lower layer demand to link"); } } } }); options.add(coupleLinkToDemand); } } } if (rowVisibleLinks.size() > 1) { if (!options.isEmpty()) options.add(new JPopupMenu.Separator()); JMenuItem caFixValue = new JMenuItem("Set capacity to all"); caFixValue.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { double u_e; while (true) { String str = JOptionPane.showInputDialog(null, "Capacity value", "Set capacity to all table links", JOptionPane.QUESTION_MESSAGE); if (str == null) return; try { u_e = Double.parseDouble(str); if (u_e < 0) throw new NumberFormatException(); break; } catch (NumberFormatException ex) { ErrorHandling.showErrorDialog( "Non-valid capacity value. Please, introduce a non-negative number", "Error setting capacity value"); } } try { for (Link link : rowVisibleLinks) link.setCapacity(u_e); callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.LINK)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Unable to set capacity to all links"); } } }); options.add(caFixValue); JMenuItem caFixValueUtilization = new JMenuItem("Set capacity to match a given utilization"); caFixValueUtilization.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { double utilization; while (true) { String str = JOptionPane.showInputDialog(null, "Link utilization value", "Set capacity to all table links to match a given utilization", JOptionPane.QUESTION_MESSAGE); if (str == null) return; try { utilization = Double.parseDouble(str); if (utilization <= 0) throw new NumberFormatException(); break; } catch (NumberFormatException ex) { ErrorHandling.showErrorDialog( "Non-valid link utilization value. Please, introduce a strictly positive number", "Error setting link utilization value"); } } try { for (Link link : rowVisibleLinks) link.setCapacity(link.getOccupiedCapacity() / utilization); callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.LINK)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Unable to set capacity to all links according to a given link utilization"); } } }); options.add(caFixValueUtilization); JMenuItem lengthToAll = new JMenuItem("Set link length to all"); lengthToAll.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { double l_e; while (true) { String str = JOptionPane.showInputDialog(null, "Link length value (in km)", "Set link length to all table links", JOptionPane.QUESTION_MESSAGE); if (str == null) return; try { l_e = Double.parseDouble(str); if (l_e < 0) throw new RuntimeException(); break; } catch (Throwable ex) { ErrorHandling.showErrorDialog( "Non-valid link length value. Please, introduce a non-negative number", "Error setting link length"); } } NetPlan netPlan = callback.getDesign(); try { for (Link link : rowVisibleLinks) link.setLengthInKm(l_e); callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.LINK)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Unable to set link length to all links"); } } }); options.add(lengthToAll); JMenuItem lengthToEuclidean_allLinks = new JMenuItem( "Set all table link lengths to node-pair Euclidean distance"); lengthToEuclidean_allLinks.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { for (Link link : rowVisibleLinks) link.setLengthInKm(netPlan.getNodePairEuclideanDistance(link.getOriginNode(), link.getDestinationNode())); callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.LINK)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Unable to set link length value to all links"); } } }); options.add(lengthToEuclidean_allLinks); JMenuItem lengthToHaversine_allLinks = new JMenuItem( "Set all table link lengths to node-pair Haversine distance (longitude-latitude) in km"); lengthToHaversine_allLinks.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { NetPlan netPlan = callback.getDesign(); try { for (Link link : rowVisibleLinks) { link.setLengthInKm(netPlan.getNodePairHaversineDistanceInKm(link.getOriginNode(), link.getDestinationNode())); } callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.LINK)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Unable to set link length value to all links"); } } }); options.add(lengthToHaversine_allLinks); JMenuItem scaleLinkLength_allLinks = new JMenuItem("Scale all table link lengths"); scaleLinkLength_allLinks.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { double scaleFactor; while (true) { String str = JOptionPane.showInputDialog(null, "(Multiplicative) Scale factor", "Scale (all) link length", JOptionPane.QUESTION_MESSAGE); if (str == null) return; try { scaleFactor = Double.parseDouble(str); if (scaleFactor < 0) throw new RuntimeException(); break; } catch (Throwable ex) { ErrorHandling.showErrorDialog( "Non-valid scale value. Please, introduce a non-negative number", "Error setting scale factor"); } } NetPlan netPlan = callback.getDesign(); try { for (Link link : rowVisibleLinks) link.setLengthInKm(link.getLengthInKm() * scaleFactor); callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.LINK)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Unable to scale link length"); } } }); options.add(scaleLinkLength_allLinks); if (netPlan.isMultilayer()) { final Set<Link> coupledLinks = rowVisibleLinks.stream().filter(e -> e.isCoupled()) .collect(Collectors.toSet()); if (!coupledLinks.isEmpty()) { JMenuItem decoupleAllLinksItem = new JMenuItem("Decouple all table links"); decoupleAllLinksItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { for (Link link : coupledLinks) if (link.getCoupledDemand() == null) link.getCoupledMulticastDemand().decouple(); else link.getCoupledDemand().decouple(); int numRows = model.getRowCount(); for (int i = 0; i < numRows; i++) model.setValueAt("", i, 20); callback.getVisualizationState().resetPickedState(); callback.updateVisualizationAfterChanges( Sets.newHashSet(NetworkElementType.LINK, NetworkElementType.DEMAND)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } }); options.add(decoupleAllLinksItem); } if (coupledLinks.size() < rowVisibleLinks.size()) { JMenuItem createLowerLayerDemandsFromLinksItem = new JMenuItem( "Create lower layer unicast demands from uncoupled links"); createLowerLayerDemandsFromLinksItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final JComboBox layerSelector = new WiderJComboBox(); for (NetworkLayer layer : netPlan.getNetworkLayers()) { if (layer.getId() == netPlan.getNetworkLayerDefault().getId()) continue; final String layerName = layer.getName(); String layerLabel = "Layer " + layer.getId(); if (!layerName.isEmpty()) layerLabel += " (" + layerName + ")"; layerSelector.addItem(StringLabeller.of(layer.getId(), 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 lower layer to create demands", 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 (Link link : rowVisibleLinks) if (!link.isCoupled()) link.coupleToNewDemandCreated(layer); callback.getVisualizationState() .recomputeCanvasTopologyBecauseOfLinkOrNodeAdditionsOrRemovals(); callback.updateVisualizationAfterChanges( Sets.newHashSet(NetworkElementType.LINK, NetworkElementType.DEMAND)); callback.getUndoRedoNavigationManager().addNetPlanChange(); break; } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Error creating lower layer demands"); } } } }); options.add(createLowerLayerDemandsFromLinksItem); } } } return options; }
From source file:net.rptools.maptool.client.functions.InputFunction.java
@Override public Object childEvaluate(Parser parser, String functionName, List<Object> parameters) throws EvaluationException, ParserException { // Extract the list of specifier strings from the parameters // "name | value | prompt | inputType | options" List<String> varStrings = new ArrayList<String>(); for (Object param : parameters) { String paramStr = (String) param; if (StringUtils.isEmpty(paramStr)) { continue; }//from ww w . j a v a2s .c o m // Multiple vars can be packed into a string, separated by "##" List<String> substrings = new ArrayList<String>(); StrListFunctions.parse(paramStr, substrings, "##"); for (String varString : substrings) { if (StringUtils.isEmpty(paramStr)) { continue; } varStrings.add(varString); } } // Create VarSpec objects from each variable's specifier string List<VarSpec> varSpecs = new ArrayList<VarSpec>(); for (String specifier : varStrings) { VarSpec vs; try { vs = new VarSpec(specifier); } catch (VarSpec.SpecifierException se) { throw new ParameterException(se.msg); } catch (InputType.OptionException oe) { throw new ParameterException(I18N.getText("macro.function.input.invalidOptionType", oe.key, oe.value, oe.type, specifier)); } varSpecs.add(vs); } // Check if any variables were defined if (varSpecs.isEmpty()) return BigDecimal.ONE; // No work to do, so treat it as a successful invocation. // UI step 1 - First, see if a token is in context. VariableResolver varRes = parser.getVariableResolver(); Token tokenInContext = null; if (varRes instanceof MapToolVariableResolver) { tokenInContext = ((MapToolVariableResolver) varRes).getTokenInContext(); } String dialogTitle = "Input Values"; if (tokenInContext != null) { String name = tokenInContext.getName(), gm_name = tokenInContext.getGMName(); boolean isGM = MapTool.getPlayer().isGM(); String extra = ""; if (isGM && gm_name != null && gm_name.compareTo("") != 0) extra = " for " + gm_name; else if (name != null && name.compareTo("") != 0) extra = " for " + name; dialogTitle = dialogTitle + extra; } // UI step 2 - build the panel with the input fields InputPanel ip = new InputPanel(varSpecs); // Calculate the height // TODO: remove this workaround int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int maxHeight = screenHeight * 3 / 4; Dimension ipPreferredDim = ip.getPreferredSize(); if (maxHeight < ipPreferredDim.height) { ip.modifyMaxHeightBy(maxHeight - ipPreferredDim.height); } // UI step 3 - show the dialog JOptionPane jop = new JOptionPane(ip, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION); JDialog dlg = jop.createDialog(MapTool.getFrame(), dialogTitle); // Set up callbacks needed for desired runtime behavior dlg.addComponentListener(new FixupComponentAdapter(ip)); dlg.setVisible(true); int dlgResult = JOptionPane.CLOSED_OPTION; try { dlgResult = (Integer) jop.getValue(); } catch (NullPointerException npe) { } dlg.dispose(); if (dlgResult == JOptionPane.CANCEL_OPTION || dlgResult == JOptionPane.CLOSED_OPTION) return BigDecimal.ZERO; // Finally, assign values from the dialog box to the variables for (ColumnPanel cp : ip.columnPanels) { List<VarSpec> panelVars = cp.varSpecs; List<JComponent> panelControls = cp.inputFields; int numPanelVars = panelVars.size(); StringBuilder allAssignments = new StringBuilder(); // holds all values assigned in this tab for (int varCount = 0; varCount < numPanelVars; varCount++) { VarSpec vs = panelVars.get(varCount); JComponent comp = panelControls.get(varCount); String newValue = null; switch (vs.inputType) { case TEXT: { newValue = ((JTextField) comp).getText(); break; } case LIST: { Integer index = ((JComboBox) comp).getSelectedIndex(); if (vs.optionValues.optionEquals("VALUE", "STRING")) { newValue = vs.valueList.get(index); } else { // default is "NUMBER" newValue = index.toString(); } break; } case CHECK: { Integer value = ((JCheckBox) comp).isSelected() ? 1 : 0; newValue = value.toString(); break; } case RADIO: { // This code assumes that the Box container returns components // in the same order that they were added. Component[] comps = ((Box) comp).getComponents(); int componentCount = 0; Integer index = 0; for (Component c : comps) { if (c instanceof JRadioButton) { JRadioButton radio = (JRadioButton) c; if (radio.isSelected()) index = componentCount; } componentCount++; } if (vs.optionValues.optionEquals("VALUE", "STRING")) { newValue = vs.valueList.get(index); } else { // default is "NUMBER" newValue = index.toString(); } break; } case LABEL: { newValue = null; // The variable name is ignored and not set. break; } case PROPS: { // Read out and assign all the subvariables. // The overall return value is a property string (as in StrPropFunctions.java) with all the new settings. Component[] comps = ((JPanel) comp).getComponents(); StringBuilder sb = new StringBuilder(); int setVars = 0; // "NONE", no assignments made if (vs.optionValues.optionEquals("SETVARS", "SUFFIXED")) setVars = 1; if (vs.optionValues.optionEquals("SETVARS", "UNSUFFIXED")) setVars = 2; if (vs.optionValues.optionEquals("SETVARS", "TRUE")) setVars = 2; // for backward compatibility for (int compCount = 0; compCount < comps.length; compCount += 2) { String key = ((JLabel) comps[compCount]).getText().split("\\:")[0]; // strip trailing colon String value = ((JTextField) comps[compCount + 1]).getText(); sb.append(key); sb.append("="); sb.append(value); sb.append(" ; "); switch (setVars) { case 0: // Do nothing break; case 1: parser.setVariable(key + "_", value); break; case 2: parser.setVariable(key, value); break; } } newValue = sb.toString(); break; } default: // should never happen newValue = null; break; } // Set the variable to the value we got from the dialog box. if (newValue != null) { parser.setVariable(vs.name, newValue.trim()); allAssignments.append(vs.name + "=" + newValue.trim() + " ## "); } } if (cp.tabVarSpec != null) { parser.setVariable(cp.tabVarSpec.name, allAssignments.toString()); } } return BigDecimal.ONE; // success // for debugging: //return debugOutput(varSpecs); }
From source file:com.net2plan.gui.utils.viewEditTopolTables.specificTables.AdvancedJTable_demand.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<Demand> tableVisibleDemands = getVisibleElementsInTable(); JMenuItem offeredTrafficToAll = new JMenuItem("Set offered traffic to all"); offeredTrafficToAll.addActionListener(new ActionListener() { @Override/*from www. j a v a2s .c om*/ public void actionPerformed(ActionEvent e) { double h_d; while (true) { String str = JOptionPane.showInputDialog(null, "Offered traffic volume", "Set traffic value to all demands in the table", 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("Please, introduce a non-negative number", "Error setting offered traffic"); } } NetPlan netPlan = callback.getDesign(); try { for (Demand d : tableVisibleDemands) d.setOfferedTraffic(h_d); callback.getVisualizationState().resetPickedState(); callback.updateVisualizationAfterChanges(Collections.singleton(NetworkElementType.DEMAND)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Unable to set offered traffic to all demands in the table"); } } }); options.add(offeredTrafficToAll); JMenuItem scaleOfferedTrafficToAll = new JMenuItem("Scale offered traffic all demands in the table"); scaleOfferedTrafficToAll.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { double scalingFactor; while (true) { String str = JOptionPane.showInputDialog(null, "Scaling factor to multiply to all offered traffics", "Scale offered traffic", JOptionPane.QUESTION_MESSAGE); if (str == null) return; try { scalingFactor = Double.parseDouble(str); if (scalingFactor < 0) throw new RuntimeException(); break; } catch (Throwable ex) { ErrorHandling.showErrorDialog("Please, introduce a non-negative number", "Error setting offered traffic"); } } try { for (Demand d : tableVisibleDemands) d.setOfferedTraffic(d.getOfferedTraffic() * scalingFactor); callback.getVisualizationState().resetPickedState(); callback.updateVisualizationAfterChanges(Collections.singleton(NetworkElementType.DEMAND)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Unable to scale demand offered traffics"); } } }); options.add(scaleOfferedTrafficToAll); JMenuItem setServiceTypes = new JMenuItem( "Set traversed resource types (to one or all demands in the table)"); setServiceTypes.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { NetPlan netPlan = callback.getDesign(); try { Demand d = netPlan.getDemandFromId((Long) itemId); String[] headers = StringUtils.arrayOf("Order", "Type"); Object[][] data = { null, null }; DefaultTableModel model = new ClassAwareTableModelImpl(data, headers); AdvancedJTable table = new AdvancedJTable(model); JButton addRow = new JButton("Add new traversed resource type"); addRow.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Object[] newRow = { table.getRowCount(), "" }; ((DefaultTableModel) table.getModel()).addRow(newRow); } }); JButton removeRow = new JButton("Remove selected"); removeRow.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ((DefaultTableModel) table.getModel()).removeRow(table.getSelectedRow()); for (int t = 0; t < table.getRowCount(); t++) table.getModel().setValueAt(t, t, 0); } }); JButton removeAllRows = new JButton("Remove all"); removeAllRows.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { while (table.getRowCount() > 0) ((DefaultTableModel) table.getModel()).removeRow(0); } }); List<String> oldTraversedResourceTypes = d.getServiceChainSequenceOfTraversedResourceTypes(); Object[][] newData = new Object[oldTraversedResourceTypes.size()][headers.length]; for (int i = 0; i < oldTraversedResourceTypes.size(); i++) { newData[i][0] = i; newData[i][1] = oldTraversedResourceTypes.get(i); } ((DefaultTableModel) table.getModel()).setDataVector(newData, headers); JPanel pane = new JPanel(); JPanel pane2 = new JPanel(); pane.setLayout(new BorderLayout()); pane2.setLayout(new BorderLayout()); pane.add(new JScrollPane(table), BorderLayout.CENTER); pane2.add(addRow, BorderLayout.WEST); pane2.add(removeRow, BorderLayout.EAST); pane2.add(removeAllRows, BorderLayout.SOUTH); pane.add(pane2, BorderLayout.SOUTH); final String[] optionsArray = new String[] { "Set to selected demand", "Set to all demands", "Cancel" }; int result = JOptionPane.showOptionDialog(null, pane, "Set traversed resource types", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, optionsArray, optionsArray[0]); if ((result != 0) && (result != 1)) return; final boolean setToAllDemands = (result == 1); List<String> newTraversedResourcesTypes = new LinkedList<>(); for (int j = 0; j < table.getRowCount(); j++) { String travResourceType = table.getModel().getValueAt(j, 1).toString(); newTraversedResourcesTypes.add(travResourceType); } if (setToAllDemands) { for (Demand dd : tableVisibleDemands) if (!dd.getRoutes().isEmpty()) throw new Net2PlanException( "It is not possible to set the resource types traversed to demands with routes"); for (Demand dd : tableVisibleDemands) dd.setServiceChainSequenceOfTraversedResourceTypes(newTraversedResourcesTypes); } else { if (!d.getRoutes().isEmpty()) throw new Net2PlanException( "It is not possible to set the resource types traversed to demands with routes"); d.setServiceChainSequenceOfTraversedResourceTypes(newTraversedResourcesTypes); } callback.getVisualizationState().resetPickedState(); callback.updateVisualizationAfterChanges(Collections.singleton(NetworkElementType.DEMAND)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Unable to set traversed resource types"); } } }); options.add(setServiceTypes); if (itemId != null && netPlan.isMultilayer()) { final long demandId = (long) itemId; if (netPlan.getDemandFromId(demandId).isCoupled()) { JMenuItem decoupleDemandItem = new JMenuItem("Decouple demand"); decoupleDemandItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { netPlan.getDemandFromId(demandId).decouple(); model.setValueAt("", row, 3); callback.getVisualizationState().resetPickedState(); callback.updateVisualizationAfterChanges(Collections.singleton(NetworkElementType.DEMAND)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } }); options.add(decoupleDemandItem); } else { JMenuItem createUpperLayerLinkFromDemandItem = new JMenuItem("Create upper layer link from demand"); createUpperLayerLinkFromDemandItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Collection<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 the link", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (result != JOptionPane.OK_OPTION) return; try { long layerId = (long) ((StringLabeller) layerSelector.getSelectedItem()) .getObject(); netPlan.getDemandFromId(demandId) .coupleToNewLinkCreated(netPlan.getNetworkLayerFromId(layerId)); callback.getVisualizationState() .recomputeCanvasTopologyBecauseOfLinkOrNodeAdditionsOrRemovals(); callback.updateVisualizationAfterChanges( Sets.newHashSet(NetworkElementType.DEMAND, NetworkElementType.LINK)); callback.getUndoRedoNavigationManager().addNetPlanChange(); break; } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Error creating upper layer link from demand"); } } } }); options.add(createUpperLayerLinkFromDemandItem); JMenuItem coupleDemandToLink = new JMenuItem("Couple demand to upper layer link"); coupleDemandToLink.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Collection<Long> layerIds = netPlan.getNetworkLayerIds(); final JComboBox layerSelector = new WiderJComboBox(); final JComboBox linkSelector = 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.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (layerSelector.getSelectedIndex() >= 0) { long selectedLayerId = (Long) ((StringLabeller) layerSelector.getSelectedItem()) .getObject(); NetworkLayer selectedLayer = netPlan.getNetworkLayerFromId(selectedLayerId); linkSelector.removeAllItems(); Collection<Link> links_thisLayer = netPlan.getLinks(selectedLayer); for (Link link : links_thisLayer) { if (link.isCoupled()) continue; String originNodeName = link.getOriginNode().getName(); String destinationNodeName = link.getDestinationNode().getName(); linkSelector.addItem(StringLabeller.unmodifiableOf(link.getId(), "e" + link.getIndex() + " [n" + link.getOriginNode().getIndex() + " (" + originNodeName + ") -> n" + link.getDestinationNode().getIndex() + " (" + destinationNodeName + ")]")); } } if (linkSelector.getItemCount() == 0) { linkSelector.setEnabled(false); } else { linkSelector.setSelectedIndex(0); linkSelector.setEnabled(true); } } }); layerSelector.setSelectedIndex(-1); layerSelector.setSelectedIndex(0); JPanel pane = new JPanel(new MigLayout("", "[][grow]", "[][]")); pane.add(new JLabel("Select layer: ")); pane.add(layerSelector, "growx, wrap"); pane.add(new JLabel("Select link: ")); pane.add(linkSelector, "growx, wrap"); while (true) { int result = JOptionPane.showConfirmDialog(null, pane, "Please select the upper layer link", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (result != JOptionPane.OK_OPTION) return; try { long layerId = (long) ((StringLabeller) layerSelector.getSelectedItem()) .getObject(); long linkId; try { linkId = (long) ((StringLabeller) linkSelector.getSelectedItem()).getObject(); } catch (Throwable ex) { throw new RuntimeException("No link was selected"); } netPlan.getDemandFromId(demandId) .coupleToUpperLayerLink(netPlan.getLinkFromId(linkId)); callback.getVisualizationState().resetPickedState(); callback.updateVisualizationAfterChanges( Sets.newHashSet(NetworkElementType.DEMAND, NetworkElementType.LINK)); callback.getUndoRedoNavigationManager().addNetPlanChange(); break; } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Error coupling upper layer link to demand"); } } } }); options.add(coupleDemandToLink); } if (numRows > 1) { JMenuItem decoupleAllDemandsItem = null; JMenuItem createUpperLayerLinksFromDemandsItem = null; final Set<Demand> coupledDemands = tableVisibleDemands.stream().filter(d -> d.isCoupled()) .collect(Collectors.toSet()); if (!coupledDemands.isEmpty()) { decoupleAllDemandsItem = new JMenuItem("Decouple all demands"); decoupleAllDemandsItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { for (Demand d : new LinkedHashSet<Demand>(coupledDemands)) d.decouple(); int numRows = model.getRowCount(); for (int i = 0; i < numRows; i++) model.setValueAt("", i, 3); callback.getVisualizationState().resetPickedState(); callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.DEMAND)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } }); } if (coupledDemands.size() < tableVisibleDemands.size()) { createUpperLayerLinksFromDemandsItem = new JMenuItem( "Create upper layer links from uncoupled demands"); createUpperLayerLinksFromDemandsItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Collection<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 (Demand demand : tableVisibleDemands) if (!demand.isCoupled()) demand.coupleToNewLinkCreated(layer); callback.getVisualizationState() .recomputeCanvasTopologyBecauseOfLinkOrNodeAdditionsOrRemovals(); callback.updateVisualizationAfterChanges( Sets.newHashSet(NetworkElementType.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:de.whiledo.iliasdownloader2.swing.service.MainController.java
protected void chooseCourses() { try {// www . ja v a2 s .c o m if (login()) { CourseChooserContr courseChooserContr = new CourseChooserContr(iliasProperties.isSyncAll(), iliasProperties.getActiveCourses(), syncService.getIliasSoapService()); if (JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog(mainFrame, courseChooserContr.getView(), "Kurse auswhlen", JOptionPane.OK_CANCEL_OPTION)) { iliasProperties.setActiveCourses(courseChooserContr.getActiveCourses()); iliasProperties.setSyncAll(courseChooserContr.isSyncAll()); saveProperties(iliasProperties); } } } catch (Exception e) { showError("Fehler beim ndern der Kursinformationen", e); } }
From source file:Installer.java
public void run() { JOptionPane optionPane = new JOptionPane(this, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, new String[] { "Install", "Cancel" }); emptyFrame = new Frame("Vivecraft Installer"); emptyFrame.setUndecorated(true);/* w ww.j a v a2s. c o m*/ emptyFrame.setVisible(true); emptyFrame.setLocationRelativeTo(null); dialog = optionPane.createDialog(emptyFrame, "Vivecraft Installer"); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setVisible(true); String str = ((String) optionPane.getValue()); if (str != null && ((String) optionPane.getValue()).equalsIgnoreCase("Install")) { int option = JOptionPane.showOptionDialog(null, "Please ensure you have closed the Minecraft launcher before proceeding.\n" //"Also, if installing with Forge please ensure you have installed Forge " + FORGE_VERSION + " first.", , "Important!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, null, null); if (option == JOptionPane.OK_OPTION) { monitor = new ProgressMonitor(null, "Installing Vivecraft...", "", 0, 100); monitor.setMillisToDecideToPopup(0); monitor.setMillisToPopup(0); task = new InstallTask(); task.addPropertyChangeListener(this); task.execute(); } else { dialog.dispose(); emptyFrame.dispose(); } } else { dialog.dispose(); emptyFrame.dispose(); } }
From source file:com.igormaznitsa.jhexed.swing.editor.ui.MainForm.java
private static void processExporterAsLongTask(final JFrame frame, final String taskDescription, final Exporter exporter, final File theFile) { if (theFile.exists()) { if (JOptionPane.showConfirmDialog(frame, "Override existing file '" + theFile.getName() + "'?", "File exists", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) { return; }/* w ww.j av a 2s. c o m*/ } new LongTaskDialog(frame, taskDescription, new Runnable() { @Override public void run() { Log.info("Started export: " + taskDescription); try { exporter.export(theFile); Log.info("Export has been completed: " + taskDescription); } catch (ExportException ex) { Log.error("Can't make export for error", ex); JOptionPane.showMessageDialog(frame, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } catch (Exception ex) { Log.error("Can't make export for error", ex); JOptionPane.showMessageDialog(frame, "Can't make export for error, see the log", "Error", JOptionPane.ERROR_MESSAGE); } } }).startTask(); }
From source file:de.whiledo.iliasdownloader2.swing.service.MainController.java
protected void changeMaxFileSize() { final JPanel panel = new JPanel(); boolean keineLimitierung = iliasProperties.getMaxFileSize() == Long.MAX_VALUE; panel.setLayout(new GridLayout(1, 0)); panel.add(new JLabel("Maximale Dateigre in MB")); final JCheckBox cb = new JCheckBox("Keine Limitierung"); cb.setSelected(keineLimitierung);/*from www. j a va2s . c o m*/ panel.add(cb); final JTextField fieldFileSize = new JTextField( String.valueOf(iliasProperties.getMaxFileSize() / (1024 * 1024))); panel.add(fieldFileSize); fieldFileSize.setVisible(!cb.isSelected()); cb.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { fieldFileSize.setVisible(!cb.isSelected()); } }); if (JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog(mainFrame, panel, "Maximale Dateigre ndern", JOptionPane.OK_CANCEL_OPTION)) { if (cb.isSelected()) { iliasProperties.setMaxFileSize(Long.MAX_VALUE); } else { iliasProperties.setMaxFileSize(Long.parseLong(fieldFileSize.getText()) * 1024 * 1024); } saveProperties(iliasProperties); } }