use of com.github.weisj.darklaf.components.tabframe.JTabFrame 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.components.tabframe.JTabFrame 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.components.tabframe.JTabFrame 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.components.tabframe.JTabFrame in project darklaf by weisJ.
the class DarkPanelPopupUI method updateBorder.
protected void updateBorder(final boolean notifyPeer) {
if (popupComponent.getTabFrame() != null) {
JTabFrame tabFrame = popupComponent.getTabFrame();
boolean[] status = tabFrame.getContentPane().getStatus();
Alignment alignment = popupComponent.getAlignment();
Insets insets = getBorderSize(tabFrame, alignment, status);
applyBorderInsets(insets);
Component component = popupComponent.getComponent();
popupComponent.doLayout();
popupComponent.repaint();
if (component != null && component != popupComponent) {
component.doLayout();
component.repaint();
}
if (header != null) {
Component headerParent = header.getParent();
if (headerParent != null) {
headerParent.doLayout();
headerParent.repaint();
}
}
if (notifyPeer) {
try {
Component peer = tabFrame.getPopupComponentAt(tabFrame.getPeer(popupComponent.getAlignment()));
peer.firePropertyChange(TabFramePopup.KEY_PEER_INSETS, 0, 1);
} catch (final IndexOutOfBoundsException ignored) {
/* may happen during transfer */
}
}
}
}
use of com.github.weisj.darklaf.components.tabframe.JTabFrame in project darklaf by weisJ.
the class DarkPanelPopupUI method uninstallListeners.
protected void uninstallListeners() {
popupComponent.removePropertyChangeListener(this);
JTabFrame frame = popupComponent.getTabFrame();
if (frame != null) {
frame.removePropertyChangeListener(this);
}
}
Aggregations