use of com.github.weisj.darklaf.util.Alignment in project darklaf by weisJ.
the class TabFrameTransferHandler method importData.
/**
* Called when the drag-and-drop operation has just completed. This creates a new tab identical to
* the one "dragged" and places it in the destination <code>JTabbedPane</code>.
*
* @param c The component receiving the "drop" (the instance of <code>JTabbedPane</code>).
* @param t The data being transfered (information about the tab and the component contained by the
* tab).
* @return Whether or not the import was successful.
*/
@Override
public boolean importData(final JComponent c, final Transferable t) {
boolean successful = false;
if (hasTabFlavor(t.getTransferDataFlavors()) && mouseLocation != null) {
try {
JTabFrame tabFrame = (JTabFrame) c;
JTabFrame.TabFramePosition tab = getDropPosition(mouseLocation, tabFrame);
Alignment a = tab.getAlignment();
int index = tab.getIndex();
TabTransferData td = (TabTransferData) t.getTransferData(tabFlavor);
if (tabFrame == td.sourceTabFrame && td.tabAlignment == a) {
if (index >= td.tabIndex) {
index--;
}
}
index++;
if (tabFrame == td.sourceTabFrame && a == td.tabAlignment && index == td.tabIndex) {
// Nothing to do. Just select the tab to be sure.
if (td.wasSelected) {
selectTab(td.sourceTabFrame, a, index);
}
return false;
}
if (a == null || index < 0 || index > tabFrame.getTabCountAt(a)) {
return false;
}
TabFrameTab tabComp = td.sourceTabFrame.getTabComponentAt(td.tabAlignment, td.tabIndex);
Component popupComp = td.sourceTabFrame.getPopupComponentAt(td.tabAlignment, td.tabIndex);
td.sourceTabFrame.removeTab(td.tabAlignment, td.tabIndex);
tabFrame.insertTab((TabFramePopup) popupComp, tabComp, a, index);
if (td.wasSelected) {
tabFrame.toggleTab(a, index, true);
}
SwingUtilities.invokeLater(() -> td.tab.getComponent().repaint());
successful = true;
TabFrameUI ui = getUI(c);
if (ui != null) {
ui.clearTargetIndicator();
}
} catch (final Exception e) {
LOGGER.log(Level.SEVERE, "Couldn't import tab data", e);
}
}
return successful;
}
use of com.github.weisj.darklaf.util.Alignment in project darklaf by weisJ.
the class TabFrameTransferHandler method dragOver.
@Override
public void dragOver(final DropTargetDragEvent e) {
e.getDropTargetContext().getComponent().setCursor(Cursor.getDefaultCursor());
mouseLocation = e.getLocation();
Component c = e.getDropTargetContext().getComponent();
JTabFrame destTabFrame = (JTabFrame) c;
TabFrameUI ui = getUI(destTabFrame);
if (ui != null) {
TabTransferable t = currentTransferable;
if (t != null) {
JTabFrame.TabFramePosition tab = getDropPosition(mouseLocation, destTabFrame);
if (tab.getAlignment() == null) {
ui.clearTargetIndicator();
} else {
try {
JTabFrame sourceTab = currentTransferable.transferData.sourceTabFrame;
int sourceIndex = currentTransferable.transferData.tabIndex;
Alignment sourceAlign = currentTransferable.transferData.tabAlignment;
int w = getUI(sourceTab).getTabWidth(sourceTab, sourceAlign, sourceIndex);
int h = getUI(sourceTab).getTabHeight(sourceTab, sourceAlign, sourceIndex);
ui.setDropSize(w, h);
ui.setTargetIndicator(tab.getAlignment(), tab.getIndex());
} catch (final IndexOutOfBoundsException ex) {
ui.clearTargetIndicator();
}
}
}
}
lastTabFrame = destTabFrame;
startTimer.restart();
}
use of com.github.weisj.darklaf.util.Alignment in project darklaf by weisJ.
the class TabFrameTransferHandler method createTransferable.
protected Transferable createTransferable(final JComponent c, final DragGestureEvent dge) {
JTabFrame tabFrame = (JTabFrame) c;
if (tabFrame.isInTransfer()) {
currentTransferable = new TabTransferable(tabFrame, tabFrame.getTransferInfo());
} else {
JTabFrame.TabFramePosition ind = getUI(tabFrame).getTabIndexAt(tabFrame, dge.getDragOrigin());
tabFrame.initTransfer(ind.getAlignment(), ind.getIndex());
currentTransferable = new TabTransferable(tabFrame, ind);
}
TabFrameUI ui = getUI(c);
createDragImage(ui);
Alignment a = currentTransferable.transferData.tabAlignment;
int index = currentTransferable.transferData.tabIndex;
ui.setSourceIndicator(a, index);
startTimer.start();
lastTabFrame = currentTransferable.transferData.sourceTabFrame;
return currentTransferable;
}
use of com.github.weisj.darklaf.util.Alignment in project darklaf by weisJ.
the class TabFrameUtil method createAcceleratorAction.
public static Action createAcceleratorAction(final JTabFrame tabFrame, final TabFrameTab tab) {
return Actions.create(e -> {
Alignment a = tab.getOrientation();
int index = tab.getIndex();
if (!tab.isSelected()) {
tabFrame.toggleTab(a, index, true);
} else {
Component popup = tabFrame.getPopupComponentAt(a, index);
if (!DarkUIUtil.hasFocus(popup)) {
popup.requestFocusInWindow();
} else {
tabFrame.toggleTab(a, index, false);
}
}
});
}
use of com.github.weisj.darklaf.util.Alignment in project darklaf by weisJ.
the class DarkTabFrameUI method maybeRestoreTabContainer.
protected JTabFrame.TabFramePosition maybeRestoreTabContainer(final JTabFrame tabFrame, final Point p) {
Alignment a = null;
int size = tabFrame.getTabSize();
int threshold = size;
int index = -10;
if (tabFrame.getTopTabCount() == 0) {
if (layout.isDraggedOver(Alignment.NORTH))
threshold *= 2;
if (p.y < threshold) {
a = p.x >= tabFrame.getWidth() / 2 ? Alignment.NORTH_EAST : Alignment.NORTH;
}
if (p.y < size)
index = -1;
}
if (a == null && tabFrame.getBottomTabCount() == 0) {
if (layout.isDraggedOver(Alignment.SOUTH))
threshold *= 2;
if (p.y > tabFrame.getHeight() - threshold) {
a = p.x >= tabFrame.getWidth() / 2 ? Alignment.SOUTH : Alignment.SOUTH_WEST;
}
if (p.y > tabFrame.getHeight() - size)
index = -1;
}
if (a == null && tabFrame.getLeftTabCount() == 0) {
if (layout.isDraggedOver(Alignment.WEST))
threshold *= 2;
if (p.x < threshold) {
a = p.y >= tabFrame.getHeight() / 2 ? Alignment.WEST : Alignment.NORTH_WEST;
}
if (p.x < size)
index = -1;
}
if (a == null && tabFrame.getRightTabCount() == 0) {
if (layout.isDraggedOver(Alignment.EAST))
threshold *= 2;
if (p.x > tabFrame.getWidth() - threshold) {
a = p.y >= tabFrame.getHeight() / 2 ? Alignment.SOUTH_EAST : Alignment.EAST;
}
if (p.x > tabFrame.getWidth() - size)
index = -1;
}
layout.setDraggedOver(false);
if (a != null) {
layout.setDraggedOver(a, true);
}
return new JTabFrame.TabFramePosition(a, index);
}
Aggregations