001/*
002 * Copyright (c) 2009-2015 The Regents of the University of California.
003 * All rights reserved.
004 *
005 * '$Author: crawl $'
006 * '$Date: 2015-08-26 18:04:09 +0000 (Wed, 26 Aug 2015) $' 
007 * '$Revision: 33643 $'
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 */
029package org.kepler.profiling.gui;
030
031import java.awt.BorderLayout;
032import java.awt.event.ActionEvent;
033import java.awt.event.ActionListener;
034
035import javax.swing.JCheckBox;
036import javax.swing.JScrollPane;
037import javax.swing.ScrollPaneConstants;
038
039import org.kepler.gui.TabPane;
040import org.kepler.gui.TabPaneFactory;
041import org.kepler.gui.WorkflowOutlineTreeModel;
042
043import ptolemy.actor.gui.TableauFrame;
044import ptolemy.kernel.CompositeEntity;
045import ptolemy.kernel.util.IllegalActionException;
046import ptolemy.kernel.util.NameDuplicationException;
047import ptolemy.kernel.util.NamedObj;
048
049/** A tab pane showing a workflow outline of port I/O.
050 * 
051 *  @author Daniel Crawl
052 *  @version $Id: PortIOOutlineTabPane.java 33643 2015-08-26 18:04:09Z crawl $
053 */
054public class PortIOOutlineTabPane extends WorkflowRunOutlineTabPane {
055    
056        @Override
057    protected void _finishRefreshOutline(NamedObj root) 
058        {
059                boolean includePorts = false;
060                if(_wfOutlineTreeModel != null) {
061                    includePorts = _wfOutlineTreeModel.includePorts;
062                }
063                
064                _wfOutlineTreeModel = new WorkflowOutlineTreeModel((CompositeEntity)root);
065                _wfOutlineTreeModel.includePorts = includePorts;
066
067                AnnotatedActorIOPTree pane = new AnnotatedActorIOPTree(
068                    _wfOutlineTreeModel, this, true, root);
069                JScrollPane jSP = new JScrollPane(pane,
070                                ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
071                                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
072                //jSP.setPreferredSize(new Dimension(200, 200));
073
074                add(jSP, BorderLayout.CENTER);
075
076                _toggleCheckbox = new JCheckBox("Show Ports");
077                _toggleCheckbox.setSelected(_wfOutlineTreeModel.includePorts);
078                _toggleCheckbox.addActionListener(new ActionListener() {
079                      @Override
080                        public void actionPerformed(ActionEvent e) {
081                            if (e.getSource() == _toggleCheckbox) {
082                                _wfOutlineTreeModel.includePorts = _toggleCheckbox.isSelected();
083                                _refreshOutline();
084                            }
085                        }
086                });
087
088                add(_toggleCheckbox, BorderLayout.SOUTH);
089                
090                repaint();
091                validate();
092        }
093        
094        public static class Factory extends TabPaneFactory {
095
096            public Factory(NamedObj container, String name)
097                                throws IllegalActionException, NameDuplicationException {
098                        super(container, name);
099                }
100
101                @Override
102        public TabPane createTabPane(TableauFrame parent) {
103                        PortIOOutlineTabPane pane = new PortIOOutlineTabPane();
104                        pane.setTabName(this.getName());
105                        return pane;
106                }
107        }
108        
109   private WorkflowOutlineTreeModel _wfOutlineTreeModel;
110}