⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 defaultmodelspanel.java

📁 代码是一个分类器的实现,其中使用了部分weka的源代码。可以将项目导入eclipse运行
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    JScrollPane listView = new JScrollPane(m_ModelList);    listView    .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);    listView.setPreferredSize(new Dimension(150, 50));        modelListPanel.setLayout(new BorderLayout());    modelListPanel.add(listView, BorderLayout.CENTER);        gbc.weightx = 1;    gbc.weighty = 1;    gbc.fill = GridBagConstraints.BOTH;    gbc.gridx = 0;    gbc.gridy = 2;    gbc.gridwidth = 3;    gbc.anchor = GridBagConstraints.WEST;    add(modelListPanel, gbc);        m_RemoveSelectedButton = new JButton("Remove Selected");    m_RemoveSelectedButton.addActionListener(this);    m_RemoveSelectedButton.setToolTipText(	"Remove the selected models from the current default set");    gbc.fill = GridBagConstraints.HORIZONTAL;    gbc.weighty = 0;    gbc.gridx = 0;    gbc.gridy = 3;    gbc.anchor = GridBagConstraints.WEST;    gbc.weightx = 1;    gbc.gridwidth = 1;    add(m_RemoveSelectedButton, gbc);        m_AddSelectedButton = new JButton("Add Selected");    m_AddSelectedButton.addActionListener(this);    m_AddSelectedButton.setToolTipText("Add selected models in "	+ "above list to the library");    gbc.fill = GridBagConstraints.HORIZONTAL;    gbc.gridx = 1;    gbc.gridy = 3;    gbc.anchor = GridBagConstraints.WEST;    gbc.gridwidth = 1;    gbc.weightx = 1;    add(m_AddSelectedButton, gbc);        m_AddAllButton = new JButton("Add All");    m_AddAllButton.addActionListener(this);    m_AddAllButton.setToolTipText("Add all models in the above"	+ "list to the Libray");    gbc.fill = GridBagConstraints.HORIZONTAL;    gbc.gridx = 2;    gbc.gridy = 3;    gbc.anchor = GridBagConstraints.WEST;    gbc.gridwidth = 1;    gbc.weightx = 1;    add(m_AddAllButton, gbc);        m_ListUpdatePending = true;      }    /**   * This method is called in response to user actions prompting   * us to reload the model list: when they select a new list,    * or hit reload.   *   */  public void updateDefaultList() {        ((ModelList.SortedListModel) m_ModelList.getModel()).clear();        String ensemblePackageString = getPackageName();        int index = m_DefaultFilesComboBox.getSelectedIndex();        Vector classifiers = null;        LibrarySerialization serialization;    try {            serialization = new LibrarySerialization();            String defaultFileString = ensemblePackageString      + m_DefaultFileNames[index].trim() + ".model.xml";            //System.out.println(defaultFileString);            InputStream is = ClassLoader.getSystemResourceAsStream(defaultFileString);            if (is == null) {	File f = new File(defaultFileString);	if (f.exists()) {	  System.out.println("file existed: " + f.getPath());	} else {	  System.out.println("file didn't exist: " + f.getPath());	}	      }            classifiers = (Vector) serialization.read(ClassLoader.getSystemResourceAsStream(defaultFileString));            for (Iterator it = classifiers.iterator(); it.hasNext();) {	EnsembleLibraryModel model = m_ListModelsPanel.getLibrary().createModel((Classifier) it.next());	model.testOptions();	((ModelList.SortedListModel) m_ModelList.getModel()).add(model);      }          } catch (Exception e) {      // TODO Auto-generated catch block      e.printStackTrace();    }  }    /**   * Deals with user input to the various buttons in this GUI   *    * @param e		the event   */  public void actionPerformed(ActionEvent e) {        ModelList.SortedListModel dataModel = ((ModelList.SortedListModel) m_ModelList	.getModel());        if (e.getSource() == m_RefreshButton) {      updateDefaultList();          } else if (e.getSource() == m_DefaultFilesComboBox) {      updateDefaultList();          } else if (e.getSource() == m_RemoveSelectedButton) {            //here we simply get the list of models that are       //currently selected and ten remove them from the list            Object[] currentModels = m_ModelList.getSelectedValues();            for (int i = 0; i < currentModels.length; i++) {	dataModel.removeElement(currentModels[i]);      }            //Shrink the selected range to the first index that was selected      if (m_ModelList.getSelectedIndices().length > 0) {	int selected[] = new int[1];	selected[0] = m_ModelList.getSelectedIndices()[0];	m_ModelList.setSelectedIndices(selected);      }          } else if (e.getSource() == m_AddAllButton) {            //here we just need to add all of the models to the       //ListModelsPanel object            Iterator it = dataModel.iterator();            while (it.hasNext()) {	EnsembleLibraryModel currentModel = (EnsembleLibraryModel) it.next();	m_ListModelsPanel.addModel(currentModel);      }            dataModel.clear();          } else if (e.getSource() == m_AddSelectedButton) {            //here we simply get the list of models that are       //currently selected and ten remove them from the list            Object[] currentModels = m_ModelList.getSelectedValues();            for (int i = 0; i < currentModels.length; i++) {		m_ListModelsPanel.addModel((EnsembleLibraryModel) currentModels[i]);	dataModel.removeElement(currentModels[i]);      }    } else if (e.getSource() == m_ExcludeModelsButton) {            if (m_ExcludeModelsComboBox.getSelectedIndex() == 0) {	applyTrainTimeFilters();      } else if (m_ExcludeModelsComboBox.getSelectedIndex() == 1) {	applyTestTimeFilters();      } else if (m_ExcludeModelsComboBox.getSelectedIndex() == 2) {	applyFileSizeFilters();      }    }  }    /**   * this listener event fires when the use switches back to this panel   * it checks to se if the working directory has changed since they were   * here last.  If so then it updates the model list.   *    * @param e		the event   */  public void stateChanged(ChangeEvent e) {    JTabbedPane pane = (JTabbedPane) e.getSource();        if (pane.getSelectedComponent().equals(this) && m_ListUpdatePending) {            updateDefaultList();      m_ListUpdatePending = false;    }  }    /**   * Removes models from the list that fit the regular expressions   * defining models that have large train times   */  public void applyTrainTimeFilters() {        //create an array of patterns and then pass them to the apply     //filters method    Pattern patterns[] = new Pattern[m_LargeTrainTimeModels.length];        for (int i = 0; i < m_LargeTrainTimeModels.length; i++) {      patterns[i] = Pattern.compile(m_LargeTrainTimeModels[i]);    }        applyFilters(patterns);  }    /**   * Removes models from the list that fit the regular expressions   * defining models that have large test times   */  public void applyTestTimeFilters() {        //create an array of patterns and then pass them to the apply     //filters method    Pattern patterns[] = new Pattern[m_LargeTestTimeModels.length];        for (int i = 0; i < m_LargeTestTimeModels.length; i++) {      patterns[i] = Pattern.compile(m_LargeTestTimeModels[i]);    }        applyFilters(patterns);  }    /**   * Removes models from the list that fit the regular expressions   * defining models that have large file sizes   */  public void applyFileSizeFilters() {        //create an array of patterns and then pass them to the apply     //filters method    Pattern patterns[] = new Pattern[m_LargeFileSizeModels.length];        for (int i = 0; i < m_LargeFileSizeModels.length; i++) {      patterns[i] = Pattern.compile(m_LargeFileSizeModels[i]);    }        applyFilters(patterns);  }    /**   * This is the code common to the previous three methods.  It basically    * takes a Java regexp pattern and applies it to the currently selected    * list of models, removing those that match as it goes.     *   * @param patterns	the regexp patterns   */  public void applyFilters(Pattern[] patterns) {        ModelList.SortedListModel dataModel = ((ModelList.SortedListModel) m_ModelList	.getModel());        //this will track all of the models that we need to remove    //from our list    Vector toRemove = new Vector();        //here we simply get the list of models that are     //currently selected and ten remove them from the list    //if they match one of the patterns        Iterator it = dataModel.iterator();        while (it.hasNext()) {      EnsembleLibraryModel currentModel = (EnsembleLibraryModel) it.next();            for (int i = 0; i < patterns.length; i++) {	if (patterns[i].matcher(currentModel.getStringRepresentation()).matches()) {	  toRemove.add(currentModel);	  break;	}      }    }        it = toRemove.iterator();        while (it.hasNext()) {      dataModel.removeElement(it.next());    }  }    /**   * this bit of code grabs all of the .model.xml files located in   * the ensemble selection package directory.  I decided to detect this *   * directory in case we change the package name which I think we planned   * on doing.     *    * @return		the package name   */  public static String getPackageName() {    return        EnsembleSelectionLibrary.class.toString()      .replaceAll("class ", "")      .replaceAll("EnsembleSelectionLibrary", "")      .replaceAll("\\.", "/");  }  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -