use of com.github.weisj.darklaf.util.Alignment in project darklaf by weisJ.
the class DarkTabFrameUI method getTabIndexAtImpl.
protected Pair<JTabFrame.TabFramePosition, Point> getTabIndexAtImpl(final JTabFrame tabFrame, final Point p) {
Component tabComp = null;
Alignment a = null;
Point pos = null;
if (!layout.isDraggedOver(Alignment.NORTH)) {
getTopContainer().getBounds(calcRect);
if (p.y >= calcRect.y && p.y <= calcRect.y + calcRect.height) {
tabComp = getTopContainer();
a = Alignment.NORTH;
pos = SwingUtilities.convertPoint(tabFrame, p, tabComp);
if (pos.x > tabComp.getWidth() / 2) {
a = Alignment.NORTH_EAST;
}
}
}
if (tabComp == null && !layout.isDraggedOver(Alignment.SOUTH)) {
getBottomContainer().getBounds(calcRect);
if (p.y >= calcRect.y && p.y <= calcRect.y + calcRect.height) {
tabComp = getBottomContainer();
a = Alignment.SOUTH;
pos = SwingUtilities.convertPoint(tabFrame, p, tabComp);
if (pos.x <= tabComp.getWidth() / 2) {
a = Alignment.SOUTH_WEST;
}
}
}
if (tabComp == null && !layout.isDraggedOver(Alignment.WEST)) {
getLeftContainer().getBounds(calcRect);
if (p.x >= calcRect.x && p.x <= calcRect.x + calcRect.width) {
tabComp = getLeftContainer();
a = Alignment.WEST;
pos = SwingUtilities.convertPoint(tabFrame, p, tabComp);
if (pos.y < tabComp.getHeight() / 2) {
a = Alignment.NORTH_WEST;
}
int tmp = pos.x;
pos.x = tabComp.getHeight() - pos.y;
pos.y = tmp;
}
}
if (tabComp == null && !layout.isDraggedOver(Alignment.EAST)) {
getRightContainer().getBounds(calcRect);
if (p.x >= calcRect.x && p.x <= calcRect.x + calcRect.width) {
tabComp = getRightContainer();
a = Alignment.EAST;
pos = SwingUtilities.convertPoint(tabFrame, p, tabComp);
if (pos.y > tabComp.getHeight() / 2) {
a = Alignment.SOUTH_EAST;
}
int tmp = pos.x;
// noinspection SuspiciousNameCombination
pos.x = pos.y;
pos.y = tmp;
}
}
if (tabComp == null) {
JTabFrame.TabFramePosition tab = maybeRestoreTabContainer(tabFrame, p);
if (tab.getAlignment() != null) {
return new Pair<>(tab, pos);
}
} else {
layout.setDraggedOver(false);
}
if (tabComp == null) {
return new Pair<>(new JTabFrame.TabFramePosition(null, -1), pos);
}
List<TabFrameTab> tabs = tabFrame.tabsForAlignment(a);
for (TabFrameTab tab : tabs) {
Rectangle rect = getTabRect(tab, a, tabComp, true);
if (rect.contains(pos)) {
return new Pair<>(new JTabFrame.TabFramePosition(a, tab.getIndex()), pos);
}
}
return new Pair<>(new JTabFrame.TabFramePosition(a, -1), pos);
}
use of com.github.weisj.darklaf.util.Alignment in project darklaf by weisJ.
the class TabFrameLayout method layoutVerticalDrop.
protected void layoutVerticalDrop(final Alignment left, final int size) {
Component comp = ui.getDropComponent(left);
Alignment a = ui.getDestAlign();
Dimension dropSize = ui.getDropSize();
Component tabComp = tabFrame.getTabContainer(left);
if (a == left) {
comp.setBounds(0, 0, dropSize.width, size);
} else {
comp.setBounds(tabComp.getWidth() - dropSize.width, 0, dropSize.width, size);
}
}
use of com.github.weisj.darklaf.util.Alignment in project darklaf by weisJ.
the class TabFrameLayout method layoutHorizontalDrop.
protected void layoutHorizontalDrop(final Alignment left, final int leftCount, final int rightCount, final int size, final int yOff) {
Alignment a = ui.getDestAlign();
Dimension dropSize = ui.getDropSize();
Component dropComp = ui.getDropComponent(left);
Component tabComp = ui.getTabContainer(left);
if (a == left) {
int x = leftCount > 0 ? leftHeight : 0;
dropComp.setBounds(x, yOff, dropSize.width, size);
} else {
int x = rightCount > 0 ? tabComp.getWidth() - rightHeight : tabComp.getWidth();
dropComp.setBounds(x - dropSize.width, yOff, dropSize.width, size);
}
}
use of com.github.weisj.darklaf.util.Alignment in project darklaf by weisJ.
the class DarkPanelPopupUI method installFocusListener.
protected void installFocusListener() {
JTabFrame tabFrame = popupComponent.getTabFrame();
Alignment a = popupComponent.getAlignment();
if (tabFrame == null || a == null)
return;
JComponent container = tabFrame.getContentPane().getContainer(a);
FocusParentHelper.setFocusParent(popupComponent, container, c -> {
if (!popupComponent.isOpen())
return;
setHeaderBackground(DarkUIUtil.hasFocus(popupComponent));
});
}
use of com.github.weisj.darklaf.util.Alignment in project darklaf by weisJ.
the class RotatableIconDemo method createComponent.
@Override
public JComponent createComponent() {
final int size = 25;
RotatableIcon rotateIcon = new RotatableIcon(((DarkSVGIcon) DemoResources.FOLDER_ICON).derive(size, size));
rotateIcon.setOrientation(Alignment.EAST);
JLabel iconLabel = new JLabel(rotateIcon);
DemoPanel panel = new DemoPanel(iconLabel);
Alignment[] orientations = new Alignment[8];
orientations[0] = Alignment.NORTH;
for (int i = 1; i <= 7; i++) {
orientations[i] = orientations[i - 1].clockwise();
}
int spacing = 360 / orientations.length;
JSlider slider = new JSlider(0, (orientations.length - 1) * spacing);
slider.setMajorTickSpacing(spacing);
slider.setSnapToTicks(true);
slider.setPaintLabels(true);
slider.setPaintTicks(true);
slider.setValue(rotateIcon.getOrientation().getIndex() * spacing);
slider.addChangeListener(e -> {
if (!slider.isEnabled())
return;
rotateIcon.setOrientation(orientations[slider.getValue() / spacing]);
iconLabel.repaint();
});
Timer timer = new Timer(1000, e -> {
Alignment orientation = rotateIcon.getOrientation().clockwise();
rotateIcon.setOrientation(orientation);
slider.setValue(orientation.getDegreeAngle());
iconLabel.repaint();
});
timer.setRepeats(true);
JCheckBox checkBox = new JCheckBox("Auto rotate");
checkBox.setSelected(false);
checkBox.addActionListener(e -> {
slider.setEnabled(!checkBox.isSelected());
if (checkBox.isSelected()) {
rotateIcon.setOrientation(Alignment.NORTH);
timer.start();
} else {
timer.stop();
}
});
JComponent controls = panel.addControls(new GridBagLayout());
controls.add(slider);
controls = panel.addControls(Box.createHorizontalBox());
controls.add(checkBox);
controls.add(Box.createHorizontalGlue());
controls = panel.addControls(new BorderLayout());
AtomicReference<Icon> nextIcon = new AtomicReference<>(rotateIcon.getIcon());
JList<AllIconsDemo.NamedIcon<? extends Icon>> list = AllIconsDemo.createIconJList(size);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.addListSelectionListener(e -> nextIcon.set(list.getSelectedValue().getSecond()));
controls.add(new OverlayScrollPane(list));
Box box = Box.createHorizontalBox();
box.add(Box.createHorizontalGlue());
JButton apply = new JButton("Change Icon");
apply.addActionListener(e -> {
rotateIcon.setIcon(nextIcon.get());
iconLabel.repaint();
});
box.add(apply);
box.add(Box.createHorizontalGlue());
controls = panel.addControls(new BorderLayout());
controls.add(box);
return panel;
}
Aggregations