http://www.jpicedt.org

jpicedt.graphic
Class PEToolKit

java.lang.Object
  extended by jpicedt.graphic.PEToolKit

public class PEToolKit
extends Object

A collection of static “utilities” methods targetting number formatting, Swing's widget creation, computation of geometrical properties,…

Since:
jpicedt 1.0
Version:
$Id: PEToolKit.java,v 1.28 2013/03/27 07:20:41 vincentb1 Exp $

Author:
Sylvain Reynal

Constructor Summary
PEToolKit()
           
 
Method Summary
static PicVector computeTangentToPath(Shape s, PicPoint pt, double maxDist)
          Returns the tangent to the given path, computed at the path-point which is closest to the given point "pt" than the given maximum distance Return null otherwise (ie if pt is too far from the given shape).
static QuadCurve2D[] convertCubicBezierToQuad(CubicCurve2D cubic)
          Converts the given cubic curve to a quad curve
static PicPoint[] convertCubicBezierToQuad(Point2D p1, Point2D pCtrl1, Point2D pCtrl2, Point2D p2)
          Given four specification points of a cubic bezier spline, returns an array of five PicPoint's containing the specification points of two quad bezier splines having the same geometry as the given curve.
static PicPoint[] convertQuadBezierToCubic(Point2D p1, Point2D pCtrl, Point2D p2)
          Given the three specification points of a quad bezier spline, returns an array of PicPoint's containing the four specification points of a cubic spline having the same geometry.
static CubicCurve2D convertQuadBezierToCubic(QuadCurve2D quad)
          Converts the given quad curve to a cubic curve
static
<T> PEComboBox<T>
createComboBox(Map<T,?> map)
          creates a PEComboBox (aka JComboBox) from an EnumMap.
static JComboBox createComboBox(Object[] items)
          creates a JComboBox
static Line2D[] createFlattenedPath(Shape s, double flatness)
          Return an array of Line2D's representing the (visible part of the) flattened path of the given shape.
static ImageIcon createImageIcon(String icon)
          create an ImageIcon built from "/jpicedt/images/"+icon+".png"
static JLabel createJLabel(String icon)
          create a JLabel with an Icon built from "/jpicedt/images/"+icon+".png"
static Shape[] createPath(Shape s)
          Return an array of Line2D, Quad2D and Cubic2D, representing the (visible part of the) path of the given shape.
static String doubleToString(double x)
          Returns a string representation of the given double.
static String doubleToString(Double x)
           
static String getIconLocation(String icon)
           
static String intToString(double x)
           
static double[] minMaxArray(double[] array)
          Return an array of length 2 containing the minimum and the maximum of the given array, in that order.
static void setAppIconToDefault(JFrame frame)
           
static int setImageIcon(JFrame frame, String icon)
          Configure l'icône du cadre frame à l'icône identifiée icon s'il est possible de la trouver, ou sinon ne fait rien.
static void setMaximumFractionDigits(int n)
          Set the maximum number of fraction digits to be used when formatting doubles using the doubleToString() method.
static int testDistanceToPath(Shape s, PicPoint pt, double maxDist)
          Return a positive integer if the given point "pt" lies closer to the given shape path (= stroke) than the given maximum distance ; this integer indicates which segment/quad/cubic of the path, starting from 0 (ie according to getPathIterator numbering scheme), lies at the closest distance from "pt" ; -1 otherwise.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PEToolKit

public PEToolKit()
Method Detail

setMaximumFractionDigits

public static void setMaximumFractionDigits(int n)
Set the maximum number of fraction digits to be used when formatting doubles using the doubleToString() method.

Parameters:
n - set to a negative number to retrieve the default behaviour

doubleToString

public static String doubleToString(double x)
Returns a string representation of the given double. Max nb of digits may be changed by invoking setMaximumFractionDigits beforehands.


doubleToString

public static String doubleToString(Double x)
Returns:
a string representation of the given double, ako %0.2f

intToString

public static String intToString(double x)
Returns:
a string representation of the given int (with implicit cast from double to int)

minMaxArray

public static double[] minMaxArray(double[] array)
Return an array of length 2 containing the minimum and the maximum of the given array, in that order.

Parameters:
array - an array of length greater than 0

computeTangentToPath

public static PicVector computeTangentToPath(Shape s,
                                             PicPoint pt,
                                             double maxDist)
Returns the tangent to the given path, computed at the path-point which is closest to the given point "pt" than the given maximum distance Return null otherwise (ie if pt is too far from the given shape).

This implementation relies on FlatteningPathIterator, hence the smaller the "maxDist" parameter, the better the return result.

