studio.ui.dndtabbedpane.DropTargetHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kdbStudio Show documentation
Show all versions of kdbStudio Show documentation
Studio for kdb+ is a rapid development environment for the ultra-fast database kdb+ from Kx Systems: http://www.kx.com.
package studio.ui.dndtabbedpane;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javax.swing.*;
import java.awt.*;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.dnd.*;
import java.io.IOException;
class DropTargetHandler implements DropTargetListener {
private final DraggableTabbedPane pane;
private static final Logger log = LogManager.getLogger();
private boolean before;
private final static int WIDTH = 4;
DropTargetHandler(DraggableTabbedPane pane) {
this.pane = pane;
}
private TabbedPaneTransferable getTransferable(Transferable transferable) {
if (! transferable.isDataFlavorSupported(TabbedPaneTransferable.TABBED_PANE_DATA_FLAVOR)) {
return null;
}
try {
TabbedPaneTransferable data = (TabbedPaneTransferable) transferable.getTransferData(TabbedPaneTransferable.TABBED_PANE_DATA_FLAVOR);
if (data.getPane().getDragID().equals(pane.getDragID())) return data;
} catch (UnsupportedFlavorException | IOException e) {
log.error("Error during getting TabbedPaneTransferable", e);
}
return null;
}
private static Rectangle flip(boolean doFlip, Rectangle rect) {
if (!doFlip) return rect;
return new Rectangle(rect.y, rect.x, rect.height, rect.width);
}
private static Point flip(boolean doFlip, Point p) {
if (!doFlip) return p;
return new Point(p.y, p.x);
}
private int checkHighlight(Transferable transferable, Point location) {
if (getTransferable(transferable) == null) return -1;
int idx = pane.indexAtLocation(location.x, location.y);
int tabPlacement = pane.getTabPlacement();
boolean flip = tabPlacement == JTabbedPane.LEFT || tabPlacement == JTabbedPane.RIGHT;
location = flip(flip, location);
int index = -1;
if (idx == -1) {
int dist = Integer.MAX_VALUE;
int count = pane.getTabCount();
for (int i = 0; i srcIndex) index--;
boolean success = source.dragTab(srcIndex, pane, index);
if (success) {
dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
} else {
dtde.rejectDrop();
}
dtde.dropComplete(success);
} catch (RuntimeException e) {
log.error("Unexpected exception", e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy