當前位置: 首頁>>代碼示例>>Java>>正文


Java Shape類代碼示例

本文整理匯總了Java中javafx.scene.shape.Shape的典型用法代碼示例。如果您正苦於以下問題:Java Shape類的具體用法?Java Shape怎麽用?Java Shape使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Shape類屬於javafx.scene.shape包,在下文中一共展示了Shape類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: generateMecanumDriveBase

import javafx.scene.shape.Shape; //導入依賴的package包/類
/**
 * Generates a mecanum drive base.
 *
 * @param wheelWidth  the width (or thickness) of the wheels
 * @param wheelHeight the height (or diameter) of the wheels
 * @param frameWidth  the width of the robot frame
 * @param frameHeight the height of the robot frame
 */
private static Shape generateMecanumDriveBase(double wheelWidth,
                                              double wheelHeight,
                                              double frameWidth,
                                              double frameHeight) {
  Rectangle frame = new Rectangle(wheelWidth, 0, frameWidth, frameHeight);
  frame.setFill(null);
  frame.setStroke(Color.WHITE);

  final Shape fl = mecanumWheel(wheelWidth, wheelHeight, MecanumWheelPos.FRONT_LEFT);
  final Shape fr = mecanumWheel(wheelWidth, wheelHeight, MecanumWheelPos.FRONT_RIGHT);
  final Shape rl = mecanumWheel(wheelWidth, wheelHeight, MecanumWheelPos.REAR_LEFT);
  final Shape rr = mecanumWheel(wheelWidth, wheelHeight, MecanumWheelPos.REAR_RIGHT);
  fr.setTranslateX(frameWidth + wheelWidth);
  rl.setTranslateY(frameHeight - wheelHeight);
  rr.setTranslateX(frameWidth + wheelWidth);
  rr.setTranslateY(frameHeight - wheelHeight);

  Shape combined = union(frame, fl, fr, rl, rr);
  combined.getStyleClass().addAll("robot-drive", "mecanum-drive");
  return combined;
}
 
開發者ID:wpilibsuite,項目名稱:shuffleboard,代碼行數:30,代碼來源:MecanumDriveWidget.java

示例2: adjust

import javafx.scene.shape.Shape; //導入依賴的package包/類
@Override
public Node adjust(Node node, double scale) {
	requireNonNull(node);
	requireValidScale(scale);
	
	if (node instanceof Shape) {
		Shape shape = (Shape) node;
		shape.strokeDashOffsetProperty().set(shape.strokeDashOffsetProperty().multiply(scale).get());
		shape.strokeWidthProperty().set(shape.strokeWidthProperty().multiply(scale).get());
		shape.strokeMiterLimitProperty().set(shape.strokeMiterLimitProperty().multiply(scale).get());
		shape.translateXProperty().set(shape.translateXProperty().multiply(scale).get());
		shape.translateYProperty().set(shape.translateYProperty().multiply(scale).get());
		shape.translateZProperty().set(shape.translateZProperty().multiply(scale).get());
	}
	return super.adjust(node, scale);
}
 
開發者ID:yumix,項目名稱:javafx-dpi-scaling,代碼行數:17,代碼來源:ShapeAdjuster.java

示例3: testManyProviders

import javafx.scene.shape.Shape; //導入依賴的package包/類
/**
 * Test several enabled+registered providers at the same time. They should
 * all paint their own events.
 */
@Test
public void testManyProviders() {
    TimeGraphDrawnEventProvider provider1 = new StubDrawnEventProvider1();
    TimeGraphDrawnEventProvider provider2 = new StubDrawnEventProvider2();
    MANAGER.getRegisteredProviders().add(provider1);
    MANAGER.getRegisteredProviders().add(provider2);
    provider1.enabledProperty().set(true);
    provider2.enabledProperty().set(true);

    repaint();

    Collection<Shape> events = getRenderedEvents();
    assertEquals(StubDrawnEventProvider1.NB_SYMBOLS + StubDrawnEventProvider2.NB_SYMBOLS,
            events.size());
}
 
開發者ID:lttng,項目名稱:lttng-scope,代碼行數:20,代碼來源:TimeGraphWidgetDrawnEventsTest.java

示例4: testEnabling

import javafx.scene.shape.Shape; //導入依賴的package包/類
/**
 * Test changing the 'enabled' property of a provider from false to true.
 * This should result in new events being painted.
 */
@Test
public void testEnabling() {
    TimeGraphDrawnEventProvider provider = new StubDrawnEventProvider1();
    MANAGER.getRegisteredProviders().add(provider);
    provider.enabledProperty().set(false);
    repaint();

    Collection<Shape> events = getRenderedEvents();
    assertTrue(events.isEmpty());

    provider.enabledProperty().set(true);
    repaint();

    events = getRenderedEvents();
    assertEquals(StubDrawnEventProvider1.NB_SYMBOLS, events.size());
}
 
開發者ID:lttng,項目名稱:lttng-scope,代碼行數:21,代碼來源:TimeGraphWidgetDrawnEventsTest.java

示例5: testDisabling

import javafx.scene.shape.Shape; //導入依賴的package包/類
/**
 * Test changing the 'enabled' property of a provider from true to false.
 * This should remove its events from the view.
 */
@Test
public void testDisabling() {
    TimeGraphDrawnEventProvider provider = new StubDrawnEventProvider1();
    MANAGER.getRegisteredProviders().add(provider);

    provider.enabledProperty().set(true);
    repaint();

    Collection<Shape> events = getRenderedEvents();
    assertEquals(StubDrawnEventProvider1.NB_SYMBOLS, events.size());

    provider.enabledProperty().set(false);
    repaint();

    events = getRenderedEvents();
    assertTrue(events.isEmpty());
}
 
開發者ID:lttng,項目名稱:lttng-scope,代碼行數:22,代碼來源:TimeGraphWidgetDrawnEventsTest.java

示例6: strokePattern

import javafx.scene.shape.Shape; //導入依賴的package包/類
private static Function strokePattern(Context context) {
    return args -> {
        val validator = Validator.with(args);
        validator.checkOrOr(1, 2);
        if (args[0].type() != Types.NODE || !(args[0].raw() instanceof ShapeNode)) {
            throw new TypeException("Shape required at first argument");
        }
        val shape = (Shape) ((ShapeNode) args[0].raw()).getFxNode();
        if (args.length == 2) {
            val array = validator.requireArrayAt(1);
            val dashList = array.stream()
                    .map(Value::asDouble)
                    .collect(Collectors.toList());
            shape.getStrokeDashArray().setAll(dashList);
            return NumberValue.ZERO;
        } else {
            return ArrayValue.from(shape.getStrokeDashArray(), NumberValue::of);
        }
    };
}
 
開發者ID:aNNiMON,項目名稱:HotaruFX,代碼行數:21,代碼來源:NodeUtilsBundle.java

示例7: scaleShape

import javafx.scene.shape.Shape; //導入依賴的package包/類
private static void scaleShape(Scene scene, Shape shape) {
    double sceneWidth = scene.getWidth();
    double sceneHeight = scene.getHeight();
    ChangeListener<Number> widthResizer = (arg0, oldValue, newValue) -> shape.setScaleX(newValue.doubleValue() / sceneWidth);
    scene.widthProperty().addListener(widthResizer);
    ChangeListener<Number> heightResizer = (arg0, oldValue, newValue) -> shape.setScaleY(newValue.doubleValue() / sceneHeight);
    scene.heightProperty().addListener(heightResizer);

}
 
開發者ID:ciphertechsolutions,項目名稱:IO,代碼行數:10,代碼來源:BaseController.java

示例8: create

import javafx.scene.shape.Shape; //導入依賴的package包/類
/**
 * Creates a new curved arrow.
 *
 * @param startAngle the starting angle of the arc, in radians
 * @param radius     the radius of the arrow. Must be non-negative.
 * @param length     the length of the arrow, in the same units as {@code radius}
 * @param xOffset    how much to offset the arc along the X-axis
 * @param headSize   the length of the head of the arrow
 *
 * @return a curved arrow shape
 *
 * @throws IllegalArgumentException if {@code radius} or {@code headSize} are negative
 */
public static Shape create(double startAngle,
                           double radius,
                           double length,
                           double xOffset,
                           double headSize) {
  if (radius < 0) {
    throw new IllegalArgumentException("Radius cannot be negative. Given: " + radius);
  }
  if (headSize < 0) {
    throw new IllegalArgumentException("The size of the arrowhead cannot be negative. Given: " + headSize);
  }
  if (radius == Double.POSITIVE_INFINITY) {
    // infinite radius = straight
    return createStraight(length, startAngle, xOffset, headSize);
  }
  return Shape.union(
      makeBody(startAngle, radius, length, xOffset),
      curvedHead(startAngle, headSize, radius, xOffset, length)
  );
}
 
開發者ID:wpilibsuite,項目名稱:shuffleboard,代碼行數:34,代碼來源:CurvedArrow.java

示例9: registerListeners

import javafx.scene.shape.Shape; //導入依賴的package包/類
private void registerListeners() {
    widthProperty().addListener(o -> resize());
    heightProperty().addListener(o -> resize());
    sceneProperty().addListener(o -> {
        if (!locations.isEmpty()) { addShapesToScene(locations.values()); }
        if (isZoomEnabled()) { getScene().addEventFilter( ScrollEvent.ANY, new WeakEventHandler<>(_scrollEventHandler)); }

        locations.addListener((MapChangeListener<Location, Shape>) CHANGE -> {
            if (CHANGE.wasAdded()) {
                addShapesToScene(CHANGE.getValueAdded());
            } else if(CHANGE.wasRemoved()) {
                Platform.runLater(() -> pane.getChildren().remove(CHANGE.getValueRemoved()));
            }
        });
    });
}
 
開發者ID:HanSolo,項目名稱:worldheatmap,代碼行數:17,代碼來源:World.java

示例10: generateOutline

import javafx.scene.shape.Shape; //導入依賴的package包/類
/**
 * Once we have drawn the path, we call this method to generate two paths 
 * (outer and inner paths) and get a SVGPath with them that can be exported
 * @param drawPath The original path
 * @param svg
 * @return the content string of the SVGPath with two paths
 */
public boolean generateOutline(Path drawPath, SVGPath svg) {
    Pane pane = (Pane) drawPath.getParent();
    final double width = pane.getWidth() * WIDTH_FACTOR; 
    
    Path outterPath = new Path(drawPath.getElements());
    outterPath.setStroke(drawPath.getStroke());
    outterPath.setStrokeLineJoin(drawPath.getStrokeLineJoin());
    outterPath.setStrokeLineCap(drawPath.getStrokeLineCap());
    outterPath.setStrokeWidth(width);
    Path s1 = (Path) Shape.subtract(outterPath, new Rectangle(0, 0));

    Path innerPath = new Path(drawPath.getElements());
    innerPath.setStrokeWidth(0);
    innerPath.setStroke(drawPath.getStroke());
    innerPath.setStrokeLineJoin(drawPath.getStrokeLineJoin());
    innerPath.setStrokeLineCap(drawPath.getStrokeLineCap());
    Path s2 = (Path) Shape.subtract(innerPath, new Rectangle(0, 0));
    
    Path result = (Path) Shape.subtract(s1, s2);
    clearSmallPolygons(result);
    svg.setContent(pathsToSVGPath());
    return validPaths.size() == 2;
}
 
開發者ID:gluonhq,項目名稱:javaone2016,代碼行數:31,代碼來源:BadgeOutline.java

示例11: addPropertyChangedListener

import javafx.scene.shape.Shape; //導入依賴的package包/類
public void addPropertyChangedListener(Node object) {
    if (object instanceof Shape) {
        Shape shape = (Shape) object;

        shape.fillProperty().addListener((observable, oldValue, newValue) -> {
            HistoryController.getInstance(mainController).createHistoryPoint();
        });

        shape.strokeProperty().addListener((observable, oldValue, newValue) -> {
            HistoryController.getInstance(mainController).createHistoryPoint();
        });

        shape.strokeWidthProperty().addListener((observable, oldValue, newValue) -> {
            HistoryController.getInstance(mainController).createHistoryPoint();
        });
    }
}
 
開發者ID:pfolta,項目名稱:Shapify,代碼行數:18,代碼來源:Document.java

示例12: register

