Search in sources :

Example 16 with Alignment

use of com.github.weisj.darklaf.util.Alignment in project darklaf by weisJ.

the class ToolTipUtil method getBestPositionMatch.

private static LocationResult getBestPositionMatch(final ToolTipContext context, final Point p) {
    if (!context.isBestFit()) {
        return new LocationResult(context.getToolTipLocation(p, null), true);
    }
    Alignment original = context.getAlignment();
    Alignment originalCenter = context.getCenterAlignment();
    LayoutConstraints layoutConstraints = calculateLayoutConstraints(context, p);
    boolean isCenter = original == Alignment.CENTER;
    Alignment targetAlignment = isCenter ? originalCenter : original;
    if (context.isChooseBestInitialAlignment()) {
        targetAlignment = probeAlignment(context, layoutConstraints);
    }
    boolean centerVertically = targetAlignment.isHorizontal();
    boolean centerHorizontally = targetAlignment.isVertical();
    Alignment[] alignments = getAlignments(targetAlignment);
    Point pos;
    BiConsumer<ToolTipContext, Alignment> setter = isCenter ? ToolTipContext::setCenterAlignment : ToolTipContext::setAlignment;
    // Check if a position keeps the tooltip inside the window.
    pos = tryAlignments(alignments, context, p, layoutConstraints, setter, centerHorizontally, centerVertically);
    if (pos == null) {
        // Try again with screen bounds instead.
        layoutConstraints.windowBounds.setBounds(layoutConstraints.screenBoundary);
        pos = tryAlignments(alignments, context, p, layoutConstraints, setter, centerHorizontally, centerVertically);
    }
    LocationResult result;
    /*
         * At this point if the tooltip is still extending outside the screen boundary we surrender and
         * leave the tooltip as it was.
         */
    if (pos == null) {
        context.setAlignment(Alignment.CENTER);
        context.setCenterAlignment(Alignment.CENTER);
        result = new LocationResult(context.getFallBackPositionProvider().calculateFallbackPosition(context), !context.getFallBackPositionProvider().providesAbsolutePosition());
    } else {
        result = new LocationResult(pos, true);
    }
    context.updateToolTip();
    context.setAlignment(original);
    context.setCenterAlignment(originalCenter);
    return result;
}
Also used : Alignment(com.github.weisj.darklaf.util.Alignment) ToolTipContext(com.github.weisj.darklaf.components.tooltip.ToolTipContext)

Example 17 with Alignment

use of com.github.weisj.darklaf.util.Alignment in project darklaf by weisJ.

the class DarkTooltipBorder method getPointerOffset.

private int getPointerOffset(final Component c, final Dimension dimension, final int thicknessFactor) {
    if (!showPointer || isPlain(c))
        return 0;
    int offset = (int) bubbleBorder.getOffset(dimension.width - 2 * shadowBorder.getShadowSize(), dimension.height) + shadowBorder.getShadowSize();
    int thickness = bubbleBorder.getThickness();
    Alignment align = bubbleBorder.getPointerSide();
    if (align.isWest(false))
        offset += thicknessFactor * thickness;
    return offset;
}
Also used : Alignment(com.github.weisj.darklaf.util.Alignment)

Example 18 with Alignment

use of com.github.weisj.darklaf.util.Alignment in project darklaf by weisJ.

the class ToolTipUtil method getAlignments.

private static Alignment[] getAlignments(final Alignment start) {
    /*
         * Example with start == NORTH: [NORTH, NORTH_WEST, NORTH_EAST, SOUTH, SOUTH_WEST, SOUTH_EAST, WEST,
         * EAST]
         */
    Alignment opposite = start.opposite();
    Alignment clockwise = start.clockwise();
    Alignment anticlockwise = start.anticlockwise();
    return new Alignment[] { start, anticlockwise, clockwise, opposite, opposite.clockwise(), opposite.anticlockwise(), anticlockwise.anticlockwise(), clockwise.clockwise() };
}
Also used : Alignment(com.github.weisj.darklaf.util.Alignment)

Example 19 with Alignment

use of com.github.weisj.darklaf.util.Alignment in project darklaf by weisJ.

the class DarkTabFrameUI method getDropPosition.

@Override
public JTabFrame.TabFramePosition getDropPosition(final JTabFrame tabFrame, final Point p) {
    Pair<JTabFrame.TabFramePosition, Point> res = getNearestTabIndexAtImpl(tabFrame, p);
    JTabFrame.TabFramePosition tab = res.getFirst();
    if (tab.getAlignment() != null) {
        Alignment a = tab.getAlignment();
        int index = tab.getIndex();
        if (index >= 0) {
            Rectangle rect = getTabRect(tabFrame.getTabComponentAt(a, index), a, tabFrame.getTabContainer(a), false);
            Point pos = res.getSecond();
            if (isForward(a)) {
                if (pos.x <= rect.x + rect.width / 2 && pos.x >= rect.x) {
                    tab.setIndex(tab.getIndex() - 1);
                }
            } else {
                if (pos.x >= rect.x + rect.width / 2) {
                    tab.setIndex(tab.getIndex() - 1);
                }
            }
        }
    }
    return tab;
}
Also used : Alignment(com.github.weisj.darklaf.util.Alignment)

Example 20 with Alignment

use of com.github.weisj.darklaf.util.Alignment in project darklaf by weisJ.

the class DarkTabFrameUI method getNearestTabIndexAtImpl.

protected Pair<JTabFrame.TabFramePosition, Point> getNearestTabIndexAtImpl(final JTabFrame tabFrame, final Point pos) {
    Pair<JTabFrame.TabFramePosition, Point> res = getTabIndexAtImpl(tabFrame, pos);
    JTabFrame.TabFramePosition tab = res.getFirst();
    if (tab.getAlignment() != null && tab.getIndex() == -1) {
        Point p = res.getSecond();
        Alignment a = tab.getAlignment();
        if (tabFrame.getTabCountAt(a) == 0) {
            tab.setIndex(-1);
            return res;
        }
        int w = a == destAlign && destIndex == -1 ? dropSize.width : 0;
        Component comp = getTabContainer(a);
        switch(a) {
            case NORTH:
            case SOUTH_WEST:
                if (p.x > getLeftContainer().getWidth() + w) {
                    tab.setIndex(tabFrame.getTabCountAt(a) - 1);
                }
                break;
            case NORTH_EAST:
            case SOUTH:
                if (p.x < comp.getWidth() - getRightContainer().getWidth() - w) {
                    tab.setIndex(tabFrame.getTabCountAt(a) - 1);
                }
                break;
            case EAST:
            case WEST:
                if (p.x > w) {
                    tab.setIndex(tabFrame.getTabCountAt(a) - 1);
                }
                break;
            case SOUTH_EAST:
            case NORTH_WEST:
                if (p.x < comp.getHeight() - w) {
                    tab.setIndex(tabFrame.getTabCountAt(a) - 1);
                }
                break;
            case CENTER:
                throw new IllegalStateException();
        }
    }
    return res;
}
Also used : Alignment(com.github.weisj.darklaf.util.Alignment)

Aggregations

Alignment (com.github.weisj.darklaf.util.Alignment)26 JTabFrame (com.github.weisj.darklaf.components.tabframe.JTabFrame)6 TabFrameUI (com.github.weisj.darklaf.components.tabframe.TabFrameUI)3 ToolTipContext (com.github.weisj.darklaf.components.tooltip.ToolTipContext)2 DemoPanel (com.github.weisj.darklaf.ui.DemoPanel)2 OverlayScrollPane (com.github.weisj.darklaf.components.OverlayScrollPane)1 AlignmentStrategy (com.github.weisj.darklaf.components.alignment.AlignmentStrategy)1 TabFrameTab (com.github.weisj.darklaf.components.tabframe.TabFrameTab)1 TabbedPopup (com.github.weisj.darklaf.components.tabframe.TabbedPopup)1 ToolTipStyle (com.github.weisj.darklaf.components.tooltip.ToolTipStyle)1 DarkSVGIcon (com.github.weisj.darklaf.properties.icons.DarkSVGIcon)1 RotatableIcon (com.github.weisj.darklaf.properties.icons.RotatableIcon)1 DemoResources (com.github.weisj.darklaf.ui.DemoResources)1 BaseComponentDemo (com.github.weisj.darklaf.ui.demo.BaseComponentDemo)1 DemoExecutor (com.github.weisj.darklaf.ui.demo.DemoExecutor)1 AlignableTooltipBorder (com.github.weisj.darklaf.ui.tooltip.AlignableTooltipBorder)1 DarkToolTipUI (com.github.weisj.darklaf.ui.tooltip.DarkToolTipUI)1 Pair (com.github.weisj.darklaf.util.Pair)1 StringUtil (com.github.weisj.darklaf.util.StringUtil)1 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1