Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Double line border (Read 7703 times)
nsandhu
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 16
Joined: Aug 22nd, 2011
Double line border
Jan 27th, 2012 at 10:38pm
Print Post  
I am looking for doing a double lined border around my rectangle shapes. I tried using the decorations in the Shape class to define an inner rectangle, however that is not ideal and has a problem that it can't be saved to xml format.

Does anyone have a better solution for doing double lines around rectangles?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Double line border
Reply #1 - Jan 30th, 2012 at 8:47am
Print Post  
In .NET you would do that using compound pens, but it seems they don't have equivalent in Java. Instead, you could set node.CustomDraw to CustomDraw.Additional to draw a second border from the drawNode event handler:

Code
Select All
public void drawNode(DrawNodeEvent e)
{
	Rectangle2D rect = e.getBounds();
	rect.setFrame(
			rect.getMinX() + 1,
			rect.getMinY() + 1,
			rect.getWidth() - 2,
			rect.getHeight() -2);

	Graphics2D g = e.getGraphics();
	e.getNode().getPen().applyTo(g);
	g.draw(rect);
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
nsandhu
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 16
Joined: Aug 22nd, 2011
Re: Double line border
Reply #2 - Jan 30th, 2012 at 6:43pm
Print Post  
It works but its not ideal. Java's equivalent of compound Pen is found in the Stroke class. There is no way in the current Pen implementation to specify a different Stroke then the Basic stroke. If the stroke could be customized in the Pen implementation then one can do all kinds of customization.

Take a look at this link(http://www.jhlabs.com/java/java2d/strokes/) to see what is possible with different Strokes
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Double line border
Reply #3 - Feb 6th, 2012 at 1:32pm
Print Post  
You can derive from Pen and set your custom stroke from the applyTo method.

Code
Select All
class MyPen extends Pen
{
	@Override
	public void applyTo(Graphics2D g)
	{
		g.setStroke(new CompositeStroke(
			new BasicStroke(getWidth()),
			new BasicStroke(getWidth() / 4)));
		g.setPaint(getColor());
	}
}

public void nodeCreated(NodeEvent e)
{
	MyPen pen = new MyPen();
	pen.setWidth(3);
	e.getNode().setPen(pen);
	// ...
} 



The sample CompositeStroke from that page doesn't look that great when applied to anything more complex than a simple line or curve though.

Stoyan
  

compositestroke.png (Attachment deleted)
Back to top
 
IP Logged
 
nsandhu
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 16
Joined: Aug 22nd, 2011
Re: Double line border
Reply #4 - Feb 7th, 2012 at 6:05pm
Print Post  
I agree, Sad
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Double line border
Reply #5 - Feb 11th, 2012 at 10:45am
Print Post  
Here's a stroke class that works fine for most shapes:
http://mindfusion.eu/_samples/DoubleStroke.txt



It ignores open figures in the shape and paints them as single lines. There are open figures drawn by ShapeNodes whose shapes contain decoration lines. You can replace the addPolygon(openFigure, result, false) line with something similar to the CompositeStroke.createStrokedShape implementation to add double lines for open figures.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint