configurationgraph.java
来自「plugin for eclipse」· Java 代码 · 共 247 行
JAVA
247 行
package isis.tinydt.editors.nesceditor;
import isis.anp.nesc.ot.Component;
import isis.anp.nesc.ot.ComponentAlias;
import isis.anp.nesc.ot.Configuration;
import isis.anp.nesc.ot.Connection;
import isis.anp.nesc.ot.FunctionPort;
import isis.anp.nesc.ot.InterfacePort;
import isis.anp.nesc.ot.Module;
import isis.anp.nesc.ot.NesCConfigurationFile;
import isis.anp.nesc.ot.Port;
import java.util.Iterator;
import org.eclipse.draw2d.ChopboxAnchor;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.LightweightSystem;
import org.eclipse.draw2d.PolygonDecoration;
import org.eclipse.draw2d.PolylineConnection;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
public class ConfigurationGraph extends Canvas
{
private NesCConfigurationFile configFile = null;
private LightweightSystem area = null;
private IFigure panel = null;
private PolylineConnection conn = null;
private int provided_interfaceX = 5, provided_interfaceY = 5,
used_interfaceX = 605, used_interfaceY = 5,
configurationX = 205, configurationY = 5,
moduleX = 405, moduleY = 5;
private static int vertical_separation = 10;
public ConfigurationGraph(Composite parent, int style)
{
super( parent, style );
area = new LightweightSystem(this);
}
private void initialize()
{
panel = new Figure();
area.setContents(panel);
if(configFile == null)
return;
Configuration config = (Configuration)configFile.getComponent();
//iterate through the components
Iterator component_it = config.getImplementation().getComponentAliases().iterator();
while( component_it.hasNext() )
{
String type;
ComponentAlias component = (ComponentAlias)component_it.next();
// create the new component
NesCFileFigure new_compnent = new NesCFileFigure(component.getAlias(), getComponentType(component.getComponent()));
new_compnent.setObject(component.getComponent());
// iterate throurg the ports of a component
Iterator port_it = component.getComponent().getPorts().iterator();
while(port_it.hasNext())
{
Port port = (Port)port_it.next();
new_compnent.addInterface(port);
}
// place it to the proper x and y coordinate
placeComponents(new_compnent, component.getComponent());
panel.add(new_compnent);
new Dragger(new_compnent);
}
//iterate through the interfaces
Iterator interface_it = config.getPorts().iterator();
while( interface_it.hasNext() )
{
Port port = (Port)interface_it.next();
// create the new component
NesCFileFigure new_compnent = new NesCFileFigure(port.getName(), getPortType(port));
new_compnent.setObject(port);
// place it to the proper x and y coordinate
placePort(new_compnent, port);
panel.add(new_compnent);
new Dragger(new_compnent);
}
// iterate through the connections
Iterator connection_it = config.getImplementation().getConnections().iterator();
while( connection_it.hasNext() )
{
Connection connection = (Connection)connection_it.next();
// create the new connection
PolylineConnection conn = new PolylineConnection();
try
{
conn.setSourceAnchor(new ChopboxAnchor(getConnectionEnd(config, connection.getSrc())));
conn.setTargetAnchor(new ChopboxAnchor(getConnectionEnd(config, connection.getDst())));
conn.setTargetDecoration(new PolygonDecoration());
panel.add(conn);
}
catch(Exception ex)
{
}
}
}
private RectangleFigure getConnectionEnd(Component parent, Port port)
{
if (port.getParent().getName().compareTo(parent.getName()) == 0)
//search among the interfaces
return getProperChild(port);
else
//get the proper child and get back its port
{
NesCFileFigure figp =(NesCFileFigure)getProperChild(port.getParent());
RectangleFigure fig = figp.getInterface(port);
return fig;
}
}
private RectangleFigure getProperChild(Object obj)
{
Iterator children_it = panel.getChildren().iterator();
while(children_it.hasNext())
{
try
{
Figure fig = (Figure) children_it.next();
if(fig instanceof NesCFileFigure)
{
if ( ((NesCFileFigure)fig).isSame(obj))
return ((NesCFileFigure)fig);
}
}
catch(Exception ex)
{
}
}
return null;
}
private String getComponentType(Component comp)
{
if(comp instanceof Configuration)
return "configuration";
if(comp instanceof Module)
return "module";
return "";
}
private String getPortType(Port port)
{
if(port instanceof InterfacePort)
return "interface";
if(port instanceof FunctionPort)
return "function";
return "";
}
private void placeComponents(NesCFileFigure figure, Component comp)
{
if(comp instanceof Configuration)
{
figure.setLocation(new Point(configurationX, configurationY));
configurationY += figure.getSize().height + vertical_separation;
}
if(comp instanceof Module)
{
figure.setLocation(new Point(moduleX, moduleY));
moduleY += figure.getSize().height + vertical_separation;
}
}
private void placePort(NesCFileFigure figure, Port port)
{
if(port.getDirection() == Port.Direction.PROVIDES)
{
figure.setLocation(new Point(provided_interfaceX, provided_interfaceY));
provided_interfaceY += figure.getSize().height + vertical_separation;
}
else
{
figure.setLocation(new Point(used_interfaceX, used_interfaceY));
used_interfaceY += figure.getSize().height + vertical_separation;
}
}
public void setConfigFile( NesCConfigurationFile configFile )
{
this.configFile = configFile;
initialize();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?