gt: 	if (index < resultsTable.getRowCount()) {
context: // $Id: TabResults.java 132 2010-09-26 23:32:33Z marcusvnac $
  // Copyright (c) 1996-2008 The Regents of the University of California. All
  // Rights Reserved. Permission to use, copy, modify, and distribute this
  // software and its documentation without fee, and without a written
  // agreement is hereby granted, provided that the above copyright notice
  // and this paragraph appear in all copies. This software program and
  // documentation are copyrighted by The Regents of the University of
  // California. The software program and documentation are supplied "AS
  // IS", without any accompanying services from The Regents. The Regents
  // does not warrant that the operation of the program will be
  // uninterrupted or error-free. The end-user understands that the program
  // was developed for research purposes and is advised not to rely
  // exclusively on the program for any reason. IN NO EVENT SHALL THE
  // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
  // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
  // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
  // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
  // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
  // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
  // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
  // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
  // UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  
  package org.argouml.ui;
  
  import java.awt.BorderLayout;
  import java.awt.Dimension;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.awt.event.KeyEvent;
  import java.awt.event.KeyListener;
  import java.awt.event.MouseEvent;
  import java.awt.event.MouseListener;
  import java.util.ArrayList;
  import java.util.Enumeration;
  import java.util.Iterator;
  import java.util.List;
  
  import javax.swing.BorderFactory;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  import javax.swing.JScrollPane;
  import javax.swing.JSplitPane;
  import javax.swing.JTable;
  import javax.swing.ListSelectionModel;
  import javax.swing.event.ListSelectionEvent;
  import javax.swing.event.ListSelectionListener;
  
  
  import org.argouml.application.api.AbstractArgoJPanel;
  import org.argouml.i18n.Translator;
  import org.argouml.ui.targetmanager.TargetManager;
  import org.argouml.uml.ChildGenRelated;
  import org.argouml.uml.PredicateSearch;
  import org.argouml.uml.TMResults;
  import org.argouml.uml.diagram.ArgoDiagram;
  import org.argouml.util.ChildGenerator;
  
  
  /**
   * The results tab for the find dialog.
   * <p>
   * NOTE: An incompatible change was made to the public API for this class
   * before the release of ArgoUML 0.26 to remove exposed internal implementation
   * details (GEF).
   */
  public class TabResults
          extends AbstractArgoJPanel
          implements
                  Runnable,
                  MouseListener,
                  ActionListener,
                  ListSelectionListener,
                  KeyListener {
      
      private static int numJumpToRelated;
  
      /**
       * Insets in pixels.
       */
      private static final int INSET_PX = 3;
  
      private PredicateSearch pred;
      private ChildGenerator cg;
      private Object root;
      private JSplitPane mainPane;
      private List results = new ArrayList();
      private List related = new ArrayList();
      private List<ArgoDiagram> diagrams = new ArrayList<ArgoDiagram>();
      private boolean relatedShown;
  
      private JLabel resultsLabel = new JLabel();
      private JTable resultsTable;
      private TMResults resultsModel;
  
      private JLabel relatedLabel = new JLabel();
      private JTable relatedTable = new JTable(4, 4);
      private TMResults relatedModel = new TMResults();
  
      /**
       * The constructor.
       *
       */
      public TabResults() {
  	this(true);
      }
  
      /**
       * The constructor.
       *
       * @param showRelated true if related results should be shown
       */
      public TabResults(boolean showRelated) {
  	super("Results", true);
  	relatedShown = showRelated;
  	setLayout(new BorderLayout());
  	resultsTable = new JTable(10, showRelated ? 4 : 3);
  	resultsModel = new TMResults(showRelated);
  
  	JPanel resultsW = new JPanel();
  	JScrollPane resultsSP = new JScrollPane(resultsTable);
  	resultsW.setLayout(new BorderLayout());
  	resultsLabel.setBorder(BorderFactory.createEmptyBorder(
                  INSET_PX, INSET_PX, INSET_PX, INSET_PX));
  	resultsW.add(resultsLabel, BorderLayout.NORTH);
  	resultsW.add(resultsSP, BorderLayout.CENTER);
  	resultsTable.setModel(resultsModel);
  	resultsTable.addMouseListener(this);
  	resultsTable.addKeyListener(this);
  	resultsTable.getSelectionModel().addListSelectionListener(
  								   this);
  	resultsTable.setSelectionMode(
  				       ListSelectionModel.SINGLE_SELECTION);
  	resultsW.setMinimumSize(new Dimension(100, 100));
  
  	JPanel relatedW = new JPanel();
  	if (relatedShown) {
  	    JScrollPane relatedSP = new JScrollPane(relatedTable);
  	    relatedW.setLayout(new BorderLayout());
              relatedLabel.setBorder(BorderFactory.createEmptyBorder(
                      INSET_PX, INSET_PX, INSET_PX, INSET_PX));
  	    relatedW.add(relatedLabel, BorderLayout.NORTH);
  	    relatedW.add(relatedSP, BorderLayout.CENTER);
  	    relatedTable.setModel(relatedModel);
  	    relatedTable.addMouseListener(this);
  	    relatedTable.addKeyListener(this);
  	    relatedW.setMinimumSize(new Dimension(100, 100));
  	}
  
  	if (relatedShown) {
  	    mainPane =
  		new JSplitPane(JSplitPane.VERTICAL_SPLIT,
  			       resultsW,
  			       relatedW);
  	    add(mainPane, BorderLayout.CENTER);
  	} else {
  	    add(resultsW, BorderLayout.CENTER);
  	}
  
      }
  
      /**
       * @param p the predicate for the search
       *            <p>
       *            NOTE: The type of this parameter was changed incompatibly
       *            before 0.26 from org.argouml.uml.PredicateFind to
       *            org.argouml.uml.PredicateSearch.
       */
      public void setPredicate(PredicateSearch p) {
          pred = p;
      }
  
      /**
       * @param r the root object for the search
       */
      public void setRoot(Object r) {
  	root = r;
      }
  
      /**
       * @param gen the generator.
       *            <p>
       *            NOTE: The type of this parameter was changed incompatibly
       *            before 0.26 from org.tigris.gef.util.ChildGenerator to
       *            org.argouml.util.ChildGenerator.
       */
      public void setGenerator(ChildGenerator gen) {
          cg = gen;
      }
  
      /**
       * @param res the results
       * @param dia the diagrams
       */
      public void setResults(List res, List dia) {
          results = res;
          diagrams = dia;
          Object[] msgArgs = {Integer.valueOf(results.size()) };
          resultsLabel.setText(Translator.messageFormat(
              "dialog.tabresults.results-items", msgArgs));
          resultsModel.setTarget(results, diagrams);
          relatedModel.setTarget((List) null, (List) null);
          relatedLabel.setText(
              Translator.localize("dialog.tabresults.related-items"));
      }
      
      /*
       * @see org.argouml.ui.AbstractArgoJPanel#spawn()
       */
      public AbstractArgoJPanel spawn() {
  	TabResults newPanel = (TabResults) super.spawn();
  	if (newPanel != null) {
  	    newPanel.setResults(results, diagrams);
  	}
  	return newPanel;
      }
  
      /**
       * Handle a doubleclick on the results tab.
       */
      public void doDoubleClick() {
  	myDoubleClick(resultsTable);
      }
  
      /**
       * Select the result at the given index.
       *
       * @param index the given index
       */
      public void selectResult(int index) {
  