コード例 #1
0
  @Test
  public void testDiagramImageChangesSize() throws Exception {
    Image image = getPrivateImageField();
    assertNull(image);

    // Add image
    File file = new File(TestSupport.getTestDataFolder().getPath(), "img/img1.png");
    addImage(file);

    // Check initial Image size
    image = getPrivateImageField();
    assertEquals(new Rectangle(0, 0, 1024, 1024), image.getBounds());

    // Check correct default size of image
    assertEquals(new Dimension(1024, 1024), figure.getDefaultSize());
    assertEquals(new Dimension(1024, 1024), figure.getPreferredSize(-1, -1));

    // Change size of DiagramModelImage and check it was rescaled
    IBounds bounds = IArchimateFactory.eINSTANCE.createBounds(0, 0, 512, 512);
    dmImage.setBounds(bounds);

    // Layout
    editor.layoutPendingUpdates();

    // Force a mock repaint since we are not using a GUI
    figure.paint(mock(Graphics.class));

    // Test image was rescaled
    image = getPrivateImageField();
    assertEquals(new Rectangle(0, 0, 512, 512), image.getBounds());
  }
コード例 #2
0
  @Override
  protected DiagramImageFigure createFigure() {
    // Add a DiagramModelImage
    dmImage = IArchimateFactory.eINSTANCE.createDiagramModelImage();
    dmImage.setBounds(IArchimateFactory.eINSTANCE.createBounds());
    dm = (IArchimateDiagramModel) model.getDefaultDiagramModel();
    dm.getChildren().add(dmImage);

    // Layout
    editor.layoutPendingUpdates();

    figure = (DiagramImageFigure) editor.findFigure(dmImage);
    return figure;
  }