01: package net.sourceforge.pmd.util.viewer.gui;
02:
03: import net.sourceforge.pmd.util.viewer.model.ViewerModel;
04: import net.sourceforge.pmd.util.viewer.model.ViewerModelEvent;
05: import net.sourceforge.pmd.util.viewer.model.ViewerModelListener;
06: import net.sourceforge.pmd.util.viewer.util.NLS;
07:
08: import javax.swing.*;
09: import java.awt.Dimension;
10:
11: /**
12: * Panel for the XPath entry and editing
13: *
14: * @author Boris Gruschko ( boris at gruschko.org )
15: * @version $Id: XPathPanel.java 4217 2006-02-10 14:15:31Z tomcopeland $
16: */
17:
18: public class XPathPanel extends JTabbedPane implements
19: ViewerModelListener {
20: private ViewerModel model;
21: private JTextArea xPathArea;
22:
23: /**
24: * Constructs the panel
25: *
26: * @param model model to refer to
27: */
28: public XPathPanel(ViewerModel model) {
29: super (JTabbedPane.BOTTOM);
30: this .model = model;
31: init();
32: }
33:
34: private void init() {
35: model.addViewerModelListener(this );
36: xPathArea = new JTextArea();
37: setBorder(BorderFactory.createTitledBorder(BorderFactory
38: .createEtchedBorder(), NLS.nls("XPATH.PANEL.TITLE")));
39: add(new JScrollPane(xPathArea), NLS
40: .nls("XPATH.PANEL.EXPRESSION"));
41: add(new EvaluationResultsPanel(model), NLS
42: .nls("XPATH.PANEL.RESULTS"));
43: setPreferredSize(new Dimension(-1, 200));
44: }
45:
46: public String getXPathExpression() {
47: return xPathArea.getText();
48: }
49:
50: /**
51: * @see ViewerModelListener#viewerModelChanged(ViewerModelEvent)
52: */
53: public void viewerModelChanged(ViewerModelEvent e) {
54: switch (e.getReason()) {
55: case ViewerModelEvent.PATH_EXPRESSION_APPENDED:
56: if (e.getSource() != this ) {
57: xPathArea.append((String) e.getParameter());
58: }
59: setSelectedIndex(0);
60: break;
61: case ViewerModelEvent.CODE_RECOMPILED:
62: setSelectedIndex(0);
63: break;
64: }
65: }
66: }
|