|
|
|
@ -3,13 +3,13 @@ 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.utils.FineUIScale; |
|
|
|
|
import com.fine.theme.utils.FineUIUtils; |
|
|
|
|
import com.fr.design.event.GlobalNameListener; |
|
|
|
|
import com.fr.design.event.GlobalNameObserver; |
|
|
|
|
import com.fr.design.event.UIObserver; |
|
|
|
|
import com.fr.design.event.UIObserverListener; |
|
|
|
|
import com.fr.design.utils.gui.UIComponentUtils; |
|
|
|
|
import com.fr.stable.ArrayUtils; |
|
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
|
|
|
|
|
@ -17,7 +17,6 @@ import javax.swing.Icon;
|
|
|
|
|
import javax.swing.border.LineBorder; |
|
|
|
|
import javax.swing.event.ChangeEvent; |
|
|
|
|
import javax.swing.event.ChangeListener; |
|
|
|
|
import java.awt.Dimension; |
|
|
|
|
import java.awt.event.ActionListener; |
|
|
|
|
import java.awt.event.MouseAdapter; |
|
|
|
|
import java.awt.event.MouseEvent; |
|
|
|
@ -29,19 +28,24 @@ import java.util.List;
|
|
|
|
|
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; |
|
|
|
|
import static com.fine.theme.utils.FineClientProperties.BUTTON_GROUP_POSITION; |
|
|
|
|
import static com.fine.theme.utils.FineClientProperties.GROUP_BUTTON_POSITION_INNER; |
|
|
|
|
import static com.fine.theme.utils.FineClientProperties.GROUP_BUTTON_POSITION_LEFT; |
|
|
|
|
import static com.fine.theme.utils.FineClientProperties.GROUP_BUTTON_POSITION_LEFT_BOTTOM; |
|
|
|
|
import static com.fine.theme.utils.FineClientProperties.GROUP_BUTTON_POSITION_LEFT_TOP; |
|
|
|
|
import static com.fine.theme.utils.FineClientProperties.GROUP_BUTTON_POSITION_RIGHT; |
|
|
|
|
import static com.fine.theme.utils.FineClientProperties.GROUP_BUTTON_POSITION_RIGHT_BOTTOM; |
|
|
|
|
import static com.fine.theme.utils.FineClientProperties.GROUP_BUTTON_POSITION_RIGHT_TOP; |
|
|
|
|
|
|
|
|
|
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 int TEXT_LENGTH = 3; |
|
|
|
|
private static final int BUTTON_SIZE = 2; |
|
|
|
|
private int currentButtonSize = 0; |
|
|
|
|
protected List<UIToggleButton> labelButtonList; |
|
|
|
|
protected int totalButtonSize; |
|
|
|
|
protected int selectedIndex = -1; |
|
|
|
|
private List<T> objectList;// 起到一个render的作用
|
|
|
|
|
private GlobalNameListener globalNameListener = null; |
|
|
|
|
private String buttonGroupName = StringUtils.EMPTY; |
|
|
|
|
private boolean isToolBarComponent = false; |
|
|
|
|
private boolean isClick; |
|
|
|
|
|
|
|
|
|
private UIObserverListener uiObserverListener; |
|
|
|
@ -64,6 +68,7 @@ public class UIButtonGroup<T> extends Column implements GlobalNameObserver, UIOb
|
|
|
|
|
this.objectList = Arrays.asList(objects); |
|
|
|
|
} |
|
|
|
|
labelButtonList = new ArrayList<>(iconArray.length); |
|
|
|
|
totalButtonSize = iconArray.length; |
|
|
|
|
for (int i = 0; i < iconArray.length; i++) { |
|
|
|
|
final int index = i; |
|
|
|
|
Icon icon = iconArray[i]; |
|
|
|
@ -89,7 +94,7 @@ public class UIButtonGroup<T> extends Column implements GlobalNameObserver, UIOb
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
initButton(labelButton); |
|
|
|
|
initButton(labelButton, index); |
|
|
|
|
} |
|
|
|
|
initLayout(getCols()); |
|
|
|
|
} |
|
|
|
@ -98,6 +103,7 @@ public class UIButtonGroup<T> extends Column implements GlobalNameObserver, UIOb
|
|
|
|
|
if (!ArrayUtils.isEmpty(objects) && iconArray.length == objects.length) { |
|
|
|
|
this.objectList = Arrays.asList(objects); |
|
|
|
|
} |
|
|
|
|
totalButtonSize = iconArray.length; |
|
|
|
|
labelButtonList = new ArrayList<>(iconArray.length); |
|
|
|
|
for (int i = 0; i < iconArray.length; i++) { |
|
|
|
|
final int index = i; |
|
|
|
@ -124,7 +130,7 @@ public class UIButtonGroup<T> extends Column implements GlobalNameObserver, UIOb
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
initButton(labelButton); |
|
|
|
|
initButton(labelButton, index); |
|
|
|
|
} |
|
|
|
|
initLayout(getCols()); |
|
|
|
|
} |
|
|
|
@ -133,8 +139,8 @@ public class UIButtonGroup<T> extends Column implements GlobalNameObserver, UIOb
|
|
|
|
|
if (!ArrayUtils.isEmpty(objects) && textArray.length == objects.length) { |
|
|
|
|
this.objectList = Arrays.asList(objects); |
|
|
|
|
} |
|
|
|
|
currentButtonSize = textArray.length; |
|
|
|
|
labelButtonList = new ArrayList<>(textArray.length); |
|
|
|
|
totalButtonSize = textArray.length; |
|
|
|
|
for (int i = 0; i < textArray.length; i++) { |
|
|
|
|
final int index = i; |
|
|
|
|
final UIToggleButton labelButton = new UIToggleButton(textArray[i]) { |
|
|
|
@ -159,7 +165,7 @@ public class UIButtonGroup<T> extends Column implements GlobalNameObserver, UIOb
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
initButton(labelButton); |
|
|
|
|
initButton(labelButton, index); |
|
|
|
|
} |
|
|
|
|
initLayout(getCols()); |
|
|
|
|
} |
|
|
|
@ -169,8 +175,13 @@ public class UIButtonGroup<T> extends Column implements GlobalNameObserver, UIOb
|
|
|
|
|
return UI_CLASS_ID; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 计算按钮组的列布局 |
|
|
|
|
* |
|
|
|
|
* @return 列布局,形如[5,3] 即为两行,首行5个组件,次行3个组件 |
|
|
|
|
*/ |
|
|
|
|
protected int[] getCols() { |
|
|
|
|
return new int[]{labelButtonList.size()}; |
|
|
|
|
return new int[]{totalButtonSize}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected void initLayout(int[] cols) { |
|
|
|
@ -198,21 +209,41 @@ public class UIButtonGroup<T> extends Column implements GlobalNameObserver, UIOb
|
|
|
|
|
return spacer; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected void initButton(UIToggleButton labelButton) { |
|
|
|
|
protected void initButton(UIToggleButton labelButton, int index) { |
|
|
|
|
labelButton.setBorder(new FineRoundBorder()); |
|
|
|
|
labelButton.setBorderPainted(false); |
|
|
|
|
labelButton.putClientProperty(BUTTON_TYPE, BUTTON_TYPE_GROUP); |
|
|
|
|
adjustButton(labelButton); |
|
|
|
|
UIComponentUtils.setLineWrap(labelButton); |
|
|
|
|
labelButton.putClientProperty(BUTTON_GROUP_POSITION, getGroupButtonPosition(index)); |
|
|
|
|
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); |
|
|
|
|
/** |
|
|
|
|
* 计算按钮位于整个按钮组件中的位置 |
|
|
|
|
* @param index 按钮序号 |
|
|
|
|
* @return 按钮位置,详见 {@link com.fine.theme.utils.FineClientProperties} |
|
|
|
|
*/ |
|
|
|
|
protected int getGroupButtonPosition(int index) { |
|
|
|
|
int[] cols = getCols(); |
|
|
|
|
if (cols.length == 1) { |
|
|
|
|
if (index == 0) { |
|
|
|
|
return GROUP_BUTTON_POSITION_LEFT; |
|
|
|
|
} else if (index == totalButtonSize - 1) { |
|
|
|
|
return GROUP_BUTTON_POSITION_RIGHT; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
int rightTopCorner = cols[0] - 1; |
|
|
|
|
int leftBottomCorner = totalButtonSize - cols[cols.length - 1]; |
|
|
|
|
if (index == 0) { |
|
|
|
|
return GROUP_BUTTON_POSITION_LEFT_TOP; |
|
|
|
|
} else if (index == totalButtonSize - 1) { |
|
|
|
|
return GROUP_BUTTON_POSITION_RIGHT_BOTTOM; |
|
|
|
|
} else if (index == rightTopCorner) { |
|
|
|
|
return GROUP_BUTTON_POSITION_RIGHT_TOP; |
|
|
|
|
} else if (index == leftBottomCorner) { |
|
|
|
|
return GROUP_BUTTON_POSITION_LEFT_BOTTOM; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return GROUP_BUTTON_POSITION_INNER; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public boolean hasClick() { |
|
|
|
@ -224,7 +255,6 @@ public class UIButtonGroup<T> extends Column implements GlobalNameObserver, UIOb
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setForToolBarButtonGroup(boolean isToolBarComponent) { |
|
|
|
|
this.isToolBarComponent = isToolBarComponent; |
|
|
|
|
if (isToolBarComponent) { |
|
|
|
|
for (UIToggleButton uiToggleButton : labelButtonList) { |
|
|
|
|
uiToggleButton.set4ToolbarButton(); |
|
|
|
|