Bundle-SymbolicName: org.simantics.graphviz
Bundle-Version: 1.1.0.qualifier
Bundle-Activator: org.simantics.graphviz.Activator
-Require-Bundle: org.eclipse.core.runtime
+Require-Bundle: org.eclipse.core.runtime,
+ org.slf4j.api;bundle-version="1.7.25"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: org.simantics.graphviz,
import org.simantics.graphviz.continuation.Continuation;
import org.simantics.graphviz.internal.xdot.DrawCommand;
import org.simantics.graphviz.internal.xdot.DrawCommandParser;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* A drawable that draws a given graph.
* @author Hannu Niemist�
*/
public class GraphDrawable implements Drawable {
-
+ private static final Logger LOGGER = LoggerFactory.getLogger(GraphDrawable.class);
+
private static String DEFAULT_ALGORITHM = "dot";
DrawCommand[] commands;
@Override
public synchronized Rectangle2D getBounds() {
if(bounds == null)
- System.err.println("bounds == null");
+ LOGGER.warn("bounds == null");
return bounds;
}
addMouseMotionListener(new MouseAdapter() {
@Override
public void mouseDragged(MouseEvent e) {
+ if(transform == null)
+ return;
Point cur = e.getPoint();
if (prev == null)
prev = cur;
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
- if(transform != null) {
- double scale = Math.exp(-0.1*e.getUnitsToScroll());
- Point p = e.getPoint();
- AffineTransform mod = new AffineTransform();
- mod.translate(p.getX(), p.getY());
- mod.scale(scale, scale);
- mod.translate(-p.getX(), -p.getY());
- transform.preConcatenate(mod);
- repaint();
- }
+ if(transform == null)
+ return;
+ double scale = Math.exp(-0.1*e.getUnitsToScroll());
+ Point p = e.getPoint();
+ AffineTransform mod = new AffineTransform();
+ mod.translate(p.getX(), p.getY());
+ mod.scale(scale, scale);
+ mod.translate(-p.getX(), -p.getY());
+ transform.preConcatenate(mod);
+ repaint();
}
});
private void fit() {
Rectangle2D bounds = drawable.getBounds();
-
Rectangle2D container = getBounds();
+
+ if(bounds == null || container == null)
+ return;
+
double scale = container == null ? 1 : Math.min(
container.getWidth() / bounds.getWidth(),
container.getHeight() / bounds.getHeight());
g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
- if(transform == null)
+ if(transform == null) {
fit();
+ if(transform == null) {
+ g.setTransform(new AffineTransform());
+ g.setColor(Color.BLACK);
+ g.drawString("No data available yet", 20f, 20f);
+ return;
+ }
+ }
g.setTransform(transform);
drawable.draw(g, null);