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;
}
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;
}
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() };
}
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;
}
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;
}
Aggregations