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