001/* 002 * Copyright (c) 2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: crawl $' 006 * '$Date: 2015-10-28 21:00:47 +0000 (Wed, 28 Oct 2015) $' 007 * '$Revision: 34133 $' 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.JSplitPane; 044import javax.swing.JTabbedPane; 045import javax.swing.plaf.basic.BasicTabbedPaneUI; 046 047import ptolemy.actor.gui.TableauFrame; 048import ptolemy.kernel.util.IllegalActionException; 049import ptolemy.kernel.util.NameDuplicationException; 050import ptolemy.kernel.util.NamedObj; 051 052/** 053 * A ViewPane consisting of 2 vertical (side by side) ViewPaneLocations. 054 * 055 * @author Aaron Schultz 056 * 057 */ 058public class DualVerticalViewPane extends JPanel implements ViewPane { 059 060 private TableauFrame _frame; 061 private String _viewName; 062 private Vector<ViewPaneLocation> _locations; 063 064 /* 065 * The top level split pane that divides the JPanel into left and right 066 * halves. 067 */ 068 private JSplitPane _westEastSplitPane; 069 070 /* 071 * The two JTabbedPanes. These are the 072 * containers that the TabPanes are added to and each corresponds to a 073 * ViewPaneLocation. 074 */ 075 private JTabbedPane _wtp; 076 private JTabbedPane _etp; 077 078 /** 079 * Constructor. Initializes available locations. 080 */ 081 public DualVerticalViewPane() { 082 _locations = new Vector<ViewPaneLocation>(); 083 _locations.add(new ViewPaneLocation("W")); 084 _locations.add(new ViewPaneLocation("E")); 085 } 086 087 /* 088 * (non-Javadoc) 089 * 090 * @see org.kepler.gui.ViewPane#getParentFrame() 091 */ 092 @Override 093 public TableauFrame getParentFrame() { 094 return _frame; 095 } 096 097 /* 098 * (non-Javadoc) 099 * 100 * @see 101 * org.kepler.gui.ViewPane#setParentFrame(ptolemy.actor.gui.TableauFrame) 102 */ 103 @Override 104 public void setParentFrame(TableauFrame parent) { 105 _frame = parent; 106 } 107 108 /* 109 * (non-Javadoc) 110 * 111 * @see org.kepler.gui.ViewPane#getViewName() 112 */ 113 @Override 114 public String getViewName() { 115 return _viewName; 116 } 117 118 public void setViewName(String viewName) { 119 _viewName = viewName; 120 } 121 122 /* 123 * (non-Javadoc) 124 * 125 * @see org.kepler.gui.ViewPane#initializeView() 126 */ 127 @Override 128 public void initializeView() throws Exception { 129 130 _wtp = new JTabbedPane(); 131 _etp = new JTabbedPane(); 132 133 // hide the tab if only one pane is present. for the workflow 134 // tab displaying the canvas, this saves some vertical space since 135 // there is only one tabbed in this pane. 136 _etp.setUI(new BasicTabbedPaneUI() { 137 @Override 138 protected int calculateTabAreaHeight(int tabPlacement, int horizRunCount, int maxTabHeight) { 139 if(_etp.getTabCount() > 1) { 140 return super.calculateTabAreaHeight(tabPlacement, horizRunCount, maxTabHeight); 141 } else { 142 return -10; 143 } 144 } 145 }); 146 147 _westEastSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true); 148 _westEastSplitPane.setOneTouchExpandable(true); 149 _westEastSplitPane.setLeftComponent(_wtp); 150 _westEastSplitPane.setRightComponent(_etp); 151 152 this.setLayout(new BorderLayout()); 153 this.add(_westEastSplitPane, BorderLayout.CENTER); 154 155 } 156 157 /* 158 * (non-Javadoc) 159 * 160 * @see org.kepler.gui.ViewPane#getAvailableLocations() 161 */ 162 public Vector<ViewPaneLocation> getAvailableLocations() { 163 return _locations; 164 } 165 166 @Override 167 public boolean hasLocation(String locationName) { 168 for (int i = 0; i < _locations.size(); i++) { 169 if (_locations.elementAt(i).getName().equals(locationName)) { 170 return true; 171 } 172 } 173 return false; 174 } 175 176 /* 177 * (non-Javadoc) 178 * 179 * @see org.kepler.gui.ViewPane#addTabPane(org.kepler.gui.TabPane, 180 * org.kepler.gui.ViewPaneLocation) 181 */ 182 @Override 183 public void addTabPane(TabPane tabPane, ViewPaneLocation location) 184 throws Exception { 185 186 if (location.getName() == "W") { 187 _wtp.add(tabPane.getTabName(), (Component) tabPane); 188 } else if (location.getName() == "E") { 189 _etp.add(tabPane.getTabName(), (Component) tabPane); 190 } else { 191 throw new Exception( 192 "Unable to add " 193 + tabPane.getTabName() 194 + " TabPane to " 195 + getViewName() 196 + " ViewPane. " 197 + " The supplied ViewPaneLocation does not exist for this ViewPane."); 198 } 199 200 } 201 202 @Override 203 public Container getLocationContainer(String locationName) throws Exception { 204 205 if (locationName.equals("W")) { 206 return _wtp; 207 } else if (locationName.equals("E")) { 208 return _etp; 209 } else { 210 throw new Exception( 211 "Unable to find " 212 + locationName 213 + " ViewPaneLocation in the " 214 + getViewName() 215 + " ViewPane. " 216 + " The supplied ViewPaneLocation does not exist for this ViewPane."); 217 } 218 219 } 220 221 /** 222 * A factory that creates the library panel for the editors. 223 * 224 *@author Aaron Schultz 225 */ 226 public static class Factory extends ViewPaneFactory { 227 /** 228 * Create a factory with the given name and container. 229 * 230 *@param container 231 * The container. 232 *@param name 233 * The name of the entity. 234 *@exception IllegalActionException 235 * If the container is incompatible with this attribute. 236 *@exception NameDuplicationException 237 * If the name coincides with an attribute already in the 238 * container. 239 */ 240 public Factory(NamedObj container, String name) 241 throws IllegalActionException, NameDuplicationException { 242 super(container, name); 243 } 244 245 /** 246 * Create a library pane that displays the given library of actors. 247 * 248 * @return A new LibraryPaneTab that displays the library 249 */ 250 @Override 251 public ViewPane createViewPane(TableauFrame parent) { 252 253 DualVerticalViewPane vp = new DualVerticalViewPane(); 254 vp.setParentFrame(parent); 255 256 // use the name specified in the configuration to name the view 257 vp.setViewName(this.getName()); 258 259 return vp; 260 } 261 } 262 263 @Override 264 public List<TabPane> getTabPanes(String tabName) throws Exception { 265 List<TabPane> panes = new ArrayList<TabPane>(); 266 int index = -1; 267 index = _etp.indexOfTab(tabName); 268 if (index > -1) { 269 panes.add((TabPane) _etp.getComponentAt(index)); 270 } 271 index = _wtp.indexOfTab(tabName); 272 if (index > -1) { 273 panes.add((TabPane) _wtp.getComponentAt(index)); 274 } 275 return panes; 276 } 277 278}