Browse Source

修改了双向自适应和不自适应按钮的顺序

master
fanglei 8 years ago
parent
commit
768035300a
  1. 78
      designer/src/com/fr/design/report/mobile/MobileRadioGroupPane.java

78
designer/src/com/fr/design/report/mobile/MobileRadioGroupPane.java

@ -19,7 +19,7 @@ import java.util.List;
*/
public class MobileRadioGroupPane extends BasicBeanPane<MobileFitAttrState>{
private List<UIRadioButton> radioButtons = new ArrayList<UIRadioButton>();
private List<RadioButton> radioButtons = new ArrayList<RadioButton>();
public MobileRadioGroupPane(String title) {
initComponents(title);
@ -30,28 +30,35 @@ public class MobileRadioGroupPane extends BasicBeanPane<MobileFitAttrState>{
double[] rowSize = {p};
double[] columnSize = {p, p, p, p, p, p};
UIRadioButton defaultRadio = new UIRadioButton(MobileFitAttrState.DEFAULT.description());
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());
RadioButton defaultRadio = new RadioButton(new UIRadioButton(MobileFitAttrState.DEFAULT.description()), MobileFitAttrState.DEFAULT.getState());
defaultRadio.getRadioButton().setSelected(true);
RadioButton horizonRadio = new RadioButton(new UIRadioButton(MobileFitAttrState.HORIZONTAL.description()), MobileFitAttrState.HORIZONTAL.getState());
RadioButton verticalRadio = new RadioButton(new UIRadioButton(MobileFitAttrState.VERTICAL.description()), MobileFitAttrState.VERTICAL.getState());
RadioButton bidirectionalRadio = new RadioButton(new UIRadioButton(MobileFitAttrState.BIDIRECTIONAL.description()), MobileFitAttrState.BIDIRECTIONAL.getState());
RadioButton notFitRadio = new RadioButton(new UIRadioButton(MobileFitAttrState.NONE.description()), MobileFitAttrState.NONE.getState());
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.getRadioButton(),
horizonRadio.getRadioButton(),
verticalRadio.getRadioButton(),
bidirectionalRadio.getRadioButton(),
notFitRadio.getRadioButton()
}
};
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(RadioButton... radios) {
ButtonGroup buttonGroup = new ButtonGroup();
for (UIRadioButton radio : radios) {
for (RadioButton radio : radios) {
radioButtons.add(radio);
buttonGroup.add(radio);
buttonGroup.add(radio.getRadioButton());
}
}
@ -59,8 +66,8 @@ public class MobileRadioGroupPane extends BasicBeanPane<MobileFitAttrState>{
* 设置按钮状态
*/
public void setEnabled(boolean enabled) {
for (UIRadioButton radioButton : radioButtons) {
radioButton.setEnabled(enabled);
for (RadioButton radioButton : radioButtons) {
radioButton.getRadioButton().setEnabled(enabled);
}
}
@ -71,8 +78,8 @@ 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;
if (radioButtons.get(i).getRadioButton().isSelected()) {
return radioButtons.get(i).getRadioButtonIndex();
}
}
@ -87,16 +94,19 @@ public class MobileRadioGroupPane extends BasicBeanPane<MobileFitAttrState>{
return;
}
UIRadioButton button = radioButtons.get(index);
button.setSelected(true);
for (RadioButton radioButton : this.radioButtons) {
if (radioButton.getRadioButtonIndex() == index) {
radioButton.getRadioButton().setSelected(true);
}
}
}
/**
* 给所有的按钮加上监听
*/
public void addActionListener(ActionListener actionListener) {
for (UIRadioButton radioButton : radioButtons) {
radioButton.addActionListener(actionListener);
for (RadioButton radioButton : radioButtons) {
radioButton.getRadioButton().addActionListener(actionListener);
}
}
@ -116,3 +126,33 @@ public class MobileRadioGroupPane extends BasicBeanPane<MobileFitAttrState>{
return StringUtils.EMPTY;
}
}
/**
* created by fanglei on 2017/1/16
* 不再用radioButtonGroup的数组下标作为index而是给每个按钮传入MobileFitAttrState的枚举值
*/
class RadioButton {
private UIRadioButton radioButton;
private int index;
RadioButton(UIRadioButton radioButton, int index) {
this.radioButton = radioButton;
this.index = index;
}
public UIRadioButton getRadioButton() {
return this.radioButton;
}
public void setUIReadioButton(UIRadioButton radioButton) {
this.radioButton = radioButton;
}
public int getRadioButtonIndex() {
return this.index;
}
public void setRadioButtonIndex(int index) {
this.index = index;
}
}

Loading…
Cancel
Save