001/* 002 * Copyright (c) 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 030/** 031 * 032 */ 033package org.kepler.gui; 034 035import java.awt.BorderLayout; 036import java.awt.Component; 037import java.awt.Container; 038import java.util.ArrayList; 039import java.util.List; 040import java.util.Vector; 041 042import javax.swing.JPanel; 043import javax.swing.JTabbedPane; 044 045import ptolemy.actor.gui.TableauFrame; 046import ptolemy.kernel.util.IllegalActionException; 047import ptolemy.kernel.util.NameDuplicationException; 048import ptolemy.kernel.util.NamedObj; 049 050/** 051 * A ViewPane consisting of 4 ViewPaneLocations. 052 * 053 * @author Aaron Schultz 054 * 055 */ 056public class SingleViewPane extends JPanel implements ViewPane { 057 058 private TableauFrame _frame; 059 private String _viewName; 060 private Vector<ViewPaneLocation> _locations; 061 062 /* 063 * The top level split pane that divides the JPanel into left and right 064 * halves. 065 */ 066 067 private JTabbedPane _ctp; 068 069 /** 070 * Constructor. Initializes available locations. 071 */ 072 public SingleViewPane() { 073 _locations = new Vector<ViewPaneLocation>(); 074 _locations.add(new ViewPaneLocation("C")); 075 } 076 077 /* 078 * (non-Javadoc) 079 * 080 * @see org.kepler.gui.ViewPane#getParentFrame() 081 */ 082 public TableauFrame getParentFrame() { 083 return _frame; 084 } 085 086 /* 087 * (non-Javadoc) 088 * 089 * @see 090 * org.kepler.gui.ViewPane#setParentFrame(ptolemy.actor.gui.TableauFrame) 091 */ 092 public void setParentFrame(TableauFrame parent) { 093 _frame = parent; 094 } 095 096 /* 097 * (non-Javadoc) 098 * 099 * @see org.kepler.gui.ViewPane#getViewName() 100 */ 101 public String getViewName() { 102 return _viewName; 103 } 104 105 public void setViewName(String viewName) { 106 _viewName = viewName; 107 } 108 109 /* 110 * (non-Javadoc) 111 * 112 * @see org.kepler.gui.ViewPane#initializeView() 113 */ 114 public void initializeView() throws Exception { 115 116 _ctp = new JTabbedPane(); 117 118 this.setLayout(new BorderLayout()); 119 this.add(_ctp, BorderLayout.CENTER); 120 121 } 122 123 /* 124 * (non-Javadoc) 125 * 126 * @see org.kepler.gui.ViewPane#getAvailableLocations() 127 */ 128 public Vector<ViewPaneLocation> getAvailableLocations() { 129 return _locations; 130 } 131 132 public boolean hasLocation(String locationName) { 133 for (int i = 0; i < _locations.size(); i++) { 134 if (_locations.elementAt(i).getName().equals(locationName)) { 135 return true; 136 } 137 } 138 return false; 139 } 140 141 /* 142 * (non-Javadoc) 143 * 144 * @see org.kepler.gui.ViewPane#addTabPane(org.kepler.gui.TabPane, 145 * org.kepler.gui.ViewPaneLocation) 146 */ 147 public void addTabPane(TabPane tabPane, ViewPaneLocation location) 148 throws Exception { 149 150 if (location.getName() == "C") { 151 _ctp.add(tabPane.getTabName(), (Component) tabPane); 152 } else { 153 throw new Exception( 154 "Unable to add " 155 + tabPane.getTabName() 156 + " TabPane to " 157 + getViewName() 158 + " ViewPane. " 159 + " The supplied ViewPaneLocation does not exist for this ViewPane."); 160 } 161 162 } 163 164 public Container getLocationContainer(String locationName) throws Exception { 165 166 if (locationName.equals("C")) { 167 return _ctp; 168 } else { 169 throw new Exception( 170 "Unable to find " 171 + locationName 172 + " ViewPaneLocation in the " 173 + getViewName() 174 + " ViewPane. " 175 + " The supplied ViewPaneLocation does not exist for this ViewPane."); 176 } 177 178 } 179 180 /** 181 * A factory that creates the library panel for the editors. 182 * 183 *@author Aaron Schultz 184 */ 185 public static class Factory extends ViewPaneFactory { 186 /** 187 * Create a factory with the given name and container. 188 * 189 *@param container 190 * The container. 191 *@param name 192 * The name of the entity. 193 *@exception IllegalActionException 194 * If the container is incompatible with this attribute. 195 *@exception NameDuplicationException 196 * If the name coincides with an attribute already in the 197 * container. 198 */ 199 public Factory(NamedObj container, String name) 200 throws IllegalActionException, NameDuplicationException { 201 super(container, name); 202 } 203 204 /** 205 * Create a library pane that displays the given library of actors. 206 * 207 * @return A new LibraryPaneTab that displays the library 208 */ 209 public ViewPane createViewPane(TableauFrame parent) { 210 211 SingleViewPane vp = new SingleViewPane(); 212 vp.setParentFrame(parent); 213 214 // use the name specified in the configuration to name the view 215 vp.setViewName(this.getName()); 216 217 return vp; 218 } 219 } 220 221 public List<TabPane> getTabPanes(String tabName) throws Exception { 222 List<TabPane> panes = new ArrayList<TabPane>(); 223 int index = -1; 224 index = _ctp.indexOfTab(tabName); 225 if (index > -1) { 226 panes.add((TabPane) _ctp.getComponentAt(index)); 227 } 228 return panes; 229 } 230}