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

📄 managetemplatesdialog.java

📁 一个很好的LIBSVM的JAVA源码。对于要研究和改进SVM算法的学者。可以参考。来自数据挖掘工具YALE工具包。
💻 JAVA
字号:
/*
 *  YALE - Yet Another Learning Environment
 *  Copyright (C) 2001-2004
 *      Simon Fischer, Ralf Klinkenberg, Ingo Mierswa, 
 *          Katharina Morik, Oliver Ritthoff
 *      Artificial Intelligence Unit
 *      Computer Science Department
 *      University of Dortmund
 *      44221 Dortmund,  Germany
 *  email: yale-team@lists.sourceforge.net
 *  web:   http://yale.cs.uni-dortmund.de/
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License as 
 *  published by the Free Software Foundation; either version 2 of the
 *  License, or (at your option) any later version. 
 *
 *  This program is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 *  USA.
 */
package edu.udo.cs.yale.gui;

import edu.udo.cs.yale.Yale;
import edu.udo.cs.yale.Experiment;
import edu.udo.cs.yale.operator.Operator;
import edu.udo.cs.yale.operator.OperatorChain;
import edu.udo.cs.yale.operator.parameter.ParameterType;
import edu.udo.cs.yale.tools.ParameterService;
import edu.udo.cs.yale.tools.Tools;

import javax.swing.*;
import javax.swing.table.*;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.BorderLayout;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.event.*;
import java.io.File;
import java.io.IOException;
import java.io.FileFilter;
import java.util.Map;
import java.util.HashMap;
import java.util.Vector;
import java.util.Iterator;

/** The save as template dialog assists the user in creating a new experiment template. Template experiments 
 *  are saved in the local .yale directory of the user. The name, description and additional parameters to set 
 *  can be specified by the user. */
public class ManageTemplatesDialog extends JDialog {

    private JList templateList = new JList();
    private Map templateMap = new HashMap();

    public ManageTemplatesDialog(MainFrame mainFrame) {
	super(mainFrame, "Manage Templates", true);

	JPanel rootPanel = new JPanel(new BorderLayout());
	rootPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
	GridBagLayout layout = new GridBagLayout();
	JPanel mainPanel = new JPanel(layout);
	GridBagConstraints c = new GridBagConstraints();
	c.fill = GridBagConstraints.BOTH;
	c.weightx = 1.0d;
	c.weighty = 0.0d;

	JPanel textPanel = SwingTools.createTextPanel("Manage Templates...",
						      "Please select templates to delete them. Only " +
						      "user defined templates can be removed.");
	c.gridwidth = GridBagConstraints.REMAINDER;
	layout.setConstraints(textPanel, c);
	mainPanel.add(textPanel);

	Component sep = Box.createVerticalStrut(10);
	c.gridwidth = GridBagConstraints.REMAINDER;
	layout.setConstraints(sep, c);
	mainPanel.add(sep);

	// add components to main panel
	File[] templateFiles = ParameterService.getUserYaleDir().listFiles(new FileFilter() {
		public boolean accept(File file) {
		    return file.getName().endsWith(".template");
		}
	    });
	for (int i = 0; i < templateFiles.length; i++) {
	    try {
		Template template = new Template(templateFiles[i]);
		templateMap.put(template.getName(), template);
	    } catch (Throwable e) {
		SwingTools.showErrorMessage("Cannot load template file '"+templateFiles[i]+"'", e);
	    }
	}
        
	JScrollPane listPane = new JScrollPane(templateList);
	c.gridwidth = GridBagConstraints.REMAINDER;
	c.weighty = 1.0d;
	layout.setConstraints(listPane, c);
	mainPanel.add(listPane);
	c.weighty = 0.0d;

	// buttons
	JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
	JButton deleteButton = new JButton("Delete");
	deleteButton.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) { delete(); }
	    });
	buttonPanel.add(deleteButton);
	JButton okButton = new JButton("Ok");
	okButton.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) { ok(); }
	    });
	buttonPanel.add(okButton);

	rootPanel.add(mainPanel, BorderLayout.CENTER);
	rootPanel.add(buttonPanel, BorderLayout.SOUTH);
	getContentPane().add(rootPanel);

	update();
	pack();
	setSize(250,400);
	setLocationRelativeTo(mainFrame);
    }

    private void update() {	
	Vector data = new Vector();
	Iterator i = templateMap.values().iterator();
	while (i.hasNext()) {
	    Template template = (Template)i.next();
	    data.add(template.getName());
	}
	templateList.setListData(data);
	repaint();
    }

    private void ok() {
	dispose();
    }

    private void delete() {
	Object[] selection = templateList.getSelectedValues();
	for (int i = 0; i < selection.length; i++) {
	    String name = (String)selection[i];
	    Template template = (Template)templateMap.remove(name);
	    File templateFile = template.getFile();
	    File expFile = new File(templateFile.getParent(), template.getFilename());
	    templateFile.delete();
	    expFile.delete();
	}
	update();
    }
}

⌨️ 快捷键说明

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