?? cmsanttaskselectiontreedialog.java
字號:
/*
* File : $Source: /usr/local/cvs/opencms/src-components/org/opencms/util/ant/CmsAntTaskSelectionTreeDialog.java,v $
* Date : $Date: 2006/03/27 14:53:01 $
* Version: $Revision: 1.3 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* For further information about Alkacon Software GmbH, please see the
* company website: http://www.alkacon.com
*
* For further information about OpenCms, please see the
* project website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.opencms.util.ant;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.StringTokenizer;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.border.Border;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
/**
* This is a highly configurable Swing GUI dialog for selection.
* <p>
*
* @author Michael Moossen (original non-tree version)
* @author Achim Westermann (modified tree version)
*
* @version $Revision: 1.3 $
*
* @since 6.1.6
*
* @see CmsAntTaskSelectionPrompt
*/
public class CmsAntTaskSelectionTreeDialog extends JDialog implements ActionListener {
/** Constant for border width. */
private static final int C_BORDER_SIZE = 10;
/** Serial version UID required for safe serialization. */
private static final long serialVersionUID = -8439685952987222098L;
/** Aborted flag. */
protected boolean m_aborted = false;
/** The list of all module names. * */
private List m_allModuleList;
/** Border. */
private final Border m_border = BorderFactory.createEmptyBorder(C_BORDER_SIZE, C_BORDER_SIZE, 0, C_BORDER_SIZE);
/** Panel for buttons. */
private final JPanel m_buttons = new JPanel();
/** Cancel button. */
private final JButton m_cancel = new JButton("Cancel");
/** Main Panel. */
private final JPanel m_content = new JPanel();
/** Label for prompt. */
private JLabel m_label = null;
/** Ok button. */
private final JButton m_ok = new JButton("Ok");
/** Associated ant task. */
private final CmsAntTaskSelectionTreePrompt m_promptTask;
/** Select all button. */
private final JButton m_selAll = new JButton("All");
/** Select none button. */
private final JButton m_selNone = new JButton("None");
/** The tree for selection of sets of modudles. . */
private JTree m_tree;
/**
* Default Constructor.
* <p>
*
* @param promptTask the <code>{@link CmsAntTaskSelectionPrompt}</code> object.
* <p>
*/
public CmsAntTaskSelectionTreeDialog(CmsAntTaskSelectionTreePrompt promptTask) {
super((JFrame)null, promptTask.getTitle(), true);
m_promptTask = promptTask;
m_label = new JLabel(m_promptTask.getPrompt());
addWindowListener(new WindowAdapter() {
public void windowClosed(WindowEvent e) {
setVisible(false);
}
});
getRootPane().setDefaultButton(m_ok);
Container contentPane = getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
m_label.setBorder(m_border);
if (!m_promptTask.isSingleSelection()) {
JPanel p1 = new JPanel();
p1.add(new JLabel("Select: "));
m_selAll.addActionListener(this);
p1.add(m_selAll);
m_selNone.addActionListener(this);
p1.add(m_selNone);
JPanel p = new JPanel(new BorderLayout());
p.add(m_label, BorderLayout.NORTH);
p.add(p1, BorderLayout.SOUTH);
contentPane.add(p);
} else {
getContentPane().add(m_label);
}
JScrollPane scrollpane = new JScrollPane(m_content);
scrollpane.setBorder(m_border);
scrollpane.setPreferredSize(new Dimension(300, 800));
// parse the String-list to a clean list as it is not only used for tree-creation but for
// tree-selection determination too:
this.parseModuleList();
TreeModel treeModel = createTree();
m_tree = new SelectionTree();
m_tree.setModel(treeModel);
m_tree.setRootVisible(false);
m_tree.setShowsRootHandles(true);
expandTree(new TreePath(treeModel.getRoot()));
selectDefaultNodes((DefaultMutableTreeNode)treeModel.getRoot(), "", new TreePath(treeModel.getRoot()));
// layout: let the tree start in upper left edge instead of being centered within the pane
// - it would start to move as it expands and changes bounds.
m_content.setLayout(new GridLayout(1, 1));
m_content.add(m_tree);
m_content.setBorder(BorderFactory.createLoweredBevelBorder());
contentPane.add(scrollpane);
m_buttons.setBorder(BorderFactory.createEmptyBorder(
C_BORDER_SIZE,
C_BORDER_SIZE,
C_BORDER_SIZE / 2,
C_BORDER_SIZE));
m_ok.addActionListener(this);
m_buttons.add(m_ok);
m_cancel.addActionListener(this);
m_buttons.add(m_cancel);
getContentPane().add(m_buttons, BorderLayout.SOUTH);
pack();
}
/**
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source == m_ok) {
m_aborted = false;
setVisible(false);
} else if (source == m_cancel) {
m_aborted = true;
setVisible(false);
} else if (source == m_selAll) {
m_tree.setSelectionPath(new TreePath(m_tree.getModel().getRoot()));
} else if (source == m_selNone) {
m_tree.clearSelection();
}
m_tree.invalidate();
// m_tree.cancelEditing();
m_tree.repaint();
}
/**
* Returns <code>null</code> if the dialog was canceled, or a list of selected items if not.
* <p>
*
* @return the user selection
*/
public String getSelection() {
center();
setVisible(true);
// Ret is the complete String with all modules separated by ... look at that constant
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -