Search in sources :

Example 1 with TabFrameTab

use of com.github.weisj.darklaf.components.tabframe.TabFrameTab 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 TabFrameTab

use of com.github.weisj.darklaf.components.tabframe.TabFrameTab in project darklaf by weisJ.

the class TabFrameLayout method layoutTabArea.

protected int layoutTabArea(final Point start, final Alignment a, final boolean forward, final int size) {
    int x = start.x;
    int y = start.y;
    int sourceIndex = a == ui.getSourceAlign() ? ui.getSourceIndex() : -10;
    int destIndex = a == ui.getDestAlign() ? ui.getDestIndex() : -10;
    Rectangle bounds = new Rectangle(0, 0, 0, 0);
    int index = 0;
    Component dropComp = ui.getDropComponent(a);
    if (destIndex == -1) {
        if (forward) {
            dropComp.setBounds(x, y, ui.getDropSize().width, size);
            x += ui.getDropSize().width;
        } else {
            x -= ui.getDropSize().width;
            dropComp.setBounds(x, y, ui.getDropSize().width, size);
        }
    }
    for (TabFrameTab c : tabFrame.tabsForAlignment(a)) {
        index = c.getIndex();
        bounds.width = index == sourceIndex ? 0 : getTabWidth(c.getComponent());
        bounds.height = size;
        if (forward) {
            bounds.x = x;
            bounds.y = y;
            x += bounds.width;
            if (index == destIndex) {
                dropComp.setBounds(x, y, ui.getDropSize().width, size);
                x += ui.getDropSize().width;
            }
        } else {
            x -= bounds.width;
            bounds.x = x;
            bounds.y = y;
            if (index == destIndex) {
                x -= ui.getDropSize().width;
                dropComp.setBounds(x, y, ui.getDropSize().width, size);
            }
        }
        c.getComponent().setBounds(bounds);
    }
    if (destIndex == index + 1) {
        if (forward) {
            dropComp.setBounds(x, y, ui.getDropSize().width, size);
            x += ui.getDropSize().width;
        } else {
            x -= ui.getDropSize().width;
            dropComp.setBounds(x, y, ui.getDropSize().width, size);
        }
    }
    return x;
}
Also used : TabFrameTab(com.github.weisj.darklaf.components.tabframe.TabFrameTab)

Example 3 with TabFrameTab

use of com.github.weisj.darklaf.components.tabframe.TabFrameTab in project darklaf by weisJ.

the class TabFrameLayout method shift.

protected void shift(final int shift, final Alignment a) {
    for (TabFrameTab c : tabFrame.tabsForAlignment(a)) {
        Point pos = c.getComponent().getLocation();
        pos.x += shift;
        c.getComponent().setLocation(pos);
    }
    if (a == ui.getDestAlign()) {
        Component dropComp = ui.getDropComponent(a);
        Point pos = dropComp.getLocation();
        pos.x += shift;
        dropComp.setLocation(pos);
    }
}
Also used : TabFrameTab(com.github.weisj.darklaf.components.tabframe.TabFrameTab)

Aggregations

TabFrameTab (com.github.weisj.darklaf.components.tabframe.TabFrameTab)3 JTabFrame (com.github.weisj.darklaf.components.tabframe.JTabFrame)1 TabFrameUI (com.github.weisj.darklaf.components.tabframe.TabFrameUI)1 Alignment (com.github.weisj.darklaf.util.Alignment)1 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1