Examples of Canvas


Examples of javafx.scene.canvas.Canvas

    @Override
    public void start(Stage primaryStage) throws Exception {
        Group root = new Group();

        Canvas canvas = new Canvas(width, height);
        gc = canvas.getGraphicsContext2D();

        startX = 10;
        startY = 10;

        endX = 300;
        endY = 20;

        toleransi = 5;

        canvas.addEventHandler(MouseEvent.MOUSE_PRESSED, (MouseEvent event) -> {
            double x = event.getX();
            double y = event.getY();
            isRedraw = isAccessible(x, y);
        });

        canvas.addEventHandler(MouseEvent.MOUSE_DRAGGED, (MouseEvent event) -> {
            processMouse(event.getX(), event.getY());
        });

        canvas.addEventHandler(MouseEvent.MOUSE_RELEASED, (MouseEvent event) -> {
            isRedraw = false;
        });

        draw(gc);
View Full Code Here

Examples of javax.microedition.lcdui.Canvas


public class Test extends TestMidlet {

  protected void startApp() throws MIDletStateChangeException {
    Canvas c = new Canvas() {
     
      protected void paint(Graphics g) {
        g.setColor(0xFFFFFF);
        g.fillRect(0, 0, 300, 300);
       
View Full Code Here

Examples of nodebox.graphics.Canvas

        g.setStroke(new BasicStroke(1f));
        g.draw(canvasBounds);
    }

    private Canvas getFirstCanvas(Iterable<?> objects) {
        Canvas c = (Canvas) Iterables.getFirst(objects, null);
        return c != null ? c : new Canvas();
    }
View Full Code Here

Examples of org.adamtacy.client.ui.Canvas

  public void reflectImage(NEffectPanel thePanel, int height, double opacity,
      int gap, boolean setUp) {

    DockPanel container;
    Widget w;
    Canvas v;
    SimplePanel gapPanel;

    if (setUp) {
      w = (Image) ((DockPanel) thePanel.getPanelWidget()).getWidget(0);
      v = (Canvas) ((DockPanel) thePanel.getPanelWidget()).getWidget(WHERE_IS_REFLECTION);
      v.setSize(1, 1);
      // v = new Canvas();
      container = (DockPanel) thePanel.getPanelWidget();
      // Remove from panel now as this may make any animations look much
      // smoother
      // If not, there is a danger on slow(er) systems that the reflection hangs
      // out from image until re-drawn.
      container.remove(WHERE_IS_REFLECTION);
    } else {
      container = new DockPanel();
      w = getReflectedImage(thePanel, setUp);
      v = new Canvas();
    }

    gapPanel = new SimplePanel();
    gapPanel.setWidth("100%");
    gapPanel.add(new HTML("&nbsp;"));
    gapPanel.setHeight(gap + "px");

    int imgHeight = w.getOffsetHeight();
    int canvasHeight = (int) ((imgHeight * height) / 100);

    reflect(v.getElement(), w.getElement(), canvasHeight, opacity);

    if (setUp) {
      container.add(v, DockPanel.SOUTH);
    } else {
      container.add(w, DockPanel.NORTH);
View Full Code Here

Examples of org.apache.isis.viewer.dnd.Canvas

        // subcanvas
        x = 80;
        canvas.drawRectangle(x, y, width, height, gray);

        Canvas subcanvas = canvas.createSubcanvas(x + 1, y + 1, width - 1, height - 1);
        subcanvas.drawRectangle(0, 0, width - 2, height - 2, blue);

        x = 150;
        canvas.drawRectangle(x, y, width, height, gray);

        subcanvas = canvas.createSubcanvas(x + 1, y + 1, width - 1, height - 1);
        subcanvas.offset(-100, -200);

        subcanvas.drawRectangle(100, 200, width - 2, height - 2, red);
        subcanvas.drawRectangle(0, 0, 120, 220, green);

        // solid shapes
        x = 10;
        y = 105;

        canvas.drawRectangle(x - 1, y - 1, width + 2, height + 2, gray);
        canvas.drawSolidRectangle(x, y, width, height, black);
        canvas.drawSolidOval(x, y, width, height, green);
        canvas.drawLine(x, y, x + width - 1, y + height - 1, red);
        canvas.drawLine(x, y + height - 1, x + width - 1, y, red);

        x = 80;
        canvas.drawSolidRectangle(x, y, width, height, black);

        subcanvas = canvas.createSubcanvas(x + 1, y + 1, width - 1, height - 1);
        subcanvas.drawSolidRectangle(0, 0, width - 2, height - 2, blue);

        x = 150;
        canvas.drawRectangle(x, y, width, width, black);
        canvas.drawOval(x, y, width, width, green);
View Full Code Here

Examples of org.apache.isis.viewer.dnd.drawing.Canvas

                drawOrderIndicator(canvas, axis, x + axis.getColumnWidth(i) - 10);
            }

            canvas.drawLine(0, 0, 0, getSize().getHeight() - 1, secondary1);
            canvas.drawLine(x, 0, x, getSize().getHeight() - 1, secondary1);
            final Canvas headerCanvas = canvas.createSubcanvas(x, 0, axis.getColumnWidth(i) - 1, height);
            headerCanvas.drawText(axis.getColumnName(i), ViewConstants.HPADDING, y, secondary1, Toolkit.getText(ColorsAndFonts.TEXT_LABEL));
            x += axis.getColumnWidth(i);
        }
        // Color secondary2 = Toolkit.getColor(ColorsAndFonts.COLOR_SECONDARY2);
        // canvas.drawLine(x, 0, x, getSize().getHeight() - 1, secondary2);
        // canvas.drawRectangle(0, height, getSize().getWidth() - 1,
View Full Code Here

Examples of org.apache.pivot.wtk.media.drawing.Canvas

    };

    private DrawingListenerList drawingListeners = new DrawingListenerList();

    public Drawing() {
        setCanvas(new Canvas());
    }
View Full Code Here

Examples of org.codehaus.enunciate.examples.c.schema.draw.Canvas

    if (this.skipCTests) {
      System.out.println("C tests have been disabled.");
      return;
    }

    Canvas canvas = new Canvas();
    Bus bus = new Bus();
    bus.setId("busId");
    Rectangle busFrame = new Rectangle();
    busFrame.setWidth(100);
    bus.setFrame(busFrame);
    Cat cat = new Cat();
    cat.setId("catId");
    Circle catFace = new Circle();
    catFace.setRadius(30);
    cat.setFace(catFace);
    House house = new House();
    house.setId("houseId");
    Rectangle houseBase = new Rectangle();
    houseBase.setWidth(76);
    house.setBase(houseBase);
    canvas.setFigures(Arrays.asList(bus, cat, house));
    Rectangle rectangle = new Rectangle();
    rectangle.setHeight(50);
    rectangle.setId("rectId");
    Circle circle = new Circle();
    circle.setRadius(10);
    circle.setId("circleId");
    Triangle triangle = new Triangle();
    triangle.setBase(80);
    triangle.setId("triId");
    canvas.setShapes(Arrays.asList(rectangle, circle, triangle));
//    byte[] swaRefBytes = "This is a bunch of random bytes that are to be used as an SWA ref attachment.".getBytes();
//    byte[] explicitBase64Bytes = "This is some more random bytes that are to be used as a base 64 encoded attachment.".getBytes();
//    byte[] attachment1Bytes = "This is some more random bytes that are to be used as the first MTOM attachment.".getBytes();
//    byte[] attachment2Bytes = "This is some more random bytes that are to be used as the second MTOM attachment.".getBytes();
//    byte[] attachment3Bytes = "This is some more random bytes that are to be used as the third MTOM attachment.".getBytes();
//    CanvasAttachment attachment1 = new CanvasAttachment();
//    attachment1.setValue(attachment1Bytes);
//    CanvasAttachment attachment2 = new CanvasAttachment();
//    attachment2.setValue(attachment2Bytes);
//    CanvasAttachment attachment3 = new CanvasAttachment();
//    attachment3.setValue(attachment3Bytes);
//    ByteArrayDataSource dataSource = new ByteArrayDataSource(swaRefBytes, "application/octet-stream");
//    dataSource.setName("somename");
//    canvas.setBackgroundImage(new DataHandler(dataSource));
//    canvas.setExplicitBase64Attachment(explicitBase64Bytes);
//    canvas.setOtherAttachments(Arrays.asList(attachment1, attachment2, attachment3));

    canvas = processThroughXml(canvas);

    Collection shapes = canvas.getShapes();
    assertEquals(3, shapes.size());
    for (Object Shape : shapes) {
      if (Shape instanceof Circle) {
        assertEquals("circleId", ((Circle) Shape).getId());
        assertEquals(10, ((Circle) Shape).getRadius());
      }
      else if (Shape instanceof Rectangle) {
        assertEquals("rectId", ((Rectangle) Shape).getId());
        assertEquals(50, ((Rectangle) Shape).getHeight());
      }
      else if (Shape instanceof Triangle) {
        assertEquals("triId", ((Triangle) Shape).getId());
        assertEquals(80, ((Triangle) Shape).getBase());
      }
      else {
        fail("Unknown shape: " + Shape);
      }
    }

    Collection figures = canvas.getFigures();
    assertEquals(3, figures.size());
    for (Object Figure : figures) {
      if (Figure instanceof Bus) {
        bus = (Bus) Figure;
        assertEquals("busId", bus.getId());
View Full Code Here

Examples of org.codehaus.enunciate.examples.csharp.schema.draw.Canvas

    if (this.skipCSharpTests) {
      System.out.println("CSharp tests have been disabled.");
      return;
    }

    Canvas canvas = new Canvas();
    Bus bus = new Bus();
    bus.setId("busId");
    Rectangle busFrame = new Rectangle();
    busFrame.setWidth(100);
    bus.setFrame(busFrame);
    Cat cat = new Cat();
    cat.setId("catId");
    Circle catFace = new Circle();
    catFace.setRadius(30);
    cat.setFace(catFace);
    House house = new House();
    house.setId("houseId");
    Rectangle houseBase = new Rectangle();
    houseBase.setWidth(76);
    house.setBase(houseBase);
    canvas.setFigures(Arrays.asList(bus, cat, house));
    Rectangle rectangle = new Rectangle();
    rectangle.setHeight(50);
    rectangle.setId("rectId");
    Circle circle = new Circle();
    circle.setRadius(10);
    circle.setId("circleId");
    Triangle triangle = new Triangle();
    triangle.setBase(80);
    triangle.setId("triId");
    canvas.setShapes(Arrays.asList(rectangle, circle, triangle));
//    byte[] swaRefBytes = "This is a bunch of random bytes that are to be used as an SWA ref attachment.".getBytes();
//    byte[] explicitBase64Bytes = "This is some more random bytes that are to be used as a base 64 encoded attachment.".getBytes();
//    byte[] attachment1Bytes = "This is some more random bytes that are to be used as the first MTOM attachment.".getBytes();
//    byte[] attachment2Bytes = "This is some more random bytes that are to be used as the second MTOM attachment.".getBytes();
//    byte[] attachment3Bytes = "This is some more random bytes that are to be used as the third MTOM attachment.".getBytes();
//    CanvasAttachment attachment1 = new CanvasAttachment();
//    attachment1.setValue(attachment1Bytes);
//    CanvasAttachment attachment2 = new CanvasAttachment();
//    attachment2.setValue(attachment2Bytes);
//    CanvasAttachment attachment3 = new CanvasAttachment();
//    attachment3.setValue(attachment3Bytes);
//    ByteArrayDataSource dataSource = new ByteArrayDataSource(swaRefBytes, "application/octet-stream");
//    dataSource.setName("somename");
//    canvas.setBackgroundImage(new DataHandler(dataSource));
//    canvas.setExplicitBase64Attachment(explicitBase64Bytes);
//    canvas.setOtherAttachments(Arrays.asList(attachment1, attachment2, attachment3));

    canvas = processThroughXml(canvas);

    Collection shapes = canvas.getShapes();
    assertEquals(3, shapes.size());
    for (Object Shape : shapes) {
      if (Shape instanceof Circle) {
        assertEquals("circleId", ((Circle) Shape).getId());
        assertEquals(10, ((Circle) Shape).getRadius());
      }
      else if (Shape instanceof Rectangle) {
        assertEquals("rectId", ((Rectangle) Shape).getId());
        assertEquals(50, ((Rectangle) Shape).getHeight());
      }
      else if (Shape instanceof Triangle) {
        assertEquals("triId", ((Triangle) Shape).getId());
        assertEquals(80, ((Triangle) Shape).getBase());
      }
      else {
        fail("Unknown shape: " + Shape);
      }
    }

    Collection figures = canvas.getFigures();
    assertEquals(3, figures.size());
    for (Object Figure : figures) {
      if (Figure instanceof Bus) {
        bus = (Bus) Figure;
        assertEquals("busId", bus.getId());
View Full Code Here

Examples of org.codehaus.enunciate.examples.jaxws_client.schema.draw.Canvas

  /**
   * tests the canvas.  This one as XmlElementRefs, XmlElements, and an attachment...
   */
  public void testCanvas() throws Exception {
    Canvas canvas = new Canvas();
    Bus bus = new Bus();
    bus.setId("busId");
    Rectangle busFrame = new Rectangle();
    busFrame.setWidth(100);
    bus.setFrame(busFrame);
    Cat cat = new Cat();
    cat.setId("catId");
    Circle catFace = new Circle();
    catFace.setRadius(30);
    cat.setFace(catFace);
    House house = new House();
    house.setId("houseId");
    Rectangle houseBase = new Rectangle();
    houseBase.setWidth(76);
    house.setBase(houseBase);
    canvas.setFigures(Arrays.asList(bus, cat, house));
    Rectangle rectangle = new Rectangle();
    rectangle.setHeight(50);
    rectangle.setId("rectId");
    Circle circle = new Circle();
    circle.setRadius(10);
    circle.setId("circleId");
    Triangle triangle = new Triangle();
    triangle.setBase(80);
    triangle.setId("triId");
    canvas.setShapes(Arrays.asList(rectangle, circle, triangle));
    byte[] swaRefBytes = "This is a bunch of random bytes that are to be used as an SWA ref attachment.".getBytes();
    byte[] explicitBase64Bytes = "This is some more random bytes that are to be used as a base 64 encoded attachment.".getBytes();
    byte[] attachment1Bytes = "This is some more random bytes that are to be used as the first MTOM attachment.".getBytes();
    byte[] attachment2Bytes = "This is some more random bytes that are to be used as the second MTOM attachment.".getBytes();
    byte[] attachment3Bytes = "This is some more random bytes that are to be used as the third MTOM attachment.".getBytes();
    CanvasAttachment attachment1 = new CanvasAttachment();
    attachment1.setValue(attachment1Bytes);
    CanvasAttachment attachment2 = new CanvasAttachment();
    attachment2.setValue(attachment2Bytes);
    CanvasAttachment attachment3 = new CanvasAttachment();
    attachment3.setValue(attachment3Bytes);
    ByteArrayDataSource dataSource = new ByteArrayDataSource(swaRefBytes, "application/octet-stream");
    dataSource.setName("somename");
    //todo: uncomment when JAXB bug is fixed
//    canvas.setBackgroundImage(new DataHandler(dataSource));
    canvas.setExplicitBase64Attachment(explicitBase64Bytes);
    canvas.setOtherAttachments(Arrays.asList(attachment1, attachment2, attachment3));

    JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
    ObjectMapper canvasMapper = provider.locateMapper(Canvas.class, MediaType.APPLICATION_JSON_TYPE);
    ObjectMapper clientMapper = new ObjectMapper();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    canvasMapper.writeValue(out, canvas);
    //set up the attachments that were written

    shapes.json.draw.Canvas clientCanvas = clientMapper.readValue(new ByteArrayInputStream(out.toByteArray()), shapes.json.draw.Canvas.class);
    Collection<ObjectNode> clientShapes = clientCanvas.getShapes();
    assertEquals(3, clientShapes.size());
    for (ObjectNode shape : clientShapes) {
      assertEquals(1, shape.size());
      String shapeKey = shape.getFields().next().getKey();
      shape = (ObjectNode) shape.get(shapeKey);
      if ("circle".equals(shapeKey)) {
        assertEquals("circleId", shape.get("id").getTextValue());
        assertEquals(10, shape.get("radius").getIntValue());
      }
      else if ("triangle".equals(shapeKey)) {
        assertEquals("triId", shape.get("id").getTextValue());
        assertEquals(80, shape.get("base").getIntValue());
      }
      else if ("rectangle".equals(shapeKey)) {
        assertEquals("rectId", shape.get("id").getTextValue());
        assertEquals(50, shape.get("height").getIntValue());
      }
      else {
        fail("Unknown shape: " + shapeKey);
      }
    }

    Collection<ObjectNode> clientFigures = clientCanvas.getFigures();
    assertEquals(3, clientFigures.size());
    for (ObjectNode figure : clientFigures) {
      assertEquals(1, figure.size());
      String figureKey = figure.getFields().next().getKey();
      figure = (ObjectNode) figure.get(figureKey);
      if ("bus".equals(figureKey)) {
        assertEquals("busId", figure.get("id").getTextValue());
        assertTrue(figure.get("frame") != null);
        assertEquals(100, figure.get("frame").get("width").getIntValue());
      }
      else if ("cat".equals(figureKey)) {
        assertEquals("catId", figure.get("id").getTextValue());
        assertTrue(figure.get("circle") != null);
        assertEquals(30, figure.get("circle").get("radius").getIntValue());
      }
      else if ("house".equals(figureKey)) {
        assertEquals("houseId", figure.get("id").getTextValue());
        assertTrue(figure.get("base") != null);
        assertEquals(76, figure.get("base").get("width").getIntValue());
      }
      else {
        fail("Unknown figure: " + figure);
      }
    }

//    DataHandler backgroundImage = clientCanvas.getBackgroundImage();
//    InputStream attachmentStream = backgroundImage.getInputStream();
//    ByteArrayOutputStream bgImageIn = new ByteArrayOutputStream();
//    int byteIn = attachmentStream.read();
//    while (byteIn > 0) {
//      bgImageIn.write(byteIn);
//      byteIn = attachmentStream.read();
//    }
//    assertTrue(Arrays.equals(swaRefBytes, bgImageIn.toByteArray()));

    byte[] base64Attachment = clientCanvas.getExplicitBase64Attachment();
    assertNotNull(base64Attachment);
    assertTrue(Arrays.equals(explicitBase64Bytes, base64Attachment));

    Collection otherAttachments = clientCanvas.getOtherAttachments();
    assertEquals(3, otherAttachments.size());
    Iterator attachmentsIt = otherAttachments.iterator();
    int attachmentCount = 0;
    while (attachmentsIt.hasNext()) {
      shapes.json.draw.CanvasAttachment otherAttachment = (shapes.json.draw.CanvasAttachment) attachmentsIt.next();
      byte[] otherAttachmentBytes = otherAttachment.getValue();
      if (Arrays.equals(attachment1Bytes, otherAttachmentBytes)) {
        attachmentCount++;
      }
      else if (Arrays.equals(attachment2Bytes, otherAttachmentBytes)) {
        attachmentCount++;
      }
      else if (Arrays.equals(attachment3Bytes, otherAttachmentBytes)) {
        attachmentCount++;
      }
      else {
        fail("Unknown attachment.");
      }
    }
    assertEquals(3, attachmentCount);

    clientCanvas.setShapes(null); //@XmlElementRefs can't be (de)serialized.
    out = new ByteArrayOutputStream();
    clientMapper.writeValue(out, clientCanvas);
    canvas = canvasMapper.readValue(new ByteArrayInputStream(out.toByteArray()), Canvas.class);

    Collection shapes = canvas.getShapes();
    assertNull(shapes);
//    assertEquals(3, shapes.size());
//    for (Object Shape : shapes) {
//      if (Shape instanceof Circle) {
//        assertEquals("circleId", ((Circle) Shape).getId());
//        assertEquals(10, ((Circle) Shape).getRadius());
//      }
//      else if (Shape instanceof Rectangle) {
//        assertEquals("rectId", ((Rectangle) Shape).getId());
//        assertEquals(50, ((Rectangle) Shape).getHeight());
//      }
//      else if (Shape instanceof Triangle) {
//        assertEquals("triId", ((Triangle) Shape).getId());
//        assertEquals(80, ((Triangle) Shape).getBase());
//      }
//      else {
//        fail("Unknown shape: " + Shape);
//      }
//    }

    Collection figures = canvas.getFigures();
    assertEquals(3, figures.size());
    for (Object Figure : figures) {
      if (Figure instanceof Bus) {
        bus = (Bus) Figure;
        assertEquals("busId", bus.getId());
        Rectangle BusFrame = bus.getFrame();
        assertNotNull(BusFrame);
        assertEquals(100, busFrame.getWidth());
      }
      else if (Figure instanceof Cat) {
        cat = (Cat) Figure;
        assertEquals("catId", cat.getId());
        Circle CatFace = cat.getFace();
        assertNotNull(CatFace);
        assertEquals(30, CatFace.getRadius());
      }
      else if (Figure instanceof House) {
        house = (House) Figure;
        assertEquals("houseId", house.getId());
        Rectangle HouseBase = house.getBase();
        assertNotNull(HouseBase);
        assertEquals(76, HouseBase.getWidth());
      }
      else {
        fail("Unknown figure: " + Figure);
      }
    }

//    backgroundImage = canvas.getBackgroundImage();
//    attachmentStream = backgroundImage.getInputStream();
//    bgImageIn = new ByteArrayOutputStream();
//    byteIn = attachmentStream.read();
//    while (byteIn > 0) {
//      bgImageIn.write(byteIn);
//      byteIn = attachmentStream.read();
//    }
//
//    assertTrue(Arrays.equals(swaRefBytes, bgImageIn.toByteArray()));

    base64Attachment = canvas.getExplicitBase64Attachment();
    assertNotNull(base64Attachment);
    assertTrue(Arrays.equals(explicitBase64Bytes, base64Attachment));

    otherAttachments = canvas.getOtherAttachments();
    assertEquals(3, otherAttachments.size());
    attachmentsIt = otherAttachments.iterator();
    attachmentCount = 0;
    while (attachmentsIt.hasNext()) {
      CanvasAttachment otherAttachment = (CanvasAttachment) attachmentsIt.next();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.