|
@@ -31,6 +31,8 @@ public class NodeView extends JPanel implements AnnimatedView, MouseListener {
|
|
|
private JFrame mainView;
|
|
|
private int originalWidth;
|
|
|
private int originalHeight;
|
|
|
+
|
|
|
+ private static final int PADDING = 25;
|
|
|
|
|
|
public NodeView( LayeredGraphNode model, LayoutType lt, JFrame mv ) {
|
|
|
mainView = mv;
|
|
@@ -53,18 +55,28 @@ public class NodeView extends JPanel implements AnnimatedView, MouseListener {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ private int calculatePadding()
|
|
|
+ {
|
|
|
+ double padding = Math.min( getWidth() / 100.0 * PADDING, getHeight() / 100.0 * PADDING);
|
|
|
+ if( padding < 10 )
|
|
|
+ return 10;
|
|
|
+ if( padding > 50 )
|
|
|
+ return 50;
|
|
|
+ return (int)padding;
|
|
|
+ }
|
|
|
+
|
|
|
public int getScaledX( int x )
|
|
|
{
|
|
|
- double scale1 = Math.min( (getWidth()) / (double)getWidthOfNeededArea(), (getHeight()) / (double)getHeightOfNeededArea());
|
|
|
- double scale = Math.min( (getWidth()-50*scale1) / (double)getWidthOfNeededArea(), (getHeight()-50*scale1) / (double)getHeightOfNeededArea());
|
|
|
+ int padding = calculatePadding();
|
|
|
+ double scale = Math.min( (getWidth()-padding) / (double)getWidthOfNeededArea(), (getHeight()-padding) / (double)getHeightOfNeededArea());
|
|
|
x *= scale;
|
|
|
return x;
|
|
|
}
|
|
|
|
|
|
public int getScaledY( int y )
|
|
|
{
|
|
|
- double scale1 = Math.min( (getWidth()) / (double)getWidthOfNeededArea(), (getHeight()) / (double)getHeightOfNeededArea());
|
|
|
- double scale = Math.min( (getWidth()-50*scale1) / (double)getWidthOfNeededArea(), (getHeight()-50*scale1) / (double)getHeightOfNeededArea());
|
|
|
+ int padding = calculatePadding();
|
|
|
+ double scale = Math.min( (getWidth()-padding) / (double)getWidthOfNeededArea(), (getHeight()-padding) / (double)getHeightOfNeededArea());
|
|
|
y *= scale;
|
|
|
return y;
|
|
|
}
|
|
@@ -95,18 +107,18 @@ public class NodeView extends JPanel implements AnnimatedView, MouseListener {
|
|
|
public int getXOffset()
|
|
|
{
|
|
|
int x = 0;
|
|
|
- double scale1 = Math.min( (getWidth()) / (double)getWidthOfNeededArea(), (getHeight()) / (double)getHeightOfNeededArea());
|
|
|
- double scale = Math.min( (getWidth()-50*scale1) / (double)getWidthOfNeededArea(), (getHeight()-50*scale1) / (double)getHeightOfNeededArea());
|
|
|
- x += (getWidth()-50) / 2 - (getWidthOfNeededArea() * scale ) / 2 + 25;
|
|
|
+ int padding = calculatePadding();
|
|
|
+ double scale = Math.min( (getWidth()-padding) / (double)getWidthOfNeededArea(), (getHeight()-padding) / (double)getHeightOfNeededArea());
|
|
|
+ x += (getWidth()-padding) / 2 - (getWidthOfNeededArea() * scale ) / 2 + padding/2;
|
|
|
return x;
|
|
|
}
|
|
|
|
|
|
public int getYOffset()
|
|
|
{
|
|
|
int y = 0;
|
|
|
- double scale1 = Math.min( (getWidth()) / (double)getWidthOfNeededArea(), (getHeight()) / (double)getHeightOfNeededArea());
|
|
|
- double scale = Math.min( (getWidth()-50*scale1) / (double)getWidthOfNeededArea(), (getHeight()-50*scale1) / (double)getHeightOfNeededArea());
|
|
|
- y += (getHeight()-50) / 2 - (getHeightOfNeededArea() * scale ) / 2 + 25;
|
|
|
+ int padding = calculatePadding();
|
|
|
+ double scale = Math.min( (getWidth()-padding) / (double)getWidthOfNeededArea(), (getHeight()-padding) / (double)getHeightOfNeededArea());
|
|
|
+ y += (getHeight()-padding) / 2 - (getHeightOfNeededArea() * scale ) / 2 + padding/2;
|
|
|
return y;
|
|
|
}
|
|
|
|
|
@@ -157,8 +169,8 @@ public class NodeView extends JPanel implements AnnimatedView, MouseListener {
|
|
|
}
|
|
|
int x = 0;
|
|
|
int y = 0;
|
|
|
- double scale1 = Math.min( (getWidth()) / (double)getWidthOfNeededArea(), (getHeight()) / (double)getHeightOfNeededArea());
|
|
|
- double scale = Math.min( (getWidth()-50*scale1) / (double)getWidthOfNeededArea(), (getHeight()-50*scale1) / (double)getHeightOfNeededArea());
|
|
|
+ int padding = calculatePadding();
|
|
|
+ double scale = Math.min( (getWidth()-padding) / (double)getWidthOfNeededArea(), (getHeight()-padding) / (double)getHeightOfNeededArea());
|
|
|
x += (getWidth()) / 2 - (getWidthOfNeededArea() * scale ) / 2;
|
|
|
y += (getHeight()) / 2 - (getHeightOfNeededArea() * scale ) / 2;
|
|
|
for( Component c : getComponents() )
|
|
@@ -166,11 +178,16 @@ public class NodeView extends JPanel implements AnnimatedView, MouseListener {
|
|
|
if( !(c instanceof AnnimatedView) )
|
|
|
continue;
|
|
|
AnnimatedView view = (AnnimatedView)c;
|
|
|
- c.setLocation( getScaledX( view.getVirtualX() - (int)minX ) + x, getScaledY( view.getVirtualY() ) + y);
|
|
|
if( c instanceof NodeView )
|
|
|
+ {
|
|
|
+ c.setLocation( getScaledX( ((NodeView)c).getPlainVirtualX() - (int)minX ) + x, getScaledY( view.getVirtualY() ) + y);
|
|
|
c.setSize( getScaledX( ((NodeView)c).getOriginalWidth() ), getScaledY( ((NodeView)c).getOriginalHeight() ) );
|
|
|
+ }
|
|
|
else
|
|
|
+ {
|
|
|
+ c.setLocation( getScaledX( view.getVirtualX() - (int)minX ) + x, getScaledY( view.getVirtualY() ) + y);
|
|
|
c.setSize( getScaledX( view.getVirtualWidth() ), getScaledY( view.getVirtualHeight() ) );
|
|
|
+ }
|
|
|
c.doLayout();
|
|
|
}
|
|
|
}
|
|
@@ -181,7 +198,6 @@ public class NodeView extends JPanel implements AnnimatedView, MouseListener {
|
|
|
if( layout == LayoutType.COMBINED && model.getColor( null ) == null )
|
|
|
return;
|
|
|
updateTooltipText();
|
|
|
- paintComponent( g );
|
|
|
double minX = Double.POSITIVE_INFINITY;
|
|
|
for( Component c : getComponents() )
|
|
|
{
|
|
@@ -190,9 +206,9 @@ public class NodeView extends JPanel implements AnnimatedView, MouseListener {
|
|
|
minX = Math.min( ((AnnimatedView)c).getVirtualX(), minX);
|
|
|
}
|
|
|
int x = 0;
|
|
|
- double scale1 = Math.min( (getWidth()) / (double)getWidthOfNeededArea(), (getHeight()) / (double)getHeightOfNeededArea());
|
|
|
- double scale = Math.min( (getWidth()-50*scale1) / (double)getWidthOfNeededArea(), (getHeight()-50*scale1) / (double)getHeightOfNeededArea());
|
|
|
- x += (getWidth()-50) / 2 - (getWidthOfNeededArea() * scale ) / 2 + 25;
|
|
|
+ int padding = calculatePadding();
|
|
|
+ double scale = Math.min( (getWidth()-padding) / (double)getWidthOfNeededArea(), (getHeight()-padding) / (double)getHeightOfNeededArea());
|
|
|
+ x += (getWidth()-padding) / 2 - (getWidthOfNeededArea() * scale ) / 2 + padding/2;
|
|
|
for( Component c : getComponents() )
|
|
|
{
|
|
|
if( c instanceof NodeView )
|
|
@@ -205,6 +221,7 @@ public class NodeView extends JPanel implements AnnimatedView, MouseListener {
|
|
|
}
|
|
|
c.paint( g.create( c.getX(), c.getY(), c.getWidth(), c.getHeight() ) );
|
|
|
}
|
|
|
+ paintComponent( g );
|
|
|
}
|
|
|
|
|
|
public void renderClass( Graphics g ) {
|