Browse Source

Merge pull request #659 in BA/design from ~FANGLEI/design:dev to dev

* commit 'ecdb72d4f4aa276443b18bb52e63d206ad0dbb2f':
  不再独自创建带index的选项按钮,而是继承自UIRadioButton
  RadioButton的构造函数的第二个参数修改为MobileFitAttrState
  表单的双向自适应和不自适应顺序忘记改了
  修改了双向自适应和不自适应按钮的顺序
master
superman 8 years ago
parent
commit
9548523e0a
  1. 60
      designer/src/com/fr/design/report/mobile/MobileRadioGroupPane.java
  2. 14
      designer_form/src/com/fr/design/designer/properties/mobile/MobileFitAlignmentItems.java

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

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

14
designer_form/src/com/fr/design/designer/properties/mobile/MobileFitAlignmentItems.java

@ -9,12 +9,14 @@ public class MobileFitAlignmentItems implements ItemProvider {
private static Item[] VALUE_ITEMS; private static Item[] VALUE_ITEMS;
static { static {
MobileFitAttrState[] allStates = MobileFitAttrState.values(); // 此处不能循环根据MobileFitAttrState的枚举顺序创建items,否则不自适应选项就会跑到双向自适应选项前面。
int len = allStates.length; VALUE_ITEMS = new Item[]{
VALUE_ITEMS = new Item[len]; new Item(MobileFitAttrState.DEFAULT.description(), MobileFitAttrState.DEFAULT),
for (int i = 0; i < len ; i++) { new Item(MobileFitAttrState.HORIZONTAL.description(), MobileFitAttrState.HORIZONTAL),
VALUE_ITEMS[i] = new Item(allStates[i].description(), allStates[i]); new Item(MobileFitAttrState.VERTICAL.description(), MobileFitAttrState.VERTICAL),
} new Item(MobileFitAttrState.BIDIRECTIONAL.description(), MobileFitAttrState.BIDIRECTIONAL),
new Item(MobileFitAttrState.NONE.description(), MobileFitAttrState.NONE)
};
} }
@Override @Override

Loading…
Cancel
Save