📄 misetuppanel.java
字号:
buttons.add(m_SaveBut,constraints); constraints.gridx=2;constraints.gridy=0;constraints.weightx=5; constraints.gridwidth=1;constraints.gridheight=1; buttons.add(m_NewBut,constraints); JPanel src = new JPanel(); src.setLayout(new BorderLayout()); src.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("Result generator"), BorderFactory.createEmptyBorder(0, 5, 5, 5) )); src.add(m_RPEditorPanel, BorderLayout.NORTH); JPanel dest = new JPanel(); dest.setLayout(new BorderLayout()); dest.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("Destination"), BorderFactory.createEmptyBorder(0, 5, 5, 5) )); dest.add(m_RLEditorPanel, BorderLayout.NORTH); m_advanceDataSetFirst.setEnabled(false); m_advanceIteratorFirst.setEnabled(false); m_advanceDataSetFirst. setToolTipText("Advance data set before custom generator"); m_advanceIteratorFirst. setToolTipText("Advance custom generator before data set"); m_advanceDataSetFirst.setSelected(true); ButtonGroup bg = new ButtonGroup(); bg.add(m_advanceDataSetFirst); bg.add(m_advanceIteratorFirst); m_advanceDataSetFirst.addActionListener(m_RadioListener); m_advanceIteratorFirst.addActionListener(m_RadioListener); JPanel radioButs = new JPanel(); radioButs.setBorder(BorderFactory. createTitledBorder("Iteration control")); radioButs.setLayout(new GridLayout(1, 2)); radioButs.add(m_advanceDataSetFirst); radioButs.add(m_advanceIteratorFirst); JPanel simpleIterators = new JPanel(); simpleIterators.setLayout(new BorderLayout()); JPanel tmp = new JPanel(); tmp.setLayout(new GridBagLayout()); // tmp.setLayout(new GridLayout(1, 2)); constraints.gridx=0;constraints.gridy=0;constraints.weightx=5; constraints.fill = GridBagConstraints.HORIZONTAL; constraints.gridwidth=1;constraints.gridheight=1; constraints.insets = new Insets(0,2,0,2); tmp.add(m_RunNumberPanel,constraints); constraints.gridx=1;constraints.gridy=0;constraints.weightx=5; constraints.fill = GridBagConstraints.HORIZONTAL; constraints.gridwidth=1;constraints.gridheight=2; tmp.add(m_DistributeExperimentPanel, constraints); JPanel tmp2 = new JPanel(); // tmp2.setLayout(new GridLayout(2, 1)); tmp2.setLayout(new GridBagLayout()); constraints.gridx=0;constraints.gridy=0;constraints.weightx=5; constraints.fill = GridBagConstraints.HORIZONTAL; constraints.gridwidth=1;constraints.gridheight=1; constraints.insets = new Insets(0,2,0,2); tmp2.add(tmp,constraints); constraints.gridx=0;constraints.gridy=1;constraints.weightx=5; constraints.fill = GridBagConstraints.HORIZONTAL; constraints.gridwidth=1;constraints.gridheight=1; tmp2.add(radioButs,constraints); simpleIterators.add(tmp2, BorderLayout.NORTH); simpleIterators.add(m_DatasetListPanel, BorderLayout.CENTER); JPanel iterators = new JPanel(); iterators.setLayout(new GridLayout(1, 2)); iterators.add(simpleIterators); iterators.add(m_GeneratorPropertyPanel); JPanel top = new JPanel(); top.setLayout(new GridLayout(2, 1)); top.add(dest); top.add(src); JPanel notes = new JPanel(); notes.setLayout(new BorderLayout()); notes.setBorder(BorderFactory.createTitledBorder("Notes")); notes.add(new JScrollPane(m_NotesText), BorderLayout.CENTER); JPanel p2 = new JPanel(); // p2.setLayout(new GridLayout(2, 1)); p2.setLayout(new BorderLayout()); p2.add(iterators, BorderLayout.CENTER); p2.add(notes, BorderLayout.SOUTH); JPanel p3 = new JPanel(); p3.setLayout(new BorderLayout()); p3.add(buttons, BorderLayout.NORTH); p3.add(top, BorderLayout.SOUTH); setLayout(new BorderLayout()); add(p3, BorderLayout.NORTH); add(p2, BorderLayout.CENTER); } /** * Sets the experiment to configure. * * @param exp a value of type 'Experiment' */ public void setExperiment(MIExperiment exp) { boolean iteratorOn = exp.getUsePropertyIterator(); Object propArray = exp.getPropertyArray(); PropertyNode [] propPath = exp.getPropertyPath(); m_Exp = exp; m_SaveBut.setEnabled(true); m_RPEditor.setValue(m_Exp.getResultProducer()); m_RPEditor.setEnabled(true); m_RPEditorPanel.repaint(); m_RLEditor.setValue(m_Exp.getResultListener()); m_RLEditor.setEnabled(true); m_RLEditorPanel.repaint(); m_NotesText.setText(m_Exp.getNotes()); m_NotesText.setEnabled(true); m_advanceDataSetFirst.setSelected(m_Exp.getAdvanceDataSetFirst()); m_advanceIteratorFirst.setSelected(!m_Exp.getAdvanceDataSetFirst()); m_advanceDataSetFirst.setEnabled(true); m_advanceIteratorFirst.setEnabled(true); exp.setPropertyPath(propPath); exp.setPropertyArray(propArray); exp.setUsePropertyIterator(iteratorOn); m_GeneratorPropertyPanel.setExperiment(m_Exp); m_RunNumberPanel.setExperiment(m_Exp); m_DatasetListPanel.setExperiment(m_Exp); m_DistributeExperimentPanel.setExperiment(m_Exp); m_Support.firePropertyChange("", null, null); } /** * Gets the currently configured experiment. * * @return the currently configured experiment. */ public MIExperiment getExperiment() { return m_Exp; } /** * Prompts the user to select an experiment file and loads it. */ private void openExperiment() { int returnVal = m_FileChooser.showOpenDialog(this); if (returnVal != JFileChooser.APPROVE_OPTION) { return; } File expFile = m_FileChooser.getSelectedFile(); if (!expFile.getName().toLowerCase().endsWith(MIExperiment.FILE_EXTENSION)) { expFile = new File(expFile.getParent(), expFile.getName() + MIExperiment.FILE_EXTENSION); } try { FileInputStream fi = new FileInputStream(expFile); ObjectInputStream oi = new ObjectInputStream( new BufferedInputStream(fi)); MIExperiment exp = (MIExperiment)oi.readObject(); oi.close(); setExperiment(exp); System.err.println("Opened experiment:\n" + m_Exp); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(this, "Couldn't open experiment file:\n" + expFile + "\nReason:\n" + ex.getMessage(), "Open Experiment", JOptionPane.ERROR_MESSAGE); // Pop up error dialog } } /** * Prompts the user for a filename to save the experiment to, then saves * the experiment. */ private void saveExperiment() { int returnVal = m_FileChooser.showSaveDialog(this); if (returnVal != JFileChooser.APPROVE_OPTION) { return; } File expFile = m_FileChooser.getSelectedFile(); if (!expFile.getName().toLowerCase().endsWith(MIExperiment.FILE_EXTENSION)) { expFile = new File(expFile.getParent(), expFile.getName() + MIExperiment.FILE_EXTENSION); } try { FileOutputStream fo = new FileOutputStream(expFile); ObjectOutputStream oo = new ObjectOutputStream( new BufferedOutputStream(fo)); oo.writeObject(m_Exp); oo.close(); System.err.println("Saved experiment:\n" + m_Exp); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(this, "Couldn't save experiment file:\n" + expFile + "\nReason:\n" + ex.getMessage(), "Save Experiment", JOptionPane.ERROR_MESSAGE); } } /** * Adds a PropertyChangeListener who will be notified of value changes. * * @param l a value of type 'PropertyChangeListener' */ public void addPropertyChangeListener(PropertyChangeListener l) { m_Support.addPropertyChangeListener(l); } /** * Removes a PropertyChangeListener. * * @param l a value of type 'PropertyChangeListener' */ public void removePropertyChangeListener(PropertyChangeListener l) { m_Support.removePropertyChangeListener(l); } /** * Updates the primary loop iteration control of the experiment */ private void updateRadioLinks() { m_advanceDataSetFirst. setEnabled(m_GeneratorPropertyPanel.getEditorActive()); m_advanceIteratorFirst. setEnabled(m_GeneratorPropertyPanel.getEditorActive()); if (m_Exp != null) { if (!m_GeneratorPropertyPanel.getEditorActive()) { m_Exp.setAdvanceDataSetFirst(true); } else { m_Exp.setAdvanceDataSetFirst(m_advanceDataSetFirst.isSelected()); } } } /** * Tests out the experiment setup from the command line. * * @param args arguments to the program. */ public static void main(String [] args) { try { boolean readExp = Utils.getFlag('l', args); final boolean writeExp = Utils.getFlag('s', args); final String expFile = Utils.getOption('f', args); if ((readExp || writeExp) && (expFile.length() == 0)) { throw new Exception("A filename must be given with the -f option"); } MIExperiment exp = null; if (readExp) { FileInputStream fi = new FileInputStream(expFile); ObjectInputStream oi = new ObjectInputStream( new BufferedInputStream(fi)); exp = (MIExperiment)oi.readObject(); oi.close(); } else { exp = new MIExperiment(); } System.err.println("Initial Experiment:\n" + exp.toString()); final JFrame jf = new JFrame("Weka Experiment Setup"); jf.getContentPane().setLayout(new BorderLayout()); final MISetupPanel sp = new MISetupPanel(); //sp.setBorder(BorderFactory.createTitledBorder("Setup")); jf.getContentPane().add(sp, BorderLayout.CENTER); jf.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.err.println("\nFinal Experiment:\n" + sp.m_Exp.toString()); // Save the experiment to a file if (writeExp) { try { FileOutputStream fo = new FileOutputStream(expFile); ObjectOutputStream oo = new ObjectOutputStream( new BufferedOutputStream(fo)); oo.writeObject(sp.m_Exp); oo.close(); } catch (Exception ex) { ex.printStackTrace(); System.err.println("Couldn't write experiment to: " + expFile + '\n' + ex.getMessage()); } } jf.dispose(); System.exit(0); } }); jf.pack(); jf.setVisible(true); System.err.println("Short nap"); Thread.currentThread().sleep(3000); System.err.println("Done"); sp.setExperiment(exp); } catch (Exception ex) { ex.printStackTrace(); System.err.println(ex.getMessage()); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -