本文整理汇总了Java中java.awt.BasicStroke.getDashArray方法的典型用法代码示例。如果您正苦于以下问题:Java BasicStroke.getDashArray方法的具体用法?Java BasicStroke.getDashArray怎么用?Java BasicStroke.getDashArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.BasicStroke
的用法示例。
在下文中一共展示了BasicStroke.getDashArray方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getScaledDashArray
import java.awt.BasicStroke; //导入方法依赖的package包/类
float[] getScaledDashArray() {
BasicStroke stroke = getStyle().getStroke();
if (stroke == null) {
return null;
}
float[] dashArray = stroke.getDashArray();
float[] scaledDashArray;
if (dashArray != null) {
float scalingFactor = getWidth();
if (scalingFactor <= 0) {
scalingFactor = 1;
}
if (scalingFactor != 1) {
scaledDashArray = DataStructureUtils.cloneAndMultiplyArray(dashArray, scalingFactor);
} else {
scaledDashArray = dashArray;
}
} else {
scaledDashArray = dashArray;
}
return scaledDashArray;
}
示例2: drawRect
import java.awt.BasicStroke; //导入方法依赖的package包/类
public void drawRect(SunGraphics2D sg2d,
int x, int y, int w, int h)
{
if (w >= 0 && h >= 0) {
if (sg2d.strokeState < SunGraphics2D.STROKE_CUSTOM) {
BasicStroke bs = ((BasicStroke) sg2d.stroke);
if (w > 0 && h > 0) {
if (bs.getLineJoin() == BasicStroke.JOIN_MITER &&
bs.getDashArray() == null)
{
double lw = bs.getLineWidth();
drawRectangle(sg2d, x, y, w, h, lw);
return;
}
} else {
// Note: This calls the integer version which
// will verify that the local drawLine optimizations
// work and call super.drawLine(), if not.
drawLine(sg2d, x, y, x+w, y+h);
return;
}
}
super.drawRect(sg2d, x, y, w, h);
}
}
示例3: saveStroke
import java.awt.BasicStroke; //导入方法依赖的package包/类
public static void saveStroke(final OutputStream stream,
final Stroke stroke, final MemoryData memoryData)
throws IOException {
if (stroke instanceof BasicStroke) {
BasicStroke basickStroke = (BasicStroke) stroke;
saveBoolean(stream, true);
saveDouble(stream, basickStroke.getLineWidth());
saveInteger(stream, basickStroke.getEndCap());
saveInteger(stream, basickStroke.getLineJoin());
saveDouble(stream, basickStroke.getDashPhase());
saveDouble(stream, basickStroke.getMiterLimit());
final float ar[] = basickStroke.getDashArray();
if (ar == null)
saveInteger(stream, -1);
else {
saveInteger(stream, ar.length);
for (final float element : ar)
saveDouble(stream, element);
}
memoryData.stroukes.add(stroke);
} else if (stroke instanceof WayStroke) {
saveBoolean(stream, false);
saveInteger(stream, -10 - ((WayStroke) stroke).getType());
} else if (stroke instanceof ArrowedStroke) {
saveBoolean(stream, false);
saveInteger(stream, -20 - ((ArrowedStroke) stroke).getType());
}
}
示例4: draw
import java.awt.BasicStroke; //导入方法依赖的package包/类
public void draw(SunGraphics2D sg2d, Shape s) {
if (sg2d.strokeState < SunGraphics2D.STROKE_CUSTOM) {
BasicStroke bs = ((BasicStroke) sg2d.stroke);
if (s instanceof Rectangle2D) {
if (bs.getLineJoin() == BasicStroke.JOIN_MITER &&
bs.getDashArray() == null)
{
Rectangle2D r2d = (Rectangle2D) s;
double w = r2d.getWidth();
double h = r2d.getHeight();
double x = r2d.getX();
double y = r2d.getY();
if (w >= 0 && h >= 0) {
double lw = bs.getLineWidth();
drawRectangle(sg2d, x, y, w, h, lw);
}
return;
}
} else if (s instanceof Line2D) {
Line2D l2d = (Line2D) s;
if (drawGeneralLine(sg2d,
l2d.getX1(), l2d.getY1(),
l2d.getX2(), l2d.getY2()))
{
return;
}
}
}
outpipe.draw(sg2d, s);
}
示例5: strokeTo
import java.awt.BasicStroke; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void strokeTo(Shape src,
AffineTransform transform,
BasicStroke bs,
boolean thin,
boolean normalize,
boolean antialias,
PathConsumer2D sr)
{
PathStroker stroker = new PathStroker(sr);
PathConsumer consumer = stroker;
float matrix[] = null;
if (!thin) {
stroker.setPenDiameter(bs.getLineWidth());
if (transform != null) {
matrix = getTransformMatrix(transform);
}
stroker.setPenT4(matrix);
stroker.setPenFitting(PenUnits, MinPenUnits);
}
stroker.setCaps(RasterizerCaps[bs.getEndCap()]);
stroker.setCorners(RasterizerCorners[bs.getLineJoin()],
bs.getMiterLimit());
float[] dashes = bs.getDashArray();
if (dashes != null) {
PathDasher dasher = new PathDasher(stroker);
dasher.setDash(dashes, bs.getDashPhase());
if (transform != null && matrix == null) {
matrix = getTransformMatrix(transform);
}
dasher.setDashT4(matrix);
consumer = dasher;
}
try {
PathIterator pi = src.getPathIterator(transform);
feedConsumer(pi, consumer, normalize, 0.25f);
} catch (PathException e) {
throw new InternalError("Unable to Stroke shape ("+
e.getMessage()+")", e);
} finally {
while (consumer != null && consumer != sr) {
PathConsumer next = consumer.getConsumer();
consumer.dispose();
consumer = next;
}
}
}
示例6: setStroke
import java.awt.BasicStroke; //导入方法依赖的package包/类
public void setStroke(Stroke stroke) {
if (stroke instanceof BasicStroke) {
BasicStroke bs = (BasicStroke) stroke;
// linewidth
gc.setLineWidth((int) bs.getLineWidth());
// line join
switch (bs.getLineJoin()) {
case BasicStroke.JOIN_BEVEL :
gc.setLineJoin(SWT.JOIN_BEVEL);
break;
case BasicStroke.JOIN_MITER :
gc.setLineJoin(SWT.JOIN_MITER);
break;
case BasicStroke.JOIN_ROUND :
gc.setLineJoin(SWT.JOIN_ROUND);
break;
}
// line cap
switch (bs.getEndCap()) {
case BasicStroke.CAP_BUTT :
gc.setLineCap(SWT.CAP_FLAT);
break;
case BasicStroke.CAP_ROUND :
gc.setLineCap(SWT.CAP_ROUND);
break;
case BasicStroke.CAP_SQUARE :
gc.setLineCap(SWT.CAP_SQUARE);
break;
}
// set the line style to solid by default
gc.setLineStyle(SWT.LINE_SOLID);
// apply dash style if any
float[] dashes = bs.getDashArray();
if (dashes != null) {
int[] swtDashes = new int[dashes.length];
for (int i = 0; i < swtDashes.length; i++) {
swtDashes[i] = (int) dashes[i];
}
gc.setLineDash(swtDashes);
}
}
else {
throw new RuntimeException(
"Can only handle 'Basic Stroke' at present.");
}
}