zheng
6 years ago
9 changed files with 302 additions and 13 deletions
@ -0,0 +1,106 @@
|
||||
package com.fr.design.chartx.component; |
||||
|
||||
import com.fr.design.beans.BasicBeanPane; |
||||
import com.fr.design.gui.frpane.UICorrelationPane; |
||||
import com.fr.design.gui.itable.UITable; |
||||
import com.fr.design.gui.itable.UITableEditor; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import javax.swing.JTable; |
||||
import javax.swing.event.ChangeEvent; |
||||
import java.awt.BorderLayout; |
||||
import java.awt.Component; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* Created by shine on 2019/6/4. |
||||
*/ |
||||
public abstract class AbstractChartDataCorrelationPane<T> extends BasicBeanPane<T> { |
||||
private FieldEditorComponentWrapper[] editorComponents; |
||||
|
||||
private UICorrelationPane correlationPane; |
||||
|
||||
public AbstractChartDataCorrelationPane() { |
||||
|
||||
this.editorComponents = fieldEditorComponentWrappers(); |
||||
|
||||
String[] headers = new String[editorComponents.length]; |
||||
|
||||
for (int i = 0, len = editorComponents.length; i < len; i++) { |
||||
headers[i] = editorComponents[i].headerName(); |
||||
} |
||||
|
||||
initComps(headers); |
||||
} |
||||
|
||||
protected abstract FieldEditorComponentWrapper[] fieldEditorComponentWrappers(); |
||||
|
||||
protected List<Object[]> update() { |
||||
return correlationPane.updateBean(); |
||||
} |
||||
|
||||
protected void populate(List<Object[]> list) { |
||||
correlationPane.populateBean(list); |
||||
} |
||||
|
||||
@Override |
||||
public T updateBean() { |
||||
return null; |
||||
} |
||||
|
||||
private void initComps(String[] headers) { |
||||
correlationPane = new UICorrelationPane(headers) { |
||||
public UITableEditor createUITableEditor() { |
||||
return new Editor(); |
||||
} |
||||
|
||||
protected UITable initUITable() { |
||||
return new UITable(columnCount) { |
||||
|
||||
public UITableEditor createTableEditor() { |
||||
return createUITableEditor(); |
||||
} |
||||
|
||||
public void tableCellEditingStopped(ChangeEvent e) { |
||||
stopPaneEditing(e); |
||||
} |
||||
}; |
||||
} |
||||
}; |
||||
|
||||
this.setLayout(new BorderLayout()); |
||||
this.add(correlationPane, BorderLayout.CENTER); |
||||
} |
||||
|
||||
private class Editor extends UITableEditor { |
||||
|
||||
private Component currentComponent; |
||||
private FieldEditorComponentWrapper currentEditorWrapper; |
||||
|
||||
public Object getCellEditorValue() { |
||||
return currentEditorWrapper.value(currentComponent); |
||||
} |
||||
|
||||
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { |
||||
if (column == table.getModel().getColumnCount()) { |
||||
return null; |
||||
} |
||||
|
||||
correlationPane.stopCellEditing(); |
||||
|
||||
currentEditorWrapper = AbstractChartDataCorrelationPane.this.editorComponents[column]; |
||||
|
||||
currentComponent = currentEditorWrapper.createEditorComponent(correlationPane); |
||||
currentEditorWrapper.setValue(currentComponent, value); |
||||
|
||||
return currentComponent; |
||||
} |
||||
|
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return StringUtils.EMPTY; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,55 @@
|
||||
package com.fr.design.chartx.component; |
||||
|
||||
import com.fr.chartx.data.field.ColumnField; |
||||
import com.fr.chartx.data.field.SeriesValueColumnFields; |
||||
import com.fr.chartx.data.field.SeriesValueField; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.general.GeneralUtils; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* Created by shine on 2019/6/4. |
||||
*/ |
||||
public class CellDataSeriesValueFieldsPane extends AbstractChartDataCorrelationPane<SeriesValueColumnFields> { |
||||
|
||||
@Override |
||||
protected FieldEditorComponentWrapper[] fieldEditorComponentWrappers() { |
||||
return new FieldEditorComponentWrapper[]{ |
||||
new TinyFormulaPaneEditorComponent(Toolkit.i18nText("Fine-Design_Chart_Series_Name")), |
||||
new TinyFormulaPaneEditorComponent(Toolkit.i18nText("Fine-Design_Chart_Series_Value")) |
||||
}; |
||||
} |
||||
|
||||
@Override |
||||
public void populateBean(SeriesValueColumnFields ob) { |
||||
List<Object[]> list = new ArrayList<Object[]>(); |
||||
|
||||
List<SeriesValueField> seriesValueFieldList = ob.getSeriesValueFieldList(); |
||||
for (SeriesValueField seriesValueField : seriesValueFieldList) { |
||||
Object[] array = new Object[]{seriesValueField.getSeries().getFieldName(), seriesValueField.getValue().getFieldName()}; |
||||
list.add(array); |
||||
} |
||||
|
||||
populate(list); |
||||
} |
||||
|
||||
@Override |
||||
public void updateBean(SeriesValueColumnFields ob) { |
||||
List<Object[]> list = update(); |
||||
|
||||
List<SeriesValueField> seriesValueFieldList = new ArrayList<SeriesValueField>(); |
||||
|
||||
for (Object[] objects : list) { |
||||
SeriesValueField seriesValueField = new SeriesValueField(); |
||||
ColumnField series = new ColumnField(GeneralUtils.objectToString(objects[0])); |
||||
ColumnField value = new ColumnField(GeneralUtils.objectToString(objects[1])); |
||||
seriesValueField.setSeries(series); |
||||
seriesValueField.setValue(value); |
||||
seriesValueFieldList.add(seriesValueField); |
||||
} |
||||
|
||||
ob.setSeriesValueFieldList(seriesValueFieldList); |
||||
} |
||||
} |
@ -0,0 +1,19 @@
|
||||
package com.fr.design.chartx.component; |
||||
|
||||
import com.fr.design.gui.frpane.UICorrelationPane; |
||||
|
||||
import java.awt.Component; |
||||
|
||||
/** |
||||
* Created by shine on 2019/6/4. |
||||
*/ |
||||
public interface FieldEditorComponentWrapper<T extends Component> { |
||||
|
||||
String headerName(); |
||||
|
||||
T createEditorComponent(UICorrelationPane parent); |
||||
|
||||
Object value(T t); |
||||
|
||||
void setValue(T t, Object o); |
||||
} |
@ -0,0 +1,61 @@
|
||||
package com.fr.design.chartx.component; |
||||
|
||||
import com.fr.base.BaseFormula; |
||||
import com.fr.base.Utils; |
||||
import com.fr.design.constants.UIConstants; |
||||
import com.fr.design.event.UIObserverListener; |
||||
import com.fr.design.formula.TinyFormulaPane; |
||||
import com.fr.design.gui.frpane.UICorrelationPane; |
||||
|
||||
/** |
||||
* Created by shine on 2019/6/4. |
||||
*/ |
||||
public class TinyFormulaPaneEditorComponent implements FieldEditorComponentWrapper<TinyFormulaPane> { |
||||
|
||||
private String header; |
||||
|
||||
public TinyFormulaPaneEditorComponent(String header) { |
||||
this.header = header; |
||||
} |
||||
|
||||
@Override |
||||
public String headerName() { |
||||
return this.header; |
||||
} |
||||
|
||||
@Override |
||||
public TinyFormulaPane createEditorComponent(final UICorrelationPane parent) { |
||||
TinyFormulaPane editorComponent = new TinyFormulaPane() { |
||||
@Override |
||||
public void okEvent() { |
||||
parent.stopCellEditing(); |
||||
parent.fireTargetChanged(); |
||||
} |
||||
|
||||
@Override |
||||
protected void populateTextField(BaseFormula fm) { |
||||
formulaTextField.setText(fm.getContent()); |
||||
} |
||||
}; |
||||
editorComponent.setBackground(UIConstants.FLESH_BLUE); |
||||
|
||||
editorComponent.getUITextField().registerChangeListener(new UIObserverListener() { |
||||
@Override |
||||
public void doChange() { |
||||
parent.fireTargetChanged(); |
||||
} |
||||
}); |
||||
|
||||
return editorComponent; |
||||
} |
||||
|
||||
@Override |
||||
public Object value(TinyFormulaPane formulaPane) { |
||||
return formulaPane.getUITextField().getText(); |
||||
} |
||||
|
||||
@Override |
||||
public void setValue(TinyFormulaPane formulaPane, Object o) { |
||||
formulaPane.getUITextField().setText(Utils.objectToString(o)); |
||||
} |
||||
} |
@ -0,0 +1,41 @@
|
||||
package com.fr.design.chartx.fields.diff; |
||||
|
||||
import com.fr.chartx.data.field.diff.AbstractColumnFieldCollectionWithSeriesValue; |
||||
import com.fr.design.chartx.component.CellDataSeriesValueFieldsPane; |
||||
import com.fr.design.chartx.fields.AbstractCellDataFieldsPane; |
||||
|
||||
import javax.swing.JPanel; |
||||
import java.awt.BorderLayout; |
||||
|
||||
/** |
||||
* Created by shine on 2019/6/4. |
||||
*/ |
||||
public abstract class AbstractCellDataFieldsWithSeriesValuePane<T extends AbstractColumnFieldCollectionWithSeriesValue> |
||||
extends AbstractCellDataFieldsPane<T> { |
||||
|
||||
private CellDataSeriesValueFieldsPane seriesValueFieldsPane; |
||||
|
||||
@Override |
||||
protected JPanel createCenterPane() { |
||||
JPanel normalCenter = super.createCenterPane(); |
||||
seriesValueFieldsPane = new CellDataSeriesValueFieldsPane(); |
||||
|
||||
if (normalCenter != null) { |
||||
JPanel panel = new JPanel(new BorderLayout()); |
||||
panel.add(normalCenter, BorderLayout.CENTER); |
||||
panel.add(seriesValueFieldsPane, BorderLayout.SOUTH); |
||||
return panel; |
||||
} else { |
||||
return seriesValueFieldsPane; |
||||
} |
||||
} |
||||
|
||||
protected void populateSeriesValuePane(AbstractColumnFieldCollectionWithSeriesValue t) { |
||||
seriesValueFieldsPane.populateBean(t.getSeriesValueColumnFields()); |
||||
} |
||||
|
||||
protected void updateSeriesValuePane(AbstractColumnFieldCollectionWithSeriesValue t) { |
||||
seriesValueFieldsPane.updateBean(t.getSeriesValueColumnFields()); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue