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

📄 workspaceconfiguration.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	}

	private void init() {
		this.setSelectionRow(0);
	}

	private void reset() {
		this.setSelectionRow(workspaceconfiguration.getCurrentIndex());
	}

	private MouseAdapter TreeMouseListener() {
		return new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				TreePath path = getPathForLocation(e.getX(), e.getY());
				if (e.getClickCount() == 1 && e.getButton() == MouseEvent.BUTTON3) {
					// show popupmenu
					if (path == null) {
						workspaceconfiguration.setFarFromTree(true);
						workspacepopupmenu.setStyle(WorkspacePopupMenu.ADD);
						workspacepopupmenu.setLocation(new Point(e.getX(), e.getY()));
						workspacepopupmenu.show((Component) e.getSource(), e.getX(), e.getY());
					} else {
						workspaceconfiguration.setFarFromTree(false);
						workspacepopupmenu.setStyle(WorkspacePopupMenu.ADD_DELETE);
						workspacepopupmenu.setLocation(new Point(e.getX(), e.getY()));
						workspacepopupmenu.show((Component) e.getSource(), e.getX(), e.getY());
					}
				} else if (e.getButton() == MouseEvent.BUTTON1) {
					if (path != null) {
						WorkspaceTreeNode workspacetreenode = (WorkspaceTreeNode) path.getLastPathComponent();
						if (m_RootNode.getIndex(workspacetreenode) == workspaceconfiguration.getCurrentIndex()) {
							return;
						}
						int index = workspaceconfiguration.getCurrentIndex();
						if (!workspaceconfiguration.setCurrent(m_RootNode.getIndex(workspacetreenode))) {
							reset();
						} else {
							if (workspaceconfiguration.isNew()) {
								if (workspaceconfiguration.getCountofWorkspace() < m_RootNode.getChildCount()) {
									removeWorkspace(index);
								}
							}
						}
					}
				}
			}
		};
	}

	/**
	 * Xiaojun Chen. July 12, 2006.
	 * 
	 * @see javax.swing.event.TreeSelectionListener#valueChanged(TreeSelectionEvent)
	 */
	public void valueChanged(TreeSelectionEvent e) {
	}
}
class WorkspaceInformation extends JPanel implements ActionListener, DocumentListener {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private WorkspaceConfiguration workspaceconfiguration;
	private JScrollPane detailScrollPanel;
	private JPanel detailPanel;
	private JLabel nameLabel;
	private JLabel pathLabel;
	private JLabel descriptionLabel;
	private JTextField nameText;
	private JTextField pathText;
	private JTextField descriptionText;
	private JPanel buttonPanel;
	private JButton m_ButtonApply;
	private JButton m_ButtonReset;
	private JButton m_ButtonClose;
	private JButton pathSelect;
	private JFileChooser pathChooser;
	private boolean modified;
	private boolean initWorkspace;

	WorkspaceInformation(WorkspaceConfiguration workspaceconfiguration) {
		super();
		this.workspaceconfiguration = workspaceconfiguration;
		createUI();
	}

	private void createUI() {
		createDetailPanel();
		createButtonPanel();
		this.add(detailScrollPanel, BorderLayout.CENTER);
		this.add(buttonPanel, BorderLayout.SOUTH);
	}

	private void createDetailPanel() {
		detailScrollPanel = new JScrollPane();
		detailPanel = new JPanel();
		detailPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Resource
				.srcStr("WorkspaceInformation")), BorderFactory.createEmptyBorder(2, 0, 0, 0)));
		nameLabel = new JLabel(Resource.srcStr("WorkspaceConfiguration_name"));
		pathLabel = new JLabel(Resource.srcStr("WorkspaceConfiguration_path"));
		pathSelect = new JButton(Resource.srcStr("m_ButtonSelect"));
		pathSelect.setSize(new Dimension(40, 25));
		pathSelect.addActionListener(this);
		descriptionLabel = new JLabel(Resource.srcStr("WorkspaceConfiguration_description"));
		// nameLabel.setFont(new Font("宋体",Font.PLAIN,19));
		// pathLabel.setFont(new Font("宋体",Font.PLAIN,19));
		// descriptionLabel.setFont(new Font("宋体",Font.PLAIN,19));
		nameText = new JTextField();
		pathText = new JTextField();
		descriptionText = new JTextField();
		nameText.setPreferredSize(new Dimension(135, 25));
		pathText.setPreferredSize(new Dimension(135, 25));
		pathText.setEditable(false);
		descriptionText.setPreferredSize(new Dimension(135, 25));
		addDocumentListener();
		JPanel namePanel = new JPanel();
		namePanel.add(nameLabel, BorderLayout.CENTER);
		namePanel.add(nameText, BorderLayout.EAST);
		JPanel pathPanel = new JPanel();
		pathPanel.add(pathLabel, BorderLayout.CENTER);
		pathPanel.add(pathText, BorderLayout.EAST);
		JPanel descriptionPanel = new JPanel();
		descriptionPanel.add(descriptionLabel, BorderLayout.CENTER);
		descriptionPanel.add(descriptionText, BorderLayout.EAST);
		JPanel leftPanel = new JPanel(new GridLayout(3, 1, 5, 10));
		leftPanel.add(namePanel);
		leftPanel.add(pathPanel);
		leftPanel.add(descriptionPanel);
		JPanel selectPanel = new JPanel(new GridLayout(3, 1, 5, 10));
		selectPanel.add(new JLabel());
		selectPanel.add(pathSelect);
		selectPanel.add(new JLabel());
		detailPanel.add(leftPanel, BorderLayout.CENTER);
		detailPanel.add(selectPanel, BorderLayout.EAST);
		detailScrollPanel.getViewport().add(detailPanel);
	}

	public void resetLocale() {
		((TitledBorder)((CompoundBorder)detailPanel.getBorder()).getOutsideBorder()).setTitle(Resource
				.srcStr("WorkspaceInformation"));
		nameLabel.setText(Resource.srcStr("WorkspaceConfiguration_name"));
		pathLabel.setText(Resource.srcStr("WorkspaceConfiguration_name"));
		pathSelect.setText(Resource.srcStr("m_ButtonSelect"));
		descriptionLabel.setText(Resource.srcStr("WorkspaceConfiguration_description"));
		m_ButtonApply.setText(Resource.srcStr("m_ButtonApply"));
		m_ButtonReset.setText(Resource.srcStr("m_ButtonReset"));
		m_ButtonClose.setText(Resource.srcStr("m_ButtonClose"));
	}
	
	/**
	 * Add DocumentListener to all textfields and textareas.
	 */
	private void addDocumentListener() {
		nameText.getDocument().addDocumentListener(this);
		pathText.getDocument().addDocumentListener(this);
		descriptionText.getDocument().addDocumentListener(this);
	}

	private void createButtonPanel() {
		buttonPanel = new JPanel(new GridLayout(1, 3, 10, 5));
		m_ButtonApply = new JButton(Resource.srcStr("m_ButtonApply"));
		m_ButtonReset = new JButton(Resource.srcStr("m_ButtonReset"));
		m_ButtonClose = new JButton(Resource.srcStr("m_ButtonClose"));
		buttonPanel.add(m_ButtonApply);
		buttonPanel.add(m_ButtonReset);
		buttonPanel.add(m_ButtonClose);
		m_ButtonApply.addActionListener(this);
		m_ButtonReset.addActionListener(this);
		m_ButtonClose.addActionListener(this);
	}

	public void getContent() {
		Workspace workspace = workspaceconfiguration.getCurrentWorkspace();
		if (workspace == null || !workspace.isvalid()) {
			return;
		}
		initWorkspace = true;
		nameText.setText(workspace.getName());
		pathText.setText(workspace.getPath());
		descriptionText.setText(workspace.getDescription());
		initWorkspace = false;
		modified = false;
	}

	public void getContent(Workspace workspace) {
		if (workspace == null || !workspace.isvalid()) {
			return;
		}
		initWorkspace = true;
		nameText.setText(workspace.getName());
		pathText.setText(workspace.getPath());
		descriptionText.setText(workspace.getDescription());
		initWorkspace = false;
		modified = true;
	}

	// save content to workspaces
	public void setContent() {
		if (!modified) {
			return;
		}
		if (!workspaceconfiguration.saveWorkspace()) {
			MessageDialog.showMessageDialog(workspaceconfiguration, Resource.srcStr("workspace_saveFailure"));
		}
		modified = false;
	}

	public boolean clear() {
		modified = false;
		nameText.setText("");
		pathText.setText("");
		descriptionText.setText("");
		return true;
	}

	public Workspace getCurrentWorkspace() {
		return new Workspace(nameText.getText(), pathText.getText(), descriptionText.getText());
	}

	public void actionPerformed(ActionEvent e) {
		Object source = e.getSource();
		if (source == m_ButtonApply) {
			setContent();
		} else if (source == m_ButtonReset) {
			getContent();
		} else if (source == m_ButtonClose) {
			workspaceconfiguration.close();
		} else if (source == pathSelect) {
			selectPath();
		}
	}

	private void selectPath() {
		if (pathChooser == null) {
			pathChooser = new JFileChooser();
			pathChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		}
		pathChooser.setCurrentDirectory(new File(pathText.getText()));
		int returnVal = pathChooser.showOpenDialog(this);
		if (returnVal == JFileChooser.APPROVE_OPTION) {
			File path = pathChooser.getSelectedFile();
			if (path != null && path.exists()) {
				pathText.setText(path.getAbsolutePath());
			}
		}
	}

	void setMoidified(boolean ismodified) {
		if (!initWorkspace) {
			modified = ismodified;
		}
	}

	public void insertUpdate(DocumentEvent e) {
		setMoidified(true);
	}

	public void removeUpdate(DocumentEvent e) {
		setMoidified(true);
	}

	public void changedUpdate(DocumentEvent e) {
		setMoidified(true);
	}

	public boolean isMoidified() {
		return modified;
	}
}
class WorkspaceTreeNode extends DefaultMutableTreeNode {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public WorkspaceTreeNode(String name) {
		super(name);
	}
}
class WorkspacePopupMenu extends JPopupMenu implements ActionListener {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public static final int ADD_DELETE = 0;
	public static final int ADD = 1;
	private JMenuItem m_MenuAdd = new JMenuItem();
	private JMenuItem m_MenuDelete = new JMenuItem();
	private WorkspaceConfiguration workspaceconfiguration;

