/* -------------------------------------------------------------------------- */ /* */ /* BATCH MODE INPUT WINDOW */ /* Frans Coenen */ /* Wednesday 15 March 2006 */ /* */ /* -------------------------------------------------------------------------- */ /* Window to input batch mode parameters. */ //package lucsKDD_ARM; // Java packages import java.util.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class BatchModeParams extends JFrame implements ActionListener { /* ------------------------------------------------- */ /* */ /* FIELDS */ /* */ /* ------------------------------------------------- */ // Constants /** Array of threshold labels (also dictates ordering of defualt values). */ private final static String[] THOLD_LABELS = {"Support","Confidence", "Signifcance","Upper Noise","Lower Noise"}; /** Array of batch mode labels (includes empty first label). */ private final static String[] BATCH_LABELS = {" ","From","To","Step"}; /** Minimum thresholds value. */ private final static double MIN_VALUE = 0.0; /** Maximum thresholds value. */ private final static double MAX_VALUE = 100.0; // Other fields /** Instance of text mining model. */ private TextMiningModel tmModel = null; /** Array of batch mode default values. */ private double[][] batchValues = null; /** 2-D Array of instances of class JTextField. */ private JTextField[][] batchFields = new JTextField[5][3]; /** Panel to hold text fields. */ private JPanel panel = null; /* ------------------------------------------------- */ /* */ /* CONSTRUCTORS */ /* */ /* ------------------------------------------------- */ /** One argument constructor. @param newTMmodel new isntance of TextMiningModel class. */ public BatchModeParams(TextMiningModel newTMmodel) { super("LUCS-KDD TEXT MINING GUI: Batch mode input"); // Set fields tmModel = newTMmodel; batchValues = tmModel.getBatchValues(); // Content pane getContentPane().setBackground(Color.pink); getContentPane().setLayout(new BorderLayout(5,5)); // Heading JLabel heading = new JLabel("BATCH MODE INPUT"); getContentPane().add(heading,BorderLayout.NORTH); JPanel instructPanel = new JPanel(); instructPanel.setBackground(Color.pink); instructPanel.setLayout(new GridLayout(3,1)); Label label1 = new Label("BATCH MODE INPUT"); Label label2 = new Label("Instructions: Press enter to confirm " + "a changed value,"); Label label3 = new Label(" and \"Set batch mode parameters\" to " + "implement change."); instructPanel.add(label1); instructPanel.add(label2); instructPanel.add(label3); getContentPane().add(instructPanel,BorderLayout.NORTH); // Panel createPanel(); getContentPane().add(panel,BorderLayout.CENTER); // Set Button JButton setButton = new JButton("Set batch mode parameters"); setButton.addActionListener(this); getContentPane().add(setButton,BorderLayout.SOUTH); } /** Creates panel for text fields. */ private void createPanel() { // Creat panel and set layout panel = new JPanel(); panel.setLayout(new GridLayout(6,4,5,5)); // Add top row of labels JLabel[] bmLables = new JLabel[BATCH_LABELS.length]; for (int index=0;indexActionEvent class. */ public void actionPerformed(ActionEvent event) { String textString; // Check for set button if (event.getActionCommand().equals("Set batch mode parameters")) setInputBmode(); // Else ID source field index else { int index1 = 0; int index2 = 0; boolean foundField = false; for ( ;index1=MAX_VALUE) { String s = "Input value for " + THOLD_LABELS[index1] + " threshold \"" + BATCH_LABELS[index2+1] + "\" batch mode parameter --- " + value + ",\nnot between limits of " + MIN_VALUE + " and " + MAX_VALUE + "!"; JOptionPane.showMessageDialog(this,s, "Threshold Input Error: ", JOptionPane.ERROR_MESSAGE); } else batchValues[index1][index2] = value; } catch (NumberFormatException e) { JOptionPane.showMessageDialog(this,"Number format exception", "Threshold Input Error: ", JOptionPane.ERROR_MESSAGE); } } } /* ----------------------------------------------------- */ /* */ /* SET METHODS */ /* */ /* ----------------------------------------------------- */ /** Sets the batch mode thresholds for the given instance of the text mining model class. */ private void setInputBmode() { boolean checkFlag = true; //System.out.println("setInputBmode"); // Check Values for (int index=0;index0.000001) { if (batchValues[index1][0] > batchValues[index1][1]) { String s = "\"From\" value for " + THOLD_LABELS[index1] + " threshold batch mode parameters\nmust be less " + "than or equal to \"To\" value,\n" + batchValues[index1][0] + ">=" + batchValues[index1][1] + "!"; JOptionPane.showMessageDialog(this,s, "Batch mode Input Error: ", JOptionPane.ERROR_MESSAGE); return(!okToProceed); } } // Check step value is not 0 else { String s = "\"Step\" value for " + THOLD_LABELS[index1] + " threshold batch mode parameters\ncannot be 0 " + "otherwise batch will not terminate!"; JOptionPane.showMessageDialog(this,s, "Batch mode Input Error: ", JOptionPane.ERROR_MESSAGE); return(!okToProceed); } // Return return(okToProceed); } }