View Javadoc

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