protected void loadClusterer() {
int returnVal = m_FileChooser.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File selected = m_FileChooser.getSelectedFile();
Clusterer clusterer = null;
Instances trainHeader = null;
int[] ignoredAtts = null;
m_Log.statusMessage(Messages.getInstance().getString("ClustererPanel_VisualizeClusterer_LoadClusterer_Log_StatusSessage_Text_First"));
try {
InputStream is = new FileInputStream(selected);
if (selected.getName().endsWith(".gz")) {
is = new GZIPInputStream(is);
}
ObjectInputStream objectInputStream = new ObjectInputStream(is);
clusterer = (Clusterer) objectInputStream.readObject();
try { // see if we can load the header & ignored attribute info
trainHeader = (Instances) objectInputStream.readObject();
ignoredAtts = (int[]) objectInputStream.readObject();
} catch (Exception e) {} // don't fuss if we can't
objectInputStream.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e, Messages.getInstance().getString("ClustererPanel_VisualizeClusterer_LoadClusterer_JOptionPaneShowMessageDialog_Text"),
JOptionPane.ERROR_MESSAGE);
}
m_Log.statusMessage(Messages.getInstance().getString("ClustererPanel_VisualizeClusterer_LoadClusterer_Log_StatusMessage_Text_Second"));
if (clusterer != null) {
m_Log.logMessage(Messages.getInstance().getString("ClustererPanel_VisualizeClusterer_LoadClusterer_Log_LogMessage_Text_First") + selected.getName()+ "'");
String name = (new SimpleDateFormat("HH:mm:ss - ")).format(new Date());
String cname = clusterer.getClass().getName();
if (cname.startsWith("weka.clusterers."))
cname = cname.substring("weka.clusterers.".length());
name += cname + Messages.getInstance().getString("ClustererPanel_VisualizeClusterer_LoadClusterer_CNAme_Text_First") + selected.getName() + "'";
StringBuffer outBuff = new StringBuffer();
outBuff.append(Messages.getInstance().getString("ClustererPanel_VisualizeClusterer_LoadClusterer_OutBuffer_Text_First"));
outBuff.append(Messages.getInstance().getString("ClustererPanel_VisualizeClusterer_LoadClusterer_OutBuffer_Text_Second") + selected.getName() + "\n");
outBuff.append(Messages.getInstance().getString("ClustererPanel_VisualizeClusterer_LoadClusterer_OutBuffer_Text_Fourth") + clusterer.getClass().getName());
if (clusterer instanceof OptionHandler) {
String [] o = ((OptionHandler) clusterer).getOptions();
outBuff.append(" " + Utils.joinOptions(o));
}
outBuff.append("\n");
if (trainHeader != null) {
outBuff.append(Messages.getInstance().getString("ClustererPanel_VisualizeClusterer_LoadClusterer_OutBuffer_Text_Sixth") + trainHeader.relationName() + '\n');
outBuff.append(Messages.getInstance().getString("ClustererPanel_VisualizeClusterer_LoadClusterer_OutBuffer_Text_Eighth") + trainHeader.numAttributes() + '\n');
if (trainHeader.numAttributes() < 100) {
boolean [] selectedAtts = new boolean [trainHeader.numAttributes()];
for (int i = 0; i < trainHeader.numAttributes(); i++) {
selectedAtts[i] = true;
}
if (ignoredAtts != null)
for (int i=0; i<ignoredAtts.length; i++)
selectedAtts[ignoredAtts[i]] = false;
for (int i = 0; i < trainHeader.numAttributes(); i++) {
if (selectedAtts[i]) {
outBuff.append(" " + trainHeader.attribute(i).name()
+ '\n');
}
}
if (ignoredAtts != null) {
outBuff.append(Messages.getInstance().getString("ClustererPanel_VisualizeClusterer_LoadClusterer_OutBuffer_Text_Eleventh"));
for (int i=0; i<ignoredAtts.length; i++)
outBuff.append(" "
+ trainHeader.attribute(ignoredAtts[i]).name()
+ '\n');
}
} else {
outBuff.append(Messages.getInstance().getString("ClustererPanel_VisualizeClusterer_LoadClusterer_OutBuffer_Text_Twelveth"));
}
} else {
outBuff.append(Messages.getInstance().getString("ClustererPanel_VisualizeClusterer_LoadClusterer_OutBuffer_Text_Thirteenth"));
}
outBuff.append(Messages.getInstance().getString("ClustererPanel_VisualizeClusterer_LoadClusterer_OutBuffer_Text_Fourteenth"));
outBuff.append(clusterer.toString() + "\n");
m_History.addResult(name, outBuff);
m_History.setSingle(name);
FastVector vv = new FastVector();
vv.addElement(clusterer);