m_FilterEditor.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent e) {
m_ApplyFilterBut.setEnabled(getInstances() != null);
Capabilities currentCapabilitiesFilter = m_FilterEditor.getCapabilitiesFilter();
Filter filter = (Filter) m_FilterEditor.getValue();
Capabilities currentFilterCapabilities = null;
if (filter != null && currentCapabilitiesFilter != null &&
(filter instanceof CapabilitiesHandler)) {
currentFilterCapabilities = ((CapabilitiesHandler)filter).getCapabilities();
if (!currentFilterCapabilities.supportsMaybe(currentCapabilitiesFilter) &&
!currentFilterCapabilities.supports(currentCapabilitiesFilter)) {
m_ApplyFilterBut.setEnabled(false);
}
}
}
});
m_OpenFileBut.setToolTipText("Open a set of instances from a file");
m_OpenURLBut.setToolTipText("Open a set of instances from a URL");
m_OpenDBBut.setToolTipText("Open a set of instances from a database");
m_GenerateBut.setToolTipText("Generates artificial data");
m_UndoBut.setToolTipText("Undo the last change to the dataset");
m_UndoBut.setEnabled(ExplorerDefaults.get("enableUndo", "true").equalsIgnoreCase("true"));
if (!m_UndoBut.isEnabled()) {
m_UndoBut.setToolTipText("Undo is disabled - " +
"see weka.gui.explorer.Explorer.props to enable");
}
m_EditBut.setToolTipText("Open the current dataset in a Viewer for editing");
m_SaveBut.setToolTipText("Save the working relation to a file");
m_ApplyFilterBut.setToolTipText("Apply the current filter to the data");
m_FileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
m_OpenURLBut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setInstancesFromURLQ();
}
});
m_OpenDBBut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
SqlViewerDialog dialog = new SqlViewerDialog(null);
dialog.setVisible(true);
if (dialog.getReturnValue() == JOptionPane.OK_OPTION)
setInstancesFromDBQ(dialog.getURL(), dialog.getUser(),
dialog.getPassword(), dialog.getQuery(),
dialog.getGenerateSparseData());
}
});
m_OpenFileBut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setInstancesFromFileQ();
}
});
m_GenerateBut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
generateInstances();
}
});
m_UndoBut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
undo();
}
});
m_EditBut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
edit();
}
});
m_SaveBut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
saveWorkingInstancesToFileQ();
}
});
m_ApplyFilterBut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
applyFilter((Filter) m_FilterEditor.getValue());
}
});
m_AttPanel.getSelectionModel()
.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
ListSelectionModel lm = (ListSelectionModel) e.getSource();
for (int i = e.getFirstIndex(); i <= e.getLastIndex(); i++) {
if (lm.isSelectedIndex(i)) {
m_AttSummaryPanel.setAttribute(i);
m_AttVisualizePanel.setAttribute(i);
break;
}
}
}
}
});
m_InstSummaryPanel.setBorder(BorderFactory
.createTitledBorder("Current relation"));
JPanel attStuffHolderPanel = new JPanel();
attStuffHolderPanel.setBorder(BorderFactory
.createTitledBorder("Attributes"));
attStuffHolderPanel.setLayout(new BorderLayout());
attStuffHolderPanel.add(m_AttPanel, BorderLayout.CENTER);
m_RemoveButton.setEnabled(false);
m_RemoveButton.setToolTipText("Remove selected attributes.");
m_RemoveButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
Remove r = new Remove();
int [] selected = m_AttPanel.getSelectedAttributes();
if (selected.length == 0) {
return;
}
if (selected.length == m_Instances.numAttributes()) {
// Pop up an error optionpane
JOptionPane.showMessageDialog(PreprocessPanel.this,
"Can't remove all attributes from data!\n",
"Remove Attributes",
JOptionPane.ERROR_MESSAGE);
m_Log.logMessage("Can't remove all attributes from data!");
m_Log.statusMessage("Problem removing attributes");
return;
}
r.setAttributeIndicesArray(selected);
applyFilter(r);
m_RemoveButton.setEnabled(false);
} catch (Exception ex) {
if (m_Log instanceof TaskLogger) {
((TaskLogger)m_Log).taskFinished();
}
// Pop up an error optionpane
JOptionPane.showMessageDialog(PreprocessPanel.this,
"Problem filtering instances:\n"
+ ex.getMessage(),
"Remove Attributes",
JOptionPane.ERROR_MESSAGE);
m_Log.logMessage("Problem removing attributes: " + ex.getMessage());
m_Log.statusMessage("Problem removing attributes");
}
}
});
JPanel p1 = new JPanel();
p1.setBorder(BorderFactory.createEmptyBorder(10, 5, 10, 5));
p1.setLayout(new BorderLayout());
p1.add(m_RemoveButton, BorderLayout.CENTER);
attStuffHolderPanel.add(p1, BorderLayout.SOUTH);
m_AttSummaryPanel.setBorder(BorderFactory
.createTitledBorder("Selected attribute"));
m_UndoBut.setEnabled(false);
m_EditBut.setEnabled(false);
m_SaveBut.setEnabled(false);
m_ApplyFilterBut.setEnabled(false);
// Set up the GUI layout
JPanel buttons = new JPanel();
buttons.setBorder(BorderFactory.createEmptyBorder(10, 5, 10, 5));
buttons.setLayout(new GridLayout(1, 6, 5, 5));
buttons.add(m_OpenFileBut);
buttons.add(m_OpenURLBut);
buttons.add(m_OpenDBBut);
buttons.add(m_GenerateBut);
buttons.add(m_UndoBut);
buttons.add(m_EditBut);
buttons.add(m_SaveBut);
JPanel attInfo = new JPanel();
attInfo.setLayout(new BorderLayout());
attInfo.add(attStuffHolderPanel, BorderLayout.CENTER);
JPanel filter = new JPanel();
filter.setBorder(BorderFactory
.createTitledBorder("Filter"));
filter.setLayout(new BorderLayout());
filter.add(m_FilterPanel, BorderLayout.CENTER);
filter.add(m_ApplyFilterBut, BorderLayout.EAST);
JPanel attVis = new JPanel();
attVis.setLayout( new GridLayout(2,1) );
attVis.add(m_AttSummaryPanel);