List of usage examples for javax.swing JButton getActionMap
public final ActionMap getActionMap()
ActionMap
used to determine what Action
to fire for particular KeyStroke
binding. From source file:fxts.stations.util.preferences.EditAction.java
public void actionPerformed(ActionEvent aEvent) { JButton okButton = UIManager.getInst().createButton(); JButton cancelButton = UIManager.getInst().createButton(); final JDialog dialog = new JDialog(mEditorPanel.getParentDialog()); dialog.setTitle(mEditorPanel.getTitle()); JPanel editPanel = new JPanel(); JPanel buttonPanel = new JPanel(); JPanel mainPanel = new JPanel(); mainPanel.setLayout(UIFrontEnd.getInstance().getSideLayout()); //mainPanel.setLayout(new SideLayout()); //sets button panel buttonPanel.setLayout(UIFrontEnd.getInstance().getSideLayout()); okButton.setText(mResMan.getString("IDS_OK_BUTTON")); //okButton.setPreferredSize(new Dimension(80, 27)); GridBagConstraints sideConstraints = UIFrontEnd.getInstance().getSideConstraints(); sideConstraints.insets = new Insets(10, 10, 10, 10); sideConstraints.gridx = 0;//from ww w . ja va 2 s . com sideConstraints.gridy = 0; ResizeParameterWrapper resizeParameter = UIFrontEnd.getInstance().getResizeParameter(); resizeParameter.init(0.5, 0.0, 0.5, 0.0); resizeParameter.setToConstraints(sideConstraints); buttonPanel.add(okButton, sideConstraints); cancelButton.setText(mResMan.getString("IDS_CANCEL_BUTTON")); //cancelButton.setPreferredSize(new Dimension(80, 27)); sideConstraints = UIFrontEnd.getInstance().getSideConstraints(); sideConstraints.insets = new Insets(10, 10, 10, 10); sideConstraints.gridx = 1; sideConstraints.gridy = 0; resizeParameter = UIFrontEnd.getInstance().getResizeParameter(); resizeParameter.init(0.5, 0.0, 0.5, 0.0); resizeParameter.setToConstraints(sideConstraints); buttonPanel.add(cancelButton, sideConstraints); //adds button panel sideConstraints = UIFrontEnd.getInstance().getSideConstraints(); sideConstraints.insets = new Insets(10, 10, 10, 10); sideConstraints.gridx = 0; sideConstraints.gridy = 1; resizeParameter = UIFrontEnd.getInstance().getResizeParameter(); resizeParameter.init(0.0, 1.0, 1.0, 1.0); resizeParameter.setToConstraints(sideConstraints); mainPanel.add(buttonPanel, sideConstraints); //sets edit panel final IEditor editor = mType.getEditor(); editor.setValue(mValue); editPanel.setLayout(UIFrontEnd.getInstance().getSideLayout()); sideConstraints = UIFrontEnd.getInstance().getSideConstraints(); resizeParameter = UIFrontEnd.getInstance().getResizeParameter(); resizeParameter.init(0.0, 0.0, 1.0, 1.0); resizeParameter.setToConstraints(sideConstraints); Component editComp = editor.getComponent(); //Mar 25 2004 - kav: added for right tab order at Font Chooser at java 1.4. if (editComp instanceof FontChooser) { FontChooser fc = (FontChooser) editComp; fc.setNextFocusedComp(okButton); } editPanel.add(editComp, sideConstraints); //adds editor panel sideConstraints = UIFrontEnd.getInstance().getSideConstraints(); sideConstraints.gridx = 0; sideConstraints.gridy = 0; resizeParameter = UIFrontEnd.getInstance().getResizeParameter(); resizeParameter.init(0.0, 0.0, 1.0, 1.0); resizeParameter.setToConstraints(sideConstraints); mainPanel.add(editPanel, sideConstraints); //adds main panel dialog.getContentPane().setLayout(UIFrontEnd.getInstance().getSideLayout()); //dialog.getContentPane().setLayout(new SideLayout()); sideConstraints = UIFrontEnd.getInstance().getSideConstraints(); sideConstraints.fill = GridBagConstraints.BOTH; resizeParameter = UIFrontEnd.getInstance().getResizeParameter(); resizeParameter.init(0.0, 0.0, 1.0, 1.0); resizeParameter.setToConstraints(sideConstraints); dialog.getContentPane().add(mainPanel, sideConstraints); //adds listeners to buttons okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent aEvent) { if (editor.getValue().equals(mValue)) { // } else { mValue = editor.getValue(); mEditorPanel.setValue(mValue); mEditorPanel.refreshControls(); mEditorPanel.setValueChanged(true); } dialog.setVisible(false); dialog.dispose(); } }); okButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "ExitAction"); okButton.getActionMap().put("ExitAction", new AbstractAction() { /** * Invoked when an action occurs. */ public void actionPerformed(ActionEvent aEvent) { editor.setValue(mValue); dialog.setVisible(false); dialog.dispose(); } }); okButton.requestFocus(); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent aEvent) { editor.setValue(mValue); dialog.setVisible(false); dialog.dispose(); } }); //dialog.setResizable(false); dialog.setModal(true); dialog.pack(); //sets minimal sizes for components Dimension dim = mainPanel.getSize(); mainPanel.setMinimumSize(dim); mainPanel.setPreferredSize(dim); //sets size of buttons Dimension dimOkButton = okButton.getSize(); Dimension dimCancelButton = cancelButton.getSize(); int nMaxWidth = dimOkButton.getWidth() > dimCancelButton.getWidth() ? (int) dimOkButton.getWidth() : (int) dimCancelButton.getWidth(); okButton.setPreferredSize(new Dimension(nMaxWidth, (int) dimOkButton.getHeight())); okButton.setSize(new Dimension(nMaxWidth, (int) dimOkButton.getHeight())); cancelButton.setPreferredSize(new Dimension(nMaxWidth, (int) dimCancelButton.getHeight())); cancelButton.setSize(new Dimension(nMaxWidth, (int) dimCancelButton.getHeight())); dialog.setLocationRelativeTo(dialog.getOwner()); dialog.setVisible(true); }
From source file:userinterface.properties.GUIGraphHandler.java
public void defineConstantsAndPlot(Expression expr, JPanel graph, String seriesName, Boolean isNewGraph, boolean is2D) { JDialog dialog;//from w w w . ja v a 2 s .c om JButton ok, cancel; JScrollPane scrollPane; ConstantPickerList constantList; JComboBox<String> xAxis, yAxis; //init everything dialog = new JDialog(GUIPrism.getGUI()); dialog.setTitle("Define constants and select axes"); dialog.setSize(500, 400); dialog.setLocationRelativeTo(GUIPrism.getGUI()); dialog.setLayout(new BoxLayout(dialog.getContentPane(), BoxLayout.Y_AXIS)); dialog.setModal(true); constantList = new ConstantPickerList(); scrollPane = new JScrollPane(constantList); xAxis = new JComboBox<String>(); yAxis = new JComboBox<String>(); ok = new JButton("Ok"); ok.setMnemonic('O'); cancel = new JButton("Cancel"); cancel.setMnemonic('C'); //add all components to their dedicated panels JPanel exprPanel = new JPanel(new FlowLayout()); exprPanel.setBorder(new TitledBorder("Function")); exprPanel.add(new JLabel(expr.toString())); JPanel axisPanel = new JPanel(); axisPanel.setBorder(new TitledBorder("Select axis constants")); axisPanel.setLayout(new BoxLayout(axisPanel, BoxLayout.Y_AXIS)); JPanel xAxisPanel = new JPanel(new FlowLayout()); xAxisPanel.add(new JLabel("X axis:")); xAxisPanel.add(xAxis); JPanel yAxisPanel = new JPanel(new FlowLayout()); yAxisPanel.add(new JLabel("Y axis:")); yAxisPanel.add(yAxis); axisPanel.add(xAxisPanel); axisPanel.add(yAxisPanel); JPanel constantPanel = new JPanel(new BorderLayout()); constantPanel.setBorder(new TitledBorder("Please define the following constants")); constantPanel.add(scrollPane, BorderLayout.CENTER); constantPanel.add(new ConstantHeader(), BorderLayout.NORTH); JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); bottomPanel.add(ok); bottomPanel.add(cancel); //fill the axes components for (int i = 0; i < expr.getAllConstants().size(); i++) { xAxis.addItem(expr.getAllConstants().get(i)); if (!is2D) yAxis.addItem(expr.getAllConstants().get(i)); } if (!is2D) { yAxis.setSelectedIndex(1); } //fill the constants table for (int i = 0; i < expr.getAllConstants().size(); i++) { ConstantLine line = new ConstantLine(expr.getAllConstants().get(i), TypeDouble.getInstance()); constantList.addConstant(line); if (!is2D) { if (line.getName().equals(xAxis.getSelectedItem().toString()) || line.getName().equals(yAxis.getSelectedItem().toString())) { line.doFuncEnables(false); } else { line.doFuncEnables(true); } } } //do enables if (is2D) { yAxis.setEnabled(false); } ok.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "ok"); ok.getActionMap().put("ok", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { ok.doClick(); } }); cancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel"); cancel.getActionMap().put("cancel", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { cancel.doClick(); } }); //add action listeners xAxis.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (is2D) { return; } String item = xAxis.getSelectedItem().toString(); if (item.equals(yAxis.getSelectedItem().toString())) { int index = yAxis.getSelectedIndex(); if (index != yAxis.getItemCount() - 1) { yAxis.setSelectedIndex(++index); } else { yAxis.setSelectedIndex(--index); } } for (int i = 0; i < constantList.getNumConstants(); i++) { ConstantLine line = constantList.getConstantLine(i); if (line.getName().equals(xAxis.getSelectedItem().toString()) || line.getName().equals(yAxis.getSelectedItem().toString())) { line.doFuncEnables(false); } else { line.doFuncEnables(true); } } } }); yAxis.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String item = yAxis.getSelectedItem().toString(); if (item.equals(xAxis.getSelectedItem().toString())) { int index = xAxis.getSelectedIndex(); if (index != xAxis.getItemCount() - 1) { xAxis.setSelectedIndex(++index); } else { xAxis.setSelectedIndex(--index); } } for (int i = 0; i < constantList.getNumConstants(); i++) { ConstantLine line = constantList.getConstantLine(i); if (line.getName().equals(xAxis.getSelectedItem().toString()) || line.getName().equals(yAxis.getSelectedItem().toString())) { line.doFuncEnables(false); } else { line.doFuncEnables(true); } } } }); ok.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { constantList.checkValid(); } catch (PrismException e2) { JOptionPane.showMessageDialog(dialog, "<html> One or more of the defined constants are invalid. <br><br> <font color=red>Error: </font>" + e2.getMessage() + "</html>", "Parse Error", JOptionPane.ERROR_MESSAGE); return; } if (is2D) { // it will always be a parametric graph in 2d case ParametricGraph pGraph = (ParametricGraph) graph; ConstantLine xAxisConstant = constantList.getConstantLine(xAxis.getSelectedItem().toString()); if (xAxisConstant == null) { //should never happen JOptionPane.showMessageDialog(dialog, "The selected axis is invalid.", "Error", JOptionPane.ERROR_MESSAGE); return; } double xStartValue = Double.parseDouble(xAxisConstant.getStartValue()); double xEndValue = Double.parseDouble(xAxisConstant.getEndValue()); double xStepValue = Double.parseDouble(xAxisConstant.getStepValue()); int seriesCount = 0; for (int i = 0; i < constantList.getNumConstants(); i++) { ConstantLine line = constantList.getConstantLine(i); if (line.getName().equals(xAxis.getSelectedItem().toString())) { seriesCount++; } else { seriesCount += line.getTotalNumOfValues(); } } // if there will be too many series to be plotted, ask the user if they are sure they know what they are doing if (seriesCount > 10) { int res = JOptionPane.showConfirmDialog(dialog, "This configuration will create " + seriesCount + " series. Continue?", "Confirm", JOptionPane.YES_NO_OPTION); if (res == JOptionPane.NO_OPTION) { return; } } Values singleValuesGlobal = new Values(); //add the single values to a global values list for (int i = 0; i < constantList.getNumConstants(); i++) { ConstantLine line = constantList.getConstantLine(i); if (line.getTotalNumOfValues() == 1) { double singleValue = Double.parseDouble(line.getSingleValue()); singleValuesGlobal.addValue(line.getName(), singleValue); } } // we just have one variable so we can plot directly if (constantList.getNumConstants() == 1 || singleValuesGlobal.getNumValues() == constantList.getNumConstants() - 1) { SeriesKey key = pGraph.addSeries(seriesName); pGraph.hideShape(key); pGraph.getXAxisSettings().setHeading(xAxis.getSelectedItem().toString()); pGraph.getYAxisSettings().setHeading("function"); for (double x = xStartValue; x <= xEndValue; x += xStepValue) { double ans = -1; Values vals = new Values(); vals.addValue(xAxis.getSelectedItem().toString(), x); for (int ii = 0; ii < singleValuesGlobal.getNumValues(); ii++) { try { vals.addValue(singleValuesGlobal.getName(ii), singleValuesGlobal.getDoubleValue(ii)); } catch (PrismLangException e1) { e1.printStackTrace(); } } try { ans = expr.evaluateDouble(vals); } catch (PrismLangException e1) { e1.printStackTrace(); } pGraph.addPointToSeries(key, new PrismXYDataItem(x, ans)); } if (isNewGraph) { addGraph(pGraph); } dialog.dispose(); return; } for (int i = 0; i < constantList.getNumConstants(); i++) { ConstantLine line = constantList.getConstantLine(i); if (line == xAxisConstant || singleValuesGlobal.contains(line.getName())) { continue; } double lineStart = Double.parseDouble(line.getStartValue()); double lineEnd = Double.parseDouble(line.getEndValue()); double lineStep = Double.parseDouble(line.getStepValue()); for (double j = lineStart; j < lineEnd; j += lineStep) { SeriesKey key = pGraph.addSeries(seriesName); pGraph.hideShape(key); for (double x = xStartValue; x <= xEndValue; x += xStepValue) { double ans = -1; Values vals = new Values(); vals.addValue(xAxis.getSelectedItem().toString(), x); vals.addValue(line.getName(), j); for (int ii = 0; ii < singleValuesGlobal.getNumValues(); ii++) { try { vals.addValue(singleValuesGlobal.getName(ii), singleValuesGlobal.getDoubleValue(ii)); } catch (PrismLangException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } for (int ii = 0; ii < constantList.getNumConstants(); ii++) { if (constantList.getConstantLine(ii) == xAxisConstant || singleValuesGlobal .contains(constantList.getConstantLine(ii).getName()) || constantList.getConstantLine(ii) == line) { continue; } ConstantLine temp = constantList.getConstantLine(ii); double val = Double.parseDouble(temp.getStartValue()); vals.addValue(temp.getName(), val); } try { ans = expr.evaluateDouble(vals); } catch (PrismLangException e1) { e1.printStackTrace(); } pGraph.addPointToSeries(key, new PrismXYDataItem(x, ans)); } } } if (isNewGraph) { addGraph(graph); } } else { // this will always be a parametric graph for the 3d case ParametricGraph3D pGraph = (ParametricGraph3D) graph; //add the graph to the gui addGraph(pGraph); //Get the constants we want to put on the x and y axis ConstantLine xAxisConstant = constantList.getConstantLine(xAxis.getSelectedItem().toString()); ConstantLine yAxisConstant = constantList.getConstantLine(yAxis.getSelectedItem().toString()); //add the single values to a global values list Values singleValuesGlobal = new Values(); for (int i = 0; i < constantList.getNumConstants(); i++) { ConstantLine line = constantList.getConstantLine(i); if (line.getTotalNumOfValues() == 1) { double singleValue = Double.parseDouble(line.getSingleValue()); singleValuesGlobal.addValue(line.getName(), singleValue); } } pGraph.setGlobalValues(singleValuesGlobal); pGraph.setAxisConstants(xAxis.getSelectedItem().toString(), yAxis.getSelectedItem().toString()); pGraph.setBounds(xAxisConstant.getStartValue(), xAxisConstant.getEndValue(), yAxisConstant.getStartValue(), yAxisConstant.getEndValue()); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { //plot the graph pGraph.plot(expr.toString(), xAxis.getSelectedItem().toString(), "Function", yAxis.getSelectedItem().toString()); //calculate the sampling rates from the step sizes as given by the user int xSamples = (int) ((Double.parseDouble(xAxisConstant.getEndValue()) - Double.parseDouble(xAxisConstant.getStartValue())) / Double.parseDouble(xAxisConstant.getStepValue())); int ySamples = (int) ((Double.parseDouble(xAxisConstant.getEndValue()) - Double.parseDouble(xAxisConstant.getStartValue())) / Double.parseDouble(xAxisConstant.getStepValue())); pGraph.setSamplingRates(xSamples, ySamples); } }); } dialog.dispose(); } }); cancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); } }); //add everything to the dialog show the dialog dialog.add(exprPanel); dialog.add(axisPanel); dialog.add(constantPanel); dialog.add(bottomPanel); dialog.setVisible(true); }
From source file:userinterface.properties.GUIGraphHandler.java
public void plotNewFunction() { JDialog dialog;/*from w ww. ja va 2 s.c o m*/ JRadioButton radio2d, radio3d, newGraph, existingGraph; JTextField functionField, seriesName; JButton ok, cancel; JComboBox<String> chartOptions; JLabel example; //init all the fields of the dialog dialog = new JDialog(GUIPrism.getGUI()); radio2d = new JRadioButton("2D"); radio3d = new JRadioButton("3D"); newGraph = new JRadioButton("New Graph"); existingGraph = new JRadioButton("Exisiting"); chartOptions = new JComboBox<String>(); functionField = new JTextField(); ok = new JButton("Plot"); cancel = new JButton("Cancel"); seriesName = new JTextField(); example = new JLabel("<html><font size=3 color=red>Example:</font><font size=3>x/2 + 5</font></html>"); example.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { example.setCursor(new Cursor(Cursor.HAND_CURSOR)); example.setForeground(Color.BLUE); } @Override public void mouseExited(MouseEvent e) { example.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); example.setForeground(Color.BLACK); } @Override public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { if (radio2d.isSelected()) { functionField.setText("x/2 + 5"); } else { functionField.setText("x+y+5"); } functionField.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 15)); functionField.setForeground(Color.BLACK); } } }); //set dialog properties dialog.setSize(400, 350); dialog.setTitle("Plot a new function"); dialog.setModal(true); dialog.setLayout(new BoxLayout(dialog.getContentPane(), BoxLayout.Y_AXIS)); dialog.setLocationRelativeTo(GUIPrism.getGUI()); //add every component to their dedicated panels JPanel graphTypePanel = new JPanel(new FlowLayout()); graphTypePanel.setBorder(BorderFactory .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Function type")); graphTypePanel.add(radio2d); graphTypePanel.add(radio3d); JPanel functionFieldPanel = new JPanel(new BorderLayout()); functionFieldPanel.setBorder(BorderFactory .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Function")); functionFieldPanel.add(functionField, BorderLayout.CENTER); functionFieldPanel.add(example, BorderLayout.SOUTH); JPanel chartSelectPanel = new JPanel(); chartSelectPanel.setLayout(new BoxLayout(chartSelectPanel, BoxLayout.Y_AXIS)); chartSelectPanel.setBorder(BorderFactory .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Plot function to")); JPanel radioPlotPanel = new JPanel(new FlowLayout()); radioPlotPanel.add(newGraph); radioPlotPanel.add(existingGraph); JPanel chartOptionsPanel = new JPanel(new FlowLayout()); chartOptionsPanel.add(chartOptions); chartSelectPanel.add(radioPlotPanel); chartSelectPanel.add(chartOptionsPanel); JPanel bottomControlPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); bottomControlPanel.add(ok); bottomControlPanel.add(cancel); JPanel seriesNamePanel = new JPanel(new BorderLayout()); seriesNamePanel.setBorder(BorderFactory .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Series name")); seriesNamePanel.add(seriesName, BorderLayout.CENTER); // add all the panels to the dialog dialog.add(graphTypePanel); dialog.add(functionFieldPanel); dialog.add(chartSelectPanel); dialog.add(seriesNamePanel); dialog.add(bottomControlPanel); // do all the enables and set properties radio2d.setSelected(true); newGraph.setSelected(true); chartOptions.setEnabled(false); functionField.setText("Add function expression here...."); functionField.setFont(new Font(Font.SANS_SERIF, Font.ITALIC, 15)); functionField.setForeground(Color.GRAY); seriesName.setText("New function"); ok.setMnemonic('P'); cancel.setMnemonic('C'); example.setToolTipText("click to try out"); ok.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "ok"); ok.getActionMap().put("ok", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { ok.doClick(); } }); cancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel"); cancel.getActionMap().put("cancel", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { cancel.doClick(); } }); boolean found = false; for (int i = 0; i < theTabs.getTabCount(); i++) { if (theTabs.getComponentAt(i) instanceof Graph) { chartOptions.addItem(getGraphName(i)); found = true; } } if (!found) { existingGraph.setEnabled(false); chartOptions.setEnabled(false); } //add all the action listeners radio2d.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (radio2d.isSelected()) { radio3d.setSelected(false); if (chartOptions.getItemCount() > 0) { existingGraph.setEnabled(true); chartOptions.setEnabled(true); } example.setText( "<html><font size=3 color=red>Example:</font><font size=3>x/2 + 5</font></html>"); } } }); radio3d.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (radio3d.isSelected()) { radio2d.setSelected(false); newGraph.setSelected(true); existingGraph.setEnabled(false); chartOptions.setEnabled(false); example.setText("<html><font size=3 color=red>Example:</font><font size=3>x+y+5</font></html>"); } } }); newGraph.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (newGraph.isSelected()) { existingGraph.setSelected(false); chartOptions.setEnabled(false); } } }); existingGraph.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (existingGraph.isSelected()) { newGraph.setSelected(false); chartOptions.setEnabled(true); } } }); ok.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String function = functionField.getText(); Expression expr = null; try { expr = GUIPrism.getGUI().getPrism().parseSingleExpressionString(function); expr = (Expression) expr.accept(new ASTTraverseModify() { @Override public Object visit(ExpressionIdent e) throws PrismLangException { return new ExpressionConstant(e.getName(), TypeDouble.getInstance()); } }); expr.typeCheck(); expr.semanticCheck(); } catch (PrismLangException e1) { // for copying style JLabel label = new JLabel(); // html content in our case the error we want to show JEditorPane ep = new JEditorPane("text/html", "<html> There was an error parsing the function. To read about what built-in" + " functions are supported <br>and some more information on the functions, visit " + "<a href='http://www.prismmodelchecker.org/manual/ThePRISMLanguage/Expressions'>Prism expressions site</a>." + "<br><br><font color=red>Error: </font>" + e1.getMessage() + " </html>"); // handle link events ep.addHyperlinkListener(new HyperlinkListener() { @Override public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) { try { Desktop.getDesktop().browse(e.getURL().toURI()); } catch (IOException | URISyntaxException e1) { e1.printStackTrace(); } } } }); ep.setEditable(false); ep.setBackground(label.getBackground()); // show the error dialog JOptionPane.showMessageDialog(dialog, ep, "Parse Error", JOptionPane.ERROR_MESSAGE); return; } if (radio2d.isSelected()) { ParametricGraph graph = null; if (newGraph.isSelected()) { graph = new ParametricGraph(""); } else { for (int i = 0; i < theTabs.getComponentCount(); i++) { if (theTabs.getTitleAt(i).equals(chartOptions.getSelectedItem())) { graph = (ParametricGraph) theTabs.getComponent(i); } } } dialog.dispose(); defineConstantsAndPlot(expr, graph, seriesName.getText(), newGraph.isSelected(), true); } else if (radio3d.isSelected()) { try { expr = (Expression) expr.accept(new ASTTraverseModify() { @Override public Object visit(ExpressionIdent e) throws PrismLangException { return new ExpressionConstant(e.getName(), TypeDouble.getInstance()); } }); expr.semanticCheck(); expr.typeCheck(); } catch (PrismLangException e1) { e1.printStackTrace(); } if (expr.getAllConstants().size() < 2) { JOptionPane.showMessageDialog(dialog, "There are not enough variables in the function to plot a 3D chart!", "Error", JOptionPane.ERROR_MESSAGE); return; } // its always a new graph ParametricGraph3D graph = new ParametricGraph3D(expr); dialog.dispose(); defineConstantsAndPlot(expr, graph, seriesName.getText(), true, false); } dialog.dispose(); } }); cancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); } }); // we will show info about the function when field is out of focus functionField.addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent e) { if (!functionField.getText().equals("")) { return; } functionField.setText("Add function expression here...."); functionField.setFont(new Font(Font.SANS_SERIF, Font.ITALIC, 15)); functionField.setForeground(Color.GRAY); } @Override public void focusGained(FocusEvent e) { if (!functionField.getText().equals("Add function expression here....")) { return; } functionField.setForeground(Color.BLACK); functionField.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 15)); functionField.setText(""); } }); // show the dialog dialog.setVisible(true); }