001/* 002 * Copyright (c) 2004-2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: aschultz $' 006 * '$Date: 2010-12-23 19:01:04 +0000 (Thu, 23 Dec 2010) $' 007 * '$Revision: 26600 $' 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 java.awt.Dimension; 033 034import javax.swing.JPanel; 035import javax.swing.JScrollPane; 036import javax.swing.JTree; 037 038import org.kepler.objectmanager.library.LibraryManager; 039 040import ptolemy.actor.gui.TableauFrame; 041import ptolemy.kernel.util.IllegalActionException; 042import ptolemy.kernel.util.NameDuplicationException; 043import ptolemy.kernel.util.NamedObj; 044import ptolemy.vergil.tree.EntityTreeModel; 045import ptolemy.vergil.tree.PTree; 046 047/** 048 * A simple pane used to display the contents of the library tree. 049 * 050 * @author Matt Jones 051 * @version $Id: BasicLibraryPane.java 26600 2010-12-23 19:01:04Z aschultz $ 052 * @since Kepler 1.0 053 */ 054public class BasicLibraryPane extends JPanel implements TabPane { 055 056 private String _name; 057 058 private JTree _library; 059 private JScrollPane _libraryScrollPane; 060 061 private TableauFrame _frame; 062 063 /** 064 * Construct a new library pane for displaying the tree of actors that can 065 * be dragged to the graph editor. 066 * 067 * @param _libraryModel 068 * the model containing the library to be displayed 069 */ 070 public BasicLibraryPane() { 071 super(); 072 } 073 074 /** 075 * Implementation of TabPane getName() 076 */ 077 public String getTabName() { 078 return _name; 079 } 080 081 public void setTabName(String name) { 082 _name = name; 083 } 084 085 /** 086 * Implementation of TabPane setParentFrame(TableauFrame) 087 */ 088 public void setParentFrame(TableauFrame parent) { 089 _frame = parent; 090 } 091 092 /** 093 * Implementation of TabPane getParentFrame() 094 */ 095 public TableauFrame getParentFrame() { 096 return _frame; 097 } 098 099 /** 100 * Implementation of TabPane initializeTab() 101 */ 102 public void initializeTab() throws Exception { 103 104 // get the tree model from the LibraryManager 105 LibraryManager lman = LibraryManager.getInstance(); 106 EntityTreeModel libraryModel = lman.getTreeModel(); 107 108 _library = new PTree(libraryModel); 109 _library.setRootVisible(false); 110 _libraryScrollPane = new JScrollPane(_library); 111 _libraryScrollPane.setMinimumSize(new Dimension(200, 200)); 112 _libraryScrollPane.setPreferredSize(new Dimension(200, 325)); 113 this.add("Components", _libraryScrollPane); 114 115 } 116 117 /** 118 * A factory that creates the library panel for the editors. 119 * 120 *@author Aaron Schultz 121 */ 122 public static class Factory extends TabPaneFactory { 123 /** 124 * Create a factory with the given name and container. 125 * 126 *@param container 127 * The container. 128 *@param name 129 * The name of the entity. 130 *@exception IllegalActionException 131 * If the container is incompatible with this attribute. 132 *@exception NameDuplicationException 133 * If the name coincides with an attribute already in the 134 * container. 135 */ 136 public Factory(NamedObj container, String name) 137 throws IllegalActionException, NameDuplicationException { 138 super(container, name); 139 } 140 141 /** 142 * Create a library pane that displays the given library of actors. 143 * 144 * @return A new LibraryPaneTab that displays the library 145 */ 146 public TabPane createTabPane() { 147 BasicLibraryPane blp = new BasicLibraryPane(); 148 blp.setTabName(this.getName()); 149 return blp; 150 } 151 } 152}