import javafx.scene.shape.Shape; //導入依賴的package包/類
private void register(final ShapeFactory content, final int slotsize) {
    final PageWithSlots page = new PageWithSlots(content.name, height, width);
    page.setSlotSize(slotsize, slotsize);
    for (final AbstractEffect effect : effects) {
                Pane slot = new Pane();//Region();
                Shape shape = content.createShape();
                shape.setTranslateX(10);
                shape.setTranslateY(10);
                effect.setEffect(shape, slot); // will add shape to scene at the appropriate moment
        page.add(new TestNodeLeaf(effect.name(), slot));
    }

    Shape customShape = content.createCustomShape();
    if (null != customShape) {
        customShape.setTranslateX(10);
        customShape.setTranslateY(10);
        page.add(new TestNodeLeaf("customShape", customShape));
    }
    rootTestNode.add(page);
}
 
開發者ID:teamfx,項目名稱:openjfx-8u-dev-tests,代碼行數:21,代碼來源:Shapes2App.java

示例13: register

import javafx.scene.shape.Shape; //導入依賴的package包/類
private void register(final ShapeFactory content, final int slotsize) {
    addPage(content.name, new Runnable() {
        public void run() {
            SLOTSIZEX = slotsize;
            SLOTSIZEY = slotsize;

            for (Effects effect : Effects.values()) {
                //Region slot = new Region();
                Pane slot = new Pane();
                Shape shape = content.createShape();
                effect.setEffect(shape, slot); // will add shape to scene at the appropriate moment
                addSlot(effect.name(), slot);
            }

            content.addCustomShapes(getPageContent(), shiftX, shiftY);
        }
    });
}
 
開發者ID:teamfx,項目名稱:openjfx-8u-dev-tests,代碼行數:19,代碼來源:ShapePathElementsApp.java

示例14: before

import javafx.scene.shape.Shape; //導入依賴的package包/類
@Before
@Override
public void before()
{
    super.before();
    circleOneWrap = byID(getScene(), "circle_one", Shape.class);
    circleTwoWrap = byID(getScene(), "circle_two", Shape.class);
    circleThreeWrap = byID(getScene(), "circle_three", Shape.class);
    circleFourWrap = byID(getScene(), "circle_four", Shape.class);
    realTranform.setMxx(1);
    realTranform.setMxy(0);
    realTranform.setMxz(0);
    realTranform.setMyx(0);
    realTranform.setMyy(1);
    realTranform.setMyz(0);
    realTranform.setMzx(0);
    realTranform.setMzy(0);
    realTranform.setMzz(1);
}
 
開發者ID:teamfx,項目名稱:openjfx-8u-dev-tests,代碼行數:20,代碼來源:LocalTo_TransformsTest.java

示例15: before

import javafx.scene.shape.Shape; //導入依賴的package包/類
@Override
@Before
public void before()
{
    super.before();
    System.out.println("fx: " + VersionInfo.getRuntimeVersion());
    firstDTest = byID(getScene(), "first_depth_test", ComboBox.class).as(ComboBoxWrap.class);
    secondDTest = byID(getScene(), "second_depth_test", ComboBox.class).as(ComboBoxWrap.class);
    parentDTest = byID(getScene(), "parent_depth_test", ComboBox.class).as(ComboBoxWrap.class);
    firstNodeCombo = byID(getScene(), "first_node_combo", ComboBox.class).as(ComboBoxWrap.class);
    secondNodeCombo = byID(getScene(), "second_node_combo", ComboBox.class).as(ComboBoxWrap.class);
    firstToFront = byID(getScene(), "first_node_to_front", RadioButton.class).as(ToggleButtonWrap.class);
    secondToFront = byID(getScene(), "second_node_to_front", RadioButton.class).as(ToggleButtonWrap.class);
    indicator = byID(getScene(), "indicator", Shape.class);
    referenceGreen = byID(getScene(), "reference_green", Shape.class);
    referenceRed = byID(getScene(), "reference_red", Shape.class);
}
 
開發者ID:teamfx,項目名稱:openjfx-8u-dev-tests,代碼行數:18,代碼來源:DepthTestTest.java


注:本文中的javafx.scene.shape.Shape類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。