Example #1
0
  @Test
  public void testSettingNewImagePath() 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));

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

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

    // Check correct default size of image
    assertEquals(new Dimension(268, 268), figure.getDefaultSize());
    assertEquals(new Dimension(268, 268), figure.getPreferredSize(-1, -1));
  }
Example #2
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());
  }
Example #3
0
  @Test
  public void testGetOriginalImage() throws Exception {
    Image image = figure.getOriginalImage();
    assertNull(image);

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

    image = figure.getOriginalImage();
    assertEquals(new Rectangle(0, 0, 268, 268), image.getBounds());
  }
Example #4
0
  @Test
  public void testGetDefaultSize() throws Exception {
    assertEquals(DiagramImageFigure.DEFAULT_SIZE, figure.getDefaultSize());

    // Add image
    File file = new File(TestSupport.getTestDataFolder().getPath(), "img/img1.png");
    addImage(file);
    Image image = getPrivateImageField();
    assertEquals(new Dimension(image), figure.getDefaultSize());

    // Reset
    dmImage.setImagePath(null);
    assertEquals(DiagramImageFigure.DEFAULT_SIZE, figure.getDefaultSize());
  }
Example #5
0
  @Test
  public void testRescaleImage() throws Exception {
    File file = new File(TestSupport.getTestDataFolder().getPath(), "img/img3.png");
    addImage(file);
    Image image = getPrivateImageField();
    assertEquals(new Rectangle(0, 0, 268, 268), image.getBounds());

    figure.setBounds(new org.eclipse.draw2d.geometry.Rectangle(0, 0, 10, 10));

    figure.rescaleImage();

    image = getPrivateImageField();
    assertEquals(new Rectangle(0, 0, 10, 10), image.getBounds());
  }