|
|
|
@ -6,6 +6,7 @@ import com.fr.design.gui.ibutton.UIRadioButton;
|
|
|
|
|
import com.fr.design.gui.ilable.UILabel; |
|
|
|
|
import com.fr.design.layout.TableLayout; |
|
|
|
|
import com.fr.design.layout.TableLayoutHelper; |
|
|
|
|
import com.fr.general.data.index.Index; |
|
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
|
|
|
|
|
|
import javax.swing.*; |
|
|
|
@ -19,7 +20,7 @@ import java.util.List;
|
|
|
|
|
*/ |
|
|
|
|
public class MobileRadioGroupPane extends BasicBeanPane<MobileFitAttrState>{ |
|
|
|
|
|
|
|
|
|
private List<UIRadioButton> radioButtons = new ArrayList<UIRadioButton>(); |
|
|
|
|
private List<IndexRadioButton> radioButtons = new ArrayList<IndexRadioButton>(); |
|
|
|
|
|
|
|
|
|
public MobileRadioGroupPane(String title) { |
|
|
|
|
initComponents(title); |
|
|
|
@ -30,26 +31,33 @@ public class MobileRadioGroupPane extends BasicBeanPane<MobileFitAttrState>{
|
|
|
|
|
double[] rowSize = {p}; |
|
|
|
|
double[] columnSize = {p, p, p, p, p, p}; |
|
|
|
|
|
|
|
|
|
UIRadioButton defaultRadio = new UIRadioButton(MobileFitAttrState.DEFAULT.description()); |
|
|
|
|
IndexRadioButton defaultRadio = new IndexRadioButton(MobileFitAttrState.DEFAULT.description(), MobileFitAttrState.DEFAULT); |
|
|
|
|
defaultRadio.setSelected(true); |
|
|
|
|
UIRadioButton horizonRadio = new UIRadioButton(MobileFitAttrState.HORIZONTAL.description()); |
|
|
|
|
UIRadioButton verticalRadio = new UIRadioButton(MobileFitAttrState.VERTICAL.description()); |
|
|
|
|
UIRadioButton bidirectionalRadio = new UIRadioButton(MobileFitAttrState.BIDIRECTIONAL.description()); |
|
|
|
|
UIRadioButton notFitRadio = new UIRadioButton(MobileFitAttrState.NONE.description()); |
|
|
|
|
IndexRadioButton horizonRadio = new IndexRadioButton(MobileFitAttrState.HORIZONTAL.description(), MobileFitAttrState.HORIZONTAL); |
|
|
|
|
IndexRadioButton verticalRadio = new IndexRadioButton(MobileFitAttrState.VERTICAL.description(), MobileFitAttrState.VERTICAL); |
|
|
|
|
IndexRadioButton bidirectionalRadio = new IndexRadioButton(MobileFitAttrState.BIDIRECTIONAL.description(), MobileFitAttrState.BIDIRECTIONAL); |
|
|
|
|
IndexRadioButton notFitRadio = new IndexRadioButton(MobileFitAttrState.NONE.description(), MobileFitAttrState.NONE); |
|
|
|
|
|
|
|
|
|
addToButtonGroup(defaultRadio, horizonRadio, verticalRadio, notFitRadio, bidirectionalRadio); |
|
|
|
|
|
|
|
|
|
Component[][] components = new Component[][]{ |
|
|
|
|
new Component[]{new UILabel(title), defaultRadio, horizonRadio, verticalRadio, notFitRadio, bidirectionalRadio} |
|
|
|
|
new Component[] { |
|
|
|
|
new UILabel(title), |
|
|
|
|
defaultRadio, |
|
|
|
|
horizonRadio, |
|
|
|
|
verticalRadio, |
|
|
|
|
bidirectionalRadio, |
|
|
|
|
notFitRadio |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
JPanel fitOpsPane = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); |
|
|
|
|
fitOpsPane.setBorder(BorderFactory.createEmptyBorder(10, 13, 10, 10)); |
|
|
|
|
this.add(fitOpsPane); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void addToButtonGroup(UIRadioButton... radios) { |
|
|
|
|
private void addToButtonGroup(IndexRadioButton... radios) { |
|
|
|
|
ButtonGroup buttonGroup = new ButtonGroup(); |
|
|
|
|
for (UIRadioButton radio : radios) { |
|
|
|
|
for (IndexRadioButton radio : radios) { |
|
|
|
|
radioButtons.add(radio); |
|
|
|
|
buttonGroup.add(radio); |
|
|
|
|
} |
|
|
|
@ -59,7 +67,7 @@ public class MobileRadioGroupPane extends BasicBeanPane<MobileFitAttrState>{
|
|
|
|
|
* 设置按钮状态 |
|
|
|
|
*/ |
|
|
|
|
public void setEnabled(boolean enabled) { |
|
|
|
|
for (UIRadioButton radioButton : radioButtons) { |
|
|
|
|
for (IndexRadioButton radioButton : radioButtons) { |
|
|
|
|
radioButton.setEnabled(enabled); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -72,7 +80,7 @@ public class MobileRadioGroupPane extends BasicBeanPane<MobileFitAttrState>{
|
|
|
|
|
public int getSelectRadioIndex() { |
|
|
|
|
for (int i = 0, len = radioButtons.size(); i < len; i++) { |
|
|
|
|
if (radioButtons.get(i).isSelected()) { |
|
|
|
|
return i; |
|
|
|
|
return radioButtons.get(i).getRadioButtonIndex(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -87,15 +95,18 @@ public class MobileRadioGroupPane extends BasicBeanPane<MobileFitAttrState>{
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
UIRadioButton button = radioButtons.get(index); |
|
|
|
|
button.setSelected(true); |
|
|
|
|
for (IndexRadioButton radioButton : this.radioButtons) { |
|
|
|
|
if (radioButton.getRadioButtonIndex() == index) { |
|
|
|
|
radioButton.setSelected(true); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 给所有的按钮加上监听 |
|
|
|
|
*/ |
|
|
|
|
public void addActionListener(ActionListener actionListener) { |
|
|
|
|
for (UIRadioButton radioButton : radioButtons) { |
|
|
|
|
for (IndexRadioButton radioButton : radioButtons) { |
|
|
|
|
radioButton.addActionListener(actionListener); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -116,3 +127,24 @@ public class MobileRadioGroupPane extends BasicBeanPane<MobileFitAttrState>{
|
|
|
|
|
return StringUtils.EMPTY; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* created by fanglei on 2017/1/16 |
|
|
|
|
* 不再用radioButtonGroup的数组下标作为index,而是给每个按钮传入MobileFitAttrState的枚举值 |
|
|
|
|
*/ |
|
|
|
|
class IndexRadioButton extends UIRadioButton { |
|
|
|
|
private int index; |
|
|
|
|
|
|
|
|
|
IndexRadioButton(String text, MobileFitAttrState mobileFitAttrState) { |
|
|
|
|
super(text); |
|
|
|
|
this.index = mobileFitAttrState.getState(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public int getRadioButtonIndex() { |
|
|
|
|
return this.index; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setRadioButtonIndex(int index) { |
|
|
|
|
this.index = index; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|