下面列出了java.awt.BasicStroke#getDashPhase ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void setStroke(Stroke s) {
String l;
if (s instanceof BasicStroke) {
BasicStroke bs = (BasicStroke)s;
l = "setStroke(Stoke):" +
"\n s = BasicStroke(" +
"\n dash[]: "+Arrays.toString(bs.getDashArray()) +
"\n dashPhase: "+bs.getDashPhase() +
"\n endCap: "+bs.getEndCap() +
"\n lineJoin: "+bs.getLineJoin() +
"\n width: "+bs.getLineWidth() +
"\n miterLimit: "+bs.getMiterLimit() +
"\n )";
} else {
l = "setStroke(Stoke):" +
"\n s = " + s;
}
log.println( l );
g2D.setStroke( s );
}
/**
* Performs the writing of a single object.
*
* @param tagName the tag name.
* @param object the object ({@link BasicStroke} expected).
* @param writer the writer.
* @param mPlexAttribute ??
* @param mPlexValue ??
*
* @throws IOException if there is an I/O problem.
* @throws XMLWriterException if there is a problem with the writer.
*/
public void write(final String tagName, final Object object, final XMLWriter writer,
final String mPlexAttribute, final String mPlexValue)
throws IOException, XMLWriterException {
final BasicStroke stroke = (BasicStroke) object;
final float[] dashArray = stroke.getDashArray();
final float dashPhase = stroke.getDashPhase();
final int endCap = stroke.getEndCap();
final int lineJoin = stroke.getLineJoin();
final float lineWidth = stroke.getLineWidth();
final float miterLimit = stroke.getMiterLimit();
final AttributeList attribs = new AttributeList();
if (mPlexAttribute != null) {
attribs.setAttribute(mPlexAttribute, mPlexValue);
}
attribs.setAttribute("type", "basic");
attribs.setAttribute("endCap", String.valueOf(endCap));
attribs.setAttribute("lineJoin", String.valueOf(lineJoin));
attribs.setAttribute("lineWidth", String.valueOf(lineWidth));
attribs.setAttribute("miterLimit", String.valueOf(miterLimit));
if (dashArray != null) {
attribs.setAttribute("dashArray", toString(dashArray));
attribs.setAttribute("dashPhase", String.valueOf(dashPhase));
}
writer.writeTag(tagName, attribs, true);
}
private Stroke transformStroke( final Stroke stroke ) {
if ( !( stroke instanceof BasicStroke ) ) {
return stroke;
}
final BasicStroke st = (BasicStroke) stroke;
final float scale = (float) Math.sqrt( Math.abs( transform.getDeterminant() ) );
final float[] dash = st.getDashArray();
if ( dash != null ) {
final int dashLength = dash.length;
for ( int k = 0; k < dashLength; ++k ) {
dash[k] *= scale;
}
}
return new BasicStroke( st.getLineWidth() * scale, st.getEndCap(), st.getLineJoin(), st.getMiterLimit(), dash, st
.getDashPhase()
* scale );
}
public String toAttributeValue( final Object o ) throws BeanException {
if ( o instanceof BasicStroke == false ) {
throw new BeanException();
}
final BasicStroke s = (BasicStroke) o;
final float lineWidth = s.getLineWidth();
final int lineJoin = s.getLineJoin();
final float dashPhase = s.getDashPhase();
final int endCap = s.getEndCap();
final float mitterLimit = s.getMiterLimit();
final float[] dashArray = s.getDashArray();
final StringBuilder b = new StringBuilder();
if ( dashArray != null ) {
for ( int i = 0; i < dashArray.length; i++ ) {
if ( i != 0 ) {
b.append( "," );
}
b.append( dashArray[i] );
}
}
return String.format( Locale.US, "BasicStroke:%f:%d:%f:%d:%f:%s", lineWidth, lineJoin, dashPhase, endCap,
mitterLimit, b.toString() );
}
static Stroke setLineWidth(Stroke s, float lw) {
if(s instanceof BasicStroke) {
BasicStroke b = (BasicStroke)s;
float[] da = b.getDashArray();
if(da != null) {
float[] dsa = new float[da.length];
for(int i = 0; i < dsa.length; i++)
dsa[i] = da[i] * (lw / b.getLineWidth());
da = dsa;
}
return new BasicStroke(lw,
b.getEndCap(),
b.getLineJoin(),
b.getMiterLimit(),
da,
b.getDashPhase());
}
else return s;
}
private Stroke transformStroke(Stroke stroke) {
if (!(stroke instanceof BasicStroke)) {
return stroke;
}
BasicStroke st = (BasicStroke) stroke;
float scale = (float) Math.sqrt(Math.abs(transform.getDeterminant()));
float dash[] = st.getDashArray();
if (dash != null) {
for (int k = 0; k < dash.length; ++k) {
dash[k] *= scale;
}
}
return new BasicStroke(st.getLineWidth() * scale, st.getEndCap(), st.getLineJoin(), st.getMiterLimit(), dash, st.getDashPhase() * scale);
}
private Stroke transformStroke(Stroke stroke) {
if (!(stroke instanceof BasicStroke))
return stroke;
BasicStroke st = (BasicStroke)stroke;
float scale = (float)Math.sqrt(Math.abs(transform.getDeterminant()));
float dash[] = st.getDashArray();
if (dash != null) {
for (int k = 0; k < dash.length; ++k)
dash[k] *= scale;
}
return new BasicStroke(st.getLineWidth() * scale, st.getEndCap(), st.getLineJoin(), st.getMiterLimit(), dash, st.getDashPhase() * scale);
}
public BasicStroke getStroke() {
BasicStroke stroke = style.getStroke();
if (stroke != null) {
float[] scaledDashArray = getScaledDashArray();
BasicStroke scaledStroke = new BasicStroke(this.getWidth(), stroke.getEndCap(), stroke.getLineJoin(),
stroke.getMiterLimit(), scaledDashArray, stroke.getDashPhase());
return scaledStroke;
} else {
return null;
}
}
static Stroke setEndCap(Stroke s, int cap) {
if(s instanceof BasicStroke) {
BasicStroke b = (BasicStroke)s;
return new BasicStroke(b.getLineWidth(),
cap,
b.getLineJoin(),
b.getMiterLimit(),
b.getDashArray(),
b.getDashPhase());
}
else return s;
}
/**
* Overrides TPoint setStroke method.
*
* @param stroke the desired stroke
*/
public void setStroke(BasicStroke stroke) {
if(stroke==null) {
return;
}
this.stroke = new BasicStroke(stroke.getLineWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 8, stroke.getDashArray(), stroke.getDashPhase());
}
private Stroke transformStroke(Stroke stroke) {
if (!(stroke instanceof BasicStroke))
return stroke;
BasicStroke st = (BasicStroke)stroke;
float scale = (float)Math.sqrt(Math.abs(transform.getDeterminant()));
float dash[] = st.getDashArray();
if (dash != null) {
for (int k = 0; k < dash.length; ++k)
dash[k] *= scale;
}
return new BasicStroke(st.getLineWidth() * scale, st.getEndCap(), st.getLineJoin(), st.getMiterLimit(), dash, st.getDashPhase() * scale);
}