forked from fanruan/design
Browse Source
Merge in DESIGN/design from ~FANGLEI/design:feature/x to feature/x * commit '46f00406e9a866479003af3de985249164b9a4e2': CHART-22531 多分类轴分层设置标签样式—设计器面板feature/x
fanglei
3 years ago
8 changed files with 563 additions and 38 deletions
@ -0,0 +1,158 @@ |
|||||||
|
package com.fr.van.chart.designer.style.axis; |
||||||
|
|
||||||
|
import com.fr.base.BaseFormula; |
||||||
|
import com.fr.chart.base.TextAttr; |
||||||
|
import com.fr.design.beans.BasicBeanPane; |
||||||
|
import com.fr.design.gui.frpane.UINumberDragPane; |
||||||
|
import com.fr.design.gui.ibutton.UIButtonGroup; |
||||||
|
import com.fr.design.gui.ilable.UILabel; |
||||||
|
import com.fr.design.gui.itextfield.UITextField; |
||||||
|
import com.fr.design.i18n.Toolkit; |
||||||
|
import com.fr.design.layout.TableLayout; |
||||||
|
import com.fr.design.mainframe.chart.gui.style.ChartTextAttrPane; |
||||||
|
import com.fr.design.mainframe.chart.gui.style.ChartTextAttrPaneWithThemeStyle; |
||||||
|
import com.fr.design.mainframe.chart.mode.ChartEditContext; |
||||||
|
import com.fr.design.utils.gui.UIComponentUtils; |
||||||
|
import com.fr.design.widget.FRWidgetFactory; |
||||||
|
import com.fr.plugin.chart.VanChartAxisCategoryStyle; |
||||||
|
import com.fr.van.chart.designer.TableLayout4VanChartHelper; |
||||||
|
import com.fr.van.chart.designer.style.axis.component.AxisLabelDisplayComboBox; |
||||||
|
|
||||||
|
import javax.swing.JPanel; |
||||||
|
import java.awt.BorderLayout; |
||||||
|
import java.awt.Component; |
||||||
|
import java.awt.Dimension; |
||||||
|
import java.awt.event.ActionEvent; |
||||||
|
import java.awt.event.ActionListener; |
||||||
|
|
||||||
|
public class VanChartAxisStyleSettingPane extends BasicBeanPane<VanChartAxisCategoryStyle> { |
||||||
|
private static final double ROTATION_MAX = 90.0; |
||||||
|
|
||||||
|
private AxisLabelDisplayComboBox labelDisplayComboBox; |
||||||
|
private ChartTextAttrPane labelTextAttrPane; |
||||||
|
private UINumberDragPane labelTextRotation; |
||||||
|
private UIButtonGroup<Integer> labelGapStyle; |
||||||
|
private UITextField labelGapValue; |
||||||
|
private JPanel labelGapPane; |
||||||
|
private JPanel labelGapValuePane; |
||||||
|
private JPanel contentPane; |
||||||
|
|
||||||
|
public VanChartAxisStyleSettingPane() { |
||||||
|
double p = TableLayout.PREFERRED; |
||||||
|
double f = TableLayout.FILL; |
||||||
|
double s = TableLayout4VanChartHelper.SECOND_EDIT_AREA_WIDTH; |
||||||
|
double[] column = {f, s}; |
||||||
|
double[] row = {p, p, p}; |
||||||
|
|
||||||
|
labelDisplayComboBox = new AxisLabelDisplayComboBox(); |
||||||
|
JPanel labelDisplayPane = TableLayout4VanChartHelper.createGapTableLayoutPane(Toolkit.i18nText("Fine-Design_Chart_Axis_Label_Show"), labelDisplayComboBox, TableLayout4VanChartHelper.SECOND_EDIT_AREA_WIDTH); |
||||||
|
labelTextAttrPane = getChartTextAttrPane(); |
||||||
|
labelTextRotation = new UINumberDragPane(-ROTATION_MAX, ROTATION_MAX); |
||||||
|
labelGapStyle = new UIButtonGroup<>(new String[]{Toolkit.i18nText("Fine-Design_Chart_Automatic"), Toolkit.i18nText("Fine-Design_Chart_Fixed")}); |
||||||
|
labelGapValue = new UITextField(); |
||||||
|
labelGapPane = createLabelGapPane(row, column); |
||||||
|
|
||||||
|
this.setLayout(new BorderLayout()); |
||||||
|
contentPane = new JPanel(new BorderLayout()); |
||||||
|
contentPane.add(labelDisplayPane, BorderLayout.NORTH); |
||||||
|
contentPane.add(labelTextAttrPane, BorderLayout.CENTER); |
||||||
|
contentPane.add(labelGapPane, BorderLayout.SOUTH); |
||||||
|
this.add(contentPane, BorderLayout.NORTH); |
||||||
|
initListner(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Dimension getPreferredSize() { |
||||||
|
Dimension defaultSize = super.getPreferredSize(); |
||||||
|
return new Dimension(defaultSize.width, contentPane.getPreferredSize().height); |
||||||
|
} |
||||||
|
|
||||||
|
private void initListner() { |
||||||
|
labelDisplayComboBox.addActionListener(new ActionListener() { |
||||||
|
@Override |
||||||
|
public void actionPerformed(ActionEvent e) { |
||||||
|
labelGapPane.setVisible(labelDisplayComboBox.getSelectedIndex() == 0); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
labelGapStyle.addActionListener(new ActionListener() { |
||||||
|
@Override |
||||||
|
public void actionPerformed(ActionEvent e) { |
||||||
|
labelGapValuePane.setVisible(labelGapStyle.getSelectedIndex() == 1); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void populateBean(VanChartAxisCategoryStyle style) { |
||||||
|
labelDisplayComboBox.populateBean(style.getLabelDisplay()); |
||||||
|
labelTextAttrPane.populate(style.getTextAttr()); |
||||||
|
labelTextRotation.populateBean((double) style.getTextAttr().getRotation()); |
||||||
|
labelGapStyle.setSelectedIndex(style.isAutoLabelGap() ? 0 : 1); |
||||||
|
labelGapValue.setText(style.getLabelIntervalNumber().getContent()); |
||||||
|
|
||||||
|
labelGapPane.setVisible(labelDisplayComboBox.getSelectedIndex() == 0); |
||||||
|
labelGapValuePane.setVisible(labelGapStyle.getSelectedIndex() == 1); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public VanChartAxisCategoryStyle updateBean() { |
||||||
|
VanChartAxisCategoryStyle style = new VanChartAxisCategoryStyle(); |
||||||
|
style.setLabelDisplay(labelDisplayComboBox.updateBean()); |
||||||
|
TextAttr textAttr = style.getTextAttr(); |
||||||
|
labelTextAttrPane.update(textAttr); |
||||||
|
textAttr.setRotation(labelTextRotation.updateBean().intValue()); |
||||||
|
style.setTextAttr(textAttr); |
||||||
|
style.setAutoLabelGap(labelGapStyle.getSelectedIndex() == 0); |
||||||
|
if (style.isAutoLabelGap()) { |
||||||
|
style.setLabelIntervalNumber(BaseFormula.createFormulaBuilder().build("0")); |
||||||
|
} else { |
||||||
|
style.setLabelIntervalNumber(BaseFormula.createFormulaBuilder().build(labelGapValue.getText())); |
||||||
|
} |
||||||
|
return style; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected String title4PopupWindow() { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
private JPanel createLabelGapPane(double[] row, double[] col) { |
||||||
|
Component[][] gapComponents = new Component[][]{ |
||||||
|
new Component[]{null, null}, |
||||||
|
new Component[]{ |
||||||
|
FRWidgetFactory.createLineWrapLabel(Toolkit.i18nText("Fine-Design_Chart_TextRotation")), |
||||||
|
UIComponentUtils.wrapWithBorderLayoutPane(labelTextRotation) |
||||||
|
}, |
||||||
|
new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Chart_Label_Interval")), labelGapStyle} |
||||||
|
}; |
||||||
|
|
||||||
|
JPanel gapDetailPane = TableLayout4VanChartHelper.createGapTableLayoutPane(gapComponents, row, col); |
||||||
|
labelGapValuePane = TableLayout4VanChartHelper.createGapTableLayoutPane(Toolkit.i18nText(""), labelGapValue, TableLayout4VanChartHelper.SECOND_EDIT_AREA_WIDTH); |
||||||
|
|
||||||
|
JPanel panel = new JPanel(new BorderLayout()); |
||||||
|
panel.add(gapDetailPane, BorderLayout.CENTER); |
||||||
|
panel.add(labelGapValuePane, BorderLayout.SOUTH); |
||||||
|
|
||||||
|
return panel; |
||||||
|
} |
||||||
|
|
||||||
|
protected ChartTextAttrPane getChartTextAttrPane() { |
||||||
|
return ChartEditContext.supportTheme() ? new ChartTextAttrPaneWithThemeStyle() { |
||||||
|
protected double getEdithAreaWidth() { |
||||||
|
return TableLayout4VanChartHelper.SECOND_EDIT_AREA_WIDTH; |
||||||
|
} |
||||||
|
} : new ChartTextAttrPane() { |
||||||
|
@Override |
||||||
|
protected JPanel getContentPane(JPanel buttonPane) { |
||||||
|
double p = TableLayout.PREFERRED; |
||||||
|
double f = TableLayout.FILL; |
||||||
|
double e = TableLayout4VanChartHelper.SECOND_EDIT_AREA_WIDTH; |
||||||
|
double[] columnSize = {f, e}; |
||||||
|
double[] rowSize = {p, p, p}; |
||||||
|
|
||||||
|
return TableLayout4VanChartHelper.createGapTableLayoutPane(getComponents(buttonPane), rowSize, columnSize); |
||||||
|
} |
||||||
|
}; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,102 @@ |
|||||||
|
package com.fr.van.chart.designer.style.axis.component; |
||||||
|
|
||||||
|
import com.fr.design.gui.frpane.AbstractAttrNoScrollPane; |
||||||
|
import com.fr.design.gui.frpane.UIBubbleFloatPane; |
||||||
|
import com.fr.design.gui.ibutton.UIButton; |
||||||
|
import com.fr.design.gui.icheckbox.UICheckBox; |
||||||
|
import com.fr.design.i18n.Toolkit; |
||||||
|
import com.fr.plugin.chart.VanChartAxisCategoryStyle; |
||||||
|
import com.fr.stable.Constants; |
||||||
|
import com.fr.van.chart.designer.style.axis.VanChartAxisStyleSettingPane; |
||||||
|
|
||||||
|
import javax.swing.BorderFactory; |
||||||
|
import javax.swing.JPanel; |
||||||
|
import java.awt.BorderLayout; |
||||||
|
import java.awt.Dimension; |
||||||
|
import java.awt.Point; |
||||||
|
import java.awt.event.ActionEvent; |
||||||
|
import java.awt.event.ActionListener; |
||||||
|
import java.awt.event.MouseAdapter; |
||||||
|
import java.awt.event.MouseEvent; |
||||||
|
import java.util.LinkedHashMap; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
public class VanChartCategoryStylePaneWithCheckBox extends JPanel { |
||||||
|
private UICheckBox checkBox; // 复选框
|
||||||
|
private UIButton settingButton; // 设置按钮
|
||||||
|
private VanChartAxisStyleSettingPane settingPane; // 设置弹窗面板
|
||||||
|
|
||||||
|
private JPanel showOnPane; |
||||||
|
private AbstractAttrNoScrollPane parent; |
||||||
|
|
||||||
|
private String axisId; |
||||||
|
private VanChartAxisCategoryStyle axis; |
||||||
|
|
||||||
|
public VanChartCategoryStylePaneWithCheckBox(AbstractAttrNoScrollPane parent, JPanel showOnPane, String checkBoxName) { |
||||||
|
this.parent = parent; |
||||||
|
this.showOnPane = showOnPane; |
||||||
|
|
||||||
|
this.setLayout(new BorderLayout()); |
||||||
|
checkBox = new UICheckBox(checkBoxName); |
||||||
|
checkBox.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); |
||||||
|
checkBox.addActionListener(new ActionListener() { |
||||||
|
@Override |
||||||
|
public void actionPerformed(ActionEvent e) { |
||||||
|
/* 为什么需要这句话呢?因为这个checkBox是动态加上去的,没有走最上层父组件ChartStylePane的initAllListener方法, |
||||||
|
* 所以不会触发update监听,下面的bubble弹窗则是不属于ChartStylePane的单独悬浮组件,也只能这样触发update监听 |
||||||
|
*/ |
||||||
|
if(parent != null){ |
||||||
|
parent.attributeChanged(); |
||||||
|
} |
||||||
|
} |
||||||
|
}); |
||||||
|
settingButton = new UIButton(Toolkit.i18nText("Fine-Design_Chart_Axis_Style_Setting")); |
||||||
|
|
||||||
|
this.add(checkBox, BorderLayout.CENTER); |
||||||
|
this.add(settingButton, BorderLayout.EAST); |
||||||
|
|
||||||
|
initListener(); |
||||||
|
} |
||||||
|
|
||||||
|
private void initListener() { |
||||||
|
if(settingButton != null) { |
||||||
|
settingButton.addMouseListener(new MouseAdapter() { |
||||||
|
@Override |
||||||
|
public void mouseReleased(MouseEvent e) { |
||||||
|
if (settingPane == null) { |
||||||
|
settingPane = new VanChartAxisStyleSettingPane(); |
||||||
|
} |
||||||
|
|
||||||
|
Point comPoint = settingButton.getLocationOnScreen(); |
||||||
|
Point arrowPoint = new Point(comPoint.x +settingButton.getWidth() - 25, comPoint.y + settingButton.getHeight()); |
||||||
|
Dimension size = settingPane.getPreferredSize(); |
||||||
|
UIBubbleFloatPane<VanChartAxisCategoryStyle> pane = new UIBubbleFloatPane(Constants.LEFT, arrowPoint, settingPane, size.width, 216) { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void updateContentPane() { |
||||||
|
axis = settingPane.updateBean(); |
||||||
|
if(parent != null){//条件属性没有parent
|
||||||
|
parent.attributeChanged(); |
||||||
|
} |
||||||
|
} |
||||||
|
}; |
||||||
|
pane.show(showOnPane, axis); |
||||||
|
super.mouseReleased(e); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void populate(VanChartAxisCategoryStyle style, String uuid) { |
||||||
|
this.axis = style; |
||||||
|
this.axisId = uuid; |
||||||
|
checkBox.setSelected(axis.isAvailable()); |
||||||
|
} |
||||||
|
|
||||||
|
public Map<String, VanChartAxisCategoryStyle> update() { |
||||||
|
axis.setAvailable(checkBox.isSelected()); |
||||||
|
Map<String, VanChartAxisCategoryStyle> map = new LinkedHashMap<>(); |
||||||
|
map.put(axisId, axis); |
||||||
|
return map; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue