List of usage examples for java.awt GridBagLayout setConstraints
public void setConstraints(Component comp, GridBagConstraints constraints)
From source file:ChiSquareCalculator.java
ChiSquareCalculator() { final JFrame jfrm = new JFrame("Chi Square Calculator"); jfrm.setSize(400, 550);//from w w w .java2s . 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(); 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);// w w w .j a v a 2 s . 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:com.rapidminer.gui.graphs.GraphViewer.java
private JComponent createControlPanel() { // === mouse behaviour === if (graphMouse != null) { vv.setGraphMouse(graphMouse);// w ww .ja va 2 s.co m vv.addKeyListener(graphMouse.getModeKeyListener()); graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING); } transformAction.setEnabled(false); pickingAction.setEnabled(true); vv.addGraphMouseListener(new GraphMouseListener<V>() { @Override public void graphClicked(V vertex, MouseEvent arg1) { } @Override public void graphPressed(V arg0, MouseEvent arg1) { } @Override public void graphReleased(V vertex, MouseEvent arg1) { if (currentMode.equals(ModalGraphMouse.Mode.TRANSFORMING)) { if (graphCreator.getObjectViewer() != null) { vv.getPickedVertexState().clear(); vv.getPickedVertexState().pick(vertex, true); graphCreator.getObjectViewer().showObject(graphCreator.getObject(vertex)); } } } }); JPanel controls = new JPanel(); GridBagLayout gbLayout = new GridBagLayout(); controls.setLayout(gbLayout); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.insets = new Insets(4, 4, 4, 4); c.weightx = 1; c.weighty = 0; // zooming JToolBar zoomBar = new ExtendedJToolBar(); zoomBar.setLayout(new FlowLayout(FlowLayout.CENTER)); zoomBar.add(new ZoomInAction(this, IconSize.SMALL)); zoomBar.add(new ZoomOutAction(this, IconSize.SMALL)); zoomBar.setBorder(BorderFactory.createTitledBorder("Zoom")); c.gridwidth = GridBagConstraints.REMAINDER; gbLayout.setConstraints(zoomBar, c); controls.add(zoomBar); // mode JToolBar modeBar = new ExtendedJToolBar(); modeBar.setLayout(new FlowLayout(FlowLayout.CENTER)); modeBar.add(transformAction); modeBar.add(pickingAction); modeBar.setBorder(BorderFactory.createTitledBorder("Mode")); c.gridwidth = GridBagConstraints.REMAINDER; gbLayout.setConstraints(modeBar, c); controls.add(modeBar); // layout selection c.gridwidth = GridBagConstraints.REMAINDER; gbLayout.setConstraints(layoutSelection, c); controls.add(layoutSelection); // show node labels JCheckBox nodeLabels = new JCheckBox("Node Labels", graphCreator.showVertexLabelsDefault()); nodeLabels.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { togglePaintVertexLabels(); } }); c.gridwidth = GridBagConstraints.REMAINDER; gbLayout.setConstraints(nodeLabels, c); controls.add(nodeLabels); // show edge labels JCheckBox edgeLabels = new JCheckBox("Edge Labels", graphCreator.showEdgeLabelsDefault()); edgeLabels.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { togglePaintEdgeLabels(); } }); c.gridwidth = GridBagConstraints.REMAINDER; gbLayout.setConstraints(edgeLabels, c); controls.add(edgeLabels); // option components for (int i = 0; i < graphCreator.getNumberOfOptionComponents(); i++) { JComponent optionComponent = graphCreator.getOptionComponent(this, i); if (optionComponent != null) { c.gridwidth = GridBagConstraints.REMAINDER; gbLayout.setConstraints(optionComponent, c); controls.add(optionComponent); } } // save image JButton imageButton = new JButton("Save Image..."); imageButton.setToolTipText("Saves an image of the current graph."); imageButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final Component tosave = vv; new ExportImageAction(false) { private static final long serialVersionUID = 1L; @Override protected PrintableComponent getPrintableComponent() { return new SimplePrintableComponent(tosave, "Graph"); } }.actionPerformed(e); } }); c.gridwidth = GridBagConstraints.REMAINDER; gbLayout.setConstraints(imageButton, c); controls.add(imageButton); // help JButton help = new JButton("Help"); help.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(vv, INSTRUCTIONS); } }); c.gridwidth = GridBagConstraints.REMAINDER; gbLayout.setConstraints(help, c); controls.add(help); JPanel fillPanel = new JPanel(); c.weighty = 1.0d; c.gridwidth = GridBagConstraints.REMAINDER; gbLayout.setConstraints(fillPanel, c); controls.add(fillPanel); return controls; }
From source file:it.cnr.icar.eric.client.ui.swing.AdhocQuerySearchPanel.java
private JPanel createParameterEntryPanel(QueryType uiQueryType) { JPanel parameterEntryPanel = new JPanel(); GridBagLayout gbl = new GridBagLayout(); parameterEntryPanel.setLayout(gbl);/*from w w w . j av a 2 s .c o m*/ paramComponents.clear(); List<?> params = uiQueryType.getParameter(); Iterator<?> iter = params.iterator(); int i = 0; while (iter.hasNext()) { ParameterType param = (ParameterType) iter.next(); String tooltip = getLocalizedValue(param.getDescription()); JLabel label = new JLabel(getLocalizedValue(param.getName()) + ":", SwingConstants.LEADING); label.setToolTipText(tooltip); c.gridx = 0; c.gridy = i; c.gridwidth = 1; c.gridheight = 1; c.weightx = 0.0; c.weighty = 0.0; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.LINE_END; c.insets = new Insets(4, 4, 0, 4); gbl.setConstraints(label, c); parameterEntryPanel.add(label); //Get default value for Parameter if any String defaultValue = param.getDefaultValue(); JComponent comp = getComponentForParameter(param, defaultValue); //comp.setToolTipText(tooltip); c.gridx = 1; c.gridy = i; c.gridwidth = 1; c.gridheight = 1; c.weightx = 0.5; c.weighty = 0.0; c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_END; c.insets = new Insets(4, 4, 4, 4); gbl.setConstraints(comp, c); parameterEntryPanel.add(comp); paramComponents.add(comp); i++; } return parameterEntryPanel; }
From source file:be.agiv.security.demo.Main.java
private void showPreferences() { JTabbedPane tabbedPane = new JTabbedPane(); GridBagLayout proxyGridBagLayout = new GridBagLayout(); GridBagConstraints proxyGridBagConstraints = new GridBagConstraints(); JPanel proxyPanel = new JPanel(proxyGridBagLayout) { private static final long serialVersionUID = 1L; @Override/*from www . j a v a 2 s. c o m*/ public Insets getInsets() { return new Insets(10, 10, 10, 10); } }; tabbedPane.addTab("Proxy", proxyPanel); JCheckBox proxyEnableCheckBox = new JCheckBox("Enable proxy", this.proxyEnable); proxyGridBagConstraints.gridx = 0; proxyGridBagConstraints.gridy = 0; proxyGridBagConstraints.anchor = GridBagConstraints.WEST; proxyGridBagConstraints.ipadx = 5; proxyGridBagConstraints.gridwidth = GridBagConstraints.REMAINDER; proxyGridBagLayout.setConstraints(proxyEnableCheckBox, proxyGridBagConstraints); proxyPanel.add(proxyEnableCheckBox); proxyGridBagConstraints.gridwidth = 1; JLabel proxyHostLabel = new JLabel("Host:"); proxyGridBagConstraints.gridx = 0; proxyGridBagConstraints.gridy++; proxyGridBagLayout.setConstraints(proxyHostLabel, proxyGridBagConstraints); proxyPanel.add(proxyHostLabel); JTextField proxyHostTextField = new JTextField(this.proxyHost, 20); proxyGridBagConstraints.gridx++; proxyGridBagLayout.setConstraints(proxyHostTextField, proxyGridBagConstraints); proxyPanel.add(proxyHostTextField); JLabel proxyPortLabel = new JLabel("Port:"); proxyGridBagConstraints.gridx = 0; proxyGridBagConstraints.gridy++; proxyGridBagLayout.setConstraints(proxyPortLabel, proxyGridBagConstraints); proxyPanel.add(proxyPortLabel); JTextField proxyPortTextField = new JTextField(Integer.toString(this.proxyPort), 8); proxyGridBagConstraints.gridx++; proxyGridBagLayout.setConstraints(proxyPortTextField, proxyGridBagConstraints); proxyPanel.add(proxyPortTextField); JLabel proxyTypeLabel = new JLabel("Type:"); proxyGridBagConstraints.gridx = 0; proxyGridBagConstraints.gridy++; proxyGridBagLayout.setConstraints(proxyTypeLabel, proxyGridBagConstraints); proxyPanel.add(proxyTypeLabel); JComboBox proxyTypeComboBox = new JComboBox(new Object[] { Proxy.Type.HTTP, Proxy.Type.SOCKS }); proxyTypeComboBox.setSelectedItem(this.proxyType); proxyGridBagConstraints.gridx++; proxyGridBagLayout.setConstraints(proxyTypeComboBox, proxyGridBagConstraints); proxyPanel.add(proxyTypeComboBox); int dialogResult = JOptionPane.showConfirmDialog(this, tabbedPane, "Preferences", JOptionPane.OK_CANCEL_OPTION); if (dialogResult == JOptionPane.CANCEL_OPTION) { return; } this.statusBar.setStatus("Applying new preferences..."); this.proxyHost = proxyHostTextField.getText(); this.proxyPort = Integer.parseInt(proxyPortTextField.getText()); this.proxyType = (Proxy.Type) proxyTypeComboBox.getSelectedItem(); this.proxyEnable = proxyEnableCheckBox.isSelected(); }
From source file:net.sf.jabref.gui.groups.GroupSelector.java
/** * The first element for each group defines which field to use for the quicksearch. The next two define the name and * regexp for the group./*from w w w .j a v a2s .c o m*/ */ public GroupSelector(JabRefFrame frame, SidePaneManager manager) { super(manager, IconTheme.JabRefIcon.TOGGLE_GROUPS.getIcon(), Localization.lang("Groups")); this.frame = frame; hideNonHits = new JRadioButtonMenuItem(Localization.lang("Hide non-hits"), !Globals.prefs.getBoolean(JabRefPreferences.GRAY_OUT_NON_HITS)); grayOut = new JRadioButtonMenuItem(Localization.lang("Gray out non-hits"), Globals.prefs.getBoolean(JabRefPreferences.GRAY_OUT_NON_HITS)); ButtonGroup nonHits = new ButtonGroup(); nonHits.add(hideNonHits); nonHits.add(grayOut); floatCb.addChangeListener( event -> Globals.prefs.putBoolean(JabRefPreferences.GROUP_FLOAT_SELECTIONS, floatCb.isSelected())); andCb.addChangeListener(event -> Globals.prefs.putBoolean(JabRefPreferences.GROUP_INTERSECT_SELECTIONS, andCb.isSelected())); invCb.addChangeListener( event -> Globals.prefs.putBoolean(JabRefPreferences.GROUP_INVERT_SELECTIONS, invCb.isSelected())); showOverlappingGroups.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { Globals.prefs.putBoolean(JabRefPreferences.GROUP_SHOW_OVERLAPPING, showOverlappingGroups.isSelected()); if (!showOverlappingGroups.isSelected()) { groupsTree.setOverlappingGroups(Collections.emptyList()); } } }); grayOut.addChangeListener( event -> Globals.prefs.putBoolean(JabRefPreferences.GRAY_OUT_NON_HITS, grayOut.isSelected())); JRadioButtonMenuItem highlCb = new JRadioButtonMenuItem(Localization.lang("Highlight"), false); if (Globals.prefs.getBoolean(JabRefPreferences.GROUP_FLOAT_SELECTIONS)) { floatCb.setSelected(true); highlCb.setSelected(false); } else { highlCb.setSelected(true); floatCb.setSelected(false); } JRadioButtonMenuItem orCb = new JRadioButtonMenuItem(Localization.lang("Union"), false); if (Globals.prefs.getBoolean(JabRefPreferences.GROUP_INTERSECT_SELECTIONS)) { andCb.setSelected(true); orCb.setSelected(false); } else { orCb.setSelected(true); andCb.setSelected(false); } showNumberOfElements.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { Globals.prefs.putBoolean(JabRefPreferences.GROUP_SHOW_NUMBER_OF_ELEMENTS, showNumberOfElements.isSelected()); if (groupsTree != null) { groupsTree.invalidate(); groupsTree.repaint(); } } }); autoAssignGroup.addChangeListener(event -> Globals.prefs.putBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP, autoAssignGroup.isSelected())); invCb.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_INVERT_SELECTIONS)); showOverlappingGroups.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_OVERLAPPING)); editModeIndicator = Globals.prefs.getBoolean(JabRefPreferences.EDIT_GROUP_MEMBERSHIP_MODE); editModeCb.setSelected(editModeIndicator); showNumberOfElements.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_NUMBER_OF_ELEMENTS)); autoAssignGroup.setSelected(Globals.prefs.getBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP)); JButton openSettings = new JButton(IconTheme.JabRefIcon.PREFERENCES.getSmallIcon()); settings.add(andCb); settings.add(orCb); settings.addSeparator(); settings.add(invCb); settings.addSeparator(); settings.add(editModeCb); settings.addSeparator(); settings.add(grayOut); settings.add(hideNonHits); settings.addSeparator(); settings.add(showOverlappingGroups); settings.addSeparator(); settings.add(showNumberOfElements); settings.add(autoAssignGroup); openSettings.addActionListener(e -> { if (!settings.isVisible()) { JButton src = (JButton) e.getSource(); showNumberOfElements .setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_NUMBER_OF_ELEMENTS)); autoAssignGroup.setSelected(Globals.prefs.getBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP)); settings.show(src, 0, openSettings.getHeight()); } }); editModeCb.addActionListener(e -> setEditMode(editModeCb.getState())); JButton newButton = new JButton(IconTheme.JabRefIcon.ADD_NOBOX.getSmallIcon()); int butSize = newButton.getIcon().getIconHeight() + 5; Dimension butDim = new Dimension(butSize, butSize); newButton.setPreferredSize(butDim); newButton.setMinimumSize(butDim); JButton helpButton = new HelpAction(Localization.lang("Help on groups"), HelpFile.GROUP).getHelpButton(); helpButton.setPreferredSize(butDim); helpButton.setMinimumSize(butDim); JButton autoGroup = new JButton(IconTheme.JabRefIcon.AUTO_GROUP.getSmallIcon()); autoGroup.setPreferredSize(butDim); autoGroup.setMinimumSize(butDim); openSettings.setPreferredSize(butDim); openSettings.setMinimumSize(butDim); Insets butIns = new Insets(0, 0, 0, 0); helpButton.setMargin(butIns); openSettings.setMargin(butIns); newButton.addActionListener(e -> { GroupDialog gd = new GroupDialog(frame, panel, null); gd.setVisible(true); if (gd.okPressed()) { AbstractGroup newGroup = gd.getResultingGroup(); groupsRoot.addNewGroup(newGroup, panel.getUndoManager()); panel.markBaseChanged(); frame.output(Localization.lang("Created group \"%0\".", newGroup.getName())); } }); andCb.addActionListener(e -> valueChanged(null)); orCb.addActionListener(e -> valueChanged(null)); invCb.addActionListener(e -> valueChanged(null)); showOverlappingGroups.addActionListener(e -> valueChanged(null)); autoGroup.addActionListener(e -> { AutoGroupDialog gd = new AutoGroupDialog(frame, panel, groupsRoot, Globals.prefs.get(JabRefPreferences.GROUPS_DEFAULT_FIELD), " .,", Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); gd.setVisible(true); // gd does the operation itself }); floatCb.addActionListener(e -> valueChanged(null)); highlCb.addActionListener(e -> valueChanged(null)); hideNonHits.addActionListener(e -> valueChanged(null)); grayOut.addActionListener(e -> valueChanged(null)); newButton.setToolTipText(Localization.lang("New group")); andCb.setToolTipText(Localization.lang("Display only entries belonging to all selected groups.")); orCb.setToolTipText( Localization.lang("Display all entries belonging to one or more of the selected groups.")); autoGroup.setToolTipText(Localization.lang("Automatically create groups for database.")); openSettings.setToolTipText(Localization.lang("Settings")); invCb.setToolTipText( "<html>" + Localization.lang("Show entries <b>not</b> in group selection") + "</html>"); showOverlappingGroups.setToolTipText(Localization .lang("Highlight groups that contain entries contained in any currently selected group")); floatCb.setToolTipText(Localization.lang("Move entries in group selection to the top")); highlCb.setToolTipText(Localization.lang("Gray out entries not in group selection")); editModeCb.setToolTipText(Localization.lang("Click group to toggle membership of selected entries")); ButtonGroup bgr = new ButtonGroup(); bgr.add(andCb); bgr.add(orCb); ButtonGroup visMode = new ButtonGroup(); visMode.add(floatCb); visMode.add(highlCb); JPanel rootPanel = new JPanel(); GridBagLayout gbl = new GridBagLayout(); rootPanel.setLayout(gbl); GridBagConstraints con = new GridBagConstraints(); con.fill = GridBagConstraints.BOTH; con.weightx = 1; con.gridwidth = 1; con.gridy = 0; con.gridx = 0; gbl.setConstraints(newButton, con); rootPanel.add(newButton); con.gridx = 1; gbl.setConstraints(autoGroup, con); rootPanel.add(autoGroup); con.gridx = 2; gbl.setConstraints(openSettings, con); rootPanel.add(openSettings); con.gridx = 3; con.gridwidth = GridBagConstraints.REMAINDER; gbl.setConstraints(helpButton, con); rootPanel.add(helpButton); groupsTree = new GroupsTree(this); groupsTree.addTreeSelectionListener(this); JScrollPane groupsTreePane = new JScrollPane(groupsTree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); groupsTreePane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); con.gridwidth = GridBagConstraints.REMAINDER; con.weighty = 1; con.gridx = 0; con.gridwidth = 4; con.gridy = 1; gbl.setConstraints(groupsTreePane, con); rootPanel.add(groupsTreePane); add(rootPanel, BorderLayout.CENTER); setEditMode(editModeIndicator); definePopup(); NodeAction moveNodeUpAction = new MoveNodeUpAction(); moveNodeUpAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.CTRL_MASK)); NodeAction moveNodeDownAction = new MoveNodeDownAction(); moveNodeDownAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.CTRL_MASK)); NodeAction moveNodeLeftAction = new MoveNodeLeftAction(); moveNodeLeftAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.CTRL_MASK)); NodeAction moveNodeRightAction = new MoveNodeRightAction(); moveNodeRightAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.CTRL_MASK)); setGroups(GroupTreeNode.fromGroup(new AllEntriesGroup())); }
From source file:gdsc.smlm.ij.plugins.SpotAnalysis.java
private void createFrame() { Panel mainPanel = new Panel(); add(mainPanel);// ww w . j a va2 s. c o m inputChoice = new Choice(); mainPanel.add(createChoicePanel(inputChoice, "")); widthTextField = new TextField(); mainPanel.add(createTextPanel(widthTextField, "PSF width", "1.2")); blurTextField = new TextField(); mainPanel.add(createTextPanel(blurTextField, "Blur (relative to width)", "1")); gainTextField = new TextField(); mainPanel.add(createTextPanel(gainTextField, "Gain", "37.7")); exposureTextField = new TextField(); mainPanel.add(createTextPanel(exposureTextField, "ms/Frame", "20")); smoothingTextField = new TextField(); mainPanel.add(createTextPanel(smoothingTextField, "Smoothing", "0.25")); profileButton = new Button("Profile"); profileButton.addActionListener(this); addButton = new Button("Add"); addButton.addActionListener(this); deleteButton = new Button("Remove"); deleteButton.addActionListener(this); saveButton = new Button("Save"); saveButton.addActionListener(this); saveTracesButton = new Button("Save Traces"); saveTracesButton.addActionListener(this); currentLabel = new Label(); mainPanel.add(createLabelPanel(currentLabel, "", "")); rawFittedLabel = new Label(); mainPanel.add(createLabelPanel(rawFittedLabel, "", "")); blurFittedLabel = new Label(); mainPanel.add(createLabelPanel(blurFittedLabel, "", "")); JPanel buttonPanel = new JPanel(); FlowLayout l = new FlowLayout(); l.setVgap(0); buttonPanel.setLayout(l); buttonPanel.add(profileButton, BorderLayout.CENTER); buttonPanel.add(addButton, BorderLayout.CENTER); buttonPanel.add(deleteButton, BorderLayout.CENTER); buttonPanel.add(saveButton, BorderLayout.CENTER); buttonPanel.add(saveTracesButton, BorderLayout.CENTER); mainPanel.add(buttonPanel); listModel = new DefaultListModel<Spot>(); onFramesList = new JList<Spot>(listModel); onFramesList.setVisibleRowCount(15); onFramesList.addListSelectionListener(this); //mainPanel.add(onFramesList); JScrollPane scrollPane = new JScrollPane(onFramesList); scrollPane.getVerticalScrollBarPolicy(); mainPanel.add(scrollPane); GridBagLayout mainGrid = new GridBagLayout(); int y = 0; GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.fill = GridBagConstraints.BOTH; c.anchor = GridBagConstraints.WEST; c.gridwidth = 1; c.insets = new Insets(2, 2, 2, 2); for (Component comp : mainPanel.getComponents()) { c.gridy = y++; mainGrid.setConstraints(comp, c); } mainPanel.setLayout(mainGrid); }
From source file:gdsc.smlm.ij.plugins.PSFEstimator.java
/** * @param imp//w w w. j a va2 s .c o m * @return */ private int showDialog(ImagePlus imp) { // Keep class variables for the parameters we are fitting FitConfiguration fitConfig = config.getFitConfiguration(); initialPeakStdDev0 = fitConfig.getInitialPeakStdDev0(); initialPeakStdDev1 = fitConfig.getInitialPeakStdDev1(); initialPeakAngle = fitConfig.getInitialAngle(); if (!extraOptions) { interlacedData = false; integrateFrames = 1; } this.imp = imp; GenericDialog gd = new GenericDialog(TITLE); gd.addHelp(About.HELP_URL); gd.addMessage("Estimate 2D Gaussian to fit maxima"); gd.addNumericField("Initial_StdDev0", initialPeakStdDev0, 3); gd.addNumericField("Initial_StdDev1", initialPeakStdDev1, 3); gd.addNumericField("Initial_Angle", initialPeakAngle, 3); gd.addNumericField("Number_of_peaks", settings.numberOfPeaks, 0); // pValue sets the smallest significance level probability level at which they are said to be different. // i.e. p <= pValue they are different // lower pValue means harder to be found different. // lower pValue means easier to be found the same. gd.addNumericField("p-Value", settings.pValue, 4); gd.addCheckbox("Update_preferences", settings.updatePreferences); gd.addCheckbox("Log_progress", settings.debugPSFEstimator); gd.addCheckbox("Iterate", settings.iterate); gd.addCheckbox("Show_histograms", settings.showHistograms); gd.addNumericField("Histogram_bins", settings.histogramBins, 0); String[] filterTypes = SettingsManager.getNames((Object[]) DataFilterType.values()); gd.addChoice("Spot_filter_type", filterTypes, filterTypes[config.getDataFilterType().ordinal()]); String[] filterNames = SettingsManager.getNames((Object[]) DataFilter.values()); gd.addChoice("Spot_filter", filterNames, filterNames[config.getDataFilter(0).ordinal()]); gd.addSlider("Smoothing", 0, 2.5, config.getSmooth(0)); gd.addSlider("Search_width", 0.5, 2.5, config.getSearch()); gd.addSlider("Border", 0.5, 2.5, config.getBorder()); gd.addSlider("Fitting_width", 2, 4.5, config.getFitting()); if (extraOptions) { gd.addCheckbox("Interlaced_data", optionInterlacedData); gd.addSlider("Integrate_frames", 1, 5, optionIntegrateFrames); } gd.addMessage("--- Gaussian fitting ---"); Component splitLabel = gd.getMessage(); String[] solverNames = SettingsManager.getNames((Object[]) FitSolver.values()); gd.addChoice("Fit_solver", solverNames, solverNames[fitConfig.getFitSolver().ordinal()]); String[] functionNames = SettingsManager.getNames((Object[]) FitFunction.values()); gd.addChoice("Fit_function", functionNames, functionNames[fitConfig.getFitFunction().ordinal()]); // Parameters specific to each Fit solver are collected in a second dialog gd.addNumericField("Fail_limit", config.getFailuresLimit(), 0); gd.addCheckbox("Include_neighbours", config.isIncludeNeighbours()); gd.addSlider("Neighbour_height", 0.01, 1, config.getNeighbourHeightThreshold()); gd.addSlider("Residuals_threshold", 0.01, 1, config.getResidualsThreshold()); gd.addMessage("--- Peak filtering ---\nDiscard fits that shift; are too low; or expand/contract"); gd.addSlider("Shift_factor", 0.01, 2, fitConfig.getCoordinateShiftFactor()); gd.addNumericField("Signal_strength", fitConfig.getSignalStrength(), 2); gd.addNumericField("Min_photons", fitConfig.getMinPhotons(), 0); gd.addSlider("Width_factor", 0.01, 5, fitConfig.getWidthFactor()); if (gd.getLayout() != null) { GridBagLayout grid = (GridBagLayout) gd.getLayout(); int xOffset = 0, yOffset = 0; int lastY = -1, rowCount = 0; for (Component comp : gd.getComponents()) { // Check if this should be the second major column if (comp == splitLabel) { xOffset += 2; yOffset -= rowCount; } // Reposition the field GridBagConstraints c = grid.getConstraints(comp); if (lastY != c.gridy) rowCount++; lastY = c.gridy; c.gridx = c.gridx + xOffset; c.gridy = c.gridy + yOffset; c.insets.left = c.insets.left + 10 * xOffset; c.insets.top = 0; c.insets.bottom = 0; grid.setConstraints(comp, c); } if (IJ.isLinux()) gd.setBackground(new Color(238, 238, 238)); } gd.showDialog(); if (gd.wasCanceled() || !readDialog(gd)) return DONE; return flags; }
From source file:ViewProj.java
public void init() { setLayout(new BorderLayout()); nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(3);//from ww w .j a v a 2 s.co m GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); JPanel canvasPanel = new JPanel(); GridBagLayout gridbag = new GridBagLayout(); canvasPanel.setLayout(gridbag); canvas = new Canvas3D(config); canvas.setSize(400, 400); GridBagConstraints constraints = new GridBagConstraints(); constraints.gridx = 0; constraints.gridy = 0; constraints.gridwidth = 2; constraints.gridheight = 2; constraints.insets = new Insets(5, 5, 5, 5); constraints.fill = GridBagConstraints.BOTH; gridbag.setConstraints(canvas, constraints); canvasPanel.add(canvas); constraints.fill = GridBagConstraints.REMAINDER; constraints.gridwidth = 1; constraints.gridheight = 1; constraints.gridx = 2; constraints.gridy = 0; urCanvas = new Canvas3D(config); urCanvas.setSize(200, 200); gridbag.setConstraints(urCanvas, constraints); canvasPanel.add(urCanvas); constraints.gridx = 2; constraints.gridy = 1; lrCanvas = new Canvas3D(config); lrCanvas.setSize(200, 200); gridbag.setConstraints(lrCanvas, constraints); canvasPanel.add(lrCanvas); add(canvasPanel, BorderLayout.NORTH); SimpleUniverse u = new SimpleUniverse(canvas); urUniverse = new SimpleUniverse(urCanvas); lrUniverse = new SimpleUniverse(lrCanvas); if (isApplication) { offScreenCanvas = new OffScreenCanvas3D(config, true); // set the size of the off-screen canvas based on a scale // of the on-screen size Screen3D sOn = canvas.getScreen3D(); Screen3D sOff = offScreenCanvas.getScreen3D(); Dimension dim = sOn.getSize(); dim.width *= offScreenScale; dim.height *= offScreenScale; sOff.setSize(dim); sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth() * offScreenScale); sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight() * offScreenScale); // attach the offscreen canvas to the view u.getViewer().getView().addCanvas3D(offScreenCanvas); urOffScreenCanvas = new OffScreenCanvas3D(config, true); // set the size of the off-screen canvas based on a scale // of the on-screen size sOn = urCanvas.getScreen3D(); sOff = urOffScreenCanvas.getScreen3D(); dim = sOn.getSize(); dim.width *= urOffScreenScale; dim.height *= urOffScreenScale; sOff.setSize(dim); sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth() * urOffScreenScale); sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight() * urOffScreenScale); // attach the offscreen canvas to the view urUniverse.getViewer().getView().addCanvas3D(urOffScreenCanvas); lrOffScreenCanvas = new OffScreenCanvas3D(config, true); // set the size of the off-screen canvas based on a scale // of the on-screen size sOn = lrCanvas.getScreen3D(); sOff = lrOffScreenCanvas.getScreen3D(); dim = sOn.getSize(); dim.width *= lrOffScreenScale; dim.height *= lrOffScreenScale; sOff.setSize(dim); sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth() * lrOffScreenScale); sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight() * lrOffScreenScale); // attach the offscreen canvas to the view lrUniverse.getViewer().getView().addCanvas3D(lrOffScreenCanvas); } // Create a simple scene and attach it to the virtual universe BranchGroup scene = createSceneGraph(); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. viewingPlatform = u.getViewingPlatform(); viewingPlatform.setNominalViewingTransform(); view = u.getViewer().getView(); view.setFrontClipPolicy(View.VIRTUAL_EYE); view.setBackClipPolicy(View.VIRTUAL_EYE); view.setFrontClipDistance(frontClipDist); view.setBackClipDistance(backClipDist); u.addBranchGraph(scene); // init the clipGridPts arrays for (int i = 0; i < maxClipGridPts; i++) { clipGridPtsVW[i] = new Point3f(); clipGridPtsProj[i] = new Point3f(); } // init the circlePts arrays for (int i = 0; i < numCirclePts; i++) { circlePtsVW[i] = new Point3f(); circlePtsProj[i] = new Point3f(); } // setup the ur canvas urScene = createVWorldViewSG(); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. urUniverse.getViewingPlatform().setNominalViewingTransform(); View urView = urUniverse.getViewer().getView(); urView.setProjectionPolicy(View.PARALLEL_PROJECTION); urUniverse.addBranchGraph(urScene); // set up the background on a separate BG so that it can stay there // when we replace the scene SG Background urBgWhite = new Background(white); urBgWhite.setApplicationBounds(infiniteBounds); BranchGroup urBackBG = new BranchGroup(); urBackBG.addChild(urBgWhite); urUniverse.addBranchGraph(urBackBG); // setup the lr canvas lrScene = createProjViewSG(); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. lrUniverse.getViewingPlatform().setNominalViewingTransform(); View lrView = lrUniverse.getViewer().getView(); lrView.setProjectionPolicy(View.PARALLEL_PROJECTION); lrUniverse.addBranchGraph(lrScene); // set up the background on a separate BG so that it can stay there // when we replace the scene SG Background lrBgWhite = new Background(white); lrBgWhite.setApplicationBounds(infiniteBounds); BranchGroup lrBackBG = new BranchGroup(); lrBackBG.addChild(lrBgWhite); lrUniverse.addBranchGraph(lrBackBG); // set up the sliders JPanel guiPanel = new JPanel(); guiPanel.setLayout(new GridLayout(0, 2)); FloatLabelJSlider dynamicSlider = new FloatLabelJSlider("Dynamic Offset", 0.1f, 0.0f, 2.0f, dynamicOffset); dynamicSlider.addFloatListener(new FloatListener() { public void floatChanged(FloatEvent e) { dynamicOffset = e.getValue(); solidPa.setPolygonOffsetFactor(dynamicOffset); } }); guiPanel.add(dynamicSlider); LogFloatLabelJSlider staticSlider = new LogFloatLabelJSlider("Static Offset", 0.1f, 10000.0f, staticOffset); staticSlider.addFloatListener(new FloatListener() { public void floatChanged(FloatEvent e) { staticOffset = e.getValue(); solidPa.setPolygonOffset(staticOffset); } }); guiPanel.add(staticSlider); // These are declared final here so they can be changed by the // listener routines below. LogFloatLabelJSlider frontClipSlider = new LogFloatLabelJSlider("Front Clip Distance", 0.001f, 10.0f, frontClipDist); final LogFloatLabelJSlider backClipSlider = new LogFloatLabelJSlider("Back Clip Distance", 1.0f, 10000.0f, backClipDist); final LogFloatLabelJSlider backClipRatioSlider = new LogFloatLabelJSlider("Back Clip Ratio", 1.0f, 10000.0f, backClipRatio); frontClipSlider.addFloatListener(new FloatListener() { public void floatChanged(FloatEvent e) { frontClipDist = e.getValue(); view.setFrontClipDistance(frontClipDist); backClipRatio = backClipDist / frontClipDist; backClipRatioSlider.setValue(backClipRatio); updateViewWindows(); } }); guiPanel.add(frontClipSlider); backClipSlider.addFloatListener(new FloatListener() { public void floatChanged(FloatEvent e) { backClipDist = e.getValue(); backClipRatio = backClipDist / frontClipDist; backClipRatioSlider.setValue(backClipRatio); view.setBackClipDistance(backClipDist); updateViewWindows(); } }); guiPanel.add(backClipSlider); backClipRatioSlider.addFloatListener(new FloatListener() { public void floatChanged(FloatEvent e) { backClipRatio = e.getValue(); backClipDist = backClipRatio * frontClipDist; backClipSlider.setValue(backClipDist); updateViewWindows(); } }); guiPanel.add(backClipRatioSlider); FloatLabelJSlider innerSphereSlider = new FloatLabelJSlider("Inner Sphere Scale", 0.001f, 0.90f, 1.0f, innerScale); innerSphereSlider.addFloatListener(new FloatListener() { public void floatChanged(FloatEvent e) { innerScale = e.getValue(); updateInnerScale(); } }); guiPanel.add(innerSphereSlider); JButton mainSnap = new JButton(snapImageString); mainSnap.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Point loc = canvas.getLocationOnScreen(); offScreenCanvas.setOffScreenLocation(loc); Dimension dim = canvas.getSize(); dim.width *= offScreenScale; dim.height *= offScreenScale; nf.setMinimumIntegerDigits(3); offScreenCanvas.snapImageFile(outFileBase + nf.format(outFileSeq++), dim.width, dim.height); nf.setMinimumIntegerDigits(0); } }); guiPanel.add(mainSnap); JButton urSnap = new JButton(urSnapImageString); urSnap.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Snap UR"); Point loc = urCanvas.getLocationOnScreen(); urOffScreenCanvas.setOffScreenLocation(loc); Dimension dim = urCanvas.getSize(); dim.width *= urOffScreenScale; dim.height *= urOffScreenScale; nf.setMinimumIntegerDigits(3); urOffScreenCanvas.snapImageFile(urOutFileBase + nf.format(urOutFileSeq++), dim.width, dim.height); nf.setMinimumIntegerDigits(0); } }); guiPanel.add(urSnap); JButton lrSnap = new JButton(lrSnapImageString); lrSnap.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Snap LR"); Point loc = lrCanvas.getLocationOnScreen(); lrOffScreenCanvas.setOffScreenLocation(loc); Dimension dim = lrCanvas.getSize(); dim.width *= lrOffScreenScale; dim.height *= lrOffScreenScale; nf.setMinimumIntegerDigits(3); lrOffScreenCanvas.snapImageFile(lrOutFileBase + nf.format(lrOutFileSeq++), dim.width, dim.height); nf.setMinimumIntegerDigits(0); } }); guiPanel.add(lrSnap); add(guiPanel, BorderLayout.SOUTH); }
From source file:net.sf.jabref.groups.GroupSelector.java
/** * The first element for each group defines which field to use for the quicksearch. The next two define the name and * regexp for the group.// w w w . ja v a2 s.c o m */ public GroupSelector(JabRefFrame frame, SidePaneManager manager) { super(manager, IconTheme.JabRefIcon.TOGGLE_GROUPS.getIcon(), Localization.lang("Groups")); this.groupsRoot = new GroupTreeNode(new AllEntriesGroup()); this.frame = frame; hideNonHits = new JRadioButtonMenuItem(Localization.lang("Hide non-hits"), !Globals.prefs.getBoolean(JabRefPreferences.GRAY_OUT_NON_HITS)); grayOut = new JRadioButtonMenuItem(Localization.lang("Gray out non-hits"), Globals.prefs.getBoolean(JabRefPreferences.GRAY_OUT_NON_HITS)); ButtonGroup nonHits = new ButtonGroup(); nonHits.add(hideNonHits); nonHits.add(grayOut); floatCb.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { Globals.prefs.putBoolean(JabRefPreferences.GROUP_FLOAT_SELECTIONS, floatCb.isSelected()); } }); andCb.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { Globals.prefs.putBoolean(JabRefPreferences.GROUP_INTERSECT_SELECTIONS, andCb.isSelected()); } }); invCb.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { Globals.prefs.putBoolean(JabRefPreferences.GROUP_INVERT_SELECTIONS, invCb.isSelected()); } }); showOverlappingGroups.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { Globals.prefs.putBoolean(JabRefPreferences.GROUP_SHOW_OVERLAPPING, showOverlappingGroups.isSelected()); if (!showOverlappingGroups.isSelected()) { groupsTree.setHighlight2Cells(null); } } }); select.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { Globals.prefs.putBoolean(JabRefPreferences.GROUP_SELECT_MATCHES, select.isSelected()); } }); grayOut.addChangeListener( event -> Globals.prefs.putBoolean(JabRefPreferences.GRAY_OUT_NON_HITS, grayOut.isSelected())); JRadioButtonMenuItem highlCb = new JRadioButtonMenuItem(Localization.lang("Highlight"), false); if (Globals.prefs.getBoolean(JabRefPreferences.GROUP_FLOAT_SELECTIONS)) { floatCb.setSelected(true); highlCb.setSelected(false); } else { highlCb.setSelected(true); floatCb.setSelected(false); } JRadioButtonMenuItem orCb = new JRadioButtonMenuItem(Localization.lang("Union"), false); if (Globals.prefs.getBoolean(JabRefPreferences.GROUP_INTERSECT_SELECTIONS)) { andCb.setSelected(true); orCb.setSelected(false); } else { orCb.setSelected(true); andCb.setSelected(false); } showNumberOfElements.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { Globals.prefs.putBoolean(JabRefPreferences.GROUP_SHOW_NUMBER_OF_ELEMENTS, showNumberOfElements.isSelected()); if (groupsTree != null) { groupsTree.invalidate(); groupsTree.validate(); groupsTree.repaint(); } } }); autoAssignGroup.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { Globals.prefs.putBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP, autoAssignGroup.isSelected()); } }); invCb.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_INVERT_SELECTIONS)); showOverlappingGroups.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_OVERLAPPING)); select.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SELECT_MATCHES)); editModeIndicator = Globals.prefs.getBoolean(JabRefPreferences.EDIT_GROUP_MEMBERSHIP_MODE); editModeCb.setSelected(editModeIndicator); showNumberOfElements.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_NUMBER_OF_ELEMENTS)); autoAssignGroup.setSelected(Globals.prefs.getBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP)); openset.setMargin(new Insets(0, 0, 0, 0)); settings.add(andCb); settings.add(orCb); settings.addSeparator(); settings.add(invCb); settings.addSeparator(); settings.add(select); settings.addSeparator(); settings.add(editModeCb); settings.addSeparator(); settings.add(grayOut); settings.add(hideNonHits); settings.addSeparator(); settings.add(showOverlappingGroups); settings.addSeparator(); settings.add(showNumberOfElements); settings.add(autoAssignGroup); // settings.add(moreRow); // settings.add(lessRow); openset.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (!settings.isVisible()) { JButton src = (JButton) e.getSource(); showNumberOfElements .setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_NUMBER_OF_ELEMENTS)); autoAssignGroup.setSelected(Globals.prefs.getBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP)); settings.show(src, 0, openset.getHeight()); } } }); JButton expand = new JButton(IconTheme.JabRefIcon.ADD_ROW.getSmallIcon()); expand.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int i = Globals.prefs.getInt(JabRefPreferences.GROUPS_VISIBLE_ROWS) + 1; groupsTree.setVisibleRowCount(i); groupsTree.revalidate(); groupsTree.repaint(); GroupSelector.this.revalidate(); GroupSelector.this.repaint(); Globals.prefs.putInt(JabRefPreferences.GROUPS_VISIBLE_ROWS, i); LOGGER.info("Height: " + GroupSelector.this.getHeight() + "; Preferred height: " + GroupSelector.this.getPreferredSize().getHeight()); } }); JButton reduce = new JButton(IconTheme.JabRefIcon.REMOVE_ROW.getSmallIcon()); reduce.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int i = Globals.prefs.getInt(JabRefPreferences.GROUPS_VISIBLE_ROWS) - 1; if (i < 1) { i = 1; } groupsTree.setVisibleRowCount(i); groupsTree.revalidate(); groupsTree.repaint(); GroupSelector.this.revalidate(); // _panel.sidePaneManager.revalidate(); GroupSelector.this.repaint(); Globals.prefs.putInt(JabRefPreferences.GROUPS_VISIBLE_ROWS, i); } }); editModeCb.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { editModeIndicator = editModeCb.getState(); updateBorder(editModeIndicator); Globals.prefs.putBoolean(JabRefPreferences.EDIT_GROUP_MEMBERSHIP_MODE, editModeIndicator); } }); int butSize = newButton.getIcon().getIconHeight() + 5; Dimension butDim = new Dimension(butSize, butSize); //Dimension butDimSmall = new Dimension(20, 20); newButton.setPreferredSize(butDim); newButton.setMinimumSize(butDim); refresh.setPreferredSize(butDim); refresh.setMinimumSize(butDim); JButton helpButton = new HelpAction(Localization.lang("Help on groups"), HelpFiles.groupsHelp) .getHelpButton(); helpButton.setPreferredSize(butDim); helpButton.setMinimumSize(butDim); autoGroup.setPreferredSize(butDim); autoGroup.setMinimumSize(butDim); openset.setPreferredSize(butDim); openset.setMinimumSize(butDim); expand.setPreferredSize(butDim); expand.setMinimumSize(butDim); reduce.setPreferredSize(butDim); reduce.setMinimumSize(butDim); Insets butIns = new Insets(0, 0, 0, 0); helpButton.setMargin(butIns); reduce.setMargin(butIns); expand.setMargin(butIns); openset.setMargin(butIns); newButton.addActionListener(this); refresh.addActionListener(this); andCb.addActionListener(this); orCb.addActionListener(this); invCb.addActionListener(this); showOverlappingGroups.addActionListener(this); autoGroup.addActionListener(this); floatCb.addActionListener(this); highlCb.addActionListener(this); select.addActionListener(this); hideNonHits.addActionListener(this); grayOut.addActionListener(this); newButton.setToolTipText(Localization.lang("New group")); refresh.setToolTipText(Localization.lang("Refresh view")); andCb.setToolTipText(Localization.lang("Display only entries belonging to all selected groups.")); orCb.setToolTipText( Localization.lang("Display all entries belonging to one or more of the selected groups.")); autoGroup.setToolTipText(Localization.lang("Automatically create groups for database.")); invCb.setToolTipText(Localization.lang("Show entries *not* in group selection")); showOverlappingGroups.setToolTipText(Localization .lang("Highlight groups that contain entries contained in any currently selected group")); floatCb.setToolTipText(Localization.lang("Move entries in group selection to the top")); highlCb.setToolTipText(Localization.lang("Gray out entries not in group selection")); select.setToolTipText(Localization.lang("Select entries in group selection")); expand.setToolTipText(Localization.lang("Show one more row")); reduce.setToolTipText(Localization.lang("Show one less rows")); editModeCb.setToolTipText(Localization.lang("Click group to toggle membership of selected entries")); ButtonGroup bgr = new ButtonGroup(); bgr.add(andCb); bgr.add(orCb); ButtonGroup visMode = new ButtonGroup(); visMode.add(floatCb); visMode.add(highlCb); JPanel main = new JPanel(); GridBagLayout gbl = new GridBagLayout(); main.setLayout(gbl); GridBagConstraints con = new GridBagConstraints(); con.fill = GridBagConstraints.BOTH; //con.insets = new Insets(0, 0, 2, 0); con.weightx = 1; con.gridwidth = 1; con.gridx = 0; con.gridy = 0; //con.insets = new Insets(1, 1, 1, 1); gbl.setConstraints(newButton, con); main.add(newButton); con.gridx = 1; gbl.setConstraints(refresh, con); main.add(refresh); con.gridx = 2; gbl.setConstraints(autoGroup, con); main.add(autoGroup); con.gridx = 3; con.gridwidth = GridBagConstraints.REMAINDER; gbl.setConstraints(helpButton, con); main.add(helpButton); // header.setBorder(BorderFactory.createMatteBorder(1,1,1,1,Color.red)); // helpButton.setBorder(BorderFactory.createMatteBorder(1,1,1,1,Color.red)); groupsTree = new GroupsTree(this); groupsTree.addTreeSelectionListener(this); groupsTree.setModel(groupsTreeModel = new DefaultTreeModel(groupsRoot)); JScrollPane sp = new JScrollPane(groupsTree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); revalidateGroups(); con.gridwidth = GridBagConstraints.REMAINDER; con.weighty = 1; con.gridx = 0; con.gridwidth = 4; con.gridy = 1; gbl.setConstraints(sp, con); main.add(sp); JPanel pan = new JPanel(); GridBagLayout gb = new GridBagLayout(); con.weighty = 0; gbl.setConstraints(pan, con); pan.setLayout(gb); con.insets = new Insets(0, 0, 0, 0); con.gridx = 0; con.gridy = 0; con.weightx = 1; con.gridwidth = 4; con.fill = GridBagConstraints.HORIZONTAL; gb.setConstraints(openset, con); pan.add(openset); con.gridwidth = 1; con.gridx = 4; con.gridy = 0; gb.setConstraints(expand, con); pan.add(expand); con.gridx = 5; gb.setConstraints(reduce, con); pan.add(reduce); con.gridwidth = 6; con.gridy = 1; con.gridx = 0; con.fill = GridBagConstraints.HORIZONTAL; con.gridy = 2; con.gridx = 0; con.gridwidth = 4; gbl.setConstraints(pan, con); main.add(pan); main.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); add(main, BorderLayout.CENTER); updateBorder(editModeIndicator); definePopup(); NodeAction moveNodeUpAction = new MoveNodeUpAction(); moveNodeUpAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.CTRL_MASK)); NodeAction moveNodeDownAction = new MoveNodeDownAction(); moveNodeDownAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.CTRL_MASK)); NodeAction moveNodeLeftAction = new MoveNodeLeftAction(); moveNodeLeftAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.CTRL_MASK)); NodeAction moveNodeRightAction = new MoveNodeRightAction(); moveNodeRightAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.CTRL_MASK)); }