|
|
@ -1,7 +1,11 @@ |
|
|
|
package com.fr.design.gui.ibutton; |
|
|
|
package com.fr.design.gui.ibutton; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.fine.swing.ui.layout.Column; |
|
|
|
|
|
|
|
import com.fine.swing.ui.layout.Row; |
|
|
|
|
|
|
|
import com.fine.swing.ui.layout.Spacer; |
|
|
|
import com.fine.theme.light.ui.FineRoundBorder; |
|
|
|
import com.fine.theme.light.ui.FineRoundBorder; |
|
|
|
import com.fine.theme.light.ui.RectangleButtonUI; |
|
|
|
import com.fine.theme.light.ui.RectangleButtonUI; |
|
|
|
|
|
|
|
import com.fine.theme.utils.FineUIUtils; |
|
|
|
import com.formdev.flatlaf.ui.FlatUIUtils; |
|
|
|
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; |
|
|
@ -11,10 +15,9 @@ import com.fr.design.utils.gui.UIComponentUtils; |
|
|
|
import com.fr.stable.ArrayUtils; |
|
|
|
import com.fr.stable.ArrayUtils; |
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.BorderFactory; |
|
|
|
|
|
|
|
import javax.swing.Icon; |
|
|
|
import javax.swing.Icon; |
|
|
|
import javax.swing.JPanel; |
|
|
|
|
|
|
|
import javax.swing.border.Border; |
|
|
|
import javax.swing.border.Border; |
|
|
|
|
|
|
|
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.UIManager; |
|
|
@ -22,9 +25,6 @@ import javax.swing.JComponent; |
|
|
|
import javax.swing.plaf.ComponentUI; |
|
|
|
import javax.swing.plaf.ComponentUI; |
|
|
|
import java.awt.Dimension; |
|
|
|
import java.awt.Dimension; |
|
|
|
import java.awt.Graphics; |
|
|
|
import java.awt.Graphics; |
|
|
|
import java.awt.Graphics2D; |
|
|
|
|
|
|
|
import java.awt.GridLayout; |
|
|
|
|
|
|
|
import java.awt.LayoutManager; |
|
|
|
|
|
|
|
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; |
|
|
@ -34,7 +34,9 @@ import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
public class UIButtonGroup<T> extends JPanel implements GlobalNameObserver, UIObserver { |
|
|
|
import static com.fine.swing.ui.layout.Layouts.cell; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class UIButtonGroup<T> extends Column implements GlobalNameObserver, UIObserver { |
|
|
|
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; |
|
|
@ -46,7 +48,6 @@ public class UIButtonGroup<T> extends JPanel implements GlobalNameObserver, UIOb |
|
|
|
private String buttonGroupName = StringUtils.EMPTY; |
|
|
|
private String buttonGroupName = StringUtils.EMPTY; |
|
|
|
private boolean isToolBarComponent = false; |
|
|
|
private boolean isToolBarComponent = false; |
|
|
|
private boolean isClick; |
|
|
|
private boolean isClick; |
|
|
|
protected int totalButtonSize = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private UIObserverListener uiObserverListener; |
|
|
|
private UIObserverListener uiObserverListener; |
|
|
|
private boolean autoFireStateChanged = true; |
|
|
|
private boolean autoFireStateChanged = true; |
|
|
@ -67,10 +68,7 @@ public class UIButtonGroup<T> extends JPanel implements GlobalNameObserver, UIOb |
|
|
|
if (!ArrayUtils.isEmpty(objects) && iconArray.length == objects.length) { |
|
|
|
if (!ArrayUtils.isEmpty(objects) && iconArray.length == objects.length) { |
|
|
|
this.objectList = Arrays.asList(objects); |
|
|
|
this.objectList = Arrays.asList(objects); |
|
|
|
} |
|
|
|
} |
|
|
|
labelButtonList = new ArrayList<UIToggleButton>(iconArray.length); |
|
|
|
labelButtonList = new ArrayList<>(iconArray.length); |
|
|
|
totalButtonSize = iconArray.length; |
|
|
|
|
|
|
|
this.setLayout(getGridLayout(iconArray.length)); |
|
|
|
|
|
|
|
this.setBorder(getGroupBorder()); |
|
|
|
|
|
|
|
for (int i = 0; i < iconArray.length; i++) { |
|
|
|
for (int i = 0; i < iconArray.length; i++) { |
|
|
|
final int index = i; |
|
|
|
final int index = i; |
|
|
|
Icon icon = iconArray[i]; |
|
|
|
Icon icon = iconArray[i]; |
|
|
@ -96,18 +94,16 @@ public class UIButtonGroup<T> extends JPanel implements GlobalNameObserver, UIOb |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
initButton(labelButton, i); |
|
|
|
initButton(labelButton); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
initLayout(getCols()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public UIButtonGroup(Icon[][] iconArray, T[] objects) { |
|
|
|
public UIButtonGroup(Icon[][] iconArray, T[] objects) { |
|
|
|
if (!ArrayUtils.isEmpty(objects) && iconArray.length == objects.length) { |
|
|
|
if (!ArrayUtils.isEmpty(objects) && iconArray.length == objects.length) { |
|
|
|
this.objectList = Arrays.asList(objects); |
|
|
|
this.objectList = Arrays.asList(objects); |
|
|
|
} |
|
|
|
} |
|
|
|
totalButtonSize = iconArray.length; |
|
|
|
labelButtonList = new ArrayList<>(iconArray.length); |
|
|
|
labelButtonList = new ArrayList<UIToggleButton>(iconArray.length); |
|
|
|
|
|
|
|
this.setLayout(getGridLayout(iconArray.length)); |
|
|
|
|
|
|
|
this.setBorder(getGroupBorder()); |
|
|
|
|
|
|
|
for (int i = 0; i < iconArray.length; i++) { |
|
|
|
for (int i = 0; i < iconArray.length; i++) { |
|
|
|
final int index = i; |
|
|
|
final int index = i; |
|
|
|
Icon[] icon = iconArray[i]; |
|
|
|
Icon[] icon = iconArray[i]; |
|
|
@ -133,50 +129,17 @@ public class UIButtonGroup<T> extends JPanel implements GlobalNameObserver, UIOb |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
initButton(labelButton, i); |
|
|
|
initButton(labelButton); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean hasClick() { |
|
|
|
|
|
|
|
return isClick; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setClickState(boolean changeFlag) { |
|
|
|
|
|
|
|
isClick = changeFlag; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setForToolBarButtonGroup(boolean isToolBarComponent) { |
|
|
|
|
|
|
|
this.isToolBarComponent = isToolBarComponent; |
|
|
|
|
|
|
|
if (isToolBarComponent) { |
|
|
|
|
|
|
|
for (UIToggleButton uiToggleButton : labelButtonList) { |
|
|
|
|
|
|
|
uiToggleButton.set4ToolbarButton(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
repaint(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* setEnabled |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param enabled |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public void setEnabled(boolean enabled) { |
|
|
|
|
|
|
|
super.setEnabled(enabled); |
|
|
|
|
|
|
|
for (int i = 0; i < labelButtonList.size(); i++) { |
|
|
|
|
|
|
|
labelButtonList.get(i).setEnabled(enabled); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
initLayout(getCols()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public UIButtonGroup(String[] textArray, T[] objects) { |
|
|
|
public UIButtonGroup(String[] textArray, T[] objects) { |
|
|
|
if (!ArrayUtils.isEmpty(objects) && textArray.length == objects.length) { |
|
|
|
if (!ArrayUtils.isEmpty(objects) && textArray.length == objects.length) { |
|
|
|
this.objectList = Arrays.asList(objects); |
|
|
|
this.objectList = Arrays.asList(objects); |
|
|
|
} |
|
|
|
} |
|
|
|
totalButtonSize = textArray.length; |
|
|
|
|
|
|
|
currentButtonSize = textArray.length; |
|
|
|
currentButtonSize = textArray.length; |
|
|
|
labelButtonList = new ArrayList<UIToggleButton>(textArray.length); |
|
|
|
labelButtonList = new ArrayList<>(textArray.length); |
|
|
|
this.setLayout(getGridLayout(textArray.length)); |
|
|
|
|
|
|
|
this.setBorder(getGroupBorder()); |
|
|
|
|
|
|
|
for (int i = 0; i < textArray.length; i++) { |
|
|
|
for (int i = 0; i < textArray.length; i++) { |
|
|
|
final int index = i; |
|
|
|
final int index = i; |
|
|
|
final UIToggleButton labelButton = new UIToggleButton(textArray[i]) { |
|
|
|
final UIToggleButton labelButton = new UIToggleButton(textArray[i]) { |
|
|
@ -201,10 +164,94 @@ public class UIButtonGroup<T> extends JPanel implements GlobalNameObserver, UIOb |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
initButton(labelButton, i); |
|
|
|
initButton(labelButton); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
initLayout(getCols()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected int[] getCols() { |
|
|
|
|
|
|
|
return new int[]{labelButtonList.size()}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void initLayout(int[] cols) { |
|
|
|
|
|
|
|
int currentIndex = 0; |
|
|
|
|
|
|
|
for (int row = 0; row < cols.length; row++) { |
|
|
|
|
|
|
|
int col = cols[row]; |
|
|
|
|
|
|
|
Row rowContainer = new Row(); |
|
|
|
|
|
|
|
for (int j = 0; j < col; j++) { |
|
|
|
|
|
|
|
rowContainer.add(cell(labelButtonList.get(currentIndex)).weight(1.0)); |
|
|
|
|
|
|
|
currentIndex++; |
|
|
|
|
|
|
|
if (j != col - 1) { |
|
|
|
|
|
|
|
rowContainer.add(createDivider()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
add(rowContainer); |
|
|
|
|
|
|
|
if (row != cols.length - 1) { |
|
|
|
|
|
|
|
add(createDivider()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.setBorder(getGroupBorder()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Spacer createDivider() { |
|
|
|
|
|
|
|
Spacer spacer = new Spacer(1); |
|
|
|
|
|
|
|
spacer.setBorder(new LineBorder(FineUIUtils.getUIColor("defaultBorderColor", "Component.borderColor"))); |
|
|
|
|
|
|
|
return spacer; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void initButton(UIToggleButton labelButton) { |
|
|
|
|
|
|
|
labelButton.setUI(new TabButtonUI(false)); |
|
|
|
|
|
|
|
labelButton.setBorderPainted(false); |
|
|
|
|
|
|
|
adjustButton(labelButton); |
|
|
|
|
|
|
|
UIComponentUtils.setLineWrap(labelButton); |
|
|
|
|
|
|
|
labelButtonList.add(labelButton); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void adjustButton(UIToggleButton labelButton) { |
|
|
|
|
|
|
|
if (labelButton.getText().length() > TEXT_LENGTH && currentButtonSize > BUTTON_SIZE) { |
|
|
|
|
|
|
|
Dimension dimension = labelButton.getPreferredSize(); |
|
|
|
|
|
|
|
dimension.height <<= 1; |
|
|
|
|
|
|
|
labelButton.setPreferredSize(dimension); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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() { |
|
|
|
|
|
|
|
return isClick; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setClickState(boolean changeFlag) { |
|
|
|
|
|
|
|
isClick = changeFlag; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setForToolBarButtonGroup(boolean isToolBarComponent) { |
|
|
|
|
|
|
|
this.isToolBarComponent = isToolBarComponent; |
|
|
|
|
|
|
|
if (isToolBarComponent) { |
|
|
|
|
|
|
|
for (UIToggleButton uiToggleButton : labelButtonList) { |
|
|
|
|
|
|
|
uiToggleButton.set4ToolbarButton(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
repaint(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void setEnabled(boolean enabled) { |
|
|
|
|
|
|
|
super.setEnabled(enabled); |
|
|
|
|
|
|
|
labelButtonList.forEach(b -> b.setEnabled(enabled)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static class TabButtonUI extends RectangleButtonUI { |
|
|
|
private static class TabButtonUI extends RectangleButtonUI { |
|
|
|
|
|
|
|
|
|
|
|
protected int minimumWidth; |
|
|
|
protected int minimumWidth; |
|
|
@ -236,94 +283,18 @@ public class UIButtonGroup<T> extends JPanel implements GlobalNameObserver, UIOb |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setGlobalName(String name) { |
|
|
|
public void setGlobalName(String name) { |
|
|
|
buttonGroupName = name; |
|
|
|
buttonGroupName = name; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected void initButton(UIToggleButton labelButton) { |
|
|
|
|
|
|
|
initButton(labelButton, 0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void initButton(UIToggleButton labelButton, int buttonIndex) { |
|
|
|
|
|
|
|
labelButton.setUI(new TabButtonUI(false)); |
|
|
|
|
|
|
|
paintInnerBorder(labelButton, buttonIndex); |
|
|
|
|
|
|
|
adjustButton(labelButton, buttonIndex); |
|
|
|
|
|
|
|
UIComponentUtils.setLineWrap(labelButton); |
|
|
|
|
|
|
|
labelButtonList.add(labelButton); |
|
|
|
|
|
|
|
this.add(labelButton); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 绘制按钮组内边框 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param labelButton 按钮 |
|
|
|
|
|
|
|
* @param index 按钮序号 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected void paintInnerBorder(UIToggleButton labelButton, int index) { |
|
|
|
|
|
|
|
LayoutManager layout = getLayout(); |
|
|
|
|
|
|
|
int leftBorder = 0; |
|
|
|
|
|
|
|
int bottomBorder = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (layout instanceof GridLayout) { |
|
|
|
|
|
|
|
GridLayout gridLayout = (GridLayout) layout; |
|
|
|
|
|
|
|
int rows = gridLayout.getRows(); |
|
|
|
|
|
|
|
int columns = gridLayout.getColumns(); |
|
|
|
|
|
|
|
rows = getActualColumnRow(rows, columns, totalButtonSize); |
|
|
|
|
|
|
|
columns = getActualColumnRow(columns, rows, totalButtonSize); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int columnIndex = index % columns; |
|
|
|
|
|
|
|
int rowIndex = index / columns; |
|
|
|
|
|
|
|
// 非首列,绘制左边框
|
|
|
|
|
|
|
|
leftBorder = (columnIndex != 0) ? 1 : 0; |
|
|
|
|
|
|
|
// 非末行,绘制底边框
|
|
|
|
|
|
|
|
bottomBorder = (rows > 1 && rowIndex < rows - 1) ? 1 : 0; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
leftBorder = (index != 0) ? 1 : 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
labelButton.setBorderPainted((leftBorder | bottomBorder) != 0); |
|
|
|
|
|
|
|
labelButton.setBorder((leftBorder | bottomBorder) != 0 ? |
|
|
|
|
|
|
|
BorderFactory.createMatteBorder(0, leftBorder, bottomBorder, 0, UIManager.getColor("defaultBorderColor")) : |
|
|
|
|
|
|
|
null); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int getActualColumnRow(int origin, int divider, int total) { |
|
|
|
|
|
|
|
return (origin == 0 || divider == 0) ? (int) Math.ceil((double) total / divider) : origin; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void adjustButton(UIToggleButton labelButton, int index) { |
|
|
|
|
|
|
|
if (labelButton.getText().length() > TEXT_LENGTH && currentButtonSize > BUTTON_SIZE) { |
|
|
|
|
|
|
|
Dimension dimension = labelButton.getPreferredSize(); |
|
|
|
|
|
|
|
dimension.height <<= 1; |
|
|
|
|
|
|
|
labelButton.setPreferredSize(dimension); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected Border getGroupBorder() { |
|
|
|
|
|
|
|
return new FineRoundBorder(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected LayoutManager getGridLayout(int number) { |
|
|
|
|
|
|
|
return new GridLayout(0, number, 0, 0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void paint(Graphics g) { |
|
|
|
|
|
|
|
Graphics2D g2d = (Graphics2D) g; |
|
|
|
|
|
|
|
FlatUIUtils.setRenderingHints(g2d); |
|
|
|
|
|
|
|
int arc = UIManager.getInt("Button.group.arc"); |
|
|
|
|
|
|
|
g2d.clip(new RoundRectangle2D.Double(0, 0, getWidth(), getHeight(), arc, arc)); |
|
|
|
|
|
|
|
super.paint(g); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setAutoFireStateChanged(boolean autoFireStateChanged) { |
|
|
|
public void setAutoFireStateChanged(boolean autoFireStateChanged) { |
|
|
|
this.autoFireStateChanged = autoFireStateChanged; |
|
|
|
this.autoFireStateChanged = autoFireStateChanged; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* setSelectedItem |
|
|
|
* 设置选择对象 |
|
|
|
* |
|
|
|
* |
|
|
|
* @param ob |
|
|
|
* @param ob 选择对象 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setSelectedItem(T ob) { |
|
|
|
public void setSelectedItem(T ob) { |
|
|
|
if (objectList == null) { |
|
|
|
if (objectList == null) { |
|
|
@ -334,9 +305,9 @@ public class UIButtonGroup<T> extends JPanel implements GlobalNameObserver, UIOb |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* getSelectedItem |
|
|
|
* 获取选择对象 |
|
|
|
* |
|
|
|
* |
|
|
|
* @return |
|
|
|
* @return 选择对象 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public T getSelectedItem() { |
|
|
|
public T getSelectedItem() { |
|
|
|
if (selectedIndex == -1) { |
|
|
|
if (selectedIndex == -1) { |
|
|
@ -348,12 +319,18 @@ public class UIButtonGroup<T> extends JPanel implements GlobalNameObserver, UIOb |
|
|
|
/** |
|
|
|
/** |
|
|
|
* getSelectedIndex |
|
|
|
* getSelectedIndex |
|
|
|
* |
|
|
|
* |
|
|
|
* @return |
|
|
|
* @return 获取选中序号 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public int getSelectedIndex() { |
|
|
|
public int getSelectedIndex() { |
|
|
|
return selectedIndex; |
|
|
|
return selectedIndex; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 设置选中序号 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param newSelectedIndex 选中序号 |
|
|
|
|
|
|
|
* @param fireChanged 是否联动事件 |
|
|
|
|
|
|
|
*/ |
|
|
|
public void setSelectedIndex(int newSelectedIndex, boolean fireChanged) { |
|
|
|
public void setSelectedIndex(int newSelectedIndex, boolean fireChanged) { |
|
|
|
if (selectedIndex != newSelectedIndex) { |
|
|
|
if (selectedIndex != newSelectedIndex) { |
|
|
|
selectedIndex = newSelectedIndex; |
|
|
|
selectedIndex = newSelectedIndex; |
|
|
@ -369,7 +346,7 @@ public class UIButtonGroup<T> extends JPanel implements GlobalNameObserver, UIOb |
|
|
|
/** |
|
|
|
/** |
|
|
|
* setSelectedIndex |
|
|
|
* setSelectedIndex |
|
|
|
* |
|
|
|
* |
|
|
|
* @param newSelectedIndex |
|
|
|
* @param newSelectedIndex 选中序号 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setSelectedIndex(int newSelectedIndex) { |
|
|
|
public void setSelectedIndex(int newSelectedIndex) { |
|
|
|
setSelectedIndex(newSelectedIndex, false); |
|
|
|
setSelectedIndex(newSelectedIndex, false); |
|
|
@ -395,8 +372,8 @@ public class UIButtonGroup<T> extends JPanel implements GlobalNameObserver, UIOb |
|
|
|
/** |
|
|
|
/** |
|
|
|
* getButton |
|
|
|
* getButton |
|
|
|
* |
|
|
|
* |
|
|
|
* @param index |
|
|
|
* @param index 序号 |
|
|
|
* @return |
|
|
|
* @return 按钮 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public UIToggleButton getButton(int index) { |
|
|
|
public UIToggleButton getButton(int index) { |
|
|
|
return labelButtonList.get(index); |
|
|
|
return labelButtonList.get(index); |
|
|
@ -413,11 +390,8 @@ public class UIButtonGroup<T> extends JPanel implements GlobalNameObserver, UIOb |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 注册全局属性名字监听器 |
|
|
|
* 注册全局属性名字监听器 |
|
|
|
* |
|
|
|
|
|
|
|
* @param listener 观察者监听事件 |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void registerNameListener(GlobalNameListener listener) { |
|
|
|
public void registerNameListener(GlobalNameListener listener) { |
|
|
|
globalNameListener = listener; |
|
|
|
globalNameListener = listener; |
|
|
@ -425,8 +399,6 @@ public class UIButtonGroup<T> extends JPanel implements GlobalNameObserver, UIOb |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 是否响应名字监听事件 |
|
|
|
* 是否响应名字监听事件 |
|
|
|
* |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean shouldResponseNameListener() { |
|
|
|
public boolean shouldResponseNameListener() { |
|
|
|
return true; |
|
|
|
return true; |
|
|
@ -442,76 +414,41 @@ public class UIButtonGroup<T> extends JPanel implements GlobalNameObserver, UIOb |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @param l |
|
|
|
* @param l 监听器 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void addChangeListener(ChangeListener l) { |
|
|
|
public void addChangeListener(ChangeListener l) { |
|
|
|
listenerList.add(ChangeListener.class, l); |
|
|
|
listenerList.add(ChangeListener.class, l); |
|
|
|
for (int i = 0; i < labelButtonList.size(); i++) { |
|
|
|
labelButtonList.forEach(b -> b.addChangeListener(l)); |
|
|
|
labelButtonList.get(i).addChangeListener(l); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @param l |
|
|
|
* @param l 监听器 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void removeChangeListener(ChangeListener l) { |
|
|
|
public void removeChangeListener(ChangeListener l) { |
|
|
|
listenerList.remove(ChangeListener.class, l); |
|
|
|
listenerList.remove(ChangeListener.class, l); |
|
|
|
for (int i = 0; i < labelButtonList.size(); i++) { |
|
|
|
labelButtonList.forEach(b -> b.removeChangeListener(l)); |
|
|
|
labelButtonList.get(i).removeChangeListener(l); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @param l |
|
|
|
* @param l 监听器 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void addActionListener(ActionListener l) { |
|
|
|
public void addActionListener(ActionListener l) { |
|
|
|
for (int i = 0; i < labelButtonList.size(); i++) { |
|
|
|
labelButtonList.forEach(b -> b.addActionListener(l)); |
|
|
|
labelButtonList.get(i).addActionListener(l); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @param l |
|
|
|
* @param l 监听器 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void removeActionListener(ActionListener l) { |
|
|
|
public void removeActionListener(ActionListener l) { |
|
|
|
for (int i = 0; i < labelButtonList.size(); i++) { |
|
|
|
labelButtonList.forEach(b -> b.removeActionListener(l)); |
|
|
|
labelButtonList.get(i).removeActionListener(l); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* populate |
|
|
|
* populate 渲染 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void populateBean() { |
|
|
|
public void populateBean() { |
|
|
|
fireStateChanged(); |
|
|
|
fireStateChanged(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* main |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param args |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static void main(String... args) { |
|
|
|
|
|
|
|
// JFrame jf = new JFrame("test");
|
|
|
|
|
|
|
|
// jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
|
|
|
|
|
// JPanel content = (JPanel) jf.getContentPane();
|
|
|
|
|
|
|
|
// content.setLayout(new BorderLayout());
|
|
|
|
|
|
|
|
// Icon[] a1 = {BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_left_normal.png"), BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_center_normal.png"),
|
|
|
|
|
|
|
|
// BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_right_normal.png")};
|
|
|
|
|
|
|
|
// Integer[] a2 = new Integer[]{Constants.LEFT, Constants.CENTER, Constants.RIGHT};
|
|
|
|
|
|
|
|
// UIButtonGroup<Integer> bb = new UIButtonGroup<Integer>(a1, a2);
|
|
|
|
|
|
|
|
// bb.setBounds(20, 20, bb.getPreferredSize().width, bb.getPreferredSize().height);
|
|
|
|
|
|
|
|
// bb.setSelectedIndex(0);
|
|
|
|
|
|
|
|
// bb.setEnabled(false);
|
|
|
|
|
|
|
|
// content.add(bb);
|
|
|
|
|
|
|
|
// GUICoreUtils.centerWindow(jf);
|
|
|
|
|
|
|
|
// jf.setSize(400, 400);
|
|
|
|
|
|
|
|
// jf.setVisible(true);
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |