001: package org.acm.seguin.pmd.swingui;
002:
003: import org.acm.seguin.pmd.PMDDirectory;
004: import org.acm.seguin.pmd.PMDException;
005:
006: import javax.swing.JButton;
007: import javax.swing.JDialog;
008: import javax.swing.JFrame;
009: import javax.swing.JPanel;
010: import javax.swing.JScrollPane;
011: import javax.swing.JSplitPane;
012: import javax.swing.UIManager;
013: import java.awt.BorderLayout;
014: import java.awt.Color;
015: import java.awt.event.ActionEvent;
016: import java.awt.event.ActionListener;
017: import java.io.File;
018:
019: /**
020: *
021: * @author Donald A. Leckie
022: * @since August 29, 2002
023: * @version $Revision: 1.1 $, $Date: 2003/07/29 20:51:59 $
024: */
025: class RulesClassSelectDialog extends JDialog {
026:
027: private DirectoryTree m_tree;
028: private DirectoryTable m_table;
029: private JSplitPane m_splitPane;
030: private JScrollPane m_treeScrollPane;
031: private JScrollPane m_tableScrollPane;
032: private File m_selectedClassFile;
033: private boolean m_selectWasPressed;
034:
035: /**
036: *******************************************************************************
037: *
038: * @param parentWindow
039: */
040: protected RulesClassSelectDialog(JFrame parentWindow)
041: throws PMDException {
042: super (parentWindow, "Rules Class File Selector", true);
043:
044: setSize(ComponentFactory.adjustWindowSize(1200, 800));
045: setLocationRelativeTo(PMDViewer.getViewer());
046: setResizable(true);
047: setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
048: createDirectoryTreeScrollPane();
049: createDirectoryTableScrollPane();
050: createDirectorySplitPane();
051: buildTree();
052: JPanel buttonPanel = createButtonPanel();
053: JPanel contentPanel = new JPanel(new BorderLayout());
054: contentPanel.add(m_splitPane, BorderLayout.CENTER);
055: contentPanel.add(buttonPanel, BorderLayout.SOUTH);
056:
057: getContentPane().add(contentPanel);
058: }
059:
060: /**
061: *********************************************************************************
062: *
063: */
064: private void createDirectoryTreeScrollPane() {
065: Color background;
066:
067: m_tree = new DirectoryTree("Rules Repository");
068: m_treeScrollPane = ComponentFactory.createScrollPane(m_tree);
069: background = UIManager.getColor("pmdTreeBackground");
070:
071: m_treeScrollPane.getViewport().setBackground(background);
072: }
073:
074: /**
075: *********************************************************************************
076: *
077: */
078: private void createDirectoryTableScrollPane() {
079: Color background;
080:
081: m_table = new DirectoryTable(m_tree, ".class");
082: m_tableScrollPane = ComponentFactory.createScrollPane(m_table);
083: background = UIManager.getColor("pmdTableBackground");
084:
085: m_tableScrollPane.getViewport().setBackground(background);
086: }
087:
088: /**
089: *********************************************************************************
090: *
091: */
092: private void createDirectorySplitPane() {
093: m_splitPane = ComponentFactory.createHorizontalSplitPane(
094: m_treeScrollPane, m_tableScrollPane);
095: }
096:
097: /**
098: *******************************************************************************
099: *
100: */
101: private void buildTree() throws PMDException {
102: PMDDirectory pmdDirectory = PMDDirectory.getDirectory();
103: String rulesDirectoryPath = pmdDirectory
104: .getRuleSetsDirectoryPath();
105: File[] rulesDirectory = { new File(rulesDirectoryPath) };
106: ((DirectoryTreeModel) m_tree.getModel())
107: .setupFiles(rulesDirectory);
108: m_tree.expandRootNode();
109: }
110:
111: /**
112: *******************************************************************************
113: *
114: */
115: private JPanel createButtonPanel() {
116: ActionListener selectActionListener = new SelectButtonActionListener();
117: ActionListener cancelActionListener = new CancelButtonActionListener();
118: JPanel buttonPanel = ComponentFactory.createButtonPanel();
119: JButton selectButton = ComponentFactory
120: .createSaveButton(selectActionListener);
121: JButton cancelButton = ComponentFactory
122: .createCancelButton(cancelActionListener);
123: selectButton.setText("Select");
124: buttonPanel.add(selectButton);
125: buttonPanel.add(cancelButton);
126:
127: return buttonPanel;
128: }
129:
130: /**
131: *******************************************************************************
132: *
133: * @return
134: */
135: protected File getSelectedClassFile() {
136: return m_selectedClassFile;
137: }
138:
139: /**
140: *******************************************************************************
141: *
142: * @return
143: */
144: protected boolean selectWasPressed() {
145: return m_selectWasPressed;
146: }
147:
148: /**
149: *******************************************************************************
150: *******************************************************************************
151: *******************************************************************************
152: */
153: private class SelectButtonActionListener implements ActionListener {
154:
155: /**
156: ********************************************************************
157: *
158: * @param event
159: */
160: public void actionPerformed(ActionEvent event) {
161: m_selectWasPressed = true;
162: m_selectedClassFile = m_table.getSelectedFile();
163: RulesClassSelectDialog.this .setVisible(false);
164: }
165: }
166:
167: /**
168: *******************************************************************************
169: *******************************************************************************
170: *******************************************************************************
171: */
172: private class CancelButtonActionListener implements ActionListener {
173:
174: /**
175: ********************************************************************
176: *
177: * @param event
178: */
179: public void actionPerformed(ActionEvent event) {
180: RulesClassSelectDialog.this .setVisible(false);
181: }
182: }
183: }
|