|
|
@ -1,21 +1,25 @@ |
|
|
|
package com.fr.design.gui.frpane; |
|
|
|
package com.fr.design.gui.frpane; |
|
|
|
|
|
|
|
|
|
|
|
import com.fine.swing.ui.layout.Column; |
|
|
|
import com.fine.swing.ui.layout.Box; |
|
|
|
import com.fine.theme.utils.FineUIStyle; |
|
|
|
import com.fine.theme.utils.FineUIUtils; |
|
|
|
|
|
|
|
import com.formdev.flatlaf.ui.FlatUIUtils; |
|
|
|
import com.formdev.flatlaf.util.ScaledEmptyBorder; |
|
|
|
import com.formdev.flatlaf.util.ScaledEmptyBorder; |
|
|
|
import com.fr.design.gui.ibutton.UIButtonGroup; |
|
|
|
import com.fr.design.gui.ibutton.UIButtonGroup; |
|
|
|
|
|
|
|
import com.fr.design.utils.ColorUtils; |
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.JComponent; |
|
|
|
import javax.swing.JComponent; |
|
|
|
import javax.swing.JPanel; |
|
|
|
import javax.swing.JPanel; |
|
|
|
import javax.swing.event.ChangeListener; |
|
|
|
import javax.swing.event.ChangeListener; |
|
|
|
import java.awt.BorderLayout; |
|
|
|
import java.awt.BorderLayout; |
|
|
|
import java.awt.CardLayout; |
|
|
|
import java.awt.CardLayout; |
|
|
|
|
|
|
|
import java.awt.Color; |
|
|
|
import java.awt.Component; |
|
|
|
import java.awt.Component; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.LinkedHashMap; |
|
|
|
import java.util.LinkedHashMap; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
import static com.fine.swing.ui.layout.Layouts.cell; |
|
|
|
import static com.fine.swing.ui.layout.Layouts.cell; |
|
|
|
|
|
|
|
import static com.fine.swing.ui.layout.Layouts.column; |
|
|
|
import static com.fine.swing.ui.layout.Layouts.fix; |
|
|
|
import static com.fine.swing.ui.layout.Layouts.fix; |
|
|
|
import static com.fine.swing.ui.layout.Layouts.flex; |
|
|
|
import static com.fine.swing.ui.layout.Layouts.flex; |
|
|
|
import static com.fine.swing.ui.layout.Layouts.row; |
|
|
|
import static com.fine.swing.ui.layout.Layouts.row; |
|
|
@ -29,17 +33,19 @@ import static com.fine.theme.utils.FineClientProperties.ROUNDED_PANEL; |
|
|
|
* @since 11.0 |
|
|
|
* @since 11.0 |
|
|
|
* Created on 2024/05/14 |
|
|
|
* Created on 2024/05/14 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class FineTabbedPane extends Column { |
|
|
|
public class FineTabbedPane extends Box { |
|
|
|
|
|
|
|
|
|
|
|
private CardLayout cards; |
|
|
|
private CardLayout cards; |
|
|
|
private JPanel centerPane; |
|
|
|
private JPanel centerPane; |
|
|
|
private final float headRatio; |
|
|
|
private final float headRatio; |
|
|
|
private final UIButtonGroup<String> tabGroup; |
|
|
|
private final UIButtonGroup<String> tabGroup; |
|
|
|
private final Map<String, JComponent> tabComponents; |
|
|
|
private final Map<String, JComponent> tabComponents; |
|
|
|
|
|
|
|
private final int[] tabLayout; |
|
|
|
|
|
|
|
|
|
|
|
private FineTabbedPane(Map<String, JComponent> tabComponents, float headRatio, int[] tabLayout) { |
|
|
|
private FineTabbedPane(Map<String, JComponent> tabComponents, float headRatio, int[] tabLayout) { |
|
|
|
this.headRatio = headRatio; |
|
|
|
this.headRatio = headRatio; |
|
|
|
this.tabComponents = tabComponents; |
|
|
|
this.tabComponents = tabComponents; |
|
|
|
|
|
|
|
this.tabLayout = tabLayout; |
|
|
|
|
|
|
|
|
|
|
|
String[] titleArray = tabComponents.keySet().toArray(new String[0]); |
|
|
|
String[] titleArray = tabComponents.keySet().toArray(new String[0]); |
|
|
|
this.tabGroup = new UIButtonGroup<>(titleArray, titleArray, tabLayout); |
|
|
|
this.tabGroup = new UIButtonGroup<>(titleArray, titleArray, tabLayout); |
|
|
@ -110,7 +116,9 @@ public class FineTabbedPane extends Column { |
|
|
|
if (headRatio > 1) { |
|
|
|
if (headRatio > 1) { |
|
|
|
throw new IllegalArgumentException("illegal headRatio argument!"); |
|
|
|
throw new IllegalArgumentException("illegal headRatio argument!"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (tabLayout != null && Arrays.stream(tabLayout).sum() != tabComponents.size()) { |
|
|
|
if (tabLayout == null) { |
|
|
|
|
|
|
|
tabLayout = new int[]{tabComponents.size()}; |
|
|
|
|
|
|
|
} else if (Arrays.stream(tabLayout).sum() != tabComponents.size()) { |
|
|
|
throw new IllegalArgumentException("illegal tab layout argument!"); |
|
|
|
throw new IllegalArgumentException("illegal tab layout argument!"); |
|
|
|
} |
|
|
|
} |
|
|
|
return new FineTabbedPane(tabComponents, headRatio, tabLayout); |
|
|
|
return new FineTabbedPane(tabComponents, headRatio, tabLayout); |
|
|
@ -118,6 +126,26 @@ public class FineTabbedPane extends Column { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void initLayout() { |
|
|
|
private void initLayout() { |
|
|
|
|
|
|
|
initCoreComponents(); |
|
|
|
|
|
|
|
setMatchParentSize(true); |
|
|
|
|
|
|
|
float flexRatio = (1 - headRatio) / 2; |
|
|
|
|
|
|
|
int headHeight = FlatUIUtils.getUIInt("Component.defaultHeight",24) * tabLayout.length / 2; |
|
|
|
|
|
|
|
add( |
|
|
|
|
|
|
|
column( |
|
|
|
|
|
|
|
row( |
|
|
|
|
|
|
|
flex(flexRatio), cell(tabGroup).weight(headRatio), flex(flexRatio) |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
flex() |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
column( |
|
|
|
|
|
|
|
fix(headHeight), |
|
|
|
|
|
|
|
cell(centerPane).with(it -> it.setBorder(new ScaledEmptyBorder(headHeight + 10, 10, 10, 10))).weight(1) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
fillBackgroundColor(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void initCoreComponents() { |
|
|
|
cards = new CardLayout(); |
|
|
|
cards = new CardLayout(); |
|
|
|
centerPane = new JPanel(cards); |
|
|
|
centerPane = new JPanel(cards); |
|
|
|
centerPane.putClientProperty(PANEL_TYPE, ROUNDED_PANEL); |
|
|
|
centerPane.putClientProperty(PANEL_TYPE, ROUNDED_PANEL); |
|
|
@ -125,15 +153,12 @@ public class FineTabbedPane extends Column { |
|
|
|
value.setOpaque(false); |
|
|
|
value.setOpaque(false); |
|
|
|
centerPane.add(value, key); |
|
|
|
centerPane.add(value, key); |
|
|
|
}); |
|
|
|
}); |
|
|
|
float flexRatio = (1 - headRatio) / 2; |
|
|
|
} |
|
|
|
add( |
|
|
|
|
|
|
|
row( |
|
|
|
private void fillBackgroundColor() { |
|
|
|
flex(flexRatio), cell(tabGroup).weight(headRatio), flex(flexRatio) |
|
|
|
Color fillColor = FineUIUtils.getUIColor("FineTabbedPane.background", "fill.gray"); |
|
|
|
), |
|
|
|
Color defaultColor = FineUIUtils.getUIColor("default.background", "Component.background"); |
|
|
|
fix(5), |
|
|
|
ColorUtils.syncBackgroundIfAbsent(centerPane, fillColor, defaultColor); |
|
|
|
cell(centerPane).weight(1).with(it -> FineUIStyle.setStyle(it, FineUIStyle.LIGHT_GREY)) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
setBorder(new ScaledEmptyBorder(10, 10, 10, 10)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void initListeners() { |
|
|
|
private void initListeners() { |
|
|
|