List of usage examples for javax.swing JDialog add
public Component add(Component comp)
From source file:org.openflexo.view.controller.FlexoInspectorController.java
public static void main(String[] args) { JFrame frame = new JFrame(); final JDialog dialog = new JDialog(frame); dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); JButton button = new JButton("Show dialog"); button.addActionListener(new ActionListener() { @Override/*from w w w. j a v a 2 s . c o m*/ public void actionPerformed(ActionEvent e) { dialog.setVisible(true); } }); JLabel label = new JLabel("coucou"); dialog.add(label); dialog.pack(); JPanel panel = new JPanel(new BorderLayout()); panel.add(button); panel.setPreferredSize(new Dimension(500, 400)); frame.add(panel); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:plugins.tprovoost.Microscopy.MicroManagerForIcy.MMMainFrame.java
/** * Create an error dialog concerning DLL issues with Micro-Manager. * // ww w . j av a 2s . co m * @return Returns the dialog. */ private JDialog createDLLErrorDialog() { MainFrame mainFrame = Icy.getMainInterface().getMainFrame(); // Dialog frame to be returned final JDialog dialog = new JDialog(mainFrame, "Loading Error", true); // main panel of the dialog JPanel panel_main = new JPanel(); panel_main.setLayout(new BorderLayout()); JLabel lbl_html = new JLabel("<html>" + "<h2>Unable to load library</h2>" + "<br/><b>What happened ?</b>" + "<p>The library is a file used by Manager to interact with the devices. Each device needs a specific file in order <br/>" + "to work properly with the system. If only one file is missing, this error occurs.</p>" + "<b>To avoid getting this problem again, please acknowledge the following steps: </b>" + "<ol><li>Do you have Micro-Manager 1.4 installed ? If not, please install it via the button below.</li>" + "<li>Check the application directory of Icy. You should find a file named: " + "<ul><li>on Windows: MMCoreJ_wrap</li><li>on Mac: libMMCoreJ_wrap</li></ul>" + "<li>Plus : you should have a file for each of your devices starting with the name:" + "<ul><li>on Windows: mmgr_dal_</li><li>on Mac: libmmgr_dal_</li></ul>" + "<li>If you don't have these files, please copy (not move) them from the Manager application directory<br/>" + "to your Icy application directory.</li></ol></html>"); panel_main.add(lbl_html, BorderLayout.CENTER); panel_main.setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20)); JPanel panel_buttons = new JPanel(); panel_buttons.setLayout(new BoxLayout(panel_buttons, BoxLayout.X_AXIS)); panel_buttons.add(Box.createHorizontalGlue()); JButton btn_link = new JButton(); btn_link.setText("Download Micro-Manager 1.4.14"); btn_link.setBackground(Color.WHITE); btn_link.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { NetworkUtil .openBrowser("http://valelab.ucsf.edu/~MM/MMwiki/index.php/Micro-Manager_Version_Archive"); } }); panel_buttons.add(btn_link); JButton btn_ok = new JButton("OK"); btn_ok.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialog.setVisible(false); } }); panel_buttons.add(btn_ok); panel_main.add(panel_buttons, BorderLayout.SOUTH); dialog.add(panel_main); dialog.pack(); dialog.setLocation((int) mainFrame.getSize().getWidth() / 2 - dialog.getWidth() / 2, (int) mainFrame.getSize().getHeight() / 2 - dialog.getHeight() / 2); return dialog; }
From source file:ui.frame.UILogin.java
public UILogin() { super("Login"); Label l = new Label(); setLayout(new BorderLayout()); this.setPreferredSize(new Dimension(400, 300)); Panel p = new Panel(); loginPanel = p.createPanel(Layouts.grid, 4, 2); loginPanel.setBorder(new EmptyBorder(25, 25, 0, 25)); lblUser = l.createLabel("Username:"); lblPassword = l.createLabel("Password:"); lblURL = l.createLabel("Server URL"); lblBucket = l.createLabel("Bucket"); tfURL = new JTextField(); tfURL.setText("kaiup.kaisquare.com"); tfBucket = new JTextField(); PromptSupport.setPrompt("BucketName", tfBucket); tfUser = new JTextField(); PromptSupport.setPrompt("Username", tfUser); pfPassword = new JPasswordField(); PromptSupport.setPrompt("Password", pfPassword); buttonPanel = p.createPanel(Layouts.flow); buttonPanel.setBorder(new EmptyBorder(0, 0, 25, 0)); Button b = new Button(); JButton btnLogin = b.createButton("Login"); JButton btnExit = b.createButton("Exit"); btnLogin.setPreferredSize(new Dimension(150, 50)); btnExit.setPreferredSize(new Dimension(150, 50)); Component[] arrayBtn = { btnExit, btnLogin }; p.addComponentsToPanel(buttonPanel, arrayBtn); Component[] arrayComponents = { lblURL, tfURL, lblBucket, tfBucket, lblUser, tfUser, lblPassword, pfPassword };/*from ww w . j ava 2 s. co m*/ p.addComponentsToPanel(loginPanel, arrayComponents); add(loginPanel, BorderLayout.CENTER); add(buttonPanel, BorderLayout.SOUTH); pack(); setDefaultCloseOperation(EXIT_ON_CLOSE); setLocationRelativeTo(null); setVisible(true); btnLogin.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { SwingWorker<Void, Void> mySwingWorker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { if (tfUser.getText().equals("") || String.valueOf(pfPassword.getPassword()).equals("") || tfBucket.getText().equals("")) { JOptionPane.showMessageDialog(Data.mainFrame, "Please fill up all the fields", "Error", JOptionPane.ERROR_MESSAGE); } else { String username = tfUser.getText(); String password = String.valueOf(pfPassword.getPassword()); Data.URL = Data.protocol + tfURL.getText(); Data.targetURL = Data.protocol + tfURL.getText() + "/api/" + tfBucket.getText() + "/"; String response = api.loginBucket(Data.targetURL, username, password); try { if (DesktopAppMain.checkResult(response)) { JSONObject responseJSON = new JSONObject(response); Data.sessionKey = responseJSON.get("session-key").toString(); response = api.getUserFeatures(Data.targetURL, Data.sessionKey); if (checkFeatures(response)) { Data.mainFrame = new KAIQRFrame(); Data.mainFrame.uiInventorySelect = new UIInventorySelect(); Data.mainFrame.addPanel(Data.mainFrame.uiInventorySelect, "inventory"); Data.mainFrame.showPanel("inventory"); Data.mainFrame.pack(); setVisible(false); Data.mainFrame.setVisible(true); } else { JOptionPane.showMessageDialog(Data.loginFrame, "User does not have necessary features", "Error", JOptionPane.ERROR_MESSAGE); } } else { JOptionPane.showMessageDialog(Data.loginFrame, "Wrong username/password", "Error", JOptionPane.ERROR_MESSAGE); } } catch (JSONException e1) { e1.printStackTrace(); } } return null; } }; Window win = SwingUtilities.getWindowAncestor((AbstractButton) e.getSource()); final JDialog dialog = new JDialog(win, "Login", ModalityType.APPLICATION_MODAL); mySwingWorker.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("state")) { if (evt.getNewValue() == SwingWorker.StateValue.DONE) { dialog.dispose(); } } } }); mySwingWorker.execute(); JProgressBar progressBar = new JProgressBar(); progressBar.setIndeterminate(true); JPanel panel = new JPanel(new BorderLayout()); panel.add(progressBar, BorderLayout.CENTER); panel.add(new JLabel("Logging in .........."), BorderLayout.PAGE_START); dialog.add(panel); dialog.pack(); dialog.setBounds(50, 50, 300, 100); dialog.setLocationRelativeTo(Data.mainFrame); dialog.setVisible(true); } }); btnExit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); }
From source file:ui.panel.UIAccessKeySelect.java
public void runaccessKeySelect() { getAccessKeyData();//ww w .j av a2 s .co m Panel p = new Panel(); Button b = new Button(); Label l = new Label(); setLayout(new BorderLayout()); JPanel pnlInstruction = p.createPanel(Layouts.flow); JLabel lblInstruction = l.createLabel("Access Keys"); pnlInstruction.setBackground(CustomColor.LightBlue.returnColor()); lblInstruction.setForeground(Color.white); lblInstruction.setFont(new Font("San Serif", Font.PLAIN, 18)); pnlInstruction.add(lblInstruction); JPanel pnlBucketList = p.createPanel(Layouts.border); listBucket.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane scrollBucket = new JScrollPane(listBucket); Component[] BucketListComponents = { scrollBucket }; pnlBucketList.add(scrollBucket, BorderLayout.CENTER); JPanel pnlButtons = p.createPanel(Layouts.flow); JButton btnBack = b.createButton("Back"); JButton btnSelectElements = b.createButton("Next"); JButton btnAdd = b.createButton("Generate Access Key"); JButton btnRefresh = b.createButton("Refresh"); pnlButtons.add(btnBack); pnlButtons.add(btnAdd); pnlButtons.add(btnRefresh); pnlButtons.add(btnSelectElements); add(pnlInstruction, BorderLayout.NORTH); add(pnlBucketList, BorderLayout.CENTER); add(pnlButtons, BorderLayout.SOUTH); btnBack.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Data.mainFrame.showPanel("license"); } }); btnRefresh.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { getAccessKeyData(); } }); btnAdd.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Data.mainFrame.uiGenerateKey = new UIGenerateKey(); Data.mainFrame.addPanel(Data.mainFrame.uiGenerateKey, "generateKey"); Data.mainFrame.pack(); Data.mainFrame.showPanel("generateKey"); } }); btnSelectElements.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { SwingWorker<Void, Void> mySwingWorker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { int selected = listBucket.getSelectedRow(); if (selected != -1) { Data.accessKey = (String) listBucket.getModel().getValueAt(selected, 0); Data.mainFrame.qrGenerator = new JavaQR(); Data.mainFrame.pack(); Data.mainFrame.addPanel(Data.mainFrame.qrGenerator, "generateQR"); Data.mainFrame.showPanel("generateQR"); } else { JOptionPane.showMessageDialog(Data.mainFrame, "Please Select Access Key", "Error", JOptionPane.ERROR_MESSAGE); } return null; } }; Window win = SwingUtilities.getWindowAncestor((AbstractButton) e.getSource()); final JDialog dialog = new JDialog(win, "Loading", ModalityType.APPLICATION_MODAL); mySwingWorker.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("state")) { if (evt.getNewValue() == SwingWorker.StateValue.DONE) { dialog.dispose(); } } } }); mySwingWorker.execute(); JProgressBar progressBar = new JProgressBar(); progressBar.setIndeterminate(true); JPanel panel = new JPanel(new BorderLayout()); panel.add(progressBar, BorderLayout.CENTER); panel.add(new JLabel("Generating QR Code......."), BorderLayout.PAGE_START); dialog.add(panel); dialog.pack(); dialog.setBounds(50, 50, 300, 100); dialog.setLocationRelativeTo(Data.mainFrame); dialog.setVisible(true); } }); }
From source file:ui.panel.UIBucketSelect.java
public void runBucketSelect() { Panel p = new Panel(); Button b = new Button(); Label l = new Label(); setLayout(new BorderLayout()); JPanel pnlInstruction = p.createPanel(Layouts.flow); JLabel lblInstruction = l.createLabel("Bucket List"); pnlInstruction.setBackground(CustomColor.LightBlue.returnColor()); lblInstruction.setForeground(Color.white); lblInstruction.setFont(new Font("San Serif", Font.PLAIN, 18)); pnlInstruction.add(lblInstruction);/*from w w w . j a v a 2 s . co m*/ JPanel pnlBucketList = p.createPanel(Layouts.border); listBucket.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane scrollBucket = new JScrollPane(listBucket); scrollBucket.setPreferredSize(new Dimension(300, 150)); pnlBucketList.add(scrollBucket, BorderLayout.CENTER); JPanel pnlButtons = p.createPanel(Layouts.flow); JButton btnBack = b.createButton("Back"); JButton btnSelectElements = b.createButton("Next"); JButton btnRefresh = b.createButton("Refresh Bucket List"); pnlButtons.add(btnBack); pnlButtons.add(btnRefresh); pnlButtons.add(btnSelectElements); add(pnlInstruction, BorderLayout.NORTH); add(pnlBucketList, BorderLayout.CENTER); add(pnlButtons, BorderLayout.SOUTH); setVisible(true); btnRefresh.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { getBucketData(); } }); btnSelectElements.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { SwingWorker<Void, Void> mySwingWorker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { int selected = listBucket.getSelectedRow(); if (selected == -1) { JOptionPane.showMessageDialog(Data.mainFrame, "Please Select a Bucket", "Error", JOptionPane.ERROR_MESSAGE); } else { Data.bucketID = (int) listBucket.getModel().getValueAt(selected, 0); Data.mainFrame.addPanel(Data.mainFrame.uiLicenseDetail = new UILicenseDetail(), "license"); Data.mainFrame.pack(); Data.mainFrame.showPanel("license"); } return null; } }; Window win = SwingUtilities.getWindowAncestor((AbstractButton) e.getSource()); final JDialog dialog = new JDialog(win, "Loading", ModalityType.APPLICATION_MODAL); mySwingWorker.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("state")) { if (evt.getNewValue() == SwingWorker.StateValue.DONE) { dialog.dispose(); } } } }); mySwingWorker.execute(); JProgressBar progressBar = new JProgressBar(); progressBar.setIndeterminate(true); JPanel panel = new JPanel(new BorderLayout()); panel.add(progressBar, BorderLayout.CENTER); panel.add(new JLabel("Retrieving Licenses......."), BorderLayout.PAGE_START); dialog.add(panel); dialog.pack(); dialog.setBounds(50, 50, 300, 100); dialog.setLocationRelativeTo(Data.mainFrame); dialog.setVisible(true); } }); btnBack.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setVisible(false); Data.mainFrame.showPanel("inventory"); } }); }
From source file:ui.panel.UILicenseAdd.java
public JPanel createButtonPanel() { JPanel panel = p.createPanel(Layouts.flow); panel.setLayout(new FlowLayout(FlowLayout.CENTER)); btnSubmit = b.createButton("Submit"); btnCancel = b.createButton("Cancel"); btnSubmit.addActionListener(new ActionListener() { @Override//from w ww . j a va2 s . c o m public void actionPerformed(ActionEvent e) { SwingWorker<Void, Void> mySwingWorker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { TreePath[] path = checkTreeManager.getSelectionModel().getSelectionPaths(); ArrayList<String> featureL = new ArrayList<String>(); String[] features = new String[] {}; for (TreePath tp : path) { if (tp.getLastPathComponent().toString().equals("Features")) { Object rootNode = tree.getModel().getRoot(); int parentCount = tree.getModel().getChildCount(rootNode); for (int i = 0; i < parentCount; i++) { Object parentNode = tree.getModel().getChild(rootNode, i); int childrenCount = tree.getModel().getChildCount(parentNode); for (int x = 0; x < childrenCount; x++) { MyDataNode node = (MyDataNode) tree.getModel().getChild(parentNode, x); featureL.add(node.getValue()); } } } else if (tp.getPathCount() == 2) { Object rootNode = tree.getModel().getRoot(); int parentCount = tree.getModel().getChildCount(rootNode); for (int i = 0; i < parentCount; i++) { Object parentNode = tree.getModel().getChild(rootNode, i); if (parentNode.toString().equals(tp.getLastPathComponent().toString())) { int childrenCount = tree.getModel().getChildCount(parentNode); for (int x = 0; x < childrenCount; x++) { MyDataNode node = (MyDataNode) tree.getModel().getChild(parentNode, x); featureL.add(node.getValue()); } } } } else if (tp.getPathCount() == 3) { MyDataNode node = (MyDataNode) tp.getLastPathComponent(); featureL.add(node.getValue()); } } features = featureL.toArray(features); String duration = spnValidity.getValue().toString(); if (cbPerpetual.isSelected()) { duration = "-1"; } String storage = spnCloud.getValue().toString(); String maxVCA = spnConcurrentVCA.getValue().toString(); String response = apiCall.addNodeLicense(Data.targetURL, Data.sessionKey, Data.bucketID, features, duration, storage, maxVCA); try { JSONObject responseObject = new JSONObject(response); if (responseObject.get("result").equals("ok")) { Data.mainFrame.uiLicenseDetail.getLicenseData(); Data.mainFrame.showPanel("license"); } } catch (JSONException e1) { e1.printStackTrace(); } return null; } }; Window win = SwingUtilities.getWindowAncestor((AbstractButton) e.getSource()); final JDialog dialog = new JDialog(win, "Loading", ModalityType.APPLICATION_MODAL); mySwingWorker.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("state")) { if (evt.getNewValue() == SwingWorker.StateValue.DONE) { dialog.dispose(); } } } }); mySwingWorker.execute(); JProgressBar progressBar = new JProgressBar(); progressBar.setIndeterminate(true); JPanel panel = new JPanel(new BorderLayout()); panel.add(progressBar, BorderLayout.CENTER); panel.add(new JLabel("Retrieving License..."), BorderLayout.PAGE_START); dialog.add(panel); dialog.pack(); dialog.setBounds(50, 50, 300, 100); dialog.setLocationRelativeTo(Data.mainFrame); dialog.setVisible(true); } }); btnCancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setVisible(false); Data.mainFrame.showPanel("license"); } }); panel.add(btnSubmit); panel.add(btnCancel); return panel; }
From source file:ui.panel.UILicenseDetail.java
public JPanel createButtonPanel() { JPanel panel = p.createPanel(Layouts.flow); panel.setLayout(new FlowLayout(FlowLayout.CENTER)); btnSubmit = b.createButton("Next"); btnBack = b.createButton("Back"); btnAdd = b.createButton("Add License"); panel.add(btnBack);/* w w w . j ava2 s . co m*/ panel.add(btnAdd); panel.add(btnSubmit); btnBack.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Data.mainFrame.showPanel("bucket"); } }); btnAdd.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Data.mainFrame.addPanel(Data.mainFrame.uiLicenseAdd = new UILicenseAdd(), "licenseAdd"); Data.mainFrame.showPanel("licenseAdd"); } }); btnSubmit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { SwingWorker<Void, Void> mySwingWorker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { int row = tblInfo.getSelectedRow(); if (row == -1) { JOptionPane.showMessageDialog(Data.mainFrame, "Please Select a License", "Error", JOptionPane.ERROR_MESSAGE); } else { Data.licenseNumber = (String) tblInfo.getModel().getValueAt(row, 0); Data.mainFrame.uiAccessKeySelect = new UIAccessKeySelect(); Data.mainFrame.addPanel(Data.mainFrame.uiAccessKeySelect, "access"); Data.mainFrame.showPanel("access"); } return null; } }; Window win = SwingUtilities.getWindowAncestor((AbstractButton) e.getSource()); final JDialog dialog = new JDialog(win, "Loading", ModalityType.APPLICATION_MODAL); mySwingWorker.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("state")) { if (evt.getNewValue() == SwingWorker.StateValue.DONE) { dialog.dispose(); } } } }); mySwingWorker.execute(); JProgressBar progressBar = new JProgressBar(); progressBar.setIndeterminate(true); JPanel panel = new JPanel(new BorderLayout()); panel.add(progressBar, BorderLayout.CENTER); panel.add(new JLabel("Retrieving Access Keys"), BorderLayout.PAGE_START); dialog.add(panel); dialog.pack(); dialog.setBounds(50, 50, 300, 100); dialog.setLocationRelativeTo(Data.mainFrame); dialog.setVisible(true); } }); btnBack.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setVisible(false); Data.mainFrame.showPanel("bucket"); } }); btnAdd.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setVisible(false); Data.mainFrame.addPanel(Data.mainFrame.uiLicenseAdd = new UILicenseAdd(), "licenseAdd"); Data.mainFrame.pack(); Data.mainFrame.showPanel("licenseAdd"); } }); return panel; }
From source file:utybo.branchingstorytree.swing.editor.StoryEditor.java
public StoryEditor(BranchingStory baseStory) throws BSTException { setLayout(new MigLayout("hidemode 3", "[grow]", "[][grow]")); JToolBar toolBar = new JToolBar(); toolBar.setBorder(null);//from ww w.ja v a 2 s .c om toolBar.setFloatable(false); add(toolBar, "cell 0 0,growx"); JButton btnSaveAs = new JButton(Lang.get("saveas"), new ImageIcon(Icons.getImage("Save As", 16))); btnSaveAs.addActionListener(e -> { saveAs(); }); toolBar.add(btnSaveAs); JButton btnSave = new JButton(Lang.get("save"), new ImageIcon(Icons.getImage("Save", 16))); btnSave.addActionListener(e -> { save(); }); toolBar.add(btnSave); JButton btnPlay = new JButton(Lang.get("play"), new ImageIcon(Icons.getImage("Circled Play", 16))); btnPlay.addActionListener(ev -> { try { String s = exportToString(); File f = Files.createTempDirectory("openbst").toFile(); File bstFile = new File(f, "expoted.bst"); try (FileOutputStream fos = new FileOutputStream(bstFile);) { IOUtils.write(s, fos, StandardCharsets.UTF_8); } OpenBSTGUI.getInstance().openStory(bstFile); } catch (Exception e) { OpenBST.LOG.error("Export failed", e); Messagers.showException(OpenBSTGUI.getInstance(), Lang.get("editor.exportfail"), e); } }); toolBar.add(btnPlay); JButton btnFilePreview = new JButton(Lang.get("editor.exportpreview"), new ImageIcon(Icons.getImage("PreviewText", 16))); btnFilePreview.addActionListener(e -> { try { String s = exportToString(); JDialog dialog = new JDialog(OpenBSTGUI.getInstance(), Lang.get("editor.exportpreview")); JTextArea jta = new JTextArea(s); jta.setLineWrap(true); jta.setWrapStyleWord(true); dialog.add(new JScrollPane(jta)); dialog.setModalityType(ModalityType.APPLICATION_MODAL); dialog.setSize((int) (Icons.getScale() * 350), (int) (Icons.getScale() * 300)); dialog.setLocationRelativeTo(OpenBSTGUI.getInstance()); dialog.setVisible(true); } catch (Exception x) { OpenBST.LOG.error("Failed to preview", x); Messagers.showException(OpenBSTGUI.getInstance(), Lang.get("editor.previewerror"), x); } }); toolBar.add(btnFilePreview); Component horizontalGlue = Box.createHorizontalGlue(); toolBar.add(horizontalGlue); JButton btnClose = new JButton(Lang.get("close"), new ImageIcon(Icons.getImage("Cancel", 16))); btnClose.addActionListener(e -> { askClose(); }); toolBar.add(btnClose); for (final Component component : toolBar.getComponents()) { if (component instanceof JButton) { ((JButton) component).setHideActionText(false); ((JButton) component).setToolTipText(((JButton) component).getText()); ((JButton) component).setText(""); } } JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP); tabbedPane.setTabPlacement(JTabbedPane.LEFT); add(tabbedPane, "cell 0 1,grow"); tabbedPane.addTab("Beta Warning", new StoryEditorWelcomeScreen()); details = new StoryDetailsEditor(this); tabbedPane.addTab(Lang.get("editor.details"), details); nodesEditor = new StoryNodesEditor(); tabbedPane.addTab(Lang.get("editor.nodes"), nodesEditor); this.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke("control S"), "doSave"); this.getActionMap().put("doSave", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { save(); } }); importFrom(baseStory); }
From source file:Widgets.Simulation.java
public Simulation(final JFrame aFrame, NetworkElement item) { super(aFrame); grn = ((DynamicalModelElement) item).getGeneNetwork(); plot = new Plot2DPanel(); //closing listener this.addWindowListener(new WindowAdapter() { @Override//from www.j a v a 2s. c o m public void windowClosing(WindowEvent windowEvent) { if (simulation != null && simulation.myThread_.isAlive()) { simulation.stop(); System.out.print("Simulation is canceled.\n"); JOptionPane.showMessageDialog(new Frame(), "Simulation is canceled.", "Warning!", JOptionPane.INFORMATION_MESSAGE); } escapeAction(); } }); // Model model_.setModel(new DefaultComboBoxModel(new String[] { "Deterministic Model (ODEs)", "Stochastic Model (SDEs)", "Stochastic Simulation (Gillespie Algorithm)" })); model_.setSelectedIndex(0); setModelAction(); //set plot part //display result if (grn.getTimeScale().size() >= 1) { //update parameters numTimeSeries_.setValue(grn.getTraj_itsValue()); tmax_.setValue(grn.getTraj_maxTime()); sdeDiffusionCoeff_.setValue(grn.getTraj_noise()); if (grn.getTraj_model().equals("ode")) model_.setSelectedIndex(0); else if (grn.getTraj_model().equals("sde")) model_.setSelectedIndex(1); else model_.setSelectedIndex(2); //update plot trajPlot.removeAll(); trajPlot.add(trajectoryTabb()); trajPlot.updateUI(); trajPlot.setVisible(true); trajPlot.repaint(); analyzeResult.setVisible(true); } /** * ACTIONS */ model_.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { setModelAction(); } }); analyzeResult.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent arg0) { final JDialog a = new JDialog(); a.setSize(new Dimension(500, 450)); a.setModal(true); a.setTitle("Gene List (seperated by ';')"); a.setLocationRelativeTo(null); final JTextArea focusGenesArea = new JTextArea(); focusGenesArea.setLineWrap(true); focusGenesArea.setEditable(false); focusGenesArea.setRows(3); String geneNames = ""; for (int i = 0; i < grn.getNodes().size(); i++) geneNames += grn.getNodes().get(i).getLabel() + ";"; focusGenesArea.setText(geneNames); JButton submitButton = new JButton("Submit"); JButton cancelButton = new JButton("Cancel"); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); buttonPanel.add(submitButton); buttonPanel.add(cancelButton); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent arg0) { a.dispose(); } }); submitButton.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent arg0) { a.dispose(); final JDialog a = new JDialog(); a.setSize(new Dimension(500, 450)); a.setModal(true); a.setTitle("Statistics"); a.setLocationRelativeTo(null); if (grn.getTimeSeries().isEmpty()) { JOptionPane.showMessageDialog(new Frame(), "Please run the simulation first.", "Warning!", JOptionPane.INFORMATION_MESSAGE); } else { JPanel infoPanel = new JPanel(); infoPanel.setLayout(new BorderLayout()); //output String[] focusGenes = focusGenesArea.getText().split(";"); ; String content = ""; //discrete the final state int dimension = grn.getNodes().size(); //get gene index int[] focus_index = new int[focusGenes.length]; for (int j = 0; j < focusGenes.length; j++) for (int i = 0; i < dimension; i++) if (grn.getNode(i).getLabel().equals(focusGenes[j])) focus_index[j] = i; JScrollPane jsp = new JScrollPane(); //calculate steady states grn.setLand_itsValue((Integer) numTimeSeries_.getModel().getValue()); int[] isConverge = new int[grn.getTraj_itsValue()]; String out = calculateSteadyStates(focusGenes, focus_index, isConverge); //show the convergence final JDialog ifconvergent = new JDialog(); ifconvergent.setSize(new Dimension(500, 450)); ifconvergent.setModal(true); ifconvergent.setTitle("Convergence"); ifconvergent.setLocationRelativeTo(null); ConvergenceTable tablePanel = new ConvergenceTable(isConverge); JButton continueButton = new JButton("Click to check the attractors."); continueButton.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent arg0) { ifconvergent.dispose(); } }); JPanel ifconvergentPanel = new JPanel(); ifconvergentPanel.setLayout(new BorderLayout()); ifconvergentPanel.add(tablePanel, BorderLayout.NORTH); ifconvergentPanel.add(continueButton, BorderLayout.SOUTH); ifconvergent.add(ifconvergentPanel); ifconvergent.setVisible(true); //show attractors if (out.equals("ok")) { AttractorTable panel = new AttractorTable(grn, focusGenes); jsp.setViewportView(panel); } else if (grn.getSumPara().size() == 0) content += "Cannot find a steady state!"; else content += "\nI dont know why!"; if (content != "") { JLabel warningLabel = new JLabel(); warningLabel.setText(content); jsp.setViewportView(warningLabel); } grn.setSumPara(null); grn.setCounts(null); //jsp.setPreferredSize(new Dimension(280,130)); jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); jsp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); infoPanel.add(jsp, BorderLayout.CENTER); a.add(infoPanel); a.setVisible(true); } //end of else } }); JPanel options3 = new JPanel(); options3.setLayout(new BorderLayout()); options3.add(focusGenesArea, BorderLayout.NORTH); options3.add(buttonPanel); options3.setBorder(new EmptyBorder(5, 0, 5, 0)); a.add(options3); a.setVisible(true); } }); runButton_.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent arg0) { //System.out.print("Memory start: "+s_runtime.totalMemory()+"\n"); enterAction(); } }); cancelButton_.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent arg0) { if (simulation != null) simulation.stop(); System.out.print("Simulation is canceled!\n"); } }); fixButton.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent arg0) { JDialog a = new JDialog(); a.setTitle("Fixed initial values"); a.setSize(new Dimension(400, 400)); a.setLocationRelativeTo(null); JPanel speciesPanel = new JPanel(); String[] columnName = { "Name", "InitialValue" }; boolean editable = false; //false; new SpeciesTable(speciesPanel, columnName, grn, editable); /** LAYOUT **/ JPanel wholePanel = new JPanel(); wholePanel.setLayout(new BoxLayout(wholePanel, BoxLayout.Y_AXIS)); wholePanel.add(speciesPanel); a.add(wholePanel); a.setModal(true); a.setVisible(true); } }); randomButton.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent arg0) { final JDialog a = new JDialog(); a.setTitle("Set boundaries"); a.setSize(new Dimension(300, 200)); a.setModal(true); a.setLocationRelativeTo(null); JPanel upPanel = new JPanel(); JLabel upLabel = new JLabel("Input the upper boundary: "); final JTextField upValue = new JTextField("3"); upPanel.setLayout(new BoxLayout(upPanel, BoxLayout.X_AXIS)); upPanel.add(upLabel); upPanel.add(upValue); JPanel lowPanel = new JPanel(); JLabel lowLabel = new JLabel("Input the lower boundary: "); final JTextField lowValue = new JTextField("0"); lowPanel.setLayout(new BoxLayout(lowPanel, BoxLayout.X_AXIS)); lowPanel.add(lowLabel); lowPanel.add(lowValue); JPanel buttonPanel = new JPanel(); JButton submit = new JButton("Submit"); JButton cancel = new JButton("Cancel"); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); buttonPanel.add(submit); buttonPanel.add(cancel); buttonPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); submit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (upValue.getText().equals("")) JOptionPane.showMessageDialog(null, "Please input upper boundary", "Error", JOptionPane.ERROR_MESSAGE); else { try { upbound = Double.parseDouble(upValue.getText()); if (lowValue.getText().equals("")) JOptionPane.showMessageDialog(null, "Please input lower boundary", "Error", JOptionPane.ERROR_MESSAGE); else { try { lowbound = Double.parseDouble(lowValue.getText()); if (upbound < lowbound) JOptionPane.showMessageDialog(null, "Upper boundary should be not less than lower boundary", "Error", JOptionPane.ERROR_MESSAGE); else a.dispose(); } catch (Exception er) { JOptionPane.showMessageDialog(null, "Invalid value", "Error", JOptionPane.INFORMATION_MESSAGE); MsgManager.Messages.errorMessage(er, "Error", ""); } } } catch (Exception er) { JOptionPane.showMessageDialog(null, "Invalid value", "Error", JOptionPane.INFORMATION_MESSAGE); MsgManager.Messages.errorMessage(er, "Error", ""); } } } }); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, "The default values are used!", "", JOptionPane.INFORMATION_MESSAGE); a.dispose(); } }); JPanel wholePanel = new JPanel(); wholePanel.setLayout(new BoxLayout(wholePanel, BoxLayout.Y_AXIS)); wholePanel.add(upPanel); wholePanel.add(lowPanel); wholePanel.add(buttonPanel); wholePanel.setBorder(new EmptyBorder(5, 5, 5, 5)); a.add(wholePanel); a.setVisible(true); } }); }