|
@@ -24,7 +24,7 @@ import graph.LayeredGraphNode;
|
|
* @author kolja
|
|
* @author kolja
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
-public class NodeView extends JPanel implements AnnimatedView, MouseListener {
|
|
|
|
|
|
+public class NodeView extends JPanel implements AnimatedView, MouseListener {
|
|
private static final long serialVersionUID = 1L;
|
|
private static final long serialVersionUID = 1L;
|
|
private LayeredGraphNode model;
|
|
private LayeredGraphNode model;
|
|
private LayoutType layout;
|
|
private LayoutType layout;
|
|
@@ -34,6 +34,12 @@ public class NodeView extends JPanel implements AnnimatedView, MouseListener {
|
|
|
|
|
|
private static final int PADDING = 25;
|
|
private static final int PADDING = 25;
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * creates a view for a given node
|
|
|
|
+ * @param model the node
|
|
|
|
+ * @param lt the layout in which to draw the node
|
|
|
|
+ * @param mv the frame in which to draw the layout
|
|
|
|
+ */
|
|
public NodeView( LayeredGraphNode model, LayoutType lt, JFrame mv ) {
|
|
public NodeView( LayeredGraphNode model, LayoutType lt, JFrame mv ) {
|
|
mainView = mv;
|
|
mainView = mv;
|
|
this.model = model;
|
|
this.model = model;
|
|
@@ -65,6 +71,11 @@ public class NodeView extends JPanel implements AnnimatedView, MouseListener {
|
|
return (int)padding;
|
|
return (int)padding;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * returns the x coordinate that was scaled such that the whole image fits on the screen
|
|
|
|
+ * @param x the coordinate
|
|
|
|
+ * @return the coordinate
|
|
|
|
+ */
|
|
public int getScaledX( int x )
|
|
public int getScaledX( int x )
|
|
{
|
|
{
|
|
int padding = calculatePadding();
|
|
int padding = calculatePadding();
|
|
@@ -72,7 +83,11 @@ public class NodeView extends JPanel implements AnnimatedView, MouseListener {
|
|
x *= scale;
|
|
x *= scale;
|
|
return x;
|
|
return x;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ /**
|
|
|
|
+ * returns the y coordinate that was scaled such that the whole image fits on the screen
|
|
|
|
+ * @param y the coordinate
|
|
|
|
+ * @return the coordinate
|
|
|
|
+ */
|
|
public int getScaledY( int y )
|
|
public int getScaledY( int y )
|
|
{
|
|
{
|
|
int padding = calculatePadding();
|
|
int padding = calculatePadding();
|
|
@@ -81,6 +96,9 @@ public class NodeView extends JPanel implements AnnimatedView, MouseListener {
|
|
return y;
|
|
return y;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * updates the text that is displayed when hovering over the node.
|
|
|
|
+ */
|
|
public void updateTooltipText() {
|
|
public void updateTooltipText() {
|
|
if( layout != LayoutType.COMBINED )
|
|
if( layout != LayoutType.COMBINED )
|
|
{
|
|
{
|
|
@@ -104,6 +122,10 @@ public class NodeView extends JPanel implements AnnimatedView, MouseListener {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * returns the offset of the node
|
|
|
|
+ * @return the offset of the node
|
|
|
|
+ */
|
|
public int getXOffset()
|
|
public int getXOffset()
|
|
{
|
|
{
|
|
int x = 0;
|
|
int x = 0;
|
|
@@ -112,7 +134,10 @@ public class NodeView extends JPanel implements AnnimatedView, MouseListener {
|
|
x += (getWidth()-padding) / 2 - (getWidthOfNeededArea() * scale ) / 2 + padding/2;
|
|
x += (getWidth()-padding) / 2 - (getWidthOfNeededArea() * scale ) / 2 + padding/2;
|
|
return x;
|
|
return x;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ /**
|
|
|
|
+ * returns the offset of the node
|
|
|
|
+ * @return the offset of the node
|
|
|
|
+ */
|
|
public int getYOffset()
|
|
public int getYOffset()
|
|
{
|
|
{
|
|
int y = 0;
|
|
int y = 0;
|
|
@@ -121,13 +146,21 @@ public class NodeView extends JPanel implements AnnimatedView, MouseListener {
|
|
y += (getHeight()-padding) / 2 - (getHeightOfNeededArea() * scale ) / 2 + padding/2;
|
|
y += (getHeight()-padding) / 2 - (getHeightOfNeededArea() * scale ) / 2 + padding/2;
|
|
return y;
|
|
return y;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * returns the original width of the node, before any scaling
|
|
|
|
+ * @return the width
|
|
|
|
+ */
|
|
public int getOriginalWidth() {
|
|
public int getOriginalWidth() {
|
|
if( model.isDummyNode() )
|
|
if( model.isDummyNode() )
|
|
return (int)(originalWidth / 3);
|
|
return (int)(originalWidth / 3);
|
|
return originalWidth;
|
|
return originalWidth;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * returns the original height of the node, before any scaling
|
|
|
|
+ * @return the height
|
|
|
|
+ */
|
|
public int getOriginalHeight() {
|
|
public int getOriginalHeight() {
|
|
return originalHeight;
|
|
return originalHeight;
|
|
}
|
|
}
|
|
@@ -140,7 +173,7 @@ public class NodeView extends JPanel implements AnnimatedView, MouseListener {
|
|
if( c instanceof NodeView )
|
|
if( c instanceof NodeView )
|
|
{
|
|
{
|
|
max = Math.max( max, ((NodeView)c).getVirtualX() + ((NodeView)c).getOriginalWidth() );
|
|
max = Math.max( max, ((NodeView)c).getVirtualX() + ((NodeView)c).getOriginalWidth() );
|
|
- min = Math.min( ((AnnimatedView)c).getVirtualX(), min);
|
|
|
|
|
|
+ min = Math.min( ((AnimatedView)c).getVirtualX(), min);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return max - (int)min;
|
|
return max - (int)min;
|
|
@@ -154,7 +187,7 @@ public class NodeView extends JPanel implements AnnimatedView, MouseListener {
|
|
if( c instanceof NodeView )
|
|
if( c instanceof NodeView )
|
|
{
|
|
{
|
|
max = Math.max( max, ((NodeView)c).getVirtualY() + ((NodeView)c).getOriginalHeight() );
|
|
max = Math.max( max, ((NodeView)c).getVirtualY() + ((NodeView)c).getOriginalHeight() );
|
|
- min = Math.min( ((AnnimatedView)c).getVirtualY(), min);
|
|
|
|
|
|
+ min = Math.min( ((AnimatedView)c).getVirtualY(), min);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return max - (int)min;
|
|
return max - (int)min;
|
|
@@ -165,9 +198,9 @@ public class NodeView extends JPanel implements AnnimatedView, MouseListener {
|
|
double minX = Double.POSITIVE_INFINITY;
|
|
double minX = Double.POSITIVE_INFINITY;
|
|
for( Component c : getComponents() )
|
|
for( Component c : getComponents() )
|
|
{
|
|
{
|
|
- if( !(c instanceof AnnimatedView) )
|
|
|
|
|
|
+ if( !(c instanceof AnimatedView) )
|
|
continue;
|
|
continue;
|
|
- minX = Math.min( ((AnnimatedView)c).getVirtualX(), minX);
|
|
|
|
|
|
+ minX = Math.min( ((AnimatedView)c).getVirtualX(), minX);
|
|
}
|
|
}
|
|
int x = 0;
|
|
int x = 0;
|
|
int y = 0;
|
|
int y = 0;
|
|
@@ -177,9 +210,9 @@ public class NodeView extends JPanel implements AnnimatedView, MouseListener {
|
|
y += (getHeight()) / 2 - (getHeightOfNeededArea() * scale ) / 2;
|
|
y += (getHeight()) / 2 - (getHeightOfNeededArea() * scale ) / 2;
|
|
for( Component c : getComponents() )
|
|
for( Component c : getComponents() )
|
|
{
|
|
{
|
|
- if( !(c instanceof AnnimatedView) )
|
|
|
|
|
|
+ if( !(c instanceof AnimatedView) )
|
|
continue;
|
|
continue;
|
|
- AnnimatedView view = (AnnimatedView)c;
|
|
|
|
|
|
+ AnimatedView view = (AnimatedView)c;
|
|
if( c instanceof NodeView )
|
|
if( c instanceof NodeView )
|
|
{
|
|
{
|
|
c.setLocation( getScaledX( ((NodeView)c).getVirtualX() - (int)minX ) + x, getScaledY( view.getVirtualY() ) + y);
|
|
c.setLocation( getScaledX( ((NodeView)c).getVirtualX() - (int)minX ) + x, getScaledY( view.getVirtualY() ) + y);
|
|
@@ -203,9 +236,9 @@ public class NodeView extends JPanel implements AnnimatedView, MouseListener {
|
|
double minX = Double.POSITIVE_INFINITY;
|
|
double minX = Double.POSITIVE_INFINITY;
|
|
for( Component c : getComponents() )
|
|
for( Component c : getComponents() )
|
|
{
|
|
{
|
|
- if( !(c instanceof AnnimatedView) )
|
|
|
|
|
|
+ if( !(c instanceof AnimatedView) )
|
|
continue;
|
|
continue;
|
|
- minX = Math.min( ((AnnimatedView)c).getVirtualX(), minX);
|
|
|
|
|
|
+ minX = Math.min( ((AnimatedView)c).getVirtualX(), minX);
|
|
}
|
|
}
|
|
int x = 0;
|
|
int x = 0;
|
|
int padding = calculatePadding();
|
|
int padding = calculatePadding();
|
|
@@ -226,6 +259,10 @@ public class NodeView extends JPanel implements AnnimatedView, MouseListener {
|
|
paintComponent( g );
|
|
paintComponent( g );
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * draws a background in the color of this nodes class around it
|
|
|
|
+ * @param g where to draw
|
|
|
|
+ */
|
|
public void renderClass( Graphics g ) {
|
|
public void renderClass( Graphics g ) {
|
|
g.setColor( model.getRoot( layout ).getClassColor( layout ) );
|
|
g.setColor( model.getRoot( layout ).getClassColor( layout ) );
|
|
if( model.getContainedNodes().size() == 0 && model.getRoot( layout ).getClassColor( layout ) != Color.LIGHT_GRAY )
|
|
if( model.getContainedNodes().size() == 0 && model.getRoot( layout ).getClassColor( layout ) != Color.LIGHT_GRAY )
|