Commit dccaaeb6 authored by Nicolas Petitprez's avatar Nicolas Petitprez

Allow to zoom in sequences diagrams

parent b73c66c7
package org.ow2.frascati.intent.umlsequencediagram.explorer;
import java.beans.PropertyChangeListener;
public interface Property<TYPE> {
public void addPropertyChangeListener(PropertyChangeListener listener);
public TYPE get();
public void removePropertyChangeListener(PropertyChangeListener listener);
public void set(TYPE value);
}
package org.ow2.frascati.intent.umlsequencediagram.explorer;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
public class PropertyImpl<TYPE> implements Property<TYPE> {
private final PropertyChangeSupport support = new PropertyChangeSupport(
this);
private TYPE value;
@org.osoa.sca.annotations.Property
protected String name;
public void addPropertyChangeListener(PropertyChangeListener listener) {
support.addPropertyChangeListener(listener);
}
public TYPE get() {
return value;
}
public void removePropertyChangeListener(PropertyChangeListener listener) {
support.removePropertyChangeListener(listener);
}
@Override
public String toString() {
return "Property [name=" + name + ", value=" + value + "]";
}
public void set(TYPE value) {
if (this.value != value) {
TYPE old = this.value;
this.value = value;
support.firePropertyChange(name, old, value);
}
}
}
......@@ -27,6 +27,9 @@
package org.ow2.frascati.intent.umlsequencediagram.explorer;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import net.sf.sdedit.config.Configuration;
import net.sf.sdedit.config.ConfigurationManager;
......@@ -39,7 +42,7 @@ import org.ow2.frascati.assembly.factory.api.CompositeManager;
import org.ow2.frascati.explorer.api.FraSCAtiExplorer;
import org.ow2.frascati.explorer.gui.AbstractSelectionPanel;
import org.ow2.frascati.intent.trace.api.Trace;
import org.ow2.frascati.intent.umlsequencediagram.api.Constants;
import org.ow2.frascati.intent.umlsequencediagram.api.Constants;
import org.ow2.frascati.intent.umlsequencediagram.lib.TraceDiagramGenerator;
/**
......@@ -48,13 +51,23 @@ import org.ow2.frascati.intent.umlsequencediagram.lib.TraceDiagramGenerator;
* @author Philippe Merle - INRIA
* @version 1.4
*/
public class TracePanel extends AbstractSelectionPanel<Trace> {
public class TracePanel extends AbstractSelectionPanel<Trace> implements
PropertyChangeListener {
public static final Property<Double> zoom = new PropertyImpl();
ZoomPane zoomPanel = new ZoomPane();
public void propertyChange(PropertyChangeEvent evt) {
zoomPanel.setScale(zoom.get());
}
/**
* @see org.objectweb.util.explorer.api.Panel#selected(org.objectweb.util.explorer.api.TreeView)
*/
public void selected(TreeView treeView) {
super.selected(treeView);
zoom.addPropertyChangeListener(this);
setMinimumSize(new Dimension(0, 0));
setPreferredSize(new Dimension(800, 600));
Trace trace = (Trace) treeView.getSelectedObject();
......@@ -71,7 +84,6 @@ public class TracePanel extends AbstractSelectionPanel<Trace> {
}
PanelPaintDevice paintDevice = new PanelPaintDevice(true);
Configuration dataObject = (Configuration) ConfigurationManager
.createNewDefaultConfiguration().getDataObject();
......@@ -82,10 +94,13 @@ public class TracePanel extends AbstractSelectionPanel<Trace> {
} catch (Exception e) {
e.printStackTrace();
}
ZoomPane zoom = new ZoomPane();
zoom.setViewportView(paintDevice.getPanel());
zoomPanel.setViewportView(paintDevice.getPanel());
if (zoom.get() == null)
zoom.set(1d);
zoomPanel.setScale(zoom.get());
setLayout(new BorderLayout());
add(BorderLayout.CENTER, zoom);
add(BorderLayout.CENTER, zoomPanel);
// Refresh the Swing Panel.
validate();
......@@ -95,8 +110,7 @@ public class TracePanel extends AbstractSelectionPanel<Trace> {
* @see org.objectweb.util.explorer.api.Panel#unselected(org.objectweb.util.explorer.api.TreeView)
*/
public void unselected(TreeView treeView) {
// Delete the tmp SVG file created into the previous method selected().
zoom.removePropertyChangeListener(this);
}
}
package org.ow2.frascati.intent.umlsequencediagram.explorer;
import org.ow2.frascati.explorer.action.AbstractAlwaysEnabledMenuItem;
import org.ow2.frascati.intent.trace.api.Trace;
public class ZoomIn extends AbstractAlwaysEnabledMenuItem<Trace> {
private static final double MAX_ZOOM = 2;
@Override
protected void execute(Trace selected) throws Exception {
double zoomvalue = TracePanel.zoom.get() * 1.1;
if (zoomvalue < MAX_ZOOM)
TracePanel.zoom.set(zoomvalue * 1.1);
}
}
package org.ow2.frascati.intent.umlsequencediagram.explorer;
import org.ow2.frascati.explorer.action.AbstractAlwaysEnabledMenuItem;
import org.ow2.frascati.intent.trace.api.Trace;
public class ZoomOut extends AbstractAlwaysEnabledMenuItem<Trace> {
private static final double MIN_ZOOM = 0.5;
@Override
protected void execute(Trace selected) throws Exception {
double zoomvalue = TracePanel.zoom.get() * .9;
if (zoomvalue > MIN_ZOOM)
TracePanel.zoom.set(zoomvalue);
}
}
......@@ -26,9 +26,7 @@
package org.ow2.frascati.intent.umlsequencediagram.lib;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import net.sf.sdedit.diagram.DiagramDataProvider;
......@@ -48,6 +46,12 @@ public class TextDiagramGenerator implements TraceDiagramGenerator {
@Property
protected int messageLength = 20;
@Property
protected boolean showCompositeAsFragment = false;
@Property
protected boolean showReference = false;
private class Actor {
private String label;
private final String name;
......@@ -126,7 +130,8 @@ public class TextDiagramGenerator implements TraceDiagramGenerator {
buffer.append(cleanStr(returned.getReturnValueAsString()))
.append("=");
else if (thro != null)
buffer.append(cleanStr(thro.getThrowableAsString())).append("=");
buffer.append(cleanStr(thro.getThrowableAsString()))
.append("=");
}
if (target != null) {
......@@ -176,11 +181,11 @@ public class TextDiagramGenerator implements TraceDiagramGenerator {
public DiagramDataProvider getDiagramDataProvider(Trace trace) {
try {
Map<Thread, Stack<Calling>> calls = new HashMap<Thread, Stack<Calling>>();
Stack<Calling> currentStack = new Stack<Calling>();
for (TraceEvent event : trace.getTraceEvents()) {
// add a section to show composites
if (event.isScaComposite()) {
if (showCompositeAsFragment && event.isScaComposite()) {
if (event instanceof TraceEventReturn
|| event instanceof TraceEventThrow) {
if (diagramEvent.get(diagramEvent.size() - 1)
......@@ -193,41 +198,23 @@ public class TextDiagramGenerator implements TraceDiagramGenerator {
.add("[c:" + event.getComponentName() + "]");
}
} else {
Stack<Calling> currentStack = calls.get(event.getThread());
if (currentStack == null) {
currentStack = new Stack<Calling>();
calls.put(event.getThread(), currentStack);
}
TraceEventCall tracecall = (TraceEventCall) event;
if (!showReference && tracecall.isScaReference())
continue;
if (event instanceof TraceEventReturn) {
Calling pop = currentStack.pop();
TraceEventReturn ret = (TraceEventReturn) event;
TraceEventReturn ret = (TraceEventReturn) tracecall;
pop.returned = ret;
} else if (event instanceof TraceEventThrow) {
Calling pop = currentStack.pop();
TraceEventThrow ret = (TraceEventThrow) event;
pop.thro = ret;
} else if (event instanceof TraceEventCall) {
TraceEventCall tracecall = (TraceEventCall) event;
} else {
Actor prev = currentStack.isEmpty() ? addActor(
trace.getName(), trace.getName(),
trace.getName()) : currentStack.peek().target;
if (!currentStack.isEmpty()
&& currentStack.peek().target.getName().equals(
tracecall.getComponentName())
&& currentStack.peek().call.getMethod().equals(
tracecall.getMethod())) {
Calling peek = currentStack.peek();
peek.target.type = getType(tracecall);
currentStack.push(peek);
continue;
}
Actor actor = addActor(tracecall.getInterfaceName(),
Actor actor = addActor(tracecall.getComponentName(),
getType(tracecall), null);
Calling call = new Calling();
call.call = tracecall;
call.src = prev;
......@@ -249,7 +236,7 @@ public class TextDiagramGenerator implements TraceDiagramGenerator {
for (Object object : diagramEvent) {
buffer.append(object.toString()).append("\n");
}
System.out.println(buffer.toString());
// System.out.println(buffer.toString());
return new TextHandler(buffer.toString());
} catch (Exception e) {
e.printStackTrace();
......
......@@ -81,6 +81,20 @@
<icon-file url="icons/Remove-Trace.gif"/>
</icon>
</item>
<item label="ZoomOut">
<code>org.ow2.frascati.intent.umlsequencediagram.explorer.ZoomOut
</code>
<icon>
<icon-file url="icons/zoom_out.png" />
</icon>
</item>
<item label="ZoomIn">
<code>org.ow2.frascati.intent.umlsequencediagram.explorer.ZoomIn
</code>
<icon>
<icon-file url="icons/zoom_in.png" />
</icon>
</item>
</menu>
<panel>
<table>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment