Ejemplo n.º 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());
  }
Ejemplo n.º 2
0
  @Test
  public void testBorderColor() {
    assertNull(figure.getBorderColor());

    dmImage.setBorderColor("#010203");
    Color expected = new Color(null, 1, 2, 3);
    assertEquals(expected, figure.getBorderColor());
    expected.dispose();
  }
Ejemplo n.º 3
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;
  }
Ejemplo n.º 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());
  }
Ejemplo n.º 5
0
 private void addImage(File file) throws IOException {
   IArchiveManager archiveManager = (IArchiveManager) dmImage.getAdapter(IArchiveManager.class);
   String path = archiveManager.addImageFromFile(file);
   dmImage.setImagePath(path);
 }