package bicat.gui.window; import bicat.gui.BicatGui; import javax.swing.*; import java.awt.event.*; import java.awt.*; import bicat.run_machine.*; import java.text.NumberFormat; /** * @author Waseem Ahmad (wahmad at acm dot org) * @version 1.0 * **/ public class RunDialog_cHawk implements ActionListener { BicatGui owner; JDialog dialog; static String DEFAULT_PARAMETERS = "set_defaults"; static String RUN_CHAWK = "run_cHawk"; static String RUN_CHAWK_DIALOG_CANCEL = "cancel"; static String DEFAULT_SEED_VALUE = "13"; static String DEFAULT_ALGO_VALUE = "0"; static String DEFAULT_ITER_VALUE="5"; static String DEFAULT_NUMBER_BICLUSTERS_VALUE = "10"; static String DEFAULT_ALPHA_VALUE = "1.2"; static String DEFAULT_DELTA_VALUE = "0.5"; static String DEFAULT_NORM_THRESHOLD = "5"; static JTextField seed_f; static JComboBox algo_b; static JTextField delta_f; static JTextField iter_f; static JTextField norm_threshold; static String[] algoStrings = { "KL-Divergence", "Euclidean Distance", "Logistic Loss", "Itakura-Saito Distance", "Hinge Loss", "Mahalanobis Distance", "Mean Squared Residue"}; ArgumentscHawk cca; // =========================================================================== public RunDialog_cHawk() { } public RunDialog_cHawk(BicatGui o, ArgumentscHawk args) { owner = o; cca = args; } // =========================================================================== public void makeWindow() { // user-defined parameters: delta, I and N dialog = new JDialog(owner, "Run cHawk"); JPanel parameters = new JPanel( new GridLayout(0,1) ); // .... JPanel p0 = new JPanel( new FlowLayout() ); JPanel parameter_values = new JPanel( new GridLayout(0,2) ); JLabel seed_l = new JLabel("Select Distance Function"); seed_l.setAlignmentX(JPanel.LEFT_ALIGNMENT); parameter_values.add(seed_l); algo_b = new JComboBox(algoStrings); algo_b.setSelectedIndex(0); algo_b.addActionListener(this); parameter_values.add(algo_b); // seed_f = new JTextField(); // seed_f.setText(DEFAULT_SEED_VALUE); // seed_f.addActionListener(this); // .... JLabel delta_l = new JLabel("Set delta: "); delta_l.setAlignmentX(JPanel.LEFT_ALIGNMENT); parameter_values.add(delta_l); delta_f = new JTextField(); delta_f.setText(DEFAULT_DELTA_VALUE); delta_f.addActionListener(this); parameter_values.add(delta_f); JLabel iter_l = new JLabel("Set Number of Iterations: "); iter_l.setAlignmentX(JPanel.LEFT_ALIGNMENT); parameter_values.add(iter_l); iter_f = new JTextField(); iter_f.setText(DEFAULT_ITER_VALUE); iter_f.addActionListener(this); parameter_values.add(iter_f); // .... JLabel number_BCs_l = new JLabel("Set the normalization threshold: "); number_BCs_l.setAlignmentX(JPanel.LEFT_ALIGNMENT); parameter_values.add(number_BCs_l); norm_threshold = new JTextField(); norm_threshold.setText(DEFAULT_NORM_THRESHOLD); norm_threshold.addActionListener(this); parameter_values.add(norm_threshold); p0.add(parameter_values); // ........................................................................ JPanel p1 = new JPanel( new GridBagLayout() ); JButton okButton = new JButton("Run cHawk"); okButton.setActionCommand(RUN_CHAWK); okButton.addActionListener(this); p1.add(okButton); JButton cancelButton = new JButton("Cancel"); cancelButton.setActionCommand(RUN_CHAWK_DIALOG_CANCEL); cancelButton.addActionListener(this); p1.add(cancelButton); // ........................................................................ parameters.add(p0); parameters.add(p1); dialog.setContentPane(parameters); // ........................................................................ dialog.pack(); dialog.setLocationRelativeTo(owner); dialog.setVisible(true); } // =========================================================================== /** * For ActionListener interface, reacts to user selections and * button clicks in this search window. * * */ public void actionPerformed(ActionEvent e) { if(RUN_CHAWK.equals(e.getActionCommand())) { try { //int seed = ( new Integer(seed_f.getText()).intValue()); int algo = algo_b.getSelectedIndex(); int iter = ( new Integer(iter_f.getText()).intValue()); double delta = ( new Double(delta_f.getText()).doubleValue()); int norm_th = ( new Integer(norm_threshold.getText()).intValue()); cca.setAlgorithm(algo); cca.setIter(iter); cca.setDelta(delta); cca.setN(norm_th); // number of output biclusters JOptionPane.showMessageDialog(null, "cHawk algorithm is running... \nThe calculations may take some time"); for (int i = 0; i < 500000000; i++) {} //wait owner.runMachine_cHawk.runBiclustering(cca); dialog.setVisible(false); dialog.dispose(); } catch(NumberFormatException nfe) { nfe.printStackTrace(); } } else if(RUN_CHAWK_DIALOG_CANCEL.equals(e.getActionCommand())) { dialog.setVisible(false); dialog.dispose(); } } }