	public WorkspacePopupMenu(WorkspaceConfiguration workspaceconfiguration) {
		super();
		this.workspaceconfiguration = workspaceconfiguration;
		createMenu();
	}

	private void createMenu() {
		m_MenuAdd.setText(Resource.srcStr("workspacepopupmenu_Add"));
		m_MenuDelete.setText(Resource.srcStr("workspacepopupmenu_Delete"));
		m_MenuAdd.addActionListener(this);
		m_MenuDelete.addActionListener(this);
		add(m_MenuAdd);
	}

	public void setStyle(int style) {
		switch (style) {
		case ADD_DELETE:
			add(m_MenuDelete);
			break;
		case ADD:
			remove(m_MenuDelete);
			break;
		}
	}

	public void resetLocale() {
		m_MenuAdd.setText(Resource.srcStr("workspacepopupmenu_Add"));
		m_MenuDelete.setText(Resource.srcStr("workspacepopupmenu_Delete"));
	}
	
	public void actionPerformed(ActionEvent e) {
		Object source = e.getSource();
		if (source == m_MenuAdd) {
			if (!workspaceconfiguration.addWorkspace()) {
				MessageDialog.showMessageDialog(workspaceconfiguration, Resource.srcStr("addWorkspace_failure"));
			}
		} else if (source == m_MenuDelete) {
			workspaceconfiguration.deleteWorkspace();
		}
	}
}

⌨️ 快捷键说明

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