forked from fanruan/design
Browse Source
Merge in DESIGN/design from ~HENRY.WANG/design:feature/x to feature/x * commit 'bd82a9d6949b8793092b28235099a8661e2c75fb': REPORT-62440 表头排序内置 REPORT-62440 表头排序内置 REPORT-62440 表头排序内置 REPORT-62440 表头排序内置 REPORT-62440 表头排序内置 REPORT-62440 表头排序内置 REPORT-62440 表头排序内置 REPORT-62440 表头排序内置feature/x
Henry.Wang
3 years ago
36 changed files with 1982 additions and 273 deletions
@ -0,0 +1,7 @@
|
||||
package com.fr.design.event; |
||||
|
||||
import java.awt.*; |
||||
|
||||
public interface ComponentChangeListener { |
||||
void initListener(Container changedComponent); |
||||
} |
@ -0,0 +1,6 @@
|
||||
package com.fr.design.event; |
||||
|
||||
|
||||
public interface ComponentChangeObserver { |
||||
void registerChangeListener(ComponentChangeListener uiChangeableListener); |
||||
} |
After Width: | Height: | Size: 141 B |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 175 B |
After Width: | Height: | Size: 166 B |
After Width: | Height: | Size: 3.3 KiB |
@ -0,0 +1,38 @@
|
||||
package com.fr.design.sort.celldscolumn; |
||||
|
||||
import com.fr.design.data.DesignTableDataManager; |
||||
import com.fr.design.data.tabledata.wrapper.TableDataWrapper; |
||||
import com.fr.design.file.HistoryTemplateListCache; |
||||
import com.fr.design.sort.common.AbstractSortGroupPane; |
||||
import com.fr.design.sort.common.AbstractSortItemPane; |
||||
import com.fr.report.cell.cellattr.core.group.DSColumn; |
||||
import com.fr.report.core.sort.sortexpression.SortExpression; |
||||
|
||||
public class CellDSColumnSortGroupPane extends AbstractSortGroupPane { |
||||
DSColumn dsColumn; |
||||
|
||||
public CellDSColumnSortGroupPane(int sortGroupPaneWidth, int sortGroupPaneRightWidth) { |
||||
super(sortGroupPaneWidth, sortGroupPaneRightWidth); |
||||
} |
||||
|
||||
public void populateDsColumn( DSColumn dsColumn){ |
||||
this.dsColumn = dsColumn; |
||||
} |
||||
|
||||
@Override |
||||
protected AbstractSortItemPane refreshSortItemPane(int sortItemPaneWidth, int sortItemPaneRightWidth, SortExpression sortExpression) { |
||||
CellDSColumnSortItemPane cellDSColumnSortItemPane = new CellDSColumnSortItemPane( sortItemPaneWidth, sortItemPaneRightWidth); |
||||
java.util.Map<String, TableDataWrapper> tableDataWrapperMap = |
||||
DesignTableDataManager.getAllEditingDataSet(HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getTarget()); |
||||
TableDataWrapper tableDataWrapper = tableDataWrapperMap.get(dsColumn.getDSName()); |
||||
java.util.List<String> columnNameList = tableDataWrapper.calculateColumnNameList(); |
||||
String[] columnNames = new String[columnNameList.size()]; |
||||
columnNameList.toArray(columnNames); |
||||
cellDSColumnSortItemPane.sortAreaUiComboBox.removeAllItems(); |
||||
for (String columnName : columnNames) { |
||||
cellDSColumnSortItemPane.sortAreaUiComboBox.addItem(columnName); |
||||
} |
||||
cellDSColumnSortItemPane.populateBean(sortExpression); |
||||
return cellDSColumnSortItemPane; |
||||
} |
||||
} |
@ -0,0 +1,40 @@
|
||||
package com.fr.design.sort.celldscolumn; |
||||
|
||||
import com.fr.design.gui.icombobox.UIComboBox; |
||||
import com.fr.design.sort.common.AbstractSortItemPane; |
||||
import com.fr.design.sort.common.AbstractSortPane; |
||||
import com.fr.report.core.sort.sortexpression.SortExpression; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
|
||||
|
||||
public class CellDSColumnSortItemPane extends AbstractSortItemPane { |
||||
|
||||
UIComboBox sortAreaUiComboBox; |
||||
|
||||
public CellDSColumnSortItemPane(int sortItemPaneWidth, int sortItemPaneRightWidth) { |
||||
super(sortItemPaneWidth, sortItemPaneRightWidth); |
||||
} |
||||
|
||||
@Override |
||||
public void initMainSortAreaPane(JPanel sortAreaPane) { |
||||
sortAreaUiComboBox = new UIComboBox(new String[0]); |
||||
sortAreaUiComboBox.setPreferredSize(new Dimension(sortItemPaneRightWidth, AbstractSortPane.PANE_COMPONENT_HEIGHT)); |
||||
sortAreaPane.add(sortAreaUiComboBox); |
||||
} |
||||
|
||||
public void populateBean(SortExpression sortExpression) { |
||||
sortAreaUiComboBox.setSelectedItem(sortExpression.getSortArea()); |
||||
super.populateBean(sortExpression); |
||||
} |
||||
|
||||
public SortExpression updateBean() { |
||||
SortExpression sortExpression = super.updateBean(); |
||||
if (sortExpression != null) { |
||||
sortExpression.setSortArea(sortAreaUiComboBox.getSelectedItem().toString()); |
||||
} |
||||
return sortExpression; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,59 @@
|
||||
package com.fr.design.sort.celldscolumn; |
||||
|
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.sort.common.AbstractSortPane; |
||||
import com.fr.general.data.TableDataColumn; |
||||
import com.fr.report.cell.TemplateCellElement; |
||||
import com.fr.report.cell.cellattr.core.group.DSColumn; |
||||
import com.fr.report.core.sort.common.CellSortAttr; |
||||
|
||||
import javax.swing.*; |
||||
|
||||
|
||||
public class CellDSColumnSortPane extends AbstractSortPane { |
||||
|
||||
public CellDSColumnSortPane() { |
||||
super(220, 150); |
||||
//this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
|
||||
} |
||||
|
||||
@Override |
||||
protected void initSortGroupPane() { |
||||
sortGroupPane = new CellDSColumnSortGroupPane(sortPaneWidth, sortPaneRightWidth); |
||||
this.add(sortGroupPane); |
||||
} |
||||
|
||||
@Override |
||||
protected CellSortAttr getCellSortAttr(TemplateCellElement cellElement) { |
||||
if (cellElement.getValue() instanceof DSColumn) { |
||||
DSColumn dsColumn = ((DSColumn) cellElement.getValue()); |
||||
if (dsColumn.getCellSortAttr() == null) { |
||||
dsColumn.setCellSortAttr(new CellSortAttr()); |
||||
} |
||||
return dsColumn.getCellSortAttr(); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
protected void populateSortArea(TemplateCellElement cellElement) { |
||||
super.populateSortArea(cellElement); |
||||
if (cellElement.getValue() instanceof DSColumn) { |
||||
DSColumn dsColumn = ((DSColumn) cellElement.getValue()); |
||||
TableDataColumn tableDataColumn = dsColumn.getColumn(); |
||||
if (tableDataColumn instanceof TableDataColumn) { |
||||
selfSortArea = TableDataColumn.getColumnName(tableDataColumn); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public void populateBean(TemplateCellElement cellElement) { |
||||
if (cellElement.getValue() instanceof DSColumn) { |
||||
DSColumn dsColumn = ((DSColumn) cellElement.getValue()); |
||||
if (sortGroupPane != null) { |
||||
((CellDSColumnSortGroupPane) sortGroupPane).populateDsColumn(dsColumn); |
||||
} |
||||
} |
||||
super.populateBean(cellElement); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,19 @@
|
||||
package com.fr.design.sort.cellexpand; |
||||
|
||||
import com.fr.design.sort.common.AbstractSortGroupPane; |
||||
import com.fr.design.sort.common.AbstractSortItemPane; |
||||
import com.fr.report.core.sort.sortexpression.SortExpression; |
||||
|
||||
public class CellExpandSortGroupPane extends AbstractSortGroupPane { |
||||
|
||||
public CellExpandSortGroupPane(int sortGroupPaneWidth, int sortGroupPaneRightWidth) { |
||||
super(sortGroupPaneWidth, sortGroupPaneRightWidth); |
||||
} |
||||
|
||||
@Override |
||||
protected AbstractSortItemPane refreshSortItemPane(int sortItemPaneWidth, int sortItemPaneRightWidth, SortExpression sortExpression) { |
||||
AbstractSortItemPane abstractSortItemPane = new CellExpandSortItemPane( sortItemPaneWidth, sortItemPaneRightWidth); |
||||
abstractSortItemPane.populateBean(sortExpression); |
||||
return abstractSortItemPane; |
||||
} |
||||
} |
@ -0,0 +1,37 @@
|
||||
package com.fr.design.sort.cellexpand; |
||||
|
||||
import com.fr.design.sort.common.AbstractSortPane; |
||||
import com.fr.design.sort.common.SortColumnRowPane; |
||||
import com.fr.design.sort.common.AbstractSortItemPane; |
||||
import com.fr.report.core.sort.sortexpression.SortExpression; |
||||
import com.fr.stable.ColumnRow; |
||||
|
||||
import javax.swing.*; |
||||
|
||||
public class CellExpandSortItemPane extends AbstractSortItemPane { |
||||
SortColumnRowPane columnRowPane; |
||||
|
||||
public CellExpandSortItemPane(int sortItemPaneWidth, int sortItemPaneRightWidth) { |
||||
super(sortItemPaneWidth, sortItemPaneRightWidth); |
||||
} |
||||
|
||||
@Override |
||||
public void initMainSortAreaPane(JPanel sortAreaPane) { |
||||
columnRowPane = new SortColumnRowPane(sortItemPaneRightWidth + 4, AbstractSortPane.PANE_COMPONENT_HEIGHT); |
||||
sortAreaPane.add(columnRowPane); |
||||
} |
||||
|
||||
public void populateBean(SortExpression sortExpression) { |
||||
columnRowPane.populateBean(ColumnRow.valueOf(sortExpression.getSortArea())); |
||||
super.populateBean(sortExpression); |
||||
} |
||||
|
||||
public SortExpression updateBean() { |
||||
SortExpression sortExpression = super.updateBean(); |
||||
if (sortExpression != null) { |
||||
ColumnRow columnRow = columnRowPane.updateBean(); |
||||
sortExpression.setSortArea(columnRow == null ? null : columnRow.toString()); |
||||
} |
||||
return sortExpression; |
||||
} |
||||
} |
@ -0,0 +1,39 @@
|
||||
package com.fr.design.sort.cellexpand; |
||||
|
||||
|
||||
import com.fr.design.mainframe.cell.settingpane.CellExpandAttrPane; |
||||
import com.fr.design.sort.common.AbstractSortPane; |
||||
import com.fr.report.cell.TemplateCellElement; |
||||
import com.fr.report.cell.cellattr.CellExpandAttr; |
||||
import com.fr.report.core.sort.common.CellSortAttr; |
||||
|
||||
|
||||
import javax.swing.*; |
||||
|
||||
public class CellExpandSortPane extends AbstractSortPane { |
||||
CellExpandAttrPane cellExpandAttrPane; |
||||
|
||||
public CellExpandSortPane(CellExpandAttrPane cellExpandAttrPane) { |
||||
super(227, 155); |
||||
this.cellExpandAttrPane = cellExpandAttrPane; |
||||
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
||||
} |
||||
|
||||
@Override |
||||
protected void initSortGroupPane() { |
||||
sortGroupPane = new CellExpandSortGroupPane(sortPaneWidth, sortPaneRightWidth); |
||||
this.add(sortGroupPane); |
||||
} |
||||
|
||||
@Override |
||||
protected CellSortAttr getCellSortAttr(TemplateCellElement cellElement) { |
||||
CellExpandAttr cellExpandAttr = cellElement.getCellExpandAttr(); |
||||
if (cellExpandAttr != null) { |
||||
if (cellExpandAttr.getCellSortAttr() == null) { |
||||
cellExpandAttr.setCellSortAttr(new CellSortAttr()); |
||||
} |
||||
return cellExpandAttr.getCellSortAttr(); |
||||
} |
||||
return null; |
||||
} |
||||
} |
@ -0,0 +1,148 @@
|
||||
package com.fr.design.sort.common; |
||||
|
||||
import com.fr.base.svg.IconUtils; |
||||
import com.fr.design.event.ComponentChangeListener; |
||||
import com.fr.design.event.ComponentChangeObserver; |
||||
import com.fr.design.gui.ibutton.UIButton; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.report.core.sort.sortexpression.CellSortExpression; |
||||
import com.fr.report.core.sort.sortexpression.SortExpression; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.awt.event.ActionEvent; |
||||
import java.awt.event.ActionListener; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
|
||||
public abstract class AbstractSortGroupPane extends JPanel implements ComponentChangeObserver { |
||||
|
||||
protected int sortGroupPaneWidth; |
||||
protected int sortGroupPaneRightWidth; |
||||
List<SortExpression> sortExpressions; |
||||
List<JPanel> sortItemPanes = new ArrayList<>(); |
||||
AddSortItemBar addSortItemBar; |
||||
JPanel sortItemListPane; |
||||
UIButton uiButton; |
||||
String selfSortArea; |
||||
|
||||
ComponentChangeListener componentChangeListener; |
||||
|
||||
public AbstractSortGroupPane(int sortGroupPaneWidth, int sortGroupPaneRightWidth) { |
||||
this.sortGroupPaneRightWidth = sortGroupPaneRightWidth; |
||||
this.sortGroupPaneWidth = sortGroupPaneWidth; |
||||
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
||||
initComponents(); |
||||
} |
||||
|
||||
private void initComponents() { |
||||
addSortItemBar = new AddSortItemBar(this); |
||||
sortItemListPane = new JPanel(); |
||||
sortItemListPane.setLayout(new BoxLayout(sortItemListPane, BoxLayout.Y_AXIS)); |
||||
this.add(sortItemListPane); |
||||
this.add(addSortItemBar); |
||||
} |
||||
|
||||
public void populateBean(List<SortExpression> sortExpressions, String selfSortArea) { |
||||
this.sortItemListPane.removeAll(); |
||||
this.selfSortArea = selfSortArea; |
||||
this.sortExpressions = sortExpressions; |
||||
this.sortItemPanes = new ArrayList<>(); |
||||
for (int i = 0; i < sortExpressions.size(); i++) { |
||||
addSortItem(sortExpressions.get(i), i == 0); |
||||
} |
||||
refresh(); |
||||
} |
||||
|
||||
protected abstract AbstractSortItemPane refreshSortItemPane(int sortItemPaneWidth, int sortItemPaneRightWidth, SortExpression sortExpression); |
||||
|
||||
public List<SortExpression> updateBean() { |
||||
List<SortExpression> sortExpressions = new ArrayList<>(); |
||||
for (JPanel sortItemPane : sortItemPanes) { |
||||
SortExpression sortExpression = null; |
||||
AbstractSortItemPane abstractSortItemPane = null; |
||||
if (sortItemPane instanceof AbstractSortItemPane) { |
||||
abstractSortItemPane = (AbstractSortItemPane) sortItemPane; |
||||
} else if (sortItemPane instanceof SortUIExpandablePane) { |
||||
abstractSortItemPane = (AbstractSortItemPane) ((SortUIExpandablePane) sortItemPane).getContentPane(); |
||||
} |
||||
if (abstractSortItemPane != null) { |
||||
sortExpression = abstractSortItemPane.updateBean(); |
||||
} |
||||
if (sortExpression != null) { |
||||
sortExpressions.add(sortExpression); |
||||
} |
||||
} |
||||
return sortExpressions; |
||||
} |
||||
|
||||
|
||||
public void removeSortItem(int no) { |
||||
if (no < sortExpressions.size()) { |
||||
sortItemListPane.remove(sortItemPanes.get(no)); |
||||
sortExpressions.remove(no); |
||||
sortItemPanes.remove(no); |
||||
refresh(); |
||||
} |
||||
} |
||||
|
||||
public void registerChangeListener(ComponentChangeListener componentChangeListener) { |
||||
this.componentChangeListener = componentChangeListener; |
||||
} |
||||
|
||||
public void addSortItem(SortExpression sortExpression, boolean mainSort) { |
||||
int sortItemPaneWidth = sortGroupPaneWidth; |
||||
int sortItemPaneRightWidth = sortGroupPaneRightWidth; |
||||
if (!mainSort) { |
||||
sortItemPaneWidth -= 12; |
||||
sortItemPaneRightWidth -= 12; |
||||
} |
||||
if (sortExpression == null) { |
||||
sortExpression = new CellSortExpression(selfSortArea); |
||||
sortExpressions.add(sortExpression); |
||||
} |
||||
|
||||
AbstractSortItemPane abstractSortItemPane = |
||||
refreshSortItemPane(sortItemPaneWidth, sortItemPaneRightWidth, sortExpression); |
||||
|
||||
JPanel sortItemPane = abstractSortItemPane; |
||||
if (!mainSort) { |
||||
sortItemPane = new SortUIExpandablePane(abstractSortItemPane, this); |
||||
} |
||||
sortItemListPane.add(sortItemPane); |
||||
sortItemPanes.add(sortItemPane); |
||||
|
||||
if (componentChangeListener != null) { |
||||
componentChangeListener.initListener(sortItemPane); |
||||
} |
||||
refresh(); |
||||
} |
||||
|
||||
protected void refresh() { |
||||
validate(); |
||||
repaint(); |
||||
revalidate(); |
||||
} |
||||
|
||||
class AddSortItemBar extends JPanel { |
||||
AbstractSortGroupPane sortGroupPane; |
||||
|
||||
AddSortItemBar(AbstractSortGroupPane sortGroupPane) { |
||||
init(); |
||||
this.sortGroupPane = sortGroupPane; |
||||
} |
||||
|
||||
void init() { |
||||
uiButton = new UIButton(Toolkit.i18nText("Fine-Design_Sort_Add_Second_Sort"), |
||||
IconUtils.readIcon("/com/fr/design/images/sort/add.png")); |
||||
uiButton.setPreferredSize(new Dimension(sortGroupPaneWidth - 4, 20)); |
||||
this.add(uiButton); |
||||
uiButton.addActionListener(new ActionListener() { |
||||
public void actionPerformed(ActionEvent e) { |
||||
sortGroupPane.addSortItem(null, false); |
||||
} |
||||
}); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,153 @@
|
||||
package com.fr.design.sort.common; |
||||
|
||||
import com.fr.design.gui.icombobox.UIComboBox; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
|
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.design.sort.expressionpane.CellSortExpressionPane; |
||||
import com.fr.design.sort.expressionpane.CustomSequenceSortExpressionPane; |
||||
import com.fr.design.sort.expressionpane.FormulaSortExpressionPane; |
||||
import com.fr.design.sort.expressionpane.SortExpressionPane; |
||||
import com.fr.report.core.sort.sortexpression.SortExpression; |
||||
import com.fr.report.core.sort.common.SortRule; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.awt.event.ItemEvent; |
||||
import java.awt.event.ItemListener; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
public abstract class AbstractSortItemPane extends JPanel { |
||||
protected int sortItemPaneWidth; |
||||
protected int sortItemPaneRightWidth; |
||||
List<SortExpressionPane> sortExpressionPanes = new ArrayList<>(); |
||||
SortExpressionPane currentSortExpressionPane = null; |
||||
JPanel sortBasisPanel = null; |
||||
UIComboBox sortRuleUiComboBox; |
||||
UIComboBox sortBasisUiComboBox; |
||||
JPanel sortAreaPane; |
||||
JPanel sortRulePane; |
||||
|
||||
public AbstractSortItemPane(int sortItemPaneWidth, int sortItemPaneRightWidth) { |
||||
this.sortItemPaneWidth = sortItemPaneWidth; |
||||
this.sortItemPaneRightWidth = sortItemPaneRightWidth; |
||||
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
||||
registerSortExpressionPanes(); |
||||
initComponents(); |
||||
} |
||||
|
||||
private void initComponents() { |
||||
initSortAreaPane(); |
||||
initSortBasisPanel(); |
||||
initSortRulePane(); |
||||
} |
||||
|
||||
private void registerSortExpressionPanes() { |
||||
sortExpressionPanes.add(new CellSortExpressionPane(sortItemPaneRightWidth)); |
||||
sortExpressionPanes.add(new FormulaSortExpressionPane(sortItemPaneRightWidth)); |
||||
sortExpressionPanes.add(new CustomSequenceSortExpressionPane(sortItemPaneWidth, sortItemPaneRightWidth)); |
||||
} |
||||
|
||||
void initSortAreaPane() { |
||||
sortAreaPane = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, AbstractSortPane.PANE_COMPONENT_V_GAP)); |
||||
sortAreaPane.add(new UILabel(Toolkit.i18nText("Fine-Design_Sort_Sort_Area"), SwingConstants.LEFT)); |
||||
sortAreaPane.add(AbstractSortPane.createIntervalUILabel()); |
||||
initMainSortAreaPane(sortAreaPane); |
||||
this.add(sortAreaPane); |
||||
} |
||||
|
||||
public abstract void initMainSortAreaPane(JPanel sortAreaPane); |
||||
|
||||
void initSortRulePane() { |
||||
sortRulePane = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, AbstractSortPane.PANE_COMPONENT_V_GAP)); |
||||
sortRuleUiComboBox = new UIComboBox(new String[]{SortRule.ASC.getDescription(), |
||||
SortRule.DES.getDescription(), SortRule.NO_SORT.getDescription()}); |
||||
sortRuleUiComboBox.setPreferredSize(new Dimension(sortItemPaneRightWidth, AbstractSortPane.PANE_COMPONENT_HEIGHT)); |
||||
sortRulePane.add(new UILabel(Toolkit.i18nText("Fine-Design_Sort_Sort_Rule"), SwingConstants.LEFT)); |
||||
sortRulePane.add(AbstractSortPane.createIntervalUILabel()); |
||||
sortRulePane.add(sortRuleUiComboBox); |
||||
this.add(sortRulePane); |
||||
} |
||||
|
||||
void initSortBasisPanel() { |
||||
sortBasisPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, AbstractSortPane.PANE_COMPONENT_V_GAP)); |
||||
sortBasisUiComboBox = new UIComboBox(getSortNames()); |
||||
sortBasisUiComboBox.setPreferredSize(new Dimension(sortItemPaneRightWidth, AbstractSortPane.PANE_COMPONENT_HEIGHT)); |
||||
sortBasisUiComboBox.addItemListener(new ItemListener() { |
||||
@Override |
||||
public void itemStateChanged(ItemEvent e) { |
||||
if (sortExpressionPanes.get(sortBasisUiComboBox.getSelectedIndex()) != currentSortExpressionPane) { |
||||
if (currentSortExpressionPane != null) { |
||||
currentSortExpressionPane.setVisible(false); |
||||
} |
||||
currentSortExpressionPane = sortExpressionPanes.get(sortBasisUiComboBox.getSelectedIndex()); |
||||
refreshCurrentSortExpressionPane(); |
||||
} |
||||
} |
||||
}); |
||||
sortBasisPanel.add(new UILabel(Toolkit.i18nText("Fine-Design_Sort_Sort_Basis"), SwingConstants.LEFT)); |
||||
sortBasisPanel.add(AbstractSortPane.createIntervalUILabel()); |
||||
sortBasisPanel.add(sortBasisUiComboBox); |
||||
this.add(sortBasisPanel); |
||||
for (SortExpressionPane sortExpressionPane : sortExpressionPanes) { |
||||
this.add(sortExpressionPane); |
||||
sortExpressionPane.setVisible(false); |
||||
} |
||||
} |
||||
|
||||
private void refreshCurrentSortExpressionPane() { |
||||
currentSortExpressionPane.setVisible(true); |
||||
sortAreaPane.setVisible(currentSortExpressionPane.needSortArea()); |
||||
sortRulePane.setVisible(currentSortExpressionPane.needSortRule()); |
||||
} |
||||
|
||||
private String[] getSortNames() { |
||||
String[] sortNames = new String[sortExpressionPanes.size()]; |
||||
for (int i = 0; i < sortExpressionPanes.size(); i++) { |
||||
sortNames[i] = sortExpressionPanes.get(i).getSortName(); |
||||
} |
||||
return sortNames; |
||||
} |
||||
|
||||
public void populateBean(SortExpression sortExpression) { |
||||
if (sortExpression.getSortRule() == SortRule.ASC) { |
||||
sortRuleUiComboBox.setSelectedIndex(0); |
||||
} else if (sortExpression.getSortRule() == SortRule.DES) { |
||||
sortRuleUiComboBox.setSelectedIndex(1); |
||||
} else if (sortExpression.getSortRule() == SortRule.NO_SORT) { |
||||
sortRuleUiComboBox.setSelectedIndex(2); |
||||
} |
||||
for (int i = 0; i < sortExpressionPanes.size(); i++) { |
||||
if (StringUtils.equals(sortExpression.getSortName(), sortExpressionPanes.get(i).getSortName())) { |
||||
if (currentSortExpressionPane != null) { |
||||
currentSortExpressionPane.setVisible(false); |
||||
} |
||||
currentSortExpressionPane = sortExpressionPanes.get(i); |
||||
currentSortExpressionPane.populateBean(sortExpression); |
||||
sortBasisUiComboBox.setSelectedIndex(i); |
||||
refreshCurrentSortExpressionPane(); |
||||
break; |
||||
} |
||||
} |
||||
refresh(); |
||||
} |
||||
|
||||
public SortExpression updateBean() { |
||||
SortExpression sortExpression = currentSortExpressionPane.updateBean(); |
||||
if (sortExpression != null) { |
||||
String sortRule = sortRuleUiComboBox.getSelectedItem().toString(); |
||||
if (StringUtils.isNotBlank(sortRule)) { |
||||
sortExpression.setSortRule(SortRule.parse(sortRule)); |
||||
} |
||||
} |
||||
return sortExpression; |
||||
} |
||||
|
||||
protected void refresh() { |
||||
validate(); |
||||
repaint(); |
||||
revalidate(); |
||||
} |
||||
} |
@ -0,0 +1,103 @@
|
||||
package com.fr.design.sort.common; |
||||
|
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.sort.header.SortHeaderPane; |
||||
import com.fr.report.cell.TemplateCellElement; |
||||
import com.fr.report.core.sort.common.CellSortAttr; |
||||
import com.fr.report.core.sort.sortexpression.CellSortExpression; |
||||
import com.fr.report.core.sort.sortexpression.SortExpression; |
||||
import com.fr.report.core.sort.header.SortHeader; |
||||
import com.fr.stable.ColumnRow; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
|
||||
public abstract class AbstractSortPane extends JPanel { |
||||
protected int sortPaneWidth; |
||||
protected int sortPaneRightWidth; |
||||
public static final int PANE_COMPONENT_HEIGHT = 20; |
||||
public static final int PANE_COMPONENT_V_GAP = 4; |
||||
public static final int PANE_COMPONENT_H_GAP = 14; |
||||
protected AbstractSortGroupPane sortGroupPane; |
||||
protected SortHeaderPane sortHeaderPane; |
||||
protected String selfSortArea; |
||||
protected String defaultHeaderArea; |
||||
|
||||
public AbstractSortPane(int sortPaneWidth, int sortPaneRightWidth) { |
||||
this.sortPaneWidth = sortPaneWidth; |
||||
this.sortPaneRightWidth = sortPaneRightWidth; |
||||
initComponents(); |
||||
} |
||||
|
||||
private void initComponents() { |
||||
initSortGroupPane(); |
||||
sortHeaderPane = new SortHeaderPane(sortPaneWidth, sortPaneRightWidth + 5); |
||||
this.add(sortHeaderPane); |
||||
} |
||||
|
||||
protected abstract void initSortGroupPane(); |
||||
|
||||
|
||||
protected abstract CellSortAttr getCellSortAttr(TemplateCellElement cellElement); |
||||
|
||||
public void populateBean(TemplateCellElement cellElement) { |
||||
populateSortArea(cellElement); |
||||
List<SortExpression> sortExpressions = null; |
||||
CellSortAttr cellSortAttr = getCellSortAttr(cellElement); |
||||
if (cellSortAttr != null) { |
||||
sortExpressions = cellSortAttr.getSortExpressions(); |
||||
} |
||||
if (sortExpressions == null || sortExpressions.size() == 0) { |
||||
sortExpressions = new ArrayList<>(); |
||||
sortExpressions.add(new CellSortExpression(selfSortArea)); |
||||
} |
||||
sortGroupPane.populateBean(sortExpressions, selfSortArea); |
||||
SortHeader sortHeader = null; |
||||
if (cellSortAttr != null) { |
||||
sortHeader = cellSortAttr.getSortHeader(); |
||||
} |
||||
sortHeaderPane.populateBean(sortHeader, defaultHeaderArea); |
||||
refresh(); |
||||
} |
||||
|
||||
protected void populateSortArea(TemplateCellElement cellElement) { |
||||
int row = cellElement.getRow(); |
||||
int column = cellElement.getColumn(); |
||||
selfSortArea = ColumnRow.valueOf(column, row).toString(); |
||||
if (row > 1) { |
||||
defaultHeaderArea = ColumnRow.valueOf(column, row - 1).toString(); |
||||
} else { |
||||
defaultHeaderArea = null; |
||||
} |
||||
} |
||||
|
||||
public void updateBean(TemplateCellElement cellElement) { |
||||
List<SortExpression> sortExpressions = sortGroupPane.updateBean(); |
||||
SortHeader sortHeader = sortHeaderPane.updateBean(); |
||||
CellSortAttr cellSortAttr = getCellSortAttr(cellElement); |
||||
cellSortAttr.setSortExpressions(sortExpressions); |
||||
if (sortHeader != null) { |
||||
sortHeader.setSortArea(selfSortArea); |
||||
} |
||||
cellSortAttr.setSortHeader(sortHeader); |
||||
} |
||||
|
||||
protected void refresh() { |
||||
validate(); |
||||
repaint(); |
||||
revalidate(); |
||||
} |
||||
|
||||
public static UILabel createIntervalUILabel() { |
||||
return createIntervalUILabel(PANE_COMPONENT_H_GAP); |
||||
} |
||||
|
||||
public static UILabel createIntervalUILabel(int vGap) { |
||||
UILabel uiLabel = new UILabel(); |
||||
uiLabel.setPreferredSize(new Dimension(vGap, 10)); |
||||
return uiLabel; |
||||
} |
||||
} |
@ -0,0 +1,173 @@
|
||||
package com.fr.design.sort.common; |
||||
|
||||
import com.fr.base.svg.IconUtils; |
||||
import com.fr.design.designer.TargetComponent; |
||||
import com.fr.design.event.UIObserver; |
||||
import com.fr.design.event.UIObserverListener; |
||||
import com.fr.design.file.HistoryTemplateListCache; |
||||
import com.fr.design.gui.ibutton.UIButton; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.mainframe.ElementCasePane; |
||||
import com.fr.design.selection.SelectionEvent; |
||||
import com.fr.design.selection.SelectionListener; |
||||
import com.fr.grid.selection.CellSelection; |
||||
import com.fr.grid.selection.Selection; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.stable.ColumnRow; |
||||
import com.fr.stable.EssentialUtils; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.awt.event.ActionEvent; |
||||
import java.awt.event.ActionListener; |
||||
|
||||
public class SortColumnRowPane extends JPanel implements UIObserver { |
||||
int paneWidth; |
||||
int paneHeight; |
||||
int jTextFieldWidth; |
||||
JTextField colJTextField; |
||||
JTextField rowJTextField; |
||||
UIButton selectButton; |
||||
private boolean isAlreadyAddListener = false; |
||||
private CellSelection oldSelection; |
||||
private SelectionListener gridSelectionChangeListener; |
||||
UIObserverListener uiObserverListener; |
||||
|
||||
public SortColumnRowPane(int paneWidth, int paneHeight) { |
||||
this.paneWidth = paneWidth; |
||||
this.paneHeight = paneHeight; |
||||
initComponents(); |
||||
} |
||||
|
||||
private void initComponents() { |
||||
initSize(); |
||||
this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); |
||||
intUILabel(); |
||||
initTextField(); |
||||
initSelectButton(); |
||||
this.setSize(new Dimension(paneWidth, paneHeight)); |
||||
} |
||||
|
||||
void initSize() { |
||||
jTextFieldWidth = (paneWidth - 40) / 2; |
||||
} |
||||
|
||||
void intUILabel() { |
||||
UILabel uiLabel = new UILabel(IconUtils.readIcon("/com/fr/design/images/buttonicon/propertiestab/cellelement_normal.png")); |
||||
this.add(uiLabel); |
||||
} |
||||
|
||||
public static boolean isAvailableColumnRow(ColumnRow columnRow) { |
||||
return columnRow != null && columnRow.getRow() != -1 && columnRow.getColumn() != -1; |
||||
} |
||||
|
||||
void initTextField() { |
||||
colJTextField = new JTextField(); |
||||
colJTextField.setEditable(false); |
||||
rowJTextField = new JTextField(); |
||||
rowJTextField.setEditable(false); |
||||
colJTextField.setPreferredSize(new Dimension(jTextFieldWidth, paneHeight)); |
||||
rowJTextField.setPreferredSize(new Dimension(jTextFieldWidth, paneHeight)); |
||||
this.add(colJTextField); |
||||
this.add(rowJTextField); |
||||
} |
||||
|
||||
void initSelectButton() { |
||||
selectButton = new UIButton(IconUtils.readIcon("/com/fr/design/images/buttonicon/select.png")); |
||||
selectButton.addActionListener(new SelectActionListener(this)); |
||||
this.add(selectButton); |
||||
} |
||||
|
||||
public void populateBean(ColumnRow columnRow) { |
||||
if (SortColumnRowPane.isAvailableColumnRow(columnRow)) { |
||||
colJTextField.setText(EssentialUtils.convertIntToABC(columnRow.column + 1)); |
||||
rowJTextField.setText(String.valueOf(columnRow.row + 1)); |
||||
} else { |
||||
colJTextField.setText(StringUtils.EMPTY); |
||||
rowJTextField.setText(StringUtils.EMPTY); |
||||
} |
||||
refresh(); |
||||
} |
||||
|
||||
public void setColumnRow(ColumnRow columnRow){ |
||||
populateBean(columnRow); |
||||
uiObserverListener.doChange(); |
||||
} |
||||
|
||||
public ColumnRow updateBean() { |
||||
if (StringUtils.isNotBlank(colJTextField.getText()) && StringUtils.isNotBlank(rowJTextField.getText())) { |
||||
return ColumnRow.valueOf(colJTextField.getText() + rowJTextField.getText()); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public void registerChangeListener(UIObserverListener listener) { |
||||
this.uiObserverListener = listener; |
||||
} |
||||
|
||||
@Override |
||||
public boolean shouldResponseChangeListener() { |
||||
return true; |
||||
} |
||||
|
||||
class SelectActionListener implements ActionListener { |
||||
SortColumnRowPane columnRowPane; |
||||
|
||||
SelectActionListener(SortColumnRowPane columnRowPane) { |
||||
this.columnRowPane = columnRowPane; |
||||
} |
||||
|
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
ElementCasePane elementCasePane = getCurrentElementCase(); |
||||
if (elementCasePane == null || isAlreadyAddListener) { |
||||
return; |
||||
} |
||||
oldSelection = (CellSelection) elementCasePane.getSelection(); |
||||
elementCasePane.getGrid().setNotShowingTableSelectPane(false); |
||||
elementCasePane.setEditable(false); |
||||
elementCasePane.repaint(10); |
||||
|
||||
gridSelectionChangeListener = new SelectionListener() { |
||||
@Override |
||||
public void selectionChanged(SelectionEvent e) { |
||||
Selection selection = elementCasePane.getSelection(); |
||||
if (selection instanceof CellSelection) { |
||||
CellSelection cellselection = (CellSelection) selection; |
||||
ColumnRow cr = ColumnRow.valueOf(cellselection.getColumn(), cellselection.getRow()); |
||||
elementCasePane.setOldSelecton(oldSelection); |
||||
columnRowPane.setColumnRow(cr); |
||||
} |
||||
elementCasePane.removeSelectionChangeListener(gridSelectionChangeListener); |
||||
isAlreadyAddListener = false; |
||||
elementCasePane.getGrid().setNotShowingTableSelectPane(true); |
||||
elementCasePane.setEditable(true); |
||||
elementCasePane.repaint(); |
||||
} |
||||
}; |
||||
elementCasePane.addSelectionChangeListener(gridSelectionChangeListener); |
||||
isAlreadyAddListener = true; |
||||
} |
||||
} |
||||
|
||||
private ElementCasePane getCurrentElementCase() { |
||||
try { |
||||
TargetComponent targetComponent |
||||
= HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getCurrentElementCasePane(); |
||||
if (targetComponent instanceof ElementCasePane) { |
||||
return (ElementCasePane) targetComponent; |
||||
} |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e, e.getMessage()); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
protected void refresh() { |
||||
validate(); |
||||
repaint(); |
||||
revalidate(); |
||||
} |
||||
} |
@ -0,0 +1,100 @@
|
||||
package com.fr.design.sort.common; |
||||
|
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.base.svg.IconUtils; |
||||
import com.fr.design.gui.ibutton.UIButton; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.i18n.Toolkit; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.awt.event.MouseAdapter; |
||||
import java.awt.event.MouseEvent; |
||||
|
||||
|
||||
public class SortUIExpandablePane extends JPanel { |
||||
private static final long serialVersionUID = 1L; |
||||
private HeaderPane headerPane; |
||||
private AbstractSortItemPane contentPane; |
||||
private AbstractSortGroupPane sortGroupPane; |
||||
|
||||
private JPanel wrapPane; |
||||
|
||||
public JPanel getContentPane() { |
||||
return contentPane; |
||||
} |
||||
|
||||
public SortUIExpandablePane(AbstractSortItemPane contentPane, AbstractSortGroupPane sortGroupPane) { |
||||
super(); |
||||
this.sortGroupPane = sortGroupPane; |
||||
this.contentPane = contentPane; |
||||
initComponents(); |
||||
wrapPane.setBorder(BorderFactory.createLineBorder(Color.gray, 1)); |
||||
wrapPane.setBackground(Color.WHITE); |
||||
} |
||||
|
||||
|
||||
private void initComponents() { |
||||
wrapPane = new JPanel(); |
||||
wrapPane.setLayout(new BorderLayout()); |
||||
headerPane = new HeaderPane(sortGroupPane); |
||||
headerPane.addMouseListener(new MouseAdapter() { |
||||
@Override |
||||
public void mouseClicked(MouseEvent e) { |
||||
setContentPanelShow(!contentPane.isVisible()); |
||||
} |
||||
}); |
||||
headerPane.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.gray)); |
||||
contentPane.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); |
||||
wrapPane.add(headerPane, BorderLayout.NORTH); |
||||
wrapPane.add(contentPane, BorderLayout.CENTER); |
||||
setContentPanelShow(true); |
||||
this.add(wrapPane); |
||||
} |
||||
|
||||
|
||||
private void setContentPanelShow(Boolean show) { |
||||
contentPane.setVisible(show); |
||||
headerPane.setShow(show); |
||||
} |
||||
|
||||
class HeaderPane extends JPanel { |
||||
UILabel iconUiLabel; |
||||
UILabel closeButton; |
||||
AbstractSortGroupPane sortGroupPane; |
||||
|
||||
HeaderPane(AbstractSortGroupPane sortGroupPane) { |
||||
this.sortGroupPane = sortGroupPane; |
||||
this.setLayout(new FlowLayout(FlowLayout.LEFT, 3, 3)); |
||||
initComponents(); |
||||
} |
||||
|
||||
private void initComponents() { |
||||
iconUiLabel = new UILabel(); |
||||
this.add(iconUiLabel); |
||||
UILabel uiLabel = new UILabel(Toolkit.i18nText("Fine-Design_Sort_Second_Sort")); |
||||
this.add(uiLabel); |
||||
this.add(AbstractSortPane.createIntervalUILabel(114)); |
||||
|
||||
closeButton = new UILabel(IconUtils.readIcon("/com/fr/design/images/control/close.png")); |
||||
this.add(closeButton); |
||||
closeButton.addMouseListener(new MouseAdapter() { |
||||
@Override |
||||
public void mouseClicked(MouseEvent e) { |
||||
sortGroupPane.removeSortItem(1); |
||||
} |
||||
}); |
||||
this.setPreferredSize(new Dimension(contentPane.sortItemPaneWidth + 7, AbstractSortPane.PANE_COMPONENT_HEIGHT)); |
||||
} |
||||
|
||||
public void setShow(boolean show) { |
||||
if (show) { |
||||
iconUiLabel.setIcon(IconUtils.readIcon("/com/fr/design/images/sort/down_arrow.png")); |
||||
} else { |
||||
iconUiLabel.setIcon(IconUtils.readIcon("/com/fr/design/images/sort/left_arrow.png")); |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
@ -0,0 +1,32 @@
|
||||
package com.fr.design.sort.expressionpane; |
||||
|
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.locale.InterProviderFactory; |
||||
import com.fr.report.core.sort.sortexpression.CellSortExpression; |
||||
|
||||
|
||||
import java.awt.*; |
||||
|
||||
|
||||
public class CellSortExpressionPane extends SortExpressionPane<CellSortExpression> { |
||||
public CellSortExpressionPane(int with) { |
||||
this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); |
||||
} |
||||
|
||||
@Override |
||||
public String getSortName() { |
||||
return InterProviderFactory.getProvider().getLocText("Fine-Engine_Sort_Cell"); |
||||
} |
||||
|
||||
@Override |
||||
public void populateBean(CellSortExpression cellSortExpression) { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public CellSortExpression updateBean() { |
||||
return new CellSortExpression(); |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,160 @@
|
||||
package com.fr.design.sort.expressionpane; |
||||
|
||||
import com.fr.design.dialog.BasicPane; |
||||
import com.fr.design.gui.icontainer.UIScrollPane; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.gui.ilist.UIList; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.design.mainframe.dnd.SerializableTransferable; |
||||
import com.fr.design.mainframe.share.ui.base.PlaceholderTextArea; |
||||
import com.fr.locale.InterProviderFactory; |
||||
import com.fr.report.core.sort.sortexpression.CustomSequenceSortExpression; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.awt.datatransfer.DataFlavor; |
||||
import java.awt.datatransfer.Transferable; |
||||
import java.awt.dnd.DnDConstants; |
||||
import java.awt.dnd.DragGestureEvent; |
||||
import java.awt.dnd.DragGestureListener; |
||||
import java.awt.dnd.DragSource; |
||||
import java.awt.dnd.DragSourceAdapter; |
||||
import java.awt.dnd.DropTarget; |
||||
import java.awt.dnd.DropTargetAdapter; |
||||
import java.awt.dnd.DropTargetDropEvent; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
public class CustomSequenceEditPane extends BasicPane { |
||||
java.util.List<String> customSequence; |
||||
JPanel referenceSequencePanel; |
||||
JPanel editSequencePanel; |
||||
JTextArea jTextArea; |
||||
|
||||
CustomSequenceEditPane(java.util.List<String> customSequence) { |
||||
this.customSequence = customSequence; |
||||
initComponents(); |
||||
} |
||||
|
||||
void initComponents() { |
||||
this.setLayout(new BorderLayout()); |
||||
initReferenceSequencePanel(); |
||||
initEditSequencePanel(); |
||||
} |
||||
|
||||
void initReferenceSequencePanel() { |
||||
referenceSequencePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
||||
UILabel uiLabel = new UILabel(Toolkit.i18nText("Fine-Design_Sort_Reference_Sequence")); |
||||
referenceSequencePanel.add(uiLabel); |
||||
UIScrollPane uiScrollPane = new UIScrollPane(getReferenceSequenceList()); |
||||
uiScrollPane.setPreferredSize(new Dimension(200, 300)); |
||||
referenceSequencePanel.add(uiScrollPane); |
||||
referenceSequencePanel.setPreferredSize(new Dimension(200, 400)); |
||||
this.add(referenceSequencePanel, BorderLayout.WEST); |
||||
} |
||||
|
||||
private UIList getReferenceSequenceList() { |
||||
UIList uiList = new UIList(getReferenceSequenceModel()); |
||||
new CustomSequenceEditDragSource(uiList, DnDConstants.ACTION_MOVE); |
||||
return uiList; |
||||
} |
||||
|
||||
private String[] getReferenceSequenceModel() { |
||||
List<List<String>> customSequences = CustomSequenceSortExpression.getReferenceCustomSequences(); |
||||
String[] listModel = new String[customSequences.size()]; |
||||
for (int i = 0; i < customSequences.size(); i++) { |
||||
listModel[i] = CustomSequenceSortExpression.customSequenceToString(customSequences.get(i), ","); |
||||
} |
||||
return listModel; |
||||
} |
||||
|
||||
void initEditSequencePanel() { |
||||
editSequencePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
||||
UILabel uiLabel = new UILabel(Toolkit.i18nText("Fine-Design_Sort_Input_Sequence")); |
||||
editSequencePanel.add(uiLabel); |
||||
UILabel uiLabel2 = new UILabel(Toolkit.i18nText("Fine-Design_Sort_Please_Interlace_Sequence_Elements")); |
||||
uiLabel2.setForeground(Color.lightGray); |
||||
editSequencePanel.add(uiLabel2); |
||||
jTextArea = getTextArea(); |
||||
UIScrollPane uiScrollPane = new UIScrollPane(jTextArea); |
||||
uiScrollPane.setPreferredSize(new Dimension(475, 300)); |
||||
editSequencePanel.add(uiScrollPane); |
||||
this.add(editSequencePanel, BorderLayout.CENTER); |
||||
|
||||
} |
||||
|
||||
|
||||
JTextArea getTextArea() { |
||||
PlaceholderTextArea placeholderTextArea = new PlaceholderTextArea(10, 10, getPlaceholderText()); |
||||
new CustomSequenceEditDropTarget(placeholderTextArea, CustomSequenceSortExpression.getReferenceCustomSequences()); |
||||
placeholderTextArea.setText(CustomSequenceSortExpression.customSequenceToString(customSequence, "\n")); |
||||
return placeholderTextArea; |
||||
} |
||||
|
||||
String getPlaceholderText() { |
||||
StringBuilder stringBuilder = new StringBuilder(); |
||||
stringBuilder.append(Toolkit.i18nText("Fine-Design_Sort_Please_Interlace_Sequence_Elements_Such_As") + "\n"); |
||||
stringBuilder.append(Toolkit.i18nText("Fine-Design_Sort_Department_One") + "\n"); |
||||
stringBuilder.append(Toolkit.i18nText("Fine-Design_Sort_Department_Two") + "\n"); |
||||
stringBuilder.append(Toolkit.i18nText("Fine-Design_Sort_Department_Three") + "\n"); |
||||
return stringBuilder.toString(); |
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return InterProviderFactory.getProvider().getLocText("Fine-Engine_Sort_Custom_Sequence"); |
||||
} |
||||
|
||||
|
||||
class CustomSequenceEditDragSource extends DragSourceAdapter implements DragGestureListener { |
||||
private DragSource source; |
||||
|
||||
public CustomSequenceEditDragSource(UIList uiList, int actions) { |
||||
source = new DragSource(); |
||||
source.createDefaultDragGestureRecognizer(uiList, actions, this); |
||||
} |
||||
|
||||
public void dragGestureRecognized(DragGestureEvent dge) { |
||||
Component comp = dge.getComponent(); |
||||
if (comp instanceof UIList) { |
||||
UIList uiList = (UIList) comp; |
||||
source.startDrag(dge, DragSource.DefaultLinkDrop, new SerializableTransferable(uiList.getSelectedIndex()), this); |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
class CustomSequenceEditDropTarget extends DropTargetAdapter { |
||||
java.util.List<java.util.List<String>> customSequences = new ArrayList<>(); |
||||
|
||||
public CustomSequenceEditDropTarget(PlaceholderTextArea jPanel, java.util.List<java.util.List<String>> customSequences) { |
||||
new DropTarget(jPanel, this); |
||||
this.customSequences = customSequences; |
||||
} |
||||
|
||||
@Override |
||||
public void drop(DropTargetDropEvent dtde) { |
||||
try { |
||||
Transferable transferable = dtde.getTransferable(); |
||||
DataFlavor[] dataFlavors = transferable.getTransferDataFlavors(); |
||||
if (dataFlavors.length == 1) { |
||||
Integer index = (Integer) transferable.getTransferData(dataFlavors[0]); |
||||
String text = ""; |
||||
java.util.List<String> customSequence = customSequences.get(index); |
||||
for (int i = 0; i < customSequence.size(); i++) { |
||||
text += customSequence.get(i) + "\n"; |
||||
} |
||||
JTextArea jTextArea = (JTextArea) dtde.getDropTargetContext().getComponent(); |
||||
jTextArea.setText(text); |
||||
} |
||||
} catch (Exception e) { |
||||
|
||||
} |
||||
} |
||||
} |
||||
|
||||
public List<String> updateBean() { |
||||
return CustomSequenceSortExpression.stringToCustomSequence(jTextArea.getText(), "\n"); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,66 @@
|
||||
package com.fr.design.sort.expressionpane; |
||||
|
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.base.svg.IconUtils; |
||||
import com.fr.design.dialog.DialogActionAdapter; |
||||
import com.fr.design.gui.ibutton.UIButton; |
||||
import com.fr.design.gui.itextfield.UITextField; |
||||
import com.fr.design.mainframe.DesignerContext; |
||||
import com.fr.design.sort.common.AbstractSortPane; |
||||
import com.fr.report.core.sort.sortexpression.CustomSequenceSortExpression; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.awt.event.ActionEvent; |
||||
import java.awt.event.ActionListener; |
||||
import java.util.List; |
||||
|
||||
|
||||
public class CustomSequencePane extends JPanel { |
||||
protected UITextField textField; |
||||
protected UIButton button; |
||||
List<String> customSequence; |
||||
|
||||
public CustomSequencePane(int width) { |
||||
this.setLayout(new FlowLayout(FlowLayout.RIGHT, 0, 0)); |
||||
this.initComponents(width); |
||||
} |
||||
|
||||
protected void initComponents(int width) { |
||||
textField = new UITextField(); |
||||
textField.setEditable(false); |
||||
textField.setPreferredSize(new Dimension(width - 20, 20)); |
||||
Icon icon = IconUtils.readIcon("/com/fr/design/images/control/refresh.png"); |
||||
button = new UIButton(icon); |
||||
button.setBackground(Color.RED); |
||||
button.setPreferredSize(new Dimension(24, 20)); |
||||
button.setOpaque(false); |
||||
button.setCursor(new Cursor(Cursor.HAND_CURSOR)); |
||||
button.addActionListener(new ActionListener() { |
||||
public void actionPerformed(ActionEvent evt) { |
||||
CustomSequenceEditPane customSequenceEditPane = new CustomSequenceEditPane(customSequence); |
||||
customSequenceEditPane.showWindowWithCustomSize(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { |
||||
@Override |
||||
public void doOk() { |
||||
customSequence = customSequenceEditPane.updateBean(); |
||||
textField.setText(CustomSequenceSortExpression.customSequenceToString(customSequence, ",")); |
||||
} |
||||
}, new Dimension(700, 400)).setVisible(true); |
||||
} |
||||
}); |
||||
button.setPreferredSize(new Dimension(24, AbstractSortPane.PANE_COMPONENT_HEIGHT)); |
||||
|
||||
this.add(textField); |
||||
this.add(button); |
||||
} |
||||
|
||||
|
||||
public List<String> updateBean() { |
||||
return customSequence; |
||||
} |
||||
|
||||
public void populateBean(List<String> customSequence) { |
||||
this.customSequence = customSequence; |
||||
textField.setText(CustomSequenceSortExpression.customSequenceToString(customSequence, ",")); |
||||
} |
||||
} |
@ -0,0 +1,39 @@
|
||||
package com.fr.design.sort.expressionpane; |
||||
|
||||
import com.fr.design.sort.common.AbstractSortPane; |
||||
import com.fr.locale.InterProviderFactory; |
||||
import com.fr.report.core.sort.sortexpression.CustomSequenceSortExpression; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.util.List; |
||||
|
||||
|
||||
public class CustomSequenceSortExpressionPane extends SortExpressionPane<CustomSequenceSortExpression> { |
||||
CustomSequencePane customSequencePane; |
||||
|
||||
public CustomSequenceSortExpressionPane(int width, int rightWidth) { |
||||
this.setLayout(new FlowLayout(FlowLayout.RIGHT, 0, 0)); |
||||
customSequencePane = new CustomSequencePane(rightWidth); |
||||
customSequencePane.setPreferredSize(new Dimension(width, AbstractSortPane.PANE_COMPONENT_HEIGHT)); |
||||
customSequencePane.setBorder(BorderFactory.createEmptyBorder(0,0,0,3)); |
||||
this.add(customSequencePane); |
||||
} |
||||
|
||||
@Override |
||||
public String getSortName() { |
||||
return InterProviderFactory.getProvider().getLocText("Fine-Engine_Sort_Custom_Sequence"); |
||||
} |
||||
|
||||
@Override |
||||
public void populateBean(CustomSequenceSortExpression customSequenceSortExpression) { |
||||
List<String> customSequence = customSequenceSortExpression.getCustomSequence(); |
||||
customSequencePane.populateBean(customSequence); |
||||
} |
||||
|
||||
@Override |
||||
public CustomSequenceSortExpression updateBean() { |
||||
List<String> customSequence = customSequencePane.updateBean(); |
||||
return new CustomSequenceSortExpression(customSequence); |
||||
} |
||||
} |
@ -0,0 +1,42 @@
|
||||
package com.fr.design.sort.expressionpane; |
||||
|
||||
import com.fr.design.formula.TinyFormulaPane; |
||||
import com.fr.design.sort.common.AbstractSortPane; |
||||
import com.fr.locale.InterProviderFactory; |
||||
import com.fr.report.core.sort.sortexpression.FormulaSortExpression; |
||||
|
||||
import java.awt.*; |
||||
|
||||
public class FormulaSortExpressionPane extends SortExpressionPane<FormulaSortExpression> { |
||||
|
||||
TinyFormulaPane tinyFormulaPane; |
||||
|
||||
public FormulaSortExpressionPane(int width) { |
||||
this.setLayout(new FlowLayout(FlowLayout.RIGHT, 0, 1)); |
||||
tinyFormulaPane = new TinyFormulaPane(); |
||||
tinyFormulaPane.setPreferredSize(new Dimension(width, AbstractSortPane.PANE_COMPONENT_HEIGHT)); |
||||
this.add(tinyFormulaPane); |
||||
} |
||||
|
||||
@Override |
||||
public String getSortName() { |
||||
return InterProviderFactory.getProvider().getLocText("Fine-Engine_Sort_Formula"); |
||||
} |
||||
|
||||
@Override |
||||
public void populateBean(FormulaSortExpression formulaSortExpression) { |
||||
String formula = formulaSortExpression.getFormula(); |
||||
tinyFormulaPane.getUITextField().setText(formula); |
||||
} |
||||
|
||||
@Override |
||||
public FormulaSortExpression updateBean() { |
||||
String formula = tinyFormulaPane.getUITextField().getText(); |
||||
return new FormulaSortExpression(formula); |
||||
} |
||||
|
||||
public boolean needSortArea() { |
||||
return false; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,23 @@
|
||||
package com.fr.design.sort.expressionpane; |
||||
|
||||
import com.fr.report.core.sort.sortexpression.SortExpression; |
||||
|
||||
import javax.swing.*; |
||||
|
||||
|
||||
public abstract class SortExpressionPane<T extends SortExpression> extends JPanel { |
||||
|
||||
public abstract String getSortName(); |
||||
|
||||
public abstract void populateBean(T sortExpression); |
||||
|
||||
public abstract T updateBean(); |
||||
|
||||
public boolean needSortArea() { |
||||
return true; |
||||
} |
||||
|
||||
public boolean needSortRule() { |
||||
return true; |
||||
} |
||||
} |
@ -0,0 +1,125 @@
|
||||
package com.fr.design.sort.header; |
||||
|
||||
import com.fr.design.gui.icombobox.UIComboBox; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.design.sort.common.AbstractSortPane; |
||||
import com.fr.design.sort.common.SortColumnRowPane; |
||||
import com.fr.stable.ColumnRow; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.awt.event.ItemEvent; |
||||
import java.awt.event.ItemListener; |
||||
|
||||
|
||||
public class HeaderAreaPane extends JPanel { |
||||
protected int headerAreaPaneWidth; |
||||
protected int headerAreaPaneRightWidth; |
||||
|
||||
AreaJLayeredPane areaJLayeredPane; |
||||
|
||||
HeaderAreaPane(int headerAreaPaneWidth, int headerAreaPaneRightWidth) { |
||||
this.headerAreaPaneWidth = headerAreaPaneWidth; |
||||
this.headerAreaPaneRightWidth = headerAreaPaneRightWidth; |
||||
this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); |
||||
initComponents(); |
||||
} |
||||
|
||||
void initComponents() { |
||||
initUILabel(); |
||||
initLayeredPane(); |
||||
} |
||||
|
||||
void initUILabel() { |
||||
UILabel uiLabel = new UILabel(Toolkit.i18nText("Fine-Design_Sort_Header_Area"), SwingConstants.LEFT); |
||||
this.add(uiLabel); |
||||
this.add(AbstractSortPane.createIntervalUILabel()); |
||||
} |
||||
|
||||
void initLayeredPane() { |
||||
areaJLayeredPane = new AreaJLayeredPane(); |
||||
this.add(areaJLayeredPane); |
||||
} |
||||
|
||||
public void populateBean(ColumnRow columnRow) { |
||||
areaJLayeredPane.populateBean(columnRow); |
||||
} |
||||
|
||||
public ColumnRow updateBean() { |
||||
return areaJLayeredPane.updateBean(); |
||||
} |
||||
|
||||
class AreaJLayeredPane extends JPanel { |
||||
SortColumnRowPane columnRowPane; |
||||
JLayeredPane jLayeredPane; |
||||
UIComboBox uiComboBox; |
||||
|
||||
AreaJLayeredPane() { |
||||
this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); |
||||
initComponents(); |
||||
} |
||||
|
||||
private void initComponents() { |
||||
initUIComboBox(); |
||||
initJLayeredPane(); |
||||
} |
||||
|
||||
|
||||
void initUIComboBox() { |
||||
uiComboBox = new UIComboBox(new String[]{Toolkit.i18nText("Fine-Design_Basic_None"), Toolkit.i18nText("Fine-Design_Basic_Custom")}); |
||||
uiComboBox.setSize(new Dimension(headerAreaPaneRightWidth, AbstractSortPane.PANE_COMPONENT_HEIGHT)); |
||||
uiComboBox.addItemListener(new ItemListener() { |
||||
@Override |
||||
public void itemStateChanged(ItemEvent e) { |
||||
setSortColumnRowPaneShow(uiComboBox.getSelectedIndex() == 1); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
void setSortColumnRowPaneShow(boolean show) { |
||||
if (show) { |
||||
jLayeredPane.setLayer(columnRowPane, JLayeredPane.POPUP_LAYER); |
||||
jLayeredPane.setLayer(uiComboBox, JLayeredPane.MODAL_LAYER); |
||||
} else { |
||||
jLayeredPane.setLayer(uiComboBox, JLayeredPane.POPUP_LAYER); |
||||
jLayeredPane.setLayer(columnRowPane, JLayeredPane.MODAL_LAYER); |
||||
} |
||||
refresh(); |
||||
} |
||||
|
||||
void initJLayeredPane() { |
||||
jLayeredPane = new JLayeredPane(); |
||||
columnRowPane = new SortColumnRowPane(headerAreaPaneRightWidth - 18, AbstractSortPane.PANE_COMPONENT_HEIGHT); |
||||
jLayeredPane.setPreferredSize(new Dimension(headerAreaPaneRightWidth, AbstractSortPane.PANE_COMPONENT_HEIGHT)); |
||||
jLayeredPane.add(columnRowPane, JLayeredPane.MODAL_LAYER); |
||||
jLayeredPane.add(uiComboBox, JLayeredPane.POPUP_LAYER); |
||||
this.add(jLayeredPane); |
||||
} |
||||
|
||||
public void populateBean(ColumnRow columnRow) { |
||||
if (SortColumnRowPane.isAvailableColumnRow(columnRow)) { |
||||
uiComboBox.setSelectedIndex(1); |
||||
} else { |
||||
uiComboBox.setSelectedIndex(0); |
||||
} |
||||
columnRowPane.populateBean(columnRow); |
||||
setSortColumnRowPaneShow(uiComboBox.getSelectedIndex() == 1); |
||||
} |
||||
|
||||
public ColumnRow updateBean() { |
||||
if (uiComboBox.getSelectedIndex() == 0) { |
||||
return null; |
||||
} else { |
||||
return columnRowPane.updateBean(); |
||||
} |
||||
} |
||||
|
||||
public void refresh() { |
||||
validate(); |
||||
repaint(); |
||||
revalidate(); |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,81 @@
|
||||
package com.fr.design.sort.header; |
||||
|
||||
import com.fr.design.gui.icheckbox.UICheckBox; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.design.sort.common.AbstractSortPane; |
||||
import com.fr.report.core.sort.header.SortHeader; |
||||
|
||||
import javax.swing.*; |
||||
import javax.swing.event.ChangeEvent; |
||||
import javax.swing.event.ChangeListener; |
||||
import java.awt.*; |
||||
|
||||
public class HeaderSettingPane extends JPanel { |
||||
protected int headerSettingPaneWidth; |
||||
protected int headerSettingPaneRightWidth; |
||||
HeaderSortRulePane headerSortRulePane; |
||||
UICheckBox uiCheckBox; |
||||
|
||||
HeaderSettingPane(int headerSettingPaneWidth, int headerSettingPaneRightWidth) { |
||||
this.headerSettingPaneWidth = headerSettingPaneWidth; |
||||
this.headerSettingPaneRightWidth = headerSettingPaneRightWidth; |
||||
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
||||
initComponents(); |
||||
} |
||||
|
||||
void initComponents() { |
||||
initUILabel(); |
||||
initHeaderSortRulePane(); |
||||
} |
||||
|
||||
void initUILabel() { |
||||
JPanel jPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 2)); |
||||
UILabel uiLabel = new UILabel(Toolkit.i18nText("Fine-Design_Sort_Header_Setting")); |
||||
UILabel emptyUILabel = new UILabel(); |
||||
emptyUILabel.setPreferredSize(new Dimension(10, 10)); |
||||
|
||||
uiCheckBox = new UICheckBox(Toolkit.i18nText("Fine-Design_Sort_Allow_User_Click_Sort_Order")); |
||||
uiCheckBox.setPreferredSize(new Dimension(headerSettingPaneRightWidth - 10, AbstractSortPane.PANE_COMPONENT_HEIGHT)); |
||||
uiCheckBox.addChangeListener(new ChangeListener() { |
||||
@Override |
||||
public void stateChanged(ChangeEvent e) { |
||||
headerSortRulePane.setVisible(uiCheckBox.isSelected()); |
||||
} |
||||
}); |
||||
jPanel.add(uiLabel); |
||||
jPanel.add(emptyUILabel); |
||||
jPanel.add(uiCheckBox); |
||||
this.add(jPanel); |
||||
} |
||||
|
||||
void initHeaderSortRulePane() { |
||||
headerSortRulePane = new HeaderSortRulePane(); |
||||
this.add(headerSortRulePane); |
||||
headerSortRulePane.setVisible(false); |
||||
} |
||||
|
||||
protected void refresh() { |
||||
validate(); |
||||
repaint(); |
||||
revalidate(); |
||||
} |
||||
|
||||
public void populateBean(SortHeader.SortItem[] sortItems) { |
||||
if (sortItems == null) { |
||||
uiCheckBox.setSelected(false); |
||||
} else { |
||||
uiCheckBox.setSelected(true); |
||||
} |
||||
headerSortRulePane.populateBean(sortItems); |
||||
} |
||||
|
||||
public SortHeader.SortItem[] updateBean() { |
||||
if (uiCheckBox.isSelected()) { |
||||
return headerSortRulePane.updateBean(); |
||||
} else { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,234 @@
|
||||
package com.fr.design.sort.header; |
||||
|
||||
import com.fr.base.svg.SVGIcon; |
||||
import com.fr.base.svg.SVGTranscoder; |
||||
import com.fr.design.event.UIObserver; |
||||
import com.fr.design.event.UIObserverListener; |
||||
import com.fr.design.gui.icheckbox.UICheckBox; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.design.layout.TableLayoutHelper; |
||||
import com.fr.design.mainframe.theme.edit.ui.ColorListPane; |
||||
import com.fr.general.IOUtils; |
||||
import com.fr.report.core.sort.header.SortHeader; |
||||
import com.fr.report.core.sort.common.SortRule; |
||||
import org.apache.batik.transcoder.TranscoderInput; |
||||
|
||||
import javax.swing.*; |
||||
import javax.swing.event.ChangeEvent; |
||||
import javax.swing.event.ChangeListener; |
||||
import java.awt.*; |
||||
import java.awt.image.BufferedImage; |
||||
import java.io.ByteArrayInputStream; |
||||
import java.io.InputStream; |
||||
import java.util.ArrayList; |
||||
|
||||
public class HeaderSortRulePane extends JPanel { |
||||
private static final String ASC_ICON_TEMPLATE_PATH = "/com/fr/design/images/sort/asc.svg"; |
||||
private static final String DES_ICON_TEMPLATE_PATH = "/com/fr/design/images/sort/des.svg"; |
||||
private static final String NOSORT_ICON_TEMPLATE_PATH = "/com/fr/design/images/sort/nosort.svg"; |
||||
IconButton ascIconButton; |
||||
IconButton desIconButton; |
||||
IconButton nosortIconButton; |
||||
UICheckBox ascUICheckBox; |
||||
UICheckBox desUICheckBox; |
||||
UICheckBox nosortUICheckBox; |
||||
|
||||
HeaderSortRulePane() { |
||||
initComponents(); |
||||
initState(); |
||||
this.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 15)); |
||||
} |
||||
|
||||
void initComponents() { |
||||
this.setLayout(new BorderLayout()); |
||||
initUILabel(); |
||||
initSortRuleItem(); |
||||
this.setPreferredSize(new Dimension(160, 160)); |
||||
} |
||||
|
||||
void initUILabel() { |
||||
UILabel uiLabel = new UILabel(Toolkit.i18nText("Fine-Design_Sort_Header_Sort_Basis"), SwingConstants.LEFT); |
||||
this.add(uiLabel, BorderLayout.NORTH); |
||||
} |
||||
|
||||
void initSortRuleItem() { |
||||
Component[][] components = new Component[][]{ |
||||
new Component[]{ascUICheckBox = new UICheckBox(SortRule.ASC.getDescription()), ascIconButton = new IconButton(ASC_ICON_TEMPLATE_PATH)}, |
||||
new Component[]{desUICheckBox = new UICheckBox(SortRule.DES.getDescription()), desIconButton = new IconButton(DES_ICON_TEMPLATE_PATH)}, |
||||
new Component[]{nosortUICheckBox = new UICheckBox(SortRule.NO_SORT.getDescription()), nosortIconButton = new IconButton(NOSORT_ICON_TEMPLATE_PATH)}, |
||||
}; |
||||
double[] rowSize = {24, 24, 24}; |
||||
double[] columnSize = {80, 30}; |
||||
JPanel sortRuleItem = TableLayoutHelper.createCommonTableLayoutPane(components, rowSize, columnSize, 0); |
||||
this.add(sortRuleItem, BorderLayout.CENTER); |
||||
} |
||||
|
||||
void initState() { |
||||
ascUICheckBox.setSelected(false); |
||||
desUICheckBox.setSelected(false); |
||||
nosortUICheckBox.setSelected(false); |
||||
ascIconButton.refreshIconLabelColor(new Color(33, 33, 34)); |
||||
desIconButton.refreshIconLabelColor(new Color(33, 33, 34)); |
||||
nosortIconButton.refreshIconLabelColor(new Color(33, 33, 34)); |
||||
} |
||||
|
||||
class IconButton extends JPanel implements UIObserver { |
||||
JLayeredPane jLayeredPane; |
||||
String iconTemplatePath; |
||||
UILabel iconLabel; |
||||
ColorListPane.ColorButton colorButton; |
||||
Color color; |
||||
BufferedImage bufferedImage; |
||||
UIObserverListener uiObserverListener; |
||||
|
||||
IconButton(String iconTemplatePath) { |
||||
this.iconTemplatePath = iconTemplatePath; |
||||
initComponents(); |
||||
} |
||||
|
||||
void initComponents() { |
||||
jLayeredPane = new JLayeredPane(); |
||||
iconLabel = getIconLabel(iconTemplatePath); |
||||
|
||||
|
||||
UILabel emptyUiLabel = new UILabel(); |
||||
emptyUiLabel.setSize(16, 16); |
||||
emptyUiLabel.setOpaque(true); |
||||
emptyUiLabel.setBackground(Color.WHITE); |
||||
iconLabel.setSize(16, 16); |
||||
colorButton = new ColorListPane.ColorButton(Color.CYAN); |
||||
colorButton.setSize(16, 16); |
||||
colorButton.addChangeListener(new ChangeListener() { |
||||
@Override |
||||
public void stateChanged(ChangeEvent e) { |
||||
color = colorButton.getSelectObject(); |
||||
refreshIconLabelColor(color); |
||||
uiObserverListener.doChange(); |
||||
} |
||||
}); |
||||
jLayeredPane.setPreferredSize(new Dimension(16, 16)); |
||||
|
||||
jLayeredPane.add(iconLabel, JLayeredPane.POPUP_LAYER); |
||||
jLayeredPane.add(emptyUiLabel, JLayeredPane.MODAL_LAYER); |
||||
jLayeredPane.add(colorButton, JLayeredPane.PALETTE_LAYER); |
||||
this.add(jLayeredPane); |
||||
} |
||||
|
||||
void refreshIconLabelColor(Color color) { |
||||
Icon icon = getIcon(iconTemplatePath, color); |
||||
refreshIconLabel(icon); |
||||
} |
||||
|
||||
void refreshIconLabel(Icon icon) { |
||||
if (icon != null) { |
||||
iconLabel.removeAll(); |
||||
iconLabel.setIcon(icon); |
||||
iconLabel.repaint(); |
||||
} |
||||
} |
||||
|
||||
UILabel getIconLabel(String iconPath) { |
||||
return getIconLabel(iconPath, new Color(33, 33, 34)); |
||||
} |
||||
|
||||
UILabel getIconLabel(String iconPath, Color color) { |
||||
Icon svgIcon = getIcon(iconPath, color); |
||||
return new UILabel(svgIcon); |
||||
} |
||||
|
||||
Icon getIcon(String iconPath, Color color) { |
||||
try { |
||||
InputStream inputStream = IOUtils.getResourceAsStream(iconPath, HeaderSortRulePane.class); |
||||
String svgText = getSvgText(inputStream); |
||||
svgText = svgText.replaceAll("\\{fillColor\\}", shiftColor(color)); |
||||
InputStream svgInputStream = new ByteArrayInputStream(svgText.getBytes()); |
||||
TranscoderInput input = new TranscoderInput(svgInputStream); |
||||
bufferedImage = SVGTranscoder.createImage(1.0, input).getImage(); |
||||
SVGIcon svgIcon = new SVGIcon(bufferedImage); |
||||
return svgIcon; |
||||
} catch (Exception e) { |
||||
|
||||
} |
||||
return null; |
||||
|
||||
} |
||||
|
||||
String shiftColor(Color color) { |
||||
StringBuilder stringBuilder = new StringBuilder(); |
||||
stringBuilder.append(shiftValue(color.getRed())); |
||||
stringBuilder.append(shiftValue(color.getGreen())); |
||||
stringBuilder.append(shiftValue(color.getBlue())); |
||||
return stringBuilder.toString(); |
||||
} |
||||
|
||||
String shiftValue(int value) { |
||||
int resultValue = (int) ((((float) value) / 255) * 99); |
||||
if (resultValue < 10) { |
||||
return "0" + resultValue; |
||||
} else { |
||||
return "" + resultValue; |
||||
} |
||||
} |
||||
|
||||
private String getSvgText(InputStream inputStream) throws Exception { |
||||
StringBuffer stringBuffer = new StringBuffer(); |
||||
byte[] b = new byte[1024]; |
||||
for (int n; (n = inputStream.read(b)) != -1; ) { |
||||
stringBuffer.append(new String(b, 0, n)); |
||||
} |
||||
return stringBuffer.toString(); |
||||
} |
||||
|
||||
@Override |
||||
public void registerChangeListener(UIObserverListener uiObserverListener) { |
||||
this.uiObserverListener = uiObserverListener; |
||||
} |
||||
|
||||
@Override |
||||
public boolean shouldResponseChangeListener() { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
public void populateBean(SortHeader.SortItem[] sortItems) { |
||||
initState(); |
||||
if (sortItems != null) { |
||||
for (SortHeader.SortItem sortItem : sortItems) { |
||||
SortRule sortRule = sortItem.getSortRule(); |
||||
BufferedImage bufferedImage = sortItem.getBufferedImage(); |
||||
Icon icon = null; |
||||
if (bufferedImage != null) { |
||||
icon = new SVGIcon(bufferedImage); |
||||
} |
||||
if (sortRule == SortRule.ASC) { |
||||
ascIconButton.refreshIconLabel(icon); |
||||
ascUICheckBox.setSelected(true); |
||||
} else if (sortRule == SortRule.DES) { |
||||
desIconButton.refreshIconLabel(icon); |
||||
desUICheckBox.setSelected(true); |
||||
} else if (sortRule == SortRule.NO_SORT) { |
||||
nosortIconButton.refreshIconLabel(icon); |
||||
nosortUICheckBox.setSelected(true); |
||||
} |
||||
|
||||
} |
||||
} |
||||
} |
||||
|
||||
public SortHeader.SortItem[] updateBean() { |
||||
java.util.List<SortHeader.SortItem> items = new ArrayList<>(); |
||||
if (ascUICheckBox.isSelected()) { |
||||
items.add(new SortHeader.SortItem(SortRule.ASC, ascIconButton.bufferedImage)); |
||||
} |
||||
if (desUICheckBox.isSelected()) { |
||||
items.add(new SortHeader.SortItem(SortRule.DES, desIconButton.bufferedImage)); |
||||
} |
||||
if (nosortUICheckBox.isSelected()) { |
||||
items.add(new SortHeader.SortItem(SortRule.NO_SORT, nosortIconButton.bufferedImage)); |
||||
} |
||||
SortHeader.SortItem[] resultItems = new SortHeader.SortItem[items.size()]; |
||||
return items.toArray(resultItems); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,59 @@
|
||||
package com.fr.design.sort.header; |
||||
|
||||
import com.fr.report.core.sort.header.SortHeader; |
||||
import com.fr.stable.ColumnRow; |
||||
|
||||
import javax.swing.*; |
||||
|
||||
public class SortHeaderPane extends JPanel { |
||||
int sortHeaderPaneWidth; |
||||
int sortHeaderPaneRightWidth; |
||||
SortHeader sortHeader; |
||||
HeaderAreaPane headerAreaPane; |
||||
HeaderSettingPane headerSettingPane; |
||||
|
||||
public SortHeaderPane(int sortHeaderPaneWidth, int sortHeaderPaneRightWidth) { |
||||
this.sortHeaderPaneWidth = sortHeaderPaneWidth; |
||||
this.sortHeaderPaneRightWidth = sortHeaderPaneRightWidth; |
||||
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
||||
initHeaderArea(); |
||||
initHeaderSetting(); |
||||
this.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); |
||||
} |
||||
|
||||
void initHeaderArea() { |
||||
this.headerAreaPane = new HeaderAreaPane(sortHeaderPaneWidth, sortHeaderPaneRightWidth); |
||||
this.add(headerAreaPane); |
||||
} |
||||
|
||||
void initHeaderSetting() { |
||||
this.headerSettingPane = new HeaderSettingPane(sortHeaderPaneWidth, sortHeaderPaneRightWidth); |
||||
this.add(headerSettingPane); |
||||
} |
||||
|
||||
public void populateBean(SortHeader sortHeader, String defaultHeaderArea) { |
||||
this.sortHeader = sortHeader; |
||||
ColumnRow columnRow = null; |
||||
SortHeader.SortItem[] sortItems = null; |
||||
String headerArea = defaultHeaderArea; |
||||
if (sortHeader != null) { |
||||
headerArea = sortHeader.getHeaderArea(); |
||||
sortItems = sortHeader.getSortItems(); |
||||
} |
||||
columnRow = ColumnRow.valueOf(headerArea); |
||||
|
||||
headerAreaPane.populateBean(columnRow); |
||||
headerSettingPane.populateBean(sortItems); |
||||
} |
||||
|
||||
public SortHeader updateBean() { |
||||
ColumnRow columnRow = headerAreaPane.updateBean(); |
||||
SortHeader.SortItem[] items = headerSettingPane.updateBean(); |
||||
String headerArea = null; |
||||
if (columnRow != null) { |
||||
headerArea = columnRow.toString(); |
||||
} |
||||
SortHeader sortHeader = new SortHeader(headerArea, null, items); |
||||
return sortHeader; |
||||
} |
||||
} |
Loading…
Reference in new issue