001/* 002 * Copyright (c) 2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: barseghian $' 006 * '$Date: 2011-02-12 02:25:44 +0000 (Sat, 12 Feb 2011) $' 007 * '$Revision: 27102 $' 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/* The ItemsOfInterestPanel is being used in the 031 * current version of the ReportDesigner. 032 * 033 * ItemsOfInterestPanel implements TabPane, and is instantiated through the 034 * Kepler configuration.xml file. 035 * 036 * When the user employs the context menu in the Kepler Canvas Pane 037 * to 'add to report items list' the ports and parameters that they select 038 * are added to an ArrayList that is maintained by the 039 * ReportItemManager class in org.kepler.reporting.roml 040 * 041 * The ItemsOfInterestPanel gets a tree model from the ReportItemManager like this: 042 * TreeModel model = ReportItemManager.getInstance().getReportItems(_workflowId); 043 * and then feeds that model over to PTree (a Ptolemy class for creating JTrees 044 * from NamedObj's. PTree has some drag and drop support as well. 045 * TODO A new class needs to be created (that extends PTree), 046 * that is specific to the Reporting suite, rather than over-riding the 047 * Ptolemy class, as is now the case. 048 * 049 * @author debi 050 */ 051 052package org.kepler.reporting.gui; 053 054import java.awt.BorderLayout; 055import java.awt.Color; 056import java.awt.Cursor; 057import java.awt.Dimension; 058import java.awt.GridLayout; 059import java.awt.event.MouseAdapter; 060import java.awt.event.MouseEvent; 061import java.net.URL; 062import java.util.ArrayList; 063import java.util.List; 064 065import javax.swing.BorderFactory; 066import javax.swing.ImageIcon; 067import javax.swing.JComponent; 068import javax.swing.JLabel; 069import javax.swing.JPanel; 070import javax.swing.JScrollPane; 071import javax.swing.JSplitPane; 072import javax.swing.TransferHandler; 073import javax.swing.border.Border; 074 075import org.kepler.gui.TabPane; 076import org.kepler.gui.TabPaneFactory; 077import org.kepler.gui.WorkflowOutlinePanel; 078import org.kepler.reporting.rio.GUIReportItemManager; 079import org.kepler.reporting.rio.StaticReportItem; 080 081import ptolemy.actor.gui.PtolemyFrame; 082import ptolemy.actor.gui.TableauFrame; 083import ptolemy.kernel.CompositeEntity; 084import ptolemy.kernel.util.IllegalActionException; 085import ptolemy.kernel.util.NameDuplicationException; 086import ptolemy.kernel.util.NamedObj; 087 088public class ItemsOfInterestPanel extends JPanel implements TabPane { 089 090 private TableauFrame _frame; 091 private String _title; 092 private static Cursor handCursor = Cursor 093 .getPredefinedCursor(Cursor.HAND_CURSOR); 094 private boolean showFormattingControls = true; 095 096 097 public ItemsOfInterestPanel(String title, String workflowId) { 098 super(new BorderLayout()); 099 100 _title = title; 101 } 102 103 public ItemsOfInterestPanel(String panel, String workflowId, 104 boolean showFormattingControls) { 105 this(panel, workflowId); 106 this.showFormattingControls = showFormattingControls; 107 } 108 109 /** 110 * Implementation of TabPane getName() 111 */ 112 public String getTabName() { 113 return _title; 114 } 115 116 /** 117 * Implementation of TabPane setParentFrame(TableauFrame) 118 */ 119 public void setParentFrame(TableauFrame parent) { 120 _frame = parent; 121 } 122 123 /** 124 * Implementation of getParentFrame getName() 125 */ 126 public TableauFrame getParentFrame() { 127 return _frame; 128 } 129 130 public void initializeTab() throws Exception { 131 132 // Build Top Panel 133 JPanel toppanel = new JPanel(new BorderLayout()); 134 toppanel.setPreferredSize(new Dimension(200, 300)); 135 toppanel.setMaximumSize(new Dimension(200, 300)); 136 toppanel.setMinimumSize(new Dimension(200, 200)); 137 138 // add outline to the top panel 139 CompositeEntity entity = (CompositeEntity) ((PtolemyFrame) _frame) 140 .getModel(); 141 toppanel.add(new WorkflowOutlinePanel(entity, true, false, false), BorderLayout.CENTER); 142 143 // Build Bottom Panel 144 JPanel bottompanel = new JPanel(new GridLayout(4, 1, 3, 3)); 145 Border titled = BorderFactory.createTitledBorder("Report Formatting Items"); 146 bottompanel.setBorder(titled); 147 bottompanel.setBackground(Color.WHITE); 148 149 // initialize all the static items 150 List<StaticReportItem> staticitemlist = GUIReportItemManager 151 .initStaticItems(); 152 List<JLabel> staticitemlabellist = new ArrayList<JLabel>(); 153 154 // set up the icons for the static report items 155 for (int i = 0; i < staticitemlist.size(); i++) { 156 StaticReportItem listitem = staticitemlist.get(i); 157 String tmptype = listitem.getType(); 158 ImageIcon tmpicon = listitem.getIcon(); 159 listitem.setIcon(tmpicon); 160 161 JLabel tmplabel = new JLabel(tmptype); 162 //XXX necessary: 163 new JLabelDragSource(tmplabel); 164 tmplabel.setCursor(handCursor); 165 tmplabel.setIcon(tmpicon); 166 staticitemlabellist.add(tmplabel); 167 } 168 169 for (int i = 0; i < staticitemlabellist.size(); i++) { 170 JLabel alabel = staticitemlabellist.get(i); 171 bottompanel.add(alabel); 172 } 173 bottompanel.setPreferredSize(new Dimension(200, 100)); 174 bottompanel.setMaximumSize(new Dimension(200, 100));///200)); 175 bottompanel.setMinimumSize(new Dimension(100, 100)); 176 177 this.setBackground(Color.WHITE); 178 179 if (showFormattingControls) { 180 JSplitPane innersplitpane = new JSplitPane( 181 JSplitPane.VERTICAL_SPLIT, toppanel, add(new JScrollPane( 182 bottompanel))); 183 184 innersplitpane.setDividerLocation(320); 185 //innersplitpane.resetToPreferredSizes(); 186 187 add(innersplitpane); 188 } else { 189 add(toppanel); 190 } 191 } 192 193 public URL getIconURL(String iconname, String extension) { 194 195 String IconLocation = ReportDesignerPanel.IMAGES_DIR + iconname + "." + extension; 196 URL iconURL = ItemsOfInterestPanel.class.getResource(IconLocation); 197 return iconURL; 198 } 199 200 static class StaticReportItemMouseListener extends MouseAdapter { 201 202 @Override() 203 public void mousePressed(MouseEvent e) { 204 205 Cursor droppableCursor = Cursor 206 .getPredefinedCursor(Cursor.HAND_CURSOR); 207 JComponent c = (JComponent) e.getSource(); 208 c.setCursor(droppableCursor); 209 TransferHandler handler = c.getTransferHandler(); 210 handler.exportAsDrag(c, e, TransferHandler.COPY); 211 } 212 } 213 214 static public class DragMouseAdapter extends MouseAdapter { 215 216 public void mousePressed(MouseEvent e) { 217 JComponent c = (JComponent) e.getSource(); 218 TransferHandler handler = c.getTransferHandler(); 219 handler.exportAsDrag(c, e, TransferHandler.COPY); 220 } 221 } 222 223 /** 224 * A factory that creates the library panel for the editors. 225 * 226 * @author aaron 227 */ 228 public static class Factory extends TabPaneFactory { 229 /** 230 * Create a factory with the given name and container. 231 * 232 * @param container 233 * The container. 234 * @param name 235 * The name of the entity. 236 * @exception IllegalActionException 237 * If the container is incompatible with this attribute. 238 * @exception NameDuplicationException 239 * If the name coincides with an attribute already in the 240 * container. 241 */ 242 public Factory(NamedObj container, String name) 243 throws IllegalActionException, NameDuplicationException { 244 super(container, name); 245 } 246 247 public TabPane createTabPane(TableauFrame parent) { 248 ItemsOfInterestPanel ioip = new ItemsOfInterestPanel( 249 this.getName(), ((PtolemyFrame) parent).getModel() 250 .getName()); 251 Dimension d = new Dimension(200, 500); 252 ioip.setMinimumSize(d); 253 ioip.setPreferredSize(d); 254 return ioip; 255 } 256 } 257 258 public static class PlottingFactory extends TabPaneFactory { 259 public PlottingFactory(NamedObj container, String name) 260 throws IllegalActionException, NameDuplicationException { 261 super(container, name); 262 } 263 264 public TabPane createTabPane(TableauFrame parent) { 265 ItemsOfInterestPanel ioip = new ItemsOfInterestPanel( 266 this.getName(), ((PtolemyFrame) parent).getModel() 267 .getName(), false); 268 Dimension d = new Dimension(200, 500); 269 ioip.setMinimumSize(d); 270 ioip.setPreferredSize(d); 271 return ioip; 272 } 273 } 274 275}