Fixed text alignment within outline boxes; removed some debug logging;

modified code to use italicized font for interface chains.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@187 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2001-07-17 05:16:16 +00:00
parent 79b7065abf
commit c34ca2cfc3
3 changed files with 37 additions and 25 deletions
@@ -1,11 +1,12 @@
//
// $Id: CascadingChainVisualizer.java,v 1.3 2001/07/17 01:54:19 mdb Exp $
// $Id: CascadingChainVisualizer.java,v 1.4 2001/07/17 05:16:16 mdb Exp $
package com.samskivert.viztool.viz;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.geom.*;
import java.awt.font.TextLayout;
import java.awt.geom.*;
import java.util.ArrayList;
/**
@@ -29,7 +30,8 @@ public class CascadingChainVisualizer
public void layoutChain (Chain chain, Graphics2D gfx)
{
// create a text layout based on the current rendering conditions
TextLayout layout = new TextLayout(chain.getName(), gfx.getFont(),
Font font = chain.getRoot().isInterface() ? _ifaceFont : _classFont;
TextLayout layout = new TextLayout(chain.getName(), font,
gfx.getFontRenderContext());
// the header will be the name of this chain surrounded by N
@@ -71,18 +73,19 @@ public class CascadingChainVisualizer
// " at +" + x + "+" + y + ".");
// create a text layout based on the current rendering conditions
TextLayout layout = new TextLayout(chain.getName(), gfx.getFont(),
Font font = chain.getRoot().isInterface() ? _ifaceFont : _classFont;
TextLayout layout = new TextLayout(chain.getName(), font,
gfx.getFontRenderContext());
// stroke a box that will contain the name
Rectangle2D tbounds = getTextBox(gfx, layout);
double tx = -bounds.getX(), ty = -bounds.getY();
double dx = -tbounds.getX(), dy = -tbounds.getY();
tbounds.setRect(x, y, tbounds.getWidth(), tbounds.getHeight());
gfx.draw(tbounds);
// now draw the name
layout.draw(gfx, (float)(x + HEADER_BORDER),
(float)(y + layout.getAscent() + HEADER_BORDER));
layout.draw(gfx, (float)(x + dx + HEADER_BORDER),
(float)(y + dy + HEADER_BORDER));
// render our connecty lines
ArrayList kids = chain.getChildren();
@@ -95,8 +98,7 @@ public class CascadingChainVisualizer
for (int i = 0; i < kids.size(); i++) {
Chain kid = (Chain)kids.get(i);
kbounds = kid.getBounds();
double ly = y + kbounds.getY() + layout.getAscent() +
HEADER_BORDER;
double ly = y + kbounds.getY() + dy + HEADER_BORDER;
path.lineTo((float)(x + half), (float)ly);
path.lineTo((float)(x + kbounds.getX()), (float)ly);
path.moveTo((float)(x + half), (float)ly);
@@ -128,4 +130,7 @@ public class CascadingChainVisualizer
bounds.getHeight() + 2*HEADER_BORDER);
return bounds;
}
protected static Font _classFont = new Font("Helvetica", Font.PLAIN, 8);
protected static Font _ifaceFont = new Font("Helvetica", Font.ITALIC, 8);
}
@@ -1,5 +1,5 @@
//
// $Id: ChainGroup.java,v 1.2 2001/07/17 01:54:19 mdb Exp $
// $Id: ChainGroup.java,v 1.3 2001/07/17 05:16:16 mdb Exp $
package com.samskivert.viztool.viz;
@@ -47,9 +47,14 @@ public class ChainGroup
TextLayout layout = new TextLayout(_pkg, gfx.getFont(),
gfx.getFontRenderContext());
// keep room for our border
// we let the title stick halfway up out of our rectangular
// bounding box
Rectangle2D tbounds = layout.getBounds();
double titleAscent = tbounds.getHeight()/2;
// keep room for our border and title
pageWidth -= 2*BORDER;
pageHeight -= (2*BORDER + layout.getAscent());
pageHeight -= (2*BORDER + titleAscent);
// arrange them on the page
ElementLayout elay = new PackedColumnElementLayout();
@@ -58,7 +63,7 @@ public class ChainGroup
// for now we're punting and assume that no group will exceed a
// single page in size
double width = dims[0].getWidth();
double height = dims[0].getHeight() + layout.getAscent();
double height = dims[0].getHeight() + titleAscent;
// make sure we're wide enough for our title
width = Math.max(width, layout.getAdvance() + 4);
@@ -83,8 +88,17 @@ public class ChainGroup
TextLayout layout = new TextLayout(_pkg, gfx.getFont(),
gfx.getFontRenderContext());
// shift everything down to the ascent of the title
y += layout.getAscent();
// we let the title stick halfway up out of our rectangular
// bounding box
Rectangle2D tbounds = layout.getBounds();
double titleAscent = tbounds.getHeight()/2;
double dy = -tbounds.getY();
// print our title
layout.draw(gfx, (float)(x + BORDER + 2), (float)(y + dy));
// shift everything down by the ascent of the title
y += titleAscent;
// translate to our rendering area
double cx = x + BORDER;
@@ -103,10 +117,8 @@ public class ChainGroup
// undo the translation
gfx.translate(-cx, -cy);
// print our title and a box around our border
layout.draw(gfx, (float)(x + BORDER + 2), (float)y);
double height = _size.getHeight() - layout.getAscent();
// print our border box
double height = _size.getHeight() - titleAscent;
GeneralPath path = new GeneralPath();
path.moveTo((float)(x + BORDER), (float)y);
path.lineTo((float)x, (float)y);
@@ -1,5 +1,5 @@
//
// $Id: PackedColumnElementLayout.java,v 1.3 2001/07/17 01:54:19 mdb Exp $
// $Id: PackedColumnElementLayout.java,v 1.4 2001/07/17 05:16:16 mdb Exp $
package com.samskivert.viztool.viz;
@@ -22,9 +22,6 @@ public class PackedColumnElementLayout implements ElementLayout
elements.toArray(elems);
Arrays.sort(elems, HEIGHT_COMP);
System.out.println("Laying out in " +
pageWidth + "x" + pageHeight + ".");
// lay out the elements across the page
ArrayList pagedims = new ArrayList();
double x = 0, y = 0, rowheight = 0, maxwidth = 0;
@@ -65,8 +62,6 @@ public class PackedColumnElementLayout implements ElementLayout
// lay this element out at our current coordinates
elems[i].setBounds(x, y, bounds.getWidth(), bounds.getHeight());
// elems[i].setPage(pageno);
System.out.println("Laying out " + elems[i].getName() +
" at " + elems[i].getBounds() + ".");
// keep track of the maximum row height
if (bounds.getHeight() > rowheight) {