001/* 002 * Copyright (c) 2009-2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: welker $' 006 * '$Date: 2010-05-06 05:21:26 +0000 (Thu, 06 May 2010) $' 007 * '$Revision: 24234 $' 008 * 009 * Permission is hereby granted, without written agreement and without 010 * license or royalty fees, to use, copy, modify, and distribute this 011 * software and its documentation for any purpose, provided that the above 012 * copyright notice and the following two paragraphs appear in all copies 013 * of this software. 014 * 015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 019 * SUCH DAMAGE. 020 * 021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 026 * ENHANCEMENTS, OR MODIFICATIONS. 027 * 028 */ 029 030package org.kepler.gui; 031 032import javax.swing.tree.TreePath; 033 034import ptolemy.kernel.util.IllegalActionException; 035import ptolemy.kernel.util.NameDuplicationException; 036import ptolemy.kernel.util.NamedObj; 037import ptolemy.vergil.tree.PTree; 038 039/** 040 * This class implements a simple result display where the results from the 041 * search are simply highlighted in the tree. Any subtree where a result may be 042 * located is also expanded. 043 * 044 * @author Chad Berkley 045 */ 046public class ResultHighlighter extends LibrarySearchResultPane { 047 /** 048 * the constructor passes in the library to highlight the results in and the 049 * results to highlight. if results is null, the tree is built fully 050 * collapsed with no highlights. 051 * 052 * @param library 053 * the library to highlight the results in 054 * @param results 055 * the results to highlight 056 */ 057 public ResultHighlighter(PTree library, LibrarySearchResults results) 058 throws IllegalActionException { 059 super(library, results); 060 } 061 062 /** 063 * this method allows the search results to be updated in the panel 064 * 065 * @param results 066 * the results to update to 067 */ 068 public void update(LibrarySearchResults results) { 069 this.results = results; 070 if (results != null) { 071 TreePath[] tp = createTreePathArray(); 072 library.clearSelection(); // clear the current selections 073 collapseAll(); 074 for (int i = 0; i < tp.length; i++) { 075 // library.expandPath(tp[i]); 076 library.addSelectionPath(tp[i]); 077 } 078 } 079 } 080 081 /** 082 * A factory that creates the searcher to search the library 083 */ 084 public static class Factory extends LibrarySearchResultPaneFactory { 085 /** 086 * Create an factory with the given name and container. 087 * 088 * @param container 089 * The container. 090 * @param name 091 * The name of the entity. 092 * @exception IllegalActionException 093 * If the container is incompatible with this attribute. 094 * @exception NameDuplicationException 095 * If the name coincides with an attribute already in the 096 * container. 097 */ 098 public Factory(NamedObj container, String name) 099 throws IllegalActionException, NameDuplicationException { 100 super(container, name); 101 } 102 103 /** 104 * creates a ResultsHighlighter and returns it. 105 * 106 * @param _libraryModel 107 * the model containing the actor library 108 * @return A new LibraryPane that displays the library 109 */ 110 public LibrarySearchResultPane createLibrarySearchResultPane( 111 PTree library, LibrarySearchResults results) 112 throws IllegalActionException { 113 return new ResultHighlighter(library, results); 114 } 115 } 116}