|
|
@ -3,10 +3,8 @@ package com.fr.design.gui.ibutton; |
|
|
|
import com.fine.swing.ui.layout.Column; |
|
|
|
import com.fine.swing.ui.layout.Column; |
|
|
|
import com.fine.swing.ui.layout.Row; |
|
|
|
import com.fine.swing.ui.layout.Row; |
|
|
|
import com.fine.swing.ui.layout.Spacer; |
|
|
|
import com.fine.swing.ui.layout.Spacer; |
|
|
|
import com.fine.theme.light.ui.FineRoundBorder; |
|
|
|
import com.fine.theme.utils.FineUIScale; |
|
|
|
import com.fine.theme.light.ui.RectangleButtonUI; |
|
|
|
|
|
|
|
import com.fine.theme.utils.FineUIUtils; |
|
|
|
import com.fine.theme.utils.FineUIUtils; |
|
|
|
import com.formdev.flatlaf.ui.FlatUIUtils; |
|
|
|
|
|
|
|
import com.fr.design.event.GlobalNameListener; |
|
|
|
import com.fr.design.event.GlobalNameListener; |
|
|
|
import com.fr.design.event.GlobalNameObserver; |
|
|
|
import com.fr.design.event.GlobalNameObserver; |
|
|
|
import com.fr.design.event.UIObserver; |
|
|
|
import com.fr.design.event.UIObserver; |
|
|
@ -16,27 +14,24 @@ import com.fr.stable.ArrayUtils; |
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.Icon; |
|
|
|
import javax.swing.Icon; |
|
|
|
import javax.swing.border.Border; |
|
|
|
|
|
|
|
import javax.swing.border.LineBorder; |
|
|
|
import javax.swing.border.LineBorder; |
|
|
|
import javax.swing.event.ChangeEvent; |
|
|
|
import javax.swing.event.ChangeEvent; |
|
|
|
import javax.swing.event.ChangeListener; |
|
|
|
import javax.swing.event.ChangeListener; |
|
|
|
import javax.swing.UIManager; |
|
|
|
|
|
|
|
import javax.swing.JComponent; |
|
|
|
|
|
|
|
import javax.swing.plaf.ComponentUI; |
|
|
|
|
|
|
|
import java.awt.Dimension; |
|
|
|
import java.awt.Dimension; |
|
|
|
import java.awt.Graphics; |
|
|
|
|
|
|
|
import java.awt.event.ActionListener; |
|
|
|
import java.awt.event.ActionListener; |
|
|
|
import java.awt.event.MouseAdapter; |
|
|
|
import java.awt.event.MouseAdapter; |
|
|
|
import java.awt.event.MouseEvent; |
|
|
|
import java.awt.event.MouseEvent; |
|
|
|
import java.awt.event.MouseListener; |
|
|
|
import java.awt.event.MouseListener; |
|
|
|
import java.awt.geom.RoundRectangle2D; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
import static com.fine.swing.ui.layout.Layouts.cell; |
|
|
|
import static com.fine.swing.ui.layout.Layouts.cell; |
|
|
|
|
|
|
|
import static com.fine.theme.utils.FineClientProperties.BUTTON_TYPE_GROUP; |
|
|
|
|
|
|
|
import static com.fine.theme.utils.FineClientProperties.BUTTON_TYPE; |
|
|
|
|
|
|
|
|
|
|
|
public class UIButtonGroup<T> extends Column implements GlobalNameObserver, UIObserver { |
|
|
|
public class UIButtonGroup<T> extends Column implements GlobalNameObserver, UIObserver { |
|
|
|
|
|
|
|
private static final String UI_CLASS_ID = "ButtonGroupUI"; |
|
|
|
private static final long serialVersionUID = 1L; |
|
|
|
private static final long serialVersionUID = 1L; |
|
|
|
private static final int TEXT_LENGTH = 3; |
|
|
|
private static final int TEXT_LENGTH = 3; |
|
|
|
private static final int BUTTON_SIZE = 2; |
|
|
|
private static final int BUTTON_SIZE = 2; |
|
|
@ -169,6 +164,11 @@ public class UIButtonGroup<T> extends Column implements GlobalNameObserver, UIOb |
|
|
|
initLayout(getCols()); |
|
|
|
initLayout(getCols()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public String getUIClassID() { |
|
|
|
|
|
|
|
return UI_CLASS_ID; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected int[] getCols() { |
|
|
|
protected int[] getCols() { |
|
|
|
return new int[]{labelButtonList.size()}; |
|
|
|
return new int[]{labelButtonList.size()}; |
|
|
|
} |
|
|
|
} |
|
|
@ -190,18 +190,17 @@ public class UIButtonGroup<T> extends Column implements GlobalNameObserver, UIOb |
|
|
|
add(createDivider()); |
|
|
|
add(createDivider()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
this.setBorder(getGroupBorder()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Spacer createDivider() { |
|
|
|
private Spacer createDivider() { |
|
|
|
Spacer spacer = new Spacer(1); |
|
|
|
Spacer spacer = new Spacer(FineUIScale.scale(1)); |
|
|
|
spacer.setBorder(new LineBorder(FineUIUtils.getUIColor("defaultBorderColor", "Component.borderColor"))); |
|
|
|
spacer.setBorder(new LineBorder(FineUIUtils.getUIColor("defaultBorderColor", "Component.borderColor"))); |
|
|
|
return spacer; |
|
|
|
return spacer; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected void initButton(UIToggleButton labelButton) { |
|
|
|
protected void initButton(UIToggleButton labelButton) { |
|
|
|
labelButton.setUI(new TabButtonUI(false)); |
|
|
|
|
|
|
|
labelButton.setBorderPainted(false); |
|
|
|
labelButton.setBorderPainted(false); |
|
|
|
|
|
|
|
labelButton.putClientProperty(BUTTON_TYPE, BUTTON_TYPE_GROUP); |
|
|
|
adjustButton(labelButton); |
|
|
|
adjustButton(labelButton); |
|
|
|
UIComponentUtils.setLineWrap(labelButton); |
|
|
|
UIComponentUtils.setLineWrap(labelButton); |
|
|
|
labelButtonList.add(labelButton); |
|
|
|
labelButtonList.add(labelButton); |
|
|
@ -216,18 +215,6 @@ public class UIButtonGroup<T> extends Column implements GlobalNameObserver, UIOb |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected Border getGroupBorder() { |
|
|
|
|
|
|
|
return new FineRoundBorder(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
protected void paintComponent(Graphics g) { |
|
|
|
|
|
|
|
super.paintComponent(g); |
|
|
|
|
|
|
|
FlatUIUtils.setRenderingHints(g); |
|
|
|
|
|
|
|
int arc = FineUIUtils.getUIInt("Button.group.arc", "Component.arc"); |
|
|
|
|
|
|
|
g.setClip(new RoundRectangle2D.Double(0, 0, getWidth(), getHeight(), arc, arc)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean hasClick() { |
|
|
|
public boolean hasClick() { |
|
|
|
return isClick; |
|
|
|
return isClick; |
|
|
|
} |
|
|
|
} |
|
|
@ -252,37 +239,6 @@ public class UIButtonGroup<T> extends Column implements GlobalNameObserver, UIOb |
|
|
|
labelButtonList.forEach(b -> b.setEnabled(enabled)); |
|
|
|
labelButtonList.forEach(b -> b.setEnabled(enabled)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static class TabButtonUI extends RectangleButtonUI { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected int minimumWidth; |
|
|
|
|
|
|
|
protected int minimumHeight; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected TabButtonUI(boolean shared) { |
|
|
|
|
|
|
|
super(shared); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static ComponentUI createUI(JComponent c) { |
|
|
|
|
|
|
|
return new TabButtonUI(false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void installUI(JComponent c) { |
|
|
|
|
|
|
|
super.installUI(c); |
|
|
|
|
|
|
|
background = UIManager.getColor("Button.group.background"); |
|
|
|
|
|
|
|
pressedBackground = UIManager.getColor("Button.group.pressedBackground"); |
|
|
|
|
|
|
|
selectedBackground = UIManager.getColor("Button.group.selectedBackground"); |
|
|
|
|
|
|
|
pressedForeground = UIManager.getColor("Button.group.pressedForeground"); |
|
|
|
|
|
|
|
selectedForeground = UIManager.getColor("Button.group.selectedForeground"); |
|
|
|
|
|
|
|
minimumWidth = UIManager.getInt("Button.group.minimumWidth"); |
|
|
|
|
|
|
|
minimumHeight = UIManager.getInt("Button.group.minimumHeight"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public Dimension getMinimumSize(JComponent c) { |
|
|
|
|
|
|
|
return new Dimension(minimumWidth, minimumHeight); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setGlobalName(String name) { |
|
|
|
public void setGlobalName(String name) { |
|
|
|
buttonGroupName = name; |
|
|
|
buttonGroupName = name; |
|
|
|
} |
|
|
|
} |
|
|
|