Browse Source

CHART-10225 兼容 折线类型和线宽

research/11.0
zheng 5 years ago
parent
commit
bdf6cae85e
  1. 85
      designer-chart/src/main/java/com/fr/van/chart/designer/component/LineTypeComboBox.java
  2. 99
      designer-chart/src/main/java/com/fr/van/chart/designer/component/VanChartLineTypePane.java
  3. 25
      designer-chart/src/main/java/com/fr/van/chart/designer/component/VanChartLineWidthPane.java
  4. 25
      designer-chart/src/main/java/com/fr/van/chart/scatter/component/VanChartScatterLineTypePane.java

85
designer-chart/src/main/java/com/fr/van/chart/designer/component/LineTypeComboBox.java

@ -0,0 +1,85 @@
package com.fr.van.chart.designer.component;
import com.fr.base.FRContext;
import com.fr.base.GraphHelper;
import com.fr.base.ScreenResolution;
import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.icombobox.UIComboBoxRenderer;
import com.fr.design.i18n.Toolkit;
import com.fr.general.FRFont;
import com.fr.plugin.chart.type.LineType;
import com.fr.stable.Constants;
import javax.swing.JLabel;
import javax.swing.JList;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
/**
* Created by shine on 2019/08/30.
*/
public class LineTypeComboBox extends UIComboBox {
public LineTypeComboBox(LineType[] lineType) {
super(lineType);
this.setRenderer(new CellRenderer());
}
private class CellRenderer extends UIComboBoxRenderer {
private LineType lineType;
public Component getListCellRendererComponent(
JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
JLabel comp = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
this.lineType = (LineType) value;
comp.setText(null);
return comp;
}
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2d = (Graphics2D) g;
Dimension d = getSize();
g2d.setColor(getForeground());
switch (this.lineType) {
case NONE:
FRFont font = FRContext.getDefaultValues().getFRFont();
int resolution = ScreenResolution.getScreenResolution();
Font rfont = font.applyResolutionNP(resolution);
g2d.setFont(rfont);
FontMetrics fm = GraphHelper.getFontMetrics(rfont);
GraphHelper.drawString(g2d, Toolkit.i18nText("Fine-Design_Report_None"), 4, (d.height - fm.getHeight()) / 2 + fm.getAscent());
break;
case NORMAL:
GraphHelper.drawLine(g2d, 4, d.height / 2, d.width - 8, d.height / 2);
break;
case DASH:
GraphHelper.drawLine(g2d, 4, d.height / 2, d.width - 8, d.height / 2, Constants.LINE_DASH);
break;
default:
break;
}
}
public Dimension getPreferredSize() {
return new Dimension(60, 16);
}
public Dimension getMinimumSize() {
return getPreferredSize();
}
}
}

99
designer-chart/src/main/java/com/fr/van/chart/designer/component/VanChartLineTypePane.java

@ -2,21 +2,24 @@ package com.fr.van.chart.designer.component;
import com.fr.design.dialog.BasicPane;
import com.fr.design.gui.ibutton.UIButtonGroup;
import com.fr.design.gui.icombobox.LineComboBox;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.ispinner.UISpinner;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.TableLayout;
import com.fr.design.utils.gui.UIComponentUtils;
import com.fr.design.widget.FRWidgetFactory;
import com.fr.general.ComparatorUtils;
import com.fr.plugin.chart.base.VanChartAttrLine;
import com.fr.plugin.chart.type.LineStyle;
import com.fr.stable.Constants;
import com.fr.stable.CoreConstants;
import com.fr.plugin.chart.type.LineType;
import com.fr.van.chart.designer.TableLayout4VanChartHelper;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Arrays;
/**
* line相关设置
@ -24,64 +27,99 @@ import java.awt.Component;
public class VanChartLineTypePane extends BasicPane {
private static final long serialVersionUID = -6581862503009962973L;
protected LineComboBox lineWidth;//线型
private LineTypeComboBox lineTypeComboBox;//线型
private UISpinner lineWidthSpinner;//线宽
protected UIButtonGroup<LineStyle> lineStyle;//形态
protected UIButtonGroup nullValueBreak;//空值断开
private UIButtonGroup nullValueBreak;//空值断开
public VanChartLineTypePane() {
lineWidth = new LineComboBox(CoreConstants.STRIKE_LINE_STYLE_ARRAY_4_CHART);
lineTypeComboBox = new LineTypeComboBox(new LineType[]{LineType.NONE, LineType.NORMAL, LineType.DASH});
lineWidthSpinner = new UISpinner(0.5, Integer.MAX_VALUE, 0.5, 2);
createLineStyle();
nullValueBreak = new UIButtonGroup(new String[]{com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Open"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Close")});
nullValueBreak = new UIButtonGroup(new String[]{Toolkit.i18nText("Fine-Design_Chart_Open"), Toolkit.i18nText("Fine-Design_Chart_Close")});
lineTypeComboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
checkLineWidth();
}
});
this.setLayout(new BorderLayout());
double p = TableLayout.PREFERRED;
double f = TableLayout.FILL;
this.add(createContentPane(p, f), BorderLayout.CENTER);
double e = TableLayout4VanChartHelper.EDIT_AREA_WIDTH;
Component[] lineTypeComponent = new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Chart_Line_Style")), lineTypeComboBox},
lineWidthComponent = new Component[]{
FRWidgetFactory.createLineWrapLabel(Toolkit.i18nText("Fine-Design_Chart_Line_Width")),
UIComponentUtils.wrapWithBorderLayoutPane(lineWidthSpinner)},
lineStyleComponent = new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Chart_Style_Present")), lineStyle},
nullValueBreakComponent = new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Chart_Null_Value_Break")), nullValueBreak};
Component[][] components = createContentComponent(lineTypeComponent, lineWidthComponent, lineStyleComponent, nullValueBreakComponent);
double[] row = new double[components.length];
Arrays.fill(row, p);
double[] col = {f, e};
JPanel contentPane = TableLayout4VanChartHelper.createGapTableLayoutPane(components, row, col);
this.setLayout(new BorderLayout());
this.add(contentPane, BorderLayout.CENTER);
}
private JPanel createTypeAndWidthPane() {
//todo@shinerefactor:当前兼容工作到这边,因为finekit和移动端,暂停
JPanel panel = new JPanel(new BorderLayout(0, 6));
return panel;
}
protected void createLineStyle() {
String[] textArray = new String[]{com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Normal_Line"),
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_StepLine"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_CurveLine")};
String[] textArray = new String[]{Toolkit.i18nText("Fine-Design_Chart_Normal_Line"),
Toolkit.i18nText("Fine-Design_Chart_StepLine"), Toolkit.i18nText("Fine-Design_Chart_CurveLine")};
lineStyle = new UIButtonGroup<LineStyle>(textArray, LineStyle.values());
}
protected JPanel createContentPane(double p, double f) {
double[] row = {p, p, p, p};
double e = TableLayout4VanChartHelper.EDIT_AREA_WIDTH;
double[] col = {f, e};
Component[][] components = new Component[][]{
protected Component[][] createContentComponent(Component[] lineTypeComponent, Component[] lineWidthComponent,
Component[] lineStyleComponent, Component[] nullValueBreakComponent) {
return new Component[][]{
new Component[]{null,null},
new Component[]{
FRWidgetFactory.createLineWrapLabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Line_Style")),
UIComponentUtils.wrapWithBorderLayoutPane(lineWidth)
},
new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Style_Present")),lineStyle},
new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Null_Value_Break")),nullValueBreak},
lineTypeComponent,
lineWidthComponent,
lineStyleComponent,
nullValueBreakComponent
};
}
return TableLayout4VanChartHelper.createGapTableLayoutPane(components, row, col);
private void checkLineWidth() {
if (lineWidthSpinner != null && lineTypeComboBox != null) {
lineWidthSpinner.setVisible(!ComparatorUtils.equals(lineTypeComboBox.getSelectedItem(), LineType.NONE));
}
}
public void checkLarge(boolean large){
if(large){
lineWidth.setSelectedLineStyle(Constants.LINE_NONE);
lineTypeComboBox.setSelectedItem(LineType.NONE);
}
lineWidth.setEnabled(!large);
lineTypeComboBox.setEnabled(!large);
lineStyle.setEnabled(!large);
}
protected String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Line");
return Toolkit.i18nText("Fine-Design_Chart_Line");
}
public void populate(VanChartAttrLine line) {
if (line == null) {
line = initVanChartAttrLine();
}
lineWidth.setSelectedLineStyle(line.getLineWidth());
lineTypeComboBox.setSelectedItem(line.getLineType());
lineWidthSpinner.setValue(line.getLineWidth());
lineStyle.setSelectedItem(line.getLineStyle());
nullValueBreak.setSelectedIndex(line.isNullValueBreak() ? 0 : 1);
}
@ -92,7 +130,8 @@ public class VanChartLineTypePane extends BasicPane {
public VanChartAttrLine update() {
VanChartAttrLine line = new VanChartAttrLine();
line.setLineWidth(lineWidth.getSelectedLineStyle());
line.setLineType((LineType) lineTypeComboBox.getSelectedItem());
line.setLineWidth(lineWidthSpinner.getValue());
line.setLineStyle(lineStyle.getSelectedItem());
line.setNullValueBreak(nullValueBreak.getSelectedIndex() == 0);
return line;

25
designer-chart/src/main/java/com/fr/van/chart/designer/component/VanChartLineWidthPane.java

@ -1,30 +1,19 @@
package com.fr.van.chart.designer.component;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.van.chart.designer.TableLayout4VanChartHelper;
import javax.swing.JPanel;
import java.awt.Component;
/**
* 线-线型
* 线型+线宽+空值断开
*/
public class VanChartLineWidthPane extends VanChartLineTypePane {
private static final long serialVersionUID = 4537158946119294689L;
protected JPanel createContentPane(double p, double f) {
double[] row = {p, p, p};
double e = TableLayout4VanChartHelper.EDIT_AREA_WIDTH;
double[] col = {f, e};
Component[][] components = new Component[][]{
new Component[]{null,null},
new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Line_Style")), lineWidth},
new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Null_Value_Break")), nullValueBreak},
@Override
protected Component[][] createContentComponent(Component[] lineTypeComponent, Component[] lineWidthComponent, Component[] lineStyleComponent, Component[] nullValueBreakComponent) {
return new Component[][]{
lineTypeComponent,
lineWidthComponent,
nullValueBreakComponent
};
return TableLayoutHelper.createTableLayoutPane(components, row, col);
}
}

25
designer-chart/src/main/java/com/fr/van/chart/scatter/component/VanChartScatterLineTypePane.java

@ -1,16 +1,11 @@
package com.fr.van.chart.scatter.component;
import com.fr.design.gui.ibutton.UIButtonGroup;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.plugin.chart.base.VanChartAttrLine;
import com.fr.plugin.chart.type.LineStyle;
import com.fr.stable.Constants;
import com.fr.van.chart.designer.TableLayout4VanChartHelper;
import com.fr.plugin.chart.type.LineType;
import com.fr.van.chart.designer.component.VanChartLineTypePane;
import javax.swing.JPanel;
import java.awt.Component;
/**
@ -26,24 +21,20 @@ public class VanChartScatterLineTypePane extends VanChartLineTypePane {
}
@Override
protected JPanel createContentPane(double p, double f) {
double[] row = {p,p,p};
double e = TableLayout4VanChartHelper.EDIT_AREA_WIDTH;
double[] col = {f, e};
Component[][] components = new Component[][]{
new Component[]{null,null},
new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Line_Style")), lineWidth},
new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Style_Present")), lineStyle},
protected Component[][] createContentComponent(Component[] lineTypeComponent, Component[] lineWidthComponent, Component[] lineStyleComponent, Component[] nullValueBreakComponent) {
return new Component[][]{
new Component[]{null, null},
lineTypeComponent,
lineWidthComponent,
lineStyleComponent
};
return TableLayoutHelper.createTableLayoutPane(components, row, col);
}
@Override
protected VanChartAttrLine initVanChartAttrLine() {
VanChartAttrLine attrLine = new VanChartAttrLine();
//默认为无线型,且默認空值不斷開
attrLine.setLineWidth(Constants.LINE_NONE);
attrLine.setLineType(LineType.NONE);
attrLine.setNullValueBreak(false);
return attrLine;
}

Loading…
Cancel
Save