source: src/main/java/weka/gui/EnsembleSelectionLibraryEditor.java @ 17

Last change on this file since 17 was 4, checked in by gnappo, 14 years ago

Import di weka.

File size: 4.5 KB
Line 
1/*
2 *    This program is free software; you can redistribute it and/or modify
3 *    it under the terms of the GNU General Public License as published by
4 *    the Free Software Foundation; either version 2 of the License, or
5 *    (at your option) any later version.
6 *
7 *    This program is distributed in the hope that it will be useful,
8 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 *    GNU General Public License for more details.
11 *
12 *    You should have received a copy of the GNU General Public License
13 *    along with this program; if not, write to the Free Software
14 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15 */
16
17/*
18 *    EnsembleSelectionLibraryEditor.java
19 *    Copyright (C) 2006 Robert Jung
20 *
21 */
22
23package weka.gui;
24
25import weka.classifiers.meta.ensembleSelection.EnsembleSelectionLibrary;
26import weka.gui.ensembleLibraryEditor.AddModelsPanel;
27import weka.gui.ensembleLibraryEditor.DefaultModelsPanel;
28import weka.gui.ensembleLibraryEditor.ListModelsPanel;
29import weka.gui.ensembleLibraryEditor.LoadModelsPanel;
30
31import java.awt.BorderLayout;
32import java.awt.Component;
33import java.awt.Dimension;
34
35import javax.swing.JPanel;
36import javax.swing.JTabbedPane;
37
38/**
39 * Class for editing Ensemble Library objects. This basically
40 * does the same thing as its parent class except that it also
41 * adds two extra panels.  A "loadModelsPanel" to detect model
42 * specifications from an ensemble working directory and a
43 * "defaltModelsPanel" which lets you choose sets of model specs
44 * from a few default lists.  Brings up a custom editing
45 * panel with which the user can edit the library interactively, as well
46 * as save load libraries from files. 
47 *
48 * @author  Robert Jung (mrbobjung@gmail.com)
49 * @version $Revision: 1.1 $
50 */
51public class EnsembleSelectionLibraryEditor extends EnsembleLibraryEditor {
52 
53  /** An instance of the custom  editor */
54  protected CustomEditor m_CustomEditor = new CustomEditor();
55 
56  /** the panel showing models in a workingDirectory */
57  protected LoadModelsPanel m_LoadModelsPanel;
58 
59  /** The panel showing the defaults */
60  protected DefaultModelsPanel m_DefaultModelsPanel;
61 
62  /**
63   * This class presents a GUI for editing the library, and saving and
64   * loading model list from files.
65   */
66  private class CustomEditor 
67    extends JPanel {
68   
69    /** for serialization */
70    private static final long serialVersionUID = -3859973750432725901L;
71
72    /**
73     * Constructs a new CustomEditor.
74     *
75     */
76    public CustomEditor() {
77     
78      m_ModelOptionsPane = new JTabbedPane();
79     
80      m_ListModelsPanel = new ListModelsPanel(m_Library);
81      m_ModelOptionsPane.addTab("Library List", m_ListModelsPanel);
82     
83      //Each of the three other panels needs a reference to the main one so that
84      //they can add models to it.
85      m_ModelOptionsPane.addTab("Add Models", new AddModelsPanel(
86          m_ListModelsPanel));
87     
88      m_DefaultModelsPanel = new DefaultModelsPanel(m_ListModelsPanel);
89      m_ModelOptionsPane.addTab("Add Default Set", m_DefaultModelsPanel);
90      m_ModelOptionsPane.addChangeListener(m_DefaultModelsPanel);
91     
92      m_LoadModelsPanel = new LoadModelsPanel(m_ListModelsPanel,
93          EnsembleSelectionLibraryEditor.this);
94      m_ModelOptionsPane.addTab("Load Models", m_LoadModelsPanel);
95      m_ModelOptionsPane.addChangeListener(m_LoadModelsPanel);
96     
97      setLayout(new BorderLayout());
98      add(m_ModelOptionsPane, BorderLayout.CENTER);
99     
100      setPreferredSize(new Dimension(420, 500));
101    }
102  }
103 
104  /**
105   * Constructs a new LibraryEditor.
106   *
107   */
108  public EnsembleSelectionLibraryEditor() {
109    super();
110   
111    m_CustomEditor = new CustomEditor();
112  }
113 
114  /**
115   * Sets the value of the Library to be edited.
116   *
117   * @param value a Library object to be edited
118   */
119  public void setValue(Object value) {
120    super.setValue(value);
121    m_LoadModelsPanel.setLibrary((EnsembleSelectionLibrary) m_Library);
122   
123    ((EnsembleSelectionLibrary) m_Library)
124    .addWorkingDirectoryListener(m_LoadModelsPanel);
125  }
126 
127  /**
128   * Gets a GUI component with which the user can edit the cost matrix.
129   *
130   * @return an editor GUI component
131   */
132  public Component getCustomEditor() {
133    return m_CustomEditor;
134  }
135 
136  /**
137   * returns whether or not the LoadModelsPanel is currently selected
138   *
139   * @return true if selected
140   */
141  public boolean isLoadModelsPanelSelected() {
142    return m_ModelOptionsPane.getSelectedComponent().equals(
143        m_LoadModelsPanel);
144  }
145}
Note: See TracBrowser for help on using the repository browser.