diff --git a/designer/src/com/fr/design/actions/insert/cell/FormulaCellAction.java b/designer/src/com/fr/design/actions/insert/cell/FormulaCellAction.java index 499b9119d..56abd1e35 100644 --- a/designer/src/com/fr/design/actions/insert/cell/FormulaCellAction.java +++ b/designer/src/com/fr/design/actions/insert/cell/FormulaCellAction.java @@ -3,8 +3,8 @@ */ package com.fr.design.actions.insert.cell; +import com.fr.base.BaseFormula; import com.fr.base.BaseUtils; -import com.fr.base.Formula; import com.fr.design.actions.core.WorkBookSupportable; import com.fr.design.mainframe.ElementCasePane; import com.fr.design.menu.MenuKeySet; @@ -48,6 +48,6 @@ public class FormulaCellAction extends AbstractCellAction implements WorkBookSup @Override public Class getCellValueClass() { - return Formula.class; + return BaseFormula.class; } } \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/insert/flot/FormulaFloatAction.java b/designer/src/com/fr/design/actions/insert/flot/FormulaFloatAction.java index 4e2a7cbb0..99f0b3157 100644 --- a/designer/src/com/fr/design/actions/insert/flot/FormulaFloatAction.java +++ b/designer/src/com/fr/design/actions/insert/flot/FormulaFloatAction.java @@ -1,135 +1,128 @@ -/* - * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. - */ -package com.fr.design.actions.insert.flot; - -import com.fr.base.BaseUtils; -import com.fr.base.DynamicUnitList; -import com.fr.base.Formula; -import com.fr.design.actions.ElementCaseAction; -import com.fr.design.dialog.BasicDialog; -import com.fr.design.dialog.DialogActionAdapter; -import com.fr.design.file.HistoryTemplateListPane; -import com.fr.design.formula.FormulaFactory; -import com.fr.design.formula.UIFormula; -import com.fr.design.mainframe.DesignerContext; -import com.fr.design.mainframe.ElementCasePane; -import com.fr.design.menu.MenuKeySet; -import com.fr.design.report.SelectImagePane; -import com.fr.general.Inter; -import com.fr.grid.Grid; -import com.fr.grid.selection.FloatSelection; -import com.fr.report.ReportHelper; -import com.fr.report.cell.FloatElement; -import com.fr.report.cell.cellattr.CellImage; -import com.fr.report.elementcase.TemplateElementCase; -import com.fr.stable.CoreGraphHelper; -import com.fr.stable.StringUtils; -import com.fr.stable.unit.FU; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.io.File; - -/** - * Insert formula. - */ -public class FormulaFloatAction extends ElementCaseAction { - - private boolean returnValue = false; - - public FormulaFloatAction(ElementCasePane t) { - super(t); - this.setMenuKeySet(FLOAT_INSERT_FORMULA); - this.setName(getMenuKeySet().getMenuKeySetName()); - this.setMnemonic(getMenuKeySet().getMnemonic()); - this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_insert/formula.png")); - } - - public static final MenuKeySet FLOAT_INSERT_FORMULA = new MenuKeySet() { - @Override - public char getMnemonic() { - return 'F'; - } - - @Override - public String getMenuName() { - return Inter.getLocText("FR-Designer_Insert_Formula"); - } - - @Override - public KeyStroke getKeyStroke() { - return null; - } - }; - - private void doWithDrawingFloatElement() { - ElementCasePane jws = (ElementCasePane) HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().getCurrentElementCasePane(); - Grid grid = jws.getGrid(); - - ElementCasePane reportPane = grid.getElementCasePane(); - TemplateElementCase report = reportPane.getEditingElementCase(); - DynamicUnitList columnWidthList = ReportHelper.getColumnWidthList(report); - DynamicUnitList rowHeightList = ReportHelper.getRowHeightList(report); - - int horizentalScrollValue = grid.getHorizontalValue(); - int verticalScrollValue = grid.getVerticalValue(); - - int resolution = grid.getResolution(); - int floatWdith = grid.getDrawingFloatElement().getWidth().toPixI(resolution); - int floatHeight = grid.getDrawingFloatElement().getWidth().toPixI(resolution); - - FU evtX_fu = FU.valueOfPix((grid.getWidth() - floatWdith) / 2, resolution); - FU evtY_fu = FU.valueOfPix((grid.getHeight() - floatHeight) / 2, resolution); - - FU leftDistance = FU.getInstance(evtX_fu.toFU() + columnWidthList.getRangeValue(0, horizentalScrollValue).toFU()); - FU topDistance = FU.getInstance(evtY_fu.toFU() + rowHeightList.getRangeValue(0, verticalScrollValue).toFU()); - - grid.getDrawingFloatElement().setLeftDistance(leftDistance); - grid.getDrawingFloatElement().setTopDistance(topDistance); - - report.addFloatElement(grid.getDrawingFloatElement()); - reportPane.setSelection(new FloatSelection(grid.getDrawingFloatElement().getName())); - } - - /** - * 执行动作 - * - * @return 成功返回true - */ - @Override - public boolean executeActionReturnUndoRecordNeeded() { - final ElementCasePane reportPane = (ElementCasePane) HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().getCurrentElementCasePane(); - if (reportPane == null) { - return false; - } - - reportPane.stopEditing(); - final FloatElement floatElement = new FloatElement(); - final UIFormula formulaPane = FormulaFactory.createFormulaPane(); - formulaPane.populate(new Formula(StringUtils.EMPTY)); - - BasicDialog dialog = formulaPane.showLargeWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { - - @Override - public void doOk() { - floatElement.setValue(formulaPane.update()); - if (reportPane == null) { - return; - } - reportPane.getGrid().setDrawingFloatElement(floatElement); - doWithDrawingFloatElement(); - returnValue = true; - } - - @Override - public void doCancel() { - returnValue = false; - } - }); - dialog.setVisible(true); - return returnValue; - } - +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.insert.flot; + +import com.fr.base.BaseFormula; +import com.fr.base.BaseUtils; +import com.fr.base.DynamicUnitList; +import com.fr.design.actions.ElementCaseAction; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.file.HistoryTemplateListPane; +import com.fr.design.formula.FormulaFactory; +import com.fr.design.formula.UIFormula; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.menu.MenuKeySet; +import com.fr.general.Inter; +import com.fr.grid.Grid; +import com.fr.grid.selection.FloatSelection; +import com.fr.report.ReportHelper; +import com.fr.report.cell.FloatElement; +import com.fr.report.elementcase.TemplateElementCase; +import com.fr.stable.unit.FU; + +import javax.swing.*; + +/** + * Insert formula. + */ +public class FormulaFloatAction extends ElementCaseAction { + + private boolean returnValue = false; + + public FormulaFloatAction(ElementCasePane t) { + super(t); + this.setMenuKeySet(FLOAT_INSERT_FORMULA); + this.setName(getMenuKeySet().getMenuKeySetName()); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_insert/formula.png")); + } + + public static final MenuKeySet FLOAT_INSERT_FORMULA = new MenuKeySet() { + @Override + public char getMnemonic() { + return 'F'; + } + + @Override + public String getMenuName() { + return Inter.getLocText("FR-Designer_Insert_Formula"); + } + + @Override + public KeyStroke getKeyStroke() { + return null; + } + }; + + private void doWithDrawingFloatElement() { + ElementCasePane jws = (ElementCasePane) HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().getCurrentElementCasePane(); + Grid grid = jws.getGrid(); + + ElementCasePane reportPane = grid.getElementCasePane(); + TemplateElementCase report = reportPane.getEditingElementCase(); + DynamicUnitList columnWidthList = ReportHelper.getColumnWidthList(report); + DynamicUnitList rowHeightList = ReportHelper.getRowHeightList(report); + + int horizentalScrollValue = grid.getHorizontalValue(); + int verticalScrollValue = grid.getVerticalValue(); + + int resolution = grid.getResolution(); + int floatWdith = grid.getDrawingFloatElement().getWidth().toPixI(resolution); + int floatHeight = grid.getDrawingFloatElement().getWidth().toPixI(resolution); + + FU evtX_fu = FU.valueOfPix((grid.getWidth() - floatWdith) / 2, resolution); + FU evtY_fu = FU.valueOfPix((grid.getHeight() - floatHeight) / 2, resolution); + + FU leftDistance = FU.getInstance(evtX_fu.toFU() + columnWidthList.getRangeValue(0, horizentalScrollValue).toFU()); + FU topDistance = FU.getInstance(evtY_fu.toFU() + rowHeightList.getRangeValue(0, verticalScrollValue).toFU()); + + grid.getDrawingFloatElement().setLeftDistance(leftDistance); + grid.getDrawingFloatElement().setTopDistance(topDistance); + + report.addFloatElement(grid.getDrawingFloatElement()); + reportPane.setSelection(new FloatSelection(grid.getDrawingFloatElement().getName())); + } + + /** + * 执行动作 + * + * @return 成功返回true + */ + @Override + public boolean executeActionReturnUndoRecordNeeded() { + final ElementCasePane reportPane = (ElementCasePane) HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().getCurrentElementCasePane(); + if (reportPane == null) { + return false; + } + + reportPane.stopEditing(); + final FloatElement floatElement = new FloatElement(); + final UIFormula formulaPane = FormulaFactory.createFormulaPane(); + formulaPane.populate(BaseFormula.createFormulaBuilder().build()); + + BasicDialog dialog = formulaPane.showLargeWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { + + @Override + public void doOk() { + floatElement.setValue(formulaPane.update()); + if (reportPane == null) { + return; + } + reportPane.getGrid().setDrawingFloatElement(floatElement); + doWithDrawingFloatElement(); + returnValue = true; + } + + @Override + public void doCancel() { + returnValue = false; + } + }); + dialog.setVisible(true); + return returnValue; + } + } \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/editor/FormulaCellEditor.java b/designer/src/com/fr/design/cell/editor/FormulaCellEditor.java index e69742ea9..38b8b7551 100644 --- a/designer/src/com/fr/design/cell/editor/FormulaCellEditor.java +++ b/designer/src/com/fr/design/cell/editor/FormulaCellEditor.java @@ -3,7 +3,7 @@ */ package com.fr.design.cell.editor; -import com.fr.base.Formula; +import com.fr.base.BaseFormula; import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.formula.FormulaFactory; import com.fr.design.formula.UIFormula; @@ -34,7 +34,7 @@ public class FormulaCellEditor extends com.fr.design.cell.editor.AbstractCellEdi */ @Override public Object getCellEditorValue() throws Exception { - Formula newFormula = this.formulaEditorPane.update(); + BaseFormula newFormula = this.formulaEditorPane.update(); if (newFormula.getContent() != null && newFormula.getContent().trim().length() > 1) { return newFormula; } else { @@ -64,13 +64,13 @@ public class FormulaCellEditor extends com.fr.design.cell.editor.AbstractCellEdi if (cellElement != null) { value = cellElement.getValue(); } - if (value == null || !(value instanceof Formula)) { - value = new Formula(""); + if (value == null || !(value instanceof BaseFormula)) { + value = BaseFormula.createFormulaBuilder().build(); } this.formulaEditorPane = FormulaFactory.createFormulaPaneWhenReserveFormula(); - this.formulaEditorPane.populate((Formula) value); + this.formulaEditorPane.populate((BaseFormula) value); return this.formulaEditorPane.showLargeWindow(SwingUtilities.getWindowAncestor(grid), new DialogActionAdapter() { @Override diff --git a/designer/src/com/fr/design/cell/editor/FormulaFloatEditor.java b/designer/src/com/fr/design/cell/editor/FormulaFloatEditor.java index 046b3ebe3..23a41bbdd 100644 --- a/designer/src/com/fr/design/cell/editor/FormulaFloatEditor.java +++ b/designer/src/com/fr/design/cell/editor/FormulaFloatEditor.java @@ -3,7 +3,7 @@ */ package com.fr.design.cell.editor; -import com.fr.base.Formula; +import com.fr.base.BaseFormula; import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.formula.FormulaFactory; import com.fr.design.formula.UIFormula; @@ -31,7 +31,7 @@ public class FormulaFloatEditor extends AbstractFloatEditor { */ @Override public Object getFloatEditorValue() throws Exception { - Formula newFormula = this.formulaEditorPane.update(); + BaseFormula newFormula = this.formulaEditorPane.update(); if (newFormula.getContent() != null && newFormula.getContent().trim().length() > 1) { return newFormula; } else { @@ -59,12 +59,12 @@ public class FormulaFloatEditor extends AbstractFloatEditor { public Component getFloatEditorComponent(Grid grid, FloatElement floatElement, int resolution) { //populate data to UI Object value = floatElement.getValue(); - if (value == null || !(value instanceof com.fr.base.Formula)) { - value = new Formula(""); + if (value == null || !(value instanceof BaseFormula)) { + value = BaseFormula.createFormulaBuilder().build(); } this.formulaEditorPane = FormulaFactory.createFormulaPane(); - this.formulaEditorPane.populate((Formula) value); + this.formulaEditorPane.populate((BaseFormula) value); return this.formulaEditorPane.showLargeWindow(SwingUtilities.getWindowAncestor(grid), new DialogActionAdapter() { diff --git a/designer/src/com/fr/design/cell/editor/RichTextToolBar.java b/designer/src/com/fr/design/cell/editor/RichTextToolBar.java index 0b5721975..d48070371 100644 --- a/designer/src/com/fr/design/cell/editor/RichTextToolBar.java +++ b/designer/src/com/fr/design/cell/editor/RichTextToolBar.java @@ -3,9 +3,9 @@ */ package com.fr.design.cell.editor; +import com.fr.base.BaseFormula; import com.fr.base.BaseUtils; import com.fr.base.FRContext; -import com.fr.base.Formula; import com.fr.base.Utils; import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.DialogActionAdapter; @@ -27,10 +27,27 @@ import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; import javax.swing.*; -import javax.swing.event.*; -import javax.swing.text.*; +import javax.swing.event.CaretEvent; +import javax.swing.event.CaretListener; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import javax.swing.text.AttributeSet; +import javax.swing.text.BadLocationException; +import javax.swing.text.Element; +import javax.swing.text.MutableAttributeSet; +import javax.swing.text.SimpleAttributeSet; +import javax.swing.text.StyleConstants; +import javax.swing.text.StyledDocument; import java.awt.*; -import java.awt.event.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; import java.math.BigDecimal; /** @@ -311,12 +328,12 @@ public class RichTextToolBar extends BasicPane{ private ActionListener formulaActionListener = new ActionListener() { public void actionPerformed(ActionEvent evt) { final UIFormula formulaPane = FormulaFactory.createFormulaPane(); - formulaPane.populate(new Formula()); + formulaPane.populate(BaseFormula.createFormulaBuilder().build()); formulaPane.showLargeWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { @Override public void doOk() { StyledDocument doc = (StyledDocument) textPane.getDocument(); - Formula fm = formulaPane.update(); + BaseFormula fm = formulaPane.update(); String content = RichTextConverter.asFormula(fm.getContent()); int start = textPane.getSelectionStart(); AttributeSet attrs = start > 0 ? doc.getCharacterElement(start - 1).getAttributes() : new SimpleAttributeSet(); diff --git a/designer/src/com/fr/design/dscolumn/DSColumnAdvancedPane.java b/designer/src/com/fr/design/dscolumn/DSColumnAdvancedPane.java index 59fdb2205..02776c273 100644 --- a/designer/src/com/fr/design/dscolumn/DSColumnAdvancedPane.java +++ b/designer/src/com/fr/design/dscolumn/DSColumnAdvancedPane.java @@ -1,6 +1,6 @@ package com.fr.design.dscolumn; -import com.fr.base.Formula; +import com.fr.base.BaseFormula; import com.fr.data.util.SortOrder; import com.fr.design.data.DesignTableDataManager; import com.fr.design.dialog.BasicPane; @@ -31,7 +31,9 @@ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import static com.fr.report.cell.cellattr.core.group.FilterTypeEnum.*; +import static com.fr.report.cell.cellattr.core.group.FilterTypeEnum.BOTTOM; +import static com.fr.report.cell.cellattr.core.group.FilterTypeEnum.SPECIFY; +import static com.fr.report.cell.cellattr.core.group.FilterTypeEnum.TOP; public class DSColumnAdvancedPane extends BasicPane { @@ -460,7 +462,7 @@ public class DSColumnAdvancedPane extends BasicPane { private ActionListener formulaButtonActionListener = new ActionListener() { public void actionPerformed(ActionEvent evt) { - Formula valueFormula = new Formula(); + BaseFormula valueFormula = BaseFormula.createFormulaBuilder().build(); String text = formulaTextField.getText(); if (text == null || text.length() <= 0) { valueFormula.setContent(defaultValue); @@ -485,7 +487,7 @@ public class DSColumnAdvancedPane extends BasicPane { formulaPane.showLargeWindow(SwingUtilities.getWindowAncestor(JFormulaField.this), new DialogActionAdapter() { @Override public void doOk() { - Formula valueFormula = formulaPane.update(); + BaseFormula valueFormula = formulaPane.update(); if (valueFormula.getContent().length() <= 1) { formulaTextField.setText(defaultValue); } else { diff --git a/designer/src/com/fr/design/dscolumn/SpecifiedGroupAttrPane.java b/designer/src/com/fr/design/dscolumn/SpecifiedGroupAttrPane.java index 7321f2ca6..d03a6e47b 100644 --- a/designer/src/com/fr/design/dscolumn/SpecifiedGroupAttrPane.java +++ b/designer/src/com/fr/design/dscolumn/SpecifiedGroupAttrPane.java @@ -1,6 +1,6 @@ package com.fr.design.dscolumn; -import com.fr.base.Formula; +import com.fr.base.BaseFormula; import com.fr.design.beans.BasicBeanPane; import com.fr.design.condition.DSColumnLiteConditionPane; import com.fr.design.dialog.BasicPane; @@ -333,7 +333,7 @@ public class SpecifiedGroupAttrPane extends BasicPane { formulaButton.setPreferredSize(new Dimension(25, valueField.getPreferredSize().height)); formulaButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { - Formula valueFormula = new Formula(); + BaseFormula valueFormula = BaseFormula.createFormulaBuilder().build(); String text = valueField.getText(); if (text == null || text.length() <= 0) { valueFormula.setContent("$$$"); @@ -347,7 +347,7 @@ public class SpecifiedGroupAttrPane extends BasicPane { formulaPane.showLargeWindow(SwingUtilities.getWindowAncestor(FormulaGroupPane.this), new DialogActionAdapter(){ @Override public void doOk() { - Formula valueFormula = formulaPane.update(); + BaseFormula valueFormula = formulaPane.update(); if (valueFormula.getContent().length() <= 1) { valueField.setText("$$$"); } else { diff --git a/designer/src/com/fr/design/headerfooter/HFAttributesEditDialog.java b/designer/src/com/fr/design/headerfooter/HFAttributesEditDialog.java index f30a6e212..f432c39f7 100644 --- a/designer/src/com/fr/design/headerfooter/HFAttributesEditDialog.java +++ b/designer/src/com/fr/design/headerfooter/HFAttributesEditDialog.java @@ -3,8 +3,16 @@ */ package com.fr.design.headerfooter; -import com.fr.base.Formula; -import com.fr.base.headerfooter.*; +import com.fr.base.BaseFormula; +import com.fr.base.headerfooter.DateHFElement; +import com.fr.base.headerfooter.FormulaHFElement; +import com.fr.base.headerfooter.HFElement; +import com.fr.base.headerfooter.ImageHFElement; +import com.fr.base.headerfooter.NewLineHFElement; +import com.fr.base.headerfooter.NumberOfPageHFElement; +import com.fr.base.headerfooter.PageNumberHFElement; +import com.fr.base.headerfooter.TextHFElement; +import com.fr.base.headerfooter.TimeHFElement; import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.formula.FormulaFactory; @@ -121,7 +129,7 @@ public class HFAttributesEditDialog extends BasicPane { formulaButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { - Formula valueFormula = new Formula(); + BaseFormula valueFormula = BaseFormula.createFormulaBuilder().build(); String text = formulaContentField.getText(); if (text == null || text.length() <= 0) { valueFormula.setContent(""); @@ -135,7 +143,7 @@ public class HFAttributesEditDialog extends BasicPane { @Override public void doOk() { - Formula valueFormula = formulaPane.update(); + BaseFormula valueFormula = formulaPane.update(); if (valueFormula.getContent().length() <= 1) { formulaContentField.setText(""); } else { diff --git a/designer/src/com/fr/design/mainframe/ElementCasePane.java b/designer/src/com/fr/design/mainframe/ElementCasePane.java index 0445b0987..8a84788b6 100644 --- a/designer/src/com/fr/design/mainframe/ElementCasePane.java +++ b/designer/src/com/fr/design/mainframe/ElementCasePane.java @@ -322,7 +322,7 @@ public abstract class ElementCasePane extends Tar private void initDefaultEditors() { Grid grid = this.getGrid(); grid.setDefaultCellEditor(DSColumn.class, new DSColumnCellEditor(this)); - grid.setDefaultCellEditor(Formula.class, new FormulaCellEditor(this)); + grid.setDefaultCellEditor(BaseFormula.class, new FormulaCellEditor(this)); grid.setDefaultCellEditor(RichText.class, new RichTextCellEditor(this)); grid.setDefaultCellEditor(BiasTextPainter.class, new BiasTextPainterCellEditor(this)); diff --git a/designer/src/com/fr/design/module/DesignerModule.java b/designer/src/com/fr/design/module/DesignerModule.java index c037267fb..ba10f4225 100644 --- a/designer/src/com/fr/design/module/DesignerModule.java +++ b/designer/src/com/fr/design/module/DesignerModule.java @@ -112,7 +112,7 @@ public class DesignerModule extends DesignModule { private void registerCellEditor() { ActionFactory.registerCellEditor(String.class, CellStringQuickEditor.class); ActionFactory.registerCellEditor(Number.class, CellStringQuickEditor.class); - ActionFactory.registerCellEditor(Formula.class, CellFormulaQuickEditor.class); + ActionFactory.registerCellEditor(BaseFormula.class, CellFormulaQuickEditor.class); ActionFactory.registerCellEditor(SubReport.class, CellSubReportEditor.class); ActionFactory.registerCellEditor(RichText.class, CellRichTextEditor.class); ActionFactory.registerCellEditor(DSColumn.class, CellDSColumnEditor.class); diff --git a/designer/src/com/fr/design/report/RichTextEditingPane.java b/designer/src/com/fr/design/report/RichTextEditingPane.java index 15b3496bd..57c5fad2e 100644 --- a/designer/src/com/fr/design/report/RichTextEditingPane.java +++ b/designer/src/com/fr/design/report/RichTextEditingPane.java @@ -3,8 +3,8 @@ */ package com.fr.design.report; +import com.fr.base.BaseFormula; import com.fr.base.FRContext; -import com.fr.base.Formula; import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.formula.FormulaFactory; import com.fr.design.formula.UIFormula; @@ -139,12 +139,12 @@ public class RichTextEditingPane extends UITextPane{ private void popUpFormulaEditPane(final String formulaContent, final int formulaStart, final AttributeSet attrs){ final UIFormula formulaPane = FormulaFactory.createFormulaPane(); - formulaPane.populate(new Formula(formulaContent)); + formulaPane.populate(BaseFormula.createFormulaBuilder().build(formulaContent)); formulaPane.showLargeWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { @Override public void doOk() { StyledDocument doc = (StyledDocument) RichTextEditingPane.this.getDocument(); - Formula fm = formulaPane.update(); + BaseFormula fm = formulaPane.update(); String content = RichTextConverter.asFormula(fm.getContent()); try { doc.remove(formulaStart, formulaContent.length() + WRAPPER_LEN); diff --git a/designer/src/com/fr/design/report/RichTextPane.java b/designer/src/com/fr/design/report/RichTextPane.java index 239518e7e..f6fe22910 100644 --- a/designer/src/com/fr/design/report/RichTextPane.java +++ b/designer/src/com/fr/design/report/RichTextPane.java @@ -1,21 +1,7 @@ package com.fr.design.report; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Font; -import java.math.BigDecimal; -import java.util.Iterator; - -import javax.swing.JPanel; -import javax.swing.text.AttributeSet; -import javax.swing.text.BadLocationException; -import javax.swing.text.DefaultStyledDocument; -import javax.swing.text.Element; -import javax.swing.text.SimpleAttributeSet; -import javax.swing.text.StyleConstants; - +import com.fr.base.BaseFormula; import com.fr.base.FRContext; -import com.fr.base.Formula; import com.fr.base.Style; import com.fr.design.cell.editor.RichTextToolBar; import com.fr.design.dialog.BasicPane; @@ -34,6 +20,17 @@ import com.fr.stable.Constants; import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; +import javax.swing.*; +import javax.swing.text.AttributeSet; +import javax.swing.text.BadLocationException; +import javax.swing.text.DefaultStyledDocument; +import javax.swing.text.Element; +import javax.swing.text.SimpleAttributeSet; +import javax.swing.text.StyleConstants; +import java.awt.*; +import java.math.BigDecimal; +import java.util.Iterator; + public class RichTextPane extends BasicPane { //12号字体有个奇怪的bug, 字体下部分渲染会截断一部分, 换其他字体没问题, 字体改大小也没问题. @@ -82,7 +79,7 @@ public class RichTextPane extends BasicPane { if(cellValue == null){ return; } - if(cellValue instanceof Formula){ + if(cellValue instanceof BaseFormula){ cellValue = RichTextConverter.asFormula(String.valueOf(cellValue)); } diff --git a/designer/src/com/fr/design/report/ValueVerifierEditPane.java b/designer/src/com/fr/design/report/ValueVerifierEditPane.java index f3ebda61a..5eea0f207 100644 --- a/designer/src/com/fr/design/report/ValueVerifierEditPane.java +++ b/designer/src/com/fr/design/report/ValueVerifierEditPane.java @@ -1,71 +1,71 @@ -package com.fr.design.report; - -import com.fr.base.Formula; -import com.fr.data.VerifyItem; -import com.fr.design.gui.itableeditorpane.ActionStyle; -import com.fr.design.gui.itableeditorpane.UIArrayFormulaTableModel; -import com.fr.design.gui.itableeditorpane.UITableEditorPane; -import com.fr.design.layout.FRGUIPaneFactory; -import com.fr.general.GeneralUtils; -import com.fr.general.Inter; -import com.fr.report.write.ValueVerifier; -import com.fr.stable.FormulaProvider; -import com.fr.stable.StableUtils; - -import javax.swing.*; -import java.awt.*; - -public class ValueVerifierEditPane extends JPanel { - private UITableEditorPane tableEditorPane; - private final String[] columnNames = new String[] { - Inter.getLocText(new String[] {"Verify-Verify_Formula", "Verify-ToolTips"}, new String[] {"(", ")"}), - Inter.getLocText("Verify-Error_Information") }; - - public ValueVerifierEditPane() { - // ben:UITableEditorPane; - this.setLayout(FRGUIPaneFactory.createM_BorderLayout()); - tableEditorPane = new UITableEditorPane(new UIArrayFormulaTableModel(columnNames, new int[] { - ActionStyle.ADDSTYLE, ActionStyle.DELETESTYLE, - ActionStyle.MOVEUPSTYLE, ActionStyle.MOVEDOWNSTYLE})); - this.add(tableEditorPane, BorderLayout.CENTER); - } - - /** - * populate - */ - public void populate(ValueVerifier valueVerifier) { - if (valueVerifier == null) { - return; - } - int rowCount = valueVerifier.getVerifyItemsCount(); - Object[][] os = new Object[rowCount][]; - int tableDataCount = 0; - for (int i = 0; i < rowCount; i ++) { - VerifyItem item = valueVerifier.getVerifyItem(i); - FormulaProvider formula = item.getFormula(); - if (formula == null) { - continue; - } - String msg = item.getMessage(); - if (!StableUtils.canBeFormula(msg)) { - msg = "\"" + msg + "\"";//如果报错信息是以前的写法(字符串)就拼上"" - } - os[tableDataCount++] = new Object[]{formula, new Formula(msg)}; - } - this.tableEditorPane.populate(os); - } - - public ValueVerifier update() { - ValueVerifier valueVerifier = new ValueVerifier(); - java.util.List list = tableEditorPane.update(); - for (int i = 0; i < list.size(); i++) { - Object[] o = list.get(i); - if (o == null || o[0] == null) { - continue; - } - VerifyItem item = new VerifyItem(new Formula(GeneralUtils.objectToString(o[0])), GeneralUtils.objectToString(o[1])); - valueVerifier.addVerifyItem(item); - } - return valueVerifier; - } -} +package com.fr.design.report; + +import com.fr.base.BaseFormula; +import com.fr.data.VerifyItem; +import com.fr.design.gui.itableeditorpane.ActionStyle; +import com.fr.design.gui.itableeditorpane.UIArrayFormulaTableModel; +import com.fr.design.gui.itableeditorpane.UITableEditorPane; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.general.GeneralUtils; +import com.fr.general.Inter; +import com.fr.report.write.ValueVerifier; +import com.fr.stable.FormulaProvider; +import com.fr.stable.StableUtils; + +import javax.swing.*; +import java.awt.*; + +public class ValueVerifierEditPane extends JPanel { + private UITableEditorPane tableEditorPane; + private final String[] columnNames = new String[] { + Inter.getLocText(new String[] {"Verify-Verify_Formula", "Verify-ToolTips"}, new String[] {"(", ")"}), + Inter.getLocText("Verify-Error_Information") }; + + public ValueVerifierEditPane() { + // ben:UITableEditorPane; + this.setLayout(FRGUIPaneFactory.createM_BorderLayout()); + tableEditorPane = new UITableEditorPane(new UIArrayFormulaTableModel(columnNames, new int[] { + ActionStyle.ADDSTYLE, ActionStyle.DELETESTYLE, + ActionStyle.MOVEUPSTYLE, ActionStyle.MOVEDOWNSTYLE})); + this.add(tableEditorPane, BorderLayout.CENTER); + } + + /** + * populate + */ + public void populate(ValueVerifier valueVerifier) { + if (valueVerifier == null) { + return; + } + int rowCount = valueVerifier.getVerifyItemsCount(); + Object[][] os = new Object[rowCount][]; + int tableDataCount = 0; + for (int i = 0; i < rowCount; i ++) { + VerifyItem item = valueVerifier.getVerifyItem(i); + FormulaProvider formula = item.getFormula(); + if (formula == null) { + continue; + } + String msg = item.getMessage(); + if (!StableUtils.canBeFormula(msg)) { + msg = "\"" + msg + "\"";//如果报错信息是以前的写法(字符串)就拼上"" + } + os[tableDataCount++] = new Object[]{formula, BaseFormula.createFormulaBuilder().build(msg)}; + } + this.tableEditorPane.populate(os); + } + + public ValueVerifier update() { + ValueVerifier valueVerifier = new ValueVerifier(); + java.util.List list = tableEditorPane.update(); + for (int i = 0; i < list.size(); i++) { + Object[] o = list.get(i); + if (o == null || o[0] == null) { + continue; + } + VerifyItem item = new VerifyItem(BaseFormula.createFormulaBuilder().build(o[0]), GeneralUtils.objectToString(o[1])); + valueVerifier.addVerifyItem(item); + } + return valueVerifier; + } +} diff --git a/designer/src/com/fr/design/widget/CellWidgetCardPane.java b/designer/src/com/fr/design/widget/CellWidgetCardPane.java index 043e3a779..77d1542cb 100644 --- a/designer/src/com/fr/design/widget/CellWidgetCardPane.java +++ b/designer/src/com/fr/design/widget/CellWidgetCardPane.java @@ -2,7 +2,7 @@ package com.fr.design.widget; import com.fr.design.constants.UIConstants; import com.fr.design.data.DataCreatorUI; -import com.fr.design.designer.IntervalConstants; +import com.fr.design.dialog.AttrScrollPane; import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.BasicScrollPane; import com.fr.design.foldablepane.UIExpandablePane; @@ -51,38 +51,24 @@ public class CellWidgetCardPane extends BasicPane { this.removeAll(); this.setLayout(FRGUIPaneFactory.createBorderLayout()); - final JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); - - BasicScrollPane basicScrollPane = new BasicScrollPane() { - @Override - protected JPanel createContentPane() { - return jPanel; - } - - @Override - public void populateBean(Object ob) { - - } - - @Override - protected String title4PopupWindow() { - return null; - } - }; - this.add(basicScrollPane, BorderLayout.CENTER); - //k tabbedPane = new CardLayout(); center = new JPanel(tabbedPane); - jPanel.add(center, BorderLayout.CENTER); - jPanel.setBorder(BorderFactory.createEmptyBorder(0, IntervalConstants.INTERVAL_L6, 0, 0)); + this.add(center, BorderLayout.CENTER); attriTabPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); eventTabPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + eventTabPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10)); initPaneList(); eventPane = initWidgetEventPane(pane); eventTabPane.add(eventPane, BorderLayout.CENTER); //k - center.add(attriTabPane, Inter.getLocText("FR-Designer_Attribute")); + BasicScrollPane basicScrollPane = new AttrScrollPane() { + @Override + protected JPanel createContentPane() { + return attriTabPane; + } + }; + center.add(basicScrollPane, Inter.getLocText("FR-Designer_Attribute")); center.add(eventTabPane, Inter.getLocText("FR-Designer_Event")); final String[] tabTitles = new String[]{Inter.getLocText("FR-Designer_Attribute"), Inter.getLocText("FR-Designer_Event")}; @@ -100,7 +86,8 @@ public class CellWidgetCardPane extends BasicPane { UIExpandablePane uiExpandablePane = new UIExpandablePane(Inter.getLocText("FR-Designer_Basic"), 280, 24, widgetPropertyPane); - attriTabPane.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); + + attriTabPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10)); attriTabPane.add(uiExpandablePane, BorderLayout.NORTH); attriCardPane = FRGUIPaneFactory.createCardLayout_S_Pane(); diff --git a/designer/src/com/fr/design/widget/ui/DateEditorDefinePane.java b/designer/src/com/fr/design/widget/ui/DateEditorDefinePane.java index 49c0d9928..5ef1e7a47 100644 --- a/designer/src/com/fr/design/widget/ui/DateEditorDefinePane.java +++ b/designer/src/com/fr/design/widget/ui/DateEditorDefinePane.java @@ -1,7 +1,6 @@ package com.fr.design.widget.ui; import com.fr.base.FRContext; -import com.fr.base.Formula; import com.fr.data.core.FormatField; import com.fr.design.designer.IntervalConstants; import com.fr.design.gui.ibutton.UIButtonGroup; @@ -13,11 +12,8 @@ import com.fr.design.layout.TableLayoutHelper; import com.fr.design.widget.component.DateValuePane; import com.fr.design.widget.component.UIComboBoxNoArrow; import com.fr.form.ui.DateEditor; -import com.fr.general.DateUtils; import com.fr.general.Inter; -import com.fr.script.Calculator; import com.fr.stable.ArrayUtils; -import com.fr.stable.UtilEvalError; import javax.swing.*; import javax.swing.event.ChangeEvent; @@ -58,10 +54,17 @@ public class DateEditorDefinePane extends DirectWriteEditorDefinePane { /** * FieldEditorDefinePane diff --git a/designer/src/com/fr/grid/GridUI.java b/designer/src/com/fr/grid/GridUI.java index 93ca03f81..2215fc2b7 100644 --- a/designer/src/com/fr/grid/GridUI.java +++ b/designer/src/com/fr/grid/GridUI.java @@ -1,1227 +1,1238 @@ -package com.fr.grid; - -import com.fr.base.*; -import com.fr.base.background.ColorBackground; -import com.fr.base.background.ImageBackground; -import com.fr.design.constants.UIConstants; -import com.fr.design.file.HistoryTemplateListPane; -import com.fr.design.mainframe.DesignerContext; -import com.fr.design.mainframe.ElementCasePane; -import com.fr.design.mainframe.JTemplate; -import com.fr.design.roleAuthority.ReportAndFSManagePane; -import com.fr.general.Background; -import com.fr.general.ComparatorUtils; -import com.fr.grid.selection.CellSelection; -import com.fr.grid.selection.FloatSelection; -import com.fr.grid.selection.Selection; -import com.fr.page.PaperSettingProvider; -import com.fr.page.ReportSettingsProvider; -import com.fr.report.ReportHelper; -import com.fr.report.cell.CellElement; -import com.fr.report.cell.FloatElement; -import com.fr.report.cell.TemplateCellElement; -import com.fr.report.cell.cellattr.CellExpandAttr; -import com.fr.report.cell.cellattr.CellGUIAttr; -import com.fr.report.cell.cellattr.CellPageAttr; -import com.fr.report.core.PaintUtils; -import com.fr.report.core.ReportUtils; -import com.fr.report.elementcase.ElementCase; -import com.fr.report.elementcase.TemplateElementCase; -import com.fr.report.report.Report; -import com.fr.report.stable.ReportConstants; -import com.fr.report.stable.ReportSettings; -import com.fr.report.worksheet.FormElementCase; -import com.fr.report.worksheet.WorkSheet; -import com.fr.stable.ColumnRow; -import com.fr.stable.Constants; -import com.fr.stable.script.CalculatorUtils; -import com.fr.stable.unit.FU; -import com.fr.third.antlr.ANTLRException; - -import javax.swing.*; -import javax.swing.plaf.ComponentUI; -import java.awt.*; -import java.awt.geom.*; -import java.awt.geom.Line2D.Double; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -public class GridUI extends ComponentUI { - - public static int INVALID_INTEGER = Integer.MIN_VALUE;// 作为不合法的数值. - protected Dimension gridSize; - protected int verticalValue; - protected int horizontalValue; - protected double paperPaintWidth; - protected double paperPaintHeight; - protected DynamicUnitList rowHeightList; - protected DynamicUnitList columnWidthList; - protected int verticalEndValue; - protected int horizontalEndValue; - protected DrawFlowRect drawFlowRect; - // paint的辅助类 - protected List paintCellElementList = new ArrayList(); - protected List paintCellElementRectangleList = new ArrayList(); - protected List paginateLineList = new ArrayList(); // 分页线 - // 为了画白色的背景. - protected static Background WHITE_Backgorund = ColorBackground.getInstance(Color.WHITE); - // CellElementPainter - protected CellElementPainter painter = new CellElementPainter(); - // Left - protected Rectangle2D.Double left_col_row_rect = new Rectangle2D.Double(0, 0, 0, 0); - // Top - protected Rectangle2D.Double top_col_row_rect = new Rectangle2D.Double(0, 0, 0, 0); - protected Rectangle2D.Double back_or_selection_rect = new Rectangle2D.Double(0, 0, 0, 0); - // alex:用来画拖拽中的格子的边框 - protected Rectangle2D.Double drag_cell_rect = new Rectangle2D.Double(0, 0, 0, 0); - // alex:用来画单元格的白色背景,以清空原来画的内容 - protected Rectangle2D.Double cell_back_rect = new Rectangle2D.Double(0, 0, 0, 0); - // 由于报表冻结的时候,当有冻结线穿过merge的格子的时候,最多需要由8个rectangle来决定. - protected Rectangle2D.Double tmpRectangle = new Rectangle2D.Double(INVALID_INTEGER, - INVALID_INTEGER, INVALID_INTEGER, INVALID_INTEGER); - - protected int resolution; - - private boolean isAuthority = false; - - public GridUI(int resolution) { - super(); - this.resolution = resolution; - } - - protected ReportSettingsProvider getReportSettings(ElementCase elementCase) { - if (elementCase instanceof Report) { - return ReportUtils.getReportSettings((Report) elementCase); - } else if(elementCase instanceof FormElementCase){ - return ((FormElementCase) elementCase).getReportSettings(); - } else { - return new ReportSettings(); - } - } - - protected void paintBackground(Graphics g, Grid grid, ElementCase elementCase, int resolution) { - Graphics2D g2d = (Graphics2D) g; - - // 当前的Grid面板的大小 - this.back_or_selection_rect.setRect(0, 0, gridSize.getWidth(), gridSize.getHeight()); - - // 需要用白色背景来清空背景. - clearBackground(g2d, grid); - - // paint print dash line. - this.paperPaintWidth = 0; - this.paperPaintHeight = 0; - - // richer;聚合报表设计中,最初的ElementCase还没有加到Report中,所以elementCase.getReport()可能为空 - ReportSettingsProvider reportSettings = getReportSettings(elementCase); - PaperSettingProvider psetting = reportSettings.getPaperSetting(); - if (grid.isShowPaginateLine()) {// paint paper margin line. - PaperSize paperSize = psetting.getPaperSize(); - Margin margin = psetting.getMargin(); - - double paperWidth = paperSize.getWidth().toPixD(resolution); - double paperHeight = paperSize.getHeight().toPixD(resolution); - // carl:横向就反过来 - if (psetting.getOrientation() == ReportConstants.LANDSCAPE) { - paperWidth = paperSize.getHeight().toPixD(resolution); - paperHeight = paperSize.getWidth().toPixD(resolution); - } - - paperPaintWidth = paperWidth - margin.getLeft().toPixD(resolution) - - margin.getRight().toPixD(resolution); - paperPaintHeight = paperHeight - margin.getTop().toPixD(resolution) - - margin.getBottom().toPixD(resolution) - - reportSettings.getHeaderHeight().toPixD(resolution) - - reportSettings.getFooterHeight().toPixD(resolution); - } - - // denny:画背景.Background - Background background = reportSettings.getBackground(); - - if (background != null) { - // denny: except the ColorBackground and ImageBackground - if (grid.isEnabled() && !(background instanceof ImageBackground)) { - background.paint(g2d, this.back_or_selection_rect); - } - - // denny: make that the background can move with scroll - paintScrollBackground(g2d, grid, background, psetting, reportSettings); - } - } - - private void clearBackground(Graphics2D g2d, Grid grid) { - if (grid.isEnabled()) { - g2d.setPaint(Color.WHITE); - } else { - g2d.setPaint(UIManager.getColor("control")); - } - GraphHelper.fill(g2d, this.back_or_selection_rect); - } - - private void paintScrollBackground(Graphics2D g2d, Grid grid, Background background, PaperSettingProvider psetting, ReportSettingsProvider reportSettings) { - boolean isCanDrawImage = grid.isEditable() || isAuthority; - if (isCanDrawImage && (background instanceof ImageBackground)) { - if (!grid.isShowPaginateLine()) { - calculatePaper(psetting, reportSettings); - } - - ImageBackground imageBackground = (ImageBackground) background; - - int hideWidth = columnWidthList.getRangeValue(0, horizontalValue) - .toPixI(resolution); - int hideHeight = rowHeightList.getRangeValue(0, verticalValue).toPixI(resolution); - - for (int i = 0; i * paperPaintWidth < gridSize.getWidth(); i++) { - for (int j = 0; j * paperPaintHeight < gridSize.getHeight(); j++) { - this.back_or_selection_rect.setRect(i * paperPaintWidth, j - * paperPaintHeight, paperPaintWidth, paperPaintHeight); - imageBackground.paint4Scroll(g2d, this.back_or_selection_rect, hideWidth, - hideHeight); - } - } - - this.back_or_selection_rect - .setRect(0, 0, gridSize.getWidth(), gridSize.getHeight()); - } - } - - - private void calculatePaper(PaperSettingProvider psetting, ReportSettingsProvider reportSettings) { - PaperSize paperSize = psetting.getPaperSize(); - Margin margin = psetting.getMargin(); - - double paperWidth = paperSize.getWidth().toPixD(resolution); - double paperHeight = paperSize.getHeight().toPixD(resolution); - if (psetting.getOrientation() == ReportConstants.LANDSCAPE - && paperSize.getWidth().toPixD(resolution) < paperSize.getHeight() - .toPixD(resolution)) { - paperWidth = Math.max(paperSize.getWidth().toPixD(resolution), paperSize - .getHeight().toPixD(resolution)); - paperHeight = Math.min(paperSize.getWidth().toPixD(resolution), paperSize - .getHeight().toPixD(resolution)); - } else if (psetting.getOrientation() == ReportConstants.PORTRAIT - && paperSize.getWidth().toPixD(resolution) > paperSize.getHeight() - .toPixD(resolution)) { - paperWidth = Math.min(paperSize.getWidth().toPixD(resolution), paperSize - .getHeight().toPixD(resolution)); - paperHeight = Math.max(paperSize.getWidth().toPixD(resolution), paperSize - .getHeight().toPixD(resolution)); - } - - paperPaintWidth = paperWidth - margin.getLeft().toPixD(resolution) - - margin.getRight().toPixD(resolution); - paperPaintHeight = paperHeight - margin.getTop().toPixD(resolution) - - margin.getBottom().toPixD(resolution) - - reportSettings.getHeaderHeight().toPixD(resolution) - - reportSettings.getFooterHeight().toPixD(resolution); - } - - private void paintGridLine(Graphics g, Grid grid, double realWidth, double realHeight, - int resolution) { - Graphics2D g2d = (Graphics2D) g; - - // --开始画水平,垂直线. - g2d.setPaint(grid.getGridLineColor()); // line color. - GraphHelper.setStroke(g2d, GraphHelper.getStroke(Constants.LINE_THIN)); - - // 分页线 - paginateLineList.clear(); - - new DrawVerticalLineHelper(grid.getVerticalBeginValue(), verticalEndValue, - grid.isShowGridLine(), grid.isShowPaginateLine(), rowHeightList, paperPaintHeight, - paginateLineList, realWidth, resolution).iterateStart2End(g2d); - - new DrawHorizontalLineHelper(grid.getHorizontalBeginValue(), horizontalEndValue, - grid.isShowGridLine(), grid.isShowPaginateLine(), columnWidthList, paperPaintWidth, - paginateLineList, realHeight, resolution).iterateStart2End(g2d); - } - - /** - * 最后处理 - */ - public void finalize() { - try { - super.finalize(); - if (drawFlowRect != null) { - this.drawFlowRect.exit(); - } - } catch (Throwable e) { - FRContext.getLogger().error(e.getMessage(), e); - } - } - - private static abstract class DrawLineHelper { - private int startIndex; - private int endIndex; - - private boolean showGridLine; - private boolean showPaginateLine; - - private DynamicUnitList sizeList; - private double paperPaintSize; - - private List paginateLineList; - - Line2D tmpLine2D = new Line2D.Double(0, 0, 0, 0); - - private int resolution; - - DrawLineHelper(int startIndex, int endIndex, boolean showGridLine, - boolean showPaginateLine, DynamicUnitList sizeList, double paperPaintSize, - List paginateLineList, int resolution) { - this.startIndex = startIndex; - this.endIndex = endIndex; - this.showGridLine = showGridLine; - this.showPaginateLine = showPaginateLine; - this.sizeList = sizeList; - this.paperPaintSize = paperPaintSize; - - this.paginateLineList = paginateLineList; - this.resolution = resolution; - } - - protected void iterateStart2End(Graphics2D g2d) { - float tmpSize = 0, paperSumSize = 0, sumSize = 0; - for (int i = 0; i <= endIndex; i++) { - // denny: 开始 - if (i == 0) { - i = startIndex; - - // denny: 增加从0到Grid左边被hide的列宽 - for (int k = 0; k < startIndex; k++) { - tmpSize = sizeList.get(k).toPixF(resolution); - - paperSumSize += tmpSize; - if (paperSumSize >= paperPaintSize) { - paperSumSize = tmpSize; - } - } - } - - // adjust height. - tmpSize = sizeList.get(i).toPixF(resolution); - paperSumSize += tmpSize; - - if (showGridLine) {// paint line. - setLine2D((int) sumSize); - g2d.draw(tmpLine2D); - } - - // paint paper margin line. - if (showPaginateLine && paperSumSize >= paperPaintSize) { - paginateLineList.add(getPaginateLine2D((int) sumSize)); - paperSumSize = tmpSize; - } - - sumSize += tmpSize; - } - - // paint 最后一个横线.. - if (showGridLine) { - drawLastLine(g2d, (int) sumSize); - } - } - - protected abstract void setLine2D(int sumSize); - - protected abstract Line2D.Double getPaginateLine2D(int sumSize); - - protected abstract void drawLastLine(Graphics2D g2d, int sumSize); - } - - private class DrawVerticalLineHelper extends DrawLineHelper { - private double realWidth; - - DrawVerticalLineHelper(int startIndex, int endIndex, boolean showGridLine, - boolean showPaginateLine, DynamicUnitList unitSizeList, double paperPaintSize, - List paginateLineList, double realWidth, int resolution) { - super(startIndex, endIndex, showGridLine, showPaginateLine, unitSizeList, - paperPaintSize, paginateLineList, resolution); - this.realWidth = realWidth; - } - - @Override - protected Double getPaginateLine2D(int sumHeight) { - return new Line2D.Double(0, sumHeight, gridSize.width, sumHeight); - } - - @Override - protected void setLine2D(int sumHeight) { - tmpLine2D.setLine(0, sumHeight, realWidth, sumHeight); - } - - @Override - protected void drawLastLine(Graphics2D g2d, int sumHeight) { - GraphHelper.drawLine(g2d, 0, sumHeight, realWidth, sumHeight); - } - } - - private class DrawHorizontalLineHelper extends DrawLineHelper { - private double realHeight; - - DrawHorizontalLineHelper(int startIndex, int endIndex, boolean showGridLine, - boolean showPaginateLine, DynamicUnitList unitSizeList, double paperPaintSize, - List paginateLineList, double realHeight, int resolution) { - super(startIndex, endIndex, showGridLine, showPaginateLine, unitSizeList, - paperPaintSize, paginateLineList, resolution); - this.realHeight = realHeight; - } - - @Override - protected Double getPaginateLine2D(int sumWidth) { - return new Line2D.Double(sumWidth, 0, sumWidth, gridSize.height); - } - - @Override - protected void setLine2D(int sumWidth) { - tmpLine2D.setLine(sumWidth, 0, sumWidth, realHeight); - } - - @Override - protected void drawLastLine(Graphics2D g2d, int sumWidth) { - GraphHelper.drawLine(g2d, sumWidth, 0, sumWidth, realHeight); - } - } - - private void paintCellElements(Graphics g, Grid grid, TemplateElementCase report, int resolution) { - Graphics2D g2d = (Graphics2D) g; - - CellElement selectedCellElement = null; - ElementCasePane reportPane = grid.getElementCasePane(); - Selection sel = reportPane.getSelection(); - - if (sel instanceof CellSelection) { - selectedCellElement = report.getCellElement(((CellSelection) sel).getColumn(), ((CellSelection) sel).getRow()); - } - - int horizontalBeginValue = grid.getHorizontalBeginValue(); - int verticalBeginValue = grid.getVerticalBeginValue(); - - // 元素数目. - Shape oldClip = null; - TemplateCellElement tmpCellElement = null; - - Iterator cells = report.intersect(horizontalBeginValue, verticalBeginValue, - horizontalEndValue - horizontalBeginValue, verticalEndValue - verticalBeginValue); - - // 计算隐藏掉的width - double hideWidth = columnWidthList.getRangeValue(0, horizontalValue).toPixD(resolution); - double hideHeight = rowHeightList.getRangeValue(0, verticalValue).toPixD(resolution); - - // 清空left和top的绘画区域. - this.left_col_row_rect.setRect(0, 0, 0, 0); - this.top_col_row_rect.setRect(0, 0, 0, 0); - - paintDetailedCellElements(g2d, cells, tmpCellElement, reportPane, selectedCellElement, hideWidth, hideHeight, oldClip, report); - paintBorder(g2d, tmpCellElement, report); - paintFatherLeft(g2d, selectedCellElement, report); - } - - private void paintDetailedCellElements(Graphics2D g2d, Iterator cells, TemplateCellElement tmpCellElement, ElementCasePane reportPane, - CellElement selectedCellElement, double hideWidth, double hideHeight, Shape oldClip, TemplateElementCase report) { - while (cells.hasNext()) { - tmpCellElement = (TemplateCellElement) cells.next(); - if (tmpCellElement == null) { - continue; - } - // 强制分页线 - this.calculateForcedPagingOfCellElement(reportPane, tmpCellElement, hideWidth, hideHeight); - storeFatherLocation(selectedCellElement, tmpCellElement); - // element bounds - // TODO: 2017/7/13 tmpRectangle : 72*19 - this.caculateScrollVisibleBounds(this.tmpRectangle, tmpCellElement.getColumn(), - tmpCellElement.getRow(), tmpCellElement.getColumnSpan(), - tmpCellElement.getRowSpan()); - // peter:clip的区域. - // peter:保留clip. - oldClip = g2d.getClip(); /* - * alex:此处的tmpRectangle_1被GridUtils.validate判断必定为true, - * 因为这些tmpCellElement是intersect的结果 所以,不必判断了 - */ - g2d.clip(this.tmpRectangle); - - // 这边为什么要加1? 因为单元格的左边和上面有线,宽度为一,属于此单元格,画单元格的内容不应该把那条线给遮住了 - g2d.translate(this.tmpRectangle.getX() + 1, this.tmpRectangle.getY() + 1); - - // peter:tmpRectangle2D_3只是一个临时的Rectangle2D,由于后面不少地方需要用到这个矩形 - this.cell_back_rect.setRect(0, 0, this.tmpRectangle.getWidth() - 1, - this.tmpRectangle.getHeight() - 1); - // peter:对于合并的单元格,需要先白色的背景来清除背景. - if (tmpCellElement.getColumnSpan() > 1 || tmpCellElement.getRowSpan() > 1) { - WHITE_Backgorund.paint(g2d, this.cell_back_rect); - //daniel:上面这里就有问题了啊....报表的背景在这个之前画的 会覆盖报表背景....不过只是设计器中看到预览浏览没问题 - } - // peter:将这个元素添加到需要paint的元素列表当中去,留着画边框线.. - paintCellElementList.add(tmpCellElement); - paintCellElementRectangleList.add(this.tmpRectangle.clone()); - - - int cellWidth = (int) this.tmpRectangle.getWidth(); - int cellHeight = (int) this.tmpRectangle.getHeight(); - // denny_Grid: 画Grid中单元格的内容(包括单元格的背景Content + Background), 不包括边框 - - painter.paintBackground(g2d, report, tmpCellElement, cellWidth, cellHeight); - painter.paintContent(g2d, report, tmpCellElement, cellWidth, cellHeight, resolution); - // denny_Grid: 注意下面还要减一, 因为上面translate时加一 - g2d.translate(-this.tmpRectangle.getX() - 1, -this.tmpRectangle.getY() - 1); - paintAuthorityCell(g2d, tmpCellElement); - g2d.setClip(oldClip); - } - } - - private void paintAuthorityCell(Graphics2D g2d, TemplateCellElement tmpCellElement) { - String selectedRole = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); - boolean isWidgetAuthority = false; - if (tmpCellElement.getWidget() != null) { - isWidgetAuthority = tmpCellElement.getWidget().isDirtyWidget(selectedRole); - } - boolean isCellDoneAuthority = tmpCellElement.isDoneAuthority(selectedRole) || tmpCellElement.isDoneNewValueAuthority(selectedRole); - boolean isDoneAuthority = isWidgetAuthority || isCellDoneAuthority; - if (isAuthority && isDoneAuthority) { - Composite oldComposite = g2d.getComposite(); - g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f)); - Paint oldPaint = g2d.getPaint(); - g2d.setPaint(UIConstants.AUTHORITY_COLOR); - GraphHelper.fill(g2d, tmpRectangle); - g2d.setComposite(oldComposite); - g2d.setPaint(oldPaint); - } - } - - private void storeFatherLocation(CellElement selectedCellElement, TemplateCellElement tmpCellElement) { -// // 需要检查是否在Design状态隐藏. -// CellGUIAttr cellGUIAttr = tmpCellElement.getCellGUIAttr(); -// if (cellGUIAttr == null) { -// // 不set给curCellElement,赋值只是为了方便下面的操作 -// cellGUIAttr = CellGUIAttr.DEFAULT_CELLGUIATTR; -// } - - /* - * 记录当前选中的单元格的左父与上父的位置于leftColumnRowRectangle2D & - * topColumnRowRectangle2D - */ - if (selectedCellElement == tmpCellElement) { - CellExpandAttr cellExpandAttr = tmpCellElement.getCellExpandAttr(); - if (cellExpandAttr != null) { - ColumnRow leftColumnRow = cellExpandAttr.getLeftParentColumnRow(); - // leftColumnRow必须在可视范围内 - if (ColumnRow.validate(leftColumnRow)) { - this.caculateScrollVisibleBounds(this.left_col_row_rect, - leftColumnRow.getColumn(), leftColumnRow.getRow(), 1, 1); - } - - ColumnRow topColumnRow = cellExpandAttr.getUpParentColumnRow(); - // topColumnRow必须在可视范围内 - if (ColumnRow.validate(topColumnRow)) { - this.caculateScrollVisibleBounds(this.top_col_row_rect, - topColumnRow.getColumn(), topColumnRow.getRow(), 1, 1); - } - } - } - } - - private void paintBorder(Graphics2D g2d, TemplateCellElement tmpCellElement, TemplateElementCase report) { - // 画边框 - Rectangle2D.Double tmpCellElementRectangle; - for (int i = 0; i < paintCellElementList.size(); i++) { - tmpCellElement = (TemplateCellElement) paintCellElementList.get(i); - tmpCellElementRectangle = (Rectangle2D.Double) paintCellElementRectangleList.get(i); - - // 需要检查是否在Design状态隐藏. - CellGUIAttr cellGUIAttr = tmpCellElement.getCellGUIAttr(); - if (cellGUIAttr == null) { - // 不set给curCellElement,赋值只是为了方便下面的操作 - cellGUIAttr = CellGUIAttr.DEFAULT_CELLGUIATTR; - } - - g2d.translate(tmpCellElementRectangle.getX(), tmpCellElementRectangle.getY()); - - painter.paintBorder(g2d, report, tmpCellElement, tmpCellElementRectangle.getWidth(), - tmpCellElementRectangle.getHeight()); - - g2d.translate(-tmpCellElementRectangle.getX(), -tmpCellElementRectangle.getY()); - } - } - - protected void paintFatherLeft(Graphics2D g2d, CellElement selectedCellElement, TemplateElementCase report) { - // 画左父格子. - if (validate(this.left_col_row_rect) && this.left_col_row_rect.getHeight() > 5) { - g2d.setPaint(Color.BLUE); - double centerX = this.left_col_row_rect.getX() + 4; - double centerY = this.left_col_row_rect.getY() + this.left_col_row_rect.getHeight() / 2; - GraphHelper.drawLine(g2d, centerX, centerY - 5, centerX, centerY + 5); - GeneralPath polyline = new GeneralPath(Path2D.WIND_EVEN_ODD, 3); - polyline.moveTo((float) centerX, (float) centerY + 5); - polyline.lineTo((float) centerX + 3, (float) centerY + 5 - 4); - polyline.lineTo((float) centerX - 2, (float) centerY + 5 - 4); - GraphHelper.fill(g2d, polyline); - } - if (validate(this.top_col_row_rect) && this.top_col_row_rect.getWidth() > 5) { - g2d.setPaint(Color.BLUE); - double centerX = this.top_col_row_rect.getX() + this.top_col_row_rect.getWidth() / 2; - double centerY = this.top_col_row_rect.getY() + 4; - GraphHelper.drawLine(g2d, centerX - 5, centerY, centerX + 5, centerY); - GeneralPath polyline = new GeneralPath(Path2D.WIND_EVEN_ODD, 3); - polyline.moveTo((float) centerX + 5, (float) centerY); - polyline.lineTo((float) centerX + 5 - 4, (float) centerY + 3); - polyline.lineTo((float) centerX + 5 - 4, (float) centerY - 3); - - GraphHelper.fill(g2d, polyline); - } - } - - private void paintPaginateLines(Graphics g, Grid grid) { - JTemplate jTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); - if(!jTemplate.isJWorkBook()){ - //报表块无分页之说 - return; - } - Graphics2D g2d = (Graphics2D) g; - - // james 画分页线 - if (this.paginateLineList.size() > 0) { - Line2D tmpLine2D = new Line2D.Double(0, 0, 0, 0); - - // james - // 梳理forcedPaperMarginLineList,将其中相同的线去除,否则在Grid的paintConponet时会因setXORMode而将相同的线给覆盖掉 - Line2D tmpLine2D2; - for (int j = 0; j < paginateLineList.size(); j++) { - tmpLine2D = (Line2D) paginateLineList.get(j);// 直接强制转换,因为List中肯定都是Line2D型的 - for (int k = j + 1; k < paginateLineList.size(); k++) { - tmpLine2D2 = (Line2D) paginateLineList.get(k); - if (tmpLine2D2.getX1() == tmpLine2D.getX1() - && tmpLine2D2.getX2() == tmpLine2D.getX2() - && tmpLine2D2.getY1() == tmpLine2D.getY1() - && tmpLine2D2.getY2() == tmpLine2D.getY2()) { - paginateLineList.remove(k); - } - } - } - - g2d.setPaint(grid.getPaginationLineColor()); - - //g2d.setXORMode(Utils.getXORColor(grid.getPaginationLineColor())); - GraphHelper.setStroke(g2d, GraphHelper.getStroke(Constants.LINE_DASH_DOT)); - for (int i = 0, len = paginateLineList.size(); i < len; i++) { - g2d.draw((Shape) paginateLineList.get(i)); - } - - g2d.setPaintMode(); - } - } - - private void paintGridSelection(Graphics g, Grid grid, ElementCase report) { - Graphics2D g2d = (Graphics2D) g; - Selection sel = grid.getElementCasePane().getSelection(); - // 画GridSelection:CELL - if (sel instanceof CellSelection) {// james:cell不可以select的时候就不画了 - CellSelection gridSelection = (CellSelection) sel; - // peter:开始选择框CellRectangle. - Rectangle editRectangle = gridSelection.getEditRectangle(); - int cellRectangleCount = gridSelection.getCellRectangleCount(); - Area selectedCellRectArea = new Area(); - Area editCellRectArea = new Area(); - // denny: editCellRectArea - ElementCasePane reportPane = grid.getElementCasePane(); - if (DesignerContext.getFormatState() == DesignerContext.FORMAT_STATE_NULL) { - this.caculateScrollVisibleBounds(this.tmpRectangle, new Rectangle( - gridSelection.getColumn(), gridSelection.getRow(), gridSelection.getColumnSpan(), gridSelection.getRowSpan() - )); - if (validate(this.tmpRectangle)) { - editCellRectArea.add(new Area(this.tmpRectangle)); - } - if (cellRectangleCount == 1) { - paintOne(selectedCellRectArea, gridSelection, grid, g2d); - } else { - paintMore(selectedCellRectArea, gridSelection, grid, g2d, cellRectangleCount, editCellRectArea); - } - } else { - Rectangle referenced = null; - referenced = paintReferenceCell(reportPane, grid, g2d, editCellRectArea, selectedCellRectArea, referenced); - paintFormatArea(selectedCellRectArea, gridSelection, grid, g2d, referenced); - } - // denny: 标记公式用到的单元格 - paintGridSelectionForFormula(g2d, report, gridSelection); - } - } - - private Rectangle paintReferenceCell(ElementCasePane reportPane, Grid grid, Graphics2D g2d, Area editCellRectArea, Area selectedCellRectArea, Rectangle referenced) { - CellSelection referencedCell = reportPane.getFormatReferencedCell(); - if (referencedCell == null) { - return null; - } - - if (DesignerContext.getReferencedIndex() != - ((JTemplate) HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()).getEditingReportIndex()) { - return null; - } - referenced = new Rectangle( - referencedCell.getColumn(), referencedCell.getRow(), referencedCell.getColumnSpan(), referencedCell.getRowSpan() - ); - this.caculateScrollVisibleBounds(this.tmpRectangle, referenced); - if (validate(this.tmpRectangle)) { - editCellRectArea.add(new Area(this.tmpRectangle)); - } - paintOne(selectedCellRectArea, referencedCell, grid, g2d); - return referenced; - } - - - private void paintFormatArea(Area selectedCellRectArea, CellSelection gridSelection, Grid grid, Graphics2D g2d, Rectangle referenced) { - Rectangle format = new Rectangle( - gridSelection.getColumn(), gridSelection.getRow(), gridSelection.getColumnSpan(), gridSelection.getRowSpan() - ); - if (ComparatorUtils.equals(DesignerContext.getReferencedElementCasePane(), grid.getElementCasePane()) && ComparatorUtils.equals(format, referenced)) { - return; - } - - this.caculateScrollVisibleBounds(this.tmpRectangle, format); - if (validate(this.tmpRectangle)) { - selectedCellRectArea = new Area(this.tmpRectangle); - double selectedCellX = this.tmpRectangle.getX(); - double selectedCellY = this.tmpRectangle.getY(); - double selectedCellWidth = this.tmpRectangle.getWidth(); - double selectedCellHeight = this.tmpRectangle.getHeight(); - - // TODO ALEX_SEP 这个半透明的,画不画呢? - // peter:画半透明的背景,必须SelectCellRectangle和EditCellRectangle不重复才需要半透明背景. - if (gridSelection.getRowSpan() > 1 - || gridSelection.getColumnSpan() > 1) { - Composite oldComposite = g2d.getComposite(); - g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); - g2d.setPaint(grid.getSelectedBackground()); - GraphHelper.fill(g2d, selectedCellRectArea); - g2d.setComposite(oldComposite); - } - - - paintNormal(g2d, selectedCellX, selectedCellY, selectedCellWidth, selectedCellHeight, grid); - } - - } - - private void paintOne(Area selectedCellRectArea, CellSelection gridSelection, Grid grid, Graphics2D g2d) { - if (validate(this.tmpRectangle)) { - selectedCellRectArea = new Area(this.tmpRectangle); - double selectedCellX = this.tmpRectangle.getX(); - double selectedCellY = this.tmpRectangle.getY(); - double selectedCellWidth = this.tmpRectangle.getWidth(); - double selectedCellHeight = this.tmpRectangle.getHeight(); - - // TODO ALEX_SEP 这个半透明的,画不画呢? - // peter:画半透明的背景,必须SelectCellRectangle和EditCellRectangle不重复才需要半透明背景. - if (gridSelection.getRowSpan() > 1 - || gridSelection.getColumnSpan() > 1) { - Composite oldComposite = g2d.getComposite(); - g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); - g2d.setPaint(grid.getSelectedBackground()); - GraphHelper.fill(g2d, selectedCellRectArea); - g2d.setComposite(oldComposite); - } - - - // 判断是否使用智能添加单元格若使用智能添加单元格,则画动态虚线 - paintGridSelectionDependsOnTableSelectionPane(g2d, selectedCellX, selectedCellY, selectedCellWidth, selectedCellHeight, grid); - } - } - - - private void paintMore(Area selectedCellRectArea, CellSelection gridSelection, Grid grid, Graphics2D g2d, int cellRectangleCount, Area editCellRectArea) { - - selectedCellRectArea = new Area(); - // cellRectangleCount > 1 - - // p:下面处理多个选择的情况,麻烦一些. - for (int i = 0; i < cellRectangleCount; i++) { - Rectangle cellRectangle = gridSelection.getCellRectangle(i); - - // p:计算CellSelection. - this.caculateScrollVisibleBounds(this.tmpRectangle, cellRectangle); - - if (validate(this.tmpRectangle)) { - selectedCellRectArea.add(new Area(this.tmpRectangle)); - paintGridSelectionDependsOnTableSelectionPane(g2d, tmpRectangle.x, tmpRectangle.y, tmpRectangle.width, tmpRectangle.height, grid); - } - } - - selectedCellRectArea.add(editCellRectArea); - selectedCellRectArea.exclusiveOr(editCellRectArea); - - // denny: 画半透明背景 - Composite oldComposite = g2d.getComposite(); - g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); - g2d.setPaint(grid.getSelectedBackground()); - GraphHelper.fill(g2d, selectedCellRectArea); - g2d.setComposite(oldComposite); - - // p:画edit空白区域的边框. - g2d.setPaint(Color.blue); - // marks:如果editCellRectArea为空,就不需要画,说明都不在可见区域内 - if (editCellRectArea != null) { - GraphHelper.draw(g2d, editCellRectArea); - } - - - } - - - private void paintGridSelectionForFormula(Graphics2D g2d, ElementCase report, CellSelection cs) { - // denny: 标记公式用到的单元格 - if (report.getCellValue(cs.getColumn(), cs.getRow()) instanceof Formula) { - Formula tmpFormula = (Formula) report - .getCellValue(cs.getColumn(), cs.getRow()); - String statement = tmpFormula.getContent(); - // denny: 获得公式中包含的所有单元格 - ColumnRow[] columnRowArray = new ColumnRow[0]; - try { - columnRowArray = CalculatorUtils.relatedColumnRowArray(statement.substring(1)); - } catch (ANTLRException ae) { - // do nothing. - } - Area formulaCellArea = null; - for (int i = 0; i < columnRowArray.length; i++) { - ColumnRow columnRow = columnRowArray[i]; - int columnSpan = 1; - int rowSpan = 1; - CellElement columnRowCE = report.getCellElement(columnRow.getColumn(), - columnRow.getRow()); - if (columnRowCE != null) { - columnSpan = columnRowCE.getColumnSpan(); - rowSpan = columnRowCE.getRowSpan(); - // _denny: 如果取得是合并单元格的后面的,那么需要重置columnRow - if (columnSpan > 1 || rowSpan > 1) { - columnRow = ColumnRow.valueOf(columnRowCE.getColumn(), - columnRowCE.getRow()); - } - } - - this.caculateScrollVisibleBounds(this.tmpRectangle, columnRow.getColumn(), - columnRow.getRow(), columnSpan, rowSpan); - - if (validate(this.tmpRectangle)) { - paintFormulaCellArea(g2d, formulaCellArea, i); - } - } - } - } - - protected void paintFormulaCellArea(Graphics2D g2d, Area formulaCellArea, int i) { - // denny: 标记格子的边框 - formulaCellArea = new Area(new Rectangle2D.Double(this.tmpRectangle.getX(), - this.tmpRectangle.getY(), this.tmpRectangle.getWidth(), - this.tmpRectangle.getHeight())); - - // peter:去掉edit的格子区域 - formulaCellArea.exclusiveOr(new Area( - new Rectangle2D.Double(this.tmpRectangle.getX() + 1, - this.tmpRectangle.getY() + 1, - this.tmpRectangle.getWidth() - 2, this.tmpRectangle - .getHeight() - 2))); - - formulaCellArea.add(new Area(new Rectangle2D.Double(this.tmpRectangle - .getX(), this.tmpRectangle.getY(), 3, 3))); - formulaCellArea.add(new Area(new Rectangle2D.Double(this.tmpRectangle - .getX() + this.tmpRectangle.getWidth() - 3, this.tmpRectangle - .getY(), 3, 3))); - formulaCellArea.add(new Area(new Rectangle2D.Double(this.tmpRectangle - .getX(), this.tmpRectangle.getY() + this.tmpRectangle.getHeight() - - 3, 3, 3))); - formulaCellArea.add(new Area(new Rectangle2D.Double(this.tmpRectangle - .getX() + this.tmpRectangle.getWidth() - 3, this.tmpRectangle - .getY() + this.tmpRectangle.getHeight() - 3, 3, 3))); - g2d.setPaint(new Color(((i + 2) * 50) % 256, ((i + 1) * 50) % 256, - (i * 50) % 256)); - if (formulaCellArea != null) { - GraphHelper.fill(g2d, formulaCellArea); - } - } - - private void paintGridSelectionDependsOnTableSelectionPane(Graphics2D g2d, double selectedCellX, double selectedCellY, - double selectedCellWidth, double selectedCellHeight, Grid grid) { - if (grid.IsNotShowingTableSelectPane()) { - // peter:构建并开始画边框,只需要对第一个Cell - paintNormal(g2d, selectedCellX, selectedCellY, selectedCellWidth, selectedCellHeight, grid); - } else { - // 动态虚线 - Stroke stroke = g2d.getStroke(); - g2d.setStroke(new BasicStroke(1)); - if (drawFlowRect == null) { - drawFlowRect = new DrawFlowRect(); - } - drawFlowRect.setGrid(grid); - drawFlowRect.drawFlowRect(g2d, (int) selectedCellX, (int) selectedCellY, - (int) selectedCellWidth + (int) selectedCellX, - (int) selectedCellHeight + (int) selectedCellY); - g2d.setStroke(stroke); - } - } - - - private void paintNormal(Graphics2D g2d, double selectedCellX, double selectedCellY, - double selectedCellWidth, double selectedCellHeight, Grid grid) { - this.back_or_selection_rect.setRect(selectedCellX - 1, selectedCellY - 1, - selectedCellWidth + 3, selectedCellHeight + 3); - Area borderLineArea = new Area(this.back_or_selection_rect); - this.back_or_selection_rect.setRect(selectedCellX + 2, selectedCellY + 2, - selectedCellWidth - 3, selectedCellHeight - 3); - borderLineArea.exclusiveOr(new Area(this.back_or_selection_rect)); - this.back_or_selection_rect.setRect(selectedCellX + selectedCellWidth - 1, - selectedCellY + selectedCellHeight - 3, 3, 1); - borderLineArea.exclusiveOr(new Area(this.back_or_selection_rect)); - this.back_or_selection_rect.setRect(selectedCellX + selectedCellWidth - 3, - selectedCellY + selectedCellHeight - 1, 1, 3); - borderLineArea.exclusiveOr(new Area(this.back_or_selection_rect)); - // peter:右下角落的那个小黑方块. - this.back_or_selection_rect.setRect(selectedCellX + selectedCellWidth - 2, - selectedCellY + selectedCellHeight - 2, 5, 5); - borderLineArea.add(new Area(this.back_or_selection_rect)); - - //g2d.setXORMode(Utils.getXORColor(grid.getSelectedBorderLineColor())); - g2d.setPaint(grid.getSelectedBorderLineColor()); - GraphHelper.fill(g2d, borderLineArea); - g2d.setPaintMode(); - } - - private void paintFloatElements(Graphics g, Grid grid, ElementCase report, int resolution) { - Graphics2D g2d = (Graphics2D) g; - - Selection sel = grid.getElementCasePane().getSelection(); - - Iterator flotIt = report.floatIterator(); - while (flotIt.hasNext()) { - FloatElement tmpFloatElement = (FloatElement) flotIt.next(); - - int lastRow = rowHeightList.getValueIndex(FU.getInstance( - tmpFloatElement.getTopDistance().toFU() + tmpFloatElement.getHeight().toFU() - )); - - // 限制相对位置. - if (isSuitablePosition(lastRow)) { - float floatX = columnWidthList.getRangeValue(horizontalValue, 0).toPixF( - resolution) - + tmpFloatElement.getLeftDistance().toPixF(resolution); - float floatY = rowHeightList.getRangeValue(verticalValue, 0).toPixF(resolution) - + tmpFloatElement.getTopDistance().toPixF(resolution); - - g2d.translate(floatX, floatY); - - PaintUtils.paintFloatElement(g2d, tmpFloatElement, - tmpFloatElement.getWidth().toPixI(resolution), - tmpFloatElement.getHeight().toPixI(resolution), resolution); - - g2d.translate(-floatX, -floatY); - } - } - - // p:画选中的悬浮元素的边框,这里必须再循环一次所有的悬浮元素, - // 因为这些方框选择点,及时这个悬浮元素被覆盖的时候,还能够选中点击的,来改变元素的尺寸的. - paintFloatElementsBorder(g2d, grid, sel, flotIt, report); - - paintAuthorityFloatElement(g2d, report, ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(), grid); - } - - private boolean isSuitablePosition(int lastRow) { - // confusing logic... - return 0 >= verticalValue || 0 <= verticalEndValue || lastRow >= verticalValue - || lastRow <= verticalValue; - } - - private void paintFloatElementsBorder(Graphics2D g2d, Grid grid, Selection sel, Iterator flotIt, ElementCase report) { - // p:画选中的悬浮元素的边框,这里必须再循环一次所有的悬浮元素, - // 因为这些方框选择点,及时这个悬浮元素被覆盖的时候,还能够选中点击的,来改变元素的尺寸的. - if (sel instanceof FloatSelection) { - flotIt = report.floatIterator(); - while (flotIt.hasNext()) { - FloatElement tmpFloatElement = (FloatElement) flotIt.next(); - // p:如果不是选中的悬浮元素,直接continue. - if (!ComparatorUtils.equals(tmpFloatElement.getName(), ((FloatSelection) sel).getSelectedFloatName())) { - continue; - } - - Rectangle2D[] rectArray = calculateFloatElementPoints(tmpFloatElement); - - GraphHelper.setStroke(g2d, GraphHelper.getStroke(Constants.LINE_THIN)); - for (int j = 0; j < rectArray.length; j++) { - g2d.setPaint(Utils.getXORColor(grid.getSelectedBorderLineColor())); - GraphHelper.fill(g2d, rectArray[j]); - g2d.setPaint(grid.getSelectedBorderLineColor()); - GraphHelper.draw(g2d, rectArray[j]); - } - } - } - } - - - private Rectangle2D[] calculateFloatElementPoints(FloatElement tmpFloatElement) { - // width and height - float floatX1 = columnWidthList.getRangeValue(horizontalValue, 0).toPixF( - resolution) + tmpFloatElement.getLeftDistance().toPixF(resolution); - float floatY1 = rowHeightList.getRangeValue(verticalValue, 0).toPixF(resolution) - + tmpFloatElement.getTopDistance().toPixF(resolution); - int floatX2 = (int) (floatX1 + tmpFloatElement.getWidth().toPixF(resolution)); - int floatY2 = (int) (floatY1 + tmpFloatElement.getHeight().toPixF(resolution)); - - return new Rectangle2D[]{ - new Rectangle2D.Double(floatX1 - 3, floatY1 - 3, 6, 6), - new Rectangle2D.Double((floatX1 + floatX2) / 2 - 3, floatY1 - 3, 6, 6), - new Rectangle2D.Double(floatX2 - 3, floatY1 - 3, 6, 6), - new Rectangle2D.Double(floatX2 - 3, (floatY1 + floatY2) / 2 - 3, 6, 6), - new Rectangle2D.Double(floatX2 - 3, floatY2 - 3, 6, 6), - new Rectangle2D.Double((floatX1 + floatX2) / 2 - 3, floatY2 - 3, 6, 6), - new Rectangle2D.Double(floatX1 - 3, floatY2 - 3, 6, 6), - new Rectangle2D.Double(floatX1 - 3, (floatY1 + floatY2) / 2 - 3, 6, 6)}; - } - - - private void paintAuthorityFloatElement(Graphics2D g2d, ElementCase report, String selectedRoles, Grid grid) { - Iterator flotIt = report.floatIterator(); - while (flotIt.hasNext()) { - FloatElement tmpFloatElement = (FloatElement) flotIt.next(); - // p:如果不是选中的悬浮元素,直接continue. - if (!tmpFloatElement.getFloatPrivilegeControl().checkInvisible(selectedRoles)) { - continue; - } - float floatX1 = columnWidthList.getRangeValue(horizontalValue, 0).toPixF( - resolution) + tmpFloatElement.getLeftDistance().toPixF(resolution); - float floatY1 = rowHeightList.getRangeValue(verticalValue, 0).toPixF(resolution) - + tmpFloatElement.getTopDistance().toPixF(resolution); - int floatX2 = (int) (floatX1 + tmpFloatElement.getWidth().toPixF(resolution)); - int floatY2 = (int) (floatY1 + tmpFloatElement.getHeight().toPixF(resolution)); - double x = floatX1; - double y = floatY1; - double width = floatX2 - x; - double height = floatY2 - y; - - //画做过权限编辑过的悬浮元素的边框 - if (isAuthority) { - paintAuthorityFloatElementBorder(g2d, x, y, width, height, grid); - } - } - } - - private void paintAuthorityFloatElementBorder(Graphics2D g2d, double selectedCellX, double selectedCellY, - double selectedCellWidth, double selectedCellHeight, Grid grid) { - this.back_or_selection_rect.setRect(selectedCellX - 1, selectedCellY - 1, - selectedCellWidth + 3, selectedCellHeight + 3); - Area borderLineArea = new Area(this.back_or_selection_rect); - g2d.setXORMode(Utils.getXORColor(grid.getSelectedBorderLineColor())); - g2d.setPaint(UIConstants.AUTHORITY_COLOR); - g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f)); - GraphHelper.fill(g2d, borderLineArea); - g2d.setPaintMode(); - } - - private void paintDragCellBorder(Graphics g, Grid grid) { - Graphics2D g2d = (Graphics2D) g; - - if ((grid.getDragType() == GridUtils.DRAG_CELLSELECTION || grid.getDragType() == GridUtils.DRAG_CELLSELECTION_BOTTOMRIGHT_CORNER) - && (grid.getDragRectangle() != null)) { - this.caculateScrollVisibleBounds(this.drag_cell_rect, grid.getDragRectangle()); - - g2d.setPaint(Color.GRAY); - GraphHelper.draw(g2d, this.drag_cell_rect, Constants.LINE_THICK); - } - } - - @Override - /** - * paint - */ - public void paint(Graphics g, JComponent c) { - if (!(c instanceof Grid)) { - throw new IllegalArgumentException("The component c to paint must be a Grid!"); - } - - isAuthority = BaseUtils.isAuthorityEditing(); - - Graphics2D g2d = (Graphics2D) g; - - Grid grid = (Grid) c; - - // 取得ElementCasePane.ElementCase - ElementCasePane elementCasePane = grid.getElementCasePane(); - TemplateElementCase elementCase = elementCasePane.getEditingElementCase();// 取出ElementCase对象 - - dealWithSizeBeforePaint(grid, elementCase); - - double realWidth = gridSize.getWidth();// 宽度 - double realHeight = gridSize.getHeight();// 高度 - - // 画背景 - this.paintBackground(g2d, grid, elementCase, resolution); - - // 画Grid Line - this.paintGridLine(g2d, grid, realWidth, realHeight, resolution); - - // peter:添上线程的支持,有时候,paint元素的时候,可能会有元素被删除了. - // 需要先清除画Border需要的元素. - paintCellElementList.clear(); - paintCellElementRectangleList.clear(); - - // 画单元格元素 - this.paintCellElements(g2d, grid, elementCase, resolution); - - // 画分页线 - this.paintPaginateLines(g2d, grid); - - // 画 GridSelection - if (!(isAuthority && elementCase instanceof WorkSheet && !((WorkSheet) elementCase).isPaintSelection())) { - this.paintGridSelection(g2d, grid, elementCase); - } - - // 画悬浮元素 - this.paintFloatElements(g2d, grid, elementCase, resolution); - - // 画Drag格子的边框. - this.paintDragCellBorder(g2d, grid); - - grid.ajustEditorComponentBounds(); // refresh size - } - - - private void dealWithSizeBeforePaint(Grid grid, TemplateElementCase elementCase) { - // 取出所有的行高和列宽的List - this.rowHeightList = ReportHelper.getRowHeightList(elementCase); - this.columnWidthList = ReportHelper.getColumnWidthList(elementCase); - - this.verticalValue = grid.getVerticalValue(); - this.horizontalValue = grid.getHorizontalValue(); - - int verticalExtent = grid.getVerticalExtent(); - int horizontalExtent = grid.getHorizontalExtent(); - - // denny: set the verticalBeginValue and horizontalBeginValue - grid.setVerticalBeinValue(verticalValue); - grid.setHorizontalBeginValue(horizontalValue); - // denny: end - - // 获得控件的实际尺寸 - this.gridSize = grid.getSize(); - - this.verticalEndValue = verticalValue + verticalExtent + 1; - this.horizontalEndValue = horizontalValue + horizontalExtent + 1; - } - - /** - * 计算单元格可见的边框范围 - * - * @param rect 用于计算的rect - * @param cellElement 单元格 - */ - public void caculateScrollVisibleBounds(Rectangle2D.Double rect, CellElement cellElement) { - caculateScrollVisibleBounds(rect, cellElement.getColumn(), cellElement.getRow(), - cellElement.getColumnSpan(), cellElement.getRowSpan()); - } - - /** - * 计算矩形可见的边框范围 - * - * @param rect 用于计算的rect - * @param target 目标矩形 - */ - public void caculateScrollVisibleBounds(Rectangle2D.Double rect, Rectangle target) { - caculateScrollVisibleBounds(rect, target.x, target.y, target.width, target.height); - } - - /** - * 计算(int column,int row,int columnSpan,int rowSpan,),在Grid控件上面的位置. - * 注意:返回的paintRectangle和clipRectangle不能为null,来区别是否不需要paint或者没有clip. - * 因为这个方法用在Grid里面,为了加快Grid的paint速度,不能不停的new Rectangle()来增加内存的消耗. - *

- * 处理过的tmpRectangle2Ds必须经过validate的处理才可以使用!! - * - * @param rect rect是一个长度为8的Rectangle2D数组, 绘画的区域不可见 paintRectangle.x =INVALID_INTEGER - * @param column 列 - * @param row 行 - * @param columnSpan 列数 - * @param rowSpan 行数 - */ - public void caculateScrollVisibleBounds(Rectangle2D.Double rect, int column, int row, - int columnSpan, int rowSpan) { - // 判断是否在不可见的区域. - if (outOfScreen(column, row, columnSpan, rowSpan)) { - // 如果在屏幕之外,变成INVALID_INTEGER - rect.x = INVALID_INTEGER; - } else { - rect.x = (columnWidthList.getRangeValue(horizontalValue, column)) - .toPixD(resolution); - rect.y = (rowHeightList.getRangeValue(verticalValue, row)).toPixD(resolution); - rect.width = (columnWidthList.getRangeValue(column, column + columnSpan)) - .toPixD(resolution); - rect.height = (rowHeightList.getRangeValue(row, row + rowSpan)).toPixD(resolution); - } - } - - private boolean outOfScreen(int column, int row, int columnSpan, int rowSpan) { - return column > horizontalEndValue || row > verticalEndValue - || column + columnSpan <= horizontalValue || row + rowSpan <= verticalValue; - } - - /** - * 是否有效的Rectangle2D - * - * @param rect 目标rect - * @return 有效返回true - */ - public static boolean validate(Rectangle2D rect) { - return rect != null && rect.getX() != INVALID_INTEGER; - } - - - /** - * double frozenHeight从顶部到冻结窗口的格子高度 - * - * @param reportPane 用于计算的单元格面板 - * @param tmpCellElement 用于计算的element - * @param hideWidth 由于冻结窗口或滚动条滚动隐藏了的总宽度 double - * @param hideHeight 由于冻结窗口或滚动条滚动隐藏了的总高度 double frozenWidth;//从左侧到冻结窗口的格子宽度 - */ - public void calculateForcedPagingOfCellElement(ElementCasePane reportPane, - CellElement tmpCellElement, double hideWidth, double hideHeight) { - if (tmpCellElement == null) { - return; - } - - // 找出所有需要paint的强制分页线 - CellPageAttr cellPageAttr = tmpCellElement.getCellPageAttr(); - if (cellPageAttr == null) { - return; - } - - ElementCase report = reportPane.getEditingElementCase(); - - DynamicUnitList columnWidthList = ReportHelper.getColumnWidthList(report); - DynamicUnitList rowHeightList = ReportHelper.getRowHeightList(report); - - int width = reportPane.getSize().width; - int height = reportPane.getSize().height; - - double sumWidth;// 分页线的起始x位置 - double sumHeight;// 分页线的起始y位置 - if (cellPageAttr.isPageAfterColumn()) { - sumWidth = columnWidthList.getRangeValueFromZero( - tmpCellElement.getColumn() + tmpCellElement.getColumnSpan()).toPixD(resolution) - - hideWidth; - paginateLineList.add(new Line2D.Double(sumWidth, 0, sumWidth, height)); - } - if (cellPageAttr.isPageBeforeColumn()) { - sumWidth = columnWidthList.getRangeValueFromZero(tmpCellElement.getColumn()).toPixD( - resolution) - - hideWidth; - paginateLineList.add(new Line2D.Double(sumWidth, 0, sumWidth, height)); - } - if (cellPageAttr.isPageAfterRow()) { - sumHeight = rowHeightList.getRangeValueFromZero( - tmpCellElement.getRow() + tmpCellElement.getRowSpan()).toPixD(resolution) - - hideHeight; - paginateLineList.add(new Line2D.Double(0, sumHeight, width, sumHeight)); - } - if (cellPageAttr.isPageBeforeRow()) { - sumHeight = rowHeightList.getRangeValueFromZero(tmpCellElement.getRow()).toPixD( - resolution) - - hideHeight; - paginateLineList.add(new Line2D.Double(0, sumHeight, width, sumHeight)); - } - } +package com.fr.grid; + +import com.fr.base.BaseFormula; +import com.fr.base.BaseUtils; +import com.fr.base.DynamicUnitList; +import com.fr.base.FRContext; +import com.fr.base.GraphHelper; +import com.fr.base.Margin; +import com.fr.base.PaperSize; +import com.fr.base.Utils; +import com.fr.base.background.ColorBackground; +import com.fr.base.background.ImageBackground; +import com.fr.design.constants.UIConstants; +import com.fr.design.file.HistoryTemplateListPane; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.mainframe.JTemplate; +import com.fr.design.roleAuthority.ReportAndFSManagePane; +import com.fr.general.Background; +import com.fr.general.ComparatorUtils; +import com.fr.grid.selection.CellSelection; +import com.fr.grid.selection.FloatSelection; +import com.fr.grid.selection.Selection; +import com.fr.page.PaperSettingProvider; +import com.fr.page.ReportSettingsProvider; +import com.fr.report.ReportHelper; +import com.fr.report.cell.CellElement; +import com.fr.report.cell.FloatElement; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.cell.cellattr.CellExpandAttr; +import com.fr.report.cell.cellattr.CellGUIAttr; +import com.fr.report.cell.cellattr.CellPageAttr; +import com.fr.report.core.PaintUtils; +import com.fr.report.core.ReportUtils; +import com.fr.report.elementcase.ElementCase; +import com.fr.report.elementcase.TemplateElementCase; +import com.fr.report.report.Report; +import com.fr.report.stable.ReportConstants; +import com.fr.report.stable.ReportSettings; +import com.fr.report.worksheet.FormElementCase; +import com.fr.report.worksheet.WorkSheet; +import com.fr.stable.ColumnRow; +import com.fr.stable.Constants; +import com.fr.stable.script.CalculatorUtils; +import com.fr.stable.unit.FU; +import com.fr.third.antlr.ANTLRException; + +import javax.swing.*; +import javax.swing.plaf.ComponentUI; +import java.awt.*; +import java.awt.geom.Area; +import java.awt.geom.GeneralPath; +import java.awt.geom.Line2D; +import java.awt.geom.Line2D.Double; +import java.awt.geom.Path2D; +import java.awt.geom.Rectangle2D; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class GridUI extends ComponentUI { + + public static int INVALID_INTEGER = Integer.MIN_VALUE;// 作为不合法的数值. + protected Dimension gridSize; + protected int verticalValue; + protected int horizontalValue; + protected double paperPaintWidth; + protected double paperPaintHeight; + protected DynamicUnitList rowHeightList; + protected DynamicUnitList columnWidthList; + protected int verticalEndValue; + protected int horizontalEndValue; + protected DrawFlowRect drawFlowRect; + // paint的辅助类 + protected List paintCellElementList = new ArrayList(); + protected List paintCellElementRectangleList = new ArrayList(); + protected List paginateLineList = new ArrayList(); // 分页线 + // 为了画白色的背景. + protected static Background WHITE_Backgorund = ColorBackground.getInstance(Color.WHITE); + // CellElementPainter + protected CellElementPainter painter = new CellElementPainter(); + // Left + protected Rectangle2D.Double left_col_row_rect = new Rectangle2D.Double(0, 0, 0, 0); + // Top + protected Rectangle2D.Double top_col_row_rect = new Rectangle2D.Double(0, 0, 0, 0); + protected Rectangle2D.Double back_or_selection_rect = new Rectangle2D.Double(0, 0, 0, 0); + // alex:用来画拖拽中的格子的边框 + protected Rectangle2D.Double drag_cell_rect = new Rectangle2D.Double(0, 0, 0, 0); + // alex:用来画单元格的白色背景,以清空原来画的内容 + protected Rectangle2D.Double cell_back_rect = new Rectangle2D.Double(0, 0, 0, 0); + // 由于报表冻结的时候,当有冻结线穿过merge的格子的时候,最多需要由8个rectangle来决定. + protected Rectangle2D.Double tmpRectangle = new Rectangle2D.Double(INVALID_INTEGER, + INVALID_INTEGER, INVALID_INTEGER, INVALID_INTEGER); + + protected int resolution; + + private boolean isAuthority = false; + + public GridUI(int resolution) { + super(); + this.resolution = resolution; + } + + protected ReportSettingsProvider getReportSettings(ElementCase elementCase) { + if (elementCase instanceof Report) { + return ReportUtils.getReportSettings((Report) elementCase); + } else if(elementCase instanceof FormElementCase){ + return ((FormElementCase) elementCase).getReportSettings(); + } else { + return new ReportSettings(); + } + } + + protected void paintBackground(Graphics g, Grid grid, ElementCase elementCase, int resolution) { + Graphics2D g2d = (Graphics2D) g; + + // 当前的Grid面板的大小 + this.back_or_selection_rect.setRect(0, 0, gridSize.getWidth(), gridSize.getHeight()); + + // 需要用白色背景来清空背景. + clearBackground(g2d, grid); + + // paint print dash line. + this.paperPaintWidth = 0; + this.paperPaintHeight = 0; + + // richer;聚合报表设计中,最初的ElementCase还没有加到Report中,所以elementCase.getReport()可能为空 + ReportSettingsProvider reportSettings = getReportSettings(elementCase); + PaperSettingProvider psetting = reportSettings.getPaperSetting(); + if (grid.isShowPaginateLine()) {// paint paper margin line. + PaperSize paperSize = psetting.getPaperSize(); + Margin margin = psetting.getMargin(); + + double paperWidth = paperSize.getWidth().toPixD(resolution); + double paperHeight = paperSize.getHeight().toPixD(resolution); + // carl:横向就反过来 + if (psetting.getOrientation() == ReportConstants.LANDSCAPE) { + paperWidth = paperSize.getHeight().toPixD(resolution); + paperHeight = paperSize.getWidth().toPixD(resolution); + } + + paperPaintWidth = paperWidth - margin.getLeft().toPixD(resolution) + - margin.getRight().toPixD(resolution); + paperPaintHeight = paperHeight - margin.getTop().toPixD(resolution) + - margin.getBottom().toPixD(resolution) + - reportSettings.getHeaderHeight().toPixD(resolution) + - reportSettings.getFooterHeight().toPixD(resolution); + } + + // denny:画背景.Background + Background background = reportSettings.getBackground(); + + if (background != null) { + // denny: except the ColorBackground and ImageBackground + if (grid.isEnabled() && !(background instanceof ImageBackground)) { + background.paint(g2d, this.back_or_selection_rect); + } + + // denny: make that the background can move with scroll + paintScrollBackground(g2d, grid, background, psetting, reportSettings); + } + } + + private void clearBackground(Graphics2D g2d, Grid grid) { + if (grid.isEnabled()) { + g2d.setPaint(Color.WHITE); + } else { + g2d.setPaint(UIManager.getColor("control")); + } + GraphHelper.fill(g2d, this.back_or_selection_rect); + } + + private void paintScrollBackground(Graphics2D g2d, Grid grid, Background background, PaperSettingProvider psetting, ReportSettingsProvider reportSettings) { + boolean isCanDrawImage = grid.isEditable() || isAuthority; + if (isCanDrawImage && (background instanceof ImageBackground)) { + if (!grid.isShowPaginateLine()) { + calculatePaper(psetting, reportSettings); + } + + ImageBackground imageBackground = (ImageBackground) background; + + int hideWidth = columnWidthList.getRangeValue(0, horizontalValue) + .toPixI(resolution); + int hideHeight = rowHeightList.getRangeValue(0, verticalValue).toPixI(resolution); + + for (int i = 0; i * paperPaintWidth < gridSize.getWidth(); i++) { + for (int j = 0; j * paperPaintHeight < gridSize.getHeight(); j++) { + this.back_or_selection_rect.setRect(i * paperPaintWidth, j + * paperPaintHeight, paperPaintWidth, paperPaintHeight); + imageBackground.paint4Scroll(g2d, this.back_or_selection_rect, hideWidth, + hideHeight); + } + } + + this.back_or_selection_rect + .setRect(0, 0, gridSize.getWidth(), gridSize.getHeight()); + } + } + + + private void calculatePaper(PaperSettingProvider psetting, ReportSettingsProvider reportSettings) { + PaperSize paperSize = psetting.getPaperSize(); + Margin margin = psetting.getMargin(); + + double paperWidth = paperSize.getWidth().toPixD(resolution); + double paperHeight = paperSize.getHeight().toPixD(resolution); + if (psetting.getOrientation() == ReportConstants.LANDSCAPE + && paperSize.getWidth().toPixD(resolution) < paperSize.getHeight() + .toPixD(resolution)) { + paperWidth = Math.max(paperSize.getWidth().toPixD(resolution), paperSize + .getHeight().toPixD(resolution)); + paperHeight = Math.min(paperSize.getWidth().toPixD(resolution), paperSize + .getHeight().toPixD(resolution)); + } else if (psetting.getOrientation() == ReportConstants.PORTRAIT + && paperSize.getWidth().toPixD(resolution) > paperSize.getHeight() + .toPixD(resolution)) { + paperWidth = Math.min(paperSize.getWidth().toPixD(resolution), paperSize + .getHeight().toPixD(resolution)); + paperHeight = Math.max(paperSize.getWidth().toPixD(resolution), paperSize + .getHeight().toPixD(resolution)); + } + + paperPaintWidth = paperWidth - margin.getLeft().toPixD(resolution) + - margin.getRight().toPixD(resolution); + paperPaintHeight = paperHeight - margin.getTop().toPixD(resolution) + - margin.getBottom().toPixD(resolution) + - reportSettings.getHeaderHeight().toPixD(resolution) + - reportSettings.getFooterHeight().toPixD(resolution); + } + + private void paintGridLine(Graphics g, Grid grid, double realWidth, double realHeight, + int resolution) { + Graphics2D g2d = (Graphics2D) g; + + // --开始画水平,垂直线. + g2d.setPaint(grid.getGridLineColor()); // line color. + GraphHelper.setStroke(g2d, GraphHelper.getStroke(Constants.LINE_THIN)); + + // 分页线 + paginateLineList.clear(); + + new DrawVerticalLineHelper(grid.getVerticalBeginValue(), verticalEndValue, + grid.isShowGridLine(), grid.isShowPaginateLine(), rowHeightList, paperPaintHeight, + paginateLineList, realWidth, resolution).iterateStart2End(g2d); + + new DrawHorizontalLineHelper(grid.getHorizontalBeginValue(), horizontalEndValue, + grid.isShowGridLine(), grid.isShowPaginateLine(), columnWidthList, paperPaintWidth, + paginateLineList, realHeight, resolution).iterateStart2End(g2d); + } + + /** + * 最后处理 + */ + public void finalize() { + try { + super.finalize(); + if (drawFlowRect != null) { + this.drawFlowRect.exit(); + } + } catch (Throwable e) { + FRContext.getLogger().error(e.getMessage(), e); + } + } + + private static abstract class DrawLineHelper { + private int startIndex; + private int endIndex; + + private boolean showGridLine; + private boolean showPaginateLine; + + private DynamicUnitList sizeList; + private double paperPaintSize; + + private List paginateLineList; + + Line2D tmpLine2D = new Line2D.Double(0, 0, 0, 0); + + private int resolution; + + DrawLineHelper(int startIndex, int endIndex, boolean showGridLine, + boolean showPaginateLine, DynamicUnitList sizeList, double paperPaintSize, + List paginateLineList, int resolution) { + this.startIndex = startIndex; + this.endIndex = endIndex; + this.showGridLine = showGridLine; + this.showPaginateLine = showPaginateLine; + this.sizeList = sizeList; + this.paperPaintSize = paperPaintSize; + + this.paginateLineList = paginateLineList; + this.resolution = resolution; + } + + protected void iterateStart2End(Graphics2D g2d) { + float tmpSize = 0, paperSumSize = 0, sumSize = 0; + for (int i = 0; i <= endIndex; i++) { + // denny: 开始 + if (i == 0) { + i = startIndex; + + // denny: 增加从0到Grid左边被hide的列宽 + for (int k = 0; k < startIndex; k++) { + tmpSize = sizeList.get(k).toPixF(resolution); + + paperSumSize += tmpSize; + if (paperSumSize >= paperPaintSize) { + paperSumSize = tmpSize; + } + } + } + + // adjust height. + tmpSize = sizeList.get(i).toPixF(resolution); + paperSumSize += tmpSize; + + if (showGridLine) {// paint line. + setLine2D((int) sumSize); + g2d.draw(tmpLine2D); + } + + // paint paper margin line. + if (showPaginateLine && paperSumSize >= paperPaintSize) { + paginateLineList.add(getPaginateLine2D((int) sumSize)); + paperSumSize = tmpSize; + } + + sumSize += tmpSize; + } + + // paint 最后一个横线.. + if (showGridLine) { + drawLastLine(g2d, (int) sumSize); + } + } + + protected abstract void setLine2D(int sumSize); + + protected abstract Line2D.Double getPaginateLine2D(int sumSize); + + protected abstract void drawLastLine(Graphics2D g2d, int sumSize); + } + + private class DrawVerticalLineHelper extends DrawLineHelper { + private double realWidth; + + DrawVerticalLineHelper(int startIndex, int endIndex, boolean showGridLine, + boolean showPaginateLine, DynamicUnitList unitSizeList, double paperPaintSize, + List paginateLineList, double realWidth, int resolution) { + super(startIndex, endIndex, showGridLine, showPaginateLine, unitSizeList, + paperPaintSize, paginateLineList, resolution); + this.realWidth = realWidth; + } + + @Override + protected Double getPaginateLine2D(int sumHeight) { + return new Line2D.Double(0, sumHeight, gridSize.width, sumHeight); + } + + @Override + protected void setLine2D(int sumHeight) { + tmpLine2D.setLine(0, sumHeight, realWidth, sumHeight); + } + + @Override + protected void drawLastLine(Graphics2D g2d, int sumHeight) { + GraphHelper.drawLine(g2d, 0, sumHeight, realWidth, sumHeight); + } + } + + private class DrawHorizontalLineHelper extends DrawLineHelper { + private double realHeight; + + DrawHorizontalLineHelper(int startIndex, int endIndex, boolean showGridLine, + boolean showPaginateLine, DynamicUnitList unitSizeList, double paperPaintSize, + List paginateLineList, double realHeight, int resolution) { + super(startIndex, endIndex, showGridLine, showPaginateLine, unitSizeList, + paperPaintSize, paginateLineList, resolution); + this.realHeight = realHeight; + } + + @Override + protected Double getPaginateLine2D(int sumWidth) { + return new Line2D.Double(sumWidth, 0, sumWidth, gridSize.height); + } + + @Override + protected void setLine2D(int sumWidth) { + tmpLine2D.setLine(sumWidth, 0, sumWidth, realHeight); + } + + @Override + protected void drawLastLine(Graphics2D g2d, int sumWidth) { + GraphHelper.drawLine(g2d, sumWidth, 0, sumWidth, realHeight); + } + } + + private void paintCellElements(Graphics g, Grid grid, TemplateElementCase report, int resolution) { + Graphics2D g2d = (Graphics2D) g; + + CellElement selectedCellElement = null; + ElementCasePane reportPane = grid.getElementCasePane(); + Selection sel = reportPane.getSelection(); + + if (sel instanceof CellSelection) { + selectedCellElement = report.getCellElement(((CellSelection) sel).getColumn(), ((CellSelection) sel).getRow()); + } + + int horizontalBeginValue = grid.getHorizontalBeginValue(); + int verticalBeginValue = grid.getVerticalBeginValue(); + + // 元素数目. + Shape oldClip = null; + TemplateCellElement tmpCellElement = null; + + Iterator cells = report.intersect(horizontalBeginValue, verticalBeginValue, + horizontalEndValue - horizontalBeginValue, verticalEndValue - verticalBeginValue); + + // 计算隐藏掉的width + double hideWidth = columnWidthList.getRangeValue(0, horizontalValue).toPixD(resolution); + double hideHeight = rowHeightList.getRangeValue(0, verticalValue).toPixD(resolution); + + // 清空left和top的绘画区域. + this.left_col_row_rect.setRect(0, 0, 0, 0); + this.top_col_row_rect.setRect(0, 0, 0, 0); + + paintDetailedCellElements(g2d, cells, tmpCellElement, reportPane, selectedCellElement, hideWidth, hideHeight, oldClip, report); + paintBorder(g2d, tmpCellElement, report); + paintFatherLeft(g2d, selectedCellElement, report); + } + + private void paintDetailedCellElements(Graphics2D g2d, Iterator cells, TemplateCellElement tmpCellElement, ElementCasePane reportPane, + CellElement selectedCellElement, double hideWidth, double hideHeight, Shape oldClip, TemplateElementCase report) { + while (cells.hasNext()) { + tmpCellElement = (TemplateCellElement) cells.next(); + if (tmpCellElement == null) { + continue; + } + // 强制分页线 + this.calculateForcedPagingOfCellElement(reportPane, tmpCellElement, hideWidth, hideHeight); + storeFatherLocation(selectedCellElement, tmpCellElement); + // element bounds + // TODO: 2017/7/13 tmpRectangle : 72*19 + this.caculateScrollVisibleBounds(this.tmpRectangle, tmpCellElement.getColumn(), + tmpCellElement.getRow(), tmpCellElement.getColumnSpan(), + tmpCellElement.getRowSpan()); + // peter:clip的区域. + // peter:保留clip. + oldClip = g2d.getClip(); /* + * alex:此处的tmpRectangle_1被GridUtils.validate判断必定为true, + * 因为这些tmpCellElement是intersect的结果 所以,不必判断了 + */ + g2d.clip(this.tmpRectangle); + + // 这边为什么要加1? 因为单元格的左边和上面有线,宽度为一,属于此单元格,画单元格的内容不应该把那条线给遮住了 + g2d.translate(this.tmpRectangle.getX() + 1, this.tmpRectangle.getY() + 1); + + // peter:tmpRectangle2D_3只是一个临时的Rectangle2D,由于后面不少地方需要用到这个矩形 + this.cell_back_rect.setRect(0, 0, this.tmpRectangle.getWidth() - 1, + this.tmpRectangle.getHeight() - 1); + // peter:对于合并的单元格,需要先白色的背景来清除背景. + if (tmpCellElement.getColumnSpan() > 1 || tmpCellElement.getRowSpan() > 1) { + WHITE_Backgorund.paint(g2d, this.cell_back_rect); + //daniel:上面这里就有问题了啊....报表的背景在这个之前画的 会覆盖报表背景....不过只是设计器中看到预览浏览没问题 + } + // peter:将这个元素添加到需要paint的元素列表当中去,留着画边框线.. + paintCellElementList.add(tmpCellElement); + paintCellElementRectangleList.add(this.tmpRectangle.clone()); + + + int cellWidth = (int) this.tmpRectangle.getWidth(); + int cellHeight = (int) this.tmpRectangle.getHeight(); + // denny_Grid: 画Grid中单元格的内容(包括单元格的背景Content + Background), 不包括边框 + + painter.paintBackground(g2d, report, tmpCellElement, cellWidth, cellHeight); + painter.paintContent(g2d, report, tmpCellElement, cellWidth, cellHeight, resolution); + // denny_Grid: 注意下面还要减一, 因为上面translate时加一 + g2d.translate(-this.tmpRectangle.getX() - 1, -this.tmpRectangle.getY() - 1); + paintAuthorityCell(g2d, tmpCellElement); + g2d.setClip(oldClip); + } + } + + private void paintAuthorityCell(Graphics2D g2d, TemplateCellElement tmpCellElement) { + String selectedRole = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); + boolean isWidgetAuthority = false; + if (tmpCellElement.getWidget() != null) { + isWidgetAuthority = tmpCellElement.getWidget().isDirtyWidget(selectedRole); + } + boolean isCellDoneAuthority = tmpCellElement.isDoneAuthority(selectedRole) || tmpCellElement.isDoneNewValueAuthority(selectedRole); + boolean isDoneAuthority = isWidgetAuthority || isCellDoneAuthority; + if (isAuthority && isDoneAuthority) { + Composite oldComposite = g2d.getComposite(); + g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f)); + Paint oldPaint = g2d.getPaint(); + g2d.setPaint(UIConstants.AUTHORITY_COLOR); + GraphHelper.fill(g2d, tmpRectangle); + g2d.setComposite(oldComposite); + g2d.setPaint(oldPaint); + } + } + + private void storeFatherLocation(CellElement selectedCellElement, TemplateCellElement tmpCellElement) { +// // 需要检查是否在Design状态隐藏. +// CellGUIAttr cellGUIAttr = tmpCellElement.getCellGUIAttr(); +// if (cellGUIAttr == null) { +// // 不set给curCellElement,赋值只是为了方便下面的操作 +// cellGUIAttr = CellGUIAttr.DEFAULT_CELLGUIATTR; +// } + + /* + * 记录当前选中的单元格的左父与上父的位置于leftColumnRowRectangle2D & + * topColumnRowRectangle2D + */ + if (selectedCellElement == tmpCellElement) { + CellExpandAttr cellExpandAttr = tmpCellElement.getCellExpandAttr(); + if (cellExpandAttr != null) { + ColumnRow leftColumnRow = cellExpandAttr.getLeftParentColumnRow(); + // leftColumnRow必须在可视范围内 + if (ColumnRow.validate(leftColumnRow)) { + this.caculateScrollVisibleBounds(this.left_col_row_rect, + leftColumnRow.getColumn(), leftColumnRow.getRow(), 1, 1); + } + + ColumnRow topColumnRow = cellExpandAttr.getUpParentColumnRow(); + // topColumnRow必须在可视范围内 + if (ColumnRow.validate(topColumnRow)) { + this.caculateScrollVisibleBounds(this.top_col_row_rect, + topColumnRow.getColumn(), topColumnRow.getRow(), 1, 1); + } + } + } + } + + private void paintBorder(Graphics2D g2d, TemplateCellElement tmpCellElement, TemplateElementCase report) { + // 画边框 + Rectangle2D.Double tmpCellElementRectangle; + for (int i = 0; i < paintCellElementList.size(); i++) { + tmpCellElement = (TemplateCellElement) paintCellElementList.get(i); + tmpCellElementRectangle = (Rectangle2D.Double) paintCellElementRectangleList.get(i); + + // 需要检查是否在Design状态隐藏. + CellGUIAttr cellGUIAttr = tmpCellElement.getCellGUIAttr(); + if (cellGUIAttr == null) { + // 不set给curCellElement,赋值只是为了方便下面的操作 + cellGUIAttr = CellGUIAttr.DEFAULT_CELLGUIATTR; + } + + g2d.translate(tmpCellElementRectangle.getX(), tmpCellElementRectangle.getY()); + + painter.paintBorder(g2d, report, tmpCellElement, tmpCellElementRectangle.getWidth(), + tmpCellElementRectangle.getHeight()); + + g2d.translate(-tmpCellElementRectangle.getX(), -tmpCellElementRectangle.getY()); + } + } + + protected void paintFatherLeft(Graphics2D g2d, CellElement selectedCellElement, TemplateElementCase report) { + // 画左父格子. + if (validate(this.left_col_row_rect) && this.left_col_row_rect.getHeight() > 5) { + g2d.setPaint(Color.BLUE); + double centerX = this.left_col_row_rect.getX() + 4; + double centerY = this.left_col_row_rect.getY() + this.left_col_row_rect.getHeight() / 2; + GraphHelper.drawLine(g2d, centerX, centerY - 5, centerX, centerY + 5); + GeneralPath polyline = new GeneralPath(Path2D.WIND_EVEN_ODD, 3); + polyline.moveTo((float) centerX, (float) centerY + 5); + polyline.lineTo((float) centerX + 3, (float) centerY + 5 - 4); + polyline.lineTo((float) centerX - 2, (float) centerY + 5 - 4); + GraphHelper.fill(g2d, polyline); + } + if (validate(this.top_col_row_rect) && this.top_col_row_rect.getWidth() > 5) { + g2d.setPaint(Color.BLUE); + double centerX = this.top_col_row_rect.getX() + this.top_col_row_rect.getWidth() / 2; + double centerY = this.top_col_row_rect.getY() + 4; + GraphHelper.drawLine(g2d, centerX - 5, centerY, centerX + 5, centerY); + GeneralPath polyline = new GeneralPath(Path2D.WIND_EVEN_ODD, 3); + polyline.moveTo((float) centerX + 5, (float) centerY); + polyline.lineTo((float) centerX + 5 - 4, (float) centerY + 3); + polyline.lineTo((float) centerX + 5 - 4, (float) centerY - 3); + + GraphHelper.fill(g2d, polyline); + } + } + + private void paintPaginateLines(Graphics g, Grid grid) { + JTemplate jTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); + if(!jTemplate.isJWorkBook()){ + //报表块无分页之说 + return; + } + Graphics2D g2d = (Graphics2D) g; + + // james 画分页线 + if (this.paginateLineList.size() > 0) { + Line2D tmpLine2D = new Line2D.Double(0, 0, 0, 0); + + // james + // 梳理forcedPaperMarginLineList,将其中相同的线去除,否则在Grid的paintConponet时会因setXORMode而将相同的线给覆盖掉 + Line2D tmpLine2D2; + for (int j = 0; j < paginateLineList.size(); j++) { + tmpLine2D = (Line2D) paginateLineList.get(j);// 直接强制转换,因为List中肯定都是Line2D型的 + for (int k = j + 1; k < paginateLineList.size(); k++) { + tmpLine2D2 = (Line2D) paginateLineList.get(k); + if (tmpLine2D2.getX1() == tmpLine2D.getX1() + && tmpLine2D2.getX2() == tmpLine2D.getX2() + && tmpLine2D2.getY1() == tmpLine2D.getY1() + && tmpLine2D2.getY2() == tmpLine2D.getY2()) { + paginateLineList.remove(k); + } + } + } + + g2d.setPaint(grid.getPaginationLineColor()); + + //g2d.setXORMode(Utils.getXORColor(grid.getPaginationLineColor())); + GraphHelper.setStroke(g2d, GraphHelper.getStroke(Constants.LINE_DASH_DOT)); + for (int i = 0, len = paginateLineList.size(); i < len; i++) { + g2d.draw((Shape) paginateLineList.get(i)); + } + + g2d.setPaintMode(); + } + } + + private void paintGridSelection(Graphics g, Grid grid, ElementCase report) { + Graphics2D g2d = (Graphics2D) g; + Selection sel = grid.getElementCasePane().getSelection(); + // 画GridSelection:CELL + if (sel instanceof CellSelection) {// james:cell不可以select的时候就不画了 + CellSelection gridSelection = (CellSelection) sel; + // peter:开始选择框CellRectangle. + Rectangle editRectangle = gridSelection.getEditRectangle(); + int cellRectangleCount = gridSelection.getCellRectangleCount(); + Area selectedCellRectArea = new Area(); + Area editCellRectArea = new Area(); + // denny: editCellRectArea + ElementCasePane reportPane = grid.getElementCasePane(); + if (DesignerContext.getFormatState() == DesignerContext.FORMAT_STATE_NULL) { + this.caculateScrollVisibleBounds(this.tmpRectangle, new Rectangle( + gridSelection.getColumn(), gridSelection.getRow(), gridSelection.getColumnSpan(), gridSelection.getRowSpan() + )); + if (validate(this.tmpRectangle)) { + editCellRectArea.add(new Area(this.tmpRectangle)); + } + if (cellRectangleCount == 1) { + paintOne(selectedCellRectArea, gridSelection, grid, g2d); + } else { + paintMore(selectedCellRectArea, gridSelection, grid, g2d, cellRectangleCount, editCellRectArea); + } + } else { + Rectangle referenced = null; + referenced = paintReferenceCell(reportPane, grid, g2d, editCellRectArea, selectedCellRectArea, referenced); + paintFormatArea(selectedCellRectArea, gridSelection, grid, g2d, referenced); + } + // denny: 标记公式用到的单元格 + paintGridSelectionForFormula(g2d, report, gridSelection); + } + } + + private Rectangle paintReferenceCell(ElementCasePane reportPane, Grid grid, Graphics2D g2d, Area editCellRectArea, Area selectedCellRectArea, Rectangle referenced) { + CellSelection referencedCell = reportPane.getFormatReferencedCell(); + if (referencedCell == null) { + return null; + } + + if (DesignerContext.getReferencedIndex() != + ((JTemplate) HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()).getEditingReportIndex()) { + return null; + } + referenced = new Rectangle( + referencedCell.getColumn(), referencedCell.getRow(), referencedCell.getColumnSpan(), referencedCell.getRowSpan() + ); + this.caculateScrollVisibleBounds(this.tmpRectangle, referenced); + if (validate(this.tmpRectangle)) { + editCellRectArea.add(new Area(this.tmpRectangle)); + } + paintOne(selectedCellRectArea, referencedCell, grid, g2d); + return referenced; + } + + + private void paintFormatArea(Area selectedCellRectArea, CellSelection gridSelection, Grid grid, Graphics2D g2d, Rectangle referenced) { + Rectangle format = new Rectangle( + gridSelection.getColumn(), gridSelection.getRow(), gridSelection.getColumnSpan(), gridSelection.getRowSpan() + ); + if (ComparatorUtils.equals(DesignerContext.getReferencedElementCasePane(), grid.getElementCasePane()) && ComparatorUtils.equals(format, referenced)) { + return; + } + + this.caculateScrollVisibleBounds(this.tmpRectangle, format); + if (validate(this.tmpRectangle)) { + selectedCellRectArea = new Area(this.tmpRectangle); + double selectedCellX = this.tmpRectangle.getX(); + double selectedCellY = this.tmpRectangle.getY(); + double selectedCellWidth = this.tmpRectangle.getWidth(); + double selectedCellHeight = this.tmpRectangle.getHeight(); + + // TODO ALEX_SEP 这个半透明的,画不画呢? + // peter:画半透明的背景,必须SelectCellRectangle和EditCellRectangle不重复才需要半透明背景. + if (gridSelection.getRowSpan() > 1 + || gridSelection.getColumnSpan() > 1) { + Composite oldComposite = g2d.getComposite(); + g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); + g2d.setPaint(grid.getSelectedBackground()); + GraphHelper.fill(g2d, selectedCellRectArea); + g2d.setComposite(oldComposite); + } + + + paintNormal(g2d, selectedCellX, selectedCellY, selectedCellWidth, selectedCellHeight, grid); + } + + } + + private void paintOne(Area selectedCellRectArea, CellSelection gridSelection, Grid grid, Graphics2D g2d) { + if (validate(this.tmpRectangle)) { + selectedCellRectArea = new Area(this.tmpRectangle); + double selectedCellX = this.tmpRectangle.getX(); + double selectedCellY = this.tmpRectangle.getY(); + double selectedCellWidth = this.tmpRectangle.getWidth(); + double selectedCellHeight = this.tmpRectangle.getHeight(); + + // TODO ALEX_SEP 这个半透明的,画不画呢? + // peter:画半透明的背景,必须SelectCellRectangle和EditCellRectangle不重复才需要半透明背景. + if (gridSelection.getRowSpan() > 1 + || gridSelection.getColumnSpan() > 1) { + Composite oldComposite = g2d.getComposite(); + g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); + g2d.setPaint(grid.getSelectedBackground()); + GraphHelper.fill(g2d, selectedCellRectArea); + g2d.setComposite(oldComposite); + } + + + // 判断是否使用智能添加单元格若使用智能添加单元格,则画动态虚线 + paintGridSelectionDependsOnTableSelectionPane(g2d, selectedCellX, selectedCellY, selectedCellWidth, selectedCellHeight, grid); + } + } + + + private void paintMore(Area selectedCellRectArea, CellSelection gridSelection, Grid grid, Graphics2D g2d, int cellRectangleCount, Area editCellRectArea) { + + selectedCellRectArea = new Area(); + // cellRectangleCount > 1 + + // p:下面处理多个选择的情况,麻烦一些. + for (int i = 0; i < cellRectangleCount; i++) { + Rectangle cellRectangle = gridSelection.getCellRectangle(i); + + // p:计算CellSelection. + this.caculateScrollVisibleBounds(this.tmpRectangle, cellRectangle); + + if (validate(this.tmpRectangle)) { + selectedCellRectArea.add(new Area(this.tmpRectangle)); + paintGridSelectionDependsOnTableSelectionPane(g2d, tmpRectangle.x, tmpRectangle.y, tmpRectangle.width, tmpRectangle.height, grid); + } + } + + selectedCellRectArea.add(editCellRectArea); + selectedCellRectArea.exclusiveOr(editCellRectArea); + + // denny: 画半透明背景 + Composite oldComposite = g2d.getComposite(); + g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); + g2d.setPaint(grid.getSelectedBackground()); + GraphHelper.fill(g2d, selectedCellRectArea); + g2d.setComposite(oldComposite); + + // p:画edit空白区域的边框. + g2d.setPaint(Color.blue); + // marks:如果editCellRectArea为空,就不需要画,说明都不在可见区域内 + if (editCellRectArea != null) { + GraphHelper.draw(g2d, editCellRectArea); + } + + + } + + + private void paintGridSelectionForFormula(Graphics2D g2d, ElementCase report, CellSelection cs) { + // denny: 标记公式用到的单元格 + if (report.getCellValue(cs.getColumn(), cs.getRow()) instanceof BaseFormula) { + BaseFormula tmpFormula = (BaseFormula) report + .getCellValue(cs.getColumn(), cs.getRow()); + String statement = tmpFormula.getContent(); + // denny: 获得公式中包含的所有单元格 + ColumnRow[] columnRowArray = new ColumnRow[0]; + try { + columnRowArray = CalculatorUtils.relatedColumnRowArray(statement.substring(1)); + } catch (ANTLRException ae) { + // do nothing. + } + Area formulaCellArea = null; + for (int i = 0; i < columnRowArray.length; i++) { + ColumnRow columnRow = columnRowArray[i]; + int columnSpan = 1; + int rowSpan = 1; + CellElement columnRowCE = report.getCellElement(columnRow.getColumn(), + columnRow.getRow()); + if (columnRowCE != null) { + columnSpan = columnRowCE.getColumnSpan(); + rowSpan = columnRowCE.getRowSpan(); + // _denny: 如果取得是合并单元格的后面的,那么需要重置columnRow + if (columnSpan > 1 || rowSpan > 1) { + columnRow = ColumnRow.valueOf(columnRowCE.getColumn(), + columnRowCE.getRow()); + } + } + + this.caculateScrollVisibleBounds(this.tmpRectangle, columnRow.getColumn(), + columnRow.getRow(), columnSpan, rowSpan); + + if (validate(this.tmpRectangle)) { + paintFormulaCellArea(g2d, formulaCellArea, i); + } + } + } + } + + protected void paintFormulaCellArea(Graphics2D g2d, Area formulaCellArea, int i) { + // denny: 标记格子的边框 + formulaCellArea = new Area(new Rectangle2D.Double(this.tmpRectangle.getX(), + this.tmpRectangle.getY(), this.tmpRectangle.getWidth(), + this.tmpRectangle.getHeight())); + + // peter:去掉edit的格子区域 + formulaCellArea.exclusiveOr(new Area( + new Rectangle2D.Double(this.tmpRectangle.getX() + 1, + this.tmpRectangle.getY() + 1, + this.tmpRectangle.getWidth() - 2, this.tmpRectangle + .getHeight() - 2))); + + formulaCellArea.add(new Area(new Rectangle2D.Double(this.tmpRectangle + .getX(), this.tmpRectangle.getY(), 3, 3))); + formulaCellArea.add(new Area(new Rectangle2D.Double(this.tmpRectangle + .getX() + this.tmpRectangle.getWidth() - 3, this.tmpRectangle + .getY(), 3, 3))); + formulaCellArea.add(new Area(new Rectangle2D.Double(this.tmpRectangle + .getX(), this.tmpRectangle.getY() + this.tmpRectangle.getHeight() + - 3, 3, 3))); + formulaCellArea.add(new Area(new Rectangle2D.Double(this.tmpRectangle + .getX() + this.tmpRectangle.getWidth() - 3, this.tmpRectangle + .getY() + this.tmpRectangle.getHeight() - 3, 3, 3))); + g2d.setPaint(new Color(((i + 2) * 50) % 256, ((i + 1) * 50) % 256, + (i * 50) % 256)); + if (formulaCellArea != null) { + GraphHelper.fill(g2d, formulaCellArea); + } + } + + private void paintGridSelectionDependsOnTableSelectionPane(Graphics2D g2d, double selectedCellX, double selectedCellY, + double selectedCellWidth, double selectedCellHeight, Grid grid) { + if (grid.IsNotShowingTableSelectPane()) { + // peter:构建并开始画边框,只需要对第一个Cell + paintNormal(g2d, selectedCellX, selectedCellY, selectedCellWidth, selectedCellHeight, grid); + } else { + // 动态虚线 + Stroke stroke = g2d.getStroke(); + g2d.setStroke(new BasicStroke(1)); + if (drawFlowRect == null) { + drawFlowRect = new DrawFlowRect(); + } + drawFlowRect.setGrid(grid); + drawFlowRect.drawFlowRect(g2d, (int) selectedCellX, (int) selectedCellY, + (int) selectedCellWidth + (int) selectedCellX, + (int) selectedCellHeight + (int) selectedCellY); + g2d.setStroke(stroke); + } + } + + + private void paintNormal(Graphics2D g2d, double selectedCellX, double selectedCellY, + double selectedCellWidth, double selectedCellHeight, Grid grid) { + this.back_or_selection_rect.setRect(selectedCellX - 1, selectedCellY - 1, + selectedCellWidth + 3, selectedCellHeight + 3); + Area borderLineArea = new Area(this.back_or_selection_rect); + this.back_or_selection_rect.setRect(selectedCellX + 2, selectedCellY + 2, + selectedCellWidth - 3, selectedCellHeight - 3); + borderLineArea.exclusiveOr(new Area(this.back_or_selection_rect)); + this.back_or_selection_rect.setRect(selectedCellX + selectedCellWidth - 1, + selectedCellY + selectedCellHeight - 3, 3, 1); + borderLineArea.exclusiveOr(new Area(this.back_or_selection_rect)); + this.back_or_selection_rect.setRect(selectedCellX + selectedCellWidth - 3, + selectedCellY + selectedCellHeight - 1, 1, 3); + borderLineArea.exclusiveOr(new Area(this.back_or_selection_rect)); + // peter:右下角落的那个小黑方块. + this.back_or_selection_rect.setRect(selectedCellX + selectedCellWidth - 2, + selectedCellY + selectedCellHeight - 2, 5, 5); + borderLineArea.add(new Area(this.back_or_selection_rect)); + + //g2d.setXORMode(Utils.getXORColor(grid.getSelectedBorderLineColor())); + g2d.setPaint(grid.getSelectedBorderLineColor()); + GraphHelper.fill(g2d, borderLineArea); + g2d.setPaintMode(); + } + + private void paintFloatElements(Graphics g, Grid grid, ElementCase report, int resolution) { + Graphics2D g2d = (Graphics2D) g; + + Selection sel = grid.getElementCasePane().getSelection(); + + Iterator flotIt = report.floatIterator(); + while (flotIt.hasNext()) { + FloatElement tmpFloatElement = (FloatElement) flotIt.next(); + + int lastRow = rowHeightList.getValueIndex(FU.getInstance( + tmpFloatElement.getTopDistance().toFU() + tmpFloatElement.getHeight().toFU() + )); + + // 限制相对位置. + if (isSuitablePosition(lastRow)) { + float floatX = columnWidthList.getRangeValue(horizontalValue, 0).toPixF( + resolution) + + tmpFloatElement.getLeftDistance().toPixF(resolution); + float floatY = rowHeightList.getRangeValue(verticalValue, 0).toPixF(resolution) + + tmpFloatElement.getTopDistance().toPixF(resolution); + + g2d.translate(floatX, floatY); + + PaintUtils.paintFloatElement(g2d, tmpFloatElement, + tmpFloatElement.getWidth().toPixI(resolution), + tmpFloatElement.getHeight().toPixI(resolution), resolution); + + g2d.translate(-floatX, -floatY); + } + } + + // p:画选中的悬浮元素的边框,这里必须再循环一次所有的悬浮元素, + // 因为这些方框选择点,及时这个悬浮元素被覆盖的时候,还能够选中点击的,来改变元素的尺寸的. + paintFloatElementsBorder(g2d, grid, sel, flotIt, report); + + paintAuthorityFloatElement(g2d, report, ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(), grid); + } + + private boolean isSuitablePosition(int lastRow) { + // confusing logic... + return 0 >= verticalValue || 0 <= verticalEndValue || lastRow >= verticalValue + || lastRow <= verticalValue; + } + + private void paintFloatElementsBorder(Graphics2D g2d, Grid grid, Selection sel, Iterator flotIt, ElementCase report) { + // p:画选中的悬浮元素的边框,这里必须再循环一次所有的悬浮元素, + // 因为这些方框选择点,及时这个悬浮元素被覆盖的时候,还能够选中点击的,来改变元素的尺寸的. + if (sel instanceof FloatSelection) { + flotIt = report.floatIterator(); + while (flotIt.hasNext()) { + FloatElement tmpFloatElement = (FloatElement) flotIt.next(); + // p:如果不是选中的悬浮元素,直接continue. + if (!ComparatorUtils.equals(tmpFloatElement.getName(), ((FloatSelection) sel).getSelectedFloatName())) { + continue; + } + + Rectangle2D[] rectArray = calculateFloatElementPoints(tmpFloatElement); + + GraphHelper.setStroke(g2d, GraphHelper.getStroke(Constants.LINE_THIN)); + for (int j = 0; j < rectArray.length; j++) { + g2d.setPaint(Utils.getXORColor(grid.getSelectedBorderLineColor())); + GraphHelper.fill(g2d, rectArray[j]); + g2d.setPaint(grid.getSelectedBorderLineColor()); + GraphHelper.draw(g2d, rectArray[j]); + } + } + } + } + + + private Rectangle2D[] calculateFloatElementPoints(FloatElement tmpFloatElement) { + // width and height + float floatX1 = columnWidthList.getRangeValue(horizontalValue, 0).toPixF( + resolution) + tmpFloatElement.getLeftDistance().toPixF(resolution); + float floatY1 = rowHeightList.getRangeValue(verticalValue, 0).toPixF(resolution) + + tmpFloatElement.getTopDistance().toPixF(resolution); + int floatX2 = (int) (floatX1 + tmpFloatElement.getWidth().toPixF(resolution)); + int floatY2 = (int) (floatY1 + tmpFloatElement.getHeight().toPixF(resolution)); + + return new Rectangle2D[]{ + new Rectangle2D.Double(floatX1 - 3, floatY1 - 3, 6, 6), + new Rectangle2D.Double((floatX1 + floatX2) / 2 - 3, floatY1 - 3, 6, 6), + new Rectangle2D.Double(floatX2 - 3, floatY1 - 3, 6, 6), + new Rectangle2D.Double(floatX2 - 3, (floatY1 + floatY2) / 2 - 3, 6, 6), + new Rectangle2D.Double(floatX2 - 3, floatY2 - 3, 6, 6), + new Rectangle2D.Double((floatX1 + floatX2) / 2 - 3, floatY2 - 3, 6, 6), + new Rectangle2D.Double(floatX1 - 3, floatY2 - 3, 6, 6), + new Rectangle2D.Double(floatX1 - 3, (floatY1 + floatY2) / 2 - 3, 6, 6)}; + } + + + private void paintAuthorityFloatElement(Graphics2D g2d, ElementCase report, String selectedRoles, Grid grid) { + Iterator flotIt = report.floatIterator(); + while (flotIt.hasNext()) { + FloatElement tmpFloatElement = (FloatElement) flotIt.next(); + // p:如果不是选中的悬浮元素,直接continue. + if (!tmpFloatElement.getFloatPrivilegeControl().checkInvisible(selectedRoles)) { + continue; + } + float floatX1 = columnWidthList.getRangeValue(horizontalValue, 0).toPixF( + resolution) + tmpFloatElement.getLeftDistance().toPixF(resolution); + float floatY1 = rowHeightList.getRangeValue(verticalValue, 0).toPixF(resolution) + + tmpFloatElement.getTopDistance().toPixF(resolution); + int floatX2 = (int) (floatX1 + tmpFloatElement.getWidth().toPixF(resolution)); + int floatY2 = (int) (floatY1 + tmpFloatElement.getHeight().toPixF(resolution)); + double x = floatX1; + double y = floatY1; + double width = floatX2 - x; + double height = floatY2 - y; + + //画做过权限编辑过的悬浮元素的边框 + if (isAuthority) { + paintAuthorityFloatElementBorder(g2d, x, y, width, height, grid); + } + } + } + + private void paintAuthorityFloatElementBorder(Graphics2D g2d, double selectedCellX, double selectedCellY, + double selectedCellWidth, double selectedCellHeight, Grid grid) { + this.back_or_selection_rect.setRect(selectedCellX - 1, selectedCellY - 1, + selectedCellWidth + 3, selectedCellHeight + 3); + Area borderLineArea = new Area(this.back_or_selection_rect); + g2d.setXORMode(Utils.getXORColor(grid.getSelectedBorderLineColor())); + g2d.setPaint(UIConstants.AUTHORITY_COLOR); + g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f)); + GraphHelper.fill(g2d, borderLineArea); + g2d.setPaintMode(); + } + + private void paintDragCellBorder(Graphics g, Grid grid) { + Graphics2D g2d = (Graphics2D) g; + + if ((grid.getDragType() == GridUtils.DRAG_CELLSELECTION || grid.getDragType() == GridUtils.DRAG_CELLSELECTION_BOTTOMRIGHT_CORNER) + && (grid.getDragRectangle() != null)) { + this.caculateScrollVisibleBounds(this.drag_cell_rect, grid.getDragRectangle()); + + g2d.setPaint(Color.GRAY); + GraphHelper.draw(g2d, this.drag_cell_rect, Constants.LINE_THICK); + } + } + + @Override + /** + * paint + */ + public void paint(Graphics g, JComponent c) { + if (!(c instanceof Grid)) { + throw new IllegalArgumentException("The component c to paint must be a Grid!"); + } + + isAuthority = BaseUtils.isAuthorityEditing(); + + Graphics2D g2d = (Graphics2D) g; + + Grid grid = (Grid) c; + + // 取得ElementCasePane.ElementCase + ElementCasePane elementCasePane = grid.getElementCasePane(); + TemplateElementCase elementCase = elementCasePane.getEditingElementCase();// 取出ElementCase对象 + + dealWithSizeBeforePaint(grid, elementCase); + + double realWidth = gridSize.getWidth();// 宽度 + double realHeight = gridSize.getHeight();// 高度 + + // 画背景 + this.paintBackground(g2d, grid, elementCase, resolution); + + // 画Grid Line + this.paintGridLine(g2d, grid, realWidth, realHeight, resolution); + + // peter:添上线程的支持,有时候,paint元素的时候,可能会有元素被删除了. + // 需要先清除画Border需要的元素. + paintCellElementList.clear(); + paintCellElementRectangleList.clear(); + + // 画单元格元素 + this.paintCellElements(g2d, grid, elementCase, resolution); + + // 画分页线 + this.paintPaginateLines(g2d, grid); + + // 画 GridSelection + if (!(isAuthority && elementCase instanceof WorkSheet && !((WorkSheet) elementCase).isPaintSelection())) { + this.paintGridSelection(g2d, grid, elementCase); + } + + // 画悬浮元素 + this.paintFloatElements(g2d, grid, elementCase, resolution); + + // 画Drag格子的边框. + this.paintDragCellBorder(g2d, grid); + + grid.ajustEditorComponentBounds(); // refresh size + } + + + private void dealWithSizeBeforePaint(Grid grid, TemplateElementCase elementCase) { + // 取出所有的行高和列宽的List + this.rowHeightList = ReportHelper.getRowHeightList(elementCase); + this.columnWidthList = ReportHelper.getColumnWidthList(elementCase); + + this.verticalValue = grid.getVerticalValue(); + this.horizontalValue = grid.getHorizontalValue(); + + int verticalExtent = grid.getVerticalExtent(); + int horizontalExtent = grid.getHorizontalExtent(); + + // denny: set the verticalBeginValue and horizontalBeginValue + grid.setVerticalBeinValue(verticalValue); + grid.setHorizontalBeginValue(horizontalValue); + // denny: end + + // 获得控件的实际尺寸 + this.gridSize = grid.getSize(); + + this.verticalEndValue = verticalValue + verticalExtent + 1; + this.horizontalEndValue = horizontalValue + horizontalExtent + 1; + } + + /** + * 计算单元格可见的边框范围 + * + * @param rect 用于计算的rect + * @param cellElement 单元格 + */ + public void caculateScrollVisibleBounds(Rectangle2D.Double rect, CellElement cellElement) { + caculateScrollVisibleBounds(rect, cellElement.getColumn(), cellElement.getRow(), + cellElement.getColumnSpan(), cellElement.getRowSpan()); + } + + /** + * 计算矩形可见的边框范围 + * + * @param rect 用于计算的rect + * @param target 目标矩形 + */ + public void caculateScrollVisibleBounds(Rectangle2D.Double rect, Rectangle target) { + caculateScrollVisibleBounds(rect, target.x, target.y, target.width, target.height); + } + + /** + * 计算(int column,int row,int columnSpan,int rowSpan,),在Grid控件上面的位置. + * 注意:返回的paintRectangle和clipRectangle不能为null,来区别是否不需要paint或者没有clip. + * 因为这个方法用在Grid里面,为了加快Grid的paint速度,不能不停的new Rectangle()来增加内存的消耗. + *

+ * 处理过的tmpRectangle2Ds必须经过validate的处理才可以使用!! + * + * @param rect rect是一个长度为8的Rectangle2D数组, 绘画的区域不可见 paintRectangle.x =INVALID_INTEGER + * @param column 列 + * @param row 行 + * @param columnSpan 列数 + * @param rowSpan 行数 + */ + public void caculateScrollVisibleBounds(Rectangle2D.Double rect, int column, int row, + int columnSpan, int rowSpan) { + // 判断是否在不可见的区域. + if (outOfScreen(column, row, columnSpan, rowSpan)) { + // 如果在屏幕之外,变成INVALID_INTEGER + rect.x = INVALID_INTEGER; + } else { + rect.x = (columnWidthList.getRangeValue(horizontalValue, column)) + .toPixD(resolution); + rect.y = (rowHeightList.getRangeValue(verticalValue, row)).toPixD(resolution); + rect.width = (columnWidthList.getRangeValue(column, column + columnSpan)) + .toPixD(resolution); + rect.height = (rowHeightList.getRangeValue(row, row + rowSpan)).toPixD(resolution); + } + } + + private boolean outOfScreen(int column, int row, int columnSpan, int rowSpan) { + return column > horizontalEndValue || row > verticalEndValue + || column + columnSpan <= horizontalValue || row + rowSpan <= verticalValue; + } + + /** + * 是否有效的Rectangle2D + * + * @param rect 目标rect + * @return 有效返回true + */ + public static boolean validate(Rectangle2D rect) { + return rect != null && rect.getX() != INVALID_INTEGER; + } + + + /** + * double frozenHeight从顶部到冻结窗口的格子高度 + * + * @param reportPane 用于计算的单元格面板 + * @param tmpCellElement 用于计算的element + * @param hideWidth 由于冻结窗口或滚动条滚动隐藏了的总宽度 double + * @param hideHeight 由于冻结窗口或滚动条滚动隐藏了的总高度 double frozenWidth;//从左侧到冻结窗口的格子宽度 + */ + public void calculateForcedPagingOfCellElement(ElementCasePane reportPane, + CellElement tmpCellElement, double hideWidth, double hideHeight) { + if (tmpCellElement == null) { + return; + } + + // 找出所有需要paint的强制分页线 + CellPageAttr cellPageAttr = tmpCellElement.getCellPageAttr(); + if (cellPageAttr == null) { + return; + } + + ElementCase report = reportPane.getEditingElementCase(); + + DynamicUnitList columnWidthList = ReportHelper.getColumnWidthList(report); + DynamicUnitList rowHeightList = ReportHelper.getRowHeightList(report); + + int width = reportPane.getSize().width; + int height = reportPane.getSize().height; + + double sumWidth;// 分页线的起始x位置 + double sumHeight;// 分页线的起始y位置 + if (cellPageAttr.isPageAfterColumn()) { + sumWidth = columnWidthList.getRangeValueFromZero( + tmpCellElement.getColumn() + tmpCellElement.getColumnSpan()).toPixD(resolution) + - hideWidth; + paginateLineList.add(new Line2D.Double(sumWidth, 0, sumWidth, height)); + } + if (cellPageAttr.isPageBeforeColumn()) { + sumWidth = columnWidthList.getRangeValueFromZero(tmpCellElement.getColumn()).toPixD( + resolution) + - hideWidth; + paginateLineList.add(new Line2D.Double(sumWidth, 0, sumWidth, height)); + } + if (cellPageAttr.isPageAfterRow()) { + sumHeight = rowHeightList.getRangeValueFromZero( + tmpCellElement.getRow() + tmpCellElement.getRowSpan()).toPixD(resolution) + - hideHeight; + paginateLineList.add(new Line2D.Double(0, sumHeight, width, sumHeight)); + } + if (cellPageAttr.isPageBeforeRow()) { + sumHeight = rowHeightList.getRangeValueFromZero(tmpCellElement.getRow()).toPixD( + resolution) + - hideHeight; + paginateLineList.add(new Line2D.Double(0, sumHeight, width, sumHeight)); + } + } } \ No newline at end of file diff --git a/designer/src/com/fr/grid/IntelliElements.java b/designer/src/com/fr/grid/IntelliElements.java index 475235e56..2a6fdfec6 100644 --- a/designer/src/com/fr/grid/IntelliElements.java +++ b/designer/src/com/fr/grid/IntelliElements.java @@ -1,12 +1,8 @@ package com.fr.grid; -import java.awt.Rectangle; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - +import com.fr.base.BaseFormula; import com.fr.base.BaseUtils; import com.fr.base.FRContext; -import com.fr.base.Formula; import com.fr.design.cell.clipboard.CellElementsClip; import com.fr.design.cell.clipboard.ElementsTransferable; import com.fr.design.mainframe.ElementCasePane; @@ -19,6 +15,10 @@ import com.fr.report.cell.cellattr.core.group.DSColumn; import com.fr.report.elementcase.TemplateElementCase; import com.fr.stable.ColumnRow; +import java.awt.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + /** * Kevin Wang: inner class used by method intelliElements iterating in GridUtils.java. */ @@ -199,8 +199,8 @@ public class IntelliElements { newCellElement.setCellExpandAttr(sourceCellElement.getCellExpandAttr()); } else if (sourceCellElement.getValue() instanceof Number) { newCellElement.setValue(processNumber((Number) sourceCellElement.getValue())); - } else if (sourceCellElement.getValue() instanceof Formula) { - Formula formula = (Formula) sourceCellElement.getValue(); + } else if (sourceCellElement.getValue() instanceof BaseFormula) { + BaseFormula formula = (BaseFormula) sourceCellElement.getValue(); formula = this.generateSimpleFormula(formula, 1); newCellElement.setValue(formula); } else { @@ -231,12 +231,12 @@ public class IntelliElements { protected abstract ColumnRow processColumnRow(ColumnRow org, int diff); - private Formula generateSimpleFormula(Formula formula, int diff) { - Formula newFormula; + private BaseFormula generateSimpleFormula(BaseFormula formula, int diff) { + BaseFormula newFormula; try { - newFormula = (Formula) (formula.clone()); + newFormula = formula.clone(); } catch (CloneNotSupportedException e) { - newFormula = new Formula(); + newFormula = BaseFormula.createFormulaBuilder().build(); FRContext.getLogger().error(e.getMessage(), e); } String formulaContent = formula.getContent(); diff --git a/designer/src/com/fr/grid/selection/CellSelection.java b/designer/src/com/fr/grid/selection/CellSelection.java index 31a73cc62..c501efd26 100644 --- a/designer/src/com/fr/grid/selection/CellSelection.java +++ b/designer/src/com/fr/grid/selection/CellSelection.java @@ -1,10 +1,21 @@ package com.fr.grid.selection; -import com.fr.base.*; +import com.fr.base.BaseFormula; +import com.fr.base.BaseUtils; +import com.fr.base.ConfigManager; +import com.fr.base.NameStyle; +import com.fr.base.Utils; import com.fr.cache.list.IntList; import com.fr.design.actions.UpdateAction; -import com.fr.design.actions.cell.*; +import com.fr.design.actions.cell.CellAttributeAction; +import com.fr.design.actions.cell.CellExpandAttrAction; +import com.fr.design.actions.cell.CellWidgetAttrAction; +import com.fr.design.actions.cell.CleanAuthorityAction; +import com.fr.design.actions.cell.ConditionAttributesAction; +import com.fr.design.actions.cell.EditCellAction; +import com.fr.design.actions.cell.GlobalStyleMenuDef; import com.fr.design.actions.cell.GlobalStyleMenuDef.GlobalStyleSelection; +import com.fr.design.actions.cell.StyleAction; import com.fr.design.actions.core.ActionFactory; import com.fr.design.actions.edit.CopyAction; import com.fr.design.actions.edit.CutAction; @@ -26,7 +37,6 @@ import com.fr.design.mainframe.JTemplate; import com.fr.design.menu.KeySetUtils; import com.fr.design.report.RowColumnPane; import com.fr.design.selection.QuickEditor; -import com.fr.form.ui.CellWidget; import com.fr.general.Inter; import com.fr.grid.GridUtils; import com.fr.report.cell.CellElement; @@ -293,7 +303,7 @@ public class CellSelection extends Selection { for (int c = 0; c < lineTextArray.length; c++) { String textValue = lineTextArray[c]; if (textValue.length() > 0 && textValue.charAt(0) == '=') { - ec.setCellValue(column + c, row + r, new Formula(textValue)); + ec.setCellValue(column + c, row + r, BaseFormula.createFormulaBuilder().build(textValue)); } else { Number number = Utils.string2Number(lineTextArray[c]); if (number != null) { diff --git a/designer/src/com/fr/quickeditor/cellquick/CellDSColumnEditor.java b/designer/src/com/fr/quickeditor/cellquick/CellDSColumnEditor.java index 9c45dd3bc..21383b73d 100644 --- a/designer/src/com/fr/quickeditor/cellquick/CellDSColumnEditor.java +++ b/designer/src/com/fr/quickeditor/cellquick/CellDSColumnEditor.java @@ -1,6 +1,6 @@ package com.fr.quickeditor.cellquick; -import com.fr.base.Formula; +import com.fr.base.BaseFormula; import com.fr.design.actions.UpdateAction; import com.fr.design.actions.columnrow.DSColumnConditionAction; import com.fr.design.actions.core.ActionFactory; @@ -47,7 +47,12 @@ import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.util.ArrayList; -import static com.fr.report.cell.cellattr.core.group.FilterTypeEnum.*; +import static com.fr.report.cell.cellattr.core.group.FilterTypeEnum.BOTTOM; +import static com.fr.report.cell.cellattr.core.group.FilterTypeEnum.EVEN; +import static com.fr.report.cell.cellattr.core.group.FilterTypeEnum.ODD; +import static com.fr.report.cell.cellattr.core.group.FilterTypeEnum.SPECIFY; +import static com.fr.report.cell.cellattr.core.group.FilterTypeEnum.TOP; +import static com.fr.report.cell.cellattr.core.group.FilterTypeEnum.UNDEFINE; /** @@ -974,7 +979,7 @@ public class CellDSColumnEditor extends CellQuickEditor { private ActionListener formulaButtonActionListener = new ActionListener() { public void actionPerformed(ActionEvent evt) { - Formula valueFormula = new Formula(); + BaseFormula valueFormula = BaseFormula.createFormulaBuilder().build(); String text = formulaTextField.getText(); if (text == null || text.length() <= 0) { valueFormula.setContent(defaultValue); @@ -991,7 +996,7 @@ public class CellDSColumnEditor extends CellQuickEditor { formulaPane.showLargeWindow(SwingUtilities.getWindowAncestor(DSColumnAdvancedEditorPane.JFormulaField.this), new DialogActionAdapter() { @Override public void doOk() { - Formula valueFormula = formulaPane.update(); + BaseFormula valueFormula = formulaPane.update(); if (valueFormula.getContent().length() <= 1) { formulaTextField.setText(defaultValue); } else { diff --git a/designer/src/com/fr/quickeditor/cellquick/CellFormulaQuickEditor.java b/designer/src/com/fr/quickeditor/cellquick/CellFormulaQuickEditor.java index 7d245434c..695410cb0 100644 --- a/designer/src/com/fr/quickeditor/cellquick/CellFormulaQuickEditor.java +++ b/designer/src/com/fr/quickeditor/cellquick/CellFormulaQuickEditor.java @@ -1,6 +1,6 @@ package com.fr.quickeditor.cellquick; -import com.fr.base.Formula; +import com.fr.base.BaseFormula; import com.fr.base.Style; import com.fr.base.TextFormat; import com.fr.design.actions.core.ActionFactory; @@ -99,11 +99,11 @@ public class CellFormulaQuickEditor extends CellQuickEditor { public void actionPerformed(ActionEvent evt) { String text = formulaTextField.getText(); final UIFormula formulaPane = FormulaFactory.createFormulaPane(); - formulaPane.populate(new Formula(text)); + formulaPane.populate(BaseFormula.createFormulaBuilder().build(text)); formulaPane.showLargeWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { @Override public void doOk() { - Formula fm = formulaPane.update(); + BaseFormula fm = formulaPane.update(); if (fm.getContent().length() <= 1) { formulaTextField.setText(DEFAULT_FORMULA); } else { @@ -146,7 +146,7 @@ public class CellFormulaQuickEditor extends CellQuickEditor { tc.getEditingElementCase().addCellElement(cellElement, false); } if (tmpText != null && (tmpText.length() > 0 && tmpText.charAt(0) == '=')) { - Formula textFormula = new Formula(tmpText); + BaseFormula textFormula = BaseFormula.createFormulaBuilder().build(tmpText); textFormula.setReserveInResult(reserveInResult); textFormula.setReserveOnWriteOrAnaly(reserveOnWriteOrAnaly); cellElement.setValue(textFormula); @@ -175,8 +175,8 @@ public class CellFormulaQuickEditor extends CellQuickEditor { Object value = cellElement.getValue(); if (value == null) { str = StringUtils.EMPTY; - } else if (value instanceof Formula) { - Formula formula = (Formula) value; + } else if (value instanceof BaseFormula) { + BaseFormula formula = (BaseFormula) value; str = formula.getContent(); reserveInResult = formula.isReserveInResult(); reserveOnWriteOrAnaly = formula.isReserveOnWriteOrAnaly(); diff --git a/designer/src/com/fr/quickeditor/cellquick/CellStringQuickEditor.java b/designer/src/com/fr/quickeditor/cellquick/CellStringQuickEditor.java index bd5ea60d1..5f335ffb7 100644 --- a/designer/src/com/fr/quickeditor/cellquick/CellStringQuickEditor.java +++ b/designer/src/com/fr/quickeditor/cellquick/CellStringQuickEditor.java @@ -1,6 +1,6 @@ package com.fr.quickeditor.cellquick; -import com.fr.base.Formula; +import com.fr.base.BaseFormula; import com.fr.base.Style; import com.fr.base.TextFormat; import com.fr.design.gui.itextarea.UITextArea; @@ -110,7 +110,7 @@ public class CellStringQuickEditor extends CellQuickEditor { tc.getEditingElementCase().addCellElement(cellElement, false); } if (tmpText != null && (tmpText.length() > 0 && tmpText.charAt(0) == '=')) { - Formula textFormula = new Formula(tmpText); + BaseFormula textFormula = BaseFormula.createFormulaBuilder().build(tmpText); textFormula.setReserveInResult(reserveInResult); textFormula.setReserveOnWriteOrAnaly(reserveOnWriteOrAnaly); cellElement.setValue(textFormula); @@ -139,8 +139,8 @@ public class CellStringQuickEditor extends CellQuickEditor { Object value = cellElement.getValue(); if (value == null) { str = StringUtils.EMPTY; - } else if (value instanceof Formula) { - Formula formula = (Formula) value; + } else if (value instanceof BaseFormula) { + BaseFormula formula = (BaseFormula) value; str = formula.getContent(); reserveInResult = formula.isReserveInResult(); reserveOnWriteOrAnaly = formula.isReserveOnWriteOrAnaly(); diff --git a/designer/src/com/fr/quickeditor/floatquick/FloatStringQuickEditor.java b/designer/src/com/fr/quickeditor/floatquick/FloatStringQuickEditor.java index 3749407e9..1f5718a9e 100644 --- a/designer/src/com/fr/quickeditor/floatquick/FloatStringQuickEditor.java +++ b/designer/src/com/fr/quickeditor/floatquick/FloatStringQuickEditor.java @@ -1,7 +1,7 @@ package com.fr.quickeditor.floatquick; +import com.fr.base.BaseFormula; import com.fr.base.BaseUtils; -import com.fr.base.Formula; import com.fr.base.Style; import com.fr.base.TextFormat; import com.fr.design.constants.UIConstants; @@ -68,10 +68,10 @@ public class FloatStringQuickEditor extends FloatQuickEditor { Object value = floatElement.getValue(); if (value == null) { str = StringUtils.EMPTY; - } else if (value instanceof Formula) { + } else if (value instanceof BaseFormula) { //MoMeak: 没拆文本框和公式所以需要这么个玩意 formulaButton.setVisible(true); - Formula formula = (Formula) value; + BaseFormula formula = (BaseFormula) value; str = formula.getContent(); stringTextField.setLineWrap(false); this.setBorder(BorderFactory.createEmptyBorder(10, 75, 10, 10)); @@ -110,7 +110,7 @@ public class FloatStringQuickEditor extends FloatQuickEditor { protected void changeReportPaneCell(String tmpText) { if (tmpText != null && (tmpText.length() > 0 && tmpText.charAt(0) == '=')) { - Formula textFormula = new Formula(tmpText); + BaseFormula textFormula = BaseFormula.createFormulaBuilder().build(tmpText); textFormula.setReserveInResult(reserveInResult); textFormula.setReserveOnWriteOrAnaly(reserveOnWriteOrAnaly); floatElement.setValue(textFormula); diff --git a/designer_base/src/com/fr/design/DesignerEnvManager.java b/designer_base/src/com/fr/design/DesignerEnvManager.java index f43d05bac..1cd613785 100644 --- a/designer_base/src/com/fr/design/DesignerEnvManager.java +++ b/designer_base/src/com/fr/design/DesignerEnvManager.java @@ -14,7 +14,6 @@ import com.fr.env.RemoteEnv; import com.fr.env.SignIn; import com.fr.file.FILEFactory; import com.fr.general.ComparatorUtils; -import com.fr.general.FRLevel; import com.fr.general.FRLogFormatter; import com.fr.general.FRLogger; import com.fr.general.GeneralContext; @@ -34,9 +33,10 @@ import com.fr.stable.xml.XMLTools; import com.fr.stable.xml.XMLWriter; import com.fr.stable.xml.XMLableReader; -import javax.swing.*; +import javax.swing.SwingWorker; import javax.swing.SwingWorker.StateValue; -import java.awt.*; +import java.awt.Color; +import java.awt.Rectangle; import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; @@ -53,7 +53,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.logging.FileHandler; import java.util.logging.Handler; -import java.util.logging.Level; /** * The manager of Designer GUI. @@ -97,7 +96,6 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { private Color paginationLineColor = Color.black; // line color of paper private boolean supportCellEditorDef = false; private boolean isDragPermited = false; - private Level level = Level.INFO; private int language; //2014-8-26默认显示全部, 因为以前的版本, 虽然是false, 实际上是显示所有表, 因此这边要兼容 private boolean useOracleSystemSpace = true; @@ -240,10 +238,6 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { */ public static void loadLogSetting() { DesignerEnvManager designerEnvManager = DesignerEnvManager.getEnvManager(); - Level logLevel = designerEnvManager.getLogLevel(); - if (logLevel != null) { - FRContext.getLogger().setLogLevel(logLevel, true); - } if (StringUtils.isNotEmpty(designerEnvManager.getJdkHome())) { System.setProperty("java.home", designerEnvManager.getJdkHome()); } @@ -1156,20 +1150,6 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { this.logLocation = logsLocation; } - /** - * 返回日志的等级 - */ - public Level getLogLevel() { - return this.level; - } - - /** - * 设置log的等级 - */ - public void setLogLevel(Level level) { - this.level = level; - } - /** * 设置撤销的限制次数 */ @@ -1320,8 +1300,6 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { readActiveKey(reader); } else if ("LogLocation".equals(name)) { readLogLocation(reader); - } else if ("LogLevel".equals(name)) { - this.readLogLevel(reader); } else if ("Language".equals(name)) { readLanguage(reader); } else if ("JettyServerPort".equals(name)) { @@ -1516,15 +1494,6 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { checkRecentOpenedFileNum(); } - - private void readLogLevel(XMLableReader reader) { - String level; - if ((level = reader.getElementValue()) != null) { - this.setLogLevel(FRLevel.getByName(level).getLevel()); - } - } - - /** * Write XML.
* The method will be invoked when save data to XML file.
@@ -1700,11 +1669,6 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { writer.end(); } - if (this.level != null) { - writer.startTAG("LogLevel"); - writer.textNode(FRLevel.getByLevel(this.level).getName()); - writer.end(); - } if (StringUtils.isNotBlank(jdkHome)) { writer.startTAG("jdkHome"); writer.textNode(jdkHome); diff --git a/designer_base/src/com/fr/design/actions/core/ActionFactory.java b/designer_base/src/com/fr/design/actions/core/ActionFactory.java index bf59e8233..8f0213562 100644 --- a/designer_base/src/com/fr/design/actions/core/ActionFactory.java +++ b/designer_base/src/com/fr/design/actions/core/ActionFactory.java @@ -127,23 +127,32 @@ public class ActionFactory { } private static QuickEditor createEditor(Class clazz, Map> editorMap) { - Class c = editorMap.get(clazz); + Class c = findQuickEditorClass(clazz, editorMap); + if (c == null) { + return null; + } try { Constructor constructor = c.getDeclaredConstructor(); constructor.setAccessible(true); return constructor.newInstance(); - } catch (NoSuchMethodException e) { - FRContext.getLogger().error(e.getMessage(), e); - } catch (IllegalAccessException e) { - FRContext.getLogger().error(e.getMessage(), e); - } catch (InstantiationException e) { - FRContext.getLogger().error(e.getMessage(), e); - } catch (InvocationTargetException e) { + } catch (Exception e) { FRContext.getLogger().error(e.getMessage(), e); } return null; } + private static Class findQuickEditorClass(Class clazz, Map> editorMap) { + Class c = editorMap.get(clazz); + if (c == null) { + Class superClazz = clazz.getSuperclass(); + if (superClazz == null) { + return null; + } + return findQuickEditorClass(superClazz, editorMap); + } + return c; + } + public static QuickEditor getCellEditor(Class clazz) { return createEditor(clazz, cellEditor); } diff --git a/designer_base/src/com/fr/design/actions/file/PreferencePane.java b/designer_base/src/com/fr/design/actions/file/PreferencePane.java index 51b8c374a..d32b110d1 100644 --- a/designer_base/src/com/fr/design/actions/file/PreferencePane.java +++ b/designer_base/src/com/fr/design/actions/file/PreferencePane.java @@ -1,6 +1,8 @@ package com.fr.design.actions.file; import com.fr.base.BaseUtils; +import com.fr.base.ConfigManager; +import com.fr.base.FRContext; import com.fr.design.DesignerEnvManager; import com.fr.design.RestartHelper; import com.fr.design.dialog.BasicDialog; @@ -25,9 +27,24 @@ import com.fr.general.FRFont; import com.fr.general.FRLevel; import com.fr.general.Inter; -import javax.swing.*; -import java.awt.*; -import java.awt.event.*; +import javax.swing.JFileChooser; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.KeyStroke; +import javax.swing.SwingUtilities; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Window; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.io.File; import java.util.ArrayList; import java.util.Locale; @@ -354,7 +371,7 @@ public class PreferencePane extends BasicPane { logLevelPane.add(logLevelComboBox); logLevelComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - DesignerEnvManager.getEnvManager().setLogLevel(((FRLevel) logLevelComboBox.getSelectedItem()).getLevel()); + ConfigManager.getProviderInstance().setServerLogLevel(((FRLevel) logLevelComboBox.getSelectedItem()).getLevel()); } }); } @@ -534,7 +551,7 @@ public class PreferencePane extends BasicPane { this.logExportDirectoryField.setText(designerEnvManager.getLogLocation()); - this.logLevelComboBox.setSelectedItem(FRLevel.getByLevel(designerEnvManager.getLogLevel())); + this.logLevelComboBox.setSelectedItem(FRLevel.getByLevel(ConfigManager.getProviderInstance().getServerLogLevel())); this.languageComboBox.setSelectedItem(LANGUAGE.get(designerEnvManager.getLanguage())); designerEnvLanguageIndex = designerEnvManager.getLanguage(); @@ -578,8 +595,6 @@ public class PreferencePane extends BasicPane { designerEnvManager.setLogLocation(this.logExportDirectoryField.getText()); - designerEnvManager.setLogLevel(((FRLevel) logLevelComboBox.getSelectedItem()).getLevel()); - designerEnvManager.setSupportUndo(supportUndoCheckBox.isSelected()); designerEnvManager.setSupportDefaultParentCalculate(supportDefaultParentCalculateCheckBox.isSelected()); @@ -615,6 +630,14 @@ public class PreferencePane extends BasicPane { if (maxUndoLimit.getSelectedIndex() == SELECTED_INDEX_5) { designerEnvManager.setUndoLimit(MAX_UNDO_LIMIT_50); } + + ConfigManager.getProviderInstance().setServerLogLevel(((FRLevel) logLevelComboBox.getSelectedItem()).getLevel()); + try { + FRContext.getCurrentEnv().writeResource(ConfigManager.getProviderInstance()); + } catch (Exception e) { + FRContext.getLogger().error(e.getMessage()); + } + } /* diff --git a/designer_base/src/com/fr/design/condition/LiteConditionPane.java b/designer_base/src/com/fr/design/condition/LiteConditionPane.java index ab1757153..575281c7e 100644 --- a/designer_base/src/com/fr/design/condition/LiteConditionPane.java +++ b/designer_base/src/com/fr/design/condition/LiteConditionPane.java @@ -1,7 +1,7 @@ package com.fr.design.condition; +import com.fr.base.BaseFormula; import com.fr.base.BaseUtils; -import com.fr.base.Formula; import com.fr.data.DataConstants; import com.fr.data.condition.*; import com.fr.design.beans.BasicBeanPane; @@ -75,13 +75,13 @@ public abstract class LiteConditionPane extends BasicBeanPa @Override public void actionPerformed(ActionEvent evt) { - Formula formula; + BaseFormula formula; String text = formulaTextArea.getText(); if (text == null || text.length() <= 0) { - formula = new Formula(StringUtils.EMPTY); + formula = BaseFormula.createFormulaBuilder().build(); } else { - formula = new Formula(text); + formula = BaseFormula.createFormulaBuilder().build(text); } final UIFormula formulaPane = FormulaFactory.createFormulaPane(); @@ -90,7 +90,7 @@ public abstract class LiteConditionPane extends BasicBeanPa @Override public void doOk() { - Formula formula = formulaPane.update(); + BaseFormula formula = formulaPane.update(); if (formula.getContent().length() <= 1) {// 如果没有填任何字符,则是空白文本 formulaTextArea.setText(StringUtils.EMPTY); } else { diff --git a/designer_base/src/com/fr/design/data/datapane/ChoosePaneSupportFormula.java b/designer_base/src/com/fr/design/data/datapane/ChoosePaneSupportFormula.java index c59f187f5..0bc32dcf0 100644 --- a/designer_base/src/com/fr/design/data/datapane/ChoosePaneSupportFormula.java +++ b/designer_base/src/com/fr/design/data/datapane/ChoosePaneSupportFormula.java @@ -1 +1,238 @@ -package com.fr.design.data.datapane; import com.fr.base.*; import com.fr.design.data.datapane.preview.PreviewLabel; import com.fr.design.data.datapane.preview.PreviewTablePane; import com.fr.data.impl.EmbeddedTableData; import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.JTemplate; import com.fr.design.parameter.ParameterInputPane; import com.fr.design.dialog.DialogActionAdapter; import com.fr.general.ComparatorUtils; import com.fr.script.Calculator; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.util.*; /** * Author : Shockway * Date: 13-8-16 * Time: 下午3:46 */ public class ChoosePaneSupportFormula extends ChoosePane { private String ori_ds_formula; private String ori_ds_name; private String ori_table_formula; private String ori_table_name; public ChoosePaneSupportFormula() { this(null); } public ChoosePaneSupportFormula(PreviewLabel.Previewable parent) { this(parent, -1); } public ChoosePaneSupportFormula(PreviewLabel.Previewable parent, int labelSize) { super(parent, labelSize); this.dsNameComboBox.setEditable(true); } protected void addDSBoxListener() { dsNameComboBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { schemaBox.setSelectedIndex(-1); // 如果table是用公式编辑的 没必要联动清除 if (Utils.objectToString(tableNameComboBox.getEditor().getItem()).startsWith("=")) { return; } tableNameComboBox.setSelectedItem(""); JTree tree = tableNameComboBox.getTree(); if (tree == null) { return; } DefaultMutableTreeNode rootTreeNode = (DefaultMutableTreeNode) tree.getModel().getRoot(); rootTreeNode.removeAllChildren(); rootTreeNode.add(new ExpandMutableTreeNode("Loading...")); ((DefaultTreeModel) tree.getModel()).reload(); } }); } protected void addFocusListener() { } /** * 只弹出数据库框里的参数 * * @return */ protected String getDSName() { String selectedDSName = null; String item = Utils.objectToString(this.dsNameComboBox.getEditor().getItem()); // 没有选中的列表项 那么看看是不是手输值 if (item == null) { return null; } if (ComparatorUtils.equals(ori_ds_formula, item)) { return ori_ds_name; } ori_ds_formula = item; // 公式 需要解析 输入默认值 if (item.startsWith("=")) { Calculator ca = Calculator.createCalculator(); boolean isFormula = true; Parameter[] parameters = ParameterHelper.analyze4Parameters(new String[]{item}, isFormula); if (parameters.length > 0) { final Map paraMap = new HashMap(); analyseParaDefaultValue(parameters); final ParameterInputPane pPane = new ParameterInputPane(parameters, false); pPane.showSmallWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { public void doOk() { paraMap.putAll(pPane.update()); } }).setVisible(true); ca.pushNameSpace(ParameterMapNameSpace.create(paraMap)); } try { selectedDSName = Utils.objectToString(ca.eval(new Formula(item))); // selectedDSName = ParameterHelper.analyzeCurrentContextTableData4Templatee(item, parameters); } catch (Exception e) { FRContext.getLogger().error(e.getMessage()); } } else { selectedDSName = item; } ori_ds_name = selectedDSName; return selectedDSName; } /** * 在一个参数弹窗中弹出数据库框和表框的参数 * * @return */ protected String[] getDSAndTableName() { String dsName = "", tableName = ""; String dsItem = Utils.objectToString(this.dsNameComboBox.getEditor().getItem()); String tableItem = this.getTableName(); if (ComparatorUtils.equals(ori_ds_formula, dsItem) && ComparatorUtils.equals(ori_table_formula, tableItem)) { return new String[]{ori_ds_name, ori_table_name}; } ori_ds_formula = dsItem; ori_table_formula = tableItem; List paraList = new ArrayList(); pushPara(dsItem, paraList); pushPara(tableItem, paraList); Calculator ca = Calculator.createCalculator(); if (!paraList.isEmpty()) { Parameter[] parameters = (Parameter[]) paraList.toArray(new Parameter[paraList.size()]); final Map paraMap = new HashMap(); analyseParaDefaultValue(parameters); final ParameterInputPane pPane = new ParameterInputPane(parameters, false); pPane.showSmallWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { public void doOk() { paraMap.putAll(pPane.update()); } }).setVisible(true); ca.pushNameSpace(ParameterMapNameSpace.create(paraMap)); } try { dsName = dsItem.startsWith("=") ? Utils.objectToString(ca.eval(new Formula(dsItem))) : dsItem; tableName = tableItem.startsWith("=") ? Utils.objectToString(ca.eval(new Formula(tableItem))) : tableItem; } catch (Exception e) { FRContext.getLogger().error(e.getMessage()); } ori_ds_name = dsName; ori_table_name = tableName; return new String[]{dsName, tableName}; } private void pushPara(String item, List paraList) { if (item.startsWith("=")) { Parameter[] parameters = ParameterHelper.analyze4Parameters(new String[]{item}, true); for (Parameter p : parameters) { if (!paraList.contains(p)) { paraList.add(p); } } } } protected void failedToFindTable() { this.ori_ds_formula = null; this.ori_table_formula = null; } /** * 预览key value对应的数据 * @param key 键 * @param value 值 */ public void preview(int key, int value) { EmbeddedTableData tb = PreviewTablePane.previewTableData(createSelectTableData(), key, value); if (tb == null) { failedToFindTable(); } } public DataBaseItems updateBean() { return updateBean(false); } /** * 这个分两种情况 设计的时候弹窗填入参数 需要返回计算后的值 * 而当写入xml的时候 需要取他的原始formula * * @param getFormula * @return */ public DataBaseItems updateBean(boolean getFormula) { String[] names; if (getFormula) { names = new String[]{Utils.objectToString(this.dsNameComboBox.getEditor().getItem()), this.getTableName()}; } else { names = getDSAndTableName(); } if (names != null && names.length == 2) { return new DataBaseItems(names[0], this.schemaBox.getSelectedItem(), names[1]); } else { return new DataBaseItems("", "", ""); } } /** * 从模板参数和全局参数中取参数的默认值 * * @param ps 参数 */ public void analyseParaDefaultValue(Parameter[] ps) { JTemplate jTemplate = DesignerContext.getDesignerFrame().getSelectedJTemplate(); Parameter[] allParas = jTemplate.getParameters(); for (int i = 0; i < ps.length; i++) { Parameter p = ps[i]; for (int j = 0; j < allParas.length; j++) { if (ComparatorUtils.equals(p.getName(), allParas[j].getName())) { p.setValue(allParas[j].getValue()); } } } } } \ No newline at end of file +package com.fr.design.data.datapane; + +import com.fr.base.BaseFormula; +import com.fr.base.FRContext; +import com.fr.base.Parameter; +import com.fr.base.ParameterHelper; +import com.fr.base.ParameterMapNameSpace; +import com.fr.base.Utils; +import com.fr.data.impl.EmbeddedTableData; +import com.fr.design.data.datapane.preview.PreviewLabel; +import com.fr.design.data.datapane.preview.PreviewTablePane; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.JTemplate; +import com.fr.design.parameter.ParameterInputPane; +import com.fr.general.ComparatorUtils; +import com.fr.script.Calculator; + +import javax.swing.*; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeModel; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Author : Shockway + * Date: 13-8-16 + * Time: 下午3:46 + */ +public class ChoosePaneSupportFormula extends ChoosePane { + private String ori_ds_formula; + private String ori_ds_name; + private String ori_table_formula; + private String ori_table_name; + + public ChoosePaneSupportFormula() { + this(null); + } + + public ChoosePaneSupportFormula(PreviewLabel.Previewable parent) { + this(parent, -1); + } + + public ChoosePaneSupportFormula(PreviewLabel.Previewable parent, int labelSize) { + super(parent, labelSize); + this.dsNameComboBox.setEditable(true); + } + + protected void addDSBoxListener() { + dsNameComboBox.addItemListener(new ItemListener() { + + @Override + public void itemStateChanged(ItemEvent e) { + schemaBox.setSelectedIndex(-1); + // 如果table是用公式编辑的 没必要联动清除 + if (Utils.objectToString(tableNameComboBox.getEditor().getItem()).startsWith("=")) { + return; + } + tableNameComboBox.setSelectedItem(""); + JTree tree = tableNameComboBox.getTree(); + if (tree == null) { + return; + } + DefaultMutableTreeNode rootTreeNode = (DefaultMutableTreeNode) tree.getModel().getRoot(); + rootTreeNode.removeAllChildren(); + rootTreeNode.add(new ExpandMutableTreeNode("Loading...")); + ((DefaultTreeModel) tree.getModel()).reload(); + } + }); + } + + protected void addFocusListener() { + } + + /** + * 只弹出数据库框里的参数 + * + * @return + */ + protected String getDSName() { + String selectedDSName = null; + String item = Utils.objectToString(this.dsNameComboBox.getEditor().getItem()); + // 没有选中的列表项 那么看看是不是手输值 + if (item == null) { + return null; + } + if (ComparatorUtils.equals(ori_ds_formula, item)) { + return ori_ds_name; + } + ori_ds_formula = item; + // 公式 需要解析 输入默认值 + if (item.startsWith("=")) { + Calculator ca = Calculator.createCalculator(); + boolean isFormula = true; + Parameter[] parameters = ParameterHelper.analyze4Parameters(new String[]{item}, isFormula); + if (parameters.length > 0) { + final Map paraMap = new HashMap(); + analyseParaDefaultValue(parameters); + final ParameterInputPane pPane = new ParameterInputPane(parameters, false); + pPane.showSmallWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { + public void doOk() { + paraMap.putAll(pPane.update()); + } + }).setVisible(true); + ca.pushNameSpace(ParameterMapNameSpace.create(paraMap)); + } + try { + selectedDSName = Utils.objectToString(ca.eval(BaseFormula.createFormulaBuilder().build(item))); +// selectedDSName = ParameterHelper.analyzeCurrentContextTableData4Templatee(item, parameters); + } catch (Exception e) { + FRContext.getLogger().error(e.getMessage()); + } + } else { + selectedDSName = item; + } + ori_ds_name = selectedDSName; + return selectedDSName; + } + + /** + * 在一个参数弹窗中弹出数据库框和表框的参数 + * + * @return + */ + protected String[] getDSAndTableName() { + String dsName = "", tableName = ""; + String dsItem = Utils.objectToString(this.dsNameComboBox.getEditor().getItem()); + String tableItem = this.getTableName(); + if (ComparatorUtils.equals(ori_ds_formula, dsItem) && ComparatorUtils.equals(ori_table_formula, tableItem)) { + return new String[]{ori_ds_name, ori_table_name}; + } + ori_ds_formula = dsItem; + ori_table_formula = tableItem; + List paraList = new ArrayList(); + pushPara(dsItem, paraList); + pushPara(tableItem, paraList); + Calculator ca = Calculator.createCalculator(); + if (!paraList.isEmpty()) { + Parameter[] parameters = (Parameter[]) paraList.toArray(new Parameter[paraList.size()]); + final Map paraMap = new HashMap(); + analyseParaDefaultValue(parameters); + final ParameterInputPane pPane = new ParameterInputPane(parameters, false); + pPane.showSmallWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { + public void doOk() { + paraMap.putAll(pPane.update()); + } + }).setVisible(true); + ca.pushNameSpace(ParameterMapNameSpace.create(paraMap)); + } + try { + dsName = dsItem.startsWith("=") ? Utils.objectToString(ca.eval(BaseFormula.createFormulaBuilder().build(dsItem))) : dsItem; + tableName = tableItem.startsWith("=") ? Utils.objectToString(ca.eval(BaseFormula.createFormulaBuilder().build(tableItem))) : tableItem; + } catch (Exception e) { + FRContext.getLogger().error(e.getMessage()); + } + ori_ds_name = dsName; + ori_table_name = tableName; + return new String[]{dsName, tableName}; + } + + private void pushPara(String item, List paraList) { + if (item.startsWith("=")) { + Parameter[] parameters = ParameterHelper.analyze4Parameters(new String[]{item}, true); + for (Parameter p : parameters) { + if (!paraList.contains(p)) { + paraList.add(p); + } + } + } + } + + + protected void failedToFindTable() { + this.ori_ds_formula = null; + this.ori_table_formula = null; + } + + /** + * 预览key value对应的数据 + * @param key 键 + * @param value 值 + */ + public void preview(int key, int value) { + EmbeddedTableData tb = PreviewTablePane.previewTableData(createSelectTableData(), key, value); + if (tb == null) { + failedToFindTable(); + } + } + + public DataBaseItems updateBean() { + return updateBean(false); + } + + /** + * 这个分两种情况 设计的时候弹窗填入参数 需要返回计算后的值 + * 而当写入xml的时候 需要取他的原始formula + * + * @param getFormula + * @return + */ + public DataBaseItems updateBean(boolean getFormula) { + String[] names; + if (getFormula) { + names = new String[]{Utils.objectToString(this.dsNameComboBox.getEditor().getItem()), this.getTableName()}; + } else { + names = getDSAndTableName(); + } + if (names != null && names.length == 2) { + return new DataBaseItems(names[0], this.schemaBox.getSelectedItem(), names[1]); + } else { + return new DataBaseItems("", "", ""); + } + } + + /** + * 从模板参数和全局参数中取参数的默认值 + * + * @param ps 参数 + */ + public void analyseParaDefaultValue(Parameter[] ps) { + JTemplate jTemplate = DesignerContext.getDesignerFrame().getSelectedJTemplate(); + Parameter[] allParas = jTemplate.getParameters(); + for (int i = 0; i < ps.length; i++) { + Parameter p = ps[i]; + for (int j = 0; j < allParas.length; j++) { + if (ComparatorUtils.equals(p.getName(), allParas[j].getName())) { + p.setValue(allParas[j].getValue()); + } + } + } + } + +} \ No newline at end of file diff --git a/designer_base/src/com/fr/design/data/tabledata/tabledatapane/AutoStoreProcedureTableModel.java b/designer_base/src/com/fr/design/data/tabledata/tabledatapane/AutoStoreProcedureTableModel.java index 86d96f573..b7983a698 100644 --- a/designer_base/src/com/fr/design/data/tabledata/tabledatapane/AutoStoreProcedureTableModel.java +++ b/designer_base/src/com/fr/design/data/tabledata/tabledatapane/AutoStoreProcedureTableModel.java @@ -1,10 +1,11 @@ package com.fr.design.data.tabledata.tabledatapane; -import com.fr.base.Formula; + +import com.fr.base.BaseFormula; import com.fr.base.StoreProcedureParameter; -import com.fr.design.gui.itableeditorpane.ParameterTableModel; import com.fr.design.editor.ValueEditorPane; import com.fr.design.editor.ValueEditorPaneFactory; import com.fr.design.editor.editor.CursorEditor; +import com.fr.design.gui.itableeditorpane.ParameterTableModel; import com.fr.general.ComparatorUtils; import com.fr.general.Inter; @@ -16,7 +17,8 @@ import javax.swing.event.PopupMenuListener; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.TableCellEditor; import java.awt.*; -import java.util.*; +import java.util.Date; +import java.util.TimerTask; /** @@ -129,7 +131,7 @@ public class AutoStoreProcedureTableModel extends StoreProcedureTableModel { type = Inter.getLocText("Date"); else if(value instanceof Boolean) type = Inter.getLocText("Parameter-Boolean"); - else if(value instanceof Formula) + else if(value instanceof BaseFormula) type = Inter.getLocText("Formula"); else type = Inter.getLocText("Parameter-String"); diff --git a/designer_base/src/com/fr/design/data/tabledata/tabledatapane/MultiTDTableDataPane.java b/designer_base/src/com/fr/design/data/tabledata/tabledatapane/MultiTDTableDataPane.java index 3ba059d22..e13719c1b 100644 --- a/designer_base/src/com/fr/design/data/tabledata/tabledatapane/MultiTDTableDataPane.java +++ b/designer_base/src/com/fr/design/data/tabledata/tabledatapane/MultiTDTableDataPane.java @@ -386,10 +386,10 @@ public class MultiTDTableDataPane extends AbstractTableDataPane infoMap = new HashMap(); - static { - for(int i = 0; i < nameAndValue.length; i ++){ - infoMap.put(nameAndValue[i].getName(), (Integer) nameAndValue[i].getObject()); - } - } - - private UITextField nameField; - private UIComboBox schemaCombo; - private ValueEditorPane valueEditPane; - private JPanel valuePane = FRGUIPaneFactory.createBorderLayout_S_Pane(); - - public StoreProcedureParameterPane(){ - valueEditPane = ValueEditorPaneFactory.createStoreProcedValueEditorPane(); - this.initComponents(); - } - - public void checkValid() throws Exception{ - StoreProcedureParameter spp=this.update(); - if(spp.getSchema()!= StoreProcedureConstants.OUT && spp.getType() == StoreProcedureConstants.CURSOR){ - throw new Exception(Inter.getLocText("IN_and_INOUT_type_not_as_cursor")); - } - } - - private void initComponents(){ - this.setLayout(FRGUIPaneFactory.createBorderLayout()); - - schemaCombo = new UIComboBox(); - initUIComboBox(schemaCombo, schemaName); - JPanel namePane = FRGUIPaneFactory.createBorderLayout_S_Pane(); - namePane.add(new UILabel(" " + Inter.getLocText("Name") + ":"), BorderLayout.WEST); - nameField = new UITextField(10); - namePane.add(nameField, BorderLayout.CENTER); - namePane.add(new UILabel(" "), BorderLayout.EAST); - valuePane.add(new UILabel(" " + Inter.getLocText("CellWrite-InsertRow_DEFAULT") + ":"), BorderLayout.WEST); - valuePane.add(valueEditPane, BorderLayout.CENTER); - valuePane.add(new UILabel(" "), BorderLayout.EAST); - Component[][] components = {{null}, - {namePane}, - {addPane("Model", 1, schemaCombo)}, - {valuePane}, - {null} - }; - double p = TableLayout.PREFERRED; - double[] rowSize = {p, p, p, p, p, p}; - double[] columnSize = {p}; - JPanel centerPane = TableLayoutHelper.createGapTableLayoutPane( - components, rowSize, columnSize, 20, 10); - this.add(centerPane, BorderLayout.CENTER); - - } - - private JPanel addPane(String s, int i, UIComboBox combo){ - JPanel pane = FRGUIPaneFactory.createBorderLayout_S_Pane(); - pane.add(new UILabel(" " + Inter.getLocText(s) + ":"), BorderLayout.WEST); - combo.setSelectedIndex(i); - pane.add(combo, BorderLayout.CENTER); - pane.add(new UILabel(" "), BorderLayout.EAST); - - return pane; - } - - @Override - protected String title4PopupWindow() { - return Inter.getLocText("Parameter"); - } - - public void populate(StoreProcedureParameter stpParameter) { - if(stpParameter == null) - return; - this.nameField.setText(stpParameter.getName()); - String schema = getInfo4Name(stpParameter.getSchema()); - this.schemaCombo.setSelectedItem(schema); - this.valueEditPane.populate(stpParameter.getValue()); - - } - - public StoreProcedureParameter update(){ - StoreProcedureParameter p = new StoreProcedureParameter(); - p.setName(nameField.getText()); - Object value = valueEditPane.update(); - String type = ""; - if(value instanceof CursorEditor) - type=Inter.getLocText("Cursor"); - else if(value instanceof String ){ - if(((String) value).length() > 0 && ((String) value).charAt(0) == '=') - type = Inter.getLocText("Formula"); - else - type = Inter.getLocText("Parameter-String"); - }else if(value instanceof Integer) - type = Inter.getLocText("Integer"); - else if(value instanceof Double) - type = Inter.getLocText("Double"); - else if(value instanceof Date) - type = Inter.getLocText("Date"); - else if(value instanceof Boolean) - type = Inter.getLocText("Parameter-Boolean"); - else if(value instanceof Formula) - type = Inter.getLocText("Formula"); - else - type = Inter.getLocText("Parameter-String"); - int typeVl = getInfo4Value(type); - p.setType(typeVl); - String schema = (String)schemaCombo.getSelectedItem(); - int schemaVl = getInfo4Value(schema); - p.setSchema(schemaVl); - p.setValue(value); - - return p; - } - - private void initUIComboBox(UIComboBox combo, String[] p){ - for(int i = 0; i < p.length; i ++) - combo.addItem(p[i]); - } - - public static int getInfo4Value(String name){ - return infoMap.get(name); - } - - public static String getInfo4Name(int value){ - java.util.Set set = infoMap.keySet(); - for(String s : set){ - if(infoMap.get(s) == value) - return s; - } - return null; - } - /** - * - */ - private static final long serialVersionUID = 1L; +package com.fr.design.data.tabledata.tabledatapane; + +import com.fr.base.BaseFormula; +import com.fr.base.StoreProcedureParameter; +import com.fr.data.impl.storeproc.StoreProcedureConstants; +import com.fr.design.dialog.BasicPane; +import com.fr.design.editor.ValueEditorPane; +import com.fr.design.editor.ValueEditorPaneFactory; +import com.fr.design.editor.editor.CursorEditor; +import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itextfield.UITextField; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.layout.TableLayout; +import com.fr.design.layout.TableLayoutHelper; +import com.fr.general.Inter; +import com.fr.general.NameObject; + +import javax.swing.*; +import java.awt.*; +import java.util.Date; +import java.util.HashMap; + + +public class StoreProcedureParameterPane extends BasicPane { + + private static String[] schemaName = new String[]{ + "IN", "OUT", "INOUT" + }; + + private static NameObject[] nameAndValue = new NameObject[]{ + new NameObject(Inter.getLocText("Cursor"), StoreProcedureConstants.CURSOR), + new NameObject(Inter.getLocText("Parameter-String"), StoreProcedureConstants.VARCHAR), + new NameObject(Inter.getLocText("Integer"), StoreProcedureConstants.INTEGER), + new NameObject(Inter.getLocText("Double"), StoreProcedureConstants.DECIMAL), + new NameObject(Inter.getLocText("Date"), StoreProcedureConstants.DATE), + new NameObject(Inter.getLocText("Parameter-Boolean"), StoreProcedureConstants.BOOLEAN), + new NameObject(Inter.getLocText("Formula"), StoreProcedureConstants.FORMULA), + new NameObject("IN",StoreProcedureConstants.IN), + new NameObject("OUT",StoreProcedureConstants.OUT), + new NameObject("INOUT",StoreProcedureConstants.INOUT) + }; + + private static HashMap infoMap = new HashMap(); + static { + for(int i = 0; i < nameAndValue.length; i ++){ + infoMap.put(nameAndValue[i].getName(), (Integer) nameAndValue[i].getObject()); + } + } + + private UITextField nameField; + private UIComboBox schemaCombo; + private ValueEditorPane valueEditPane; + private JPanel valuePane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + + public StoreProcedureParameterPane(){ + valueEditPane = ValueEditorPaneFactory.createStoreProcedValueEditorPane(); + this.initComponents(); + } + + public void checkValid() throws Exception{ + StoreProcedureParameter spp=this.update(); + if(spp.getSchema()!= StoreProcedureConstants.OUT && spp.getType() == StoreProcedureConstants.CURSOR){ + throw new Exception(Inter.getLocText("IN_and_INOUT_type_not_as_cursor")); + } + } + + private void initComponents(){ + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + + schemaCombo = new UIComboBox(); + initUIComboBox(schemaCombo, schemaName); + JPanel namePane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + namePane.add(new UILabel(" " + Inter.getLocText("Name") + ":"), BorderLayout.WEST); + nameField = new UITextField(10); + namePane.add(nameField, BorderLayout.CENTER); + namePane.add(new UILabel(" "), BorderLayout.EAST); + valuePane.add(new UILabel(" " + Inter.getLocText("CellWrite-InsertRow_DEFAULT") + ":"), BorderLayout.WEST); + valuePane.add(valueEditPane, BorderLayout.CENTER); + valuePane.add(new UILabel(" "), BorderLayout.EAST); + Component[][] components = {{null}, + {namePane}, + {addPane("Model", 1, schemaCombo)}, + {valuePane}, + {null} + }; + double p = TableLayout.PREFERRED; + double[] rowSize = {p, p, p, p, p, p}; + double[] columnSize = {p}; + JPanel centerPane = TableLayoutHelper.createGapTableLayoutPane( + components, rowSize, columnSize, 20, 10); + this.add(centerPane, BorderLayout.CENTER); + + } + + private JPanel addPane(String s, int i, UIComboBox combo){ + JPanel pane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + pane.add(new UILabel(" " + Inter.getLocText(s) + ":"), BorderLayout.WEST); + combo.setSelectedIndex(i); + pane.add(combo, BorderLayout.CENTER); + pane.add(new UILabel(" "), BorderLayout.EAST); + + return pane; + } + + @Override + protected String title4PopupWindow() { + return Inter.getLocText("Parameter"); + } + + public void populate(StoreProcedureParameter stpParameter) { + if(stpParameter == null) + return; + this.nameField.setText(stpParameter.getName()); + String schema = getInfo4Name(stpParameter.getSchema()); + this.schemaCombo.setSelectedItem(schema); + this.valueEditPane.populate(stpParameter.getValue()); + + } + + public StoreProcedureParameter update(){ + StoreProcedureParameter p = new StoreProcedureParameter(); + p.setName(nameField.getText()); + Object value = valueEditPane.update(); + String type = ""; + if(value instanceof CursorEditor) + type=Inter.getLocText("Cursor"); + else if(value instanceof String ){ + if(((String) value).length() > 0 && ((String) value).charAt(0) == '=') + type = Inter.getLocText("Formula"); + else + type = Inter.getLocText("Parameter-String"); + }else if(value instanceof Integer) + type = Inter.getLocText("Integer"); + else if(value instanceof Double) + type = Inter.getLocText("Double"); + else if(value instanceof Date) + type = Inter.getLocText("Date"); + else if(value instanceof Boolean) + type = Inter.getLocText("Parameter-Boolean"); + else if(value instanceof BaseFormula) + type = Inter.getLocText("Formula"); + else + type = Inter.getLocText("Parameter-String"); + int typeVl = getInfo4Value(type); + p.setType(typeVl); + String schema = (String)schemaCombo.getSelectedItem(); + int schemaVl = getInfo4Value(schema); + p.setSchema(schemaVl); + p.setValue(value); + + return p; + } + + private void initUIComboBox(UIComboBox combo, String[] p){ + for(int i = 0; i < p.length; i ++) + combo.addItem(p[i]); + } + + public static int getInfo4Value(String name){ + return infoMap.get(name); + } + + public static String getInfo4Name(int value){ + java.util.Set set = infoMap.keySet(); + for(String s : set){ + if(infoMap.get(s) == value) + return s; + } + return null; + } + /** + * + */ + private static final long serialVersionUID = 1L; } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/dialog/AttrScrollPane.java b/designer_base/src/com/fr/design/dialog/AttrScrollPane.java new file mode 100644 index 000000000..d7263754d --- /dev/null +++ b/designer_base/src/com/fr/design/dialog/AttrScrollPane.java @@ -0,0 +1,30 @@ +package com.fr.design.dialog; + +import javax.swing.JPanel; + +/** + * Created by kerry on 2017/10/25. + */ +public abstract class AttrScrollPane extends BasicScrollPane { + private static final int OVER_WIDTH = 10; + + @Override + public void populateBean(Object ob) { + + } + + @Override + protected String title4PopupWindow() { + return null; + } + + @Override + protected int getOverWidth() { + return OVER_WIDTH; + } + + @Override + protected boolean hideBarWidth() { + return true; + } +} diff --git a/designer_base/src/com/fr/design/dialog/BasicScrollPane.java b/designer_base/src/com/fr/design/dialog/BasicScrollPane.java index eebf16f64..bf4cd6505 100644 --- a/designer_base/src/com/fr/design/dialog/BasicScrollPane.java +++ b/designer_base/src/com/fr/design/dialog/BasicScrollPane.java @@ -171,14 +171,23 @@ public abstract class BasicScrollPane extends BasicBeanPane{ protected void setLeftContentPaneBounds(Container parent, UIScrollBar scrollBar, int beginY, int maxheight) { int width = parent.getWidth(); int height = parent.getHeight(); - if (leftcontentPane.getPreferredSize().height > maxheight) { - leftcontentPane.setBounds(0, -beginY, width - scrollBar.getWidth() - DET_WIDTH_OVER_HEIGHT, height + beginY); + if (leftcontentPane.getPreferredSize().height > maxheight && scrollBar.isVisible()) { + leftcontentPane.setBounds(0, -beginY, width - scrollBar.getWidth() + getOverWidth() - DET_WIDTH_OVER_HEIGHT, height + beginY); scrollBar.setBounds(width - scrollBar.getWidth() - 1, 0, scrollBar.getWidth(), height); } else { - leftcontentPane.setBounds(0, 0, width - DET_WIDTH, height); + int hideBarWidth = hideBarWidth() ? scrollBar.getWidth() : 0; + leftcontentPane.setBounds(0, 0, width - DET_WIDTH + hideBarWidth, height); } } + protected int getOverWidth(){ + return 0; + } + + protected boolean hideBarWidth(){ + return false; + } + protected boolean isShowScrollBar() { return true; } diff --git a/designer_base/src/com/fr/design/editor/DoubleDeckValueEditorPane.java b/designer_base/src/com/fr/design/editor/DoubleDeckValueEditorPane.java index be285dd94..40c6059c4 100644 --- a/designer_base/src/com/fr/design/editor/DoubleDeckValueEditorPane.java +++ b/designer_base/src/com/fr/design/editor/DoubleDeckValueEditorPane.java @@ -1,9 +1,14 @@ package com.fr.design.editor; -import com.fr.base.Formula; +import com.fr.base.BaseFormula; import com.fr.design.DesignerEnvManager; import com.fr.design.dialog.BasicPane; -import com.fr.design.editor.editor.*; +import com.fr.design.editor.editor.ColumnIndexEditor; +import com.fr.design.editor.editor.ColumnNameEditor; +import com.fr.design.editor.editor.Editor; +import com.fr.design.editor.editor.FormulaEditor; +import com.fr.design.editor.editor.TextEditor; +import com.fr.design.editor.editor.XMLANameEditor; import com.fr.design.event.GlobalNameListener; import com.fr.design.event.GlobalNameObserver; import com.fr.design.event.UIObserver; @@ -234,7 +239,7 @@ public class DoubleDeckValueEditorPane extends BasicPane implements UIObserver, Object columnName = StringUtils.EMPTY; if (ComparatorUtils.equals(name, Inter.getLocText("FR-Designer_Formula"))) { - columnIndex = new Formula(columnIndex == null ? "" : columnIndex.toString()); + columnIndex = BaseFormula.createFormulaBuilder().build(columnIndex == null ? "" : columnIndex.toString()); } if (currentEditor instanceof ColumnNameEditor) { @@ -250,7 +255,7 @@ public class DoubleDeckValueEditorPane extends BasicPane implements UIObserver, Object columnName = StringUtils.EMPTY; if (ComparatorUtils.equals(name, Inter.getLocText("FR-Designer_Formula"))) { - columnIndex = new Formula(columnIndex == null ? "" : columnIndex.toString()); + columnIndex = BaseFormula.createFormulaBuilder().build(columnIndex == null ? "" : columnIndex.toString()); } if (isXMLA) { @@ -302,12 +307,12 @@ public class DoubleDeckValueEditorPane extends BasicPane implements UIObserver, if (returnValue == JOptionPane.OK_OPTION) { setCurrentEditor(j); - Formula formula = new Formula(string); + BaseFormula formula = BaseFormula.createFormulaBuilder().build(string); currentEditor.setValue(formula); } } else { setCurrentEditor(j); - Formula formula = new Formula(string); + BaseFormula formula = BaseFormula.createFormulaBuilder().build(string); currentEditor.setValue(formula); } } diff --git a/designer_base/src/com/fr/design/editor/ValueEditorPane.java b/designer_base/src/com/fr/design/editor/ValueEditorPane.java index 2b46f94fa..b54dfcaa1 100644 --- a/designer_base/src/com/fr/design/editor/ValueEditorPane.java +++ b/designer_base/src/com/fr/design/editor/ValueEditorPane.java @@ -1,405 +1,408 @@ -package com.fr.design.editor; - -import com.fr.base.Formula; -import com.fr.design.DesignerEnvManager; -import com.fr.design.dialog.BasicPane; -import com.fr.design.editor.editor.*; -import com.fr.design.event.GlobalNameListener; -import com.fr.design.event.GlobalNameObserver; -import com.fr.design.event.UIObserver; -import com.fr.design.event.UIObserverListener; -import com.fr.design.gui.ibutton.UIButton; -import com.fr.design.gui.imenu.UIMenuEastAttrItem; -import com.fr.design.gui.imenu.UIPopupEastAttrMenu; -import com.fr.design.layout.FRGUIPaneFactory; -import com.fr.design.mainframe.DesignerContext; -import com.fr.general.ComparatorUtils; -import com.fr.general.Inter; -import com.fr.stable.StringUtils; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; - -public class ValueEditorPane extends BasicPane implements UIObserver, GlobalNameObserver { - - private Editor[] cards; - - private Editor currentEditor; - - private UIButton arrowButton; - private JPopupMenu menu; - private JPanel centerPane; - - private Object value; - - private GlobalNameListener globalNameListener = null; - private UIObserverListener uiObserverListener = null; - - public ValueEditorPane(Editor[] cards) { - this(cards, null, null); - } - - public ValueEditorPane(Editor[] cards, String popupName, String textEditorValue) { - initComponents(cards, popupName, textEditorValue, 200); - } - - public ValueEditorPane(Editor[] cards, String popupName, String textEditorValue, int centerPaneWidth) { - initComponents(cards, popupName, textEditorValue, centerPaneWidth); - } - - private void initComponents(final Editor[] cards, String popupName, String textEditorValue, int centerPaneWidth) { - - this.cards = cards; - - // Frank:布局 - this.setLayout(new BorderLayout(2, 0)); - centerPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); - arrowButton = new UIButton(); - arrowButton.set4ToolbarButton(); - setCurrentEditor(0); - centerPane.setPreferredSize(new Dimension(centerPaneWidth, centerPane.getPreferredSize().height)); - arrowButton.setPreferredSize(new Dimension(20, centerPane.getPreferredSize().height)); - final Color beforeColor = arrowButton.getBackground(); - menu = createPopMenu(); - - arrowButton.addMouseListener(new MouseAdapter() { - public void mouseEntered(MouseEvent a) { - if (cards != null && cards.length > 1) { - arrowButton.setBackground(new Color(228, 246, 255)); - arrowButton.repaint(); - } - } - - public void mouseExited(MouseEvent a) { - arrowButton.setBackground(beforeColor); - arrowButton.setBorder(null); - } - }); - arrowButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - if (cards != null && cards.length > 1) { // 如果只有“列”的话,就不需要弹出菜单了 - Rectangle re = centerPane.getBounds(); - menu.setPopupSize(re.width + arrowButton.getWidth(), menu.getPreferredSize().height); - menu.show(centerPane, -arrowButton.getWidth(), re.height); - } - } - }); - - this.add(centerPane, BorderLayout.CENTER); - if (cards.length > 1) { - this.add(arrowButton, BorderLayout.WEST); - } - } - - @Override - protected String title4PopupWindow() { - return Inter.getLocText("FR-Designer_Values-Editor"); - } - - public Editor getCurrentEditor() { - return currentEditor; - } - - public int getCurrentEditorIndex() { - for (int i = 0;i < cards.length; i++){ - if (cards[i].getClass() == currentEditor.getClass()){ - return i; - } - } - return 0; - } - - public void setCurrentEditor(int i) { - this.add(arrowButton, BorderLayout.WEST); - currentEditor = this.cards[i]; - centerPane.removeAll(); - centerPane.add(currentEditor); - centerPane.validate(); - centerPane.repaint(); - arrowButton.setIcon(cards[i].getIcon()); - if (this.cards.length == 1) { - this.remove(arrowButton); - } - } - - public void setCurrentEditor(Class editorClass) { - for (int i = 0; i < cards.length; i++) { - if (cards[i].getClass() == editorClass) { - setCurrentEditor(i); - break; - } - } - } - - - private JPopupMenu createPopMenu() { - JPopupMenu scate = new UIPopupEastAttrMenu(); - - if (this.cards == null) { - return scate; - } - - for (int i = 0; i < this.cards.length; i++) { - JMenuItem item = new UIMenuEastAttrItem(cards[i].getName()); - final int j = i; - item.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - if (globalNameListener != null) { - globalNameListener.setGlobalName(Inter.getLocText("CellWrite-InsertRow_Policy")); - } - Object oldValue = currentEditor.getValue(); - setCurrentEditor(j); - currentEditor.selected(); - value = currentEditor.getValue(); - if (uiObserverListener != null) { - uiObserverListener.doChange(); - } - - ValueEditorPane.this.firePropertyChange("value", oldValue, value); - } - }); - scate.add(item); - } - return scate; - } - - public void populate(Object object) { - for (int i = 0; i < cards.length; i++) { - if (cards[i].accept(object)) { - setCardValue(i,object); - break; - } - } - } - - public void populate(Object object,String name) { - for (int i = 0; i < cards.length; i++) { - if (cards[i].accept(object) && ComparatorUtils.equals(cards[i].getName(),name)) { - setCardValue(i,object); - break; - } - } - } - - private void setCardValue(int i,Object object){ - setCurrentEditor(i); - cards[i].setValue(object); - // kunsnat: bug7861 所有的Editor值都要跟随改变, 因为populate的editor 从"" - // 一定是最后的Editor哦. - for (int j = 0; j < cards.length; j++) { - if (i == j) { - continue; - } - this.cards[j].setValue(null); - } - } - - public Object update() { - String name = currentEditor.getName(); - Object columnIndex = currentEditor.getValue(); - //bug86542,这边为啥要new一个公式出来,只保留content,其他属性全不要了? - //MoMeak:我也想注释了,但是有bug啊。。。 - if (columnIndex == null && ComparatorUtils.equals(name, Inter.getLocText("Formula"))) { - columnIndex = ((FormulaEditor) currentEditor).getFormula(); - } - - return columnIndex; - } - - public Object update(String makeAdiff) { - String name = currentEditor.getName(); - Object columnIndex = currentEditor.getValue(); - Object columnName = StringUtils.EMPTY; - - if (ComparatorUtils.equals(name, Inter.getLocText("FR-Designer_Formula"))) { - columnIndex = new Formula(columnIndex == null ? "" : columnIndex.toString()); - } - - if (currentEditor instanceof ColumnNameEditor) { - columnName = ((ColumnNameEditor) currentEditor).getColumnName(); - } - - return new Object[]{columnIndex, columnName}; - } - - public Object update(boolean isXMLA) { - String name = currentEditor.getName(); - Object columnIndex = currentEditor.getValue(); - Object columnName = StringUtils.EMPTY; - - if (ComparatorUtils.equals(name, Inter.getLocText("FR-Designer_Formula"))) { - columnIndex = new Formula(columnIndex == null ? "" : columnIndex.toString()); - } - - if (isXMLA) { - columnName = ((XMLANameEditor) currentEditor).getColumnName(); - } - - return new Object[]{columnIndex, columnName}; - } - - public void setEditors(Editor[] editors, Object obj) { - this.cards = editors; - this.populate(obj); - } - - /** - * 检查是否有效 - * - * @throws Exception 异常 - */ - public void checkValid() throws Exception { - if (!(currentEditor instanceof TextEditor)) { - return; - } - - int i; - boolean containFormulaType = false; - for (i = 0; i < cards.length; i++) { - if (ComparatorUtils.equals(cards[i].getName(), Inter.getLocText("FR-Engine_Parameter-Formula"))) { - containFormulaType = true; - break; - } - } - if (!containFormulaType) { - return; - } - - final int j = i; - - if (!(currentEditor instanceof TextEditor)) { - return; - } - String string = (String) currentEditor.getValue(); - if (isFormula(string)) { - DesignerEnvManager designerEnvManager = DesignerEnvManager.getEnvManager(); - if (designerEnvManager.isSupportStringToFormula()) { - if (!designerEnvManager.isDefaultStringToFormula()) { - int returnValue = JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("FR-Designer_Edit_String_To_Formula") - + "?", Inter.getLocText("FR-Designer_Tooltips"), JOptionPane.YES_NO_OPTION); - if (returnValue == JOptionPane.OK_OPTION) { - - setCurrentEditor(j); - Formula formula = new Formula(string); - currentEditor.setValue(formula); - } - } else { - setCurrentEditor(j); - Formula formula = new Formula(string); - currentEditor.setValue(formula); - } - } - } - - } - - private boolean isFormula(String string) { - return StringUtils.isNotBlank(string) && (string.length() > 0 && string.charAt(0) == '='); - } - - @Override - public void setEnabled(boolean enabled) { - arrowButton.setEnabled(enabled); - for (Editor card : cards) { - card.setEnabled(enabled); - } - } - - /** - * 重置组件 - */ - public void resetComponets() { - for (Editor card : cards) { - card.reset(); - } - } - - /** - * 清除组件数据 - */ - public void clearComponentsData() { - for (Editor card : cards) { - card.clearData(); - } - } - - public Editor[] getCards() { - return this.cards; - } - - public JPopupMenu getMenu() { - return this.menu; - } - - - /** - * 注册全局名字监听事件 - * - * @param listener 观察者监听事件 - */ - public void registerNameListener(GlobalNameListener listener) { - globalNameListener = listener; - } - - /** - * 是否对名字listener监听器做出响应 - * - * @return 如果要做出响应,则返回true - */ - public boolean shouldResponseNameListener() { - return false; - } - - public void setGlobalName(String name) { - for (Editor card : cards) { - setComponentGlobalName(card, name); - } - } - - private void setComponentGlobalName(Container card, String name) { - for (int i = 0, len = card.getComponentCount(); i < len; i++) { - Component component = card.getComponent(i); - if (component instanceof GlobalNameObserver) { - ((GlobalNameObserver) component).setGlobalName(name); - } else { - setComponentGlobalName((Container) component, name); - } - } - } - - /** - * 给组件登记一个观察者监听事件 - * - * @param listener 观察者监听事件 - */ - public void registerChangeListener(UIObserverListener listener) { - uiObserverListener = listener; - for (Editor card : cards) { - doLoop(card, listener); - } - } - - private void doLoop(Container card, UIObserverListener listener) { - for (int i = 0, len = card.getComponentCount(); i < len; i++) { - Component component = card.getComponent(i); - if (component instanceof UIObserver) { - ((UIObserver) component).registerChangeListener(listener); - } else { - doLoop((Container) component, listener); - } - } - } - - /** - * 组件是否需要响应添加的观察者事件 - * - * @return 如果需要响应观察者事件则返回true,否则返回false - */ - public boolean shouldResponseChangeListener() { - return true; - } +package com.fr.design.editor; + +import com.fr.base.BaseFormula; +import com.fr.design.DesignerEnvManager; +import com.fr.design.dialog.BasicPane; +import com.fr.design.editor.editor.ColumnNameEditor; +import com.fr.design.editor.editor.Editor; +import com.fr.design.editor.editor.FormulaEditor; +import com.fr.design.editor.editor.TextEditor; +import com.fr.design.editor.editor.XMLANameEditor; +import com.fr.design.event.GlobalNameListener; +import com.fr.design.event.GlobalNameObserver; +import com.fr.design.event.UIObserver; +import com.fr.design.event.UIObserverListener; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.imenu.UIMenuEastAttrItem; +import com.fr.design.gui.imenu.UIPopupEastAttrMenu; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.mainframe.DesignerContext; +import com.fr.general.ComparatorUtils; +import com.fr.general.Inter; +import com.fr.stable.StringUtils; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +public class ValueEditorPane extends BasicPane implements UIObserver, GlobalNameObserver { + + private Editor[] cards; + + private Editor currentEditor; + + private UIButton arrowButton; + private JPopupMenu menu; + private JPanel centerPane; + + private Object value; + + private GlobalNameListener globalNameListener = null; + private UIObserverListener uiObserverListener = null; + + public ValueEditorPane(Editor[] cards) { + this(cards, null, null); + } + + public ValueEditorPane(Editor[] cards, String popupName, String textEditorValue) { + initComponents(cards, popupName, textEditorValue, 200); + } + + public ValueEditorPane(Editor[] cards, String popupName, String textEditorValue, int centerPaneWidth) { + initComponents(cards, popupName, textEditorValue, centerPaneWidth); + } + + private void initComponents(final Editor[] cards, String popupName, String textEditorValue, int centerPaneWidth) { + + this.cards = cards; + + // Frank:布局 + this.setLayout(new BorderLayout(2, 0)); + centerPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + arrowButton = new UIButton(); + arrowButton.set4ToolbarButton(); + setCurrentEditor(0); + centerPane.setPreferredSize(new Dimension(centerPaneWidth, centerPane.getPreferredSize().height)); + arrowButton.setPreferredSize(new Dimension(20, centerPane.getPreferredSize().height)); + final Color beforeColor = arrowButton.getBackground(); + menu = createPopMenu(); + + arrowButton.addMouseListener(new MouseAdapter() { + public void mouseEntered(MouseEvent a) { + if (cards != null && cards.length > 1) { + arrowButton.setBackground(new Color(228, 246, 255)); + arrowButton.repaint(); + } + } + + public void mouseExited(MouseEvent a) { + arrowButton.setBackground(beforeColor); + arrowButton.setBorder(null); + } + }); + arrowButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (cards != null && cards.length > 1) { // 如果只有“列”的话,就不需要弹出菜单了 + Rectangle re = centerPane.getBounds(); + menu.setPopupSize(re.width + arrowButton.getWidth(), menu.getPreferredSize().height); + menu.show(centerPane, -arrowButton.getWidth(), re.height); + } + } + }); + + this.add(centerPane, BorderLayout.CENTER); + if (cards.length > 1) { + this.add(arrowButton, BorderLayout.WEST); + } + } + + @Override + protected String title4PopupWindow() { + return Inter.getLocText("FR-Designer_Values-Editor"); + } + + public Editor getCurrentEditor() { + return currentEditor; + } + + public int getCurrentEditorIndex() { + for (int i = 0;i < cards.length; i++){ + if (cards[i].getClass() == currentEditor.getClass()){ + return i; + } + } + return 0; + } + + public void setCurrentEditor(int i) { + this.add(arrowButton, BorderLayout.WEST); + currentEditor = this.cards[i]; + centerPane.removeAll(); + centerPane.add(currentEditor); + centerPane.validate(); + centerPane.repaint(); + arrowButton.setIcon(cards[i].getIcon()); + if (this.cards.length == 1) { + this.remove(arrowButton); + } + } + + public void setCurrentEditor(Class editorClass) { + for (int i = 0; i < cards.length; i++) { + if (cards[i].getClass() == editorClass) { + setCurrentEditor(i); + break; + } + } + } + + + private JPopupMenu createPopMenu() { + JPopupMenu scate = new UIPopupEastAttrMenu(); + + if (this.cards == null) { + return scate; + } + + for (int i = 0; i < this.cards.length; i++) { + JMenuItem item = new UIMenuEastAttrItem(cards[i].getName()); + final int j = i; + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (globalNameListener != null) { + globalNameListener.setGlobalName(Inter.getLocText("CellWrite-InsertRow_Policy")); + } + Object oldValue = currentEditor.getValue(); + setCurrentEditor(j); + currentEditor.selected(); + value = currentEditor.getValue(); + if (uiObserverListener != null) { + uiObserverListener.doChange(); + } + + ValueEditorPane.this.firePropertyChange("value", oldValue, value); + } + }); + scate.add(item); + } + return scate; + } + + public void populate(Object object) { + for (int i = 0; i < cards.length; i++) { + if (cards[i].accept(object)) { + setCardValue(i,object); + break; + } + } + } + + public void populate(Object object,String name) { + for (int i = 0; i < cards.length; i++) { + if (cards[i].accept(object) && ComparatorUtils.equals(cards[i].getName(),name)) { + setCardValue(i,object); + break; + } + } + } + + private void setCardValue(int i,Object object){ + setCurrentEditor(i); + cards[i].setValue(object); + // kunsnat: bug7861 所有的Editor值都要跟随改变, 因为populate的editor 从"" + // 一定是最后的Editor哦. + for (int j = 0; j < cards.length; j++) { + if (i == j) { + continue; + } + this.cards[j].setValue(null); + } + } + + public Object update() { + String name = currentEditor.getName(); + Object columnIndex = currentEditor.getValue(); + //bug86542,这边为啥要new一个公式出来,只保留content,其他属性全不要了? + //MoMeak:我也想注释了,但是有bug啊。。。 + if (columnIndex == null && ComparatorUtils.equals(name, Inter.getLocText("Formula"))) { + columnIndex = ((FormulaEditor) currentEditor).getFormula(); + } + + return columnIndex; + } + + public Object update(String makeAdiff) { + String name = currentEditor.getName(); + Object columnIndex = currentEditor.getValue(); + Object columnName = StringUtils.EMPTY; + + if (ComparatorUtils.equals(name, Inter.getLocText("FR-Designer_Formula"))) { + columnIndex = BaseFormula.createFormulaBuilder().build(columnIndex == null ? "" : columnIndex.toString()); + } + + if (currentEditor instanceof ColumnNameEditor) { + columnName = ((ColumnNameEditor) currentEditor).getColumnName(); + } + + return new Object[]{columnIndex, columnName}; + } + + public Object update(boolean isXMLA) { + String name = currentEditor.getName(); + Object columnIndex = currentEditor.getValue(); + Object columnName = StringUtils.EMPTY; + + if (ComparatorUtils.equals(name, Inter.getLocText("FR-Designer_Formula"))) { + columnIndex = BaseFormula.createFormulaBuilder().build(columnIndex == null ? "" : columnIndex.toString()); + } + + if (isXMLA) { + columnName = ((XMLANameEditor) currentEditor).getColumnName(); + } + + return new Object[]{columnIndex, columnName}; + } + + public void setEditors(Editor[] editors, Object obj) { + this.cards = editors; + this.populate(obj); + } + + /** + * 检查是否有效 + * + * @throws Exception 异常 + */ + public void checkValid() throws Exception { + if (!(currentEditor instanceof TextEditor)) { + return; + } + + int i; + boolean containFormulaType = false; + for (i = 0; i < cards.length; i++) { + if (ComparatorUtils.equals(cards[i].getName(), Inter.getLocText("FR-Engine_Parameter-Formula"))) { + containFormulaType = true; + break; + } + } + if (!containFormulaType) { + return; + } + + final int j = i; + + if (!(currentEditor instanceof TextEditor)) { + return; + } + String string = (String) currentEditor.getValue(); + if (isFormula(string)) { + DesignerEnvManager designerEnvManager = DesignerEnvManager.getEnvManager(); + if (designerEnvManager.isSupportStringToFormula()) { + if (!designerEnvManager.isDefaultStringToFormula()) { + int returnValue = JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("FR-Designer_Edit_String_To_Formula") + + "?", Inter.getLocText("FR-Designer_Tooltips"), JOptionPane.YES_NO_OPTION); + if (returnValue == JOptionPane.OK_OPTION) { + + setCurrentEditor(j); + BaseFormula formula = BaseFormula.createFormulaBuilder().build(string); + currentEditor.setValue(formula); + } + } else { + setCurrentEditor(j); + BaseFormula formula = BaseFormula.createFormulaBuilder().build(string); + currentEditor.setValue(formula); + } + } + } + } + + private boolean isFormula(String string) { + return StringUtils.isNotBlank(string) && (string.length() > 0 && string.charAt(0) == '='); + } + + @Override + public void setEnabled(boolean enabled) { + arrowButton.setEnabled(enabled); + for (Editor card : cards) { + card.setEnabled(enabled); + } + } + + /** + * 重置组件 + */ + public void resetComponets() { + for (Editor card : cards) { + card.reset(); + } + } + + /** + * 清除组件数据 + */ + public void clearComponentsData() { + for (Editor card : cards) { + card.clearData(); + } + } + + public Editor[] getCards() { + return this.cards; + } + + public JPopupMenu getMenu() { + return this.menu; + } + + + /** + * 注册全局名字监听事件 + * + * @param listener 观察者监听事件 + */ + public void registerNameListener(GlobalNameListener listener) { + globalNameListener = listener; + } + + /** + * 是否对名字listener监听器做出响应 + * + * @return 如果要做出响应,则返回true + */ + public boolean shouldResponseNameListener() { + return false; + } + + public void setGlobalName(String name) { + for (Editor card : cards) { + setComponentGlobalName(card, name); + } + } + + private void setComponentGlobalName(Container card, String name) { + for (int i = 0, len = card.getComponentCount(); i < len; i++) { + Component component = card.getComponent(i); + if (component instanceof GlobalNameObserver) { + ((GlobalNameObserver) component).setGlobalName(name); + } else { + setComponentGlobalName((Container) component, name); + } + } + } + + /** + * 给组件登记一个观察者监听事件 + * + * @param listener 观察者监听事件 + */ + public void registerChangeListener(UIObserverListener listener) { + uiObserverListener = listener; + for (Editor card : cards) { + doLoop(card, listener); + } + } + + private void doLoop(Container card, UIObserverListener listener) { + for (int i = 0, len = card.getComponentCount(); i < len; i++) { + Component component = card.getComponent(i); + if (component instanceof UIObserver) { + ((UIObserver) component).registerChangeListener(listener); + } else { + doLoop((Container) component, listener); + } + } + } + + /** + * 组件是否需要响应添加的观察者事件 + * + * @return 如果需要响应观察者事件则返回true,否则返回false + */ + public boolean shouldResponseChangeListener() { + return true; + } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/editor/ValueEditorPaneFactory.java b/designer_base/src/com/fr/design/editor/ValueEditorPaneFactory.java index 7d0316273..bd71b300a 100644 --- a/designer_base/src/com/fr/design/editor/ValueEditorPaneFactory.java +++ b/designer_base/src/com/fr/design/editor/ValueEditorPaneFactory.java @@ -1,6 +1,6 @@ package com.fr.design.editor; -import com.fr.base.Formula; +import com.fr.base.BaseFormula; import com.fr.design.editor.editor.BooleanEditor; import com.fr.design.editor.editor.ColumnRowEditor; import com.fr.design.editor.editor.ColumnRowGroupEditor; @@ -471,9 +471,9 @@ public class ValueEditorPaneFactory { if (hyperLinkEditorMap == null) { return lists; } - Iterator> entries = hyperLinkEditorMap.entrySet().iterator(); + Iterator> entries = hyperLinkEditorMap.entrySet().iterator(); while (entries.hasNext()) { - Map.Entry entry = entries.next(); + Map.Entry entry = entries.next(); ConstantsEditor editor = new ConstantsEditor(entry.getKey(), entry.getValue()); editor.setEnabled(false); lists.add(editor); diff --git a/designer_base/src/com/fr/design/editor/editor/ConstantsEditor.java b/designer_base/src/com/fr/design/editor/editor/ConstantsEditor.java index bf4a7f006..31f99e58c 100644 --- a/designer_base/src/com/fr/design/editor/editor/ConstantsEditor.java +++ b/designer_base/src/com/fr/design/editor/editor/ConstantsEditor.java @@ -1,11 +1,11 @@ package com.fr.design.editor.editor; -import com.fr.base.Formula; +import com.fr.base.BaseFormula; public class ConstantsEditor extends FormulaEditor { - public ConstantsEditor(String name, Formula formula) { + public ConstantsEditor(String name, BaseFormula formula) { super(name, formula); } @@ -13,11 +13,11 @@ public class ConstantsEditor extends FormulaEditor { // do nothing 防止修改... } - public void setValue(Formula value) { + public void setValue(BaseFormula value) { // do nothing 防止修改... } public boolean accept(Object object) { - return object instanceof Formula && object.equals(this.getValue()); + return object instanceof BaseFormula && object.equals(this.getValue()); } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/editor/editor/FormulaEditor.java b/designer_base/src/com/fr/design/editor/editor/FormulaEditor.java index 943fb3a66..a5992a17d 100644 --- a/designer_base/src/com/fr/design/editor/editor/FormulaEditor.java +++ b/designer_base/src/com/fr/design/editor/editor/FormulaEditor.java @@ -3,13 +3,12 @@ */ package com.fr.design.editor.editor; -import com.fr.base.Formula; +import com.fr.base.BaseFormula; import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.formula.FormulaFactory; import com.fr.design.formula.UIFormula; import com.fr.design.gui.itextfield.UITextField; import com.fr.design.layout.FRGUIPaneFactory; -import com.fr.stable.StringUtils; import javax.swing.*; import javax.swing.event.DocumentListener; @@ -23,10 +22,10 @@ import java.awt.event.MouseEvent; * @editor zhou * @since 2012-3-29下午6:27:27 */ -public class FormulaEditor extends Editor { - private Formula formula = new Formula(StringUtils.EMPTY); +public class FormulaEditor extends Editor { + private BaseFormula formula = BaseFormula.createFormulaBuilder().build(); private UITextField currentTextField; - private ShowPaneListener listerner = new ShowPaneListener(); + private ShowPaneListener listener = new ShowPaneListener(); /** * Constructor. @@ -39,7 +38,7 @@ public class FormulaEditor extends Editor { this(name, null); } - public FormulaEditor(String name, Formula formula) { + public FormulaEditor(String name, BaseFormula formula) { if (formula != null) { this.formula = formula; } @@ -51,7 +50,7 @@ public class FormulaEditor extends Editor { editPane.add(currentTextField, BorderLayout.CENTER); currentTextField.setEditable(false); - currentTextField.addMouseListener(listerner); + currentTextField.addMouseListener(listener); this.add(editPane, BorderLayout.CENTER); this.setName(name); } @@ -96,7 +95,7 @@ public class FormulaEditor extends Editor { }).setVisible(true); } - public Formula getFormula(){ + public BaseFormula getFormula(){ return formula; } @@ -104,7 +103,7 @@ public class FormulaEditor extends Editor { * Return the value of the CellEditor. */ @Override - public Formula getValue() { + public BaseFormula getValue() { if (formula != null && "=".equals(formula.getContent())) { return null; } @@ -115,9 +114,9 @@ public class FormulaEditor extends Editor { * Set the value to the CellEditor. */ @Override - public void setValue(Formula value) { + public void setValue(BaseFormula value) { if (value == null) { - value = new Formula(StringUtils.EMPTY); + value = BaseFormula.createFormulaBuilder().build(); } this.formula = value; currentTextField.setText(value.toString()); @@ -143,7 +142,7 @@ public class FormulaEditor extends Editor { * @return 是公式类型则返回true */ public boolean accept(Object object) { - return object instanceof Formula; + return object instanceof BaseFormula; } /** @@ -151,7 +150,7 @@ public class FormulaEditor extends Editor { */ public void reset() { currentTextField.setText("="); - formula = new Formula(StringUtils.EMPTY); + formula = BaseFormula.createFormulaBuilder().build(); } /** @@ -170,13 +169,13 @@ public class FormulaEditor extends Editor { this.setEnabled(flag); this.currentTextField.setEnabled(flag); if (flag == false) { - this.currentTextField.removeMouseListener(listerner); + this.currentTextField.removeMouseListener(listener); } else { int listenerSize = this.currentTextField.getMouseListeners().length; for (int i = 0; i < listenerSize; i++) { - this.currentTextField.removeMouseListener(listerner); + this.currentTextField.removeMouseListener(listener); } - this.currentTextField.addMouseListener(listerner); + this.currentTextField.addMouseListener(listener); } } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/formula/FormulaPane.java b/designer_base/src/com/fr/design/formula/FormulaPane.java index 156a2e2f2..034773172 100644 --- a/designer_base/src/com/fr/design/formula/FormulaPane.java +++ b/designer_base/src/com/fr/design/formula/FormulaPane.java @@ -1,8 +1,8 @@ package com.fr.design.formula; +import com.fr.base.BaseFormula; import com.fr.base.BaseUtils; import com.fr.base.FRContext; -import com.fr.base.Formula; import com.fr.design.actions.UpdateAction; import com.fr.design.border.UIRoundedBorder; import com.fr.design.constants.UIConstants; @@ -32,13 +32,27 @@ import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; -import javax.swing.tree.*; - +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeCellRenderer; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.MutableTreeNode; +import javax.swing.tree.TreePath; import java.awt.*; -import java.awt.event.*; -import java.io.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.StringReader; import java.util.Locale; -import java.util.Set; /** * 公式编辑面板 @@ -468,11 +482,11 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { /** * Populate */ - public void populate(Formula formula) { + public void populate(BaseFormula formula) { this.populate(formula, VariableResolver.DEFAULT); } - public void populate(Formula formula, VariableResolver variableResolver) { + public void populate(BaseFormula formula, VariableResolver variableResolver) { this.variableTreeAndDescriptionArea.populate(variableResolver); // set text @@ -508,19 +522,18 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { /** * update */ - public Formula update() { - Formula formula; + public BaseFormula update() { + BaseFormula formula; if (ifHasBeenWriten == 0) { - String content = StringUtils.EMPTY; - formula = new Formula(content); + formula = BaseFormula.createFormulaBuilder().build(); return formula; } else { String content = this.formulaTextArea.getText(); if (StringUtils.isEmpty(content) || content.trim().charAt(0) == '=') { - formula = new Formula(content); + formula = BaseFormula.createFormulaBuilder().build(content); } else { - formula = new Formula("=" + content); + formula = BaseFormula.createFormulaBuilder().build("=" + content); } return formula; } diff --git a/designer_base/src/com/fr/design/formula/FormulaPaneWhenReserveFormula.java b/designer_base/src/com/fr/design/formula/FormulaPaneWhenReserveFormula.java index 05530d630..40ace6a48 100644 --- a/designer_base/src/com/fr/design/formula/FormulaPaneWhenReserveFormula.java +++ b/designer_base/src/com/fr/design/formula/FormulaPaneWhenReserveFormula.java @@ -1,6 +1,6 @@ package com.fr.design.formula; -import com.fr.base.Formula; +import com.fr.base.BaseFormula; import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.general.Inter; @@ -46,15 +46,15 @@ public class FormulaPaneWhenReserveFormula extends FormulaPane { } @Override - public void populate(Formula formula, VariableResolver variableResolver) { + public void populate(BaseFormula formula, VariableResolver variableResolver) { super.populate(formula, variableResolver); reserveCheckBox4Result.setSelected(formula.isReserveInResult()); reserveCheckBox4Write.setSelected(formula.isReserveOnWriteOrAnaly()); } @Override - public Formula update() { - Formula formula = super.update(); + public BaseFormula update() { + BaseFormula formula = super.update(); if (formula != null) { formula.setReserveInResult(this.reserveCheckBox4Result.isSelected()); formula.setReserveOnWriteOrAnaly(this.reserveCheckBox4Write.isSelected()); diff --git a/designer_base/src/com/fr/design/formula/SortFormulaPane.java b/designer_base/src/com/fr/design/formula/SortFormulaPane.java index 5e3398ec5..1ab101cd2 100644 --- a/designer_base/src/com/fr/design/formula/SortFormulaPane.java +++ b/designer_base/src/com/fr/design/formula/SortFormulaPane.java @@ -1,7 +1,7 @@ package com.fr.design.formula; -import com.fr.base.Formula; +import com.fr.base.BaseFormula; import com.fr.data.util.SortOrder; import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.gui.ibutton.UIButton; @@ -57,12 +57,11 @@ public abstract class SortFormulaPane extends JPanel { public void showFormulaDialog(String[] displayNames) { String text = sortFormulaTextField.getText(); final UIFormula formulaPane = FormulaFactory.createFormulaPaneWhenReserveFormula(); - - formulaPane.populate(new Formula(text), new CustomVariableResolver(displayNames, true)); + formulaPane.populate(BaseFormula.createFormulaBuilder().build(text), new CustomVariableResolver(displayNames, true)); formulaPane.showLargeWindow(SwingUtilities.getWindowAncestor(SortFormulaPane.this), new DialogActionAdapter() { public void doOk() { - Formula fm = formulaPane.update(); + BaseFormula fm = formulaPane.update(); if (fm.getContent().length() <= 1) { sortFormulaTextField.setText(""); } else { diff --git a/designer_base/src/com/fr/design/formula/TinyFormulaPane.java b/designer_base/src/com/fr/design/formula/TinyFormulaPane.java index a37b384c3..0f19e219d 100644 --- a/designer_base/src/com/fr/design/formula/TinyFormulaPane.java +++ b/designer_base/src/com/fr/design/formula/TinyFormulaPane.java @@ -1,18 +1,15 @@ package com.fr.design.formula; +import com.fr.base.BaseFormula; import com.fr.base.BaseUtils; -import com.fr.base.Formula; import com.fr.design.beans.BasicBeanPane; -import com.fr.design.constants.LayoutConstants; import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.event.UIObserver; import com.fr.design.event.UIObserverListener; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.itextfield.UITextField; import com.fr.design.layout.TableLayout; -import com.fr.design.layout.TableLayoutHelper; import com.fr.design.mainframe.DesignerContext; -import com.fr.design.utils.gui.GUICoreUtils; import com.fr.general.Inter; import javax.swing.*; @@ -51,11 +48,11 @@ public class TinyFormulaPane extends BasicBeanPane implements UIObserver String text = formulaTextField.getText(); final UIFormula formulaPane = FormulaFactory.createFormulaPane(); - formulaPane.populate(new Formula(text)); + formulaPane.populate(BaseFormula.createFormulaBuilder().build(text)); formulaPane.showLargeWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { @Override public void doOk() { - Formula fm = formulaPane.update(); + BaseFormula fm = formulaPane.update(); populateTextField(fm); okEvent(); } @@ -65,7 +62,7 @@ public class TinyFormulaPane extends BasicBeanPane implements UIObserver initLayout(); } - protected void populateTextField(Formula fm) { + protected void populateTextField(BaseFormula fm) { if (fm.getContent().length() <= 1) { formulaTextField.setText("$$$"); } else { diff --git a/designer_base/src/com/fr/design/formula/UIFormula.java b/designer_base/src/com/fr/design/formula/UIFormula.java index fa6c75c3a..9eec6f14b 100644 --- a/designer_base/src/com/fr/design/formula/UIFormula.java +++ b/designer_base/src/com/fr/design/formula/UIFormula.java @@ -1,6 +1,6 @@ package com.fr.design.formula; -import com.fr.base.Formula; +import com.fr.base.BaseFormula; import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.DialogActionListener; @@ -17,20 +17,20 @@ public interface UIFormula { * 从已有的公式还原公式面板 * @param formula 公式 */ - void populate(Formula formula); + void populate(BaseFormula formula); /** * 根据指定的变量处理和公式还原公式面板 * @param formula 公式 * @param variableResolver 变量处理器 */ - void populate(Formula formula, VariableResolver variableResolver); + void populate(BaseFormula formula, VariableResolver variableResolver); /** * 获取公式面板的参数 * @return 公式 */ - Formula update(); + BaseFormula update(); /** * 显示窗口 diff --git a/designer_base/src/com/fr/design/gui/frpane/JTreeAutoBuildPane.java b/designer_base/src/com/fr/design/gui/frpane/JTreeAutoBuildPane.java index ffe35cbb0..9daad1bd8 100644 --- a/designer_base/src/com/fr/design/gui/frpane/JTreeAutoBuildPane.java +++ b/designer_base/src/com/fr/design/gui/frpane/JTreeAutoBuildPane.java @@ -1,229 +1,233 @@ -package com.fr.design.gui.frpane; - -import com.fr.base.Formula; -import com.fr.design.data.BasicTableDataTreePane; -import com.fr.design.data.DesignTableDataManager; -import com.fr.design.data.datapane.EditOrNewLabel; -import com.fr.design.data.datapane.TableDataTreePane; -import com.fr.design.data.datapane.TreeTableDataComboBox; -import com.fr.design.data.datapane.preview.PreviewLabel; -import com.fr.data.impl.NameTableData; -import com.fr.data.impl.RecursionTableData; -import com.fr.data.impl.TableDataDictionary; -import com.fr.design.data.tabledata.wrapper.AbstractTableDataWrapper; -import com.fr.design.data.tabledata.wrapper.TableDataWrapper; -import com.fr.design.data.tabledata.wrapper.TemplateTableDataWrapper; -import com.fr.design.DesignModelAdapter; -import com.fr.design.gui.ilable.UILabel; -import com.fr.design.layout.FRGUIPaneFactory; -import com.fr.design.layout.TableLayout; -import com.fr.design.layout.TableLayoutHelper; -import com.fr.design.dialog.BasicPane; -import com.fr.design.editor.ValueEditorPane; -import com.fr.design.editor.ValueEditorPaneFactory; -import com.fr.design.editor.editor.*; -import com.fr.general.Inter; -import com.fr.stable.StringUtils; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.util.List; - -public class JTreeAutoBuildPane extends BasicPane implements PreviewLabel.Previewable, EditOrNewLabel.Editable { - private TreeTableDataComboBox treeTableDataComboBox; - private ValueEditorPane valuePane; - private ValueEditorPane textPane; - private JPanel centerPane; - private JPanel selectTreeDataPanel; - - public JTreeAutoBuildPane() { - this.initComponent(); - } - - /** - * 初始化 - */ - public void initComponent() { - this.setLayout(FRGUIPaneFactory.createM_BorderLayout()); - UILabel selectTreeDataLabel = new UILabel(Inter.getLocText("Select_A_Tree_DataSource_To_Build") + ": "); - treeTableDataComboBox = new TreeTableDataComboBox(DesignTableDataManager.getEditingTableDataSource()); - treeTableDataComboBox.setPreferredSize(new Dimension(180, 20)); - selectTreeDataPanel = FRGUIPaneFactory.createBoxFlowInnerContainer_S_Pane(); - selectTreeDataPanel.add(selectTreeDataLabel); - treeTableDataComboBox.addItemListener(new ItemListener() { - public void itemStateChanged(ItemEvent e) { - tdChange(); - } - }); - selectTreeDataPanel.add(treeTableDataComboBox); - treeTableDataComboBox.setPreferredSize(new Dimension(200, 25)); - treeTableDataComboBox.setSelectedIndex(-1); - PreviewLabel pl = new PreviewLabel(this); - pl.setPreferredSize(new Dimension(25, 25)); - EditOrNewLabel enl = new EditOrNewLabel(this, this); - enl.setPreferredSize(new Dimension(25, 25)); - selectTreeDataPanel.add(pl); - selectTreeDataPanel.add(enl); - - this.add(selectTreeDataPanel, BorderLayout.NORTH); - - valuePane = ValueEditorPaneFactory.createValueEditorPane(new Editor[]{new ColumnNameEditor(), new ColumnIndexEditor()}); - FormulaEditor formulaEditor = new FormulaEditor(Inter.getLocText("Parameter-Formula")); - formulaEditor.setEnabled(true); - textPane = ValueEditorPaneFactory.createValueEditorPane(new Editor[]{new ColumnNameEditor(), new ColumnIndexEditor(), formulaEditor}); - Component[][] coms = { - {new UILabel(Inter.getLocText("Actual_Value") + ":"), - valuePane}, - {new UILabel(Inter.getLocText("Display_Value") + ":"), - textPane}}; - - double p = TableLayout.PREFERRED; - - double[] rowSize = {p, p, p}; - double[] columnSize = {p, p}; - centerPane = TableLayoutHelper.createTableLayoutPane(coms, rowSize, - columnSize); - - this.add(centerPane, BorderLayout.CENTER); - tdChange(); - } - - private void tdChange() { - TableDataWrapper tableDataWrappe = this.treeTableDataComboBox.getSelectedItem(); - if (tableDataWrappe == null) { - return; - } - try { - List namelist = tableDataWrappe.calculateColumnNameList(); - String[] columnNames = new String[namelist.size()]; - namelist.toArray(columnNames); - valuePane.setEditors(new Editor[]{new ColumnNameEditor(columnNames), new ColumnIndexEditor(columnNames.length)}, columnNames[0]); - FormulaEditor formulaEditor = new FormulaEditor(Inter.getLocText("Parameter-Formula")); - formulaEditor.setEnabled(true); - textPane.setEditors(new Editor[]{new ColumnNameEditor(columnNames), new ColumnIndexEditor(columnNames.length), formulaEditor}, columnNames[0]); - } catch (Exception e) { - valuePane.setEditors(new Editor[]{new OldColumnIndexEditor(100, Inter.getLocText("ColumnName"))}, 1); - FormulaEditor formulaEditor = new FormulaEditor(Inter.getLocText("Parameter-Formula")); - formulaEditor.setEnabled(true); - textPane.setEditors(new Editor[]{new OldColumnIndexEditor(100, Inter.getLocText("ColumnName")), formulaEditor}, 1); - } - } - - public void populate(TableDataDictionary tableDataDict) { - if (tableDataDict == null) { - this.treeTableDataComboBox.setSelectedItem(""); - this.textPane.populate(1); - this.valuePane.populate(1); - return; - } else { - String _name = ""; - if (tableDataDict.getTableData() instanceof NameTableData) { - _name = ((NameTableData) tableDataDict.getTableData()).getName(); - } - this.treeTableDataComboBox.setSelectedTableDataByName(_name); - tdChange(); - // alex:因为显示到界面上的index是以1为始的,所以要加1 - if (!StringUtils.isEmpty(tableDataDict.getKeyColumnName())) { - this.valuePane.populate(tableDataDict.getKeyColumnName()); - } else { - this.valuePane.populate(tableDataDict.getKeyColumnIndex() + 1); - } - Object value = null; - if ((tableDataDict).getFormula() != null) { - value = (tableDataDict).getFormula(); - } else { - if (!StringUtils.isEmpty(tableDataDict.getValueColumnName())) { - value = tableDataDict.getValueColumnName(); - } else { - value = tableDataDict.getValueColumnIndex() + 1; - } - } - - this.textPane.populate(value); - } - } - - public TableDataDictionary update() { - TableDataDictionary tableDataDict = new TableDataDictionary(); - Object object = this.valuePane.update(StringUtils.EMPTY); - // alex:因为显示到界面上的index是以1为始的,所以要减1 - // carl:假如这里的序号要变,请考虑6.2的兼容 - - if (object instanceof Object[]) { - Object[] temp = (Object[]) object; - tableDataDict.setKeyColumnIndex(((Integer) temp[0]).intValue() - 1); - tableDataDict.setKeyColumnName((String) temp[1]); - } else if (object instanceof Integer) { - tableDataDict.setKeyColumnIndex((Integer) object - 1); - } else if (object instanceof String) { - tableDataDict.setKeyColumnName((String) object); - } - Object object_text = this.textPane.update(StringUtils.EMPTY); - if (object_text instanceof Object[]) { - Object[] temp = (Object[]) object_text; - if (temp[0] instanceof Formula) { - tableDataDict.setFormula((Formula) temp[0]); - } else { - tableDataDict.setValueColumnIndex(((Integer) temp[0]).intValue() - 1); - tableDataDict.setValueColumnName((String) temp[1]); - } - } else if (object_text instanceof Integer) { - tableDataDict.setValueColumnIndex((Integer) this.textPane.update() - 1); - } else if (object_text instanceof String) { - tableDataDict.setValueColumnName((String) object_text); - } else { - tableDataDict.setFormula(((Formula) object)); - } - - TableDataWrapper tableDataWrappe = this.treeTableDataComboBox.getSelectedItem(); - if (tableDataWrappe != null) { - tableDataDict.setTableData(new NameTableData(tableDataWrappe.getTableDataName())); - } - - return tableDataDict; - } - - @Override - protected String title4PopupWindow() { - return "Auto Build Tree"; - } - - /** - * 预览 - */ - public void preview() { - TableDataWrapper tableDataWrappe = treeTableDataComboBox.getSelectedItem(); - if (tableDataWrappe == null) { - return; - } - tableDataWrappe.previewData(); - } - - /** - * 编辑 - * @param jPanel 面板 - */ - public void edit(JPanel jPanel) { - RecursionTableData rtd = null; - String name = ""; - BasicTableDataTreePane tdtp = TableDataTreePane.getInstance(DesignModelAdapter.getCurrentModelAdapter()); - if (treeTableDataComboBox.getSelectedItem() == null) { - //新建 - rtd = new RecursionTableData(); - name = TableDataTreePane.createUnrepeatedName(tdtp.getDataTree(), "Tree"); - } else { - //编辑 - rtd = treeTableDataComboBox.getSelcetedTableData(); - name = treeTableDataComboBox.getSelectedItem().getTableDataName(); - } - AbstractTableDataWrapper atdw = new TemplateTableDataWrapper(rtd, ""); - tdtp.dgEdit(atdw.creatTableDataPane(), name); - treeTableDataComboBox.refresh(); - treeTableDataComboBox.setSelectedTableDataByName(name); - textPane.populate(1); - valuePane.populate(1); - } - +package com.fr.design.gui.frpane; + +import com.fr.base.BaseFormula; +import com.fr.data.impl.NameTableData; +import com.fr.data.impl.RecursionTableData; +import com.fr.data.impl.TableDataDictionary; +import com.fr.design.DesignModelAdapter; +import com.fr.design.data.BasicTableDataTreePane; +import com.fr.design.data.DesignTableDataManager; +import com.fr.design.data.datapane.EditOrNewLabel; +import com.fr.design.data.datapane.TableDataTreePane; +import com.fr.design.data.datapane.TreeTableDataComboBox; +import com.fr.design.data.datapane.preview.PreviewLabel; +import com.fr.design.data.tabledata.wrapper.AbstractTableDataWrapper; +import com.fr.design.data.tabledata.wrapper.TableDataWrapper; +import com.fr.design.data.tabledata.wrapper.TemplateTableDataWrapper; +import com.fr.design.dialog.BasicPane; +import com.fr.design.editor.ValueEditorPane; +import com.fr.design.editor.ValueEditorPaneFactory; +import com.fr.design.editor.editor.ColumnIndexEditor; +import com.fr.design.editor.editor.ColumnNameEditor; +import com.fr.design.editor.editor.Editor; +import com.fr.design.editor.editor.FormulaEditor; +import com.fr.design.editor.editor.OldColumnIndexEditor; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.layout.TableLayout; +import com.fr.design.layout.TableLayoutHelper; +import com.fr.general.Inter; +import com.fr.stable.StringUtils; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.List; + +public class JTreeAutoBuildPane extends BasicPane implements PreviewLabel.Previewable, EditOrNewLabel.Editable { + private TreeTableDataComboBox treeTableDataComboBox; + private ValueEditorPane valuePane; + private ValueEditorPane textPane; + private JPanel centerPane; + private JPanel selectTreeDataPanel; + + public JTreeAutoBuildPane() { + this.initComponent(); + } + + /** + * 初始化 + */ + public void initComponent() { + this.setLayout(FRGUIPaneFactory.createM_BorderLayout()); + UILabel selectTreeDataLabel = new UILabel(Inter.getLocText("Select_A_Tree_DataSource_To_Build") + ": "); + treeTableDataComboBox = new TreeTableDataComboBox(DesignTableDataManager.getEditingTableDataSource()); + treeTableDataComboBox.setPreferredSize(new Dimension(180, 20)); + selectTreeDataPanel = FRGUIPaneFactory.createBoxFlowInnerContainer_S_Pane(); + selectTreeDataPanel.add(selectTreeDataLabel); + treeTableDataComboBox.addItemListener(new ItemListener() { + public void itemStateChanged(ItemEvent e) { + tdChange(); + } + }); + selectTreeDataPanel.add(treeTableDataComboBox); + treeTableDataComboBox.setPreferredSize(new Dimension(200, 25)); + treeTableDataComboBox.setSelectedIndex(-1); + PreviewLabel pl = new PreviewLabel(this); + pl.setPreferredSize(new Dimension(25, 25)); + EditOrNewLabel enl = new EditOrNewLabel(this, this); + enl.setPreferredSize(new Dimension(25, 25)); + selectTreeDataPanel.add(pl); + selectTreeDataPanel.add(enl); + + this.add(selectTreeDataPanel, BorderLayout.NORTH); + + valuePane = ValueEditorPaneFactory.createValueEditorPane(new Editor[]{new ColumnNameEditor(), new ColumnIndexEditor()}); + FormulaEditor formulaEditor = new FormulaEditor(Inter.getLocText("Parameter-Formula")); + formulaEditor.setEnabled(true); + textPane = ValueEditorPaneFactory.createValueEditorPane(new Editor[]{new ColumnNameEditor(), new ColumnIndexEditor(), formulaEditor}); + Component[][] coms = { + {new UILabel(Inter.getLocText("Actual_Value") + ":"), + valuePane}, + {new UILabel(Inter.getLocText("Display_Value") + ":"), + textPane}}; + + double p = TableLayout.PREFERRED; + + double[] rowSize = {p, p, p}; + double[] columnSize = {p, p}; + centerPane = TableLayoutHelper.createTableLayoutPane(coms, rowSize, + columnSize); + + this.add(centerPane, BorderLayout.CENTER); + tdChange(); + } + + private void tdChange() { + TableDataWrapper tableDataWrappe = this.treeTableDataComboBox.getSelectedItem(); + if (tableDataWrappe == null) { + return; + } + try { + List namelist = tableDataWrappe.calculateColumnNameList(); + String[] columnNames = new String[namelist.size()]; + namelist.toArray(columnNames); + valuePane.setEditors(new Editor[]{new ColumnNameEditor(columnNames), new ColumnIndexEditor(columnNames.length)}, columnNames[0]); + FormulaEditor formulaEditor = new FormulaEditor(Inter.getLocText("Parameter-Formula")); + formulaEditor.setEnabled(true); + textPane.setEditors(new Editor[]{new ColumnNameEditor(columnNames), new ColumnIndexEditor(columnNames.length), formulaEditor}, columnNames[0]); + } catch (Exception e) { + valuePane.setEditors(new Editor[]{new OldColumnIndexEditor(100, Inter.getLocText("ColumnName"))}, 1); + FormulaEditor formulaEditor = new FormulaEditor(Inter.getLocText("Parameter-Formula")); + formulaEditor.setEnabled(true); + textPane.setEditors(new Editor[]{new OldColumnIndexEditor(100, Inter.getLocText("ColumnName")), formulaEditor}, 1); + } + } + + public void populate(TableDataDictionary tableDataDict) { + if (tableDataDict == null) { + this.treeTableDataComboBox.setSelectedItem(""); + this.textPane.populate(1); + this.valuePane.populate(1); + return; + } else { + String _name = ""; + if (tableDataDict.getTableData() instanceof NameTableData) { + _name = ((NameTableData) tableDataDict.getTableData()).getName(); + } + this.treeTableDataComboBox.setSelectedTableDataByName(_name); + tdChange(); + // alex:因为显示到界面上的index是以1为始的,所以要加1 + if (!StringUtils.isEmpty(tableDataDict.getKeyColumnName())) { + this.valuePane.populate(tableDataDict.getKeyColumnName()); + } else { + this.valuePane.populate(tableDataDict.getKeyColumnIndex() + 1); + } + Object value = null; + if ((tableDataDict).getFormula() != null) { + value = (tableDataDict).getFormula(); + } else { + if (!StringUtils.isEmpty(tableDataDict.getValueColumnName())) { + value = tableDataDict.getValueColumnName(); + } else { + value = tableDataDict.getValueColumnIndex() + 1; + } + } + + this.textPane.populate(value); + } + } + + public TableDataDictionary update() { + TableDataDictionary tableDataDict = new TableDataDictionary(); + Object object = this.valuePane.update(StringUtils.EMPTY); + // alex:因为显示到界面上的index是以1为始的,所以要减1 + // carl:假如这里的序号要变,请考虑6.2的兼容 + + if (object instanceof Object[]) { + Object[] temp = (Object[]) object; + tableDataDict.setKeyColumnIndex(((Integer) temp[0]).intValue() - 1); + tableDataDict.setKeyColumnName((String) temp[1]); + } else if (object instanceof Integer) { + tableDataDict.setKeyColumnIndex((Integer) object - 1); + } else if (object instanceof String) { + tableDataDict.setKeyColumnName((String) object); + } + Object object_text = this.textPane.update(StringUtils.EMPTY); + if (object_text instanceof Object[]) { + Object[] temp = (Object[]) object_text; + if (temp[0] instanceof BaseFormula) { + tableDataDict.setFormula((BaseFormula) temp[0]); + } else { + tableDataDict.setValueColumnIndex(((Integer) temp[0]).intValue() - 1); + tableDataDict.setValueColumnName((String) temp[1]); + } + } else if (object_text instanceof Integer) { + tableDataDict.setValueColumnIndex((Integer) this.textPane.update() - 1); + } else if (object_text instanceof String) { + tableDataDict.setValueColumnName((String) object_text); + } else { + tableDataDict.setFormula(((BaseFormula) object)); + } + + TableDataWrapper tableDataWrappe = this.treeTableDataComboBox.getSelectedItem(); + if (tableDataWrappe != null) { + tableDataDict.setTableData(new NameTableData(tableDataWrappe.getTableDataName())); + } + + return tableDataDict; + } + + @Override + protected String title4PopupWindow() { + return "Auto Build Tree"; + } + + /** + * 预览 + */ + public void preview() { + TableDataWrapper tableDataWrappe = treeTableDataComboBox.getSelectedItem(); + if (tableDataWrappe == null) { + return; + } + tableDataWrappe.previewData(); + } + + /** + * 编辑 + * @param jPanel 面板 + */ + public void edit(JPanel jPanel) { + RecursionTableData rtd = null; + String name = ""; + BasicTableDataTreePane tdtp = TableDataTreePane.getInstance(DesignModelAdapter.getCurrentModelAdapter()); + if (treeTableDataComboBox.getSelectedItem() == null) { + //新建 + rtd = new RecursionTableData(); + name = TableDataTreePane.createUnrepeatedName(tdtp.getDataTree(), "Tree"); + } else { + //编辑 + rtd = treeTableDataComboBox.getSelcetedTableData(); + name = treeTableDataComboBox.getSelectedItem().getTableDataName(); + } + AbstractTableDataWrapper atdw = new TemplateTableDataWrapper(rtd, ""); + tdtp.dgEdit(atdw.creatTableDataPane(), name); + treeTableDataComboBox.refresh(); + treeTableDataComboBox.setSelectedTableDataByName(name); + textPane.populate(1); + valuePane.populate(1); + } + } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/gui/ibutton/UIButtonGroup.java b/designer_base/src/com/fr/design/gui/ibutton/UIButtonGroup.java index a8ad8f095..76828e38e 100644 --- a/designer_base/src/com/fr/design/gui/ibutton/UIButtonGroup.java +++ b/designer_base/src/com/fr/design/gui/ibutton/UIButtonGroup.java @@ -1,12 +1,9 @@ package com.fr.design.gui.ibutton; -import com.fr.base.BaseUtils; import com.fr.design.constants.UIConstants; import com.fr.design.event.GlobalNameListener; import com.fr.design.event.GlobalNameObserver; -import com.fr.design.utils.gui.GUICoreUtils; import com.fr.stable.ArrayUtils; -import com.fr.stable.Constants; import com.fr.stable.StringUtils; import sun.swing.SwingUtilities2; @@ -200,7 +197,7 @@ public class UIButtonGroup extends JPanel implements GlobalNameObserver { if (isPressed(b)) { g.setColor(Color.white); } else { - g.setColor(Color.black); + g.setColor(b.isEnabled() ? Color.black : UIConstants.LINE_COLOR); } SwingUtilities2.drawStringUnderlineCharAt(b, g, text, mnemonicIndex, textRec.x + getTextShiftOffset(), textRec.y + fm.getAscent() + getTextShiftOffset()); diff --git a/designer_base/src/com/fr/design/gui/ispinner/UISpinner.java b/designer_base/src/com/fr/design/gui/ispinner/UISpinner.java index 2ffd53e19..0ec3768aa 100644 --- a/designer_base/src/com/fr/design/gui/ispinner/UISpinner.java +++ b/designer_base/src/com/fr/design/gui/ispinner/UISpinner.java @@ -262,7 +262,9 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver textField.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { + textField.getDocument().removeDocumentListener(docListener); textField.setValue(value); + textField.getDocument().addDocumentListener(docListener); } }); } diff --git a/designer_base/src/com/fr/design/mainframe/loghandler/DesignerLogHandler.java b/designer_base/src/com/fr/design/mainframe/loghandler/DesignerLogHandler.java index 740bd4ffe..9a2aed712 100644 --- a/designer_base/src/com/fr/design/mainframe/loghandler/DesignerLogHandler.java +++ b/designer_base/src/com/fr/design/mainframe/loghandler/DesignerLogHandler.java @@ -1,20 +1,44 @@ package com.fr.design.mainframe.loghandler; import com.fr.base.BaseUtils; +import com.fr.base.ConfigManager; import com.fr.base.FRContext; -import com.fr.design.DesignerEnvManager; import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.imenu.UIMenuItem; import com.fr.design.layout.FRGUIPaneFactory; -import com.fr.general.*; +import com.fr.general.ComparatorUtils; +import com.fr.general.FRLogLevel; +import com.fr.general.FRLogger; +import com.fr.general.GeneralContext; +import com.fr.general.Inter; import com.fr.log.LogHandler; import com.fr.stable.EnvChangedListener; import com.fr.stable.xml.LogRecordTimeProvider; -import javax.swing.*; -import javax.swing.text.*; -import java.awt.*; -import java.awt.event.*; +import javax.swing.AbstractAction; +import javax.swing.ActionMap; +import javax.swing.InputMap; +import javax.swing.JCheckBoxMenuItem; +import javax.swing.JComponent; +import javax.swing.JPanel; +import javax.swing.JPopupMenu; +import javax.swing.JTextPane; +import javax.swing.KeyStroke; +import javax.swing.text.BadLocationException; +import javax.swing.text.DefaultEditorKit; +import javax.swing.text.Document; +import javax.swing.text.SimpleAttributeSet; +import javax.swing.text.StyleConstants; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.text.SimpleDateFormat; import java.util.Date; import java.util.logging.Level; @@ -105,7 +129,7 @@ public class DesignerLogHandler { @Override public void actionPerformed(ActionEvent e) { JPopupMenu showsetPopup = new JPopupMenu(); - int logLevelvalue = DesignerEnvManager.getEnvManager().getLogLevel().intValue(); + int logLevelvalue = ConfigManager.getProviderInstance().getServerLogLevel().intValue(); if (logLevelvalue <= INFO_INT) { showsetPopup.add(showInfo); showsetPopup.add(showError); diff --git a/designer_base/src/com/fr/design/mainframe/widget/accessibles/AccessibleDictionaryEditor.java b/designer_base/src/com/fr/design/mainframe/widget/accessibles/AccessibleDictionaryEditor.java index 735bbe002..c2195512a 100644 --- a/designer_base/src/com/fr/design/mainframe/widget/accessibles/AccessibleDictionaryEditor.java +++ b/designer_base/src/com/fr/design/mainframe/widget/accessibles/AccessibleDictionaryEditor.java @@ -1,14 +1,12 @@ package com.fr.design.mainframe.widget.accessibles; -import javax.swing.*; - import com.fr.data.Dictionary; -import com.fr.design.mainframe.widget.wrappers.DictionaryWrapper; -import com.fr.design.present.dict.DictionaryPane; import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.mainframe.widget.wrappers.DictionaryWrapper; +import com.fr.design.present.dict.DictionaryPane; -import java.awt.*; +import javax.swing.SwingUtilities; public class AccessibleDictionaryEditor extends UneditableAccessibleEditor { @@ -38,4 +36,26 @@ public class AccessibleDictionaryEditor extends UneditableAccessibleEditor { dictPane.populateBean((Dictionary) getValue()); dlg.setVisible(true); } + + + /** + * @param dictionary dictionary + * @deprecated 这个方法只用于兼容8.0下拉框类型控件的插件, + * 推荐使用{@link UneditableAccessibleEditor#setValue(java.lang.Object)} + */ + @Deprecated + public void populateBean(Dictionary dictionary) { + this.setValue(dictionary); + } + + + /** + * @return Dictionary dictionary + * @deprecated 这个方法只用于兼容8.0下拉框类型控件的插件, + * 推荐使用{@link UneditableAccessibleEditor#getValue()} + */ + @Deprecated + public Dictionary updateBean() { + return (Dictionary) this.getValue(); + } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/parameter/ParameterInputPane.java b/designer_base/src/com/fr/design/parameter/ParameterInputPane.java index 7e8203bcb..3f56be617 100644 --- a/designer_base/src/com/fr/design/parameter/ParameterInputPane.java +++ b/designer_base/src/com/fr/design/parameter/ParameterInputPane.java @@ -3,28 +3,10 @@ */ package com.fr.design.parameter; -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.util.ArrayList; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import javax.swing.BorderFactory; -import javax.swing.JComponent; - -import com.fr.base.Utils; -import com.fr.design.gui.ilable.UILabel; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.SwingConstants; - -import com.fr.base.Formula; +import com.fr.base.BaseFormula; import com.fr.base.StoreProcedureParameter; +import com.fr.base.Utils; import com.fr.data.impl.storeproc.StoreProcedureConstants; -import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.dialog.BasicPane; import com.fr.design.editor.ValueEditorPane; import com.fr.design.editor.ValueEditorPaneFactory; @@ -35,10 +17,21 @@ import com.fr.design.editor.editor.Editor; import com.fr.design.editor.editor.FloatEditor; import com.fr.design.editor.editor.IntegerEditor; import com.fr.design.editor.editor.TextEditor; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.layout.FRGUIPaneFactory; import com.fr.general.Inter; import com.fr.stable.ParameterProvider; import com.fr.stable.StringUtils; +import javax.swing.*; +import java.awt.*; +import java.util.ArrayList; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + /** * The dialog used to input parameter. * @editor zhou @@ -130,7 +123,7 @@ public class ParameterInputPane extends BasicPane { editors[0] = new DateEditor(true, Inter.getLocText("Date")); } else if (pv instanceof Boolean) { editors[0] = new BooleanEditor(); - } else if (pv instanceof Formula) { + } else if (pv instanceof BaseFormula) { editors = ValueEditorPaneFactory.basicEditors(); } else { editors[0] = new TextEditor(); diff --git a/designer_base/src/com/fr/design/present/dict/DatabaseDictPane.java b/designer_base/src/com/fr/design/present/dict/DatabaseDictPane.java index 5cd4e41ea..72def6f05 100644 --- a/designer_base/src/com/fr/design/present/dict/DatabaseDictPane.java +++ b/designer_base/src/com/fr/design/present/dict/DatabaseDictPane.java @@ -1,6 +1,6 @@ package com.fr.design.present.dict; -import com.fr.base.Formula; +import com.fr.base.BaseFormula; import com.fr.base.TableData; import com.fr.data.core.db.DBUtils; import com.fr.data.impl.DatabaseDictionary; @@ -205,7 +205,7 @@ public class DatabaseDictPane extends FurtherBasicBeanPane i dbDict.setValueColumnIndex(valueColumnIndex); dbDict.setValueColumnName(valueColumnName); } else { - dbDict.setFormula(((Formula) value)); + dbDict.setFormula(((BaseFormula) value)); } return dbDict; diff --git a/designer_base/src/com/fr/design/present/dict/FormulaDictPane.java b/designer_base/src/com/fr/design/present/dict/FormulaDictPane.java index 98a2c9986..1246d1845 100644 --- a/designer_base/src/com/fr/design/present/dict/FormulaDictPane.java +++ b/designer_base/src/com/fr/design/present/dict/FormulaDictPane.java @@ -1,118 +1,116 @@ -package com.fr.design.present.dict; - -import com.fr.base.BaseUtils; -import com.fr.base.Formula; -import com.fr.data.impl.FormulaDictionary; -import com.fr.design.beans.FurtherBasicBeanPane; -import com.fr.design.constants.LayoutConstants; -import com.fr.design.constants.UIConstants; -import com.fr.design.editor.editor.FormulaEditor; -import com.fr.design.gui.ilable.UILabel; -import com.fr.design.layout.TableLayout; -import com.fr.design.layout.TableLayoutHelper; -import com.fr.design.utils.gui.GUICoreUtils; -import com.fr.general.Inter; -import com.fr.stable.StringUtils; - -import javax.swing.*; -import javax.swing.event.DocumentListener; -import java.awt.*; - -public class FormulaDictPane extends FurtherBasicBeanPane { - - private static final int EDITOR_COLUMN = 15; - private static final int LEFT_BORDER = 5; - private FormulaEditor keyFormulaEditor; - private FormulaEditor valueFormulaEditor; - - public FormulaDictPane() { - initComponents(); - } - - private void initComponents() { - keyFormulaEditor = new FormulaEditor(); - keyFormulaEditor.setColumns(EDITOR_COLUMN); - JPanel keyFormulaContainer = new JPanel(new FlowLayout(FlowLayout.RIGHT, LEFT_BORDER, 0)); - keyFormulaContainer.setBorder(BorderFactory.createEmptyBorder(0, -LEFT_BORDER, 0, -LEFT_BORDER)); - keyFormulaEditor.setPreferredSize(new Dimension(144, 20)); - Icon icon = BaseUtils.readIcon("/com/fr/design/images/m_insert/formula.png"); - keyFormulaContainer.add(new JLabel(icon)); - keyFormulaContainer.add(keyFormulaEditor); - - valueFormulaEditor = new FormulaEditor(); - valueFormulaEditor.setColumns(EDITOR_COLUMN); - - double p = TableLayout.PREFERRED; - double f = TableLayout.FILL; - double[] columnSize = {p, f}; - double[] rowSize = {p, p, p}; - int[][] rowCount = {{1, 1}, {1, 1}, {1, 1}}; - - UILabel tag = new UILabel(Inter.getLocText("FR-Designer-Formula_Dictionary_Display_Examples_Html")); - tag.setForeground(new Color(143, 143, 146)); - tag.setPreferredSize(new Dimension(225, 80)); - JPanel t = new JPanel(new BorderLayout()); - t.add(tag, BorderLayout.CENTER); - - Formula vf = new Formula("$$$"); - valueFormulaEditor = new FormulaEditor(StringUtils.EMPTY, vf); - - JPanel valueFormulaContainer = new JPanel(new FlowLayout(FlowLayout.RIGHT, LEFT_BORDER, 0)); - valueFormulaContainer.setBorder(BorderFactory.createEmptyBorder(0, -LEFT_BORDER, 0, -LEFT_BORDER)); - valueFormulaEditor.setPreferredSize(new Dimension(144, 20)); - valueFormulaContainer.add(new JLabel(icon)); - valueFormulaContainer.add(valueFormulaEditor); - - - Component[][] components = new Component[][]{ - new Component[]{new UILabel(Inter.getLocText("FR-Designer_Actual_Value"), UILabel.LEFT), keyFormulaContainer}, - new Component[]{new UILabel(Inter.getLocText("FR-Designer_Display_Value"), UILabel.LEFT), valueFormulaContainer}, - new Component[]{tag, null} - }; - JPanel panel = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_LARGE, LayoutConstants.VGAP_LARGE); - - this.setLayout(new BorderLayout()); - this.add(panel, BorderLayout.CENTER); - - } - - public void addChangeListener(DocumentListener l) { - keyFormulaEditor.addDocumentListener(l); - valueFormulaEditor.addDocumentListener(l); - } - - @Override - public String title4PopupWindow() { - return Inter.getLocText("FR-Designer_Formula"); - } - - @Override - public void populateBean(FormulaDictionary dict) { - keyFormulaEditor.setValue(new Formula(dict.getProduceFormula() == null ? StringUtils.EMPTY : dict.getProduceFormula())); - valueFormulaEditor.setValue(new Formula(dict.getExcuteFormula() == null ? StringUtils.EMPTY : dict.getExcuteFormula())); - } - - @Override - public FormulaDictionary updateBean() { - FormulaDictionary dict = new FormulaDictionary(); - if (keyFormulaEditor.getValue() != null) { - dict.setProduceFormula(keyFormulaEditor.getValue().getContent()); - } - if (valueFormulaEditor.getValue() != null) { - dict.setExcuteFormula(valueFormulaEditor.getValue().getContent()); - } - - return dict; - } - - @Override - public boolean accept(Object ob) { - return ob instanceof FormulaDictionary; - } - - @Override - public void reset() { - keyFormulaEditor.reset(); - valueFormulaEditor.reset(); - } +package com.fr.design.present.dict; + +import com.fr.base.BaseFormula; +import com.fr.base.BaseUtils; +import com.fr.data.impl.FormulaDictionary; +import com.fr.design.beans.FurtherBasicBeanPane; +import com.fr.design.constants.LayoutConstants; +import com.fr.design.editor.editor.FormulaEditor; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.layout.TableLayout; +import com.fr.design.layout.TableLayoutHelper; +import com.fr.general.Inter; +import com.fr.stable.StringUtils; + +import javax.swing.*; +import javax.swing.event.DocumentListener; +import java.awt.*; + +public class FormulaDictPane extends FurtherBasicBeanPane { + + private static final int EDITOR_COLUMN = 15; + private static final int LEFT_BORDER = 5; + private FormulaEditor keyFormulaEditor; + private FormulaEditor valueFormulaEditor; + + public FormulaDictPane() { + initComponents(); + } + + private void initComponents() { + keyFormulaEditor = new FormulaEditor(); + keyFormulaEditor.setColumns(EDITOR_COLUMN); + JPanel keyFormulaContainer = new JPanel(new FlowLayout(FlowLayout.RIGHT, LEFT_BORDER, 0)); + keyFormulaContainer.setBorder(BorderFactory.createEmptyBorder(0, -LEFT_BORDER, 0, -LEFT_BORDER)); + keyFormulaEditor.setPreferredSize(new Dimension(144, 20)); + Icon icon = BaseUtils.readIcon("/com/fr/design/images/m_insert/formula.png"); + keyFormulaContainer.add(new JLabel(icon)); + keyFormulaContainer.add(keyFormulaEditor); + + valueFormulaEditor = new FormulaEditor(); + valueFormulaEditor.setColumns(EDITOR_COLUMN); + + double p = TableLayout.PREFERRED; + double f = TableLayout.FILL; + double[] columnSize = {p, f}; + double[] rowSize = {p, p, p}; + int[][] rowCount = {{1, 1}, {1, 1}, {1, 1}}; + + UILabel tag = new UILabel(Inter.getLocText("FR-Designer-Formula_Dictionary_Display_Examples_Html")); + tag.setForeground(new Color(143, 143, 146)); + tag.setPreferredSize(new Dimension(225, 80)); + JPanel t = new JPanel(new BorderLayout()); + t.add(tag, BorderLayout.CENTER); + + BaseFormula vf = BaseFormula.createFormulaBuilder().build("$$$"); + valueFormulaEditor = new FormulaEditor(StringUtils.EMPTY, vf); + + JPanel valueFormulaContainer = new JPanel(new FlowLayout(FlowLayout.RIGHT, LEFT_BORDER, 0)); + valueFormulaContainer.setBorder(BorderFactory.createEmptyBorder(0, -LEFT_BORDER, 0, -LEFT_BORDER)); + valueFormulaEditor.setPreferredSize(new Dimension(144, 20)); + valueFormulaContainer.add(new JLabel(icon)); + valueFormulaContainer.add(valueFormulaEditor); + + + Component[][] components = new Component[][]{ + new Component[]{new UILabel(Inter.getLocText("FR-Designer_Actual_Value"), UILabel.LEFT), keyFormulaContainer}, + new Component[]{new UILabel(Inter.getLocText("FR-Designer_Display_Value"), UILabel.LEFT), valueFormulaContainer}, + new Component[]{tag, null} + }; + JPanel panel = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_LARGE, LayoutConstants.VGAP_LARGE); + + this.setLayout(new BorderLayout()); + this.add(panel, BorderLayout.CENTER); + + } + + public void addChangeListener(DocumentListener l) { + keyFormulaEditor.addDocumentListener(l); + valueFormulaEditor.addDocumentListener(l); + } + + @Override + public String title4PopupWindow() { + return Inter.getLocText("FR-Designer_Formula"); + } + + @Override + public void populateBean(FormulaDictionary dict) { + keyFormulaEditor.setValue(BaseFormula.createFormulaBuilder().build(dict.getProduceFormula() == null ? StringUtils.EMPTY : dict.getProduceFormula())); + valueFormulaEditor.setValue(BaseFormula.createFormulaBuilder().build(dict.getExcuteFormula() == null ? StringUtils.EMPTY : dict.getExcuteFormula())); + } + + @Override + public FormulaDictionary updateBean() { + FormulaDictionary dict = new FormulaDictionary(); + if (keyFormulaEditor.getValue() != null) { + dict.setProduceFormula(keyFormulaEditor.getValue().getContent()); + } + if (valueFormulaEditor.getValue() != null) { + dict.setExcuteFormula(valueFormulaEditor.getValue().getContent()); + } + + return dict; + } + + @Override + public boolean accept(Object ob) { + return ob instanceof FormulaDictionary; + } + + @Override + public void reset() { + keyFormulaEditor.reset(); + valueFormulaEditor.reset(); + } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/present/dict/TableDataDictPane.java b/designer_base/src/com/fr/design/present/dict/TableDataDictPane.java index fd7c14da1..343de54d4 100644 --- a/designer_base/src/com/fr/design/present/dict/TableDataDictPane.java +++ b/designer_base/src/com/fr/design/present/dict/TableDataDictPane.java @@ -1,371 +1,371 @@ -package com.fr.design.present.dict; - -import com.fr.base.Formula; -import com.fr.base.TableData; -import com.fr.data.TableDataSource; -import com.fr.data.impl.DBTableData; -import com.fr.data.impl.DynamicSQLDict; -import com.fr.data.impl.NameTableData; -import com.fr.data.impl.TableDataDictionary; -import com.fr.design.DesignModelAdapter; -import com.fr.design.beans.FurtherBasicBeanPane; -import com.fr.design.constants.LayoutConstants; -import com.fr.design.constants.UIConstants; -import com.fr.design.data.DesignTableDataManager; -import com.fr.design.data.datapane.TableDataComboBox; -import com.fr.design.data.datapane.TableDataTreePane; -import com.fr.design.data.datapane.preview.PreviewLabel; -import com.fr.design.data.datapane.preview.PreviewLabel.Previewable; -import com.fr.design.data.tabledata.wrapper.TableDataWrapper; -import com.fr.design.data.tabledata.wrapper.TemplateTableDataWrapper; -import com.fr.design.editor.DoubleDeckValueEditorPane; -import com.fr.design.editor.editor.ColumnIndexEditor; -import com.fr.design.editor.editor.ColumnNameEditor; -import com.fr.design.editor.editor.Editor; -import com.fr.design.editor.editor.FormulaEditor; -import com.fr.design.event.UIObserver; -import com.fr.design.event.UIObserverListener; -import com.fr.design.gui.ilable.UILabel; -import com.fr.design.layout.TableLayout; -import com.fr.design.layout.TableLayoutHelper; -import com.fr.design.utils.gui.GUICoreUtils; -import com.fr.general.ComparatorUtils; -import com.fr.general.Inter; -import com.fr.stable.ArrayUtils; -import com.fr.stable.StringUtils; - -import javax.swing.*; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import java.awt.*; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.util.List; - -/** - * 数据字典的数据查询面板 - * - * @editor zhou - * @since 2012-3-29下午1:49:24 - */ -public class TableDataDictPane extends FurtherBasicBeanPane implements Previewable, UIObserver { - private static final int BEGIN = 1; - private static final int END = 10; - private static final int VGAP = 24; - private static final long serialVersionUID = -5469742115988153206L; - private static final int SELECTED_NO_TABLEDATA = -2; - public TableDataComboBox tableDataNameComboBox; - private DoubleDeckValueEditorPane keyColumnPane; - private DoubleDeckValueEditorPane valueDictPane; - private ItemListener itemListener; - private UIObserverListener uiObserverListener; - - public TableDataDictPane() { - initBasicComponets(); - initComponents(); - iniListener(); - } - - public static void main(String[] args) { - JFrame jf = new JFrame("test"); - jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - JPanel content = (JPanel) jf.getContentPane(); - content.setLayout(new BorderLayout()); - content.add(new TableDataDictPane(), BorderLayout.NORTH); - GUICoreUtils.centerWindow(jf); - jf.setSize(290, 400); - jf.setVisible(true); - } - - private void initBasicComponets() { - tableDataNameComboBox = new TableDataComboBox(DesignTableDataManager.getEditingTableDataSource()); - tableDataNameComboBox.addItemListener(new ItemListener() { - public void itemStateChanged(ItemEvent e) { - if (e.getStateChange() == ItemEvent.SELECTED) { - tdChange(e); - } - } - }); -// keyColumnPane = ValueEditorPaneFactory.createValueEditorPane(new Editor[]{new ColumnNameEditor(), new ColumnIndexEditor()}); - keyColumnPane = new DoubleDeckValueEditorPane(new Editor[]{new ColumnNameEditor(), new ColumnIndexEditor()}); - FormulaEditor formulaEditor = new FormulaEditor(Inter.getLocText("FR-Designer_Parameter-Formula")); - formulaEditor.setEnabled(true); -// valueDictPane = ValueEditorPaneFactory.createValueEditorPane(new Editor[]{new ColumnNameEditor(), new ColumnIndexEditor(), formulaEditor}); - valueDictPane = new DoubleDeckValueEditorPane(new Editor[]{new ColumnNameEditor(), new ColumnIndexEditor(), formulaEditor}); - } - - private void initComponents() { - - double p = TableLayout.PREFERRED; - double f = TableLayout.FILL; - double[] columnSize = {p, f}; - double[] rowSize = {p, p, p, p, p}; - int[][] rowCount = {{1, 1}, {1, 3}, {1, 3}}; - - JPanel firstLine = new JPanel(new BorderLayout(4, 0)); - firstLine.add(tableDataNameComboBox, BorderLayout.CENTER); - firstLine.add(new PreviewLabel(this), BorderLayout.EAST); - - Component[][] components = new Component[][]{ - new Component[]{new UILabel(Inter.getLocText("FR-Designer_DS_TableData") + " ", UILabel.LEFT), firstLine}, - new Component[]{new UILabel(Inter.getLocText("FR-Designer_Actual_Value") + " ", UILabel.LEFT), keyColumnPane}, - new Component[]{new UILabel(Inter.getLocText("FR-Designer_Display_Value") + " ", UILabel.LEFT), valueDictPane}, - }; - - JPanel panel = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, VGAP, LayoutConstants.VGAP_MEDIUM); - this.setLayout(new BorderLayout()); - this.add(panel, BorderLayout.CENTER); - } - - - private void iniListener() { - if (shouldResponseChangeListener()) { - this.addItemListener(new ItemListener() { - @Override - public void itemStateChanged(ItemEvent e) { - if (uiObserverListener == null) { - return; - } - if (e.getStateChange() == ItemEvent.SELECTED) { - uiObserverListener.doChange(); - } - } - }); - } - } - - /** - * 增加Listener - * - * @param aListener 将本对象的Listener指向该listener - */ - public void addItemListener(ItemListener aListener) { - this.itemListener = aListener; - } - - /** - * 该面板标题 - * - * @return 返回是窗口显示的标题 - */ - public String title4PopupWindow() { - return Inter.getLocText("FR-Designer_Dic_Data_Query"); - } - - private void tdChange(final ItemEvent e) { - TableDataWrapper tableDataWrappe = this.tableDataNameComboBox.getSelectedItem(); - if (tableDataWrappe == null) { - return; - } - - List namelist = tableDataWrappe.calculateColumnNameList(); - String[] columnNames = null; - if (!namelist.isEmpty()) { - columnNames = namelist.toArray(ArrayUtils.EMPTY_STRING_ARRAY); - } else { - columnNames = new String[]{""}; - } - ColumnNameEditor columnNameEditor1 = new ColumnNameEditor(columnNames); - columnNameEditor1.addItemListener(itemListener); - ColumnIndexEditor columnIndexEditor1 = new ColumnIndexEditor(columnNames.length); - columnIndexEditor1.addItemListener(itemListener); - keyColumnPane.setEditors(new Editor[]{columnNameEditor1, columnIndexEditor1}, columnNames[0]); - - FormulaEditor formulaEditor = new FormulaEditor(Inter.getLocText("FR-Designer_Parameter-Formula")); - formulaEditor.setEnabled(true); - formulaEditor.addChangeListener(new ChangeListener() { - - @Override - public void stateChanged(ChangeEvent ee) { - if (itemListener != null) { - itemListener.itemStateChanged(e); - } - } - }); - ColumnNameEditor columnNameEditor2 = new ColumnNameEditor(columnNames); - columnNameEditor2.addItemListener(itemListener); - ColumnIndexEditor columnIndexEditor2 = new ColumnIndexEditor(columnNames.length); - columnIndexEditor2.addItemListener(itemListener); - valueDictPane.setEditors(new Editor[]{columnNameEditor2, columnIndexEditor2, formulaEditor}, columnNames[0]); - if (itemListener != null) { - itemListener.itemStateChanged(e); - } - } - - @Override - /** - * - */ - public void populateBean(TableDataDictionary tableDataDict) { - populate(tableDataDict, ""); - } - - private void populate(TableDataDictionary tableDataDict, String name) { - if (tableDataDict == null || tableDataDict.getTableData() == TableData.EMPTY_TABLEDATA) { - this.tableDataNameComboBox.setSelectedIndex(-1); - this.keyColumnPane.populate(StringUtils.EMPTY); - this.valueDictPane.populate(StringUtils.EMPTY); - return; - } - if (tableDataDict.getTableData() instanceof DBTableData && !"".equals(name)) { - this.tableDataNameComboBox.putTableDataIntoMap(name, new TemplateTableDataWrapper( - (DBTableData) tableDataDict.getTableData(), name)); - this.tableDataNameComboBox.setSelectedTableDataByName(name); - } else if (tableDataDict.getTableData() instanceof NameTableData) { - this.tableDataNameComboBox.setSelectedTableDataByName(((NameTableData) tableDataDict.getTableData()) - .getName()); - } - // alex:因为显示到界面上的index是以1为始的,所以要加1 - - TableDataWrapper tableDataWrappe = this.tableDataNameComboBox.getSelectedItem(); - if (tableDataWrappe == null) { - keyColumnPane.resetComponets(); - valueDictPane.resetComponets(); - } else { - if (StringUtils.isNotEmpty(tableDataDict.getKeyColumnName())) { - this.keyColumnPane.populate(tableDataDict.getKeyColumnName()); - } else { - this.keyColumnPane.populate(tableDataDict.getKeyColumnIndex() + 1); - } - - Object value = null; - if (tableDataDict.getFormula() != null) { - value = tableDataDict.getFormula(); - } else { - if (StringUtils.isNotEmpty(tableDataDict.getValueColumnName())) { - value = tableDataDict.getValueColumnName(); - } else { - value = tableDataDict.getValueColumnIndex() + 1; - } - } - - this.valueDictPane.populate(value); - } - } - - /** - * @param dsql - */ - public void populateBean(DynamicSQLDict dsql) { - DBTableData db = new DBTableData(dsql.getDatabaseConnection(), dsql.getSqlFormula()); - String name = ""; - TableDataSource dataSource = DesignTableDataManager.getEditingTableDataSource(); - if (dataSource != null) { - for (int i = BEGIN; i < END; i++) { - TableData td = dataSource.getTableData(Inter.getLocText("FR-Designer_Dictionary_Dynamic_SQL") + i); - if (td == null) { - name = Inter.getLocText("FR-Designer_Dictionary_Dynamic_SQL") + i; - dataSource.putTableData(Inter.getLocText("FR-Designer_Dictionary_Dynamic_SQL") + i, db); - break; - } else { - if (ComparatorUtils.equals(td, db)) { - name = Inter.getLocText("FR-Designer_Dictionary_Dynamic_SQL") + i; - break; - } else { - continue; - } - } - } - } - - TableDataDictionary tdd = new TableDataDictionary(db, dsql.getKeyColumnIndex(), dsql.getValueColumnIndex()); - if (dsql.getFormula() != null) { - tdd.setFormula(dsql.getFormula()); - } - this.populate(tdd, name); - TableDataTreePane.getInstance(DesignModelAdapter.getCurrentModelAdapter()); - } - - /** - * @return - */ - public TableDataDictionary updateBean() { - TableDataDictionary tableDataDict = new TableDataDictionary(); - Object object = this.valueDictPane.update(); - // alex:因为显示到界面上的index是以1为始的,所以要减1 - // carl:假如这里的序号要变,请考虑6.2的兼容 - if (object instanceof Integer) { - int valuleColumnIndex = (Integer) object - 1; - String valueColumnName = StringUtils.EMPTY; - - if (this.valueDictPane.getCurrentEditor() instanceof ColumnNameEditor) { - valueColumnName = ((ColumnNameEditor) this.valueDictPane.getCurrentEditor()).getColumnName(); - valuleColumnIndex = -1; - } - tableDataDict.setValueColumnIndex(valuleColumnIndex); - tableDataDict.setValueColumnName(valueColumnName); - } else { - tableDataDict.setFormula(((Formula) object)); - } - TableDataWrapper tableDataWrappe = this.tableDataNameComboBox.getSelectedItem(); - if (tableDataWrappe != null) { - tableDataDict.setTableData(new NameTableData(tableDataWrappe.getTableDataName())); - int keyColumnIndex = (Integer) this.keyColumnPane.update() - 1; - String keyColumnName = StringUtils.EMPTY; - - if (keyColumnPane.getCurrentEditor() instanceof ColumnNameEditor) { - keyColumnName = ((ColumnNameEditor) this.keyColumnPane.getCurrentEditor()).getColumnName(); - keyColumnIndex = -1; - } - - tableDataDict.setKeyColumnIndex(keyColumnIndex); - tableDataDict.setKeyColumnName(keyColumnName); - } - - return tableDataDict; - } - - /** - * 预览 - */ - public void preview() { - TableDataWrapper tableDataWrappe = tableDataNameComboBox.getSelectedItem(); - if (tableDataWrappe == null) { - return; - } - Object object = this.valueDictPane.update(); - if (object instanceof Integer) { - tableDataWrappe.previewData((Integer) this.keyColumnPane.update() - 1, (Integer) object - 1); - } - - } - - /** - * 判断ob是否是TableDataDictionary类型 - * - * @param ob 用于判断的Object - * @return 如果是TableDataDictionary类型,则返回true - */ - public boolean accept(Object ob) { - return ob instanceof TableDataDictionary; - } - - @Override - /** - *重置 - */ - public void reset() { - GUICoreUtils.setSelectedItemQuietly(tableDataNameComboBox, UIConstants.PENDING); - keyColumnPane.clearComponentsData(); - valueDictPane.clearComponentsData(); - } - - - /** - * 给组件登记一个观察者监听事件 - * - * @param listener 观察者监听事件 - */ - public void registerChangeListener(UIObserverListener listener) { - uiObserverListener = listener; - } - - /** - * 是否应该相应listener事件 - * - * @return 要是响应listener事件,则返回true - */ - public boolean shouldResponseChangeListener() { - return true; - } +package com.fr.design.present.dict; + +import com.fr.base.BaseFormula; +import com.fr.base.TableData; +import com.fr.data.TableDataSource; +import com.fr.data.impl.DBTableData; +import com.fr.data.impl.DynamicSQLDict; +import com.fr.data.impl.NameTableData; +import com.fr.data.impl.TableDataDictionary; +import com.fr.design.DesignModelAdapter; +import com.fr.design.beans.FurtherBasicBeanPane; +import com.fr.design.constants.LayoutConstants; +import com.fr.design.constants.UIConstants; +import com.fr.design.data.DesignTableDataManager; +import com.fr.design.data.datapane.TableDataComboBox; +import com.fr.design.data.datapane.TableDataTreePane; +import com.fr.design.data.datapane.preview.PreviewLabel; +import com.fr.design.data.datapane.preview.PreviewLabel.Previewable; +import com.fr.design.data.tabledata.wrapper.TableDataWrapper; +import com.fr.design.data.tabledata.wrapper.TemplateTableDataWrapper; +import com.fr.design.editor.DoubleDeckValueEditorPane; +import com.fr.design.editor.editor.ColumnIndexEditor; +import com.fr.design.editor.editor.ColumnNameEditor; +import com.fr.design.editor.editor.Editor; +import com.fr.design.editor.editor.FormulaEditor; +import com.fr.design.event.UIObserver; +import com.fr.design.event.UIObserverListener; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.layout.TableLayout; +import com.fr.design.layout.TableLayoutHelper; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.general.ComparatorUtils; +import com.fr.general.Inter; +import com.fr.stable.ArrayUtils; +import com.fr.stable.StringUtils; + +import javax.swing.*; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import java.awt.*; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.List; + +/** + * 数据字典的数据查询面板 + * + * @editor zhou + * @since 2012-3-29下午1:49:24 + */ +public class TableDataDictPane extends FurtherBasicBeanPane implements Previewable, UIObserver { + private static final int BEGIN = 1; + private static final int END = 10; + private static final int VGAP = 24; + private static final long serialVersionUID = -5469742115988153206L; + private static final int SELECTED_NO_TABLEDATA = -2; + public TableDataComboBox tableDataNameComboBox; + private DoubleDeckValueEditorPane keyColumnPane; + private DoubleDeckValueEditorPane valueDictPane; + private ItemListener itemListener; + private UIObserverListener uiObserverListener; + + public TableDataDictPane() { + initBasicComponets(); + initComponents(); + iniListener(); + } + + public static void main(String[] args) { + JFrame jf = new JFrame("test"); + jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + JPanel content = (JPanel) jf.getContentPane(); + content.setLayout(new BorderLayout()); + content.add(new TableDataDictPane(), BorderLayout.NORTH); + GUICoreUtils.centerWindow(jf); + jf.setSize(290, 400); + jf.setVisible(true); + } + + private void initBasicComponets() { + tableDataNameComboBox = new TableDataComboBox(DesignTableDataManager.getEditingTableDataSource()); + tableDataNameComboBox.addItemListener(new ItemListener() { + public void itemStateChanged(ItemEvent e) { + if (e.getStateChange() == ItemEvent.SELECTED) { + tdChange(e); + } + } + }); +// keyColumnPane = ValueEditorPaneFactory.createValueEditorPane(new Editor[]{new ColumnNameEditor(), new ColumnIndexEditor()}); + keyColumnPane = new DoubleDeckValueEditorPane(new Editor[]{new ColumnNameEditor(), new ColumnIndexEditor()}); + FormulaEditor formulaEditor = new FormulaEditor(Inter.getLocText("FR-Designer_Parameter-Formula")); + formulaEditor.setEnabled(true); +// valueDictPane = ValueEditorPaneFactory.createValueEditorPane(new Editor[]{new ColumnNameEditor(), new ColumnIndexEditor(), formulaEditor}); + valueDictPane = new DoubleDeckValueEditorPane(new Editor[]{new ColumnNameEditor(), new ColumnIndexEditor(), formulaEditor}); + } + + private void initComponents() { + + double p = TableLayout.PREFERRED; + double f = TableLayout.FILL; + double[] columnSize = {p, f}; + double[] rowSize = {p, p, p, p, p}; + int[][] rowCount = {{1, 1}, {1, 3}, {1, 3}}; + + JPanel firstLine = new JPanel(new BorderLayout(4, 0)); + firstLine.add(tableDataNameComboBox, BorderLayout.CENTER); + firstLine.add(new PreviewLabel(this), BorderLayout.EAST); + + Component[][] components = new Component[][]{ + new Component[]{new UILabel(Inter.getLocText("FR-Designer_DS_TableData") + " ", UILabel.LEFT), firstLine}, + new Component[]{new UILabel(Inter.getLocText("FR-Designer_Actual_Value") + " ", UILabel.LEFT), keyColumnPane}, + new Component[]{new UILabel(Inter.getLocText("FR-Designer_Display_Value") + " ", UILabel.LEFT), valueDictPane}, + }; + + JPanel panel = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, VGAP, LayoutConstants.VGAP_MEDIUM); + this.setLayout(new BorderLayout()); + this.add(panel, BorderLayout.CENTER); + } + + + private void iniListener() { + if (shouldResponseChangeListener()) { + this.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + if (uiObserverListener == null) { + return; + } + if (e.getStateChange() == ItemEvent.SELECTED) { + uiObserverListener.doChange(); + } + } + }); + } + } + + /** + * 增加Listener + * + * @param aListener 将本对象的Listener指向该listener + */ + public void addItemListener(ItemListener aListener) { + this.itemListener = aListener; + } + + /** + * 该面板标题 + * + * @return 返回是窗口显示的标题 + */ + public String title4PopupWindow() { + return Inter.getLocText("FR-Designer_Dic_Data_Query"); + } + + private void tdChange(final ItemEvent e) { + TableDataWrapper tableDataWrappe = this.tableDataNameComboBox.getSelectedItem(); + if (tableDataWrappe == null) { + return; + } + + List namelist = tableDataWrappe.calculateColumnNameList(); + String[] columnNames = null; + if (!namelist.isEmpty()) { + columnNames = namelist.toArray(ArrayUtils.EMPTY_STRING_ARRAY); + } else { + columnNames = new String[]{""}; + } + ColumnNameEditor columnNameEditor1 = new ColumnNameEditor(columnNames); + columnNameEditor1.addItemListener(itemListener); + ColumnIndexEditor columnIndexEditor1 = new ColumnIndexEditor(columnNames.length); + columnIndexEditor1.addItemListener(itemListener); + keyColumnPane.setEditors(new Editor[]{columnNameEditor1, columnIndexEditor1}, columnNames[0]); + + FormulaEditor formulaEditor = new FormulaEditor(Inter.getLocText("FR-Designer_Parameter-Formula")); + formulaEditor.setEnabled(true); + formulaEditor.addChangeListener(new ChangeListener() { + + @Override + public void stateChanged(ChangeEvent ee) { + if (itemListener != null) { + itemListener.itemStateChanged(e); + } + } + }); + ColumnNameEditor columnNameEditor2 = new ColumnNameEditor(columnNames); + columnNameEditor2.addItemListener(itemListener); + ColumnIndexEditor columnIndexEditor2 = new ColumnIndexEditor(columnNames.length); + columnIndexEditor2.addItemListener(itemListener); + valueDictPane.setEditors(new Editor[]{columnNameEditor2, columnIndexEditor2, formulaEditor}, columnNames[0]); + if (itemListener != null) { + itemListener.itemStateChanged(e); + } + } + + @Override + /** + * + */ + public void populateBean(TableDataDictionary tableDataDict) { + populate(tableDataDict, ""); + } + + private void populate(TableDataDictionary tableDataDict, String name) { + if (tableDataDict == null || tableDataDict.getTableData() == TableData.EMPTY_TABLEDATA) { + this.tableDataNameComboBox.setSelectedIndex(-1); + this.keyColumnPane.populate(StringUtils.EMPTY); + this.valueDictPane.populate(StringUtils.EMPTY); + return; + } + if (tableDataDict.getTableData() instanceof DBTableData && !"".equals(name)) { + this.tableDataNameComboBox.putTableDataIntoMap(name, new TemplateTableDataWrapper( + (DBTableData) tableDataDict.getTableData(), name)); + this.tableDataNameComboBox.setSelectedTableDataByName(name); + } else if (tableDataDict.getTableData() instanceof NameTableData) { + this.tableDataNameComboBox.setSelectedTableDataByName(((NameTableData) tableDataDict.getTableData()) + .getName()); + } + // alex:因为显示到界面上的index是以1为始的,所以要加1 + + TableDataWrapper tableDataWrappe = this.tableDataNameComboBox.getSelectedItem(); + if (tableDataWrappe == null) { + keyColumnPane.resetComponets(); + valueDictPane.resetComponets(); + } else { + if (StringUtils.isNotEmpty(tableDataDict.getKeyColumnName())) { + this.keyColumnPane.populate(tableDataDict.getKeyColumnName()); + } else { + this.keyColumnPane.populate(tableDataDict.getKeyColumnIndex() + 1); + } + + Object value = null; + if (tableDataDict.getFormula() != null) { + value = tableDataDict.getFormula(); + } else { + if (StringUtils.isNotEmpty(tableDataDict.getValueColumnName())) { + value = tableDataDict.getValueColumnName(); + } else { + value = tableDataDict.getValueColumnIndex() + 1; + } + } + + this.valueDictPane.populate(value); + } + } + + /** + * @param dsql + */ + public void populateBean(DynamicSQLDict dsql) { + DBTableData db = new DBTableData(dsql.getDatabaseConnection(), dsql.getSqlFormula()); + String name = ""; + TableDataSource dataSource = DesignTableDataManager.getEditingTableDataSource(); + if (dataSource != null) { + for (int i = BEGIN; i < END; i++) { + TableData td = dataSource.getTableData(Inter.getLocText("FR-Designer_Dictionary_Dynamic_SQL") + i); + if (td == null) { + name = Inter.getLocText("FR-Designer_Dictionary_Dynamic_SQL") + i; + dataSource.putTableData(Inter.getLocText("FR-Designer_Dictionary_Dynamic_SQL") + i, db); + break; + } else { + if (ComparatorUtils.equals(td, db)) { + name = Inter.getLocText("FR-Designer_Dictionary_Dynamic_SQL") + i; + break; + } else { + continue; + } + } + } + } + + TableDataDictionary tdd = new TableDataDictionary(db, dsql.getKeyColumnIndex(), dsql.getValueColumnIndex()); + if (dsql.getFormula() != null) { + tdd.setFormula(dsql.getFormula()); + } + this.populate(tdd, name); + TableDataTreePane.getInstance(DesignModelAdapter.getCurrentModelAdapter()); + } + + /** + * @return + */ + public TableDataDictionary updateBean() { + TableDataDictionary tableDataDict = new TableDataDictionary(); + Object object = this.valueDictPane.update(); + // alex:因为显示到界面上的index是以1为始的,所以要减1 + // carl:假如这里的序号要变,请考虑6.2的兼容 + if (object instanceof Integer) { + int valuleColumnIndex = (Integer) object - 1; + String valueColumnName = StringUtils.EMPTY; + + if (this.valueDictPane.getCurrentEditor() instanceof ColumnNameEditor) { + valueColumnName = ((ColumnNameEditor) this.valueDictPane.getCurrentEditor()).getColumnName(); + valuleColumnIndex = -1; + } + tableDataDict.setValueColumnIndex(valuleColumnIndex); + tableDataDict.setValueColumnName(valueColumnName); + } else { + tableDataDict.setFormula(((BaseFormula) object)); + } + TableDataWrapper tableDataWrappe = this.tableDataNameComboBox.getSelectedItem(); + if (tableDataWrappe != null) { + tableDataDict.setTableData(new NameTableData(tableDataWrappe.getTableDataName())); + int keyColumnIndex = (Integer) this.keyColumnPane.update() - 1; + String keyColumnName = StringUtils.EMPTY; + + if (keyColumnPane.getCurrentEditor() instanceof ColumnNameEditor) { + keyColumnName = ((ColumnNameEditor) this.keyColumnPane.getCurrentEditor()).getColumnName(); + keyColumnIndex = -1; + } + + tableDataDict.setKeyColumnIndex(keyColumnIndex); + tableDataDict.setKeyColumnName(keyColumnName); + } + + return tableDataDict; + } + + /** + * 预览 + */ + public void preview() { + TableDataWrapper tableDataWrappe = tableDataNameComboBox.getSelectedItem(); + if (tableDataWrappe == null) { + return; + } + Object object = this.valueDictPane.update(); + if (object instanceof Integer) { + tableDataWrappe.previewData((Integer) this.keyColumnPane.update() - 1, (Integer) object - 1); + } + + } + + /** + * 判断ob是否是TableDataDictionary类型 + * + * @param ob 用于判断的Object + * @return 如果是TableDataDictionary类型,则返回true + */ + public boolean accept(Object ob) { + return ob instanceof TableDataDictionary; + } + + @Override + /** + *重置 + */ + public void reset() { + GUICoreUtils.setSelectedItemQuietly(tableDataNameComboBox, UIConstants.PENDING); + keyColumnPane.clearComponentsData(); + valueDictPane.clearComponentsData(); + } + + + /** + * 给组件登记一个观察者监听事件 + * + * @param listener 观察者监听事件 + */ + public void registerChangeListener(UIObserverListener listener) { + uiObserverListener = listener; + } + + /** + * 是否应该相应listener事件 + * + * @return 要是响应listener事件,则返回true + */ + public boolean shouldResponseChangeListener() { + return true; + } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/widget/component/DateValuePane.java b/designer_base/src/com/fr/design/widget/component/DateValuePane.java index b6f59ec6e..e96e885b9 100644 --- a/designer_base/src/com/fr/design/widget/component/DateValuePane.java +++ b/designer_base/src/com/fr/design/widget/component/DateValuePane.java @@ -1,12 +1,15 @@ package com.fr.design.widget.component; -import com.fr.base.Formula; +import com.fr.base.BaseFormula; import com.fr.design.constants.LayoutConstants; -import com.fr.design.editor.editor.*; +import com.fr.design.editor.editor.DateEditor; +import com.fr.design.editor.editor.Editor; +import com.fr.design.editor.editor.FormulaEditor; +import com.fr.design.editor.editor.NoneEditor; import com.fr.design.gui.ibutton.UIButtonGroup; import com.fr.general.ComparatorUtils; import com.fr.general.Inter; -import com.fr.stable.StringUtils; + import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; @@ -61,7 +64,7 @@ public class DateValuePane extends JPanel { Editor e = editor[index]; Object value = e.getValue(); if(value == null && ComparatorUtils.equals(FORMULA_EDITOR_NAME, e.getName())){ - value = new Formula(StringUtils.EMPTY); + value = BaseFormula.createFormulaBuilder().build(); } return value; } diff --git a/designer_base/src/com/fr/design/widget/component/NumberEditorValidatePane.java b/designer_base/src/com/fr/design/widget/component/NumberEditorValidatePane.java index 68ca5ae1e..bc2612aa6 100644 --- a/designer_base/src/com/fr/design/widget/component/NumberEditorValidatePane.java +++ b/designer_base/src/com/fr/design/widget/component/NumberEditorValidatePane.java @@ -254,11 +254,12 @@ public class NumberEditorValidatePane extends JPanel { minValueSpinner.setEnabled(true); minValueSpinner.setValue(new Double(e.getMinValue())); } - errorMsgTextField.setText(e.getRegErrorMessage()); - if(e.getMaxValue() == Double.MAX_VALUE || e.getMinValue() == -Double.MAX_VALUE){ + if(setMinValueCheckBox.isSelected() || setMaxValueCheckBox.isSelected()){ errorMsgTextFieldPane.setVisible(true); + errorMsgTextField.setText(e.getRegErrorMessage()); }else{ errorMsgTextFieldPane.setVisible(false); + errorMsgTextField.setText(StringUtils.EMPTY); } } diff --git a/designer_base/src/com/fr/design/write/submit/DBManipulationPane.java b/designer_base/src/com/fr/design/write/submit/DBManipulationPane.java index 23eb50f85..dc0083051 100644 --- a/designer_base/src/com/fr/design/write/submit/DBManipulationPane.java +++ b/designer_base/src/com/fr/design/write/submit/DBManipulationPane.java @@ -1,46 +1,7 @@ package com.fr.design.write.submit; -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.FlowLayout; -import java.awt.GridLayout; -import java.awt.Image; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.FocusAdapter; -import java.awt.event.FocusEvent; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.ArrayList; -import java.util.Date; -import java.util.EventObject; -import java.util.List; - -import javax.swing.AbstractCellEditor; -import javax.swing.BorderFactory; -import javax.swing.DefaultCellEditor; -import javax.swing.DefaultComboBoxModel; -import javax.swing.Icon; -import javax.swing.JList; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.JTree; -import javax.swing.ListSelectionModel; -import javax.swing.SwingUtilities; -import javax.swing.table.AbstractTableModel; -import javax.swing.table.DefaultTableCellRenderer; -import javax.swing.table.TableCellEditor; -import javax.swing.table.TableColumn; -import javax.swing.tree.DefaultTreeCellRenderer; -import javax.swing.tree.DefaultTreeModel; - +import com.fr.base.BaseFormula; import com.fr.base.BaseUtils; -import com.fr.base.Formula; import com.fr.base.Parameter; import com.fr.data.DataConstants; import com.fr.data.condition.JoinCondition; @@ -86,6 +47,27 @@ import com.fr.write.config.InsertConfig; import com.fr.write.config.IntelliDMLConfig; import com.fr.write.config.UpdateConfig; +import javax.swing.*; +import javax.swing.table.AbstractTableModel; +import javax.swing.table.DefaultTableCellRenderer; +import javax.swing.table.TableCellEditor; +import javax.swing.table.TableColumn; +import javax.swing.tree.DefaultTreeCellRenderer; +import javax.swing.tree.DefaultTreeModel; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.ArrayList; +import java.util.Date; +import java.util.EventObject; +import java.util.List; + //august:这个东西应该分成两类,一类是有单元格的情况,一类是没有单元格的情况 public class DBManipulationPane extends BasicBeanPane { private static final Image ICODS_IMAGE = BaseUtils.readImage("/com/fr/web/core/css/images/icons.png"); @@ -752,7 +734,7 @@ public class DBManipulationPane extends BasicBeanPane { String columnName = column.getColumnName(); if (!acceptPara && column.getColumnValue() instanceof Parameter) { // 表单中,将以前的参数转换为公式 - column.setColumnValue(new Formula(((Parameter)column.getColumnValue()).getName())); + column.setColumnValue(BaseFormula.createFormulaBuilder().build(((Parameter)column.getColumnValue()).getName())); } KeyColumnNameValue newColumnNameValue = new KeyColumnNameValue(column.isKey(), new ColumnName(columnName), new ColumnValue(column.getColumnValue()), diff --git a/designer_base/src/com/fr/start/BaseDesigner.java b/designer_base/src/com/fr/start/BaseDesigner.java index d299a8cdd..47e53bd72 100644 --- a/designer_base/src/com/fr/start/BaseDesigner.java +++ b/designer_base/src/com/fr/start/BaseDesigner.java @@ -62,16 +62,17 @@ public abstract class BaseDesigner extends ToolBarMenuDock { private Timer timer; public BaseDesigner(String[] args) { - + + init(args); + } + + private void init(String[] args) { + RestartHelper.deleteRecordFilesWhenStart(); ConfigManagerFactory.registerConfigManagerProxy(new ConfigManagerCreatorProxy()); //启动core BuildContext.setBuildFilePath(buildPropertiesPath()); - Register.load(); - //标记一下是设计器启动 - PluginConversionModule.getInstance().markDesignerStart(); - SiteCenter.getInstance(); - + if (isDebug()) { setDebugEnv(); } else { @@ -82,13 +83,18 @@ public abstract class BaseDesigner extends ToolBarMenuDock { DesignUtils.clientSend(args); return; } - + + Register.load(); + //标记一下是设计器启动 + PluginConversionModule.getInstance().markDesignerStart(); + SiteCenter.getInstance(); + //下面这两句的位置不能随便调换,因为会影响语言切换的问题 initLanguage(); - + // 在 initLanguage 之后加载设计器国际化文件,确保是正确的语言环境 Inter.loadLocaleFile(GeneralContext.getLocale(), DesignModule.LOCALE_FILE_PATH); - + SplashWindow splashWindow = new SplashWindow(createSplashPane()); if (args != null) { for (String arg : args) { @@ -99,43 +105,47 @@ public abstract class BaseDesigner extends ToolBarMenuDock { } } } - + initLookAndFeel(args, splashWindow); + } + + private void initLookAndFeel(String[] args, SplashWindow splashWindow) { + // 初始化look and feel.这个在预加载之前执行是因为lookAndFeel里的东西,预加载时也要用到 DesignUtils.initLookAndFeel(); - + DesignUtils.creatListeningServer(getStartPort(), startFileSuffix()); - + // 初始化Log Handler DesignerEnvManager.loadLogSetting(); DesignerFrame df = createDesignerFrame(); - + // 默认加载工作目录,用于读取License switch2LastEnv(); - + initDefaultFont(); //PluginManager要在环境切换和模块启动之前初始化 PluginManager.registerEnvListener(); // 必须先初始化Env再去startModule, 不然会导致lic读取不到 ModuleContext.startModule(module2Start()); - + // 再次加载工作目录,用于读取工作目录下的各种插件 switch2LastEnv(); - + ModuleContext.clearModuleListener(); collectUserInformation(); showDesignerFrame(args, df, false); for (int i = 0; !TemplateTreePane.getInstance().getTemplateFileTree().isTemplateShowing() && i < LOAD_TREE_MAXNUM; i++) { TemplateTreePane.getInstance().getTemplateFileTree().refresh(); } - + splashWindow.setVisible(false); splashWindow.dispose(); - + bindGlobalListener(); - + showErrorPluginsMessage(); } - + private void bindGlobalListener() { GlobalListenerProviderManager.getInstance().init(); @@ -199,7 +209,8 @@ public abstract class BaseDesigner extends ToolBarMenuDock { //在VM options里加入-Ddebug=true激活 private boolean isDebug() { - return "true".equals(System.getProperty("debug")); + + return ComparatorUtils.equals("true", System.getProperty("debug")); } private static final int DEBUG_PORT = 51463; @@ -250,32 +261,7 @@ public abstract class BaseDesigner extends ToolBarMenuDock { file = FILEFactory.createFILE(FILEFactory.ENV_PREFIX + DesignerEnvManager.getEnvManager().getLastOpenFile()); } - - //启动时打开指定文件的接口 - DesignerStartOpenFileProcessor processor = ExtraDesignClassManager.getInstance().getSingle(DesignerStartOpenFileProcessor.XML_TAG); - if (processor != null) { - FILE f = processor.fileToShow(); - if (f != null) { - file = f;//避免null - } else { - isException = true;//此时有文件nullpointer异常,执行打开空文件 - } - } - if (file.exists() && !isException) { - df.openTemplate(file); - } else { - df.addAndActivateJTemplate(); - MutilTempalteTabPane.getInstance().setTemTemplate(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()); - } - if (OperatingSystem.isMacOS()) { - enableFullScreenMode(df); - } - df.addWindowListener(new WindowAdapter() { - public void windowOpened(WindowEvent e) { - df.getSelectedJTemplate().requestGridFocus(); - } - }); - df.setVisible(true); + isException = openFile(df, isException, file); } catch (Exception e) { FRLogger.getLogger().error(e.getMessage(), e); if (!isException) { @@ -285,8 +271,38 @@ public abstract class BaseDesigner extends ToolBarMenuDock { } } } - - + + private boolean openFile(final DesignerFrame df, boolean isException, FILE file) { + + //启动时打开指定文件的接口 + DesignerStartOpenFileProcessor processor = ExtraDesignClassManager.getInstance().getSingle(DesignerStartOpenFileProcessor.XML_TAG); + if (processor != null) { + FILE f = processor.fileToShow(); + if (f != null) { + file = f;//避免null + } else { + isException = true;//此时有文件nullpointer异常,执行打开空文件 + } + } + if (file.exists() && !isException) { + df.openTemplate(file); + } else { + df.addAndActivateJTemplate(); + MutilTempalteTabPane.getInstance().setTemTemplate(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()); + } + if (OperatingSystem.isMacOS()) { + enableFullScreenMode(df); + } + df.addWindowListener(new WindowAdapter() { + public void windowOpened(WindowEvent e) { + df.getSelectedJTemplate().requestGridFocus(); + } + }); + df.setVisible(true); + return isException; + } + + /** * @param window */ diff --git a/designer_chart/src/com/fr/design/chart/ChartSwingUtils.java b/designer_chart/src/com/fr/design/chart/ChartSwingUtils.java index 0f60814cc..0a7ebd583 100644 --- a/designer_chart/src/com/fr/design/chart/ChartSwingUtils.java +++ b/designer_chart/src/com/fr/design/chart/ChartSwingUtils.java @@ -1,6 +1,6 @@ package com.fr.design.chart; -import com.fr.base.Formula; +import com.fr.base.BaseFormula; import com.fr.base.Utils; import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.formula.FormulaFactory; @@ -58,10 +58,10 @@ public class ChartSwingUtils { private static void showFormulaPane(final UITextField jTextField, final OKListener l) { final UIFormula formulaPane = FormulaFactory.createFormulaPane(); - formulaPane.populate(new Formula(jTextField.getText())); + formulaPane.populate(BaseFormula.createFormulaBuilder().build(jTextField.getText())); formulaPane.showLargeWindow(SwingUtilities.getWindowAncestor(FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane()), new DialogActionAdapter(){ public void doOk() { - Formula formula = formulaPane.update(); + BaseFormula formula = formulaPane.update(); jTextField.setText(Utils.objectToString(formula)); if (l != null) { l.action(); diff --git a/designer_chart/src/com/fr/design/chart/axis/ChartAlertValuePane.java b/designer_chart/src/com/fr/design/chart/axis/ChartAlertValuePane.java index c38d2eb73..a9dbf91a8 100644 --- a/designer_chart/src/com/fr/design/chart/axis/ChartAlertValuePane.java +++ b/designer_chart/src/com/fr/design/chart/axis/ChartAlertValuePane.java @@ -1,6 +1,6 @@ package com.fr.design.chart.axis; -import com.fr.base.Formula; +import com.fr.base.BaseFormula; import com.fr.base.Utils; import com.fr.chart.chartattr.ChartAlertValue; import com.fr.design.beans.BasicBeanPane; @@ -162,10 +162,10 @@ public class ChartAlertValuePane extends BasicBeanPane { private void showFormulaPane() { final UIFormula formulaPane = FormulaFactory.createFormulaPane(); - formulaPane.populate(new Formula(textField.getText())); + formulaPane.populate(BaseFormula.createFormulaBuilder().build(textField.getText())); formulaPane.showLargeWindow(SwingUtilities.getWindowAncestor(ChartAlertValuePane.this), new DialogActionAdapter(){ public void doOk() { - Formula formula = formulaPane.update(); + BaseFormula formula = formulaPane.update(); textField.setText(Utils.objectToString(formula)); } }).setVisible(true); @@ -206,7 +206,7 @@ public class ChartAlertValuePane extends BasicBeanPane { public void updateBean(ChartAlertValue chartAlertValue) { - chartAlertValue.setAlertValueFormula(new Formula(textField.getText())); + chartAlertValue.setAlertValueFormula(BaseFormula.createFormulaBuilder().build(textField.getText())); chartAlertValue.getLineColor().setSeriesColor(colorBox.getSelectObject()); chartAlertValue.getLineStyle().setLineStyle(lineCombo.getSelectedLineStyle()); chartAlertValue.setAlertLineAlpha(alphaPane.update()); diff --git a/designer_chart/src/com/fr/design/chart/axis/MinMaxValuePane.java b/designer_chart/src/com/fr/design/chart/axis/MinMaxValuePane.java index 5f73635d8..458adbf07 100644 --- a/designer_chart/src/com/fr/design/chart/axis/MinMaxValuePane.java +++ b/designer_chart/src/com/fr/design/chart/axis/MinMaxValuePane.java @@ -1,6 +1,6 @@ package com.fr.design.chart.axis; -import com.fr.base.Formula; +import com.fr.base.BaseFormula; import com.fr.chart.base.ChartBaseUtils; import com.fr.chart.chartattr.Axis; import com.fr.design.chart.ChartSwingUtils; @@ -147,13 +147,13 @@ public class MinMaxValuePane extends JPanel { // 最大最小值 if (minCheckBox.isSelected()) { axis.setCustomMinValue(StringUtils.isNotEmpty(minValueField.getText())); - axis.setMinValue(new Formula(minValueField.getText())); + axis.setMinValue(BaseFormula.createFormulaBuilder().build(minValueField.getText())); } else { axis.setCustomMinValue(false); } if (maxCheckBox.isSelected()) { axis.setCustomMaxValue(StringUtils.isNotEmpty(maxValueField.getText())); - axis.setMaxValue(new Formula(maxValueField.getText())); + axis.setMaxValue(BaseFormula.createFormulaBuilder().build(maxValueField.getText())); } else { axis.setCustomMaxValue(false); } @@ -170,10 +170,10 @@ public class MinMaxValuePane extends JPanel { axis.setMainUnit(null); } else { axis.setCustomMainUnit(true); - Formula formula = new Formula(increment); + BaseFormula formula = BaseFormula.createFormulaBuilder().build(increment); Number number = ChartBaseUtils.formula2Number(formula); if(number != null && number.doubleValue() < 0) { - axis.setMainUnit(new Formula("10")); + axis.setMainUnit(BaseFormula.createFormulaBuilder().build("10")); } else { axis.setMainUnit(formula); } @@ -189,10 +189,10 @@ public class MinMaxValuePane extends JPanel { axis.setSecUnit(null); } else { axis.setCustomSecUnit(true); - Formula formula = new Formula(increment); + BaseFormula formula = BaseFormula.createFormulaBuilder().build(increment); Number number = ChartBaseUtils.formula2Number(formula); if(number != null && number.doubleValue() < 0) { - axis.setSecUnit(new Formula("10")); + axis.setSecUnit(BaseFormula.createFormulaBuilder().build("10")); } else { axis.setSecUnit(formula); } diff --git a/designer_chart/src/com/fr/design/chart/report/GisMapReportDataContentPane.java b/designer_chart/src/com/fr/design/chart/report/GisMapReportDataContentPane.java index 1c2a97027..3d8faa2bf 100644 --- a/designer_chart/src/com/fr/design/chart/report/GisMapReportDataContentPane.java +++ b/designer_chart/src/com/fr/design/chart/report/GisMapReportDataContentPane.java @@ -1,301 +1,297 @@ -package com.fr.design.chart.report; - -import java.awt.*; -import java.awt.event.FocusAdapter; -import java.awt.event.FocusEvent; -import java.util.ArrayList; -import java.util.List; - -import javax.swing.JComponent; -import javax.swing.JPanel; -import javax.swing.JTable; -import javax.swing.SwingConstants; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; - -import com.fr.base.Formula; -import com.fr.base.Utils; -import com.fr.chart.chartdata.BaseSeriesDefinition; -import com.fr.chart.chartdata.GisMapReportDefinition; -import com.fr.chart.chartdata.SeriesDefinition; -import com.fr.design.constants.LayoutConstants; -import com.fr.design.constants.UIConstants; -import com.fr.design.beans.FurtherBasicBeanPane; -import com.fr.design.event.UIObserver; -import com.fr.design.event.UIObserverListener; -import com.fr.design.formula.TinyFormulaPane; -import com.fr.design.gui.frpane.UICorrelationPane; -import com.fr.design.gui.ibutton.UIButtonGroup; -import com.fr.design.gui.ilable.UILabel; -import com.fr.design.gui.itable.UITableEditor; -import com.fr.design.gui.itextfield.UITextField; -import com.fr.design.layout.TableLayout; -import com.fr.design.layout.TableLayoutHelper; -import com.fr.general.Inter; -import com.fr.stable.StableUtils; -import com.fr.stable.StringUtils; - -/** - * 属性表gis地图单元格数据源设置界面 - * - * @author eason - */ -public class GisMapReportDataContentPane extends FurtherBasicBeanPane implements UIObserver { - private UIButtonGroup addressType; - private UIButtonGroup lnglatOrder; - private TinyFormulaPane addressPane; - private TinyFormulaPane addressNamePane; - private UICorrelationPane seriesPane; - private JPanel orderPane; - private ArrayList changeListeners = new ArrayList(); - - public GisMapReportDataContentPane() { - initCom(); - } - - private void initCom() { - this.setLayout(new BorderLayout(0, 0)); - addressType = new UIButtonGroup(new String[]{Inter.getLocText("Chart-Address"), Inter.getLocText("Chart-LngLat")}); - lnglatOrder = new UIButtonGroup(new String[]{Inter.getLocText("Chart-LngFirst"), Inter.getLocText("Chart-LatFirst")}); - addressPane = new TinyFormulaPane(); - addressNamePane = new TinyFormulaPane(); - double p = TableLayout.PREFERRED; - double f = TableLayout.FILL; - double[] columnSize = new double[]{p, f}; - double[] rowSize = new double[]{p, p, p}; - - orderPane = new JPanel(new BorderLayout(LayoutConstants.VGAP_MEDIUM, 0)) { - @Override - public Dimension getPreferredSize() { - if (this.isVisible()) { - return super.getPreferredSize(); - } else { - return new Dimension(0, 0); - } - } - }; - orderPane.add(new UILabel(Inter.getLocText("Chart-LatLngOrder")), BorderLayout.WEST); - orderPane.add(lnglatOrder, BorderLayout.CENTER); - orderPane.setVisible(false); - lnglatOrder.setSelectedIndex(0); - addressType.setSelectedIndex(0); - Component[][] components = new Component[][]{ - new Component[]{addressType, addressPane}, - new Component[]{orderPane, null}, - new Component[]{new UILabel(" " +Inter.getLocText("Chart-Address-Name")+":", SwingConstants.RIGHT), addressNamePane}, - }; - JPanel northPane = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); - - this.add(northPane, BorderLayout.NORTH); - - String[] columnNames = new String[]{Inter.getLocText(new String[]{"Filed", "Title"}), Inter.getLocText("Area_Value")}; - seriesPane = new UICorrelationPane(columnNames) { - public UITableEditor createUITableEditor() { - return new InnerTableEditor(); - } - }; - - this.add(seriesPane, BorderLayout.CENTER); - } - - /** - * 界面接入. - * @param ob 对象 - * @return true表示接受 - */ - public boolean accept(Object ob) { - return true; - } - - /** - * 重置 - */ - public void reset() { - - } - - /** - * 界面弹出标题. - * @return 标题 - */ - public String title4PopupWindow() { - return Inter.getLocText("Cell"); - } - - @Override - public void populateBean(GisMapReportDefinition ob) { - if (ob.getCategoryName() != null) { - if (ob.isAddress()) { - addressType.setSelectedIndex(0); - orderPane.setVisible(false); - } else { - addressType.setSelectedIndex(1); - orderPane.setVisible(true); - } - - if (ob.isLngFirst()) { - lnglatOrder.setSelectedIndex(0); - } else { - lnglatOrder.setSelectedIndex(1); - } - - addressPane.populateBean(Utils.objectToString(ob.getCategoryName())); - if (ob.getAddressName() != null) { - addressNamePane.populateBean(Utils.objectToString(ob.getAddressName())); - } - int size = ob.getTitleValueSize(); - List paneList = new ArrayList(); - for (int i = 0; i < size; i++) { - BaseSeriesDefinition first = ob.getTitleValueWithIndex(i); - if (first != null && first.getSeriesName() != null && first.getValue() != null) { - paneList.add(new Object[]{first.getSeriesName(), first.getValue()}); - } - } - if (!paneList.isEmpty()) { - seriesPane.populateBean(paneList); - } - } - } - - @Override - public GisMapReportDefinition updateBean() { - GisMapReportDefinition reportDefinition = new GisMapReportDefinition(); - if (this.addressType.getSelectedIndex() == 0) { - reportDefinition.setAddressType(true); - orderPane.setVisible(false); - } else { - reportDefinition.setAddressType(false); - orderPane.setVisible(true); - } - - if (this.lnglatOrder.getSelectedIndex() == 0) { - reportDefinition.setLnglatOrder(true); - } else { - reportDefinition.setLnglatOrder(false); - } - - String address = addressPane.updateBean(); - if (StringUtils.isBlank(address)) { - return null; - } - if (StableUtils.canBeFormula(address)) { - reportDefinition.setCategoryName(new Formula(address)); - } else { - reportDefinition.setCategoryName(address); - } - - String addressName = addressNamePane.updateBean(); - if (addressName != null && !StringUtils.isBlank(addressName)) { - if (StableUtils.canBeFormula(addressName)) { - reportDefinition.setAddressName(addressName); - } else { - reportDefinition.setAddressName(addressName); - } - } - List values = seriesPane.updateBean(); - if (values != null && !values.isEmpty()) { - for (int i = 0, size = values.size(); i < size; i++) { - Object[] objects = (Object[]) values.get(i); - Object name = objects[0]; - Object value = objects[1]; - - if (StableUtils.canBeFormula(value)) { - value = new Formula(Utils.objectToString(value)); - } - SeriesDefinition definition = new SeriesDefinition(name, value); - reportDefinition.addTitleValue(definition); - } - } - return reportDefinition; - } - - /** - * 给组件登记一个观察者监听事件 - * - * @param listener 观察者监听事件 - */ - public void registerChangeListener(final UIObserverListener listener) { - changeListeners.add(new ChangeListener() { - public void stateChanged(ChangeEvent e) { - listener.doChange(); - } - }); - } - - /** - * 组件是否需要响应添加的观察者事件 - * - * @return 如果需要响应观察者事件则返回true,否则返回false - */ - public boolean shouldResponseChangeListener() { - return true; - } - - private class InnerTableEditor extends UITableEditor { - private JComponent editorComponent; - - /** - * 返回当前编辑器的值 - */ - public Object getCellEditorValue() { - if (editorComponent instanceof TinyFormulaPane) { - return ((TinyFormulaPane) editorComponent).getUITextField().getText(); - } else if (editorComponent instanceof UITextField) { - return ((UITextField) editorComponent).getText(); - } - - return super.getCellEditorValue(); - } - - /** - * 返回当前编辑器.. - */ - public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { - if (column == table.getModel().getColumnCount()) { - return null; - } - return getEditorComponent(column, value); - } - - private JComponent getEditorComponent(int column, Object value) { - if (column == 0) { - UITextField field = new UITextField(); - addListener4UITextFiled(field); - - if (value != null) { - field.setText(Utils.objectToString(value)); - } - editorComponent = field; - } else { - TinyFormulaPane tinyPane = new TinyFormulaPane() { - @Override - public void okEvent() { - seriesPane.stopCellEditing(); - seriesPane.fireTargetChanged(); - } - }; - tinyPane.setBackground(UIConstants.FLESH_BLUE); - - addListener4UITextFiled(tinyPane.getUITextField()); - - if (value != null) { - tinyPane.getUITextField().setText(Utils.objectToString(value)); - } - - editorComponent = tinyPane; - } - return editorComponent; - } - - private void addListener4UITextFiled(UITextField textField) { - - textField.addFocusListener(new FocusAdapter() { - @Override - public void focusLost(FocusEvent e) { -// seriesPane.stopCellEditing(); //kunsnat: 不stop是因为可能直接点击公式编辑按钮, 否则需要点击两次才能弹出. - seriesPane.fireTargetChanged(); - } - }); - } - } +package com.fr.design.chart.report; + +import com.fr.base.BaseFormula; +import com.fr.base.Utils; +import com.fr.chart.chartdata.BaseSeriesDefinition; +import com.fr.chart.chartdata.GisMapReportDefinition; +import com.fr.chart.chartdata.SeriesDefinition; +import com.fr.design.beans.FurtherBasicBeanPane; +import com.fr.design.constants.LayoutConstants; +import com.fr.design.constants.UIConstants; +import com.fr.design.event.UIObserver; +import com.fr.design.event.UIObserverListener; +import com.fr.design.formula.TinyFormulaPane; +import com.fr.design.gui.frpane.UICorrelationPane; +import com.fr.design.gui.ibutton.UIButtonGroup; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itable.UITableEditor; +import com.fr.design.gui.itextfield.UITextField; +import com.fr.design.layout.TableLayout; +import com.fr.design.layout.TableLayoutHelper; +import com.fr.general.Inter; +import com.fr.stable.StableUtils; +import com.fr.stable.StringUtils; + +import javax.swing.*; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import java.awt.*; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.util.ArrayList; +import java.util.List; + +/** + * 属性表gis地图单元格数据源设置界面 + * + * @author eason + */ +public class GisMapReportDataContentPane extends FurtherBasicBeanPane implements UIObserver { + private UIButtonGroup addressType; + private UIButtonGroup lnglatOrder; + private TinyFormulaPane addressPane; + private TinyFormulaPane addressNamePane; + private UICorrelationPane seriesPane; + private JPanel orderPane; + private ArrayList changeListeners = new ArrayList(); + + public GisMapReportDataContentPane() { + initCom(); + } + + private void initCom() { + this.setLayout(new BorderLayout(0, 0)); + addressType = new UIButtonGroup(new String[]{Inter.getLocText("Chart-Address"), Inter.getLocText("Chart-LngLat")}); + lnglatOrder = new UIButtonGroup(new String[]{Inter.getLocText("Chart-LngFirst"), Inter.getLocText("Chart-LatFirst")}); + addressPane = new TinyFormulaPane(); + addressNamePane = new TinyFormulaPane(); + double p = TableLayout.PREFERRED; + double f = TableLayout.FILL; + double[] columnSize = new double[]{p, f}; + double[] rowSize = new double[]{p, p, p}; + + orderPane = new JPanel(new BorderLayout(LayoutConstants.VGAP_MEDIUM, 0)) { + @Override + public Dimension getPreferredSize() { + if (this.isVisible()) { + return super.getPreferredSize(); + } else { + return new Dimension(0, 0); + } + } + }; + orderPane.add(new UILabel(Inter.getLocText("Chart-LatLngOrder")), BorderLayout.WEST); + orderPane.add(lnglatOrder, BorderLayout.CENTER); + orderPane.setVisible(false); + lnglatOrder.setSelectedIndex(0); + addressType.setSelectedIndex(0); + Component[][] components = new Component[][]{ + new Component[]{addressType, addressPane}, + new Component[]{orderPane, null}, + new Component[]{new UILabel(" " +Inter.getLocText("Chart-Address-Name")+":", SwingConstants.RIGHT), addressNamePane}, + }; + JPanel northPane = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); + + this.add(northPane, BorderLayout.NORTH); + + String[] columnNames = new String[]{Inter.getLocText(new String[]{"Filed", "Title"}), Inter.getLocText("Area_Value")}; + seriesPane = new UICorrelationPane(columnNames) { + public UITableEditor createUITableEditor() { + return new InnerTableEditor(); + } + }; + + this.add(seriesPane, BorderLayout.CENTER); + } + + /** + * 界面接入. + * @param ob 对象 + * @return true表示接受 + */ + public boolean accept(Object ob) { + return true; + } + + /** + * 重置 + */ + public void reset() { + + } + + /** + * 界面弹出标题. + * @return 标题 + */ + public String title4PopupWindow() { + return Inter.getLocText("Cell"); + } + + @Override + public void populateBean(GisMapReportDefinition ob) { + if (ob.getCategoryName() != null) { + if (ob.isAddress()) { + addressType.setSelectedIndex(0); + orderPane.setVisible(false); + } else { + addressType.setSelectedIndex(1); + orderPane.setVisible(true); + } + + if (ob.isLngFirst()) { + lnglatOrder.setSelectedIndex(0); + } else { + lnglatOrder.setSelectedIndex(1); + } + + addressPane.populateBean(Utils.objectToString(ob.getCategoryName())); + if (ob.getAddressName() != null) { + addressNamePane.populateBean(Utils.objectToString(ob.getAddressName())); + } + int size = ob.getTitleValueSize(); + List paneList = new ArrayList(); + for (int i = 0; i < size; i++) { + BaseSeriesDefinition first = ob.getTitleValueWithIndex(i); + if (first != null && first.getSeriesName() != null && first.getValue() != null) { + paneList.add(new Object[]{first.getSeriesName(), first.getValue()}); + } + } + if (!paneList.isEmpty()) { + seriesPane.populateBean(paneList); + } + } + } + + @Override + public GisMapReportDefinition updateBean() { + GisMapReportDefinition reportDefinition = new GisMapReportDefinition(); + if (this.addressType.getSelectedIndex() == 0) { + reportDefinition.setAddressType(true); + orderPane.setVisible(false); + } else { + reportDefinition.setAddressType(false); + orderPane.setVisible(true); + } + + if (this.lnglatOrder.getSelectedIndex() == 0) { + reportDefinition.setLnglatOrder(true); + } else { + reportDefinition.setLnglatOrder(false); + } + + String address = addressPane.updateBean(); + if (StringUtils.isBlank(address)) { + return null; + } + if (StableUtils.canBeFormula(address)) { + reportDefinition.setCategoryName(BaseFormula.createFormulaBuilder().build(address)); + } else { + reportDefinition.setCategoryName(address); + } + + String addressName = addressNamePane.updateBean(); + if (addressName != null && !StringUtils.isBlank(addressName)) { + if (StableUtils.canBeFormula(addressName)) { + reportDefinition.setAddressName(addressName); + } else { + reportDefinition.setAddressName(addressName); + } + } + List values = seriesPane.updateBean(); + if (values != null && !values.isEmpty()) { + for (int i = 0, size = values.size(); i < size; i++) { + Object[] objects = (Object[]) values.get(i); + Object name = objects[0]; + Object value = objects[1]; + + if (StableUtils.canBeFormula(value)) { + value = BaseFormula.createFormulaBuilder().build(value); + } + SeriesDefinition definition = new SeriesDefinition(name, value); + reportDefinition.addTitleValue(definition); + } + } + return reportDefinition; + } + + /** + * 给组件登记一个观察者监听事件 + * + * @param listener 观察者监听事件 + */ + public void registerChangeListener(final UIObserverListener listener) { + changeListeners.add(new ChangeListener() { + public void stateChanged(ChangeEvent e) { + listener.doChange(); + } + }); + } + + /** + * 组件是否需要响应添加的观察者事件 + * + * @return 如果需要响应观察者事件则返回true,否则返回false + */ + public boolean shouldResponseChangeListener() { + return true; + } + + private class InnerTableEditor extends UITableEditor { + private JComponent editorComponent; + + /** + * 返回当前编辑器的值 + */ + public Object getCellEditorValue() { + if (editorComponent instanceof TinyFormulaPane) { + return ((TinyFormulaPane) editorComponent).getUITextField().getText(); + } else if (editorComponent instanceof UITextField) { + return ((UITextField) editorComponent).getText(); + } + + return super.getCellEditorValue(); + } + + /** + * 返回当前编辑器.. + */ + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + if (column == table.getModel().getColumnCount()) { + return null; + } + return getEditorComponent(column, value); + } + + private JComponent getEditorComponent(int column, Object value) { + if (column == 0) { + UITextField field = new UITextField(); + addListener4UITextFiled(field); + + if (value != null) { + field.setText(Utils.objectToString(value)); + } + editorComponent = field; + } else { + TinyFormulaPane tinyPane = new TinyFormulaPane() { + @Override + public void okEvent() { + seriesPane.stopCellEditing(); + seriesPane.fireTargetChanged(); + } + }; + tinyPane.setBackground(UIConstants.FLESH_BLUE); + + addListener4UITextFiled(tinyPane.getUITextField()); + + if (value != null) { + tinyPane.getUITextField().setText(Utils.objectToString(value)); + } + + editorComponent = tinyPane; + } + return editorComponent; + } + + private void addListener4UITextFiled(UITextField textField) { + + textField.addFocusListener(new FocusAdapter() { + @Override + public void focusLost(FocusEvent e) { +// seriesPane.stopCellEditing(); //kunsnat: 不stop是因为可能直接点击公式编辑按钮, 否则需要点击两次才能弹出. + seriesPane.fireTargetChanged(); + } + }); + } + } } \ No newline at end of file diff --git a/designer_chart/src/com/fr/design/chart/report/MapMoreReportIndexPane.java b/designer_chart/src/com/fr/design/chart/report/MapMoreReportIndexPane.java index 70f11f8b4..bba5fc301 100644 --- a/designer_chart/src/com/fr/design/chart/report/MapMoreReportIndexPane.java +++ b/designer_chart/src/com/fr/design/chart/report/MapMoreReportIndexPane.java @@ -1,202 +1,196 @@ -package com.fr.design.chart.report; - -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.FlowLayout; -import java.awt.event.FocusAdapter; -import java.awt.event.FocusEvent; -import java.util.ArrayList; -import java.util.List; - -import javax.swing.JComponent; -import javax.swing.JPanel; -import javax.swing.JTable; - -import com.fr.base.Formula; -import com.fr.base.Utils; -import com.fr.chart.chartdata.BaseSeriesDefinition; -import com.fr.chart.chartdata.MapSingleLayerReportDefinition; -import com.fr.chart.chartdata.SeriesDefinition; -import com.fr.design.constants.UIConstants; -import com.fr.design.beans.BasicBeanPane; -import com.fr.design.event.UIObserver; -import com.fr.design.event.UIObserverListener; -import com.fr.design.formula.TinyFormulaPane; -import com.fr.design.gui.frpane.UICorrelationPane; -import com.fr.design.gui.ilable.UILabel; -import com.fr.design.gui.itable.UITableEditor; -import com.fr.design.gui.itextfield.UITextField; -import com.fr.general.Inter; -import com.fr.stable.StableUtils; -import com.fr.stable.StringUtils; - -/** - * 多层地图, 单元格, 多层切换 单界面. - * @author kunsnat E-mail:kunsnat@gmail.com - * @version 创建时间:2013-4-22 下午04:26:10 - */ -public class MapMoreReportIndexPane extends BasicBeanPane implements UIObserver{ - private String title = StringUtils.EMPTY; - - private TinyFormulaPane areaNamePane; - private UICorrelationPane tabPane; - - public MapMoreReportIndexPane() { - initPane(); - } - - public MapMoreReportIndexPane(String titleName) { - title = titleName; - initPane(); - } - - private void initPane() { - this.setLayout(new BorderLayout(0, 0)); - - JPanel northPane = new JPanel(); - this.add(northPane, BorderLayout.NORTH); - northPane.setLayout(new FlowLayout(FlowLayout.LEFT)); - - northPane.add(new UILabel(Inter.getLocText("Area_Name") + ":")); - - areaNamePane = new TinyFormulaPane(); - areaNamePane.setPreferredSize(new Dimension(120, 20)); - northPane.add(areaNamePane); - - tabPane = new UICorrelationPane(new String[]{Inter.getLocText(new String[]{"Filed", "Title"}), Inter.getLocText("Area_Value")}){ - public UITableEditor createUITableEditor() { - return new InnerTableEditor(); - } - }; - - this.add(tabPane, BorderLayout.CENTER); - } - - @Override - public void populateBean(MapSingleLayerReportDefinition definition) { - if(definition != null && definition.getCategoryName() != null) { - areaNamePane.populateBean(Utils.objectToString(definition.getCategoryName())); - - List paneList = new ArrayList(); - int titleValueSize = definition.getTitleValueSize(); - for(int i = 0; i < titleValueSize; i++) { - BaseSeriesDefinition sd = definition.getTitleValueWithIndex(i); - if(sd != null && sd.getSeriesName() != null && sd.getValue() != null) { - paneList.add(new Object[]{sd.getSeriesName(), sd.getValue()}); - } - } - - if(!paneList.isEmpty()) { - tabPane.populateBean(paneList); - } - } - } - - public MapSingleLayerReportDefinition updateBean() { - MapSingleLayerReportDefinition definition = new MapSingleLayerReportDefinition(); - - String areaName = areaNamePane.updateBean(); - if(StableUtils.canBeFormula(areaName)) { - definition.setCategoryName(new Formula(areaName)); - } else { - definition.setCategoryName(areaName); - } - - List paneList = tabPane.updateBean(); - for(int i = 0, size = paneList.size(); i < size; i++) { - Object[] values = (Object[])paneList.get(i); - if(values.length == 2) { - SeriesDefinition seriesDefinition = new SeriesDefinition(); - seriesDefinition.setSeriesName(values[0]); - seriesDefinition.setValue(values[1]); - definition.addTitleValue(seriesDefinition); - } - } - - return definition; - } - - @Override - protected String title4PopupWindow() { - return title; - } - - private class InnerTableEditor extends UITableEditor { - private JComponent editorComponent; - - /** - * 返回当前编辑器的值 - */ - public Object getCellEditorValue() { - if(editorComponent instanceof TinyFormulaPane) { - return ((TinyFormulaPane)editorComponent).getUITextField().getText(); - } else if(editorComponent instanceof UITextField) { - return ((UITextField)editorComponent).getText(); - } - - return super.getCellEditorValue(); - } - - /** - * 返回当前编辑器.. - */ - public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { - if (column == table.getModel().getColumnCount()) { - return null; - } - return getEditorComponent(column, value); - } - - private JComponent getEditorComponent(int column, Object value) { - if(column == 0) { - UITextField field = new UITextField(); - editorComponent = field; - - if(value != null) { - field.setText(Utils.objectToString(value)); - } - } else { - TinyFormulaPane tinyPane = new TinyFormulaPane() { - @Override - public void okEvent() { - tabPane.stopCellEditing(); - tabPane.fireTargetChanged(); - } - }; - tinyPane.setBackground(UIConstants.FLESH_BLUE); - - tinyPane.getUITextField().addFocusListener(new FocusAdapter() { - @Override - public void focusLost(FocusEvent e) { -// tabPane.stopCellEditing();//kunsnat: 不stop是因为可能直接点击公式编辑按钮, 否则需要点击两次才能弹出. - tabPane.fireTargetChanged(); - } - }); - - if(value != null) { - tinyPane.getUITextField().setText(Utils.objectToString(value)); - } - - editorComponent = tinyPane; - } - return editorComponent; - } - } - - @Override - public void registerChangeListener(UIObserverListener listener) { - if(tabPane != null) { - tabPane.registerChangeListener(listener); - } - if(areaNamePane != null) { - areaNamePane.registerChangeListener(listener); - } - } - - @Override - public boolean shouldResponseChangeListener() { - return true; - } - +package com.fr.design.chart.report; + +import com.fr.base.BaseFormula; +import com.fr.base.Utils; +import com.fr.chart.chartdata.BaseSeriesDefinition; +import com.fr.chart.chartdata.MapSingleLayerReportDefinition; +import com.fr.chart.chartdata.SeriesDefinition; +import com.fr.design.beans.BasicBeanPane; +import com.fr.design.constants.UIConstants; +import com.fr.design.event.UIObserver; +import com.fr.design.event.UIObserverListener; +import com.fr.design.formula.TinyFormulaPane; +import com.fr.design.gui.frpane.UICorrelationPane; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itable.UITableEditor; +import com.fr.design.gui.itextfield.UITextField; +import com.fr.general.Inter; +import com.fr.stable.StableUtils; +import com.fr.stable.StringUtils; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.util.ArrayList; +import java.util.List; + +/** + * 多层地图, 单元格, 多层切换 单界面. + * @author kunsnat E-mail:kunsnat@gmail.com + * @version 创建时间:2013-4-22 下午04:26:10 + */ +public class MapMoreReportIndexPane extends BasicBeanPane implements UIObserver{ + private String title = StringUtils.EMPTY; + + private TinyFormulaPane areaNamePane; + private UICorrelationPane tabPane; + + public MapMoreReportIndexPane() { + initPane(); + } + + public MapMoreReportIndexPane(String titleName) { + title = titleName; + initPane(); + } + + private void initPane() { + this.setLayout(new BorderLayout(0, 0)); + + JPanel northPane = new JPanel(); + this.add(northPane, BorderLayout.NORTH); + northPane.setLayout(new FlowLayout(FlowLayout.LEFT)); + + northPane.add(new UILabel(Inter.getLocText("Area_Name") + ":")); + + areaNamePane = new TinyFormulaPane(); + areaNamePane.setPreferredSize(new Dimension(120, 20)); + northPane.add(areaNamePane); + + tabPane = new UICorrelationPane(new String[]{Inter.getLocText(new String[]{"Filed", "Title"}), Inter.getLocText("Area_Value")}){ + public UITableEditor createUITableEditor() { + return new InnerTableEditor(); + } + }; + + this.add(tabPane, BorderLayout.CENTER); + } + + @Override + public void populateBean(MapSingleLayerReportDefinition definition) { + if(definition != null && definition.getCategoryName() != null) { + areaNamePane.populateBean(Utils.objectToString(definition.getCategoryName())); + + List paneList = new ArrayList(); + int titleValueSize = definition.getTitleValueSize(); + for(int i = 0; i < titleValueSize; i++) { + BaseSeriesDefinition sd = definition.getTitleValueWithIndex(i); + if(sd != null && sd.getSeriesName() != null && sd.getValue() != null) { + paneList.add(new Object[]{sd.getSeriesName(), sd.getValue()}); + } + } + + if(!paneList.isEmpty()) { + tabPane.populateBean(paneList); + } + } + } + + public MapSingleLayerReportDefinition updateBean() { + MapSingleLayerReportDefinition definition = new MapSingleLayerReportDefinition(); + + String areaName = areaNamePane.updateBean(); + if(StableUtils.canBeFormula(areaName)) { + definition.setCategoryName(BaseFormula.createFormulaBuilder().build(areaName)); + } else { + definition.setCategoryName(areaName); + } + + List paneList = tabPane.updateBean(); + for(int i = 0, size = paneList.size(); i < size; i++) { + Object[] values = (Object[])paneList.get(i); + if(values.length == 2) { + SeriesDefinition seriesDefinition = new SeriesDefinition(); + seriesDefinition.setSeriesName(values[0]); + seriesDefinition.setValue(values[1]); + definition.addTitleValue(seriesDefinition); + } + } + + return definition; + } + + @Override + protected String title4PopupWindow() { + return title; + } + + private class InnerTableEditor extends UITableEditor { + private JComponent editorComponent; + + /** + * 返回当前编辑器的值 + */ + public Object getCellEditorValue() { + if(editorComponent instanceof TinyFormulaPane) { + return ((TinyFormulaPane)editorComponent).getUITextField().getText(); + } else if(editorComponent instanceof UITextField) { + return ((UITextField)editorComponent).getText(); + } + + return super.getCellEditorValue(); + } + + /** + * 返回当前编辑器.. + */ + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + if (column == table.getModel().getColumnCount()) { + return null; + } + return getEditorComponent(column, value); + } + + private JComponent getEditorComponent(int column, Object value) { + if(column == 0) { + UITextField field = new UITextField(); + editorComponent = field; + + if(value != null) { + field.setText(Utils.objectToString(value)); + } + } else { + TinyFormulaPane tinyPane = new TinyFormulaPane() { + @Override + public void okEvent() { + tabPane.stopCellEditing(); + tabPane.fireTargetChanged(); + } + }; + tinyPane.setBackground(UIConstants.FLESH_BLUE); + + tinyPane.getUITextField().addFocusListener(new FocusAdapter() { + @Override + public void focusLost(FocusEvent e) { +// tabPane.stopCellEditing();//kunsnat: 不stop是因为可能直接点击公式编辑按钮, 否则需要点击两次才能弹出. + tabPane.fireTargetChanged(); + } + }); + + if(value != null) { + tinyPane.getUITextField().setText(Utils.objectToString(value)); + } + + editorComponent = tinyPane; + } + return editorComponent; + } + } + + @Override + public void registerChangeListener(UIObserverListener listener) { + if(tabPane != null) { + tabPane.registerChangeListener(listener); + } + if(areaNamePane != null) { + areaNamePane.registerChangeListener(listener); + } + } + + @Override + public boolean shouldResponseChangeListener() { + return true; + } + } \ No newline at end of file diff --git a/designer_chart/src/com/fr/design/chart/report/MapReportDataSinglePane.java b/designer_chart/src/com/fr/design/chart/report/MapReportDataSinglePane.java index c8f1b4f1e..03ddfc015 100644 --- a/designer_chart/src/com/fr/design/chart/report/MapReportDataSinglePane.java +++ b/designer_chart/src/com/fr/design/chart/report/MapReportDataSinglePane.java @@ -1,28 +1,12 @@ package com.fr.design.chart.report; -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.FlowLayout; -import java.awt.event.FocusAdapter; -import java.awt.event.FocusEvent; -import java.util.ArrayList; -import java.util.List; - -import javax.swing.JComponent; -import javax.swing.JPanel; -import javax.swing.JTable; -import javax.swing.SwingConstants; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; - -import com.fr.base.Formula; +import com.fr.base.BaseFormula; import com.fr.base.Utils; import com.fr.chart.chartdata.BaseSeriesDefinition; import com.fr.chart.chartdata.MapSingleLayerReportDefinition; import com.fr.chart.chartdata.SeriesDefinition; -import com.fr.design.constants.UIConstants; import com.fr.design.beans.FurtherBasicBeanPane; +import com.fr.design.constants.UIConstants; import com.fr.design.event.UIObserver; import com.fr.design.event.UIObserverListener; import com.fr.design.formula.TinyFormulaPane; @@ -33,6 +17,15 @@ import com.fr.design.gui.itextfield.UITextField; import com.fr.general.Inter; import com.fr.stable.StableUtils; +import javax.swing.*; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import java.awt.*; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.util.ArrayList; +import java.util.List; + /** * 地图 单元格数据 单层地图 界面 * @@ -118,7 +111,7 @@ public class MapReportDataSinglePane extends FurtherBasicBeanPane refreshList(HashMap map) { List list = new ArrayList(); - java.util.HashMap hyperLinkEditorMap = plot.getHyperLinkEditorMap(); + java.util.HashMap hyperLinkEditorMap = plot.getHyperLinkEditorMap(); list.add(new ChartUIMenuNameableCreator(hyperLinkEditorMap, Inter.getLocText("Hyperlink-Web_link"), new WebHyperlink(), getUseMap(map, WebHyperlink.class))); diff --git a/designer_chart/src/com/fr/design/mainframe/chart/gui/other/ChartInteractivePane.java b/designer_chart/src/com/fr/design/mainframe/chart/gui/other/ChartInteractivePane.java index e5f9a8a7d..f6b7d2023 100644 --- a/designer_chart/src/com/fr/design/mainframe/chart/gui/other/ChartInteractivePane.java +++ b/designer_chart/src/com/fr/design/mainframe/chart/gui/other/ChartInteractivePane.java @@ -1,7 +1,7 @@ package com.fr.design.mainframe.chart.gui.other; +import com.fr.base.BaseFormula; import com.fr.base.CoreDecimalFormat; -import com.fr.base.Formula; import com.fr.base.Style; import com.fr.base.chart.chartdata.TopDefinitionProvider; import com.fr.chart.base.AttrContents; @@ -854,7 +854,7 @@ public class ChartInteractivePane extends BasicScrollPane implements UIOb protected List refreshList(HashMap map) { List list = new ArrayList(); - java.util.HashMap hyperLinkEditorMap = plot.getHyperLinkEditorMap(); + java.util.HashMap hyperLinkEditorMap = plot.getHyperLinkEditorMap(); list.add(new ChartUIMenuNameableCreator(hyperLinkEditorMap, Inter.getLocText("Chart-Link_Reportlet"), new ReportletHyperlink(), getUseMap(map, ReportletHyperlink.class))); diff --git a/designer_chart/src/com/fr/design/mainframe/chart/gui/other/TimeSwitchPane.java b/designer_chart/src/com/fr/design/mainframe/chart/gui/other/TimeSwitchPane.java index 21e680da2..0e1a65ffb 100644 --- a/designer_chart/src/com/fr/design/mainframe/chart/gui/other/TimeSwitchPane.java +++ b/designer_chart/src/com/fr/design/mainframe/chart/gui/other/TimeSwitchPane.java @@ -1,7 +1,7 @@ package com.fr.design.mainframe.chart.gui.other; +import com.fr.base.BaseFormula; import com.fr.base.BaseUtils; -import com.fr.base.Formula; import com.fr.base.Utils; import com.fr.chart.base.ChartConstants; import com.fr.chart.base.TimeSwitchAttr; @@ -22,7 +22,12 @@ import com.fr.general.Inter; import javax.swing.*; import java.awt.*; -import java.awt.event.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; @@ -85,10 +90,10 @@ public class TimeSwitchPane extends JPanel implements UIObserver { private void initTablePane(){ tablePane = new JPanel(new TableLayout()); - tablePane.add(new TimeTickBox(new Formula("1"),ChartConstants.MONTH_TYPE)); - tablePane.add(new TimeTickBox(new Formula("3"),ChartConstants.MONTH_TYPE)); - tablePane.add(new TimeTickBox(new Formula("6"),ChartConstants.MONTH_TYPE)); - tablePane.add(new TimeTickBox(new Formula("1"), ChartConstants.YEAR_TYPE)); + tablePane.add(new TimeTickBox(BaseFormula.createFormulaBuilder().build("1"),ChartConstants.MONTH_TYPE)); + tablePane.add(new TimeTickBox(BaseFormula.createFormulaBuilder().build("3"),ChartConstants.MONTH_TYPE)); + tablePane.add(new TimeTickBox(BaseFormula.createFormulaBuilder().build("6"),ChartConstants.MONTH_TYPE)); + tablePane.add(new TimeTickBox(BaseFormula.createFormulaBuilder().build("1"), ChartConstants.YEAR_TYPE)); tablePane.revalidate(); } @@ -111,7 +116,7 @@ public class TimeSwitchPane extends JPanel implements UIObserver { return new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - tablePane.add(new TimeTickBox(new Formula(),ChartConstants.YEAR_TYPE)); + tablePane.add(new TimeTickBox(BaseFormula.createFormulaBuilder().build(),ChartConstants.YEAR_TYPE)); tablePane.revalidate(); fireChange(); } @@ -150,7 +155,7 @@ public class TimeSwitchPane extends JPanel implements UIObserver { continue; } TimeTickBox box =(TimeTickBox) component; - timeMap.add(new TimeSwitchAttr(new Formula(box.mainUnitField.getText()),VALUES.get(box.mainType.getSelectedItem()))); + timeMap.add(new TimeSwitchAttr(BaseFormula.createFormulaBuilder().build(box.mainUnitField.getText()),VALUES.get(box.mainType.getSelectedItem()))); } } @@ -267,7 +272,7 @@ public class TimeSwitchPane extends JPanel implements UIObserver { private UIComboBox mainType; private UIButton delButton; - public TimeTickBox(Formula time,int unit){ + public TimeTickBox(BaseFormula time,int unit){ this.setLayout(new FlowLayout(FlowLayout.CENTER, 4, 0)); mainUnitField = new UITextField(time.toString()); mainUnitField.setEditable(false); @@ -310,7 +315,7 @@ public class TimeSwitchPane extends JPanel implements UIObserver { private void showFormulaPane(final UITextField jTextField) { final UIFormula formulaPane = FormulaFactory.createFormulaPane(); final String original = jTextField.getText(); - formulaPane.populate(new Formula(original)); + formulaPane.populate(BaseFormula.createFormulaBuilder().build(original)); BasicDialog dlg = formulaPane.showLargeWindow(SwingUtilities.getWindowAncestor(TimeSwitchPane.this), new DialogActionAdapter() { public void doOk() { String newText = Utils.objectToString(formulaPane.update()); diff --git a/designer_chart/src/com/fr/design/mainframe/chart/gui/style/ChartAxisLabelPane.java b/designer_chart/src/com/fr/design/mainframe/chart/gui/style/ChartAxisLabelPane.java index 5aefede5c..899c4c019 100644 --- a/designer_chart/src/com/fr/design/mainframe/chart/gui/style/ChartAxisLabelPane.java +++ b/designer_chart/src/com/fr/design/mainframe/chart/gui/style/ChartAxisLabelPane.java @@ -1,471 +1,469 @@ -package com.fr.design.mainframe.chart.gui.style; - -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; - -import javax.swing.JPanel; -import javax.swing.SpinnerNumberModel; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; - -import com.fr.base.Formula; -import com.fr.base.Style; -import com.fr.base.Utils; -import com.fr.chart.base.ChartBaseUtils; -import com.fr.chart.base.TextAttr; -import com.fr.chart.chartattr.Axis; -import com.fr.design.constants.LayoutConstants; -import com.fr.design.event.UIObserver; -import com.fr.design.event.UIObserverListener; -import com.fr.design.gui.icheckbox.UICheckBox; -import com.fr.design.gui.icombobox.UIComboBox; -import com.fr.design.gui.ilable.UILabel; -import com.fr.design.gui.ispinner.UIBasicSpinner; -import com.fr.design.gui.itextfield.UITextField; -import com.fr.design.gui.style.NumberDragBar; -import com.fr.design.layout.TableLayout; -import com.fr.design.layout.TableLayoutHelper; -import com.fr.design.dialog.BasicPane; -import com.fr.general.Inter; - -public class ChartAxisLabelPane extends BasicPane implements UIObserver{ - private static final int LABEL_INTERVAL = 0; - private static final int LABEL_WRAP =1; - - private static final long serialVersionUID = 6601571951210596823L; - private static final int NUM90 = 90; - private UICheckBox isLabelShow; - private UIComboBox showWay;//显示方式 - private UITextField customLabelSamleTime; - private UIComboBox labelOrientationChoose; - private NumberDragBar orientationBar; - private UIBasicSpinner orientationSpinner; - private ChartTextAttrPane textAttrPane; - private UICheckBox auto; - private UICheckBox custom; - private UIComboBox labelSampleChoose; - - private JPanel labelPane; - private JPanel showWayPane; - private UIObserverListener observerListener; - private ActionListener autoActionListener = new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - auto.removeActionListener(autoActionListener); - custom.removeActionListener(customActionListener); - auto.setSelected(true); - custom.setSelected(false); - customLabelSamleTime.setEnabled(false); - auto.addActionListener(autoActionListener); - custom.addActionListener(customActionListener); - } - }; - - private ActionListener customActionListener = new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - auto.removeActionListener(autoActionListener); - custom.removeActionListener(customActionListener); - auto.setSelected(false); - custom.setSelected(true); - customLabelSamleTime.setEnabled(true); - customLabelSamleTime.setText("1"); - auto.addActionListener(autoActionListener); - custom.addActionListener(customActionListener); - } - }; - - public ChartAxisLabelPane() { - initComponents(); - } - - private void initComponents() { - isLabelShow = new UICheckBox(Inter.getLocText("FR-Utils_Label")); - auto = new UICheckBox(Inter.getLocText(new String[]{"FR-App-All_Auto", "FR-Chart-Axis_labelInterval"})); - custom = new UICheckBox(Inter.getLocText(new String[]{"FR-App-All_Custom", "FR-Chart-Axis_labelInterval"})); - showWay = new UIComboBox(new String[]{Inter.getLocText("FR-Chart-Axis_labelInterval"),Inter.getLocText("FR-Chart-Axis_labelWrap")}); - customLabelSamleTime = new UITextField(); - - String[] nameObjects = {Inter.getLocText("FR-Chart_All_Normal"), Inter.getLocText("FR-Chart-Text_Vertical"), Inter.getLocText("FR-Chart-Text_Rotation")}; - labelOrientationChoose = new UIComboBox(nameObjects); - orientationBar = new NumberDragBar(-NUM90, NUM90); - orientationSpinner = new UIBasicSpinner(new SpinnerNumberModel(0, -NUM90, NUM90, 1)); - - String[] sampleType = {Inter.getLocText("FR-App-All_Auto"), Inter.getLocText("FR-App-All_Custom")}; - labelSampleChoose = new UIComboBox(sampleType); - customLabelSamleTime = new UITextField(); - checkCustomSampleField(); - - checkOrientationField(); - - textAttrPane = new ChartTextAttrPane(); - this.setLayout(new BorderLayout()); - - initListener(); - } - - private void initListener(){ - - showWay.addItemListener(new ItemListener() { - @Override - public void itemStateChanged(ItemEvent e) { - checkShowWay(); - } - }); - - orientationSpinner.addChangeListener(new ChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - orientationBar.setValue((Integer) orientationSpinner.getValue()); - - } - }); - orientationBar.addChangeListener(new ChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - orientationSpinner.setValue((Integer) orientationBar.getValue()); - - } - }); - - - labelSampleChoose.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - checkCustomSampleField(); - } - }); - - auto.addActionListener(autoActionListener); - - custom.addActionListener(customActionListener); - labelOrientationChoose.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - checkOrientationField(); - } - }); - isLabelShow.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - checkLabelUse(); - } - }); - } - - private JPanel getWrapShowWayPane() { - double p = TableLayout.PREFERRED; - double f = TableLayout.FILL; - double[] columnSize = {LayoutConstants.CHART_ATTR_TOMARGIN, p, p, f}; - double[] rowSize = {p, p, p, p}; - - Component[][] components = new Component[][]{ - new Component[]{null, new UILabel(Inter.getLocText("FR-Chart-Axis_labelShowway")), showWay, null}, - new Component[]{null, new UILabel(Inter.getLocText("StyleAlignment-Text_Rotation")), labelOrientationChoose, null}, - new Component[]{null, orientationSpinner, orientationBar, null}, - new Component[]{null, textAttrPane, null, null}, - }; - return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); - } - - private JPanel getIntervalShowWayPane() { - - double p = TableLayout.PREFERRED; - double f = TableLayout.FILL; - double[] columnSize = {f}; - double[] rowSize = {p, p, p}; - - Component[][] components = new Component[][]{ - new Component[]{getCombox()}, - new Component[]{getTowChoose()}, - new Component[]{getOther()} - }; - return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); - } - - private JPanel getTowChoose() { - auto.registerChangeListener(this.observerListener); - custom.registerChangeListener(this.observerListener); - customLabelSamleTime.registerChangeListener(this.observerListener); - auto.setSelected(true); - custom.setSelected(false); - customLabelSamleTime.setVisible(true); - customLabelSamleTime.setEnabled(false); - double p = TableLayout.PREFERRED; - double f = TableLayout.FILL; - double[] columnSize = {LayoutConstants.CHART_ATTR_TOMARGIN, f}; - double[] rowSize = {p, p}; - - JPanel customPane = TableLayoutHelper.createTableLayoutPane(new Component[][]{ - new Component[]{custom, customLabelSamleTime, null}, - }, new double[]{p}, new double[]{p, p, f}); - - Component[][] components = new Component[][]{ - new Component[]{null, auto,}, - new Component[]{null, customPane} - }; - return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); - } - - private JPanel getCombox() { - double p = TableLayout.PREFERRED; - double f = TableLayout.FILL; - double[] columnSize = {LayoutConstants.CHART_ATTR_TOMARGIN, p, p, f}; - double[] rowSize = {p}; - - Component[][] components = new Component[][]{ - new Component[]{null, new UILabel(Inter.getLocText("FR-Chart-Axis_labelShowway")), showWay, null} - }; - return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); - } - - private JPanel getOther() { - double p = TableLayout.PREFERRED; - double f = TableLayout.FILL; - double[] columnSize = {LayoutConstants.CHART_ATTR_TOMARGIN, p, p, f}; - double[] rowSize = {p, p, p}; - - Component[][] components = new Component[][]{ - new Component[]{null, new UILabel(Inter.getLocText("StyleAlignment-Text_Rotation")), labelOrientationChoose, null}, - new Component[]{null, orientationSpinner, orientationBar, null}, - new Component[]{null, textAttrPane, null, null}, - }; - return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); - } - - private void checkShowWay() { - if (showWayPane != null) { - this.remove(showWayPane); - } - showWay.registerChangeListener(this.observerListener); - orientationSpinner.registerChangeListener(this.observerListener); - labelOrientationChoose.registerChangeListener(this.observerListener); - if (showWay.getSelectedIndex() == LABEL_INTERVAL) { - labelPane = getIntervalShowWayPane(); - } else { - labelPane = getWrapShowWayPane(); - } - double p = TableLayout.PREFERRED; - double f = TableLayout.FILL; - double[] row = {p, p}; - double[] col = {f}; - showWayPane = TableLayoutHelper.createTableLayoutPane(new Component[][]{ - new Component[]{isLabelShow}, new Component[]{labelPane}}, row, col); - this.add(showWayPane, BorderLayout.CENTER); - this.validate(); - } - - - - private void checkOrientationField() { - if (labelOrientationChoose.getSelectedIndex() != 2) { - orientationBar.setVisible(false); - orientationSpinner.setVisible(false); - } else { - orientationBar.setVisible(true); - orientationSpinner.setVisible(true); - } - } - - private void checkPaneOnlyInterval(){ - if (showWayPane != null) { - this.remove(showWayPane); - } - showWayPane = getPanel(); - this.add(showWayPane, BorderLayout.CENTER); - this.validate(); - } - - - private JPanel getPanel() { - labelSampleChoose.registerChangeListener(this.observerListener); - customLabelSamleTime.registerChangeListener(this.observerListener); - orientationSpinner.registerChangeListener(this.observerListener); - labelOrientationChoose.registerChangeListener(this.observerListener); - double p = TableLayout.PREFERRED; - double f = TableLayout.FILL; - double[] columnSize = {LayoutConstants.CHART_ATTR_TOMARGIN, p, p, f}; - double[] rowSize = {p, p, p, p}; - - Component[][] components = new Component[][]{ - new Component[]{null,new UILabel(Inter.getLocText("ChartF-Label_Interval")), labelSampleChoose, customLabelSamleTime}, - new Component[]{null,new UILabel(Inter.getLocText("StyleAlignment-Text_Rotation")), labelOrientationChoose, null}, - new Component[]{null,orientationSpinner, orientationBar, null}, - new Component[]{null,textAttrPane, null, null}, - }; - labelPane = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); - - double[] row = {p,p}; - double[] col = {f}; - return TableLayoutHelper.createTableLayoutPane(new Component[][]{ - new Component[]{isLabelShow}, new Component[]{labelPane}}, row, col); - } - - private void checkCustomSampleField() { - if (labelSampleChoose.getSelectedIndex() == 0) { - customLabelSamleTime.setVisible(false); - } else { - customLabelSamleTime.setVisible(true); - customLabelSamleTime.setText("1"); - } - } - - - /** - * 界面标签 - */ - protected String title4PopupWindow() { - return Inter.getLocText("ChartF-Tick_Label"); - } - - private int getLabelTextOrientationIndex(TextAttr textAttr) { - if (textAttr.getAlignText() == Style.VERTICALTEXT) { - return 1; - } else if (textAttr.getRotation() != 0) { - return 2; - } else { - return 0; - } - } - - private int getLabelSampleNumber(Formula formula) { - Number number = ChartBaseUtils.formula2Number(formula); - if (number != null) { - int num = number.intValue(); - return num < 1 ? 0 : 1; - } - return 0; - } - - private boolean isWrapShow(Formula formula){ - Number number = ChartBaseUtils.formula2Number(formula); - return number == null; - } - - /** - * 检查 标签界面是否可用. - */ - private void checkLabelUse() { - isLabelShow.setEnabled(true); - labelPane.setVisible(isLabelShow.isSelected()); - } - - @Override - public Dimension getPreferredSize() { - if (isLabelShow.isSelected()) { - return super.getPreferredSize(); - } else { - return this.isLabelShow.getPreferredSize(); - } - } - - /** - * 更新界面内容. - */ - public void populate(Axis axis) { - if(axis.isSupportAxisLabelWrap()){ - checkShowWay(); - if (isWrapShow(axis.getLabelNumber())) { - showWay.setSelectedIndex(LABEL_WRAP); - } else { - showWay.setSelectedIndex(LABEL_INTERVAL); - boolean isAuto = getLabelSampleNumber(axis.getLabelNumber()) == 0; - auto.setSelected(isAuto); - custom.setSelected(!isAuto); - customLabelSamleTime.setText(isAuto ? "" : String.valueOf(ChartBaseUtils.formula2Number(axis.getLabelNumber()))); - customLabelSamleTime.setEnabled(!isAuto); - } - }else{ - checkPaneOnlyInterval(); - labelSampleChoose.setSelectedIndex(getLabelSampleNumber(axis.getLabelNumber())); - if (labelSampleChoose.getSelectedIndex() == 1) { - customLabelSamleTime.setText(String.valueOf(ChartBaseUtils.formula2Number(axis.getLabelNumber()))); - } - } - isLabelShow.setSelected(axis.isShowAxisLabel()); - textAttrPane.populate(axis.getTextAttr()); - labelOrientationChoose.setSelectedIndex(getLabelTextOrientationIndex(axis.getTextAttr())); - orientationBar.setValue(axis.getTextAttr().getRotation()); - orientationSpinner.setValue(axis.getTextAttr().getRotation()); - checkLabelUse(); - this.initSelfListener(this); - } - - - /** - * 保存界面属性. - */ - public void update(Axis axis) { - axis.setShowAxisLabel(isLabelShow.isSelected()); - if (isLabelShow.isSelected()) { - if(axis.isSupportAxisLabelWrap()){ - this.update4Wrap(axis); - }else{ - update4Normal(axis); - } - - TextAttr textAttr = axis.getTextAttr(); - textAttrPane.update(textAttr); - if (labelOrientationChoose.getSelectedIndex() == 0) { - textAttr.setRotation(0); - textAttr.setAlignText(Style.HORIZONTALTEXT); - } else if (labelOrientationChoose.getSelectedIndex() == 1) { - textAttr.setRotation(0); - textAttr.setAlignText(Style.VERTICALTEXT); - } else { - textAttr.setAlignText(Style.HORIZONTALTEXT); - textAttr.setRotation(Utils.objectToNumber(orientationSpinner.getValue(), false).intValue()); - } - } - } - - private void update4Normal(Axis axis){ - if (labelSampleChoose.getSelectedIndex() == 0) { - axis.setLabelIntervalNumber(new Formula("0")); - } else { - axis.setLabelIntervalNumber(new Formula(customLabelSamleTime.getText())); - } - } - - private void update4Wrap(Axis axis){ - if (showWay.getSelectedIndex() == LABEL_WRAP) { - axis.setLabelIntervalNumber(new Formula()); - } else if (showWay.getSelectedIndex() == LABEL_INTERVAL) { - if (auto.isSelected()) { - axis.setLabelIntervalNumber(new Formula("0")); - } else if (custom.isSelected()) { - axis.setLabelIntervalNumber(new Formula(customLabelSamleTime.getText())); - } - } - } - - /** - * 注册时间监听器 - * @param listener 观察者监听事件 - */ - public void registerChangeListener(UIObserverListener listener) { - this.observerListener = listener; - } - - private void initSelfListener(Container parentComponent) { - for (int i = 0; i < parentComponent.getComponentCount(); i++) { - Component tmpComp = parentComponent.getComponent(i); - if (tmpComp instanceof Container) { - initSelfListener((Container) tmpComp); - } - if (tmpComp instanceof UIObserver) { - ((UIObserver) tmpComp).registerChangeListener(observerListener); - } - } - } - - /** - * 是否响应事件监听 - * @return 是则返回true - */ - public boolean shouldResponseChangeListener() { - return true; - } +package com.fr.design.mainframe.chart.gui.style; + +import com.fr.base.BaseFormula; +import com.fr.base.Style; +import com.fr.base.Utils; +import com.fr.chart.base.ChartBaseUtils; +import com.fr.chart.base.TextAttr; +import com.fr.chart.chartattr.Axis; +import com.fr.design.constants.LayoutConstants; +import com.fr.design.dialog.BasicPane; +import com.fr.design.event.UIObserver; +import com.fr.design.event.UIObserverListener; +import com.fr.design.gui.icheckbox.UICheckBox; +import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.ispinner.UIBasicSpinner; +import com.fr.design.gui.itextfield.UITextField; +import com.fr.design.gui.style.NumberDragBar; +import com.fr.design.layout.TableLayout; +import com.fr.design.layout.TableLayoutHelper; +import com.fr.general.Inter; + +import javax.swing.*; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; + +public class ChartAxisLabelPane extends BasicPane implements UIObserver{ + private static final int LABEL_INTERVAL = 0; + private static final int LABEL_WRAP =1; + + private static final long serialVersionUID = 6601571951210596823L; + private static final int NUM90 = 90; + private UICheckBox isLabelShow; + private UIComboBox showWay;//显示方式 + private UITextField customLabelSamleTime; + private UIComboBox labelOrientationChoose; + private NumberDragBar orientationBar; + private UIBasicSpinner orientationSpinner; + private ChartTextAttrPane textAttrPane; + private UICheckBox auto; + private UICheckBox custom; + private UIComboBox labelSampleChoose; + + private JPanel labelPane; + private JPanel showWayPane; + private UIObserverListener observerListener; + private ActionListener autoActionListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + auto.removeActionListener(autoActionListener); + custom.removeActionListener(customActionListener); + auto.setSelected(true); + custom.setSelected(false); + customLabelSamleTime.setEnabled(false); + auto.addActionListener(autoActionListener); + custom.addActionListener(customActionListener); + } + }; + + private ActionListener customActionListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + auto.removeActionListener(autoActionListener); + custom.removeActionListener(customActionListener); + auto.setSelected(false); + custom.setSelected(true); + customLabelSamleTime.setEnabled(true); + customLabelSamleTime.setText("1"); + auto.addActionListener(autoActionListener); + custom.addActionListener(customActionListener); + } + }; + + public ChartAxisLabelPane() { + initComponents(); + } + + private void initComponents() { + isLabelShow = new UICheckBox(Inter.getLocText("FR-Utils_Label")); + auto = new UICheckBox(Inter.getLocText(new String[]{"FR-App-All_Auto", "FR-Chart-Axis_labelInterval"})); + custom = new UICheckBox(Inter.getLocText(new String[]{"FR-App-All_Custom", "FR-Chart-Axis_labelInterval"})); + showWay = new UIComboBox(new String[]{Inter.getLocText("FR-Chart-Axis_labelInterval"),Inter.getLocText("FR-Chart-Axis_labelWrap")}); + customLabelSamleTime = new UITextField(); + + String[] nameObjects = {Inter.getLocText("FR-Chart_All_Normal"), Inter.getLocText("FR-Chart-Text_Vertical"), Inter.getLocText("FR-Chart-Text_Rotation")}; + labelOrientationChoose = new UIComboBox(nameObjects); + orientationBar = new NumberDragBar(-NUM90, NUM90); + orientationSpinner = new UIBasicSpinner(new SpinnerNumberModel(0, -NUM90, NUM90, 1)); + + String[] sampleType = {Inter.getLocText("FR-App-All_Auto"), Inter.getLocText("FR-App-All_Custom")}; + labelSampleChoose = new UIComboBox(sampleType); + customLabelSamleTime = new UITextField(); + checkCustomSampleField(); + + checkOrientationField(); + + textAttrPane = new ChartTextAttrPane(); + this.setLayout(new BorderLayout()); + + initListener(); + } + + private void initListener(){ + + showWay.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + checkShowWay(); + } + }); + + orientationSpinner.addChangeListener(new ChangeListener() { + @Override + public void stateChanged(ChangeEvent e) { + orientationBar.setValue((Integer) orientationSpinner.getValue()); + + } + }); + orientationBar.addChangeListener(new ChangeListener() { + @Override + public void stateChanged(ChangeEvent e) { + orientationSpinner.setValue((Integer) orientationBar.getValue()); + + } + }); + + + labelSampleChoose.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + checkCustomSampleField(); + } + }); + + auto.addActionListener(autoActionListener); + + custom.addActionListener(customActionListener); + labelOrientationChoose.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + checkOrientationField(); + } + }); + isLabelShow.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + checkLabelUse(); + } + }); + } + + private JPanel getWrapShowWayPane() { + double p = TableLayout.PREFERRED; + double f = TableLayout.FILL; + double[] columnSize = {LayoutConstants.CHART_ATTR_TOMARGIN, p, p, f}; + double[] rowSize = {p, p, p, p}; + + Component[][] components = new Component[][]{ + new Component[]{null, new UILabel(Inter.getLocText("FR-Chart-Axis_labelShowway")), showWay, null}, + new Component[]{null, new UILabel(Inter.getLocText("StyleAlignment-Text_Rotation")), labelOrientationChoose, null}, + new Component[]{null, orientationSpinner, orientationBar, null}, + new Component[]{null, textAttrPane, null, null}, + }; + return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); + } + + private JPanel getIntervalShowWayPane() { + + double p = TableLayout.PREFERRED; + double f = TableLayout.FILL; + double[] columnSize = {f}; + double[] rowSize = {p, p, p}; + + Component[][] components = new Component[][]{ + new Component[]{getCombox()}, + new Component[]{getTowChoose()}, + new Component[]{getOther()} + }; + return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); + } + + private JPanel getTowChoose() { + auto.registerChangeListener(this.observerListener); + custom.registerChangeListener(this.observerListener); + customLabelSamleTime.registerChangeListener(this.observerListener); + auto.setSelected(true); + custom.setSelected(false); + customLabelSamleTime.setVisible(true); + customLabelSamleTime.setEnabled(false); + double p = TableLayout.PREFERRED; + double f = TableLayout.FILL; + double[] columnSize = {LayoutConstants.CHART_ATTR_TOMARGIN, f}; + double[] rowSize = {p, p}; + + JPanel customPane = TableLayoutHelper.createTableLayoutPane(new Component[][]{ + new Component[]{custom, customLabelSamleTime, null}, + }, new double[]{p}, new double[]{p, p, f}); + + Component[][] components = new Component[][]{ + new Component[]{null, auto,}, + new Component[]{null, customPane} + }; + return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); + } + + private JPanel getCombox() { + double p = TableLayout.PREFERRED; + double f = TableLayout.FILL; + double[] columnSize = {LayoutConstants.CHART_ATTR_TOMARGIN, p, p, f}; + double[] rowSize = {p}; + + Component[][] components = new Component[][]{ + new Component[]{null, new UILabel(Inter.getLocText("FR-Chart-Axis_labelShowway")), showWay, null} + }; + return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); + } + + private JPanel getOther() { + double p = TableLayout.PREFERRED; + double f = TableLayout.FILL; + double[] columnSize = {LayoutConstants.CHART_ATTR_TOMARGIN, p, p, f}; + double[] rowSize = {p, p, p}; + + Component[][] components = new Component[][]{ + new Component[]{null, new UILabel(Inter.getLocText("StyleAlignment-Text_Rotation")), labelOrientationChoose, null}, + new Component[]{null, orientationSpinner, orientationBar, null}, + new Component[]{null, textAttrPane, null, null}, + }; + return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); + } + + private void checkShowWay() { + if (showWayPane != null) { + this.remove(showWayPane); + } + showWay.registerChangeListener(this.observerListener); + orientationSpinner.registerChangeListener(this.observerListener); + labelOrientationChoose.registerChangeListener(this.observerListener); + if (showWay.getSelectedIndex() == LABEL_INTERVAL) { + labelPane = getIntervalShowWayPane(); + } else { + labelPane = getWrapShowWayPane(); + } + double p = TableLayout.PREFERRED; + double f = TableLayout.FILL; + double[] row = {p, p}; + double[] col = {f}; + showWayPane = TableLayoutHelper.createTableLayoutPane(new Component[][]{ + new Component[]{isLabelShow}, new Component[]{labelPane}}, row, col); + this.add(showWayPane, BorderLayout.CENTER); + this.validate(); + } + + + + private void checkOrientationField() { + if (labelOrientationChoose.getSelectedIndex() != 2) { + orientationBar.setVisible(false); + orientationSpinner.setVisible(false); + } else { + orientationBar.setVisible(true); + orientationSpinner.setVisible(true); + } + } + + private void checkPaneOnlyInterval(){ + if (showWayPane != null) { + this.remove(showWayPane); + } + showWayPane = getPanel(); + this.add(showWayPane, BorderLayout.CENTER); + this.validate(); + } + + + private JPanel getPanel() { + labelSampleChoose.registerChangeListener(this.observerListener); + customLabelSamleTime.registerChangeListener(this.observerListener); + orientationSpinner.registerChangeListener(this.observerListener); + labelOrientationChoose.registerChangeListener(this.observerListener); + double p = TableLayout.PREFERRED; + double f = TableLayout.FILL; + double[] columnSize = {LayoutConstants.CHART_ATTR_TOMARGIN, p, p, f}; + double[] rowSize = {p, p, p, p}; + + Component[][] components = new Component[][]{ + new Component[]{null,new UILabel(Inter.getLocText("ChartF-Label_Interval")), labelSampleChoose, customLabelSamleTime}, + new Component[]{null,new UILabel(Inter.getLocText("StyleAlignment-Text_Rotation")), labelOrientationChoose, null}, + new Component[]{null,orientationSpinner, orientationBar, null}, + new Component[]{null,textAttrPane, null, null}, + }; + labelPane = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); + + double[] row = {p,p}; + double[] col = {f}; + return TableLayoutHelper.createTableLayoutPane(new Component[][]{ + new Component[]{isLabelShow}, new Component[]{labelPane}}, row, col); + } + + private void checkCustomSampleField() { + if (labelSampleChoose.getSelectedIndex() == 0) { + customLabelSamleTime.setVisible(false); + } else { + customLabelSamleTime.setVisible(true); + customLabelSamleTime.setText("1"); + } + } + + + /** + * 界面标签 + */ + protected String title4PopupWindow() { + return Inter.getLocText("ChartF-Tick_Label"); + } + + private int getLabelTextOrientationIndex(TextAttr textAttr) { + if (textAttr.getAlignText() == Style.VERTICALTEXT) { + return 1; + } else if (textAttr.getRotation() != 0) { + return 2; + } else { + return 0; + } + } + + private int getLabelSampleNumber(BaseFormula formula) { + Number number = ChartBaseUtils.formula2Number(formula); + if (number != null) { + int num = number.intValue(); + return num < 1 ? 0 : 1; + } + return 0; + } + + private boolean isWrapShow(BaseFormula formula){ + Number number = ChartBaseUtils.formula2Number(formula); + return number == null; + } + + /** + * 检查 标签界面是否可用. + */ + private void checkLabelUse() { + isLabelShow.setEnabled(true); + labelPane.setVisible(isLabelShow.isSelected()); + } + + @Override + public Dimension getPreferredSize() { + if (isLabelShow.isSelected()) { + return super.getPreferredSize(); + } else { + return this.isLabelShow.getPreferredSize(); + } + } + + /** + * 更新界面内容. + */ + public void populate(Axis axis) { + if(axis.isSupportAxisLabelWrap()){ + checkShowWay(); + if (isWrapShow(axis.getLabelNumber())) { + showWay.setSelectedIndex(LABEL_WRAP); + } else { + showWay.setSelectedIndex(LABEL_INTERVAL); + boolean isAuto = getLabelSampleNumber(axis.getLabelNumber()) == 0; + auto.setSelected(isAuto); + custom.setSelected(!isAuto); + customLabelSamleTime.setText(isAuto ? "" : String.valueOf(ChartBaseUtils.formula2Number(axis.getLabelNumber()))); + customLabelSamleTime.setEnabled(!isAuto); + } + }else{ + checkPaneOnlyInterval(); + labelSampleChoose.setSelectedIndex(getLabelSampleNumber(axis.getLabelNumber())); + if (labelSampleChoose.getSelectedIndex() == 1) { + customLabelSamleTime.setText(String.valueOf(ChartBaseUtils.formula2Number(axis.getLabelNumber()))); + } + } + isLabelShow.setSelected(axis.isShowAxisLabel()); + textAttrPane.populate(axis.getTextAttr()); + labelOrientationChoose.setSelectedIndex(getLabelTextOrientationIndex(axis.getTextAttr())); + orientationBar.setValue(axis.getTextAttr().getRotation()); + orientationSpinner.setValue(axis.getTextAttr().getRotation()); + checkLabelUse(); + this.initSelfListener(this); + } + + + /** + * 保存界面属性. + */ + public void update(Axis axis) { + axis.setShowAxisLabel(isLabelShow.isSelected()); + if (isLabelShow.isSelected()) { + if(axis.isSupportAxisLabelWrap()){ + this.update4Wrap(axis); + }else{ + update4Normal(axis); + } + + TextAttr textAttr = axis.getTextAttr(); + textAttrPane.update(textAttr); + if (labelOrientationChoose.getSelectedIndex() == 0) { + textAttr.setRotation(0); + textAttr.setAlignText(Style.HORIZONTALTEXT); + } else if (labelOrientationChoose.getSelectedIndex() == 1) { + textAttr.setRotation(0); + textAttr.setAlignText(Style.VERTICALTEXT); + } else { + textAttr.setAlignText(Style.HORIZONTALTEXT); + textAttr.setRotation(Utils.objectToNumber(orientationSpinner.getValue(), false).intValue()); + } + } + } + + private void update4Normal(Axis axis){ + if (labelSampleChoose.getSelectedIndex() == 0) { + axis.setLabelIntervalNumber(BaseFormula.createFormulaBuilder().build("0")); + } else { + axis.setLabelIntervalNumber(BaseFormula.createFormulaBuilder().build(customLabelSamleTime.getText())); + } + } + + private void update4Wrap(Axis axis){ + if (showWay.getSelectedIndex() == LABEL_WRAP) { + axis.setLabelIntervalNumber(BaseFormula.createFormulaBuilder().build()); + } else if (showWay.getSelectedIndex() == LABEL_INTERVAL) { + if (auto.isSelected()) { + axis.setLabelIntervalNumber(BaseFormula.createFormulaBuilder().build("0")); + } else if (custom.isSelected()) { + axis.setLabelIntervalNumber(BaseFormula.createFormulaBuilder().build(customLabelSamleTime.getText())); + } + } + } + + /** + * 注册时间监听器 + * @param listener 观察者监听事件 + */ + public void registerChangeListener(UIObserverListener listener) { + this.observerListener = listener; + } + + private void initSelfListener(Container parentComponent) { + for (int i = 0; i < parentComponent.getComponentCount(); i++) { + Component tmpComp = parentComponent.getComponent(i); + if (tmpComp instanceof Container) { + initSelfListener((Container) tmpComp); + } + if (tmpComp instanceof UIObserver) { + ((UIObserver) tmpComp).registerChangeListener(observerListener); + } + } + } + + /** + * 是否响应事件监听 + * @return 是则返回true + */ + public boolean shouldResponseChangeListener() { + return true; + } } \ No newline at end of file diff --git a/designer_chart/src/com/fr/design/mainframe/chart/gui/style/ChartAxisTitlePane.java b/designer_chart/src/com/fr/design/mainframe/chart/gui/style/ChartAxisTitlePane.java index 469ec4b53..8348b0cba 100644 --- a/designer_chart/src/com/fr/design/mainframe/chart/gui/style/ChartAxisTitlePane.java +++ b/designer_chart/src/com/fr/design/mainframe/chart/gui/style/ChartAxisTitlePane.java @@ -1,19 +1,19 @@ package com.fr.design.mainframe.chart.gui.style; +import com.fr.base.BaseFormula; import com.fr.base.BaseUtils; -import com.fr.base.Formula; import com.fr.base.Style; import com.fr.base.Utils; import com.fr.chart.chartattr.Axis; import com.fr.chart.chartattr.Title; import com.fr.design.constants.LayoutConstants; +import com.fr.design.dialog.BasicPane; import com.fr.design.formula.TinyFormulaPane; import com.fr.design.gui.ibutton.UIButtonGroup; import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.gui.ilable.UILabel; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; -import com.fr.design.dialog.BasicPane; import com.fr.general.FRFont; import com.fr.general.Inter; import com.fr.stable.Constants; @@ -109,7 +109,7 @@ public class ChartAxisTitlePane extends BasicPane{ title.getTextAttr().setAlignText(Style.VERTICALTEXT); } if(StableUtils.canBeFormula(axisTitleContentPane.updateBean())) { - title.setTextObject(new Formula(axisTitleContentPane.updateBean())); + title.setTextObject(BaseFormula.createFormulaBuilder().build(axisTitleContentPane.updateBean())); } else { title.setTextObject(axisTitleContentPane.updateBean()); } diff --git a/designer_chart/src/com/fr/design/mainframe/chart/gui/style/DateAxisValuePane.java b/designer_chart/src/com/fr/design/mainframe/chart/gui/style/DateAxisValuePane.java index 7276ab8df..f9683e39a 100644 --- a/designer_chart/src/com/fr/design/mainframe/chart/gui/style/DateAxisValuePane.java +++ b/designer_chart/src/com/fr/design/mainframe/chart/gui/style/DateAxisValuePane.java @@ -1,360 +1,365 @@ -package com.fr.design.mainframe.chart.gui.style; - -import com.fr.base.Formula; -import com.fr.base.Utils; -import com.fr.chart.base.ChartConstants; -import com.fr.chart.chartattr.CategoryAxis; -import com.fr.design.beans.FurtherBasicBeanPane; -import com.fr.design.dialog.BasicDialog; -import com.fr.design.dialog.DialogActionAdapter; -import com.fr.design.editor.ValueEditorPane; -import com.fr.design.editor.editor.DateEditor; -import com.fr.design.editor.editor.Editor; -import com.fr.design.editor.editor.FormulaEditor; -import com.fr.design.formula.FormulaFactory; -import com.fr.design.formula.UIFormula; -import com.fr.design.gui.date.UIDatePicker; -import com.fr.design.gui.icheckbox.UICheckBox; -import com.fr.design.gui.icombobox.UIComboBox; -import com.fr.design.gui.itextfield.UITextField; -import com.fr.design.layout.FRGUIPaneFactory; -import com.fr.design.layout.TableLayout; -import com.fr.design.layout.TableLayoutHelper; -import com.fr.design.style.FormatBox; -import com.fr.general.DateUtils; -import com.fr.general.FRLogger; -import com.fr.general.Inter; -import com.fr.stable.StringUtils; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.*; -import java.text.ParseException; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; -import java.util.regex.Pattern; - -/** - * 属性表, 坐标轴, 日期范围定义界面 - * @author kunsnat E-mail:kunsnat@gmail.com - * @version 创建时间:2013-1-4 上午10:25:15 - */ -public class DateAxisValuePane extends FurtherBasicBeanPane{ - - private static String[] TYPES = new String[]{ - Inter.getLocText("Year"), Inter.getLocText("Month"), Inter.getLocText("Sun"), - Inter.getLocText("Sche-Hour"), Inter.getLocText("Sche-Minute"), - Inter.getLocText("Sche-Second") - }; - - private static Map VALUES = new HashMap(); - static { - VALUES.put(Inter.getLocText("Year"), ChartConstants.YEAR_TYPE); - VALUES.put(Inter.getLocText("Month"), ChartConstants.MONTH_TYPE); - VALUES.put(Inter.getLocText("Sun"), ChartConstants.DAY_TYPE); - VALUES.put(Inter.getLocText("Sche-Hour"), ChartConstants.HOUR_TYPE); - VALUES.put(Inter.getLocText("Sche-Minute"), ChartConstants.MINUTE_TYPE); - VALUES.put(Inter.getLocText("Sche-Second"), ChartConstants.SECOND_TYPE); - } - - private static Map INTS = new HashMap(); - static { - INTS.put(ChartConstants.YEAR_TYPE, Inter.getLocText("Year")); - INTS.put(ChartConstants.MONTH_TYPE, Inter.getLocText("Month")); - INTS.put(ChartConstants.DAY_TYPE, Inter.getLocText("Sun")); - INTS.put(ChartConstants.HOUR_TYPE, Inter.getLocText("Sche-Hour")); - INTS.put(ChartConstants.MINUTE_TYPE, Inter.getLocText("Sche-Minute")); - INTS.put(ChartConstants.SECOND_TYPE, Inter.getLocText("Sche-Second")); - } - - // 最大最小值 - private UICheckBox maxCheckBox; - private ValueEditorPane maxValueField; - private UICheckBox minCheckBox; - private ValueEditorPane minValueField; - - private UICheckBox mainTickBox; - private UITextField mainUnitField; - private UIComboBox mainType; - - private FormatBox formatBox; - public FormatBox getFormatBox() { - return this.formatBox; - } - - public DateAxisValuePane() { - this.initComponents(); - } - - private void initMin() { - // 最小值. - minCheckBox = new UICheckBox(Inter.getLocText("Min_Value")); - Date tmp = null; - DateEditor dateEditor = new DateEditor(tmp, true, Inter.getLocText("Date"), UIDatePicker.STYLE_CN_DATETIME1); - Editor formulaEditor = new FormulaEditor(Inter.getLocText("Parameter-Formula")); - Editor[] editor = new Editor[]{dateEditor, formulaEditor}; - minValueField = new ValueEditorPane(editor); - minValueField.setEnabled(false); - minCheckBox.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - checkBoxUse(); - } - }); - } - - private void initMax() { - // 最大值 - maxCheckBox = new UICheckBox(Inter.getLocText("Max_Value")); - Date tmp = null; - DateEditor dateEditor = new DateEditor(tmp, true, Inter.getLocText("Date"), UIDatePicker.STYLE_CN_DATETIME1); - Editor formulaEditor = new FormulaEditor(Inter.getLocText("Parameter-Formula")); - Editor[] editor = new Editor[]{dateEditor, formulaEditor}; - maxValueField = new ValueEditorPane(editor); - maxValueField.setEnabled(false); - maxCheckBox.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - checkBoxUse(); - } - }); - } - - private void initMain() { - // 主要刻度单位 - mainTickBox = new UICheckBox(Inter.getLocText("MainGraduationUnit")); - mainUnitField = new UITextField(); - mainUnitField.setPreferredSize(new Dimension(30, 20)); - mainUnitField.setEditable(false); - mainType = new UIComboBox(TYPES); - mainType.setEnabled(false); - - mainTickBox.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - checkBoxUse(); - } - }); - - addListener(mainTickBox, mainUnitField); - } - - private void initComponents() { - setLayout(FRGUIPaneFactory.createBorderLayout()); - formatBox = new FormatBox(); - JPanel pane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane(); - add(pane, BorderLayout.NORTH); - - initMin(); - initMax(); - initMain(); - - JPanel mainTickPane = new JPanel(); - mainTickPane.setLayout(new FlowLayout(FlowLayout.CENTER, 4, 0)); - - mainTickPane.add(mainUnitField); - mainTickPane.add(mainType); - - JPanel secTickPane = new JPanel(); - secTickPane.setLayout(new FlowLayout(FlowLayout.CENTER, 4, 0)); - - double p = TableLayout.PREFERRED; - double f = TableLayout.FILL; - double[] rowSize = {p, p, p}; - double[] columnSize = {p, f}; - Component[][] maxMin = { - {minCheckBox, minValueField}, - {maxCheckBox, maxValueField}, - - }; - JPanel maxMinPane = TableLayoutHelper.createTableLayoutPane(maxMin, rowSize, columnSize); - Component[][] components = { - {maxMinPane, null}, - {mainTickBox, mainTickPane} - - }; - pane.add(TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize)); - } - - private void addListener(final UICheckBox box, final UITextField textField) { - textField.addMouseListener(new MouseAdapter() { - public void mousePressed(MouseEvent e) { - if (box.isSelected()) { - showFormulaPane(textField); - } - } - }); - textField.addKeyListener(new KeyAdapter() { - public void keyTyped(KeyEvent e) { - if (box.isSelected()) { - e.consume(); - showFormulaPane(textField); - } - } - }); - } - - private void showFormulaPane(final UITextField jTextField) { - final UIFormula formulaPane = FormulaFactory.createFormulaPane(); - formulaPane.populate(new Formula(jTextField.getText())); - BasicDialog dlg = formulaPane.showLargeWindow(SwingUtilities.getWindowAncestor(DateAxisValuePane.this), new DialogActionAdapter() { - public void doOk() { - jTextField.setText(Utils.objectToString(formulaPane.update())); - } - }); - dlg.setVisible(true); - } - - private void populateMain(CategoryAxis axis) { - if (axis.isCustomMainUnit() && axis.getMainUnit() != null) { - mainTickBox.setSelected(true); - mainUnitField.setText(Utils.objectToString(axis.getMainUnit())); - mainType.setSelectedItem(INTS.get(axis.getMainType())); - } - } - - private void updateMain(CategoryAxis axis) { - if (mainTickBox.isSelected() && StringUtils.isNotEmpty(mainUnitField.getText())) { - axis.setCustomMainUnit(true); - axis.setMainUnit(new Formula(mainUnitField.getText())); - axis.setMainType(VALUES.get(mainType.getSelectedItem())); - } else { - axis.setCustomMainUnit(false); - } - } - - @Override - public boolean accept(Object ob) { - return ob instanceof CategoryAxis; - } - - @Override - public void reset() { - - } - - @Override - public String title4PopupWindow() { - return Inter.getLocText("Chart_Date_Axis"); - } - - private void checkBoxUse() { - minValueField.setEnabled(minCheckBox.isSelected()); - maxValueField.setEnabled(maxCheckBox.isSelected()); - if(minValueField.getCurrentEditor() instanceof FormulaEditor){ - FormulaEditor tmpEditor = (FormulaEditor)minValueField.getCurrentEditor(); - tmpEditor.enableEditor(minCheckBox.isSelected()); - } - - if(maxValueField.getCurrentEditor() instanceof FormulaEditor){ - FormulaEditor tmpEditor = (FormulaEditor)maxValueField.getCurrentEditor(); - tmpEditor.enableEditor(maxCheckBox.isSelected()); - } - - mainType.setEnabled(mainTickBox.isSelected()); - mainUnitField.setEnabled(mainTickBox.isSelected()); - } - - @Override - public void populateBean(CategoryAxis axis) { - if (axis == null) { - return; - } - if (!axis.isDate()) { - return; - } - // 最小值 - if (axis.isCustomMinValue() && axis.getMinValue() != null) { - minCheckBox.setSelected(true); - String dateStr = axis.getMinValue().getPureContent(); - if(!isDateForm(dateStr)){ - minValueField.populate(axis.getMinValue()); - }else{ - Date tmpDate = getDateFromFormula(axis.getMinValue()); - minValueField.populate(tmpDate); - } - - } - - - // 最大值 - if (axis.isCustomMaxValue() && axis.getMaxValue() != null) { - maxCheckBox.setSelected(true); - String dateStr = axis.getMaxValue().getPureContent(); - if(!isDateForm(dateStr)){ - maxValueField.populate(axis.getMaxValue()); - }else{ - Date tmpDate = getDateFromFormula(axis.getMaxValue()); - maxValueField.populate(tmpDate); - } - } - populateMain(axis); - - checkBoxUse(); - } - - private boolean isDateForm(String form){ - form = Pattern.compile("\"").matcher(form).replaceAll(StringUtils.EMPTY); - //全部是数字的话直接返回,string2Date会把全部是数字也会转化成日期 - if(form.matches("^[+-]?[0-9]*[0-9]$")){ - return false; - } - return (DateUtils.string2Date(form, true) != null); - } - - public void updateBean(CategoryAxis axis) { - updateMain(axis); - //最小值 - if (minCheckBox.isSelected()) { - if(minValueField.getCurrentEditor() instanceof FormulaEditor){ - Formula min = (Formula)minValueField.update(); - axis.setMinValue(min); - axis.setCustomMinValue(!StringUtils.isEmpty(min.getPureContent())); - }else{ - Date datetmp = (Date)minValueField.update(); - DateEditor dateEditor = (DateEditor)minValueField.getCurrentEditor(); - String dateString = dateEditor.getUIDatePickerFormat().format(datetmp); - axis.setCustomMinValue(!StringUtils.isEmpty(dateString)); - axis.setMinValue(new Formula(dateString)); - } - } else { - axis.setCustomMinValue(false); - } - - //最大值 - if (maxCheckBox.isSelected()) { - if(maxValueField.getCurrentEditor() instanceof FormulaEditor){ - Formula max = (Formula)maxValueField.update(); - axis.setMaxValue(max); - axis.setCustomMaxValue(!StringUtils.isEmpty(max.getPureContent())); - }else{ - Date datetmp = (Date)maxValueField.update(); - DateEditor dateEditor = (DateEditor)maxValueField.getCurrentEditor(); - String dateString = dateEditor.getUIDatePickerFormat().format(datetmp); - axis.setCustomMaxValue(!StringUtils.isEmpty(dateString)); - axis.setMaxValue(new Formula(dateString)); - } - } else { - axis.setCustomMaxValue(false); - } - - this.checkBoxUse(); - } - - @Override - public CategoryAxis updateBean() { - return null; - } - - //将从formula读出来的内容转化为指定格式的日期 - private static final Date getDateFromFormula(Formula dateFormula){ - String dateStr = dateFormula.getPureContent(); - dateStr = Pattern.compile("\"").matcher(dateStr).replaceAll(StringUtils.EMPTY); - Date toDate = DateUtils.string2Date(dateStr, true); - try { - String tmp = DateUtils.getDate2LStr(toDate); - toDate = DateUtils.DATETIMEFORMAT2.parse(tmp); - } catch (ParseException e) { - FRLogger.getLogger().error(Inter.getLocText("Cannot_Get_Date")); - } - return toDate; - } +package com.fr.design.mainframe.chart.gui.style; + +import com.fr.base.BaseFormula; +import com.fr.base.Utils; +import com.fr.chart.base.ChartConstants; +import com.fr.chart.chartattr.CategoryAxis; +import com.fr.design.beans.FurtherBasicBeanPane; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.editor.ValueEditorPane; +import com.fr.design.editor.editor.DateEditor; +import com.fr.design.editor.editor.Editor; +import com.fr.design.editor.editor.FormulaEditor; +import com.fr.design.formula.FormulaFactory; +import com.fr.design.formula.UIFormula; +import com.fr.design.gui.date.UIDatePicker; +import com.fr.design.gui.icheckbox.UICheckBox; +import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.gui.itextfield.UITextField; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.layout.TableLayout; +import com.fr.design.layout.TableLayoutHelper; +import com.fr.design.style.FormatBox; +import com.fr.general.DateUtils; +import com.fr.general.FRLogger; +import com.fr.general.Inter; +import com.fr.stable.StringUtils; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.text.ParseException; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Pattern; + +/** + * 属性表, 坐标轴, 日期范围定义界面 + * @author kunsnat E-mail:kunsnat@gmail.com + * @version 创建时间:2013-1-4 上午10:25:15 + */ +public class DateAxisValuePane extends FurtherBasicBeanPane{ + + private static String[] TYPES = new String[]{ + Inter.getLocText("Year"), Inter.getLocText("Month"), Inter.getLocText("Sun"), + Inter.getLocText("Sche-Hour"), Inter.getLocText("Sche-Minute"), + Inter.getLocText("Sche-Second") + }; + + private static Map VALUES = new HashMap(); + static { + VALUES.put(Inter.getLocText("Year"), ChartConstants.YEAR_TYPE); + VALUES.put(Inter.getLocText("Month"), ChartConstants.MONTH_TYPE); + VALUES.put(Inter.getLocText("Sun"), ChartConstants.DAY_TYPE); + VALUES.put(Inter.getLocText("Sche-Hour"), ChartConstants.HOUR_TYPE); + VALUES.put(Inter.getLocText("Sche-Minute"), ChartConstants.MINUTE_TYPE); + VALUES.put(Inter.getLocText("Sche-Second"), ChartConstants.SECOND_TYPE); + } + + private static Map INTS = new HashMap(); + static { + INTS.put(ChartConstants.YEAR_TYPE, Inter.getLocText("Year")); + INTS.put(ChartConstants.MONTH_TYPE, Inter.getLocText("Month")); + INTS.put(ChartConstants.DAY_TYPE, Inter.getLocText("Sun")); + INTS.put(ChartConstants.HOUR_TYPE, Inter.getLocText("Sche-Hour")); + INTS.put(ChartConstants.MINUTE_TYPE, Inter.getLocText("Sche-Minute")); + INTS.put(ChartConstants.SECOND_TYPE, Inter.getLocText("Sche-Second")); + } + + // 最大最小值 + private UICheckBox maxCheckBox; + private ValueEditorPane maxValueField; + private UICheckBox minCheckBox; + private ValueEditorPane minValueField; + + private UICheckBox mainTickBox; + private UITextField mainUnitField; + private UIComboBox mainType; + + private FormatBox formatBox; + public FormatBox getFormatBox() { + return this.formatBox; + } + + public DateAxisValuePane() { + this.initComponents(); + } + + private void initMin() { + // 最小值. + minCheckBox = new UICheckBox(Inter.getLocText("Min_Value")); + Date tmp = null; + DateEditor dateEditor = new DateEditor(tmp, true, Inter.getLocText("Date"), UIDatePicker.STYLE_CN_DATETIME1); + Editor formulaEditor = new FormulaEditor(Inter.getLocText("Parameter-Formula")); + Editor[] editor = new Editor[]{dateEditor, formulaEditor}; + minValueField = new ValueEditorPane(editor); + minValueField.setEnabled(false); + minCheckBox.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + checkBoxUse(); + } + }); + } + + private void initMax() { + // 最大值 + maxCheckBox = new UICheckBox(Inter.getLocText("Max_Value")); + Date tmp = null; + DateEditor dateEditor = new DateEditor(tmp, true, Inter.getLocText("Date"), UIDatePicker.STYLE_CN_DATETIME1); + Editor formulaEditor = new FormulaEditor(Inter.getLocText("Parameter-Formula")); + Editor[] editor = new Editor[]{dateEditor, formulaEditor}; + maxValueField = new ValueEditorPane(editor); + maxValueField.setEnabled(false); + maxCheckBox.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + checkBoxUse(); + } + }); + } + + private void initMain() { + // 主要刻度单位 + mainTickBox = new UICheckBox(Inter.getLocText("MainGraduationUnit")); + mainUnitField = new UITextField(); + mainUnitField.setPreferredSize(new Dimension(30, 20)); + mainUnitField.setEditable(false); + mainType = new UIComboBox(TYPES); + mainType.setEnabled(false); + + mainTickBox.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + checkBoxUse(); + } + }); + + addListener(mainTickBox, mainUnitField); + } + + private void initComponents() { + setLayout(FRGUIPaneFactory.createBorderLayout()); + formatBox = new FormatBox(); + JPanel pane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane(); + add(pane, BorderLayout.NORTH); + + initMin(); + initMax(); + initMain(); + + JPanel mainTickPane = new JPanel(); + mainTickPane.setLayout(new FlowLayout(FlowLayout.CENTER, 4, 0)); + + mainTickPane.add(mainUnitField); + mainTickPane.add(mainType); + + JPanel secTickPane = new JPanel(); + secTickPane.setLayout(new FlowLayout(FlowLayout.CENTER, 4, 0)); + + double p = TableLayout.PREFERRED; + double f = TableLayout.FILL; + double[] rowSize = {p, p, p}; + double[] columnSize = {p, f}; + Component[][] maxMin = { + {minCheckBox, minValueField}, + {maxCheckBox, maxValueField}, + + }; + JPanel maxMinPane = TableLayoutHelper.createTableLayoutPane(maxMin, rowSize, columnSize); + Component[][] components = { + {maxMinPane, null}, + {mainTickBox, mainTickPane} + + }; + pane.add(TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize)); + } + + private void addListener(final UICheckBox box, final UITextField textField) { + textField.addMouseListener(new MouseAdapter() { + public void mousePressed(MouseEvent e) { + if (box.isSelected()) { + showFormulaPane(textField); + } + } + }); + textField.addKeyListener(new KeyAdapter() { + public void keyTyped(KeyEvent e) { + if (box.isSelected()) { + e.consume(); + showFormulaPane(textField); + } + } + }); + } + + private void showFormulaPane(final UITextField jTextField) { + final UIFormula formulaPane = FormulaFactory.createFormulaPane(); + formulaPane.populate(BaseFormula.createFormulaBuilder().build(jTextField.getText())); + BasicDialog dlg = formulaPane.showLargeWindow(SwingUtilities.getWindowAncestor(DateAxisValuePane.this), new DialogActionAdapter() { + public void doOk() { + jTextField.setText(Utils.objectToString(formulaPane.update())); + } + }); + dlg.setVisible(true); + } + + private void populateMain(CategoryAxis axis) { + if (axis.isCustomMainUnit() && axis.getMainUnit() != null) { + mainTickBox.setSelected(true); + mainUnitField.setText(Utils.objectToString(axis.getMainUnit())); + mainType.setSelectedItem(INTS.get(axis.getMainType())); + } + } + + private void updateMain(CategoryAxis axis) { + if (mainTickBox.isSelected() && StringUtils.isNotEmpty(mainUnitField.getText())) { + axis.setCustomMainUnit(true); + axis.setMainUnit(BaseFormula.createFormulaBuilder().build(mainUnitField.getText())); + axis.setMainType(VALUES.get(mainType.getSelectedItem())); + } else { + axis.setCustomMainUnit(false); + } + } + + @Override + public boolean accept(Object ob) { + return ob instanceof CategoryAxis; + } + + @Override + public void reset() { + + } + + @Override + public String title4PopupWindow() { + return Inter.getLocText("Chart_Date_Axis"); + } + + private void checkBoxUse() { + minValueField.setEnabled(minCheckBox.isSelected()); + maxValueField.setEnabled(maxCheckBox.isSelected()); + if(minValueField.getCurrentEditor() instanceof FormulaEditor){ + FormulaEditor tmpEditor = (FormulaEditor)minValueField.getCurrentEditor(); + tmpEditor.enableEditor(minCheckBox.isSelected()); + } + + if(maxValueField.getCurrentEditor() instanceof FormulaEditor){ + FormulaEditor tmpEditor = (FormulaEditor)maxValueField.getCurrentEditor(); + tmpEditor.enableEditor(maxCheckBox.isSelected()); + } + + mainType.setEnabled(mainTickBox.isSelected()); + mainUnitField.setEnabled(mainTickBox.isSelected()); + } + + @Override + public void populateBean(CategoryAxis axis) { + if (axis == null) { + return; + } + if (!axis.isDate()) { + return; + } + // 最小值 + if (axis.isCustomMinValue() && axis.getMinValue() != null) { + minCheckBox.setSelected(true); + String dateStr = axis.getMinValue().getPureContent(); + if(!isDateForm(dateStr)){ + minValueField.populate(axis.getMinValue()); + }else{ + Date tmpDate = getDateFromFormula(axis.getMinValue()); + minValueField.populate(tmpDate); + } + + } + + + // 最大值 + if (axis.isCustomMaxValue() && axis.getMaxValue() != null) { + maxCheckBox.setSelected(true); + String dateStr = axis.getMaxValue().getPureContent(); + if(!isDateForm(dateStr)){ + maxValueField.populate(axis.getMaxValue()); + }else{ + Date tmpDate = getDateFromFormula(axis.getMaxValue()); + maxValueField.populate(tmpDate); + } + } + populateMain(axis); + + checkBoxUse(); + } + + private boolean isDateForm(String form){ + form = Pattern.compile("\"").matcher(form).replaceAll(StringUtils.EMPTY); + //全部是数字的话直接返回,string2Date会把全部是数字也会转化成日期 + if(form.matches("^[+-]?[0-9]*[0-9]$")){ + return false; + } + return (DateUtils.string2Date(form, true) != null); + } + + public void updateBean(CategoryAxis axis) { + updateMain(axis); + //最小值 + if (minCheckBox.isSelected()) { + if(minValueField.getCurrentEditor() instanceof FormulaEditor){ + BaseFormula min = (BaseFormula) minValueField.update(); + axis.setMinValue(min); + axis.setCustomMinValue(!StringUtils.isEmpty(min.getPureContent())); + }else{ + Date datetmp = (Date)minValueField.update(); + DateEditor dateEditor = (DateEditor)minValueField.getCurrentEditor(); + String dateString = dateEditor.getUIDatePickerFormat().format(datetmp); + axis.setCustomMinValue(!StringUtils.isEmpty(dateString)); + axis.setMinValue(BaseFormula.createFormulaBuilder().build(dateString)); + } + } else { + axis.setCustomMinValue(false); + } + + //最大值 + if (maxCheckBox.isSelected()) { + if(maxValueField.getCurrentEditor() instanceof FormulaEditor){ + BaseFormula max = (BaseFormula) maxValueField.update(); + axis.setMaxValue(max); + axis.setCustomMaxValue(!StringUtils.isEmpty(max.getPureContent())); + }else{ + Date datetmp = (Date)maxValueField.update(); + DateEditor dateEditor = (DateEditor)maxValueField.getCurrentEditor(); + String dateString = dateEditor.getUIDatePickerFormat().format(datetmp); + axis.setCustomMaxValue(!StringUtils.isEmpty(dateString)); + axis.setMaxValue(BaseFormula.createFormulaBuilder().build(dateString)); + } + } else { + axis.setCustomMaxValue(false); + } + + this.checkBoxUse(); + } + + @Override + public CategoryAxis updateBean() { + return null; + } + + //将从formula读出来的内容转化为指定格式的日期 + private static final Date getDateFromFormula(BaseFormula dateFormula){ + String dateStr = dateFormula.getPureContent(); + dateStr = Pattern.compile("\"").matcher(dateStr).replaceAll(StringUtils.EMPTY); + Date toDate = DateUtils.string2Date(dateStr, true); + try { + String tmp = DateUtils.getDate2LStr(toDate); + toDate = DateUtils.DATETIMEFORMAT2.parse(tmp); + } catch (ParseException e) { + FRLogger.getLogger().error(Inter.getLocText("Cannot_Get_Date")); + } + return toDate; + } } \ No newline at end of file diff --git a/designer_chart/src/com/fr/design/mainframe/chart/gui/style/axis/ChartValuePane.java b/designer_chart/src/com/fr/design/mainframe/chart/gui/style/axis/ChartValuePane.java index f62be44fb..602e7ddca 100644 --- a/designer_chart/src/com/fr/design/mainframe/chart/gui/style/axis/ChartValuePane.java +++ b/designer_chart/src/com/fr/design/mainframe/chart/gui/style/axis/ChartValuePane.java @@ -1,6 +1,6 @@ package com.fr.design.mainframe.chart.gui.style.axis; -import com.fr.base.Formula; +import com.fr.base.BaseFormula; import com.fr.base.Utils; import com.fr.chart.base.ChartBaseUtils; import com.fr.chart.base.ChartConstants; @@ -280,11 +280,11 @@ public class ChartValuePane extends ChartAxisUsePane{ numberAxis.setLogBase(null); } else { numberAxis.setLog(true); - Formula formula = new Formula(increment); + BaseFormula formula = BaseFormula.createFormulaBuilder().build(increment); Number number = ChartBaseUtils.formula2Number(formula); // 界面处理防止 遇到 对数增量为小于1的值. if (number != null && number.doubleValue() <= 1.0) { - numberAxis.setLogBase(new Formula("2")); + numberAxis.setLogBase(BaseFormula.createFormulaBuilder().build("2")); } else { numberAxis.setLogBase(formula); } diff --git a/designer_chart/src/com/fr/design/mainframe/chart/gui/style/series/UIColorPickerPane.java b/designer_chart/src/com/fr/design/mainframe/chart/gui/style/series/UIColorPickerPane.java index 945fd4d5e..7beb17709 100644 --- a/designer_chart/src/com/fr/design/mainframe/chart/gui/style/series/UIColorPickerPane.java +++ b/designer_chart/src/com/fr/design/mainframe/chart/gui/style/series/UIColorPickerPane.java @@ -1,6 +1,6 @@ package com.fr.design.mainframe.chart.gui.style.series; -import com.fr.base.Formula; +import com.fr.base.BaseFormula; import com.fr.chart.base.AreaColor; import com.fr.chart.base.ChartBaseUtils; import com.fr.chart.chartglyph.MapHotAreaColor; @@ -465,7 +465,7 @@ public class UIColorPickerPane extends BasicPane implements UIObserver { private class TextFieldGroupPane extends JPanel { private static final long serialVersionUID = -8390474551829486013L; - public void refreshTextGroupPane(Formula[] values) { + public void refreshTextGroupPane(BaseFormula[] values) { if (values.length == textFieldList.size()) { for (int i = 0; i < textFieldList.size(); i++) { @@ -519,13 +519,13 @@ public class UIColorPickerPane extends BasicPane implements UIObserver { if(i == size - 1) { backValue = -Double.MAX_VALUE; } else { - Number backNumber = ChartBaseUtils.formula2Number(new Formula(getValue4Index(i+1))); + Number backNumber = ChartBaseUtils.formula2Number(BaseFormula.createFormulaBuilder().build(getValue4Index(i+1))); if(backNumber != null){ backValue = backNumber.doubleValue(); } } - Number number = ChartBaseUtils.formula2Number(new Formula(getValue4Index(i))); + Number number = ChartBaseUtils.formula2Number(BaseFormula.createFormulaBuilder().build(getValue4Index(i))); if(number != null) { double value = number.doubleValue(); @@ -633,7 +633,7 @@ public class UIColorPickerPane extends BasicPane implements UIObserver { * @param colorArray 颜色值 * @param valueArray 值区间 */ - public void refreshGroupPane(Color[] colorArray, Formula[] valueArray) { + public void refreshGroupPane(Color[] colorArray, BaseFormula[] valueArray) { colorGroup.refreshColorGroupPane(colorArray); textGroup.refreshTextGroupPane(valueArray); @@ -657,7 +657,7 @@ public class UIColorPickerPane extends BasicPane implements UIObserver { UIColorPickerPane.this.add(textGroup); UIColorPickerPane.this.add(colorGroup); Color[] colors = hotAreaColor.initColor(); - Formula[] values = hotAreaColor.initValues(); + BaseFormula[] values = hotAreaColor.initValues(); refreshGroupPane(colors, values); this.initContainerLister(); regionNumPane.populateBean(value); @@ -686,7 +686,7 @@ public class UIColorPickerPane extends BasicPane implements UIObserver { } hotAreaColor.clearColor(); Color[] colors = getColors4Custom(fillStyleCombox.getSelectObject(), regionNumPane.updateBean().intValue()); - Formula[] value = getValueArray(regionNumPane.updateBean().intValue()); + BaseFormula[] value = getValueArray(regionNumPane.updateBean().intValue()); for (int i = 0; i < colors.length; i++) { hotAreaColor.addAreaColor(new AreaColor(value[i], value[i + 1], colors[i])); @@ -705,7 +705,7 @@ public class UIColorPickerPane extends BasicPane implements UIObserver { if(StringUtils.isEmpty(getValue4Index(i))){ return false; } - Number number = ChartBaseUtils.formula2Number(new Formula(getValue4Index(i))); + Number number = ChartBaseUtils.formula2Number(BaseFormula.createFormulaBuilder().build(getValue4Index(i))); if(number != null) { double value = number.doubleValue(); if(value > maxValue) { @@ -739,13 +739,13 @@ public class UIColorPickerPane extends BasicPane implements UIObserver { return ChartBaseUtils.createColorsWithHSB(color, sum); } - private Formula[] getValueArray(int count) { - Formula[] valueArray = new Formula[count + 1]; + private BaseFormula[] getValueArray(int count) { + BaseFormula[] valueArray = new BaseFormula[count + 1]; for (int i = 0; i < valueArray.length; i++) { if (i >= textFieldList.size()) { - valueArray[i] = new Formula(new Double((count + 1 - i) * VALUE).toString()); + valueArray[i] = BaseFormula.createFormulaBuilder().build((count + 1 - i) * VALUE); } else { - valueArray[i] = new Formula(getValue4Index(i)); + valueArray[i] = BaseFormula.createFormulaBuilder().build(getValue4Index(i)); } } return valueArray; diff --git a/designer_chart/src/com/fr/design/mainframe/chart/gui/style/title/ChartTitlePane.java b/designer_chart/src/com/fr/design/mainframe/chart/gui/style/title/ChartTitlePane.java index 247e17ee5..bbd10ed4d 100644 --- a/designer_chart/src/com/fr/design/mainframe/chart/gui/style/title/ChartTitlePane.java +++ b/designer_chart/src/com/fr/design/mainframe/chart/gui/style/title/ChartTitlePane.java @@ -1,195 +1,191 @@ -package com.fr.design.mainframe.chart.gui.style.title; - - -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.Icon; -import javax.swing.JPanel; -import javax.swing.JSeparator; - -import com.fr.base.BaseUtils; -import com.fr.base.Formula; -import com.fr.base.Utils; -import com.fr.chart.base.TextAttr; -import com.fr.chart.chartattr.Chart; -import com.fr.chart.chartattr.Title; -import com.fr.design.constants.LayoutConstants; -import com.fr.design.formula.TinyFormulaPane; -import com.fr.design.gui.ibutton.UIButtonGroup; -import com.fr.design.gui.icheckbox.UICheckBox; -import com.fr.design.gui.ilable.BoldFontTextLabel; -import com.fr.design.layout.TableLayout; -import com.fr.design.layout.TableLayoutHelper; -import com.fr.design.mainframe.chart.PaneTitleConstants; -import com.fr.design.mainframe.chart.gui.style.ChartBackgroundNoImagePane; -import com.fr.design.mainframe.chart.gui.style.ChartBorderPane; -import com.fr.design.mainframe.chart.gui.style.ChartTextAttrPane; -import com.fr.design.dialog.BasicScrollPane; -import com.fr.general.Inter; -import com.fr.stable.Constants; -import com.fr.stable.StableUtils; -import com.fr.stable.StringUtils; - -public class ChartTitlePane extends BasicScrollPane { - private static final long serialVersionUID = 5748881235830708722L; - private UICheckBox isTitleVisable; - - private TinyFormulaPane titleContent; - private ChartTextAttrPane textAttrPane; - private UIButtonGroup alignmentPane; - - private JPanel chartDefaultAttrPane; - private ChartBorderPane borderPane; - private ChartBackgroundNoImagePane backgroundPane; - - private JPanel titlePane; - - private class ContentPane extends JPanel { - private static final long serialVersionUID = -6455600016731592455L; - - public ContentPane() { - initComponents(); - } - - private void initComponents() { - isTitleVisable = new UICheckBox(Inter.getLocText("Chart_Title_Is_Visible")); - titlePane = createTitlePane(); - - double p = TableLayout.PREFERRED; - double f = TableLayout.FILL; - double[] columnSize = {f}; - double[] rowSize = {p, p}; - Component[][] components = new Component[][]{ - new Component[]{isTitleVisable}, - new Component[]{titlePane} - } ; - - JPanel panel = TableLayoutHelper.createTableLayoutPane(components,rowSize,columnSize); - this.setLayout(new BorderLayout()); - this.add(panel,BorderLayout.CENTER); - - isTitleVisable.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - checkTitlePaneUse(); - } - }); - } - } - - private JPanel createTitlePane(){ - borderPane = new ChartBorderPane(); - backgroundPane = new ChartBackgroundNoImagePane(); - chartDefaultAttrPane = createDefaultAttrPane(); - - double p = TableLayout.PREFERRED; - double f = TableLayout.FILL; - double[] columnSize = {p, f}; - double[] rowSize = {p,p,p,p,p}; - Component[][] components = new Component[][]{ - new Component[]{chartDefaultAttrPane,null}, - new Component[]{new JSeparator(),null}, - new Component[]{borderPane,null}, - new Component[]{backgroundPane,null} - } ; - - return TableLayoutHelper.createTableLayoutPane(components,rowSize,columnSize); - } - - private JPanel createDefaultAttrPane(){ - titleContent = new TinyFormulaPane(); - textAttrPane = new ChartTextAttrPane(); - Icon[] alignmentIconArray = {BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_left_normal.png"), - BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_center_normal.png"), - BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_right_normal.png")}; - Integer[] alignment = new Integer[]{Constants.LEFT, Constants.CENTER, Constants.RIGHT}; - alignmentPane = new UIButtonGroup(alignmentIconArray, alignment); - - double p = TableLayout.PREFERRED; - double f = TableLayout.FILL; - double[] columnSize = {LayoutConstants.CHART_ATTR_TOMARGIN, p, f}; - double[] rowSize = {p, p,p}; - Component[][] components = new Component[][]{ - new Component[]{null,titleContent,null}, - new Component[]{null,textAttrPane,null}, - new Component[]{null,new BoldFontTextLabel(Inter.getLocText("Alignment-Style") + ":"),alignmentPane} , - } ; - - return TableLayoutHelper.createTableLayoutPane(components,rowSize,columnSize); - } - - // 检查标题界面是否可用. - private void checkTitlePaneUse() { - isTitleVisable.setVisible(true); - isTitleVisable.setEnabled(true); - titlePane.setVisible(isTitleVisable.isSelected()); - this.repaint(); - } - - /** - * 弹出框的界面标题 - * @return 界面标题 - */ - public String title4PopupWindow() { - return PaneTitleConstants.CHART_STYLE_TITLE_TITLE; - } - - @Override - protected JPanel createContentPane() { - return new ContentPane(); - } - - @Override - public void populateBean(Chart chart) { - Title title = chart.getTitle(); - if (title == null) { - return; - } - isTitleVisable.setSelected(title.isTitleVisible()); - if (title.getTextObject() instanceof Formula) { - titleContent.populateBean(((Formula) title.getTextObject()).getContent()); - } else { - titleContent.populateBean(Utils.objectToString(title.getTextObject())); - } - alignmentPane.setSelectedItem(title.getPosition()); - TextAttr textAttr = title.getTextAttr(); - if (textAttr == null) { - textAttr = new TextAttr(); - } - textAttrPane.populate(textAttr); - borderPane.populate(title); - backgroundPane.populate(title); - - checkTitlePaneUse(); - } - - @Override - public void updateBean(Chart chart) { - if (chart == null) { - chart = new Chart(); - } - Title title = chart.getTitle(); - if (title == null) { - title = new Title(StringUtils.EMPTY); - } - title.setTitleVisible(isTitleVisable.isSelected()); - String titleString = titleContent.updateBean(); - Object titleObj; - if (StableUtils.maybeFormula(titleString)) { - titleObj = new Formula(titleString); - } else { - titleObj = titleString; - } - title.setTextObject(titleObj); - TextAttr textAttr = title.getTextAttr(); - if (textAttr == null) { - textAttr = new TextAttr(); - } - title.setPosition(alignmentPane.getSelectedItem()); - textAttrPane.update(textAttr); - borderPane.update(title); - backgroundPane.update(title); - } +package com.fr.design.mainframe.chart.gui.style.title; + + +import com.fr.base.BaseFormula; +import com.fr.base.BaseUtils; +import com.fr.base.Utils; +import com.fr.chart.base.TextAttr; +import com.fr.chart.chartattr.Chart; +import com.fr.chart.chartattr.Title; +import com.fr.design.constants.LayoutConstants; +import com.fr.design.dialog.BasicScrollPane; +import com.fr.design.formula.TinyFormulaPane; +import com.fr.design.gui.ibutton.UIButtonGroup; +import com.fr.design.gui.icheckbox.UICheckBox; +import com.fr.design.gui.ilable.BoldFontTextLabel; +import com.fr.design.layout.TableLayout; +import com.fr.design.layout.TableLayoutHelper; +import com.fr.design.mainframe.chart.PaneTitleConstants; +import com.fr.design.mainframe.chart.gui.style.ChartBackgroundNoImagePane; +import com.fr.design.mainframe.chart.gui.style.ChartBorderPane; +import com.fr.design.mainframe.chart.gui.style.ChartTextAttrPane; +import com.fr.general.Inter; +import com.fr.stable.Constants; +import com.fr.stable.StableUtils; +import com.fr.stable.StringUtils; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class ChartTitlePane extends BasicScrollPane { + private static final long serialVersionUID = 5748881235830708722L; + private UICheckBox isTitleVisable; + + private TinyFormulaPane titleContent; + private ChartTextAttrPane textAttrPane; + private UIButtonGroup alignmentPane; + + private JPanel chartDefaultAttrPane; + private ChartBorderPane borderPane; + private ChartBackgroundNoImagePane backgroundPane; + + private JPanel titlePane; + + private class ContentPane extends JPanel { + private static final long serialVersionUID = -6455600016731592455L; + + public ContentPane() { + initComponents(); + } + + private void initComponents() { + isTitleVisable = new UICheckBox(Inter.getLocText("Chart_Title_Is_Visible")); + titlePane = createTitlePane(); + + double p = TableLayout.PREFERRED; + double f = TableLayout.FILL; + double[] columnSize = {f}; + double[] rowSize = {p, p}; + Component[][] components = new Component[][]{ + new Component[]{isTitleVisable}, + new Component[]{titlePane} + } ; + + JPanel panel = TableLayoutHelper.createTableLayoutPane(components,rowSize,columnSize); + this.setLayout(new BorderLayout()); + this.add(panel,BorderLayout.CENTER); + + isTitleVisable.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + checkTitlePaneUse(); + } + }); + } + } + + private JPanel createTitlePane(){ + borderPane = new ChartBorderPane(); + backgroundPane = new ChartBackgroundNoImagePane(); + chartDefaultAttrPane = createDefaultAttrPane(); + + double p = TableLayout.PREFERRED; + double f = TableLayout.FILL; + double[] columnSize = {p, f}; + double[] rowSize = {p,p,p,p,p}; + Component[][] components = new Component[][]{ + new Component[]{chartDefaultAttrPane,null}, + new Component[]{new JSeparator(),null}, + new Component[]{borderPane,null}, + new Component[]{backgroundPane,null} + } ; + + return TableLayoutHelper.createTableLayoutPane(components,rowSize,columnSize); + } + + private JPanel createDefaultAttrPane(){ + titleContent = new TinyFormulaPane(); + textAttrPane = new ChartTextAttrPane(); + Icon[] alignmentIconArray = {BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_left_normal.png"), + BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_center_normal.png"), + BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_right_normal.png")}; + Integer[] alignment = new Integer[]{Constants.LEFT, Constants.CENTER, Constants.RIGHT}; + alignmentPane = new UIButtonGroup(alignmentIconArray, alignment); + + double p = TableLayout.PREFERRED; + double f = TableLayout.FILL; + double[] columnSize = {LayoutConstants.CHART_ATTR_TOMARGIN, p, f}; + double[] rowSize = {p, p,p}; + Component[][] components = new Component[][]{ + new Component[]{null,titleContent,null}, + new Component[]{null,textAttrPane,null}, + new Component[]{null,new BoldFontTextLabel(Inter.getLocText("Alignment-Style") + ":"),alignmentPane} , + } ; + + return TableLayoutHelper.createTableLayoutPane(components,rowSize,columnSize); + } + + // 检查标题界面是否可用. + private void checkTitlePaneUse() { + isTitleVisable.setVisible(true); + isTitleVisable.setEnabled(true); + titlePane.setVisible(isTitleVisable.isSelected()); + this.repaint(); + } + + /** + * 弹出框的界面标题 + * @return 界面标题 + */ + public String title4PopupWindow() { + return PaneTitleConstants.CHART_STYLE_TITLE_TITLE; + } + + @Override + protected JPanel createContentPane() { + return new ContentPane(); + } + + @Override + public void populateBean(Chart chart) { + Title title = chart.getTitle(); + if (title == null) { + return; + } + isTitleVisable.setSelected(title.isTitleVisible()); + if (title.getTextObject() instanceof BaseFormula) { + titleContent.populateBean(((BaseFormula) title.getTextObject()).getContent()); + } else { + titleContent.populateBean(Utils.objectToString(title.getTextObject())); + } + alignmentPane.setSelectedItem(title.getPosition()); + TextAttr textAttr = title.getTextAttr(); + if (textAttr == null) { + textAttr = new TextAttr(); + } + textAttrPane.populate(textAttr); + borderPane.populate(title); + backgroundPane.populate(title); + + checkTitlePaneUse(); + } + + @Override + public void updateBean(Chart chart) { + if (chart == null) { + chart = new Chart(); + } + Title title = chart.getTitle(); + if (title == null) { + title = new Title(StringUtils.EMPTY); + } + title.setTitleVisible(isTitleVisable.isSelected()); + String titleString = titleContent.updateBean(); + Object titleObj; + if (StableUtils.maybeFormula(titleString)) { + titleObj = BaseFormula.createFormulaBuilder().build(titleString); + } else { + titleObj = titleString; + } + title.setTextObject(titleObj); + TextAttr textAttr = title.getTextAttr(); + if (textAttr == null) { + textAttr = new TextAttr(); + } + title.setPosition(alignmentPane.getSelectedItem()); + textAttrPane.update(textAttr); + borderPane.update(title); + backgroundPane.update(title); + } } \ No newline at end of file diff --git a/designer_chart/src/com/fr/plugin/chart/designer/other/VanChartInteractivePane.java b/designer_chart/src/com/fr/plugin/chart/designer/other/VanChartInteractivePane.java index 5e2b1fd9b..2f10e968c 100644 --- a/designer_chart/src/com/fr/plugin/chart/designer/other/VanChartInteractivePane.java +++ b/designer_chart/src/com/fr/plugin/chart/designer/other/VanChartInteractivePane.java @@ -1,6 +1,6 @@ package com.fr.plugin.chart.designer.other; -import com.fr.base.Formula; +import com.fr.base.BaseFormula; import com.fr.base.Utils; import com.fr.chart.chartattr.Chart; import com.fr.chart.chartattr.Plot; @@ -296,13 +296,13 @@ public class VanChartInteractivePane extends AbstractVanChartScrollPane { zoomWidget.setSelectedIndex(zoom.isZoomVisible() ? 0 : 1); zoomGesture.setSelectedIndex(zoom.isZoomGesture() ? 0 : 1); zoomResize.setSelectedIndex(zoom.isZoomResize() ? 0 : 1); - if (zoom.getFrom() instanceof Formula) { - from.populateBean(((Formula) zoom.getFrom()).getContent()); + if (zoom.getFrom() instanceof BaseFormula) { + from.populateBean(((BaseFormula) zoom.getFrom()).getContent()); } else { from.populateBean(Utils.objectToString(zoom.getFrom())); } - if (zoom.getTo() instanceof Formula) { - to.populateBean(((Formula) zoom.getTo()).getContent()); + if (zoom.getTo() instanceof BaseFormula) { + to.populateBean(((BaseFormula) zoom.getTo()).getContent()); } else { to.populateBean(Utils.objectToString(zoom.getTo())); } @@ -381,7 +381,7 @@ public class VanChartInteractivePane extends AbstractVanChartScrollPane { String fromString = from.updateBean(); Object fromObject; if (StableUtils.maybeFormula(fromString)) { - fromObject = new Formula(fromString); + fromObject = BaseFormula.createFormulaBuilder().build(fromString); } else { fromObject = fromString; } @@ -389,7 +389,7 @@ public class VanChartInteractivePane extends AbstractVanChartScrollPane { String toString = to.updateBean(); Object toObject; if (StableUtils.maybeFormula(toString)) { - toObject = new Formula(toString); + toObject = BaseFormula.createFormulaBuilder().build(toString); } else { toObject = toString; } diff --git a/designer_chart/src/com/fr/plugin/chart/designer/style/VanChartTitlePane.java b/designer_chart/src/com/fr/plugin/chart/designer/style/VanChartTitlePane.java index e7ebc7bd7..11e969522 100644 --- a/designer_chart/src/com/fr/plugin/chart/designer/style/VanChartTitlePane.java +++ b/designer_chart/src/com/fr/plugin/chart/designer/style/VanChartTitlePane.java @@ -1,7 +1,7 @@ package com.fr.plugin.chart.designer.style; +import com.fr.base.BaseFormula; import com.fr.base.BaseUtils; -import com.fr.base.Formula; import com.fr.base.Style; import com.fr.base.Utils; import com.fr.chart.base.TextAttr; @@ -272,8 +272,8 @@ public class VanChartTitlePane extends AbstractVanChartScrollPane { return; } isTitleVisible.setSelected(title.isTitleVisible()); - if (title.getTextObject() instanceof Formula) { - titleContent.populateBean(((Formula) title.getTextObject()).getContent()); + if (title.getTextObject() instanceof BaseFormula) { + titleContent.populateBean(((BaseFormula) title.getTextObject()).getContent()); } else { titleContent.populateBean(Utils.objectToString(title.getTextObject())); } @@ -313,7 +313,7 @@ public class VanChartTitlePane extends AbstractVanChartScrollPane { String titleString = titleContent.updateBean(); Object titleObj; if (StableUtils.maybeFormula(titleString)) { - titleObj = new Formula(titleString); + titleObj = BaseFormula.createFormulaBuilder().build(titleString); } else { titleObj = titleString; } diff --git a/designer_chart/src/com/fr/plugin/chart/designer/style/axis/VanChartBaseAxisPane.java b/designer_chart/src/com/fr/plugin/chart/designer/style/axis/VanChartBaseAxisPane.java index 9a5c0ee4d..8cec9d703 100644 --- a/designer_chart/src/com/fr/plugin/chart/designer/style/axis/VanChartBaseAxisPane.java +++ b/designer_chart/src/com/fr/plugin/chart/designer/style/axis/VanChartBaseAxisPane.java @@ -1,7 +1,7 @@ package com.fr.plugin.chart.designer.style.axis; +import com.fr.base.BaseFormula; import com.fr.base.BaseUtils; -import com.fr.base.Formula; import com.fr.base.Utils; import com.fr.chart.base.TextAttr; import com.fr.chart.chartattr.Title; @@ -428,8 +428,8 @@ public class VanChartBaseAxisPane extends FurtherBasicBeanPane { private void populateTitle(VanChartAxis axis){ Title axisTitle = axis.getTitle(); if(axisTitle != null){ - if (axisTitle.getTextObject() instanceof Formula && titleContent != null) { - titleContent.populateBean(((Formula) axisTitle.getTextObject()).getContent()); + if (axisTitle.getTextObject() instanceof BaseFormula && titleContent != null) { + titleContent.populateBean(((BaseFormula) axisTitle.getTextObject()).getContent()); } else if(titleContent != null){ titleContent.populateBean(Utils.objectToString(axisTitle.getTextObject())); } @@ -547,7 +547,7 @@ public class VanChartBaseAxisPane extends FurtherBasicBeanPane { String titleString = titleContent.updateBean(); Object titleObj; if (StableUtils.maybeFormula(titleString)) { - titleObj = new Formula(titleString); + titleObj = BaseFormula.createFormulaBuilder().build(titleString); } else { titleObj = titleString; } @@ -586,9 +586,9 @@ public class VanChartBaseAxisPane extends FurtherBasicBeanPane { } if(labelGapValue != null){ if(axis.isAutoLabelGap()){ - axis.setLabelIntervalNumber(new Formula("1")); + axis.setLabelIntervalNumber(BaseFormula.createFormulaBuilder().build("1")); } else { - axis.setLabelIntervalNumber(new Formula(labelGapValue.getText())); + axis.setLabelIntervalNumber(BaseFormula.createFormulaBuilder().build(labelGapValue.getText())); } } } diff --git a/designer_chart/src/com/fr/plugin/chart/designer/style/axis/VanChartTimeAxisPane.java b/designer_chart/src/com/fr/plugin/chart/designer/style/axis/VanChartTimeAxisPane.java index 09b4ead6e..5523b0756 100644 --- a/designer_chart/src/com/fr/plugin/chart/designer/style/axis/VanChartTimeAxisPane.java +++ b/designer_chart/src/com/fr/plugin/chart/designer/style/axis/VanChartTimeAxisPane.java @@ -1,6 +1,6 @@ package com.fr.plugin.chart.designer.style.axis; -import com.fr.base.Formula; +import com.fr.base.BaseFormula; import com.fr.base.Utils; import com.fr.design.chart.ChartSwingUtils; import com.fr.design.editor.ValueEditorPane; @@ -267,7 +267,7 @@ public class VanChartTimeAxisPane extends VanChartBaseAxisPane { public void update(VanChartTimeAxis timeAxis){ if (minCheckBox.isSelected()) {//最小值 if(minValueField.getCurrentEditor() instanceof FormulaEditor){ - Formula min = (Formula)minValueField.update(); + BaseFormula min = (BaseFormula) minValueField.update(); timeAxis.setMinValue(min); timeAxis.setCustomMinValue(StringUtils.isNotEmpty(min.getPureContent())); }else{ @@ -275,14 +275,14 @@ public class VanChartTimeAxisPane extends VanChartBaseAxisPane { DateEditor dateEditor = (DateEditor)minValueField.getCurrentEditor(); String dateString = dateEditor.getUIDatePickerFormat().format(datetmp); timeAxis.setCustomMinValue(StringUtils.isNotEmpty(dateString)); - timeAxis.setMinValue(new Formula(dateString)); + timeAxis.setMinValue(BaseFormula.createFormulaBuilder().build(dateString)); } } else { timeAxis.setCustomMinValue(false); } if (maxCheckBox.isSelected()) {//最大值 if(maxValueField.getCurrentEditor() instanceof FormulaEditor){ - Formula max = (Formula)maxValueField.update(); + BaseFormula max = (BaseFormula) maxValueField.update(); timeAxis.setMaxValue(max); timeAxis.setCustomMaxValue(StringUtils.isNotEmpty(max.getPureContent())); }else{ @@ -290,14 +290,14 @@ public class VanChartTimeAxisPane extends VanChartBaseAxisPane { DateEditor dateEditor = (DateEditor)maxValueField.getCurrentEditor(); String dateString = dateEditor.getUIDatePickerFormat().format(datetmp); timeAxis.setCustomMaxValue(StringUtils.isNotEmpty(dateString)); - timeAxis.setMaxValue(new Formula(dateString)); + timeAxis.setMaxValue(BaseFormula.createFormulaBuilder().build(dateString)); } } else { timeAxis.setCustomMaxValue(false); } if (mainTickBox.isSelected() && StringUtils.isNotEmpty(mainUnitField.getText())) {//主要刻度单位 timeAxis.setCustomMainUnit(true); - timeAxis.setMainUnit(new Formula(mainUnitField.getText())); + timeAxis.setMainUnit(BaseFormula.createFormulaBuilder().build(mainUnitField.getText())); String item = mainType.getSelectedItem().toString(); timeAxis.setMainType(TimeType.parseString(item)); } else { @@ -305,7 +305,7 @@ public class VanChartTimeAxisPane extends VanChartBaseAxisPane { } if (secondTickBox.isSelected() && StringUtils.isNotEmpty(secondUnitField.getText())) { //次要刻度单位 timeAxis.setCustomSecUnit(true); - timeAxis.setSecUnit(new Formula(secondUnitField.getText())); + timeAxis.setSecUnit(BaseFormula.createFormulaBuilder().build(secondUnitField.getText())); String item = secondType.getSelectedItem().toString(); timeAxis.setSecondType(TimeType.parseString(item)); } else { @@ -367,7 +367,7 @@ public class VanChartTimeAxisPane extends VanChartBaseAxisPane { } //将从formula读出来的内容转化为指定格式的日期 - private Date getDateFromFormula(Formula dateFormula){ + private Date getDateFromFormula(BaseFormula dateFormula){ String dateStr = dateFormula.getPureContent(); dateStr = Pattern.compile("\"").matcher(dateStr).replaceAll(StringUtils.EMPTY); Date toDate = DateUtils.string2Date(dateStr, true); diff --git a/designer_chart/src/com/fr/plugin/chart/designer/style/axis/VanChartValueAxisPane.java b/designer_chart/src/com/fr/plugin/chart/designer/style/axis/VanChartValueAxisPane.java index 3749f77ac..dbd9e2853 100644 --- a/designer_chart/src/com/fr/plugin/chart/designer/style/axis/VanChartValueAxisPane.java +++ b/designer_chart/src/com/fr/plugin/chart/designer/style/axis/VanChartValueAxisPane.java @@ -1,6 +1,6 @@ package com.fr.plugin.chart.designer.style.axis; -import com.fr.base.Formula; +import com.fr.base.BaseFormula; import com.fr.chart.base.ChartBaseUtils; import com.fr.design.chart.ChartSwingUtils; import com.fr.design.gui.icheckbox.UICheckBox; @@ -162,11 +162,11 @@ public class VanChartValueAxisPane extends VanChartBaseAxisPane { valueAxis.setLogBase(null); } else { valueAxis.setLog(true); - Formula formula = new Formula(increment); + BaseFormula formula = BaseFormula.createFormulaBuilder().build(increment); Number number = ChartBaseUtils.formula2Number(formula); // 界面处理防止 遇到 对数增量为小于1的值. if (number != null && number.doubleValue() <= 1.0) { - valueAxis.setLogBase(new Formula("2")); + valueAxis.setLogBase(BaseFormula.createFormulaBuilder().build("2")); } else { valueAxis.setLogBase(formula); } diff --git a/designer_chart/src/com/fr/plugin/chart/designer/style/axis/component/MinMaxValuePaneWithOutTick.java b/designer_chart/src/com/fr/plugin/chart/designer/style/axis/component/MinMaxValuePaneWithOutTick.java index 43eedd3eb..da43d7f8a 100644 --- a/designer_chart/src/com/fr/plugin/chart/designer/style/axis/component/MinMaxValuePaneWithOutTick.java +++ b/designer_chart/src/com/fr/plugin/chart/designer/style/axis/component/MinMaxValuePaneWithOutTick.java @@ -1,6 +1,6 @@ package com.fr.plugin.chart.designer.style.axis.component; -import com.fr.base.Formula; +import com.fr.base.BaseFormula; import com.fr.plugin.chart.range.MinAndMaxValue; import javax.swing.*; @@ -35,8 +35,8 @@ public class MinMaxValuePaneWithOutTick extends VanChartMinMaxValuePane { if(minAndMaxValue == null) { return; } - minAndMaxValue.setMinValue(new Formula(minValueField.getText())); - minAndMaxValue.setMaxValue(new Formula(maxValueField.getText())); + minAndMaxValue.setMinValue(BaseFormula.createFormulaBuilder().build(minValueField.getText())); + minAndMaxValue.setMaxValue(BaseFormula.createFormulaBuilder().build(maxValueField.getText())); minAndMaxValue.setCustomMin(minCheckBox.isSelected()); minAndMaxValue.setCustomMax(maxCheckBox.isSelected()); } diff --git a/designer_chart/src/com/fr/plugin/chart/designer/style/background/VanChartAlertValuePane.java b/designer_chart/src/com/fr/plugin/chart/designer/style/background/VanChartAlertValuePane.java index ec934be6f..6d944d522 100644 --- a/designer_chart/src/com/fr/plugin/chart/designer/style/background/VanChartAlertValuePane.java +++ b/designer_chart/src/com/fr/plugin/chart/designer/style/background/VanChartAlertValuePane.java @@ -1,6 +1,6 @@ package com.fr.plugin.chart.designer.style.background; -import com.fr.base.Formula; +import com.fr.base.BaseFormula; import com.fr.base.Utils; import com.fr.design.beans.BasicBeanPane; import com.fr.design.formula.TinyFormulaPane; @@ -15,6 +15,7 @@ import com.fr.design.layout.TableLayoutHelper; import com.fr.design.style.color.ColorSelectBox; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.general.FRFont; +import com.fr.general.GeneralUtils; import com.fr.general.Inter; import com.fr.plugin.chart.VanChartAttrHelper; import com.fr.plugin.chart.attr.axis.VanChartAlertValue; @@ -158,10 +159,10 @@ public class VanChartAlertValuePane extends BasicBeanPane { alertTextPosition.setSelectedIndex(chartAlertValue.getAlertPosition() == Constants.LEFT ? 0 : 1); } - if (chartAlertValue.getAlertContentFormula() instanceof Formula) { - alertText.populateBean(((Formula) chartAlertValue.getAlertContentFormula()).getContent()); + if (chartAlertValue.getAlertContentFormula() instanceof BaseFormula) { + alertText.populateBean(((BaseFormula) chartAlertValue.getAlertContentFormula()).getContent()); } else { - alertText.populateBean(Utils.objectToString(chartAlertValue.getAlertContentFormula())); + alertText.populateBean(GeneralUtils.objectToString(chartAlertValue.getAlertContentFormula())); } fontName.setSelectedItem(chartAlertValue.getAlertFont().getName()); fontSize.setSelectedItem(chartAlertValue.getAlertFont().getSize()); @@ -171,14 +172,14 @@ public class VanChartAlertValuePane extends BasicBeanPane { public VanChartAlertValue updateBean(){ chartAlertValue.setAxisName(alertAxis.getSelectedItem().toString()); - chartAlertValue.setAlertValueFormula(new Formula(alertValue.updateBean())); + chartAlertValue.setAlertValueFormula(BaseFormula.createFormulaBuilder().build(alertValue.updateBean())); chartAlertValue.getLineColor().setSeriesColor(alertLineColor.getSelectObject()); chartAlertValue.getLineStyle().setLineStyle(alertLineStyle.getSelectedLineStyle()); String contentString = alertText.updateBean(); Object contentObj; if (StableUtils.maybeFormula(contentString)) { - contentObj = new Formula(contentString); + contentObj = BaseFormula.createFormulaBuilder().build(contentString); } else { contentObj = contentString; } diff --git a/designer_chart/src/com/fr/plugin/chart/designer/style/background/VanChartCustomIntervalBackgroundPane.java b/designer_chart/src/com/fr/plugin/chart/designer/style/background/VanChartCustomIntervalBackgroundPane.java index b67f11529..8fb5423b7 100644 --- a/designer_chart/src/com/fr/plugin/chart/designer/style/background/VanChartCustomIntervalBackgroundPane.java +++ b/designer_chart/src/com/fr/plugin/chart/designer/style/background/VanChartCustomIntervalBackgroundPane.java @@ -1,6 +1,6 @@ package com.fr.plugin.chart.designer.style.background; -import com.fr.base.Formula; +import com.fr.base.BaseFormula; import com.fr.base.Utils; import com.fr.design.beans.BasicBeanPane; import com.fr.design.formula.TinyFormulaPane; @@ -105,8 +105,8 @@ public class VanChartCustomIntervalBackgroundPane extends BasicBeanPane 1) { - parent.remove(parent.getTitleCreator()); - } - } - - /** - * 设置样式为标题样式时,对应组件加上标题 - * @param style 样式 - */ - protected void initTitleStyle(LayoutBorderStyle style){ - if (style.getTitle() == null) { - return; - } - XWTitleLayout parent = (XWTitleLayout) this.getParent(); - if (parent.getComponentCount() > 1) { - XLabel title = (XLabel) parent.getTitleCreator(); - Label widget = title.toData(); - updateTitleWidgetStyle(widget, style); - title.initXCreatorProperties(); - return; - } - // 初始化标题控件 - XLabel title = new XLabel(new Label(), new Dimension()); - Label label = title.toData(); - updateTitleWidgetStyle(label, style); - parent.add(title, WTitleLayout.TITLE); - // 初始化标题边框 - title.initXCreatorProperties(); - WTitleLayout layout = parent.toData(); - layout.updateChildBounds(layout.getBodyBoundsWidget().getBounds()); - } - - /** - * 更新标题控件所有的样式 - */ - private void updateTitleWidgetStyle(Label title, LayoutBorderStyle style) { - //标题的边框样式目前是取对应的控件的边框样式 - title.setBorder(style.getBorder()); - title.setColor(style.getColor()); -// title.setCorner(style.isCorner()); - - WidgetTitle wTitle = style.getTitle(); - //设置成随机不重复的, 不然都用一个名字的话, 联动只能联动一个 - title.setWidgetName(wTitle.TITLE_NAME_INDEX + this.toData().getWidgetName()); - title.setWidgetValue(getTitleValue(wTitle)); - title.setFont(wTitle.getFrFont()); - title.setTextalign(wTitle.getPosition()); - title.setBackground(wTitle.getBackground()); - } - - private WidgetValue getTitleValue(WidgetTitle wTitle){ - String content = String.valueOf(wTitle.getTextObject()); - Object vlaue = content.startsWith("=") ? new Formula(content) : content; - return new WidgetValue(vlaue); - } - - @Override - protected String getIconName() { - return StringUtils.EMPTY; - } - @Override - protected JComponent initEditor() { - return this; - } - - /** - * 内边距 - * @return 同上 - */ - @Override - public Insets getInsets() { - PaddingMargin padding = toData().getMargin(); - if (padding == null) { - return new Insets(0, 0, 0, 0); - } - return new Insets(padding.getTop(), padding.getLeft(), padding.getBottom(), padding.getRight()); - } - - /** - * data属性改变触发其他操作 - * - */ - public void firePropertyChange(){ - - } - +package com.fr.design.designer.creator; + +import com.fr.base.BaseFormula; +import com.fr.design.border.UIRoundedBorder; +import com.fr.form.ui.AbstractBorderStyleWidget; +import com.fr.form.ui.Label; +import com.fr.form.ui.LayoutBorderStyle; +import com.fr.form.ui.PaddingMargin; +import com.fr.form.ui.Widget; +import com.fr.form.ui.WidgetTitle; +import com.fr.form.ui.WidgetValue; +import com.fr.form.ui.container.WTitleLayout; +import com.fr.general.ComparatorUtils; +import com.fr.stable.Constants; +import com.fr.stable.StringUtils; + +import javax.swing.*; +import java.awt.*; + +/** + * Created with IntelliJ IDEA. + * User: zx + * Date: 14-9-22 + * Time: 上午10:40 + */ + +public class XBorderStyleWidgetCreator extends XWidgetCreator{ + protected static final Dimension BORDER_PREFERRED_SIZE = new Dimension(250, 150); + + public XBorderStyleWidgetCreator(Widget widget, Dimension initSize) { + super(widget, initSize); + } + + /** + * 返回容器对应的widget + * @return 同上 + */ + @Override + public AbstractBorderStyleWidget toData() { + return (AbstractBorderStyleWidget) data; + } + + protected void initStyle() { + LayoutBorderStyle style = toData().getBorderStyle(); + initBorderStyle(); + if (ComparatorUtils.equals(style.getType(), LayoutBorderStyle.TITLE)) { + initTitleStyle(style); + } else { + clearTitleWidget(); + } + } + + // 边框默认值设为NONE,不然像scalelayout这种只用默认边框的会不显示边框 + protected void initBorderStyle() { + LayoutBorderStyle style = toData().getBorderStyle(); + if (style != null && style.getBorder() != Constants.LINE_NONE) { + this.setBorder(new UIRoundedBorder(style.getBorder(), style.getColor(), style.getBorderRadius())); + } else { + this.setBorder(DEFALUTBORDER); + } + } + + private void clearTitleWidget() { + if (acceptType(XWFitLayout.class)) { + return; + } + XWTitleLayout parent = (XWTitleLayout) this.getParent(); + if (parent.getComponentCount() > 1) { + parent.remove(parent.getTitleCreator()); + } + } + + /** + * 设置样式为标题样式时,对应组件加上标题 + * @param style 样式 + */ + protected void initTitleStyle(LayoutBorderStyle style){ + if (style.getTitle() == null) { + return; + } + XWTitleLayout parent = (XWTitleLayout) this.getParent(); + if (parent.getComponentCount() > 1) { + XLabel title = (XLabel) parent.getTitleCreator(); + Label widget = title.toData(); + updateTitleWidgetStyle(widget, style); + title.initXCreatorProperties(); + return; + } + // 初始化标题控件 + XLabel title = new XLabel(new Label(), new Dimension()); + Label label = title.toData(); + updateTitleWidgetStyle(label, style); + parent.add(title, WTitleLayout.TITLE); + // 初始化标题边框 + title.initXCreatorProperties(); + WTitleLayout layout = parent.toData(); + layout.updateChildBounds(layout.getBodyBoundsWidget().getBounds()); + } + + /** + * 更新标题控件所有的样式 + */ + private void updateTitleWidgetStyle(Label title, LayoutBorderStyle style) { + //标题的边框样式目前是取对应的控件的边框样式 + title.setBorder(style.getBorder()); + title.setColor(style.getColor()); +// title.setCorner(style.isCorner()); + + WidgetTitle wTitle = style.getTitle(); + //设置成随机不重复的, 不然都用一个名字的话, 联动只能联动一个 + title.setWidgetName(wTitle.TITLE_NAME_INDEX + this.toData().getWidgetName()); + title.setWidgetValue(getTitleValue(wTitle)); + title.setFont(wTitle.getFrFont()); + title.setTextalign(wTitle.getPosition()); + title.setBackground(wTitle.getBackground()); + } + + private WidgetValue getTitleValue(WidgetTitle wTitle){ + String content = String.valueOf(wTitle.getTextObject()); + Object vlaue = content.startsWith("=") ? BaseFormula.createFormulaBuilder().build(content) : content; + return new WidgetValue(vlaue); + } + + @Override + protected String getIconName() { + return StringUtils.EMPTY; + } + @Override + protected JComponent initEditor() { + return this; + } + + /** + * 内边距 + * @return 同上 + */ + @Override + public Insets getInsets() { + PaddingMargin padding = toData().getMargin(); + if (padding == null) { + return new Insets(0, 0, 0, 0); + } + return new Insets(padding.getTop(), padding.getLeft(), padding.getBottom(), padding.getRight()); + } + + /** + * data属性改变触发其他操作 + * + */ + public void firePropertyChange(){ + + } + } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/designer/creator/cardlayout/XWCardLayout.java b/designer_form/src/com/fr/design/designer/creator/cardlayout/XWCardLayout.java index 215647877..4c54efd4a 100644 --- a/designer_form/src/com/fr/design/designer/creator/cardlayout/XWCardLayout.java +++ b/designer_form/src/com/fr/design/designer/creator/cardlayout/XWCardLayout.java @@ -405,6 +405,7 @@ public class XWCardLayout extends XLayoutContainer { XWCardMainBorderLayout borderLayout = (XWCardMainBorderLayout) this.getBackupParent(); WCardMainBorderLayout border = borderLayout.toData(); WCardTitleLayout titleLayout = border.getTitlePart(); + titleLayout.setCardName(cardLayoutName); WCardTagLayout tagLayout = titleLayout.getTagPart(); for (int i = 0, len = tagLayout.getWidgetCount(); i < len; i++) { CardSwitchButton button = tagLayout.getSwitchButton(i); diff --git a/designer_form/src/com/fr/design/gui/xpane/JTreeAutoBuildPane.java b/designer_form/src/com/fr/design/gui/xpane/JTreeAutoBuildPane.java index 52433d6bb..d0bbcbdad 100644 --- a/designer_form/src/com/fr/design/gui/xpane/JTreeAutoBuildPane.java +++ b/designer_form/src/com/fr/design/gui/xpane/JTreeAutoBuildPane.java @@ -1,6 +1,6 @@ package com.fr.design.gui.xpane; -import com.fr.base.Formula; +import com.fr.base.BaseFormula; import com.fr.data.impl.NameTableData; import com.fr.data.impl.RecursionTableData; import com.fr.data.impl.TableDataDictionary; @@ -144,7 +144,7 @@ public class JTreeAutoBuildPane extends BasicPane implements Previewable, Editab if (object instanceof Integer) { tableDataDict.setValueColumnIndex((Integer) object - 1); } else { - tableDataDict.setFormula(((Formula) object)); + tableDataDict.setFormula(((BaseFormula) object)); } TableDataWrapper tableDataWrappe = this.treeTableDataComboBox.getSelectedItem(); if (tableDataWrappe != null) { diff --git a/designer_form/src/com/fr/design/gui/xtable/TableUtils.java b/designer_form/src/com/fr/design/gui/xtable/TableUtils.java index 413c1d1ee..fd2d00619 100644 --- a/designer_form/src/com/fr/design/gui/xtable/TableUtils.java +++ b/designer_form/src/com/fr/design/gui/xtable/TableUtils.java @@ -3,16 +3,7 @@ */ package com.fr.design.gui.xtable; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Point; -import java.util.HashMap; - -import javax.swing.table.DefaultTableCellRenderer; -import javax.swing.table.TableCellRenderer; - -import com.fr.base.Formula; +import com.fr.base.BaseFormula; import com.fr.design.mainframe.widget.editors.BooleanEditor; import com.fr.design.mainframe.widget.editors.ColorEditor; import com.fr.design.mainframe.widget.editors.DimensionEditor; @@ -31,6 +22,11 @@ import com.fr.design.mainframe.widget.renderer.PointCellRenderer; import com.fr.design.mainframe.widget.renderer.RectangleCellRenderer; import com.fr.third.com.lowagie.text.Rectangle; +import javax.swing.table.DefaultTableCellRenderer; +import javax.swing.table.TableCellRenderer; +import java.awt.*; +import java.util.HashMap; + /** * @author richer * @since 6.5.3 @@ -56,7 +52,7 @@ public class TableUtils { propertyEditorClasses.put(double.class, DoubleEditor.class); propertyEditorClasses.put(Double.class, IntegerPropertyEditor.class); - propertyEditorClasses.put(Formula.class, FormulaEditor.class); + propertyEditorClasses.put(BaseFormula.class, FormulaEditor.class); // TODO ALEX_SEP // propertyEditorClasses.put(DSColumn.class, DSColumnEditor.class); @@ -78,10 +74,24 @@ public class TableUtils { } public static Class getPropertyEditorClass(Class propType) { - return propertyEditorClasses.get(propType); + Class clazz = propertyEditorClasses.get(propType); + if (clazz == null) { + Class superClazz = propType.getSuperclass(); + if (superClazz != null) { + return getPropertyEditorClass(superClazz); + } + } + return clazz; } public static Class getTableCellRendererClass(Class propType) { - return cellRendererClasses.get(propType); + Class clazz = cellRendererClasses.get(propType); + if (clazz == null) { + Class superClazz = propType.getSuperclass(); + if (superClazz != null) { + return getTableCellRendererClass(superClazz); + } + } + return clazz; } } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/mainframe/widget/accessibles/AccessibleFormulaEditor.java b/designer_form/src/com/fr/design/mainframe/widget/accessibles/AccessibleFormulaEditor.java index d23b7634b..17074d0fa 100644 --- a/designer_form/src/com/fr/design/mainframe/widget/accessibles/AccessibleFormulaEditor.java +++ b/designer_form/src/com/fr/design/mainframe/widget/accessibles/AccessibleFormulaEditor.java @@ -3,7 +3,7 @@ */ package com.fr.design.mainframe.widget.accessibles; -import com.fr.base.Formula; +import com.fr.base.BaseFormula; import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.formula.FormulaFactory; @@ -37,7 +37,7 @@ public class AccessibleFormulaEditor extends BaseAccessibleEditor { fireStateChanged(); } }); - formulaPane.populate((Formula) getValue()); + formulaPane.populate((BaseFormula) getValue()); dlg.setVisible(true); } } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/mainframe/widget/ui/FormWidgetCardPane.java b/designer_form/src/com/fr/design/mainframe/widget/ui/FormWidgetCardPane.java index 8f6e075c4..1ac55c2ed 100644 --- a/designer_form/src/com/fr/design/mainframe/widget/ui/FormWidgetCardPane.java +++ b/designer_form/src/com/fr/design/mainframe/widget/ui/FormWidgetCardPane.java @@ -3,6 +3,7 @@ package com.fr.design.mainframe.widget.ui; import com.fr.design.data.DataCreatorUI; import com.fr.design.designer.beans.events.DesignerEvent; import com.fr.design.designer.creator.*; +import com.fr.design.dialog.AttrScrollPane; import com.fr.design.dialog.BasicScrollPane; import com.fr.design.foldablepane.UIExpandablePane; import com.fr.design.gui.frpane.AbstractAttrNoScrollPane; @@ -112,26 +113,16 @@ public class FormWidgetCardPane extends AbstractAttrNoScrollPane { XCreator innerCreator = getXCreatorDedicated(); final JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); - BasicScrollPane basicScrollPane = new BasicScrollPane() { + BasicScrollPane basicScrollPane = new AttrScrollPane() { @Override protected JPanel createContentPane() { return jPanel; } - - @Override - public void populateBean(Object ob) { - - } - - @Override - protected String title4PopupWindow() { - return null; - } }; this.add(basicScrollPane, BorderLayout.CENTER); attriCardPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); jPanel.add(attriCardPane, BorderLayout.CENTER); - jPanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0)); + jPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10)); final boolean isExtraWidget = FormWidgetDefinePaneFactoryBase.isExtraXWidget(innerCreator.toData()); this.listener = new AttributeChangeListener() { diff --git a/designer_form/src/com/fr/design/mainframe/widget/wrappers/FormulaWrapper.java b/designer_form/src/com/fr/design/mainframe/widget/wrappers/FormulaWrapper.java index e74348bac..f66e438be 100644 --- a/designer_form/src/com/fr/design/mainframe/widget/wrappers/FormulaWrapper.java +++ b/designer_form/src/com/fr/design/mainframe/widget/wrappers/FormulaWrapper.java @@ -3,12 +3,12 @@ */ package com.fr.design.mainframe.widget.wrappers; -import com.fr.base.Formula; -import com.fr.general.Inter; -import com.fr.stable.StringUtils; +import com.fr.base.BaseFormula; import com.fr.design.Exception.ValidationException; import com.fr.design.designer.properties.Decoder; import com.fr.design.designer.properties.Encoder; +import com.fr.general.Inter; +import com.fr.stable.StringUtils; /** * @author richer @@ -29,7 +29,7 @@ public class FormulaWrapper implements Encoder, Decoder{ @Override public Object decode(String txt) { - return new Formula(txt); + return BaseFormula.createFormulaBuilder().build(txt); } @Override diff --git a/designer_form/src/com/fr/design/parameter/RootDesignDefinePane.java b/designer_form/src/com/fr/design/parameter/RootDesignDefinePane.java index d8ef6f0fc..c1725e8b7 100644 --- a/designer_form/src/com/fr/design/parameter/RootDesignDefinePane.java +++ b/designer_form/src/com/fr/design/parameter/RootDesignDefinePane.java @@ -47,7 +47,7 @@ public class RootDesignDefinePane extends AbstractDataModify { public void initComponent() { this.setLayout(FRGUIPaneFactory.createBorderLayout()); - designerWidth = new UISpinner(1, 1000, 1); + designerWidth = new UISpinner(1, Integer.MAX_VALUE, 1); JPanel advancePane = createAdvancePane(); UIExpandablePane advanceExpandablePane = new UIExpandablePane(Inter.getLocText("FR-Designer_Advanced"), 280, 20, advancePane); this.add(advanceExpandablePane, BorderLayout.NORTH); diff --git a/designer_form/src/com/fr/design/widget/ui/designer/CheckBoxDefinePane.java b/designer_form/src/com/fr/design/widget/ui/designer/CheckBoxDefinePane.java index ab65dbda6..fc7a1dfdc 100644 --- a/designer_form/src/com/fr/design/widget/ui/designer/CheckBoxDefinePane.java +++ b/designer_form/src/com/fr/design/widget/ui/designer/CheckBoxDefinePane.java @@ -4,21 +4,23 @@ import com.fr.design.designer.IntervalConstants; import com.fr.design.designer.creator.XCreator; import com.fr.design.foldablepane.UIExpandablePane; import com.fr.design.gui.ilable.UILabel; -import com.fr.design.gui.ispinner.UISpinner; import com.fr.design.gui.itextfield.UITextField; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; +import com.fr.design.widget.ui.designer.component.FontSizeComboPane; import com.fr.design.widget.ui.designer.component.FormWidgetValuePane; import com.fr.form.ui.CheckBox; import com.fr.general.Inter; -import javax.swing.*; -import java.awt.*; +import javax.swing.BorderFactory; +import javax.swing.JPanel; +import javax.swing.SwingConstants; +import java.awt.Component; public class CheckBoxDefinePane extends AbstractDataModify { private UITextField text; - private UISpinner fontSizePane; + private FontSizeComboPane fontSizePane; private FormWidgetValuePane formWidgetValuePane; protected UITextField labelNameTextField; @@ -30,15 +32,17 @@ public class CheckBoxDefinePane extends AbstractDataModify { private void iniComoponents() { this.setLayout(FRGUIPaneFactory.createBorderLayout()); text = new UITextField(); - fontSizePane = new UISpinner(0, 20, 1, 0); + fontSizePane = new FontSizeComboPane(); labelNameTextField = new UITextField(); + UILabel widgetValueLabel = new UILabel(Inter.getLocText("FR-Designer-Estate_Widget_Value")); + widgetValueLabel.setVerticalAlignment(SwingConstants.TOP); formWidgetValuePane = new FormWidgetValuePane(creator.toData(), false); double f = TableLayout.FILL; double p = TableLayout.PREFERRED; Component[][] components = new Component[][]{ new Component[]{new UILabel(Inter.getLocText("FR-Designer_Label_Name")), labelNameTextField}, new Component[]{new UILabel(Inter.getLocText("FR-Designer_Text")), text }, - new Component[]{new UILabel(Inter.getLocText("FR-Designer-Estate_Widget_Value")), formWidgetValuePane }, + new Component[]{widgetValueLabel, formWidgetValuePane }, new Component[]{new UILabel(Inter.getLocText("FR-Designer_Font-Size")), fontSizePane}, }; double[] rowSize = {p, p, p, p, p, p}; @@ -70,7 +74,7 @@ public class CheckBoxDefinePane extends AbstractDataModify { public CheckBox updateBean() { CheckBox box = (CheckBox)creator.toData(); box.setText(text.getText()); - box.setFontSize((int)fontSizePane.getValue()); + box.setFontSize(fontSizePane.getValue()); formWidgetValuePane.update(box); box.setLabelName(labelNameTextField.getText()); return box; diff --git a/designer_form/src/com/fr/design/widget/ui/designer/DateEditorDefinePane.java b/designer_form/src/com/fr/design/widget/ui/designer/DateEditorDefinePane.java index 2cdb311b5..99d1c6d2b 100644 --- a/designer_form/src/com/fr/design/widget/ui/designer/DateEditorDefinePane.java +++ b/designer_form/src/com/fr/design/widget/ui/designer/DateEditorDefinePane.java @@ -1,7 +1,6 @@ package com.fr.design.widget.ui.designer; import com.fr.base.FRContext; -import com.fr.base.Formula; import com.fr.data.core.FormatField; import com.fr.design.designer.IntervalConstants; import com.fr.design.designer.creator.XCreator; @@ -15,15 +14,10 @@ import com.fr.design.widget.component.DateValuePane; import com.fr.design.widget.component.UIComboBoxNoArrow; import com.fr.design.widget.ui.designer.component.FormWidgetValuePane; import com.fr.form.ui.DateEditor; -import com.fr.general.DateUtils; import com.fr.general.Inter; -import com.fr.script.Calculator; import com.fr.stable.ArrayUtils; -import com.fr.stable.UtilEvalError; -import javax.swing.BorderFactory; -import javax.swing.JPanel; -import javax.swing.SwingConstants; +import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import java.awt.*; @@ -56,6 +50,14 @@ public class DateEditorDefinePane extends DirectWriteEditorDefinePane(new String[] {Inter.getLocText("Date") , Inter.getLocText("String")}); JPanel formatHead = createFormatHead(); @@ -65,10 +67,10 @@ public class DateEditorDefinePane extends DirectWriteEditorDefinePane e @Override protected JPanel setFirstContentPane() { JPanel advancePane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + UILabel widgetValueLabel = new UILabel(Inter.getLocText("FR-Designer-Estate_Widget_Value")); + widgetValueLabel.setVerticalAlignment(SwingConstants.TOP); formWidgetValuePane = new FormWidgetValuePane(creator.toData(), false); Component[] removeRepeatPane = new Component[]{createRepeatCheckBox(), null}; Component[] dicPane = createDictPane(); @@ -36,7 +38,7 @@ public abstract class DirectWriteEditorDefinePane e double p = TableLayout.PREFERRED; Component[][] components = new Component[][]{ new Component[]{new UILabel(Inter.getLocText("FR-Designer_Label_Name")), labelNameTextField}, - new Component[]{new UILabel(Inter.getLocText("FR-Designer-Estate_Widget_Value")), formWidgetValuePane }, + new Component[]{widgetValueLabel, formWidgetValuePane }, dicPane, removeRepeatPane, waterMarkComponent, diff --git a/designer_form/src/com/fr/design/widget/ui/designer/FieldEditorDefinePane.java b/designer_form/src/com/fr/design/widget/ui/designer/FieldEditorDefinePane.java index 8392ac2b6..ad47924d4 100644 --- a/designer_form/src/com/fr/design/widget/ui/designer/FieldEditorDefinePane.java +++ b/designer_form/src/com/fr/design/widget/ui/designer/FieldEditorDefinePane.java @@ -6,11 +6,10 @@ import com.fr.design.designer.creator.*; import com.fr.design.foldablepane.UIExpandablePane; import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.gui.ilable.UILabel; -import com.fr.design.gui.ispinner.UISpinner; import com.fr.design.gui.itextfield.UITextField; import com.fr.design.layout.FRGUIPaneFactory; -import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; +import com.fr.design.widget.ui.designer.component.FontSizeComboPane; import com.fr.form.ui.FieldEditor; import com.fr.general.Inter; @@ -26,7 +25,7 @@ public abstract class FieldEditorDefinePane extends Abstr // richer:错误信息,是所有控件共有的属性,所以放到这里来 protected UITextField errorMsgTextField; protected JPanel validatePane; - protected UISpinner fontSizePane; + protected FontSizeComboPane fontSizePane; protected UITextField labelNameTextField; @@ -40,7 +39,7 @@ public abstract class FieldEditorDefinePane extends Abstr labelNameTextField = new UITextField(); allowBlankCheckBox = new UICheckBox(Inter.getLocText("FR-Designer_Allow_Null")); allowBlankCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); - fontSizePane = new UISpinner(0, 20, 1, 0); + fontSizePane = new FontSizeComboPane(); errorMsgTextField = new UITextField(); JPanel contentPane = this.setFirstContentPane(); JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); @@ -70,7 +69,7 @@ public abstract class FieldEditorDefinePane extends Abstr e.setAllowBlank(this.allowBlankCheckBox.isSelected()); e.setErrorMessage(this.errorMsgTextField.getText()); - e.setFontSize((int)fontSizePane.getValue()); + e.setFontSize(fontSizePane.getValue()); e.setLabelName(labelNameTextField.getText()); return e; } diff --git a/designer_form/src/com/fr/design/widget/ui/designer/LabelDefinePane.java b/designer_form/src/com/fr/design/widget/ui/designer/LabelDefinePane.java index 2cf3c72bb..549f4266f 100644 --- a/designer_form/src/com/fr/design/widget/ui/designer/LabelDefinePane.java +++ b/designer_form/src/com/fr/design/widget/ui/designer/LabelDefinePane.java @@ -62,10 +62,12 @@ public class LabelDefinePane extends AbstractDataModify