コード例 #1
0
  public void testModelDimensionDpConversion() {
    TestComponent testComponent = new TestComponent();

    MyRoot nativeComponent = new MyRoot(2.0);
    JPanel panel = new JPanel();
    panel.add(nativeComponent);
    nativeComponent.setLocation(15, 20);
    JPanel other = new JPanel();
    panel.add(other);
    other.setLocation(5, 5);

    testComponent.setNativeComponent(nativeComponent);

    assertEquals(
        new Dimension(300, 400),
        testComponent.toModelDp(160, nativeComponent, new Dimension(300, 400)));
    assertEquals(
        new Dimension(300, 400),
        testComponent.toModelDp(160, panel, new Dimension(300 * 2, 400 * 2)));
    assertEquals(
        new Dimension(300, 400),
        testComponent.toModelDp(160, other, new Dimension(300 * 2, 400 * 2)));
    assertEquals(
        new Dimension(300 / 2, 400 / 2),
        testComponent.toModelDp(2 * 160, nativeComponent, new Dimension(300, 400)));
    assertEquals(
        new Dimension(300 / 2, 400 / 2),
        testComponent.toModelDp(2 * 160, panel, new Dimension(300 * 2, 400 * 2)));
    assertEquals(
        new Dimension(300 / 2, 400 / 2),
        testComponent.toModelDp(2 * 160, other, new Dimension(300 * 2, 400 * 2)));
  }
コード例 #2
0
  public void testModelPointDpConversion() {
    TestComponent testComponent = new TestComponent();

    MyRoot nativeComponent = new MyRoot(2.0);
    JPanel panel = new JPanel();
    panel.add(nativeComponent);
    nativeComponent.setLocation(15, 20);
    JPanel other = new JPanel();
    panel.add(other);
    other.setLocation(5, 5);

    testComponent.setNativeComponent(nativeComponent);

    assertEquals(
        new Point(100, 110), testComponent.toModelDp(160, nativeComponent, new Point(100, 110)));
    assertEquals(
        new Point(100, 110),
        testComponent.toModelDp(160, panel, new Point(100 * 2 + 15, 110 * 2 + 20)));
    assertEquals(
        new Point(100, 110),
        testComponent.toModelDp(160, other, new Point(100 * 2 + 15 - 5, 110 * 2 + 20 - 5)));
    assertEquals(
        new Point(100 / 2, 110 / 2),
        testComponent.toModelDp(2 * 160, nativeComponent, new Point(100, 110)));
    assertEquals(
        new Point(100 / 2, 110 / 2),
        testComponent.toModelDp(2 * 160, panel, new Point(100 * 2 + 15, 110 * 2 + 20)));
    assertEquals(
        new Point(100 / 2, 110 / 2),
        testComponent.toModelDp(2 * 160, other, new Point(100 * 2 + 15 - 5, 110 * 2 + 20 - 5)));
  }