Browse Source

CHART-19508 图表切换支持调整顺序和复制

feature/10.0
白岳 3 years ago
parent
commit
bf84ab6a3e
  1. 249
      designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/ChartTypeButtonPane.java

249
designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/ChartTypeButtonPane.java

@ -6,7 +6,6 @@ import com.fr.chart.chartattr.ChartCollection;
import com.fr.chart.charttypes.ChartTypeManager;
import com.fr.chartx.attr.ChartProvider;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.mainframe.chart.info.ChartInfoCollector;
import com.fr.design.dialog.DialogActionListener;
import com.fr.design.dialog.UIDialog;
import com.fr.design.event.UIObserver;
@ -16,7 +15,9 @@ import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ibutton.UIToggleButton;
import com.fr.design.gui.imenutable.UIMenuNameableCreator;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.chart.gui.ChartTypePane.ComboBoxPane;
import com.fr.design.mainframe.chart.info.ChartInfoCollector;
import com.fr.general.ComparatorUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.chart.vanchart.VanChart;
@ -48,6 +49,7 @@ import java.awt.image.BufferedImage;
/**
* 图表 类型 增删 控制按钮界面.
*
* @author kunsnat E-mail:kunsnat@gmail.com
* @version 创建时间2013-9-26 上午09:27:49
*/
@ -55,7 +57,7 @@ public class ChartTypeButtonPane extends BasicBeanPane<ChartCollection> implemen
private static final long serialVersionUID = -8130803225718028933L;
private static final int B_W = 52;
private static final int B_H = 20;
private static final int COL_COUNT = 3;
private static final int COL_COUNT = 4;
private static final int P_W = 300;
private static final int P_H = 400;
@ -67,7 +69,11 @@ public class ChartTypeButtonPane extends BasicBeanPane<ChartCollection> implemen
private UIButton addButton;
private UIButton configButton;
private ArrayList<ChartChangeButton> indexList = new ArrayList<ChartChangeButton>();
private UIButton copyButton;
private UIButton moveForwardButton;
private UIButton moveBackButton;
private ArrayList<ChartChangeButton> indexList = new ArrayList<>();
private JPanel buttonPane;
private ChartCollection editingCollection;
@ -85,37 +91,60 @@ public class ChartTypeButtonPane extends BasicBeanPane<ChartCollection> implemen
//所以:stopEditing--选中其他button则响应click之后relayout;普通失焦则直接relayout.
private boolean pressOtherButtonWhenEditing = false;
public ChartTypeButtonPane(ChartTypePane chartTypePane){
public ChartTypeButtonPane(ChartTypePane chartTypePane) {
this();
parent = chartTypePane;
}
public ChartTypeButtonPane() {
this.setLayout(new BorderLayout());
addButton = new UIButton(BaseUtils.readIcon("/com/fr/design/images/buttonicon/add.png"));
configButton = new UIButton(BaseUtils.readIcon("/com/fr/design/images/buttonicon/config.png"));
initButton();
buttonPane = new JPanel();
this.add(buttonPane, BorderLayout.CENTER);
JPanel eastPane = new JPanel();
this.add(eastPane, BorderLayout.EAST);
JPanel northPane = new JPanel();
this.add(northPane, BorderLayout.NORTH);
eastPane.setLayout(new BorderLayout());
northPane.setLayout(new BorderLayout());
northPane.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
JPanel addPanel = new JPanel();
addPanel.setLayout(new BorderLayout());
addPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 3));
addPanel.add(addButton, BorderLayout.CENTER);
eastPane.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 5));
JPanel button = new JPanel();
button.setPreferredSize(new Dimension(45, 20));
button.setLayout(new GridLayout(1, 2, 5, 0));
button.add(addButton);
button.add(configButton);
eastPane.add(button, BorderLayout.NORTH);
button.setPreferredSize(new Dimension(95, 20));
button.setLayout(new GridLayout(1, 4, 0, 0));
button.add(addPanel);
button.add(copyButton);
button.add(moveForwardButton);
button.add(moveBackButton);
northPane.add(button, BorderLayout.WEST);
northPane.add(configButton, BorderLayout.EAST);
initAddButton();
initConfigButton();
initConfigCreator();
// Toolkit.getDefaultToolkit().addAWTEventListener(awt, AWTEvent.MOUSE_EVENT_MASK);
// Toolkit.getDefaultToolkit().addAWTEventListener(awt, AWTEvent.MOUSE_EVENT_MASK);
}
private void initButton() {
addButton = new UIButton(BaseUtils.readIcon("/com/fr/design/images/buttonicon/add.png"));
configButton = new UIButton(BaseUtils.readIcon("/com/fr/design/images/buttonicon/config.png"));
copyButton = new UIButton(BaseUtils.readIcon("/com/fr/design/images/m_edit/copy.png"));
copyButton.setBorderPainted(false);
copyButton.setToolTipText(Toolkit.i18nText("Fine-Design_Basic_Action_Copy"));
moveForwardButton = new UIButton(BaseUtils.readIcon("/com/fr/design/images/control/left.png"));
moveForwardButton.setToolTipText(Toolkit.i18nText("Fine-Design_Report_HF_Move_Left"));
moveForwardButton.setBorderPainted(false);
moveBackButton = new UIButton(BaseUtils.readIcon("/com/fr/design/images/control/right.png"));
moveBackButton.setToolTipText(Toolkit.i18nText("Fine-Design_Report_HF_Move_Right"));
moveBackButton.setBorderPainted(false);
initAddButton();
initConfigButton();
initMoveButton();
initCopyButton();
}
public static void registerSupportChangeConfigChartClass(Class<? extends ChartProvider> cls) {
@ -123,53 +152,95 @@ public class ChartTypeButtonPane extends BasicBeanPane<ChartCollection> implemen
}
private void initConfigCreator() {
configCreator = new UIMenuNameableCreator(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Change_Config_Attributes"), new AttrChangeConfig(), ChangeConfigPane.class);
configCreator = new UIMenuNameableCreator(Toolkit.i18nText("Fine-Design_Chart_Change_Config_Attributes"), new AttrChangeConfig(), ChangeConfigPane.class);
}
private void initAddButton() {
addButton.setPreferredSize(new Dimension(20, 20));
addButton.addActionListener(addListener);
addButton.addActionListener((e) -> {
String name = getNewChartName();
ChartProvider chart = getChangeStateNewChart();
addNewChart(chart, name, editingCollection.getChartCount());
});
}
private void initConfigButton() {
configButton.setPreferredSize(new Dimension(20, 20));
configButton.addActionListener(configListener);
configButton.addActionListener((e) -> showConfigDialog());
}
ActionListener addListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String name = getNewChartName();
ChartChangeButton button = new ChartChangeButton(name);// some set selected
private void initCopyButton() {
copyButton.setPreferredSize(new Dimension(20, 20));
copyButton.addActionListener((e) -> {
String name = getCopyChartName();
ChartProvider chart = getCopyChart();
addNewChart(chart, name, editingCollection.getSelectedIndex() + 1);
});
}
button.registerChangeListener(uiobListener);
private void initMoveButton() {
moveForwardButton.setPreferredSize(new Dimension(20, 20));
moveBackButton.setPreferredSize(new Dimension(20, 20));
moveForwardButton.addActionListener((e) -> moveForwardChart());
moveBackButton.addActionListener((e) -> moveBackChart());
}
indexList.add(button);
private void moveBackChart() {
editingCollection.moveBackChart();
populateBean(editingCollection);
}
if (editingCollection != null) {
//点击添加按钮,则会触发切换状态
ChartProvider chart = getChangeStateNewChart();
try {
ChartProvider newChart = (ChartProvider) chart.clone();
editingCollection.addNamedChart(name, newChart);
ChartInfoCollector.getInstance().collection(newChart, null);
} catch (CloneNotSupportedException e1) {
FineLoggerFactory.getLogger().error("Error in Clone");
}
checkoutChange();
}
layoutPane(buttonPane);
private void moveForwardChart() {
editingCollection.moveForwardChart();
populateBean(editingCollection);
}
private void checkMoveButton() {
moveBackButton.setEnabled(editingCollection.getSelectedIndex() != editingCollection.getChartCount() - 1);
moveForwardButton.setEnabled(editingCollection.getSelectedIndex() != 0);
}
private void addNewChart(ChartProvider chart, String name, int index) {
if (chart == null) {
return;
}
};
ChartChangeButton button = new ChartChangeButton(name);// some set selected
button.registerChangeListener(uiobListener);
indexList.add(index, button);
editingCollection.addNamedChart(index, name, chart);
ChartInfoCollector.getInstance().collection(chart, null);
checkoutChange();
layoutPane(buttonPane);
}
private void showConfigDialog() {
UIMenuNameableCreator ui = configCreator.clone();
final BasicBeanPane pane = ui.getPane();
pane.populateBean(editingCollection);
UIDialog dialog = pane.showUnsizedWindow(SwingUtilities.getWindowAncestor(new JPanel()), new DialogActionListener() {
@Override
public void doOk() {
pane.updateBean(editingCollection);
}
@Override
public void doCancel() {
}
});
dialog.setSize(P_W, P_H);
dialog.setVisible(true);
}
//获取图表收集器的状态
private void checkoutChange(){
private void checkoutChange() {
calculateMultiChartMode();
if (parent != null){
if (parent != null) {
parent.relayoutChartTypePane(editingCollection);
}
//检查是否可以配置切换
configButton.setEnabled(changeEnable());
checkMoveButton();
}
/**
@ -181,7 +252,23 @@ public class ChartTypeButtonPane extends BasicBeanPane<ChartCollection> implemen
ChartProvider chart = editingCollection.getSelectedChartProvider(ChartProvider.class);
String chartID = chart.getID();
String priority = ChartTypeManager.getInstanceWithCheck().getPriority(chartID);
return ChartTypeManager.getInstanceWithCheck().getFirstChart(priority);
ChartProvider firstChart = ChartTypeManager.getInstanceWithCheck().getFirstChart(priority);
try {
return (ChartProvider) firstChart.clone();
} catch (Exception ex) {
FineLoggerFactory.getLogger().error(ex.getMessage(), ex);
}
return null;
}
public ChartProvider getCopyChart() {
ChartProvider chart = editingCollection.getSelectedChartProvider(ChartProvider.class);
try {
return (ChartProvider) chart.clone();
} catch (Exception ex) {
FineLoggerFactory.getLogger().error(ex.getMessage(), ex);
return getChangeStateNewChart();
}
}
//图表收集器模式状态改变
@ -204,48 +291,42 @@ public class ChartTypeButtonPane extends BasicBeanPane<ChartCollection> implemen
return supportChangeConfigChartClassSet.contains(editingCollection.getSelectedChartProvider(ChartProvider.class).getClass());
}
ActionListener configListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
UIMenuNameableCreator ui = configCreator.clone();
final BasicBeanPane pane = ui.getPane();
pane.populateBean(editingCollection);
UIDialog dialog = pane.showUnsizedWindow(SwingUtilities.getWindowAncestor(parent), new DialogActionListener() {
@Override
public void doOk() {
pane.updateBean(editingCollection);
}
@Override
public void doCancel() {
}
});
dialog.setSize(P_W, P_H);
dialog.setVisible(true);
}
};
private String getNewChartName() {
int count = indexList.size() + 1;
while (true) {
String name_test = com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Module_Name") + count;
boolean repeated = false;
for (int i = 0, len = indexList.size(); i < len; i++) {
ChartChangeButton nameable = indexList.get(i);
if (ComparatorUtils.equals(nameable.getButtonName(), name_test)) {
repeated = true;
break;
}
String nameTest = Toolkit.i18nText("Fine-Design_Chart_Module_Name") + count;
if (!nameRepeated(nameTest)) {
return nameTest;
}
count++;
}
}
if (!repeated) {
return name_test;
private String getCopyChartName() {
String chartName = "CopyOf" + editingCollection.getChartName(editingCollection.getSelectedIndex());
if (!nameRepeated(chartName)) {
return chartName;
}
int count = 1;
while (true) {
String nameTest = chartName + count;
if (!nameRepeated(nameTest)) {
return nameTest;
}
count++;
}
}
private boolean nameRepeated(String name) {
for (int i = 0, len = indexList.size(); i < len; i++) {
ChartChangeButton nameable = indexList.get(i);
if (ComparatorUtils.equals(nameable.getButtonName(), name)) {
return true;
}
}
return false;
}
private void layoutPane(JPanel northPane) {
if (northPane == null) {
return;
@ -291,6 +372,7 @@ public class ChartTypeButtonPane extends BasicBeanPane<ChartCollection> implemen
/**
* 注册监听器
*
* @param listener 观察者监听事件
*/
public void registerChangeListener(UIObserverListener listener) {
@ -299,6 +381,7 @@ public class ChartTypeButtonPane extends BasicBeanPane<ChartCollection> implemen
/**
* 是否应该响应事件监听器
*
* @return 是则返回true
*/
public boolean shouldResponseChangeListener() {
@ -383,7 +466,7 @@ public class ChartTypeButtonPane extends BasicBeanPane<ChartCollection> implemen
int selectedIndex = editingCollection.getSelectedIndex();
ChartChangeButton button = indexList.get(selectedIndex);
button.isMoveOn = false;
if (!ComparatorUtils.equals(editingCollection.getChartName(selectedIndex), newName)) {
if (!nameRepeated(newName)) {
editingCollection.setChartName(selectedIndex, newName);
HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().fireTargetModified();
button.changeChartName(newName);
@ -391,7 +474,7 @@ public class ChartTypeButtonPane extends BasicBeanPane<ChartCollection> implemen
buttonPane.remove(currentEditingEditor);
currentEditingEditor = null;
if(!pressOtherButtonWhenEditing) {
if (!pressOtherButtonWhenEditing) {
layoutPane(buttonPane);
}
}
@ -427,7 +510,7 @@ public class ChartTypeButtonPane extends BasicBeanPane<ChartCollection> implemen
@Override
public void focusLost(FocusEvent e) {//编辑状态lost才走这边
if (currentEditingEditor != null ) {
if (currentEditingEditor != null) {
stopEditing();
}
}
@ -519,7 +602,7 @@ public class ChartTypeButtonPane extends BasicBeanPane<ChartCollection> implemen
relayoutPane();
//重构面板
if (parent != null ){
if (parent != null) {
parent.reLayoutEditPane(lastPlotID, editingCollection);
}
}
@ -534,7 +617,7 @@ public class ChartTypeButtonPane extends BasicBeanPane<ChartCollection> implemen
@Override
public void mouseClicked(MouseEvent e) {
mouseClick(e);
if(pressOtherButtonWhenEditing){
if (pressOtherButtonWhenEditing) {
relayoutPane();
pressOtherButtonWhenEditing = false;
}
@ -581,7 +664,7 @@ public class ChartTypeButtonPane extends BasicBeanPane<ChartCollection> implemen
//需要先更新,最后重构面板
//重构面板
if (parent != null ){
if (parent != null) {
parent.reLayoutEditPane(lastPlotID, editingCollection);
}
}

Loading…
Cancel
Save