Package org.apache.isis.viewer.dnd.drawing

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


    private static final int PADDING = 10;

    @Override
    public Location determinePlacement(final Workspace workspace, final View relativeToView, final View newView) {
        if (relativeToView == null) {
            return new Location();
        }

        final Size workspaceSize = workspace.getSize();
        final View rootView = rootView(workspace, relativeToView);
        final Location rootViewLocation = rootView.getLocation();
        final Size rootViewSize = rootView.getSize();
        final Location newLocation = new Location(rootViewLocation);
        final Size requiredSize = newView.getView().getRequiredSize(Size.createMax());

        if (rootViewLocation.getX() + rootViewSize.getWidth() + PADDING + requiredSize.getWidth() < workspaceSize.getWidth()) {
            newLocation.add(rootViewSize.getWidth() + PADDING, 0);
        } else if (rootViewLocation.getY() + rootViewSize.getHeight() + PADDING + requiredSize.getHeight() < workspaceSize.getHeight()) {
            newLocation.add(0, rootViewSize.getHeight() + PADDING);
        } else if (requiredSize.getWidth() + PADDING < rootViewLocation.getX()) {
            newLocation.subtract(requiredSize.getWidth() + PADDING, 0);
        } else if (requiredSize.getHeight() + PADDING < rootViewLocation.getY()) {
            newLocation.subtract(0, requiredSize.getHeight() + PADDING);
        } else {
            newLocation.add(PADDING * 6, PADDING * 6);
        }

        final int maxSpaceToLeft = workspaceSize.getWidth() - requiredSize.getWidth();
        final int maxSpaceAbove = workspaceSize.getHeight() - requiredSize.getHeight();

        ensureWidth(newLocation, maxSpaceToLeft);
        ensureHeight(newLocation, maxSpaceAbove);

        final Location firstAttempt = new Location(newLocation);

        while (workspace.subviewFor(newLocation) != null && workspace.subviewFor(newLocation).getLocation().equals(newLocation)) {
            newLocation.add(PADDING * 4, PADDING * 4);
            ensureWidth(newLocation, maxSpaceToLeft);
            ensureHeight(newLocation, maxSpaceAbove);
View Full Code Here


    }

    public void draw(final Canvas canvas, final int x, final int baseline) {
        final int y = baseline - this.baseline + 1;
        if (Toolkit.debug) {
            canvas.drawDebugOutline(new Bounds(new Location(x, y), getSize()), getBaseline(), Toolkit.getColor(ColorsAndFonts.COLOR_DEBUG_BOUNDS_DRAW));
        }
        final Image icon = icon();
        if (icon == null) {
            canvas.drawSolidOval(x + 1, y, iconHeight, iconHeight, Toolkit.getColor(ColorsAndFonts.COLOR_PRIMARY3));
        } else {
View Full Code Here

        }
    }

    @Override
    public DragEvent dragStart(final DragStart drag) {
        final Location at = drag.getLocation();

        final Location anchor = getAbsoluteLocation();
        // TODO adjust anchor so only the field is rubberbanded
        /*
         * final Size size = getView().getSize(); final ViewAxis axis =
         * getViewAxis(LabelAxis.class); if (axis instanceof LabelAxis) { final
         * int width = ((LabelAxis) axis).getWidth(); size.contractWidth(width);
View Full Code Here

        return null;
    }

    @Override
    public void dragTo(final InternalDrag drag) {
        final Location at = drag.getLocation();
        if (canChangeValue().isAllowed()) {
            selection.extendTo(at);
            markDamaged();
        }
    }
View Full Code Here

     * nearest the point of the mouse.
     */
    @Override
    public void firstClick(final Click click) {
        if (canChangeValue().isAllowed()) {
            final Location at = click.getLocation();
            at.subtract(ViewConstants.HPADDING, ViewConstants.VPADDING);
            cursor.cursorAt(at);
            resetSelection();

            // testing
            if (cursor.getLine() > textContent.getNoLinesOfContent()) {
                throw new IsisException("not inside content for line " + cursor.getLine() + " : " + textContent.getNoLinesOfContent());
            }

            markDamaged();
        }

        if (!canChangeValue().isAllowed() || click.isShift() || click.button2()) {
            final ObjectAdapter valueAdapter = getContent().getAdapter();
            if (valueAdapter != null && valueAdapter.titleString().length() > 0) {
                final View textView = new BackgroundBorder(Toolkit.getColor(ColorsAndFonts.COLOR_PRIMARY3), new LineBorder(1, Toolkit.getColor(ColorsAndFonts.COLOR_PRIMARY1), new TextView(getContent(), null)));
                getViewManager().setOverlayView(textView);

                final int offset = getView().getPadding().getLeft();
                final Location location = getAbsoluteLocation();
                location.add(offset, 0);
                textView.setLocation(location);
                textView.markDamaged();
            }
        }
    }
View Full Code Here

    }

    public void testLocation() {
        final DummyView sourceView = new DummyView();
        sourceView.setParent(new DummyWorkspaceView());
        sourceView.setupLocation(new Location(1000, 1000));

        final ContentDrag drag = new ContentDragImpl(sourceView, new Location(10, 10), new DummyView());
        assertEquals(new Location(10, 10), drag.getOffset());

        final DummyView targetView = new DummyView();
        targetView.setupAbsoluteLocation(new Location(100, 100));

        // drag.drag(targetView, new Location(120, 120), 0);
        // assertEquals(new Location(20, 20), drag.getTargetLocation());
    }
View Full Code Here

        junit.textui.TestRunner.run(InternalDragTest.class);
    }

    public void testDragStart() {
        final DummyView view = new DummyView();
        view.setupAbsoluteLocation(new Location(30, 60));

        final InternalDrag id = new SimpleInternalDrag(view, new Location(100, 110));
        assertEquals(new Location(70, 50), id.getLocation());

        // id.drag(null, new Location(110, 130), 0);
        // assertEquals(new Location(80, 70), id.getLocation());
    }
