Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2006

Tip: Looking for answers? Try searching our database.

Custom Stroke

Thread view: 
Rob McDonald - 06 Jan 2006 18:23 GMT
I need to use Graphics2D to draw a figure with lines representing
constraints.  Imagine a curve, with some hatching along one side.  (bad
ascii art follows)

----------------------- line
/ / / / / / / / / / / / hatching

Of course, the hatching needs to 'follow' the line as it curves and meanders
around the plot.

My initial inclination is to accomplish this with a custom implementation of
the java.awt.Stroke interface.  Is this the best way to go?  Should it be
based on some sort of paint or fill instead?  Does anyone have any examples
of something similar laying around?

Because the hatching only belongs on one side of the line, the line segment
will need to be directed...  I.e. the hatching always falls on the right
hand side of the line.  That way, if you want the hatching as above you
traverse the line from left to right.  If you want the hatching on the top
instead, you traverse the line from right to left.

Instead of hatching, it may be easier to implement this idea with a fat
alpha=0.5 line (but that is offset to the hatched side).  That way, the
constraint would be represented with a solid curve, and the hatching would
be semi-transparent.

The Stroke interface only has one method, so I'm not sure how to accomplish
these goals...

public Shape createStrokedShape(Shape s);

I found this one example, any more thoughts are greatly appreciated.

http://www.java2s.com/ExampleCode/2D-Graphics-GUI/CustomStrokes.htm

            Rob
Andrey Kuznetsov - 06 Jan 2006 20:03 GMT
>I need to use Graphics2D to draw a figure with lines representing
> constraints.  Imagine a curve, with some hatching along one side.  (bad
> ascii art follows)
>
> ----------------------- line
> / / / / / / / / / / / / hatching
in V.J.Hardy's book "Java 2D API graphics" you can find implementation of
ShapeStroke.
You can download GLF here http://java.sun.com/developer/Books/2dgraphics/

Signature

Andrey Kuznetsov
http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities

Rob McDonald - 06 Jan 2006 20:54 GMT
> in V.J.Hardy's book "Java 2D API graphics" you can find implementation of
> ShapeStroke.
> You can download GLF here http://java.sun.com/developer/Books/2dgraphics/

Thanks for the link.  I'll have to check the book out next time I'm at the
store.

ShapeStroke doesn't offset or rotate the shape as it goes, but it should
provide good reference.  As do the author's other strokes, TextStroke and
WaveStroke.

TextStroke aligns the text with the local curve, so that may provide a hint
as to how to rotate it.  WaveStroke uses a generalized Transform, so that
may provide help too.

Starting with the first link I posted
(http://www.java2s.com/ExampleCode/2D-Graphics-GUI/CustomStrokes.htm)
SloppyStroke, I see how to access the coordinates as you traverse the curve.
If I have two consecutive points, calculating a slope, m, and then
offsetting the points by -1/m isn't too bad.  However, the bookkeeping of
the points as the iterator moves along the curve is potentially nasty...

I also came across www.psc-cavers.org/carto , a tool for cartographers,
which has a custom hatched stroke.  I haven't quite managed to pull it out
so I can test it to see what it does...

           Rob
Rob McDonald - 06 Jan 2006 22:20 GMT
> I also came across www.psc-cavers.org/carto , a tool for cartographers,
> which has a custom hatched stroke.  I haven't quite managed to pull it out
> so I can test it to see what it does...

This tool's strokes look like they'll do the trick nicely.  Or at least
provide a very close foundation.

Thanks for the pointers.

         Rob


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.