/* * Copyright (c) 2004-2006 Extreme! Lab, Indiana University. All rights reserved. * * This software is open source. See the bottom of this file for the license. * * $Id: ComponentViewer.java,v 1.6 2006/11/20 18:35:12 sshirasu Exp $ */ package edu.indiana.extreme.xbaya.component.gui; import java.awt.Color; import javax.swing.JEditorPane; import javax.swing.SwingUtilities; import xsul5.XmlConstants; import edu.indiana.extreme.xbaya.component.Component; import edu.indiana.extreme.xbaya.component.gui.ComponentSelectorEvent.ComponentSelectorEventType; import edu.indiana.extreme.xbaya.graph.Node; import edu.indiana.extreme.xbaya.graph.gui.GraphCanvas; import edu.indiana.extreme.xbaya.graph.gui.GraphCanvasEvent; import edu.indiana.extreme.xbaya.graph.gui.GraphCanvasListener; import edu.indiana.extreme.xbaya.graph.gui.GraphCanvasEvent.GraphCanvasEventType; import edu.indiana.extreme.xbaya.gui.XBayaComponent; /** * @author Satoshi Shirasuna */ public class ComponentViewer implements GraphCanvasListener, ComponentSelectorListener, XBayaComponent { /** * The title */ public static final String TITLE = "Component Information"; private static final String DEFAULT_HTML_MESSAGE = " Select a component from the " + ComponentSelector.TITLE + "."; //private static final MLogger logger = MLogger.getLogger(); private Component currentComponent; private JEditorPane editorPane; /** * Creates a ComponentViewer. */ public ComponentViewer() { super(); this.currentComponent = null; this.editorPane = new JEditorPane(); this.editorPane.setEditable(false); this.editorPane.setBackground(Color.WHITE); this.editorPane.setContentType(XmlConstants.CONTENT_TYPE_HTML); this.editorPane.setText(DEFAULT_HTML_MESSAGE); } /** * @return the GUI component */ public JEditorPane getSwingComponent() { return this.editorPane; } /** * Sets a component to show. * * @param component * the component to show */ public void setComponent(final Component component) { // logger.entering(component); SwingUtilities.invokeLater(new Runnable() { public void run() { if (component == null) { ComponentViewer.this.editorPane .setText(DEFAULT_HTML_MESSAGE); } else if (component != ComponentViewer.this.currentComponent) { ComponentViewer.this.editorPane.setText(component.toHTML()); // To prevent from scrolling down to the bottom. ComponentViewer.this.editorPane.setCaretPosition(0); } ComponentViewer.this.currentComponent = component; } }); // logger.exiting(); } /** * @see edu.indiana.extreme.xbaya.graph.gui.GraphCanvasListener#graphCanvasChanged(edu.indiana.extreme.xbaya.graph.gui.GraphCanvasEvent) */ public void graphCanvasChanged(GraphCanvasEvent event) { GraphCanvasEventType type = event.getType(); GraphCanvas graphCanvas = event.getGraphCanvas(); switch (type) { case NODE_SELECTED: Node node = graphCanvas.getSelectedNode(); if (node == null) { setComponent(null); } else { setComponent(node.getComponent()); } break; case GRAPH_LOADED: case NAME_CHANGED: case INPUT_PORT_SELECTED: case OUTPUT_PORT_SELECTED: // do nothing } } /** * @see edu.indiana.extreme.xbaya.component.gui.ComponentSelectorListener#componentSelectorChanged(edu.indiana.extreme.xbaya.component.gui.ComponentSelectorEvent) */ public void componentSelectorChanged(ComponentSelectorEvent event) { ComponentSelectorEventType type = event.getType(); switch (type) { case COMPONENT_SELECTED: Component component = event.getComponent(); setComponent(component); break; } } } /* * Indiana University Extreme! Lab Software License, Version 1.2 * * Copyright (c) 2004-2006 The Trustees of Indiana University. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1) All redistributions of source code must retain the above copyright notice, * the list of authors in the original source code, this list of conditions and * the disclaimer listed in this license; * * 2) All redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the disclaimer listed in this license in * the documentation and/or other materials provided with the distribution; * * 3) Any documentation included with all redistributions must include the * following acknowledgement: * * "This product includes software developed by the Indiana University Extreme! * Lab. For further information please visit http://www.extreme.indiana.edu/" * * Alternatively, this acknowledgment may appear in the software itself, and * wherever such third-party acknowledgments normally appear. * * 4) The name "Indiana University" or "Indiana University Extreme! Lab" shall * not be used to endorse or promote products derived from this software without * prior written permission from Indiana University. For written permission, * please contact http://www.extreme.indiana.edu/. * * 5) Products derived from this software may not use "Indiana University" name * nor may "Indiana University" appear in their name, without prior written * permission of the Indiana University. * * Indiana University provides no reassurances that the source code provided * does not infringe the patent or any other intellectual property rights of any * other entity. Indiana University disclaims any liability to any recipient for * claims brought by any other entity based on infringement of intellectual * property rights or otherwise. * * LICENSEE UNDERSTANDS THAT SOFTWARE IS PROVIDED "AS IS" FOR WHICH NO * WARRANTIES AS TO CAPABILITIES OR ACCURACY ARE MADE. INDIANA UNIVERSITY GIVES * NO WARRANTIES AND MAKES NO REPRESENTATION THAT SOFTWARE IS FREE OF * INFRINGEMENT OF THIRD PARTY PATENT, COPYRIGHT, OR OTHER PROPRIETARY RIGHTS. * INDIANA UNIVERSITY MAKES NO WARRANTIES THAT SOFTWARE IS FREE FROM "BUGS", * "VIRUSES", "TROJAN HORSES", "TRAP DOORS", "WORMS", OR OTHER HARMFUL CODE. * LICENSEE ASSUMES THE ENTIRE RISK AS TO THE PERFORMANCE OF SOFTWARE AND/OR * ASSOCIATED MATERIALS, AND TO THE PERFORMANCE AND VALIDITY OF INFORMATION * GENERATED USING SOFTWARE. */