View Full Code Here

    }

    @Test
    public void testCursorPostioningAtCorner() {
        content.setText("test insert that is longer than a single line");
        assertEquals(0, content.cursorAtLine(new Location()));
        assertEquals(0, content.cursorAtCharacter(new Location(), 0));
    }
View Full Code Here

    }

    @Test
    public void testCursorPostioningByLine() {
        content.setText("test insert that is longer than a single line");
        assertEquals(0, content.cursorAtLine(new Location(1000, 0)));
        assertEquals(0, content.cursorAtLine(new Location(1000, 10)));
        assertEquals(0, content.cursorAtLine(new Location(1000, 14)));

        assertEquals(1, content.cursorAtLine(new Location(1000, 15)));

        assertEquals(1, content.cursorAtLine(new Location(1000, 25)));
        assertEquals(1, content.cursorAtLine(new Location(1000, 29)));

        assertEquals(2, content.cursorAtLine(new Location(1000, 30)));
        assertEquals(2, content.cursorAtLine(new Location(1000, 44)));

        assertEquals(3, content.cursorAtLine(new Location(1000, 45)));
    }
View Full Code Here

    }

    @Test
    public void testCursorPostioningByCharacter() {
        content.setText("test insert that");
        assertEquals(0, content.cursorAtCharacter(new Location(0, 1000), 0));
        assertEquals(0, content.cursorAtCharacter(new Location(3, 1000), 0));

        assertEquals(1, content.cursorAtCharacter(new Location(4, 1000), 0));
        assertEquals(1, content.cursorAtCharacter(new Location(13, 1000), 0));

        assertEquals(2, content.cursorAtCharacter(new Location(14, 1000), 0));
        assertEquals(2, content.cursorAtCharacter(new Location(23, 1000), 0));

        assertEquals(15, content.cursorAtCharacter(new Location(153, 1000), 0));

        assertEquals(16, content.cursorAtCharacter(new Location(154, 1000), 0));

        assertEquals(16, content.cursorAtCharacter(new Location(199, 1000), 0));
    }
View Full Code Here

TOP

Related Classes of org.apache.isis.viewer.dnd.drawing.Location

Copyright © 2018 www.massapicom. 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.