List of usage examples for javax.swing JLabel setEnabled
@BeanProperty(expert = true, preferred = true, visualUpdate = true, description = "The enabled state of the component.") public void setEnabled(boolean enabled)
From source file:edu.ku.brc.af.ui.forms.validation.FormValidator.java
/** * Evaluate all the enable/disable rules and set the control and label *//*w ww . j a v a 2s .c om*/ public boolean processFormRules() { boolean formIsOK = true; boolean debug = false; if (debug) { log.debug(name + " ****** processFormRules "); Map<?, ?> map = jc.getVars(); Object[] keys = map.keySet().toArray(); for (Object key : keys) { log.debug(name + " ### [" + key + "][" + map.get(key).getClass().toString() + "]"); } } //log.debug("processFormRules ["+name+"]------------------------------------------------- Number of Rules: "+formRules.size()); for (FormValidationRuleIFace rule : formRules) { try { // Now evaluate the expression, getting the result boolean result = rule.evaluate(jc); //log.debug("Result ["+result+"] for ID["+rule.getId()+"] Rule["+((RuleExpression)rule).expression.getExpression()+"]"); if (rule.getScope() == FormValidationRuleIFace.Scope.Field) { Component comp = getComp(rule.getId()); if (comp != null) { //log.debug(" comp.setEnabled("+result+") "+comp.getClass().toString()); comp.setEnabled(result); } JLabel lbl = labels.get(rule.getId()); if (lbl != null) { lbl.setEnabled(result); } } else if (rule.getScope() == FormValidationRuleIFace.Scope.Form) { formIsOK &= result; } } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(FormValidator.class, ex); log.error(name + " " + ex.toString()); formIsOK = false; //ex.printStackTrace(); } } return formIsOK; }
From source file:org.cds06.speleograph.graph.GraphEditor.java
/** * Creates a modal dialog by specifying the attached {@link GraphPanel}. * <p>Please look at {@link javax.swing.JDialog#JDialog()} to see defaults params applied to this Dialog.</p> *///from w ww .j a v a2 s . com public GraphEditor(GraphPanel panel) { super((Frame) SwingUtilities.windowForComponent(panel), true); Validate.notNull(panel); this.graphPanel = panel; KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); mainPanel.registerKeyboardAction(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setVisible(false); } }, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW); setContentPane(mainPanel); mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); this.setTitle(I18nSupport.translate("menus.graph.graphEditor")); { // This section use FormLayout which is an external layout for Java, consult the doc before edit the // following lines ! final FormLayout layout = new FormLayout( "right:max(40dlu;p), 4dlu, p:grow, 4dlu, p, 4dlu, p:grow, 4dlu, p", //NON-NLS "p,4dlu,p,4dlu,p,4dlu,p,4dlu,p" //NON-NLS ); PanelBuilder builder = new PanelBuilder(layout); final JLabel colorLabel = new JLabel(); final JTextField titleForGraph = new JTextField( graphPanel.getChart().getTitle() != null ? graphPanel.getChart().getTitle().getText() : ""); final JLabel colorXYPlotLabel = new JLabel(); final JLabel colorGridLabel = new JLabel(); final JCheckBox showLegendCheckBox = new JCheckBox("Afficher la lgende", graphPanel.getChart().getLegend().isVisible()); { builder.addLabel("Titre :", "1,1"); builder.add(titleForGraph, "3,1,7,1"); } { builder.addLabel(I18nSupport.translate("menus.graph.graphEditor.backgroundColor"), "1,3"); colorLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); colorLabel.setText(" "); colorLabel.setBackground((Color) graphPanel.getChart().getBackgroundPaint()); colorLabel.setOpaque(true); colorLabel.setEnabled(false); final JButton edit = new JButton(I18nSupport.translate("menus.graph.graphEditor.edit")); edit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Color c = JColorChooser.showDialog(GraphEditor.this, I18nSupport.translate("menus.graph.graphEditor.selectColor"), colorLabel.getBackground()); if (c != null) { colorLabel.setBackground(c); } } }); builder.add(colorLabel, "3,3,5,1"); builder.add(edit, "9,3"); } final XYPlot xyPlot = graphPanel.getChart().getXYPlot(); { builder.addLabel(I18nSupport.translate("menus.graph.graphEditor.graphColor"), "1,5"); colorXYPlotLabel.setText(" "); colorXYPlotLabel.setOpaque(true); colorXYPlotLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); colorXYPlotLabel.setBackground((Color) xyPlot.getBackgroundPaint()); colorXYPlotLabel.setEnabled(false); final JButton edit = new JButton(I18nSupport.translate("menus.graph.graphEditor.edit")); edit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Color c = JColorChooser.showDialog(GraphEditor.this, I18nSupport.translate("menus.graph.graphEditor.selectColor"), colorXYPlotLabel.getBackground()); if (c != null) { colorXYPlotLabel.setBackground(c); } } }); builder.add(colorXYPlotLabel, "3,5,5,1"); builder.add(edit, "9,5"); } { builder.addLabel(I18nSupport.translate("menus.graph.graphEditor.gridColor"), "1,7"); colorGridLabel.setOpaque(true); colorGridLabel.setText(" "); colorGridLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); colorGridLabel.setBackground((Color) xyPlot.getRangeGridlinePaint()); colorGridLabel.setEnabled(false); final JButton edit = new JButton(I18nSupport.translate("menus.graph.graphEditor.edit")); edit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Color c = JColorChooser.showDialog(GraphEditor.this, I18nSupport.translate("menus.graph.graphEditor.selectColor"), colorGridLabel.getBackground()); if (c != null) { colorGridLabel.setBackground(c); } } }); builder.add(colorGridLabel, "3,7,5,1"); builder.add(edit, "9,7"); } { builder.add(showLegendCheckBox, "1,9,9,1"); } mainPanel.add(builder.build(), BorderLayout.CENTER); ButtonBarBuilder buttonBarBuilder = new ButtonBarBuilder(); buttonBarBuilder.addGlue(); buttonBarBuilder.addButton(new AbstractAction() { { putValue(NAME, I18nSupport.translate("cancel")); } @Override public void actionPerformed(ActionEvent e) { GraphEditor.this.setVisible(false); } }); buttonBarBuilder.addButton(new AbstractAction() { { putValue(NAME, I18nSupport.translate("ok")); } @Override public void actionPerformed(ActionEvent e) { if (titleForGraph.getText().isEmpty()) graphPanel.getChart().setTitle((String) null); else graphPanel.getChart().setTitle(titleForGraph.getText()); { Color c = colorGridLabel.getBackground(); xyPlot.setRangeGridlinePaint(c); xyPlot.setRangeMinorGridlinePaint(c); xyPlot.setDomainGridlinePaint(c); xyPlot.setDomainMinorGridlinePaint(c); } graphPanel.getChart().setBackgroundPaint(colorLabel.getBackground()); xyPlot.setBackgroundPaint(colorXYPlotLabel.getBackground()); graphPanel.getChart().getLegend().setVisible(showLegendCheckBox.isSelected()); GraphEditor.this.setVisible(false); } }); mainPanel.add(buttonBarBuilder.build(), BorderLayout.SOUTH); } pack(); Dimension d = this.getPreferredSize(); this.setSize(new Dimension(d.width + 20, d.height)); setResizable(false); }
From source file:ChiSquareCalculator.java
ChiSquareCalculator() { final JFrame jfrm = new JFrame("Chi Square Calculator"); jfrm.setSize(400, 550);/*from w w w . ja v a 2s . co m*/ jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jfrm.setResizable(false); // panel 1 JPanel pn1 = new JPanel(); pn1.setOpaque(true); pn1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "2 x 2")); JLabel jlab1 = new JLabel("class 1"); JLabel jlab2 = new JLabel("class 2"); JLabel jlab3 = new JLabel("case"); JLabel jlab4 = new JLabel("control"); jtf1 = new JTextField(); jtf2 = new JTextField(); jtf3 = new JTextField(); jtf4 = new JTextField(); // pn1 layout all GridBagLayout CalLayout1 = new GridBagLayout(); GridBagConstraints gbc1 = new GridBagConstraints(); pn1.setLayout(CalLayout1); gbc1.weightx = 1.0; //default 0.0 gbc1.weighty = 1.0; //default 0.0 gbc1.insets = new Insets(4, 4, 4, 4); // Add some space gbc1.fill = GridBagConstraints.BOTH; gbc1.gridwidth = 1; gbc1.gridx = 1; gbc1.gridy = 0; CalLayout1.setConstraints(jlab1, gbc1); gbc1.gridx = 2; gbc1.gridy = 0; CalLayout1.setConstraints(jlab2, gbc1); gbc1.gridx = 0; gbc1.gridy = 1; CalLayout1.setConstraints(jlab3, gbc1); gbc1.gridx = 1; gbc1.gridy = 1; CalLayout1.setConstraints(jtf1, gbc1); gbc1.gridx = 2; gbc1.gridy = 1; CalLayout1.setConstraints(jtf2, gbc1); gbc1.gridx = 0; gbc1.gridy = 2; CalLayout1.setConstraints(jlab4, gbc1); gbc1.gridx = 1; gbc1.gridy = 2; CalLayout1.setConstraints(jtf3, gbc1); gbc1.gridx = 2; gbc1.gridy = 2; CalLayout1.setConstraints(jtf4, gbc1); pn1.add(jlab1); pn1.add(jlab2); pn1.add(jlab3); pn1.add(jlab4); pn1.add(jtf1); pn1.add(jtf2); pn1.add(jtf3); pn1.add(jtf4); // panel 2 JPanel pn2 = new JPanel(); pn2.setOpaque(true); pn2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "2 x 3")); JLabel jlab5 = new JLabel("class 1"); JLabel jlab6 = new JLabel("class 2"); JLabel jlab7 = new JLabel("class 3"); JLabel jlab8 = new JLabel("case"); JLabel jlab9 = new JLabel("control"); jtf5 = new JTextField(); jtf6 = new JTextField(); jtf7 = new JTextField(); jtf8 = new JTextField(); jtf9 = new JTextField(); jtf10 = new JTextField(); // pn2 layout all GridBagLayout CalLayout2 = new GridBagLayout(); GridBagConstraints gbc2 = new GridBagConstraints(); pn2.setLayout(CalLayout2); gbc2.weightx = 1.0; //default 0.0 gbc2.weighty = 1.0; //default 0.0 gbc2.insets = new Insets(4, 4, 4, 4); // Add some space gbc2.fill = GridBagConstraints.BOTH; gbc2.gridwidth = 1; gbc2.gridx = 1; gbc2.gridy = 0; CalLayout2.setConstraints(jlab5, gbc2); gbc2.gridx = 2; gbc2.gridy = 0; CalLayout2.setConstraints(jlab6, gbc2); gbc2.gridx = 3; gbc2.gridy = 0; CalLayout2.setConstraints(jlab7, gbc2); gbc2.gridx = 0; gbc2.gridy = 1; CalLayout2.setConstraints(jlab8, gbc2); gbc2.gridx = 1; gbc2.gridy = 1; CalLayout2.setConstraints(jtf5, gbc2); gbc2.gridx = 2; gbc2.gridy = 1; CalLayout2.setConstraints(jtf6, gbc2); gbc2.gridx = 3; gbc2.gridy = 1; CalLayout2.setConstraints(jtf7, gbc2); gbc2.gridx = 0; gbc2.gridy = 2; CalLayout2.setConstraints(jlab9, gbc2); gbc2.gridx = 1; gbc2.gridy = 2; CalLayout2.setConstraints(jtf8, gbc2); gbc2.gridx = 2; gbc2.gridy = 2; CalLayout2.setConstraints(jtf9, gbc2); gbc2.gridx = 3; gbc2.gridy = 2; CalLayout2.setConstraints(jtf10, gbc2); pn2.add(jlab5); pn2.add(jlab6); pn2.add(jlab7); pn2.add(jlab8); pn2.add(jlab9); pn2.add(jtf5); pn2.add(jtf6); pn2.add(jtf7); pn2.add(jtf8); pn2.add(jtf9); pn2.add(jtf10); // panel 3 JPanel pn3 = new JPanel(); pn3.setOpaque(true); pn3.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "statistic")); JLabel jlab10 = new JLabel("chi-square"); JLabel jlab11 = new JLabel("degree of freedom"); jtf11 = new JTextField(); jtf12 = new JTextField(); GridBagLayout CalLayout3 = new GridBagLayout(); GridBagConstraints gbc3 = new GridBagConstraints(); pn3.setLayout(CalLayout3); gbc3.weightx = 1.0; //default 0.0 gbc3.weighty = 1.0; //default 0.0 gbc3.insets = new Insets(4, 4, 4, 4); // Add some space gbc3.fill = GridBagConstraints.BOTH; gbc3.gridwidth = 1; gbc3.gridx = 0; gbc3.gridy = 0; CalLayout3.setConstraints(jlab10, gbc3); gbc3.gridwidth = 3; gbc3.gridx = 1; gbc3.gridy = 0; CalLayout3.setConstraints(jtf11, gbc3); gbc3.gridwidth = 2; gbc3.gridx = 0; gbc3.gridy = 1; CalLayout3.setConstraints(jlab11, gbc3); gbc3.gridx = 2; gbc3.gridy = 1; CalLayout3.setConstraints(jtf12, gbc3); pn3.add(jlab10); pn3.add(jlab11); pn3.add(jtf11); pn3.add(jtf12); JPanel pn4 = new JPanel(); pn4.setOpaque(true); pn4.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "result")); JLabel jlab12 = new JLabel("p-value"); final JLabel jlab13 = new JLabel("odds ratio"); final JLabel jlab14 = new JLabel("standard error"); final JLabel jlab15 = new JLabel("confidence interval 95%"); jtf13 = new JTextField(); jtf14 = new JTextField(); jtf15 = new JTextField(); jtf16 = new JTextField(); jtf17 = new JTextField(); jlab13.setEnabled(false); jlab14.setEnabled(false); jlab15.setEnabled(false); jtf14.setEnabled(false); jtf15.setEnabled(false); jtf16.setEnabled(false); jtf17.setEnabled(false); JButton jbtn1 = new JButton("Run 2x2"); jbtn1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { long number1, number2, number3, number4; try { number1 = Long.parseLong(jtf1.getText()); number2 = Long.parseLong(jtf2.getText()); number3 = Long.parseLong(jtf3.getText()); number4 = Long.parseLong(jtf4.getText()); } catch (Exception ne) { JOptionPane.showMessageDialog(jfrm, "Error: Bad input, only integer is acceptable!"); return; } long[][] obs = new long[2][2]; obs[0][0] = number1; obs[0][1] = number2; obs[1][0] = number3; obs[1][1] = number4; ChiSquareTest mychiSquare = new ChiSquareTest(); double stats = mychiSquare.chiSquare(obs); jtf11.setText(String.valueOf(stats)); jtf12.setText(String.valueOf(1)); double pvalue = mychiSquare.chiSquareTest(obs); jtf13.setText(String.valueOf(pvalue)); jtf5.setText(""); jtf6.setText(""); jtf7.setText(""); jtf8.setText(""); jtf9.setText(""); jtf10.setText(""); jlab13.setEnabled(true); jlab14.setEnabled(true); jlab15.setEnabled(true); jtf14.setEnabled(true); jtf15.setEnabled(true); jtf16.setEnabled(true); jtf17.setEnabled(true); double or = (double) (number2 * number3) / (number1 * number4); double se = Math.sqrt( (double) 1 / number1 + (double) 1 / number2 + (double) 1 / number3 + (double) 1 / number4); double logOR = Math.log(or); double logU95 = logOR + 1.96 * se; double logL95 = logOR - 1.96 * se; double U95 = Math.exp(logU95); double L95 = Math.exp(logL95); final java.text.DecimalFormat mydf = new java.text.DecimalFormat("0.000000"); jtf14.setText(String.valueOf(or)); jtf15.setText(String.valueOf(se)); jtf16.setText(String.valueOf(mydf.format(L95))); jtf17.setText(String.valueOf(mydf.format(U95))); } }); JButton jbtn2 = new JButton("Run 2x3"); jbtn2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { long number1, number2, number3, number4, number5, number6; try { number1 = Long.parseLong(jtf5.getText()); number2 = Long.parseLong(jtf6.getText()); number3 = Long.parseLong(jtf7.getText()); number4 = Long.parseLong(jtf8.getText()); number5 = Long.parseLong(jtf9.getText()); number6 = Long.parseLong(jtf10.getText()); } catch (Exception ne) { JOptionPane.showMessageDialog(jfrm, "Error: Bad input, only integer is acceptable!"); return; } long[][] obs = new long[2][3]; obs[0][0] = number1; obs[0][1] = number2; obs[0][2] = number3; obs[1][0] = number4; obs[1][1] = number5; obs[1][2] = number6; ChiSquareTest mychiSquare = new ChiSquareTest(); double stats = mychiSquare.chiSquare(obs); jtf11.setText(String.valueOf(stats)); jtf12.setText(String.valueOf(2)); double pvalue = mychiSquare.chiSquareTest(obs); jtf13.setText(String.valueOf(pvalue)); jtf1.setText(""); jtf2.setText(""); jtf3.setText(""); jtf4.setText(""); jtf14.setText(""); jtf15.setText(""); jtf16.setText(""); jtf17.setText(""); jlab13.setEnabled(false); jlab14.setEnabled(false); jlab15.setEnabled(false); jtf14.setEnabled(false); jtf15.setEnabled(false); jtf16.setEnabled(false); jtf17.setEnabled(false); } }); JButton jbtn3 = new JButton("Run Statistic"); jbtn3.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { double stat, df; try { stat = Double.parseDouble(jtf11.getText()); df = Double.parseDouble(jtf12.getText()); } catch (Exception ne) { JOptionPane.showMessageDialog(jfrm, "Error: Bad input, only number is acceptable!"); return; } ChiSquaredDistribution distribution = new ChiSquaredDistribution(df); double pvalue = 1 - distribution.cumulativeProbability(stat); jtf13.setText(String.valueOf(pvalue)); jtf1.setText(""); jtf2.setText(""); jtf3.setText(""); jtf4.setText(""); jtf5.setText(""); jtf6.setText(""); jtf7.setText(""); jtf8.setText(""); jtf9.setText(""); jtf10.setText(""); jtf14.setText(""); jtf15.setText(""); jtf16.setText(""); jtf17.setText(""); jlab13.setEnabled(false); jlab14.setEnabled(false); jlab15.setEnabled(false); jtf14.setEnabled(false); jtf15.setEnabled(false); jtf16.setEnabled(false); jtf17.setEnabled(false); } }); JButton jbtn4 = new JButton("clear"); jbtn4.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { jtf1.setText(""); jtf2.setText(""); jtf3.setText(""); jtf4.setText(""); jtf5.setText(""); jtf6.setText(""); jtf7.setText(""); jtf8.setText(""); jtf9.setText(""); jtf10.setText(""); jtf11.setText(""); jtf12.setText(""); jtf13.setText(""); jtf14.setText(""); jtf15.setText(""); jtf16.setText(""); jtf17.setText(""); jlab13.setEnabled(false); jlab14.setEnabled(false); jlab15.setEnabled(false); jtf14.setEnabled(false); jtf15.setEnabled(false); jtf16.setEnabled(false); jtf17.setEnabled(false); } }); GridBagLayout CalLayout4 = new GridBagLayout(); GridBagConstraints gbc4 = new GridBagConstraints(); pn4.setLayout(CalLayout4); gbc4.weightx = 1.0; //default 0.0 gbc4.weighty = 1.0; //default 0.0 gbc4.insets = new Insets(4, 4, 4, 4); // Add some space gbc4.fill = GridBagConstraints.BOTH; gbc4.gridwidth = 1; gbc4.gridx = 0; gbc4.gridy = 0; CalLayout4.setConstraints(jbtn1, gbc4); gbc4.gridx = 1; gbc4.gridy = 0; CalLayout4.setConstraints(jbtn2, gbc4); gbc4.gridx = 2; gbc4.gridy = 0; CalLayout4.setConstraints(jbtn3, gbc4); gbc4.gridx = 3; gbc4.gridy = 0; CalLayout4.setConstraints(jbtn4, gbc4); gbc4.gridx = 0; gbc4.gridy = 1; CalLayout4.setConstraints(jlab12, gbc4); gbc4.gridwidth = 3; gbc4.gridx = 1; gbc4.gridy = 1; CalLayout4.setConstraints(jtf13, gbc4); gbc4.gridwidth = 2; gbc4.gridx = 0; gbc4.gridy = 2; CalLayout4.setConstraints(jlab13, gbc4); gbc4.gridx = 2; gbc4.gridy = 2; CalLayout4.setConstraints(jtf14, gbc4); gbc4.gridx = 0; gbc4.gridy = 3; CalLayout4.setConstraints(jlab14, gbc4); gbc4.gridx = 2; gbc4.gridy = 3; CalLayout4.setConstraints(jtf15, gbc4); gbc4.gridx = 0; gbc4.gridy = 4; CalLayout4.setConstraints(jlab15, gbc4); gbc4.gridwidth = 1; gbc4.gridx = 2; gbc4.gridy = 4; CalLayout4.setConstraints(jtf16, gbc4); gbc4.gridx = 3; gbc4.gridy = 4; CalLayout4.setConstraints(jtf17, gbc4); pn4.add(jlab12); pn4.add(jlab13); pn4.add(jlab14); pn4.add(jlab15); pn4.add(jtf13); pn4.add(jtf14); pn4.add(jtf15); pn4.add(jtf16); pn4.add(jtf17); pn4.add(jbtn1); pn4.add(jbtn2); pn4.add(jbtn3); pn4.add(jbtn4); // jfrm layout all GridBagLayout CalLayout = new GridBagLayout(); GridBagConstraints gbc = new GridBagConstraints(); jfrm.setLayout(CalLayout); gbc.weightx = 1.0; //default 0.0 gbc.weighty = 1.0; //default 0.0 gbc.insets = new Insets(4, 4, 4, 4); // Add some space gbc.fill = GridBagConstraints.BOTH; gbc.gridwidth = 4; gbc.gridx = 0; gbc.gridy = 0; CalLayout.setConstraints(pn1, gbc); gbc.gridx = 0; gbc.gridy = 1; CalLayout.setConstraints(pn2, gbc); gbc.gridx = 0; gbc.gridy = 2; CalLayout.setConstraints(pn3, gbc); gbc.gridx = 0; gbc.gridy = 3; CalLayout.setConstraints(pn4, gbc); jfrm.add(pn1); jfrm.add(pn2); jfrm.add(pn3); jfrm.add(pn4); // Help Menu Bar JMenuBar jmb = new JMenuBar(); JMenu jmh = new JMenu("Help"); JMenuItem jmiAbout = new JMenuItem("About"); jmiAbout.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { JOptionPane.showMessageDialog(jfrm, "Name: Chi Square Calculator\n" + "Version: 1.0\n" + "Author: Felix Yanhui Fan\n" + "EMail: nolanfyh@gmail.com\n" + "Website: http://felixfan.github.io/ChiSquareCalculator\n"); } }); JMenuItem jmiLisence = new JMenuItem("Lisence"); jmiLisence.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(jfrm, "This program is licensed under the terms of \n" + "the GNU General Public License version 3 \n" + "Available online under: \n" + "http://www.gnu.org/licenses/gpl-3.0.html\n"); } }); jmh.add(jmiAbout); jmh.add(jmiLisence); jmb.add(Box.createHorizontalGlue()); // Aligning JMenu on the right corner of JMenuBar jmb.add(jmh); jfrm.setJMenuBar(jmb); jfrm.setVisible(true); }
From source file:chisquarecalculator.ChisqCal.java
public ChisqCal() { final JFrame jfrm = new JFrame("Chi Square Calculator"); jfrm.setSize(400, 550);//from w w w . ja va 2s . c o m jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jfrm.setResizable(false); // panel 1 JPanel pn1 = new JPanel(); pn1.setOpaque(true); pn1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "2 x 2")); JLabel jlab1 = new JLabel("class 1"); JLabel jlab2 = new JLabel("class 2"); JLabel jlab3 = new JLabel("case"); JLabel jlab4 = new JLabel("control"); jtf1 = new JTextField(); jtf2 = new JTextField(); jtf3 = new JTextField(); jtf4 = new JTextField(); // pn1 layout all GridBagLayout CalLayout1 = new GridBagLayout(); GridBagConstraints gbc1 = new GridBagConstraints(); pn1.setLayout(CalLayout1); gbc1.weightx = 1.0; //default 0.0 gbc1.weighty = 1.0; //default 0.0 gbc1.insets = new Insets(4, 4, 4, 4); // Add some space gbc1.fill = GridBagConstraints.BOTH; gbc1.gridwidth = 1; gbc1.gridx = 1; gbc1.gridy = 0; CalLayout1.setConstraints(jlab1, gbc1); gbc1.gridx = 2; gbc1.gridy = 0; CalLayout1.setConstraints(jlab2, gbc1); gbc1.gridx = 0; gbc1.gridy = 1; CalLayout1.setConstraints(jlab3, gbc1); gbc1.gridx = 1; gbc1.gridy = 1; CalLayout1.setConstraints(jtf1, gbc1); gbc1.gridx = 2; gbc1.gridy = 1; CalLayout1.setConstraints(jtf2, gbc1); gbc1.gridx = 0; gbc1.gridy = 2; CalLayout1.setConstraints(jlab4, gbc1); gbc1.gridx = 1; gbc1.gridy = 2; CalLayout1.setConstraints(jtf3, gbc1); gbc1.gridx = 2; gbc1.gridy = 2; CalLayout1.setConstraints(jtf4, gbc1); pn1.add(jlab1); pn1.add(jlab2); pn1.add(jlab3); pn1.add(jlab4); pn1.add(jtf1); pn1.add(jtf2); pn1.add(jtf3); pn1.add(jtf4); // panel 2 JPanel pn2 = new JPanel(); pn2.setOpaque(true); pn2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "2 x 3")); JLabel jlab5 = new JLabel("class 1"); JLabel jlab6 = new JLabel("class 2"); JLabel jlab7 = new JLabel("class 3"); JLabel jlab8 = new JLabel("case"); JLabel jlab9 = new JLabel("control"); jtf5 = new JTextField(); jtf6 = new JTextField(); jtf7 = new JTextField(); jtf8 = new JTextField(); jtf9 = new JTextField(); jtf10 = new JTextField(); // pn2 layout all GridBagLayout CalLayout2 = new GridBagLayout(); GridBagConstraints gbc2 = new GridBagConstraints(); pn2.setLayout(CalLayout2); gbc2.weightx = 1.0; //default 0.0 gbc2.weighty = 1.0; //default 0.0 gbc2.insets = new Insets(4, 4, 4, 4); // Add some space gbc2.fill = GridBagConstraints.BOTH; gbc2.gridwidth = 1; gbc2.gridx = 1; gbc2.gridy = 0; CalLayout2.setConstraints(jlab5, gbc2); gbc2.gridx = 2; gbc2.gridy = 0; CalLayout2.setConstraints(jlab6, gbc2); gbc2.gridx = 3; gbc2.gridy = 0; CalLayout2.setConstraints(jlab7, gbc2); gbc2.gridx = 0; gbc2.gridy = 1; CalLayout2.setConstraints(jlab8, gbc2); gbc2.gridx = 1; gbc2.gridy = 1; CalLayout2.setConstraints(jtf5, gbc2); gbc2.gridx = 2; gbc2.gridy = 1; CalLayout2.setConstraints(jtf6, gbc2); gbc2.gridx = 3; gbc2.gridy = 1; CalLayout2.setConstraints(jtf7, gbc2); gbc2.gridx = 0; gbc2.gridy = 2; CalLayout2.setConstraints(jlab9, gbc2); gbc2.gridx = 1; gbc2.gridy = 2; CalLayout2.setConstraints(jtf8, gbc2); gbc2.gridx = 2; gbc2.gridy = 2; CalLayout2.setConstraints(jtf9, gbc2); gbc2.gridx = 3; gbc2.gridy = 2; CalLayout2.setConstraints(jtf10, gbc2); pn2.add(jlab5); pn2.add(jlab6); pn2.add(jlab7); pn2.add(jlab8); pn2.add(jlab9); pn2.add(jtf5); pn2.add(jtf6); pn2.add(jtf7); pn2.add(jtf8); pn2.add(jtf9); pn2.add(jtf10); // panel 3 JPanel pn3 = new JPanel(); pn3.setOpaque(true); pn3.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "statistic")); JLabel jlab10 = new JLabel("chi-square"); JLabel jlab11 = new JLabel("degree of freedom"); jtf11 = new JTextField(); jtf12 = new JTextField(); GridBagLayout CalLayout3 = new GridBagLayout(); GridBagConstraints gbc3 = new GridBagConstraints(); pn3.setLayout(CalLayout3); gbc3.weightx = 1.0; //default 0.0 gbc3.weighty = 1.0; //default 0.0 gbc3.insets = new Insets(4, 4, 4, 4); // Add some space gbc3.fill = GridBagConstraints.BOTH; gbc3.gridwidth = 1; gbc3.gridx = 0; gbc3.gridy = 0; CalLayout3.setConstraints(jlab10, gbc3); gbc3.gridwidth = 3; gbc3.gridx = 1; gbc3.gridy = 0; CalLayout3.setConstraints(jtf11, gbc3); gbc3.gridwidth = 2; gbc3.gridx = 0; gbc3.gridy = 1; CalLayout3.setConstraints(jlab11, gbc3); gbc3.gridx = 2; gbc3.gridy = 1; CalLayout3.setConstraints(jtf12, gbc3); pn3.add(jlab10); pn3.add(jlab11); pn3.add(jtf11); pn3.add(jtf12); JPanel pn4 = new JPanel(); pn4.setOpaque(true); pn4.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "result")); JLabel jlab12 = new JLabel("p-value"); final JLabel jlab13 = new JLabel("odds ratio"); final JLabel jlab14 = new JLabel("standard error"); final JLabel jlab15 = new JLabel("confidence interval 95%"); jtf13 = new JTextField(); jtf14 = new JTextField(); jtf15 = new JTextField(); jtf16 = new JTextField(); jtf17 = new JTextField(); jlab13.setEnabled(false); jlab14.setEnabled(false); jlab15.setEnabled(false); jtf14.setEnabled(false); jtf15.setEnabled(false); jtf16.setEnabled(false); jtf17.setEnabled(false); JButton jbtn1 = new JButton("Run 2x2"); jbtn1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { long number1, number2, number3, number4; try { number1 = Long.parseLong(jtf1.getText()); number2 = Long.parseLong(jtf2.getText()); number3 = Long.parseLong(jtf3.getText()); number4 = Long.parseLong(jtf4.getText()); } catch (Exception ne) { JOptionPane.showMessageDialog(jfrm, "Error: Bad input, only integer is acceptable!"); return; } long[][] obs = new long[2][2]; obs[0][0] = number1; obs[0][1] = number2; obs[1][0] = number3; obs[1][1] = number4; ChiSquareTest mychiSquare = new ChiSquareTest(); final java.text.DecimalFormat mydf = new java.text.DecimalFormat("0.0000"); double stats = mychiSquare.chiSquare(obs); jtf11.setText(String.valueOf(mydf.format(stats))); jtf12.setText(String.valueOf(1)); double pvalue = mychiSquare.chiSquareTest(obs); jtf13.setText(String.valueOf(pvalue)); jtf5.setText(""); jtf6.setText(""); jtf7.setText(""); jtf8.setText(""); jtf9.setText(""); jtf10.setText(""); jlab13.setEnabled(true); jlab14.setEnabled(true); jlab15.setEnabled(true); jtf14.setEnabled(true); jtf15.setEnabled(true); jtf16.setEnabled(true); jtf17.setEnabled(true); double or = (double) (number2 * number3) / (number1 * number4); double se = Math.sqrt( (double) 1 / number1 + (double) 1 / number2 + (double) 1 / number3 + (double) 1 / number4); double logOR = Math.log(or); double logU95 = logOR + 1.96 * se; double logL95 = logOR - 1.96 * se; double U95 = Math.exp(logU95); double L95 = Math.exp(logL95); jtf14.setText(String.valueOf(mydf.format(or))); jtf15.setText(String.valueOf(mydf.format(se))); jtf16.setText(String.valueOf(mydf.format(L95))); jtf17.setText(String.valueOf(mydf.format(U95))); } }); JButton jbtn2 = new JButton("Run 2x3"); jbtn2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { long number1, number2, number3, number4, number5, number6; try { number1 = Long.parseLong(jtf5.getText()); number2 = Long.parseLong(jtf6.getText()); number3 = Long.parseLong(jtf7.getText()); number4 = Long.parseLong(jtf8.getText()); number5 = Long.parseLong(jtf9.getText()); number6 = Long.parseLong(jtf10.getText()); } catch (Exception ne) { JOptionPane.showMessageDialog(jfrm, "Error: Bad input, only integer is acceptable!"); return; } long[][] obs = new long[2][3]; obs[0][0] = number1; obs[0][1] = number2; obs[0][2] = number3; obs[1][0] = number4; obs[1][1] = number5; obs[1][2] = number6; ChiSquareTest mychiSquare = new ChiSquareTest(); final java.text.DecimalFormat mydf = new java.text.DecimalFormat("0.0000"); double stats = mychiSquare.chiSquare(obs); jtf11.setText(String.valueOf(mydf.format(stats))); jtf12.setText(String.valueOf(2)); double pvalue = mychiSquare.chiSquareTest(obs); jtf13.setText(String.valueOf(pvalue)); jtf1.setText(""); jtf2.setText(""); jtf3.setText(""); jtf4.setText(""); jtf14.setText(""); jtf15.setText(""); jtf16.setText(""); jtf17.setText(""); jlab13.setEnabled(false); jlab14.setEnabled(false); jlab15.setEnabled(false); jtf14.setEnabled(false); jtf15.setEnabled(false); jtf16.setEnabled(false); jtf17.setEnabled(false); } }); JButton jbtn3 = new JButton("Run Statistic"); jbtn3.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { double stat, df; try { stat = Double.parseDouble(jtf11.getText()); df = Double.parseDouble(jtf12.getText()); } catch (Exception ne) { JOptionPane.showMessageDialog(jfrm, "Error: Bad input, only number is acceptable!"); return; } ChiSquaredDistribution distribution = new ChiSquaredDistribution(df); double pvalue = 1 - distribution.cumulativeProbability(stat); jtf13.setText(String.valueOf(pvalue)); jtf1.setText(""); jtf2.setText(""); jtf3.setText(""); jtf4.setText(""); jtf5.setText(""); jtf6.setText(""); jtf7.setText(""); jtf8.setText(""); jtf9.setText(""); jtf10.setText(""); jtf14.setText(""); jtf15.setText(""); jtf16.setText(""); jtf17.setText(""); jlab13.setEnabled(false); jlab14.setEnabled(false); jlab15.setEnabled(false); jtf14.setEnabled(false); jtf15.setEnabled(false); jtf16.setEnabled(false); jtf17.setEnabled(false); } }); JButton jbtn4 = new JButton("clear"); jbtn4.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { jtf1.setText(""); jtf2.setText(""); jtf3.setText(""); jtf4.setText(""); jtf5.setText(""); jtf6.setText(""); jtf7.setText(""); jtf8.setText(""); jtf9.setText(""); jtf10.setText(""); jtf11.setText(""); jtf12.setText(""); jtf13.setText(""); jtf14.setText(""); jtf15.setText(""); jtf16.setText(""); jtf17.setText(""); jlab13.setEnabled(false); jlab14.setEnabled(false); jlab15.setEnabled(false); jtf14.setEnabled(false); jtf15.setEnabled(false); jtf16.setEnabled(false); jtf17.setEnabled(false); } }); GridBagLayout CalLayout4 = new GridBagLayout(); GridBagConstraints gbc4 = new GridBagConstraints(); pn4.setLayout(CalLayout4); gbc4.weightx = 1.0; //default 0.0 gbc4.weighty = 1.0; //default 0.0 // gbc4.insets = new Insets(4, 4, 4, 4); // Add some space gbc4.insets = new Insets(1, 1, 1, 1); gbc4.fill = GridBagConstraints.BOTH; gbc4.gridwidth = 1; gbc4.gridx = 0; gbc4.gridy = 0; CalLayout4.setConstraints(jbtn1, gbc4); gbc4.gridx = 1; gbc4.gridy = 0; CalLayout4.setConstraints(jbtn2, gbc4); gbc4.gridx = 2; gbc4.gridy = 0; CalLayout4.setConstraints(jbtn3, gbc4); gbc4.gridx = 3; gbc4.gridy = 0; CalLayout4.setConstraints(jbtn4, gbc4); gbc4.gridx = 0; gbc4.gridy = 1; CalLayout4.setConstraints(jlab12, gbc4); gbc4.gridwidth = 3; gbc4.gridx = 1; gbc4.gridy = 1; CalLayout4.setConstraints(jtf13, gbc4); gbc4.gridwidth = 2; gbc4.gridx = 0; gbc4.gridy = 2; CalLayout4.setConstraints(jlab13, gbc4); gbc4.gridx = 2; gbc4.gridy = 2; CalLayout4.setConstraints(jtf14, gbc4); gbc4.gridx = 0; gbc4.gridy = 3; CalLayout4.setConstraints(jlab14, gbc4); gbc4.gridx = 2; gbc4.gridy = 3; CalLayout4.setConstraints(jtf15, gbc4); gbc4.gridx = 0; gbc4.gridy = 4; CalLayout4.setConstraints(jlab15, gbc4); gbc4.gridwidth = 1; gbc4.gridx = 2; gbc4.gridy = 4; CalLayout4.setConstraints(jtf16, gbc4); gbc4.gridx = 3; gbc4.gridy = 4; CalLayout4.setConstraints(jtf17, gbc4); pn4.add(jlab12); pn4.add(jlab13); pn4.add(jlab14); pn4.add(jlab15); pn4.add(jtf13); pn4.add(jtf14); pn4.add(jtf15); pn4.add(jtf16); pn4.add(jtf17); pn4.add(jbtn1); pn4.add(jbtn2); pn4.add(jbtn3); pn4.add(jbtn4); // jfrm layout all GridBagLayout CalLayout = new GridBagLayout(); GridBagConstraints gbc = new GridBagConstraints(); jfrm.setLayout(CalLayout); gbc.weightx = 1.0; //default 0.0 gbc.weighty = 1.0; //default 0.0 gbc.insets = new Insets(4, 4, 4, 4); // Add some space gbc.fill = GridBagConstraints.BOTH; gbc.gridwidth = 4; gbc.gridx = 0; gbc.gridy = 0; CalLayout.setConstraints(pn1, gbc); gbc.gridx = 0; gbc.gridy = 1; CalLayout.setConstraints(pn2, gbc); gbc.gridx = 0; gbc.gridy = 2; CalLayout.setConstraints(pn3, gbc); gbc.gridx = 0; gbc.gridy = 3; CalLayout.setConstraints(pn4, gbc); jfrm.add(pn1); jfrm.add(pn2); jfrm.add(pn3); jfrm.add(pn4); // Help Menu Bar JMenuBar jmb = new JMenuBar(); JMenu jmh = new JMenu("Help"); JMenuItem jmiAbout = new JMenuItem("About"); jmiAbout.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { JOptionPane.showMessageDialog(jfrm, "Name: Chi Square Calculator\n" + "Version: 1.0\n" + "Author: Felix Yanhui Fan\n" + "EMail: felixfanyh@gmail.com\n" + "Website: http://felixfan.github.io/ChiSquareCalculator\n"); } }); JMenuItem jmiLisence = new JMenuItem("Lisence"); jmiLisence.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(jfrm, "This program is licensed under the terms of \n" + "the GNU General Public License version 3 \n" + "Available online under: \n" + "http://www.gnu.org/licenses/gpl-3.0.html\n"); } }); jmh.add(jmiAbout); jmh.add(jmiLisence); jmb.add(Box.createHorizontalGlue()); // Aligning JMenu on the right corner of JMenuBar jmb.add(jmh); jfrm.setJMenuBar(jmb); jfrm.setVisible(true); }
From source file:edu.ku.brc.specify.datamodel.busrules.BaseTreeBusRules.java
@SuppressWarnings("unchecked") protected void parentChanged(final FormViewObj form, final ValComboBoxFromQuery parentComboBox, final ValComboBox rankComboBox, final JCheckBox acceptedCheckBox, final ValComboBoxFromQuery acceptedParentWidget) { if (form.getAltView().getMode() != CreationMode.EDIT) { return;/*from w ww. ja va 2 s . com*/ } //log.debug("form was validated: calling adjustRankComboBoxModel()"); Object objInForm = form.getDataObj(); //log.debug("form data object = " + objInForm); if (objInForm == null) { return; } final T formNode = (T) objInForm; // set the contents of this combobox based on the value chosen as the parent adjustRankComboBoxModel(parentComboBox, rankComboBox, formNode); T parent = null; if (parentComboBox.getValue() instanceof String) { // the data is still in the VIEW mode for some reason log.debug("Form is in mode (" + form.getAltView().getMode() + ") but the parent data is a String"); parentComboBox.getValue(); parent = formNode.getParent(); } else { parent = (T) parentComboBox.getValue(); } // set the tree def for the object being edited by using the parent node's tree def // set the parent too??? (lookups for the AcceptedParent QueryComboBox need this) if (parent != null) { formNode.setDefinition(parent.getDefinition()); formNode.setParent(parent); } SwingUtilities.invokeLater(new Runnable() { public void run() { boolean rnkEnabled = rankComboBox.getComboBox().getModel().getSize() > 0; rankComboBox.setEnabled(rnkEnabled); JLabel label = form.getLabelFor(rankComboBox); if (label != null) { label.setEnabled(rnkEnabled); } if (rankComboBox.hasFocus() && !rnkEnabled) { parentComboBox.requestFocus(); } rankChanged(formViewObj, parentComboBox, rankComboBox, acceptedCheckBox, acceptedParentWidget); form.getValidator().validateForm(); } }); }
From source file:edu.ku.brc.af.ui.db.DatabaseLoginPanel.java
/** * Helper to enable all the UI components. * @param enable true or false//from w w w. ja va2 s . c o m */ protected void enableUI(final boolean enable) { cancelBtn.setEnabled(enable); loginBtn.setEnabled(enable); helpBtn.setEnabled(enable); username.setEnabled(enable); password.setEnabled(enable); databases.setEnabled(enable); servers.setEnabled(enable); rememberUsernameCBX.setEnabled(enable); dbDriverCBX.setEnabled(enable); moreBtn.setEnabled(enable); if (portSpinner != null) { portSpinner.setEnabled(enable); } if (editKeyInfoBtn != null) { editKeyInfoBtn.setEnabled(enable); } for (JLabel lbl : labels) { lbl.setEnabled(enable); } }
From source file:lejos.pc.charting.LogChartFrame.java
private void manageAxisLabel(int AxisIndex) { JLabel tempLabel; JTextField tempTextField;//from w w w . j a v a 2s . c o m switch (AxisIndex) { case 0: tempLabel = jLabel2; tempTextField = axis1LabelTextField; break; case 1: tempLabel = jLabel3; tempTextField = axis2LabelTextField; break; case 2: tempLabel = jLabel4; tempTextField = axis3LabelTextField; break; case 3: tempLabel = jLabel6; tempTextField = axis4LabelTextField; break; default: return; } boolean axisExists = loggingJFreeChart.getXYPlot().getRangeAxis(AxisIndex) != null; tempTextField.setEnabled(axisExists); tempLabel.setEnabled(axisExists); if (!axisExists) return; String chartAxisLabel = loggingJFreeChart.getXYPlot().getRangeAxis(AxisIndex).getLabel(); String customLabel = tempTextField.getText(); if (customLabel.equals("")) { tempTextField.setText(chartAxisLabel); } else { loggingJFreeChart.getXYPlot().getRangeAxis(AxisIndex).setLabel(customLabel); } }
From source file:ffx.ui.ModelingPanel.java
/** * This handles conditional command option input. * * @param evt ActionEvent//from w w w.j ava 2 s.c o m */ private void conditionalCommandEvent(ActionEvent evt) { Object source = evt.getSource(); if (source instanceof JRadioButton) { JRadioButton jrb = (JRadioButton) source; String selection = jrb.getText().toLowerCase(); for (JLabel label : conditionals) { JTextField jtf = (JTextField) label.getLabelFor(); String cupon = label.getName().toLowerCase(); if (cupon.contains(selection) && jrb.isSelected()) { label.setEnabled(true); jtf.setEnabled(true); } else { label.setEnabled(false); jtf.setEnabled(false); } } } else if (source instanceof JCheckBox) { JCheckBox jcb = (JCheckBox) source; String selection = jcb.getText().toLowerCase(); for (JLabel label : conditionals) { String cupon = label.getName().toLowerCase(); JTextField jtf = (JTextField) label.getLabelFor(); if (cupon.contains(selection) && jcb.isSelected()) { label.setEnabled(true); jtf.setEnabled(true); } else { label.setEnabled(false); jtf.setEnabled(false); } } } statusLabel.setText(" " + createCommandInput()); }
From source file:org.esa.snap.rcp.statistics.StatisticsPanel.java
private JPanel createAccuracyPanel() { final JPanel accuracyPanel = new JPanel(new GridBagLayout()); final GridBagConstraints gbc = new GridBagConstraints(); final JLabel label = new JLabel("Histogram accuracy:"); accuracyModel = new AccuracyModel(); final BindingContext bindingContext = new BindingContext( PropertyContainer.createObjectBacked(accuracyModel)); final SpinnerNumberModel accuracyNumberModel = new SpinnerNumberModel(accuracyModel.accuracy, 0, Util.MAX_ACCURACY, 1); final JSpinner accuracySpinner = new JSpinner(accuracyNumberModel); ((JSpinner.DefaultEditor) accuracySpinner.getEditor()).getTextField().setEditable(false); bindingContext.bind("accuracy", accuracySpinner); final JCheckBox checkBox = new JCheckBox("Auto accuracy"); bindingContext.bind("useAutoAccuracy", checkBox); final IntervalValidator rangeValidator = new IntervalValidator(new ValueRange(0, Util.MAX_ACCURACY)); final PropertyDescriptor accuracyDescriptor = bindingContext.getPropertySet().getDescriptor("accuracy"); accuracyDescriptor.setValidator(rangeValidator); checkBox.setSelected(accuracyModel.useAutoAccuracy); bindingContext.getPropertySet().getProperty("useAutoAccuracy") .addPropertyChangeListener(new PropertyChangeListener() { @Override/*from ww w . j a v a 2 s . co m*/ public void propertyChange(PropertyChangeEvent evt) { label.setEnabled(!checkBox.isSelected()); accuracySpinner.setEnabled(!checkBox.isSelected()); if (checkBox.isSelected()) { bindingContext.getBinding("accuracy").setPropertyValue(3); } computePanel.updateEnablement(); } }); label.setEnabled(false); accuracySpinner.setEnabled(false); accuracySpinner.setToolTipText("Specify the number of histogram bins (#bins: 10^accuracy)."); accuracySpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { computePanel.updateEnablement(); } }); GridBagUtils.addToPanel(accuracyPanel, new TitledSeparator("Histogram accuracy"), gbc, "fill=HORIZONTAL, weightx=1.0,anchor=NORTH,gridwidth=2"); GridBagUtils.addToPanel(accuracyPanel, checkBox, gbc, "gridy=1,insets.left=5,insets.top=2"); GridBagUtils.addToPanel(accuracyPanel, label, gbc, "gridy=2, insets.left=26,weightx=0.0,fill=NONE,anchor=WEST,gridwidth=1"); GridBagUtils.addToPanel(accuracyPanel, accuracySpinner, gbc, "gridx=1,weightx=1.0,fill=HORIZONTAL,insets.right=5,insets.left=5"); return accuracyPanel; }
From source file:ffx.ui.ModelingPanel.java
private void loadCommand() { synchronized (this) { // Force Field X Command Element command;//from www. j ava 2s . c o m // Command Options NodeList options; Element option; // Option Values NodeList values; Element value; // Options may be Conditional based on previous Option values (not // always supplied) NodeList conditionalList; Element conditional; // JobPanel GUI Components that change based on command JPanel optionPanel; // Clear the previous components commandPanel.removeAll(); optionsTabbedPane.removeAll(); conditionals.clear(); String currentCommand = (String) currentCommandBox.getSelectedItem(); if (currentCommand == null) { commandPanel.validate(); commandPanel.repaint(); return; } command = null; for (int i = 0; i < commandList.getLength(); i++) { command = (Element) commandList.item(i); String name = command.getAttribute("name"); if (name.equalsIgnoreCase(currentCommand)) { break; } } int div = splitPane.getDividerLocation(); descriptTextArea.setText(currentCommand.toUpperCase() + ": " + command.getAttribute("description")); splitPane.setBottomComponent(descriptScrollPane); splitPane.setDividerLocation(div); // The "action" tells Force Field X what to do when the // command finishes commandActions = command.getAttribute("action").trim(); // The "fileType" specifies what file types this command can execute // on String string = command.getAttribute("fileType").trim(); String[] types = string.split(" +"); commandFileTypes.clear(); for (String type : types) { if (type.contains("XYZ")) { commandFileTypes.add(FileType.XYZ); } if (type.contains("INT")) { commandFileTypes.add(FileType.INT); } if (type.contains("ARC")) { commandFileTypes.add(FileType.ARC); } if (type.contains("PDB")) { commandFileTypes.add(FileType.PDB); } if (type.contains("ANY")) { commandFileTypes.add(FileType.ANY); } } // Determine what options are available for this command options = command.getElementsByTagName("Option"); int length = options.getLength(); for (int i = 0; i < length; i++) { // This Option will be enabled (isEnabled = true) unless a // Conditional disables it boolean isEnabled = true; option = (Element) options.item(i); conditionalList = option.getElementsByTagName("Conditional"); /* * Currently, there can only be 0 or 1 Conditionals per Option * There are three types of Conditionals implemented. 1.) * Conditional on a previous Option, this option may be * available 2.) Conditional on input for this option, a * sub-option may be available 3.) Conditional on the presence * of keywords, this option may be available */ if (conditionalList != null) { conditional = (Element) conditionalList.item(0); } else { conditional = null; } // Get the command line flag String flag = option.getAttribute("flag").trim(); // Get the description String optionDescript = option.getAttribute("description"); JTextArea optionTextArea = new JTextArea(" " + optionDescript.trim()); optionTextArea.setEditable(false); optionTextArea.setLineWrap(true); optionTextArea.setWrapStyleWord(true); optionTextArea.setBorder(etchedBorder); // Get the default for this Option (if one exists) String defaultOption = option.getAttribute("default"); // Option Panel optionPanel = new JPanel(new BorderLayout()); optionPanel.add(optionTextArea, BorderLayout.NORTH); String swing = option.getAttribute("gui"); JPanel optionValuesPanel = new JPanel(new FlowLayout()); optionValuesPanel.setBorder(etchedBorder); ButtonGroup bg = null; if (swing.equalsIgnoreCase("CHECKBOXES")) { // CHECKBOXES allows selection of 1 or more values from a // predefined set (Analyze, for example) values = option.getElementsByTagName("Value"); for (int j = 0; j < values.getLength(); j++) { value = (Element) values.item(j); JCheckBox jcb = new JCheckBox(value.getAttribute("name")); jcb.addMouseListener(this); jcb.setName(flag); if (defaultOption != null && jcb.getActionCommand().equalsIgnoreCase(defaultOption)) { jcb.setSelected(true); } optionValuesPanel.add(jcb); } } else if (swing.equalsIgnoreCase("TEXTFIELD")) { // TEXTFIELD takes an arbitrary String as input JTextField jtf = new JTextField(20); jtf.addMouseListener(this); jtf.setName(flag); if (defaultOption != null && defaultOption.equals("ATOMS")) { FFXSystem sys = mainPanel.getHierarchy().getActive(); if (sys != null) { jtf.setText("" + sys.getAtomList().size()); } } else if (defaultOption != null) { jtf.setText(defaultOption); } optionValuesPanel.add(jtf); } else if (swing.equalsIgnoreCase("RADIOBUTTONS")) { // RADIOBUTTONS allows one choice from a set of predifined // values bg = new ButtonGroup(); values = option.getElementsByTagName("Value"); for (int j = 0; j < values.getLength(); j++) { value = (Element) values.item(j); JRadioButton jrb = new JRadioButton(value.getAttribute("name")); jrb.addMouseListener(this); jrb.setName(flag); bg.add(jrb); if (defaultOption != null && jrb.getActionCommand().equalsIgnoreCase(defaultOption)) { jrb.setSelected(true); } optionValuesPanel.add(jrb); } } else if (swing.equalsIgnoreCase("PROTEIN")) { // Protein allows selection of amino acids for the protein // builder optionValuesPanel.setLayout(new BoxLayout(optionValuesPanel, BoxLayout.Y_AXIS)); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); optionValuesPanel.add(getAminoAcidPanel()); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); acidComboBox.removeAllItems(); JButton add = new JButton("Edit"); add.setActionCommand("PROTEIN"); add.addActionListener(this); add.setAlignmentX(Button.CENTER_ALIGNMENT); JPanel comboPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); comboPanel.add(acidTextField); comboPanel.add(add); optionValuesPanel.add(comboPanel); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); JButton remove = new JButton("Remove"); add.setMinimumSize(remove.getPreferredSize()); add.setPreferredSize(remove.getPreferredSize()); remove.setActionCommand("PROTEIN"); remove.addActionListener(this); remove.setAlignmentX(Button.CENTER_ALIGNMENT); comboPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); comboPanel.add(acidComboBox); comboPanel.add(remove); optionValuesPanel.add(comboPanel); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); optionValuesPanel.add(acidScrollPane); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); JButton reset = new JButton("Reset"); reset.setActionCommand("PROTEIN"); reset.addActionListener(this); reset.setAlignmentX(Button.CENTER_ALIGNMENT); optionValuesPanel.add(reset); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); acidTextArea.setText(""); acidTextField.setText(""); } else if (swing.equalsIgnoreCase("NUCLEIC")) { // Nucleic allows selection of nucleic acids for the nucleic // acid builder optionValuesPanel.setLayout(new BoxLayout(optionValuesPanel, BoxLayout.Y_AXIS)); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); optionValuesPanel.add(getNucleicAcidPanel()); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); acidComboBox.removeAllItems(); JButton add = new JButton("Edit"); add.setActionCommand("NUCLEIC"); add.addActionListener(this); add.setAlignmentX(Button.CENTER_ALIGNMENT); JPanel comboPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); comboPanel.add(acidTextField); comboPanel.add(add); optionValuesPanel.add(comboPanel); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); JButton remove = new JButton("Remove"); add.setMinimumSize(remove.getPreferredSize()); add.setPreferredSize(remove.getPreferredSize()); remove.setActionCommand("NUCLEIC"); remove.addActionListener(this); remove.setAlignmentX(Button.CENTER_ALIGNMENT); comboPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); comboPanel.add(acidComboBox); comboPanel.add(remove); optionValuesPanel.add(comboPanel); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); optionValuesPanel.add(acidScrollPane); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); JButton button = new JButton("Reset"); button.setActionCommand("NUCLEIC"); button.addActionListener(this); button.setAlignmentX(Button.CENTER_ALIGNMENT); optionValuesPanel.add(button); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); acidTextArea.setText(""); acidTextField.setText(""); } else if (swing.equalsIgnoreCase("SYSTEMS")) { // SYSTEMS allows selection of an open system JComboBox<FFXSystem> jcb = new JComboBox<>(mainPanel.getHierarchy().getNonActiveSystems()); jcb.setSize(jcb.getMaximumSize()); jcb.addActionListener(this); optionValuesPanel.add(jcb); } // Set up a Conditional for this Option if (conditional != null) { isEnabled = false; String conditionalName = conditional.getAttribute("name"); String conditionalValues = conditional.getAttribute("value"); String cDescription = conditional.getAttribute("description"); String cpostProcess = conditional.getAttribute("postProcess"); if (conditionalName.toUpperCase().startsWith("KEYWORD")) { optionPanel.setName(conditionalName); String keywords[] = conditionalValues.split(" +"); if (activeSystem != null) { Hashtable<String, Keyword> systemKeywords = activeSystem.getKeywords(); for (String key : keywords) { if (systemKeywords.containsKey(key.toUpperCase())) { isEnabled = true; } } } } else if (conditionalName.toUpperCase().startsWith("VALUE")) { isEnabled = true; // Add listeners to the values of this option so // the conditional options can be disabled/enabled. for (int j = 0; j < optionValuesPanel.getComponentCount(); j++) { JToggleButton jtb = (JToggleButton) optionValuesPanel.getComponent(j); jtb.addActionListener(this); jtb.setActionCommand("Conditional"); } JPanel condpanel = new JPanel(); condpanel.setBorder(etchedBorder); JLabel condlabel = new JLabel(cDescription); condlabel.setEnabled(false); condlabel.setName(conditionalValues); JTextField condtext = new JTextField(10); condlabel.setLabelFor(condtext); if (cpostProcess != null) { condtext.setName(cpostProcess); } condtext.setEnabled(false); condpanel.add(condlabel); condpanel.add(condtext); conditionals.add(condlabel); optionPanel.add(condpanel, BorderLayout.SOUTH); } else if (conditionalName.toUpperCase().startsWith("REFLECTION")) { String[] condModifiers; if (conditionalValues.equalsIgnoreCase("AltLoc")) { condModifiers = activeSystem.getAltLocations(); if (condModifiers != null && condModifiers.length > 1) { isEnabled = true; bg = new ButtonGroup(); for (int j = 0; j < condModifiers.length; j++) { JRadioButton jrbmi = new JRadioButton(condModifiers[j]); jrbmi.addMouseListener(this); bg.add(jrbmi); optionValuesPanel.add(jrbmi); if (j == 0) { jrbmi.setSelected(true); } } } } else if (conditionalValues.equalsIgnoreCase("Chains")) { condModifiers = activeSystem.getChainNames(); if (condModifiers != null && condModifiers.length > 0) { isEnabled = true; for (int j = 0; j < condModifiers.length; j++) { JRadioButton jrbmi = new JRadioButton(condModifiers[j]); jrbmi.addMouseListener(this); bg.add(jrbmi); optionValuesPanel.add(jrbmi, j); } } } } } optionPanel.add(optionValuesPanel, BorderLayout.CENTER); optionPanel.setPreferredSize(optionPanel.getPreferredSize()); optionsTabbedPane.addTab(option.getAttribute("name"), optionPanel); optionsTabbedPane.setEnabledAt(optionsTabbedPane.getTabCount() - 1, isEnabled); } } optionsTabbedPane.setPreferredSize(optionsTabbedPane.getPreferredSize()); commandPanel.setLayout(borderLayout); commandPanel.add(optionsTabbedPane, BorderLayout.CENTER); commandPanel.validate(); commandPanel.repaint(); loadLogSettings(); statusLabel.setText(" " + createCommandInput()); }