Search in sources :

Example 1 with Alignment

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;
}
Also used : Alignment(com.github.weisj.darklaf.util.Alignment) JTabFrame(com.github.weisj.darklaf.components.tabframe.JTabFrame) TabFrameTab(com.github.weisj.darklaf.components.tabframe.TabFrameTab) TabFrameUI(com.github.weisj.darklaf.components.tabframe.TabFrameUI) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Example 2 with Alignment

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();
}
Also used : Alignment(com.github.weisj.darklaf.util.Alignment) JTabFrame(com.github.weisj.darklaf.components.tabframe.JTabFrame) TabFrameUI(com.github.weisj.darklaf.components.tabframe.TabFrameUI)

Example 3 with Alignment

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;
}
Also used : Alignment(com.github.weisj.darklaf.util.Alignment) JTabFrame(com.github.weisj.darklaf.components.tabframe.JTabFrame) TabFrameUI(com.github.weisj.darklaf.components.tabframe.TabFrameUI)

Example 4 with Alignment

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);
            }
        }
    });
}
Also used : Alignment(com.github.weisj.darklaf.util.Alignment)

Example 5 with Alignment

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);
}
Also used : Alignment(com.github.weisj.darklaf.util.Alignment)

Aggregations

Alignment (com.github.weisj.darklaf.util.Alignment)26 JTabFrame (com.github.weisj.darklaf.components.tabframe.JTabFrame)6 TabFrameUI (com.github.weisj.darklaf.components.tabframe.TabFrameUI)3 ToolTipContext (com.github.weisj.darklaf.components.tooltip.ToolTipContext)2 DemoPanel (com.github.weisj.darklaf.ui.DemoPanel)2 OverlayScrollPane (com.github.weisj.darklaf.components.OverlayScrollPane)1 AlignmentStrategy (com.github.weisj.darklaf.components.alignment.AlignmentStrategy)1 TabFrameTab (com.github.weisj.darklaf.components.tabframe.TabFrameTab)1 TabbedPopup (com.github.weisj.darklaf.components.tabframe.TabbedPopup)1 ToolTipStyle (com.github.weisj.darklaf.components.tooltip.ToolTipStyle)1 DarkSVGIcon (com.github.weisj.darklaf.properties.icons.DarkSVGIcon)1 RotatableIcon (com.github.weisj.darklaf.properties.icons.RotatableIcon)1 DemoResources (com.github.weisj.darklaf.ui.DemoResources)1 BaseComponentDemo (com.github.weisj.darklaf.ui.demo.BaseComponentDemo)1 DemoExecutor (com.github.weisj.darklaf.ui.demo.DemoExecutor)1 AlignableTooltipBorder (com.github.weisj.darklaf.ui.tooltip.AlignableTooltipBorder)1 DarkToolTipUI (com.github.weisj.darklaf.ui.tooltip.DarkToolTipUI)1 Pair (com.github.weisj.darklaf.util.Pair)1 StringUtil (com.github.weisj.darklaf.util.StringUtil)1 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1