Parameters:
s - basically this would rather be a quadratic or a cubic bezier segment, but Arc2D should work as well..
maxDist - the maximum distance allowed between the given PicPoint and the stroke of the given Shape before null is returned ; may be Double.POSITIVE_INFINITY, in which case a tangent is always returned.
Returns:
a unit-norm vector

testDistanceToPath

public static int testDistanceToPath(Shape s,
                                     PicPoint pt,
                                     double maxDist)
Return a positive integer if the given point "pt" lies closer to the given shape path (= stroke) than the given maximum distance ; this integer indicates which segment/quad/cubic of the path, starting from 0 (ie according to getPathIterator numbering scheme), lies at the closest distance from "pt" ; -1 otherwise.

This may be used by the UI to determine if a mouse-click occured on a stroke path, especially for complex shapes like Bezier curves, or arcs (although the returned integer only really makes sense for shape which are made of bezier curves or segments). This uses FlatteningPathIterator, with the given maxDist parameter also used as the flatness parameter, since it's the value which gives the best results.


createPath

public static Shape[] createPath(Shape s)
Return an array of Line2D, Quad2D and Cubic2D, representing the (visible part of the) path of the given shape. This is based on Shape.getPathIterator() This may be used, for instance, by formaters willing to express a given shape only in terms of Bezier curves and segments, if these are the only shapes available in the given target language (e.g. this is the case with LaTeX's picture environment, where ellipses are not available).


createFlattenedPath

public static Line2D[] createFlattenedPath(Shape s,
                                           double flatness)
Return an array of Line2D's representing the (visible part of the) flattened path of the given shape. This is based on FlattenedPathIterator, and may be used by the UI to test the distance b/w a given shape and the mouse, or by a formatter to format a given shape in terms of segments only, if the target language only supports lines.

Parameters:
flatness - the flatness used to build the FlattenedPathIterator (max. dist. b/w shape and segments of the flattened path).

convertCubicBezierToQuad

public static PicPoint[] convertCubicBezierToQuad(Point2D p1,
                                                  Point2D pCtrl1,
                                                  Point2D pCtrl2,
                                                  Point2D p2)
Given four specification points of a cubic bezier spline, returns an array of five PicPoint's containing the specification points of two quad bezier splines having the same geometry as the given curve.

Parameters:
p1 - first cubic spline end-point
p2 - second cubic spline end-point
pCtrl1 - first cubic spline control-point
pCtrl2 - second cubic spline control-point
Returns:
an array containing {Q1P1, Q1CTRL,Q1P2=Q2P1, Q2CTRL, Q2P2}, where Q1 and Q2 refer to the two quad splines, and QiCTRL are quad's control-points.
See Also:
CubicCurve2D, QuadCurve2D

convertQuadBezierToCubic

public static PicPoint[] convertQuadBezierToCubic(Point2D p1,
                                                  Point2D pCtrl,
                                                  Point2D p2)
Given the three specification points of a quad bezier spline, returns an array of PicPoint's containing the four specification points of a cubic spline having the same geometry.

The following algorith is being used (xQ and xC refer to quad and cubic spline resp.) :

where xQ(0) = pt1, xQ(1) = ptCtrl and xQ(2) = pt2

Parameters:
p1 - first quad end-point
p2 - second quad end-point
pCtrl - quad control-point
Returns:
{P1, PCTRL1, PCTRL2, P2}

convertQuadBezierToCubic

public static CubicCurve2D convertQuadBezierToCubic(QuadCurve2D quad)
Converts the given quad curve to a cubic curve


convertCubicBezierToQuad

public static QuadCurve2D[] convertCubicBezierToQuad(CubicCurve2D cubic)
Converts the given cubic curve to a quad curve


getIconLocation

public static String getIconLocation(String icon)
Parameters:
icon - Le nom de base de la ressouce image contenant l'icône, sans l'extension .png.
Returns:
Le chemin de la ressource

createImageIcon

public static ImageIcon createImageIcon(String icon)
create an ImageIcon built from "/jpicedt/images/"+icon+".png"


setImageIcon

public static int setImageIcon(JFrame frame,
                               String icon)
Configure l'icône du cadre frame à l'icône identifiée icon s'il est possible de la trouver, ou sinon ne fait rien.

Returns:
0 si ça a réussi.

setAppIconToDefault

public static void setAppIconToDefault(JFrame frame)

createJLabel

public static JLabel createJLabel(String icon)
create a JLabel with an Icon built from "/jpicedt/images/"+icon+".png"


createComboBox

public static JComboBox createComboBox(Object[] items)
creates a JComboBox


createComboBox

public static <T> PEComboBox<T> createComboBox(Map<T,?> map)
creates a PEComboBox (aka JComboBox) from an EnumMap.

Since:
jpicedt 1.5

http://www.jpicedt.org

Submit a bug : syd@jpicedt.org