diff --git a/.gitattributes b/.gitattributes index 9b9bf8f8a..ab7f46498 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,461 @@ * text=auto !eol +designer/.classpath -text +designer/.project -text +designer/designer.iml -text +designer/src/com/fr/design/actions/ButtonGroupAction.java -text +designer/src/com/fr/design/actions/CellSelectionAction.java -text +designer/src/com/fr/design/actions/ElementCaseAction.java -text +designer/src/com/fr/design/actions/FloatSelectionAction.java -text +designer/src/com/fr/design/actions/JWorkBookAction.java -text +designer/src/com/fr/design/actions/PresentCheckBoxAction.java -text +designer/src/com/fr/design/actions/ReportComponentAction.java -text +designer/src/com/fr/design/actions/cell/AbstractCellElementAction.java -text +designer/src/com/fr/design/actions/cell/BorderAction.java -text +designer/src/com/fr/design/actions/cell/CellAttributeAction.java -text +designer/src/com/fr/design/actions/cell/CellAttributeTableAction.java -text +designer/src/com/fr/design/actions/cell/CellExpandAttrAction.java -text +designer/src/com/fr/design/actions/cell/CellWidgetAttrAction.java -text +designer/src/com/fr/design/actions/cell/CleanAuthorityAction.java -text +designer/src/com/fr/design/actions/cell/ConditionAttributesAction.java -text +designer/src/com/fr/design/actions/cell/EditCellAction.java -text +designer/src/com/fr/design/actions/cell/FloatStyleAction.java -text +designer/src/com/fr/design/actions/cell/GlobalStyleMenuDef.java -text +designer/src/com/fr/design/actions/cell/NewPresentAction.java -text +designer/src/com/fr/design/actions/cell/StyleAction.java -text +designer/src/com/fr/design/actions/cell/UIToolbarBorderButton.java -text +designer/src/com/fr/design/actions/cell/style/AbstractStyleAction.java -text +designer/src/com/fr/design/actions/cell/style/AlignmentAction.java -text +designer/src/com/fr/design/actions/cell/style/ReportFontBoldAction.java -text +designer/src/com/fr/design/actions/cell/style/ReportFontForegroundAction.java -text +designer/src/com/fr/design/actions/cell/style/ReportFontItalicAction.java -text +designer/src/com/fr/design/actions/cell/style/ReportFontNameAction.java -text +designer/src/com/fr/design/actions/cell/style/ReportFontSizeAction.java -text +designer/src/com/fr/design/actions/cell/style/ReportFontUnderlineAction.java -text +designer/src/com/fr/design/actions/cell/style/StyleActionInterface.java -text +designer/src/com/fr/design/actions/cell/style/StyleBackgroundAction.java -text +designer/src/com/fr/design/actions/columnrow/AbstractColumnRowIndexAction.java -text +designer/src/com/fr/design/actions/columnrow/CancelColumnAction.java -text +designer/src/com/fr/design/actions/columnrow/CancelRowAction.java -text +designer/src/com/fr/design/actions/columnrow/ColumnHideAction.java -text +designer/src/com/fr/design/actions/columnrow/ColumnRowRepeatAction.java -text +designer/src/com/fr/design/actions/columnrow/ColumnRowSizingAction.java -text +designer/src/com/fr/design/actions/columnrow/ColumnWidthAction.java -text +designer/src/com/fr/design/actions/columnrow/DSColumnAdvancedAction.java -text +designer/src/com/fr/design/actions/columnrow/DSColumnBasicAction.java -text +designer/src/com/fr/design/actions/columnrow/DSColumnConditionAction.java -text +designer/src/com/fr/design/actions/columnrow/DeleteColumnAction.java -text +designer/src/com/fr/design/actions/columnrow/DeleteRowAction.java -text +designer/src/com/fr/design/actions/columnrow/FootColumnAction.java -text +designer/src/com/fr/design/actions/columnrow/FootRowAction.java -text +designer/src/com/fr/design/actions/columnrow/HeadColumnAction.java -text +designer/src/com/fr/design/actions/columnrow/HeadRowAction.java -text +designer/src/com/fr/design/actions/columnrow/InsertColumnAction.java -text +designer/src/com/fr/design/actions/columnrow/InsertRowAction.java -text +designer/src/com/fr/design/actions/columnrow/ResetColumnHideAction.java -text +designer/src/com/fr/design/actions/columnrow/ResetRowHideAction.java -text +designer/src/com/fr/design/actions/columnrow/RowHeightAction.java -text +designer/src/com/fr/design/actions/columnrow/RowHideAction.java -text +designer/src/com/fr/design/actions/edit/DeleteAction.java -text +designer/src/com/fr/design/actions/edit/EditFloatElementNameAction.java -text +designer/src/com/fr/design/actions/edit/HyperlinkAction.java -text +designer/src/com/fr/design/actions/edit/clear/ClearAction.java -text +designer/src/com/fr/design/actions/edit/clear/ClearAllAction.java -text +designer/src/com/fr/design/actions/edit/clear/ClearContentsAction.java -text +designer/src/com/fr/design/actions/edit/clear/ClearFormatsAction.java -text +designer/src/com/fr/design/actions/edit/clear/ClearWidgetAction.java -text +designer/src/com/fr/design/actions/edit/merge/MergeCellAction.java -text +designer/src/com/fr/design/actions/edit/merge/UnmergeCellAction.java -text +designer/src/com/fr/design/actions/edit/order/AbstractFloatElementOrderAction.java -text +designer/src/com/fr/design/actions/edit/order/BringFloatElementForwardAction.java -text +designer/src/com/fr/design/actions/edit/order/BringFloatElementToFrontAction.java -text +designer/src/com/fr/design/actions/edit/order/SendFloatElementBackwardAction.java -text +designer/src/com/fr/design/actions/edit/order/SendFloatElementToBackAction.java -text +designer/src/com/fr/design/actions/file/export/AbstractExcelExportAction.java -text +designer/src/com/fr/design/actions/file/export/AbstractExportAction.java -text +designer/src/com/fr/design/actions/file/export/CSVExportAction.java -text +designer/src/com/fr/design/actions/file/export/EmbeddedExportExportAction.java -text +designer/src/com/fr/design/actions/file/export/ExcelExportAction.java -text +designer/src/com/fr/design/actions/file/export/PDFExportAction.java -text +designer/src/com/fr/design/actions/file/export/PageExcelExportAction.java -text +designer/src/com/fr/design/actions/file/export/PageToSheetExcelExportAction.java -text +designer/src/com/fr/design/actions/file/export/SVGExportAction.java -text +designer/src/com/fr/design/actions/file/export/TextExportAction.java -text +designer/src/com/fr/design/actions/file/export/WordExportAction.java -text +designer/src/com/fr/design/actions/file/newReport/NewOEMWorkBookAction.java -text +designer/src/com/fr/design/actions/file/newReport/NewPolyReportAction.java -text +designer/src/com/fr/design/actions/file/newReport/NewWorkBookAction.java -text +designer/src/com/fr/design/actions/form/AbastractFormECAction.java -text +designer/src/com/fr/design/actions/form/FormECBackgroundAction.java -text +designer/src/com/fr/design/actions/form/FormECColumnsAction.java -text +designer/src/com/fr/design/actions/form/FormECFrozenAction.java -text +designer/src/com/fr/design/actions/insert/cell/AbstractCellAction.java -text +designer/src/com/fr/design/actions/insert/cell/BiasCellAction.java -text +designer/src/com/fr/design/actions/insert/cell/ChartCellAction.java -text +designer/src/com/fr/design/actions/insert/cell/DSColumnCellAction.java -text +designer/src/com/fr/design/actions/insert/cell/FormulaCellAction.java -text +designer/src/com/fr/design/actions/insert/cell/GeneralCellAction.java -text +designer/src/com/fr/design/actions/insert/cell/ImageCellAction.java -text +designer/src/com/fr/design/actions/insert/cell/RichTextCellAction.java -text +designer/src/com/fr/design/actions/insert/cell/SubReportCellAction.java -text +designer/src/com/fr/design/actions/insert/flot/AbstractShapeAction.java -text +designer/src/com/fr/design/actions/insert/flot/ChartFloatAction.java -text +designer/src/com/fr/design/actions/insert/flot/FormulaFloatAction.java -text +designer/src/com/fr/design/actions/insert/flot/ImageFloatAction.java -text +designer/src/com/fr/design/actions/insert/flot/TextBoxFloatAction.java -text +designer/src/com/fr/design/actions/report/ReportBackgroundAction.java -text +designer/src/com/fr/design/actions/report/ReportColumnsAction.java -text +designer/src/com/fr/design/actions/report/ReportEngineAttrAction.java -text +designer/src/com/fr/design/actions/report/ReportExportAttrAction.java -text +designer/src/com/fr/design/actions/report/ReportFooterAction.java -text +designer/src/com/fr/design/actions/report/ReportHeaderAction.java -text +designer/src/com/fr/design/actions/report/ReportPageAttrAction.java -text +designer/src/com/fr/design/actions/report/ReportPageSetupAction.java -text +designer/src/com/fr/design/actions/report/ReportParameterAction.java -text +designer/src/com/fr/design/actions/report/ReportWebAttrAction.java -text +designer/src/com/fr/design/actions/report/ReportWriteAttrAction.java -text +designer/src/com/fr/design/actions/server/ServerConfigManagerAction.java -text +designer/src/com/fr/design/actions/server/StyleListAction.java -text +designer/src/com/fr/design/actions/server/StyleManagerPane.java -text +designer/src/com/fr/design/actions/server/WidgetManagerAction.java -text +designer/src/com/fr/design/actions/utils/DeprecatedActionManager.java -text +designer/src/com/fr/design/actions/utils/ReportActionUtils.java -text +designer/src/com/fr/design/cell/bar/BarHelper.java -text +designer/src/com/fr/design/cell/bar/DynamicScrollBar.java -text +designer/src/com/fr/design/cell/bar/DynamicScrollBarUI.java -text +designer/src/com/fr/design/cell/bar/DynamicScrollButton.java -text +designer/src/com/fr/design/cell/bar/ScrollBarUIConstant.java -text +designer/src/com/fr/design/cell/clipboard/CellElementsClip.java -text +designer/src/com/fr/design/cell/clipboard/ElementsTransferable.java -text +designer/src/com/fr/design/cell/clipboard/FloatElementsClip.java -text +designer/src/com/fr/design/cell/editor/AbstractCellEditor.java -text +designer/src/com/fr/design/cell/editor/AbstractFloatEditor.java -text +designer/src/com/fr/design/cell/editor/BiasTextPainterCellEditor.java -text +designer/src/com/fr/design/cell/editor/CellEditor.java -text +designer/src/com/fr/design/cell/editor/ChartCellEditor.java -text +designer/src/com/fr/design/cell/editor/ChartFloatEditor.java -text +designer/src/com/fr/design/cell/editor/ComboBoxCellEditor.java -text +designer/src/com/fr/design/cell/editor/DSColumnCellEditor.java -text +designer/src/com/fr/design/cell/editor/DateCellEditor.java -text +designer/src/com/fr/design/cell/editor/FloatEditor.java -text +designer/src/com/fr/design/cell/editor/FormulaCellEditor.java -text +designer/src/com/fr/design/cell/editor/FormulaFloatEditor.java -text +designer/src/com/fr/design/cell/editor/GeneralCellEditor.java -text +designer/src/com/fr/design/cell/editor/GeneralFloatEditor.java -text +designer/src/com/fr/design/cell/editor/ImageCellEditor.java -text +designer/src/com/fr/design/cell/editor/ImageFloatEditor.java -text +designer/src/com/fr/design/cell/editor/RichTextCellEditor.java -text +designer/src/com/fr/design/cell/editor/RichTextToolBar.java -text +designer/src/com/fr/design/cell/editor/SubReportCellEditor.java -text +designer/src/com/fr/design/cell/editor/TextCellEditor.java -text +designer/src/com/fr/design/cell/editor/TextFloatEditor.java -text +designer/src/com/fr/design/cell/editor/package.html -text +designer/src/com/fr/design/cell/smartaction/AbstractSmartJTablePaneAction.java -text +designer/src/com/fr/design/cell/smartaction/SmartJTablePane.java -text +designer/src/com/fr/design/cell/smartaction/SmartJTablePaneAction.java -text +designer/src/com/fr/design/condition/BackPane.java -text +designer/src/com/fr/design/condition/BorderHighlightPane.java -text +designer/src/com/fr/design/condition/ColumnWidthPane.java -text +designer/src/com/fr/design/condition/FontPane.java -text +designer/src/com/fr/design/condition/ForeGroundPane.java -text +designer/src/com/fr/design/condition/HighLightConditionAttributesPane.java -text +designer/src/com/fr/design/condition/HyperlinkPane.java -text +designer/src/com/fr/design/condition/NewRealValuePane.java -text +designer/src/com/fr/design/condition/PaddingPane.java -text +designer/src/com/fr/design/condition/PagePane.java -text +designer/src/com/fr/design/condition/PresentHighlightPane.java -text +designer/src/com/fr/design/condition/RowHeightPane.java -text +designer/src/com/fr/design/condition/WHPane.java -text +designer/src/com/fr/design/condition/WidgetHighlightPane.java -text +designer/src/com/fr/design/dscolumn/DSColumnAdvancedPane.java -text +designer/src/com/fr/design/dscolumn/DSColumnBasicPane.java -text +designer/src/com/fr/design/dscolumn/DSColumnConditionsPane.java -text +designer/src/com/fr/design/dscolumn/DSColumnPane.java -text +designer/src/com/fr/design/dscolumn/ResultSetGroupDockingPane.java -text +designer/src/com/fr/design/dscolumn/ResultSetGroupPane.java -text +designer/src/com/fr/design/dscolumn/ResultSetGroupPopUpPane.java -text +designer/src/com/fr/design/dscolumn/SelectedConfirmedDataColumnPane.java -text +designer/src/com/fr/design/dscolumn/SelectedDataColumnPane.java -text +designer/src/com/fr/design/dscolumn/SpecifiedGroupAttrPane.java -text +designer/src/com/fr/design/expand/ConditionParentPane.java -text +designer/src/com/fr/design/expand/Expand.java -text +designer/src/com/fr/design/expand/ExpandDirectionPane.java -text +designer/src/com/fr/design/expand/ExpandFatherPane.java -text +designer/src/com/fr/design/expand/ExpandLeftFatherPane.java -text +designer/src/com/fr/design/expand/ExpandUpFatherPane.java -text +designer/src/com/fr/design/expand/ParentPane.java -text +designer/src/com/fr/design/expand/SortExpandAttrPane.java -text +designer/src/com/fr/design/headerfooter/EditFooterPane.java -text +designer/src/com/fr/design/headerfooter/EditHeaderPane.java -text +designer/src/com/fr/design/headerfooter/HFAttributesEditDialog.java -text +designer/src/com/fr/design/headerfooter/HFComponent.java -text +designer/src/com/fr/design/headerfooter/HFContainer.java -text +designer/src/com/fr/design/headerfooter/HeaderFooterEditPane.java -text +designer/src/com/fr/design/headerfooter/HeaderFooterPane.java -text +designer/src/com/fr/design/headerfooter/ImagePane.java -text +designer/src/com/fr/design/headerfooter/MoveActionListener.java -text +designer/src/com/fr/design/javascript/ListenerEditPane.java -text +designer/src/com/fr/design/mainframe/AbstractAttrPane.java -text +designer/src/com/fr/design/mainframe/ActiveKeyGenerator.java -text +designer/src/com/fr/design/mainframe/AuthorityEditToolBarPane.java -text +designer/src/com/fr/design/mainframe/AuthoritySheetEditedPane.java -text +designer/src/com/fr/design/mainframe/AuthorityToolBarPane.java -text +designer/src/com/fr/design/mainframe/CellElementPropertyPane.java -text +designer/src/com/fr/design/mainframe/ElementCasePane.java -text +designer/src/com/fr/design/mainframe/ElementCasePaneAuthorityEditPane.java -text +designer/src/com/fr/design/mainframe/ElementCasePaneDelegate.java -text +designer/src/com/fr/design/mainframe/FormatBrushAction.java -text +designer/src/com/fr/design/mainframe/InformationCollector.java -text +designer/src/com/fr/design/mainframe/JPolyWorkBook.java -text +designer/src/com/fr/design/mainframe/JWorkBook.java -text +designer/src/com/fr/design/mainframe/PolySheetNameTabPane.java -text +designer/src/com/fr/design/mainframe/RGridLayout.java -text +designer/src/com/fr/design/mainframe/ReportComponent.java -text +designer/src/com/fr/design/mainframe/ReportComponentCardPane.java -text +designer/src/com/fr/design/mainframe/ReportComponentComposite.java -text +designer/src/com/fr/design/mainframe/SheetAuthorityEditPane.java -text +designer/src/com/fr/design/mainframe/SheetNameTabPane.java -text +designer/src/com/fr/design/mainframe/WorkBookModelAdapter.java -text +designer/src/com/fr/design/mainframe/WorkBookUndoState.java -text +designer/src/com/fr/design/mainframe/WorkSheetDesigner.java -text +designer/src/com/fr/design/mainframe/bbs/BBSBrowserDialog.java -text +designer/src/com/fr/design/mainframe/bbs/BBSConstants.java -text +designer/src/com/fr/design/mainframe/bbs/BBSDialog.java -text +designer/src/com/fr/design/mainframe/bbs/BBSGuestPane.java -text +designer/src/com/fr/design/mainframe/bbs/BBSLoginDialog.java -text +designer/src/com/fr/design/mainframe/bbs/DisplayThread.java -text +designer/src/com/fr/design/mainframe/bbs/ExitLabel.java -text +designer/src/com/fr/design/mainframe/bbs/UserInfoLabel.java -text +designer/src/com/fr/design/mainframe/bbs/UserInfoPane.java -text +designer/src/com/fr/design/mainframe/bbs/bbs.properties -text +designer/src/com/fr/design/mainframe/bbs/images/switch.png -text +designer/src/com/fr/design/mainframe/cell/CellElementEditPane.java -text +designer/src/com/fr/design/mainframe/cell/QuickEditorRegion.java -text +designer/src/com/fr/design/mainframe/cell/settingpane/AbstractCellAttrPane.java -text +designer/src/com/fr/design/mainframe/cell/settingpane/CellExpandAttrPane.java -text +designer/src/com/fr/design/mainframe/cell/settingpane/CellOtherSetPane.java -text +designer/src/com/fr/design/mainframe/cell/settingpane/CellPresentPane.java -text +designer/src/com/fr/design/mainframe/cell/settingpane/CellStylePane.java -text +designer/src/com/fr/design/mainframe/cell/settingpane/style/CustomStylePane.java -text +designer/src/com/fr/design/mainframe/cell/settingpane/style/PredefinedStylePane.java -text +designer/src/com/fr/design/mainframe/cell/settingpane/style/StylePane.java -text +designer/src/com/fr/design/mainframe/form/FormElementCaseDesigner.java -text +designer/src/com/fr/design/mainframe/form/FormElementCasePaneDelegate.java -text +designer/src/com/fr/design/mainframe/form/FormReportComponentComposite.java -text +designer/src/com/fr/design/mainframe/form/FormTabPane.java -text +designer/src/com/fr/design/module/DesignerModule.java -text +designer/src/com/fr/design/parameter/ParameterDefinitePane.java -text +designer/src/com/fr/design/parameter/WorkBookParameterReader.java -text +designer/src/com/fr/design/present/BarCodePane.java -text +designer/src/com/fr/design/present/CellWriteAttrPane.java -text +designer/src/com/fr/design/present/ColumnRowTableModel.java -text +designer/src/com/fr/design/present/ConditionAttributesGroupPane.java -text +designer/src/com/fr/design/present/CurrencyLinePane.java -text +designer/src/com/fr/design/present/PresentPane.java -text +designer/src/com/fr/design/present/StyleArrayPane.java -text +designer/src/com/fr/design/report/CustomVerifyJobPane.java -text +designer/src/com/fr/design/report/ExcelExportPane.java -text +designer/src/com/fr/design/report/LayerReportPane.java -text +designer/src/com/fr/design/report/PDFExportPane.java -text +designer/src/com/fr/design/report/PageSetupPane.java -text +designer/src/com/fr/design/report/ReportBackgroundPane.java -text +designer/src/com/fr/design/report/ReportColumnsPane.java -text +designer/src/com/fr/design/report/ReportExportAttrPane.java -text +designer/src/com/fr/design/report/ReportStylePane.java -text +designer/src/com/fr/design/report/RichTextEditingPane.java -text +designer/src/com/fr/design/report/RichTextPane.java -text +designer/src/com/fr/design/report/RowColumnPane.java -text +designer/src/com/fr/design/report/SelectImagePane.java -text +designer/src/com/fr/design/report/SubReportPane.java -text +designer/src/com/fr/design/report/UnitFieldPane.java -text +designer/src/com/fr/design/report/ValueVerifierEditPane.java -text +designer/src/com/fr/design/report/VerifierListPane.java -text +designer/src/com/fr/design/report/VerifyJobListPane.java -text +designer/src/com/fr/design/report/WordExportPane.java -text +designer/src/com/fr/design/report/WriteShortCutsPane.java -text +designer/src/com/fr/design/report/freeze/ColSpinner.java -text +designer/src/com/fr/design/report/freeze/FormECRepeatAndFreezeSettingPane.java -text +designer/src/com/fr/design/report/freeze/FreezeAndRepeatPane.java -text +designer/src/com/fr/design/report/freeze/FreezePagePane.java -text +designer/src/com/fr/design/report/freeze/FreezeWriteColPane.java -text +designer/src/com/fr/design/report/freeze/FreezeWriteRowPane.java -text +designer/src/com/fr/design/report/freeze/RepeatAndFreezeSettingPane.java -text +designer/src/com/fr/design/report/freeze/RepeatColPane.java -text +designer/src/com/fr/design/report/freeze/RepeatRowPane.java -text +designer/src/com/fr/design/report/freeze/RowSpinner.java -text +designer/src/com/fr/design/report/freeze/UICapitalLetterField.java -text +designer/src/com/fr/design/report/freeze/UIIntNumberField.java -text +designer/src/com/fr/design/report/share/ConfuseTabledataAction.java -text +designer/src/com/fr/design/report/share/ConfusionInfo.java -text +designer/src/com/fr/design/report/share/ConfusionManagerPane.java -text +designer/src/com/fr/design/report/share/ConfusionTableDataPane.java -text +designer/src/com/fr/design/report/share/ShareButton.java -text +designer/src/com/fr/design/report/share/shareToolTip.html -text +designer/src/com/fr/design/style/BorderUtils.java -text +designer/src/com/fr/design/style/StylePane.java -text +designer/src/com/fr/design/webattr/AbstractEditToolBarPane.java -text +designer/src/com/fr/design/webattr/CommonPane.java -text +designer/src/com/fr/design/webattr/DragToolBarPane.java -text +designer/src/com/fr/design/webattr/EditReportServerParameterPane.java -text +designer/src/com/fr/design/webattr/EditToolBar.java -text +designer/src/com/fr/design/webattr/ErrorTemplatePane.java -text +designer/src/com/fr/design/webattr/EventPane.java -text +designer/src/com/fr/design/webattr/FToolBar.java -text +designer/src/com/fr/design/webattr/NameOptionSelection.java -text +designer/src/com/fr/design/webattr/PageToolBarPane.java -text +designer/src/com/fr/design/webattr/PageWebSettingPane.java -text +designer/src/com/fr/design/webattr/ReportSelectToolBarPane.java -text +designer/src/com/fr/design/webattr/ReportServerPrinterPane.java -text +designer/src/com/fr/design/webattr/ReportWebAttrPane.java -text +designer/src/com/fr/design/webattr/ReportWebWidgetConstants.java -text +designer/src/com/fr/design/webattr/ReportWriteAttrPane.java -text +designer/src/com/fr/design/webattr/ServerPrinterPane.java -text +designer/src/com/fr/design/webattr/SettingToolBar.java -text +designer/src/com/fr/design/webattr/ToolBarButton.java -text +designer/src/com/fr/design/webattr/ToolBarDragPane.java -text +designer/src/com/fr/design/webattr/ToolBarPane.java -text +designer/src/com/fr/design/webattr/ViewToolBarPane.java -text +designer/src/com/fr/design/webattr/ViewWebSettingPane.java -text +designer/src/com/fr/design/webattr/WebCssPane.java -text +designer/src/com/fr/design/webattr/WebJsPane.java -text +designer/src/com/fr/design/webattr/WebSettingPane.java -text +designer/src/com/fr/design/webattr/WidgetManagerPane.java -text +designer/src/com/fr/design/webattr/WidgetToolBarPane.java -text +designer/src/com/fr/design/webattr/WriteToolBarPane.java -text +designer/src/com/fr/design/webattr/WriteWebSettingPane.java -text +designer/src/com/fr/design/widget/CellWidgetCardPane.java -text +designer/src/com/fr/design/widget/DataModify.java -text +designer/src/com/fr/design/widget/EventCreator.java -text +designer/src/com/fr/design/widget/Operator.java -text +designer/src/com/fr/design/widget/UserDefinedWidgetConfigPane.java -text +designer/src/com/fr/design/widget/ValueWidgetPane.java -text +designer/src/com/fr/design/widget/WidgetConfigPane.java -text +designer/src/com/fr/design/widget/WidgetDefinePaneFactory.java -text +designer/src/com/fr/design/widget/WidgetEventPane.java -text +designer/src/com/fr/design/widget/WidgetPane.java -text +designer/src/com/fr/design/widget/ui/AbstractDataModify.java -text +designer/src/com/fr/design/widget/ui/BasicWidgetPropertySettingPane.java -text +designer/src/com/fr/design/widget/ui/ButtonDefinePane.java -text +designer/src/com/fr/design/widget/ui/ButtonGroupDictPane.java -text +designer/src/com/fr/design/widget/ui/CheckBoxDefinePane.java -text +designer/src/com/fr/design/widget/ui/CheckBoxDictPane.java -text +designer/src/com/fr/design/widget/ui/CheckBoxGroupDefinePane.java -text +designer/src/com/fr/design/widget/ui/ComboBoxDefinePane.java -text +designer/src/com/fr/design/widget/ui/ComboCheckBoxDefinePane.java -text +designer/src/com/fr/design/widget/ui/CustomWritableRepeatEditorPane.java -text +designer/src/com/fr/design/widget/ui/DateEditorDefinePane.java -text +designer/src/com/fr/design/widget/ui/DirectWriteEditorDefinePane.java -text +designer/src/com/fr/design/widget/ui/FieldEditorDefinePane.java -text +designer/src/com/fr/design/widget/ui/IframeEditorDefinePane.java -text +designer/src/com/fr/design/widget/ui/ListEditorDefinePane.java -text +designer/src/com/fr/design/widget/ui/MultiFileEditorPane.java -text +designer/src/com/fr/design/widget/ui/NoneWidgetDefinePane.java -text +designer/src/com/fr/design/widget/ui/NumberEditorDefinePane.java -text +designer/src/com/fr/design/widget/ui/ParameterTreeComboBox.java -text +designer/src/com/fr/design/widget/ui/PasswordDefinePane.java -text +designer/src/com/fr/design/widget/ui/RadioDefinePane.java -text +designer/src/com/fr/design/widget/ui/RadioGroupDefinePane.java -text +designer/src/com/fr/design/widget/ui/TextAreaDefinePane.java -text +designer/src/com/fr/design/widget/ui/TextFieldEditorDefinePane.java -text +designer/src/com/fr/design/widget/ui/TreeComboBoxEditorDefinePane.java -text +designer/src/com/fr/design/widget/ui/TreeEditorDefinePane.java -text +designer/src/com/fr/design/widget/ui/UserEditorDefinePane.java -text +designer/src/com/fr/design/widget/ui/WaterMarkDictPane.java -text +designer/src/com/fr/design/widget/ui/WritableRepeatEditorPane.java -text +designer/src/com/fr/design/widget/ui/WriteUnableRepeatEditorPane.java -text +designer/src/com/fr/design/widget/ui/btn/AppendRowButtonDefinePane.java -text +designer/src/com/fr/design/widget/ui/btn/ButtonDetailPaneFactory.java -text +designer/src/com/fr/design/widget/ui/btn/ButtonSytleDefinedPane.java -text +designer/src/com/fr/design/widget/ui/btn/DefaultButtonDetailPane.java -text +designer/src/com/fr/design/widget/ui/btn/DefaultButtonStylePane.java -text +designer/src/com/fr/design/widget/ui/btn/DefineAppendColumnRowPane.java -text +designer/src/com/fr/design/widget/ui/btn/DefineDeleteColumnRowPane.java -text +designer/src/com/fr/design/widget/ui/btn/DeleteRowButtonDefinePane.java -text +designer/src/com/fr/design/widget/ui/btn/FreeButtonDetailPane.java -text +designer/src/com/fr/design/widget/ui/btn/TreeNodeToogleButtonDefinePane.java -text +designer/src/com/fr/design/write/submit/DefaultSubmit.java -text +designer/src/com/fr/design/write/submit/SmartInsertDBManipulationInWidgetEventPane.java -text +designer/src/com/fr/design/write/submit/SmartInsertDBManipulationPane.java -text +designer/src/com/fr/design/write/submit/SmartInsertDMLJobPane.java -text +designer/src/com/fr/design/write/submit/SubmiterListPane.java -text +designer/src/com/fr/grid/AbstractGridHeaderMouseHandler.java -text +designer/src/com/fr/grid/BaseGridComponent.java -text +designer/src/com/fr/grid/CellElementPainter.java -text +designer/src/com/fr/grid/DrawFlowRect.java -text +designer/src/com/fr/grid/Grid.java -text +designer/src/com/fr/grid/GridColumn.java -text +designer/src/com/fr/grid/GridColumnMouseHandler.java -text +designer/src/com/fr/grid/GridColumnUI.java -text +designer/src/com/fr/grid/GridCorner.java -text +designer/src/com/fr/grid/GridCornerMouseHandler.java -text +designer/src/com/fr/grid/GridHeader.java -text +designer/src/com/fr/grid/GridKeyAction.java -text +designer/src/com/fr/grid/GridKeyListener.java -text +designer/src/com/fr/grid/GridMouseAdapter.java -text +designer/src/com/fr/grid/GridRow.java -text +designer/src/com/fr/grid/GridRowMouseHandler.java -text +designer/src/com/fr/grid/GridRowUI.java -text +designer/src/com/fr/grid/GridUI.java -text +designer/src/com/fr/grid/GridUtils.java -text +designer/src/com/fr/grid/IntelliElements.java -text +designer/src/com/fr/grid/KeyEventWork.java -text +designer/src/com/fr/grid/dnd/ElementCasePaneDropTarget.java -text +designer/src/com/fr/grid/event/CellEditorEvent.java -text +designer/src/com/fr/grid/event/CellEditorListener.java -text +designer/src/com/fr/grid/event/FloatEditorEvent.java -text +designer/src/com/fr/grid/event/FloatEditorListener.java -text +designer/src/com/fr/grid/event/package.html -text +designer/src/com/fr/grid/selection/CellSelection.java -text +designer/src/com/fr/grid/selection/FloatSelection.java -text +designer/src/com/fr/grid/selection/Selection.java -text +designer/src/com/fr/poly/JPolyBlockPane.java -text +designer/src/com/fr/poly/PolyArea.java -text +designer/src/com/fr/poly/PolyBlockProperPane.java -text +designer/src/com/fr/poly/PolyBlockProperTable.java -text +designer/src/com/fr/poly/PolyComponetsBar.java -text +designer/src/com/fr/poly/PolyConstants.java -text +designer/src/com/fr/poly/PolyDesignUI.java -text +designer/src/com/fr/poly/PolyDesigner.java -text +designer/src/com/fr/poly/PolyDesignerLayout.java -text +designer/src/com/fr/poly/PolyEditorLayout.java -text +designer/src/com/fr/poly/PolyUtils.java -text +designer/src/com/fr/poly/actions/DeleteBlockAction.java -text +designer/src/com/fr/poly/creator/BlockCreator.java -text +designer/src/com/fr/poly/creator/BlockEditor.java -text +designer/src/com/fr/poly/creator/BlockEditorLayout.java -text +designer/src/com/fr/poly/creator/ChartBlockCreator.java -text +designer/src/com/fr/poly/creator/ChartBlockEditor.java -text +designer/src/com/fr/poly/creator/ECBlockCreator.java -text +designer/src/com/fr/poly/creator/ECBlockEditor.java -text +designer/src/com/fr/poly/creator/ECBlockPane.java -text +designer/src/com/fr/poly/creator/PolyElementCasePane.java -text +designer/src/com/fr/poly/group/PolyBoundsGroup.java -text +designer/src/com/fr/poly/group/PolyNameGroup.java -text +designer/src/com/fr/poly/hanlder/BlockForbiddenWindow.java -text +designer/src/com/fr/poly/hanlder/BlockOperationMouseHandler.java -text +designer/src/com/fr/poly/hanlder/BottomCornerMouseHanlder.java -text +designer/src/com/fr/poly/hanlder/ColumnOperationMouseHandler.java -text +designer/src/com/fr/poly/hanlder/DataEditingListener.java -text +designer/src/com/fr/poly/hanlder/PolyDesignerDropTarget.java -text +designer/src/com/fr/poly/hanlder/RowOperationMouseHandler.java -text +designer/src/com/fr/poly/model/AddedData.java -text +designer/src/com/fr/poly/model/AddingData.java -text +designer/src/com/fr/quickeditor/CellQuickEditor.java -text +designer/src/com/fr/quickeditor/ChartQuickEditor.java -text +designer/src/com/fr/quickeditor/FloatQuickEditor.java -text +designer/src/com/fr/quickeditor/cellquick/CellBiasTextPainterEditor.java -text +designer/src/com/fr/quickeditor/cellquick/CellDScolumnEditor.java -text +designer/src/com/fr/quickeditor/cellquick/CellImageQuickEditor.java -text +designer/src/com/fr/quickeditor/cellquick/CellRichTextEditor.java -text +designer/src/com/fr/quickeditor/cellquick/CellStringQuickEditor.java -text +designer/src/com/fr/quickeditor/cellquick/CellSubReportEditor.java -text +designer/src/com/fr/quickeditor/floatquick/FloatImageQuickEditor.java -text +designer/src/com/fr/quickeditor/floatquick/FloatStringQuickEditor.java -text +designer/src/com/fr/start/BISplashPane.java -text +designer/src/com/fr/start/CollectUserInformationDialog.java -text +designer/src/com/fr/start/Designer.java -text +designer/src/com/fr/start/Designer4BI.java -text +designer/src/com/fr/start/Designer4Debug.java -text +designer/src/com/fr/start/ReportSplashPane.java -text designer_chart/.classpath -text designer_chart/.project -text designer_chart/designer_chart.iml -text diff --git a/.gitignore b/.gitignore index d61aea28b..62e272039 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +designer/bin designer_chart/bin diff --git a/designer/.classpath b/designer/.classpath new file mode 100644 index 000000000..f46ca27d3 --- /dev/null +++ b/designer/.classpath @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/designer/.project b/designer/.project new file mode 100644 index 000000000..2b547b258 --- /dev/null +++ b/designer/.project @@ -0,0 +1 @@ + designer org.eclipse.jdt.core.javabuilder org.eclipse.jdt.core.javanature \ No newline at end of file diff --git a/designer/designer.iml b/designer/designer.iml new file mode 100644 index 000000000..c798a6fe0 --- /dev/null +++ b/designer/designer.iml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/ButtonGroupAction.java b/designer/src/com/fr/design/actions/ButtonGroupAction.java new file mode 100644 index 000000000..ad461c1f0 --- /dev/null +++ b/designer/src/com/fr/design/actions/ButtonGroupAction.java @@ -0,0 +1,56 @@ +package com.fr.design.actions; + +import javax.swing.Icon; + +import com.fr.design.gui.ibutton.UIButtonGroup; +import com.fr.design.mainframe.ElementCasePane; + +public abstract class ButtonGroupAction extends ElementCaseAction{ + protected Icon[] iconArray; + protected Integer[] valueArray; + + private UIButtonGroup group; + + protected ButtonGroupAction(ElementCasePane t, Icon[] iconArray, Integer[] valueArray) { + super(t); + this.iconArray = iconArray; + this.valueArray = valueArray; + } + + protected Integer getSelectedValue() { + if(getSelectedIndex() < 0 || getSelectedIndex() >= valueArray.length) { + return valueArray[0]; + } + return valueArray[getSelectedIndex()]; + } + + private int getSelectedIndex() { + return createToolBarComponent().getSelectedIndex(); + } + + protected void setSelectedIndex(int value) { + int index = -1; + for(int i = 0; i < valueArray.length; i++) { + if(value == valueArray[i]) { + index = i; + break; + } + } + if(value == -1 && createToolBarComponent().hasClick()) { + index = getSelectedIndex(); + createToolBarComponent().setClickState(false); + } + createToolBarComponent().removeActionListener(this); + createToolBarComponent().setSelectedIndex(index); + createToolBarComponent().addActionListener(this); + } + + @Override + public UIButtonGroup createToolBarComponent() { + if(group == null) { + group = new UIButtonGroup(iconArray, valueArray); + group.addActionListener(this); + } + return group; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/CellSelectionAction.java b/designer/src/com/fr/design/actions/CellSelectionAction.java new file mode 100644 index 000000000..8ca67feaf --- /dev/null +++ b/designer/src/com/fr/design/actions/CellSelectionAction.java @@ -0,0 +1,34 @@ +package com.fr.design.actions; + +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.selection.CellSelection; +import com.fr.grid.selection.Selection; + +public abstract class CellSelectionAction extends ElementCaseAction { + protected CellSelectionAction(ElementCasePane t) { + super(t); + } + + @Override + public boolean executeActionReturnUndoRecordNeeded() { + ElementCasePane ePane = this.getEditingComponent(); + Selection s = ePane.getSelection(); + + // TODO ALEX_SEP instanceof i hate it + if (s instanceof CellSelection) { + return executeActionReturnUndoRecordNeededWithCellSelection((CellSelection)s); + } + + return false; + } + + protected abstract boolean executeActionReturnUndoRecordNeededWithCellSelection(CellSelection cs); + + @Override + public void update() { + super.update(); + if (this.isEnabled()) { + this.setEnabled(this.getEditingComponent().getSelection() instanceof CellSelection); + } + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/ElementCaseAction.java b/designer/src/com/fr/design/actions/ElementCaseAction.java new file mode 100644 index 000000000..be9ff9f9a --- /dev/null +++ b/designer/src/com/fr/design/actions/ElementCaseAction.java @@ -0,0 +1,33 @@ +package com.fr.design.actions; + +//ElementCaseAction应该有GridSelectionChangeListener,就从悬浮元素和单元格来讲,就必须有了,用来判断这些ElementCaseAction是否可以编辑,当然还可以做些其他事情 +// + +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.selection.CellSelection; +import com.fr.grid.selection.Selection; +import com.fr.design.selection.SelectionEvent; +import com.fr.design.selection.SelectionListener; + +public abstract class ElementCaseAction extends TemplateComponentAction { + protected ElementCaseAction(ElementCasePane t) { + super(t); + t.addSelectionChangeListener(new SelectionListener() { + + @Override + public void selectionChanged(SelectionEvent e) { + update(); + if (DesignerContext.getFormatState() != DesignerContext.FORMAT_STATE_NULL) { + Selection selection = getEditingComponent().getSelection(); + if (selection instanceof CellSelection) { + CellSelection cellselection = (CellSelection) selection; + //样式处理 + getEditingComponent().setCellNeedTOFormat(cellselection); + } + } + } + }); + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/FloatSelectionAction.java b/designer/src/com/fr/design/actions/FloatSelectionAction.java new file mode 100644 index 000000000..46f904c0e --- /dev/null +++ b/designer/src/com/fr/design/actions/FloatSelectionAction.java @@ -0,0 +1,37 @@ +package com.fr.design.actions; + +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.selection.FloatSelection; +import com.fr.grid.selection.Selection; + +public abstract class FloatSelectionAction extends ElementCaseAction { + + protected FloatSelectionAction(ElementCasePane t) { + super(t); + } + + @Override + public boolean executeActionReturnUndoRecordNeeded() { + ElementCasePane ePane = this.getEditingComponent(); + Selection s = ePane.getSelection(); + + // TODO ALEX_SEP instanceof i hate it + if (s instanceof FloatSelection) { + return executeActionReturnUndoRecordNeededWithFloatSelection((FloatSelection)s); + } + + return false; + } + + protected abstract boolean executeActionReturnUndoRecordNeededWithFloatSelection(FloatSelection fs); + + @Override + public void update() { + super.update(); + + if (this.isEnabled()) { + this.setEnabled(this.getEditingComponent().getSelection() instanceof FloatSelection); + } + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/JWorkBookAction.java b/designer/src/com/fr/design/actions/JWorkBookAction.java new file mode 100644 index 000000000..2b01eff6a --- /dev/null +++ b/designer/src/com/fr/design/actions/JWorkBookAction.java @@ -0,0 +1,9 @@ +package com.fr.design.actions; + +import com.fr.design.mainframe.JWorkBook; + +public abstract class JWorkBookAction extends JTemplateAction { + protected JWorkBookAction(JWorkBook jwb) { + super(jwb); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/PresentCheckBoxAction.java b/designer/src/com/fr/design/actions/PresentCheckBoxAction.java new file mode 100644 index 000000000..921831608 --- /dev/null +++ b/designer/src/com/fr/design/actions/PresentCheckBoxAction.java @@ -0,0 +1,26 @@ +package com.fr.design.actions; + +import com.fr.design.gui.imenu.UICheckBoxMenuItem; +import com.fr.design.mainframe.ElementCasePane; + +public abstract class PresentCheckBoxAction extends ElementCaseAction { + protected PresentCheckBoxAction(ElementCasePane t) { + super(t); + } + + @Override + public UICheckBoxMenuItem createMenuItem() { + Object object = this.getValue(UICheckBoxMenuItem.class.getName()); + if (object == null) { + object = createCheckBoxMenuItem(this); + this.putValue(UICheckBoxMenuItem.class.getName(), object); + } + + // isSelected. + ((UICheckBoxMenuItem) object).setSelected(this.isSelected()); + + return (UICheckBoxMenuItem) object; + } + + public abstract boolean isSelected(); +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/ReportComponentAction.java b/designer/src/com/fr/design/actions/ReportComponentAction.java new file mode 100644 index 000000000..d1d619634 --- /dev/null +++ b/designer/src/com/fr/design/actions/ReportComponentAction.java @@ -0,0 +1,9 @@ +package com.fr.design.actions; + +import com.fr.design.mainframe.ReportComponent; + +public abstract class ReportComponentAction extends TemplateComponentAction { + protected ReportComponentAction(T tc) { + super(tc); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/cell/AbstractCellElementAction.java b/designer/src/com/fr/design/actions/cell/AbstractCellElementAction.java new file mode 100644 index 000000000..49eab9911 --- /dev/null +++ b/designer/src/com/fr/design/actions/cell/AbstractCellElementAction.java @@ -0,0 +1,100 @@ +package com.fr.design.actions.cell; + +import com.fr.design.actions.CellSelectionAction; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.BasicPane; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.GridUtils; +import com.fr.grid.selection.CellSelection; +import com.fr.report.cell.DefaultTemplateCellElement; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.core.SheetUtils; +import com.fr.report.elementcase.TemplateElementCase; +import com.fr.report.stable.ReportConstants; + +// TODO ALEX_SEP 这个类与AbstractCellAction有什么关系? +public abstract class AbstractCellElementAction extends CellSelectionAction { + protected AbstractCellElementAction(ElementCasePane t) { + super(t); + } + + @Override + protected boolean executeActionReturnUndoRecordNeededWithCellSelection(CellSelection cs) { + final ElementCasePane ePane = this.getEditingComponent(); + final TemplateElementCase tplEC = ePane.getEditingElementCase(); + TemplateCellElement editCellElement = tplEC.getTemplateCellElement(cs.getColumn(), cs.getRow()); + if (editCellElement == null) { + editCellElement = new DefaultTemplateCellElement(cs.getColumn(), cs.getRow()); + tplEC.addCellElement(editCellElement); + } + if (tplEC != null) { + SheetUtils.calculateDefaultParent(tplEC); + } + final CellSelection finalCS = cs; + final BasicPane bp = populateBasicPane(editCellElement); + BasicDialog dialog = bp.showWindow(DesignerContext.getDesignerFrame()); + dialog.addDialogActionListener(new DialogActionAdapter() { + @Override + public void doOk() { + // 需要先行后列地增加新元素。 + for (int j = 0; j < finalCS.getRowSpan(); j++) { + for (int i = 0; i < finalCS.getColumnSpan(); i++) { + int column = i + finalCS.getColumn(); + int row = j + finalCS.getRow(); + TemplateCellElement editCellElement = tplEC.getTemplateCellElement(column, row); + if (editCellElement == null) { + editCellElement = new DefaultTemplateCellElement(column, row); + tplEC.addCellElement(editCellElement); + } + // alex:不加这一句话会导致跨行跨列的格子被多次update + if (editCellElement.getColumn() != column || editCellElement.getRow() != row) { + continue; + } + updateBasicPane(bp, editCellElement); + // update cell attributes + if (isNeedShinkToFit()) { + // shink to fit.(如果value是String) + Object editElementValue = editCellElement.getValue(); + if (editElementValue != null && (editElementValue instanceof String || editElementValue instanceof Number)) { + // TODO ALEX_SEP 暂时用FIT_DEFAULT替代,不取reportsetting里面的设置,因为也不知道是应该放在report里面还是elementcase里面 + GridUtils.shrinkToFit(ReportConstants.AUTO_SHRINK_TO_FIT_DEFAULT, tplEC, editCellElement); + } + } + } + } + ePane.fireTargetModified(); + } + }); + //控件设置记住dlg,提交入库智能添加单元格后可以show出来 + DesignerContext.setReportWritePane(dialog); + dialog.setVisible(true); + return false; + } + + /** + * 初始化对话框 + * + * @param cellElement + * @return + */ + protected abstract BasicPane populateBasicPane(TemplateCellElement cellElement); + + /** + * 更新对话框之后,改变值 + * + * @param cellElement + * @return + */ + protected abstract void updateBasicPane(BasicPane basicPane, TemplateCellElement cellElement); + + /** + * if isNeedShinkToFit,please override this method + * + * @return isNeedShinkToFit + */ + protected boolean isNeedShinkToFit() { + return false; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/cell/BorderAction.java b/designer/src/com/fr/design/actions/cell/BorderAction.java new file mode 100644 index 000000000..a47a4c030 --- /dev/null +++ b/designer/src/com/fr/design/actions/cell/BorderAction.java @@ -0,0 +1,85 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.cell; + +import javax.swing.JComponent; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +import com.fr.base.BaseUtils; +import com.fr.base.CellBorderStyle; +import com.fr.design.actions.ElementCaseAction; +import com.fr.design.actions.core.ActionUtils; +import com.fr.design.style.BorderUtils; +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; + +/** + * Border. + */ +public class BorderAction extends ElementCaseAction implements ChangeListener { + + private CellBorderStyle oldCellBorderStyle; + + public BorderAction(ElementCasePane t) { + super(t); + + this.setName(Inter.getLocText("M_Format_A-Border")); + } + + public void stateChanged(ChangeEvent e) { + this.actionPerformedUndoable(); + } + + @Override + public boolean executeActionReturnUndoRecordNeeded() { + Object object = this.getValue(UIToolbarBorderButton.class.getName()); + ElementCasePane reportPane = this.getEditingComponent(); + if (reportPane == null) { + return false; + } + if (object != null && object instanceof UIToolbarBorderButton) { + oldCellBorderStyle = ((UIToolbarBorderButton) object).getCellBorderStyle(); + + return this.update(reportPane); + } + return false; + } + + @Override + public JComponent createToolBarComponent() { + Object object = this.getValue(UIToolbarBorderButton.class.getName()); + if (object == null || !(object instanceof UIToolbarBorderButton)) { + UIToolbarBorderButton borderStylePane = new UIToolbarBorderButton(BaseUtils.readIcon("/com/fr/design/images/m_format/noboder.png"), this.getEditingComponent()); + this.putValue(UIToolbarBorderButton.class.getName(), borderStylePane); + borderStylePane.setEnabled(this.isEnabled()); + borderStylePane.set4Toolbar(); + // peter:产生tooltip + borderStylePane.setToolTipText(ActionUtils.createButtonToolTipText(this)); + borderStylePane.setCellBorderStyle(new CellBorderStyle()); + borderStylePane.addStyleChangeListener(this); + return borderStylePane; + } + + return (JComponent) object; + } + + public boolean update(ElementCasePane elementCasePane) { + if (oldCellBorderStyle.isNoneBorderStyle()) { + //无边框格式 + return BorderUtils.updateCellBorderStyle(elementCasePane, oldCellBorderStyle); + } + return BorderUtils.update(elementCasePane, oldCellBorderStyle); + } + + @Override + public void update() { + this.setEnabled(true); + ElementCasePane reportPane = this.getEditingComponent(); + if (reportPane == null) { + this.setEnabled(false); + return; + } + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/cell/CellAttributeAction.java b/designer/src/com/fr/design/actions/cell/CellAttributeAction.java new file mode 100644 index 000000000..949d72de0 --- /dev/null +++ b/designer/src/com/fr/design/actions/cell/CellAttributeAction.java @@ -0,0 +1,22 @@ +package com.fr.design.actions.cell; + +import com.fr.design.menu.KeySetUtils; +import com.fr.general.Inter; + +/** + * Cell Attribute. + */ +public class CellAttributeAction extends CellAttributeTableAction { + public CellAttributeAction() { + this.setMenuKeySet(KeySetUtils.CELL_OTHER_ATTR); + this.setName(getMenuKeySet().getMenuKeySetName()+ "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + // this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_format/cellAttr.png")); + } + + @Override + protected String getID() { + return Inter.getLocText("Datasource-Other_Attributes"); + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/cell/CellAttributeTableAction.java b/designer/src/com/fr/design/actions/cell/CellAttributeTableAction.java new file mode 100644 index 000000000..2906306d0 --- /dev/null +++ b/designer/src/com/fr/design/actions/cell/CellAttributeTableAction.java @@ -0,0 +1,23 @@ +package com.fr.design.actions.cell; + +import java.awt.event.ActionEvent; + +import com.fr.design.actions.UpdateAction; +import com.fr.design.mainframe.CellElementPropertyPane; + +/** + * 所有的CellAttributeTableAction都是指向单元格属性表的,点了就自动跳转到单元格属性表 + * + * @author zhou + * @since 2012-5-23下午4:19:48 + */ +public abstract class CellAttributeTableAction extends UpdateAction { + + protected abstract String getID(); + + @Override + public void actionPerformed(ActionEvent e) { + CellElementPropertyPane.getInstance().GoToPane(getID()); + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/cell/CellExpandAttrAction.java b/designer/src/com/fr/design/actions/cell/CellExpandAttrAction.java new file mode 100644 index 000000000..40c09ff52 --- /dev/null +++ b/designer/src/com/fr/design/actions/cell/CellExpandAttrAction.java @@ -0,0 +1,24 @@ +package com.fr.design.actions.cell; + +import com.fr.base.BaseUtils; +import com.fr.design.menu.KeySetUtils; +import com.fr.general.Inter; + +public class CellExpandAttrAction extends CellAttributeTableAction{ + + public CellExpandAttrAction() { + super(); + this.setMenuKeySet(KeySetUtils.CELL_EXPAND_ATTR); + this.setName(getMenuKeySet().getMenuKeySetName()); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/expand/cellAttr.gif")); + } + + + + @Override + public String getID() { + return Inter.getLocText("ExpandD-Expand_Attribute"); + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/cell/CellWidgetAttrAction.java b/designer/src/com/fr/design/actions/cell/CellWidgetAttrAction.java new file mode 100644 index 000000000..f5307b2ac --- /dev/null +++ b/designer/src/com/fr/design/actions/cell/CellWidgetAttrAction.java @@ -0,0 +1,72 @@ +package com.fr.design.actions.cell; + +import com.fr.base.BaseUtils; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.menu.KeySetUtils; +import com.fr.design.present.CellWriteAttrPane; +import com.fr.design.dialog.BasicPane; +import com.fr.form.ui.Widget; +import com.fr.general.FRLogger; +import com.fr.grid.selection.CellSelection; +import com.fr.grid.selection.Selection; +import com.fr.privilege.finegrain.WidgetPrivilegeControl; +import com.fr.report.cell.TemplateCellElement; + +/** + * Cell Widget Attribute. + */ +public class CellWidgetAttrAction extends AbstractCellElementAction { + + public CellWidgetAttrAction(ElementCasePane t) { + super(t); + this.setMenuKeySet(KeySetUtils.CELL_WIDGET_ATTR); + this.setName(getMenuKeySet().getMenuKeySetName()); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_format/modified.png")); + } + + @Override + protected BasicPane populateBasicPane(TemplateCellElement cellElement) { + CellWriteAttrPane pane = new CellWriteAttrPane(this.getEditingComponent()); + //got simple cell element from column and row. + pane.populate(cellElement); + + return pane; + } + + @Override + protected void updateBasicPane(BasicPane bp, TemplateCellElement cellElement) { + CellWriteAttrPane pane = (CellWriteAttrPane) bp; + if (cellElement.getWidget() == null) { + pane.update(cellElement); + return; + } + try { + Widget oldWidget = (Widget) cellElement.getWidget().clone(); + pane.update(cellElement); + //这边需要重新设置权限细粒度的hashset是因为Update是直接生成一个新的来update的,所以以前里面的hashset都没有了 + Widget newWidget = cellElement.getWidget(); + if (newWidget.getClass() == oldWidget.getClass()) { + newWidget.setWidgetPrivilegeControl((WidgetPrivilegeControl) oldWidget.getWidgetPrivilegeControl().clone()); + } + } catch (Exception e) { + FRLogger.getLogger().error(e.getMessage()); + } + } + + @Override + protected boolean isNeedShinkToFit() { + return true; + } + + @Override + public void update() { + ElementCasePane ePane = this.getEditingComponent(); + Selection sel = ePane.getSelection(); + if (sel instanceof CellSelection) { + this.setEnabled(true); + } else { + this.setEnabled(false); + } + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/cell/CleanAuthorityAction.java b/designer/src/com/fr/design/actions/cell/CleanAuthorityAction.java new file mode 100644 index 000000000..f403fcb9c --- /dev/null +++ b/designer/src/com/fr/design/actions/cell/CleanAuthorityAction.java @@ -0,0 +1 @@ +package com.fr.design.actions.cell; import java.awt.Rectangle; import java.awt.event.ActionEvent; import com.fr.design.actions.ElementCaseAction; import com.fr.design.mainframe.AuthorityPropertyPane; import com.fr.design.mainframe.EastRegionContainerPane; import com.fr.design.mainframe.ElementCasePane; import com.fr.design.roleAuthority.ReportAndFSManagePane; import com.fr.design.roleAuthority.RolesAlreadyEditedPane; import com.fr.general.Inter; import com.fr.grid.selection.CellSelection; import com.fr.grid.selection.FloatSelection; import com.fr.grid.selection.Selection; import com.fr.report.cell.FloatElement; import com.fr.report.cell.TemplateCellElement; import com.fr.report.elementcase.TemplateElementCase; /** * Author : daisy * Date: 13-9-23 * Time: 下午2:41 */ public class CleanAuthorityAction extends ElementCaseAction { public CleanAuthorityAction(ElementCasePane t) { super(t); this.setName(Inter.getLocText(new String[]{"Clear", "DashBoard-Potence"})); } /** * 清楚权限动作 * * @param evt 事件 */ public void actionPerformed(ActionEvent evt) { ElementCasePane reportPane = getEditingComponent(); Selection selection = reportPane.getSelection(); String selectedRoles = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); if (selection instanceof FloatSelection) { String name = ((FloatSelection) selection).getSelectedFloatName(); TemplateElementCase ec = reportPane.getEditingElementCase(); FloatElement fe = ec.getFloatElement(name); if (fe.isDoneAuthority(selectedRoles)) { fe.cleanAuthority(selectedRoles); } doAfterAuthority(reportPane); return; } CellSelection cellSelection = (CellSelection) selection; boolean isChooseColumnRow = cellSelection.getSelectedType() == CellSelection.CHOOSE_COLUMN || cellSelection.getSelectedType() == CellSelection.CHOOSE_ROW; if (isChooseColumnRow && cellSelection.getCellRectangleCount() == 1) { cleanColumnRow(cellSelection, reportPane, selectedRoles); } else { cleanCell(cellSelection, reportPane, selectedRoles); } doAfterAuthority(reportPane); } private void doAfterAuthority(ElementCasePane reportPane) { reportPane.repaint(); reportPane.fireTargetModified(); RolesAlreadyEditedPane.getInstance().refreshDockingView(); RolesAlreadyEditedPane.getInstance().repaint(); if (EastRegionContainerPane.getInstance().getUpPane() instanceof AuthorityPropertyPane) { AuthorityPropertyPane authorityPropertyPane = (AuthorityPropertyPane) EastRegionContainerPane.getInstance().getUpPane(); authorityPropertyPane.populate(); EastRegionContainerPane.getInstance().replaceUpPane(authorityPropertyPane); } } /** * 清除单元格对应的角色的权限 * * @param cellSelection * @param reportPane */ private void cleanCell(CellSelection cellSelection, ElementCasePane reportPane, String selectedRoles) { if (selectedRoles == null) { return; } TemplateElementCase elementCase = reportPane.getEditingElementCase(); int cellRectangleCount = cellSelection.getCellRectangleCount(); for (int rect = 0; rect < cellRectangleCount; rect++) { Rectangle cellRectangle = cellSelection.getCellRectangle(rect); for (int j = 0; j < cellRectangle.height; j++) { for (int i = 0; i < cellRectangle.width; i++) { int column = i + cellRectangle.x; int row = j + cellRectangle.y; TemplateCellElement cellElement = elementCase.getTemplateCellElement(column, row); if (cellElement == null) { continue; } //清除权限 if (cellElement.isDoneAuthority(selectedRoles) || cellElement.isDoneNewValueAuthority(selectedRoles)) { cellElement.cleanAuthority(selectedRoles); } if (cellElement.getWidget() == null) { continue; } boolean isDoneAuthority = cellElement.getWidget().isDoneVisibleAuthority(selectedRoles) || cellElement.getWidget().isDoneUsableAuthority(selectedRoles); if (isDoneAuthority) { cellElement.getWidget().cleanAuthority(selectedRoles); } } } } } private void cleanColumnRow(CellSelection cellSelection, ElementCasePane reportPane, String selectedRoles) { if (selectedRoles == null) { return; } TemplateElementCase elementCase = reportPane.getEditingElementCase(); if (cellSelection.getSelectedType() == CellSelection.CHOOSE_COLUMN) { for (int col = cellSelection.getColumn(); col < cellSelection.getColumn() + cellSelection.getColumnSpan(); col++) { elementCase.removeColumnPrivilegeControl(col, selectedRoles); } } else { for (int row = cellSelection.getRow(); row < cellSelection.getRow() + cellSelection.getRowSpan(); row++) { elementCase.removeRowPrivilegeControl(row, selectedRoles); } } } /** * 是否需要撤销动作 * * @return 不需要 */ public boolean executeActionReturnUndoRecordNeeded() { return false; } } \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/cell/ConditionAttributesAction.java b/designer/src/com/fr/design/actions/cell/ConditionAttributesAction.java new file mode 100644 index 000000000..61fe9fefe --- /dev/null +++ b/designer/src/com/fr/design/actions/cell/ConditionAttributesAction.java @@ -0,0 +1,37 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.cell; + +import com.fr.base.BaseUtils; +import com.fr.design.menu.KeySetUtils; +import com.fr.design.present.ConditionAttributesGroupPane; +import com.fr.design.dialog.BasicPane; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.report.cell.TemplateCellElement; + +/** + * Condition Attributes. + */ +public class ConditionAttributesAction extends AbstractCellElementAction { + public ConditionAttributesAction(ElementCasePane t) { + super(t); + this.setMenuKeySet(KeySetUtils.CONDITION_ATTR); + this.setName(getMenuKeySet().getMenuKeySetName()); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_format/highlight.png")); + } + + @Override + protected BasicPane populateBasicPane(TemplateCellElement cellElement) { + ConditionAttributesGroupPane pane = new ConditionAttributesGroupPane(); + pane.populate(cellElement.getHighlightGroup()); + + return pane; + } + + @Override + protected void updateBasicPane(BasicPane bp, TemplateCellElement cellElement) { + cellElement.setHighlightGroup(((ConditionAttributesGroupPane)bp).updateHighlightGroup()); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/cell/EditCellAction.java b/designer/src/com/fr/design/actions/cell/EditCellAction.java new file mode 100644 index 000000000..d9f1de6f5 --- /dev/null +++ b/designer/src/com/fr/design/actions/cell/EditCellAction.java @@ -0,0 +1,41 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.cell; + +import java.awt.Toolkit; +import java.awt.event.ActionEvent; + +import com.fr.base.BaseUtils; +import com.fr.design.actions.ElementCaseAction; +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; + +/** + * EditCellAction. + */ +public class EditCellAction extends ElementCaseAction { + public EditCellAction(ElementCasePane t) { + super(t); + + this.setName(Inter.getLocText("Edit")); + this.setMnemonic('I'); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/control/edit.png")); + } + + @Override + public void actionPerformed(ActionEvent evt) { + ElementCasePane reportPane = getEditingComponent(); + if(reportPane.isSelectedOneCell()){ + reportPane.getGrid().startEditing(); + }else{ + Toolkit.getDefaultToolkit().beep(); + } + } + + // TODO ALEX_SEP 这里的undo redo又是怎么回事呢? + @Override + public boolean executeActionReturnUndoRecordNeeded() { + return false; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/cell/FloatStyleAction.java b/designer/src/com/fr/design/actions/cell/FloatStyleAction.java new file mode 100644 index 000000000..baa63b0d8 --- /dev/null +++ b/designer/src/com/fr/design/actions/cell/FloatStyleAction.java @@ -0,0 +1,52 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.cell; + +import javax.swing.SwingUtilities; + +import com.fr.base.BaseUtils; +import com.fr.design.actions.ElementCaseAction; +import com.fr.design.menu.KeySetUtils; +import com.fr.design.report.ReportStylePane; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.mainframe.ElementCasePane; + +/** + * Cell Style. + */ +public class FloatStyleAction extends ElementCaseAction { + boolean okreturn = false; + + public FloatStyleAction(ElementCasePane t) { + super(t); + this.setMenuKeySet(KeySetUtils.GLOBAL_STYLE); + this.setName(getMenuKeySet().getMenuKeySetName()); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_format/cell.png")); + } + + /** + * 执行动作 + * @return 成功返回true + */ + public boolean executeActionReturnUndoRecordNeeded() { + final ElementCasePane reportPane = this.getEditingComponent(); + if (reportPane == null) { + return false; + } + final ReportStylePane reportStylePane = new ReportStylePane(); + final BasicDialog styleDialog = reportStylePane.showWindow(SwingUtilities.getWindowAncestor(reportPane)); + reportStylePane.populate(reportPane); + styleDialog.addDialogActionListener(new DialogActionAdapter() { + @Override + public void doOk() { + reportStylePane.update(reportPane); + FloatStyleAction.this.okreturn = true; + } + }); + styleDialog.setVisible(true); + return okreturn; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/cell/GlobalStyleMenuDef.java b/designer/src/com/fr/design/actions/cell/GlobalStyleMenuDef.java new file mode 100644 index 000000000..b33d26996 --- /dev/null +++ b/designer/src/com/fr/design/actions/cell/GlobalStyleMenuDef.java @@ -0,0 +1,153 @@ +package com.fr.design.actions.cell; + +/** + * richer:global style menu + */ + +import com.fr.base.BaseUtils; +import com.fr.base.ConfigManager; +import com.fr.base.NameStyle; +import com.fr.design.actions.ElementCaseAction; +import com.fr.design.actions.UpdateAction; +import com.fr.design.gui.imenu.UIMenu; +import com.fr.design.mainframe.CellElementPropertyPane; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.menu.KeySetUtils; +import com.fr.design.menu.MenuDef; +import com.fr.design.style.StylePane; +import com.fr.general.Inter; +import com.fr.base.ConfigManagerProvider; +import com.fr.stable.StringUtils; +import com.fr.stable.pinyin.PinyinHelper; + +import java.awt.event.ActionEvent; +import java.util.Iterator; + +public class GlobalStyleMenuDef extends MenuDef { + private static final int MAX_LENTH = 12; + private ElementCasePane ePane; + + public GlobalStyleMenuDef(ElementCasePane ePane) { + this.ePane = ePane; + this.setMenuKeySet(KeySetUtils.GLOBAL_STYLE); + this.setName(getMenuKeySet().getMenuKeySetName()); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setIconPath("/com/fr/design/images/m_web/style.png"); + } + + /** + * 更新菜单项 + */ + public void updateMenu() { + UIMenu createdMenu = this.createJMenu(); + createdMenu.removeAll(); + ConfigManagerProvider configManager = ConfigManager.getProviderInstance(); + Iterator iterator = configManager.getStyleNameIterator(); + while (iterator.hasNext()) { + String name = (String) iterator.next(); + NameStyle nameStyle = NameStyle.getInstance(name); + + UpdateAction.UseMenuItem useMenuItem = new GlobalStyleSelection(ePane, nameStyle).createUseMenuItem(); + useMenuItem.setNameStyle(nameStyle); + createdMenu.add(useMenuItem); + } + createdMenu.addSeparator(); + createdMenu.add(new CustomStyleAction(Inter.getLocText("FR-Engine_Custom"))); + } + + /** + * 控制自定义样式名称的长度 + * + * @param longName 名字 + * @return 控制之后的名字 + */ + public static String judgeChina(String longName) { + + //neil:bug 1623 控制自定义样式名称的长度,只显示前12个字符,每个英文算1个字符,每个汉字算2个字符 + Integer index = 0; + StringBuffer sBuffer = new StringBuffer(); + for (int i = 0; i < longName.length(); i++) { + String bb = longName.substring(i, i + 1); //生成一个Pattern,同时编译一个正则表达式 + boolean cc = PinyinHelper.isChinese(bb.charAt(0)); + if (index == MAX_LENTH) { + sBuffer.append(".."); + break; + } + if ((index == MAX_LENTH - 1 && cc)) { + continue; + } + if (cc) { + index = index + 2; + } else { + index = index + 1; + } + + sBuffer.append(bb); + if (index > MAX_LENTH) { + sBuffer.append(".."); + break; + } + + } + + return sBuffer.toString(); + + } + + public static class CustomStyleAction extends UpdateAction { + + public CustomStyleAction(String name) { + + this.setName(name); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_format/cell.png")); + } + + /** + * 动作 + * + * @param e 事件 + */ + public void actionPerformed(ActionEvent e) { + CellElementPropertyPane.getInstance().GoToPane(new String[]{Inter.getLocText("FR-Engine_Style"), Inter.getLocText("FR-Engine_Custom")}); + } + + } + + public static class GlobalStyleSelection extends ElementCaseAction { + + private NameStyle nameStyle; + + public GlobalStyleSelection(ElementCasePane t, NameStyle nameStyle) { + super(t); + setName(StringUtils.EMPTY); + //重复画了一次,不需要icon +// this.setName(nameStyle == null ? "" : nameStyle.getName()); +// this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_format/cell.png")); + this.setNameStyle(nameStyle); + } + + public NameStyle getNameStyle() { + return this.nameStyle; + } + + public void setNameStyle(NameStyle nameStyle) { + this.nameStyle = nameStyle; + } + + /** + * 执行动作返回 + * @return 是返回true + */ + public boolean executeActionReturnUndoRecordNeeded() { + StylePane stylePane = new StylePane(); + if (StringUtils.isEmpty(this.getName())) { + stylePane.setGlobalStyle(this.getNameStyle()); + } else { + stylePane.setGlobalStyle(NameStyle.getInstance(this.getName())); + } + + stylePane.updateGlobalStyle(getEditingComponent()); + return true; + } + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/cell/NewPresentAction.java b/designer/src/com/fr/design/actions/cell/NewPresentAction.java new file mode 100644 index 000000000..a35333d61 --- /dev/null +++ b/designer/src/com/fr/design/actions/cell/NewPresentAction.java @@ -0,0 +1,84 @@ +package com.fr.design.actions.cell; + +import com.fr.base.present.Present; +import com.fr.design.actions.PresentCheckBoxAction; +import com.fr.design.mainframe.CellElementPropertyPane; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.general.ComparatorUtils; +import com.fr.general.GeneralUtils; +import com.fr.general.Inter; +import com.fr.grid.selection.CellSelection; +import com.fr.grid.selection.Selection; +import com.fr.report.cell.TemplateCellElement; +import com.fr.stable.StableUtils; + +public class NewPresentAction extends PresentCheckBoxAction { + + private String itemName = null; + + public NewPresentAction(ElementCasePane t, String title, String name) { + super(t); + + this.setName(title); + this.itemName = name; + } + + @Override + public boolean executeActionReturnUndoRecordNeeded() { + if (!ComparatorUtils.equals(this.itemName, "NOPRESENT")) { + CellElementPropertyPane.getInstance().GoToPane(Inter.getLocText("Present"), this.itemName); + } else { + TemplateCellElement ce = getSelectedCellElement(); + // 只有原来ce设置了形态的情况下才有undo操作 + if (ce != null && ce.getPresent() != null) { + ce.setPresent(null); + return true; + } else { + return false; + } + } + return false; + } + + @Override + public boolean isSelected() { + return hasCurrentPresentSet(); + } + + // TODO ALEX_SEP enable有没有可能也通过这个方法来解决呢? + private TemplateCellElement getSelectedCellElement() { + ElementCasePane ePane = this.getEditingComponent(); + Selection sel = ePane.getSelection(); + if (sel instanceof CellSelection) { + return (TemplateCellElement) ePane.getEditingElementCase().getCellElement(((CellSelection) sel).getColumn(), ((CellSelection) sel).getRow()); + } + return null; + } + + @Override + public void update() { + ElementCasePane ePane = this.getEditingComponent(); + Selection sel = ePane.getSelection(); + if (sel instanceof CellSelection) { + this.setEnabled(true); + } else { + this.setEnabled(false); + } + } + + public boolean hasCurrentPresentSet() { + TemplateCellElement ce = getSelectedCellElement(); + if (ce != null) { + Present currentPresent = ce.getPresent(); + try { + Class clazz = GeneralUtils.classForName(itemName); + if (itemName.equals(currentPresent.getClass().getName())) { + return StableUtils.classInstanceOf(currentPresent.getClass(), clazz); + } + } catch (Exception e) { + return "NOPRESENT".equals(itemName) && currentPresent == null; + } + } + return false; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/cell/StyleAction.java b/designer/src/com/fr/design/actions/cell/StyleAction.java new file mode 100644 index 000000000..9d6e3e1d0 --- /dev/null +++ b/designer/src/com/fr/design/actions/cell/StyleAction.java @@ -0,0 +1,33 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.cell; + + +import java.awt.event.ActionEvent; + +import com.fr.base.BaseUtils; +import com.fr.design.actions.UpdateAction; +import com.fr.design.mainframe.CellElementPropertyPane; +import com.fr.design.menu.KeySetUtils; +import com.fr.general.Inter; + +public class StyleAction extends UpdateAction { + + public StyleAction() { + + this.setMenuKeySet(KeySetUtils.GLOBAL_STYLE); + this.setName(getMenuKeySet().getMenuKeySetName()); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_format/cell.png")); + } + + /** + * 动作 + * @param e 事件 + */ + public void actionPerformed(ActionEvent e) { + CellElementPropertyPane.getInstance().GoToPane(new String[] { Inter.getLocText("Style"), Inter.getLocText("Custom") }); + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/cell/UIToolbarBorderButton.java b/designer/src/com/fr/design/actions/cell/UIToolbarBorderButton.java new file mode 100644 index 000000000..eaa063c2d --- /dev/null +++ b/designer/src/com/fr/design/actions/cell/UIToolbarBorderButton.java @@ -0,0 +1,308 @@ +package com.fr.design.actions.cell; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.GridLayout; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.Icon; +import javax.swing.JPanel; +import javax.swing.JPopupMenu; +import javax.swing.JSeparator; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.event.EventListenerList; + +import com.fr.base.BaseUtils; +import com.fr.base.CellBorderStyle; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.ibutton.UICombinationButton; +import com.fr.design.gui.ipoppane.PopupHider; +import com.fr.design.icon.BorderIcon; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.style.BorderUtils; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.stable.Constants; +import com.fr.design.style.BorderPane; +import com.fr.design.style.color.TransparentPane; +import com.fr.design.utils.gui.GUICoreUtils; + +/** + * 这个Pane用来显示常用边框和设置自定义边框 + * + * @author richer + * + */ +public class UIToolbarBorderButton extends UICombinationButton implements PopupHider { + private EventListenerList styleChangeListenerList = new EventListenerList(); + private boolean isCanBeNull = false; + private ElementCasePane reportPane; + private JPopupMenu popupWin; + + public UIToolbarBorderButton(Icon icon, ElementCasePane reportPane) { + super(new UIButton(icon), new UIButton(BaseUtils.readIcon("/com/fr/design/images/gui/popup.gif"))); + this.reportPane = reportPane; + } + + public CellBorderStyle getCellBorderStyle() { + return this.cellBorderStyle; + } + + public void setCellBorderStyle(CellBorderStyle cellBorderStyle) { + this.cellBorderStyle = cellBorderStyle; + this.leftButton.setIcon(new BorderIcon(cellBorderStyle)); + fireStyleStateChanged(); + } + + @Override + public void setEnabled(boolean enabled) { + super.setEnabled(enabled); + + if (!enabled) { + cellBorderStyle = null; + } + + leftButton.setEnabled(enabled); + rightButton.setEnabled(enabled); + } + + @Override + public void setToolTipText(String tooltipText) { + super.setToolTipText(tooltipText); + + leftButton.setToolTipText(tooltipText); + rightButton.setToolTipText(tooltipText); + } + + + private void showPopupMenu() { + if (popupWin != null && popupWin.isVisible()) { + hidePopupMenu(); + return; + } + + if (!this.isEnabled()) { + return; + } + + popupWin = this.getActionPopupMenu(); + GUICoreUtils.showPopupMenu(popupWin, this, 0, this.getSize().height); + } + + protected JPopupMenu getActionPopupMenu() { + if (this.popupWin == null) { + this.popupWin = new BorderStyleControlWindow(this.isCanBeNull()); + } + + return popupWin; + } + + protected void leftButtonClickEvent() { + UIToolbarBorderButton.this.cellBorderStyle = ((BorderIcon)getLeftButton().getIcon()).cellBorderStyle; + UIToolbarBorderButton.this.fireStyleStateChanged(); + } + + @Override + protected void rightButtonClickEvent() { + showPopupMenu(); + } + + class BorderStyleControlWindow extends JPopupMenu { + + /** + * Constructor + */ + public BorderStyleControlWindow(boolean isSupportTransparent) { + this.initComponents(isSupportTransparent); + } + + public void initComponents(boolean isSupportTransparent) { + setLightWeightPopupEnabled(JPopupMenu.getDefaultLightWeightPopupEnabled()); + + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + setBorderPainted(true); + setBorder(UIManager.getBorder("PopupMenu.border")); + setOpaque(false); + setDoubleBuffered(true); + setFocusable(false); + + this.add(new NormalBorderPane(isSupportTransparent, UIToolbarBorderButton.this), BorderLayout.CENTER); + this.pack(); + } + } + + // richer:常用边框线类型展现面板 + class NormalBorderPane extends TransparentPane { + PopupHider popupHider; + + public NormalBorderPane(boolean isSupportTransparent, PopupHider popupHider) { + super(isSupportTransparent); + this.popupHider = popupHider; + } + + @Override + public void initCenterPaneChildren(JPanel centerPane) { + JPanel menuColorPane = new /**/JPanel(); + centerPane.add(menuColorPane); + + menuColorPane.setLayout(new /**/GridLayout(3, 4, 2, 2)); + for (int i = 0; i < borderStyleArray.length; i++) { + final UIButton borderStyleCell = new UIButton(new BorderIcon(borderStyleArray[i])); + borderStyleCell.set4ToolbarButton(); + borderStyleCell.addMouseListener(new MouseAdapter() { + @Override + public void mousePressed(MouseEvent e) { + UIButton toolBarButton = (UIButton) e.getSource(); + if (toolBarButton.getIcon() instanceof BorderIcon) { + BorderIcon borderIcon = (BorderIcon) toolBarButton.getIcon(); + UIToolbarBorderButton.this.setCellBorderStyle(borderIcon.cellBorderStyle); + hidePopupMenu(); + } else { + UIToolbarBorderButton.this.setCellBorderStyle(borderStyleArray[0]); + } + } + }); + + borderStyleCell.addMouseListener(new MouseAdapter() { + + @Override + public void mouseEntered(MouseEvent e) { + borderStyleCell.setBorder(BorderFactory.createEtchedBorder()); + } + + @Override + public void mouseExited(MouseEvent e) { + borderStyleCell.setBorder(null); + } + }); + borderStyleCell.setToolTipText(BorderStyleTooltips[i]); + menuColorPane.add(borderStyleCell); + } + + centerPane.add(Box.createVerticalStrut(5)); + centerPane.add(new JSeparator()); + centerPane.add(Box.createVerticalStrut(5)); + } + + @Override + public void doTransparent() { + UIToolbarBorderButton.this.setCellBorderStyle(null); + popupHider.hidePopupMenu(); + } + + @Override + public void customButtonPressed() { + popupHider.hidePopupMenu(); + final BorderPane borderPane = new BorderPane(); + BasicDialog borderDialog = borderPane.showWindow(SwingUtilities.getWindowAncestor(reportPane)); + Object[] fourObjectArray = BorderUtils.createCellBorderObject(reportPane); + if (fourObjectArray != null && fourObjectArray.length == 4) { + borderPane.populate((CellBorderStyle) fourObjectArray[0], ((Boolean) fourObjectArray[1]).booleanValue(), + ((Integer) fourObjectArray[2]).intValue(), (Color) fourObjectArray[3]); + } + borderDialog.addDialogActionListener(new DialogActionAdapter() { + + @Override + public void doOk() { + CellBorderStyle cellBorderStyle = borderPane.update(); + UIToolbarBorderButton.this.setCellBorderStyle(cellBorderStyle); + } + }); + borderDialog.setVisible(true); + + } + + @Override + protected String title4PopupWindow() { + return Inter.getLocText("Border"); + } + } + + /** + * Adds a new StyleChangeListener + */ + public void addStyleChangeListener(ChangeListener changeListener) { + styleChangeListenerList.add(ChangeListener.class, changeListener); + } + + /** + * Removes an old StyleChangeListener. + */ + public void removeColorChangeListener(ChangeListener changeListener) { + styleChangeListenerList.remove(ChangeListener.class, changeListener); + } + + /** + * + */ + public void fireStyleStateChanged() { + Object[] listeners = styleChangeListenerList.getListenerList(); + ChangeEvent e = null; + + for (int i = listeners.length - 2; i >= 0; i -= 2) { + if (listeners[i] == ChangeListener.class) { + if (e == null) { + e = new ChangeEvent(this); + } + ((ChangeListener) listeners[i + 1]).stateChanged(e); + } + } + } + + public boolean isCanBeNull() { + return this.isCanBeNull; + } + + public void setCanBeNull(boolean isCanBeNull) { + this.isCanBeNull = isCanBeNull; + } + + private CellBorderStyle cellBorderStyle = new CellBorderStyle(); + + private static final CellBorderStyle[] borderStyleArray = { + new CellBorderStyle(), + new CellBorderStyle(Color.black, Constants.LINE_NONE, Color.black, Constants.LINE_NONE, Color.black, Constants.LINE_THIN, Color.black, + Constants.LINE_NONE, Color.black, Constants.LINE_NONE, Color.black, Constants.LINE_NONE), + new CellBorderStyle(Color.black, Constants.LINE_NONE, Color.black, Constants.LINE_THIN, Color.black, Constants.LINE_NONE, Color.black, + Constants.LINE_NONE, Color.black, Constants.LINE_NONE, Color.black, Constants.LINE_NONE), + new CellBorderStyle(Color.black, Constants.LINE_NONE, Color.black, Constants.LINE_NONE, Color.black, Constants.LINE_NONE, Color.black, + Constants.LINE_THIN, Color.black, Constants.LINE_NONE, Color.black, Constants.LINE_NONE), + new CellBorderStyle(Color.black, Constants.LINE_NONE, Color.black, Constants.LINE_NONE, Color.black, Constants.LINE_DOUBLE, Color.black, + Constants.LINE_NONE, Color.black, Constants.LINE_NONE, Color.black, Constants.LINE_NONE), + new CellBorderStyle(Color.black, Constants.LINE_NONE, Color.black, Constants.LINE_NONE, Color.black, Constants.LINE_THICK, Color.black, + Constants.LINE_NONE, Color.black, Constants.LINE_NONE, Color.black, Constants.LINE_NONE), + new CellBorderStyle(Color.black, Constants.LINE_THIN, Color.black, Constants.LINE_NONE, Color.black, Constants.LINE_THIN, Color.black, + Constants.LINE_NONE, Color.black, Constants.LINE_NONE, Color.black, Constants.LINE_NONE), + new CellBorderStyle(Color.black, Constants.LINE_THIN, Color.black, Constants.LINE_NONE, Color.black, Constants.LINE_DOUBLE, Color.black, + Constants.LINE_NONE, Color.black, Constants.LINE_NONE, Color.black, Constants.LINE_NONE), + new CellBorderStyle(Color.black, Constants.LINE_THIN, Color.black, Constants.LINE_NONE, Color.black, Constants.LINE_THICK, Color.black, + Constants.LINE_NONE, Color.black, Constants.LINE_NONE, Color.black, Constants.LINE_NONE), + new CellBorderStyle(Color.black, Constants.LINE_THIN, Color.black, Constants.LINE_THIN, Color.black, Constants.LINE_THIN, Color.black, + Constants.LINE_THIN, Color.black, Constants.LINE_THIN, Color.black, Constants.LINE_THIN), + new CellBorderStyle(Color.black, Constants.LINE_THIN, Color.black, Constants.LINE_THIN, Color.black, Constants.LINE_THIN, Color.black, + Constants.LINE_THIN, Color.black, Constants.LINE_NONE, Color.black, Constants.LINE_NONE), + new CellBorderStyle(Color.black, Constants.LINE_THICK, Color.black, Constants.LINE_THICK, Color.black, Constants.LINE_THICK, Color.black, + Constants.LINE_THICK, Color.black, Constants.LINE_NONE, Color.black, Constants.LINE_NONE) }; + private static final String[] BorderStyleTooltips = { Inter.getLocText("NO_Border_Line"), Inter.getLocText("Bottom_Border_Line"), + Inter.getLocText("Left_Border_Line"), Inter.getLocText("Right_Border_Line"), Inter.getLocText("Double_Bottom_BorderLine"), + Inter.getLocText("Thick_Bottom_Border_Line"), Inter.getLocText("Top_Bottom_Border_Line"), + Inter.getLocText("Top_And_Double_Bottom_Border_Line"), Inter.getLocText("Top_And_Thick_Bottom_Border_Line"), + Inter.getLocText("All_Border_Line"), Inter.getLocText("Out_Border_Line"), Inter.getLocText("Out_Thick_Border_Line") }; + + @Override + public void hidePopupMenu() { + if (popupWin != null) { + popupWin.setVisible(false); + } + + popupWin = null; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/cell/style/AbstractStyleAction.java b/designer/src/com/fr/design/actions/cell/style/AbstractStyleAction.java new file mode 100644 index 000000000..3a3101d01 --- /dev/null +++ b/designer/src/com/fr/design/actions/cell/style/AbstractStyleAction.java @@ -0,0 +1,82 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.cell.style; + +import com.fr.base.Style; +import com.fr.base.chart.BaseChartCollection; +import com.fr.design.actions.ElementCaseAction; +import com.fr.design.actions.utils.ReportActionUtils; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.selection.CellSelection; +import com.fr.grid.selection.FloatSelection; +import com.fr.grid.selection.Selection; +import com.fr.report.cell.FloatElement; +import com.fr.report.elementcase.TemplateElementCase; + +/** + * Abstract cellstyle. + */ +public abstract class AbstractStyleAction extends ElementCaseAction implements StyleActionInterface { + protected AbstractStyleAction(ElementCasePane t) { + super(t); + } + + @Override + public abstract Style executeStyle(Style style, Style defStyle); + + @Override + public boolean executeActionReturnUndoRecordNeeded() { + ElementCasePane reportPane = this.getEditingComponent(); + if (reportPane == null) { + return false; + } + + return ReportActionUtils.executeAction(this, reportPane); + } + + /** + * Update Style. + * + * @param style the updated style. + */ + @Override + public void updateStyle(Style style) { + // peter:这个方法默认情况下什么都不做. + } + + public boolean isFontStye() { + return true; + } + + @Override + public void update() { + // james:应该从Action中的ReportPane拿Style,而不是从reportFrame中拿 + this.setEnabled(true); + ElementCasePane reportPane = this.getEditingComponent(); + if (reportPane == null) { + this.setEnabled(false); + return; + } + if (isFontStye()) { + Selection cs = reportPane.getSelection(); + TemplateElementCase tplEC = reportPane.getEditingElementCase(); + + if (tplEC != null && cs instanceof FloatSelection) { + FloatElement selectedFloat = tplEC.getFloatElement(((FloatSelection) cs).getSelectedFloatName()); + if (selectedFloat == null) { + //有情况是撤销worksheet里面的元素撤消了,但是reportpane里面的selection没有变 + reportPane.setSelection(new CellSelection()); + return; + } + Object value = selectedFloat.getValue(); + if (value instanceof BaseChartCollection) { + this.setEnabled(false); + return; + } + } + } + // 更新Style + this.updateStyle(ReportActionUtils.getCurrentStyle(reportPane)); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/cell/style/AlignmentAction.java b/designer/src/com/fr/design/actions/cell/style/AlignmentAction.java new file mode 100644 index 000000000..326b47f65 --- /dev/null +++ b/designer/src/com/fr/design/actions/cell/style/AlignmentAction.java @@ -0,0 +1,111 @@ +package com.fr.design.actions.cell.style; + +import javax.swing.Icon; + +import com.fr.base.BaseUtils; +import com.fr.base.Style; +import com.fr.base.chart.BaseChartCollection; +import com.fr.design.constants.UIConstants; +import com.fr.design.actions.ButtonGroupAction; +import com.fr.design.actions.utils.ReportActionUtils; +import com.fr.design.gui.ibutton.UIButtonGroup; +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.selection.FloatSelection; +import com.fr.grid.selection.Selection; +import com.fr.report.cell.FloatElement; +import com.fr.report.elementcase.TemplateElementCase; + + +public class AlignmentAction extends ButtonGroupAction implements StyleActionInterface { + + public AlignmentAction(ElementCasePane t, Icon[] iconArray, + Integer[] valueArray) { + super(t, iconArray, valueArray); + } + + + /** + * executeStyle + * + * @param style + * @param selectedStyle + * @return style + */ + public Style executeStyle(Style style, Style selectedStyle) { + return style.deriveHorizontalAlignment(getSelectedValue()); + } + + /** + * 更新Style + * + * @param style style + */ + public void updateStyle(Style style) { + setSelectedIndex(BaseUtils.getAlignment4Horizontal(style)); + } + + /** + * executeActionReturnUndoRecordNeeded + * + * @return + */ + public boolean executeActionReturnUndoRecordNeeded() { + ElementCasePane reportPane = this.getEditingComponent(); + if (reportPane == null) { + return false; + } + + return ReportActionUtils.executeAction(this, reportPane); + } + + /** + * update + */ + public void update() { + super.update(); + + //peter:如果当前没有ReportFrame,不需要继续. + if (!this.isEnabled()) { + return; + } + + //got simple cell element from row and column + ElementCasePane reportPane = this.getEditingComponent(); + if (reportPane == null) { + this.setEnabled(false); + return; + } + Selection cs = reportPane.getSelection(); + TemplateElementCase tplEC = reportPane.getEditingElementCase(); + + if (tplEC != null && cs instanceof FloatSelection) { + FloatElement selectedFloat = tplEC.getFloatElement(((FloatSelection) cs).getSelectedFloatName()); + Object value = selectedFloat.getValue(); + if (value instanceof BaseChartCollection) { + this.setEnabled(false); + return; + } + } + this.updateStyle(ReportActionUtils.getCurrentStyle(reportPane)); + } + + /** + * 创建工具条,且有提示 + * + * @return + */ + public UIButtonGroup createToolBarComponent() { + UIButtonGroup group = super.createToolBarComponent(); + if (group != null) { + group.setForToolBarButtonGroup(true); + group.setAllToolTips(new String[]{Inter.getLocText("StyleAlignment-Left"), Inter.getLocText("Center"), Inter.getLocText("StyleAlignment-Right")}); + } + for (int i = 0; i < 3; i++) { + group.getButton(i).setRoundBorder(true, UIConstants.ARC); + group.getButton(i).setBorderPainted(true); + } + return group; + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/cell/style/ReportFontBoldAction.java b/designer/src/com/fr/design/actions/cell/style/ReportFontBoldAction.java new file mode 100644 index 000000000..101d1f1f0 --- /dev/null +++ b/designer/src/com/fr/design/actions/cell/style/ReportFontBoldAction.java @@ -0,0 +1,91 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.cell.style; + +import com.fr.base.BaseUtils; +import com.fr.base.Style; +import com.fr.base.core.StyleUtils; +import com.fr.design.actions.ToggleButtonUpdateAction; +import com.fr.design.gui.ibutton.UIToggleButton; +import com.fr.general.FRFont; +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.utils.gui.GUICoreUtils; + +/** + * Bold. + */ +public class ReportFontBoldAction extends AbstractStyleAction implements ToggleButtonUpdateAction { + private UIToggleButton button; + protected Style style; + + public ReportFontBoldAction(ElementCasePane t) { + super(t); + + this.setName(Inter.getLocText("FRFont-bold")); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/bold.png")); + } + + /** + * 根据按钮状态获取格式 + * + * @param style + * @param defStyle + * @return + */ + @Override + public Style executeStyle(Style style, Style defStyle) { + createToolBarComponent().setSelected(!createToolBarComponent().isSelected()); + if (createToolBarComponent().isSelected()) { + setSelectedFont(style); + createToolBarComponent().setSelected(false); + } else { + setUnselectedFont(style); + createToolBarComponent().setSelected(true); + } + + return this.style; + } + + protected void setSelectedFont(Style style) { + this.style = StyleUtils.boldReportFont(style); + } + + protected void setUnselectedFont(Style style) { + this.style = StyleUtils.unBoldReportFont(style); + } + + /** + * Update Style. + */ + @Override + public void updateStyle(Style style) { + if (style == null) { + return; + } + FRFont frFont = style.getFRFont(); + if (frFont == null) { + return; + } + createToolBarComponent().setSelected(isStyle(frFont)); + } + + protected boolean isStyle(FRFont frFont) { + return frFont.isBold(); + } + + /** + * Gets component on toolbar. + * + * @return the created components on toolbar. + */ + @Override + public UIToggleButton createToolBarComponent() { + if (button == null) { + button = GUICoreUtils.createToolBarComponent(this); + button.setEventBannded(true); + } + return button; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/cell/style/ReportFontForegroundAction.java b/designer/src/com/fr/design/actions/cell/style/ReportFontForegroundAction.java new file mode 100644 index 000000000..d3ceb77c0 --- /dev/null +++ b/designer/src/com/fr/design/actions/cell/style/ReportFontForegroundAction.java @@ -0,0 +1,68 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.cell.style; + +import java.awt.Color; + +import javax.swing.JComponent; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +import com.fr.base.BaseUtils; +import com.fr.base.Style; +import com.fr.base.core.StyleUtils; +import com.fr.design.actions.core.ActionUtils; +import com.fr.general.ComparatorUtils; +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.style.color.UIToolbarColorButton; + +/** + * Foreground. + */ +public class ReportFontForegroundAction extends AbstractStyleAction implements ChangeListener { + public ReportFontForegroundAction(ElementCasePane t) { + super(t); + + this.setName(Inter.getLocText("Foreground")); + } + + public void stateChanged(ChangeEvent evt) { + this.actionPerformedUndoable(); + } + + @Override + public Style executeStyle(Style style, Style defStyle) { + Object object = this.getValue(UIToolbarColorButton.class.getName()); + if (object != null && object instanceof UIToolbarColorButton) { + Color selectedColor = ((UIToolbarColorButton) object).getColor(); + if (style.getFRFont() != null && + ComparatorUtils.equals(selectedColor, style.getFRFont())) { + return style; + } + + style = StyleUtils.setReportFontForeground(style, selectedColor); + } + + return style; + } + + @Override + public JComponent createToolBarComponent() { + Object object = this.getValue(UIToolbarColorButton.class.getName()); + if (object == null || !(object instanceof UIToolbarColorButton)) { + UIToolbarColorButton tbButton = new UIToolbarColorButton(BaseUtils.readIcon("/com/fr/design/images/gui/color/foreground.png")); + this.putValue(UIToolbarColorButton.class.getName(), tbButton); + tbButton.set4Toolbar(); + tbButton.setEnabled(this.isEnabled()); + tbButton.addColorChangeListener(this); + + //peter:产生tooltip + tbButton.setToolTipText(ActionUtils.createButtonToolTipText(this)); + return tbButton; + } + + return (JComponent) object; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/cell/style/ReportFontItalicAction.java b/designer/src/com/fr/design/actions/cell/style/ReportFontItalicAction.java new file mode 100644 index 000000000..1e6c87a1a --- /dev/null +++ b/designer/src/com/fr/design/actions/cell/style/ReportFontItalicAction.java @@ -0,0 +1,39 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.cell.style; + +import com.fr.base.BaseUtils; +import com.fr.base.Style; +import com.fr.base.core.StyleUtils; +import com.fr.general.FRFont; +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; + +/** + * Bold. + */ +public class ReportFontItalicAction extends ReportFontBoldAction { + + public ReportFontItalicAction(ElementCasePane t) { + super(t); + + this.setName(Inter.getLocText("FRFont-italic")); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/italic.png")); + } + + + protected void setSelectedFont (Style style) { + this.style = StyleUtils.italicReportFont(style); + } + + protected void setUnselectedFont (Style style) { + this.style = StyleUtils.unItalicReportFont(style); + } + + + protected boolean isStyle(FRFont frFont) { + return frFont.isItalic(); + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/cell/style/ReportFontNameAction.java b/designer/src/com/fr/design/actions/cell/style/ReportFontNameAction.java new file mode 100644 index 000000000..b68976806 --- /dev/null +++ b/designer/src/com/fr/design/actions/cell/style/ReportFontNameAction.java @@ -0,0 +1,104 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.cell.style; + +import java.awt.Dimension; + +import javax.swing.ComboBoxModel; +import javax.swing.JComponent; + +import com.fr.base.Style; +import com.fr.base.Utils; +import com.fr.base.core.StyleUtils; +import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.general.ComparatorUtils; +import com.fr.general.FRFont; +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; + +/** + * Font name.. + */ +public class ReportFontNameAction extends AbstractStyleAction { + public ReportFontNameAction(ElementCasePane t) { + super(t); + + this.setName(Inter.getLocText("FRFont-Family")); + } + + @Override + public Style executeStyle(Style style, Style defStyle) { + Object object = this.getValue(UIComboBox.class.getName()); + if (object != null && object instanceof UIComboBox) { + String selectedFontName = (String) ((UIComboBox) object).getSelectedItem(); + //这两个if 语句的意思是:如果传过来的cellStyle.getFRFont() 即不为空也和原来的被选择的相同。则不改变。 + // 首先判断是否为空,如果空出错。 + //然后将它们的类型均转化为delCellStyle相同。然后再将之判断是否与选择的相同否。如不同则转化为相同。 + if (ComparatorUtils.equals(style.getFRFont().getName(), defStyle.getFRFont().getName())) { + style = StyleUtils.setReportFontName(style, defStyle.getFRFont().getName()); + } + if (ComparatorUtils.equals(selectedFontName, style.getFRFont().getName())) { + return style; + } + style = StyleUtils.setReportFontName(style, selectedFontName); + } + + return style; + } + + public void setFontName(String fontName) { + Object object = this.getValue(UIComboBox.class.getName()); + if (object != null && object instanceof UIComboBox) { + UIComboBox comboBox = (UIComboBox) object; + ComboBoxModel comboBoxModel = comboBox.getModel(); + for (int i = 0; i < comboBoxModel.getSize(); i++) { + Object item = comboBoxModel.getElementAt(i); + + if (ComparatorUtils.equals(item, fontName)) { + //设置新Font Name + comboBox.removeActionListener(this); + comboBox.setSelectedIndex(i); + comboBox.addActionListener(this); + break; + } + } + } + } + + @Override + public JComponent createToolBarComponent() { + Object object = this.getValue(UIComboBox.class.getName()); + if (object == null || !(object instanceof UIComboBox)) { + UIComboBox itemComponent = new UIComboBox(Utils.getAvailableFontFamilyNames4Report()); + this.putValue(UIComboBox.class.getName(), itemComponent); + //设置最佳宽度. + itemComponent.setPreferredSize(new Dimension( + Math.min(140, itemComponent.getPreferredSize().width), + itemComponent.getPreferredSize().height)); + + itemComponent.setEnabled(this.isEnabled()); + itemComponent.addActionListener(this); + + return itemComponent; + } + + return (UIComboBox) object; + } + + /** + * Update Style. + */ + @Override + public void updateStyle(Style style) { + if (style == null) { + return; + } + FRFont frFont = style.getFRFont(); + if (frFont == null) { + return; + } + + this.setFontName(frFont.getFamily()); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/cell/style/ReportFontSizeAction.java b/designer/src/com/fr/design/actions/cell/style/ReportFontSizeAction.java new file mode 100644 index 000000000..bae2330ef --- /dev/null +++ b/designer/src/com/fr/design/actions/cell/style/ReportFontSizeAction.java @@ -0,0 +1,127 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.cell.style; + +import java.awt.Dimension; +import java.util.Vector; + +import javax.swing.JComponent; + +import com.fr.base.Style; +import com.fr.base.Utils; +import com.fr.base.core.StyleUtils; +import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.general.ComparatorUtils; +import com.fr.general.FRFont; +import com.fr.general.Inter; + +/** + * Font size. + */ +public class ReportFontSizeAction extends AbstractStyleAction { + + private static final int MAX_FONT_SIZE = 100; + + public ReportFontSizeAction(ElementCasePane t) { + super(t); + + this.setName(Inter.getLocText("FRFont-Size")); + } + + /** + * 应用选中的样式 + * + * @param style 之前的样式 + * @param defStyle 选中的样式 + * + * @return 更改后的样式 + * + * @date 2015-1-22-下午4:54:00 + * + */ + public Style executeStyle(Style style, Style defStyle) { + Object object = this.getValue(UIComboBox.class.getName()); + if (object != null && object instanceof UIComboBox) { + Object value = ((UIComboBox) object).getSelectedItem(); + float selectedFontSize; + selectedFontSize = Utils.round5(Float.parseFloat(value.toString())); + + if (style.getFRFont().getSize() == defStyle.getFRFont().getSize()) { + style = StyleUtils.setReportFontSize(style, defStyle.getFRFont().getSize()); + } + if (selectedFontSize == style.getFRFont().getSize()) { + return style; + } + style = StyleUtils.setReportFontSize(style, selectedFontSize); + } + + return style; + } + + public void setFontSize(float size) { + Object object = this.getValue(UIComboBox.class.getName()); + if (object != null && object instanceof UIComboBox) { + UIComboBox comboBox = (UIComboBox) object; + //先和以前的Font Size比较. + if (ComparatorUtils.equals(comboBox.getSelectedItem(), size)) { + return; + } + + //设置新Font Size + comboBox.removeActionListener(this); + comboBox.setSelectedItem(size + ""); + comboBox.addActionListener(this); + } + } + + /** + * 创建工具栏组件 + * + * @return 组件 + * + * @date 2015-1-22-下午4:53:29 + * + */ + public JComponent createToolBarComponent() { + Object object = this.getValue(UIComboBox.class.getName()); + if (object == null || !(object instanceof UIComboBox)) { + Vector integerList = new Vector(); + for (int i = 1; i < MAX_FONT_SIZE; i++) { + integerList.add(i); + } + + UIComboBox itemComponent = new UIComboBox(integerList); + this.putValue(UIComboBox.class.getName(), itemComponent); + itemComponent.setMinimumSize(new Dimension(50, 20)); + itemComponent.setPreferredSize(new Dimension(50, 20)); + itemComponent.setEnabled(this.isEnabled()); + itemComponent.addActionListener(this); + //需求字体大小可编辑 + itemComponent.setEditable(true); + + return itemComponent; + } + + return (JComponent) object; + } + + /** + * 更新样式 + * + * @param style 样式 + * + */ + @Override + public void updateStyle(Style style) { + if (style == null) { + return; + } + FRFont frFont = style.getFRFont(); + if (frFont == null) { + return; + } + setFontSize(Utils.round5(frFont.getSize2D())); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/cell/style/ReportFontUnderlineAction.java b/designer/src/com/fr/design/actions/cell/style/ReportFontUnderlineAction.java new file mode 100644 index 000000000..e79782abf --- /dev/null +++ b/designer/src/com/fr/design/actions/cell/style/ReportFontUnderlineAction.java @@ -0,0 +1,38 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.cell.style; + +import com.fr.base.BaseUtils; +import com.fr.base.Style; +import com.fr.base.core.StyleUtils; +import com.fr.general.FRFont; +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.stable.Constants; + +/** + * Bold. + */ +public class ReportFontUnderlineAction extends ReportFontBoldAction { + public ReportFontUnderlineAction(ElementCasePane t) { + super(t); + + this.setName(Inter.getLocText("FRFont-Underline")); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/underline.png")); + } + + protected void setSelectedFont (Style style) { + this.style = StyleUtils.setReportFontUnderline(style, true); + } + + protected void setUnselectedFont (Style style) { + this.style = StyleUtils.setReportFontUnderline(style, false); + } + + + protected boolean isStyle(FRFont frFont) { + return frFont.getUnderline() != Constants.LINE_NONE; + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/cell/style/StyleActionInterface.java b/designer/src/com/fr/design/actions/cell/style/StyleActionInterface.java new file mode 100644 index 000000000..e6c2b2707 --- /dev/null +++ b/designer/src/com/fr/design/actions/cell/style/StyleActionInterface.java @@ -0,0 +1,17 @@ +package com.fr.design.actions.cell.style; + +import com.fr.base.Style; + +/** + * peter:这个方法只是在编辑Style的时候使用. + */ +public interface StyleActionInterface { + public Style executeStyle(Style style2Mod, Style selectedStyle); + + /** + * Update Style. + * + * @param style style + */ + public void updateStyle(Style style); +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/cell/style/StyleBackgroundAction.java b/designer/src/com/fr/design/actions/cell/style/StyleBackgroundAction.java new file mode 100644 index 000000000..b3304727a --- /dev/null +++ b/designer/src/com/fr/design/actions/cell/style/StyleBackgroundAction.java @@ -0,0 +1,77 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.cell.style; + +import java.awt.Color; + +import javax.swing.JComponent; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +import com.fr.base.BaseUtils; +import com.fr.base.Style; +import com.fr.base.background.ColorBackground; +import com.fr.design.actions.core.ActionUtils; +import com.fr.general.ComparatorUtils; +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.style.color.UIToolbarColorButton; + +/** + * Background. + */ +public class StyleBackgroundAction extends AbstractStyleAction implements ChangeListener { + public StyleBackgroundAction(ElementCasePane t) { + super(t); + + this.setName(Inter.getLocText("Background")); + } + + public void stateChanged(ChangeEvent evt) { + this.actionPerformedUndoable(); + } + + @Override + public Style executeStyle(Style style, Style defStyle) { + Object object = this.getValue(UIToolbarColorButton.class.getName()); + if (object != null && object instanceof UIToolbarColorButton) { + Color selectedColor = ((UIToolbarColorButton) object).getColor(); + if (style.getBackground() != null && + style.getBackground() instanceof ColorBackground && + ComparatorUtils.equals(selectedColor, + ((ColorBackground) style.getBackground()).getColor())) { + return style; + } + + style = style.deriveBackground(ColorBackground.getInstance(selectedColor)); + } + + return style; + } + + @Override + public boolean isFontStye() { + return false; + } + + @Override + public JComponent createToolBarComponent() { + Object object = this.getValue(UIToolbarColorButton.class.getName()); + if (object == null || !(object instanceof UIToolbarColorButton)) { + UIToolbarColorButton tbButton = new UIToolbarColorButton(BaseUtils.readIcon("/com/fr/design/images/gui/color/background.png")); + tbButton.set4Toolbar(); + this.putValue(UIToolbarColorButton.class.getName(), tbButton); + + tbButton.setEnabled(this.isEnabled()); + tbButton.setColor(Color.WHITE); + tbButton.addColorChangeListener(this); + + //peter:产生tooltip + tbButton.setToolTipText(ActionUtils.createButtonToolTipText(this)); + return tbButton; + } + + return (JComponent) object; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/columnrow/AbstractColumnRowIndexAction.java b/designer/src/com/fr/design/actions/columnrow/AbstractColumnRowIndexAction.java new file mode 100644 index 000000000..bc7046e45 --- /dev/null +++ b/designer/src/com/fr/design/actions/columnrow/AbstractColumnRowIndexAction.java @@ -0,0 +1,20 @@ +package com.fr.design.actions.columnrow; + +import com.fr.design.actions.CellSelectionAction; +import com.fr.design.mainframe.ElementCasePane; + +public abstract class AbstractColumnRowIndexAction extends CellSelectionAction { + private int index = 0; + + protected AbstractColumnRowIndexAction(ElementCasePane t, int indexOfColumnOrRow) { + super(t); + this.index = indexOfColumnOrRow; + } + + /** + * Return index. + */ + public int getIndex() { + return this.index; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/columnrow/CancelColumnAction.java b/designer/src/com/fr/design/actions/columnrow/CancelColumnAction.java new file mode 100644 index 000000000..e66f5a99e --- /dev/null +++ b/designer/src/com/fr/design/actions/columnrow/CancelColumnAction.java @@ -0,0 +1,38 @@ +package com.fr.design.actions.columnrow; + +import com.fr.page.ReportPageAttrProvider; +import com.fr.design.actions.CellSelectionAction; +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.selection.CellSelection; +import com.fr.report.elementcase.ElementCase; + +public class CancelColumnAction extends CellSelectionAction{ + public CancelColumnAction(ElementCasePane t) { + super(t); + + this.setName(Inter.getLocText("Cancel_Repeat_Attributes")); + } + + @Override + protected boolean executeActionReturnUndoRecordNeededWithCellSelection( + CellSelection cs) { + ElementCasePane ePane = this.getEditingComponent(); + ElementCase report = ePane.getEditingElementCase(); + if (report.getReportPageAttr() == null) { + return false; + } + int[] columns = cs.getSelectedColumns(); + ReportPageAttrProvider pageAttr = report.getReportPageAttr(); + int i = columns[0]; + if (i == pageAttr.getRepeatHeaderColumnFrom() || i == pageAttr.getRepeatHeaderColumnTo()) { + pageAttr.setRepeatHeaderColumnFrom(-1); + pageAttr.setRepeatHeaderColumnTo(-1); + } + if (i == pageAttr.getRepeatFooterColumnFrom() || i == pageAttr.getRepeatFooterColumnTo()) { + pageAttr.setRepeatFooterColumnFrom(-1); + pageAttr.setRepeatFooterColumnTo(-1); + } + return true; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/columnrow/CancelRowAction.java b/designer/src/com/fr/design/actions/columnrow/CancelRowAction.java new file mode 100644 index 000000000..d92b22f57 --- /dev/null +++ b/designer/src/com/fr/design/actions/columnrow/CancelRowAction.java @@ -0,0 +1,40 @@ +package com.fr.design.actions.columnrow; + +import com.fr.page.ReportPageAttrProvider; +import com.fr.design.actions.CellSelectionAction; +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.selection.CellSelection; +import com.fr.report.elementcase.ElementCase; + +public class CancelRowAction extends CellSelectionAction { + + public CancelRowAction(ElementCasePane t) { + super(t); + + this.setName(Inter.getLocText("Cancel_Repeat_Attributes")); + } + + @Override + protected boolean executeActionReturnUndoRecordNeededWithCellSelection( + CellSelection cs) { + ElementCasePane ePane = getEditingComponent(); + ElementCase report = ePane.getEditingElementCase(); + + int[] rows = cs.getSelectedRows(); + if (report.getReportPageAttr() == null) { + return false; + } + ReportPageAttrProvider pageAttr = report.getReportPageAttr(); + int i = rows[0]; + if (i == pageAttr.getRepeatHeaderRowFrom() || i == pageAttr.getRepeatHeaderRowTo()) { + pageAttr.setRepeatHeaderRowFrom(-1); + pageAttr.setRepeatHeaderRowTo(-1); + } + if (i == pageAttr.getRepeatFooterRowFrom() || i == pageAttr.getRepeatFooterRowTo()) { + pageAttr.setRepeatFooterRowFrom(-1); + pageAttr.setRepeatFooterRowTo(-1); + } + return true; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/columnrow/ColumnHideAction.java b/designer/src/com/fr/design/actions/columnrow/ColumnHideAction.java new file mode 100644 index 000000000..561efc39b --- /dev/null +++ b/designer/src/com/fr/design/actions/columnrow/ColumnHideAction.java @@ -0,0 +1,29 @@ +package com.fr.design.actions.columnrow; + +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.selection.CellSelection; +import com.fr.report.elementcase.ElementCase; +import com.fr.stable.unit.UNIT; + +public class ColumnHideAction extends AbstractColumnRowIndexAction { + + public ColumnHideAction(ElementCasePane t, int indexOfColumnOrRow) { + super(t, indexOfColumnOrRow); + this.setName(Inter.getLocText("Hide")); + } + + @Override + protected boolean executeActionReturnUndoRecordNeededWithCellSelection(CellSelection cs) { + ElementCasePane ePane = this.getEditingComponent(); + ElementCase report = ePane.getEditingElementCase(); + int[] cols = cs.getSelectedColumns(); + for (int i = 0; i < cols.length; i++) { + report.setColumnWidth(cols[i], UNIT.ZERO); + } + ePane.fireTargetModified(); + ePane.repaint(); + return false; + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/columnrow/ColumnRowRepeatAction.java b/designer/src/com/fr/design/actions/columnrow/ColumnRowRepeatAction.java new file mode 100644 index 000000000..4f3125903 --- /dev/null +++ b/designer/src/com/fr/design/actions/columnrow/ColumnRowRepeatAction.java @@ -0,0 +1,47 @@ +package com.fr.design.actions.columnrow; + +import com.fr.page.ReportPageAttrProvider; +import com.fr.design.actions.CellSelectionAction; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.selection.CellSelection; +import com.fr.report.elementcase.ElementCase; +import com.fr.stable.bridge.StableFactory; + +public abstract class ColumnRowRepeatAction extends CellSelectionAction { + + public ColumnRowRepeatAction(ElementCasePane t) { + super(t); + } + + @Override + protected boolean executeActionReturnUndoRecordNeededWithCellSelection( + CellSelection cs) { + ElementCasePane ePane = this.getEditingComponent(); + ElementCase report = ePane.getEditingElementCase(); + + int[] indices; + if (isColumn()) { + indices = cs.getSelectedColumns(); + } else { + indices = cs.getSelectedRows(); + } + + doReportPageAttrSet(isColumn(), isFoot(), report, indices[0], indices[indices.length - 1]); + + return true; + } + + protected abstract boolean isColumn(); + protected abstract boolean isFoot(); + + private void doReportPageAttrSet(boolean isColumn, boolean isFoot, ElementCase elementCase, int from, int to) { + ReportPageAttrProvider reportPageAttr = elementCase.getReportPageAttr(); + if (reportPageAttr == null) { + reportPageAttr = (ReportPageAttrProvider) StableFactory.createXmlObject(ReportPageAttrProvider.XML_TAG); + elementCase.setReportPageAttr(reportPageAttr); + } + + reportPageAttr.setRepeatFromTo(isFoot, isColumn, from, to); + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/columnrow/ColumnRowSizingAction.java b/designer/src/com/fr/design/actions/columnrow/ColumnRowSizingAction.java new file mode 100644 index 000000000..f25fe7f1c --- /dev/null +++ b/designer/src/com/fr/design/actions/columnrow/ColumnRowSizingAction.java @@ -0,0 +1,120 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.columnrow; + +import com.fr.design.DesignerEnvManager; +import com.fr.design.gui.frpane.UnitInputPane; +import com.fr.design.gui.frpane.UnitInputPane.ValueNotChangeException; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.selection.CellSelection; +import com.fr.report.elementcase.ElementCase; +import com.fr.stable.ArrayUtils; +import com.fr.stable.Constants; +import com.fr.stable.unit.CM; +import com.fr.stable.unit.INCH; +import com.fr.stable.unit.MM; +import com.fr.stable.unit.PT; +import com.fr.stable.unit.UNIT; + +/** + * @author richer + * @since 6.5.3 + */ +public abstract class ColumnRowSizingAction extends AbstractColumnRowIndexAction { + protected ColumnRowSizingAction(ElementCasePane t, int indexOfColumnOrRow) { + super(t, indexOfColumnOrRow); + } + + @Override + protected boolean executeActionReturnUndoRecordNeededWithCellSelection( + CellSelection cs) { + final ElementCasePane ePane = this.getEditingComponent(); + final ElementCase report = ePane.getEditingElementCase(); + + final UnitInputPane uPane = new UnitInputPane(3,title4UnitInputPane()) { + @Override + protected String title4PopupWindow() { + return ColumnRowSizingAction.this.title4UnitInputPane(); + } + }; + UNIT len = getShowLen(report, cs); + populateNumberDialog(uPane, len); + + final CellSelection finalCS = cs; + uPane.showSmallWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { + + @Override + public void doOk() { + try { + float newHeight = (float) uPane.update(); + int unitType = DesignerEnvManager.getEnvManager().getReportLengthUnit(); + UNIT len; + if (unitType == Constants.UNIT_CM) { + len = new CM(newHeight); + } else if (unitType == Constants.UNIT_INCH) { + len = new INCH(newHeight); + } else if (unitType == Constants.UNIT_PT) { + len = new PT(newHeight); + } else { + len = new MM(newHeight); + } + updateAction(report, len, finalCS); + } catch (ValueNotChangeException e) { + // nothing + } + + ePane.fireTargetModified(); + } + }).setVisible(true); + return false; + } + + protected void populateNumberDialog(final UnitInputPane uPane, UNIT unit) { + int unitType = DesignerEnvManager.getEnvManager().getReportLengthUnit(); + float va; + if (unitType == Constants.UNIT_CM) { + va = unit.toCMValue4Scale2(); + uPane.setUnitText(Inter.getLocText("Unit_CM")); + } else if (unitType == Constants.UNIT_INCH) { + va = unit.toINCHValue4Scale3(); + uPane.setUnitText(Inter.getLocText("Unit_INCH")); + } else if (unitType == Constants.UNIT_PT) { + va = unit.toPTValue4Scale2(); + uPane.setUnitText(Inter.getLocText("Unit_PT")); + } else { + va = unit.toMMValue4Scale2(); + uPane.setUnitText(Inter.getLocText("Unit_MM")); + } + + uPane.populate(va); + } + + protected abstract String title4UnitInputPane(); + + protected abstract void updateAction(ElementCase report, UNIT len, CellSelection cs); + + protected abstract UNIT getShowLen(ElementCase report, CellSelection cs); + + protected abstract UNIT getIndexLen(int index, ElementCase report); + + protected UNIT getSelectedCellsLen(int[] cells, ElementCase report){ + int length = ArrayUtils.getLength(cells); + UNIT temp = null; + for (int i = 0; i < length; i++) { + UNIT current = getIndexLen(cells[i], report); + if (temp == null) { + temp = current; + continue; + } + if (temp.subtract(current).not_equal_zero()){ + return UNIT.ZERO; + } + } + + return getIndexLen(this.getIndex(), report); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/columnrow/ColumnWidthAction.java b/designer/src/com/fr/design/actions/columnrow/ColumnWidthAction.java new file mode 100644 index 000000000..83410c2f0 --- /dev/null +++ b/designer/src/com/fr/design/actions/columnrow/ColumnWidthAction.java @@ -0,0 +1,46 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.columnrow; + +import com.fr.design.mainframe.ElementCasePane; +import com.fr.general.Inter; +import com.fr.grid.selection.CellSelection; +import com.fr.report.elementcase.ElementCase; +import com.fr.stable.unit.UNIT; + +/** + * Column width. + */ +public class ColumnWidthAction extends ColumnRowSizingAction { + + public ColumnWidthAction(ElementCasePane t, int indexOfColumnOrRow) { + super(t, indexOfColumnOrRow); + + this.setName(Inter.getLocText("Utils-Column_Width") + "..."); + this.setMnemonic('C'); + } + + @Override + protected String title4UnitInputPane() { + return Inter.getLocText("Utils-Column_Width"); + } + + @Override + protected void updateAction(ElementCase report, UNIT len, CellSelection cs) { + int[] columns = cs.getSelectedColumns(); + for (int i = 0; i < columns.length; i++) { + report.setColumnWidth(columns[i], len); + } + } + + protected UNIT getIndexLen(int index, ElementCase report){ + return report.getColumnWidth(index); + } + + @Override + protected UNIT getShowLen(ElementCase report, CellSelection cs) { + int[] columns = cs.getSelectedColumns(); + return getSelectedCellsLen(columns, report); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/columnrow/DSColumnAdvancedAction.java b/designer/src/com/fr/design/actions/columnrow/DSColumnAdvancedAction.java new file mode 100644 index 000000000..028f2f2d2 --- /dev/null +++ b/designer/src/com/fr/design/actions/columnrow/DSColumnAdvancedAction.java @@ -0,0 +1,36 @@ +package com.fr.design.actions.columnrow; + +import com.fr.base.BaseUtils; +import com.fr.design.actions.cell.AbstractCellElementAction; +import com.fr.design.dscolumn.DSColumnAdvancedPane; +import com.fr.design.dialog.BasicPane; +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.report.cell.TemplateCellElement; + +public class DSColumnAdvancedAction extends AbstractCellElementAction { + private boolean returnValue=false; + private TemplateCellElement editCellElement; + public DSColumnAdvancedAction(ElementCasePane t) { + super(t); + + this.setName(Inter.getLocText("Advanced")); + this.setMnemonic('A'); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/expand/cellAttr.gif")); + } + + @Override + protected BasicPane populateBasicPane(TemplateCellElement cellElement) { + this.editCellElement = cellElement; + DSColumnAdvancedPane dSColumnAdvancedPane = new DSColumnAdvancedPane(); + dSColumnAdvancedPane.populate(cellElement); + return dSColumnAdvancedPane; + } + + + @Override + protected void updateBasicPane(BasicPane basicPane, + TemplateCellElement cellElement) { + ((DSColumnAdvancedPane)basicPane).update(editCellElement); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/columnrow/DSColumnBasicAction.java b/designer/src/com/fr/design/actions/columnrow/DSColumnBasicAction.java new file mode 100644 index 000000000..ed5ff2dfc --- /dev/null +++ b/designer/src/com/fr/design/actions/columnrow/DSColumnBasicAction.java @@ -0,0 +1,88 @@ +package com.fr.design.actions.columnrow; + +import javax.swing.SwingUtilities; + +import com.fr.base.BaseUtils; +import com.fr.design.actions.CellSelectionAction; +import com.fr.design.dscolumn.DSColumnBasicPane; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.selection.CellSelection; +import com.fr.report.cell.DefaultTemplateCellElement; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.core.SheetUtils; +import com.fr.report.elementcase.TemplateElementCase; + +public class DSColumnBasicAction extends CellSelectionAction { + + public DSColumnBasicAction(ElementCasePane t) { + super(t); + + this.setName(Inter.getLocText("Basic")); + // this.setMnemonic('B'); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/expand/cellAttr.gif")); + } + + @Override + protected boolean executeActionReturnUndoRecordNeededWithCellSelection( + CellSelection cs) { + final ElementCasePane reportPane = this.getEditingComponent(); + final DSColumnBasicPane dsColumnBasicPane = new DSColumnBasicPane(); + + BasicDialog dSColumnBasicDialog = dsColumnBasicPane.showWindow(SwingUtilities.getWindowAncestor(reportPane)); + + // Got editCellElement. + TemplateCellElement editCellElement = null; + + // got simple cell element from column and row. + final TemplateElementCase report = reportPane.getEditingElementCase(); + editCellElement = report.getTemplateCellElement(cs.getColumn(), cs.getRow()); + + dsColumnBasicPane.putElementcase(getEditingComponent()); + dsColumnBasicPane.putCellElement(editCellElement); + + // alex:如果是线性报表,这时还要计算一下默认父格是什么z + if (report != null) { + SheetUtils.calculateDefaultParent(report); + } + dsColumnBasicPane.populate(null, editCellElement); + final CellSelection finalCS = cs; + dSColumnBasicDialog.addDialogActionListener(new CellElementDialogActionListenr(editCellElement) { + + @Override + public void doOk() { + // 需要先行后列地增加新元素。 + for (int j = 0; j < finalCS.getRowSpan(); j++) { + for (int i = 0; i < finalCS.getColumnSpan(); i++) { + int column = i + finalCS.getColumn(); + int row = j + finalCS.getRow(); + + editCellElement = report.getTemplateCellElement(column, row); + if (editCellElement == null) { + editCellElement = new DefaultTemplateCellElement(column, row); + report.addCellElement(editCellElement); + } + // update cell attributes + dsColumnBasicPane.update(editCellElement); + } + } + + reportPane.fireTargetModified(); + } + }); + + dSColumnBasicDialog.setVisible(true); + return false; + } + + public static class CellElementDialogActionListenr extends DialogActionAdapter { + + TemplateCellElement editCellElement; + + public CellElementDialogActionListenr(TemplateCellElement editCellElement) { + this.editCellElement = editCellElement; + } + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/columnrow/DSColumnConditionAction.java b/designer/src/com/fr/design/actions/columnrow/DSColumnConditionAction.java new file mode 100644 index 000000000..0036b2806 --- /dev/null +++ b/designer/src/com/fr/design/actions/columnrow/DSColumnConditionAction.java @@ -0,0 +1,36 @@ +package com.fr.design.actions.columnrow; + +import com.fr.base.BaseUtils; +import com.fr.design.data.DesignTableDataManager; +import com.fr.design.actions.cell.AbstractCellElementAction; +import com.fr.design.dscolumn.DSColumnConditionsPane; +import com.fr.design.dialog.BasicPane; +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.report.cell.TemplateCellElement; + +public class DSColumnConditionAction extends AbstractCellElementAction { + + private boolean returnValue = false; + private TemplateCellElement editCellElement; + + public DSColumnConditionAction(ElementCasePane t) { + super(t); + + this.setName(Inter.getLocText("Filter")); + this.setMnemonic('E'); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/expand/cellAttr.gif")); + } + + @Override + protected BasicPane populateBasicPane(TemplateCellElement cellElement) { + DSColumnConditionsPane dSColumnConditionsPane = new DSColumnConditionsPane(); + dSColumnConditionsPane.populate(DesignTableDataManager.getEditingTableDataSource(), cellElement); + return dSColumnConditionsPane; + } + + @Override + protected void updateBasicPane(BasicPane bp, TemplateCellElement cellElement) { + ((DSColumnConditionsPane) bp).update(cellElement); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/columnrow/DeleteColumnAction.java b/designer/src/com/fr/design/actions/columnrow/DeleteColumnAction.java new file mode 100644 index 000000000..867ab68c2 --- /dev/null +++ b/designer/src/com/fr/design/actions/columnrow/DeleteColumnAction.java @@ -0,0 +1,62 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.columnrow; + +import com.fr.base.BaseUtils; +import com.fr.design.actions.CellSelectionAction; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.menu.MenuKeySet; +import com.fr.general.Inter; +import com.fr.grid.selection.CellSelection; +import com.fr.report.elementcase.ElementCase; + +import javax.swing.*; + +/** + * Delete Column + */ +public class DeleteColumnAction extends CellSelectionAction { + + public DeleteColumnAction(ElementCasePane t) { + this(t, DELETE_COLUMN.getMenuName()); + } + + public DeleteColumnAction(ElementCasePane t, String name) { + super(t); + this.setName(name); + this.setMnemonic(DELETE_COLUMN.getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_report/deleteColumn.png")); + } + + @Override + protected boolean executeActionReturnUndoRecordNeededWithCellSelection( + CellSelection cs) { + ElementCasePane ePane = this.getEditingComponent(); + ElementCase report = ePane.getEditingElementCase(); + + // 删掉多行 + int[] columns = cs.getSelectedColumns(); + for (int i = 0; i < columns.length; i++) { + report.removeColumn(columns[i] - i); + } + return true; + } + + public static final MenuKeySet DELETE_COLUMN= new MenuKeySet() { + @Override + public char getMnemonic() { + return 'D'; + } + + @Override + public String getMenuName() { + return Inter.getLocText("Column"); + } + + @Override + public KeyStroke getKeyStroke() { + return null; + } + }; +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/columnrow/DeleteRowAction.java b/designer/src/com/fr/design/actions/columnrow/DeleteRowAction.java new file mode 100644 index 000000000..9ee9c2975 --- /dev/null +++ b/designer/src/com/fr/design/actions/columnrow/DeleteRowAction.java @@ -0,0 +1,63 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.columnrow; + +import com.fr.base.BaseUtils; +import com.fr.design.actions.CellSelectionAction; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.menu.MenuKeySet; +import com.fr.general.Inter; +import com.fr.grid.selection.CellSelection; +import com.fr.report.elementcase.ElementCase; + +import javax.swing.*; + +/** + * Delete Row + */ +public class DeleteRowAction extends CellSelectionAction { + + public DeleteRowAction(ElementCasePane t) { + this(t, DELETE_ROW.getMenuName()); + } + + public DeleteRowAction(ElementCasePane t, String name) { + super(t); + + this.setName(name); + this.setMnemonic(DELETE_ROW.getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_report/deleteRow.png")); + } + + @Override + protected boolean executeActionReturnUndoRecordNeededWithCellSelection( + CellSelection cs) { + ElementCasePane ePane = this.getEditingComponent(); + ElementCase report = ePane.getEditingElementCase(); + + // 删掉多行 + int[] rows = cs.getSelectedRows(); + for (int i = 0; i < rows.length; i++) { + report.removeRow(rows[i] - i); + } + return true; + } + + public static final MenuKeySet DELETE_ROW = new MenuKeySet() { + @Override + public char getMnemonic() { + return 'D'; + } + + @Override + public String getMenuName() { + return Inter.getLocText("Row"); + } + + @Override + public KeyStroke getKeyStroke() { + return null; + } + }; +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/columnrow/FootColumnAction.java b/designer/src/com/fr/design/actions/columnrow/FootColumnAction.java new file mode 100644 index 000000000..080296896 --- /dev/null +++ b/designer/src/com/fr/design/actions/columnrow/FootColumnAction.java @@ -0,0 +1,24 @@ +package com.fr.design.actions.columnrow; + +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; + +public class FootColumnAction extends ColumnRowRepeatAction { + + public FootColumnAction(ElementCasePane t) { + super(t); + + this.setName(Inter.getLocText("Set_Column_Title_End")); +// this.setMnemonic('F'); + } + + @Override + protected boolean isColumn() { + return true; + } + + @Override + protected boolean isFoot() { + return true; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/columnrow/FootRowAction.java b/designer/src/com/fr/design/actions/columnrow/FootRowAction.java new file mode 100644 index 000000000..a1a912607 --- /dev/null +++ b/designer/src/com/fr/design/actions/columnrow/FootRowAction.java @@ -0,0 +1,23 @@ +package com.fr.design.actions.columnrow; + +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; + +public class FootRowAction extends ColumnRowRepeatAction { + public FootRowAction(ElementCasePane t) { + super(t); + + this.setName(Inter.getLocText("Set_Row_Title_End")); +// this.setMnemonic('F'); + } + + @Override + protected boolean isColumn() { + return false; + } + + @Override + protected boolean isFoot() { + return true; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/columnrow/HeadColumnAction.java b/designer/src/com/fr/design/actions/columnrow/HeadColumnAction.java new file mode 100644 index 000000000..813449ff0 --- /dev/null +++ b/designer/src/com/fr/design/actions/columnrow/HeadColumnAction.java @@ -0,0 +1,23 @@ +package com.fr.design.actions.columnrow; + +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; + +public class HeadColumnAction extends ColumnRowRepeatAction { + + public HeadColumnAction(ElementCasePane t) { + super(t); + + this.setName(Inter.getLocText("Set_Column_Title_Start")); + } + + @Override + protected boolean isColumn() { + return true; + } + + @Override + protected boolean isFoot() { + return false; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/columnrow/HeadRowAction.java b/designer/src/com/fr/design/actions/columnrow/HeadRowAction.java new file mode 100644 index 000000000..774f07c71 --- /dev/null +++ b/designer/src/com/fr/design/actions/columnrow/HeadRowAction.java @@ -0,0 +1,24 @@ +package com.fr.design.actions.columnrow; + +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; + +public class HeadRowAction extends ColumnRowRepeatAction { + + public HeadRowAction(ElementCasePane t) { + super(t); + + this.setName(Inter.getLocText("Set_Row_Title_Start")); +// this.setMnemonic('H'); + } + + @Override + protected boolean isColumn() { + return false; + } + + @Override + protected boolean isFoot() { + return false; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/columnrow/InsertColumnAction.java b/designer/src/com/fr/design/actions/columnrow/InsertColumnAction.java new file mode 100644 index 000000000..b059ba075 --- /dev/null +++ b/designer/src/com/fr/design/actions/columnrow/InsertColumnAction.java @@ -0,0 +1,62 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.columnrow; + +import com.fr.base.BaseUtils; +import com.fr.design.actions.CellSelectionAction; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.menu.MenuKeySet; +import com.fr.general.Inter; +import com.fr.grid.selection.CellSelection; +import com.fr.report.elementcase.ElementCase; + +import javax.swing.*; + +/** + * Insert Column + */ +public class InsertColumnAction extends CellSelectionAction { + + public InsertColumnAction(ElementCasePane t) { + this(t, INSERT_COLUMN.getMenuName()); + } + + public InsertColumnAction(ElementCasePane t, String name) { + super(t); + + this.setName(name); + this.setMnemonic(INSERT_COLUMN.getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_insert/insertColumn.png")); + } + + public static final MenuKeySet INSERT_COLUMN = new MenuKeySet() { + @Override + public char getMnemonic() { + return 'I'; + } + + @Override + public String getMenuName() { + return Inter.getLocText("Column"); + } + + @Override + public KeyStroke getKeyStroke() { + return null; + } + }; + + @Override + protected boolean executeActionReturnUndoRecordNeededWithCellSelection( + CellSelection cs) { + ElementCasePane ePane = this.getEditingComponent(); + ElementCase report = ePane.getEditingElementCase(); + + int[] columns = cs.getSelectedColumns(); + for (int i = 0; i < columns.length; i++) { + report.insertColumn(columns[i]); + } + return true; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/columnrow/InsertRowAction.java b/designer/src/com/fr/design/actions/columnrow/InsertRowAction.java new file mode 100644 index 000000000..eaf976dd0 --- /dev/null +++ b/designer/src/com/fr/design/actions/columnrow/InsertRowAction.java @@ -0,0 +1,62 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.columnrow; + +import com.fr.base.BaseUtils; +import com.fr.design.actions.CellSelectionAction; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.menu.MenuKeySet; +import com.fr.general.Inter; +import com.fr.grid.selection.CellSelection; +import com.fr.report.elementcase.ElementCase; + +import javax.swing.*; + +/** + * Insert Row + */ +public class InsertRowAction extends CellSelectionAction { + + public InsertRowAction(ElementCasePane t) { + this(t,INSERT_ROW.getMenuName()); + } + + public InsertRowAction(ElementCasePane t, String name) { + super(t); + this.setName(name); + this.setMnemonic(INSERT_ROW.getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_insert/insertRow.png")); + } + + public static final MenuKeySet INSERT_ROW = new MenuKeySet() { + @Override + public char getMnemonic() { + return 'I'; + } + + @Override + public String getMenuName() { + return Inter.getLocText("Row"); + } + + @Override + public KeyStroke getKeyStroke() { + return null; + } + }; + + @Override + protected boolean executeActionReturnUndoRecordNeededWithCellSelection(CellSelection cs) { + ElementCasePane ePane = this.getEditingComponent(); + + ElementCase report = ePane.getEditingElementCase(); + + int[] rows = cs.getSelectedRows(); + for (int i = 0; i < rows.length; i++) { + report.insertRow(rows[i]); + } + + return true; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/columnrow/ResetColumnHideAction.java b/designer/src/com/fr/design/actions/columnrow/ResetColumnHideAction.java new file mode 100644 index 000000000..b0875a5f1 --- /dev/null +++ b/designer/src/com/fr/design/actions/columnrow/ResetColumnHideAction.java @@ -0,0 +1,57 @@ +package com.fr.design.actions.columnrow; + +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.selection.CellSelection; +import com.fr.grid.selection.Selection; +import com.fr.report.elementcase.ElementCase; +import com.fr.stable.unit.UNITConstants; + +public class ResetColumnHideAction extends AbstractColumnRowIndexAction { + + public ResetColumnHideAction(ElementCasePane t, int indexOfColumnOrRow) { + super(t, indexOfColumnOrRow); + this.setName(Inter.getLocText(new String[]{"MConfig-CancelButton", "Hide"})); + } + + @Override + protected boolean executeActionReturnUndoRecordNeededWithCellSelection(CellSelection cs) { + ElementCasePane ePane = this.getEditingComponent(); + ElementCase report = ePane.getEditingElementCase(); + + int[] columns = cs.getSelectedColumns(); + boolean ischanged = false; + for (int column : columns) { + if (report.getColumnWidth(column).equal_zero()) { + report.setColumnWidth(column, UNITConstants.DEFAULT_COL_WIDTH); + ischanged = true; + } + } + if (ischanged) { + ePane.repaint(); + ePane.fireTargetModified(); + } + + return false; + } + + @Override + public void update() { + ElementCasePane ePane = this.getEditingComponent(); + ElementCase report = ePane.getEditingElementCase(); + Selection s = ePane.getSelection(); + if (s instanceof CellSelection) { + CellSelection cs = (CellSelection)s; + int[] rows = cs.getSelectedRows(); + for (int i = 0; i < rows.length; i++) { + if (report.getColumnWidth(i).equal_zero()) { + this.setEnabled(true); + return; + } + } + } + this.setEnabled(false); + + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/columnrow/ResetRowHideAction.java b/designer/src/com/fr/design/actions/columnrow/ResetRowHideAction.java new file mode 100644 index 000000000..acfb5364f --- /dev/null +++ b/designer/src/com/fr/design/actions/columnrow/ResetRowHideAction.java @@ -0,0 +1,57 @@ +package com.fr.design.actions.columnrow; + +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.selection.CellSelection; +import com.fr.grid.selection.Selection; +import com.fr.report.elementcase.ElementCase; +import com.fr.stable.unit.UNITConstants; + +public class ResetRowHideAction extends AbstractColumnRowIndexAction { + + public ResetRowHideAction(ElementCasePane t, int indexOfColumnOrRow) { + super(t, indexOfColumnOrRow); + this.setName(Inter.getLocText(new String[]{"MConfig-CancelButton", "Hide"})); + } + + @Override + protected boolean executeActionReturnUndoRecordNeededWithCellSelection(CellSelection cs) { + ElementCasePane ePane = this.getEditingComponent(); + ElementCase report = ePane.getEditingElementCase(); + + int[] rows = cs.getSelectedRows(); + boolean ischanged = false; + for (int row : rows) { + if (report.getRowHeight(row).equal_zero()) { + report.setRowHeight(row, UNITConstants.DEFAULT_ROW_HEIGHT); + ischanged = true; + } + } + if (ischanged) { + ePane.repaint(); + ePane.fireTargetModified(); + } + + return false; + } + + @Override + public void update() { + ElementCasePane ePane = this.getEditingComponent(); + ElementCase report = ePane.getEditingElementCase(); + Selection s = ePane.getSelection(); + if (s instanceof CellSelection) { + CellSelection cs = (CellSelection)s; + int[] rows = cs.getSelectedRows(); + for (int i = 0; i < rows.length; i++) { + if (report.getRowHeight(i).equal_zero()) { + this.setEnabled(true); + return; + } + } + } + this.setEnabled(false); + + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/columnrow/RowHeightAction.java b/designer/src/com/fr/design/actions/columnrow/RowHeightAction.java new file mode 100644 index 000000000..314e66775 --- /dev/null +++ b/designer/src/com/fr/design/actions/columnrow/RowHeightAction.java @@ -0,0 +1,47 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.columnrow; + +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.selection.CellSelection; +import com.fr.report.elementcase.ElementCase; +import com.fr.stable.unit.UNIT; + +/** + * Row height + */ +public class RowHeightAction extends ColumnRowSizingAction { + + public RowHeightAction(ElementCasePane t, int indexOfColumnOrRow) { + super(t, indexOfColumnOrRow); + + this.setName(Inter.getLocText("Utils-Row_Height") + "..."); + this.setMnemonic('R'); + } + + @Override + protected String title4UnitInputPane() { + return Inter.getLocText("Utils-Row_Height"); + } + + @Override + protected void updateAction(ElementCase report, UNIT len, CellSelection cs) { + int[] rows = cs.getSelectedRows(); + for (int i = 0; i < rows.length; i++) { + report.setRowHeight(rows[i], len); + } + } + + @Override + protected UNIT getShowLen(ElementCase report, CellSelection cs) { + int[] rows = cs.getSelectedRows(); + return getSelectedCellsLen(rows, report); + } + + protected UNIT getIndexLen(int index, ElementCase report){ + return report.getRowHeight(index); + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/columnrow/RowHideAction.java b/designer/src/com/fr/design/actions/columnrow/RowHideAction.java new file mode 100644 index 000000000..3fa2aa514 --- /dev/null +++ b/designer/src/com/fr/design/actions/columnrow/RowHideAction.java @@ -0,0 +1,29 @@ +package com.fr.design.actions.columnrow; + +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.selection.CellSelection; +import com.fr.report.elementcase.ElementCase; +import com.fr.stable.unit.UNIT; + +public class RowHideAction extends AbstractColumnRowIndexAction { + + public RowHideAction(ElementCasePane t, int indexOfColumnOrRow) { + super(t, indexOfColumnOrRow); + this.setName(Inter.getLocText("Hide")); + } + + @Override + protected boolean executeActionReturnUndoRecordNeededWithCellSelection(CellSelection cs) { + ElementCasePane ePane = this.getEditingComponent(); + ElementCase report = ePane.getEditingElementCase(); + int[] rows = cs.getSelectedRows(); + for (int i = 0; i < rows.length; i++) { + report.setRowHeight(rows[i], UNIT.ZERO); + } + ePane.fireTargetModified(); + ePane.repaint(); + return false; + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/edit/DeleteAction.java b/designer/src/com/fr/design/actions/edit/DeleteAction.java new file mode 100644 index 000000000..01e07a75b --- /dev/null +++ b/designer/src/com/fr/design/actions/edit/DeleteAction.java @@ -0,0 +1,33 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.edit; + +import com.fr.base.BaseUtils; +import com.fr.design.actions.ElementCaseAction; +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; + +/** + * Delete Row, Column or FloatElement.. + */ +public class DeleteAction extends ElementCaseAction { + /** + * Constructor + */ + public DeleteAction(ElementCasePane t) { + super(t); + + this.setName(Inter.getLocText("M_Edit-Delete") + "..."); + this.setMnemonic('D'); + //Richie:删除菜单图标 + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_report/delete.png")); + } + + @Override + public boolean executeActionReturnUndoRecordNeeded() { + ElementCasePane ePane = getEditingComponent(); + + return ePane.getSelection().triggerDeleteAction(ePane); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/edit/EditFloatElementNameAction.java b/designer/src/com/fr/design/actions/edit/EditFloatElementNameAction.java new file mode 100644 index 000000000..6f235307e --- /dev/null +++ b/designer/src/com/fr/design/actions/edit/EditFloatElementNameAction.java @@ -0,0 +1,70 @@ +package com.fr.design.actions.edit; + +import javax.swing.SwingUtilities; + +import com.fr.design.actions.FloatSelectionAction; +import com.fr.design.gui.itextfield.UITextField; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.BasicPane; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.selection.FloatSelection; +import com.fr.report.cell.FloatElement; +import com.fr.report.elementcase.ElementCase; + +public class EditFloatElementNameAction extends FloatSelectionAction { + + public EditFloatElementNameAction(ElementCasePane t) { + super(t); + + this.setName(Inter.getLocText(new String[]{"Set", "Float_Element_Name"})); + } + + @Override + protected boolean executeActionReturnUndoRecordNeededWithFloatSelection( + FloatSelection fs) { + final ElementCasePane reportPane = getEditingComponent(); + final ElementCase report = reportPane.getEditingElementCase(); + + //p:获得最后一个选中的悬浮元素. + final FloatElement selectedFloatElement = report.getFloatElement(fs.getSelectedFloatName()); + + final NamePane pane = new NamePane(); + pane.populate(selectedFloatElement.getName()); + BasicDialog nameDialog = pane.showSmallWindow(SwingUtilities.getWindowAncestor(reportPane),new DialogActionAdapter() { + @Override + public void doOk() { + String name = pane.update(); + if (report.getFloatElement(name) == null) { + selectedFloatElement.setName(name); + } + reportPane.setSelection(new FloatSelection(name)); + } + }); + nameDialog.setVisible(true); + + return true; + } + + class NamePane extends BasicPane{ + private UITextField jtext; + public NamePane() { + jtext = new UITextField(15); + this.add(jtext); + } + + @Override + protected String title4PopupWindow() { + return Inter.getLocText(new String[]{"Set", "Float_Element_Name"}); + } + + public void populate(String name) { + jtext.setText(name); + } + + public String update() { + return jtext.getText(); + } + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/edit/HyperlinkAction.java b/designer/src/com/fr/design/actions/edit/HyperlinkAction.java new file mode 100644 index 000000000..41559e0a0 --- /dev/null +++ b/designer/src/com/fr/design/actions/edit/HyperlinkAction.java @@ -0,0 +1,113 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.edit; + +import java.awt.Color; + +import javax.swing.SwingUtilities; + +import com.fr.base.BaseUtils; +import com.fr.base.Style; +import com.fr.design.actions.ElementCaseAction; +import com.fr.design.actions.utils.ReportActionUtils; +import com.fr.design.actions.utils.ReportActionUtils.IterAction; +import com.fr.design.gui.frpane.HyperlinkGroupPane; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.menu.KeySetUtils; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.general.FRFont; +import com.fr.grid.selection.CellSelection; +import com.fr.grid.selection.FloatSelection; +import com.fr.grid.selection.Selection; +import com.fr.js.NameJavaScriptGroup; +import com.fr.report.cell.CellElement; +import com.fr.report.cell.FloatElement; +import com.fr.report.elementcase.TemplateElementCase; +import com.fr.stable.Constants; + +/** + * HyperlinkAction. + */ +public class HyperlinkAction extends ElementCaseAction { + private boolean b; + + public HyperlinkAction(ElementCasePane t) { + super(t); + this.setMenuKeySet(KeySetUtils.HYPER_LINK); + this.setName(getMenuKeySet().getMenuKeySetName() + "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_insert/hyperLink.png")); + } + + /** + * 计算Action, + * @return 返回是否需要记录undo + */ + public boolean executeActionReturnUndoRecordNeeded() { + b = true; + ElementCasePane reportPane = this.getEditingComponent(); + if (reportPane == null) { + return false; + } + + final TemplateElementCase report = reportPane.getEditingElementCase(); + NameJavaScriptGroup nameHyperlinks = getNameJSGroup(reportPane, report); + final HyperlinkGroupPane pane = DesignerContext.getDesignerFrame().getSelectedJTemplate().getHyperLinkPane(); + pane.populate(nameHyperlinks); + + final Selection sel = reportPane.getSelection(); + BasicDialog dialog = pane.showWindow(SwingUtilities.getWindowAncestor(reportPane)); + dialog.addDialogActionListener(new DialogActionAdapter() { + public void doOk() { + super.doOk(); + final NameJavaScriptGroup updateNameHyperlinks = pane.updateJSGroup(); + if (sel instanceof FloatSelection) { + FloatElement selectedFloatElement = report.getFloatElement(((FloatSelection)sel).getSelectedFloatName()); + selectedFloatElement.setNameHyperlinkGroup(updateNameHyperlinks); + } else { + ReportActionUtils.actionIterateWithCellSelection((CellSelection)sel, report, new IterAction() { + public void dealWith(CellElement editCellElement) { + Style elementStyle = editCellElement.getStyle(); + FRFont frFont = elementStyle.getFRFont(); + if (updateNameHyperlinks.size() > 0) { + frFont = frFont.applyForeground(Color.blue); + frFont = frFont.applyUnderline(Constants.LINE_THIN); + } else { + frFont = frFont.applyForeground(Color.black); + frFont = frFont.applyUnderline(Constants.LINE_NONE); + } + editCellElement.setStyle(elementStyle.deriveFRFont(frFont)); + editCellElement.setNameHyperlinkGroup(updateNameHyperlinks); + } + }); + } + } + public void doCancel() { + b = false; + } + }); + dialog.setVisible(true); + + return b; + } + + private NameJavaScriptGroup getNameJSGroup(ElementCasePane reportPane, final TemplateElementCase report) { + NameJavaScriptGroup nameHyperlinks = null; + final Selection sel = reportPane.getSelection(); + if (sel instanceof FloatSelection) { + FloatElement selectedFloatElement = report.getFloatElement(((FloatSelection)sel).getSelectedFloatName()); + nameHyperlinks = selectedFloatElement.getNameHyperlinkGroup(); + } else { + CellElement editCellElement = report.getCellElement(((CellSelection)sel).getColumn(), ((CellSelection)sel).getRow()); + if (editCellElement != null) { + nameHyperlinks = editCellElement.getNameHyperlinkGroup(); + } + } + + return nameHyperlinks; + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/edit/clear/ClearAction.java b/designer/src/com/fr/design/actions/edit/clear/ClearAction.java new file mode 100644 index 000000000..352477bcd --- /dev/null +++ b/designer/src/com/fr/design/actions/edit/clear/ClearAction.java @@ -0,0 +1,17 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.edit.clear; + +import com.fr.design.actions.ElementCaseAction; +import com.fr.design.mainframe.ElementCasePane; + +/** + * @author richer + * @since 6.5.3 + */ +public abstract class ClearAction extends ElementCaseAction { + protected ClearAction(ElementCasePane t) { + super(t); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/edit/clear/ClearAllAction.java b/designer/src/com/fr/design/actions/edit/clear/ClearAllAction.java new file mode 100644 index 000000000..d0d44f380 --- /dev/null +++ b/designer/src/com/fr/design/actions/edit/clear/ClearAllAction.java @@ -0,0 +1,31 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.edit.clear; + +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; + +/** + * Clear all. + */ +public class ClearAllAction extends ClearAction { + /** + * Constructor + */ + public ClearAllAction(ElementCasePane t) { + super(t); + + this.setName(Inter.getLocText("M_Edit-Clear_All")); + this.setMnemonic('A'); + } + + @Override + public boolean executeActionReturnUndoRecordNeeded() { + ElementCasePane reportPane = getEditingComponent(); + if (reportPane == null) { + return false; + } + return reportPane.clearAll(); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/edit/clear/ClearContentsAction.java b/designer/src/com/fr/design/actions/edit/clear/ClearContentsAction.java new file mode 100644 index 000000000..cae3c4708 --- /dev/null +++ b/designer/src/com/fr/design/actions/edit/clear/ClearContentsAction.java @@ -0,0 +1,31 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.edit.clear; + +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; + +/** + * Clear contents. + */ +public class ClearContentsAction extends ClearAction { + /** + * Constructor + */ + public ClearContentsAction(ElementCasePane t) { + super(t); + + this.setName(Inter.getLocText("M_Edit-Clear_Contents")); + this.setMnemonic('C'); + } + + @Override + public boolean executeActionReturnUndoRecordNeeded() { + ElementCasePane reportPane = getEditingComponent(); + if (reportPane == null) { + return false; + } + return reportPane.clearContents(); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/edit/clear/ClearFormatsAction.java b/designer/src/com/fr/design/actions/edit/clear/ClearFormatsAction.java new file mode 100644 index 000000000..8918869f7 --- /dev/null +++ b/designer/src/com/fr/design/actions/edit/clear/ClearFormatsAction.java @@ -0,0 +1,31 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.edit.clear; + +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; + +/** + * Clear formats. + */ +public class ClearFormatsAction extends ClearAction { + /** + * Constructor + */ + public ClearFormatsAction(ElementCasePane t) { + super(t); + + this.setName(Inter.getLocText("M_Edit-Clear_Formats")); + this.setMnemonic('F'); + } + + @Override + public boolean executeActionReturnUndoRecordNeeded() { + ElementCasePane reportPane = getEditingComponent(); + if (reportPane == null) { + return false; + } + return reportPane.clearFormats(); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/edit/clear/ClearWidgetAction.java b/designer/src/com/fr/design/actions/edit/clear/ClearWidgetAction.java new file mode 100644 index 000000000..ff8802c28 --- /dev/null +++ b/designer/src/com/fr/design/actions/edit/clear/ClearWidgetAction.java @@ -0,0 +1,27 @@ +package com.fr.design.actions.edit.clear; + +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; + +//:jackie 用于清除控件 +public class ClearWidgetAction extends ClearAction { + + /** + * Constructor + */ + public ClearWidgetAction(ElementCasePane t) { + super(t); + + this.setName(Inter.getLocText("Widget")); + this.setMnemonic('W'); + } + + @Override + public boolean executeActionReturnUndoRecordNeeded() { + ElementCasePane reportPane = getEditingComponent(); + if (reportPane == null) { + return false; + } + return reportPane.clearWidget(); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/edit/merge/MergeCellAction.java b/designer/src/com/fr/design/actions/edit/merge/MergeCellAction.java new file mode 100644 index 000000000..6aad28a13 --- /dev/null +++ b/designer/src/com/fr/design/actions/edit/merge/MergeCellAction.java @@ -0,0 +1,46 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.edit.merge; + +import com.fr.base.BaseUtils; +import com.fr.design.actions.ElementCaseAction; +import com.fr.design.menu.KeySetUtils; +import com.fr.design.mainframe.ElementCasePane; + +/** + * merge cell.. + */ +public class MergeCellAction extends ElementCaseAction { + + /** + * Constructor + */ + public MergeCellAction(ElementCasePane t) { + super(t); + this.setMenuKeySet(KeySetUtils.MERGE_CELL); + this.setName(getMenuKeySet().getMenuKeySetName()); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/merge.png")); + } + + /** + * 执行动作 + * @return 是则返回true + */ + public boolean executeActionReturnUndoRecordNeeded() { + ElementCasePane reportPane = getEditingComponent(); + if (reportPane == null) { + return false; + } + return reportPane.mergeCell(); + } + + @Override + public void update() { + super.update(); + ElementCasePane reportPane = getEditingComponent(); + this.setEnabled(reportPane.canMergeCell()); + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/edit/merge/UnmergeCellAction.java b/designer/src/com/fr/design/actions/edit/merge/UnmergeCellAction.java new file mode 100644 index 000000000..3079e8745 --- /dev/null +++ b/designer/src/com/fr/design/actions/edit/merge/UnmergeCellAction.java @@ -0,0 +1,45 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.edit.merge; + +import com.fr.base.BaseUtils; +import com.fr.design.actions.ElementCaseAction; +import com.fr.design.menu.KeySetUtils; +import com.fr.design.mainframe.ElementCasePane; + +/** + * unmerge cell.. + */ +public class UnmergeCellAction extends ElementCaseAction { + /** + * Constructor + */ + public UnmergeCellAction(ElementCasePane t) { + super(t); + this.setMenuKeySet(KeySetUtils.UNMERGE_CELL); + this.setName(getMenuKeySet().getMenuKeySetName()); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/unmerge.png")); + } + + @Override + public void update() { + super.update(); + ElementCasePane reportPane = getEditingComponent(); + this.setEnabled(reportPane.canUnMergeCell()); + } + + /** + * 执行动作 + * @return 是则返回true + */ + public boolean executeActionReturnUndoRecordNeeded() { + ElementCasePane reportPane = getEditingComponent(); + if (reportPane == null) { + return false; + } + return reportPane.unMergeCell(); + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/edit/order/AbstractFloatElementOrderAction.java b/designer/src/com/fr/design/actions/edit/order/AbstractFloatElementOrderAction.java new file mode 100644 index 000000000..79694882f --- /dev/null +++ b/designer/src/com/fr/design/actions/edit/order/AbstractFloatElementOrderAction.java @@ -0,0 +1,31 @@ +package com.fr.design.actions.edit.order; + +import com.fr.design.actions.FloatSelectionAction; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.selection.FloatSelection; +import com.fr.report.cell.FloatElement; +import com.fr.report.elementcase.ElementCase; + +/** + * FloatElement order. + */ +public abstract class AbstractFloatElementOrderAction extends FloatSelectionAction { + protected AbstractFloatElementOrderAction(ElementCasePane t) { + super(t); + } + + @Override + public boolean executeActionReturnUndoRecordNeededWithFloatSelection(FloatSelection fs) { + ElementCasePane ePane = getEditingComponent(); + + ElementCase report = ePane.getEditingElementCase(); + + //p:获得最后一个选中的悬浮元素. + FloatElement selectedFloatElement = report.getFloatElement(fs.getSelectedFloatName()); + orderWithSelectedFloatElement(report, selectedFloatElement); + + return true; + } + + public abstract void orderWithSelectedFloatElement(ElementCase report, FloatElement floatElement); +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/edit/order/BringFloatElementForwardAction.java b/designer/src/com/fr/design/actions/edit/order/BringFloatElementForwardAction.java new file mode 100644 index 000000000..c1ffd413a --- /dev/null +++ b/designer/src/com/fr/design/actions/edit/order/BringFloatElementForwardAction.java @@ -0,0 +1,32 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.edit.order; + +import com.fr.base.BaseUtils; +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.report.cell.FloatElement; +import com.fr.report.elementcase.ElementCase; + +/** + * Bring FloatElement forward. + */ +public class BringFloatElementForwardAction extends AbstractFloatElementOrderAction { + /** + * Constructor. + */ + public BringFloatElementForwardAction(ElementCasePane t) { + super(t); + + this.setName(Inter.getLocText("M_Edit-Bring_Forward")); + this.setMnemonic('F'); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/bringForward.png")); + } + + @Override + public void orderWithSelectedFloatElement(ElementCase report, + FloatElement floatElement) { + report.bringFloatElementForward(floatElement); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/edit/order/BringFloatElementToFrontAction.java b/designer/src/com/fr/design/actions/edit/order/BringFloatElementToFrontAction.java new file mode 100644 index 000000000..880abaeec --- /dev/null +++ b/designer/src/com/fr/design/actions/edit/order/BringFloatElementToFrontAction.java @@ -0,0 +1,32 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.edit.order; + +import com.fr.base.BaseUtils; +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.report.cell.FloatElement; +import com.fr.report.elementcase.ElementCase; + +/** + * Bring FloatElement to front. + */ +public class BringFloatElementToFrontAction extends AbstractFloatElementOrderAction { + /** + * Constructor. + */ + public BringFloatElementToFrontAction(ElementCasePane t) { + super(t); + + this.setName(Inter.getLocText("M_Edit-Bring_to_Front")); + this.setMnemonic('t'); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/bringToFront.png")); + } + + @Override + public void orderWithSelectedFloatElement(ElementCase report, + FloatElement floatElement) { + report.bringFloatElementToFront(floatElement); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/edit/order/SendFloatElementBackwardAction.java b/designer/src/com/fr/design/actions/edit/order/SendFloatElementBackwardAction.java new file mode 100644 index 000000000..166a2f79b --- /dev/null +++ b/designer/src/com/fr/design/actions/edit/order/SendFloatElementBackwardAction.java @@ -0,0 +1,33 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.edit.order; + +import com.fr.base.BaseUtils; +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.report.cell.FloatElement; +import com.fr.report.elementcase.ElementCase; + +/** + * Send FloatElement backward. + */ +public class SendFloatElementBackwardAction extends AbstractFloatElementOrderAction { + /** + * Constructor + */ + public SendFloatElementBackwardAction(ElementCasePane t) { + super(t); + + this.setName(Inter.getLocText("M_Edit-Send_Backward")); + this.setMnemonic('B'); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/sendBackward.png")); + } + + @Override + public void orderWithSelectedFloatElement(ElementCase report, + FloatElement floatElement) { + report.sendFloatElementBackward(floatElement); + + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/edit/order/SendFloatElementToBackAction.java b/designer/src/com/fr/design/actions/edit/order/SendFloatElementToBackAction.java new file mode 100644 index 000000000..a97ea3fb9 --- /dev/null +++ b/designer/src/com/fr/design/actions/edit/order/SendFloatElementToBackAction.java @@ -0,0 +1,32 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.edit.order; + +import com.fr.base.BaseUtils; +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.report.cell.FloatElement; +import com.fr.report.elementcase.ElementCase; + +/** + * Send FloatElement to back. + */ +public class SendFloatElementToBackAction extends AbstractFloatElementOrderAction { + /** + * Constructor + */ + public SendFloatElementToBackAction(ElementCasePane t) { + super(t); + + this.setName(Inter.getLocText("M_Edit-Send_to_Back")); + this.setMnemonic('K'); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/sendToBack.png")); + } + + @Override + public void orderWithSelectedFloatElement(ElementCase report, + FloatElement floatElement) { + report.sendFloatElementToBack(floatElement); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/file/export/AbstractExcelExportAction.java b/designer/src/com/fr/design/actions/file/export/AbstractExcelExportAction.java new file mode 100644 index 000000000..63aaf064c --- /dev/null +++ b/designer/src/com/fr/design/actions/file/export/AbstractExcelExportAction.java @@ -0,0 +1,42 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.file.export; + +import com.fr.base.ExcelUtils; +import com.fr.design.mainframe.JWorkBook; +import com.fr.file.filter.ChooseFileFilter; +import com.fr.general.Inter; +import com.fr.main.TemplateWorkBook; + +/** + * Export excel. + */ +public abstract class AbstractExcelExportAction extends AbstractExportAction { + /** + * Constructor + */ + protected AbstractExcelExportAction(JWorkBook jwb) { + super(jwb); + } + + @Override + protected ChooseFileFilter getChooseFileFilter() { + TemplateWorkBook tpl = this.getTemplateWorkBook(); + if (hasLayerReport(tpl)) { + return new ChooseFileFilter(new String[]{"zip"}, "ZIP"); + } else { + return new ChooseFileFilter(new String[]{"xls", "xlsx"}, Inter.getLocText("Export-Excel")); + } + } + + @Override + protected String getDefaultExtension() { + TemplateWorkBook tpl = this.getTemplateWorkBook(); + if (hasLayerReport(tpl)) { + return "zip"; + } else { + return ExcelUtils.checkPOIJarExist() ? "xlsx" : "xls"; + } + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/file/export/AbstractExportAction.java b/designer/src/com/fr/design/actions/file/export/AbstractExportAction.java new file mode 100644 index 000000000..a4a55ac30 --- /dev/null +++ b/designer/src/com/fr/design/actions/file/export/AbstractExportAction.java @@ -0,0 +1,184 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.file.export; + +import com.fr.base.FRContext; +import com.fr.base.Parameter; +import com.fr.page.PageSetProvider; +import com.fr.design.actions.JWorkBookAction; +import com.fr.design.gui.iprogressbar.FRProgressBar; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.DesignerFrame; +import com.fr.design.mainframe.JWorkBook; +import com.fr.design.parameter.ParameterInputPane; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.file.FILE; +import com.fr.file.FILEChooserPane; +import com.fr.file.filter.ChooseFileFilter; +import com.fr.general.FRLogger; +import com.fr.general.Inter; +import com.fr.io.exporter.*; +import com.fr.main.TemplateWorkBook; +import com.fr.main.impl.WorkBook; +import com.fr.report.ReportHelper; +import com.fr.report.core.ReportUtils; +import com.fr.report.report.Report; +import com.fr.report.worksheet.WorkSheet; +import com.fr.stable.ActorConstants; +import com.fr.stable.ActorFactory; + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.io.FileOutputStream; +import java.util.Map; + +/** + * Abstract export action. + */ +public abstract class AbstractExportAction extends JWorkBookAction { + protected AbstractExportAction(JWorkBook jwb) { + super(jwb); + } + + private FRProgressBar progressbar; + + protected WorkBook getTemplateWorkBook() { + return this.getEditingComponent().getTarget(); + } + + /** + * 执行方法 + */ + public void actionPerformed(ActionEvent e) { + JWorkBook jwb = this.getEditingComponent(); + FILE editingFILE = jwb.getEditingFILE(); + DesignerFrame designerFrame = DesignerContext.getDesignerFrame(); + + // 弹出参数 + final java.util.Map parameterMap = new java.util.HashMap(); + final TemplateWorkBook tpl = getTemplateWorkBook(); + Parameter[] parameters = tpl.getParameters(); + if (parameters != null && parameters.length > 0) {// 检查Parameter. + final ParameterInputPane pPane = new ParameterInputPane( + parameters); + pPane.showSmallWindow(designerFrame, new DialogActionAdapter() { + + @Override + public void doOk() { + parameterMap.putAll(pPane.update()); + } + }).setVisible(true); + } + + // Choose a file name.... + FILEChooserPane fileChooserPane = FILEChooserPane.getInstance(false, true); + fileChooserPane.setFILEFilter(this.getChooseFileFilter()); + + // 打开文件后输出文件名修改,eg:w.cpt.doc / w.svg.doc,去掉中间的后缀名~~ w.doc + String filenName = editingFILE.getName(); + if (filenName.indexOf('.') != -1) { + filenName = filenName.substring(0, editingFILE.getName().lastIndexOf('.')); + } + fileChooserPane.setFileNameTextField(filenName, "." + this.getDefaultExtension()); + int saveValue = fileChooserPane.showSaveDialog(designerFrame, "." + this.getDefaultExtension()); + if (saveValue == FILEChooserPane.CANCEL_OPTION || saveValue == FILEChooserPane.JOPTIONPANE_CANCEL_OPTION) { + fileChooserPane = null; + return; + } else if (saveValue == FILEChooserPane.JOPTIONPANE_OK_OPTION || saveValue == FILEChooserPane.OK_OPTION) { + FILE file = fileChooserPane.getSelectedFILE(); + try { + file.mkfile(); + } catch (Exception e1) { + FRLogger.getLogger().error("Error In Make New File"); + } + fileChooserPane = null; + FRContext.getLogger().info("\"" + file.getName() + "\"" + Inter.getLocText("Prepare_Export") + "!"); + + (progressbar = new FRProgressBar(createExportWork(file, tpl, parameterMap), designerFrame, + Inter.getLocText("Exporting"), "", 0, 100)).start(); + } + } + + private SwingWorker createExportWork(FILE file, final TemplateWorkBook tpl, final Map parameterMap) { + final String filePath = file.getPath(); + final String fileGetName = file.getName(); + + SwingWorker exportWorker = new SwingWorker() { + protected Void doInBackground() throws Exception { + Thread.sleep(100); //bug 10516 + try { + final FileOutputStream fileOutputStream = new FileOutputStream(filePath); + + this.setProgress(10); + dealExporter(fileOutputStream, tpl, parameterMap); + this.setProgress(80); + fileOutputStream.close(); + this.setProgress(100); + + FRContext.getLogger().info("\"" + fileGetName + "\"" + Inter.getLocText("Finish_Export") + "!"); + JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), + Inter.getLocText("Exported_successfully") + "\n" + filePath); + } catch (Exception exp) { + this.setProgress(100); + FRContext.getLogger().errorWithServerLevel(exp.getMessage(), exp); + JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("Export_failed") + "\n" + filePath); + } + return null; + } + + public void done() { + progressbar.close(); + } + }; + return exportWorker; + } + + private void dealExporter(FileOutputStream fileOutputStream, final TemplateWorkBook tpl, final Map parameterMap) throws Exception { + final Exporter exporter = AbstractExportAction.this.getExporter(); + if (exporter instanceof AppExporter) { + AppExporter appExporter = (AppExporter) exporter; + if (exporter instanceof ExcelExporter || exporter instanceof CSVExporter + || exporter instanceof PDFExporter || exporter instanceof WordExporter) { + ReportHelper.clearFormulaResult(tpl);// 清空rpt中的公式计算结果 + + appExporter.export(fileOutputStream, tpl.execute(parameterMap, ActorFactory.getActor(ActorConstants.TYPE_PAGE) + )); + } else { + ReportHelper.clearFormulaResult(tpl);// 清空currentReport中的公式计算结果 + + PageSetProvider pageSet = tpl.execute(parameterMap, ActorFactory.getActor(ActorConstants.TYPE_PAGE)).generateReportPageSet( + ReportUtils.getPaperSettingListFromWorkBook(tpl)).traverse4Export(); + appExporter.export(fileOutputStream, pageSet); + pageSet.release(); + } + } else if (exporter instanceof EmbeddedTableDataExporter) { + ((EmbeddedTableDataExporter) exporter).export(fileOutputStream, (WorkBook) tpl, parameterMap); + } + } + + /* + * 这边判断是否有层式报表,有层式需要使用大数据量导出 + */ + protected boolean hasLayerReport(TemplateWorkBook tpl) { + if (tpl == null) { + return false; + } + for (int i = 0; i < tpl.getReportCount(); i++) { + Report r = tpl.getReport(i); + if (r instanceof WorkSheet) { + if (((WorkSheet) r).getLayerReportAttr() != null) { + return true; + } + } + } + + return false; + } + + protected abstract ChooseFileFilter getChooseFileFilter(); + + protected abstract String getDefaultExtension(); + + protected abstract Exporter getExporter(); +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/file/export/CSVExportAction.java b/designer/src/com/fr/design/actions/file/export/CSVExportAction.java new file mode 100644 index 000000000..1e5b816b0 --- /dev/null +++ b/designer/src/com/fr/design/actions/file/export/CSVExportAction.java @@ -0,0 +1,55 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.file.export; + +import com.fr.base.BaseUtils; +import com.fr.design.mainframe.JWorkBook; +import com.fr.design.menu.KeySetUtils; +import com.fr.file.filter.ChooseFileFilter; +import com.fr.general.Inter; +import com.fr.io.exporter.CSVExporter; +import com.fr.io.exporter.Exporter; +import com.fr.io.exporter.LargeDataPageCSVExporter; +import com.fr.main.TemplateWorkBook; + +/** + * Export CSV. + */ +public class CSVExportAction extends AbstractExportAction { + /** + * Constructor + */ + public CSVExportAction(JWorkBook jwb) { + super(jwb); + this.setMenuKeySet(KeySetUtils.CSV_EXPORT); + this.setName(getMenuKeySet().getMenuKeySetName()+ "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_file/csv.png")); + } + + @Override + protected Exporter getExporter() { + TemplateWorkBook tpl = this.getTemplateWorkBook(); + if (hasLayerReport(tpl)) { + return new LargeDataPageCSVExporter(); + } else { + return new CSVExporter(); + } + } + + @Override + protected ChooseFileFilter getChooseFileFilter() { + return new ChooseFileFilter(new String[]{"csv"}, Inter.getLocText("Export-CSV")); + } + + @Override + protected String getDefaultExtension() { + TemplateWorkBook tpl = this.getTemplateWorkBook(); + if (hasLayerReport(tpl)) { + return "zip"; + } else { + return "csv"; + } + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/file/export/EmbeddedExportExportAction.java b/designer/src/com/fr/design/actions/file/export/EmbeddedExportExportAction.java new file mode 100644 index 000000000..7f87d9b99 --- /dev/null +++ b/designer/src/com/fr/design/actions/file/export/EmbeddedExportExportAction.java @@ -0,0 +1,42 @@ +package com.fr.design.actions.file.export; + +import com.fr.base.BaseUtils; +import com.fr.design.mainframe.JWorkBook; +import com.fr.design.menu.KeySetUtils; +import com.fr.file.filter.ChooseFileFilter; +import com.fr.general.Inter; +import com.fr.io.exporter.EmbeddedTableDataExporter; +import com.fr.io.exporter.Exporter; + +/** + * Export Embedded. + */ +public class EmbeddedExportExportAction extends AbstractExportAction { + /** + * Constructor + */ + public EmbeddedExportExportAction(JWorkBook jwb) { + super(jwb); + this.setMenuKeySet(KeySetUtils.EMBEDDED_EXPORT); + this.setName(getMenuKeySet().getMenuKeySetName() + "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/base/images/oem/logo.png")); + } + + @Override + protected Exporter getExporter() { + return new EmbeddedTableDataExporter(); + } + + @Override + protected ChooseFileFilter getChooseFileFilter() { + return new ChooseFileFilter(new String[]{"cpt"}, + Inter.getLocText("Export-Template(embedded_data)")); + } + + @Override + protected String getDefaultExtension() { + return "cpt"; + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/file/export/ExcelExportAction.java b/designer/src/com/fr/design/actions/file/export/ExcelExportAction.java new file mode 100644 index 000000000..42684c11c --- /dev/null +++ b/designer/src/com/fr/design/actions/file/export/ExcelExportAction.java @@ -0,0 +1,33 @@ +package com.fr.design.actions.file.export; + +import com.fr.base.BaseUtils; +import com.fr.design.mainframe.JWorkBook; +import com.fr.design.menu.KeySetUtils; +import com.fr.io.exporter.ExcelExporter; +import com.fr.io.exporter.Exporter; +import com.fr.io.exporter.LargeDataPageExcelExporter; +import com.fr.main.TemplateWorkBook; +import com.fr.report.core.ReportUtils; + +public class ExcelExportAction extends AbstractExcelExportAction { + /** + * Constructor + */ + public ExcelExportAction(JWorkBook jwb) { + super(jwb); + this.setMenuKeySet(KeySetUtils.SIMPLE_EXCEL_EXPORT); + this.setName(getMenuKeySet().getMenuKeySetName()); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_file/excel.png")); + } + + @Override + protected Exporter getExporter() { + TemplateWorkBook tpl = this.getTemplateWorkBook(); + if (hasLayerReport(tpl)) { + return new LargeDataPageExcelExporter(ReportUtils.getPaperSettingListFromWorkBook(tpl), false); + } else { + return new ExcelExporter(ReportUtils.getPaperSettingListFromWorkBook(tpl)); + } + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/file/export/PDFExportAction.java b/designer/src/com/fr/design/actions/file/export/PDFExportAction.java new file mode 100644 index 000000000..68fdd783f --- /dev/null +++ b/designer/src/com/fr/design/actions/file/export/PDFExportAction.java @@ -0,0 +1,44 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.file.export; + +import com.fr.base.BaseUtils; +import com.fr.design.mainframe.JWorkBook; +import com.fr.design.menu.KeySetUtils; +import com.fr.file.filter.ChooseFileFilter; +import com.fr.general.Inter; +import com.fr.io.exporter.Exporter; +import com.fr.io.exporter.PDFExporter; + +/** + * Export pdf + */ +public class PDFExportAction extends AbstractExportAction { + /** + * Constructor + */ + public PDFExportAction(JWorkBook jwb) { + super(jwb); + this.setMenuKeySet(KeySetUtils.PDF_EXPORT); + this.setName(getMenuKeySet().getMenuKeySetName()+"..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_file/pdf.png")); + } + + @Override + protected Exporter getExporter() { + return new PDFExporter(); + } + + @Override + protected ChooseFileFilter getChooseFileFilter() { + return new ChooseFileFilter(new String[]{"pdf"}, Inter.getLocText("Export-PDF")); + } + + @Override + protected String getDefaultExtension() { + return "pdf"; + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/file/export/PageExcelExportAction.java b/designer/src/com/fr/design/actions/file/export/PageExcelExportAction.java new file mode 100644 index 000000000..34d63fdd6 --- /dev/null +++ b/designer/src/com/fr/design/actions/file/export/PageExcelExportAction.java @@ -0,0 +1,31 @@ +package com.fr.design.actions.file.export; + +import com.fr.base.BaseUtils; +import com.fr.design.mainframe.JWorkBook; +import com.fr.design.menu.KeySetUtils; +import com.fr.io.exporter.Exporter; +import com.fr.io.exporter.LargeDataPageExcelExporter; +import com.fr.io.exporter.PageExcelExporter; +import com.fr.main.TemplateWorkBook; +import com.fr.report.core.ReportUtils; + +public class PageExcelExportAction extends AbstractExcelExportAction { + + public PageExcelExportAction(JWorkBook jwb) { + super(jwb); + this.setMenuKeySet(KeySetUtils.PAGE_EXCEL_EXPORT); + this.setName(getMenuKeySet().getMenuKeySetName()+"..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_file/excel.png")); + } + + @Override + protected Exporter getExporter() { + TemplateWorkBook tpl = this.getTemplateWorkBook(); + if (hasLayerReport(tpl)) { + return new LargeDataPageExcelExporter(ReportUtils.getPaperSettingListFromWorkBook(tpl), true); + } else { + return new PageExcelExporter(ReportUtils.getPaperSettingListFromWorkBook(tpl)); + } + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/file/export/PageToSheetExcelExportAction.java b/designer/src/com/fr/design/actions/file/export/PageToSheetExcelExportAction.java new file mode 100644 index 000000000..7bacb870d --- /dev/null +++ b/designer/src/com/fr/design/actions/file/export/PageToSheetExcelExportAction.java @@ -0,0 +1,39 @@ +package com.fr.design.actions.file.export; + +import com.fr.base.BaseUtils; +import com.fr.design.mainframe.JWorkBook; +import com.fr.design.menu.KeySetUtils; +import com.fr.file.filter.ChooseFileFilter; +import com.fr.general.Inter; +import com.fr.io.exporter.Exporter; +import com.fr.io.exporter.PageToSheetExcelExporter; +import com.fr.main.TemplateWorkBook; +import com.fr.report.core.ReportUtils; + +public class PageToSheetExcelExportAction extends AbstractExcelExportAction { + + public PageToSheetExcelExportAction(JWorkBook jwb) { + super(jwb); + + this.setMenuKeySet(KeySetUtils.PAGETOSHEET_EXCEL_EXPORT); + this.setName(getMenuKeySet().getMenuKeySetName()+"..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_file/excel.png")); + } + + @Override + protected Exporter getExporter() { + TemplateWorkBook tpl = this.getTemplateWorkBook(); + return new PageToSheetExcelExporter(ReportUtils.getPaperSettingListFromWorkBook(tpl)); + } + + @Override + protected ChooseFileFilter getChooseFileFilter() { + return new ChooseFileFilter(new String[]{"xls"}, Inter.getLocText("Export-Excel")); + } + + @Override + protected String getDefaultExtension() { + return "xls"; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/file/export/SVGExportAction.java b/designer/src/com/fr/design/actions/file/export/SVGExportAction.java new file mode 100644 index 000000000..156849133 --- /dev/null +++ b/designer/src/com/fr/design/actions/file/export/SVGExportAction.java @@ -0,0 +1,44 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.file.export; + +import com.fr.base.BaseUtils; +import com.fr.design.mainframe.JWorkBook; +import com.fr.design.menu.KeySetUtils; +import com.fr.file.filter.ChooseFileFilter; +import com.fr.general.Inter; +import com.fr.io.exporter.Exporter; +import com.fr.io.exporter.SVGExporter; + +/** + * Export SVG + */ +public class SVGExportAction extends AbstractExportAction { + /** + * Constructor + */ + public SVGExportAction(JWorkBook jwb) { + super(jwb); + + this.setMenuKeySet(KeySetUtils.SVG_EXPORT); + this.setName(getMenuKeySet().getMenuKeySetName()+"..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_file/svg.png")); + } + + @Override + protected Exporter getExporter() { + return new SVGExporter(); + } + + @Override + protected ChooseFileFilter getChooseFileFilter() { + return new ChooseFileFilter(new String[]{"svg"}, Inter.getLocText("Export-SVG")); + } + + @Override + protected String getDefaultExtension() { + return "svg"; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/file/export/TextExportAction.java b/designer/src/com/fr/design/actions/file/export/TextExportAction.java new file mode 100644 index 000000000..61d525bac --- /dev/null +++ b/designer/src/com/fr/design/actions/file/export/TextExportAction.java @@ -0,0 +1,43 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.file.export; + +import com.fr.base.BaseUtils; +import com.fr.design.mainframe.JWorkBook; +import com.fr.design.menu.KeySetUtils; +import com.fr.file.filter.ChooseFileFilter; +import com.fr.general.Inter; +import com.fr.io.exporter.Exporter; +import com.fr.io.exporter.TextExporter; + +/** + * Export Text. + */ +public class TextExportAction extends AbstractExportAction { + /** + * Constructor + */ + public TextExportAction(JWorkBook jwb) { + super(jwb); + this.setMenuKeySet(KeySetUtils.TEXT_EXPORT); + this.setName(getMenuKeySet().getMenuKeySetName()+ "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_file/text.png")); + } + + @Override + protected Exporter getExporter() { + return new TextExporter(); + } + + @Override + protected ChooseFileFilter getChooseFileFilter() { + return new ChooseFileFilter(new String[]{"txt"}, Inter.getLocText("Export-Text")); + } + + @Override + protected String getDefaultExtension() { + return "txt"; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/file/export/WordExportAction.java b/designer/src/com/fr/design/actions/file/export/WordExportAction.java new file mode 100644 index 000000000..57b8756da --- /dev/null +++ b/designer/src/com/fr/design/actions/file/export/WordExportAction.java @@ -0,0 +1,43 @@ +/* + * * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.file.export; + +import com.fr.base.BaseUtils; +import com.fr.design.mainframe.JWorkBook; +import com.fr.design.menu.KeySetUtils; +import com.fr.file.filter.ChooseFileFilter; +import com.fr.general.Inter; +import com.fr.io.exporter.Exporter; +import com.fr.io.exporter.WordExporter; + +/** + * Export excel. + */ +public class WordExportAction extends AbstractExportAction { + /** + * Constructor + */ + public WordExportAction(JWorkBook jwb) { + super(jwb); + this.setMenuKeySet(KeySetUtils.WORD_EXPORT); + this.setName(getMenuKeySet().getMenuKeySetName()+ "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_file/word.png")); + } + + @Override + protected Exporter getExporter() { + return new WordExporter(); + } + + @Override + protected ChooseFileFilter getChooseFileFilter() { + return new ChooseFileFilter(new String[]{"doc"}, Inter.getLocText("Export-Word")); + } + + @Override + protected String getDefaultExtension() { + return "doc"; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/file/newReport/NewOEMWorkBookAction.java b/designer/src/com/fr/design/actions/file/newReport/NewOEMWorkBookAction.java new file mode 100644 index 000000000..c7595deb4 --- /dev/null +++ b/designer/src/com/fr/design/actions/file/newReport/NewOEMWorkBookAction.java @@ -0,0 +1,18 @@ +package com.fr.design.actions.file.newReport; + +import com.fr.base.BaseUtils; + +import javax.swing.*; + +/** + * @author richie + * @date 2015-06-16 + * @since 8.0 + */ +public class NewOEMWorkBookAction extends NewWorkBookAction { + + @Override + protected Icon icon() { + return BaseUtils.readIcon("/com/fr/plugin/oem/images/newoemcpt.png"); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/file/newReport/NewPolyReportAction.java b/designer/src/com/fr/design/actions/file/newReport/NewPolyReportAction.java new file mode 100644 index 000000000..ea7785f7a --- /dev/null +++ b/designer/src/com/fr/design/actions/file/newReport/NewPolyReportAction.java @@ -0,0 +1,34 @@ +package com.fr.design.actions.file.newReport; + +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; + +import javax.swing.KeyStroke; + +import com.fr.base.BaseUtils; +import com.fr.design.actions.UpdateAction; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.JPolyWorkBook; +import com.fr.general.Inter; + +public class NewPolyReportAction extends UpdateAction { + + public NewPolyReportAction() { + this.setName(Inter.getLocText("M-New_Multi_Report")); + this.setMnemonic('F'); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_file/formExport.png")); + this.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, KeyEvent.CTRL_MASK)); + } + + /** + * Action触发后 + * + * @param e 触发的事件 + * + * @date 2015-2-5-上午11:43:13 + * + */ + public void actionPerformed(ActionEvent e) { + DesignerContext.getDesignerFrame().addAndActivateJTemplate(new JPolyWorkBook()); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/file/newReport/NewWorkBookAction.java b/designer/src/com/fr/design/actions/file/newReport/NewWorkBookAction.java new file mode 100644 index 000000000..268adafbf --- /dev/null +++ b/designer/src/com/fr/design/actions/file/newReport/NewWorkBookAction.java @@ -0,0 +1,54 @@ +package com.fr.design.actions.file.newReport; + +import com.fr.base.BaseUtils; +import com.fr.design.actions.UpdateAction; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.JWorkBook; +import com.fr.design.menu.MenuKeySet; +import com.fr.general.Inter; + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; + +public class NewWorkBookAction extends UpdateAction { + + public NewWorkBookAction() { + this.setMenuKeySet(NEW_WORK_BOOK); + this.setName(getMenuKeySet().getMenuKeySetName()); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(icon()); + this.setAccelerator(getMenuKeySet().getKeyStroke()); + } + + protected Icon icon() { + return BaseUtils.readIcon("/com/fr/design/images/buttonicon/newcpts.png"); + } + + /** + * 动作 + * @param e 事件 + */ + public void actionPerformed(ActionEvent e) { + DesignerContext.getDesignerFrame().addAndActivateJTemplate(new JWorkBook()); + } + + public static final MenuKeySet NEW_WORK_BOOK = new MenuKeySet() { + @Override + public char getMnemonic() { + return 'N'; + } + + @Override + public String getMenuName() { + return Inter.getLocText("M-New_WorkBook"); + } + + @Override + public KeyStroke getKeyStroke() { + return KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_MASK); + } + }; + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/form/AbastractFormECAction.java b/designer/src/com/fr/design/actions/form/AbastractFormECAction.java new file mode 100644 index 000000000..60585564c --- /dev/null +++ b/designer/src/com/fr/design/actions/form/AbastractFormECAction.java @@ -0,0 +1,17 @@ +package com.fr.design.actions.form; + +import com.fr.design.actions.TemplateComponentAction; +import com.fr.design.mainframe.form.FormElementCasePaneDelegate; + +public class AbastractFormECAction extends TemplateComponentAction{ + + protected AbastractFormECAction(T t) { + super(t); + } + + @Override + public boolean executeActionReturnUndoRecordNeeded() { + return false; + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/form/FormECBackgroundAction.java b/designer/src/com/fr/design/actions/form/FormECBackgroundAction.java new file mode 100644 index 000000000..d9ce17935 --- /dev/null +++ b/designer/src/com/fr/design/actions/form/FormECBackgroundAction.java @@ -0,0 +1,47 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.form; + +import com.fr.base.BaseUtils; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.form.FormElementCasePaneDelegate; +import com.fr.design.menu.KeySetUtils; +import com.fr.design.report.ReportBackgroundPane; +import com.fr.design.dialog.DialogActionAdapter; + +/** + * Background action. + */ +public class FormECBackgroundAction extends AbastractFormECAction{ + + public FormECBackgroundAction(FormElementCasePaneDelegate rc) { + super(rc); + this.setMenuKeySet(KeySetUtils.REPORT_BACKGROUND); + this.setName(getMenuKeySet().getMenuKeySetName() + "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_report/background.png")); + } + + /** + * 执行动作 + * @return 是否执行成功 + */ + public boolean executeActionReturnUndoRecordNeeded() { + final FormElementCasePaneDelegate elementCasePane = this.getEditingComponent(); + if (elementCasePane == null) { + return false; + } + final ReportBackgroundPane bPane = new ReportBackgroundPane(); + bPane.populate(elementCasePane.getReportSettings()); + bPane.showWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { + + @Override + public void doOk() { + bPane.update(elementCasePane.getReportSettings()); + elementCasePane.fireTargetModified(); + } + }).setVisible(true); + return false; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/form/FormECColumnsAction.java b/designer/src/com/fr/design/actions/form/FormECColumnsAction.java new file mode 100644 index 000000000..fd13e21fa --- /dev/null +++ b/designer/src/com/fr/design/actions/form/FormECColumnsAction.java @@ -0,0 +1,52 @@ +package com.fr.design.actions.form; + +import com.fr.base.BaseUtils; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.form.FormElementCasePaneDelegate; +import com.fr.design.menu.KeySetUtils; +import com.fr.design.report.ReportColumnsPane; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.report.stable.WorkSheetAttr; +import com.fr.report.worksheet.FormElementCase; + +public class FormECColumnsAction extends AbastractFormECAction{ + + public FormECColumnsAction(FormElementCasePaneDelegate t) { + super(t); + this.setMenuKeySet(KeySetUtils.EC_COLUMNS); + this.setName(getMenuKeySet().getMenuKeySetName() + "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/form/toolbar/ec_columns.png")); + } + + /** + * 执行动作 + * + * @return 是否执行成功 + */ + public boolean executeActionReturnUndoRecordNeeded() { + final FormElementCasePaneDelegate jws = this.getEditingComponent(); + if (jws == null) { + return false; + } + final FormElementCase elementCase = jws.getTarget(); + + final ReportColumnsPane cPane = new ReportColumnsPane(); + WorkSheetAttr attr = elementCase.getWorkSheetAttr(); + int rowCount = elementCase.getRowCount(); + int colCount = elementCase.getColumnCount(); + cPane.populate(attr, rowCount, colCount); + cPane.showWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { + + @Override + public void doOk() { + // bug:64173 重新生成一个workSheetAttr,否则会受到之前属性的干扰 + WorkSheetAttr attr = new WorkSheetAttr(); + elementCase.setWorkSheetAttr(attr); + cPane.update(attr); + jws.fireTargetModified(); + } + }).setVisible(true); + return false; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/form/FormECFrozenAction.java b/designer/src/com/fr/design/actions/form/FormECFrozenAction.java new file mode 100644 index 000000000..5228fcf44 --- /dev/null +++ b/designer/src/com/fr/design/actions/form/FormECFrozenAction.java @@ -0,0 +1,55 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.form; + +import javax.swing.SwingUtilities; + +import com.fr.base.BaseUtils; +import com.fr.design.mainframe.form.FormElementCasePaneDelegate; +import com.fr.design.menu.KeySetUtils; +import com.fr.design.report.freeze.FormECRepeatAndFreezeSettingPane; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.report.worksheet.FormElementCase; + +/** + * 表单报表块冻结 + */ +public class FormECFrozenAction extends AbastractFormECAction{ + private boolean returnValue; + + public FormECFrozenAction(FormElementCasePaneDelegate t) { + super(t); + this.setMenuKeySet(KeySetUtils.EC_FROZEN); + this.setName(getMenuKeySet().getMenuKeySetName() + "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/form/toolbar/ec_frozen.png")); + } + + /** + * 执行动作 + * + * @return 是否执行成功 + */ + public boolean executeActionReturnUndoRecordNeeded() { + FormElementCasePaneDelegate jws = getEditingComponent(); + if (jws == null) { + return false; + } + final FormElementCase fc = jws.getTarget(); + final FormECRepeatAndFreezeSettingPane attrPane = new FormECRepeatAndFreezeSettingPane(); + attrPane.populate(fc.getReportPageAttr()); + BasicDialog dlg = attrPane.showWindow(SwingUtilities.getWindowAncestor(jws)); + dlg.addDialogActionListener(new DialogActionAdapter() { + + @Override + public void doOk() { + fc.setReportPageAttr(attrPane.update()); + returnValue = true; + } + }); + dlg.setVisible(true); + return returnValue; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/insert/cell/AbstractCellAction.java b/designer/src/com/fr/design/actions/insert/cell/AbstractCellAction.java new file mode 100644 index 000000000..a8c9ab80f --- /dev/null +++ b/designer/src/com/fr/design/actions/insert/cell/AbstractCellAction.java @@ -0,0 +1,51 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.insert.cell; + +import com.fr.design.actions.CellSelectionAction; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.selection.CellSelection; +import com.fr.report.core.SheetUtils; +import com.fr.report.elementcase.TemplateElementCase; + +/** + * Cell. + */ +public abstract class AbstractCellAction extends CellSelectionAction { + protected AbstractCellAction(ElementCasePane t) { + super(t); + } + + public abstract Class getCellValueClass(); + + /* + * TODO ALEX_SEP 这里的返回boolean量表示模板是否改变,导致很多很多的方法的boolean返回值都是这个意思 + * + * 感觉有点浪费 + */ + @Override + protected boolean executeActionReturnUndoRecordNeededWithCellSelection( + CellSelection cs) { + ElementCasePane ePane = this.getEditingComponent(); + //got simple cell element from column and row. + TemplateElementCase report = ePane.getEditingElementCase(); + + //alex:如果是线性报表,这时还要计算一下默认父格是什么 + if (report != null && this instanceof DSColumnCellAction) { + SheetUtils.calculateDefaultParent(report); + } + + return ePane.getGrid().startCellEditingAt_DEC( + cs.getColumn(), + cs.getRow(), + this.getCellValueClass(), false + ); + } + @Override + public void update() { + super.update(); + ElementCasePane ePane = this.getEditingComponent(); + this.setEnabled(ePane.isSelectedOneCell()); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/insert/cell/BiasCellAction.java b/designer/src/com/fr/design/actions/insert/cell/BiasCellAction.java new file mode 100644 index 000000000..af5371122 --- /dev/null +++ b/designer/src/com/fr/design/actions/insert/cell/BiasCellAction.java @@ -0,0 +1,48 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.insert.cell; + +import javax.swing.KeyStroke; + +import com.fr.base.BaseUtils; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.menu.MenuKeySet; +import com.fr.general.Inter; +import com.fr.report.cell.painter.BiasTextPainter; + +/** + * Bias + */ +public class BiasCellAction extends AbstractCellAction { + public BiasCellAction(ElementCasePane t) { + super(t); + this.setMenuKeySet(INSERT_SLOPE_LINE); + this.setName(getMenuKeySet().getMenuKeySetName()+ "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_insert/bias.png")); + } + + public static final MenuKeySet INSERT_SLOPE_LINE = new MenuKeySet() { + @Override + public char getMnemonic() { + //之前是S, 跟子报表subreport重复了 + return 'X'; + } + + @Override + public String getMenuName() { + return Inter.getLocText("M_Insert-Slope_Line"); + } + + @Override + public KeyStroke getKeyStroke() { + return null; + } + }; + + @Override + public Class getCellValueClass() { + return BiasTextPainter.class; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/insert/cell/ChartCellAction.java b/designer/src/com/fr/design/actions/insert/cell/ChartCellAction.java new file mode 100644 index 000000000..240b995ac --- /dev/null +++ b/designer/src/com/fr/design/actions/insert/cell/ChartCellAction.java @@ -0,0 +1,48 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.insert.cell; + +import com.fr.base.BaseUtils; +import com.fr.design.actions.core.ActionUtils; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.menu.MenuKeySet; +import com.fr.general.Inter; + +import javax.swing.*; + +/** + * . + */ +public class ChartCellAction extends AbstractCellAction { + public ChartCellAction(ElementCasePane t) { + super(t); + this.setMenuKeySet(INSERT_CHART); + this.setName(getMenuKeySet().getMenuKeySetName()+ "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_insert/chart.png")); + } + + public static final MenuKeySet INSERT_CHART = new MenuKeySet() { + @Override + public char getMnemonic() { + return 'C'; + } + + @Override + public String getMenuName() { + return Inter.getLocText("M_Insert-Chart"); + } + + @Override + public KeyStroke getKeyStroke() { + return null; + } + }; + + + @Override + public Class getCellValueClass() { + return ActionUtils.getChartCollectionClass(); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/insert/cell/DSColumnCellAction.java b/designer/src/com/fr/design/actions/insert/cell/DSColumnCellAction.java new file mode 100644 index 000000000..50a6bf4a7 --- /dev/null +++ b/designer/src/com/fr/design/actions/insert/cell/DSColumnCellAction.java @@ -0,0 +1,21 @@ +package com.fr.design.actions.insert.cell; + +import com.fr.base.BaseUtils; +import com.fr.design.menu.KeySetUtils; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.report.cell.cellattr.core.group.DSColumn; + +public class DSColumnCellAction extends AbstractCellAction { + public DSColumnCellAction(ElementCasePane t) { + super(t); + this.setMenuKeySet(KeySetUtils.INSERT_DATA_COLUMN); + this.setName(getMenuKeySet().getMenuKeySetName()+ "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_insert/bindColumn.png")); + } + + @Override + public Class getCellValueClass() { + return DSColumn.class; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/insert/cell/FormulaCellAction.java b/designer/src/com/fr/design/actions/insert/cell/FormulaCellAction.java new file mode 100644 index 000000000..cd155b13e --- /dev/null +++ b/designer/src/com/fr/design/actions/insert/cell/FormulaCellAction.java @@ -0,0 +1,44 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.insert.cell; + +import com.fr.base.BaseUtils; +import com.fr.base.Formula; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.menu.MenuKeySet; +import com.fr.general.Inter; + +import javax.swing.*; + +public class FormulaCellAction extends AbstractCellAction { + public FormulaCellAction(ElementCasePane t) { + super(t); + this.setMenuKeySet(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 INSERT_FORMULA = new MenuKeySet() { + @Override + public char getMnemonic() { + return 'F'; + } + + @Override + public String getMenuName() { + return Inter.getLocText("M_Insert-Formula"); + } + + @Override + public KeyStroke getKeyStroke() { + return null; + } + }; + + @Override + public Class getCellValueClass() { + return Formula.class; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/insert/cell/GeneralCellAction.java b/designer/src/com/fr/design/actions/insert/cell/GeneralCellAction.java new file mode 100644 index 000000000..2205c867e --- /dev/null +++ b/designer/src/com/fr/design/actions/insert/cell/GeneralCellAction.java @@ -0,0 +1,46 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.insert.cell; + +import com.fr.base.BaseUtils; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.menu.MenuKeySet; +import com.fr.general.Inter; + +import javax.swing.*; + +/** + * + */ +public class GeneralCellAction extends AbstractCellAction { + public GeneralCellAction(ElementCasePane t) { + super(t); + this.setMenuKeySet(INSERT_TEXT); + this.setName(getMenuKeySet().getMenuKeySetName()+ "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_insert/text.png")); + } + + public static final MenuKeySet INSERT_TEXT = new MenuKeySet() { + @Override + public char getMnemonic() { + return 'T'; + } + + @Override + public String getMenuName() { + return Inter.getLocText("M_Insert-Text"); + } + + @Override + public KeyStroke getKeyStroke() { + return null; + } + }; + + @Override + public Class getCellValueClass() { + return String.class; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/insert/cell/ImageCellAction.java b/designer/src/com/fr/design/actions/insert/cell/ImageCellAction.java new file mode 100644 index 000000000..7834b7985 --- /dev/null +++ b/designer/src/com/fr/design/actions/insert/cell/ImageCellAction.java @@ -0,0 +1,47 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.insert.cell; + +import com.fr.base.BaseUtils; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.menu.MenuKeySet; +import com.fr.general.Inter; + +import javax.swing.*; +import java.awt.*; + +/** + * Image + */ +public class ImageCellAction extends AbstractCellAction { + public ImageCellAction(ElementCasePane t) { + super(t); + this.setMenuKeySet(INSERT_IMAGE); + this.setName(getMenuKeySet().getMenuKeySetName()+ "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_insert/image.png")); + } + + public static final MenuKeySet INSERT_IMAGE = new MenuKeySet() { + @Override + public char getMnemonic() { + return 'I'; + } + + @Override + public String getMenuName() { + return Inter.getLocText("M_Insert-Image"); + } + + @Override + public KeyStroke getKeyStroke() { + return null; + } + }; + + @Override + public Class getCellValueClass() { + return Image.class; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/insert/cell/RichTextCellAction.java b/designer/src/com/fr/design/actions/insert/cell/RichTextCellAction.java new file mode 100644 index 000000000..c6550f2ef --- /dev/null +++ b/designer/src/com/fr/design/actions/insert/cell/RichTextCellAction.java @@ -0,0 +1,61 @@ +package com.fr.design.actions.insert.cell; + +import javax.swing.KeyStroke; + +import com.fr.base.BaseUtils; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.menu.MenuKeySet; +import com.fr.general.ComparatorUtils; +import com.fr.general.Inter; +import com.fr.report.cell.cellattr.core.RichText; + +public class RichTextCellAction extends AbstractCellAction { + + public RichTextCellAction(ElementCasePane t) { + super(t); + this.setMenuKeySet(INSERT_RICHTEXT); + this.setName(getMenuKeySet().getMenuKeySetName()+ "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon( + "/com/fr/design/images/m_insert/richtext.png")); + } + + @Override + public Class getCellValueClass() { + return RichText.class; + } + + /** + * equals 比较 + * @param object + * @return true false + */ + @Override + public boolean equals(Object object) { + if (this == object){ + return true; + } + if (!(object instanceof RichTextCellAction)){ + return false; + } + + return ComparatorUtils.equals(this.getEditingComponent(),((RichTextCellAction)object).getEditingComponent()); + } + + private static final MenuKeySet INSERT_RICHTEXT = new MenuKeySet() { + @Override + public char getMnemonic() { + return 'R'; + } + + @Override + public String getMenuName() { + return Inter.getLocText("FR-Designer_RichText"); + } + + @Override + public KeyStroke getKeyStroke() { + return null; + } + }; +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/insert/cell/SubReportCellAction.java b/designer/src/com/fr/design/actions/insert/cell/SubReportCellAction.java new file mode 100644 index 000000000..79dc6c642 --- /dev/null +++ b/designer/src/com/fr/design/actions/insert/cell/SubReportCellAction.java @@ -0,0 +1,62 @@ +package com.fr.design.actions.insert.cell; + +import javax.swing.KeyStroke; + +import com.fr.base.BaseUtils; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.menu.MenuKeySet; +import com.fr.general.ComparatorUtils; +import com.fr.general.Inter; +import com.fr.report.cell.cellattr.core.SubReport; + +public class SubReportCellAction extends AbstractCellAction { + + public SubReportCellAction(ElementCasePane t) { + super(t); + this.setMenuKeySet(INSERT_SUB_REPORT); + this.setName(getMenuKeySet().getMenuKeySetName()+ "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon( + "/com/fr/design/images/m_insert/subReport.png")); + } + + public static final MenuKeySet INSERT_SUB_REPORT = new MenuKeySet() { + @Override + public char getMnemonic() { + return 'S'; + } + + @Override + public String getMenuName() { + return Inter.getLocText("M_Insert-Sub_Report"); + } + + @Override + public KeyStroke getKeyStroke() { + return null; + } + }; + + /** + * equals 比较 + * @param object + * @return true false + */ + @Override + public boolean equals(Object object) { + if (this == object){ + return true; + } + if (!(object instanceof SubReportCellAction)){ + return false; + } + + return ComparatorUtils.equals(this.getEditingComponent(),((SubReportCellAction)object).getEditingComponent()); + } + + @Override + public Class getCellValueClass() { + return SubReport.class; + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/insert/flot/AbstractShapeAction.java b/designer/src/com/fr/design/actions/insert/flot/AbstractShapeAction.java new file mode 100644 index 000000000..f3bd328d4 --- /dev/null +++ b/designer/src/com/fr/design/actions/insert/flot/AbstractShapeAction.java @@ -0,0 +1,30 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.insert.flot; + +import com.fr.design.actions.ElementCaseAction; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.report.cell.FloatElement; + +/** + * Abstract shape. + */ +public abstract class AbstractShapeAction extends ElementCaseAction { + protected AbstractShapeAction(ElementCasePane t) { + super(t); + } + + public void startDraw(FloatElement floatElement) { + ElementCasePane jws = getEditingComponent(); + if (jws == null) { + return; + } + jws.getGrid().setDrawingFloatElement(floatElement); + } + + @Override + public boolean executeActionReturnUndoRecordNeeded() { + return false; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/insert/flot/ChartFloatAction.java b/designer/src/com/fr/design/actions/insert/flot/ChartFloatAction.java new file mode 100644 index 000000000..63716621b --- /dev/null +++ b/designer/src/com/fr/design/actions/insert/flot/ChartFloatAction.java @@ -0,0 +1,108 @@ +/* + * 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.Style; +import com.fr.base.chart.BaseChartCollection; +import com.fr.design.actions.ElementCaseAction; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.gui.chart.MiddleChartDialog; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.menu.MenuKeySet; +import com.fr.design.module.DesignModuleFactory; +import com.fr.general.FRLogger; +import com.fr.general.Inter; +import com.fr.grid.selection.FloatSelection; +import com.fr.report.cell.FloatElement; +import com.fr.stable.Constants; +import com.fr.stable.bridge.StableFactory; +import com.fr.stable.unit.OLDPIX; + +import javax.swing.*; +import java.awt.*; + +/** + * 图表插入悬浮元素的操作. + */ +public class ChartFloatAction extends ElementCaseAction { + + /** + * 构造函数 图表插入悬浮元素 + */ + public ChartFloatAction(ElementCasePane t) { + super(t); + this.setMenuKeySet(FLOAT_INSERT_CHART); + this.setName(getMenuKeySet().getMenuKeySetName()+ "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_insert/chart.png")); + } + + public static final MenuKeySet FLOAT_INSERT_CHART = new MenuKeySet() { + @Override + public char getMnemonic() { + return 'C'; + } + + @Override + public String getMenuName() { + return Inter.getLocText("M_Insert-Chart"); + } + + @Override + public KeyStroke getKeyStroke() { + return null; + } + }; + + /** + * 执行插入悬浮元素操作, 并返回true, 需要记录撤销. + * @return 是则返回true + */ + public boolean executeActionReturnUndoRecordNeeded() { + final ElementCasePane reportPane = getEditingComponent(); + if (reportPane == null) { + return false; + } + + reportPane.stopEditing(); + + final BaseChartCollection cc = (BaseChartCollection)StableFactory.createXmlObject(BaseChartCollection.XML_TAG); + cc.removeAllNameObject(); + final MiddleChartDialog chartDialog = DesignModuleFactory.getChartDialog(DesignerContext.getDesignerFrame()); + chartDialog.populate(cc); + chartDialog.addDialogActionListener(new DialogActionAdapter() { + @Override + public void doOk() { + + FloatElement newFloatElement; + try { + newFloatElement = new FloatElement(chartDialog.getChartCollection().clone()); + newFloatElement.setLeftDistance(new OLDPIX(20)); + newFloatElement.setTopDistance(new OLDPIX(20)); + newFloatElement.setWidth(new OLDPIX(BaseChartCollection.CHART_DEFAULT_WIDTH)); + newFloatElement.setHeight(new OLDPIX(BaseChartCollection.CHART_DEFAULT_HEIGHT)); + + Style style = newFloatElement.getStyle(); + if(style != null) { + newFloatElement.setStyle(style.deriveBorder(Constants.LINE_NONE, Color.black, + Constants.LINE_NONE, Color.black, + Constants.LINE_NONE, Color.black, + Constants.LINE_NONE, Color.black)); + } + reportPane.getEditingElementCase().addFloatElement(newFloatElement); + reportPane.setSelection(new FloatSelection(newFloatElement.getName())); + reportPane.fireTargetModified(); + reportPane.fireSelectionChangeListener(); + } catch (CloneNotSupportedException e) { + FRLogger.getLogger().error("Error in Float"); + } + } + }); + + chartDialog.setVisible(true); + return true; + } +} \ 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 new file mode 100644 index 000000000..a4f9e57e1 --- /dev/null +++ b/designer/src/com/fr/design/actions/insert/flot/FormulaFloatAction.java @@ -0,0 +1,59 @@ +/* + * 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.Formula; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.menu.MenuKeySet; +import com.fr.general.Inter; +import com.fr.report.cell.FloatElement; + +import javax.swing.*; +import java.awt.event.ActionEvent; + +/** + * Insert formula. + */ +public class FormulaFloatAction extends AbstractShapeAction { + 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("HF-Insert_Formula"); + } + + @Override + public KeyStroke getKeyStroke() { + return null; + } + }; + + /** + * 动作 + * @param e 事件 + */ + public void actionPerformed(ActionEvent e) { + ElementCasePane jws = getEditingComponent(); + if (jws == null) { + return; + } + + // + FloatElement floatElement = new FloatElement( new Formula("")); + this.startDraw(floatElement); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/insert/flot/ImageFloatAction.java b/designer/src/com/fr/design/actions/insert/flot/ImageFloatAction.java new file mode 100644 index 000000000..f59483fb9 --- /dev/null +++ b/designer/src/com/fr/design/actions/insert/flot/ImageFloatAction.java @@ -0,0 +1,108 @@ +/* + * 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.ScreenResolution; +import com.fr.design.actions.ElementCaseAction; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +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.selection.FloatSelection; +import com.fr.report.cell.FloatElement; +import com.fr.report.cell.cellattr.CellImage; +import com.fr.stable.CoreGraphHelper; +import com.fr.stable.unit.FU; + +import javax.swing.*; +import java.awt.*; +import java.io.File; + +/** + * Insert image. + */ +public class ImageFloatAction extends ElementCaseAction { + + private boolean returnValue = false; + + public ImageFloatAction(ElementCasePane t) { + super(t); + this.setMenuKeySet(FLOAT_INSERT_IMAGE); + this.setName(getMenuKeySet().getMenuKeySetName()+ "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_insert/image.png")); + } + + public static final MenuKeySet FLOAT_INSERT_IMAGE = new MenuKeySet() { + @Override + public char getMnemonic() { + return 'I'; + } + + @Override + public String getMenuName() { + return Inter.getLocText("HF-Insert_Image"); + } + + @Override + public KeyStroke getKeyStroke() { + return null; + } + }; + + /** + * 执行动作 + * @return 成功返回true + */ + public boolean executeActionReturnUndoRecordNeeded() { + final ElementCasePane reportPane = getEditingComponent(); + if (reportPane == null) { + return false; + } + + reportPane.stopEditing(); + + final FloatElement floatElement = new FloatElement(); + + final SelectImagePane selectImagePane = new SelectImagePane(); + selectImagePane.populate(floatElement); + + BasicDialog dialog = selectImagePane.showWindow(DesignerContext.getDesignerFrame()); + dialog.addDialogActionListener(new DialogActionAdapter() { + + @Override + public void doOk() { + File selectedFile = selectImagePane.getSelectedImage(); + + if (selectedFile != null && selectedFile.isFile()) { + Image image = BaseUtils.readImage(selectedFile.getPath()); + CellImage cellImage = selectImagePane.update(); + CoreGraphHelper.waitForImage(image); + + floatElement.setValue(image); + + int resolution = ScreenResolution.getScreenResolution(); + floatElement.setWidth(FU.valueOfPix(image.getWidth(null), resolution)); + floatElement.setHeight(FU.valueOfPix(image.getHeight(null), resolution)); + floatElement.setStyle(cellImage.getStyle()); + reportPane.addFloatElementToCenterOfElementPane(floatElement); + reportPane.setSelection(new FloatSelection(floatElement.getName())); + + 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/actions/insert/flot/TextBoxFloatAction.java b/designer/src/com/fr/design/actions/insert/flot/TextBoxFloatAction.java new file mode 100644 index 000000000..774ef5b53 --- /dev/null +++ b/designer/src/com/fr/design/actions/insert/flot/TextBoxFloatAction.java @@ -0,0 +1,57 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.insert.flot; + +import com.fr.base.BaseUtils; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.menu.MenuKeySet; +import com.fr.general.Inter; +import com.fr.report.cell.FloatElement; + +import javax.swing.*; +import java.awt.event.ActionEvent; + +/** + * Insert textbox. + */ +public class TextBoxFloatAction extends AbstractShapeAction { + public TextBoxFloatAction(ElementCasePane t) { + super(t); + this.setMenuKeySet(FLOAT_INSERT_TEXT); + this.setName(getMenuKeySet().getMenuKeySetName()+ "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_insert/text.png")); + } + + public static final MenuKeySet FLOAT_INSERT_TEXT = new MenuKeySet() { + @Override + public char getMnemonic() { + return 'T'; + } + + @Override + public String getMenuName() { + return Inter.getLocText("M_Insert-Text"); + } + + @Override + public KeyStroke getKeyStroke() { + return null; + } + }; + + + /** + * 动作 + * @param e 动作 + */ + public void actionPerformed(ActionEvent e) { + ElementCasePane jws = getEditingComponent(); + if (jws == null) { + return; + } + FloatElement floatElement = new FloatElement("Text"); + this.startDraw(floatElement); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/report/ReportBackgroundAction.java b/designer/src/com/fr/design/actions/report/ReportBackgroundAction.java new file mode 100644 index 000000000..6e8fd84f0 --- /dev/null +++ b/designer/src/com/fr/design/actions/report/ReportBackgroundAction.java @@ -0,0 +1,49 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.report; + +import com.fr.base.BaseUtils; +import com.fr.design.actions.ReportComponentAction; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.ReportComponent; +import com.fr.design.menu.KeySetUtils; +import com.fr.design.report.ReportBackgroundPane; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.report.core.ReportUtils; + +/** + * Background action. + */ +public class ReportBackgroundAction extends ReportComponentAction { + + public ReportBackgroundAction(ReportComponent rc) { + super(rc); + this.setMenuKeySet(KeySetUtils.REPORT_BACKGROUND); + this.setName(getMenuKeySet().getMenuKeySetName() + "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_report/background.png")); + } + + /** + * 执行动作 + * @return 是否执行成功 + */ + public boolean executeActionReturnUndoRecordNeeded() { + final ReportComponent reportPane = this.getEditingComponent(); + if (reportPane == null) { + return false; + } + final ReportBackgroundPane bPane = new ReportBackgroundPane(); + bPane.populate(ReportUtils.getReportSettings(reportPane.getTemplateReport())); + bPane.showWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { + + @Override + public void doOk() { + bPane.update(reportPane.getTemplateReport().getReportSettings()); + reportPane.fireTargetModified(); + } + }).setVisible(true); + return false; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/report/ReportColumnsAction.java b/designer/src/com/fr/design/actions/report/ReportColumnsAction.java new file mode 100644 index 000000000..375f92b9d --- /dev/null +++ b/designer/src/com/fr/design/actions/report/ReportColumnsAction.java @@ -0,0 +1,46 @@ +package com.fr.design.actions.report; + +import com.fr.base.BaseUtils; +import com.fr.design.actions.ReportComponentAction; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.WorkSheetDesigner; +import com.fr.design.menu.KeySetUtils; +import com.fr.design.report.ReportColumnsPane; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.report.worksheet.WorkSheet; + +public class ReportColumnsAction extends ReportComponentAction { + + public ReportColumnsAction(WorkSheetDesigner t) { + super(t); + this.setMenuKeySet(KeySetUtils.REPORT_COLUMN); + this.setName(getMenuKeySet().getMenuKeySetName() + "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_report/linearAttr.png")); + } + + /** + * 执行动作 + * + * @return 是否执行成功 + */ + public boolean executeActionReturnUndoRecordNeeded() { + final WorkSheetDesigner jws = this.getEditingComponent(); + if (jws == null) { + return false; + } + final WorkSheet workSheet = jws.getTemplateReport(); + + final ReportColumnsPane cPane = new ReportColumnsPane(); + cPane.populate(workSheet); + cPane.showWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { + + @Override + public void doOk() { + cPane.update(workSheet); + jws.fireTargetModified(); + } + }).setVisible(true); + return false; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/report/ReportEngineAttrAction.java b/designer/src/com/fr/design/actions/report/ReportEngineAttrAction.java new file mode 100644 index 000000000..796e3b638 --- /dev/null +++ b/designer/src/com/fr/design/actions/report/ReportEngineAttrAction.java @@ -0,0 +1,55 @@ +package com.fr.design.actions.report; + +import com.fr.base.BaseUtils; +import com.fr.design.actions.ReportComponentAction; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.WorkSheetDesigner; +import com.fr.design.menu.KeySetUtils; +import com.fr.design.report.LayerReportPane; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.report.worksheet.WorkSheet; + +public class ReportEngineAttrAction extends ReportComponentAction { + + public ReportEngineAttrAction(WorkSheetDesigner tc) { + super(tc); + this.setMenuKeySet(KeySetUtils.REPORT_ENGINE); + this.setName(getMenuKeySet().getMenuKeySetName() + "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_report/reportEngineAttr.png")); + } + + private boolean isChange; + + /** + * 执行动作 + * + * @return 是否执行成功 + */ + public boolean executeActionReturnUndoRecordNeeded() { + WorkSheetDesigner jws = getEditingComponent(); + if (jws == null) { + return false; + } + final WorkSheet tplEC = jws.getTemplateReport(); + + final LayerReportPane layerReportPane = new LayerReportPane(tplEC); + layerReportPane.populateBean(tplEC.getLayerReportAttr()); + BasicDialog dialog = layerReportPane.showWindow(DesignerContext.getDesignerFrame()); + isChange = false; + + dialog.addDialogActionListener(new DialogActionAdapter() { + @Override + public void doOk() { + isChange = true; + tplEC.setLayerReportAttr(layerReportPane.updateBean()); + } + }); + + dialog.setVisible(true); + + return isChange; + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/report/ReportExportAttrAction.java b/designer/src/com/fr/design/actions/report/ReportExportAttrAction.java new file mode 100644 index 000000000..6d958b648 --- /dev/null +++ b/designer/src/com/fr/design/actions/report/ReportExportAttrAction.java @@ -0,0 +1,46 @@ +package com.fr.design.actions.report; + +import java.awt.event.ActionEvent; + +import com.fr.base.BaseUtils; +import com.fr.design.actions.JWorkBookAction; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.JWorkBook; +import com.fr.design.menu.KeySetUtils; +import com.fr.design.report.ReportExportAttrPane; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.main.TemplateWorkBook; + +public class ReportExportAttrAction extends JWorkBookAction { + + public ReportExportAttrAction(JWorkBook jwb) { + super(jwb); + this.setMenuKeySet(KeySetUtils.REPORT_EXPORT_ATTR); + this.setName(getMenuKeySet().getMenuKeySetName()+"..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_report/exportAttr.png")); + } + + /** + * 动作 + * @param evt 事件 + */ + public void actionPerformed(ActionEvent evt) { + final JWorkBook jwb = getEditingComponent(); + if (jwb == null) { + return; + } + final TemplateWorkBook wbTpl = jwb.getTarget(); + final ReportExportAttrPane dialog = new ReportExportAttrPane(); + dialog.populate(wbTpl.getReportExportAttr()); + dialog.showWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { + + @Override + public void doOk() { + wbTpl.setReportExportAttr(dialog.update()); + jwb.fireTargetModified(); + } + }).setVisible(true); + + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/report/ReportFooterAction.java b/designer/src/com/fr/design/actions/report/ReportFooterAction.java new file mode 100644 index 000000000..9b38fd146 --- /dev/null +++ b/designer/src/com/fr/design/actions/report/ReportFooterAction.java @@ -0,0 +1,92 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.report; + +import java.util.Hashtable; + +import javax.swing.SwingUtilities; + +import com.fr.base.BaseUtils; +import com.fr.base.FRContext; +import com.fr.design.menu.KeySetUtils; +import com.fr.page.ReportSettingsProvider; +import com.fr.design.actions.ReportComponentAction; +import com.fr.design.headerfooter.EditFooterPane; +import com.fr.design.mainframe.ReportComponent; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.report.core.ReportHF; +import com.fr.report.core.ReportUtils; +import com.fr.report.report.Report; +import com.fr.report.report.TemplateReport; +import com.fr.report.stable.ReportConstants; + +/** + * Footer action. + */ +public class ReportFooterAction extends ReportComponentAction { + public ReportFooterAction(ReportComponent rc) { + super(rc); + this.setMenuKeySet(KeySetUtils.REPORT_FOOTER); + this.setName(getMenuKeySet().getMenuKeySetName() + "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_report/footer.png")); + } + + /** + * 执行动作 + * + * @return 是否执行成功 + */ + public boolean executeActionReturnUndoRecordNeeded() { + final ReportComponent reportPane = this.getEditingComponent(); + if (reportPane == null){ + return false; + } + final TemplateReport report = reportPane.getTemplateReport(); + + final EditFooterPane footerEditDialog = new EditFooterPane(); + + //Clone 给当前hashtable. + Hashtable cloneeportHFHash = new Hashtable(); + for (int i = 0; i != ReportConstants.PAGE_INFO.length; i++){ + this.cloneReportHFHashFoottable(cloneeportHFHash, report, ReportConstants.PAGE_INFO[i]); + } + final ReportSettingsProvider set = ReportUtils.getReportSettings(report); + footerEditDialog.populate(set, false); + footerEditDialog.populate(cloneeportHFHash); + footerEditDialog.showWindow( + SwingUtilities.getWindowAncestor(reportPane), + new DialogActionAdapter() { + @Override + public void doOk() { + Hashtable newReportHFHash = footerEditDialog.update(); + + report.setFooter(ReportConstants.REPORTPAGE_DEFAULT, + (ReportHF) newReportHFHash.get(new Integer(ReportConstants.REPORTPAGE_DEFAULT))); + report.setFooter(ReportConstants.REPORTPAGE_FIRST, + (ReportHF) newReportHFHash.get(new Integer(ReportConstants.REPORTPAGE_FIRST))); + report.setFooter(ReportConstants.REPORTPAGE_LAST, + (ReportHF) newReportHFHash.get(new Integer(ReportConstants.REPORTPAGE_LAST))); + report.setFooter(ReportConstants.REPORTPAGE_ODD, + (ReportHF) newReportHFHash.get(new Integer(ReportConstants.REPORTPAGE_ODD))); + report.setFooter(ReportConstants.REPORTPAGE_EVEN, + (ReportHF) newReportHFHash.get(new Integer(ReportConstants.REPORTPAGE_EVEN))); + set.setFooterHeight(footerEditDialog.updateReportSettings()); + + reportPane.fireTargetModified(); + } + }).setVisible(true); + return false; + } + + private void cloneReportHFHashFoottable(Hashtable reportHFHash, Report report, int reportHFType) { + if (report.getFooter(reportHFType) != null) { + try { + reportHFHash.put(new Integer(reportHFType), report.getFooter(reportHFType).clone()); + } catch (Exception e) { + FRContext.getLogger().error(e.getMessage(), e); + } + } + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/report/ReportHeaderAction.java b/designer/src/com/fr/design/actions/report/ReportHeaderAction.java new file mode 100644 index 000000000..a3fbb1b89 --- /dev/null +++ b/designer/src/com/fr/design/actions/report/ReportHeaderAction.java @@ -0,0 +1,94 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.report; + +import java.util.Hashtable; + +import javax.swing.SwingUtilities; + +import com.fr.base.BaseUtils; +import com.fr.base.FRContext; +import com.fr.design.menu.KeySetUtils; +import com.fr.page.ReportSettingsProvider; +import com.fr.design.actions.ReportComponentAction; +import com.fr.design.headerfooter.EditHeaderPane; +import com.fr.design.mainframe.ReportComponent; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.report.core.ReportHF; +import com.fr.report.core.ReportUtils; +import com.fr.report.report.Report; +import com.fr.report.report.TemplateReport; +import com.fr.report.stable.ReportConstants; + +/** + * Header action. + */ +public class ReportHeaderAction extends ReportComponentAction { + + private boolean returnVal = false; + + public ReportHeaderAction(ReportComponent rc) { + super(rc); + this.setMenuKeySet(KeySetUtils.REPORT_HEADER); + this.setName(getMenuKeySet().getMenuKeySetName() + "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_report/header.png")); + } + + /** + * 执行动作 + * @return 是否执行成功 + */ + public boolean executeActionReturnUndoRecordNeeded() { + final ReportComponent reportPane = this.getEditingComponent(); + if (reportPane == null){ + return false; + } + final TemplateReport report = reportPane.getTemplateReport(); + final EditHeaderPane headerEditDialog = new EditHeaderPane(); + final ReportSettingsProvider set = ReportUtils.getReportSettings(report); + + //Clone 给当前hashtable. + Hashtable cloneeportHFHash = new Hashtable(); + for (int i = 0; i != ReportConstants.PAGE_INFO.length; i++){ + this.cloneReportHFHashHeadtable(cloneeportHFHash, report, ReportConstants.PAGE_INFO[i]); + } + headerEditDialog.populate(set); + headerEditDialog.populate(cloneeportHFHash); + headerEditDialog.showWindow( + SwingUtilities.getWindowAncestor(reportPane), + new DialogActionAdapter() { + + @Override + public void doOk() { + Hashtable newReportHFHash = headerEditDialog.update(); + + report.setHeader(ReportConstants.REPORTPAGE_DEFAULT, + (ReportHF) newReportHFHash.get(new Integer(ReportConstants.REPORTPAGE_DEFAULT))); + report.setHeader(ReportConstants.REPORTPAGE_FIRST, + (ReportHF) newReportHFHash.get(new Integer(ReportConstants.REPORTPAGE_FIRST))); + report.setHeader(ReportConstants.REPORTPAGE_LAST, + (ReportHF) newReportHFHash.get(new Integer(ReportConstants.REPORTPAGE_LAST))); + report.setHeader(ReportConstants.REPORTPAGE_ODD, + (ReportHF) newReportHFHash.get(new Integer(ReportConstants.REPORTPAGE_ODD))); + report.setHeader(ReportConstants.REPORTPAGE_EVEN, + (ReportHF) newReportHFHash.get(new Integer(ReportConstants.REPORTPAGE_EVEN))); + set.setHeaderHeight(headerEditDialog.updateReportSettings()); + returnVal = true; + reportPane.fireTargetModified(); + } + }).setVisible(true); + return returnVal; + } + + private void cloneReportHFHashHeadtable(Hashtable reportHFHash, Report report, int reportHFType) { + if (report.getHeader(reportHFType) != null) { + try { + reportHFHash.put(new Integer(reportHFType), report.getHeader(reportHFType).clone()); + } catch (Exception e) { + FRContext.getLogger().error(e.getMessage(), e); + } + } + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/report/ReportPageAttrAction.java b/designer/src/com/fr/design/actions/report/ReportPageAttrAction.java new file mode 100644 index 000000000..57d5039ad --- /dev/null +++ b/designer/src/com/fr/design/actions/report/ReportPageAttrAction.java @@ -0,0 +1,60 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.report; + +import javax.swing.SwingUtilities; + +import com.fr.base.BaseUtils; +import com.fr.design.actions.ReportComponentAction; +import com.fr.design.mainframe.WorkSheetDesigner; +import com.fr.design.menu.KeySetUtils; +import com.fr.design.report.freeze.RepeatAndFreezeSettingPane; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.report.worksheet.WorkSheet; + +/** + * @author richer + * @since 6.5.5 + * 创建于2011-6-14 + */ +public class ReportPageAttrAction extends ReportComponentAction { + private boolean returnValue; + + public ReportPageAttrAction(WorkSheetDesigner t) { + super(t); + this.setMenuKeySet(KeySetUtils.REPORT_PAGE); + this.setName(getMenuKeySet().getMenuKeySetName() + "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_file/pageSetup.png")); + } + + /** + * 执行动作 + * + * @return 是否执行成功 + */ + public boolean executeActionReturnUndoRecordNeeded() { + WorkSheetDesigner jws = getEditingComponent(); + if (jws == null) { + return false; + } + final WorkSheet tplECReport = jws.getTemplateReport(); + final RepeatAndFreezeSettingPane attrPane = new RepeatAndFreezeSettingPane(); + attrPane.populate(tplECReport.getReportPageAttr()); + attrPane.populateWriteFrozenColumnRow(tplECReport.getReportSettings().getWriteFrozenColumnRow()); + BasicDialog dlg = attrPane.showWindow(SwingUtilities.getWindowAncestor(jws)); + dlg.addDialogActionListener(new DialogActionAdapter() { + + @Override + public void doOk() { + tplECReport.setReportPageAttr(attrPane.update()); + tplECReport.getReportSettings().setWriteFrozenColumnRow(attrPane.updateWriteFrozenColumnRow()); + returnValue = true; + } + }); + dlg.setVisible(true); + return returnValue; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/report/ReportPageSetupAction.java b/designer/src/com/fr/design/actions/report/ReportPageSetupAction.java new file mode 100644 index 000000000..53af204ad --- /dev/null +++ b/designer/src/com/fr/design/actions/report/ReportPageSetupAction.java @@ -0,0 +1,61 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.report; + +import javax.swing.SwingUtilities; + +import com.fr.base.BaseUtils; +import com.fr.design.DesignerEnvManager; +import com.fr.design.actions.ReportComponentAction; +import com.fr.design.mainframe.ReportComponent; +import com.fr.design.menu.KeySetUtils; +import com.fr.design.report.PageSetupPane; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.report.report.TemplateReport; + +/** + * PageSetup action. + */ +public class ReportPageSetupAction extends ReportComponentAction { + + private boolean returnValue; + + public ReportPageSetupAction(ReportComponent rc) { + super(rc); + this.setMenuKeySet(KeySetUtils.REPORT_PAGE_SETUP); + this.setName(getMenuKeySet().getMenuKeySetName()+"..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_file/pageSetup.png")); + } + + /** + * 执行动作 + * @return 是否执行成功 + */ + public boolean executeActionReturnUndoRecordNeeded() { + ReportComponent rc = getEditingComponent(); + if (rc == null) { + return false; + } + final TemplateReport report = rc.getTemplateReport();//当前的报表. + final PageSetupPane pageSetupPane = new PageSetupPane(); + pageSetupPane.populate(report, DesignerEnvManager.getEnvManager().getPageLengthUnit()); + BasicDialog dlg = pageSetupPane.showWindow(SwingUtilities.getWindowAncestor(rc)); + dlg.addDialogActionListener(new DialogActionAdapter() { + + @Override + public void doOk() { + pageSetupPane.update(report); + returnValue = true; + } + @Override + public void doCancel() { + returnValue = false; + } + }); + dlg.setVisible(true); + return returnValue; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/report/ReportParameterAction.java b/designer/src/com/fr/design/actions/report/ReportParameterAction.java new file mode 100644 index 000000000..61507ebfe --- /dev/null +++ b/designer/src/com/fr/design/actions/report/ReportParameterAction.java @@ -0,0 +1,79 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.report; + +import java.awt.event.ActionEvent; + +import javax.swing.SwingUtilities; + +import com.fr.base.BaseUtils; +import com.fr.base.Parameter; +import com.fr.design.actions.JWorkBookAction; +import com.fr.design.mainframe.JWorkBook; +import com.fr.design.menu.KeySetUtils; +import com.fr.design.parameter.ParameterArrayPane; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.main.TemplateWorkBook; +import com.fr.main.parameter.ReportParameterAttr; + +/** + * Report Parameter + */ +public class ReportParameterAction extends JWorkBookAction { + + public ReportParameterAction(JWorkBook jwb) { + super(jwb); + this.setMenuKeySet(KeySetUtils.REPORT_PARAMETER_ATTR); + this.setName(getMenuKeySet().getMenuKeySetName() + "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_report/p.png")); + } + + /** + * 执行动作 + * + * @return 是否执行成功 + */ + public void actionPerformed(ActionEvent evt) { + final JWorkBook jwb = getEditingComponent(); + if (jwb == null) { + return; + } + final TemplateWorkBook wbTpl = jwb.getTarget(); + + final ParameterArrayPane parameterArrayPane = new ParameterArrayPane(); + BasicDialog parameterArrayDialog = parameterArrayPane.showWindow(SwingUtilities.getWindowAncestor(jwb)); + parameterArrayDialog.setModal(true); + + final ReportParameterAttr copyReportParameterAttr = getParameter(wbTpl); + parameterArrayPane.populate(copyReportParameterAttr.getParameters()); + + parameterArrayDialog.addDialogActionListener(new DialogActionAdapter() { + + @Override + public void doOk() { + copyReportParameterAttr.clearParameters(); + Parameter[] parameters = parameterArrayPane.updateParameters(); + for (int i = 0; i < parameters.length; i++) { + copyReportParameterAttr.addParameter(parameters[i]); + } + jwb.fireTargetModified(); + jwb.updateReportParameterAttr(); + jwb.populateReportParameterAttr(); + } + }); + parameterArrayDialog.setVisible(true); + } + + private ReportParameterAttr getParameter(TemplateWorkBook wbTpl) { + ReportParameterAttr reportParameterAttr = wbTpl.getReportParameterAttr(); + if (reportParameterAttr == null) { + reportParameterAttr = new ReportParameterAttr(); + wbTpl.setReportParameterAttr(reportParameterAttr); + } + + return reportParameterAttr; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/report/ReportWebAttrAction.java b/designer/src/com/fr/design/actions/report/ReportWebAttrAction.java new file mode 100644 index 000000000..b64cb18bc --- /dev/null +++ b/designer/src/com/fr/design/actions/report/ReportWebAttrAction.java @@ -0,0 +1,73 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.report; + +import com.fr.base.BaseUtils; +import com.fr.base.ConfigManager; +import com.fr.base.Env; +import com.fr.base.FRContext; +import com.fr.design.actions.JWorkBookAction; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.JWorkBook; +import com.fr.design.menu.KeySetUtils; +import com.fr.design.webattr.ReportWebAttrPane; +import com.fr.main.TemplateWorkBook; +import com.fr.base.ConfigManagerProvider; + +import java.awt.event.ActionEvent; + +/** + * ReportWebAttr + */ +public class ReportWebAttrAction extends JWorkBookAction { + + public ReportWebAttrAction(JWorkBook jwb) { + super(jwb); + this.setMenuKeySet(KeySetUtils.REPORT_WEB_ATTR); + this.setName(getMenuKeySet().getMenuKeySetName()+"..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_report/webreportattribute.png")); + } + + /** + * 动作 + * @param evt 事件 + */ + public void actionPerformed(ActionEvent evt) { + final JWorkBook jwb = getEditingComponent(); + if (jwb == null) { + return; + } + final TemplateWorkBook wbTpl = jwb.getTarget(); + final ReportWebAttrPane reportWebAttrPane = new ReportWebAttrPane() { + @Override + public void complete() { + populate(wbTpl.getReportWebAttr()); + } + }; + final BasicDialog dialog = reportWebAttrPane.showWindow( + DesignerContext.getDesignerFrame() + ); + + dialog.addDialogActionListener(new DialogActionAdapter() { + @Override + public void doOk() { + wbTpl.setReportWebAttr(reportWebAttrPane.update()); + final ConfigManagerProvider configManager = ConfigManager.getProviderInstance(); + Env currentEnv = FRContext.getCurrentEnv(); + try { + currentEnv.writeResource(configManager); + } catch (Exception ex) { + FRContext.getLogger().error(ex.getMessage(), ex); + } + jwb.fireTargetModified(); + } + }); + + dialog.setVisible(true); + + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/report/ReportWriteAttrAction.java b/designer/src/com/fr/design/actions/report/ReportWriteAttrAction.java new file mode 100644 index 000000000..6f752fa36 --- /dev/null +++ b/designer/src/com/fr/design/actions/report/ReportWriteAttrAction.java @@ -0,0 +1,75 @@ +package com.fr.design.actions.report; + +import com.fr.base.BaseUtils; +import com.fr.design.actions.ReportComponentAction; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.JTemplate; +import com.fr.design.mainframe.WorkSheetDesigner; +import com.fr.design.menu.KeySetUtils; +import com.fr.design.webattr.ReportWriteAttrPane; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.report.worksheet.WorkSheet; + +/** + * ReportWriteAttrAction + */ +public class ReportWriteAttrAction extends ReportComponentAction { + public ReportWriteAttrAction(WorkSheetDesigner t) { + super(t); + this.setMenuKeySet(KeySetUtils.REPORT_WRITE); + this.setName(getMenuKeySet().getMenuKeySetName() + "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_report/reportWriteAttr.png")); + } + + // ben:用来判断是否update + private boolean isChange; + private boolean hasActionPerformed; + + /** + * 执行动作 + * + * @return 是否执行成功 + */ + public boolean executeActionReturnUndoRecordNeeded() { + hasActionPerformed = false; + WorkSheetDesigner jws = getEditingComponent(); + if (jws == null) { + return false; + } + final WorkSheet tplEC = jws.getTemplateReport(); + + final ReportWriteAttrPane reportWritePane = new ReportWriteAttrPane(jws.getEditingElementCasePane()) { + @Override + public void complete() { + populate(tplEC); + } + }; + + BasicDialog dialog = reportWritePane.showWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { + @Override + public void doOk() { + isChange = true; + tplEC.setReportWriteAttr(reportWritePane.update()); + if (hasActionPerformed) { + final JTemplate targetComponent = DesignerContext.getDesignerFrame().getSelectedJTemplate(); + if (targetComponent != null) { + targetComponent.fireTargetModified(); + targetComponent.requestFocus(); + } + } + } + + @Override + public void doCancel() { + isChange = false; + } + }); + + DesignerContext.setReportWritePane(dialog); + dialog.setVisible(true); + hasActionPerformed = true; + return isChange; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/server/ServerConfigManagerAction.java b/designer/src/com/fr/design/actions/server/ServerConfigManagerAction.java new file mode 100644 index 000000000..549426eb1 --- /dev/null +++ b/designer/src/com/fr/design/actions/server/ServerConfigManagerAction.java @@ -0,0 +1,86 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.server; + +import com.fr.base.BaseUtils; +import com.fr.base.ConfigManager; +import com.fr.base.Env; +import com.fr.base.FRContext; +import com.fr.design.actions.UpdateAction; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.menu.MenuKeySet; +import com.fr.design.webattr.EditReportServerParameterPane; +import com.fr.general.Inter; +import com.fr.base.ConfigManagerProvider; + +import javax.swing.*; +import java.awt.event.ActionEvent; + +/** + * Server Config Manager + */ +public class ServerConfigManagerAction extends UpdateAction { + public ServerConfigManagerAction() { + this.setMenuKeySet(SERVER_CONFIG_MANAGER); + this.setName(getMenuKeySet().getMenuKeySetName()+ "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_web/edit.png")); + } + + /** + * 动作 + * @param e 事件 + */ + public void actionPerformed(ActionEvent e) { + final ConfigManagerProvider configManager = ConfigManager.getProviderInstance(); + final EditReportServerParameterPane editReportServerParameterPane = new EditReportServerParameterPane() { + @Override + public void complete() { + populate(configManager); + } + }; + + final BasicDialog editReportServerParameterDialog = editReportServerParameterPane.showWindow( + DesignerContext.getDesignerFrame() + ); + + editReportServerParameterDialog.addDialogActionListener(new DialogActionAdapter() { + @Override + public void doOk() { + editReportServerParameterPane.update(configManager); + Env currentEnv = FRContext.getCurrentEnv(); + try { + currentEnv.writeResource(configManager); + } catch (Exception ex) { + FRContext.getLogger().error(ex.getMessage(), ex); + } + } + }); + editReportServerParameterDialog.setVisible(true); + } + + @Override + public void update() { + this.setEnabled(true); + } + + public static final MenuKeySet SERVER_CONFIG_MANAGER = new MenuKeySet() { + @Override + public char getMnemonic() { + return 'M'; + } + + @Override + public String getMenuName() { + return Inter.getLocText("M_Server-Server_Config_Manager"); + } + + @Override + public KeyStroke getKeyStroke() { + return null; + } + }; +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/server/StyleListAction.java b/designer/src/com/fr/design/actions/server/StyleListAction.java new file mode 100644 index 000000000..a918a25c4 --- /dev/null +++ b/designer/src/com/fr/design/actions/server/StyleListAction.java @@ -0,0 +1,78 @@ +package com.fr.design.actions.server; + +import com.fr.base.BaseUtils; +import com.fr.base.ConfigManager; +import com.fr.base.Env; +import com.fr.base.FRContext; +import com.fr.design.actions.UpdateAction; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.DesignerFrame; +import com.fr.design.menu.MenuKeySet; +import com.fr.general.Inter; + +import javax.swing.*; +import java.awt.event.ActionEvent; + + +/** + * StyleList Action + */ +public class StyleListAction extends UpdateAction { + public StyleListAction() { + this.setMenuKeySet(PREDEFINED_STYLES); + this.setName(getMenuKeySet().getMenuKeySetName()+ "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_web/style.png")); + } + + /** + * 动作 + * @param evt 事件 + */ + public void actionPerformed(ActionEvent evt) { + DesignerFrame designerFrame = DesignerContext.getDesignerFrame(); + final StyleManagerPane styleListPane = new StyleManagerPane(); + BasicDialog styleListDialog = styleListPane.showWindow(designerFrame); + styleListDialog.addDialogActionListener(new DialogActionAdapter() { + @Override + public void doOk() { + styleListPane.update(ConfigManager.getProviderInstance()); + //marks:保存数据 + Env currentEnv = FRContext.getCurrentEnv(); + try { + currentEnv.writeResource(ConfigManager.getProviderInstance()); + } catch (Exception e) { + FRContext.getLogger().error(e.getMessage(), e); + } + } + }); + + styleListPane.populate(ConfigManager.getProviderInstance()); + styleListDialog.setVisible(true); + + } + + @Override + public void update() { + this.setEnabled(true); + } + + public static final MenuKeySet PREDEFINED_STYLES = new MenuKeySet() { + @Override + public char getMnemonic() { + return 'K'; + } + + @Override + public String getMenuName() { + return Inter.getLocText("ServerM-Predefined_Styles"); + } + + @Override + public KeyStroke getKeyStroke() { + return null; + } + }; +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/server/StyleManagerPane.java b/designer/src/com/fr/design/actions/server/StyleManagerPane.java new file mode 100644 index 000000000..5388c1d07 --- /dev/null +++ b/designer/src/com/fr/design/actions/server/StyleManagerPane.java @@ -0,0 +1,51 @@ +package com.fr.design.actions.server; + +import com.fr.base.FRContext; +import com.fr.base.ConfigManagerProvider; +import com.fr.design.dialog.BasicPane; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itextfield.UITextField; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.present.StyleArrayPane; +import com.fr.general.Inter; +import com.fr.stable.project.ProjectConstants; + +import javax.swing.*; +import java.awt.*; +import java.io.File; + +public class StyleManagerPane extends BasicPane { + private UITextField StyleTextField; + private StyleArrayPane styleArrayPane; + + public StyleManagerPane(){ + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + + JPanel stylePathPane = FRGUIPaneFactory.createBorderLayout_L_Pane(); + this.add(stylePathPane, BorderLayout.NORTH); + + stylePathPane.add(new UILabel(Inter.getLocText("FR-Designer_Save_Path") + ":"), BorderLayout.WEST); + this.StyleTextField = new UITextField(); + stylePathPane.add(StyleTextField, BorderLayout.CENTER); + this.StyleTextField.setEditable(false); + + styleArrayPane = new StyleArrayPane(); + this.add(styleArrayPane, BorderLayout.CENTER); + } + + @Override + protected String title4PopupWindow() { + return Inter.getLocText("ServerM-Predefined_Styles"); + } + + public void populate(ConfigManagerProvider configManager) { + this.StyleTextField.setText(FRContext.getCurrentEnv().getPath() + File.separator + + ProjectConstants.RESOURCES_NAME + + File.separator + configManager.fileName()); + this.styleArrayPane.populate(configManager); + } + + public void update(ConfigManagerProvider configManager) { + this.styleArrayPane.update(configManager); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/server/WidgetManagerAction.java b/designer/src/com/fr/design/actions/server/WidgetManagerAction.java new file mode 100644 index 000000000..58fb9ec37 --- /dev/null +++ b/designer/src/com/fr/design/actions/server/WidgetManagerAction.java @@ -0,0 +1,88 @@ +package com.fr.design.actions.server; + +import com.fr.base.BaseUtils; +import com.fr.base.Env; +import com.fr.base.FRContext; +import com.fr.design.DesignModelAdapter; +import com.fr.design.actions.UpdateAction; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.DesignerFrame; +import com.fr.design.menu.MenuKeySet; +import com.fr.design.webattr.WidgetManagerPane; +import com.fr.form.ui.WidgetManager; +import com.fr.form.ui.WidgetManagerProvider; +import com.fr.general.Inter; + +import javax.swing.*; +import java.awt.event.ActionEvent; + +public class WidgetManagerAction extends UpdateAction { + public WidgetManagerAction() { + this.setMenuKeySet(WIDGET_MANAGER); + this.setName(getMenuKeySet().getMenuKeySetName()+ "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_format/modified.png")); + } + + /** + * 动作 + * @param e 事件 + */ + public void actionPerformed(ActionEvent e) { + final DesignerFrame designerFrame = DesignerContext.getDesignerFrame(); + final WidgetManagerProvider widgetManager = WidgetManager.getProviderInstance(); + final WidgetManagerPane widgetManagerPane = new WidgetManagerPane() { + @Override + public void complete() { + populate(widgetManager); + } + }; + + BasicDialog widgetConfigDialog = widgetManagerPane.showLargeWindow(designerFrame,new DialogActionAdapter() { + @Override + public void doOk() { + widgetManagerPane.update(widgetManager); + + Env currentEnv = FRContext.getCurrentEnv(); + try { + currentEnv.writeResource(widgetManager); + //marks: 由于这个面板还改变权限相关的操作,所以这个时候还要操作权限配置 +// currentEnv.writeResource(FRContext.getPrivilegeManager()); + } catch (Exception ex) { + FRContext.getLogger().error(ex.getMessage(), ex); + } + DesignModelAdapter model = DesignModelAdapter.getCurrentModelAdapter(); + if (model != null) { + model.widgetConfigChanged(); + } + designerFrame.getSelectedJTemplate().refreshToolArea(); + } + }); + + widgetConfigDialog.setVisible(true); + } + + @Override + public void update() { + this.setEnabled(true); + } + + public static final MenuKeySet WIDGET_MANAGER = new MenuKeySet() { + @Override + public char getMnemonic() { + return 'W'; + } + + @Override + public String getMenuName() { + return Inter.getLocText("ServerM-Widget_Manager"); + } + + @Override + public KeyStroke getKeyStroke() { + return null; + } + }; +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/utils/DeprecatedActionManager.java b/designer/src/com/fr/design/actions/utils/DeprecatedActionManager.java new file mode 100644 index 000000000..0135f8ddf --- /dev/null +++ b/designer/src/com/fr/design/actions/utils/DeprecatedActionManager.java @@ -0,0 +1,178 @@ +package com.fr.design.actions.utils; + + +import com.fr.base.BaseUtils; +import com.fr.base.present.DictPresent; +import com.fr.base.present.FormulaPresent; +import com.fr.design.ExtraDesignClassManager; +import com.fr.design.constants.UIConstants; +import com.fr.design.actions.UpdateAction; +import com.fr.design.actions.cell.NewPresentAction; +import com.fr.design.actions.core.ActionUtils; +import com.fr.design.actions.edit.clear.*; +import com.fr.design.actions.edit.order.BringFloatElementForwardAction; +import com.fr.design.actions.edit.order.BringFloatElementToFrontAction; +import com.fr.design.actions.edit.order.SendFloatElementBackwardAction; +import com.fr.design.actions.edit.order.SendFloatElementToBackAction; +import com.fr.design.actions.columnrow.DeleteColumnAction; +import com.fr.design.actions.columnrow.DeleteRowAction; +import com.fr.design.actions.columnrow.InsertColumnAction; +import com.fr.design.actions.columnrow.InsertRowAction; +import com.fr.design.file.HistoryTemplateListPane; +import com.fr.design.fun.PresentKindProvider; +import com.fr.design.gui.imenu.UIMenu; +import com.fr.design.mainframe.JTemplate; +import com.fr.design.menu.KeySetUtils; +import com.fr.design.menu.MenuDef; +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.selection.CellSelection; +import com.fr.grid.selection.Selection; +import com.fr.design.selection.SelectionEvent; +import com.fr.design.selection.SelectionListener; +import com.fr.report.cell.cellattr.BarcodePresent; +import com.fr.report.cell.cellattr.CurrencyLinePresent; + +import javax.swing.*; + +/** + * peter: 这个方法只是临时放在这边的, 等插件系统全部完善后,立刻删除. + */ +public class DeprecatedActionManager { + // TODO ALEX_SEP 这里的所有方法,都和TemplateComponent对应的ToolbarMenuAdapter有重复 + + /** + * Clear menu. + * + * @return the clearReportPage menu. + */ + public static UIMenu getClearMenu(ElementCasePane ePane) { + UIMenu clearMenu = new UIMenu(Inter.getLocText("M_Edit-Clear")); + clearMenu.setIcon(UIConstants.BLACK_ICON); + clearMenu.setMnemonic('a'); + + ClearAction ReportComponentAction = new ClearAllAction(ePane); + clearMenu.add(ReportComponentAction.createMenuItem()); + + ReportComponentAction = new ClearFormatsAction(ePane); + clearMenu.add(ReportComponentAction.createMenuItem()); + ReportComponentAction = new ClearContentsAction(ePane); + clearMenu.add(ReportComponentAction.createMenuItem()); + + JTemplate jTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); + if (jTemplate.isJWorkBook()){ //表单中报表块编辑屏蔽掉 清除控件 + ReportComponentAction = new ClearWidgetAction(ePane); + clearMenu.add(ReportComponentAction.createMenuItem()); + } + return clearMenu; + } + + /** + * Order menu + */ + public static JMenu getOrderMenu(ElementCasePane ePane) { + JMenu orderMenu = new JMenu(Inter.getLocText("M_Edit-Order")); + orderMenu.setIcon(UIConstants.BLACK_ICON); + orderMenu.setMnemonic('O'); + orderMenu.setBackground(UIConstants.NORMAL_BACKGROUND); + + orderMenu.add(new BringFloatElementToFrontAction(ePane).createMenuItem()); + orderMenu.add(new SendFloatElementToBackAction(ePane).createMenuItem()); + orderMenu.add(new BringFloatElementForwardAction(ePane).createMenuItem()); + orderMenu.add(new SendFloatElementBackwardAction(ePane).createMenuItem()); + + return orderMenu; + } + + /** + * Cell Style. + */ + public static MenuDef getCellMenu(final ElementCasePane ePane) { + // 单元格菜单 + final MenuDef subMenuDef = new MenuDef(KeySetUtils.CELL_ELEMENT.getMenuName()); + subMenuDef.setIconPath("/com/fr/design/images/m_insert/cell.png"); + + UpdateAction[] actions = ActionUtils.createCellInsertAction(ElementCasePane.class, ePane); + for (int i = 0; i < actions.length; i++) { + subMenuDef.addShortCut(actions[i]); + } + ePane.addSelectionChangeListener(new SelectionListener() { + + @Override + public void selectionChanged(SelectionEvent e) { + Selection sel = ePane.getSelection(); + if (sel instanceof CellSelection) { + subMenuDef.setEnabled(true); + } else { + subMenuDef.setEnabled(false); + } + } + }); + return subMenuDef; + } + + public static MenuDef getPresentMenu(final ElementCasePane ePane) { + final MenuDef presentMenu = new MenuDef(KeySetUtils.PRESENT.getMenuKeySetName()); + presentMenu.setIconPath("com/fr/design/images/data/source/dataDictionary.png"); + presentMenu.setMnemonic(KeySetUtils.PRESENT.getMnemonic()); + NewPresentAction dataDictAction = new NewPresentAction(ePane, Inter.getLocText("M_Format-Data_Map"), DictPresent.class.getName()); + dataDictAction.setMnemonic('D'); + NewPresentAction formulaAction = new NewPresentAction(ePane, Inter.getLocText("Present-Formula_Present"), FormulaPresent.class.getName()); + formulaAction.setMnemonic('F'); + NewPresentAction barcodeAction = new NewPresentAction(ePane, Inter.getLocText("M_Insert-Barcode"), BarcodePresent.class.getName()); + barcodeAction.setMnemonic('B'); + NewPresentAction currencyLineAction = new NewPresentAction(ePane, Inter.getLocText("Currency_Line"), CurrencyLinePresent.class.getName()); + currencyLineAction.setMnemonic('L'); + NewPresentAction nonePresentAction = new NewPresentAction(ePane, Inter.getLocText("Present-No_Present"), "NOPRESENT"); + nonePresentAction.setMnemonic('N'); + presentMenu.addShortCut(dataDictAction); + presentMenu.addShortCut(formulaAction); + presentMenu.addShortCut(barcodeAction); + presentMenu.addShortCut(currencyLineAction); + + PresentKindProvider[] providers = ExtraDesignClassManager.getInstance().getPresentKindProviders(); + for (PresentKindProvider provider : providers) { + NewPresentAction action = new NewPresentAction(ePane, provider.title(), provider.kindOfPresent().getName()); + action.setMnemonic(provider.mnemonic()); + presentMenu.addShortCut(action); + } + presentMenu.addShortCut(nonePresentAction); + + ePane.addSelectionChangeListener(new SelectionListener() { + + @Override + public void selectionChanged(SelectionEvent e) { + Selection sel = ePane.getSelection(); + if (sel instanceof CellSelection) { + presentMenu.setEnabled(true); + } else { + presentMenu.setEnabled(false); + } + } + }); + + return presentMenu; + } + + public static UIMenu getDeleteMenu(ElementCasePane ePane) { + UIMenu deleteMenu = new UIMenu(Inter.getLocText("M_Edit-Delete")); + deleteMenu.setIcon(BaseUtils.readIcon("/com/fr/design/images/control/remove.png")); + deleteMenu.setMnemonic('d'); + deleteMenu.add(new DeleteRowAction(ePane).createMenuItem()); + + deleteMenu.add(new DeleteColumnAction(ePane).createMenuItem()); + + return deleteMenu; + } + + public static UIMenu getInsertMenu(ElementCasePane ePane) { + UIMenu deleteMenu = new UIMenu(Inter.getLocText("Insert") + "(I)"); + deleteMenu.setIcon(BaseUtils.readIcon("/com/fr/base/images/cell/control/add.png")); + deleteMenu.setMnemonic('i'); + deleteMenu.add(new InsertRowAction(ePane).createMenuItem()); + + deleteMenu.add(new InsertColumnAction(ePane).createMenuItem()); + + return deleteMenu; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/actions/utils/ReportActionUtils.java b/designer/src/com/fr/design/actions/utils/ReportActionUtils.java new file mode 100644 index 000000000..7f4a51394 --- /dev/null +++ b/designer/src/com/fr/design/actions/utils/ReportActionUtils.java @@ -0,0 +1,122 @@ +package com.fr.design.actions.utils; + +import com.fr.base.Style; +import com.fr.design.actions.cell.style.StyleActionInterface; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.selection.CellSelection; +import com.fr.grid.selection.FloatSelection; +import com.fr.grid.selection.Selection; +import com.fr.report.cell.CellElement; +import com.fr.report.cell.DefaultTemplateCellElement; +import com.fr.report.cell.FloatElement; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.elementcase.ElementCase; +import com.fr.report.elementcase.TemplateElementCase; + +import java.awt.*; + +public class ReportActionUtils { + private ReportActionUtils() { + } + + + public static interface IterAction { + public void dealWith(CellElement editCellElement); + } + + public static boolean executeAction( + final StyleActionInterface styleActionInterface, ElementCasePane reportPane) { + + Selection sel = reportPane.getSelection(); + if (sel instanceof FloatSelection) { + ElementCase report = reportPane.getEditingElementCase(); + FloatElement selectedFloatElement = + report.getFloatElement(((FloatSelection) sel).getSelectedFloatName()); + + Style selectedStyle = selectedFloatElement.getStyle(); + selectedFloatElement.setStyle( + styleActionInterface.executeStyle(selectedStyle, selectedStyle)); + } else { + TemplateElementCase report = reportPane.getEditingElementCase(); + TemplateCellElement editCellElement = report.getTemplateCellElement(((CellSelection) sel).getColumn(), ((CellSelection) sel).getRow()); + if (editCellElement == null) { + editCellElement = new DefaultTemplateCellElement(((CellSelection) sel).getColumn(), ((CellSelection) sel).getRow()); + report.addCellElement(editCellElement); + } + + final Style selectedStyle = editCellElement.getStyle(); + + actionIterateWithCellSelection((CellSelection) sel, report, new IterAction() { + @Override + public void dealWith(CellElement editCellElement) { + Style style2Mod = editCellElement.getStyle(); + editCellElement.setStyle( + styleActionInterface.executeStyle(style2Mod, selectedStyle)); + + } + }); + } + + return true; + } + + public static void actionIterateWithCellSelection( + CellSelection gridSelection, TemplateElementCase report, IterAction action) { + //需要先行后列地增加新元素。 + // 从最后循环起以保证最后一个修改标准单元格(originalStyle)。 + int cellRectangleCount = gridSelection.getCellRectangleCount(); + for (int rec = 0; rec < cellRectangleCount; rec++) { + Rectangle cellRectangle = gridSelection.getCellRectangle(rec); + // 从最后循环起以保证最后一个修改标准单元格(originalStyle)。 + for (int j = cellRectangle.height - 1; j >= 0; j--) { + for (int i = cellRectangle.width - 1; i >= 0; i--) { + int column = i + cellRectangle.x; + int row = j + cellRectangle.y; + + TemplateCellElement editCellElement = report.getTemplateCellElement(column, row); + if (editCellElement == null) { + editCellElement = new DefaultTemplateCellElement(column, row); + report.addCellElement(editCellElement); + } else { + // 对于合并的格子,我们不多次计算的Style. + if (editCellElement.getColumn() != column + || editCellElement.getRow() != row) { + continue; + } + } + + action.dealWith(editCellElement); + } + } + } + } + + /** + * peter:是只读的分析然后获得当前的Style. + * + * @param reportPane the current rpt pane. + * @return current style. + */ + public static Style getCurrentStyle(ElementCasePane reportPane) { + //got simple cell element from row and column + ElementCase report = reportPane.getEditingElementCase(); + + Selection sel = reportPane.getSelection(); + if (sel instanceof FloatSelection) { + FloatElement selectedFloatElement = report.getFloatElement(((FloatSelection) sel).getSelectedFloatName()); + return selectedFloatElement.getStyle(); + } + + //需要先行后列地增加新元素。 + //vivian: 如excel那样改变style.是状态的改变由第一个的状态决定,即如果只选择了第一个值那么就改为相反的值, + // 如果是选择了多个值则首先变成和第一个值的一样 + + CellElement editCellElement = report.getCellElement(((CellSelection) sel).getColumn(), ((CellSelection) sel).getRow()); + if (editCellElement == null) { + return Style.DEFAULT_STYLE; + } + + //peter:直接返回当前编辑元素的Style + return editCellElement.getStyle(); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/bar/BarHelper.java b/designer/src/com/fr/design/cell/bar/BarHelper.java new file mode 100644 index 000000000..ba952983b --- /dev/null +++ b/designer/src/com/fr/design/cell/bar/BarHelper.java @@ -0,0 +1,20 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.cell.bar; + +/** + * @author richer + * @since 6.5.3 + * 用来帮助调整滚动条的当前值、跨度、最小值和最大值的帮助类 + */ +public abstract class BarHelper { + + public abstract double getVisibleSize(); + + public abstract int getExtent(int currentValue); + + public abstract void resetBeginValue(int newValue); + + public abstract void resetExtentValue(int extentValue); +} \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/bar/DynamicScrollBar.java b/designer/src/com/fr/design/cell/bar/DynamicScrollBar.java new file mode 100644 index 000000000..bf61f7a5e --- /dev/null +++ b/designer/src/com/fr/design/cell/bar/DynamicScrollBar.java @@ -0,0 +1,291 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.cell.bar; + +import java.awt.Adjustable; +import java.awt.Dimension; +import java.awt.event.ComponentEvent; +import java.awt.event.ComponentListener; + +import javax.accessibility.AccessibleContext; +import javax.swing.*; + +import com.fr.base.DynamicUnitList; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.GridUtils; +import com.fr.report.ReportHelper; + +/** + * ScrollBar change its max value dynamically. + */ +public class DynamicScrollBar extends JScrollBar { + private ElementCasePane reportPane; + private boolean isSupportHide = true;//是否支持将ScrollBar隐藏起来. + private int dpi; + + public DynamicScrollBar(int orientation, ElementCasePane reportPane, int dpi) { + super(orientation); + + this.reportPane = reportPane; + + this.dpi = dpi; + + //init some values.h + this.setMinimum(0); + this.setUnitIncrement(1); + this.setBlockIncrement(3); + + this.addComponentListener(new ComponentListener() { + public void componentResized(ComponentEvent e) { + ajustValues(); + } + + public void componentMoved(ComponentEvent e) { + ajustValues(); + } + + public void componentShown(ComponentEvent e) { + ajustValues(); + } + + public void componentHidden(ComponentEvent e) { + ajustValues(); + } + + private void ajustValues() { + DynamicScrollBar.this.setValue(DynamicScrollBar.this.getValue()); + } + }); + } + + public ElementCasePane getReportPane() { + return reportPane; + } + + public void setReportPane(ElementCasePane reportPane) { + if (reportPane == null) { + return; + } + + this.reportPane = reportPane; + + //ajust + if (orientation == Adjustable.VERTICAL) { + verticalBarHelper.setValue(this.reportPane.getGrid().getVerticalValue()); + } else { + horizontalBarHelper.setValue(this.reportPane.getGrid().getHorizontalValue()); + } + } + + /** + * Returns the scrollbar's extent, aka its "visibleAmount". + */ + @Override + public int getVisibleAmount() { + if (this.reportPane == null) { + return 0; + } + + if (orientation == Adjustable.VERTICAL) { + return verticalBarHelper.getExtent(this.getValue()); + } else { + return horizontalBarHelper.getExtent(this.getValue()); + } + } + + + public void updateUI() { + setUI(new DynamicScrollBarUI()); + } + + @Override + public void setValue(int value) { + if (reportPane == null) { + return; + } + + if (orientation == Adjustable.VERTICAL) { + verticalBarHelper.setValue(value); + } else { + horizontalBarHelper.setValue(value); + } + } + + private abstract class DynamicScrollBarHelper extends BarHelper { + protected abstract DynamicUnitList getSizeList(); + + protected abstract int getLastIndex(); + + @Override + public int getExtent(int currentValue) { + return GridUtils.getExtentValue(currentValue, getSizeList(), getVisibleSize(), dpi) - currentValue; + } + + private int adjustNewValue(int newValue, int oldValue, DynamicUnitList sizeList) { + //adjust zero. + if (newValue < 0) { + newValue = 0; + } + + //ajust new value, ignore these row which height is zero. + if (oldValue < newValue) { + int increased = newValue - oldValue; + + int tmpIdx = 0; + for (int i = (oldValue + 1); true; i++) { + if (sizeList.get(i).more_than_zero()) { + tmpIdx++; + + if (tmpIdx == increased) { + newValue = i; + break; + } + } + } + } else if (oldValue > newValue) { + int decreased = oldValue - newValue; + + int tmpIdx = 0; + for (int i = (oldValue - 1); i >= 0; i--) { + if (sizeList.get(i).more_than_zero()) { + tmpIdx++; + + if (tmpIdx == decreased) { + newValue = i; + break; + } + } + } + } + return newValue; + } + + public void setValue(int newValue) { + int oldValue = DynamicScrollBar.this.getValue(); + + DynamicUnitList sizeList = getSizeList(); + int lastIndex = getLastIndex(); + + newValue = adjustNewValue(newValue, oldValue, sizeList); + + int extent = getExtent(newValue); + int maxIndex; + maxIndex = Math.max(lastIndex, extent) + 1; + maxIndex = Math.max(newValue + extent, maxIndex); + + // TODO ALEX_SEP 不明白这段代码的必要性 +// //Check GridSelection. +// GridSelection gridSelection = reportPane.getGridSelection(); +// int type = gridSelection.getType(); +// if(type == GridSelection.CELL) { +// Rectangle cellRectangle = gridSelection.getFirstCellRectangle(); +// maxIndex = Math.max(cellRectangle.y + cellRectangle.height + 1, maxIndex); //denny:- this.getReportPane().getFrozenRow() +// } + + //Check old value. + BoundedRangeModel boundedRangeModel = DynamicScrollBar.this.getModel(); + if (newValue != boundedRangeModel.getValue() || + extent != boundedRangeModel.getExtent() || + maxIndex != boundedRangeModel.getMaximum()) { + boundedRangeModel.setRangeProperties(newValue, extent, 0, maxIndex, true); + + resetBeginValue(newValue); + resetExtentValue(extent); + DynamicScrollBar.this.reportPane.repaint(40); + + if (accessibleContext != null) { + accessibleContext.firePropertyChange(AccessibleContext.ACCESSIBLE_VALUE_PROPERTY, + new Integer(oldValue), + new Integer(DynamicScrollBar.this.getValue())); + } + } + } + } + + private DynamicScrollBarHelper verticalBarHelper = new DynamicScrollBarHelper() { + @Override + public int getLastIndex() { + return reportPane.getEditingElementCase().getRowCount() - 1; + } + + @Override + public DynamicUnitList getSizeList() { + return ReportHelper.getRowHeightList(reportPane.getEditingElementCase()); + } + + @Override + public double getVisibleSize() { + return reportPane.getGrid().getHeight(); + } + + ; + + @Override + public void resetBeginValue(int newValue) { + DynamicScrollBar.this.reportPane.getGrid().setVerticalValue(newValue); + } + + @Override + public void resetExtentValue(int extentValue) { + DynamicScrollBar.this.reportPane.getGrid().setVerticalExtent(extentValue); + } + }; + + private DynamicScrollBarHelper horizontalBarHelper = new DynamicScrollBarHelper() { + @Override + public int getLastIndex() { + return reportPane.getEditingElementCase().getColumnCount() - 1; + } + + @Override + public DynamicUnitList getSizeList() { + return ReportHelper.getColumnWidthList(reportPane.getEditingElementCase()); + } + + @Override + public double getVisibleSize() { + return reportPane.getGrid().getWidth(); + } + + ; + + @Override + public void resetBeginValue(int newValue) { + DynamicScrollBar.this.reportPane.getGrid().setHorizontalValue(newValue); + } + + @Override + public void resetExtentValue(int extentValue) { + DynamicScrollBar.this.reportPane.getGrid().setHorizontalExtent(extentValue); + } + }; + + public boolean isSupportHide() { + return isSupportHide; + } + + public void setSupportHide(boolean supportHide) { + isSupportHide = supportHide; + } + + /** + * Return the preferred size. + */ + @Override + public Dimension getPreferredSize() { + if (isSupportHide) { + if (this.getOrientation() == Adjustable.HORIZONTAL) { + if (reportPane != null && !reportPane.isHorizontalScrollBarVisible()) { + return new Dimension(0, 0); + } + } else if (this.getOrientation() == Adjustable.VERTICAL) { + if (reportPane != null && !reportPane.isVerticalScrollBarVisible()) { + return new Dimension(0, 0); + } + } + } + + return super.getPreferredSize(); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/bar/DynamicScrollBarUI.java b/designer/src/com/fr/design/cell/bar/DynamicScrollBarUI.java new file mode 100644 index 000000000..abf911e82 --- /dev/null +++ b/designer/src/com/fr/design/cell/bar/DynamicScrollBarUI.java @@ -0,0 +1,221 @@ +package com.fr.design.cell.bar; + +import com.fr.design.gui.iscrollbar.UISBChooser; + +import javax.swing.*; +import javax.swing.plaf.basic.BasicScrollBarUI; +import java.awt.*; +import java.awt.event.MouseEvent; + +/** + * Created by IntelliJ IDEA. + * Author : daisy + * Version: 6.5.6 + * Date: 13-12-30 + * Time: 下午2:28 + */ +public class DynamicScrollBarUI extends BasicScrollBarUI { + + + private boolean isRollover = false; + //是否 + private boolean wasRollover = false; + + + public DynamicScrollBarUI() { + + } + + /** + * 是否可见 + * @return 可见返回true + */ + public boolean isThumbVisible() { + if (scrollbar.getOrientation() == JScrollBar.VERTICAL) { + return getThumbBounds().height > 0; + } else { + return getThumbBounds().width > 0; + } + } + + public void paintThumb(Graphics g, JComponent c, Rectangle t) { +// super.paintThumb(g,c,t); + paintXP(g, t); + } + + private void paintXP(Graphics g, Rectangle t) { + Color c = null; + if (isDragging && isRollover) { + c = ScrollBarUIConstant.PRESS_SCROLL_BAR_COLOR; + } else if (isRollover) { + c = ScrollBarUIConstant.ROLL_OVER_SCROLL_BAR_COLOR; + } else { + c = ScrollBarUIConstant.NORMAL_SCROLL_BAR_COLOR; + } + + g.setColor(c); + + int xs = t.x + 1; + int ys = t.y + 1; + int x2 = t.x + t.width - 1; + int y2 = t.y + t.height - 1; + + paintScrollBar(g, xs, ys, x2, y2, t); + + // draw Grip +// if (t.height < 11) { +// return; +// } +// +// if (scrollbar.getOrientation() == JScrollBar.VERTICAL) { +// drawVertical(t, y2, g, c); +// } else { +// drawHrizontal(t, x2, g, c); +// } + } + + + private void drawHrizontal(Rectangle t, int x2, Graphics g, Color c) { + int x1 = t.x + (t.width) / 2 - 4; + x2 = Math.min(x1 + 8, t.x + t.width - 5); + + int x = x1 + 1; + // we take only saturation & brightness and apply them + // to the background color (normal/rollover/pressed) + g.setColor(UISBChooser.getAdjustedColor(c, 0, 71)); + while (x < x2) { + g.drawLine(x, 5, x, 11); + x += 2; + } + + x = x1; + g.setColor(UISBChooser.getAdjustedColor(c, 0, -13)); + while (x < x2) { + g.drawLine(x, 6, x, 12); + x += 2; + } + } + + private void drawVertical(Rectangle t, int y2, Graphics g, Color c) { + int y1 = t.y + (t.height) / 2 - 4; + y2 = Math.min(y1 + 8, t.y + t.height - 5); + + int y = y1; + // we take only saturation & brightness and apply them + // to the background color (normal/rollover/pressed) + g.setColor(UISBChooser.getAdjustedColor(c, 0, 71)); + while (y < y2) { + g.drawLine(5, y, 11, y); + y += 2; + } + + y = y1 + 1; + g.setColor(UISBChooser.getAdjustedColor(c, 0, -13)); + while (y < y2) { + g.drawLine(6, y, 12, y); + y += 2; + } + } + + private void paintScrollBar(Graphics g, int xs, int ys, int x2, int y2, Rectangle t) { + switch (scrollbar.getOrientation()) { + //harry: 垂直滚动条和水平滚动条的画法分开。 + case JScrollBar.VERTICAL: + Graphics2D g2 = (Graphics2D) g; + GradientPaint scrollBarBg = null; + if (isRollover) { + scrollBarBg = new GradientPaint(xs, ys, ScrollBarUIConstant.ROLL_OVER_SCROLL_BAR_COLOR, x2, ys, ScrollBarUIConstant.ROLL_OVER_SCROLL_BAR_COLOR); + } else { + scrollBarBg = new GradientPaint(xs, ys, ScrollBarUIConstant.NORMAL_SCROLL_BAR_COLOR, x2, ys, ScrollBarUIConstant.NORMAL_SCROLL_BAR_COLOR); + } + g2.setPaint(scrollBarBg); + g2.fillRoundRect(xs, ys, t.width - 2, t.height - 2, 0, 0); + break; + case JScrollBar.HORIZONTAL: + Graphics2D g2H = (Graphics2D) g; + if (isRollover) { + scrollBarBg = new GradientPaint(xs, ys, ScrollBarUIConstant.ROLL_OVER_SCROLL_BAR_COLOR, xs, y2, ScrollBarUIConstant.ROLL_OVER_SCROLL_BAR_COLOR); + } else { + scrollBarBg = new GradientPaint(xs, ys, ScrollBarUIConstant.NORMAL_SCROLL_BAR_COLOR, xs, y2, ScrollBarUIConstant.NORMAL_SCROLL_BAR_COLOR); + } + g2H.setPaint(scrollBarBg); + g2H.fillRoundRect(xs, ys, t.width - 2, t.height - 2, 0, 0); + break; + } + } + + + protected JButton createDecreaseButton(int orientation) { + return new DynamicScrollButton(orientation, this); + } + + /** + * Creates the increase button of the scrollbar. + * + * @param orientation The button's orientation. + * @return The created button. + */ + protected JButton createIncreaseButton(int orientation) { + return new DynamicScrollButton(orientation, this); + } + + protected TrackListener createTrackListener() { + return new ScrollBarTrackListener(); + } + + + private class ScrollBarTrackListener extends BasicScrollBarUI.TrackListener { + public void mouseReleased(MouseEvent e) { + super.mouseReleased(e); + scrollbar.repaint(); + } + + public void mousePressed(MouseEvent e) { + super.mousePressed(e); + scrollbar.repaint(); + } + + public void mouseEntered(MouseEvent e) { + isRollover = false; + wasRollover = false; + if (getThumbBounds().contains(e.getPoint())) { + isRollover = true; + wasRollover = isRollover; + scrollbar.repaint(); + } + } + + public void mouseExited(MouseEvent e) { + isRollover = false; + if (isRollover != wasRollover) { + wasRollover = isRollover; + scrollbar.repaint(); + } + } + + public void mouseDragged(MouseEvent e) { + if (getThumbBounds().contains(e.getPoint())) { + isDragging = true; + } + super.mouseDragged(e); + } + + public void mouseMoved(MouseEvent e) { + if (getThumbBounds().contains(e.getPoint())) { + isRollover = true; + if (isRollover != wasRollover) { + scrollbar.repaint(); + wasRollover = isRollover; + } + } else { + isRollover = false; + if (isRollover != wasRollover) { + scrollbar.repaint(); + wasRollover = isRollover; + } + } + } + } + + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/bar/DynamicScrollButton.java b/designer/src/com/fr/design/cell/bar/DynamicScrollButton.java new file mode 100644 index 000000000..1ddb34c17 --- /dev/null +++ b/designer/src/com/fr/design/cell/bar/DynamicScrollButton.java @@ -0,0 +1,208 @@ +package com.fr.design.cell.bar; + +import com.fr.general.ComparatorUtils; + +import javax.swing.*; +import javax.swing.plaf.basic.BasicArrowButton; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.util.HashMap; + +/** + * Created by IntelliJ IDEA. + * Author : daisy + * Version: 6.5.6 + * Date: 13-12-30 + * Time: 下午3:22 + */ +public class DynamicScrollButton extends BasicArrowButton { + + + private DynamicScrollBarUI scrollbarUI; + + + static HashMap cache = new HashMap(); + + private Dimension buttonSize = new Dimension(17, 17); + + public DynamicScrollButton(int direction, DynamicScrollBarUI scrollbarUI) { + super(direction); + + this.scrollbarUI = scrollbarUI; + setBorder(null); + setRolloverEnabled(true); + setMargin(new Insets(0, 0, 0, 0)); + setSize(buttonSize); + } + + public void paint(Graphics g) { + Color c = null; + + if (!scrollbarUI.isThumbVisible()) { + c = ScrollBarUIConstant.DISABLE_SCROLL_BAR_COLOR; + } else if (getModel().isPressed()) { + c = ScrollBarUIConstant.PRESS_SCROLL_BAR_COLOR; + } else if (getModel().isRollover()) { + c = ScrollBarUIConstant.ROLL_OVER_SCROLL_BAR_COLOR; + } else { + c = ScrollBarUIConstant.NORMAL_SCROLL_BAR_COLOR; + } + + g.setColor(c); + paintButton(g, getSize(), c); + if (!scrollbarUI.isThumbVisible()) { + g.setColor(ScrollBarUIConstant.ARROW_DISABLED_COLOR); + } else { + g.setColor(ScrollBarUIConstant.SCROLL_ARROW_COLOR); + } + + paintArrow(g, getSize()); + } + + + private void paintArrow(Graphics g, Dimension size) { + switch (direction) { + case SwingConstants.NORTH: + g.drawLine(8, 5, 8, 5); + g.drawLine(7, 6, 9, 6); + g.drawLine(6, 7, 10, 7); + g.drawLine(5, 8, 7, 8); + g.drawLine(9, 8, 11, 8); + g.drawLine(4, 9, 6, 9); + g.drawLine(10, 9, 12, 9); + g.drawLine(5, 10, 5, 10); + g.drawLine(11, 10, 11, 10); + break; + case SwingConstants.SOUTH: + g.drawLine(5, 6, 5, 6); + g.drawLine(11, 6, 11, 6); + g.drawLine(4, 7, 6, 7); + g.drawLine(10, 7, 12, 7); + g.drawLine(5, 8, 7, 8); + g.drawLine(9, 8, 11, 8); + g.drawLine(6, 9, 10, 9); + g.drawLine(7, 10, 9, 10); + g.drawLine(8, 11, 8, 11); + break; + case SwingConstants.EAST: + g.drawLine(6, 5, 6, 5); + g.drawLine(6, 11, 6, 11); + g.drawLine(7, 4, 7, 6); + g.drawLine(7, 10, 7, 12); + g.drawLine(8, 5, 8, 7); + g.drawLine(8, 9, 8, 11); + g.drawLine(9, 6, 9, 10); + g.drawLine(10, 7, 10, 9); + g.drawLine(11, 8, 11, 8); + break; + case SwingConstants.WEST: + g.drawLine(4, 8, 4, 8); + g.drawLine(5, 7, 5, 9); + g.drawLine(6, 6, 6, 10); + g.drawLine(7, 5, 7, 7); + g.drawLine(7, 9, 7, 11); + g.drawLine(8, 4, 8, 6); + g.drawLine(8, 10, 8, 12); + g.drawLine(9, 5, 9, 5); + g.drawLine(9, 11, 9, 11); + break; + } + } + + + private void paintButton(Graphics g, Dimension size, Color c) { + boolean enabled = scrollbarUI.isThumbVisible(); + boolean pressed = getModel().isPressed(); + boolean rollover = getModel().isRollover(); + ScrollButtonKey key = new ScrollButtonKey( + (direction == NORTH || direction == SOUTH), + c, pressed, enabled, rollover); + Object value = cache.get(key); + if (value != null) { + // image was cached - paint image and return + g.drawImage((Image) value, 0, 0, this); + return; + } + Image img = new BufferedImage(17, 17, BufferedImage.TYPE_INT_ARGB); + Graphics imgGraphics = img.getGraphics(); + switch (direction) { + case EAST: + case WEST: + case NORTH: + case SOUTH: + Color a = ScrollBarUIConstant.SCROLL_BORDER_COLOR; + Graphics2D g2 = (Graphics2D) imgGraphics; + GradientPaint scrollBarBg = null; + if (!scrollbarUI.isThumbVisible()) { + scrollBarBg = new GradientPaint(1, 1, ScrollBarUIConstant.NORMAL_SCROLL_BUTTON_COLOR, 1, 16, ScrollBarUIConstant.NORMAL_SCROLL_BUTTON_COLOR); + } else if (getModel().isPressed()) { + scrollBarBg = new GradientPaint(1, 1, ScrollBarUIConstant.PRESSED_SCROLL_BUTTON_COLOR, 1, 16, ScrollBarUIConstant.PRESSED_SCROLL_BUTTON_COLOR); + } else if (getModel().isRollover()) { + scrollBarBg = new GradientPaint(1, 1, ScrollBarUIConstant.PRESSED_SCROLL_BUTTON_COLOR, 1, 16, ScrollBarUIConstant.PRESSED_SCROLL_BUTTON_COLOR); + } else { + scrollBarBg = new GradientPaint(1, 1, ScrollBarUIConstant.NORMAL_SCROLL_BUTTON_COLOR, 1, 16, ScrollBarUIConstant.NORMAL_SCROLL_BUTTON_COLOR); + } + //GradientPaint scrollBarHight = new GradientPaint(0, 0, new Color(1.0f, 1.0f, 1.0f, 0.5f), 0, 7, new Color(1.0f, 1.0f, 1.0f, 0.2f)); + g2.setPaint(scrollBarBg); + g2.fillRoundRect(1, 1, 16, 16, 0, 0); +// g2.setPaint(scrollBarHight); +// g2.fillRoundRect(1, 1, 16, 7, 3, 3); +// g2.setColor(a); +// g2.drawRoundRect(1, 1, 15, 15, 3, 3); +// g2.setColor(new Color(240, 240, 240)); +// g2.drawRoundRect(2, 2, 13, 13, 3, 3); + break; + } + // dispose of image graphics + imgGraphics.dispose(); + // draw the image + g.drawImage(img, 0, 0, this); + // add the image to the cache + cache.put(key, img); + } + + static class ScrollButtonKey { + + private boolean vertical; + private Color c; + private boolean pressed; + private boolean enabled; + private boolean rollover; + + ScrollButtonKey(boolean vertical, Color c, + boolean pressed, boolean enabled, boolean rollover) { + this.vertical = vertical; + this.c = c; + this.pressed = pressed; + this.enabled = enabled; + this.rollover = rollover; + } + + public boolean equals(Object o) { + if (o == null) { + return false; + } + if (!(o instanceof ScrollButtonKey)) { + return false; + } + + ScrollButtonKey other = (ScrollButtonKey) o; + + return vertical == other.vertical && + pressed == other.pressed && + enabled == other.enabled && + rollover == other.rollover && + ComparatorUtils.equals(c, other.c); + + } + + public int hashCode() { + return c.hashCode() * + (pressed ? 1 : 2) * + (enabled ? 4 : 8) * + (rollover ? 16 : 32) * + (vertical ? 64 : 128); + } + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/bar/ScrollBarUIConstant.java b/designer/src/com/fr/design/cell/bar/ScrollBarUIConstant.java new file mode 100644 index 000000000..9bce9d025 --- /dev/null +++ b/designer/src/com/fr/design/cell/bar/ScrollBarUIConstant.java @@ -0,0 +1,34 @@ +package com.fr.design.cell.bar; + +import javax.swing.plaf.ColorUIResource; + +/** + * Created by IntelliJ IDEA. + * Author : daisy + * Version: 6.5.6 + * Date: 13-12-30 + * Time: 下午4:12 + */ +public class ScrollBarUIConstant { + + public static final ColorUIResource NORMAL_LIGHT_COLOR = new ColorUIResource(236, 236, 236); + public static final ColorUIResource NORMAL_SCROLL_BAR_COLOR = new ColorUIResource(0xe2e2e2); + public static final ColorUIResource ROLL_OVER_SCROLL_BAR_COLOR = new ColorUIResource(0xd2d2d2); + public static final ColorUIResource PRESS_SCROLL_BAR_COLOR = new ColorUIResource(96, 189, 246); + + public static final ColorUIResource SCROLL_BORDER_COLOR = new ColorUIResource(198, 198, 198); + public static final ColorUIResource DISABLE_SCROLL_BAR_COLOR = new ColorUIResource(238, 237, 231); + + public static final ColorUIResource ARROW_DISABLED_COLOR = new ColorUIResource(193, 193, 193); + public static final ColorUIResource SCROLL_ARROW_COLOR = new ColorUIResource(112, 112, 112); + + public static final ColorUIResource PRESSED_LIGHT_COLOR = new ColorUIResource(205, 234, 252); + public static final ColorUIResource WHITE_BORDER_COLOR = new ColorUIResource(240, 240, 240); + public static final ColorUIResource NORMAL_SCROLL_BUTTON_COLOR = new ColorUIResource(0xffffff); + public static final ColorUIResource PRESSED_SCROLL_BUTTON_COLOR = new ColorUIResource(0xd2d2d2); + + + + + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/clipboard/CellElementsClip.java b/designer/src/com/fr/design/cell/clipboard/CellElementsClip.java new file mode 100644 index 000000000..89015286d --- /dev/null +++ b/designer/src/com/fr/design/cell/clipboard/CellElementsClip.java @@ -0,0 +1,122 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.cell.clipboard; + +import java.util.Arrays; +import java.util.Iterator; + +import com.fr.base.FRContext; +import com.fr.grid.selection.CellSelection; +import com.fr.report.cell.CellElement; +import com.fr.report.cell.CellElementComparator; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.elementcase.TemplateElementCase; + +/** + * The clip of CellElement. + */ +public class CellElementsClip implements Cloneable, java.io.Serializable { + private int columnSpan = 0; + private int rowSpan = 0; + + private TemplateCellElement[] clips; + + public CellElementsClip(int columnSpan, int rowSpan, TemplateCellElement[] clips) { + this.columnSpan = columnSpan; + this.rowSpan = rowSpan; + + this.clips = clips; + } + + public String compateExcelPaste() { + Arrays.sort(this.clips, CellElementComparator.getRowFirstComparator()); + + // 排序 + StringBuffer sbuf = new StringBuffer(); + + int currentRow = -1; + for (int i = 0; i < clips.length; i++) { + CellElement cellElement = clips[i]; + if (currentRow == -1) {// 初始化当前行. + currentRow = cellElement.getRow(); + } + + if (currentRow < cellElement.getRow()) { + for (int r = currentRow; r < cellElement.getRow(); r++) { + sbuf.append('\n'); + } + currentRow = cellElement.getRow(); + } + + // 添加分隔符号. + if (sbuf.length() > 0 && sbuf.charAt(sbuf.length() - 1) != '\n') { + sbuf.append('\t'); + } + + sbuf.append(cellElement.getValue()); + } + + return sbuf.toString(); + } + + public CellSelection pasteAt(TemplateElementCase ec, int column, int row) { + + Iterator cells = ec.intersect(column, row, columnSpan, rowSpan); + while (cells.hasNext()) { + TemplateCellElement cellElement = (TemplateCellElement)cells.next(); + ec.removeCellElement(cellElement); + } + for (int i = 0; i < clips.length; i++) { + TemplateCellElement cellElement; + try { + cellElement = (TemplateCellElement) clips[i].clone(); + } catch (CloneNotSupportedException e) { + FRContext.getLogger().error(e.getMessage(), e); + return null; + } + + // peter:因为前面已经将这个位置的元素删除了,所以不需要override了. + ec.addCellElement((TemplateCellElement) cellElement.deriveCellElement( + column + cellElement.getColumn(), row + cellElement.getRow() + ), false); + } + + return new CellSelection(column, row, columnSpan, rowSpan); + } + + public void pasteAtRegion(TemplateElementCase ec, + int startColumn, int startRow, + int column, int row, + int columnSpan, int rowSpan) { + for (int i = 0; i < clips.length; i++) { + TemplateCellElement cellElement = clips[i]; + + cellElement = (TemplateCellElement) cellElement.deriveCellElement(startColumn + cellElement.getColumn(), startRow + cellElement.getRow()); + //peter:检查是否越界,越界就不做了. + if (cellElement.getColumn() >= column + columnSpan || cellElement.getRow() >= row + rowSpan || cellElement.getColumn() < column + || cellElement.getRow() < row) { + continue; + } + + ec.addCellElement(cellElement); + } + } + + /** + * Clone. + */ + @Override + public Object clone() throws CloneNotSupportedException { + CellElementsClip cloned = (CellElementsClip) super.clone(); + + if (this.clips != null) { + cloned.clips = new TemplateCellElement[this.clips.length]; + for (int i = 0; i < this.clips.length; i++) { + cloned.clips[i] = (TemplateCellElement)this.clips[i].clone(); + } + } + + return cloned; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/clipboard/ElementsTransferable.java b/designer/src/com/fr/design/cell/clipboard/ElementsTransferable.java new file mode 100644 index 000000000..f56c681cf --- /dev/null +++ b/designer/src/com/fr/design/cell/clipboard/ElementsTransferable.java @@ -0,0 +1,129 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.cell.clipboard; + +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.ClipboardOwner; +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.Transferable; +import java.awt.datatransfer.UnsupportedFlavorException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import com.fr.stable.StableUtils; + +public class ElementsTransferable implements Transferable, ClipboardOwner { + public static final DataFlavor CellElementsClipDataFlavor = + createConstant(CellElementsClip.class, "CellElementsClip"); + public static final DataFlavor FloatElementClipDataFlavor = + createConstant(FloatElementsClip.class, "FloatElementClip"); + public static final DataFlavor StringDataFlavor = + createConstant(String.class, "String"); + + private static final DataFlavor[] flavors = { + ElementsTransferable.CellElementsClipDataFlavor, + ElementsTransferable.FloatElementClipDataFlavor, + ElementsTransferable.StringDataFlavor + }; + + private List dataList = new ArrayList(); + + private static DataFlavor createConstant(Class rc, String prn) { + try { + return new DataFlavor(rc, prn); + } catch (Exception e) { + return null; + } + } + + /** + * Creates a Transferable capable. + */ + public ElementsTransferable() { + } + + public void addObject(Object object) { + dataList.add(object); + } + + public Object getFirstObject() { + if(this.dataList.size() <= 0) { + return null; + } + + return this.dataList.get(0); + } + + /** + * Returns an array of flavors in which this Transferable + * can provide the data. + */ + @Override + public DataFlavor[] getTransferDataFlavors() { + // returning flavors itself would allow client code to modify + // our core behavior + return flavors.clone(); + } + + /** + * Returns whether the requested flavor is supported by this + * Transferable. + */ + @Override + public boolean isDataFlavorSupported(DataFlavor flavor) { + // JCK Test StringSelection0003: if 'flavor' is null, throw NPE + for (int i = 0; i < flavors.length; i++) { + if (flavor.equals(flavors[i])) { + return true; + } + } + + return false; + } + + /** + * Gets the Transferable's data in the requested + * DataFlavor if possible. + */ + @Override + public Object getTransferData(DataFlavor flavor) + throws UnsupportedFlavorException, IOException { + if(flavor == null) { + return null; + } + + for(int i = 0; i < dataList.size(); i++) { + Object dataObj = dataList.get(i); + if(dataObj == null) { + continue; + } + + if(StableUtils.classInstanceOf(flavor.getRepresentationClass(), dataObj.getClass())) { + return dataObj; + } + } + + return null; + } + @Override + public void lostOwnership(Clipboard clipboard, Transferable contents) { + } + + /** + * ElementNotStringTransderData. + */ + public static Object getElementNotStringTransderData(Transferable transferable) + throws UnsupportedFlavorException, IOException { + //marks:The flavor of string is the last one, and the loop don't contain the last one + for(int i = 0; i < flavors.length - 1; i++) { + Object obj = transferable.getTransferData(flavors[i]); + if(obj != null) { + return obj; + } + } + + return null; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/clipboard/FloatElementsClip.java b/designer/src/com/fr/design/cell/clipboard/FloatElementsClip.java new file mode 100644 index 000000000..b7cbb400a --- /dev/null +++ b/designer/src/com/fr/design/cell/clipboard/FloatElementsClip.java @@ -0,0 +1,103 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.cell.clipboard; + +import java.util.Iterator; + +import com.fr.base.FRContext; +import com.fr.design.cell.FloatElementsProvider; +import com.fr.general.ComparatorUtils; +import com.fr.grid.selection.FloatSelection; +import com.fr.report.cell.FloatElement; +import com.fr.report.elementcase.ElementCase; +import com.fr.report.elementcase.TemplateElementCase; +import com.fr.stable.unit.FU; +import com.fr.stable.unit.OLDPIX; + +/** + * The clip of Float Element. + */ +public class FloatElementsClip implements Cloneable, java.io.Serializable,FloatElementsProvider { + private FloatElement floatEl; + + public FloatElementsClip(FloatElement floatEl) { + this.floatEl = floatEl; + } + + /** + * 悬浮元素的粘贴 + * + * @param ec 单元格 + * @return 粘贴的悬浮元素 + */ + public FloatSelection pasteAt(TemplateElementCase ec) { + if (floatEl == null) { + return null; + } + FloatElement ret; + try { + ret = (FloatElement)this.floatEl.clone(); + } catch (CloneNotSupportedException e) { + FRContext.getLogger().error(e.getMessage(), e); + return null; + } + + while (ec.getFloatElement(ret.getName()) != null) { + ret.setName(ret.getName() + "-Copy"); + } + + while (true) { + if (isContainSameBoundFloatElement(ec, ret)) { + ret.setTopDistance(FU.getInstance(ret.getTopDistance().toFU() + new OLDPIX(50).toFU())); + ret.setLeftDistance(FU.getInstance(ret.getLeftDistance().toFU() + new OLDPIX(50).toFU())); + } else { + break; + } + } + + ec.addFloatElement(ret); + + return new FloatSelection(ret.getName()); + } + + /** + * Contain same location and bounds FloatElement. + */ + private static boolean isContainSameBoundFloatElement(ElementCase report, FloatElement oFloatElement) { + if (oFloatElement == null) { + return false; + } + + Iterator flotIt = report.floatIterator(); + while (flotIt.hasNext()) { + FloatElement tmpFloatElement = (FloatElement) flotIt.next(); + if (hasSameDistance(tmpFloatElement,oFloatElement)) { + return true; + } + } + + return false; + } + + private static boolean hasSameDistance(FloatElement tmpFloatElement,FloatElement oFloatElement){ + return (ComparatorUtils.equals(tmpFloatElement.getTopDistance(), oFloatElement.getTopDistance()) + && ComparatorUtils.equals(tmpFloatElement.getLeftDistance(), oFloatElement.getLeftDistance()) + && ComparatorUtils.equals(tmpFloatElement.getWidth(), oFloatElement.getWidth()) + && ComparatorUtils.equals(tmpFloatElement.getHeight(), oFloatElement.getHeight())); + } + + /** + * Clone. + */ + @Override + public Object clone() throws CloneNotSupportedException { + FloatElementsClip cloned = (FloatElementsClip) super.clone(); + + if (floatEl != null) { + cloned.floatEl = (FloatElement)this.floatEl.clone(); + } + + return cloned; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/editor/AbstractCellEditor.java b/designer/src/com/fr/design/cell/editor/AbstractCellEditor.java new file mode 100644 index 000000000..cc9c43564 --- /dev/null +++ b/designer/src/com/fr/design/cell/editor/AbstractCellEditor.java @@ -0,0 +1,140 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.cell.editor; + +import java.awt.Point; + +import javax.swing.event.EventListenerList; + +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.event.CellEditorEvent; +import com.fr.grid.event.CellEditorListener; +import com.fr.report.elementcase.TemplateElementCase; + +/** + * The baics abstract editor. + */ +public abstract class AbstractCellEditor implements CellEditor { + private EventListenerList listenerList = new EventListenerList(); + private CellEditorEvent cellEditEvent = null; + private Point locationOnCellElement = null; + private ElementCasePane ePane; + + public AbstractCellEditor() { + + } + + public AbstractCellEditor(ElementCasePane ePane) { + this.ePane = ePane; + } + + /** + * Gets the location of this component in the form of a point + * specifying the component's top-left corner in the CellElement's + * coordinate space. The default value is (0, 0). + * @return an instance of Point representing + * the top-left corner of the component's bounds in the + * coordinate space of the CellElement + */ + public Point getLocationOnCellElement() { + return this.locationOnCellElement; + } + + /** + * Sets the location of this component in the form of a point + * specifying the component's top-left corner in the CellElement's + * coordinate space. + * @param loc an instance of Point representing + * the top-left corner of the component's bounds in the + * coordinate space of the CellElement + */ + public void setLocationOnCellElement(Point loc) { + this.locationOnCellElement = loc; + } + + /** + * Tells the editor to stop editing and accept any partially edited + * value as the value of the editor. The editor returns false if + * editing was not stopped; this is useful for editors that validate + * and can not accept invalid entries. + * + * @return true if editing was stopped; false otherwise + */ + public boolean stopCellEditing() { + fireEditingStopped(); + return true; + } + + /** + * Tells the editor to cancel editing and not accept any partially + * edited value. + */ + public void cancelCellEditing() { + fireEditingCanceled(); + } + + /** + * Adds a listener to the list that's notified when the editor + * stops, or cancels editing. + * + * @param cellEditorListener the CellEditorListener + */ + public void addCellEditorListener(CellEditorListener cellEditorListener) { + listenerList.add(CellEditorListener.class, cellEditorListener); + } + + /** + * Removes a listener from the list that's notified + * + * @param cellEditorListener the CellEditorListener + */ + public void removeCellEditorListener(CellEditorListener cellEditorListener) { + listenerList.remove(CellEditorListener.class, cellEditorListener); + } + + /** + * Fire editing stopped listeners. + */ + protected void fireEditingStopped() { + // Guaranteed to return a non-null array + Object[] listeners = listenerList.getListenerList(); + + // Process the listeners last to first, notifying + // those that are interested in this event + for (int i = listeners.length - 2; i >= 0; i -= 2) { + if (listeners[i] == CellEditorListener.class) { + // Lazily create the event: + if (cellEditEvent == null) { + cellEditEvent = new CellEditorEvent(this); + } + + ((CellEditorListener) listeners[i + 1]).editingStopped(cellEditEvent); + } + } + if(ePane != null) { + ePane.fireSelectionChangeListener(); + } + } + + /** + * Fire editing canceled listeners. + */ + protected void fireEditingCanceled() { + // Guaranteed to return a non-null array + Object[] listeners = listenerList.getListenerList(); + + // Process the listeners last to first, notifying + // those that are interested in this event + for (int i = listeners.length - 2; i >= 0; i -= 2) { + if (listeners[i] == CellEditorListener.class) { + // Lazily create the event: + if (cellEditEvent == null) { + cellEditEvent = new CellEditorEvent(this); + } + + ((CellEditorListener) listeners[i + 1]).editingCanceled(cellEditEvent); + } + } + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/editor/AbstractFloatEditor.java b/designer/src/com/fr/design/cell/editor/AbstractFloatEditor.java new file mode 100644 index 000000000..b87102d28 --- /dev/null +++ b/designer/src/com/fr/design/cell/editor/AbstractFloatEditor.java @@ -0,0 +1,108 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.cell.editor; + +import java.awt.event.KeyEvent; + +import javax.swing.event.EventListenerList; + +import com.fr.grid.event.FloatEditorEvent; +import com.fr.grid.event.FloatEditorListener; + +/** + * The baics abstract float editor. + */ +public abstract class AbstractFloatEditor implements FloatEditor { + private EventListenerList listenerList = new EventListenerList(); + private FloatEditorEvent floatEditEvent = null; + + /** + * Accept keyevent to start editing. + */ + public boolean acceptKeyEventToStartFloatEditing(KeyEvent evt) { + return true; + } + + /** + * Tells the editor to stop editing and accept any partially edited + * value as the value of the editor. The editor returns false if + * editing was not stopped; this is useful for editors that validate + * and can not accept invalid entries. + * + * @return true if editing was stopped; false otherwise + */ + public boolean stopFloatEditing() { + fireEditingStopped(); + return true; + } + + /** + * Tells the editor to cancel editing and not accept any partially + * edited value. + */ + public void cancelFloatEditing() { + fireEditingCanceled(); + } + + /** + * Adds a listener to the list that's notified when the editor + * stops, or cancels editing. + * + * @param floatEditorListener the FloatEditorListener + */ + public void addFloatEditorListener(FloatEditorListener floatEditorListener) { + listenerList.add(FloatEditorListener.class, floatEditorListener); + } + + /** + * Removes a listener from the list that's notified + * + * @param floatEditorListener the FloatEditorListener + */ + public void removeFloatEditorListener(FloatEditorListener floatEditorListener) { + listenerList.remove(FloatEditorListener.class, floatEditorListener); + } + + /** + * Fire editing stopped listeners. + */ + protected void fireEditingStopped() { + // Guaranteed to return a non-null array + Object[] listeners = listenerList.getListenerList(); + + // Process the listeners last to first, notifying + // those that are interested in this event + for (int i = listeners.length - 2; i >= 0; i -= 2) { + if (listeners[i] == FloatEditorListener.class) { + // Lazily create the event: + if (floatEditEvent == null) { + floatEditEvent = new FloatEditorEvent(this); + } + + ((FloatEditorListener) listeners[i + 1]).editingStopped(floatEditEvent); + } + } + } + + /** + * Fire editing canceled listeners. + */ + protected void fireEditingCanceled() { + // Guaranteed to return a non-null array + Object[] listeners = listenerList.getListenerList(); + + // Process the listeners last to first, notifying + // those that are interested in this event + for (int i = listeners.length - 2; i >= 0; i -= 2) { + if (listeners[i] == FloatEditorListener.class) { + // Lazily create the event: + if (floatEditEvent == null) { + floatEditEvent = new FloatEditorEvent(this); + } + + ((FloatEditorListener) listeners[i + 1]).editingCanceled(floatEditEvent); + } + } + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/editor/BiasTextPainterCellEditor.java b/designer/src/com/fr/design/cell/editor/BiasTextPainterCellEditor.java new file mode 100644 index 000000000..9a6a3d095 --- /dev/null +++ b/designer/src/com/fr/design/cell/editor/BiasTextPainterCellEditor.java @@ -0,0 +1,201 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.cell.editor; + +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Window; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.ButtonGroup; + +import com.fr.design.gui.ibutton.UIRadioButton; +import com.fr.design.gui.ilable.UILabel; + +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.SwingUtilities; + +import com.fr.design.gui.itextarea.UITextArea; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.dialog.BasicPane; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.general.ComparatorUtils; +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.Grid; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.cell.painter.BiasTextPainter; +import com.fr.report.elementcase.TemplateElementCase; + +/** + * BiasTextPainter + */ +public class BiasTextPainterCellEditor extends AbstractCellEditor { + + private BiasTextPainterPane biasTextPainterPane = null; + + /** + * Constructor. + */ + public BiasTextPainterCellEditor(ElementCasePane ePane) { + super(ePane); + } + + /** + * Return the value of the CellEditor. + */ + @Override + public Object getCellEditorValue() throws Exception { + if (this.biasTextPainterPane == null) { + return null; + } + + return this.biasTextPainterPane.update(); + } + + /** + * Sets an initial cellElement for the editor. This will cause + * the editor to stopCellEditing and lose any partially + * edited value if the editor is editing when this method is called.

+ *

+ * Returns the component that should be added to the client's + * Component hierarchy. Once installed in the client's + * hierarchy this component will then be able to draw and receive + * user input. + * + * @param grid the Grid that is asking the + * editor to edit; can be null + * @param cellElement the value of the cell to be edited; it is + * up to the specific editor to interpret + * and draw the value. + */ + @Override + public Component getCellEditorComponent(Grid grid, TemplateCellElement cellElement, int resolution) { + Object value = null; + if (cellElement != null) { + value = cellElement.getValue(); + } + if (value == null || !(value instanceof BiasTextPainter)) { + value = new BiasTextPainter(""); + } + + BiasTextPainter biasTextPainter = (BiasTextPainter) value; + + Window parentWindow = SwingUtilities.getWindowAncestor(grid); + this.biasTextPainterPane = new BiasTextPainterPane(); + this.biasTextPainterPane.populate(biasTextPainter); + return this.biasTextPainterPane.showSmallWindow(parentWindow, new DialogActionAdapter() { + + @Override + public void doOk() { + BiasTextPainterCellEditor.this.fireEditingStopped(); + } + + @Override + public void doCancel() { + BiasTextPainterCellEditor.this.fireEditingCanceled(); + } + }); + } + + public static class BiasTextPainterPane extends BasicPane { + private UITextArea formulaTextArea; + private boolean isBackSlash; + private UIRadioButton choice1; + private UIRadioButton choice2; + + public BiasTextPainterPane() { + JPanel defaultPane = this; + + //center + JPanel centerPane =FRGUIPaneFactory.createBorderLayout_S_Pane(); + defaultPane.add(centerPane, BorderLayout.CENTER); + + //text + JPanel textPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + centerPane.setBorder(BorderFactory.createEmptyBorder(20, 0, 0, 0)); + centerPane.add(textPane, BorderLayout.CENTER); + + UILabel formulaLabel = new UILabel(Inter.getLocText(new String[] {"BiasD-Input_Slope_Line_text_separated_by_'|'", "Example"}, new String[] {" ", ": Season|Product"}) ); + textPane.add(formulaLabel, BorderLayout.NORTH); + formulaLabel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 0)); + + textPane.add(Box.createVerticalStrut(2), BorderLayout.SOUTH); + + formulaTextArea = new UITextArea(); + JScrollPane scrollPane = new JScrollPane(formulaTextArea); + // 去了scollPane的边框,否则会有两层边框,略丑 + scrollPane.setBorder(null); + textPane.add(scrollPane, BorderLayout.CENTER); + + + JPanel choicePane = FRGUIPaneFactory.createX_AXISBoxInnerContainer_S_Pane(); + + choice1 = new UIRadioButton((Inter.getLocText("BiasD-From-upper_left_to_lower_right"))); + choice2 = new UIRadioButton((Inter.getLocText("BiasD-From-lower_left_to_upper_right"))); + choice1.addActionListener(leftUp); + choice2.addActionListener(leftDown); + + final ButtonGroup group = new ButtonGroup(); + group.add(choice1); + group.add(choice2); + + choicePane.add(choice1); +// choicePane.add(new UILabel(" ")); + choicePane.add(choice2); + + centerPane.add(choicePane, BorderLayout.SOUTH); + } + + @Override + protected String title4PopupWindow() { + return Inter.getLocText("BiasD-Slope_Line"); + } + + public void populate(BiasTextPainter biasTextPainter) { + if (biasTextPainter == null) { + return; + } + + this.isBackSlash = biasTextPainter.isBackSlash(); + if (this.isBackSlash) { + this.choice2.setSelected(true); + } else { + this.choice1.setSelected(true); + } + this.formulaTextArea.setText(biasTextPainter.getText()); + } + + /** + * update + */ + public BiasTextPainter update() { + BiasTextPainter tmp = new BiasTextPainter(this.formulaTextArea.getText()); + tmp.setIsBackSlash(this.isBackSlash); + return tmp; + } + ActionListener leftUp = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + if (ComparatorUtils.equals(e.getSource(), BiasTextPainterPane.this.choice1)) { + BiasTextPainterPane.this.isBackSlash = false; + } + } + }; + ActionListener leftDown = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + if (ComparatorUtils.equals(e.getSource(), BiasTextPainterPane.this.choice2)) { + BiasTextPainterPane.this.isBackSlash = true; + } + } + }; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/editor/CellEditor.java b/designer/src/com/fr/design/cell/editor/CellEditor.java new file mode 100644 index 000000000..f95bfd4fa --- /dev/null +++ b/designer/src/com/fr/design/cell/editor/CellEditor.java @@ -0,0 +1,93 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.cell.editor; + +import java.awt.Component; +import java.awt.Point; + +import com.fr.grid.Grid; +import com.fr.grid.event.CellEditorListener; +import com.fr.report.cell.TemplateCellElement; + +/** + * CellEditor interface. + */ +public interface CellEditor { + /** + * Returns the value contained in the editor. + * + * @return the value contained in the editor + */ + public Object getCellEditorValue() throws Exception; + + /** + * Sets an initial cellElement for the editor. This will cause + * the editor to stopCellEditing and lose any partially + * edited value if the editor is editing when this method is called.

+ *

+ * Returns the component that should be added to the client's + * Component hierarchy. Once installed in the client's + * hierarchy this component will then be able to draw and receive + * user input. + * + * @param grid the Grid that is asking the + * editor to edit; can be null + * @param cellElement the value of the cell to be edited; it is + * up to the specific editor to interpret + * and draw the value. + * @param resolution the current screen resolution + */ + public Component getCellEditorComponent(Grid grid, TemplateCellElement cellElement, int resolution); + + /** + * Gets the location of this component in the form of a point + * specifying the component's top-left corner in the CellElement's + * coordinate space. The default value is (0, 0). + * @return an instance of Point representing + * the top-left corner of the component's bounds in the + * coordinate space of the CellElement + */ + public Point getLocationOnCellElement(); + + /** + * Sets the location of this component in the form of a point + * specifying the component's top-left corner in the CellElement's + * coordinate space. + * @param loc an instance of Point representing + * the top-left corner of the component's bounds in the + * coordinate space of the CellElement + */ + public void setLocationOnCellElement(Point loc); + + /** + * Tells the editor to stop editing and accept any partially edited + * value as the value of the editor. The editor returns false if + * editing was not stopped; this is useful for editors that validate + * and can not accept invalid entries. + * + * @return true if editing was stopped; false otherwise + */ + public boolean stopCellEditing(); + + /** + * Tells the editor to cancel editing and not accept any partially + * edited value. + */ + public void cancelCellEditing(); + + /** + * Adds a listener to the list that's notified when the editor + * stops, or cancels editing. + * + * @param cellEditorListener the CellEditorListener + */ + public void addCellEditorListener(CellEditorListener cellEditorListener); + + /** + * Removes a listener from the list that's notified + * + * @param cellEditorListener the CellEditorListener + */ + public void removeCellEditorListener(CellEditorListener cellEditorListener); +} \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/editor/ChartCellEditor.java b/designer/src/com/fr/design/cell/editor/ChartCellEditor.java new file mode 100644 index 000000000..a4e9304c1 --- /dev/null +++ b/designer/src/com/fr/design/cell/editor/ChartCellEditor.java @@ -0,0 +1,87 @@ +package com.fr.design.cell.editor; + +import java.awt.Component; + +import javax.swing.SwingUtilities; + +import com.fr.base.chart.BaseChartCollection; +import com.fr.design.gui.chart.MiddleChartComponent; +import com.fr.design.gui.chart.MiddleChartDialog; +import com.fr.design.module.DesignModuleFactory; +import com.fr.design.dialog.DialogActionListener; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.Grid; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.elementcase.TemplateElementCase; +import com.fr.stable.bridge.StableFactory; +import com.fr.stable.core.PropertyChangeAdapter; + +/** + * CellEditor used to edit Chart object. + */ +public class ChartCellEditor extends AbstractCellEditor implements DialogActionListener { + + public ChartCellEditor(ElementCasePane ePane) { + super(ePane); + } + + private MiddleChartDialog chartCellEditorDialog = null; + private MiddleChartComponent glyphComponent = null; + protected ElementCasePane ePane; + + + /** + * Return the value of the CellEditor + */ + @Override + public Object getCellEditorValue() throws Exception { + if (this.glyphComponent != null) { + MiddleChartComponent newComponent = this.glyphComponent; + return newComponent.update(); + } + + BaseChartCollection cc = this.chartCellEditorDialog.getChartCollection(); + // 判断条件以及返回值 + if (cc != null) { + return cc; + } else { + return ""; + } + } + + public Component getCellEditorComponent(final Grid grid, TemplateCellElement cellElement, int resolution) { + Object valueCell = cellElement.getValue(); + if (valueCell instanceof BaseChartCollection) { + if (glyphComponent == null) { + glyphComponent = DesignModuleFactory.getChartComponent((BaseChartCollection)valueCell); + glyphComponent.addStopEditingListener(new PropertyChangeAdapter() { + @Override + public void propertyChange() { + stopCellEditing(); + grid.requestFocus();// kunsnat: 补充, 编辑图表reset之后, Grid也算停止编辑 重获焦点 bug20443SS + } + }); + } else { + glyphComponent.populate((BaseChartCollection) valueCell); + } + this.chartCellEditorDialog = null; + return glyphComponent; + } + this.chartCellEditorDialog = DesignModuleFactory.getChartDialog(SwingUtilities.getWindowAncestor(grid)); + this.chartCellEditorDialog.addDialogActionListener(this); + BaseChartCollection cc = (BaseChartCollection)StableFactory.createXmlObject(BaseChartCollection.XML_TAG); + this.chartCellEditorDialog.populate(cc); + this.glyphComponent = null; + return this.chartCellEditorDialog; + } + + @Override + public void doOk() { + stopCellEditing(); + } + + @Override + public void doCancel() { + cancelCellEditing(); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/editor/ChartFloatEditor.java b/designer/src/com/fr/design/cell/editor/ChartFloatEditor.java new file mode 100644 index 000000000..22bb494c7 --- /dev/null +++ b/designer/src/com/fr/design/cell/editor/ChartFloatEditor.java @@ -0,0 +1,85 @@ +package com.fr.design.cell.editor; + +import java.awt.Component; + +import javax.swing.SwingUtilities; + +import com.fr.base.chart.BaseChartCollection; +import com.fr.design.gui.chart.MiddleChartComponent; +import com.fr.design.gui.chart.MiddleChartDialog; +import com.fr.design.module.DesignModuleFactory; +import com.fr.design.dialog.DialogActionListener; +import com.fr.grid.Grid; +import com.fr.report.cell.FloatElement; +import com.fr.stable.StringUtils; +import com.fr.stable.bridge.StableFactory; +import com.fr.stable.core.PropertyChangeAdapter; + +public class ChartFloatEditor extends AbstractFloatEditor implements DialogActionListener { + + private MiddleChartDialog chartFloatEditorDialog = null; + private MiddleChartComponent glyphComponent = null; + + /** + * Constructor + */ + public ChartFloatEditor() { + } + + /** + * Return the value of the FloatEditor + */ + @Override + public Object getFloatEditorValue() throws Exception { + if (this.glyphComponent != null) { + MiddleChartComponent newComponent = this.glyphComponent; + return newComponent.update(); + } + + BaseChartCollection cc = this.chartFloatEditorDialog.getChartCollection(); + // 判断条件以及返回值 + if (cc != null) { + return cc; + } else { + return StringUtils.EMPTY; + } + } + + @Override + public Component getFloatEditorComponent(final Grid grid, FloatElement floatElement, int resolution) { + Object valueCell = floatElement.getValue(); + if (valueCell instanceof BaseChartCollection) { + this.chartFloatEditorDialog = null; + if (glyphComponent == null) { + glyphComponent = DesignModuleFactory.getChartComponent((BaseChartCollection)valueCell); + glyphComponent.addStopEditingListener(new PropertyChangeAdapter() { + @Override + public void propertyChange() { + stopFloatEditing(); + grid.requestFocus();// kunsnat: 补充, 编辑图表reset之后, Grid也算停止编辑 重获焦点 bug20443 + } + }); + + } else { + glyphComponent.populate((BaseChartCollection) valueCell); + } + return glyphComponent; + } + this.chartFloatEditorDialog = DesignModuleFactory.getChartDialog(SwingUtilities.getWindowAncestor(grid)); + this.chartFloatEditorDialog.addDialogActionListener(this); + BaseChartCollection cc = (BaseChartCollection)StableFactory.createXmlObject(BaseChartCollection.XML_TAG); + this.chartFloatEditorDialog.populate(cc); + this.glyphComponent = null; + return this.chartFloatEditorDialog; + } + + @Override + public void doOk() { + stopFloatEditing(); + } + + @Override + public void doCancel() { + cancelFloatEditing(); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/editor/ComboBoxCellEditor.java b/designer/src/com/fr/design/cell/editor/ComboBoxCellEditor.java new file mode 100644 index 000000000..97b8f2b57 --- /dev/null +++ b/designer/src/com/fr/design/cell/editor/ComboBoxCellEditor.java @@ -0,0 +1,62 @@ +package com.fr.design.cell.editor; + +import java.awt.Component; + +import com.fr.base.Utils; +import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.Grid; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.elementcase.TemplateElementCase; +import com.fr.stable.StringUtils; + +/** + * ComboBox CellEditor + */ +public class ComboBoxCellEditor extends AbstractCellEditor { + private UIComboBox comboBox; //text field. + + /** + * Constructor. + */ + public ComboBoxCellEditor(ElementCasePane ePane, Object[] keyValuePairs) { + super(ePane); + comboBox = new UIComboBox(keyValuePairs); + this.comboBox.setFocusTraversalKeysEnabled(false); + } + + /** + * Return the value of the CellEditor. + */ + public Object getCellEditorValue() throws Exception { + return this.comboBox.getSelectedItem(); + } + + /** + * Sets an initial cellElement for the editor. This will cause + * the editor to stopCellEditing and lose any partially + * edited value if the editor is editing when this method is called.

+ *

+ * Returns the component that should be added to the client's + * Component hierarchy. Once installed in the client's + * hierarchy this component will then be able to draw and receive + * user input. + * + * @param grid the Grid that is asking the + * editor to edit; can be null + * @param cellElement the value of the cell to be edited; it is + * up to the specific editor to interpret + * and draw the value. + */ + public Component getCellEditorComponent(Grid grid, TemplateCellElement cellElement, int resolution) { + Object value = null; + if(cellElement != null) { + value = cellElement.getValue(); + } + if (value == null) { + value = StringUtils.EMPTY; + } + this.comboBox.setSelectedItem(Utils.objectToString(value)); + return this.comboBox; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/editor/DSColumnCellEditor.java b/designer/src/com/fr/design/cell/editor/DSColumnCellEditor.java new file mode 100644 index 000000000..01989e295 --- /dev/null +++ b/designer/src/com/fr/design/cell/editor/DSColumnCellEditor.java @@ -0,0 +1,92 @@ +package com.fr.design.cell.editor; + +import java.awt.Component; + +import javax.swing.JOptionPane; +import javax.swing.SwingUtilities; + +import com.fr.base.FRContext; +import com.fr.design.data.DesignTableDataManager; +import com.fr.design.dscolumn.DSColumnPane; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionListener; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.Grid; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.core.SheetUtils; +import com.fr.report.elementcase.TemplateElementCase; +import com.fr.report.poly.PolyECBlock; +import com.fr.report.worksheet.WorkSheet; +import com.fr.stable.ProductConstants; + +/** + * CellEditor used to edit BindValuePainter object. + */ +public class DSColumnCellEditor extends AbstractCellEditor implements DialogActionListener { + + public DSColumnCellEditor(ElementCasePane ePane) { + super(ePane); + } + + private DSColumnPane dsColumnPane = null; + + /** + * Return the value of the CellEditor. + */ + @Override + public Object getCellEditorValue() throws Exception { + return this.dsColumnPane.update(); + } + + /** + * Sets an initial cellElement for the editor. This will + * cause the editor to stopCellEditing and lose any partially + * edited value if the editor is editing when this method is called. + *

+ *

Returns the component that should be added to the client's + * Component hierarchy. Once installed in the client's + * hierarchy this component will then be able to draw and receive user + * input. + * + * @param grid the Grid that is asking the editor to edit; can + * be null + * @param cellElement the value of the cell to be edited; it is up to the specific + * editor to interpret and draw the value. + */ + @Override + public Component getCellEditorComponent(Grid grid, TemplateCellElement cellElement, int resolution) { + TemplateElementCase tplEC = grid.getElementCasePane().getEditingElementCase(); + + //alex:如果是线性报表,这时还要计算一下默认父格是什么 + if (tplEC != null && (tplEC instanceof WorkSheet || tplEC instanceof PolyECBlock)) { + SheetUtils.calculateDefaultParent(tplEC); + } + + this.dsColumnPane = new DSColumnPane(); + dsColumnPane.putElementcase(grid.getElementCasePane()); + dsColumnPane.putCellElement(cellElement); + BasicDialog dsColumnDialog = this.dsColumnPane.showWindow(SwingUtilities.getWindowAncestor(grid)); + + dsColumnDialog.addDialogActionListener(this); + + try { + this.dsColumnPane.populate(DesignTableDataManager.getEditingTableDataSource(), cellElement); + } catch (Exception exp) { + JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(grid), exp.getMessage(), + ProductConstants.APP_NAME, JOptionPane.ERROR_MESSAGE); + FRContext.getLogger().error(exp.getMessage(), exp); + } + + return dsColumnDialog; + } + + @Override + public void doOk() { + fireEditingStopped(); + } + + @Override + public void doCancel() { + fireEditingCanceled(); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/editor/DateCellEditor.java b/designer/src/com/fr/design/cell/editor/DateCellEditor.java new file mode 100644 index 000000000..abb90f7e9 --- /dev/null +++ b/designer/src/com/fr/design/cell/editor/DateCellEditor.java @@ -0,0 +1,62 @@ +package com.fr.design.cell.editor; + +import java.awt.Component; +import java.util.Date; + +import com.fr.design.gui.date.UIDatePicker; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.Grid; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.elementcase.TemplateElementCase; + +/** + * Date CellEditor + */ +public class DateCellEditor extends AbstractCellEditor { + private UIDatePicker comboBox; //text field. + + /** + * Constructor. + */ + public DateCellEditor(ElementCasePane ePane) { + super(ePane); + comboBox = new UIDatePicker(); + this.comboBox.setFocusTraversalKeysEnabled(false); + } + + /** + * Return the value of the CellEditor. + */ + public Object getCellEditorValue() throws Exception { + return this.comboBox.getSelectedDate(); + } + + /** + * Sets an initial cellElement for the editor. This will cause + * the editor to stopCellEditing and lose any partially + * edited value if the editor is editing when this method is called.

+ *

+ * Returns the component that should be added to the client's + * Component hierarchy. Once installed in the client's + * hierarchy this component will then be able to draw and receive + * user input. + * + * @param grid the Grid that is asking the + * editor to edit; can be null + * @param cellElement the value of the cell to be edited; it is + * up to the specific editor to interpret + * and draw the value. + */ + public Component getCellEditorComponent(Grid grid, TemplateCellElement cellElement, int resolution) { + Object value = null; + if(cellElement != null) { + value = cellElement.getValue(); + } + if (value == null || !(value instanceof Date)) { + value = new Date(); + } + + this.comboBox.setSelectedItem(value); + return this.comboBox; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/editor/FloatEditor.java b/designer/src/com/fr/design/cell/editor/FloatEditor.java new file mode 100644 index 000000000..32b33008b --- /dev/null +++ b/designer/src/com/fr/design/cell/editor/FloatEditor.java @@ -0,0 +1,77 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.cell.editor; + +import java.awt.Component; +import java.awt.event.KeyEvent; + +import com.fr.grid.Grid; +import com.fr.grid.event.FloatEditorListener; +import com.fr.report.cell.FloatElement; + +/** + * FloatEditor interface to edit FloatElement. + */ +public interface FloatEditor { + /** + * Returns the value contained in the editor. + * + * @return the value contained in the editor + */ + public Object getFloatEditorValue() throws Exception; + + /** + * Sets an initial floatElement for the editor. This will cause + * the editor to stopFloatEditing and lose any partially + * edited value if the editor is editing when this method is called.

+ *

+ * Returns the component that should be added to the client's + * Component hierarchy. Once installed in the client's + * hierarchy this component will then be able to draw and receive + * user input. + * + * @param grid the Grid that is asking the + * editor to edit; can be null + * @param floatElement the value of the FloatElement to be edited; it is + * up to the specific editor to interpret + * and draw the value. + */ + public Component getFloatEditorComponent(Grid grid, FloatElement floatElement, int resolution); + + /** + * Accept keyevent to start editing. + */ + public boolean acceptKeyEventToStartFloatEditing(KeyEvent evt); + + /** + * Tells the editor to stop editing and accept any partially edited + * value as the value of the editor. The editor returns false if + * editing was not stopped; this is useful for editors that validate + * and can not accept invalid entries. + * + * @return true if editing was stopped; false otherwise + */ + public boolean stopFloatEditing(); + + /** + * Tells the editor to cancel editing and not accept any partially + * edited value. + */ + public void cancelFloatEditing(); + + /** + * Adds a listener to the list that's notified when the editor + * stops, or cancels editing. + * + * @param floatEditorListener the FloatEditorListener + */ + public void addFloatEditorListener(FloatEditorListener floatEditorListener); + + /** + * Removes a listener from the list that's notified + * + * @param floatEditorListener the FloatEditorListener + */ + public void removeFloatEditorListener(FloatEditorListener floatEditorListener); +} \ 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 new file mode 100644 index 000000000..e69742ea9 --- /dev/null +++ b/designer/src/com/fr/design/cell/editor/FormulaCellEditor.java @@ -0,0 +1,87 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.cell.editor; + +import com.fr.base.Formula; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.formula.FormulaFactory; +import com.fr.design.formula.UIFormula; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.Grid; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.elementcase.TemplateElementCase; + +import javax.swing.*; +import java.awt.*; + +/** + * CellEditor used to edit Formula object. + */ +public class FormulaCellEditor extends com.fr.design.cell.editor.AbstractCellEditor { + + private UIFormula formulaEditorPane = null; + + /** + * Constructor. + */ + public FormulaCellEditor(ElementCasePane ePane) { + super(ePane); + } + + /** + * Return the value of the CellEditor. + */ + @Override + public Object getCellEditorValue() throws Exception { + Formula newFormula = this.formulaEditorPane.update(); + if (newFormula.getContent() != null && newFormula.getContent().trim().length() > 1) { + return newFormula; + } else { + return ""; + } + } + + /** + * Sets an initial cellElement for the editor. This will cause + * the editor to stopCellEditing and lose any partially + * edited value if the editor is editing when this method is called.

+ *

+ * Returns the component that should be added to the client's + * Component hierarchy. Once installed in the client's + * hierarchy this component will then be able to draw and receive + * user input. + * + * @param grid the Grid that is asking the + * editor to edit; can be null + * @param cellElement the value of the cell to be edited; it is + * up to the specific editor to interpret + * and draw the value. + */ + @Override + public Component getCellEditorComponent(Grid grid, TemplateCellElement cellElement, int resolution) { + Object value = null; + if (cellElement != null) { + value = cellElement.getValue(); + } + if (value == null || !(value instanceof Formula)) { + value = new Formula(""); + } + + this.formulaEditorPane = FormulaFactory.createFormulaPaneWhenReserveFormula(); + + this.formulaEditorPane.populate((Formula) value); + return this.formulaEditorPane.showLargeWindow(SwingUtilities.getWindowAncestor(grid), new DialogActionAdapter() { + + @Override + public void doOk() { + FormulaCellEditor.this.stopCellEditing(); + } + + @Override + public void doCancel() { + FormulaCellEditor.this.cancelCellEditing(); + } + }); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/editor/FormulaFloatEditor.java b/designer/src/com/fr/design/cell/editor/FormulaFloatEditor.java new file mode 100644 index 000000000..046b3ebe3 --- /dev/null +++ b/designer/src/com/fr/design/cell/editor/FormulaFloatEditor.java @@ -0,0 +1,82 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.cell.editor; + +import com.fr.base.Formula; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.formula.FormulaFactory; +import com.fr.design.formula.UIFormula; +import com.fr.grid.Grid; +import com.fr.report.cell.FloatElement; + +import javax.swing.*; +import java.awt.*; + +/** + * FloatEditor used to edit Formula object. + */ +public class FormulaFloatEditor extends AbstractFloatEditor { + + private UIFormula formulaEditorPane = null; + + /** + * Constructor. + */ + public FormulaFloatEditor() { + } + + /** + * Return the value of the FloatEditor. + */ + @Override + public Object getFloatEditorValue() throws Exception { + Formula newFormula = this.formulaEditorPane.update(); + if (newFormula.getContent() != null && newFormula.getContent().trim().length() > 1) { + return newFormula; + } else { + return ""; + } + } + + /** + * Sets an initial floatElement for the editor. This will cause + * the editor to stopFloatEditing and lose any partially + * edited value if the editor is editing when this method is called.

+ *

+ * Returns the component that should be added to the client's + * Component hierarchy. Once installed in the client's + * hierarchy this component will then be able to draw and receive + * user input. + * + * @param grid the Grid that is asking the + * editor to edit; can be null + * @param floatElement the value of the float to be edited; it is + * up to the specific editor to interpret + * and draw the value. + */ + @Override + 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(""); + } + + this.formulaEditorPane = FormulaFactory.createFormulaPane(); + this.formulaEditorPane.populate((Formula) value); + + return this.formulaEditorPane.showLargeWindow(SwingUtilities.getWindowAncestor(grid), new DialogActionAdapter() { + + @Override + public void doOk() { + FormulaFloatEditor.this.stopFloatEditing(); + } + + @Override + public void doCancel() { + FormulaFloatEditor.this.cancelFloatEditing(); + } + }); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/editor/GeneralCellEditor.java b/designer/src/com/fr/design/cell/editor/GeneralCellEditor.java new file mode 100644 index 000000000..85241c3e6 --- /dev/null +++ b/designer/src/com/fr/design/cell/editor/GeneralCellEditor.java @@ -0,0 +1,61 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.cell.editor; + +import java.awt.Component; + +import com.fr.base.Style; +import com.fr.base.TextFormat; +import com.fr.grid.Grid; +import com.fr.report.ReportHelper; +import com.fr.report.cell.CellElement; +import com.fr.report.cell.TemplateCellElement; + +/** + * CellEditor used to edit general object. + */ +public class GeneralCellEditor extends TextCellEditor { + + private CellElement cellElement; + /** + * Gets the value of the CellEditor. + */ + @Override + public Object getCellEditorValue() throws Exception { + Object textValue = super.getCellEditorValue(); + + //如果格式是TextFormat,就返回普通文本. + //TODO, peter 这个地方需要重新设计,我感觉下面的 convertGeneralStringAccordingToExcel,可以用Foramt来实现。 + //peter:只读方式获得Style. + Style style = cellElement.getStyle(); + if(style != null && style.getFormat() instanceof TextFormat) { + return textValue; + } + + return ReportHelper.convertGeneralStringAccordingToExcel(textValue); + } + + /** + * Sets an initial cellElement for the editor. This will cause + * the editor to stopCellEditing and lose any partially + * edited value if the editor is editing when this method is called.

+ *

+ * Returns the component that should be added to the client's + * Component hierarchy. Once installed in the client's + * hierarchy this component will then be able to draw and receive + * user input. + * + * @param grid the Grid that is asking the + * editor to edit; can be null + * @param cellElement the value of the cell to be edited; it is + * up to the specific editor to interpret + * and draw the value. + */ + @Override + public Component getCellEditorComponent(Grid grid, TemplateCellElement cellElement, int resolution) { + this.cellElement = cellElement; + + return super.getCellEditorComponent(grid, cellElement, resolution); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/editor/GeneralFloatEditor.java b/designer/src/com/fr/design/cell/editor/GeneralFloatEditor.java new file mode 100644 index 000000000..ec297d403 --- /dev/null +++ b/designer/src/com/fr/design/cell/editor/GeneralFloatEditor.java @@ -0,0 +1,34 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.cell.editor; + +import com.fr.base.Style; +import com.fr.base.TextFormat; +import com.fr.report.ReportHelper; +import com.fr.report.cell.FloatElement; + +/** + * FloatEditor used to edit general object. + */ +public class GeneralFloatEditor extends TextFloatEditor { + /** + * Gets the value of the FloatEditor. + */ + @Override + public Object getFloatEditorValue() throws Exception { + Object textValue = super.getFloatEditorValue(); + + //如果格式是TextFormat,就返回普通文本. + //TODO, peter 这个地方需要重新设计,我感觉下面的 convertGeneralStringAccordingToExcel,可以用Foramt来实现。 + FloatElement floatElement = this.getFloatElement(); + //peter:只读方式获得Style. + Style style = floatElement.getStyle(); + if(style != null && + style.getFormat() != null && style.getFormat() == TextFormat.getInstance()) { + return textValue; + } + + return ReportHelper.convertGeneralStringAccordingToExcel(textValue); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/editor/ImageCellEditor.java b/designer/src/com/fr/design/cell/editor/ImageCellEditor.java new file mode 100644 index 000000000..d30bc0899 --- /dev/null +++ b/designer/src/com/fr/design/cell/editor/ImageCellEditor.java @@ -0,0 +1,83 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.cell.editor; + +import java.awt.Component; +import java.awt.Image; + +import javax.swing.SwingUtilities; + +import com.fr.design.report.SelectImagePane; +import com.fr.design.dialog.DialogActionListener; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.Grid; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.elementcase.TemplateElementCase; + +/** + * CellEditor used to edit Image object. + */ +public class ImageCellEditor extends AbstractCellEditor implements DialogActionListener { + + private SelectImagePane imageEditorPane = null; + + /** + * Constructor. + */ + public ImageCellEditor(ElementCasePane ePane) { + super(ePane); + } + + /** + * Return the value of the CellEditor. + */ + @Override + public Object getCellEditorValue() throws Exception { + return this.imageEditorPane.update(); + } + + /** + * Sets an initial cellElement for the editor. This will cause + * the editor to stopCellEditing and lose any partially + * edited value if the editor is editing when this method is called.

+ *

+ * Returns the component that should be added to the client's + * Component hierarchy. Once installed in the client's + * hierarchy this component will then be able to draw and receive + * user input. + * + * @param grid the Grid that is asking the + * editor to edit; can be null + * @param cellElement the value of the cell to be edited; it is + * up to the specific editor to interpret + * and draw the value. + */ + @Override + public Component getCellEditorComponent(Grid grid, TemplateCellElement cellElement, int resolution) { + Object value = null; + if (cellElement != null) { + value = cellElement.getValue(); + } + if (value == null || !(value instanceof Image)) { + value = null; + } + + this.imageEditorPane = new SelectImagePane(); + this.imageEditorPane.populate(cellElement); + + return this.imageEditorPane.showWindow(SwingUtilities.getWindowAncestor(grid), this); + } + + @Override + public void doOk() { + stopCellEditing(); + + } + + @Override + public void doCancel() { + cancelCellEditing(); + + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/editor/ImageFloatEditor.java b/designer/src/com/fr/design/cell/editor/ImageFloatEditor.java new file mode 100644 index 000000000..c5864f9ff --- /dev/null +++ b/designer/src/com/fr/design/cell/editor/ImageFloatEditor.java @@ -0,0 +1,78 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.cell.editor; + +import java.awt.Component; +import java.awt.Image; + +import javax.swing.SwingUtilities; + +import com.fr.design.report.SelectImagePane; +import com.fr.design.dialog.DialogActionListener; +import com.fr.grid.Grid; +import com.fr.report.cell.FloatElement; + +/** + * FloatEditor used to edit Image object. + */ +public class ImageFloatEditor extends AbstractFloatEditor implements DialogActionListener{ + + private SelectImagePane imageEditorPane = null; + + /** + * Constructor. + */ + public ImageFloatEditor() { + } + + /** + * Return the value of the FloatEditor. + */ + @Override + public Object getFloatEditorValue() throws Exception { + return this.imageEditorPane.update(); + } + + /** + * Sets an initial floatElement for the editor. This will cause + * the editor to stopFloatEditing and lose any partially + * edited value if the editor is editing when this method is called.

+ *

+ * Returns the component that should be added to the client's + * Component hierarchy. Once installed in the client's + * hierarchy this component will then be able to draw and receive + * user input. + * + * @param grid the Grid that is asking the + * editor to edit; can be null + * @param floatElement the value of the float to be edited; it is + * up to the specific editor to interpret + * and draw the value. + */ + @Override + public Component getFloatEditorComponent(Grid grid, FloatElement floatElement, int resolution) { + //populate data to UI + Object value = floatElement.getValue(); + if (value == null || !(value instanceof Image)) { + value = null; + } + + this.imageEditorPane = new SelectImagePane(); + this.imageEditorPane.populate(floatElement); + + return this.imageEditorPane.showWindow(SwingUtilities.getWindowAncestor(grid), this); + } + + @Override + public void doOk() { + stopFloatEditing(); + + } + + @Override + public void doCancel() { + cancelFloatEditing(); + + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/editor/RichTextCellEditor.java b/designer/src/com/fr/design/cell/editor/RichTextCellEditor.java new file mode 100644 index 000000000..6b9b90ace --- /dev/null +++ b/designer/src/com/fr/design/cell/editor/RichTextCellEditor.java @@ -0,0 +1,102 @@ +package com.fr.design.cell.editor; + +import java.awt.Component; + +import javax.swing.SwingUtilities; + +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.dialog.DialogActionListener; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.report.RichTextPane; +import com.fr.grid.Grid; +import com.fr.report.cell.CellElement; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.cell.cellattr.CellGUIAttr; +import com.fr.report.core.SheetUtils; +import com.fr.report.elementcase.TemplateElementCase; +import com.fr.report.poly.PolyECBlock; +import com.fr.report.worksheet.WorkSheet; + +public class RichTextCellEditor extends AbstractCellEditor implements + DialogActionListener { + + public RichTextCellEditor( + ElementCasePane ePane) { + super(ePane); + } + + private RichTextPane richTextPane; + + @Override + public Component getCellEditorComponent(Grid grid, + TemplateCellElement cellElement, int resolution) { + TemplateElementCase parentTplEC = grid.getElementCasePane().getEditingElementCase(); + calculateParent(parentTplEC); + this.richTextPane = new RichTextPane(); + + BasicDialog richTextDialog = this.richTextPane.showMediumWindow( + SwingUtilities.getWindowAncestor(grid), + new DialogActionAdapter() { + + @Override + public void doOk() { + RichTextCellEditor.this.fireEditingStopped(); + } + + @Override + public void doCancel() { + RichTextCellEditor.this.fireEditingCanceled(); + } + }); + richTextDialog.addDialogActionListener(this); + this.richTextPane.populate(parentTplEC, cellElement); + + setShowAsHtml(cellElement); + return richTextDialog; + } + + private void setShowAsHtml(CellElement cellElement){ + CellGUIAttr guiAttr = cellElement.getCellGUIAttr(); + if(guiAttr == null){ + guiAttr = new CellGUIAttr(); + cellElement.setCellGUIAttr(guiAttr); + } + + guiAttr.setShowAsHTML(true); + } + + private void calculateParent(TemplateElementCase parentTplEC){ + if (parentTplEC != null + && (parentTplEC instanceof WorkSheet || parentTplEC instanceof PolyECBlock)) { + SheetUtils.calculateDefaultParent(parentTplEC); + } + } + + @Override + public Object getCellEditorValue() throws Exception { + return this.richTextPane.update(); + } + + /** + * 确定 + * + * + * @date 2014-12-7-下午10:39:13 + * + */ + public void doOk() { + this.fireEditingStopped(); + } + + /** + * 取消 + * + * + * @date 2014-12-7-下午10:39:01 + * + */ + public void doCancel() { + this.fireEditingCanceled(); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/editor/RichTextToolBar.java b/designer/src/com/fr/design/cell/editor/RichTextToolBar.java new file mode 100644 index 000000000..8d7708c9c --- /dev/null +++ b/designer/src/com/fr/design/cell/editor/RichTextToolBar.java @@ -0,0 +1,639 @@ +/** + * + */ +package com.fr.design.cell.editor; + +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; +import com.fr.design.formula.FormulaFactory; +import com.fr.design.formula.UIFormula; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.ibutton.UIToggleButton; +import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.gui.style.FRFontPane; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.report.RichTextEditingPane; +import com.fr.design.report.RichTextPane; +import com.fr.design.style.color.UIToolbarColorButton; +import com.fr.general.FRFont; +import com.fr.general.Inter; +import com.fr.report.cell.cellattr.core.RichTextConverter; +import com.fr.stable.Constants; +import com.fr.stable.StableUtils; +import com.fr.stable.StringUtils; + +import javax.swing.*; +import javax.swing.event.*; +import javax.swing.text.*; +import java.awt.*; +import java.awt.event.*; +import java.math.BigDecimal; + +/** + * + * + * @date: 2014-12-5-下午1:10:31 + */ +public class RichTextToolBar extends BasicPane{ + + private static final Dimension BUTTON_SIZE = new Dimension(24, 20); + + private UIComboBox fontNameComboBox; + private UIComboBox fontSizeComboBox; + private UIToggleButton bold; + private UIToggleButton italic; + private UIToggleButton underline; + + private UIToolbarColorButton colorSelectPane; + private UIToggleButton superPane; + private UIToggleButton subPane; + private UIToggleButton formulaPane; + + //外部传进来的 + private RichTextEditingPane textPane; + + public RichTextToolBar() { + this.initComponents(); + } + + public RichTextToolBar(RichTextEditingPane textPane) { + this.textPane = textPane; + + this.initComponents(); + } + + @Override + protected String title4PopupWindow() { + return Inter.getLocText("FR-Designer_font"); + } + + protected void initComponents() { + //初始化并设置所有按钮样式 + initAllButton(); + //添加到工具栏 + addToToolBar(); + } + + private void initAllButton(){ + fontNameComboBox = new UIComboBox(Utils.getAvailableFontFamilyNames4Report()); + fontNameComboBox.setPreferredSize(new Dimension(144, 20)); + fontSizeComboBox = new UIComboBox(FRFontPane.FONT_SIZES); + colorSelectPane = new UIToolbarColorButton(BaseUtils.readIcon("/com/fr/design/images/gui/color/foreground.png")); + colorSelectPane.set4Toolbar(); + + bold = new UIToggleButton(BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/bold.png")); + italic = new UIToggleButton(BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/italic.png")); + underline = new UIToggleButton(BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/underline.png")); + superPane = new UIToggleButton(BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/sup.png")); + subPane = new UIToggleButton(BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/sub.png")); + formulaPane = new UIToggleButton(BaseUtils.readIcon("/com/fr/design/images/m_insert/formula.png")); + + //名字 + initAllNames(); + //悬浮提示 + setToolTips(); + //样式 + setAllButtonStyle(); + //绑定监听器 + bindListener(); + } + + private void setAllButtonStyle(){ + setButtonStyle(bold); + setButtonStyle(italic); + setButtonStyle(underline); + setButtonStyle(subPane); + setButtonStyle(superPane); + setButtonStyle(formulaPane); + } + + private void setButtonStyle(UIButton button){ + button.setNormalPainted(false); + button.setBackground(null); + button.setOpaque(false); + button.setPreferredSize(BUTTON_SIZE); + button.setBorderPaintedOnlyWhenPressed(true); + } + + private void addToToolBar(){ + this.setLayout(new FlowLayout(FlowLayout.LEFT)); + + this.add(fontNameComboBox); + this.add(fontSizeComboBox); + this.add(bold); + this.add(italic); + this.add(underline); + this.add(colorSelectPane); + this.add(superPane); + this.add(subPane); + this.add(formulaPane); + } + + private void bindListener(){ + FRFont defaultFont = RichTextPane.DEFAUL_FONT; + fontNameComboBox.addItemListener(fontNameItemListener); + fontNameComboBox.setSelectedItem(defaultFont.getFontName()); + fontSizeComboBox.addItemListener(fontSizeItemListener); + fontSizeComboBox.setSelectedItem(scaleDown(defaultFont.getSize())); + + bold.addActionListener(blodChangeAction); + italic.addActionListener(itaChangeAction); + underline.addActionListener(underlineChangeAction); + subPane.addActionListener(subChangeAction); + superPane.addActionListener(superChangeAction); + colorSelectPane.addColorChangeListener(colorChangeAction); + formulaPane.addActionListener(formulaActionListener); + + //选中文字的监听器 + textPane.addCaretListener(textCareListener); + textPane.addMouseListener(setMouseCurrentStyle); + textPane.getDocument().addDocumentListener(inputListener); + } + + private void initAllNames() { + fontNameComboBox.setGlobalName(Inter.getLocText("FR-Designer_Font-Family")); + fontSizeComboBox.setGlobalName(Inter.getLocText("FR-Designer_Font-Size")); + italic.setGlobalName(Inter.getLocText("FR-Designer_italic")); + bold.setGlobalName(Inter.getLocText("FR-Designer_bold")); + underline.setGlobalName(Inter.getLocText("FR-Designer_Underline")); + superPane.setGlobalName(Inter.getLocText("FR-Designer_Superscript")); + subPane.setGlobalName(Inter.getLocText("FR-Designer_Subscript")); + } + + private void setToolTips() { + colorSelectPane.setToolTipText(Inter.getLocText("FR-Designer_Foreground")); + italic.setToolTipText(Inter.getLocText("FR-Designer_italic")); + bold.setToolTipText(Inter.getLocText("FR-Designer_bold")); + underline.setToolTipText(Inter.getLocText("FR-Designer_Underline")); + superPane.setToolTipText(Inter.getLocText("FR-Designer_Superscript")); + subPane.setToolTipText(Inter.getLocText("FR-Designer_Subscript")); + formulaPane.setToolTipText(Inter.getLocText("FR-Designer_Formula")); + } + + /** + * 移除输入监听 + * 用于populate时, 插入字符串, 那时不需要插入监听 + * + * + * @date 2015-1-5-下午5:13:04 + * + */ + public void removeInputListener(){ + this.textPane.getDocument().removeDocumentListener(inputListener); + } + + /** + * 增加输入监听事件 + * + * + * @date 2015-1-5-下午5:13:26 + * + */ + public void addInputListener(){ + this.textPane.getDocument().addDocumentListener(inputListener); + } + + private ActionListener blodChangeAction = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + boolean isBold = RichTextToolBar.this.bold.isSelected(); + // 调用setCharacterAttributes函数设置文本区选择文本的字体 + MutableAttributeSet attr = new SimpleAttributeSet(); + StyleConstants.setBold(attr, !isBold); + setCharacterAttributes(RichTextToolBar.this.textPane, attr, false); + } + }; + + private ActionListener itaChangeAction = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + boolean isIta = RichTextToolBar.this.italic.isSelected(); + // 调用setCharacterAttributes函数设置文本区选择文本的字体 + MutableAttributeSet attr = new SimpleAttributeSet(); + StyleConstants.setItalic(attr, !isIta); + setCharacterAttributes(RichTextToolBar.this.textPane, attr, false); + } + }; + + private ActionListener underlineChangeAction = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + boolean isUnder = RichTextToolBar.this.underline.isSelected(); + // 调用setCharacterAttributes函数设置文本区选择文本的字体 + MutableAttributeSet attr = new SimpleAttributeSet(); + StyleConstants.setUnderline(attr, !isUnder); + setCharacterAttributes(RichTextToolBar.this.textPane, attr, false); + } + }; + private ActionListener subChangeAction = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + boolean isSub = RichTextToolBar.this.subPane.isSelected(); + // 调用setCharacterAttributes函数设置文本区选择文本的字体 + MutableAttributeSet attr = new SimpleAttributeSet(); + StyleConstants.setSubscript(attr, !isSub); + setCharacterAttributes(RichTextToolBar.this.textPane, attr, false); + } + }; + private ActionListener superChangeAction = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + boolean isSuper = RichTextToolBar.this.superPane.isSelected(); + // 调用setCharacterAttributes函数设置文本区选择文本的字体 + MutableAttributeSet attr = new SimpleAttributeSet(); + StyleConstants.setSuperscript(attr, !isSuper); + setCharacterAttributes(RichTextToolBar.this.textPane, attr, false); + } + }; + + private ChangeListener colorChangeAction = new ChangeListener() { + @Override + public void stateChanged(ChangeEvent e) { + Color color = RichTextToolBar.this.colorSelectPane.getColor(); + color = color == null ? Color.BLACK : color; + // 调用setCharacterAttributes函数设置文本区选择文本的字体 + MutableAttributeSet attr = new SimpleAttributeSet(); + StyleConstants.setForeground(attr, color); + setCharacterAttributes(RichTextToolBar.this.textPane, attr, false); + } + }; + + // 设置文本区选择文本的样式 + private void setCharacterAttributes(JEditorPane editor, AttributeSet attr, + boolean replace) { + //注意不要失焦 + textPane.requestFocus(); + + // 取得选择文本的起始位置和结束位置 + int start = editor.getSelectionStart(); + int end = editor.getSelectionEnd(); + + // 如果选中文本,设置选中文本的样式 + if (start != end) { + StyledDocument doc = (StyledDocument) textPane.getDocument(); + // 将所选文本设置为新的样式,replace为false表示不覆盖原有的样式 + doc.setCharacterAttributes(start, end - start, attr, replace); + } + } + + private ItemListener fontSizeItemListener = new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + int fontSize = (Integer) RichTextToolBar.this.fontSizeComboBox.getSelectedItem(); + fontSize = scaleUp(fontSize); + // 调用setCharacterAttributes函数设置文本区选择文本的字体 + MutableAttributeSet attr = new SimpleAttributeSet(); + StyleConstants.setFontSize(attr, fontSize); + setCharacterAttributes(RichTextToolBar.this.textPane, attr, false); + } + }; + + private ItemListener fontNameItemListener = new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + String fontName = (String) RichTextToolBar.this.fontNameComboBox.getSelectedItem(); + // 调用setCharacterAttributes函数设置文本区选择文本的字体 + MutableAttributeSet attr = new SimpleAttributeSet(); + StyleConstants.setFontFamily(attr, fontName); + setCharacterAttributes(RichTextToolBar.this.textPane, attr, false); + } + }; + + private ActionListener formulaActionListener = new ActionListener() { + public void actionPerformed(ActionEvent evt) { + final UIFormula formulaPane = FormulaFactory.createFormulaPane(); + formulaPane.populate(new Formula()); + formulaPane.showLargeWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { + @Override + public void doOk() { + StyledDocument doc = (StyledDocument) textPane.getDocument(); + Formula fm = formulaPane.update(); + String content = RichTextConverter.asFormula(fm.getContent()); + int start = textPane.getSelectionStart(); + AttributeSet attrs = start > 0 ? doc.getCharacterElement(start - 1).getAttributes() : new SimpleAttributeSet(); + try { + doc.insertString(start, content, attrs); + } catch (BadLocationException e) { + FRContext.getLogger().error(e.getMessage()); + } + } + }).setVisible(true); + } + }; + + private int roundUp(double num){ + String numStr = Double.toString(num); + numStr = new BigDecimal(numStr).setScale(0, BigDecimal.ROUND_HALF_UP).toString(); + return Integer.valueOf(numStr); + } + + private CaretListener textCareListener = new CaretListener() { + + //根据选中部分的文字样式, 来动态显示工具栏上按钮的状态 + private void setSelectedCharStyle(int start, int end, StyledDocument doc){ + boolean isBold = true; + boolean isItalic = true; + boolean isUnderline = true; + boolean isSubscript = true; + boolean isSuperscript = true; + String fontName_1st = null; + int fontSize_1st = 0; + Color fontColor_1st = null; + + for (int i = start; i < end; i++) { + Element ele = doc.getCharacterElement(i); + AttributeSet attrs = ele.getAttributes(); + + //粗体 + isBold = isBold && StyleConstants.isBold(attrs); + //斜体 + isItalic = isItalic && StyleConstants.isItalic(attrs); + //下划线 + isUnderline = isUnderline && StyleConstants.isUnderline(attrs); + //下标 + isSubscript = isSubscript && StyleConstants.isSubscript(attrs); + //上标 + isSuperscript = isSuperscript && StyleConstants.isSuperscript(attrs); + + if(i == start){ + fontName_1st = (String) attrs.getAttribute(StyleConstants.FontFamily); + fontSize_1st = (Integer) attrs.getAttribute(StyleConstants.FontSize); + fontColor_1st = (Color) attrs.getAttribute(StyleConstants.Foreground); + fontColor_1st = fontColor_1st == null ? Color.BLACK : fontColor_1st; + } + } + + setButtonSelected(isBold, isItalic, isUnderline, isSubscript, isSuperscript, + fontName_1st, fontSize_1st, fontColor_1st); + } + + //动态显示工具栏上按钮的状态 + private void setButtonSelected(boolean isBold, boolean isItalic, boolean isUnderline, + boolean isSubscript, boolean isSuperscript, String fontName_1st, + int fontSize_1st, Color fontColor_1st){ + bold.setSelected(isBold); + italic.setSelected(isItalic); + underline.setSelected(isUnderline); + subPane.setSelected(isSubscript); + superPane.setSelected(isSuperscript); + //为什么字体名称, 大小, 颜色, 不需要去判断是否全相同呢 + //因为如果全相同, 则设置为第一个字符的样式, 如果不全相同, 那么默认也设置成第一个字符的样式. + fontNameComboBox.setSelectedItem(fontName_1st); + fontSizeComboBox.removeItemListener(fontSizeItemListener); + fontSizeComboBox.setSelectedItem(scaleDown(fontSize_1st)); + fontSizeComboBox.addItemListener(fontSizeItemListener); + selectColorPane(fontColor_1st); + } + + private void selectColorPane(Color color){ + colorSelectPane.removeColorChangeListener(colorChangeAction); + colorSelectPane.setColor(color); + colorSelectPane.addColorChangeListener(colorChangeAction); + } + + @Override + public void caretUpdate(CaretEvent e) { + StyledDocument doc = (StyledDocument) textPane.getDocument(); + + // 取得选择文本的起始位置和结束位置 + int start = textPane.getSelectionStart(); + int end = textPane.getSelectionEnd(); + + //如果没有选定字符 + if(end == start){ + return; + } + + setSelectedCharStyle(start, end, doc); + } + }; + + //设置当前光标位样式 + private MouseListener setMouseCurrentStyle = new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent e) { + StyledDocument doc = (StyledDocument) textPane.getDocument(); + + // 取得选择文本的起始位置和结束位置 + int start = textPane.getSelectionStart(); + int end = textPane.getSelectionEnd(); + + if(start != end){ + return; + } + + setToLastCharStyle(end, doc); + } + + //如果默认不选字符, 那么设置为最后一个字符的样式 + private void setToLastCharStyle(int end, StyledDocument doc){ + if(textPane.isUpdating()){ + return; + } + + //取前一个字符的样式 + Element ele = doc.getCharacterElement(end - 1); + AttributeSet attrs = ele.getAttributes(); + populateToolBar(attrs); + } + }; + + /** + * 从样式中更新工具栏上的按钮状态 + * + * @param attrs 样式 + * + * + * @date 2015-1-5-下午5:12:33 + * + */ + public void populateToolBar(AttributeSet attrs){ + int size = scaleDown(StyleConstants.getFontSize(attrs)); + fontNameComboBox.setSelectedItem(StyleConstants.getFontFamily(attrs)); + fontSizeComboBox.setSelectedItem(size); + + bold.setSelected(StyleConstants.isBold(attrs)); + italic.setSelected(StyleConstants.isItalic(attrs)); + underline.setSelected(StyleConstants.isUnderline(attrs)); + subPane.setSelected(StyleConstants.isSubscript(attrs)); + superPane.setSelected(StyleConstants.isSuperscript(attrs)); + Color foreGround = StyleConstants.getForeground(attrs); + foreGround = foreGround == null ? Color.BLACK : foreGround; + colorSelectPane.setColor(foreGround); + colorSelectPane.repaint(); + } + + //pt转为px =*4/3 + private int scaleUp(int fontSize){ + return scale(fontSize, true); + } + + //px转pt = *3/4 + private int scaleDown(int fontSize){ + return scale(fontSize, false); + } + + private int scale(int fontSize, boolean isUp){ + double dpi96 = Constants.FR_PAINT_RESOLUTION; + double dpi72 = Constants.DEFAULT_FONT_PAINT_RESOLUTION; + double scale = isUp ? (dpi96 / dpi72) : (dpi72 / dpi96); + + return roundUp(fontSize * scale); + } + + private DocumentListener inputListener = new DocumentListener() { + + @Override + public void removeUpdate(DocumentEvent e) { + } + + @Override + public void insertUpdate(DocumentEvent e) { + //标志正在更新内容 + textPane.startUpdating(); + final MutableAttributeSet attr = updateStyleFromToolBar(); + final int start = textPane.getSelectionStart(); + int end = textPane.getSelectionEnd(); + + if (start != end) { + textPane.finishUpdating(); + return; + } + + //放到SwingWorker里, 是因为在documentListener里不能动态改变doc内容 + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + changeContentStyle(start, attr); + } + }); + } + + //根据Style来显示populate按钮 + private void changeContentStyle(int start, MutableAttributeSet attr){ + changeContentStyle(start, attr, 1); + } + + private void changeContentStyle(int start, MutableAttributeSet attr, int contentLength){ + // 将所选文本设置为新的样式,replace为false表示不覆盖原有的样式 + StyledDocument doc = (StyledDocument) textPane.getDocument(); + doc.setCharacterAttributes(start, contentLength, attr, false); + textPane.finishUpdating(); + } + + //将界面上的设置赋值给输入的字符 + private MutableAttributeSet updateStyleFromToolBar(){ + final boolean isBold = bold.isSelected(); + final boolean isItalic = italic.isSelected(); + final boolean isSub = subPane.isSelected(); + final boolean isSuper = superPane.isSelected(); + final boolean isUnderLine = underline.isSelected(); + final String fontName = (String) fontNameComboBox.getSelectedItem(); + final int fontSize = scaleUp((Integer) fontSizeComboBox.getSelectedItem()); + final Color foreGround = colorSelectPane.getColor() == null ? Color.BLACK : colorSelectPane.getColor(); + + MutableAttributeSet attr = new SimpleAttributeSet(); + StyleConstants.setBold(attr, isBold); + StyleConstants.setItalic(attr, isItalic); + StyleConstants.setSubscript(attr, isSub); + StyleConstants.setSuperscript(attr, isSuper); + StyleConstants.setUnderline(attr, isUnderLine); + StyleConstants.setForeground(attr, foreGround); + StyleConstants.setFontFamily(attr, fontName); + StyleConstants.setFontSize(attr, fontSize); + + return attr; + } + + private static final int NOT_INITED = -1; + private static final int UPDATING = -2; + //记录上一次输入成功后光标点定位, 因为有可能文本是在中间插入的 + private int inputStart = NOT_INITED; + private static final int JDK_6 = 6; + private static final int JDK_7 = 7; + + @Override + public void changedUpdate(DocumentEvent e) { + //这边需要注意, jdk1.6和1.7对于输入法的处理逻辑不一样, jdk6时直接在输入法中输入一大段中文 + //他会一个个insert进去直接触发inserupdate事件, 而jdk7会直接把所有的塞进来. + //inserupdate那边绑定的是一个个插入的事件, 多个一起插入的放这 + //bug84777 8.0不走if逻辑,改成只有jdk7走if逻辑 + if(StableUtils.getMajorJavaVersion() == JDK_7){ + if(isUpdating()){ + return; + } + StyledDocument doc = (StyledDocument) textPane.getDocument(); + final String content; + initFlag(doc); + + final int start = textPane.getSelectionStart(); + final int inputLen = start - inputStart; + //检测输入内容 + try { + content = doc.getText(inputStart, inputLen); + } catch (BadLocationException e1) { + return; + } + + //中文输入法, 默认输入字符会被输入法的框截取住, jtextpane得到是一个空格, 此时不做处理 + if(StringUtils.isBlank(content) || inputLen <= 0){ + return; + } + //设置一次性输入多个文字的样式 + setContentStyle(inputLen); + } + } + + private void setContentStyle(final int inputLen){ + //缓存下Start, 下面要用来设置样式 + final int _start = inputStart; + final MutableAttributeSet attr = updateStyleFromToolBar(); + + //放到SwingWorker里, 是因为在documentListener里不能动态改变doc内容 + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + //防止触发死循环change事件 + startUpdating(); + //Start-1 是因为中文输入法会用空格占1位 + changeContentStyle(_start, attr, inputLen); + resetFlag(); + } + }); + } + + private boolean isUpdating(){ + return inputStart == UPDATING; + } + + private void startUpdating(){ + inputStart = UPDATING; + } + + //初始标记状态, 用于记录中文输入法多个字符同时输入的问题 + private void initFlag(StyledDocument doc){ + if(inputStart != NOT_INITED){ + return; + } + inputStart = textPane.getSelectionStart() - 1; + } + + //重置标记状态 + private void resetFlag(){ + inputStart = NOT_INITED; + } + }; + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/editor/SubReportCellEditor.java b/designer/src/com/fr/design/cell/editor/SubReportCellEditor.java new file mode 100644 index 000000000..2c4982263 --- /dev/null +++ b/designer/src/com/fr/design/cell/editor/SubReportCellEditor.java @@ -0,0 +1,64 @@ +package com.fr.design.cell.editor; + +import java.awt.Component; + +import javax.swing.SwingUtilities; + +import com.fr.design.report.SubReportPane; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionListener; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.Grid; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.core.SheetUtils; +import com.fr.report.elementcase.TemplateElementCase; +import com.fr.report.poly.PolyECBlock; +import com.fr.report.worksheet.WorkSheet; + +public class SubReportCellEditor extends AbstractCellEditor implements + DialogActionListener { + + public SubReportCellEditor( + ElementCasePane ePane) { + super(ePane); + } + + private SubReportPane subReportPane; + + @Override + public Component getCellEditorComponent(Grid grid, + TemplateCellElement cellElement, int resolution) { + TemplateElementCase parentTplEC = grid.getElementCasePane() + .getEditingElementCase(); + + // alex:如果是线性报表,这时还要计算一下默认父格是什么 + if (parentTplEC != null + && (parentTplEC instanceof WorkSheet || parentTplEC instanceof PolyECBlock)) { + SheetUtils.calculateDefaultParent(parentTplEC); + } + + this.subReportPane = new SubReportPane(); + + BasicDialog subReportDialog = this.subReportPane + .showWindow(SwingUtilities.getWindowAncestor(grid)); + subReportDialog.addDialogActionListener(this); + this.subReportPane.populate(parentTplEC, cellElement); + + return subReportDialog; + } + + @Override + public Object getCellEditorValue() throws Exception { + return this.subReportPane.update(); + } + + @Override + public void doOk() { + this.fireEditingStopped(); + } + + @Override + public void doCancel() { + this.fireEditingCanceled(); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/editor/TextCellEditor.java b/designer/src/com/fr/design/cell/editor/TextCellEditor.java new file mode 100644 index 000000000..0682a560c --- /dev/null +++ b/designer/src/com/fr/design/cell/editor/TextCellEditor.java @@ -0,0 +1,179 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.cell.editor; + +import java.awt.Component; +import java.awt.Dimension; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; + +import javax.swing.BorderFactory; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; + +import com.fr.base.Style; +import com.fr.base.Utils; +import com.fr.design.gui.itextfield.EditTextField; +import com.fr.grid.Grid; +import com.fr.quickeditor.cellquick.CellStringQuickEditor; +import com.fr.report.cell.TemplateCellElement; +import com.fr.design.utils.gui.GUICoreUtils; + +/** + * CellEditor used to edit text object. + */ +public class TextCellEditor extends AbstractCellEditor { + private Grid grid; + + protected EditTextField textField; //text field. + //the old value of text field. + protected String oldValue = ""; + + public Grid getGrid() { + return grid; + } + + /** + * Constructor. + */ + public TextCellEditor() { + textField = new EditTextField(); + textField.setBorder(BorderFactory.createEmptyBorder(0, 1, 0, 1)); + this.textField.addKeyListener(textKeyListener); + this.textField.addFocusListener(new FocusAdapter() { + @Override + public void focusLost(FocusEvent evt) { + stopCellEditing(); + } + }); + this.textField.getDocument().addDocumentListener(documentlistener); + //兼容JDK1.4 + this.textField.setFocusTraversalKeysEnabled(false); + } + DocumentListener documentlistener = new DocumentListener() { + + @Override + public void removeUpdate(DocumentEvent e) { + textchanged(); + } + + @Override + public void insertUpdate(DocumentEvent e) { + textchanged(); + } + + @Override + public void changedUpdate(DocumentEvent e) { + textchanged(); + } + }; + /** + * Gets the max length. + * @return the max length + */ + public int getMaxLength() { + return this.textField.getMaxLength(); + } + + private void textchanged() { + CellStringQuickEditor quickeditor = (CellStringQuickEditor)grid.getElementCasePane().getCurrentEditor(); + quickeditor.showText(textField.getText()); + } + + /** + * Set the max length. + * @param maxLength the new max length. + */ + public void setMaxLength(int maxLength) { + this.textField.setMaxLength(maxLength); + } + + /** + * Gets the value of the CellEditor. + */ + public Object getCellEditorValue() throws Exception { + return this.textField.getText(); + } + + /** + * Sets an initial cellElement for the editor. This will cause + * the editor to stopCellEditing and lose any partially + * edited value if the editor is editing when this method is called.

+ *

+ * Returns the component that should be added to the client's + * Component hierarchy. Once installed in the client's + * hierarchy this component will then be able to draw and receive + * user input. + * + * @param grid the Grid that is asking the + * editor to edit; can be null + * @param cellElement the value of the cell to be edited; it is + * up to the specific editor to interpret + * and draw the value. + */ + public Component getCellEditorComponent(Grid grid, TemplateCellElement cellElement, int resolution) { + this.grid = grid; + + Object value = null; + if(cellElement != null) { + value = cellElement.getValue(); + } + if (value == null) { + value = ""; + } + if (!(value instanceof String) && !(value instanceof Number)) { + value = ""; + } + + this.oldValue = Utils.objectToString(value); + this.textField.setText(oldValue); + //peter:只读方式获得Style. + Style style = null; + if(cellElement != null) { + style = cellElement.getStyle(); + } + this.ajustTextStyle(grid, style, value, resolution); + + return this.textField; + } + + public String getOldValue () { + return oldValue; + } + + protected void ajustTextStyle(Grid grid, Style style, Object value, int resolution) { + GUICoreUtils.adjustStyle(style, textField, resolution, value); + } + + private void ajustTextFieldSize() { + Dimension textSize = textField.getSize(); + Dimension textPrefSize = textField.getPreferredSize(); + this.textField.setSize((int) Math.max(textSize.getWidth(), textPrefSize.getWidth()), (int) textSize.getHeight()); + } + + private KeyListener textKeyListener = new KeyListener() { + public void keyTyped(KeyEvent e) { + ajustTextFieldSize(); + } + + public void keyPressed(KeyEvent evt) { + int code = evt.getKeyCode(); + + if (code == KeyEvent.VK_ESCAPE) { + textField.setText(oldValue); + evt.consume(); + } else if (code == KeyEvent.VK_ENTER || code == KeyEvent.VK_TAB || + code == KeyEvent.VK_UP || code == KeyEvent.VK_DOWN) { + //将事件传递给Grid控件来实现, Enter键向下移动 和 Tab键向右移动. + grid.requestFocus(); + grid.dispatchEvent(evt); + } + } + + public void keyReleased(KeyEvent evt) { + } + }; +} \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/editor/TextFloatEditor.java b/designer/src/com/fr/design/cell/editor/TextFloatEditor.java new file mode 100644 index 000000000..09a763ffd --- /dev/null +++ b/designer/src/com/fr/design/cell/editor/TextFloatEditor.java @@ -0,0 +1,174 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.cell.editor; + +import java.awt.Component; +import java.awt.Dimension; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; + +import javax.swing.BorderFactory; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; + +import com.fr.base.Style; +import com.fr.base.Utils; +import com.fr.design.gui.itextfield.EditTextField; +import com.fr.grid.Grid; +import com.fr.quickeditor.floatquick.FloatStringQuickEditor; +import com.fr.report.cell.FloatElement; +import com.fr.design.utils.gui.GUICoreUtils; + +/** + * FloatEditor used to edit text object. + */ +public class TextFloatEditor extends AbstractFloatEditor { + private Grid grid; + private FloatElement floatElement; + + protected EditTextField textField; //text field. + //the old value of text field. + protected String oldValue = ""; + + public Grid getGrid() { + return grid; + } + + public FloatElement getFloatElement() { + return floatElement; + } + + /** + * Constructor. + */ + public TextFloatEditor() { + textField = new EditTextField(); + textField.setBorder(BorderFactory.createEmptyBorder(0, 1, 0, 1)); + this.textField.addKeyListener(textKeyListener); + this.textField.addFocusListener(new FocusAdapter() { + @Override + public void focusLost(FocusEvent evt) { + stopFloatEditing(); + } + }); + this.textField.getDocument().addDocumentListener(new DocumentListener() { + + @Override + public void removeUpdate(DocumentEvent e) { + textchanged(); + } + + @Override + public void insertUpdate(DocumentEvent e) { + textchanged(); + } + + @Override + public void changedUpdate(DocumentEvent e) { + textchanged(); + } + }); + + //兼容JDK1.4 + this.textField.setFocusTraversalKeysEnabled(false); + } + private void textchanged() { + FloatStringQuickEditor quickeditor = (FloatStringQuickEditor)grid.getElementCasePane().getCurrentEditor(); + quickeditor.showText(textField.getText()); + } + /** + * Gets the max length. + * @return the max length + */ + public int getMaxLength() { + return this.textField.getMaxLength(); + } + + /** + * Set the max length. + * @param maxLength the new max length. + */ + public void setMaxLength(int maxLength) { + this.textField.setMaxLength(maxLength); + } + + /** + * Gets the value of the FloatEditor. + */ + public Object getFloatEditorValue() throws Exception { + return this.textField.getText(); + } + + /** + * Sets an initial floatElement for the editor. This will cause + * the editor to stopFloatEditing and lose any partially + * edited value if the editor is editing when this method is called.

+ *

+ * Returns the component that should be added to the client's + * Component hierarchy. Once installed in the client's + * hierarchy this component will then be able to draw and receive + * user input. + * + * @param grid the Grid that is asking the + * editor to edit; can be null + * @param floatElement the value of the float to be edited; it is + * up to the specific editor to interpret + * and draw the value. + */ + public Component getFloatEditorComponent(Grid grid, FloatElement floatElement, int resolution) { + this.grid = grid; + this.floatElement = floatElement; + + Object value = floatElement.getValue(); + if (value == null) { + value = ""; + } + if (!(value instanceof String) && !(value instanceof Number)) { + value = ""; + } + + this.oldValue = Utils.objectToString(value); + this.textField.setText(oldValue); + //peter:只读方式获得Style. + Style style = floatElement.getStyle(); + this.ajustTextStyle(grid, style, value, resolution); + + return this.textField; + } + + protected void ajustTextStyle(Grid grid, Style style, Object value, int resolution) { + GUICoreUtils.adjustStyle(style, textField, resolution, value); + } + + private void ajustTextFieldSize() { + Dimension textSize = textField.getSize(); + Dimension textPrefSize = textField.getPreferredSize(); + this.textField.setSize((int) Math.max(textSize.getWidth(), textPrefSize.getWidth()), + (int) textSize.getHeight()); + } + + private KeyListener textKeyListener = new KeyListener() { + public void keyTyped(KeyEvent e) { + ajustTextFieldSize(); + } + + public void keyPressed(KeyEvent evt) { + int code = evt.getKeyCode(); + + if (code == KeyEvent.VK_ESCAPE) { + textField.setText(oldValue); + evt.consume(); + } else if (code == KeyEvent.VK_ENTER || code == KeyEvent.VK_TAB) { + //将事件传递给Grid控件来实现, Enter键向下移动 和 Tab键向右移动. + grid.requestFocus(); + grid.dispatchEvent(evt); + } + } + + public void keyReleased(KeyEvent evt) { + } + }; +} \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/editor/package.html b/designer/src/com/fr/design/cell/editor/package.html new file mode 100644 index 000000000..181bdb68c --- /dev/null +++ b/designer/src/com/fr/design/cell/editor/package.html @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/smartaction/AbstractSmartJTablePaneAction.java b/designer/src/com/fr/design/cell/smartaction/AbstractSmartJTablePaneAction.java new file mode 100644 index 000000000..39fd4119a --- /dev/null +++ b/designer/src/com/fr/design/cell/smartaction/AbstractSmartJTablePaneAction.java @@ -0,0 +1,49 @@ +package com.fr.design.cell.smartaction; + +import java.awt.Container; +import java.awt.Dialog; + +public abstract class AbstractSmartJTablePaneAction implements SmartJTablePaneAction { + + protected Container dialog; + + private SmartJTablePane smartJTablePane; + + public AbstractSmartJTablePaneAction(SmartJTablePane s, Container d){ + this.smartJTablePane = s; + this.dialog = d; + } + + public void setSmartJTablePane(SmartJTablePane s){ + this.smartJTablePane = s; + } + + public void doDialogExit(int choice) { + smartJTablePane.actionReportPane.getGrid().setNotShowingTableSelectPane(true); + smartJTablePane.actionReportPane.setEditable(smartJTablePane.old_editable); + smartJTablePane.actionReportPane.removeSelectionChangeListener(smartJTablePane.gridSelectionChangeL); + smartJTablePane.actionReportPane.repaint(); + + if(choice == SmartJTablePane.OK){ + doOk(); + } + showDialog(); + } + + public void showDialog() { + while (dialog != null) { + if (dialog instanceof Dialog) { + break; + } + dialog = dialog.getParent(); + } + + if (dialog != null) { + dialog.repaint(); + dialog.setVisible(true); + } + } + + public abstract void doOk(); + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/smartaction/SmartJTablePane.java b/designer/src/com/fr/design/cell/smartaction/SmartJTablePane.java new file mode 100644 index 000000000..b6af98b74 --- /dev/null +++ b/designer/src/com/fr/design/cell/smartaction/SmartJTablePane.java @@ -0,0 +1,117 @@ +package com.fr.design.cell.smartaction; + +import java.awt.BorderLayout; +import java.awt.Window; + +import com.fr.design.gui.ilable.UILabel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.table.AbstractTableModel; + +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.BasicPane; +import com.fr.design.dialog.DialogActionListener; +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.selection.SelectionListener; + +/* + * SmartJTablePane用于在Grid上面选单元格时编辑JTable + */ +public abstract class SmartJTablePane extends BasicPane { + + public static final int OK = 0; + public static final int CANCEL = 1; + + protected ElementCasePane actionReportPane; + protected AbstractTableModel model; + + protected SelectionListener gridSelectionChangeL; + protected SmartJTablePaneAction action; + + protected JTable table; + protected JScrollPane scrollPane; + + protected boolean old_editable = true; + + protected int editingRowIndex = 0; + + public SmartJTablePane(AbstractTableModel model, + ElementCasePane actionReportPane) { + this.model = model; + this.actionReportPane = actionReportPane; + old_editable = actionReportPane.isEditable(); + + initComponents(); + } + + public void initComponents() { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + + // BasicPane的north放描述 + this.add(new UILabel(Inter.getLocText("RWA-Click_Cell_To_Edit_Value")), BorderLayout.NORTH); + + // BasicPane的center放JTable + table = new JTable(model); + this.add(scrollPane = new JScrollPane(table), BorderLayout.CENTER); + + // 鼠标切换选中项时,editingRowIndex也要跟着变 + table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + + public void valueChanged(ListSelectionEvent e) { + int selected = table.getSelectedRow(); + // alex:当SmartJTablePane失去焦点时,好像也会触发这个,selected为-1 + if (selected >= 0) { + setEditingRowIndex(selected); + table.repaint(); + } + } + }); + + setCellRenderer(); + actionReportPane.addSelectionChangeListener(gridSelectionChangeL); + } + + public void changeGridSelectionChangeListener(SelectionListener g){ + actionReportPane.removeSelectionChangeListener(gridSelectionChangeL); + gridSelectionChangeL = g; + actionReportPane.addSelectionChangeListener(gridSelectionChangeL); + } + + public void changeSmartJTablePaneAction(SmartJTablePaneAction a){ + this.action = a; + } + + public abstract void setCellRenderer(); + + + + /* + * 设置正在编辑的RowIndex,并Scroll + */ + protected void setEditingRowIndex(int idx) { + editingRowIndex = idx; + + table.scrollRectToVisible(table.getCellRect(editingRowIndex, 2, true)); + } + + @Override + public BasicDialog showWindow(Window window) { + BasicDialog dlg = super.showSmallWindow(window,new DialogActionListener() { + public void doOk() { + action.doDialogExit(SmartJTablePane.OK); + } + + public void doCancel() { + action.doDialogExit(SmartJTablePane.CANCEL); + } + }); + + + return dlg; + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/cell/smartaction/SmartJTablePaneAction.java b/designer/src/com/fr/design/cell/smartaction/SmartJTablePaneAction.java new file mode 100644 index 000000000..0189b0727 --- /dev/null +++ b/designer/src/com/fr/design/cell/smartaction/SmartJTablePaneAction.java @@ -0,0 +1,8 @@ +package com.fr.design.cell.smartaction; + +public interface SmartJTablePaneAction { + + public void doDialogExit(int choice); + + public void setSmartJTablePane(SmartJTablePane s); +} \ No newline at end of file diff --git a/designer/src/com/fr/design/condition/BackPane.java b/designer/src/com/fr/design/condition/BackPane.java new file mode 100644 index 000000000..d7d6c30f3 --- /dev/null +++ b/designer/src/com/fr/design/condition/BackPane.java @@ -0,0 +1,75 @@ +package com.fr.design.condition; + +import com.fr.base.background.ColorBackground; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.style.background.BackgroundPane; +import com.fr.design.style.background.BackgroundPreviewLabel; +import com.fr.general.Inter; +import com.fr.report.cell.cellattr.highlight.BackgroundHighlightAction; +import com.fr.report.cell.cellattr.highlight.HighlightAction; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/** +* @author richie +* @date 2015-03-26 +* @since 8.0 +*/ +public class BackPane extends ConditionAttrSingleConditionPane { + private UILabel backgroundLabel; + private BackgroundPreviewLabel backgroundPreviewPane; + private UIComboBox backScopeComboBox; + + public BackPane(final ConditionAttributesPane conditionAttributesPane) { + super(conditionAttributesPane); + backgroundLabel = new UILabel(Inter.getLocText("FR-Designer_Background") + ":"); + this.backgroundPreviewPane = new BackgroundPreviewLabel(); + this.backgroundPreviewPane.setPreferredSize(new Dimension(80, 20)); + UIButton editBackgroundButton = new UIButton(Inter.getLocText("FR-Designer_Edit")); + editBackgroundButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + final BackgroundPane backgroundPane = new BackgroundPane(); + backgroundPane.populate(backgroundPreviewPane.getBackgroundObject()); + backgroundPane.showWindow( + SwingUtilities.getWindowAncestor(conditionAttributesPane), new DialogActionAdapter() { + public void doOk() { + backgroundPreviewPane.setBackgroundObject(backgroundPane.update()); + backgroundPreviewPane.repaint(); + } + }).setVisible(true); + } + }); + + this.backScopeComboBox = new UIComboBox(new String[] { + Inter.getLocText("Utils-Current_Cell"), + Inter.getLocText("Utils-Current_Row"), + Inter.getLocText("Utils-Current_Column") }); + + this.add(backgroundLabel); + this.add(backgroundPreviewPane); + this.add(editBackgroundButton); + this.add(this.backScopeComboBox); + this.backgroundPreviewPane.setBackgroundObject(ColorBackground.getInstance(Color.white)); + } + + @Override + public String nameForPopupMenuItem() { + return Inter.getLocText("FR-Designer_Background"); + } + + + public void populate(HighlightAction ha) { + this.backgroundPreviewPane.setBackgroundObject(((BackgroundHighlightAction) ha).getBackground()); + this.backScopeComboBox.setSelectedIndex(((BackgroundHighlightAction) ha).getScope()); + } + + public HighlightAction update() { + return new BackgroundHighlightAction(this.backgroundPreviewPane.getBackgroundObject(), this.backScopeComboBox.getSelectedIndex()); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/condition/BorderHighlightPane.java b/designer/src/com/fr/design/condition/BorderHighlightPane.java new file mode 100644 index 000000000..9d15ac72a --- /dev/null +++ b/designer/src/com/fr/design/condition/BorderHighlightPane.java @@ -0,0 +1,72 @@ +package com.fr.design.condition; + +import com.fr.base.CellBorderStyle; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.style.BorderPane; +import com.fr.general.Inter; +import com.fr.report.cell.cellattr.highlight.BorderHighlightAction; +import com.fr.report.cell.cellattr.highlight.HighlightAction; +import com.fr.stable.Constants; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/** +* @author richie +* @date 2015-03-26 +* @since 8.0 +*/ +public class BorderHighlightPane extends ConditionAttrSingleConditionPane { + private CellBorderStyle border; + private UIButton borderButton; + public BorderHighlightPane(final ConditionAttributesPane conditionAttributesPane) { + super(conditionAttributesPane); + borderButton = new UIButton(Inter.getLocText("FR-Designer_Edit")); + borderButton.setPreferredSize(new Dimension(53, 23)); + borderButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + final BorderPane borderPane = new BorderPane(); + int line = border == null ? Constants.LINE_NONE : border.getTopStyle(); + Color color = border == null ? Color.black : border.getTopColor(); + borderPane.populate(border, false, line, color); + BasicDialog dialog = borderPane.showWindow(SwingUtilities.getWindowAncestor(conditionAttributesPane)); + dialog.addDialogActionListener(new DialogActionAdapter() { + @Override + public void doOk() { + border = borderPane.update(); + borderButton.setBorderStyle(border); + borderButton.repaint(); + } + }); + dialog.setVisible(true); + } + }); + + UILabel borderLabel = new UILabel(Inter.getLocText("FR-Designer_Border") + ":"); + this.add(borderLabel); + this.add(borderButton); + } + + @Override + public String nameForPopupMenuItem() { + return Inter.getLocText("FR-Designer_Border"); + } + + + public void populate(HighlightAction ha) { + this.border = ((BorderHighlightAction)ha).getCellBorder(); + borderButton.setBorderStyle(border); + borderButton.repaint(); + } + + public HighlightAction update() { + return new BorderHighlightAction(border); + } + + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/condition/ColumnWidthPane.java b/designer/src/com/fr/design/condition/ColumnWidthPane.java new file mode 100644 index 000000000..ee45a2689 --- /dev/null +++ b/designer/src/com/fr/design/condition/ColumnWidthPane.java @@ -0,0 +1,28 @@ +package com.fr.design.condition; + +import com.fr.general.Inter; +import com.fr.report.cell.cellattr.highlight.ColWidthHighlightAction; +import com.fr.report.cell.cellattr.highlight.HighlightAction; +import com.fr.stable.unit.UNIT; + +/** +* @author richie +* @date 2015-03-26 +* @since 8.0 +*/ +public class ColumnWidthPane extends WHPane { + + public ColumnWidthPane(ConditionAttributesPane conditionAttributesPane) { + super(conditionAttributesPane, Inter.getLocText("Utils-Column_Width")); + } + + @Override + protected UNIT getUnit(HighlightAction ha) { + return ((ColWidthHighlightAction) ha).getColumnWidth(); + } + + @Override + protected HighlightAction returnAction(UNIT unit) { + return new ColWidthHighlightAction(unit); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/condition/FontPane.java b/designer/src/com/fr/design/condition/FontPane.java new file mode 100644 index 000000000..26e516321 --- /dev/null +++ b/designer/src/com/fr/design/condition/FontPane.java @@ -0,0 +1,80 @@ +package com.fr.design.condition; + +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.style.FRFontPane; +import com.fr.design.style.FRFontPreviewArea; +import com.fr.general.FRFont; +import com.fr.general.Inter; +import com.fr.report.cell.cellattr.highlight.FRFontHighlightAction; +import com.fr.report.cell.cellattr.highlight.HighlightAction; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/** +* @author richie +* @date 2015-03-26 +* @since 8.0 +*/ +public class FontPane extends ConditionAttrSingleConditionPane { + private UILabel fontLabel; + private FRFontPreviewArea frFontPreviewPane; + private UIComboBox fontScopeComboBox; + + public FontPane(final ConditionAttributesPane conditionAttributesPane) { + super(conditionAttributesPane); + fontLabel = new UILabel(Inter.getLocText("FR-Designer_Sytle-FRFont") + ":"); + frFontPreviewPane = new FRFontPreviewArea(); + frFontPreviewPane.setBorder(BorderFactory.createTitledBorder("")); + frFontPreviewPane.setPreferredSize(new Dimension(80, 20)); + UIButton editFRFontButton = new UIButton(Inter.getLocText("FR-Designer_Edit")); + editFRFontButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + final FRFontPane frFontPane = new FRFontPane(); + BasicDialog styleDialog = frFontPane.showWindow( + SwingUtilities.getWindowAncestor(conditionAttributesPane)); + frFontPane.populate(frFontPreviewPane.getFontObject()); + styleDialog.addDialogActionListener(new DialogActionAdapter() { + public void doOk() { + frFontPreviewPane.setFontObject(frFontPane.update()); + // repaint. + frFontPreviewPane.repaint(); + } + }); + styleDialog.setVisible(true); + } + }); + + this.fontScopeComboBox = new UIComboBox(new String[] { + Inter.getLocText("Utils-Current_Cell"), + Inter.getLocText("Utils-Current_Row"), + Inter.getLocText("Utils-Current_Column") }); + + this.add(fontLabel); + this.add(frFontPreviewPane); + this.add(editFRFontButton); + this.add(this.fontScopeComboBox); + this.frFontPreviewPane.setFontObject(FRFont.getInstance()); + } + + @Override + public String nameForPopupMenuItem() { + return Inter.getLocText("FR-Designer_Sytle-FRFont"); + } + + + public void populate(HighlightAction ha) { + this.frFontPreviewPane.setFontObject(((FRFontHighlightAction) ha).getFRFont()); + this.fontScopeComboBox.setSelectedIndex(((FRFontHighlightAction) ha).getScope()); + } + + public HighlightAction update() { + return new FRFontHighlightAction(this.frFontPreviewPane.getFontObject(), this.fontScopeComboBox.getSelectedIndex()); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/condition/ForeGroundPane.java b/designer/src/com/fr/design/condition/ForeGroundPane.java new file mode 100644 index 000000000..5bc5617fd --- /dev/null +++ b/designer/src/com/fr/design/condition/ForeGroundPane.java @@ -0,0 +1,55 @@ +package com.fr.design.condition; + +import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.style.color.ColorSelectBox; +import com.fr.general.Inter; +import com.fr.report.cell.cellattr.highlight.ForegroundHighlightAction; +import com.fr.report.cell.cellattr.highlight.HighlightAction; + +import java.awt.*; + +/** +* @author richie +* @date 2015-03-26 +* @since 8.0 +*/ +public class ForeGroundPane extends ConditionAttrSingleConditionPane { + private UILabel foregroundLabel; + private ColorSelectBox foregroundColorPane; + private UIComboBox foreScopeComboBox; + + + public ForeGroundPane(ConditionAttributesPane conditionAttributesPane) { + super(conditionAttributesPane); + foregroundLabel = new UILabel(Inter.getLocText("FR-Designer_Foreground") + ":"); + this.foregroundColorPane = new ColorSelectBox(80); + this.add(foregroundLabel); + this.add(this.foregroundColorPane); + this.foreScopeComboBox = new UIComboBox(new String[] { + Inter.getLocText("Utils-Current_Cell"), + Inter.getLocText("Utils-Current_Row"), + Inter.getLocText("Utils-Current_Column") }); + this.add(this.foreScopeComboBox); + this.foregroundColorPane.setSelectObject(Color.black); + } + + @Override + public String nameForPopupMenuItem() { + return Inter.getLocText("FR-Designer_Foreground"); + } + + @Override + protected String title4PopupWindow() { + return nameForPopupMenuItem(); + } + + public void populate(HighlightAction ha) { + this.foregroundColorPane.setSelectObject(((ForegroundHighlightAction)ha).getForegroundColor()); + this.foreScopeComboBox.setSelectedIndex(((ForegroundHighlightAction)ha).getScope()); + } + + public HighlightAction update() { + return new ForegroundHighlightAction(this.foregroundColorPane.getSelectObject(), this.foreScopeComboBox.getSelectedIndex()); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/condition/HighLightConditionAttributesPane.java b/designer/src/com/fr/design/condition/HighLightConditionAttributesPane.java new file mode 100644 index 000000000..5bdaeb853 --- /dev/null +++ b/designer/src/com/fr/design/condition/HighLightConditionAttributesPane.java @@ -0,0 +1,109 @@ +package com.fr.design.condition; + +import com.fr.data.condition.ListCondition; +import com.fr.design.ExtraDesignClassManager; +import com.fr.design.fun.HighlightProvider; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.report.cell.cellattr.highlight.*; + +import javax.swing.*; +import java.awt.*; +import java.util.Iterator; + +public class HighLightConditionAttributesPane extends ConditionAttributesPane { + + public HighLightConditionAttributesPane() { + this.initComponents(); + } + + /** + * 初始化组件 + */ + public void initComponents() { + super.initComponents(); + this.initActionList(); + this.initLiteConditionPane(); + } + + protected void initLiteConditionPane() { + // 条件Panel + JPanel centerPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + this.add(centerPane); + + liteConditionPane = new ObjectLiteConditionPane(); + centerPane.add(liteConditionPane, BorderLayout.CENTER); + liteConditionPane.setPreferredSize(new Dimension(300, 300)); + } + + protected void initActionList() { + classPaneMap.put(ForegroundHighlightAction.class, new ForeGroundPane(this)); + classPaneMap.put(BackgroundHighlightAction.class, new BackPane(this)); + classPaneMap.put(FRFontHighlightAction.class, new FontPane(this)); + classPaneMap.put(PresentHighlightAction.class, new PresentHighlightPane(this)); + classPaneMap.put(PaddingHighlightAction.class, new PaddingPane(this)); + classPaneMap.put(RowHeightHighlightAction.class, new RowHeightPane(this)); + classPaneMap.put(ColWidthHighlightAction.class, new ColumnWidthPane(this)); + classPaneMap.put(PageHighlightAction.class, new PagePane(this)); + classPaneMap.put(HyperlinkHighlightAction.class, new HyperlinkPane(this)); + classPaneMap.put(BorderHighlightAction.class, new BorderHighlightPane(this)); + classPaneMap.put(WidgetHighlightAction.class, new WidgetHighlightPane(this)); + classPaneMap.put(ValueHighlightAction.class, new NewRealValuePane(this)); + HighlightProvider[] providers = ExtraDesignClassManager.getInstance().getHighlightProviders(); + for (HighlightProvider provider : providers) { + classPaneMap.put(provider.classForHighlightAction(), provider.appearanceForCondition(this)); + } + + useAbleActionList.clear(); + + Iterator iterator = classPaneMap.values().iterator(); + + while (iterator.hasNext()) { + useAbleActionList.add(iterator.next().getHighLightConditionAction()); + } + } + + @Override + protected String title4PopupWindow() { + return "Condition"; + } + + @Override + public void populateBean(DefaultHighlight ob) { + this.selectedItemPane.removeAll(); + this.initActionList(); + + for (int i = 0, size = ob.actionCount(); i < size; i++) { + HighlightAction hightlightAction = ob.getHighlightAction(i); + + ConditionAttrSingleConditionPane pane = classPaneMap.get(hightlightAction.getClass()); + + pane.populate(hightlightAction); + this.selectedItemPane.add(pane); + useAbleActionList.remove(pane.getHighLightConditionAction()); + } + this.liteConditionPane.populateBean(ob.getCondition() == null ? new ListCondition() : ob.getCondition()); + + checkConditionPane(); + updateMenuDef(); + + validate(); + repaint(10); + } + + @Override + public DefaultHighlight updateBean() { + DefaultHighlight hl = new DefaultHighlight(); + + for (ConditionAttrSingleConditionPane pane : classPaneMap.values()) { + if (pane.getParent() == this.selectedItemPane) { + hl.addHighlightAction(pane.update()); + } + } + + hl.setCondition(this.liteConditionPane.updateBean()); + + return hl; + } + + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/condition/HyperlinkPane.java b/designer/src/com/fr/design/condition/HyperlinkPane.java new file mode 100644 index 000000000..5e24329ab --- /dev/null +++ b/designer/src/com/fr/design/condition/HyperlinkPane.java @@ -0,0 +1,128 @@ +package com.fr.design.condition; + +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.gui.frpane.HyperlinkGroupPane; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.icheckbox.UICheckBox; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itextfield.UITextField; +import com.fr.design.mainframe.DesignerContext; +import com.fr.general.Inter; +import com.fr.js.*; +import com.fr.report.cell.cellattr.highlight.HighlightAction; +import com.fr.report.cell.cellattr.highlight.HyperlinkHighlightAction; + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/** +* @author richie +* @date 2015-03-26 +* @since 8.0 +*/ +public class HyperlinkPane extends ConditionAttrSingleConditionPane { + private NameJavaScriptGroup jsGroup; + protected UITextField typeField; + protected UICheckBox useHyperlink; + protected UIButton hyperlinkButton; + protected HyperlinkGroupPane pane; + protected BasicDialog dialog; + + public HyperlinkPane(final ConditionAttributesPane conditionAttributesPane) { + super(conditionAttributesPane); + hyperlinkButton = new UIButton(Inter.getLocText("FR-Designer_Edit")); + hyperlinkButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + NameJavaScriptGroup nameHyperlinks = jsGroup; + pane = DesignerContext.getDesignerFrame().getSelectedJTemplate().getHyperLinkPane(); + pane.populate(nameHyperlinks); + dialog = pane.showWindow(SwingUtilities.getWindowAncestor(conditionAttributesPane)); + dialog.addDialogActionListener(new DialogActionAdapter() { + @Override + public void doOk() { + jsGroup = pane.updateJSGroup(); + setText(); + } + }); + dialog.setVisible(true); + } + }); + hyperlinkButton.setEnabled(false); + UILabel hyperlinkLabel = new UILabel(Inter.getLocText(new String[]{"Hyperlink", "Type"}) + ":"); + typeField = new UITextField(12); + typeField.setEditable(false); + this.add(hyperlinkLabel); + this.add(typeField); + + this.add(hyperlinkButton); + useHyperlink = new UICheckBox(Inter.getLocText(new String[]{"Use", "Links"})); + useHyperlink.addActionListener(l); + this.add(useHyperlink); + } + + @Override + public String nameForPopupMenuItem() { + return Inter.getLocText("FR-Designer_Hyperlink"); + } + + @Override + protected String title4PopupWindow() { + return nameForPopupMenuItem(); + } + + ActionListener l = new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (useHyperlink.isSelected()) { + hyperlinkButton.setEnabled(true); + setText(); + } else { + hyperlinkButton.setEnabled(false); + typeField.setText(""); + } + } + + }; + + + + public void setText() { + if (jsGroup == null) { + this.typeField.setText(""); + } else if (jsGroup.size() > 1) { + this.typeField.setText(Inter.getLocText("FR-Designer_HyperLink_Must_Alone_Reset") + "!"); + } else if (jsGroup.size() == 1) { + JavaScript js = jsGroup.getNameHyperlink(0).getJavaScript(); + if (js instanceof JavaScriptImpl) { + this.typeField.setText("JavaScript"); + } else if (js instanceof ReportletHyperlink) { + this.typeField.setText(Inter.getLocText(new String[]{"Report", "Links"})); + } else if (js instanceof WebHyperlink) { + this.typeField.setText(Inter.getLocText("Hyperlink-Web_link")); + } else if (js instanceof EmailJavaScript) { + this.typeField.setText(Inter.getLocText(new String[]{"Email", "Links"})); + } + + } + } + + public void populate(HighlightAction ha) { + this.jsGroup = ((HyperlinkHighlightAction)ha).getHperlink(); + if ( jsGroup == null || jsGroup.size() == 0) { + this.useHyperlink.setSelected(false); + this.hyperlinkButton.setEnabled(false); + } else { + this.useHyperlink.setSelected(true); + this.hyperlinkButton.setEnabled(true); + this.setText(); + } + } + + public HighlightAction update() { + if (this.useHyperlink.isSelected()) { + return new HyperlinkHighlightAction(this.jsGroup); + } + return new HyperlinkHighlightAction(); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/condition/NewRealValuePane.java b/designer/src/com/fr/design/condition/NewRealValuePane.java new file mode 100644 index 000000000..840bbcc13 --- /dev/null +++ b/designer/src/com/fr/design/condition/NewRealValuePane.java @@ -0,0 +1,42 @@ +package com.fr.design.condition; + +import com.fr.design.editor.ValueEditorPane; +import com.fr.design.editor.ValueEditorPaneFactory; +import com.fr.design.gui.ilable.UILabel; +import com.fr.general.Inter; +import com.fr.report.cell.cellattr.highlight.HighlightAction; +import com.fr.report.cell.cellattr.highlight.ValueHighlightAction; + +/** +* @author richie +* @date 2015-03-26 +* @since 8.0 +*/ +public class NewRealValuePane extends ConditionAttrSingleConditionPane { + private ValueEditorPane valueEditor; + + public NewRealValuePane(ConditionAttributesPane conditionAttributesPane) { + super(conditionAttributesPane); + this.add(new UILabel(Inter.getLocText("FR-Designer_New_Value") + ":")); + valueEditor = ValueEditorPaneFactory.createBasicValueEditorPane(); + this.add(valueEditor); + } + + @Override + public String nameForPopupMenuItem() { + return Inter.getLocText("FR-Designer_New_Value"); + } + + @Override + protected String title4PopupWindow() { + return nameForPopupMenuItem(); + } + + public void populate(HighlightAction ha) { + this.valueEditor.populate(((ValueHighlightAction)ha).getValue()); + } + + public HighlightAction update() { + return new ValueHighlightAction(this.valueEditor.update()); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/condition/PaddingPane.java b/designer/src/com/fr/design/condition/PaddingPane.java new file mode 100644 index 000000000..89f0dd1e0 --- /dev/null +++ b/designer/src/com/fr/design/condition/PaddingPane.java @@ -0,0 +1,84 @@ +package com.fr.design.condition; + +import com.fr.design.ExtraDesignClassManager; +import com.fr.design.fun.IndentationUnitProcessor; +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.style.DefaultIndentationUnitProcessor; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.general.Inter; +import com.fr.report.cell.cellattr.highlight.HighlightAction; +import com.fr.report.cell.cellattr.highlight.PaddingHighlightAction; + +import javax.swing.*; + +/** +* @author richie +* @date 2015-03-26 +* @since 8.0 +*/ +public class PaddingPane extends ConditionAttrSingleConditionPane { + private UILabel paddingLeft; + private UIBasicSpinner paddingLeftSpinner; + private UILabel paddingRight; + private UIBasicSpinner paddingRightSpinner; + private UIComboBox paddingScopeComboBox; + private IndentationUnitProcessor indentationUnitProcessor = null; + + public PaddingPane(ConditionAttributesPane conditionAttributesPane) { + super(conditionAttributesPane); + paddingLeft = new UILabel(Inter.getLocText("Style-Left_Indent") + ":"); + paddingLeftSpinner = new UIBasicSpinner(new SpinnerNumberModel(2, 0, Integer.MAX_VALUE, 1)); + GUICoreUtils.setColumnForSpinner(paddingLeftSpinner, 5); + paddingRight = new UILabel(Inter.getLocText("Style-Right_Indent") + ":"); + paddingRightSpinner = new UIBasicSpinner(new SpinnerNumberModel(2, 0, Integer.MAX_VALUE, 1)); + GUICoreUtils.setColumnForSpinner(paddingRightSpinner, 5); + this.add(paddingLeft); + this.add(paddingLeftSpinner); + this.add(paddingRight); + this.add(paddingRightSpinner); + this.paddingScopeComboBox = new UIComboBox(new String[] { + Inter.getLocText("Utils-Current_Cell"), + Inter.getLocText("Utils-Current_Row"), + Inter.getLocText("Utils-Current_Column") }); + this.add(this.paddingScopeComboBox); + this.paddingLeftSpinner.setValue(new Integer(0)); + this.paddingRightSpinner.setValue(new Integer(0)); + + this.indentationUnitProcessor = ExtraDesignClassManager.getInstance().getIndentationUnitEditor(); + if (null == this.indentationUnitProcessor) { + this.indentationUnitProcessor = new DefaultIndentationUnitProcessor(); + } + } + + /** + * 弹出窗口菜单命名 + * @return 菜单名 + */ + @Override + public String nameForPopupMenuItem() { + return Inter.getLocText("FR-Designer_Sytle-Indentation"); + } + + @Override + protected String title4PopupWindow() { + return nameForPopupMenuItem(); + } + + public void populate(HighlightAction ha) { + int leftPadding = indentationUnitProcessor.paddingUnitProcessor(((PaddingHighlightAction) ha).getPaddingLeft()); + int rightPadding = indentationUnitProcessor.paddingUnitProcessor(((PaddingHighlightAction) ha).getPaddingRight()); + this.paddingLeftSpinner.setValue(new Integer(leftPadding)); + this.paddingRightSpinner.setValue(new Integer(rightPadding)); + this.paddingScopeComboBox.setSelectedIndex(((PaddingHighlightAction) ha).getScope()); + } + + public HighlightAction update() { + int leftPadding = indentationUnitProcessor.paddingUnitGainFromSpinner((Integer)this.paddingLeftSpinner.getValue()); + int rightPadding = indentationUnitProcessor.paddingUnitGainFromSpinner((Integer)this.paddingRightSpinner.getValue()); + return new PaddingHighlightAction(Integer.valueOf(leftPadding), Integer.valueOf(rightPadding), + this.paddingScopeComboBox.getSelectedIndex()); + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/condition/PagePane.java b/designer/src/com/fr/design/condition/PagePane.java new file mode 100644 index 000000000..e09c848d8 --- /dev/null +++ b/designer/src/com/fr/design/condition/PagePane.java @@ -0,0 +1,49 @@ +package com.fr.design.condition; + +import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.gui.ilable.UILabel; +import com.fr.general.Inter; +import com.fr.report.cell.cellattr.highlight.HighlightAction; +import com.fr.report.cell.cellattr.highlight.PageHighlightAction; + +/** +* @author richie +* @date 2015-03-26 +* @since 8.0 +*/ +public class PagePane extends ConditionAttrSingleConditionPane { + private UILabel pageLabel; + private UIComboBox pageComboBox; + + public PagePane(ConditionAttributesPane conditionAttributesPane) { + super(conditionAttributesPane); + pageLabel = new UILabel(Inter.getLocText("FR-Designer_Pagination") + ":"); + this.add(pageLabel); + this.pageComboBox = new UIComboBox(new String[] { + Inter.getLocText("Utils-No_Pagination"), + Inter.getLocText("CellWrite-Page_After_Row"), + Inter.getLocText("CellWrite-Page_Before_Row"), + Inter.getLocText("CellWrite-Page_After_Column"), + Inter.getLocText("CellWrite-Page_Before_Column") }); + this.add(this.pageComboBox); + this.pageComboBox.setSelectedIndex(0); + } + + @Override + public String nameForPopupMenuItem() { + return Inter.getLocText("FR-Designer_Pagination"); + } + + @Override + protected String title4PopupWindow() { + return nameForPopupMenuItem(); + } + + public void populate(HighlightAction ha) { + this.pageComboBox.setSelectedIndex(((PageHighlightAction) ha).getPage()); + } + + public HighlightAction update() { + return new PageHighlightAction(this.pageComboBox.getSelectedIndex()); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/condition/PresentHighlightPane.java b/designer/src/com/fr/design/condition/PresentHighlightPane.java new file mode 100644 index 000000000..d00515501 --- /dev/null +++ b/designer/src/com/fr/design/condition/PresentHighlightPane.java @@ -0,0 +1,117 @@ +package com.fr.design.condition; + +import com.fr.base.present.Present; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.editor.ValueEditorPane; +import com.fr.design.editor.ValueEditorPaneFactory; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.present.PresentPane; +import com.fr.general.Inter; +import com.fr.report.cell.cellattr.NormalPresent; +import com.fr.report.cell.cellattr.PresentConstants; +import com.fr.report.cell.cellattr.highlight.HighlightAction; +import com.fr.report.cell.cellattr.highlight.PresentHighlightAction; + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; + +/** +* @author richie +* @date 2015-03-26 +* @since 8.0 +*/ +public class PresentHighlightPane extends ConditionAttrSingleConditionPane { + private UIComboBox presentComboBox; + private Present present; + private UIButton editButton; + private ValueEditorPane valueEditor; + + public PresentHighlightPane(final ConditionAttributesPane conditionAttributesPane) { + super(conditionAttributesPane); + this.add(new UILabel(Inter.getLocText("FR-Designer_Present") + ":")); + + String[] typeArray = {PresentConstants.NORMAL, Inter.getLocText(new String[]{"Other", "Present"})}; + presentComboBox = new UIComboBox(typeArray); + this.add(presentComboBox); + + editButton = new UIButton(Inter.getLocText("FR-Designer_Edit")); +// this.add(this.valueTextField); +// this.add(editButton); + + editButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (presentComboBox.getSelectedIndex() != 0) { + final PresentPane presentPane = new PresentPane(); + presentPane.populateBean(present); + BasicDialog dialog = presentPane.showWindow(SwingUtilities.getWindowAncestor(conditionAttributesPane)); + dialog.addDialogActionListener(new DialogActionAdapter() { + @Override + public void doOk() { + present = presentPane.updateBean(); + } + }); + dialog.setVisible(true); + } + } + }); +// this.valueTextField.setText(""); + valueEditor = ValueEditorPaneFactory.createBasicValueEditorPane(); + this.add(valueEditor); + presentComboBox.addItemListener(new ItemListener() { + public void itemStateChanged(ItemEvent e) { + if (presentComboBox.getSelectedIndex() == 1){ + if (valueEditor.getParent() == PresentHighlightPane.this) { + PresentHighlightPane.this.remove(valueEditor); + } + + PresentHighlightPane.this.add(editButton); + PresentHighlightPane.this.validate(); + PresentHighlightPane.this.repaint(); + } else { + if (editButton.getParent() == PresentHighlightPane.this) { + PresentHighlightPane.this.remove(editButton); + } + + PresentHighlightPane.this.add(valueEditor); + PresentHighlightPane.this.validate(); + PresentHighlightPane.this.repaint(); + } + } + }); + } + + @Override + public String nameForPopupMenuItem() { + return Inter.getLocText("FR-Designer_Present"); + } + + @Override + protected String title4PopupWindow() { + return nameForPopupMenuItem(); + } + + public void populate(HighlightAction ha) { + present = ((PresentHighlightAction)ha).getPresent(); + if (!(present instanceof NormalPresent)) { + presentComboBox.setSelectedIndex(1); + } else { + presentComboBox.setSelectedIndex(0); + valueEditor.populate(((NormalPresent)present).getNormalPresent()); + } + } + + public HighlightAction update() { + if (presentComboBox.getSelectedIndex() == 0) { + if (this.valueEditor.update() instanceof String) { + present = new NormalPresent(this.valueEditor.update()); + } + } + return new PresentHighlightAction(present); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/condition/RowHeightPane.java b/designer/src/com/fr/design/condition/RowHeightPane.java new file mode 100644 index 000000000..bd46cea71 --- /dev/null +++ b/designer/src/com/fr/design/condition/RowHeightPane.java @@ -0,0 +1,30 @@ +package com.fr.design.condition; + +import com.fr.design.gui.ispinner.UIBasicSpinner; +import com.fr.general.Inter; +import com.fr.report.cell.cellattr.highlight.HighlightAction; +import com.fr.report.cell.cellattr.highlight.RowHeightHighlightAction; +import com.fr.stable.unit.UNIT; + +/** +* @author richie +* @date 2015-03-26 +* @since 8.0 +*/ +public class RowHeightPane extends WHPane { + private UIBasicSpinner rowHeightSpinner; + + public RowHeightPane(ConditionAttributesPane conditionAttributesPane) { + super(conditionAttributesPane, Inter.getLocText("Utils-Row_Height")); + } + + @Override + protected UNIT getUnit(HighlightAction ha) { + return ((RowHeightHighlightAction) ha).getRowHeight(); + } + + @Override + protected HighlightAction returnAction(UNIT unit) { + return new RowHeightHighlightAction(unit); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/condition/WHPane.java b/designer/src/com/fr/design/condition/WHPane.java new file mode 100644 index 000000000..4769833fc --- /dev/null +++ b/designer/src/com/fr/design/condition/WHPane.java @@ -0,0 +1,109 @@ +package com.fr.design.condition; + +import com.fr.design.DesignerEnvManager; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.ispinner.UIBasicSpinner; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.general.Inter; +import com.fr.report.cell.cellattr.highlight.HighlightAction; +import com.fr.stable.Constants; +import com.fr.stable.unit.*; + +import javax.swing.*; +import java.math.BigDecimal; + +/** +* @author richie +* @date 2015-03-26 +* @since 8.0 +*/ +public abstract class WHPane extends ConditionAttrSingleConditionPane { + protected UILabel unitLabel; + private UIBasicSpinner spinner; + private String locString; + + protected WHPane(ConditionAttributesPane conditionAttributesPane, String locString) { + super(conditionAttributesPane); + this.add(new UILabel(Inter.getLocText(locString) + ":")); + this.add(spinner = new UIBasicSpinner(new SpinnerNumberModel(0, 0,Integer.MAX_VALUE, 1))); + this.add(this.unitLabel = new UILabel(getUnitString())); + GUICoreUtils.setColumnForSpinner(spinner, 5); + this.spinner.setValue(new Integer(0)); + this.locString = locString; + } + + @Override + public String nameForPopupMenuItem() { + return locString; + } + + @Override + protected String title4PopupWindow() { + return nameForPopupMenuItem(); + } + + public void populate(HighlightAction ha, JSpinner sp) { + int unitType = DesignerEnvManager.getEnvManager().getReportLengthUnit(); + UNIT width = getUnit(ha); + double va; + if (unitType == Constants.UNIT_CM) { + va = width.toCMValue4Scale2(); + unitLabel.setText(Inter.getLocText("FR-Designer_Unit_CM")); + } else if (unitType == Constants.UNIT_INCH) { + va = width.toINCHValue4Scale3(); + unitLabel.setText(Inter.getLocText("FR-Designer_Unit_INCH")); + } else if (unitType == Constants.UNIT_PT) { + va = width.toPTValue4Scale2(); + unitLabel.setText(Inter.getLocText("FR-Designer_Unit_PT")); + } else { + va = width.toMMValue4Scale2(); + unitLabel.setText(Inter.getLocText("FR-Designer_Unit_MM")); + } + // 只保留两位 + Float d = new Float(new BigDecimal(va + "").setScale(2, BigDecimal.ROUND_DOWN).floatValue()); + sp.setValue(d); + } + + protected abstract UNIT getUnit(HighlightAction ha); + + protected String getUnitString() { + int unitType = DesignerEnvManager.getEnvManager().getReportLengthUnit(); + if (unitType == Constants.UNIT_CM) { + return Inter.getLocText("FR-Designer_Unit_CM"); + } else if (unitType == Constants.UNIT_INCH) { + return Inter.getLocText("FR-Designer_Unit_INCH"); + } else if (unitType == Constants.UNIT_PT) { + return Inter.getLocText("FR-Designer_Unit_PT"); + } else { + return Inter.getLocText("FR-Designer_Unit_MM"); + } + } + + public HighlightAction update(UIBasicSpinner sp) { + float newWidth = ((Number)sp.getValue()).floatValue(); + // 只保留两位 + newWidth = new Float(new BigDecimal(newWidth + "").setScale(2, BigDecimal.ROUND_DOWN).floatValue()); + int unitType = DesignerEnvManager.getEnvManager().getReportLengthUnit(); + UNIT width; + if (unitType == Constants.UNIT_CM) { + width = new CM(newWidth); + } else if (unitType == Constants.UNIT_INCH) { + width = new INCH(newWidth); + } else if (unitType == Constants.UNIT_PT) { + width = new PT(newWidth); + } else { + width = new MM(newWidth); + } + return returnAction(width); + } + + public void populate(HighlightAction ha) { + this.populate(ha, spinner); + } + + public HighlightAction update() { + return this.update(spinner); + } + + protected abstract HighlightAction returnAction(UNIT unit); +} \ No newline at end of file diff --git a/designer/src/com/fr/design/condition/WidgetHighlightPane.java b/designer/src/com/fr/design/condition/WidgetHighlightPane.java new file mode 100644 index 000000000..da3b747e4 --- /dev/null +++ b/designer/src/com/fr/design/condition/WidgetHighlightPane.java @@ -0,0 +1,163 @@ +package com.fr.design.condition; + +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.gui.ibutton.UIButton; +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.widget.WidgetPane; +import com.fr.form.ui.*; +import com.fr.general.Inter; +import com.fr.report.cell.cellattr.highlight.HighlightAction; +import com.fr.report.cell.cellattr.highlight.WidgetHighlightAction; + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/** +* @author richie +* @date 2015-03-26 +* @since 8.0 +*/ +public class WidgetHighlightPane extends ConditionAttrSingleConditionPane { + private static final int DIALOG_WIDTH = 700; + private static final int DIALOG_HEIGHT = 400; + + private Widget widget; + private UIComboBox box; + private UICheckBox useWidget; + private UIButton widgetButton; + + public WidgetHighlightPane(final ConditionAttributesPane conditionAttributesPane) { + super(conditionAttributesPane); + widgetButton = new UIButton(Inter.getLocText("FR-Designer_Edit")); + widgetButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + final WidgetPane widgetPane = new WidgetPane(); + widgetPane.populate(widget); + BasicDialog dialog = widgetPane.showWindow( + SwingUtilities.getWindowAncestor(conditionAttributesPane)); + dialog.addDialogActionListener(new DialogActionAdapter() { + public void doOk() { + widget = widgetPane.update(); + setComboBox(); + } + }); + dialog.setVisible(true); + } + }); + + UILabel widgetLabel = new UILabel(Inter.getLocText("FR-Designer_Widget") + ":"); + this.add(widgetLabel); + String[] editorTypes = new String[] { + "", + Inter.getLocText("FR-Designer_Text"), + Inter.getLocText("FR-Designer_Form-TextArea"), + Inter.getLocText("FR-Designer_Number"), + Inter.getLocText("FR-Designer_Form-Password"), + Inter.getLocText("FR-Designer_Form-Button"), + Inter.getLocText("FR-Designer_Form-CheckBox"), + Inter.getLocText("FR-Designer_Form-RadioGroup"), + Inter.getLocText("FR-Designer_Form-CheckBoxGroup"), + Inter.getLocText("FR-Designer_ComboBox"), + Inter.getLocText("FR-Designer_Form-ComboCheckBox"), + Inter.getLocText("FR-Designer_Date"), + Inter.getLocText("FR-Designer_File"), + Inter.getLocText("FR-Designer_Form-List"), + Inter.getLocText("FR-Designer_Form-Iframe"), + Inter.getLocText("FR-Designer_Tree-ComboBox"), + Inter.getLocText("Form-View_Tree") + }; + box = new UIComboBox(editorTypes); + this.add(box); + box.setEnabled(false); + this.add(widgetButton); + widgetButton.setEnabled(false); + useWidget = new UICheckBox(Inter.getLocText(new String[]{"Use", "Widget"})); + this.add(useWidget); + useWidget.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (!useWidget.isSelected()) { + box.setSelectedIndex(0); + widgetButton.setEnabled(false); + } else { + setComboBox(); + widgetButton.setEnabled(true); + } + } + + }); + } + + @Override + public String nameForPopupMenuItem() { + return Inter.getLocText("FR-Designer_Widget"); + } + + @Override + protected String title4PopupWindow() { + return nameForPopupMenuItem(); + } + + + public void setComboBox() { + Widget value = this.widget; + + if (value instanceof ComboCheckBox) { + box.setSelectedItem(Inter.getLocText("FR-Designer_Form-ComboCheckBox")); + } else if (value instanceof ComboBox) { + box.setSelectedItem(Inter.getLocText("FR-Designer_ComboBox")); + } else if (value instanceof NumberEditor) { + box.setSelectedItem(Inter.getLocText("FR-Designer_Number")); + } else if (value instanceof IframeEditor) { + box.setSelectedItem(Inter.getLocText("FR-Designer_Form-Iframe")); + } else if (value instanceof FreeButton) { + box.setSelectedItem(Inter.getLocText("FR-Designer_Form-Button")); + } else if (value instanceof DateEditor) { + box.setSelectedItem(Inter.getLocText("FR-Designer_Date")); + } else if (value instanceof CheckBox) { + box.setSelectedItem(Inter.getLocText("FR-Designer_Form-CheckBox")); + } else if (value instanceof RadioGroup) { + box.setSelectedItem(Inter.getLocText("FR-Designer_Form-RadioGroup")); + } else if (value instanceof CheckBoxGroup) { + box.setSelectedItem(Inter.getLocText("FR-Designer_Form-CheckBoxGroup")); + } else if (value instanceof MultiFileEditor) { + box.setSelectedItem(Inter.getLocText("FR-Designer_File")); + } else if (value instanceof ListEditor) { + box.setSelectedItem(Inter.getLocText("FR-Designer_Form-List")); + } else if (value instanceof TreeComboBoxEditor) { + box.setSelectedItem(Inter.getLocText("FR-Designer_Tree-ComboBox")); + } else if (value instanceof TreeEditor) { + box.setSelectedItem(Inter.getLocText("Form-View_Tree")); + } else if (value instanceof Password) { + box.setSelectedItem(Inter.getLocText("FR-Designer_Form-Password")); + } else if (value instanceof TextArea) { + box.setSelectedItem(Inter.getLocText("FR-Designer_Form-TextArea")); + } else if (value instanceof TextEditor) { + box.setSelectedItem(Inter.getLocText("FR-Designer_Text")); + } + } + + public void populate(HighlightAction ha) { + this.widget = ((WidgetHighlightAction)ha).getWidget(); + if (widget == null) { + useWidget.setSelected(false); + box.setSelectedIndex(0); + widgetButton.setEnabled(false); + } else { + useWidget.setSelected(true); + setComboBox(); + widgetButton.setEnabled(true); + } + } + + public HighlightAction update() { + if (useWidget.isSelected()) { + return new WidgetHighlightAction(widget); + } + return new WidgetHighlightAction(); + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/dscolumn/DSColumnAdvancedPane.java b/designer/src/com/fr/design/dscolumn/DSColumnAdvancedPane.java new file mode 100644 index 000000000..0c3d6f9d7 --- /dev/null +++ b/designer/src/com/fr/design/dscolumn/DSColumnAdvancedPane.java @@ -0,0 +1,548 @@ +package com.fr.design.dscolumn; + +import com.fr.base.Formula; +import com.fr.data.util.SortOrder; +import com.fr.design.data.DesignTableDataManager; +import com.fr.design.dialog.BasicPane; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.formula.*; +import com.fr.design.gui.ibutton.UIButton; +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.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.utils.gui.GUICoreUtils; +import com.fr.general.Inter; +import com.fr.report.cell.CellElement; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.cell.cellattr.CellExpandAttr; +import com.fr.report.cell.cellattr.core.group.DSColumn; +import com.fr.report.cell.cellattr.core.group.SelectCount; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class DSColumnAdvancedPane extends BasicPane { + + private static final String InsetText = " "; + private SortPane sortPane; + private SelectCountPane selectCountPane; + private ValuePane valuePane; + private UICheckBox horizontalExtendableCheckBox; + private UICheckBox verticalExtendableCheckBox; +// private UICheckBox isCoverCheckBox; + private UICheckBox useMultiplyNumCheckBox; + private UISpinner multiNumSpinner; + + public DSColumnAdvancedPane() { + this(DSColumnPane.SETTING_ALL); + } + + public DSColumnAdvancedPane(int setting) { + this.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + + sortPane = new SortPane(); + sortPane.setBorder(GUICoreUtils.createTitledBorder(Inter.getLocText("Sort-Sort_Order"),null)); + + if (setting > DSColumnPane.SETTING_DSRELATED) { + selectCountPane = new SelectCountPane(); + selectCountPane.setBorder(GUICoreUtils.createTitledBorder(Inter.getLocText("BindColumn-Results_Filter"),null)); + } + + valuePane = new ValuePane(); + valuePane.setBorder(GUICoreUtils.createTitledBorder(Inter.getLocText("BindColumn-Custom_Data_Appearance"),null)); + + + JPanel extendablePane = null; + if (setting > DSColumnPane.SETTING_DSRELATED) { + // extendableDirectionPane + JPanel extendableDirectionPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); + + extendableDirectionPane.add(horizontalExtendableCheckBox = new UICheckBox(Inter.getLocText("ExpandD-Horizontal_Extendable"))); + extendableDirectionPane.add(verticalExtendableCheckBox = new UICheckBox(Inter.getLocText("ExpandD-Vertical_Extendable"))); + + extendablePane = FRGUIPaneFactory.createTitledBorderPane(Inter.getLocText("ExpandD-Expandable")); + extendablePane.setLayout(new BorderLayout()); + extendablePane.add(extendableDirectionPane, BorderLayout.CENTER); + } + + JPanel multiNumPane = null; + if (setting > DSColumnPane.SETTING_DSRELATED) { + multiNumPane = FRGUIPaneFactory.createTitledBorderPane(Inter.getLocText("Fill_blank_Data")); + useMultiplyNumCheckBox = new UICheckBox(Inter.getLocText("Column_Multiple")); + multiNumPane.add(useMultiplyNumCheckBox); + multiNumPane.add(new UILabel(InsetText)); + + multiNumSpinner = new UISpinner(1, 10000, 1, 1); + multiNumPane.add(multiNumSpinner); + + useMultiplyNumCheckBox.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + checkButtonEnabled(); + } + }); + } + + double[] rowSize = {TableLayout.PREFERRED, TableLayout.PREFERRED, + TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED}; + double[] columnSize = {TableLayout.FILL}; + + Component[][] components = null; + if (setting > DSColumnPane.SETTING_DSRELATED) { + components = new Component[][]{ + {sortPane}, + {selectCountPane}, + {valuePane}, + {extendablePane}, + {multiNumPane} + }; + } else { + components = new Component[][]{ + {sortPane}, + {valuePane} + }; + } + this.add(TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize), BorderLayout.CENTER); + } + + @Override + protected String title4PopupWindow() { + return Inter.getLocText("Advanced"); + } + + public void populate(TemplateCellElement cellElement) { + if (cellElement == null) { + return; + } + + sortPane.populate(cellElement); + valuePane.populate(cellElement); + + if (selectCountPane != null) { + selectCountPane.populate(cellElement); + + CellExpandAttr cellExpandAttr = cellElement.getCellExpandAttr(); + if (cellExpandAttr == null) { + cellExpandAttr = new CellExpandAttr(); + cellElement.setCellExpandAttr(cellExpandAttr); + } + + // extendable + switch (cellExpandAttr.getExtendable()) { + case CellExpandAttr.Both_EXTENDABLE: + horizontalExtendableCheckBox.setSelected(true); + verticalExtendableCheckBox.setSelected(true); + break; + case CellExpandAttr.Vertical_EXTENDABLE: + horizontalExtendableCheckBox.setSelected(false); + verticalExtendableCheckBox.setSelected(true); + break; + case CellExpandAttr.Horizontal_EXTENDABLE: + horizontalExtendableCheckBox.setSelected(true); + verticalExtendableCheckBox.setSelected(false); + break; + default: { + horizontalExtendableCheckBox.setSelected(false); + verticalExtendableCheckBox.setSelected(false); + } + + } + + if (cellExpandAttr.getMultipleNumber() == -1) { + this.useMultiplyNumCheckBox.setSelected(false); + } else { + this.useMultiplyNumCheckBox.setSelected(true); + this.multiNumSpinner.setValue(cellExpandAttr.getMultipleNumber()); + } + + this.checkButtonEnabled(); + } + } + + public void update(TemplateCellElement cellElement) { + if (cellElement == null) { + return; + } + + sortPane.update(cellElement); + valuePane.update(cellElement); + + if (selectCountPane != null) { + selectCountPane.update(cellElement); + + CellExpandAttr cellExpandAttr = cellElement.getCellExpandAttr(); + if (cellExpandAttr == null) { + cellExpandAttr = new CellExpandAttr(); + cellElement.setCellExpandAttr(cellExpandAttr); + } + + // extendable + if (horizontalExtendableCheckBox.isSelected()) { + if (verticalExtendableCheckBox.isSelected()) { + cellExpandAttr.setExtendable(CellExpandAttr.Both_EXTENDABLE); + } else { + cellExpandAttr.setExtendable(CellExpandAttr.Horizontal_EXTENDABLE); + } + } else { + if (verticalExtendableCheckBox.isSelected()) { + cellExpandAttr.setExtendable(CellExpandAttr.Vertical_EXTENDABLE); + } else { + cellExpandAttr.setExtendable(CellExpandAttr.None_EXTENDABLE); + } + } + + if (this.useMultiplyNumCheckBox.isSelected()) { + cellExpandAttr.setMultipleNumber((int) this.multiNumSpinner.getValue()); + } else { + cellExpandAttr.setMultipleNumber(-1); + } + } + } + + private static class SortPane extends SortFormulaPane { + private CellElement cellElement; + + @Override + public void formulaAction() { + if (cellElement == null) { + return; + } + Object value = cellElement.getValue(); + if (value == null || !(value instanceof DSColumn)) { + return; + } + + String[] displayNames = DesignTableDataManager.getSelectedColumnNames( + DesignTableDataManager.getEditingTableDataSource(), ((DSColumn) value).getDSName()); + + showFormulaDialog(displayNames); + } + + void populate(CellElement cellElement) { + if (cellElement == null) { + return; + } + this.cellElement = cellElement; + + Object value = cellElement.getValue(); + if (value == null || !(value instanceof DSColumn)) { + return; + } + DSColumn dSColumn = (DSColumn) value; + + int sort = dSColumn.getOrder(); + this.sortOrderComboBox.setSortOrder(new SortOrder(sort)); + + String sortFormula = dSColumn.getSortFormula(); + if (sortFormula != null && sortFormula.length() >= 1) { + sortFormulaTextField.setText(sortFormula); + } else { + sortFormulaTextField.setText(sortFormula); + } + } + + public void update(CellElement cellElement) { + if (cellElement == null) { + return; + } + Object value = cellElement.getValue(); + if (value == null || !(value instanceof DSColumn)) { + return; + } + DSColumn dSColumn = (DSColumn) (cellElement.getValue()); + + dSColumn.setOrder(this.sortOrderComboBox.getSortOrder().getOrder()); + //lance:sort formula + + String sText = null; + if (!(sortFormulaTextField.getText() == null || sortFormulaTextField.getText().trim().equals("") || sortFormulaTextField.getText().trim().equals("$$$"))) { + sText = new String(sortFormulaTextField.getText()); + } + if (!(sText == null || sText.length() < 1)) { + dSColumn.setSortFormula(sText); + } else { + dSColumn.setSortFormula(null); + } + } + } + + private static class SelectCountPane extends JPanel { + + CellElement cellElement; + // private Comparator sortComparator; + private UIComboBox selectCountComboBox; + private JPanel selectCountCardPane; + private UITextField serialTextField; + + JFormulaField topFormulaPane; + JFormulaField bottomFormulaPane; + + public SelectCountPane() { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + + selectCountComboBox = new UIComboBox(new String[]{ + Inter.getLocText("Undefined"), + Inter.getLocText("BindColumn-Top_N"), + Inter.getLocText("BindColumn-Bottom_N"), + Inter.getLocText("Odd"), + Inter.getLocText("Even"), + Inter.getLocText("Specify"),}); + selectCountComboBox.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent evt) { + int selectIndex = selectCountComboBox.getSelectedIndex(); + CardLayout c1 = (CardLayout) selectCountCardPane.getLayout(); + if (selectIndex == 1) { + c1.show(selectCountCardPane, "TOP"); + } else if (selectIndex == 2) { + c1.show(selectCountCardPane, "BOTTOM"); + } else if (selectIndex == 3) { + c1.show(selectCountCardPane, "ODD"); + } else if (selectIndex == 4) { + c1.show(selectCountCardPane, "EVEN"); + } else if (selectIndex == 5) { + c1.show(selectCountCardPane, "SPECIFY"); + } else { + c1.show(selectCountCardPane, "UNDEFINE"); + } + } + }); + + selectCountCardPane =FRGUIPaneFactory.createCardLayout_S_Pane(); + this.add(GUICoreUtils.createFlowPane(new JComponent[]{new UILabel(InsetText), selectCountComboBox, + new UILabel(InsetText), selectCountCardPane}, FlowLayout.LEFT), BorderLayout.WEST); +// selectCountCardPane.setLayout(new CardLayout()); + + //not define pane + + JPanel undefinedPane = GUICoreUtils.createFlowPane(new UILabel(Inter.getLocText("Undefined")), FlowLayout.LEFT); + topFormulaPane = new JFormulaField("-1"); + bottomFormulaPane = new JFormulaField("-1"); + serialTextField = new UITextField(18); + JPanel oddPane = GUICoreUtils.createFlowPane(new UILabel(Inter.getLocText("BindColumn-Result_Serial_Number_Start_From_1") + + " " + Inter.getLocText("BindColumn-Odd_Selected_(1,3,5...)")), FlowLayout.LEFT); + JPanel evenPane = GUICoreUtils.createFlowPane(new UILabel(Inter.getLocText("BindColumn-Result_Serial_Number_Start_From_1") + + " " + Inter.getLocText("BindColumn-Even_Selected_(2,4,6...)")), FlowLayout.LEFT); + JPanel specifyPane = GUICoreUtils.createFlowPane(new JComponent[]{ + serialTextField, new UILabel( + Inter.getLocText(new String[]{ + "Format", "BindColumn-Result_Serial_Number_Start_From_1", "Inner_Parameter", "Group_Count"}, + new String[]{": 1,2-3,5,8 ", ",", "$__count__"}) + ) + }, FlowLayout.LEFT); + serialTextField.setToolTipText(Inter.getLocText("StyleFormat-Sample") + ":=JOINARRAY(GREPARRAY(RANGE($__count__), item!=4), \",\")"); + selectCountCardPane.add(undefinedPane, "UNDEFINE"); + selectCountCardPane.add(topFormulaPane, "TOP"); + selectCountCardPane.add(bottomFormulaPane, "BOTTOM"); + //odd + selectCountCardPane.add(oddPane, "ODD"); + //even + selectCountCardPane.add(evenPane, "EVEN"); + //specify + selectCountCardPane.add(specifyPane, "SPECIFY"); + } + + public void populate(CellElement cellElement) { + if (cellElement == null) { + return; + } + this.cellElement = cellElement; + + Object value = cellElement.getValue(); + if (value == null || !(value instanceof DSColumn)) { + return; + } + DSColumn dSColumn = (DSColumn) (cellElement.getValue()); + SelectCount selectCount = dSColumn.getSelectCount(); + this.topFormulaPane.populateElement(cellElement); + this.bottomFormulaPane.populateElement(cellElement); + if (selectCount != null) { + int selectCountType = selectCount.getType(); + this.selectCountComboBox.setSelectedIndex(selectCountType); + if (selectCountType == SelectCount.TOP) { + this.topFormulaPane.populate(selectCount.getFormulaCount()); + } else if (selectCountType == SelectCount.BOTTOM) { + this.bottomFormulaPane.populate(selectCount.getFormulaCount()); + } else if (selectCountType == SelectCount.SPECIFY) { + this.serialTextField.setText(selectCount.getSerial()); + } + } + } + + public void update(CellElement cellElement) { + if (cellElement == null) { + return; + } + Object value = cellElement.getValue(); + if (value == null || !(value instanceof DSColumn)) { + return; + } + DSColumn dSColumn = (DSColumn) (cellElement.getValue()); + + //alex:SelectCount + int selectCountSelectIndex = this.selectCountComboBox.getSelectedIndex(); + if (selectCountSelectIndex == 0) { + dSColumn.setSelectCount(null); + } else { + SelectCount selectCount = new SelectCount(); + dSColumn.setSelectCount(selectCount); + selectCount.setType(selectCountSelectIndex); + if (selectCountSelectIndex == SelectCount.TOP) { + selectCount.setFormulaCount(this.topFormulaPane.getFormulaText()); + } else if (selectCountSelectIndex == SelectCount.BOTTOM) { + selectCount.setFormulaCount(this.bottomFormulaPane.getFormulaText()); + } else if (selectCountSelectIndex == SelectCount.SPECIFY) { + selectCount.setSerial(this.serialTextField.getText()); + } + } + } + + private JFormattedTextField getTextField(JSpinner spinner) { + JComponent editor = spinner.getEditor(); + if (editor instanceof JSpinner.DefaultEditor) { + return ((JSpinner.DefaultEditor) editor).getTextField(); + } else { + System.err.println("Unexpected editor type: " + + spinner.getEditor().getClass() + + " isn't a descendant of DefaultEditor"); + return null; + } + } + } + + private static class JFormulaField extends JPanel { + private CellElement cellElement; + private UITextField formulaTextField; + private String defaultValue; + + public JFormulaField(String defaultValue) { + this.defaultValue = defaultValue; + + this.setLayout(FRGUIPaneFactory.createBoxFlowLayout()); + UILabel bottomLabel = new UILabel("="); + bottomLabel.setFont(new Font("Dialog", Font.BOLD, 12)); + this.add(bottomLabel); + formulaTextField = new UITextField(24); + this.add(formulaTextField); + formulaTextField.setText(defaultValue); + + UIButton bottomFrmulaButton = new UIButton("..."); + this.add(bottomFrmulaButton); + bottomFrmulaButton.setToolTipText(Inter.getLocText("Formula") + "..."); + bottomFrmulaButton.setPreferredSize(new Dimension(25, formulaTextField.getPreferredSize().height)); + bottomFrmulaButton.addActionListener(formulaButtonActionListener); + } + + public void populate(String formulaContent) { + this.formulaTextField.setText(formulaContent); + } + public void populateElement(CellElement cellElement) { + this.cellElement = cellElement; + } + + public String getFormulaText() { + return this.formulaTextField.getText(); + } + + private ActionListener formulaButtonActionListener = new ActionListener() { + + public void actionPerformed(ActionEvent evt) { + Formula valueFormula = new Formula(); + String text = formulaTextField.getText(); + if (text == null || text.length() <= 0) { + valueFormula.setContent(defaultValue); + } else { + valueFormula.setContent(text); + } + + final UIFormula formulaPane = FormulaFactory.createFormulaPaneWhenReserveFormula(); + + if (cellElement == null) { + return; + } + Object value = cellElement.getValue(); + if (value == null || !(value instanceof DSColumn)) { + return; + } + DSColumn dsColumn = (DSColumn) value; + + String[] displayNames = DesignTableDataManager.getSelectedColumnNames(DesignTableDataManager.getEditingTableDataSource(), dsColumn.getDSName()); + + formulaPane.populate(valueFormula, new CustomVariableResolver(displayNames, true)); + formulaPane.showLargeWindow(SwingUtilities.getWindowAncestor(JFormulaField.this), new DialogActionAdapter() { + @Override + public void doOk() { + Formula valueFormula = formulaPane.update(); + if (valueFormula.getContent().length() <= 1) { + formulaTextField.setText(defaultValue); + } else { + formulaTextField.setText(valueFormula.getContent().substring(1)); + } + } + }).setVisible(true); + } + }; + } + + private static class ValuePane extends JPanel { + private JFormulaField formulaField; + + public ValuePane() { + this.setLayout(FRGUIPaneFactory.createBoxFlowLayout()); + + this.add(new UILabel(InsetText + Inter.getLocText("Value") + ":")); + this.add(Box.createHorizontalStrut(2)); + this.add((formulaField = new JFormulaField("$$$"))); + } + + public void populate(CellElement cellElement) { + if (cellElement == null) { + return; + } + + Object value = cellElement.getValue(); + if (value == null || !(value instanceof DSColumn)) { + return; + } + DSColumn dSColumn = (DSColumn) value; + + //formula + String valueFormula = dSColumn.getResult(); + if (valueFormula == null) { + valueFormula = "$$$"; + } + formulaField.populateElement(cellElement); + formulaField.populate(valueFormula); + } + + public void update(CellElement cellElement) { + if (cellElement == null) { + return; + } + Object value = cellElement.getValue(); + if (value == null || !(value instanceof DSColumn)) { + return; + } + DSColumn dSColumn = (DSColumn) (cellElement.getValue()); + + //formula + dSColumn.setResult(this.formulaField.getFormulaText()); + } + } + + private void checkButtonEnabled() { + if (useMultiplyNumCheckBox.isSelected()) { + multiNumSpinner.setEnabled(true); + } else { + multiNumSpinner.setEnabled(false); + } + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/dscolumn/DSColumnBasicPane.java b/designer/src/com/fr/design/dscolumn/DSColumnBasicPane.java new file mode 100644 index 000000000..9ba61e547 --- /dev/null +++ b/designer/src/com/fr/design/dscolumn/DSColumnBasicPane.java @@ -0,0 +1,170 @@ +package com.fr.design.dscolumn; + +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.BorderFactory; + +import com.fr.data.TableDataSource; +import com.fr.design.expand.ConditionParentPane; +import com.fr.design.expand.ExpandDirectionPane; +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.general.Inter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.report.cell.CellElement; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.cell.cellattr.CellExpandAttr; +import com.fr.design.utils.gui.GUICoreUtils; + +public class DSColumnBasicPane extends BasicPane { + + private SelectedDataColumnPane selectDataColumnPane; + private ConditionParentPane conditionParentPane; + private ResultSetGroupPopUpPane resultSetGroupPane; + private ExpandDirectionPane expandDirectionPane; + private CellElement cellElement; + + public DSColumnBasicPane() { + this(DSColumnPane.SETTING_ALL); + } + + public DSColumnBasicPane(int setting) { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + this.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); + + if (setting > DSColumnPane.SETTING_DSRELATED) { + selectDataColumnPane = new SelectedDataColumnPane(); + } else { + selectDataColumnPane = new SelectedConfirmedDataColumnPane(); + } + + selectDataColumnPane.setBorder(GUICoreUtils.createTitledBorder(Inter.getLocText("Select_DataColumn"), null)); + + if (setting > DSColumnPane.SETTING_DSRELATED) { + conditionParentPane = new ConditionParentPane(); + conditionParentPane.setBorder(GUICoreUtils.createTitledBorder(Inter.getLocText("ParentCell_Setting"), null)); + } + + resultSetGroupPane = new ResultSetGroupPopUpPane(setting > DSColumnPane.SETTING_DSRELATED); + resultSetGroupPane.setBorder(GUICoreUtils.createTitledBorder(Inter.getLocText("Data_Setting"), null)); + + if (setting > DSColumnPane.SETTING_DSRELATED) { + expandDirectionPane = new ExpandDirectionPane(); + expandDirectionPane.setBorder(GUICoreUtils.createTitledBorder(Inter.getLocText("ExpandD-Expand_Direction"), null)); + } + + double[] rowSize = {TableLayout.PREFERRED, TableLayout.PREFERRED, + TableLayout.PREFERRED, TableLayout.PREFERRED}; + double[] columnSize = {TableLayout.FILL}; + + Component[][] components = null; + + if (setting > DSColumnPane.SETTING_DSRELATED) { + components = new Component[][]{ + {selectDataColumnPane}, + {conditionParentPane}, + {resultSetGroupPane}, + {expandDirectionPane} + }; + } else { + components = new Component[][]{ + {selectDataColumnPane}, + {resultSetGroupPane}, + }; + } + + this.add(TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize), BorderLayout.CENTER); + + this.resultSetGroupPane.addListeners(summary_direction_ActionListener, otherGroup_direction_ActionListener, sdcUpdate_ActionListener); + } + + @Override + protected String title4PopupWindow() { + return Inter.getLocText("Basic"); + } + + public void populate(TableDataSource source, TemplateCellElement cellElement) { + if (cellElement == null) { + return; + } + + this.cellElement = cellElement; + + selectDataColumnPane.populate(source, cellElement); + + CellExpandAttr cellExpandAttr = cellElement.getCellExpandAttr(); + if (conditionParentPane != null) { + conditionParentPane.populate(cellExpandAttr); + } + if (expandDirectionPane != null) { + expandDirectionPane.populate(cellExpandAttr); + } + + resultSetGroupPane.populate(cellElement); + + if (expandDirectionPane != null && resultSetGroupPane.isSummaryRadioButtonSelected()) { + expandDirectionPane.setNoneRadioButtonSelected(true); + } + } + + public void update(TemplateCellElement cellElement) { + if (cellElement == null) { + return; + } + + selectDataColumnPane.update(cellElement); + + // 设置父格和扩展方向 + CellExpandAttr cellExpandAttr = cellElement.getCellExpandAttr(); + + if (cellExpandAttr == null) { + cellExpandAttr = new CellExpandAttr(); + cellElement.setCellExpandAttr(cellExpandAttr); + } + + if (conditionParentPane != null) { + conditionParentPane.update(cellExpandAttr); + } + if (expandDirectionPane != null) { + expandDirectionPane.update(cellExpandAttr); + } + resultSetGroupPane.update(); + } + ActionListener summary_direction_ActionListener = new ActionListener() { + + public void actionPerformed(ActionEvent evt) { + if (expandDirectionPane != null) { + expandDirectionPane.setNoneRadioButtonSelected(true); + } + } + }; + ActionListener otherGroup_direction_ActionListener = new ActionListener() { + + public void actionPerformed(ActionEvent evt) { + if (expandDirectionPane != null) { + expandDirectionPane.setNoneRadioButtonSelected(false); + } + } + }; + ActionListener sdcUpdate_ActionListener = new ActionListener() { + + public void actionPerformed(ActionEvent evt) { + selectDataColumnPane.update(cellElement); + } + }; + public void putElementcase(ElementCasePane t){ + if (conditionParentPane != null) { + conditionParentPane.putElementcase(t); + } + } + public void putCellElement(TemplateCellElement tplEC2) { + if (conditionParentPane != null) { + conditionParentPane.putCellElement(tplEC2); + } + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/dscolumn/DSColumnConditionsPane.java b/designer/src/com/fr/design/dscolumn/DSColumnConditionsPane.java new file mode 100644 index 000000000..228e88ae4 --- /dev/null +++ b/designer/src/com/fr/design/dscolumn/DSColumnConditionsPane.java @@ -0,0 +1,106 @@ +package com.fr.design.dscolumn; + +import java.awt.BorderLayout; +import java.awt.FlowLayout; + +import com.fr.design.gui.ilable.UILabel; + +import javax.swing.JPanel; + +import com.fr.design.data.DesignTableDataManager; +import com.fr.data.TableDataSource; +import com.fr.design.condition.DSColumnLiteConditionPane; +import com.fr.design.condition.DSColumnSimpleLiteConditionPane; +import com.fr.design.gui.icheckbox.UICheckBox; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.dialog.BasicPane; +import com.fr.general.Inter; +import com.fr.general.data.Condition; +import com.fr.report.cell.CellElement; +import com.fr.report.cell.cellattr.core.group.DSColumn; +import com.fr.design.utils.gui.GUICoreUtils; + +public class DSColumnConditionsPane extends BasicPane { + //peter: Lite Condition. + + private DSColumnLiteConditionPane liteConditionPane; + //marks:是否继承父格条件 + private UICheckBox reselectExpandCheckBox; + //marks:作为布局的空字符串 + private static final String INSET_TEXT = " "; + + public DSColumnConditionsPane() { + this(DSColumnPane.SETTING_ALL); + } + + public DSColumnConditionsPane(int setting) { + this.setLayout(FRGUIPaneFactory.createM_BorderLayout()); + + if (setting > DSColumnPane.SETTING_DSRELATED) { + liteConditionPane = new DSColumnLiteConditionPane() { + protected boolean needDoWithCondition(Condition liteCondition) { + return liteCondition != null; + } + }; + } else { + liteConditionPane = new DSColumnSimpleLiteConditionPane(); + } + this.add(liteConditionPane, BorderLayout.CENTER); + + if (setting > DSColumnPane.SETTING_DSRELATED) { + //alex:ReSelect + JPanel pane = FRGUIPaneFactory.createX_AXISBoxInnerContainer_S_Pane(); +// pane.setLayout(new BoxLayout(pane, BoxLayout.X_AXIS)); + pane.add(new UILabel(INSET_TEXT)); + + reselectExpandCheckBox = new UICheckBox(Inter.getLocText("BindColumn-Extend_the_conditions_of_fatherCell(Applied_to_the_data_contains_other_data)"), false); + pane.add(reselectExpandCheckBox); + reselectExpandCheckBox.setSelected(true); + + JPanel reSelectPane = GUICoreUtils.createFlowPane(pane, FlowLayout.LEFT); + this.add(reSelectPane, BorderLayout.NORTH); + reSelectPane.setBorder(GUICoreUtils.createTitledBorder(Inter.getLocText("BindColumn-The_Conditions_of_FatherCell"), null)); + } + } + + @Override + public String title4PopupWindow() { + return Inter.getLocText("Filter"); + } + + public void populate(TableDataSource tds, CellElement cellElement) { + if (cellElement == null) { + return; + } + Object value = cellElement.getValue(); + if (value == null || !(value instanceof DSColumn)) { + return; + } + DSColumn linearDSColumn = (DSColumn) value; + + if (reselectExpandCheckBox != null) { + reselectExpandCheckBox.setSelected(!(linearDSColumn.isReselect())); + } + + String[] columnNames = DesignTableDataManager.getSelectedColumnNames(tds, linearDSColumn.getDSName()); + liteConditionPane.populateColumns(columnNames); + + this.liteConditionPane.populateBean(linearDSColumn.getCondition()); + } + + public void update(CellElement cellElement) { + if (cellElement == null) { + return; + } + Object value = cellElement.getValue(); + if (value == null || !(value instanceof DSColumn)) { + return; + } + DSColumn linearDSColumn = (DSColumn) value; + linearDSColumn.setCondition(this.liteConditionPane.updateBean()); + if (reselectExpandCheckBox != null) { + linearDSColumn.setReselect(!(this.reselectExpandCheckBox.isSelected())); + } + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/dscolumn/DSColumnPane.java b/designer/src/com/fr/design/dscolumn/DSColumnPane.java new file mode 100644 index 000000000..74bc68165 --- /dev/null +++ b/designer/src/com/fr/design/dscolumn/DSColumnPane.java @@ -0,0 +1,154 @@ +package com.fr.design.dscolumn; + +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Dimension; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +import javax.swing.JPanel; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +import com.fr.base.FRContext; +import com.fr.data.TableDataSource; +import com.fr.design.gui.frpane.UITabbedPane; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.dialog.BasicPane; +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.report.cell.CellElement; +import com.fr.report.cell.DefaultTemplateCellElement; +import com.fr.report.cell.TemplateCellElement; + +public class DSColumnPane extends BasicPane { + + private TableDataSource tplEC; + private UITabbedPane tabbedPane; + private DSColumnBasicPane basicPane = null; + private DSColumnConditionsPane conditionPane = null; + private DSColumnAdvancedPane advancedPane = null; + private TemplateCellElement cellElement; + protected Component lastSelectedComponent; + + public static final int SETTING_ALL = 2; + public static final int SETTING_DSRELATED = 1; + + public DSColumnPane() { + this.initComponents(SETTING_ALL); + } + + public DSColumnPane(int setting) { + this.initComponents(setting); + } + + protected void initComponents(int setting) { + JPanel contentPane = this; + contentPane.setLayout(FRGUIPaneFactory.createBorderLayout()); + + //peter:中心Panel. + tabbedPane = new UITabbedPane(); + tabbedPane.addChangeListener(appliedWizardTabChangeListener); + + contentPane.add(tabbedPane, BorderLayout.CENTER); + + //_denny: 数据列面板 + basicPane = new DSColumnBasicPane(setting); + basicPane.addPropertyChangeListener("cellElement", myPropertyChangeListener); + tabbedPane.addTab(Inter.getLocText("Basic"), basicPane); + + conditionPane = new DSColumnConditionsPane(setting); + tabbedPane.addTab(Inter.getLocText("Filter"), conditionPane); + + advancedPane = new DSColumnAdvancedPane(setting); + tabbedPane.addTab(Inter.getLocText("Advanced"), advancedPane); + + this.setPreferredSize(new Dimension(610, 400)); + } + + @Override + protected String title4PopupWindow() { + return Inter.getLocText("ExpandD-Data_Column"); + } + + /* + * populate + */ + public void populate(TableDataSource tds, TemplateCellElement cellElement) throws Exception { + this.tplEC = tds; + + if (tds == null || cellElement == null) { + // _denny: 我不认为这种情况应该出现,以防万一 + this.cellElement = new DefaultTemplateCellElement(); + return; + } + // _denny: 这边需要克隆一下,因为在设置时,可能改变字段cellElement,但改变真实值是不被期望的 + try { + this.cellElement = (TemplateCellElement) cellElement.clone(); + } catch (CloneNotSupportedException ce) { + } + this.basicPane.populate(tds, this.cellElement); + this.conditionPane.populate(tds, this.cellElement); + this.advancedPane.populate(this.cellElement); + } + + /* + * update + */ + public CellElement update() { + this.basicPane.update(cellElement); + this.conditionPane.update(cellElement); + this.advancedPane.update(cellElement); + return cellElement; + } + public ChangeListener appliedWizardTabChangeListener = new ChangeListener() { + + public void stateChanged(ChangeEvent evt) { + try { + if (lastSelectedComponent == null) { + lastSelectedComponent = basicPane; + } + //selectTabComponent是正要切换到的那个Pane + Component selectTabComponent = tabbedPane.getSelectedComponent(); + // _denny: 如果切换Tab时上一个Pane是basicPane, 则刷新一下其他Pane, + // 因为选择的数据列可能改变, 导致后面过滤和使用公式用到的数据项改变 + if (lastSelectedComponent == basicPane) { + basicPane.update(cellElement); + + // denny_GUI: 刷新其他面板 + refrushOtherTabs(); + } + // 切换标签的时候就,确认是否有没有添加到列表中的条件 + lastSelectedComponent = selectTabComponent; + } catch (Exception e) { + FRContext.getLogger().error(e.getMessage(), e); + } + + } + }; + // cellElement 改变时,刷新一下 + // 比如:上边切换Tab时,basicPane Update了一下,可能会改变Field cellElement的值 + PropertyChangeListener myPropertyChangeListener = new PropertyChangeListener() { + + public void propertyChange(PropertyChangeEvent evt) { + refrushOtherTabs(); + } + }; + + //_denny:当数据tab中的数据发生变化的时候刷新后面的tab + public void refrushOtherTabs() { + // ——deny:当JTabPane中加入一个Pane时,后面的Pane可能还没有初始化 + if (conditionPane == null || advancedPane == null) { + return; + } + this.conditionPane.populate(tplEC, cellElement); + this.advancedPane.populate(cellElement); + } + public void putElementcase(ElementCasePane t){ + basicPane.putElementcase(t); + } + + public void putCellElement(TemplateCellElement tplEC2) { + basicPane.putCellElement(tplEC2); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/dscolumn/ResultSetGroupDockingPane.java b/designer/src/com/fr/design/dscolumn/ResultSetGroupDockingPane.java new file mode 100644 index 000000000..b7cc3b5ae --- /dev/null +++ b/designer/src/com/fr/design/dscolumn/ResultSetGroupDockingPane.java @@ -0,0 +1,208 @@ +package com.fr.design.dscolumn; + +import java.awt.*; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; + +import com.fr.design.gui.ilable.UILabel; +import javax.swing.JPanel; + + +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.gui.icombobox.FunctionComboBox; +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.design.mainframe.ElementCasePane; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.cell.cellattr.CellExpandAttr; +import com.fr.report.cell.cellattr.core.group.CustomGrouper; +import com.fr.report.cell.cellattr.core.group.DSColumn; +import com.fr.report.cell.cellattr.core.group.FunctionGrouper; +import com.fr.report.cell.cellattr.core.group.RecordGrouper; +import com.fr.report.cell.cellattr.core.group.SummaryGrouper; +import com.fr.stable.Constants; +import com.fr.design.utils.gui.GUICoreUtils; + +/** + * 这个pane是选中数据列后,在上方QuickRegion处显示的pane + * + * @author zhou + */ +public class ResultSetGroupDockingPane extends ResultSetGroupPane { + private static final int BIND_GROUP = 0; + private static final int BIND_SELECTED = 1; + private static final int BIND_SUMMARY = 2; + + private UIButton advancedButton; + private FunctionComboBox functionComboBox; + private JPanel cardPane; + private CardLayout cardLayout; + private UIComboBox goBox; + + ItemListener l; + + public ResultSetGroupDockingPane(ElementCasePane ePane) { + super(); + this.initComponents(ePane); + } + + public void initComponents(ElementCasePane ePane) { + goBox = new UIComboBox(new String[]{Inter.getLocText("BindColumn-Group"), Inter.getLocText("BindColumn-Select"), Inter.getLocText("BindColumn-Summary")}); + initCardPane(); + JPanel pane = layoutPane(); + this.setLayout(new BorderLayout()); + this.add(pane, BorderLayout.CENTER); + } + + private JPanel layoutPane() { + double vs = 4; + double vg = 6; + double p = TableLayout.PREFERRED; + double f = TableLayout.FILL; + + Component[][] components = new Component[][] + { + new Component[]{new UILabel(Inter.getLocText("Data_Setting")), goBox}, + new Component[]{cardPane, null} + }; + goBox.addItemListener(new ItemListener() { + public void itemStateChanged(ItemEvent ee) { + checkButtonEnabled(); + int i = goBox.getSelectedIndex(); + if (i == BIND_GROUP) { + cardLayout.show(cardPane, "groupPane"); + } else if (i == BIND_SELECTED) { + cardLayout.show(cardPane, "listPane"); + } else if (i == BIND_SUMMARY) { + cardLayout.show(cardPane, "summaryPane"); + CellExpandAttr cellExpandAttr = cellElement.getCellExpandAttr(); + cellExpandAttr.setDirection(Constants.NONE); + } + } + }); + + double[] columnSize = {p, f}; + double[] rowSize = {p, p}; + return TableLayoutHelper.createTableLayoutPane(components,rowSize,columnSize); + } + + private void initCardPane() { + cardPane = FRGUIPaneFactory.createCardLayout_S_Pane(); + cardLayout = new CardLayout(); + cardPane.setLayout(cardLayout); + + JPanel pane = new JPanel(new BorderLayout(3, 0)); + groupComboBox.addItemListener(new ItemListener() { + public void itemStateChanged(ItemEvent e) { + checkButtonEnabled(); + } + }); + advancedButton = new UIButton(Inter.getLocText("Custom")); + advancedButton.addActionListener(groupAdvancedListener); + pane.add(groupComboBox, BorderLayout.WEST); + pane.add(advancedButton, BorderLayout.CENTER); + cardPane.add(pane, "groupPane"); + + cardPane.add(new JPanel(), "listPane"); + + cardPane.add(functionComboBox = new FunctionComboBox(GUICoreUtils.getFunctionArray()), "summaryPane"); + } + + @Override + public void populate(TemplateCellElement cellElement) { + this.cellElement = cellElement; + + if (isNPE(cellElement)) return; + DSColumn dSColumn = (DSColumn) cellElement.getValue(); + + // populate groupPane + // RecordGrouper + recordGrouper = dSColumn.getGrouper(); + if (recordGrouper instanceof FunctionGrouper && !((FunctionGrouper) recordGrouper).isCustom()) { + int mode = ((FunctionGrouper) recordGrouper).getDivideMode(); + if (mode == FunctionGrouper.GROUPING_MODE) { + cardLayout.show(cardPane, "groupPane"); + this.goBox.setSelectedIndex(BIND_GROUP); + this.groupComboBox.setSelectedIndex(COMMON); + } else if (mode == FunctionGrouper.CONTINUUM_MODE) { + cardLayout.show(cardPane, "groupPane"); + this.goBox.setSelectedIndex(BIND_GROUP); + this.groupComboBox.setSelectedIndex(CONTINUUM); + } else if (mode == FunctionGrouper.LIST_MODE) { + cardLayout.show(cardPane, "listPane"); + this.goBox.setSelectedIndex(BIND_SELECTED); + } + } else if (recordGrouper instanceof FunctionGrouper && ((FunctionGrouper) recordGrouper).isCustom()) { + // 这种情况也放到自定义分组里面 + cardLayout.show(cardPane, "groupPane"); + this.goBox.setSelectedIndex(BIND_GROUP); + this.groupComboBox.setSelectedIndex(ADVANCED); + } else if (recordGrouper instanceof SummaryGrouper) { + cardLayout.show(cardPane, "summaryPane"); + this.goBox.setSelectedIndex(BIND_SUMMARY); + this.functionComboBox.setFunction(((SummaryGrouper) recordGrouper).getFunction()); + } else if (recordGrouper instanceof CustomGrouper) { + // 自定义分组 or 高级分组 + cardLayout.show(cardPane, "groupPane"); + this.goBox.setSelectedIndex(BIND_GROUP); + this.groupComboBox.setSelectedIndex(ADVANCED); + } + + checkButtonEnabled(); + } + + @Override + public void update() { + if (isNPE(cellElement)) return; + DSColumn dSColumn = (DSColumn) cellElement.getValue(); + + if (this.goBox.getSelectedIndex() == BIND_GROUP) { + recordGrouper = updateGroupCombox(); + } else if (this.goBox.getSelectedIndex() == BIND_SELECTED) { + FunctionGrouper valueGrouper = new FunctionGrouper(); + valueGrouper.setDivideMode(FunctionGrouper.LIST_MODE); + valueGrouper.setCustom(false); + recordGrouper = valueGrouper; + } else if (this.goBox.getSelectedIndex() == BIND_SUMMARY) { + SummaryGrouper summaryGrouper = new SummaryGrouper(); + summaryGrouper.setFunction(functionComboBox.getFunction()); + recordGrouper = summaryGrouper; + } + + dSColumn.setGrouper(recordGrouper); + } + + private void checkButtonEnabled() { + advancedButton.setEnabled(false); + functionComboBox.setEnabled(false); + groupComboBox.setEnabled(false); + if (this.goBox.getSelectedIndex() == BIND_SUMMARY) { + functionComboBox.setEnabled(true); + } + if (this.goBox.getSelectedIndex() == BIND_GROUP) { + groupComboBox.setEnabled(true); + if (groupComboBox.getSelectedIndex() == ADVANCED) { + advancedButton.setEnabled(true); + } + } + } + + public void addListener(ItemListener l) { + goBox.addItemListener(l); + groupComboBox.addItemListener(l); + functionComboBox.addItemListener(l); + this.l = l; + } + + void fireTargetChanged() { + l.itemStateChanged(null); + } + + @Override + public void setRecordGrouper(RecordGrouper recordGrouper) { + this.recordGrouper = recordGrouper; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/dscolumn/ResultSetGroupPane.java b/designer/src/com/fr/design/dscolumn/ResultSetGroupPane.java new file mode 100644 index 000000000..3e94802c4 --- /dev/null +++ b/designer/src/com/fr/design/dscolumn/ResultSetGroupPane.java @@ -0,0 +1,118 @@ +package com.fr.design.dscolumn; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JPanel; +import javax.swing.SwingUtilities; + +import com.fr.design.data.DesignTableDataManager; +import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.JTemplate; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.general.Inter; +import com.fr.report.cell.CellElement; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.cell.cellattr.core.group.CustomGrouper; +import com.fr.report.cell.cellattr.core.group.DSColumn; +import com.fr.report.cell.cellattr.core.group.FunctionGrouper; +import com.fr.report.cell.cellattr.core.group.RecordGrouper; + +//august:1:31 我又改回以前的样子了 neil那个方法还是有bug 9922 +public abstract class ResultSetGroupPane extends JPanel { + + protected static final int COMMON = 0; + protected static final int CONTINUUM = 1; + protected static final int ADVANCED = 2; + + protected TemplateCellElement cellElement; + protected RecordGrouper recordGrouper; + protected UIComboBox groupComboBox; + + protected ResultSetGroupPane(){ + groupComboBox = new UIComboBox(new String[] {Inter.getLocText("Common"), Inter.getLocText("Continuum"), Inter.getLocText("Advanced")}); + } + + abstract void populate(TemplateCellElement cellElement); + + abstract void update(); + + abstract void setRecordGrouper(RecordGrouper recordGrouper); + + void fireTargetChanged() { + }; + + ActionListener groupAdvancedListener = new ActionListener() { + public void actionPerformed(ActionEvent evt) { + if (cellElement == null) { + return; + } + + final SpecifiedGroupAttrPane specifiedGroupAttrPane; + Object value = cellElement.getValue(); + if (value == null || !(value instanceof DSColumn)) { + return; + } + + final DSColumn dSColumn = (DSColumn) value; + String[] columnNames = DesignTableDataManager.getSelectedColumnNames(DesignTableDataManager.getEditingTableDataSource(), dSColumn.getDSName()); + specifiedGroupAttrPane = new SpecifiedGroupAttrPane(columnNames); + + specifiedGroupAttrPane.populate(recordGrouper); + specifiedGroupAttrPane.showWindow(SwingUtilities.getWindowAncestor(ResultSetGroupPane.this), new DialogActionAdapter() { + @Override + public void doOk() { + RecordGrouper rg = specifiedGroupAttrPane.update(cellElement, recordGrouper); + if (!isNPE(cellElement)) { + dSColumn.setGrouper(rg); + } + setRecordGrouper(rg); + fireTargetChanged(); + JTemplate targetComponent = DesignerContext.getDesignerFrame().getSelectedJTemplate(); + if (targetComponent != null) { + targetComponent.fireTargetModified(); + targetComponent.requestGridFocus(); + } + } + }).setVisible(true); + } + }; + + protected RecordGrouper updateGroupCombox() { + if (groupComboBox.getSelectedIndex() == 0) { + FunctionGrouper valueGrouper = new FunctionGrouper(); + valueGrouper.setDivideMode(FunctionGrouper.GROUPING_MODE); + valueGrouper.setCustom(false); + recordGrouper = valueGrouper; + } else if (groupComboBox.getSelectedIndex() == 1) { + FunctionGrouper valueGrouper = new FunctionGrouper(); + valueGrouper.setDivideMode(FunctionGrouper.CONTINUUM_MODE); + valueGrouper.setCustom(false); + recordGrouper = valueGrouper; + } else if (groupComboBox.getSelectedIndex() == 2) { + if (recordGrouper == null) { + recordGrouper = new CustomGrouper(); + } + if (!(recordGrouper instanceof CustomGrouper) && !(recordGrouper instanceof FunctionGrouper && ((FunctionGrouper) recordGrouper).isCustom())) { + recordGrouper = new CustomGrouper(); + } + } + + return recordGrouper; + } + + protected boolean isNPE(CellElement cellElement) { + if (cellElement == null) { + return true; + } + if (cellElement.getValue() == null) { + return true; + } + if (!(cellElement.getValue() instanceof DSColumn)) { + return true; + } + return false; + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/dscolumn/ResultSetGroupPopUpPane.java b/designer/src/com/fr/design/dscolumn/ResultSetGroupPopUpPane.java new file mode 100644 index 000000000..c066fc8cb --- /dev/null +++ b/designer/src/com/fr/design/dscolumn/ResultSetGroupPopUpPane.java @@ -0,0 +1,191 @@ +package com.fr.design.dscolumn; + +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.ibutton.UIRadioButton; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.icombobox.FunctionComboBox; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.general.Inter; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.cell.cellattr.core.group.*; +import com.fr.stable.StringUtils; +import com.fr.design.utils.gui.GUICoreUtils; + +import javax.swing.*; +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 ResultSetGroupPopUpPane extends ResultSetGroupPane { + + + private UIRadioButton groupRadioButton; + private UIButton advancedButton; + private UIRadioButton listRadioButton; + private UIRadioButton summaryRadioButton; + private FunctionComboBox functionComboBox; + + + private String InsertText = StringUtils.BLANK; + + public ResultSetGroupPopUpPane() { + this(true); + } + + // 将结果集进行分组: 分组,列表,汇总,自定义 + public ResultSetGroupPopUpPane(boolean isGroup) { + super(); + this.initComponents(isGroup); + } + + public void initComponents(boolean isGroup) { + this.setLayout(FRGUIPaneFactory.create1ColumnGridLayout()); + + // 分组 + groupRadioButton = new UIRadioButton(Inter + .getLocText("BindColumn-Group(Merger_the_Items_Which_Have_The_Same_Value_in_Column)")); + groupRadioButton.addActionListener(checkEnabledActionListener); + + groupComboBox.addItemListener(new ItemListener() { + public void itemStateChanged(ItemEvent e) { + checkButtonEnabled(); + } + }); + advancedButton = new UIButton(Inter.getLocText("Custom")); + advancedButton.addActionListener(groupAdvancedListener); + this.add(GUICoreUtils.createFlowPane( + new JComponent[]{new UILabel(InsertText), groupRadioButton, groupComboBox, advancedButton}, FlowLayout.LEFT)); + + // 列表 + listRadioButton = new UIRadioButton(Inter + .getLocText("BindColumn-Select(Regardless_of_Having_the_Same_Value,Display_all_Item_in_Column)")); + listRadioButton.addActionListener(checkEnabledActionListener); + this.add(GUICoreUtils.createFlowPane( + new JComponent[]{new UILabel(InsertText), listRadioButton}, FlowLayout.LEFT)); + + // 汇总 + summaryRadioButton = new UIRadioButton(Inter + .getLocText("BindColumn-Summary(Including_SUM_,_AVERAGE_,_MAX_,_MIN_And_So_On)"), true); + summaryRadioButton.addActionListener(checkEnabledActionListener); + functionComboBox = new FunctionComboBox(GUICoreUtils.getFunctionArray()); + this.add(GUICoreUtils.createFlowPane( + new JComponent[]{new UILabel(InsertText), summaryRadioButton, functionComboBox}, FlowLayout.LEFT)); + + + ButtonGroup resultSetGroupButtonGroup = new ButtonGroup(); + resultSetGroupButtonGroup.add(groupRadioButton); + if (isGroup) { + groupRadioButton.setSelected(true); + } else { + listRadioButton.setSelected(true); + } + resultSetGroupButtonGroup.add(listRadioButton); + resultSetGroupButtonGroup.add(summaryRadioButton); + checkButtonEnabled(); + } + + @Override + public void populate(TemplateCellElement cellElement) { + this.cellElement = cellElement; + + if (isNPE(cellElement)) { + return; + } + DSColumn dSColumn = (DSColumn) cellElement.getValue(); + + // populate groupPane + // RecordGrouper + recordGrouper = dSColumn.getGrouper(); + if (recordGrouper instanceof FunctionGrouper && !((FunctionGrouper) recordGrouper).isCustom()) { + int mode = ((FunctionGrouper) recordGrouper).getDivideMode(); + if (mode == FunctionGrouper.GROUPING_MODE) { + this.groupRadioButton.setSelected(true); + this.groupComboBox.setSelectedIndex(COMMON); + } else if (mode == FunctionGrouper.CONTINUUM_MODE) { + this.groupRadioButton.setSelected(true); + this.groupComboBox.setSelectedIndex(CONTINUUM); + } else if (mode == FunctionGrouper.LIST_MODE) { + this.listRadioButton.setSelected(true); + } + } else if (recordGrouper instanceof FunctionGrouper && ((FunctionGrouper) recordGrouper).isCustom()) { + // 这种情况也放到自定义分组里面 + this.groupRadioButton.setSelected(true); + this.groupComboBox.setSelectedIndex(ADVANCED); + } else if (recordGrouper instanceof SummaryGrouper) { + this.summaryRadioButton.setSelected(true); + this.functionComboBox.setFunction(((SummaryGrouper) recordGrouper).getFunction()); + } else if (recordGrouper instanceof CustomGrouper) { + // 自定义分组 or 高级分组 + this.groupRadioButton.setSelected(true); + this.groupComboBox.setSelectedIndex(ADVANCED); + } + + checkButtonEnabled(); + } + + @Override + public void update() { + if (isNPE(cellElement)) { + return; + } + DSColumn dSColumn = (DSColumn) cellElement.getValue(); + + if (this.groupRadioButton.isSelected()) { + recordGrouper = updateGroupCombox(); + } else if (this.listRadioButton.isSelected()) { + FunctionGrouper valueGrouper = new FunctionGrouper(); + valueGrouper.setDivideMode(FunctionGrouper.LIST_MODE); + valueGrouper.setCustom(false); + recordGrouper = valueGrouper; + } else if (this.summaryRadioButton.isSelected()) { + SummaryGrouper summaryGrouper = new SummaryGrouper(); + summaryGrouper.setFunction(functionComboBox.getFunction()); + recordGrouper = summaryGrouper; + } else { + } + + dSColumn.setGrouper(recordGrouper); + } + + private void checkButtonEnabled() { + advancedButton.setEnabled(false); + functionComboBox.setEnabled(false); + groupComboBox.setEnabled(false); + if (summaryRadioButton.isSelected()) { + functionComboBox.setEnabled(true); + } + + if (groupRadioButton.isSelected()) { + groupComboBox.setEnabled(true); + if (groupComboBox.getSelectedIndex() == 2) { + advancedButton.setEnabled(true); + } + } + } + + public boolean isSummaryRadioButtonSelected() { + return summaryRadioButton.isSelected(); + } + + public void addListeners(ActionListener summaryListener, ActionListener otherListener, ActionListener sdcListener) { + summaryRadioButton.addActionListener(summaryListener); + groupRadioButton.addActionListener(otherListener); + listRadioButton.addActionListener(otherListener); + advancedButton.addActionListener(sdcListener); + } + + ActionListener checkEnabledActionListener = new ActionListener() { + public void actionPerformed(ActionEvent evt) { + checkButtonEnabled(); + } + }; + + + @Override + public void setRecordGrouper(RecordGrouper recordGrouper) { + this.recordGrouper = recordGrouper; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/dscolumn/SelectedConfirmedDataColumnPane.java b/designer/src/com/fr/design/dscolumn/SelectedConfirmedDataColumnPane.java new file mode 100644 index 000000000..282367d27 --- /dev/null +++ b/designer/src/com/fr/design/dscolumn/SelectedConfirmedDataColumnPane.java @@ -0,0 +1,45 @@ +package com.fr.design.dscolumn; + +import java.awt.Dimension; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.Iterator; + +import com.fr.data.TableDataSource; +import com.fr.design.data.datapane.TableDataComboBox; +import com.fr.design.data.tabledata.wrapper.TemplateTableDataWrapper; +import com.fr.main.impl.WorkBook; +import com.fr.report.cell.TemplateCellElement; + +public class SelectedConfirmedDataColumnPane extends SelectedDataColumnPane { + + public SelectedConfirmedDataColumnPane () { + super(false); + } + + protected void initTableNameComboBox() { + tableNameComboBox = new TableDataComboBox(new WorkBook()); + tableNameComboBox.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + columnNameComboBox.setLoaded(false); + } + }); + tableNameComboBox.setPreferredSize(new Dimension(100, 20)); + } + + public void populate(TableDataSource source, TemplateCellElement cell) { + tableNameComboBox.refresh(source); + tableNameComboBox.setEditable(false); + tableNameComboBox.setEnabled(false); + super.populate(source, cell); + try { + Iterator it = source.getTableDataNameIterator(); + String name = (String)it.next(); + TemplateTableDataWrapper wrapper = new TemplateTableDataWrapper(source.getTableData(name), name); + tableNameComboBox.setSelectedItem(wrapper); + tableNameComboBox.getModel().setSelectedItem(wrapper); + } catch (Exception e) { + } + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/dscolumn/SelectedDataColumnPane.java b/designer/src/com/fr/design/dscolumn/SelectedDataColumnPane.java new file mode 100644 index 000000000..780e81e94 --- /dev/null +++ b/designer/src/com/fr/design/dscolumn/SelectedDataColumnPane.java @@ -0,0 +1,247 @@ +package com.fr.design.dscolumn; + +import com.fr.base.Parameter; +import com.fr.design.data.DesignTableDataManager; +import com.fr.data.SimpleDSColumn; +import com.fr.data.TableDataSource; +import com.fr.design.data.datapane.TableDataComboBox; +import com.fr.design.data.tabledata.wrapper.TableDataWrapper; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itableeditorpane.ParameterTableModel; +import com.fr.design.gui.itableeditorpane.UITableEditorPane; +import com.fr.design.gui.icombobox.LazyComboBox; +import com.fr.design.layout.TableLayout; +import com.fr.design.layout.TableLayoutHelper; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.BasicPane; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.general.Inter; +import com.fr.general.data.TableDataColumn; +import com.fr.report.cell.CellElement; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.cell.cellattr.core.group.DSColumn; +import com.fr.stable.ParameterProvider; +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.ItemEvent; +import java.awt.event.ItemListener; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Pattern; + +public class SelectedDataColumnPane extends BasicPane { + protected UITableEditorPane editorPane; + protected Parameter[] ps; + + protected TableDataComboBox tableNameComboBox; + protected LazyComboBox columnNameComboBox; + private ItemListener itemListener; + + private UIButton paramButton; + + public SelectedDataColumnPane() { + this(true); + } + + public SelectedDataColumnPane(boolean showParameterButton) { + initComponent(showParameterButton); + } + + /** + * 初始化组件 + * + * @param showParameterButton 是否显示参数按钮 + * + */ + public void initComponent(boolean showParameterButton) { + initTableNameComboBox(); + if (showParameterButton) { + initWithParameterButton(); + } + columnNameComboBox = new LazyComboBox() { + + @Override + public Object[] load() { + List l = calculateColumnNameList(); + return l.toArray(new String[l.size()]); + } + + }; + columnNameComboBox.setEditable(true); + double p = TableLayout.PREFERRED; + UILabel label1 = new UILabel(Inter.getLocText("TableData") + ":"); + UILabel label2 = new UILabel(Inter.getLocText("DataColumn") + ":"); + if (showParameterButton) { + label1.setPreferredSize(new Dimension(200, 25)); + label2.setPreferredSize(new Dimension(200, 25)); + } + if (showParameterButton) { + Component[][] comps = {{label1, null, label2}, {tableNameComboBox, paramButton, columnNameComboBox}}; + this.add(TableLayoutHelper.createTableLayoutPane(comps, new double[]{p, p}, new double[]{p, p, p})); + } else { + double f = TableLayout.FILL; + double[] columnSize = {p, f}; + double[] rowSize = {p, p}; + Component[][] components = new Component[][]{ + new Component[]{label1, tableNameComboBox}, + new Component[]{label2, columnNameComboBox} + }; + JPanel jPanel = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); + this.setLayout(new BorderLayout()); + this.add(jPanel, BorderLayout.CENTER); + } + } + + protected void initTableNameComboBox() { + tableNameComboBox = new TableDataComboBox(DesignTableDataManager.getEditingTableDataSource()); + tableNameComboBox.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + columnNameComboBox.setLoaded(false); +// columnNameComboBox.loadList(); + } + }); + tableNameComboBox.setPreferredSize(new Dimension(100, 20)); + } + + private void initWithParameterButton() { + editorPane = new UITableEditorPane(new ParameterTableModel()); + paramButton = new UIButton(Inter.getLocText("TableData_Dynamic_Parameter_Setting")); + paramButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + BasicDialog paramDialog = editorPane.showSmallWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { + @Override + public void doOk() { + List parameterList = editorPane.update(); + ps = parameterList.toArray(new Parameter[parameterList.size()]); + } + }); + + editorPane.populate(ps == null ? new Parameter[0] : ps); + paramDialog.setVisible(true); + } + }); + } + + @Override + protected String title4PopupWindow() { + return "DSColumn"; + } + + public void populate(TableDataSource source, TemplateCellElement cellElement) { + if (cellElement == null) { + return; + } + + if (itemListener != null) { + removeListener(itemListener); + } + + Object value = cellElement.getValue(); + if (!(value instanceof DSColumn)) { + return; + } + + DSColumn dsColumn = (DSColumn) value; + String dsName = dsColumn.getDSName(); + tableNameComboBox.setSelectedTableDataByName(dsName); + columnNameComboBox.setSelectedItem(TableDataColumn.getColumnName(dsColumn.getColumn())); + ps = dsColumn.getParameters(); + + addListener(itemListener); + } + + public void update(CellElement cellElement) { + if (cellElement == null) { + return; + } + Object value = cellElement.getValue(); + if (this.tableNameComboBox.getSelectedItem() == null && this.columnNameComboBox.getSelectedItem() == null) { + return; + } + DSColumn dsColumn = null; + if (value == null || !(value instanceof DSColumn)) { + dsColumn = new DSColumn(); + cellElement.setValue(dsColumn); + } + dsColumn = (DSColumn) cellElement.getValue(); + + SimpleDSColumn simpleDSColumn = updateColumnPane(); + dsColumn.setDSName(simpleDSColumn.getDsName()); + dsColumn.setColumn(simpleDSColumn.getColumn()); + + dsColumn.setParameters((ps != null && ps.length > 0) ? ps : null); + } + + /** + * 更新面板 + * + * @return 更新后的值 + * + */ + public SimpleDSColumn updateColumnPane() { + SimpleDSColumn dsColumn = new SimpleDSColumn(); + TableDataWrapper tableDataWrappe = this.tableNameComboBox.getSelectedItem(); + if (tableDataWrappe == null) { + return null; + } + dsColumn.setDsName(tableDataWrappe.getTableDataName()); + TableDataColumn column; + String columnExp = (String) this.columnNameComboBox.getSelectedItem(); + if (isColumnName(columnExp)) { + String number = columnExp.substring(1); + Pattern pattern = Pattern.compile("[^\\d]"); + if (pattern.matcher(number).find()) { + column = TableDataColumn.createColumn(columnExp); + } else { + int serialNumber = Integer.parseInt(columnExp.substring(1)); + column = TableDataColumn.createColumn(serialNumber); + } + } else { + column = TableDataColumn.createColumn(columnExp); + } + dsColumn.setColumn(column); + return dsColumn; + } + + private boolean isColumnName(String columnExp) { + return StringUtils.isNotBlank(columnExp) && (columnExp.length() > 0 && columnExp.charAt(0) == '#') && !columnExp.endsWith("#"); + + } + + /** + * 添加监听事件 + * + * @param i 监听事件 + * + */ + public void addListener(ItemListener i) { + itemListener = i; + tableNameComboBox.addItemListener(i); + columnNameComboBox.addItemListener(i); + } + + /** + * 移除监听事件 + * + * @param i 监听事件 + * + */ + public void removeListener(ItemListener i) { + tableNameComboBox.removeItemListener(i); + columnNameComboBox.removeItemListener(i); + } + + private List calculateColumnNameList() { + if (this.tableNameComboBox.getSelectedItem() != null) { + return this.tableNameComboBox.getSelectedItem().calculateColumnNameList(); + } + return new ArrayList(); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/dscolumn/SpecifiedGroupAttrPane.java b/designer/src/com/fr/design/dscolumn/SpecifiedGroupAttrPane.java new file mode 100644 index 000000000..7321f2ca6 --- /dev/null +++ b/designer/src/com/fr/design/dscolumn/SpecifiedGroupAttrPane.java @@ -0,0 +1,401 @@ +package com.fr.design.dscolumn; + +import com.fr.base.Formula; +import com.fr.design.beans.BasicBeanPane; +import com.fr.design.condition.DSColumnLiteConditionPane; +import com.fr.design.dialog.BasicPane; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.formula.CustomVariableResolver; +import com.fr.design.formula.FormulaFactory; +import com.fr.design.formula.UIFormula; +import com.fr.design.gui.controlpane.NameObjectCreator; +import com.fr.design.gui.controlpane.NameableCreator; +import com.fr.design.gui.controlpane.ObjectJControlPane; +import com.fr.design.gui.ibutton.UIButton; +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.ilist.ModNameActionListener; +import com.fr.design.gui.itextfield.UITextField; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.general.Inter; +import com.fr.general.NameObject; +import com.fr.report.cell.CellElement; +import com.fr.report.cell.cellattr.core.group.ConditionGroup; +import com.fr.report.cell.cellattr.core.group.CustomGrouper; +import com.fr.report.cell.cellattr.core.group.FunctionGrouper; +import com.fr.report.cell.cellattr.core.group.RecordGrouper; +import com.fr.stable.Nameable; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.ArrayList; + +/** + * SpecifiedGroupAttrDialog + */ +public class SpecifiedGroupAttrPane extends BasicPane { + private CardLayout cardLayout; + private JPanel centerCardPane; + private JPanel conditionsGroupPane; + private FormulaGroupPane formulaGroupPane; + + private UIComboBox specifiedComboBox; + private SpecifiedGroupControlPane specifiedControlPane; + + //下拉选择列名需要的 + private String[] displayNames; + + //other pane的控件 + private UICheckBox forceCheckBox; + private UICheckBox moreCheckBox; + private UIComboBox otherComboBox; + private UITextField otherTextField; + + public class SpecifiedGroupControlPane extends ObjectJControlPane { + public SpecifiedGroupControlPane(String[] displayNames) { + super(displayNames); + this.addModNameActionListener(new ModNameActionListener() { + public void nameModed(int index, String oldName, String newName) { + populateSelectedValue(); + } + }); + } + + @Override + public NameableCreator[] createNameableCreators() { + return new NameableCreator[] { + new NameObjectCreator(Inter.getLocText("Condition"), ConditionGroup.class, ConditionGroupDetailsPane.class) + }; + } + + @Override + protected String title4PopupWindow() { + return Inter.getLocText("SpecifiedG-Specified_Group"); + } + } + + public SpecifiedGroupAttrPane(String[] displayNames) { + this.displayNames = displayNames; + this.initComponents(); + } + + protected void initComponents() { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + specifiedComboBox = new UIComboBox(new String[] { + Inter.getLocText(new String[]{"Condition", "Group"}), Inter.getLocText(new String[]{"Formula", "Group"}) + }); + + specifiedComboBox.addItemListener(new ItemListener() { + public void itemStateChanged(ItemEvent e) { + if (specifiedComboBox.getSelectedIndex() == 0) { + cardLayout.show(centerCardPane, "Condition"); + } else { + cardLayout.show(centerCardPane, "Formula"); + } + } + }); + + JPanel northPane = GUICoreUtils.createFlowPane( + new JComponent[]{new UILabel(Inter.getLocText("Select_Specified_Grouping") + ":"), + specifiedComboBox}, FlowLayout.LEFT); + this.add(northPane, BorderLayout.NORTH); + + cardLayout = new CardLayout(); + centerCardPane = FRGUIPaneFactory.createCardLayout_S_Pane(); + centerCardPane.setLayout(cardLayout); + + // 条件分组 + conditionsGroupPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + specifiedControlPane = new SpecifiedGroupControlPane(displayNames); + + conditionsGroupPane.add(specifiedControlPane, BorderLayout.CENTER); + + JPanel southPane = FRGUIPaneFactory.createMediumHGapFlowInnerContainer_M_Pane(); + conditionsGroupPane.add(southPane, BorderLayout.SOUTH); + forceCheckBox = new UICheckBox(Inter.getLocText("SpecifiedG-Force_Group")); + moreCheckBox = new UICheckBox(Inter.getLocText("one_record_exists_in_many_groups")); + southPane.add(forceCheckBox); southPane.add(moreCheckBox); + otherComboBox = new UIComboBox(new String[] {Inter.getLocText("SpecifiedG-Discard_all_others"), + Inter.getLocText("SpecifiedG-Leave_in_their_own_groups"), Inter.getLocText("SpecifiedG-Put_all_others_together")}); + otherComboBox.addItemListener(otherItemListener); + UILabel label = new UILabel(Inter.getLocText("OtherGroup_Name") + ":"); + otherTextField = new UITextField(8); + southPane.add(otherComboBox); + southPane.add(GUICoreUtils.createFlowPane(new Component[]{label, otherTextField}, FlowLayout.LEFT)); + + // 公式分组 + formulaGroupPane = new FormulaGroupPane(); + + + centerCardPane.add("Condition", conditionsGroupPane); + centerCardPane.add("Formula", formulaGroupPane); + this.add(centerCardPane, BorderLayout.CENTER); + } + + @Override + protected String title4PopupWindow() { + return Inter.getLocText("SpecifiedG-Specified_Group"); + } + + /** + * radio Select Action Listener + */ + ItemListener otherItemListener = new ItemListener() { + public void itemStateChanged(ItemEvent e) { + if (otherComboBox.getSelectedIndex() == 2) { + otherTextField.setEnabled(true); + } else { + otherTextField.setEnabled(false); + } + } + }; + + /** + * check Valid + */ + @Override + public void checkValid() throws Exception { + + } + + + // denny_DS + public void populate(RecordGrouper grouper) { + if(grouper == null){ + return; + } + + if (grouper instanceof CustomGrouper) { + this.specifiedComboBox.setSelectedIndex(0); + cardLayout.show(centerCardPane, "Condition"); + CustomGrouper customGrouper = (CustomGrouper)grouper; + boolean force = customGrouper.isForce(); + ConditionGroup[] conditionGroups = customGrouper.getConditionGroups(); + boolean more = customGrouper.isMore(); + int other = customGrouper.getOther(); + String odisplay = customGrouper.getOtherdisplay(); + + this.forceCheckBox.setSelected(force); + + this.moreCheckBox.setSelected(more); + + if (other == CustomGrouper.TOGETHER) { + this.otherComboBox.setSelectedIndex(2); + this.otherTextField.setEnabled(true); + } else if (other == CustomGrouper.DISCARD) { + this.otherComboBox.setSelectedIndex(0); + this.otherTextField.setEnabled(false); + } else { + this.otherComboBox.setSelectedIndex(1); + this.otherTextField.setEnabled(false); + } + + if (odisplay != null) { + this.otherTextField.setText(odisplay); + } + + if (conditionGroups != null){ + java.util.List list = new ArrayList(); + for(int i = 0; i < conditionGroups.length; i++) { + list.add(new NameObject(conditionGroups[i].getDisplay(), conditionGroups[i])); + } + + specifiedControlPane.populate(list.toArray(new NameObject[list.size()])); + } + } else if (grouper instanceof FunctionGrouper + && ((FunctionGrouper)grouper).isCustom()) { + this.specifiedComboBox.setSelectedIndex(1); + cardLayout.show(centerCardPane, "Formula"); + formulaGroupPane.populate(grouper); + } + + if (otherComboBox.getSelectedIndex() == 2) { + otherTextField.setEnabled(true); + } else { + otherTextField.setEnabled(false); + } + } + + public RecordGrouper update(CellElement cellElement, RecordGrouper recordGrouper) { + if (this.specifiedComboBox.getSelectedIndex() == 0) { + CustomGrouper customGroup = new CustomGrouper(); + + if (forceCheckBox.isSelected()) { + customGroup.setForce(true); + } + + if (!moreCheckBox.isSelected()) { + customGroup.setMore(false); + } + + if (otherComboBox.getSelectedIndex() == 2) { + customGroup.setOther(CustomGrouper.TOGETHER); + } else if (otherComboBox.getSelectedIndex() == 0) { + customGroup.setOther(CustomGrouper.DISCARD); + } else { + customGroup.setOther(CustomGrouper.LEAVE); + } + + customGroup.setOdisplay(this.otherTextField.getText()); + + // Nameable[]居然不能强转成NameObject[],一定要这么写... + Nameable[] res = specifiedControlPane.update(); + NameObject[] nameObject_array = new NameObject[res.length]; + java.util.Arrays.asList(res).toArray(nameObject_array); + ConditionGroup[] res_array = new ConditionGroup[res.length]; + for (int i = 0; i < res.length; i ++) { + res_array[i] = (ConditionGroup)nameObject_array[i].getObject(); + res_array[i].setDisplay(nameObject_array[i].getName()); + } + + customGroup.setConditionGroups(res_array); + recordGrouper = customGroup; + } else { + recordGrouper = formulaGroupPane.update(); + } + + return recordGrouper; + } + + public static class ConditionGroupDetailsPane extends BasicBeanPane { + private ConditionGroup editing; + + private DSColumnLiteConditionPane liteConditionPane; + public ConditionGroupDetailsPane(String[] displayNames) { + //alex:右侧的组内的条件细节 + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + this.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); + + liteConditionPane = new DSColumnLiteConditionPane(); + this.add(liteConditionPane, BorderLayout.CENTER); + if (displayNames != null) { + liteConditionPane.populateColumns(displayNames); + } + } + + @Override + protected String title4PopupWindow() { + return Inter.getLocText("SpecifiedG-Specified_Group"); + } + + @Override + public ConditionGroup updateBean() { + editing.setCondition(liteConditionPane.updateBean()); + + return editing; + } + + @Override + public void populateBean(ConditionGroup ob) { + editing = ob; + liteConditionPane.populateBean(ob.getCondition()); + } + } + + private class FormulaGroupPane extends JPanel { + + private String[] displayModeNames = {Inter.getLocText("GROUPING_MODE"), Inter.getLocText("LIST_MODE"), + Inter.getLocText("CONTINUUM_MODE")}; + + private String InsertText = " "; + + private UIComboBox modeComboBox; + private UITextField valueField; + private JPanel southPane; + + public FormulaGroupPane() { + this.setBorder(BorderFactory.createTitledBorder(Inter.getLocText("D-Dispaly_Divide_Result_Set_into_Groups"))); + this.setLayout(FRGUIPaneFactory.createM_BorderLayout()); + JPanel contentPane = FRGUIPaneFactory.createNColumnGridInnerContainer_S_Pane(1); + this.add(contentPane, BorderLayout.NORTH); + + JPanel northPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + northPane.setLayout(FRGUIPaneFactory.createBorderLayout()); + contentPane.add(northPane); + modeComboBox = new UIComboBox(displayModeNames); + + northPane.add(GUICoreUtils.createFlowPane(new JComponent[] { new UILabel(InsertText), new UILabel(Inter.getLocText("Display_Modes") + ": "), + modeComboBox }, FlowLayout.LEFT), BorderLayout.WEST); + + UILabel label = new UILabel("="); + label.setFont(new Font("Dialog", Font.BOLD, 12)); + valueField = new UITextField(16); + valueField.setText("$$$"); + + UIButton formulaButton = new UIButton("..."); + formulaButton.setToolTipText(Inter.getLocText("Formula") + "..."); + formulaButton.setPreferredSize(new Dimension(25, valueField.getPreferredSize().height)); + formulaButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + Formula valueFormula = new Formula(); + String text = valueField.getText(); + if (text == null || text.length() <= 0) { + valueFormula.setContent("$$$"); + } else { + valueFormula.setContent(text); + } + + final UIFormula formulaPane = FormulaFactory.createFormulaPane(); + + formulaPane.populate(valueFormula, new CustomVariableResolver(displayNames == null? new String[0] : displayNames, true)); + formulaPane.showLargeWindow(SwingUtilities.getWindowAncestor(FormulaGroupPane.this), new DialogActionAdapter(){ + @Override + public void doOk() { + Formula valueFormula = formulaPane.update(); + if (valueFormula.getContent().length() <= 1) { + valueField.setText("$$$"); + } else { + valueField.setText(valueFormula.getContent().substring(1)); + } + } + }).setVisible(true); + } + }); + + southPane = GUICoreUtils.createFlowPane(new JComponent[] {new UILabel(InsertText), //new UILabel(Inter.getLocText("I-Message_FunctionGrouper_2")), + new UILabel(Inter.getLocText(new String[]{"Custom", "Value"}) + ": "), label, valueField, formulaButton}, FlowLayout.LEFT); + contentPane.add(southPane); + } + + // populate + public void populate(RecordGrouper grouper) { + if (grouper instanceof FunctionGrouper) { + int mode = ((FunctionGrouper)grouper).getDivideMode(); + if (mode == FunctionGrouper.GROUPING_MODE) { + this.modeComboBox.setSelectedIndex(0); + } else if (mode == FunctionGrouper.LIST_MODE) { + this.modeComboBox.setSelectedIndex(1); + } else { + this.modeComboBox.setSelectedIndex(2); + } + String formulaContent = ((FunctionGrouper)grouper).getFormulaContent(); + if(formulaContent == null) { + this.valueField.setText("$$$"); + } else { + this.valueField.setText(formulaContent); + } + } + } + + public RecordGrouper update() { + FunctionGrouper grouper = new FunctionGrouper(); + grouper.setCustom(true); + if (this.modeComboBox.getSelectedIndex() == 0) { + grouper.setDivideMode(FunctionGrouper.GROUPING_MODE); + } else if (this.modeComboBox.getSelectedIndex() == 1) { + grouper.setDivideMode(FunctionGrouper.LIST_MODE); + } else if (this.modeComboBox.getSelectedIndex() == 2) { + grouper.setDivideMode(FunctionGrouper.CONTINUUM_MODE); + } + grouper.setFormulaContent(this.valueField.getText()); + + return grouper; + } + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/expand/ConditionParentPane.java b/designer/src/com/fr/design/expand/ConditionParentPane.java new file mode 100644 index 000000000..14d267ff8 --- /dev/null +++ b/designer/src/com/fr/design/expand/ConditionParentPane.java @@ -0,0 +1,74 @@ +package com.fr.design.expand; + + +import java.awt.FlowLayout; +import java.awt.event.ActionListener; + +import javax.swing.JComponent; +import com.fr.design.gui.ilable.UILabel; +import javax.swing.JPanel; + +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.cell.cellattr.CellExpandAttr; +import com.fr.design.utils.gui.GUICoreUtils; + +public class ConditionParentPane extends JPanel { + private ParentPane leftParentPane; + private ParentPane upParentPane; + + public ConditionParentPane() { + this.initComponents(null); + } + + public ConditionParentPane(ActionListener listener) { + this.initComponents(listener); + } + + + public void initComponents(ActionListener listener) { + JPanel innerthis=FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); + this.add(innerthis); + + + JPanel eastPane =FRGUIPaneFactory.createNormalFlowInnerContainer_M_Pane(); + innerthis.add(eastPane); + + eastPane.add(GUICoreUtils.createFlowPane(new JComponent[] { + new UILabel(Inter.getLocText("LeftParent") + ": "), + leftParentPane = new ParentPane(ParentPane.LEFT, listener) }, FlowLayout.LEFT)); + + eastPane.add(GUICoreUtils.createFlowPane( + new JComponent[] { + new UILabel(Inter.getLocText("UpParent") + ": "), + upParentPane = new ParentPane(ParentPane.UP, listener) }, FlowLayout.LEFT)); + } + public void putElementcase(ElementCasePane t){ + leftParentPane.putElementcase(t); + upParentPane.putElementcase(t); + } + public void putCellElement(TemplateCellElement cellElement){ + leftParentPane.putCellElement(cellElement); + upParentPane.putCellElement(cellElement); + } + + public void populate(CellExpandAttr cellExpandAttr) { + if (cellExpandAttr == null) { + cellExpandAttr = new CellExpandAttr(); + } + + this.leftParentPane.populate(cellExpandAttr); + this.upParentPane.populate(cellExpandAttr); + } + + public void update(CellExpandAttr cellExpandAttr) { + if (cellExpandAttr == null) { + cellExpandAttr = new CellExpandAttr(); + } + + this.leftParentPane.update(cellExpandAttr); + this.upParentPane.update(cellExpandAttr); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/expand/Expand.java b/designer/src/com/fr/design/expand/Expand.java new file mode 100644 index 000000000..5dfbb85bf --- /dev/null +++ b/designer/src/com/fr/design/expand/Expand.java @@ -0,0 +1,40 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.expand; + +import com.fr.stable.ColumnRow; + +/** + * @author richer + * @since 6.5.3 + */ +public class Expand { + private boolean _default; + private ColumnRow columnRow; + + public Expand(){ + + } + + public Expand(boolean _default, ColumnRow columnRow) { + this._default = _default; + this.columnRow = columnRow; + } + + public boolean isDefault() { + return this._default; + } + + public void setDefault(boolean _default) { + this._default = _default; + } + + public ColumnRow getParentColumnRow() { + return this.columnRow; + } + + public void setParentColumnRow(ColumnRow columnRow) { + this.columnRow = columnRow; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/expand/ExpandDirectionPane.java b/designer/src/com/fr/design/expand/ExpandDirectionPane.java new file mode 100644 index 000000000..c8d983795 --- /dev/null +++ b/designer/src/com/fr/design/expand/ExpandDirectionPane.java @@ -0,0 +1,101 @@ +package com.fr.design.expand; + +import java.awt.Component; +import java.awt.FlowLayout; +import java.awt.GridLayout; + +import javax.swing.ButtonGroup; + +import com.fr.design.gui.ibutton.UIRadioButton; +import com.fr.design.gui.ilable.UILabel; +import javax.swing.JPanel; + +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.general.Inter; +import com.fr.report.cell.cellattr.CellExpandAttr; +import com.fr.stable.Constants; +import com.fr.stable.StringUtils; +import com.fr.design.utils.gui.GUICoreUtils; +/** + * + * @editor zhou + * @since 2012-3-23下午3:21:02 + */ +public class ExpandDirectionPane extends JPanel { + + private UIRadioButton t2bRadioButton; + private UIRadioButton l2rRadioButton; + private UIRadioButton noneRadioButton; + private String InsertText = StringUtils.BLANK; + + public ExpandDirectionPane() { + super(); + this.initComponents(); + } + + public void initComponents() { + this.setLayout(new GridLayout(1, 3)); + JPanel innerthis=FRGUIPaneFactory.createNormalFlowInnerContainer_M_Pane(); + this.add(innerthis); + t2bRadioButton = new UIRadioButton(Inter.getLocText("Utils-Top_to_Bottom")); + l2rRadioButton = new UIRadioButton(Inter.getLocText("Utils-Left_to_Right")); + noneRadioButton = new UIRadioButton(Inter.getLocText("ExpandD-Not_Expand")); + ButtonGroup bg = new ButtonGroup(); + bg.add(t2bRadioButton); + bg.add(l2rRadioButton); + bg.add(noneRadioButton); + innerthis.add(GUICoreUtils.createFlowPane(new Component[]{new UILabel(InsertText), t2bRadioButton}, + FlowLayout.LEFT)); + innerthis.add(GUICoreUtils.createFlowPane(new Component[]{new UILabel(InsertText), l2rRadioButton}, + FlowLayout.LEFT)); + innerthis.add(GUICoreUtils.createFlowPane(new Component[]{new UILabel(InsertText), noneRadioButton}, + FlowLayout.LEFT)); + } + + public void populate(CellExpandAttr cellExpandAttr) { + if (cellExpandAttr == null) { + cellExpandAttr = new CellExpandAttr(); + } + + switch (cellExpandAttr.getDirection()) { + case Constants.TOP_TO_BOTTOM: + t2bRadioButton.setSelected(true); + break; + case Constants.LEFT_TO_RIGHT: + l2rRadioButton.setSelected(true); + break; + default: + noneRadioButton.setSelected(true); + } + } + + public void update(CellExpandAttr cellExpandAttr) { + if (cellExpandAttr == null) { + cellExpandAttr = new CellExpandAttr(); + } + + if (t2bRadioButton.isSelected()) { + cellExpandAttr.setDirection(Constants.TOP_TO_BOTTOM); + } else if (l2rRadioButton.isSelected()) { + cellExpandAttr.setDirection(Constants.LEFT_TO_RIGHT); + } else { + cellExpandAttr.setDirection(Constants.NONE); + } + } + + public void setNoneRadioButtonSelected(boolean isSummary) { + if (isSummary) { + this.noneRadioButton.setSelected(true); + this.l2rRadioButton.setEnabled(false); + this.t2bRadioButton.setEnabled(false); + this.noneRadioButton.setEnabled(false); + } else { + this.t2bRadioButton.setEnabled(true); + this.l2rRadioButton.setEnabled(true); + this.noneRadioButton.setEnabled(true); + if (this.noneRadioButton.isSelected()) { + this.t2bRadioButton.setSelected(true); + } + } + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/expand/ExpandFatherPane.java b/designer/src/com/fr/design/expand/ExpandFatherPane.java new file mode 100644 index 000000000..aeaf427d7 --- /dev/null +++ b/designer/src/com/fr/design/expand/ExpandFatherPane.java @@ -0,0 +1,179 @@ +package com.fr.design.expand; + +import com.fr.base.BaseUtils; +import com.fr.design.constants.LayoutConstants; +import com.fr.design.event.GlobalNameListener; +import com.fr.design.event.GlobalNameObserver; +import com.fr.design.gui.columnrow.ColumnRowPane; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.selection.CellSelection; +import com.fr.grid.selection.Selection; +import com.fr.report.cell.cellattr.CellExpandAttr; +import com.fr.design.selection.SelectionEvent; +import com.fr.design.selection.SelectionListener; +import com.fr.stable.ColumnRow; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; + +public abstract class ExpandFatherPane extends JPanel implements GlobalNameObserver { + + private UIComboBox comboBox; + private ColumnRowPane customParentColumnRowPane; + private ElementCasePane ePane; + private SelectionListener gridSelectionChangeListener; + private CellSelection oldSelection; + private String expandFatherName = ""; + private GlobalNameListener globalNameListener = null; + private boolean isAlreadyAddListener = false; + + public ExpandFatherPane() { + this.setLayout(new BorderLayout(0, LayoutConstants.VGAP_SMALL)); + comboBox = new UIComboBox(new String[]{ + Inter.getLocText("None"), + Inter.getLocText("Default"), + Inter.getLocText("Custom")}); + final CardLayout cardLayout = new CardLayout(); + final JPanel customPane = new JPanel(cardLayout); + customParentColumnRowPane = new ColumnRowPane() { + + @Override + public Dimension getPreferredSize() { + return new Dimension(super.getPreferredSize().width, 20); + } + + public void setGlobalName() { + if (shouldResponseNameListener()) { + globalNameListener.setGlobalName(expandFatherName); + } + } + }; + + UIButton imageButton = new UIButton(BaseUtils.readIcon("com/fr/design/images/buttonicon/select.png")); + imageButton.setPreferredSize(new Dimension(24, 20)); + JPanel cc = new JPanel(new BorderLayout(LayoutConstants.HGAP_SMALL, 0)); + cc.add(customParentColumnRowPane, BorderLayout.CENTER); + cc.add(imageButton, BorderLayout.EAST); + customPane.add(cc, "content"); + customPane.add(new JPanel(), "none"); + this.add(comboBox, BorderLayout.NORTH); + this.add(customPane, BorderLayout.CENTER); + comboBox.addItemListener(new ItemListener() { + + @Override + public void itemStateChanged(ItemEvent e) { + cardLayout.show(customPane, comboBox.getSelectedIndex() == 2 ? "content" : "none"); + if (globalNameListener != null && shouldResponseNameListener()) { + globalNameListener.setGlobalName(expandFatherName); + } + } + }); + imageButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + + if (ePane == null || isAlreadyAddListener) { + return; + } + oldSelection = (CellSelection) ePane.getSelection(); + ePane.getGrid().setNotShowingTableSelectPane(false); + ePane.setEditable(false); + ePane.repaint(10); + + gridSelectionChangeListener = new SelectionListener() { + + @Override + public void selectionChanged(SelectionEvent e) { + Selection selection = ePane.getSelection(); + if (selection instanceof CellSelection) { + CellSelection cellselection = (CellSelection) selection; + ColumnRow cr = ColumnRow.valueOf(cellselection.getColumn(), cellselection.getRow()); + ePane.setOldSelecton(oldSelection); + customParentColumnRowPane.setColumnRow(cr); + } + ePane.removeSelectionChangeListener(gridSelectionChangeListener); + isAlreadyAddListener = false; + ePane.getGrid().setNotShowingTableSelectPane(true); + ePane.setEditable(true); + ePane.repaint(); + } + }; + ePane.addSelectionChangeListener(gridSelectionChangeListener); + isAlreadyAddListener = true; + } + }); + comboBox.setSelectedIndex(1); + } + + /** + * @param listener 观察者监听事件 + */ + public void registerNameListener(GlobalNameListener listener) { + globalNameListener = listener; + } + + /** + * @return + */ + public boolean shouldResponseNameListener() { + return true; + } + + protected abstract ColumnRow getColumnRow(CellExpandAttr cellExpandAttr); + + protected abstract boolean isParentDefault(CellExpandAttr cellExpandAttr); + + public void populate(CellExpandAttr cellExpandAttr) { + ColumnRow columnRow = getColumnRow(cellExpandAttr); + if (isParentDefault(cellExpandAttr)) { + comboBox.setSelectedIndex(1); + this.customParentColumnRowPane.populate(ColumnRow.valueOf(0, 0)); + } else if (ColumnRow.validate(columnRow)) { + comboBox.setSelectedIndex(2); + this.customParentColumnRowPane.populate(columnRow); + } else { + comboBox.setSelectedIndex(0); + this.customParentColumnRowPane.populate(ColumnRow.valueOf(0, 0)); + } + } + + + public void setGlobalName(String name) { + expandFatherName = name; + this.comboBox.setGlobalName(name); + } + + protected abstract void setValue(CellExpandAttr cellExpandAttr, boolean isDefault, ColumnRow columnRow); + + public void update(CellExpandAttr cellExpandAttr) { + if (cellExpandAttr == null) { + cellExpandAttr = new CellExpandAttr(); + } + int i = comboBox.getSelectedIndex(); + switch (i) { + case 1: + setValue(cellExpandAttr, true, null); + break; + case 2: + setValue(cellExpandAttr, false, this.customParentColumnRowPane.update()); + break; + default: + setValue(cellExpandAttr, false, null); + break; + } + } + + public void setElementCasePane(ElementCasePane ePane) { + this.ePane = ePane; + } + + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/expand/ExpandLeftFatherPane.java b/designer/src/com/fr/design/expand/ExpandLeftFatherPane.java new file mode 100644 index 000000000..b697cad2b --- /dev/null +++ b/designer/src/com/fr/design/expand/ExpandLeftFatherPane.java @@ -0,0 +1,24 @@ +package com.fr.design.expand; + +import com.fr.report.cell.cellattr.CellExpandAttr; +import com.fr.stable.ColumnRow; + +public class ExpandLeftFatherPane extends ExpandFatherPane { + + @Override + protected ColumnRow getColumnRow(CellExpandAttr cellExpandAttr) { + return cellExpandAttr.getLeftParentColumnRow(); + } + + @Override + protected boolean isParentDefault(CellExpandAttr cellExpandAttr) { + return cellExpandAttr.isLeftParentDefault(); + } + + @Override + protected void setValue(CellExpandAttr cellExpandAttr, boolean isDefault, ColumnRow columnRow) { + cellExpandAttr.setLeftParentDefault(isDefault); + cellExpandAttr.setLeftParentColumnRow(columnRow); + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/expand/ExpandUpFatherPane.java b/designer/src/com/fr/design/expand/ExpandUpFatherPane.java new file mode 100644 index 000000000..3577c0859 --- /dev/null +++ b/designer/src/com/fr/design/expand/ExpandUpFatherPane.java @@ -0,0 +1,24 @@ +package com.fr.design.expand; + +import com.fr.report.cell.cellattr.CellExpandAttr; +import com.fr.stable.ColumnRow; + +public class ExpandUpFatherPane extends ExpandFatherPane { + + @Override + protected ColumnRow getColumnRow(CellExpandAttr cellExpandAttr) { + return cellExpandAttr.getUpParentColumnRow(); + } + + @Override + protected boolean isParentDefault(CellExpandAttr cellExpandAttr) { + return cellExpandAttr.isUpParentDefault(); + } + + @Override + protected void setValue(CellExpandAttr cellExpandAttr, boolean isDefault, ColumnRow columnRow) { + cellExpandAttr.setUpParentDefault(isDefault); + cellExpandAttr.setUpParentColumnRow(columnRow); + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/expand/ParentPane.java b/designer/src/com/fr/design/expand/ParentPane.java new file mode 100644 index 000000000..2d2757704 --- /dev/null +++ b/designer/src/com/fr/design/expand/ParentPane.java @@ -0,0 +1,353 @@ +package com.fr.design.expand; + +import java.awt.BorderLayout; +import java.awt.CardLayout; +import java.awt.Component; +import java.awt.Container; +import java.awt.Dialog; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Rectangle; +import java.awt.Window; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +import javax.swing.JComponent; +import javax.swing.JPanel; +import javax.swing.JTable; +import javax.swing.table.DefaultTableCellRenderer; + +import com.fr.base.BaseUtils; +import com.fr.design.constants.UIConstants; +import com.fr.design.cell.smartaction.AbstractSmartJTablePaneAction; +import com.fr.design.cell.smartaction.SmartJTablePane; +import com.fr.design.cell.smartaction.SmartJTablePaneAction; +import com.fr.design.gui.columnrow.ColumnRowPane; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.imenu.UIMenuItem; +import com.fr.design.gui.imenu.UIPopupMenu; +import com.fr.design.gui.itextfield.UITextField; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.present.ColumnRowTableModel; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.BasicPane; +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.GridUtils; +import com.fr.grid.selection.CellSelection; +import com.fr.grid.selection.FloatSelection; +import com.fr.grid.selection.Selection; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.cell.cellattr.CellExpandAttr; +import com.fr.design.selection.SelectionEvent; +import com.fr.design.selection.SelectionListener; +import com.fr.stable.ColumnRow; +import com.fr.stable.Constants; +import com.fr.stable.StableUtils; +import com.fr.design.utils.gui.GUICoreUtils; + +public class ParentPane extends BasicPane { + public static final int LEFT = 0; + public static final int UP = 1; + + private CardLayout cardLayout; + private JPanel parentCardPane; + private UITextField noneParentText; + private UITextField defaultParentText; + private ColumnRowPane customParentColumnRowPane; + private ElementCasePane ePane; + + private int leftOrUp = LEFT; + + private ActionListener cellAttrPaneListener = null; + + private transient TemplateCellElement oldCellElement; + + public ParentPane(int leftOrUp, ActionListener cellActionListener) { + this.leftOrUp = leftOrUp; + this.cellAttrPaneListener = cellActionListener; + this.initComponents(); + } + + private void initComponents() { + this.setLayout(new BorderLayout()); + final UIButton arrowButton = new UIButton(UIConstants.ARROW_DOWN_ICON); + ((UIButton) arrowButton).setRoundBorder(true, Constants.LEFT); + this.add(arrowButton, BorderLayout.EAST); + + cardLayout = new CardLayout(); + parentCardPane = FRGUIPaneFactory.createCardLayout_S_Pane(); + parentCardPane.setLayout(cardLayout); + customParentColumnRowPane = new ColumnRowPane(); + + UIButton imageButton4ColumnRowPane = new UIButton(BaseUtils.readIcon("com/fr/design/images/buttonicon/select.png")) { + @Override + public Dimension getPreferredSize() { + return new Dimension(24, 24); + } + }; + imageButton4ColumnRowPane.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (ePane == null || oldCellElement == null) { + return; + } + // 设置标志,为了不让grid dispose一些东西 + ePane.getGrid().setNotShowingTableSelectPane(false); + + ColumnRowTableModel model = new ColumnRowTableModel(); + model.addColumnRow(ColumnRow.valueOf(0, 0)); + BasicPane smartPane = new SmartJTablePane4CellExpandAttr(model, ePane); + Container dialog = ParentPane.this; + while (dialog != null) { + if (dialog instanceof Dialog) { + dialog.setVisible(false); + break; + } + dialog = dialog.getParent(); + } + + Window w = DesignerContext.getDesignerFrame(); + BasicDialog dlg = smartPane.showWindow(w); + ePane.setEditable(false); + dlg.setModal(false); + dlg.setVisible(true); + } + }); + + noneParentText = new UITextField(Inter.getLocText("None")); + noneParentText.setRectDirection(Constants.RIGHT); + parentCardPane.add("None", noneParentText); + defaultParentText = new UITextField(Inter.getLocText("Default")); + defaultParentText.setRectDirection(Constants.RIGHT); + parentCardPane.add("Default", defaultParentText); + parentCardPane.add("Custom", + GUICoreUtils.createFlowPane(new JComponent[] { customParentColumnRowPane, imageButton4ColumnRowPane }, FlowLayout.CENTER)); + + this.add(parentCardPane, BorderLayout.CENTER); + + final UIPopupMenu popup = createPopMenu(); + noneParentText.addMouseListener(new MouseAdapter() { + @Override + public void mousePressed(MouseEvent e) { + Rectangle leftRec = parentCardPane.getBounds(); + popup.setPopupSize(leftRec.width + arrowButton.getSize().width, popup.getPreferredSize().height); + popup.show(parentCardPane, 0, leftRec.height); + } + }); + + defaultParentText.addMouseListener(new MouseAdapter() { + @Override + public void mousePressed(MouseEvent e) { + Rectangle leftRec = parentCardPane.getBounds(); + popup.setPopupSize(leftRec.width + arrowButton.getSize().width, popup.getPreferredSize().height); + popup.show(parentCardPane, 0, leftRec.height); + } + }); + + arrowButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + Rectangle leftRec = parentCardPane.getBounds(); + popup.setPopupSize(leftRec.width + arrowButton.getSize().width, popup.getPreferredSize().height); + popup.show(parentCardPane, 0, leftRec.height); + } + }); + } + + @Override + protected String title4PopupWindow() { + return "parent"; + } + + public void putElementcase(ElementCasePane t) { + ePane = t; + } + + public void putCellElement(TemplateCellElement cellElement) { + oldCellElement = cellElement; + } + + private UIPopupMenu createPopMenu() { + UIPopupMenu pop = new UIPopupMenu(); + pop.setOnlyText(true); + UIMenuItem noneItem = new UIMenuItem(Inter.getLocText("None")); + if (cellAttrPaneListener != null) { + noneItem.addActionListener(cellAttrPaneListener); + } + noneItem.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + cardLayout.show(parentCardPane, "None"); + + } + }); + + UIMenuItem defaultItem = new UIMenuItem(Inter.getLocText("Default")); + if (cellAttrPaneListener != null) { + defaultItem.addActionListener(cellAttrPaneListener); + } + defaultItem.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + cardLayout.show(parentCardPane, "Default"); + } + }); + + UIMenuItem customItem = new UIMenuItem(Inter.getLocText("Custom")); + if (cellAttrPaneListener != null) { + customItem.addActionListener(cellAttrPaneListener); + } + customItem.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + cardLayout.show(parentCardPane, "Custom"); + } + }); + pop.add(noneItem); + pop.addSeparator(); + pop.add(defaultItem); + pop.addSeparator(); + pop.add(customItem); + + return pop; + } + + private boolean isLeft() { + return this.leftOrUp == LEFT; + } + + public void populate(CellExpandAttr cellExpandAttr) { + if (cellExpandAttr == null) { + cellExpandAttr = new CellExpandAttr(); + } + + ColumnRow columnRow = isLeft() ? cellExpandAttr.getLeftParentColumnRow() : cellExpandAttr.getUpParentColumnRow(); + if (isLeft() ? cellExpandAttr.isLeftParentDefault() : cellExpandAttr.isUpParentDefault()) { + this.cardLayout.show(parentCardPane, "Default"); + this.customParentColumnRowPane.populate(ColumnRow.valueOf(0, 0)); + if (ColumnRow.validate(columnRow)) { + this.defaultParentText.setText(Inter.getLocText("Default") + ":" + BaseUtils.convertColumnRowToCellString(columnRow)); + } else { + this.defaultParentText.setText(Inter.getLocText("Default")); + } + } else if (ColumnRow.validate(columnRow)) { + this.cardLayout.show(parentCardPane, "Custom"); + this.customParentColumnRowPane.populate(columnRow); + } else { + this.cardLayout.show(parentCardPane, "None"); + this.customParentColumnRowPane.populate(ColumnRow.valueOf(0, 0)); + } + } + + public void update(CellExpandAttr cellExpandAttr) { + if (cellExpandAttr == null) { + cellExpandAttr = new CellExpandAttr(); + } + + if (this.noneParentText.isVisible()) { + if (isLeft()) { + cellExpandAttr.setLeftParentDefault(false); + cellExpandAttr.setLeftParentColumnRow(null); + } else { + cellExpandAttr.setUpParentDefault(false); + cellExpandAttr.setUpParentColumnRow(null); + } + } else if (this.defaultParentText.isVisible()) { + if (isLeft()) { + cellExpandAttr.setLeftParentDefault(true); + cellExpandAttr.setLeftParentColumnRow(null); + } else { + cellExpandAttr.setUpParentDefault(true); + cellExpandAttr.setUpParentColumnRow(null); + } + + } else if (this.customParentColumnRowPane.isVisible()) { + if (isLeft()) { + cellExpandAttr.setLeftParentDefault(false); + cellExpandAttr.setLeftParentColumnRow(this.customParentColumnRowPane.update()); + } else { + cellExpandAttr.setUpParentDefault(false); + cellExpandAttr.setUpParentColumnRow(this.customParentColumnRowPane.update()); + } + + } + } + + + private class SmartJTablePane4CellExpandAttr extends SmartJTablePane { + public SmartJTablePane4CellExpandAttr(ColumnRowTableModel model, ElementCasePane actionReportPane) { + super(model, actionReportPane); + this.changeSmartJTablePaneAction(a); + this.changeGridSelectionChangeListener(listener); + } + + private SmartJTablePaneAction a = new AbstractSmartJTablePaneAction(this, ParentPane.this) { + @Override + public void doOk() { + GridUtils.doSelectCell(ePane, ParentPane.this.oldCellElement.getColumn(), ParentPane.this.oldCellElement.getRow()); + // 释放标志 + ePane.getGrid().setNotShowingTableSelectPane(true); + ePane.repaint(10); + ParentPane.this.cardLayout.show(parentCardPane, "Custom"); + ParentPane.this.customParentColumnRowPane.populate(((ColumnRowTableModel) SmartJTablePane4CellExpandAttr.this.table.getModel()) + .getColumnRow(0)); + } + }; + private SelectionListener listener = new SelectionListener(){ + + @Override + public void selectionChanged(SelectionEvent e) { + ElementCasePane currentReportPane = (ElementCasePane) e.getSource(); + Selection selection = currentReportPane.getSelection(); + if(selection instanceof FloatSelection){ + return; + } + CellSelection cellselection = (CellSelection) selection; + ColumnRowTableModel model = (ColumnRowTableModel) table.getModel(); + ColumnRow cr = ColumnRow.valueOf(cellselection.getColumn(), cellselection.getRow()); + model.setColumnRow(cr, 0); + model.fireTableDataChanged(); + } + }; + + @Override + public void setCellRenderer() { + javax.swing.table.TableColumn column0 = table.getColumnModel().getColumn(0); + column0.setCellRenderer(new ColumnTableCellRenderer()); + javax.swing.table.TableColumn column1 = table.getColumnModel().getColumn(1); + column1.setCellRenderer(new RowTableCellRenderer()); + } + + private class ColumnTableCellRenderer extends DefaultTableCellRenderer { + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + this.setText(StableUtils.convertIntToABC(((Integer) value) + 1)); + this.setBackground(java.awt.Color.cyan); + return this; + } + } + + private class RowTableCellRenderer extends DefaultTableCellRenderer { + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + this.setText((((Integer) value) + 1) + ""); + this.setBackground(java.awt.Color.cyan); + return this; + } + } + + @Override + protected String title4PopupWindow() { + return Inter.getLocText("RWA-Smart_Add_Cells"); + } + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/expand/SortExpandAttrPane.java b/designer/src/com/fr/design/expand/SortExpandAttrPane.java new file mode 100644 index 000000000..d346dd890 --- /dev/null +++ b/designer/src/com/fr/design/expand/SortExpandAttrPane.java @@ -0,0 +1,92 @@ +package com.fr.design.expand; + +import java.awt.BorderLayout; +import java.awt.CardLayout; + +import javax.swing.*; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +import com.fr.base.BaseUtils; +import com.fr.data.DataConstants; +import com.fr.design.formula.TinyFormulaPane; +import com.fr.design.gui.ibutton.UIButtonGroup; +import com.fr.general.Inter; +import com.fr.report.cell.cellattr.CellExpandAttr; +import com.fr.stable.StringUtils; + +public class SortExpandAttrPane extends JPanel { + private UIButtonGroup sort_type_pane; + private TinyFormulaPane tinyFormulaPane; + private CardLayout cardLayout; + private JPanel centerPane; + + + public SortExpandAttrPane() { + this.setLayout(new BorderLayout(0, 4)); + Icon[] iconArray = { + BaseUtils.readIcon("/com/fr/design/images/expand/none16x16.png"), + BaseUtils.readIcon("/com/fr/design/images/expand/asc.png"), + BaseUtils.readIcon("/com/fr/design/images/expand/des.png") + }; + String[] nameArray = { Inter.getLocText("Sort-Original"), Inter.getLocText("Sort-Ascending"), Inter.getLocText("Sort-Descending") }; + sort_type_pane = new UIButtonGroup(iconArray); + sort_type_pane.setAllToolTips(nameArray); + sort_type_pane.setGlobalName(Inter.getLocText("ExpandD-Sort_After_Expand")); + this.add(sort_type_pane, BorderLayout.NORTH); + + cardLayout = new CardLayout(); + centerPane = new JPanel(cardLayout); + + tinyFormulaPane = new TinyFormulaPane(); + + centerPane.add(new JPanel(), "none"); + centerPane.add(tinyFormulaPane, "content"); + + this.add(centerPane, BorderLayout.CENTER); + + sort_type_pane.addChangeListener(new ChangeListener() { + @Override + public void stateChanged(ChangeEvent e) { + cardLayout.show(centerPane, sort_type_pane.getSelectedIndex() == 0 ? "none" : "content"); + } + }); + } + + + + public void populate(CellExpandAttr cellExpandAttr) { + if (cellExpandAttr == null) { + cellExpandAttr = new CellExpandAttr(); + } + + int sort = cellExpandAttr.getOrder(); + this.sort_type_pane.setSelectedIndex(sort); + + String sortFormula = cellExpandAttr.getSortFormula(); + tinyFormulaPane.populateBean(sortFormula); + cardLayout.show(centerPane, sort_type_pane.getSelectedIndex() == 0 ? "none" : "content"); + } + + public void update(CellExpandAttr cellExpandAttr) { + if (cellExpandAttr == null) { + cellExpandAttr = new CellExpandAttr(); + } + + String sortFormula = null; + + cellExpandAttr.setOrder(this.sort_type_pane.getSelectedIndex()); + + if (cellExpandAttr.getOrder() != DataConstants.NONE) { + String sText = tinyFormulaPane.updateBean(); + if (StringUtils.isNotEmpty(sText)) { + cellExpandAttr.setSortFormula(sText); + } else { + cellExpandAttr.setSortFormula(sortFormula); + } + } else { + cellExpandAttr.setSortFormula(sortFormula); + } + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/headerfooter/EditFooterPane.java b/designer/src/com/fr/design/headerfooter/EditFooterPane.java new file mode 100644 index 000000000..895ee7642 --- /dev/null +++ b/designer/src/com/fr/design/headerfooter/EditFooterPane.java @@ -0,0 +1,28 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.headerfooter; + +import com.fr.general.Inter; +import com.fr.report.stable.ReportSettings; +import com.fr.stable.unit.UNIT; + +/** + * Edit footer(the object ReportHF). + */ +public class EditFooterPane extends HeaderFooterPane { + + @Override + protected String title4PopupWindow() { + return Inter.getLocText("HF-Edit_Footer"); + } + + public void populate(ReportSettings reportSettings) { + super.populate(reportSettings, false); + + } + + public UNIT updateReportSettings() { + return super.updateReportSettings(); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/headerfooter/EditHeaderPane.java b/designer/src/com/fr/design/headerfooter/EditHeaderPane.java new file mode 100644 index 000000000..dd59c4efe --- /dev/null +++ b/designer/src/com/fr/design/headerfooter/EditHeaderPane.java @@ -0,0 +1,29 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.headerfooter; + +import com.fr.page.ReportSettingsProvider; +import com.fr.general.Inter; +import com.fr.stable.unit.UNIT; + +/** + * Edit header(the object ReportHF). + */ +public class EditHeaderPane extends HeaderFooterPane { + + @Override + protected String title4PopupWindow() { + return Inter.getLocText("HF-Edit_Header"); + } + + public void populate(ReportSettingsProvider reportSettings) { + super.populate(reportSettings, true); + + } + + public UNIT updateReportSettings() { + return super.updateReportSettings(); + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/headerfooter/HFAttributesEditDialog.java b/designer/src/com/fr/design/headerfooter/HFAttributesEditDialog.java new file mode 100644 index 000000000..f30a6e212 --- /dev/null +++ b/designer/src/com/fr/design/headerfooter/HFAttributesEditDialog.java @@ -0,0 +1,367 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.headerfooter; + +import com.fr.base.Formula; +import com.fr.base.headerfooter.*; +import com.fr.design.dialog.BasicPane; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.formula.FormulaFactory; +import com.fr.design.formula.UIFormula; +import com.fr.design.gui.frpane.UITabbedPane; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itextarea.UITextArea; +import com.fr.design.gui.itextfield.UITextField; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.style.FRFontPane; +import com.fr.design.style.FormatPane; +import com.fr.general.ComparatorUtils; +import com.fr.general.Inter; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; + +/** + * The dialog used to edit + */ +public class HFAttributesEditDialog extends BasicPane { + + private HFElement hfElement = null; + private UITabbedPane tabbedPane; + //some tab pane. + private TextPane textPane; + private JPanel formulaPane; + private UITextField formulaContentField; + private FRFontPane frFontPane; + private FormatPane formatPane; + private ImagePane imagePane; + private NewLinePane newLinePane; + private UIButton moveLeftButton = null; + private UIButton moveRightButton = null; + private UIButton deleteButton = null; + private java.util.List moveActionListeners = new ArrayList(); + + /** + * Apply default pane. + */ + public HFAttributesEditDialog() { + this.setLayout(new BorderLayout(0, 4)); + + JPanel centerPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + this.add(centerPane); + + //top + JPanel topControlPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + centerPane.add(topControlPane, BorderLayout.NORTH); +// topControlPane.setLayout(FRGUIPaneFactory.createBorderLayout()); + + JPanel topControlButtonPane =FRGUIPaneFactory.createMediumHGapFlowInnerContainer_M_Pane(); + topControlPane.add(topControlButtonPane, BorderLayout.WEST); + + + moveLeftButton = new UIButton(Inter.getLocText("HF-Move_Left")); + moveLeftButton.setMnemonic('L'); + moveLeftButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + doMoveLeft(); + } + }); + topControlButtonPane.add(moveLeftButton); + + moveRightButton = new UIButton(Inter.getLocText("HF-Move_Right")); + moveRightButton.setMnemonic('R'); + moveRightButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + doMoveRight(); + } + }); + topControlButtonPane.add(moveRightButton); + + deleteButton = new UIButton(Inter.getLocText("HF-Delete_it")); + deleteButton.setMnemonic('D'); + deleteButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + doDelete(); + } + }); + topControlButtonPane.add(deleteButton); + + //tabbedpane + tabbedPane = new UITabbedPane(); + centerPane.add(tabbedPane, BorderLayout.CENTER); + + //init all tab panes. + textPane = new TextPane(); + formulaPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); + + formulaContentField = new UITextField(); + formulaPane.add(new UILabel(Inter.getLocText("Value") + ":")); + formulaPane.add(Box.createHorizontalStrut(2)); + UILabel label = new UILabel("="); + label.setFont(new Font("Dialog", Font.BOLD, 12)); + formulaPane.add(label); + formulaContentField = new UITextField(20); + formulaPane.add(formulaContentField); + + UIButton formulaButton = new UIButton("..."); + formulaPane.add(formulaButton); + formulaButton.setToolTipText(Inter.getLocText("Formula") + "..."); + formulaButton.setPreferredSize(new Dimension(25, formulaContentField.getPreferredSize().height)); + formulaButton.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent evt) { + Formula valueFormula = new Formula(); + String text = formulaContentField.getText(); + if (text == null || text.length() <= 0) { + valueFormula.setContent(""); + } else { + valueFormula.setContent(text); + } + + final UIFormula formulaPane = FormulaFactory.createFormulaPane(); + formulaPane.populate(valueFormula); + formulaPane.showLargeWindow(SwingUtilities.getWindowAncestor((Component)formulaPane), new DialogActionAdapter() { + + @Override + public void doOk() { + Formula valueFormula = formulaPane.update(); + if (valueFormula.getContent().length() <= 1) { + formulaContentField.setText(""); + } else { + formulaContentField.setText(valueFormula.getContent().substring(1)); + } + } + }).setVisible(true); + } + }); + frFontPane = new FRFontPane(); + formatPane = new FormatPane(); + imagePane = new ImagePane(); + newLinePane = new NewLinePane(); + } + + @Override + protected String title4PopupWindow() { + return Inter.getLocText("HF-Header_and_Footer"); + } + + /** + * Populate + */ + public void populate(HFElement hfElement) { + this.populate(hfElement, false); + } + + /** + * Populate + */ + public void populate(HFElement hfElement, boolean isInsert) { + this.hfElement = hfElement; + this.tabbedPane.removeAll(); + if (this.hfElement != null) { + if (ComparatorUtils.equals(this.hfElement.getClass(), TextHFElement.class)) { + this.addTextPaneToTab(); + this.addReportFontPaneToTab(); + this.textPane.populate(((TextHFElement) hfElement).getText()); + this.frFontPane.populate(((TextHFElement) hfElement).getFRFont()); + } else if (ComparatorUtils.equals(this.hfElement.getClass(), FormulaHFElement.class)) { + this.addFormulaPaneToTab(); + this.addReportFontPaneToTab(); + this.formulaContentField.setText(((FormulaHFElement) hfElement).getFormulaContent()); + this.frFontPane.populate(((FormulaHFElement) hfElement).getFRFont()); + } else if (ComparatorUtils.equals(this.hfElement.getClass(), PageNumberHFElement.class)) { + this.addReportFontPaneToTab(); + this.frFontPane.populate(((PageNumberHFElement) hfElement).getFRFont()); + } else if (ComparatorUtils.equals(this.hfElement.getClass(), NumberOfPageHFElement.class)) { + this.addReportFontPaneToTab(); + this.frFontPane.populate(((NumberOfPageHFElement) hfElement).getFRFont()); + } else if (ComparatorUtils.equals(this.hfElement.getClass(), DateHFElement.class)) { + this.addReportFontPaneToTab(); + this.addFormatPaneToTab(); + this.frFontPane.populate(((DateHFElement) hfElement).getFRFont()); + this.formatPane.populate(((DateHFElement) hfElement).getFormat()); + } else if (ComparatorUtils.equals(this.hfElement.getClass(), TimeHFElement.class)) { + this.addReportFontPaneToTab(); + this.addFormatPaneToTab(); + this.frFontPane.populate(((TimeHFElement) hfElement).getFRFont()); + this.formatPane.populate(((TimeHFElement) hfElement).getFormat()); + } else if (ComparatorUtils.equals(this.hfElement.getClass(), ImageHFElement.class)) { + this.addImagePaneToTab(); + this.imagePane.populate(((ImageHFElement) hfElement).getImage()); + } else if (ComparatorUtils.equals(this.hfElement.getClass(), NewLineHFElement.class)) { + this.addNewLinePaneToTab(); + } + } + this.tabbedPane.revalidate(); + if (isInsert) { + this.moveLeftButton.setEnabled(false); + this.moveRightButton.setEnabled(false); + deleteButton.setEnabled(false); + } else { + this.moveLeftButton.setEnabled(true); + this.moveRightButton.setEnabled(true); + deleteButton.setEnabled(true); + } + } + + /** + * Add text pane. + */ + private void addTextPaneToTab() { + this.tabbedPane.addTab(Inter.getLocText("Text"), this.textPane); + } + + /** + * Add parameter pane. + */ + private void addFormulaPaneToTab() { + this.tabbedPane.addTab(Inter.getLocText("Formula"), this.formulaPane); + } + + private void addReportFontPaneToTab() { + this.tabbedPane.addTab(Inter.getLocText("FRFont"), this.frFontPane); + } + + private void addFormatPaneToTab() { + this.tabbedPane.addTab(Inter.getLocText("Format"), this.formatPane); + } + + private void addImagePaneToTab() { + this.tabbedPane.addTab(Inter.getLocText("Image"), this.imagePane); + } + + private void addNewLinePaneToTab() { + this.tabbedPane.addTab(Inter.getLocText("HF-New_Line"), this.newLinePane); + } + + /** + * update + */ + public void update() { + if (this.hfElement == null) { + return; + } + + //update + if (ComparatorUtils.equals(this.hfElement.getClass(), TextHFElement.class)) { + ((TextHFElement) hfElement).setText(this.textPane.update()); + ((TextHFElement) hfElement).setFRFont(this.frFontPane.update()); + } else if (ComparatorUtils.equals(this.hfElement.getClass(),FormulaHFElement.class)) { + ((FormulaHFElement) hfElement).setFormulaContent(this.formulaContentField.getText()); + ((FormulaHFElement) hfElement).setFRFont(this.frFontPane.update()); + } else if (ComparatorUtils.equals(this.hfElement.getClass(),PageNumberHFElement.class)) { + ((PageNumberHFElement) hfElement).setFRFont(this.frFontPane.update()); + } else if (ComparatorUtils.equals(this.hfElement.getClass(),NumberOfPageHFElement.class)) { + ((NumberOfPageHFElement) hfElement).setFRFont(this.frFontPane.update()); + } else if (ComparatorUtils.equals(this.hfElement.getClass(),DateHFElement.class)) { + ((DateHFElement) hfElement).setFRFont(this.frFontPane.update()); + ((DateHFElement) hfElement).setFormat(this.formatPane.update()); + } else if (ComparatorUtils.equals(this.hfElement.getClass(),TimeHFElement.class)) { + ((TimeHFElement) hfElement).setFRFont(this.frFontPane.update()); + ((TimeHFElement) hfElement).setFormat(this.formatPane.update()); + } else if (ComparatorUtils.equals(this.hfElement.getClass(),ImageHFElement.class)) { + ((ImageHFElement) hfElement).setImage(this.imagePane.update()); + } else if (ComparatorUtils.equals(this.hfElement.getClass(),NewLineHFElement.class)) { + //Cannot be edit. + //((ImageHFElement) hfElement).setImage(this.newLinePane.update()); + } + } + + /** + * Do OK. + */ + public void doOK() { + update(); + + dialogExit(); + } + + public void addMoveActionListener(MoveActionListener l) { + this.moveActionListeners.add(l); + } + + /** + * move left action listener + */ + public void doMoveLeft() { + for (int i = 0, len = moveActionListeners.size(); i < len; i++) { + MoveActionListener l = (MoveActionListener) moveActionListeners.get(i); + if (l != null) { + l.doMoveLeft(); + } + } + } + + /** + * move right action listener + */ + public void doMoveRight() { + for (int i = 0, len = moveActionListeners.size(); i < len; i++) { + MoveActionListener l = (MoveActionListener) moveActionListeners.get(i); + if (l != null) { + l.doMoveRight(); + } + } + } + + /** + * Delete action listener + */ + public void doDelete() { + for (int i = 0, len = moveActionListeners.size(); i < len; i++) { + MoveActionListener l = (MoveActionListener) moveActionListeners.get(i); + if (l != null) { + l.doDelete(); + } + } + } + + /** + * Dialog exit. + */ + public void dialogExit() { + this.setVisible(false); + } + + private class TextPane extends JPanel { + + public TextPane() { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + + textArea = new UITextArea(); + this.add(new JScrollPane(textArea)); + } + + public void populate(String text) { + this.textArea.setText(text); + } + + public String update() { + return this.textArea.getText(); + } + private UITextArea textArea; + } + + private class NewLinePane extends JPanel { + + public NewLinePane() { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + + UILabel label = new UILabel(Inter.getLocText("HF-NewLine_Des")); + label.setHorizontalAlignment(SwingConstants.CENTER); + this.add(label, BorderLayout.CENTER); + + } + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/headerfooter/HFComponent.java b/designer/src/com/fr/design/headerfooter/HFComponent.java new file mode 100644 index 000000000..010860a93 --- /dev/null +++ b/designer/src/com/fr/design/headerfooter/HFComponent.java @@ -0,0 +1,306 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.headerfooter; + +import java.awt.Color; +import java.awt.Cursor; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; + +import javax.swing.BorderFactory; +import javax.swing.Icon; +import com.fr.design.gui.ilable.UILabel; +import javax.swing.JPopupMenu; +import javax.swing.JSeparator; +import javax.swing.SwingConstants; +import javax.swing.SwingUtilities; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +import com.fr.base.BaseUtils; +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.gui.imenu.UIMenuItem; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.general.Inter; +import com.fr.design.utils.gui.GUICoreUtils; + +/** + * The basic HF edit component. + */ +public class HFComponent extends UILabel implements MoveActionListener { + + private HFElement hfElement; + + private ActionListener moveLeftActionListener = null; + private ActionListener moveRightActionListener = null; + private ActionListener deleteActionListener = null; + private ChangeListener contentChangeListener = null; + + //popup menu + private JPopupMenu popupMenu; + + /** + * Constructor to set border. + */ + public HFComponent(HFElement hfElement) { + this.setBorder(BorderFactory.createLineBorder(Color.gray)); + this.setHorizontalAlignment(SwingConstants.CENTER); + + this.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + this.addMouseListener(this.editMouseListener); + + //popup menu + popupMenu = new JPopupMenu(); + + UIMenuItem editMenuItem = new UIMenuItem(Inter.getLocText("Edit") + "..."); + editMenuItem.setMnemonic('E'); + popupMenu.add(editMenuItem); + + editMenuItem.addMouseListener(this.editMouseListener); + + popupMenu.add(new JSeparator()); + + menuItemAction("HF-Move_Left",'L'); + + menuItemAction("HF-Move_Right",'R'); + + popupMenu.add(new JSeparator()); + + menuItemAction("Delete",'D'); + + this.setHFElement(hfElement); + } + + public void menuItemAction(String s,final char o){ + UIMenuItem menuItem = new UIMenuItem(Inter.getLocText(s)); + menuItem.setMnemonic(o); + popupMenu.add(menuItem); + + menuItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + switch(o){ + + case'D':doDelete(); + break; + + case'R':doMoveRight(); + break; + + case'L':doMoveLeft(); + break; + } + } + }); + } + + /** + * Return HFElement. + */ + public HFElement getHFElement() { + return this.hfElement; + } + + /** + * Set HFElement. + */ + public void setHFElement(HFElement hfElement) { + this.hfElement = hfElement; + + //ajust icon + this.setIcon(getHFElementIcon(hfElement)); + this.setToolTipText(getHFELementText(hfElement)); + } + + /** + * Return moveLeftActionListener + */ + public ActionListener getMoveLeftActionListener() { + return this.moveLeftActionListener; + } + + /** + * Set moveLeftActionListener + */ + public void setMoveLeftActionListener(ActionListener moveLeftActionListener) { + this.moveLeftActionListener = moveLeftActionListener; + } + + /** + * Return moveRightActionListener + */ + public ActionListener getMoveRightActionListener() { + return this.moveRightActionListener; + } + + /** + * Set moveRightActionListener + */ + public void setMoveRightActionListener(ActionListener moveRightActionListener) { + this.moveRightActionListener = moveRightActionListener; + } + + /** + * Return deleteActionListener. + */ + public ActionListener getDeleteActionListener() { + return this.deleteActionListener; + } + + /** + * Set deleteActionListener. + */ + public void setDeleteActionListener(ActionListener deleteActionListener) { + this.deleteActionListener = deleteActionListener; + } + + public ChangeListener getContentChangeListener() { + return contentChangeListener; + } + + public void setContentChangeListener(ChangeListener contentChangeListener) { + this.contentChangeListener = contentChangeListener; + } + + /** + * Return preferredsize. + */ + @Override + public Dimension getPreferredSize() { + return new Dimension(24, 24); + } + + /** + * Edit mouse listner. + */ + private MouseListener editMouseListener = new MouseAdapter() { + @Override + public void mouseReleased(MouseEvent evt) { + if (evt.isPopupTrigger()) {//donot suport right mouse action. + GUICoreUtils.showPopupMenu(popupMenu, HFComponent.this, + evt.getX(), evt.getY()); + return; + } + + popupHFAttributesEditDialog(); + } + }; + + /** + * Popup edit dialog + */ + private void popupHFAttributesEditDialog() { + final HFAttributesEditDialog hfAttributesEditDialog = new HFAttributesEditDialog(); + hfAttributesEditDialog.populate(hfElement); + hfAttributesEditDialog.addMoveActionListener(this); + hfAttributesEditDialog.showWindow(SwingUtilities.getWindowAncestor(HFComponent.this), new DialogActionAdapter(){ + @Override + public void doOk(){ + hfAttributesEditDialog.update(); + contentChanged(); + } + }).setVisible(true); + } + + /** + * Move left + */ + public void doMoveLeft() { + if (moveLeftActionListener != null) { + ActionEvent deleteEvt = new ActionEvent(HFComponent.this, 100, "Move Left"); + moveLeftActionListener.actionPerformed(deleteEvt); + } + } + + /** + * Move right + */ + public void doMoveRight() { + if (moveRightActionListener != null) { + ActionEvent deleteEvt = new ActionEvent(HFComponent.this, 100, "Move Right"); + moveRightActionListener.actionPerformed(deleteEvt); + } + } + + /** + * Delete + */ + public void doDelete() { + if (deleteActionListener != null) { + ActionEvent deleteEvt = new ActionEvent(HFComponent.this, 100, "Delete"); + deleteActionListener.actionPerformed(deleteEvt); + } + } + + /** + * DataChanged. + */ + private void contentChanged() { + if (this.contentChangeListener != null) { + ChangeEvent changeEvent = new ChangeEvent(HFComponent.this); + contentChangeListener.stateChanged(changeEvent); + } + } + + /** + * Gets the tooltip corresponding the HFElement. + */ + public static String getHFELementText(HFElement hfElement) { + if (hfElement.getClass().equals(TextHFElement.class)) { + return Inter.getLocText("Text"); + } else if (hfElement.getClass().equals(FormulaHFElement.class)) { + return Inter.getLocText("Formula"); + } else if (hfElement.getClass().equals(PageNumberHFElement.class)) { + return Inter.getLocText("HF-Page_Number"); + } else if (hfElement.getClass().equals(NumberOfPageHFElement.class)) { + return Inter.getLocText("HF-Number_of_Page"); + } else if (hfElement.getClass().equals(DateHFElement.class)) { + return Inter.getLocText("Date"); + } else if (hfElement.getClass().equals(TimeHFElement.class)) { + return Inter.getLocText("Time"); + } else if (hfElement.getClass().equals(ImageHFElement.class)) { + return Inter.getLocText("Image"); + } else if (hfElement.getClass().equals(NewLineHFElement.class)) { + return Inter.getLocText("HF-New_Line"); + } + + return Inter.getLocText("HF-Undefined"); + } + + /** + * Gets the icon corresponding the HFElement. + */ + public static Icon getHFElementIcon(HFElement hfElement) { + if (hfElement.getClass().equals(TextHFElement.class)) { + return BaseUtils.readIcon("/com/fr/base/images/dialog/headerfooter/text.png"); + } else if (hfElement.getClass().equals(FormulaHFElement.class)) { + return BaseUtils.readIcon("/com/fr/base/images/dialog/headerfooter/formula.png"); + } else if (hfElement.getClass().equals(PageNumberHFElement.class)) { + return BaseUtils.readIcon("/com/fr/base/images/dialog/headerfooter/page.png"); + } else if (hfElement.getClass().equals(NumberOfPageHFElement.class)) { + return BaseUtils.readIcon("/com/fr/base/images/dialog/headerfooter/pages.png"); + } else if (hfElement.getClass().equals(DateHFElement.class)) { + return BaseUtils.readIcon("/com/fr/base/images/dialog/headerfooter/date.png"); + } else if (hfElement.getClass().equals(TimeHFElement.class)) { + return BaseUtils.readIcon("/com/fr/base/images/dialog/headerfooter/time.png"); + } else if (hfElement.getClass().equals(ImageHFElement.class)) { + return BaseUtils.readIcon("/com/fr/base/images/dialog/headerfooter/image.png"); + } else if (hfElement.getClass().equals(NewLineHFElement.class)) { + return BaseUtils.readIcon("/com/fr/base/images/dialog/headerfooter/newLine.png"); + } + + return BaseUtils.readIcon("/com/fr/base/images/dialog/headerfooter/undefined.png"); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/headerfooter/HFContainer.java b/designer/src/com/fr/design/headerfooter/HFContainer.java new file mode 100644 index 000000000..fd73a2229 --- /dev/null +++ b/designer/src/com/fr/design/headerfooter/HFContainer.java @@ -0,0 +1,421 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.headerfooter; + +import java.awt.Dimension; +import java.awt.Rectangle; +import java.awt.SystemColor; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JViewport; +import javax.swing.Scrollable; +import javax.swing.SwingConstants; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +import com.fr.base.headerfooter.HFElement; +import com.fr.base.headerfooter.NewLineHFElement; +import com.fr.general.Inter; + +/** + * The container of HFComponent. + */ +public class HFContainer extends JPanel implements Scrollable { + private List hfComponentList = new ArrayList(); + + private static final int HOR_GAP = 1; + private static final int VER_GAP = 2; + + private ChangeListener contentChangeListener = null; + + /** + * Constructor. + */ + public HFContainer() { + this.setEnabled(true); + } + + @Override + public void setEnabled(boolean enabled) { + super.setEnabled(enabled); + + if (enabled) { + this.setBackground(UIManager.getColor("TextArea.background")); + } else { + this.setBackground(SystemColor.control); + } + } + + /** + * Refresh layout. + */ + private void refreshLayout() { + this.removeAll(); + + this.setLayout(null); + + int componentX = 2; + int componentY = VER_GAP; + + for (int i = 0; i < hfComponentList.size(); i++) { + HFComponent tmpHFComponent = (HFComponent) hfComponentList.get(i); + + this.add(tmpHFComponent); + tmpHFComponent.setLocation(componentX, componentY); + tmpHFComponent.setSize(tmpHFComponent.getPreferredSize().width, + tmpHFComponent.getPreferredSize().height); + + if (tmpHFComponent.getHFElement().getClass().equals(NewLineHFElement.class)) { + componentX = 2; + componentY += VER_GAP + tmpHFComponent.getPreferredSize().height; + } else { + + componentX += HOR_GAP + tmpHFComponent.getWidth(); + } + } + + this.doLayout(); + this.revalidate(); + this.repaint(); + + this.contentChanged(); + } + + public ChangeListener getContentChangeListener() { + return contentChangeListener; + } + + public void setContentChangeListener(ChangeListener contentChangeListener) { + this.contentChangeListener = contentChangeListener; + } + + /** + * DataChanged. + */ + private void contentChanged() { + if (this.contentChangeListener != null) { + ChangeEvent changeEvent = new ChangeEvent(HFContainer.this); + contentChangeListener.stateChanged(changeEvent); + } + } + + /** + * Populate + */ + public void populate(List hfElementList) { + this.hfComponentList.clear(); + + for (int i = 0; i < hfElementList.size(); i++) { + addHFComponent(new HFComponent((HFElement) hfElementList.get(i))); + } + + //refresh layout. + this.refreshLayout(); + } + + /** + * update + */ + public List update() { + List hfElementList = new ArrayList(); + + for (int i = 0; i < hfComponentList.size(); i++) { + hfElementList.add(((HFComponent) hfComponentList.get(i)).getHFElement()); + } + + return hfElementList; + } + + /** + * Add hfComponent. + * + * @param hfComponent the added object of HFComponent + */ + public void addHFComponent(HFComponent hfComponent) { + this.addHFComponent(-1, hfComponent); + } + + /** + * Add hfComponent at give position. + * + * @param index the given position. (-1 mean that add hfcomponent to the end). + * @param hfComponent the added object of HFComponent + */ + public void addHFComponent(int index, HFComponent hfComponent) { + if (index <= -1 || index > hfComponentList.size()) { + this.hfComponentList.add(hfComponent); + } else { + this.hfComponentList.add(index, hfComponent); + } + + //set move and delete actionListener + hfComponent.setMoveLeftActionListener(this.moveLeftActionListener); + hfComponent.setMoveRightActionListener(this.moveRightActionListener); + hfComponent.setDeleteActionListener(this.deleteActionListener); + + hfComponent.setContentChangeListener(this.getContentChangeListener()); + + //refresh layout. + this.refreshLayout(); + } + + /** + * Remove hfComponent. + */ + public void removeHFComponent(HFComponent hfComponent) { + if (hfComponentList.contains(hfComponent)) { + hfComponentList.remove(hfComponent); + + //refresh layout. + this.refreshLayout(); + } + } + + /** + * Move left hfComponent. + */ + public void moveLeftHFComponent(HFComponent hfComponent) { + int index = hfComponentList.indexOf(hfComponent); + + if (index > 0) { + Collections.swap(hfComponentList, index - 1, index); + } + + //refresh layout. + this.refreshLayout(); + } + + /** + * Move right hfComponent. + */ + public void moveRightHFComponent(HFComponent hfComponent) { + int index = hfComponentList.indexOf(hfComponent); + + if (index < hfComponentList.size() - 1) { + Collections.swap(hfComponentList, index, index + 1); + } + + //refresh layout. + this.refreshLayout(); + } + + /** + * Return preferredsize. + */ + @Override + public Dimension getPreferredSize() { + if (hfComponentList.size() <= 0) { + return super.getPreferredSize(); + } + + int componentWidth = 0; + int componentHeight = 0; + + int lineNumber = 0; + int maxComponentCount = 0; + + int tmpCompCount = 0; + for (int i = 0; i < hfComponentList.size(); i++) { + HFComponent tmpHFComponent = (HFComponent) hfComponentList.get(i); + + if (i == 0) { //caculate size. + componentWidth = tmpHFComponent.getPreferredSize().width; + componentHeight = tmpHFComponent.getPreferredSize().height; + } + + tmpCompCount++; + + if (tmpHFComponent.getHFElement().getClass().equals(NewLineHFElement.class)) { + maxComponentCount = Math.max(maxComponentCount, tmpCompCount); + lineNumber++; + + tmpCompCount = 0; + } + } + + maxComponentCount = Math.max(maxComponentCount, tmpCompCount); + lineNumber++; + + return new Dimension((componentWidth + HOR_GAP) * maxComponentCount + 3, + (componentHeight + VER_GAP) * lineNumber); + } + + /** + * Move left action listener. + */ + private ActionListener moveLeftActionListener = new ActionListener() { + public void actionPerformed(ActionEvent evt) { + Object obj = evt.getSource(); + + if (obj instanceof HFComponent) { + moveLeftHFComponent((HFComponent) obj); + } + } + }; + + /** + * Move right action listener. + */ + private ActionListener moveRightActionListener = new ActionListener() { + public void actionPerformed(ActionEvent evt) { + Object obj = evt.getSource(); + + if (obj instanceof HFComponent) { + moveRightHFComponent((HFComponent) obj); + } + } + }; + + /** + * Delete action listener + */ + private ActionListener deleteActionListener = new ActionListener() { + public void actionPerformed(ActionEvent evt) { + Object obj = evt.getSource(); + + if (obj instanceof HFComponent) { + int returnVal = JOptionPane.showConfirmDialog( + SwingUtilities.getWindowAncestor(HFContainer.this), + Inter.getLocText("HF-Are_you_sure_to_delete_it") + "?", + Inter.getLocText("Delete"), + JOptionPane.OK_CANCEL_OPTION, + JOptionPane.QUESTION_MESSAGE); + + if (returnVal == JOptionPane.OK_OPTION) { + removeHFComponent((HFComponent) obj); + } + } + } + }; + + // --- Scrollable methods --------------------------------------------- + + /** + * Returns the preferred size of the viewport for a view component. + * This is implemented to do the default behavior of returning + * the preferred size of the component. + * + * @return the preferredSize of a JViewport + * whose view is this Scrollable + */ + public Dimension getPreferredScrollableViewportSize() { + return getPreferredSize(); + } + + + /** + * Components that display logical rows or columns should compute + * the scroll increment that will completely expose one new row + * or column, depending on the value of orientation. Ideally, + * components should handle a partially exposed row or column by + * returning the distance required to completely expose the item. + *

+ * The default implementation of this is to simply return 10% of + * the visible area. Subclasses are likely to be able to provide + * a much more reasonable value. + * + * @param visibleRect the view area visible within the viewport + * @param orientation either SwingConstants.VERTICAL or + * SwingConstants.HORIZONTAL + * @param direction less than zero to scroll up/left, greater than + * zero for down/right + * @return the "unit" increment for scrolling in the specified direction + * @throws java.lang.IllegalArgumentException + * for an invalid orientation + * @see javax.swing.JScrollBar#setUnitIncrement + */ + public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) { + switch (orientation) { + case SwingConstants.VERTICAL: + return visibleRect.height / 10; + case SwingConstants.HORIZONTAL: + return visibleRect.width / 10; + default: + throw new IllegalArgumentException("Invalid orientation: " + orientation); + } + } + + + /** + * Components that display logical rows or columns should compute + * the scroll increment that will completely expose one block + * of rows or columns, depending on the value of orientation. + *

+ * The default implementation of this is to simply return the visible + * area. Subclasses will likely be able to provide a much more + * reasonable value. + * + * @param visibleRect the view area visible within the viewport + * @param orientation either SwingConstants.VERTICAL or + * SwingConstants.HORIZONTAL + * @param direction less than zero to scroll up/left, greater than zero + * for down/right + * @return the "block" increment for scrolling in the specified direction + * @throws java.lang.IllegalArgumentException + * for an invalid orientation + * @see javax.swing.JScrollBar#setBlockIncrement + */ + public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) { + switch (orientation) { + case SwingConstants.VERTICAL: + return visibleRect.height; + case SwingConstants.HORIZONTAL: + return visibleRect.width; + default: + throw new IllegalArgumentException("Invalid orientation: " + orientation); + } + } + + + /** + * Returns true if a viewport should always force the width of this + * Scrollable to match the width of the viewport. + * For example a normal text view that supported line wrapping + * would return true here, since it would be undesirable for + * wrapped lines to disappear beyond the right + * edge of the viewport. Note that returning true for a + * Scrollable whose ancestor is a JScrollPane + * effectively disables horizontal scrolling. + *

+ * Scrolling containers, like JViewport, + * will use this method each time they are validated. + * + * @return true if a viewport should force the Scrollables + * width to match its own + */ + public boolean getScrollableTracksViewportWidth() { + if (getParent() instanceof JViewport) { + return ((getParent()).getWidth() > getPreferredSize().width); + } + return false; + } + + /** + * Returns true if a viewport should always force the height of this + * Scrollable to match the height of the viewport. + * For example a columnar text view that flowed text in left to + * right columns could effectively disable vertical scrolling by + * returning true here. + *

+ * Scrolling containers, like JViewport, + * will use this method each time they are validated. + * + * @return true if a viewport should force the Scrollables height + * to match its own + */ + public boolean getScrollableTracksViewportHeight() { + if (getParent() instanceof JViewport) { + return ((getParent()).getHeight() > getPreferredSize().height); + } + return false; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/headerfooter/HeaderFooterEditPane.java b/designer/src/com/fr/design/headerfooter/HeaderFooterEditPane.java new file mode 100644 index 000000000..d966f4d45 --- /dev/null +++ b/designer/src/com/fr/design/headerfooter/HeaderFooterEditPane.java @@ -0,0 +1,679 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.headerfooter; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Rectangle; +import java.awt.SystemColor; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.geom.Rectangle2D; + +import javax.swing.BorderFactory; + +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.page.ReportSettingsProvider; +import com.fr.design.gui.ilable.UILabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JToolBar; +import javax.swing.JViewport; +import javax.swing.Scrollable; +import javax.swing.SwingConstants; +import javax.swing.SwingUtilities; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +import com.fr.base.BaseUtils; +import com.fr.base.GraphHelper; +import com.fr.base.PaperSize; +import com.fr.base.ScreenResolution; +import com.fr.design.DesignerEnvManager; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.icheckbox.UICheckBox; +import com.fr.design.gui.ispinner.UISpinner; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.general.Background; +import com.fr.general.Inter; +import com.fr.report.core.ReportHF; +import com.fr.stable.Constants; +import com.fr.stable.unit.CM; +import com.fr.stable.unit.FU; +import com.fr.stable.unit.INCH; +import com.fr.stable.unit.MM; +import com.fr.stable.unit.UNIT; +import com.fr.design.style.background.BackgroundPane; +import com.fr.design.utils.gui.GUICoreUtils; + +/** + * Edit header or footer(the object ReportHF). + */ +public class HeaderFooterEditPane extends JPanel { + private HFPreviewPane hfPreviewPane; + private JScrollPane scrollPreviewPane; + + private HFContainer leftHFContainer; + private HFContainer centerHFContainer; + private HFContainer rightHFContainer; + private HFContainer currentHFContainer; + private AdjustHeightPane headerUnitFieldPane; + private AdjustHeightPane footerUnitFieldPane; + private AdjustHeightPane headFootUnitFieldPane; + + private UICheckBox printBackgroundCheckBox; + private Background background; + + private double hfWidth; + /** + * Constructor + */ + public HeaderFooterEditPane() { + this.initComponents(); + } + + /** + * init components. + */ + protected void initComponents() { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + + JPanel centerPane =FRGUIPaneFactory.createBorderLayout_L_Pane(); + this.add(centerPane, BorderLayout.CENTER); + + JPanel hfPreviewContentPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + centerPane.add(hfPreviewContentPane, BorderLayout.CENTER); + hfPreviewContentPane.setBorder(GUICoreUtils.createTitledBorder(Inter.getLocText("Preview"),null)); + + hfPreviewPane = new HFPreviewPane(); + scrollPreviewPane = new JScrollPane(hfPreviewPane); + hfPreviewContentPane.add(scrollPreviewPane, BorderLayout.CENTER); + + JPanel controlPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + centerPane.add(controlPane, BorderLayout.NORTH); + controlPane.add(createToolbar(), BorderLayout.NORTH); + //center panel + JPanel controlContentPane = FRGUIPaneFactory.createNColumnGridInnerContainer_S_Pane(3); + controlPane.add(controlContentPane, BorderLayout.CENTER); + controlContentPane.setPreferredSize(new Dimension(centerPane.getPreferredSize().width, 120)); + + ChangeListener contentChangeListener = new ChangeListener() { + public void stateChanged(ChangeEvent e) { + refreshPreivewPane(); + } + }; + + leftHFContainer = new HFContainer(); + centerHFContainer = new HFContainer(); + rightHFContainer = new HFContainer(); + + leftHFContainer.addMouseListener(this.focusMouseListener); + centerHFContainer.addMouseListener(this.focusMouseListener); + rightHFContainer.addMouseListener(this.focusMouseListener); + + leftHFContainer.setContentChangeListener(contentChangeListener); + centerHFContainer.setContentChangeListener(contentChangeListener); + rightHFContainer.setContentChangeListener(contentChangeListener); + + controlContentPane.add(createContainerSection(Inter.getLocText("HF-Left_Section") + ":", leftHFContainer)); + controlContentPane.add(createContainerSection(Inter.getLocText("HF-Center_Section") + ":", centerHFContainer)); + controlContentPane.add(createContainerSection(Inter.getLocText("HF-Right_Section") + ":", rightHFContainer)); + + //set current HFContainer + setCurrentHFContainer(leftHFContainer); + + } + + private JToolBar createToolbar() { + //toolbar. + JToolBar toolbar = new JToolBar(); + toolbar.setFloatable(false); + Dimension separatorDimension = new Dimension(6, 18);//Separator分隔线 + + toolbar.add(this.createHFInsertButton(new TextHFElement())); + toolbar.add(this.createHFInsertButton(new FormulaHFElement())); + toolbar.addSeparator(separatorDimension); + toolbar.add(this.createHFInsertButton(new PageNumberHFElement())); + toolbar.add(this.createHFInsertButton(new NumberOfPageHFElement())); + toolbar.addSeparator(separatorDimension); + toolbar.add(this.createHFInsertButton(new DateHFElement())); + toolbar.add(this.createHFInsertButton(new TimeHFElement())); + toolbar.addSeparator(separatorDimension); + toolbar.add(this.createHFInsertButton(new ImageHFElement())); + toolbar.add(this.createHFInsertButton(new NewLineHFElement())); + toolbar.addSeparator(separatorDimension); + UIButton customBackgroundButton = new UIButton(); + customBackgroundButton.setToolTipText(Inter.getLocText("Background")); + customBackgroundButton.set4ToolbarButton(); + customBackgroundButton.setIcon(BaseUtils.readIcon("/com/fr/base/images/dialog/headerfooter/background.png")); + toolbar.add(customBackgroundButton); + customBackgroundButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + final BackgroundPane backgroundPane = new BackgroundPane(); + BasicDialog backgroundDialog = backgroundPane.showWindow( + SwingUtilities.getWindowAncestor(HeaderFooterEditPane.this)); + backgroundPane.populate(background); + backgroundDialog.addDialogActionListener(new DialogActionAdapter() { + @Override + public void doOk() { + background = backgroundPane.update(); + refreshPreivewPane(); + } + }); + backgroundDialog.setVisible(true); + } + }); + printBackgroundCheckBox = new UICheckBox(Inter.getLocText("ReportGUI-Print_Background")); + toolbar.add(printBackgroundCheckBox); + + toolbar.addSeparator(separatorDimension); + + JPanel headerPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); + headerUnitFieldPane = new AdjustHeightPane(); + headerPane.add(new UILabel(Inter.getLocText("PageSetup-Header") + ":")); + headerPane.add(headerUnitFieldPane); + + JPanel footerPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); + footerUnitFieldPane = new AdjustHeightPane(); + footerPane.add(new UILabel(Inter.getLocText("PageSetup-Footer") + ":")); + footerPane.add(footerUnitFieldPane); + + JPanel headerFooterPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); + headFootUnitFieldPane = new AdjustHeightPane(); + headerFooterPane.add(new UILabel(Inter.getLocText("Height") + ":")); + headerFooterPane.add(headFootUnitFieldPane); + + toolbar.add(headerFooterPane); + return toolbar; + } + + + /** + * Create HFInsertButton. + */ + public HFInsertButton createHFInsertButton(HFElement hfElement) { + HFInsertButton hfInsertButton = new HFInsertButton(hfElement); + hfInsertButton.addActionListener(insertActionListener); + + return hfInsertButton; + } + + /** + * Create container section. + */ + public JPanel createContainerSection(String containerTitle, HFContainer hfContainer) { + JPanel sectionPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + // sectionPane.setLayout(FRGUIPaneFactory.createBorderLayout()); + + UILabel titleLabel = new UILabel(containerTitle); + sectionPane.add(titleLabel, BorderLayout.NORTH); + + titleLabel.setHorizontalAlignment(SwingConstants.LEFT); + + sectionPane.add(new JScrollPane(hfContainer), BorderLayout.CENTER); + + return sectionPane; + } + + /** + * Popupate pane according to the input reportHF. + */ + public void populate(ReportHF reportHF, double hfWidth, double hfHeight) { + if (reportHF == null) { + reportHF = new ReportHF(); + } + + this.hfWidth = hfWidth; + + this.leftHFContainer.populate(reportHF.getLeftList()); + this.centerHFContainer.populate(reportHF.getCenterList()); + this.rightHFContainer.populate(reportHF.getRightList()); + + this.background = reportHF.getBackground(); + this.printBackgroundCheckBox.setSelected(reportHF.isPrintBackground()); + + //need to refrsh. + refreshPreivewPane(); + } + + /** + * Update reportHF according to current pane. + */ + public ReportHF update() { + ReportHF reportHF = new ReportHF(); + + reportHF.setLeftList(this.leftHFContainer.update()); + reportHF.setCenterList(this.centerHFContainer.update()); + reportHF.setRightList(this.rightHFContainer.update()); + + reportHF.setBackground(this.background); + reportHF.setPrintBackground(this.printBackgroundCheckBox.isSelected()); + + return reportHF; + } + + /** + * populate pageSetting + */ + public void populateReportSettings(ReportSettingsProvider reportSettings, boolean isHeader) { + headerUnitFieldPane.setUnitValue(reportSettings.getHeaderHeight()); + footerUnitFieldPane.setUnitValue(reportSettings.getFooterHeight()); + if (isHeader) { + headFootUnitFieldPane.setUnitValue(reportSettings.getHeaderHeight()); + } else { + headFootUnitFieldPane.setUnitValue(reportSettings.getFooterHeight()); + } + refreshPreivewPane(); + + } + + /** + * update pageSetting + */ + public UNIT updateReportSettings() { + return this.headFootUnitFieldPane.getUnitValue(); + } + + private void refreshPreivewPane() { + ReportHF reportHF = this.update(); + this.hfPreviewPane.refreshReportHFPaintable(reportHF, (int)hfWidth, (int)(this.headFootUnitFieldPane.getUnitValue().toPixD(ScreenResolution.getScreenResolution())), 1, 100, 1); + + } + + /** + * Insert action listner + */ + private ActionListener insertActionListener = new ActionListener() { + public void actionPerformed(ActionEvent evt) { + HFInsertButton hfInsertButton = (HFInsertButton) evt.getSource(); + + HFElement insertHFElement; + try { + insertHFElement = (HFElement) hfInsertButton.getHFElement().clone(); + } catch (CloneNotSupportedException cloneNotSupportedException) { + insertHFElement = hfInsertButton.getHFElement(); + } + + final HFComponent newHFComponent = new HFComponent(insertHFElement); + + //NewLineHFElement cannot be editable. + if (!insertHFElement.getClass().equals(NewLineHFElement.class)) { + //popup edit dialog. + final HFAttributesEditDialog hfAttributesEditDialog = new HFAttributesEditDialog(); + hfAttributesEditDialog.populate(insertHFElement, true); + + hfAttributesEditDialog.showWindow( + SwingUtilities.getWindowAncestor(HeaderFooterEditPane.this), + new DialogActionAdapter(){ + @Override + public void doOk() { + hfAttributesEditDialog.update(); + currentHFContainer.addHFComponent(newHFComponent); + + //need to refrsh. + refreshPreivewPane(); + } + + }).setVisible(true); + } + else + { + //显示换行符 + currentHFContainer.addHFComponent(newHFComponent); + } + + //need to refrsh. + refreshPreivewPane(); + } + }; + + /** + * Change focus listener + */ + private MouseListener focusMouseListener = new MouseAdapter() { + @Override + public void mousePressed(MouseEvent evt) { + Object obj = evt.getSource(); + + if (obj instanceof HFContainer) { + if (!((HFContainer) obj).isEnabled()) {//需要判断Enable. + return; + } + + ((HFContainer) obj).requestFocus(); + + //unfocus all. + leftHFContainer.setBorder(null); + centerHFContainer.setBorder(null); + rightHFContainer.setBorder(null); + + setCurrentHFContainer((HFContainer) obj); + } + } + }; + + /** + * Set current select HFContainer. + */ + private void setCurrentHFContainer(HFContainer hfContainer) { + currentHFContainer = hfContainer; + currentHFContainer.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY)); + } + + class HFPreviewPane extends JPanel implements Scrollable { + private int borderWidth = 8; + private int borderHeight = 20; + + private ReportHF reportHF = null; + private int hfWidth; + private int hfHeight; + private int pageNumber; + private int totalPageNumber; + private int firstPageNumber; + + public HFPreviewPane() { + //用默认数值. + this(new ReportHF(), + (int)(FU.getInstance(PaperSize.PAPERSIZE_A4.getWidth().toFU() - new INCH(0.75f).toFU() - new INCH(0.75f).toFU()).toPixD(ScreenResolution.getScreenResolution())), + (int)0.53 * ScreenResolution.getScreenResolution(), 1, 100, 1); + } + + public HFPreviewPane(ReportHF reportHF, int hfWidth, int hfHeight, int pageNumber, int totalPageNumber, int firstPageNumber) { + this.refreshReportHFPaintable(reportHF, hfWidth, hfHeight, pageNumber, totalPageNumber, firstPageNumber); + } + + public void refreshReportHFPaintable(ReportHF reportHF, int hfWidth, int hfHeight, int pageNumber, int totalPageNumber, int firstPageNumber) { + this.reportHF = reportHF; + this.hfWidth = hfWidth; + this.hfHeight = hfHeight; + this.pageNumber = pageNumber; + this.totalPageNumber = totalPageNumber; + this.firstPageNumber = firstPageNumber; + + if(scrollPreviewPane != null) { + scrollPreviewPane.validate(); + scrollPreviewPane.repaint(); + scrollPreviewPane.revalidate(); + } + } + + @Override + public void paintComponent(Graphics g) { + super.paintComponent(g); + if (reportHF == null) { + return; + } + + Graphics2D g2d = (Graphics2D) g; + + //size + Dimension size = this.getSize(); + if (!this.isEnabled()) { + g2d.setPaint(SystemColor.control); + } else { + g2d.setPaint(Color.WHITE); + } + g2d.fill(new Rectangle2D.Double(0, 0, size.getWidth(), size.getHeight())); + if (!this.isEnabled()) {//不能编辑,就不需要画了. + return; + } + + Rectangle2D rectangle2D = new Rectangle2D.Double( + Math.max(0, (size.getWidth() - this.hfWidth) / 2), borderHeight, + this.hfWidth, this.hfHeight); + + g2d.setPaint(Color.BLACK); + GraphHelper.draw(g2d, new Rectangle2D.Double(rectangle2D.getX() - 1, rectangle2D.getY() - 1, + rectangle2D.getWidth() + 1, rectangle2D.getHeight() + 1), Constants.LINE_DASH); + + this.reportHF.paint(g2d, rectangle2D, hfWidth, pageNumber, totalPageNumber, firstPageNumber, false, ScreenResolution.getScreenResolution()); + } + + /** + * Return preferredsize. + */ + @Override + public Dimension getPreferredSize() { + if (reportHF == null) { + return super.getPreferredSize(); + } + + return new Dimension((borderWidth * 2 + this.hfWidth), + (borderHeight * 2 + this.hfHeight)); + } + + // --- Scrollable methods --------------------------------------------- + + /** + * Returns the preferred size of the viewport for a view component. + * This is implemented to do the default behavior of returning + * the preferred size of the component. + * + * @return the preferredSize of a JViewport + * whose view is this Scrollable + */ + public Dimension getPreferredScrollableViewportSize() { + return getPreferredSize(); + } + + + /** + * Components that display logical rows or columns should compute + * the scroll increment that will completely expose one new row + * or column, depending on the value of orientation. Ideally, + * components should handle a partially exposed row or column by + * returning the distance required to completely expose the item. + *

+ * The default implementation of this is to simply return 10% of + * the visible area. Subclasses are likely to be able to provide + * a much more reasonable value. + * + * @param visibleRect the view area visible within the viewport + * @param orientation either SwingConstants.VERTICAL or + * SwingConstants.HORIZONTAL + * @param direction less than zero to scroll up/left, greater than + * zero for down/right + * @return the "unit" increment for scrolling in the specified direction + * @throws IllegalArgumentException for an invalid orientation + * @see javax.swing.JScrollBar#setUnitIncrement + */ + public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) { + switch (orientation) { + case SwingConstants.VERTICAL: + return visibleRect.height / 10; + case SwingConstants.HORIZONTAL: + return visibleRect.width / 10; + default: + throw new IllegalArgumentException("Invalid orientation: " + orientation); + } + } + + /** + * Components that display logical rows or columns should compute + * the scroll increment that will completely expose one block + * of rows or columns, depending on the value of orientation. + *

+ * The default implementation of this is to simply return the visible + * area. Subclasses will likely be able to provide a much more + * reasonable value. + * + * @param visibleRect the view area visible within the viewport + * @param orientation either SwingConstants.VERTICAL or + * SwingConstants.HORIZONTAL + * @param direction less than zero to scroll up/left, greater than zero + * for down/right + * @return the "block" increment for scrolling in the specified direction + * @throws IllegalArgumentException for an invalid orientation + * @see javax.swing.JScrollBar#setBlockIncrement + */ + public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) { + switch (orientation) { + case SwingConstants.VERTICAL: + return visibleRect.height; + case SwingConstants.HORIZONTAL: + return visibleRect.width; + default: + throw new IllegalArgumentException("Invalid orientation: " + orientation); + } + } + + + /** + * Returns true if a viewport should always force the width of this + * Scrollable to match the width of the viewport. + * For example a normal text view that supported line wrapping + * would return true here, since it would be undesirable for + * wrapped lines to disappear beyond the right + * edge of the viewport. Note that returning true for a + * Scrollable whose ancestor is a JScrollPane + * effectively disables horizontal scrolling. + *

+ * Scrolling containers, like JViewport, + * will use this method each time they are validated. + * + * @return true if a viewport should force the Scrollables + * width to match its own + */ + public boolean getScrollableTracksViewportWidth() { + if (getParent() instanceof JViewport) { + return ((getParent()).getWidth() > getPreferredSize().width); + } + return false; + } + + /** + * Returns true if a viewport should always force the height of this + * Scrollable to match the height of the viewport. + * For example a columnar text view that flowed text in left to + * right columns could effectively disable vertical scrolling by + * returning true here. + *

+ * Scrolling containers, like JViewport, + * will use this method each time they are validated. + * + * @return true if a viewport should force the Scrollables height + * to match its own + */ + public boolean getScrollableTracksViewportHeight() { + if (getParent() instanceof JViewport) { + return ((getParent()).getHeight() > getPreferredSize().height); + } + return false; + } + } + + /** + * HFInser button. + */ + class HFInsertButton extends UIButton { + private HFElement hfElement; + + public HFInsertButton(HFElement hfElement) { + this.setHFElement(hfElement); + this.set4ToolbarButton(); + } + + private void initAttributes() { + this.setIcon(HFComponent.getHFElementIcon(hfElement)); + this.setToolTipText(HFComponent.getHFELementText(hfElement)); + } + + public HFElement getHFElement() { + return this.hfElement; + } + + public void setHFElement(HFElement hfElement) { + this.hfElement = hfElement; + + //init attributes. + this.initAttributes(); + } + } + + /** + * AdjustHeightPane + */ + public class AdjustHeightPane extends JPanel { + private UISpinner valueSpinner; + private UILabel unitLabel; + + public AdjustHeightPane() { + this.setLayout(FRGUIPaneFactory.createBoxFlowLayout()); + + valueSpinner = new UISpinner(0, Integer.MAX_VALUE, 1, 0); + this.add(valueSpinner); + valueSpinner.addChangeListener(new ChangeListener() { + public void stateChanged(ChangeEvent e) { + refreshPreivewPane(); + } + + }); + + // Setting compobox contents... + unitLabel = new UILabel(); + + setUnitType(Constants.UNIT_MM); + } + + private void setUnitType(int unitType) { + if (unitType == Constants.UNIT_CM) { + unitLabel.setText(Inter.getLocText("Unit_CM")); + } else if (unitType == Constants.UNIT_INCH) { + unitLabel.setText(Inter.getLocText("PageSetup-inches")); + } else { + unitLabel.setText(Inter.getLocText("PageSetup-mm")); + } + + //ajust the heigt of unitLabel. + Dimension unitDimension = new Dimension(unitLabel.getPreferredSize().width, + valueSpinner.getPreferredSize().height); + unitLabel.setMinimumSize(unitDimension); + unitLabel.setMinimumSize(unitDimension); + unitLabel.setSize(unitDimension); + unitLabel.setPreferredSize(unitDimension); + + this.add(unitLabel); + } + + public UNIT getUnitValue() { + int unitType = DesignerEnvManager.getEnvManager().getPageLengthUnit(); + if (unitType == Constants.UNIT_CM) { + return new CM(((Number) valueSpinner.getValue()).floatValue()); + } else if (unitType == Constants.UNIT_INCH) { + return new INCH(((Number) valueSpinner.getValue()).floatValue()); + } else { + return new MM(((Number) valueSpinner.getValue()).floatValue()); + } + } + + public void setUnitValue(UNIT value) { + int unitType = DesignerEnvManager.getEnvManager().getPageLengthUnit(); + if (unitType == Constants.UNIT_CM) { + valueSpinner.setValue((int) value.toCMValue4Scale2()); + } else if (unitType == Constants.UNIT_INCH) { + valueSpinner.setValue((int) value.toINCHValue4Scale3()); + } else { + valueSpinner.setValue((int) value.toMMValue4Scale2()); + } + + setUnitType(unitType); + } + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/headerfooter/HeaderFooterPane.java b/designer/src/com/fr/design/headerfooter/HeaderFooterPane.java new file mode 100644 index 000000000..cd687dead --- /dev/null +++ b/designer/src/com/fr/design/headerfooter/HeaderFooterPane.java @@ -0,0 +1,238 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.headerfooter; + +import java.awt.BorderLayout; +import java.awt.Component; +import java.util.Hashtable; + +import javax.swing.BorderFactory; +import javax.swing.DefaultListModel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; + +import com.fr.base.BaseUtils; +import com.fr.base.PaperSize; +import com.fr.base.ScreenResolution; +import com.fr.page.ReportSettingsProvider; +import com.fr.design.gui.icheckbox.UICheckBox; +import com.fr.design.gui.icombobox.UIComboBoxRenderer; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.dialog.BasicPane; +import com.fr.general.Inter; +import com.fr.report.core.ReportHF; +import com.fr.report.stable.ReportConstants; +import com.fr.stable.unit.FU; +import com.fr.stable.unit.INCH; +import com.fr.stable.unit.UNIT; +import com.fr.design.utils.gui.GUICoreUtils; + +/** + * Edit header or footer(the object Header and Footer). + */ +public abstract class HeaderFooterPane extends BasicPane { + private Hashtable reportHFHash = new Hashtable(); + + private JList reportHFYypeList; + private int lastSelectedHFType = -1; + private UICheckBox defineCheckBox; + private HeaderFooterEditPane headerFooterEditPane; + private boolean isHeader; + + /** + * init components. + */ + public HeaderFooterPane() { + this.setLayout(new BorderLayout(0, 4)); + // Left pane + JPanel leftPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + this.add(leftPane, BorderLayout.WEST); + + DefaultListModel defaultListModel = new DefaultListModel(); + reportHFYypeList = new JList(defaultListModel); + reportHFYypeList.setCellRenderer(reportPageTypeRenderer); + reportHFYypeList + .addListSelectionListener(reportHFTypeSelectionListener); + JScrollPane hfTypeListScrollPane = new JScrollPane(reportHFYypeList); + leftPane.add(hfTypeListScrollPane, BorderLayout.CENTER); + + defaultListModel.addElement(new Integer( + ReportConstants.REPORTPAGE_DEFAULT)); + defaultListModel.addElement(new Integer( + ReportConstants.REPORTPAGE_FIRST)); + defaultListModel + .addElement(new Integer(ReportConstants.REPORTPAGE_LAST)); + defaultListModel + .addElement(new Integer(ReportConstants.REPORTPAGE_ODD)); + defaultListModel + .addElement(new Integer(ReportConstants.REPORTPAGE_EVEN)); + + // CenterPane. + JPanel centerPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + this.add(centerPane, BorderLayout.CENTER); + + JPanel definePane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); + centerPane.add(definePane, BorderLayout.NORTH); + + defineCheckBox = new UICheckBox(Inter + .getLocText("HF-Whether_to_define_the_selected_type"), true); + definePane.add(defineCheckBox); + defineCheckBox.addChangeListener(defineChangeListener); + + // HeaderFooterEditPane. + headerFooterEditPane = new HeaderFooterEditPane(); + centerPane.add(headerFooterEditPane, BorderLayout.CENTER); + headerFooterEditPane.setBorder(BorderFactory + .createLineBorder(GUICoreUtils.getTitleLineBorderColor())); + } + + /** + * populate reportSettings + * + * @param reportSettings + */ + public void populate(ReportSettingsProvider reportSettings, boolean isHeader) { + headerFooterEditPane.populateReportSettings(reportSettings, isHeader); + } + + /** + * update reportSettings + * + * @param reportSettings + */ + public UNIT updateReportSettings() { + return headerFooterEditPane.updateReportSettings(); + } + + public void populate(Hashtable reportHFHash) { + this.reportHFHash = reportHFHash; + + this.reportHFYypeList.setSelectedIndex(0); + } + + public Hashtable update() { + Object selectObj = reportHFYypeList.getSelectedValue(); + if (selectObj != null && selectObj instanceof Integer) { + if (defineCheckBox.isSelected()) { + reportHFHash.put(lastSelectedHFType, + headerFooterEditPane.update()); + } else { + reportHFHash.remove(new Integer(lastSelectedHFType)); + } + } + + return reportHFHash; + } + + ChangeListener defineChangeListener = new ChangeListener() { + public void stateChanged(ChangeEvent evt) { + Object selectObj = reportHFYypeList.getSelectedValue(); + if (selectObj == null || !(selectObj instanceof Integer)) { + return; + } + + int currentReportHFType = (Integer) selectObj; + if (defineCheckBox.isSelected()) { + GUICoreUtils.setEnabled(headerFooterEditPane, true); + reportHFHash.put(currentReportHFType, + headerFooterEditPane.update()); + } else { + GUICoreUtils.setEnabled(headerFooterEditPane, false); + reportHFHash.remove(new Integer(currentReportHFType)); + } + + reportHFYypeList.repaint(); + } + }; + + ListSelectionListener reportHFTypeSelectionListener = new ListSelectionListener() { + public void valueChanged(ListSelectionEvent evt) { + Object selectObj = reportHFYypeList.getSelectedValue(); + if (selectObj == null || !(selectObj instanceof Integer)) { + return; + } + + int currentReportHFType = (Integer) selectObj; + if (currentReportHFType != lastSelectedHFType) { + // 需要保存上次选择的页面. + if (lastSelectedHFType != -1) {// last SelectedHFType + if (defineCheckBox.isSelected()) { + reportHFHash.put(lastSelectedHFType, + headerFooterEditPane.update()); + } else { + reportHFHash.remove(new Integer(lastSelectedHFType)); + } + } + + lastSelectedHFType = currentReportHFType; + + // Populate当前的. + Object reportHFObject = reportHFHash.get(new Integer( + currentReportHFType)); + if (reportHFObject == null) { + defineCheckBox.setSelected(false); + } else { + defineCheckBox.setSelected(true); + } + headerFooterEditPane.populate((ReportHF) reportHFObject, + FU.getInstance(PaperSize.PAPERSIZE_A4.getWidth().toFU() - new INCH(0.75f).toFU() - new INCH(0.75f).toFU()).toPixD(ScreenResolution.getScreenResolution()), + 0.53 * ScreenResolution.getScreenResolution()); + +// headerFooterEditPane.populate(null, eventMask, eventMask); + // 默认页面 + if (currentReportHFType == ReportConstants.REPORTPAGE_DEFAULT) { + defineCheckBox.setSelected(true); + defineCheckBox.setEnabled(false); + } else { + defineCheckBox.setEnabled(true); + } + } + } + }; + + + UIComboBoxRenderer reportPageTypeRenderer = new UIComboBoxRenderer() { + @Override + public Component getListCellRendererComponent(JList list, Object value, + int index, boolean isSelected, boolean cellHasFocus) { + super.getListCellRendererComponent(list, value, index, isSelected, + cellHasFocus); + + if (value != null && value instanceof Integer) { + int reportHFType = (Integer) value; + + this + .setIcon(BaseUtils + .readIcon("/com/fr/base/images/oem/logo.png")); + if (reportHFType == ReportConstants.REPORTPAGE_DEFAULT) { + this.setText(Inter.getLocText("HF-Default_Page")); + } else if (reportHFType == ReportConstants.REPORTPAGE_FIRST) { + this.setText(Inter.getLocText("HF-First_Page")); + } else if (reportHFType == ReportConstants.REPORTPAGE_LAST) { + this.setText(Inter.getLocText("Utils-Last_Page")); + } else if (reportHFType == ReportConstants.REPORTPAGE_ODD) { + this.setText(Inter.getLocText("HF-Odd_Page")); + } else if (reportHFType == ReportConstants.REPORTPAGE_EVEN) { + this.setText(Inter.getLocText("HF-Even_Page")); + } + + if (reportHFHash != null) { + Object obj = reportHFHash.get(new Integer(reportHFType)); + if (obj == null) { + this.setEnabled(false); + } + } + } + + return this; + } + }; + + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/headerfooter/ImagePane.java b/designer/src/com/fr/design/headerfooter/ImagePane.java new file mode 100644 index 000000000..a67af0156 --- /dev/null +++ b/designer/src/com/fr/design/headerfooter/ImagePane.java @@ -0,0 +1,109 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.headerfooter; + +import java.awt.BorderLayout; +import java.awt.Image; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; + +import javax.swing.BorderFactory; +import javax.swing.JFileChooser; +import javax.swing.JPanel; +import javax.swing.JScrollPane; + +import com.fr.base.BaseUtils; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.dialog.BasicPane; +import com.fr.general.Inter; +import com.fr.stable.CoreGraphHelper; +import com.fr.design.style.background.image.ImageFileChooser; +import com.fr.design.style.background.image.ImagePreviewPane; + +/** + * Image Pane. + */ +public class ImagePane extends BasicPane { + private ImagePreviewPane imagePreviewPane; + private ImageFileChooser imageFileChooser = null; + + public ImagePane() { + this(true); + } + + public ImagePane(boolean hasPreviewBorder) { + this.setLayout(FRGUIPaneFactory.createM_BorderLayout()); + + //preview pane. + JPanel previewPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + this.add(previewPane); + +// previewPane.setLayout(FRGUIPaneFactory.createBorderLayout()); + if (hasPreviewBorder) { + previewPane.setBorder(BorderFactory.createTitledBorder(Inter.getLocText("Preview"))); + } + + imagePreviewPane = new ImagePreviewPane(); + previewPane.add(new JScrollPane(imagePreviewPane)); + + //select image + JPanel rightPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + this.add(rightPane, BorderLayout.EAST); + +// rightPane.setLayout(FRGUIPaneFactory.createBorderLayout()); + if (hasPreviewBorder) { + rightPane.setBorder(BorderFactory.createEmptyBorder(8, 2, 0, 2)); + } else { + rightPane.setBorder(BorderFactory.createEmptyBorder(4, 2, 0, 2)); + } + UIButton selectImageButton = new UIButton(Inter.getLocText("Image-Select_Picture")); + rightPane.add(selectImageButton, BorderLayout.NORTH); + selectImageButton.addActionListener(selectPictureActionListener); + + //init image file chooser. + imageFileChooser = new ImageFileChooser(); + imageFileChooser.setMultiSelectionEnabled(false); + } + + @Override + protected String title4PopupWindow() { + return "image"; + } + + public void populate(Image image) { + if(image == null) { + return; + } + + this.imagePreviewPane.setImage(image); + } + + public Image update() { + return this.imagePreviewPane.getImage(); + } + + /** + * Select picture. + */ + ActionListener selectPictureActionListener = new ActionListener() { + public void actionPerformed(ActionEvent evt) { + int returnVal = imageFileChooser.showOpenDialog(ImagePane.this); + if (returnVal != JFileChooser.CANCEL_OPTION) { + File selectedFile = imageFileChooser.getSelectedFile(); + + if (selectedFile != null && selectedFile.isFile()) { + Image image = BaseUtils.readImage(selectedFile.getPath()); + CoreGraphHelper.waitForImage(image); + + imagePreviewPane.setImage(image); + } else { + imagePreviewPane.setImage(null); + } + imagePreviewPane.repaint(); + } + } + }; +} \ No newline at end of file diff --git a/designer/src/com/fr/design/headerfooter/MoveActionListener.java b/designer/src/com/fr/design/headerfooter/MoveActionListener.java new file mode 100644 index 000000000..2f29218cf --- /dev/null +++ b/designer/src/com/fr/design/headerfooter/MoveActionListener.java @@ -0,0 +1,11 @@ +package com.fr.design.headerfooter; + +public interface MoveActionListener { + + public void doMoveLeft(); + + public void doMoveRight(); + + public void doDelete(); + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/javascript/ListenerEditPane.java b/designer/src/com/fr/design/javascript/ListenerEditPane.java new file mode 100644 index 000000000..8c76497af --- /dev/null +++ b/designer/src/com/fr/design/javascript/ListenerEditPane.java @@ -0,0 +1,177 @@ +package com.fr.design.javascript; + +import java.awt.BorderLayout; +import java.awt.CardLayout; +import java.awt.Component; +import java.awt.FlowLayout; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.BorderFactory; +import javax.swing.JPanel; + +import com.fr.design.beans.BasicBeanPane; +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.mainframe.DesignerContext; +import com.fr.design.mainframe.JTemplate; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.design.write.submit.DBManipulationPane; +import com.fr.form.event.Listener; +import com.fr.general.ComparatorUtils; +import com.fr.general.Inter; +import com.fr.js.Commit2DBJavaScript; +import com.fr.js.CustomActionJavaScript; +import com.fr.js.EmailJavaScript; +import com.fr.js.FormSubmitJavaScript; +import com.fr.js.JavaScript; +import com.fr.js.JavaScriptImpl; + +public class ListenerEditPane extends BasicBeanPane { + private UITextField nameText; + private UIComboBox styleBox; + private CardLayout card; + private JPanel hyperlinkPane; + + private JavaScriptImplPane javaScriptPane; + private FormSubmitJavaScriptPane formSubmitScriptPane; + private Commit2DBJavaScriptPane commit2DBJavaScriptPane; + // 自定义事件 + private CustomActionPane customActionPane; + // 发送邮件 + private EmailPane emailPane; + + private static final String JS = Inter.getLocText("JavaScript"); + private static final String FORMSUBMIT = Inter.getLocText("JavaScript-Form_Submit"); + private static final String DBCOMMIT = Inter.getLocText("JavaScript-Commit_to_Database"); + private static final String CUSTOMACTION= Inter.getLocText(new String[]{"Custom", "RWA-Submit"}); + private static final String EMAIL = Inter.getLocText("Email_sentEmail"); + + private Listener listener; + + public ListenerEditPane() { + this.initComponents(new String[0]); + } + + public ListenerEditPane(String[] defaultArgs) { + this.initComponents(defaultArgs); + } + + /** + * 初始化各个组件 + * @param defaultArgs 初始化参数 + */ + public void initComponents(String[] defaultArgs) { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + JPanel namePane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); + nameText = new UITextField(8); + nameText.setEditable(false); + namePane.add(nameText, BorderLayout.WEST); + String[] style = {JS, DBCOMMIT, CUSTOMACTION,EMAIL}; + styleBox = new UIComboBox(style); + namePane.add(styleBox); + namePane = GUICoreUtils.createFlowPane(new Component[]{new UILabel(" " + Inter.getLocText("Event_Name") + ":"), nameText, new UILabel(" " + Inter.getLocText("Event_Type") + ":"), styleBox}, FlowLayout.LEFT); + namePane.setBorder(BorderFactory.createTitledBorder(Inter.getLocText("Event_Name_Type"))); + this.add(namePane, BorderLayout.NORTH); + + card = new CardLayout(); + hyperlinkPane = FRGUIPaneFactory.createCardLayout_S_Pane(); + hyperlinkPane.setLayout(card); + // js + javaScriptPane = new JavaScriptImplPane(defaultArgs); + hyperlinkPane.add(JS, javaScriptPane); +// formSubmitScriptPane = new FormSubmitJavaScriptPane(JavaScriptActionPane.defaultJavaScriptActionPane +// .createCallButton()); +// hyperlinkPane.add(FORMSUBMIT, formSubmitScriptPane); + // 提交入库 + List dbmaniList = new ArrayList(); + dbmaniList.add(autoCreateDBManipulationPane()); + commit2DBJavaScriptPane = new Commit2DBJavaScriptPane(JavaScriptActionPane.defaultJavaScriptActionPane, + dbmaniList); + hyperlinkPane.add(DBCOMMIT, commit2DBJavaScriptPane); + // 自定义事件 + customActionPane = new CustomActionPane(); + hyperlinkPane.add(CUSTOMACTION, customActionPane); + + // 发送邮件 + emailPane = new EmailPane(); + hyperlinkPane.add(EMAIL,emailPane); + + hyperlinkPane.setBorder(BorderFactory.createTitledBorder(Inter.getLocText("JavaScript_Set"))); + this.add(hyperlinkPane); + + styleBox.addItemListener(new ItemListener() { + public void itemStateChanged(ItemEvent e) { + card.show(hyperlinkPane, styleBox.getSelectedItem().toString()); + } + }); + } + + /** + * 根据有无单元格创建 DBManipulationPane + * @return 有单元格。有智能添加单元格等按钮,返回 SmartInsertDBManipulationPane + */ + private DBManipulationPane autoCreateDBManipulationPane() { + JTemplate jTemplate = DesignerContext.getDesignerFrame().getSelectedJTemplate(); + return jTemplate.createDBManipulationPane(); + } + + @Override + protected String title4PopupWindow() { + return Inter.getLocText("Event_Set"); + } + + @Override + public void populateBean(Listener listener) { + this.listener = listener; + if (this.listener == null) { + this.listener = new Listener(); + } + + this.nameText.setText(listener.getEventName()); + + JavaScript js = listener.getAction(); + if (js instanceof JavaScriptImpl) { + styleBox.setSelectedItem(JS); + card.show(hyperlinkPane, JS); + javaScriptPane.populateBean((JavaScriptImpl)js); + } else if (js instanceof FormSubmitJavaScript){ + styleBox.setSelectedItem(FORMSUBMIT); + card.show(hyperlinkPane, FORMSUBMIT); + formSubmitScriptPane.populateBean((FormSubmitJavaScript)js); + } else if (js instanceof Commit2DBJavaScript) { + styleBox.setSelectedItem(DBCOMMIT); + card.show(hyperlinkPane, DBCOMMIT); + commit2DBJavaScriptPane.populateBean((Commit2DBJavaScript)js); + } else if (js instanceof EmailJavaScript){ + styleBox.setSelectedItem(EMAIL); + card.show(hyperlinkPane, EMAIL); + emailPane.populateBean((EmailJavaScript)js); + } else if (js instanceof CustomActionJavaScript){ + styleBox.setSelectedItem(CUSTOMACTION); + card.show(hyperlinkPane, CUSTOMACTION); + customActionPane.populateBean((CustomActionJavaScript) js); + } + } + + @Override + public Listener updateBean(){ + this.listener.setEventName(this.nameText.getText()); + if (ComparatorUtils.equals(styleBox.getSelectedItem(), JS)) { + this.listener.setAction(javaScriptPane.updateBean()); + } else if (ComparatorUtils.equals(styleBox.getSelectedItem(), FORMSUBMIT)) { + this.listener.setAction(formSubmitScriptPane.updateBean()); + } else if (ComparatorUtils.equals(styleBox.getSelectedItem(), DBCOMMIT)) { + this.listener.setAction(commit2DBJavaScriptPane.updateBean()); + } else if (ComparatorUtils.equals(styleBox.getSelectedItem(),EMAIL)){ + this.listener.setAction(emailPane.updateBean()); + } else if (ComparatorUtils.equals(styleBox.getSelectedItem(), CUSTOMACTION)){ + this.listener.setAction(customActionPane.updateBean()); + } + return this.listener; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/AbstractAttrPane.java b/designer/src/com/fr/design/mainframe/AbstractAttrPane.java new file mode 100644 index 000000000..f24cab32a --- /dev/null +++ b/designer/src/com/fr/design/mainframe/AbstractAttrPane.java @@ -0,0 +1,115 @@ +package com.fr.design.mainframe; + +import com.fr.design.gui.frpane.AbstractAttrNoScrollPane; +import com.fr.design.gui.iscrollbar.UIScrollBar; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.AdjustmentEvent; +import java.awt.event.AdjustmentListener; +import java.awt.event.MouseWheelEvent; +import java.awt.event.MouseWheelListener; + +/** + * 单元格属性表的每个tab对应的pane,已经实现了滚动条功能,如果页面装不下,会自动出来 + * 几点:子类不需要写构造函数了,所有的组件都放在createContentPane()方法生成的pane里面,它不需要考虑border。 + */ +public abstract class AbstractAttrPane extends AbstractAttrNoScrollPane { + private static final int MAXVALUE = 100; + private static final int TITLE_HEIGHT = 50; + private static final int MOUSE_WHEEL_SPEED = 5; + private static final int CONTENTPANE_WIDTH_GAP = 4; + private static final int SCROLLBAR_WIDTH = 8; + private int maxHeight = 280; + private int beginY = 0; + + private UIScrollBar scrollBar; + + public AbstractAttrPane() { + this.setLayout(new BarLayout()); + scrollBar = new UIScrollBar(UIScrollBar.VERTICAL) { + + @Override + public int getVisibleAmount() { + int preferredHeight = leftContentPane.getPreferredSize().height; + int e = MAXVALUE * (maxHeight) / preferredHeight; + setVisibleAmount(e); + return e; + } + + @Override + public int getMaximum() { + return MAXVALUE; + } + + }; + this.add(scrollBar); + this.add(leftContentPane); + + scrollBar.addAdjustmentListener(new AdjustmentListener() { + + @Override + public void adjustmentValueChanged(AdjustmentEvent e) { + adjustValues(); + } + }); + // august:鼠标滚轮滑动事件 + this.addMouseWheelListener(new MouseWheelListener() { + + @Override + public void mouseWheelMoved(MouseWheelEvent e) { + int value = scrollBar.getValue(); + value += MOUSE_WHEEL_SPEED * e.getWheelRotation(); + scrollBar.setValue(value); + adjustValues(); + } + }); + } + + /** + * 属性面板的滚动条和内容区域的布局管理类 + */ + protected class BarLayout implements LayoutManager { + + @Override + public void addLayoutComponent(String name, Component comp) { + + } + + @Override + public void removeLayoutComponent(Component comp) { + + } + + @Override + public Dimension preferredLayoutSize(Container parent) { + return leftContentPane.getPreferredSize(); + } + + @Override + public Dimension minimumLayoutSize(Container parent) { + return leftContentPane.getMinimumSize(); + } + + @Override + public void layoutContainer(Container parent) { + maxHeight = CellElementPropertyPane.getInstance().getHeight() - TITLE_HEIGHT; + if ((MAXVALUE - scrollBar.getVisibleAmount()) == 0) { + beginY = 0; + } else { + int preferredHeight = leftContentPane.getPreferredSize().height; + int value = scrollBar.getValue(); + beginY = value * (preferredHeight - maxHeight) / (MAXVALUE - scrollBar.getVisibleAmount()); + } + int width = parent.getWidth(); + int height = parent.getHeight(); + if (leftContentPane.getPreferredSize().height > maxHeight) { + leftContentPane.setBounds(0, -beginY, width - scrollBar.getWidth() - CONTENTPANE_WIDTH_GAP, height + beginY); + scrollBar.setBounds(width - scrollBar.getWidth() - 1, 0, scrollBar.getWidth(), height); + } else { + leftContentPane.setBounds(0, 0, width - SCROLLBAR_WIDTH - CONTENTPANE_WIDTH_GAP, height); + } + leftContentPane.validate(); + } + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/ActiveKeyGenerator.java b/designer/src/com/fr/design/mainframe/ActiveKeyGenerator.java new file mode 100644 index 000000000..7f52a21ab --- /dev/null +++ b/designer/src/com/fr/design/mainframe/ActiveKeyGenerator.java @@ -0,0 +1,266 @@ +package com.fr.design.mainframe; +import com.fr.base.BaseUtils; +import com.fr.design.DesignerEnvManager; +import com.fr.design.mainframe.bbs.BBSConstants; +import com.fr.general.http.HttpClient; +import com.fr.stable.StringUtils; +import com.fr.stable.core.UUID; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map.Entry; + +/** + * 限定以"-"分割得到数组长度=4; + * 至少包含10个以上不同的字符 + * 每7位字符, 要求可以被7整除 + * 限定同一个字符, 不可以出现10次以上 + * 限定不能出现7个字符内全是字母的情况 + * + * @author neil + * + * @date: 2015-4-8-上午8:49:05 + */ +public class ActiveKeyGenerator { + + //没网的情况, 返回认证错误, 下次启动再去认证 + public static final int AUTH_ERROR = -1; + //认证成功 + public static final int AUTH_SUCCESS = 0; + //认证失败 + public static final int AUTH_FAILED = 1; + + private static final int CONNECT_LEN = 4; + private static final int KEY_LEN = 5; + private static final int MIN_NUM_COUNT = 10; + private static final int MAGIC_NUM = 7; + private static final String SPLIT_CHAR = "-"; + private static final int MAX_TRY_COUNT = 100; + + /** + * 生成激活码, 用于从老的激活码生成新的 + * + * @return 8.0新的激活码 + * + */ + public static String generateActiveKey(){ + for (int i = 0; i < MAX_TRY_COUNT; i++) { + String key = UUID.randomUUID().toString(); + + char[] keyChar = key.toCharArray(); + int len = keyChar.length; + int[] numArray = new int[len]; + + if(invalidEachCharCount(len, keyChar, numArray)){ + continue; + } + + if(isCharAllNum(len, numArray, keyChar)){ + continue; + } + + String activeKey = new String(keyChar); + //跑出来的key, 自己再去认证下 + if(!localVerify(activeKey)){ + continue; + } + return activeKey; + } + + return StringUtils.EMPTY; + } + + /** + * 验证key合法性, 包括本地和在线验证 + * + * @param key 激活码 + * @param timeout 验证超时时间 + * + * @return 是否合法 + * + */ + public static boolean verify(String key, int timeout){ + return localVerify(key) && onLineVerify(key, timeout); + } + + /** + * 在线校验激活码(超时也算验证通过, 但是会在下次联网时继续验证) + * + * @param key 激活码 + * + * @return 是否验证通过 + * + */ + public static boolean onLineVerify(String key){ + return onLineVerify(key, -1); + } + + //准备验证的HttpClient + private static HttpClient prepareVerifyConnect(DesignerEnvManager envManager, int timeout, String key){ + HashMap para = new HashMap(); + para.put("uuid", envManager.getUUID()); + para.put("key", key); + para.put("username", envManager.getBBSName()); + HttpClient hc = new HttpClient(BBSConstants.VERIFY_URL, para); + if (timeout != -1) { + hc.setTimeout(timeout); + } + + return hc; + } + + /** + * 在线校验激活码(超时也算验证通过, 但是会在下次联网时继续验证) + * + * @param key 激活码 + * @param timeout 超时时间 + * + * @return 是否验证通过 + * + */ + public static boolean onLineVerify(String key, int timeout){ + DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); + HttpClient hc = prepareVerifyConnect(envManager, timeout, key); + + //先关闭掉在线验证, 服务器扛不住, 先内网跑并发测试下性能, 确定了问题在开放. + if (true || !hc.isServerAlive()) { + //连不上服务器的话, 先算通过, 下次重启还会继续在线验证 + return true; + } + + boolean res = Boolean.valueOf(hc.getResponseText()); + if (res) { + //联网验证通过了, 就把验证通过的状态存起来, 下次就不用联网验证了. + envManager.setActiveKeyStatus(AUTH_SUCCESS); + } else { + //如果没验证通过, 清空掉当前activekey.当他重启后, 重新输入激活码 + envManager.setActivationKey(StringUtils.EMPTY); + } + + return res; + } + + /** + * 本地校验激活码 + * + * @param key 激活码 + * + * @return 是否验证通过 + * + */ + public static boolean localVerify(String key){ + if(StringUtils.isEmpty(key) || invalidSplitLength(key)){ + return false; + } + char[] keyChar = key.toCharArray(); + int len = keyChar.length; + int[] numArray = new int[len]; + + if(invalidEachCharCount(len, keyChar, numArray)){ + return false; + } + + int count = len / MAGIC_NUM; + if (count != KEY_LEN) { + return false; + } + //检测余数 + return validRemain(count, numArray); + } + + //是否全字母 + private static boolean isCharAllNum(int len, int[] numArray, char[] keyChar){ + int count = len / MAGIC_NUM; + for (int j = 0; j < count; j++) { + int temp = 0; + for (int k = 0; k < MAGIC_NUM; k++) { + temp = temp + numArray[k + j * MAGIC_NUM]; + } + if(temp == 0){ + return true; + } + + updateRemain(temp, numArray, j, keyChar); + } + + return false; + } + + //是否符合规定的split格式 + private static boolean invalidSplitLength(String key){ + return key.split(SPLIT_CHAR).length != CONNECT_LEN; + } + + //获取char对应的int值 + private static int getCharIntValue(char charStr){ + if (!BaseUtils.isNum(charStr)) { + return 0; + } + return Character.getNumericValue(charStr); + } + + //校验余数 + private static boolean validRemain(int count, int[] numArray){ + for (int j = 0; j < count; j++) { + int temp = 0; + for (int k = 0; k < MAGIC_NUM; k++) { + temp = temp + numArray[k + j * MAGIC_NUM]; + } + if (temp == 0){ + return false; + } + + if(temp % MAGIC_NUM != 0){ + return false; + } + } + + return true; + } + + //判断是否存在不合法(过多)的某一个字符 + private static boolean invalidEachCharCount(int len, char[] keyChar, int[] numArray){ + HashMap hs = new HashMap(); + for (int j = 0; j < len; j++) { + int count = hs.containsKey(keyChar[j]) ? hs.get(keyChar[j]) + 1 : 1; + hs.put(keyChar[j], count); + numArray[j] = getCharIntValue(keyChar[j]); + } + + if (hs.size() <= MIN_NUM_COUNT) { + return true; + } + + Iterator> it = hs.entrySet().iterator(); + while (it.hasNext()) { + Entry entry = it.next(); + if(entry.getValue() > MIN_NUM_COUNT){ + return true; + } + } + + return false; + } + + //更新余数 + private static void updateRemain(int temp, int[] numArray, int j, char[] keyChar){ + //余数 + int remain = temp % MAGIC_NUM; + int lastMagicIndex = MAGIC_NUM - 1 + j * MAGIC_NUM; + int newNum = numArray[lastMagicIndex] - remain; + while(newNum <= 0){ + newNum += MAGIC_NUM; + } + + keyChar[lastMagicIndex] = (char)(newNum + '0'); + } + + public static void main(String[] args) { + String a = "671b3b43-cfb4-40e7-9ca8-fe71ba33b8e3"; + + String key = generateActiveKey(); + + boolean verify = localVerify(key); + System.out.println(verify); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/AuthorityEditToolBarPane.java b/designer/src/com/fr/design/mainframe/AuthorityEditToolBarPane.java new file mode 100644 index 000000000..d0534f9f2 --- /dev/null +++ b/designer/src/com/fr/design/mainframe/AuthorityEditToolBarPane.java @@ -0,0 +1 @@ +package com.fr.design.mainframe; import com.fr.design.constants.LayoutConstants; import com.fr.design.constants.UIConstants; import com.fr.design.roleAuthority.ReportAndFSManagePane; import com.fr.design.roleAuthority.RolesAlreadyEditedPane; import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.gui.icheckbox.UICheckBox; 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.webattr.ToolBarButton; import com.fr.general.ComparatorUtils; import com.fr.general.Inter; import javax.swing.*; import java.awt.*; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.util.List; /** * 用于在权限编辑状态对工具栏的元素进行权限编辑的面板 * Author : daisy * Date: 13-9-18 * Time: 下午2:15 */ public class AuthorityEditToolBarPane extends AuthorityPropertyPane { private static final int TITLE_HEIGHT = 19; private AuthorityEditPane authorityEditPane = null; private AuthorityToolBarPane authorityToolBarPane; public AuthorityEditToolBarPane(List buttonlists) { super(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()); this.setLayout(new BorderLayout()); this.setBorder(null); UILabel authorityTitle = new UILabel(Inter.getLocText(new String[]{"DashBoard-Potence", "Edit"})) { @Override public Dimension getPreferredSize() { return new Dimension(super.getPreferredSize().width, TITLE_HEIGHT); } }; authorityTitle.setHorizontalAlignment(SwingConstants.CENTER); authorityTitle.setVerticalAlignment(SwingConstants.CENTER); JPanel northPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); northPane.add(authorityTitle, BorderLayout.CENTER); northPane.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, UIConstants.LINE_COLOR)); this.add(northPane, BorderLayout.NORTH); authorityEditPane = new AuthorityEditPane(buttonlists); this.add(authorityEditPane, BorderLayout.CENTER); } public void setAuthorityToolBarPane(AuthorityToolBarPane authorityToolBarPane) { this.authorityToolBarPane = authorityToolBarPane; } public void populate() { authorityToolBarPane.populateAuthority(); signelSelection(); authorityEditPane.populateDetials(); } private void signelSelection() { JTemplate jTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); if (jTemplate.isJWorkBook()) { //清参数面板 jTemplate.removeParameterPaneSelection(); //清报表主体 jTemplate.removeTemplateSelection(); } } private class AuthorityEditPane extends JPanel { private static final int TOP_GAP = 11; private static final int LEFT_GAP = 8; private static final int ALIGNMENT_GAP = -3; private UILabel type = null; private UILabel name = null; private JPanel checkPane = null; private List buttonlists; private UICheckBox buttonVisible = new UICheckBox(Inter.getLocText("Widget-Visible")); private ItemListener itemListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { String selectedRole = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); if (ComparatorUtils.equals(selectedRole, Inter.getLocText("Role"))) { return; } if (selectedRole == null) { return; } for (int i = 0; i < buttonlists.size(); i++) { if (buttonlists.get(i).isSelected()) { buttonlists.get(i).changeAuthorityState(selectedRole, buttonVisible.isSelected()); authorityToolBarPane.repaint(); } } HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().fireTargetModified(); RolesAlreadyEditedPane.getInstance().refreshDockingView(); UICheckBox checkbox = (UICheckBox) e.getSource(); List _buttonlists = AuthorityEditPane.this.buttonlists; for (int j = 0; j < _buttonlists.size(); j++) { if (_buttonlists.get(j).isSelected()) { //由引擎实现保存进模板报表 authorityToolBarPane.setAuthorityWebAttr(_buttonlists.get(j).getWidget(), checkbox.isSelected(), selectedRole); } } } }; public AuthorityEditPane(List buttonlists) { setLayout(new BorderLayout()); type = new UILabel(); name = new UILabel(); checkPane = new JPanel(); checkPane.setLayout(new BorderLayout()); this.add(layoutText(), BorderLayout.WEST); this.add(layoutPane(), BorderLayout.CENTER); this.setBorder(BorderFactory.createEmptyBorder(TOP_GAP, LEFT_GAP, 0, 0)); this.buttonlists = buttonlists; buttonVisible.addItemListener(itemListener); } private JPanel layoutText() { double p = TableLayout.PREFERRED; Component[][] components = new Component[][]{ new Component[]{new UILabel(Inter.getLocText("Type") + ":", SwingConstants.RIGHT)}, new Component[]{new UILabel(Inter.getLocText("WF-Name") + ":", SwingConstants.RIGHT)}, new Component[]{new UILabel(Inter.getLocText("DashBoard-Potence") + ":", SwingConstants.RIGHT)}, }; double[] rowSize = {p, p, p}; double[] columnSize = {p}; int[][] rowCount = {{1}, {1}, {1}}; return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); } private JPanel layoutPane() { double f = TableLayout.FILL; double p = TableLayout.PREFERRED; Component[][] components = new Component[][]{ new Component[]{type}, new Component[]{name}, new Component[]{checkPane}, }; double[] rowSize = {p, p, p}; double[] columnSize = {f}; int[][] rowCount = {{1}, {1}, {1}}; return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); } /** * 更新权限编辑面板的具体内容:类型、名称、权限面板 */ public void populateDetials() { populateName(); populateType(); populateCheckPane(); checkVisibleCheckBoxes(); } private void checkVisibleCheckBoxes() { buttonVisible.removeItemListener(itemListener); String selected = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); if (selected == null) { buttonVisible.setSelected(true); } for (int i = 0; i < buttonlists.size(); i++) { if (buttonlists.get(i).isSelected()) { buttonVisible.setSelected(!buttonlists.get(i).isDoneAuthorityEdited(selected)); break; } } buttonVisible.addItemListener(itemListener); } public void populateType() { if (name.getText() == "") { type.setText(""); } else { type.setText(Inter.getLocText(new String[]{"ReportServerP-Toolbar", "Form-Button"})); } } public void populateName() { String names = ""; for (int i = 0; i < buttonlists.size(); i++) { if (buttonlists.get(i).isSelected()) { names += "," + buttonlists.get(i).getNameOption().optionName(); } } if (names != "") { names = names.substring(1); } name.setText(names); } public void populateCheckPane() { checkPane.removeAll(); if (name.getText() == "") { return; } double f = TableLayout.FILL; double p = TableLayout.PREFERRED; Component[][] components = new Component[][]{ new Component[]{new UILabel(Inter.getLocText("Form-Button"), SwingConstants.LEFT), buttonVisible}, }; double[] rowSize = {p, p}; double[] columnSize = {p, p, f}; int[][] rowCount = {{1, 1, 1}, {1, 1, 1}}; JPanel check = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); checkPane.add(check, BorderLayout.CENTER); checkPane.setBorder(BorderFactory.createEmptyBorder(ALIGNMENT_GAP, 0, 0, 0)); } } } \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/AuthoritySheetEditedPane.java b/designer/src/com/fr/design/mainframe/AuthoritySheetEditedPane.java new file mode 100644 index 000000000..aba809df5 --- /dev/null +++ b/designer/src/com/fr/design/mainframe/AuthoritySheetEditedPane.java @@ -0,0 +1,53 @@ +package com.fr.design.mainframe; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import javax.swing.BorderFactory; +import javax.swing.JPanel; +import javax.swing.SwingConstants; + +import com.fr.design.constants.UIConstants; +import com.fr.design.file.HistoryTemplateListPane; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.general.Inter; +import com.fr.main.impl.WorkBook; + +/** + * Created by IntelliJ IDEA. + * Author : Richer + * Version: 6.5.6 + * Date: 13-12-16 + * Time: 上午10:09 + */ +public class AuthoritySheetEditedPane extends AuthorityPropertyPane { + + private static final int TITLE_HEIGHT = 19; + private AuthorityEditPane authorityEditPane = null; + + + public AuthoritySheetEditedPane(WorkBook editingWorkBook, int selectedIndex) { + super(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()); + this.setLayout(new BorderLayout()); + this.setBorder(null); + UILabel authorityTitle = new UILabel(Inter.getLocText(new String[]{"DashBoard-Potence", "Edit"})) { + @Override + public Dimension getPreferredSize() { + return new Dimension(super.getPreferredSize().width, TITLE_HEIGHT); + } + }; + authorityTitle.setHorizontalAlignment(SwingConstants.CENTER); + authorityTitle.setVerticalAlignment(SwingConstants.CENTER); + JPanel northPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + northPane.add(authorityTitle, BorderLayout.CENTER); + northPane.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, UIConstants.LINE_COLOR)); + this.add(northPane, BorderLayout.NORTH); + authorityEditPane = new SheetAuthorityEditPane(editingWorkBook, selectedIndex); + this.add(authorityEditPane, BorderLayout.CENTER); + + } + + public void populate() { + authorityEditPane.populateDetials(); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/AuthorityToolBarPane.java b/designer/src/com/fr/design/mainframe/AuthorityToolBarPane.java new file mode 100644 index 000000000..27c2c1ec0 --- /dev/null +++ b/designer/src/com/fr/design/mainframe/AuthorityToolBarPane.java @@ -0,0 +1 @@ +package com.fr.design.mainframe; import com.fr.base.ConfigManager; import com.fr.base.FRContext; import com.fr.design.beans.BasicBeanPane; import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.gui.ilable.UILabel; import com.fr.design.mainframe.toolbar.AuthorityEditToolBarComponent; import com.fr.design.mainframe.toolbar.ToolBarMenuDock; import com.fr.design.roleAuthority.RolesAlreadyEditedPane; import com.fr.design.webattr.ReportWebWidgetConstants; import com.fr.design.webattr.ToolBarButton; import com.fr.design.webattr.ToolBarPane; import com.fr.form.ui.Button; import com.fr.form.ui.ToolBar; import com.fr.form.ui.Widget; import com.fr.general.ComparatorUtils; import com.fr.general.FRLogger; import com.fr.general.Inter; import com.fr.main.TemplateWorkBook; import com.fr.report.web.Location; import com.fr.report.web.ToolBarManager; import com.fr.report.web.WebContent; import com.fr.base.ConfigManagerProvider; import com.fr.stable.ArrayUtils; import com.fr.web.attr.ReportWebAttr; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.List; /** * Author : daisy * Date: 13-9-9 * Time: 下午4:58 */ public class AuthorityToolBarPane extends BasicBeanPane implements AuthorityEditToolBarComponent { private static final int SMALL_GAP = 13; private static final int GAP = 25; private static final int PRE_GAP = 9; private static final int COMBOX_WIDTH = 144; private static final String[] CHOOSEITEM = new String[]{Inter.getLocText("M-Page_Preview"), Inter.getLocText(new String[]{"Face_Write", "PageSetup-Page"}), Inter.getLocText("M-Data_Analysis")}; private UIComboBox choseComboBox; private ToolBarPane toolBarPane; private AuthorityEditToolBarPane authorityEditToolBarPane = null; private int selectedIndex = -1; private UILabel title = null; private MouseListener mouseListener = new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (!toolBarPane.isEnabled()) { return; } java.util.List buttonlists = toolBarPane.getToolBarButtons(); int oldIndex = selectedIndex; selectedIndex = pressButtonIndex(e, buttonlists); //实现shift多选 if (e.isShiftDown()) { if (oldIndex == -1) { removeSelection(); ((ToolBarButton) e.getSource()).setSelected(true); } else { int max = oldIndex >= selectedIndex ? oldIndex : selectedIndex; int min = oldIndex <= selectedIndex ? oldIndex : selectedIndex; for (int i = min; i <= max; i++) { buttonlists.get(i).setSelected(true); } } } else if (!e.isControlDown()) { //实现单选 removeSelection(); if (selectedIndex != -1) { ((ToolBarButton) e.getSource()).setSelected(true); } } authorityEditToolBarPane.populate(); EastRegionContainerPane.getInstance().replaceUpPane(authorityEditToolBarPane); } }; private int pressButtonIndex(MouseEvent e, java.util.List buttonlists) { if (!(e.getSource() instanceof ToolBarButton)) { return -1; } ToolBarButton button = (ToolBarButton) e.getSource(); for (int i = 0; i < buttonlists.size(); i++) { if (ComparatorUtils.equals(button, buttonlists.get(i))) { return i; } } return -1; } /** * 去掉选择 */ public void removeSelection() { for (ToolBarButton button : toolBarPane.getToolBarButtons()) { button.setSelected(false); } } private ItemListener itemListener = new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.DESELECTED) { selectedIndex = -1; populateToolBarPane(); authorityEditToolBarPane = new AuthorityEditToolBarPane(toolBarPane.getToolBarButtons()); authorityEditToolBarPane.setAuthorityToolBarPane(AuthorityToolBarPane.this); EastRegionContainerPane.getInstance().replaceUpPane(authorityEditToolBarPane); EastRegionContainerPane.getInstance().replaceDownPane(RolesAlreadyEditedPane.getInstance()); } } }; public AuthorityToolBarPane() { this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 3)); this.setBorder(BorderFactory.createEmptyBorder(0, PRE_GAP, 0, 0)); title = new UILabel(Inter.getLocText(new String[]{"ReportServerP-Toolbar", "Choose_Role"})); title.setHorizontalAlignment(SwingConstants.CENTER); this.add(title, 0); choseComboBox = new UIComboBox(CHOOSEITEM) { public Dimension getPreferredSize() { Dimension dim = super.getPreferredSize(); dim.width = COMBOX_WIDTH; return dim; } }; choseComboBox.addItemListener(itemListener); //默认选择第一个 choseComboBox.setSelectedIndex(0); this.add(createGapPanel(SMALL_GAP)); this.add(choseComboBox); toolBarPane = new ToolBarPane(); toolBarPane.setBorder(null); toolBarPane.removeDefaultMouseListener(); this.add(createGapPanel(GAP)); this.add(toolBarPane); populateDefaultToolBarWidgets(); populateBean(getReportWebAttr()); toolBarPane.addAuthorityListener(mouseListener); authorityEditToolBarPane = new AuthorityEditToolBarPane(toolBarPane.getToolBarButtons()); authorityEditToolBarPane.setAuthorityToolBarPane(this); checkToolBarPaneEnable(); } private JPanel createGapPanel(final int gap) { return new JPanel() { public Dimension getPreferredSize() { Dimension dim = super.getPreferredSize(); dim.width = gap; return dim; } }; } private void populateToolBarPane() { toolBarPane.removeAll(); populateDefaultToolBarWidgets(); populateBean(getReportWebAttr()); toolBarPane.addAuthorityListener(mouseListener); toolBarPane.repaint(); authorityEditToolBarPane = new AuthorityEditToolBarPane(toolBarPane.getToolBarButtons()); checkToolBarPaneEnable(); } /** * 使用普通用户远程设计时,如果工具栏使用的是“采用服务器设置”,则工具栏按钮为灰不可用 */ private void checkToolBarPaneEnable() { List toolBarButtons = toolBarPane.getToolBarButtons(); boolean isnotEnable = ComparatorUtils.equals(title.getText(), Inter.getLocText(new String[]{"Server", "ReportServerP-Toolbar", "Choose_Role"})) && !FRContext.getCurrentEnv().isRoot(); for (ToolBarButton button : toolBarButtons) { button.setEnabled(!isnotEnable); } toolBarPane.setEnabled(!isnotEnable); } /** * 更新权限工具栏面板 */ public void populateAuthority() { toolBarPane.repaint(); } private ReportWebAttr getReportWebAttr() { JTemplate editingTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); if (!editingTemplate.isJWorkBook()) { return null; } JWorkBook editingWorkBook = (JWorkBook) editingTemplate; TemplateWorkBook wbTpl = editingWorkBook.getTarget(); return wbTpl.getReportWebAttr(); } //将该报表的设置过权限的属性记录一下 public void setAuthorityWebAttr(Widget widget, boolean isSelected, String selectedRole) { JTemplate editingTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); if (!editingTemplate.isJWorkBook()) { return; } JWorkBook editingWorkBook = (JWorkBook) editingTemplate; TemplateWorkBook wbTpl = editingWorkBook.getTarget(); ReportWebAttr rw = wbTpl.getReportWebAttr(); ConfigManagerProvider cm = ConfigManager.getProviderInstance(); ReportWebAttr webAttr = ((ReportWebAttr) cm.getGlobalAttribute(ReportWebAttr.class)); //wbTpl.clear先清空 //再将所有的保存进去 //看是存在服务器还存在模板里面 if (choseComboBox.getSelectedIndex() == 0) { //分页 if (rw == null || rw.getWebPage() == null) { dealWithWebContent(webAttr.getWebPage(), widget, isSelected, selectedRole); } } else if (choseComboBox.getSelectedIndex() == 1) { //填报 if (rw == null || rw.getWebPage() == null) { dealWithWebContent(webAttr.getWebWrite(), widget, isSelected, selectedRole); } } else { //view if (rw == null || rw.getWebPage() == null) { dealWithWebContent(webAttr.getWebView(), widget, isSelected, selectedRole); } } try { FRContext.getCurrentEnv().writeResource(cm); } catch (Exception e) { FRLogger.getLogger().error(e.getMessage()); } } private void dealWithWebContent(WebContent wc, Widget widget, boolean isSelected, String selectedRole) { ToolBarManager[] managers = wc.getToolBarManagers(); if (managers == null) { return; } for (int i = 0; i < managers.length; i++) { ToolBar tb = managers[i].getToolBar(); for (int j = 0; j < tb.getWidgetSize(); j++) { if (widget instanceof Button && tb.getWidget(j) instanceof Button) { if (ComparatorUtils.equals(((Button) widget).getIconName(), ((Button) tb.getWidget(j)).getIconName())) { if (!isSelected) { tb.getWidget(j).getWidgetPrivilegeControl().addInvisibleRole(selectedRole); } else { tb.getWidget(j).getWidgetPrivilegeControl().removeInvisibleRole(selectedRole); } } } } } wc.setToolBarManagers(managers); } public void populateBean(ReportWebAttr reportWebAttr) { this.remove(title); // 如果是空值就说明采用服务器配置了 if (reportWebAttr == null || this.getWebContent(reportWebAttr) == null) { title = new UILabel(Inter.getLocText(new String[]{"Server", "ReportServerP-Toolbar", "Choose_Role"})); populateServerSettings(); this.add(title, 0); return; } // 模板设置 T webContent = this.getWebContent(reportWebAttr); title = new UILabel(Inter.getLocText(new String[]{"the_template", "ReportServerP-Toolbar", "Choose_Role"})); this.add(title, 0); populate(webContent.getToolBarManagers()); } public ReportWebAttr updateBean() { return null; } public void populate(ToolBarManager[] toolBarManager) { if (ArrayUtils.isEmpty(toolBarManager)) { return; } if (toolBarManager.length == 0) { return; } for (int i = 0; i < toolBarManager.length; i++) { toolBarPane.populateBean(toolBarManager[i].getToolBar()); } } public Dimension getPreferredSize() { Dimension dim = super.getPreferredSize(); dim.height = ToolBarMenuDock.PANLE_HEIGNT; return dim; } public void populateBean(ToolBarManager[] toolBarManager) { if (ArrayUtils.isEmpty(toolBarManager)) { return; } for (int i = 0; i < toolBarManager.length; i++) { Location location = toolBarManager[i].getToolBarLocation(); if (location instanceof Location.Embed) { toolBarPane.populateBean(toolBarManager[i].getToolBar()); } } } private void populateServerSettings() { ConfigManagerProvider cm = ConfigManager.getProviderInstance(); ReportWebAttr webAttr = ((ReportWebAttr) cm.getGlobalAttribute(ReportWebAttr.class)); if (this.getWebContent(webAttr) != null) { populate(this.getWebContent(webAttr).getToolBarManagers()); } } protected String title4PopupWindow() { return null; } private T getWebContent(ReportWebAttr reportWebAttr) { if (choseComboBox.getSelectedIndex() == 0) { return reportWebAttr == null ? null : (T) reportWebAttr.getWebPage(); } else if (choseComboBox.getSelectedIndex() == 1) { return reportWebAttr == null ? null : (T) reportWebAttr.getWebWrite(); } else { return reportWebAttr == null ? null : (T) reportWebAttr.getWebView(); } } private void populateDefaultToolBarWidgets() { if (choseComboBox.getSelectedIndex() == 0) { ReportWebWidgetConstants.getPageToolBarInstance(); } else if (choseComboBox.getSelectedIndex() == 1) { ReportWebWidgetConstants.getWriteToolBarInstance(); } else { ReportWebWidgetConstants.getViewToolBarInstance(); } } private ToolBarManager getDefaultToolBarManager() { if (choseComboBox.getSelectedIndex() == 0) { return ToolBarManager.createDefaultToolBar(); } else if (choseComboBox.getSelectedIndex() == 1) { return ToolBarManager.createDefaultWriteToolBar(); } else { return ToolBarManager.createDefaultViewToolBar(); } } } \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/CellElementPropertyPane.java b/designer/src/com/fr/design/mainframe/CellElementPropertyPane.java new file mode 100644 index 000000000..fa602c8bd --- /dev/null +++ b/designer/src/com/fr/design/mainframe/CellElementPropertyPane.java @@ -0,0 +1,143 @@ +/* + * Copyright(c) 2001-2011, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.mainframe; + +import java.awt.BorderLayout; +import java.awt.Dimension; + +import javax.swing.BorderFactory; +import javax.swing.Icon; +import javax.swing.JPanel; +import javax.swing.SwingConstants; + +import com.fr.base.BaseUtils; +import com.fr.design.gui.frpane.UITitlePanel; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itabpane.TitleChangeListener; +import com.fr.design.mainframe.cell.CellElementEditPane; +import com.fr.general.Inter; +import com.fr.grid.selection.CellSelection; +import com.fr.grid.selection.FloatSelection; +import com.fr.grid.selection.Selection; +import com.fr.report.cell.DefaultTemplateCellElement; +import com.fr.report.cell.Elem; +import com.fr.report.elementcase.TemplateElementCase; + + +/** + * 所有组件一次全部加载,不存在延迟加载。 原因:设计器打开第一张模板的时候,会初始化许多许多东西。这个过程需要很长时间(快的3-5s)。 + * 单元格属性表初始化全部组件,也用不了多长时间,相对于上面的(3-5s)很短,用户根本不会感觉多了时间。 + * 所以基本不影响体验。而且,以后用单元格属性表时,不会应为里面的部分组件没有初始化而导致设计器突然卡一下,很流畅的. + * + * @author zhou + * @since 2012-5-24下午1:50:21 + */ +public class CellElementPropertyPane extends DockingView { + + public synchronized static CellElementPropertyPane getInstance() { + if (singleton == null) { + singleton = new CellElementPropertyPane(); + } + return singleton; + } + + private static CellElementPropertyPane singleton; + + private CellElementEditPane cellElementEditPane; + + private JPanel titlePane; + private UILabel title; + + private TitleChangeListener titleListener = new TitleChangeListener() { + + @Override + public void fireTitleChange(String addName) { + title.setText(Inter.getLocText("CellElement-Property_Table") + '-' + addName); + } + }; + + + private CellElementPropertyPane() { + this.setLayout(new BorderLayout()); + this.setBorder(null); + cellElementEditPane = new CellElementEditPane(); + cellElementEditPane.addTitleChangeListner(titleListener); + titlePane = new JPanel(new BorderLayout()); + title = new UILabel(this.getViewTitle() + '-' + Inter.getLocText("ExpandD-Expand_Attribute")) { + private static final long serialVersionUID = 1L; + + @Override + public Dimension getPreferredSize() { + return new Dimension(super.getPreferredSize().width, 19); + } + }; + title.setHorizontalAlignment(SwingConstants.CENTER); + title.setVerticalAlignment(SwingConstants.CENTER); + titlePane.add(title, BorderLayout.CENTER); + titlePane.setBorder(BorderFactory.createEmptyBorder(0,0,1,0)); + this.add(titlePane, BorderLayout.NORTH); + this.add(cellElementEditPane, BorderLayout.CENTER); + + } + + @Override + public void refreshDockingView() { + singleton = new CellElementPropertyPane(); + } + + private Elem getSelectedElement(Selection selection, TemplateElementCase elementCase) { + Elem element = null; + if (selection instanceof CellSelection) { + CellSelection cs = (CellSelection) selection; + element = elementCase.getCellElement(cs.getColumn(), cs.getRow()); + } else if (selection instanceof FloatSelection) { + FloatSelection fs = (FloatSelection) selection; + element = elementCase.getFloatElement(fs.getSelectedFloatName()); + } + + if (element == null) { + element = new DefaultTemplateCellElement(0, 0); + } + return element; + } + + public void populate(ElementCasePane ePane) { + TemplateElementCase elementCase = ePane.getEditingElementCase(); + if (elementCase == null) { + return; + } + cellElementEditPane.populate(ePane); + } + + @Override + public String getViewTitle() { + return Inter.getLocText("CellElement-Property_Table"); + } + + @Override + public Icon getViewIcon() { + return BaseUtils.readIcon("/com/fr/design/images/m_report/qb.png"); + } + + @Override + public Location preferredLocation() { + return Location.WEST_BELOW; + } + + @Override + public UITitlePanel createTitlePanel() { + return new UITitlePanel(this); + } + + /** + * 一些面板可能有二级菜单(比如说形态) + * + * @param id + */ + public void GoToPane(String... id) { + cellElementEditPane.setSelectedIndex(id); + EastRegionContainerPane.getInstance().setWindow2PreferWidth(); + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/ElementCasePane.java b/designer/src/com/fr/design/mainframe/ElementCasePane.java new file mode 100644 index 000000000..b23273bc5 --- /dev/null +++ b/designer/src/com/fr/design/mainframe/ElementCasePane.java @@ -0,0 +1,1397 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.mainframe; + +import java.awt.AWTEvent; +import java.awt.Adjustable; +import java.awt.Dimension; +import java.awt.Image; +import java.awt.Rectangle; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.Transferable; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +import javax.swing.AbstractAction; +import javax.swing.ActionMap; +import javax.swing.Icon; +import javax.swing.InputMap; +import javax.swing.JComponent; +import javax.swing.JPanel; +import javax.swing.JPopupMenu; +import javax.swing.JScrollBar; +import javax.swing.KeyStroke; + +import com.fr.base.BaseUtils; +import com.fr.base.DynamicUnitList; +import com.fr.base.FRContext; +import com.fr.base.Formula; +import com.fr.base.ScreenResolution; +import com.fr.base.Style; +import com.fr.design.DesignState; +import com.fr.design.DesignerEnvManager; +import com.fr.design.actions.AllowAuthorityEditAction; +import com.fr.design.actions.ExitAuthorityEditAction; +import com.fr.design.actions.UpdateAction; +import com.fr.design.actions.cell.BorderAction; +import com.fr.design.actions.cell.CleanAuthorityAction; +import com.fr.design.actions.cell.style.AlignmentAction; +import com.fr.design.actions.cell.style.ReportFontBoldAction; +import com.fr.design.actions.cell.style.ReportFontForegroundAction; +import com.fr.design.actions.cell.style.ReportFontItalicAction; +import com.fr.design.actions.cell.style.ReportFontNameAction; +import com.fr.design.actions.cell.style.ReportFontSizeAction; +import com.fr.design.actions.cell.style.ReportFontUnderlineAction; +import com.fr.design.actions.cell.style.StyleBackgroundAction; +import com.fr.design.actions.columnrow.CancelColumnAction; +import com.fr.design.actions.columnrow.CancelRowAction; +import com.fr.design.actions.columnrow.ColumnHideAction; +import com.fr.design.actions.columnrow.ColumnWidthAction; +import com.fr.design.actions.columnrow.DeleteColumnAction; +import com.fr.design.actions.columnrow.DeleteRowAction; +import com.fr.design.actions.columnrow.FootColumnAction; +import com.fr.design.actions.columnrow.FootRowAction; +import com.fr.design.actions.columnrow.HeadColumnAction; +import com.fr.design.actions.columnrow.HeadRowAction; +import com.fr.design.actions.columnrow.InsertColumnAction; +import com.fr.design.actions.columnrow.InsertRowAction; +import com.fr.design.actions.columnrow.ResetColumnHideAction; +import com.fr.design.actions.columnrow.ResetRowHideAction; +import com.fr.design.actions.columnrow.RowHeightAction; +import com.fr.design.actions.columnrow.RowHideAction; +import com.fr.design.actions.core.ActionUtils; +import com.fr.design.actions.edit.CopyAction; +import com.fr.design.actions.edit.CutAction; +import com.fr.design.actions.edit.PasteAction; +import com.fr.design.actions.edit.merge.MergeCellAction; +import com.fr.design.actions.edit.merge.UnmergeCellAction; +import com.fr.design.cell.bar.DynamicScrollBar; +import com.fr.design.cell.clipboard.CellElementsClip; +import com.fr.design.cell.clipboard.ElementsTransferable; +import com.fr.design.cell.clipboard.FloatElementsClip; +import com.fr.design.cell.editor.BiasTextPainterCellEditor; +import com.fr.design.cell.editor.ChartCellEditor; +import com.fr.design.cell.editor.ChartFloatEditor; +import com.fr.design.cell.editor.DSColumnCellEditor; +import com.fr.design.cell.editor.FormulaCellEditor; +import com.fr.design.cell.editor.FormulaFloatEditor; +import com.fr.design.cell.editor.ImageCellEditor; +import com.fr.design.cell.editor.ImageFloatEditor; +import com.fr.design.cell.editor.RichTextCellEditor; +import com.fr.design.cell.editor.SubReportCellEditor; +import com.fr.design.constants.UIConstants; +import com.fr.design.designer.EditingState; +import com.fr.design.designer.TargetComponent; +import com.fr.design.file.HistoryTemplateListPane; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.imenu.UIPopupMenu; +import com.fr.design.mainframe.cell.QuickEditorRegion; +import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus; +import com.fr.design.menu.KeySetUtils; +import com.fr.design.menu.MenuDef; +import com.fr.design.menu.NameSeparator; +import com.fr.design.menu.ShortCut; +import com.fr.design.menu.ToolBarDef; +import com.fr.design.selection.QuickEditor; +import com.fr.design.selection.Selectedable; +import com.fr.design.selection.SelectionEvent; +import com.fr.design.selection.SelectionListener; +import com.fr.general.ComparatorUtils; +import com.fr.general.Inter; +import com.fr.grid.Grid; +import com.fr.grid.GridColumn; +import com.fr.grid.GridCorner; +import com.fr.grid.GridRow; +import com.fr.grid.GridUtils; +import com.fr.grid.dnd.ElementCasePaneDropTarget; +import com.fr.grid.selection.CellSelection; +import com.fr.grid.selection.Selection; +import com.fr.page.PageAttributeGetter; +import com.fr.page.ReportPageAttrProvider; +import com.fr.poly.creator.PolyElementCasePane; +import com.fr.report.ReportHelper; +import com.fr.report.cell.DefaultTemplateCellElement; +import com.fr.report.cell.FloatElement; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.cell.cellattr.core.RichText; +import com.fr.report.cell.cellattr.core.SubReport; +import com.fr.report.cell.cellattr.core.group.DSColumn; +import com.fr.report.cell.painter.BiasTextPainter; +import com.fr.report.core.SheetUtils; +import com.fr.report.elementcase.ElementCase; +import com.fr.report.elementcase.TemplateElementCase; +import com.fr.stable.ArrayUtils; +import com.fr.stable.ColumnRow; +import com.fr.stable.Constants; +import com.fr.stable.unit.FU; + +/** + * This class used to edit Report. + */ +public abstract class ElementCasePane extends TargetComponent implements Selectedable, PageAttributeGetter { + + public static enum Clear { + ALL, FORMATS, CONTENTS, WIDGETS + } + + public static final int NO_OVER = 0; + public static final int HORIZONTAL_OVER = 1; + public static final int VERTICAL_OVER = 2; + + // alex:既可以是选中一片单元格,也可以是选中一个悬浮元素 + //august:默认是个不存在的选择。方便初始化时触发GridSelectionChangeListener事件 + private Selection selection = new CellSelection(-1, -1, -1, -1); + + // alex: + private boolean supportDefaultParentCalculate = false; + // GUI. + private Grid grid; + private GridRow gridRow; + private GridColumn gridColumn; + private GridCorner gridCorner; + private JScrollBar verScrollBar; + private JScrollBar horScrollBar; + // Visible + private boolean columnHeaderVisible = true; + private boolean rowHeaderVisible = true; + private boolean verticalScrollBarVisible = true; + private boolean horizontalScrollBarVisible = true; + + private int resolution; + protected UIButton formatBrush = null; + + private CellSelection formatReferencedCell = null; + private CellSelection cellNeedTOFormat = null; + private FormatBrushAction formatBrushAction; + ActionListener keyListener = new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (!formatBrush.isSelected()) { + DesignerContext.setFormatState(DesignerContext.FORMAT_STATE_ONCE); + DesignerContext.setReferencedElementCasePane(ElementCasePane.this); + DesignerContext.setReferencedIndex( + ((JWorkBook) HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()).getEditingReportIndex()); + formatBrush.setSelected(true); + formatBrushAction.executeActionReturnUndoRecordNeeded(); + } else { + cancelFormatBrush(); + } + } + }; + ActionListener escKey = new ActionListener() { + public void actionPerformed(ActionEvent e) { + cancelFormatBrush(); + } + }; + + + /** + * Constructor. + */ + public ElementCasePane(T t) { + super(t); + // marks:能触发processEvent,不管是否给component增加listener。这里是使在reportPane中的任意位置滑动鼠标轮都能 + // 下拉grid。 + enableEvents(AWTEvent.MOUSE_WHEEL_EVENT_MASK); + this.initComponents(); + + new ElementCasePaneDropTarget(this); + this.setFocusTraversalKeysEnabled(false); + + } + + /** + * 取消格式化 + */ + public void cancelFormat() { + return; + } + + protected void initComponents() { + this.setLayout(new RGridLayout()); + + this.resolution = ScreenResolution.getScreenResolution(); + + this.initGridComponent(); + + this.grid.setElementCasePane(this); + this.gridColumn.setElementCasePane(this); + this.gridRow.setElementCasePane(this); + this.gridCorner.setElementCasePane(this); + + this.add(RGridLayout.GridCorner, this.gridCorner); + this.add(RGridLayout.GridColumn, this.gridColumn); + this.add(RGridLayout.GridRow, this.gridRow); + this.add(RGridLayout.Grid, this.grid); + + // ScrollBar + verScrollBar = new DynamicScrollBar(Adjustable.VERTICAL, this, this.resolution); + horScrollBar = new DynamicScrollBar(Adjustable.HORIZONTAL, this, this.resolution); + this.add(RGridLayout.VerticalBar, this.verScrollBar); + // this.add(RGridLayout.HorizontalBar, this.horScrollBar); + + // Init input/action map defaultly. + initInputActionMap(); + + // 设置最小的尺寸,方便 ScrollPane. + this.setMinimumSize(new Dimension(0, 0)); + + // alex:初始化Editors + initDefaultEditors(); + initFormatBrush(); + } + + public int getMenuState() { + return DesignState.WORK_SHEET; + } + + + protected void initFormatBrush() { + formatBrushAction = new FormatBrushAction(this); + formatBrush = (UIButton) formatBrushAction.createToolBarComponent(); + formatBrush.setSelected(DesignerContext.getFormatState() != DesignerContext.FORMAT_STATE_NULL); + formatBrush.removeActionListener(formatBrushAction); + formatBrush.addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + //如果没有格式刷,点击时就是想使用格式刷 + if (e.getClickCount() == 1) { + if (!formatBrush.isSelected()) { + DesignerContext.setFormatState(DesignerContext.FORMAT_STATE_ONCE); + DesignerContext.setReferencedElementCasePane(ElementCasePane.this); + DesignerContext.setReferencedIndex( + ((JTemplate) HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()).getEditingReportIndex()); + formatBrush.setSelected(true); + formatBrushAction.executeActionReturnUndoRecordNeeded(); + } else { + cancelFormatBrush(); + } + + } else if (e.getClickCount() == 2) { + if (!formatBrush.isSelected()) { + formatBrush.setSelected(true); + } + DesignerContext.setFormatState(DesignerContext.FORMAT_STATE_MORE); + DesignerContext.setReferencedElementCasePane(ElementCasePane.this); + DesignerContext.setReferencedIndex( + ((JTemplate) HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()).getEditingReportIndex()); + formatBrush.setSelected(true); + formatBrushAction.executeActionReturnUndoRecordNeeded(); + } + } + }); + formatBrush.registerKeyboardAction(keyListener, KeyStroke.getKeyStroke(KeyEvent.VK_B, InputEvent.CTRL_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW); + formatBrush.registerKeyboardAction(escKey, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); + } + + /** + * 取消格式刷 + */ + public void cancelFormatBrush() { + //如果正在使用格式刷,点击就是想退出格式刷 + setFormatState(DesignerContext.FORMAT_STATE_NULL); + formatBrush.setSelected(false); + grid.setCursor(UIConstants.CELL_DEFAULT_CURSOR); + if(DesignerContext.getReferencedElementCasePane() == null){ + return; + } + + ((ElementCasePane) DesignerContext.getReferencedElementCasePane()).getGrid().setNotShowingTableSelectPane(true); + ((ElementCasePane) DesignerContext.getReferencedElementCasePane()).getGrid().setCursor(UIConstants.CELL_DEFAULT_CURSOR); + DesignerContext.setReferencedElementCasePane(null); + DesignerContext.setReferencedIndex(0); + repaint(); + } + + public UIButton getFormatBrush() { + return formatBrush; + } + + public void setFormatState(int formatState) { + DesignerContext.setFormatState(formatState); + if (formatState == DesignerContext.FORMAT_STATE_NULL) { + cellNeedTOFormat = null; + } + + } + + public JPanel getEastUpPane() { + return new JPanel(); + } + + + public JPanel getEastDownPane() { + return new JPanel(); + } + + + public FormatBrushAction getFormatBrushAction() { + return formatBrushAction; + } + + protected void initGridComponent() { + // Components + if (this.grid == null) { + this.grid = new Grid(this.resolution); + } + if (this.gridColumn == null) { + this.gridColumn = new GridColumn(); + } + if (this.gridRow == null) { + this.gridRow = new GridRow(); + } + if (this.gridCorner == null) { + this.gridCorner = new GridCorner(); + } + } + + + /** + * 所有的操作都必须在可见范围内,否则不做任何操作 + * + * @return true 必须在可见范围内. + */ + public boolean mustInVisibleRange() { + return true; + } + + /* + * 初始化默认的Editor + */ + private void initDefaultEditors() { + Grid grid = this.getGrid(); + grid.setDefaultCellEditor(DSColumn.class, new DSColumnCellEditor(this)); + grid.setDefaultCellEditor(Formula.class, new FormulaCellEditor(this)); + grid.setDefaultCellEditor(RichText.class, new RichTextCellEditor(this)); + + grid.setDefaultCellEditor(BiasTextPainter.class, new BiasTextPainterCellEditor(this)); + grid.setDefaultCellEditor(Image.class, new ImageCellEditor(this)); + grid.setDefaultCellEditor(SubReport.class, new SubReportCellEditor(this)); + + Class chartClass = ActionUtils.getChartCollectionClass(); + if (chartClass != null) { + grid.setDefaultCellEditor(chartClass, new ChartCellEditor(this)); + grid.setDefaultFloatEditor(chartClass, new ChartFloatEditor()); + } + + grid.setDefaultFloatEditor(Formula.class, new FormulaFloatEditor()); + grid.setDefaultFloatEditor(Image.class, new ImageFloatEditor()); + DesignerEnvManager designerEnvManager = DesignerEnvManager.getEnvManager(); + grid.setGridLineColor(designerEnvManager.getGridLineColor()); + grid.setPaginationLineColor(designerEnvManager.getPaginationLineColor()); + } + + /** + * 返回当前正在编辑的模板单元格组件 + */ + public final TemplateElementCase getEditingElementCase() { + return this.getTarget(); + } + + /** + * Gets the cell table of rpt pane. Grid implement the the most + * functionalities of table. + */ + public Grid getGrid() { + return this.grid; + } + + /** + * Gets the column header of cell table. + */ + public GridColumn getGridColumn() { + return this.gridColumn; + } + + /** + * Gets the row header of cell table. + */ + public GridRow getGridRow() { + return this.gridRow; + } + + /** + * Gets the left top corner of cell table + */ + public GridCorner getGridCorner() { + return this.gridCorner; + } + + /** + * Gets vertical scroll bar + */ + public JScrollBar getVerticalScrollBar() { + return this.verScrollBar; + } + + /** + * Gets horizontal scroll bar + */ + public JScrollBar getHorizontalScrollBar() { + return this.horScrollBar; + } + + /** + * 是否支持默认计算父格 + * + * @return 是则返回true + */ + public boolean isSupportDefaultParentCalculate() { + return supportDefaultParentCalculate; + } + + /** + * Sets whether to support auto calculate default parent + * + * @param supportDefaultParentCalculate whether to support auto calculate default parent. + */ + public void setSupportDefaultParentCalculate(boolean supportDefaultParentCalculate) { + this.supportDefaultParentCalculate = supportDefaultParentCalculate; + } + + /** + * 转换选择 + * + * @return 转换 + */ + public ElementsTransferable transferSelection() { + ElementsTransferable elementsTransferable = new ElementsTransferable(); + + this.selection.asTransferable(elementsTransferable, this); + + return elementsTransferable; + } + + /** + * @return + */ + public QuickEditor getCurrentEditor() { + return this.selection.getQuickEditor(this); + } + + @Override + /** + * 加下面的判断是因为聚合报表>>添加报表聚合块>>选中B1单元格>>再选中该聚合块>>再选中B1单元格,发现属性表右下侧还是现实的聚合块的属性 + * 因为这边判断selection是一个selection,所以不会触发fireSelectionChanged + */ + public void setSelection(Selection selection) { + if (!ComparatorUtils.equals(this.selection, selection) || + !ComparatorUtils.equals(EastRegionContainerPane.getInstance().getDownPane(), CellElementPropertyPane.getInstance())) { + this.selection = selection; + fireSelectionChanged(); + } + } + + + public void setOldSelecton(Selection selection) { + this.selection = selection; + } + + + public void setFormatReferencedCell(CellSelection cellSelection) { + this.formatReferencedCell = cellSelection; + getOldStyles(formatReferencedCell); + } + + + private void getOldStyles(CellSelection oldSelection) { + Style[][] referencedStyle = new Style[formatReferencedCell.getColumnSpan()][formatReferencedCell.getRowSpan()]; + int cellRectangleCount = oldSelection.getCellRectangleCount(); + TemplateElementCase elementCase = getEditingElementCase(); + for (int rect = 0; rect < cellRectangleCount; rect++) { + Rectangle cellRectangle = oldSelection.getCellRectangle(rect); + for (int j = 0; j < cellRectangle.height; j++) { + for (int i = 0; i < cellRectangle.width; i++) { + int column = i + cellRectangle.x; + int row = j + cellRectangle.y; + TemplateCellElement cellElement = elementCase.getTemplateCellElement(column, row); + if (cellElement == null) { + cellElement = new DefaultTemplateCellElement(column, row); + elementCase.addCellElement(cellElement); + } + Style style = cellElement.getStyle(); + if (style == null) { + style = style.DEFAULT_STYLE; + } + + referencedStyle[i][j] = style; + } + } + } + + DesignerContext.setReferencedStyle(referencedStyle); + } + + public CellSelection getFormatReferencedCell() { + return this.formatReferencedCell; + } + + + @Override + /** + * + */ + public Selection getSelection() { + return selection; + } + + /** + * 是否只选中了一个单元格 + * + * @return 是则返回true + */ + public boolean isSelectedOneCell() { + return selection.isSelectedOneCell(this); + } + + /** + * 停止编辑 + */ + public void stopEditing() { + this.getGrid().stopEditing(); + } + + /** + * 剪切 + * + * @return 成功返回true + */ + public boolean cut() { + this.copy(); + + return this.clearAll(); + } + + /** + * 复制 + */ + public void copy() { + // p:Elements Transferable. + ElementsTransferable elementsTransferable = this.transferSelection(); + + // peter:这个地方产生String序列,方便从FR当中copy数据到Excel当中. + Object firstObject = elementsTransferable.getFirstObject(); + if (firstObject instanceof CellElementsClip) { + elementsTransferable.addObject(((CellElementsClip) firstObject).compateExcelPaste()); + } + + // p:加到Clipboard里面去. + Clipboard clipboard = DesignerContext.getClipboard(this.getGrid()); + + clipboard.setContents(elementsTransferable, elementsTransferable); + } + + /** + * 黏贴 + * + * @return 成功返回 true + */ + public boolean paste() { + if (!this.isEditable()) { + return false; + } + Object clipObject = getClipObject(); + //如果是悬浮元素,则不允许粘贴到表单 + if (!DesignerContext.getDesignerFrame().getSelectedJTemplate().accept(clipObject)) { + return false; + } + + if (clipObject instanceof FloatElementsClip) { + return this.selection.pasteFloatElementClip((FloatElementsClip) clipObject, this); + } else if (clipObject instanceof CellElementsClip) { + return this.selection.pasteCellElementsClip((CellElementsClip) clipObject, this); + } else if (clipObject instanceof String) { + return this.selection.pasteString((String) clipObject, this); + } else { + return this.selection.pasteOtherType(clipObject, this); + } + } + + private Object getClipObject() { + // 需要检查是否可以编辑。 + Clipboard clipboard = DesignerContext.getClipboard(this.getGrid()); + Transferable clipData = clipboard.getContents(this); + if (clipData == null) {// 剪贴板里面没有值,直接返回. + return null; + } + Object clipObject; + try { + clipObject = ElementsTransferable.getElementNotStringTransderData(clipData); + } catch (Exception exp) { + // p:如果是其他不支持的对象,会抛出Exception的,所以变成String。 + // 所以这里不打印出Exception. + try { + clipObject = clipData.getTransferData(DataFlavor.stringFlavor); + } catch (Exception e) { + FRContext.getLogger().error(e.getMessage(), e); + return null; + } + } + + return clipObject; + } + + /** + * 确认行列是否可见 + * + * @param column 列序号 + * @param row 行序号 + * @return 类型 + */ + public int ensureColumnRowVisible(int column, int row) { + Grid grid = this.getGrid(); + + int verticalEndValue = grid.getVerticalValue() + grid.getVerticalExtent() + 1; + int horizontalEndValue = grid.getHorizontalValue() + grid.getHorizontalExtent() + 1; + + int overtype = NO_OVER; + // 列. + if (grid.getHorizontalValue() > column) { + this.getHorizontalScrollBar().setValue(column); + } else if (horizontalEndValue < (column + 1)) { + if (this instanceof PolyElementCasePane) { + //如果是聚合块中的Gird,选在边界的时候,会报表会自动向右移 + overtype += HORIZONTAL_OVER; + } else { + this.getHorizontalScrollBar().setValue(column - grid.getHorizontalExtent() + 1); + } + + } + + // 行. + if (grid.getVerticalValue() > row) { + this.getVerticalScrollBar().setValue(row); + } else if (verticalEndValue <= (row + 1)) {// p: +1是保证最后一行,不能显示半行. + if (this instanceof PolyElementCasePane) { + //如果是聚合块中的Gird,选在边界的时候,会报表会自动向下移 + overtype += VERTICAL_OVER; + } else { + this.getVerticalScrollBar().setValue(row - grid.getVerticalExtent() + 1); + } + + } + return overtype; + } + + /** + * 清空所有. + * + * @return 返回是否清除全部. + */ + public boolean clearAll() { + boolean b = this.selection.clear(Clear.ALL, this); + fireSelectionChanged(); + return b; + } + + /** + * 清除格式. + * + * @return 返回是否清除格式. + */ + public boolean clearFormats() { + boolean b = this.selection.clear(Clear.FORMATS, this); + fireSelectionChanged(); + return b; + } + + /** + * 清除内容 + * + * @return 返回是否清除内容. + */ + public boolean clearContents() { + if (BaseUtils.isAuthorityEditing()) { + return false; + } + boolean b = this.selection.clear(Clear.CONTENTS, this); + fireSelectionChanged(); + return b; + } + + /** + * 清除控件 + * + * @return 返回是否清除控件. + */ + public boolean clearWidget() { + boolean b = this.selection.clear(Clear.WIDGETS, this); + fireSelectionChanged(); + return b; + } + + /** + * 是否能合并单元格 + * + * @return 返回是否能合并单元格. + */ + public boolean canMergeCell() { + return this.selection.canMergeCells(this); + } + + /** + * 合并单元格 + * + * @return 成功返回true + */ + public boolean mergeCell() { + boolean b = this.selection.mergeCells(this); + fireSelectionChanged(); + return b; + } + + /** + * 是否撤销合并单元格 + * + * @return 返回是否撤销合并单元格. + */ + public boolean canUnMergeCell() { + return this.selection.canUnMergeCells(this); + } + + /** + * 撤销合并单元格 + * + * @return 成功返回true + */ + public boolean unMergeCell() { + boolean b = this.selection.unMergeCells(this); + fireSelectionChanged(); + return b; + } + + /** + * Fire gridSelection Changed + */ + private void fireSelectionChanged() { + this.fireSelectionChangeListener(); + this.repaint(15); + } + + /** + * 添加选中的SelectionListener + * + * @param selectionListener 选中的listener + */ + public void addSelectionChangeListener(SelectionListener selectionListener) { + this.listenerList.add(SelectionListener.class, selectionListener); + } + + + /** + * 删除选中的ChangeListener + * + * @param selectionListener 选中的listener + */ + public void removeSelectionChangeListener(SelectionListener selectionListener) { + this.listenerList.remove(SelectionListener.class, selectionListener); + } + + /** + * 响应选中的ChangeListener + */ + public void fireSelectionChangeListener() { + // Guaranteed to return a non-null array + Object[] listeners = listenerList.getListenerList(); + + // Process the listeners last to first, notifying + // those that are interested in this event + for (int i = listeners.length - 2; i >= 0; i -= 2) { + if (listeners[i] == SelectionListener.class) { + ((SelectionListener) listeners[i + 1]).selectionChanged(new SelectionEvent(this)); + } + } + } + + /** + * 响应目标变动. + */ + public void fireTargetModified() { + // marks:自动计算 + TemplateElementCase report = this.getEditingElementCase(); + + // 计算父格 + if (this.isSupportDefaultParentCalculate()) { + SheetUtils.calculateDefaultParent(report); + setSupportDefaultParentCalculate(false); + } + + super.fireTargetModified(); + + } + + /** + * Init input/action map. + */ + protected void initInputActionMap() { + InputMap inputMapAncestor = this.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); + ActionMap actionMap = this.getActionMap(); + // clearReportPage old values. + inputMapAncestor.clear(); + actionMap.clear(); + inputMapAncestor.put(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK), "cut"); + actionMap.put("cut", new AbstractAction() { + public void actionPerformed(ActionEvent evt) { + if (cut()) { + fireTargetModified(); + } + } + }); + inputMapAncestor.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK), "copy"); + actionMap.put("copy", new AbstractAction() { + public void actionPerformed(ActionEvent evt) { + copy(); + } + }); + inputMapAncestor.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK), "paste"); + actionMap.put("paste", new AbstractAction() { + public void actionPerformed(ActionEvent evt) { + if (paste()) { + QuickEditorRegion.getInstance().populate(getCurrentEditor()); + fireTargetModified(); + QuickEditorRegion.getInstance().populate(getCurrentEditor()); + } + } + }); + inputMapAncestor.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "delete_content"); + actionMap.put("delete_content", new AbstractAction() { + public void actionPerformed(ActionEvent evt) { + if (clearContents()) { + fireTargetModified(); + } + } + }); + inputMapAncestor.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, InputEvent.CTRL_MASK), "delete_all"); + actionMap.put("delete_all", new AbstractAction() { + public void actionPerformed(ActionEvent evt) { + if (clearAll()) { + fireTargetModified(); + } + } + }); + } + + /** + * 是否列表头可见 + * + * @return boolean 是否列表头可见. + */ + public boolean isColumnHeaderVisible() { + return this.columnHeaderVisible; + } + + /** + * Makes the column visible or invisible. + * + * @param isColumnVisible true to make the column visible; false to make it invisible + */ + public void setColumnHeaderVisible(boolean isColumnVisible) { + this.columnHeaderVisible = isColumnVisible; + + this.resizeAndRepaint(); + } + + /** + * 是否行表头可见. + * + * @return boolean 是否行表头可见. + */ + public boolean isRowHeaderVisible() { + return this.rowHeaderVisible; + } + + /** + * Makes the row visible or invisible. + * + * @param isRowVisible true to make the row visible; false to make it invisible + */ + public void setRowHeaderVisible(boolean isRowVisible) { + this.rowHeaderVisible = isRowVisible; + + this.resizeAndRepaint(); + } + + /** + * 是否垂直滚动条可见 + * + * @return boolean 是否垂直滚动条可见. + */ + public boolean isVerticalScrollBarVisible() { + return verticalScrollBarVisible; + } + + /** + * Makes the vertical scrollbar visible or invisible. + * + * @param verticalScrollBarVisible true to make the vertical scrollbar visible; false to make it + * invisible + */ + public void setVerticalScrollBarVisible(boolean verticalScrollBarVisible) { + this.verticalScrollBarVisible = verticalScrollBarVisible; + } + + /** + * 是否水平滚动条可见. + * + * @return boolean 是否水平滚动条可见. + */ + public boolean isHorizontalScrollBarVisible() { + return horizontalScrollBarVisible; + } + + /** + * Makes the horizontal scrollbar visible or invisible. + * + * @param horizontalScrollBarVisible true to make the horizontal scrollbar visible; false to make + * it invisible + */ + public void setHorizontalScrollBarVisible(boolean horizontalScrollBarVisible) { + this.horizontalScrollBarVisible = horizontalScrollBarVisible; + } + + // //////////////////////////////Max Row and Column. + + /** + * 是否可编辑. + * + * @return boolean 是否可编辑. + */ + public boolean isEditable() { + return this.grid.isEditable(); + } + + /** + * Sets whether to editable. + * + * @param editable 是否可编辑. + */ + public void setEditable(boolean editable) { + this.grid.setEditable(editable); + } + + + /** + * 弹出列表. + * + * @return 弹出列表. + */ + public JPopupMenu createPopupMenu() { + return this.selection.createPopupMenu(this); + } + + /** + * 弹出列表 + * + * @param evt 鼠标的响应事件. + * @param selectedRows 选中的行.. + * @return UIPopupMenu 返回行的列表 + */ + public UIPopupMenu createRowPopupMenu(MouseEvent evt, int selectedRows) { + UIPopupMenu popupMenu = new UIPopupMenu(); + if (BaseUtils.isAuthorityEditing()) { + popupMenu.add(new CleanAuthorityAction(this).createMenuItem()); + return popupMenu; + } + + InsertRowAction insertRowAction = new InsertRowAction(this, Inter.getLocText("Utils-Insert_Row")); + + DeleteRowAction deleteRowAction = new DeleteRowAction(this, Inter.getLocText("Utils-Delete_Row")); + + RowHeightAction rowHeightAction = new RowHeightAction(this, selectedRows); + + RowHideAction rowHideAction = new RowHideAction(this, selectedRows); + + ResetRowHideAction resetRowHideAction = new ResetRowHideAction(this, selectedRows); + popupMenu.add(insertRowAction.createMenuItem()); + popupMenu.add(deleteRowAction.createMenuItem()); + popupMenu.addSeparator(); + popupMenu.add(rowHeightAction.createMenuItem()); + if (supportRepeatedHeaderFooter()) { + CellSelection cs = (CellSelection) this.getSelection(); + addRowMenu(popupMenu, evt, cs.getRow(), cs.getRow() + cs.getRowSpan() - 1); + } + popupMenu.add(rowHideAction.createMenuItem()); + popupMenu.add(resetRowHideAction.createMenuItem()); + return popupMenu; + } + + private void addRowMenu(JPopupMenu popupMenu, MouseEvent evt, int selectedRowsFrom, int selectedRowsTo) { + HeadRowAction headrowAction = new HeadRowAction(this); + FootRowAction footrowAction = new FootRowAction(this); + + ElementCase elementCase = this.getEditingElementCase(); + boolean cancel = false; + ColumnRow selectedCellPoint = GridUtils.getAdjustEventColumnRow(this, evt.getX(), evt.getY()); + ReportPageAttrProvider reportPageAttr = elementCase.getReportPageAttr(); + ElementCase report = this.getEditingElementCase(); + if (reportPageAttr != null) { + popupMenu.addSeparator(); + popupMenu.add(headrowAction.createMenuItem()); + popupMenu.add(footrowAction.createMenuItem()); + int from = report.getReportPageAttr().getRepeatHeaderRowFrom(); + int to = report.getReportPageAttr().getRepeatHeaderRowTo(); + int from2 = report.getReportPageAttr().getRepeatFooterRowFrom(); + int to2 = report.getReportPageAttr().getRepeatFooterRowTo(); + + if (selectedCellPoint.getRow() >= selectedRowsFrom && selectedCellPoint.getRow() <= selectedRowsTo) { + + cancel = isCancel(report, selectedRowsFrom, selectedRowsTo, from, to, from2, to2); + + } else { + + int row = selectedCellPoint.getRow(); + if (report.getReportPageAttr() != null) { + if (row == from || row == to || row == from2 || row == to2) { + cancel = true; + } + } + } + + if (cancel) { + CancelRowAction cancelAction = new CancelRowAction(this); + popupMenu.add(cancelAction.createMenuItem()); + } + } + } + + private boolean isCancel(ElementCase report, int selectedColumnsFrom, int selectedColumnsTo, int from, int to, int from2, int to2) { + + boolean cancel = false; + + if (report.getReportPageAttr() != null) { + + if (from == selectedColumnsFrom && to == selectedColumnsTo) { + cancel = true; + } + + if (from2 == selectedColumnsFrom && to2 == selectedColumnsTo) { + cancel = true; + } + } + return cancel; + } + + /** + * 弹出列表. + * + * @param evt 鼠标事件 + * @param selectedColumn 选中的列. + * @return 弹出的列表. + */ + public UIPopupMenu createColumnPopupMenu(MouseEvent evt, int selectedColumn) { + UIPopupMenu popupMenu = new UIPopupMenu(); + + if (BaseUtils.isAuthorityEditing()) { + popupMenu.add(new CleanAuthorityAction(this).createMenuItem()); + return popupMenu; + } + + InsertColumnAction insertColumnAction = new InsertColumnAction(this, Inter.getLocText("Utils-Insert_Column")); + + DeleteColumnAction deleteColumnAction = new DeleteColumnAction(this, Inter.getLocText("Utils-Delete_Column")); + + ColumnWidthAction columnWidthAction = new ColumnWidthAction(this, selectedColumn); + + ColumnHideAction columnHideAction = new ColumnHideAction(this, selectedColumn); + + ResetColumnHideAction resetRowHideAction = new ResetColumnHideAction(this, selectedColumn); + popupMenu.add(insertColumnAction.createMenuItem()); + popupMenu.add(deleteColumnAction.createMenuItem()); + popupMenu.addSeparator(); + popupMenu.add(columnWidthAction.createMenuItem()); + + if (supportRepeatedHeaderFooter()) { + CellSelection cs = (CellSelection) this.getSelection(); + addColumnMenu(popupMenu, evt, cs.getColumn(), cs.getColumn() + cs.getColumnSpan() - 1); + } + popupMenu.add(columnHideAction.createMenuItem()); + popupMenu.add(resetRowHideAction.createMenuItem()); + + return popupMenu; + } + + private void addColumnMenu(UIPopupMenu popupMenu, MouseEvent evt, int selectedColumnsFrom, int selectedColumnsTo) { + HeadColumnAction headcolumnAction = new HeadColumnAction(this); + FootColumnAction footcolumnAction = new FootColumnAction(this); + + ColumnRow selectedCellPoint = GridUtils.getAdjustEventColumnRow(this, evt.getX(), evt.getY()); + ElementCase elementCase = this.getEditingElementCase(); + boolean cancel = false; + ReportPageAttrProvider reportPageAttr = elementCase.getReportPageAttr(); + + if (reportPageAttr != null) { + popupMenu.addSeparator(); + popupMenu.add(headcolumnAction.createMenuItem()); + popupMenu.add(footcolumnAction.createMenuItem()); + int from = reportPageAttr.getRepeatHeaderColumnFrom(); + int to = reportPageAttr.getRepeatHeaderColumnTo(); + int from2 = reportPageAttr.getRepeatFooterColumnFrom(); + int to2 = reportPageAttr.getRepeatFooterColumnTo(); + int column = selectedCellPoint.getColumn(); + + if (column >= selectedColumnsFrom && column <= selectedColumnsTo) { + cancel = isCancel(elementCase, selectedColumnsFrom, selectedColumnsTo, from, to, from2, to2); + } else { + + if (elementCase.getReportPageAttr() != null) { + + if (column == from || column == to || column == from2 || column == to2) { + cancel = true; + } + } + } + if (cancel) { + CancelColumnAction cancelAction = new CancelColumnAction(this); + popupMenu.add(cancelAction.createMenuItem()); + } + } + } + + protected abstract boolean supportRepeatedHeaderFooter(); + + /** + * 请求焦点 + */ + public void requestFocus() { + super.requestFocus(); + this.getGrid().requestFocus(); + } + + /** + * Equivalent to revalidate followed by repaint. + */ + protected void resizeAndRepaint() { + revalidate(); + repaint(); + } + + /** + * 模板menu + * + * @return 返回弹出列表数组. + */ + public ShortCut[] shortcut4TemplateMenu() { + return new ShortCut[0]; + } + + /** + * 权限细粒度状态下的菜单 + * + * @return 菜单 + */ + public ShortCut[] shortCuts4Authority() { + return new ShortCut[]{ + new NameSeparator(Inter.getLocText(new String[]{"DashBoard-Potence", "Edit"})), + BaseUtils.isAuthorityEditing() ? new ExitAuthorityEditAction(this) : new AllowAuthorityEditAction(this), + }; + + } + + /** + * 目标的下列列表 + * + * @return 返回MenuDef数组. + */ + public MenuDef[] menus4Target() { + return new MenuDef[0]; + } + + /** + * kunsnat: 工具栏 快捷键菜单按钮. 最后位置为 "插入悬浮元素" 文本, 公式, 图表, 图片. + * + * @return 返回工具栏数组. + */ + public ToolBarDef[] toolbars4Target() { + return new ToolBarDef[]{ + createFontToolBar(), + createAlignmentToolBar(), + createStyleToolBar(), + createCellToolBar(), + createInsertToolBar()}; + } + + /** + * 表单下的工具按钮 + * + * @return 工具按钮 + */ + public JComponent[] toolBarButton4Form() { + formatBrush.setSelected(DesignerContext.getFormatState() != DesignerContext.FORMAT_STATE_NULL); + return new JComponent[]{new CutAction(this).createToolBarComponent(), new CopyAction(this).createToolBarComponent(), + new PasteAction(this).createToolBarComponent(), formatBrush}; + } + + protected ToolBarDef createFontToolBar() { + return ShortCut.asToolBarDef(new ShortCut[]{ + new ReportFontNameAction(this), + new ReportFontSizeAction(this), + new ReportFontBoldAction(this), + new ReportFontItalicAction(this), + new ReportFontUnderlineAction(this),}); + } + + protected ToolBarDef createAlignmentToolBar() { + return ShortCut.asToolBarDef(new ShortCut[]{ + new AlignmentAction(this, new Icon[]{ + 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")}, + new Integer[]{Constants.LEFT, Constants.CENTER, Constants.RIGHT})} + ); + } + + protected ToolBarDef createStyleToolBar() { + return ShortCut.asToolBarDef(new ShortCut[]{ + new BorderAction(this), + new StyleBackgroundAction(this), + new ReportFontForegroundAction(this),}); + } + + protected ToolBarDef createCellToolBar() { + return ShortCut.asToolBarDef(new ShortCut[]{ + new MergeCellAction(this), + new UnmergeCellAction(this),}); + } + + protected ToolBarDef createInsertToolBar() { + MenuDef insertFloatMenu = new MenuDef(); + insertFloatMenu.setName(KeySetUtils.INSERT_FLOAT.getMenuKeySetName()); + insertFloatMenu.setTooltip(Inter.getLocText("T_Insert-Float")); + insertFloatMenu.setIconPath("/com/fr/design/images/m_insert/floatPop.png"); + + UpdateAction[] actions = ActionUtils.createFloatInsertAction(ElementCasePane.class, this); + for (int i = 0; i < actions.length; i++) { + insertFloatMenu.addShortCut(actions[i]); + } + UpdateAction[] cellInsertActions = ActionUtils.createCellInsertAction(ElementCasePane.class, this); + ShortCut[] shortCuts = new ShortCut[cellInsertActions.length]; + System.arraycopy(cellInsertActions, 0, shortCuts, 0, cellInsertActions.length); + return ShortCut.asToolBarDef((ShortCut[]) ArrayUtils.add(shortCuts, insertFloatMenu)); + } + + + /** + * 创建权限犀利段编辑面板 + * + * @return 面板 + */ + public AuthorityEditPane createAuthorityEditPane() { + return new ElementCasePaneAuthorityEditPane(this); + } + + public ToolBarMenuDockPlus getToolBarMenuDockPlus() { + return new JWorkBook(); + } + + /** + * 创建正在编辑的状态. + * + * @return 返回正在编辑的状态. + */ + public EditingState createEditingState() { + return new ElementCaseEditingState(this.selection, this.verScrollBar.getValue(), this.horScrollBar.getValue()); + } + + public void setCellNeedTOFormat(CellSelection selection) { + cellNeedTOFormat = selection; + } + + public CellSelection getCellNeedTOFormat() { + return cellNeedTOFormat; + } + + + private class ElementCaseEditingState implements EditingState { + protected Selection selection; + protected int verticalValue = 0; + protected int horizontalValue = 0; + + protected ElementCaseEditingState(Selection selection, int verticalValue, int horizontalValue) { + try { + this.selection = selection.clone(); + } catch (CloneNotSupportedException e) { + throw new RuntimeException(e); + } + this.verticalValue = verticalValue; + this.horizontalValue = horizontalValue; + } + + @Override + public void revert() { + try { + ElementCasePane.this.selection = this.selection.clone(); + ElementCasePane.this.fireSelectionChangeListener(); + } catch (CloneNotSupportedException e) { + throw new RuntimeException(e); + } + + ElementCasePane.this.getVerticalScrollBar().setValue(this.verticalValue); + ElementCasePane.this.getHorizontalScrollBar().setValue(this.horizontalValue); + + // 重绘. + ElementCasePane.this.repaint(); + } + } + + /** + * 增加悬浮元素在面板中 + * + * @param floatElement 元素 + */ + public void addFloatElementToCenterOfElementPane(FloatElement floatElement) { + ElementCase report = this.getEditingElementCase(); + // 500, 270 + long floatWidth = floatElement.getWidth().toFU(); + long floatHeight = floatElement.getHeight().toFU(); + + int horizontalValue = this.getGrid().getHorizontalValue(); + int horizontalExtent = this.getGrid().getHorizontalExtent(); + int verticalValue = this.getGrid().getVerticalValue(); + int verticalExtent = this.getGrid().getVerticalExtent(); + + DynamicUnitList columnWidthList = ReportHelper.getColumnWidthList(report); + DynamicUnitList rowHeightList = ReportHelper.getRowHeightList(report); + + long totalWidth = columnWidthList.getRangeValue(horizontalValue, horizontalValue + horizontalExtent).toFU() - floatWidth; + long totalHeight = rowHeightList.getRangeValue(verticalValue, verticalValue + verticalExtent).toFU() - floatHeight; + + int columnIndex = horizontalValue; + long leftDistance = 0; + int rowIndex = verticalValue; + long topDistance = 0; + if (totalWidth > 0) { + int tmpTotalValue = 0; + while (true) { + tmpTotalValue += columnWidthList.get(columnIndex).toFU(); + if (tmpTotalValue > totalWidth / 2) { + leftDistance = tmpTotalValue - totalWidth / 2 - columnWidthList.get(columnIndex).toFU(); + break; + } + columnIndex++; + } + } + if (totalHeight > 0) { + int tmpTotalValue = 0; + while (true) { + tmpTotalValue += rowHeightList.get(rowIndex).toFU(); + if (tmpTotalValue > totalHeight / 2) { + topDistance = tmpTotalValue - totalHeight / 2 - rowHeightList.get(rowIndex).toFU(); + break; + } + rowIndex++; + } + } + + floatElement.setLeftDistance(FU.getInstance(Math.max(leftDistance, 0))); + floatElement.setTopDistance(FU.getInstance(Math.max(topDistance, 0))); + floatElement.setWidth(FU.getInstance(floatWidth)); + floatElement.setHeight(FU.getInstance(floatHeight)); + + report.addFloatElement(floatElement); + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/ElementCasePaneAuthorityEditPane.java b/designer/src/com/fr/design/mainframe/ElementCasePaneAuthorityEditPane.java new file mode 100644 index 000000000..9eb6303d5 --- /dev/null +++ b/designer/src/com/fr/design/mainframe/ElementCasePaneAuthorityEditPane.java @@ -0,0 +1 @@ +package com.fr.design.mainframe; import java.awt.BorderLayout; import java.awt.Component; import java.awt.Rectangle; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import javax.swing.BorderFactory; import javax.swing.JComponent; import javax.swing.JPanel; import javax.swing.SwingConstants; import com.fr.design.constants.LayoutConstants; import com.fr.design.editor.ValueEditorPane; import com.fr.design.editor.ValueEditorPaneFactory; import com.fr.design.event.UIObserverListener; import com.fr.design.file.HistoryTemplateListPane; 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.mainframe.toolbar.AuthorityEditToolBarComponent; import com.fr.design.roleAuthority.ReportAndFSManagePane; import com.fr.design.roleAuthority.RolesAlreadyEditedPane; import com.fr.form.ui.Widget; import com.fr.general.ComparatorUtils; import com.fr.general.Inter; import com.fr.grid.selection.CellSelection; import com.fr.grid.selection.FloatSelection; import com.fr.grid.selection.Selection; import com.fr.js.NameJavaScriptGroup; import com.fr.report.cell.AbstractCellElement; import com.fr.report.cell.DefaultTemplateCellElement; import com.fr.report.cell.FloatElement; import com.fr.report.cell.TemplateCellElement; import com.fr.report.elementcase.TemplateElementCase; import com.fr.report.worksheet.WorkSheet; import com.fr.stable.ColumnRow; /** * Author : daisy * Date: 13-9-4 * Time: 下午4:01 */ public class ElementCasePaneAuthorityEditPane extends AuthorityEditPane { private static final int WIDGET_VISIBLE = 0; private static final int WIDGET_USABLE = 1; private static final int CELL = 2; private static final int HYPER_LINK = 3; private static final int FLOAT_SELECTION = 3; private static final int NEW_VALUE = 4; //新值下面的编辑器的宽度 private static final int NEW_PANE_WIDTH = 120; private UICheckBox floatElementVisibleCheckBoxes = new UICheckBox(Inter.getLocText("FR-Designer_Visible")); private UICheckBox cellElementVisibleCheckBoxes = new UICheckBox(Inter.getLocText("FR-Designer_Visible")); private UICheckBox widgetVisible = new UICheckBox(Inter.getLocText("FR-Designer_Visible")); private UICheckBox widgetAvailable = new UICheckBox(Inter.getLocText("FR-Designer_Enabled")); private UICheckBox gridColumnRowVisible = new UICheckBox(Inter.getLocText("FR-Designer_Hide")); private UICheckBox newValue = new UICheckBox(Inter.getLocText("FR-Designer_New_Value")); private ValueEditorPane valueEditor = ValueEditorPaneFactory.createBasicValueEditorPane(NEW_PANE_WIDTH); private UICheckBox[] hyperlinkCheckBoxes = null; private ElementCasePane elementCasePane = null; private int selectionType = CellSelection.NORMAL; private CellSelection cellSelection; private FloatSelection floatSelection; private boolean isAllHasWidget; private boolean isAllHasHyperlink; private UIObserverListener observerListener = new UIObserverListener() { @Override public void doChange() { if (elementCasePane == null || cellSelection == null) { return; } if (setAuthorityStyle(NEW_VALUE)) { elementCasePane.fireTargetModified(); } } }; private ItemListener newValuelistener = new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (elementCasePane == null || cellSelection == null) { return; } if (setAuthorityStyle(NEW_VALUE)) { valueEditor.setEnabled(newValue.isSelected()); doAfterAuthority(); } } }; private ItemListener columnRowAuthorityListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (elementCasePane == null) { return; } boolean isDone = false; if (selectionType == CellSelection.CHOOSE_COLUMN) { isDone = setAuthorityColumn(); } else { isDone = setAuthorityRow(); } if (isDone) { doAfterAuthority(); } } }; private ItemListener floatElementAuthorityListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (elementCasePane == null || floatSelection == null) { return; } if (setLFloatAuthorityStyle()) { doAfterAuthority(); } } }; private ItemListener cellRolesAuthorityListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (elementCasePane == null || cellSelection == null) { return; } if (setAuthorityStyle(CELL)) { doAfterAuthority(); } } }; private ItemListener widgetVisibleRoleAuthorityListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (elementCasePane == null || cellSelection == null) { return; } if (setAuthorityStyle(WIDGET_VISIBLE)) { doAfterAuthority(); } } }; private ItemListener widgetUsableAuthorityListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (elementCasePane == null || cellSelection == null) { return; } if (setAuthorityStyle(WIDGET_USABLE)) { doAfterAuthority(); } } }; public ElementCasePaneAuthorityEditPane(ElementCasePane elementCasePane) { super(elementCasePane); this.elementCasePane = elementCasePane; initCheckBoxesState(); initListener(); } private void doAfterAuthority() { elementCasePane.repaint(); elementCasePane.fireTargetModified(); RolesAlreadyEditedPane.getInstance().refreshDockingView(); RolesAlreadyEditedPane.getInstance().setReportAndFSSelectedRoles(); RolesAlreadyEditedPane.getInstance().repaint(); checkCheckBoxes(); } private boolean setAuthorityColumn() { String selectedRoles = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); if (ComparatorUtils.equals(selectedRoles, Inter.getLocText("FR-Designer_Role"))) { return false; } if (selectedRoles == null) { return false; } final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); boolean isVisible = !gridColumnRowVisible.isSelected(); if (!isVisible) { for (int col = cellSelection.getColumn(); col < cellSelection.getColumn() + cellSelection.getColumnSpan(); col++) { elementCase.addColumnPrivilegeControl(col, selectedRoles); } } else { for (int col = cellSelection.getColumn(); col < cellSelection.getColumn() + cellSelection.getColumnSpan(); col++) { elementCase.removeColumnPrivilegeControl(col, selectedRoles); } } return true; } private boolean setAuthorityRow() { String selectedRoles = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); if (ComparatorUtils.equals(selectedRoles, Inter.getLocText("FR-Designer_Role"))) { return false; } if (selectedRoles == null) { return false; } final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); boolean isVisible = !gridColumnRowVisible.isSelected(); if (!isVisible) { for (int row = cellSelection.getRow(); row < cellSelection.getRow() + cellSelection.getRowSpan(); row++) { elementCase.addRowPrivilegeControl(row, selectedRoles); } } else { for (int row = cellSelection.getRow(); row < cellSelection.getRow() + cellSelection.getRowSpan(); row++) { elementCase.removeRowPrivilegeControl(row, selectedRoles); } } return true; } private boolean setLFloatAuthorityStyle() { String selectedRoles = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); if (ComparatorUtils.equals(selectedRoles, Inter.getLocText("FR-Designer_Role"))) { return false; } if (selectedRoles == null) { return false; } String name = floatSelection.getSelectedFloatName(); TemplateElementCase ec = elementCasePane.getEditingElementCase(); FloatElement fe = ec.getFloatElement(name); fe.changeAuthorityState(selectedRoles, floatElementVisibleCheckBoxes.isSelected()); return true; } private boolean setAuthorityStyle(int type) { String selectedRoles = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); if (ComparatorUtils.equals(selectedRoles, Inter.getLocText("FR-Designer_Role"))) { return false; } if (selectedRoles == null) { return false; } final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); int cellRectangleCount = cellSelection.getCellRectangleCount(); for (int rec = 0; rec < cellRectangleCount; rec++) { Rectangle cellRectangle = cellSelection.getCellRectangle(rec); // 从最后循环起以保证最后一个修改标准单元格(originalStyle)。 for (int j = cellRectangle.height - 1; j >= 0; j--) { for (int i = cellRectangle.width - 1; i >= 0; i--) { int column = i + cellRectangle.x; int row = j + cellRectangle.y; TemplateCellElement editCellElement = elementCase.getTemplateCellElement(column, row); if (editCellElement == null) { editCellElement = new DefaultTemplateCellElement(column, row); elementCase.addCellElement(editCellElement); } else { // 对于合并的格子,我们不多次计算的权限. if (editCellElement.getColumn() != column || editCellElement.getRow() != row) { continue; } } if (type == CELL) { editCellElement.changeAuthorityState(selectedRoles, cellElementVisibleCheckBoxes.isSelected()); } else if (type == NEW_VALUE) { editCellElement.changeNewValueAuthorityState(selectedRoles, newValue.isSelected(), valueEditor.update()); } else if (type == WIDGET_VISIBLE) { Widget widget = editCellElement.getWidget(); widget.changeVisibleAuthorityState(selectedRoles, widgetVisible.isSelected()); } else { Widget widget = editCellElement.getWidget(); widget.changeUsableAuthorityState(selectedRoles, widgetAvailable.isSelected()); } } } } return true; } /** * 选中的单元格的乐见状态以第一个单元格为齐 */ public void initCheckBoxesState() { final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); if (cellSelection == null) { cellElementVisibleCheckBoxes.setSelected(true); } else { Rectangle cellRectangle = cellSelection.getCellRectangle(0); DefaultTemplateCellElement cellElement = (DefaultTemplateCellElement) elementCase.getCellElement(cellRectangle.x, cellRectangle.y); if (cellElement == null) { cellElement = new DefaultTemplateCellElement(cellRectangle.x, cellRectangle.y); } boolean firstCellDoneaAuthority = cellElement.isDoneAuthority( ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName()); cellElementVisibleCheckBoxes.setSelected(!firstCellDoneaAuthority); } widgetAvailable.setEnabled(cellElementVisibleCheckBoxes.isSelected()); widgetVisible.setEnabled(cellElementVisibleCheckBoxes.isSelected()); } private void initListener() { cellElementVisibleCheckBoxes.addItemListener(cellRolesAuthorityListener); widgetVisible.addItemListener(widgetVisibleRoleAuthorityListener); widgetAvailable.addItemListener(widgetUsableAuthorityListener); floatElementVisibleCheckBoxes.addItemListener(floatElementAuthorityListener); gridColumnRowVisible.addItemListener(columnRowAuthorityListener); newValue.addItemListener(newValuelistener); valueEditor.registerChangeListener(observerListener); } private void removeListener() { cellElementVisibleCheckBoxes.removeItemListener(cellRolesAuthorityListener); widgetVisible.removeItemListener(widgetVisibleRoleAuthorityListener); widgetAvailable.removeItemListener(widgetUsableAuthorityListener); floatElementVisibleCheckBoxes.removeItemListener(floatElementAuthorityListener); gridColumnRowVisible.removeItemListener(columnRowAuthorityListener); newValue.removeItemListener(newValuelistener); valueEditor.registerChangeListener(null); } private void addHyperlinkListener() { cellElementVisibleCheckBoxes.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (hyperlinkCheckBoxes != null) { for (int i = 0; i < hyperlinkCheckBoxes.length; i++) { hyperlinkCheckBoxes[i].setEnabled(cellElementVisibleCheckBoxes.isSelected()); if (!cellElementVisibleCheckBoxes.isSelected()) { hyperlinkCheckBoxes[i].setSelected(false); } } } } }); for (int i = 0; i < hyperlinkCheckBoxes.length; i++) { hyperlinkCheckBoxes[i].addItemListener(cellRolesAuthorityListener); } } /** * 更新适合的类型 */ public void populateType() { if (selectionType == CellSelection.NORMAL) { type.setText(Inter.getLocText("FR-Designer_Cell")); } else if (selectionType == CellSelection.CHOOSE_ROW) { type.setText(Inter.getLocText("FR-Designer_Row")); } else if (selectionType == CellSelection.CHOOSE_COLUMN) { type.setText(Inter.getLocText("FR-Designer_Column")); } else { type.setText(Inter.getLocText("M_Insert-Float")); } } /** * 名字 */ public void populateName() { if (selectionType == CellSelection.NORMAL) { name.setText(getCellSelectionName()); } else if (selectionType == CellSelection.CHOOSE_ROW || selectionType == CellSelection.CHOOSE_COLUMN) { name.setText(getCellColumnRowName()); } else { name.setText(getFloatSelectionName()); } } private String getCellSelectionName() { String nameText = ""; int count = cellSelection.getCellRectangleCount(); for (int rect = 0; rect < count; rect++) { nameText += ","; Rectangle cellRectangle = cellSelection.getCellRectangle(rect); ColumnRow beginCR = ColumnRow.valueOf(cellRectangle.x, cellRectangle.y); nameText += beginCR.toString(); if (cellRectangle.width * cellRectangle.height != 1) { ColumnRow endCR = ColumnRow.valueOf(cellRectangle.width + cellRectangle.x - 1, cellRectangle.height + cellRectangle.y - 1); nameText += ":" + endCR.toString(); } } return nameText.substring(1); } private String getCellColumnRowName() { int count = cellSelection.getCellRectangleCount(); String nameText = ""; ColumnRow cr = ColumnRow.valueOf(cellSelection.getColumn(), cellSelection.getRow()); if (cellSelection.getSelectedType() == CellSelection.CHOOSE_COLUMN && count == 1) { if (cellSelection.getColumnSpan() == 1) { nameText = cr.toString().substring(0, 1); } else { ColumnRow endCr = ColumnRow.valueOf(cellSelection.getColumn() + cellSelection.getColumnSpan() - 1, cellSelection.getRow() + cellSelection.getRowSpan() - 1); nameText = cr.toString().substring(0, 1) + "-" + endCr.toString().substring(0, 1); } } else if (cellSelection.getSelectedType() == CellSelection.CHOOSE_ROW && count == 1) { if (cellSelection.getRowSpan() == 1) { nameText = cr.toString().substring(1); } else { ColumnRow endCr = ColumnRow.valueOf(cellSelection.getColumn() + cellSelection.getColumnSpan() - 1, cellSelection.getRow() + cellSelection.getRowSpan() - 1); nameText = cr.toString().substring(1) + "-" + endCr.toString().substring(1); } } return nameText; } private String getFloatSelectionName() { return floatSelection.getSelectedFloatName(); } private void mutilRect(CellSelection cellSelection) { isAllHasWidget = true; isAllHasHyperlink = true; int count = cellSelection.getCellRectangleCount(); final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); for (int rect = 0; rect < count; rect++) { Rectangle cellRectangle = cellSelection.getCellRectangle(rect); for (int j = 0; j < cellRectangle.height; j++) { for (int i = 0; i < cellRectangle.width; i++) { int column = i + cellRectangle.x; int row = j + cellRectangle.y; DefaultTemplateCellElement cellElement = (DefaultTemplateCellElement) elementCase.getCellElement(column, row); if (cellElement == null) { cellElement = new DefaultTemplateCellElement(cellSelection.getColumn(), cellSelection.getRow()); } if (cellElement.getCellWidgetAttr() == null) { isAllHasWidget = false; } if (cellElement.getNameHyperlinkGroup() == null) { isAllHasHyperlink = false; } } } } } /** * 更新适合的pane * * @return 返回Pane */ public JPanel populateCheckPane() { checkPane.removeAll(); if (selectionType == CellSelection.NORMAL) { populateCellSelectionCheckPane(checkPane); } else if (selectionType == CellSelection.CHOOSE_COLUMN || selectionType == CellSelection.CHOOSE_ROW) { populateColumnRowCheckPane(checkPane); } else if (selectionType == FLOAT_SELECTION) { populateFloatSelectionCheckPane(checkPane); } checkPane.setBorder(BorderFactory.createEmptyBorder(ALIGNMENT_GAP, 0, 0, 0)); return checkPane; } private void populateColumnRowCheckPane(JPanel checkPane) { double f = TableLayout.FILL; double p = TableLayout.PREFERRED; Component[][] components = new Component[][]{ new Component[]{gridColumnRowVisible} }; double[] rowSize = {p}; double[] columnSize = {f}; int[][] rowCount = {{1}}; checkPane.add( TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM) , BorderLayout.WEST); } private void populateFloatSelectionCheckPane(JPanel checkPane) { checkPane.add(populateFloatElementCheckPane(), BorderLayout.WEST); } private void populateCellSelectionCheckPane(JPanel checkPane) { if (elementCasePane.isSelectedOneCell()) { //只选中了一个单元格 final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); DefaultTemplateCellElement cellElement = (DefaultTemplateCellElement) elementCase.getCellElement(cellSelection.getColumn(), cellSelection.getRow()); if (cellElement == null) { cellElement = new DefaultTemplateCellElement(cellSelection.getColumn(), cellSelection.getRow()); } //单元格带控件 if (cellElement.getCellWidgetAttr() != null) { checkPane.add(populateWidgetCheckPane(), BorderLayout.WEST); } else { checkPane.add(populatCellCheckPane(), BorderLayout.WEST); } } else { //批量选中单元格 mutilRect(cellSelection); if (!isAllHasWidget && !isAllHasHyperlink) { checkPane.add(populateMutilCellCheckPane(), BorderLayout.WEST); } else if (isAllHasWidget) { checkPane.add(populateMutilWidgetCheckPane(), BorderLayout.WEST); } } } /** * 对单元格区域进行操作时的权限编辑页面 ,对应的角色的populate */ public void populateDetials() { //做模式标记,此时鼠标焦点是在报表主体,为下一次退出权限编辑时做准备 HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().setAuthorityMode(false); TemplateElementCase templateElementCase = elementCasePane.getEditingElementCase(); if (templateElementCase instanceof WorkSheet) { ((WorkSheet) templateElementCase).setPaintSelection(true); } signelSelection(); Selection selection = elementCasePane.getSelection(); if (selection instanceof CellSelection) { selectionType = CellSelection.NORMAL; this.cellSelection = ((CellSelection) selection).clone(); this.floatSelection = null; judgeChooseCR(); } else if (selection instanceof FloatSelection) { selectionType = FLOAT_SELECTION; cellSelection = null; floatSelection = new FloatSelection(((FloatSelection) selection).getSelectedFloatName()); } populateType(); populateName(); populateCheckPane(); checkCheckBoxes(); } //判断是否选择的行列 private void judgeChooseCR() { if (cellSelection.getSelectedType() == CellSelection.CHOOSE_COLUMN && cellSelection.getCellRectangleCount() == 1) { selectionType = CellSelection.CHOOSE_COLUMN; } if (cellSelection.getSelectedType() == CellSelection.CHOOSE_ROW && cellSelection.getCellRectangleCount() == 1) { selectionType = CellSelection.CHOOSE_ROW; } } //实现单选 private void signelSelection() { JTemplate jTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); if (jTemplate.isJWorkBook()) { //清工具栏 JComponent component = DesignerContext.getDesignerFrame().getToolbarComponent(); if (component instanceof AuthorityEditToolBarComponent) { ((AuthorityEditToolBarComponent) component).removeSelection(); } //清参数面板 jTemplate.removeParameterPaneSelection(); } } private JPanel populateFloatElementCheckPane() { double f = TableLayout.FILL; double p = TableLayout.PREFERRED; Component[][] components = new Component[][]{ new Component[]{new UILabel(Inter.getLocText("M_Insert-Float"), SwingConstants.LEFT), floatElementVisibleCheckBoxes} }; double[] rowSize = {p}; double[] columnSize = {p, f}; int[][] rowCount = {{1, 1}}; return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); } private JPanel populateWidgetCheckPane() { double f = TableLayout.FILL; double p = TableLayout.PREFERRED; Component[][] components = new Component[][]{ new Component[]{new UILabel(Inter.getLocText("FR-Designer_Cell"), SwingConstants.LEFT), cellElementVisibleCheckBoxes}, new Component[]{null, newValue}, new Component[]{null, valueEditor}, new Component[]{new UILabel(Inter.getLocText("FR-Designer_Widget"), SwingConstants.LEFT), widgetVisible}, new Component[]{null, widgetAvailable} }; double[] rowSize = {p, p, p, p, p}; double[] columnSize = {p, f}; int[][] rowCount = {{1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}}; return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); } private JPanel populateMutilWidgetCheckPane() { double f = TableLayout.FILL; double p = TableLayout.PREFERRED; Component[][] components = new Component[][]{ new Component[]{new UILabel(Inter.getLocText("FR-Designer_Cell"), SwingConstants.LEFT), cellElementVisibleCheckBoxes}, new Component[]{new UILabel(Inter.getLocText("FR-Designer_Widget"), SwingConstants.LEFT), widgetVisible}, new Component[]{null, widgetAvailable} }; double[] rowSize = {p, p, p}; double[] columnSize = {p, f}; int[][] rowCount = {{1, 1}, {1, 1}, {1, 1}}; return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); } private JPanel populateMutilCellCheckPane() { double f = TableLayout.FILL; double p = TableLayout.PREFERRED; Component[][] components = new Component[][]{ new Component[]{cellElementVisibleCheckBoxes}, }; double[] rowSize = {p}; double[] columnSize = {f}; int[][] rowCount = {{1}}; return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); } private JPanel populatCellCheckPane() { double f = TableLayout.FILL; double p = TableLayout.PREFERRED; Component[][] components = new Component[][]{ new Component[]{cellElementVisibleCheckBoxes}, new Component[]{newValue}, new Component[]{valueEditor} }; double[] rowSize = {p, p, p}; double[] columnSize = {f}; int[][] rowCount = {{1}, {1}, {1}}; return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); } public TemplateCellElement getFirstCell() { final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); Rectangle cellRectangle = cellSelection.getCellRectangle(0); // 从最后循环起以保证最后一个修改标准单元格(originalStyle)。 TemplateCellElement firstCell = null; for (int j = cellRectangle.height - 1; j >= 0; j--) { for (int i = cellRectangle.width - 1; i >= 0; i--) { int column = i + cellRectangle.x; int row = j + cellRectangle.y; TemplateCellElement editCellElement = elementCase.getTemplateCellElement(column, row); if (editCellElement != null) { // 对于合并的格子,我们不多次计算的权限. if (editCellElement.getColumn() != column || editCellElement.getRow() != row) { continue; } firstCell = editCellElement; } } } return firstCell; } private void checkCheckBoxes() { String selected = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); removeListener(); if (selectionType == CellSelection.NORMAL) { checkCellSelectionCkeckboxes(selected); } else if (selectionType == CellSelection.CHOOSE_COLUMN || selectionType == CellSelection.CHOOSE_ROW) { checkColumnRowCheckBoxes(selected); } else if (selectionType == FLOAT_SELECTION) { checkFloatSelectionCkeckboxes(selected); } initListener(); } private void checkCellSelectionCkeckboxes(String selected) { TemplateCellElement firstCell = getFirstCell(); if (firstCell == null) { resetCellElementCheckBoxes(); return; } cellElementVisibleCheckBoxes.setSelected(!firstCell.isDoneAuthority(selected)); newValue.setEnabled(!firstCell.isDoneAuthority(selected)); if (!firstCell.isDoneAuthority(selected)) { newValue.setSelected(firstCell.isDoneNewValueAuthority(selected)); if (newValue.isSelected()) { valueEditor.setEnabled(true); valueEditor.populate(firstCell.getCellPrivilegeControl().getNewValueMap().get(selected)); } else { valueEditor.setEnabled(false); } } else { newValue.setSelected(false); valueEditor.setEnabled(false); } populateWidgetButton(firstCell.getWidget(), selected, firstCell); } private void populateWidgetButton(Widget widget, String selected, TemplateCellElement firstCell){ if(widget == null){ return; } if(widget.isVisible()){ widgetVisible.setSelected(!widget.isDoneVisibleAuthority(selected)); widgetVisible.setEnabled(!firstCell.isDoneAuthority(selected)); }else{ widgetVisible.setSelected(widget.isVisibleAuthority(selected)); } if(widget.isEnabled()){ widgetAvailable.setSelected(!widget.isDoneUsableAuthority(selected)); widgetAvailable.setEnabled(!widget.isDoneVisibleAuthority(selected)); }else{ widgetAvailable.setSelected(widget.isUsableAuthority(selected)); } } private void resetCellElementCheckBoxes() { cellElementVisibleCheckBoxes.setSelected(true); widgetVisible.setSelected(true); widgetVisible.setEnabled(true); widgetAvailable.setSelected(true); widgetAvailable.setEnabled(true); newValue.setSelected(false); valueEditor.setEnabled(false); } private void checkColumnRowCheckBoxes(String selected) { if (cellSelection == null) { gridColumnRowVisible.setSelected(false); return; } TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); boolean isInside = selectionType == CellSelection.CHOOSE_COLUMN ? elementCase.getColumnPrivilegeControl(cellSelection.getColumn()).checkInvisible(selected) : elementCase.getRowPrivilegeControl(cellSelection.getRow()).checkInvisible(selected); gridColumnRowVisible.setSelected(isInside); } private void checkFloatSelectionCkeckboxes(String selected) { String name = floatSelection.getSelectedFloatName(); TemplateElementCase ec = elementCasePane.getEditingElementCase(); FloatElement fe = ec.getFloatElement(name); floatElementVisibleCheckBoxes.setSelected(!fe.isDoneAuthority(selected)); } private JPanel populateHyperlinkCheckPane(AbstractCellElement cellElement) { NameJavaScriptGroup linkGroup = cellElement.getNameHyperlinkGroup(); //超链接的个数+单元格可见的操作 hyperlinkCheckBoxes = new UICheckBox[linkGroup.size()]; double f = TableLayout.FILL; double p = TableLayout.PREFERRED; Component[][] components = new Component[hyperlinkCheckBoxes.length + 1][]; if (linkGroup.size() == 1) { components[0] = new Component[]{new UILabel(Inter.getLocText("FR-Designer_Cell"), SwingConstants.LEFT), cellElementVisibleCheckBoxes}; components[1] = new Component[]{new UILabel(Inter.getLocText("FR-Designer_Hyperlink"), SwingConstants.LEFT), hyperlinkCheckBoxes[0] = new UICheckBox(Inter.getLocText("FR-Designer_Visible"))}; } else { components[0] = new Component[]{new UILabel(Inter.getLocText("FR-Designer_Cell"), SwingConstants.LEFT), cellElementVisibleCheckBoxes = new UICheckBox(Inter.getLocText("FR-Designer_Visible"))}; components[1] = new Component[]{new UILabel(Inter.getLocText("FR-Designer_Hyperlink"), SwingConstants.LEFT), hyperlinkCheckBoxes[0] = new UICheckBox(linkGroup.getNameHyperlink(0).getName() + Inter.getLocText("FR-Designer_Visible"))}; for (int i = 1; i < hyperlinkCheckBoxes.length; i++) { components[i + 1] = new Component[]{null, hyperlinkCheckBoxes[i] = new UICheckBox(linkGroup.getNameHyperlink(i).getName() + Inter.getLocText("FR-Designer_Visible"))}; } } for (int i = 0; i < hyperlinkCheckBoxes.length; i++) { hyperlinkCheckBoxes[i].setEnabled(cellElementVisibleCheckBoxes.isSelected()); } addHyperlinkListener(); double[] rowSize = new double[hyperlinkCheckBoxes.length + 1]; int[][] rowCount = new int[hyperlinkCheckBoxes.length + 1][]; for (int i = 0; i < hyperlinkCheckBoxes.length + 1; i++) { rowSize[i] = p; rowCount[i] = new int[]{1, 1}; } double[] columnSize = {p, f}; return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); } private JPanel populateMutilHyperlinkCheckPane() { //超链接的个数+单元格可见的操作 hyperlinkCheckBoxes = new UICheckBox[1]; double f = TableLayout.FILL; double p = TableLayout.PREFERRED; Component[][] components = new Component[2][]; components[0] = new Component[]{new UILabel(Inter.getLocText("FR-Designer_Cell"), SwingConstants.LEFT), cellElementVisibleCheckBoxes}; components[1] = new Component[]{new UILabel(Inter.getLocText("FR-Designer_Hyperlink"), SwingConstants.LEFT), hyperlinkCheckBoxes[0] = new UICheckBox(Inter.getLocText("FR-Designer_Visible"))}; hyperlinkCheckBoxes[0].setEnabled(cellElementVisibleCheckBoxes.isSelected()); addHyperlinkListener(); double[] rowSize = {p, p}; double[] columnSize = {p, f}; int[][] rowCount = {{1, 1}, {1, 1}}; return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); } } \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/ElementCasePaneDelegate.java b/designer/src/com/fr/design/mainframe/ElementCasePaneDelegate.java new file mode 100644 index 000000000..9ea5e47aa --- /dev/null +++ b/designer/src/com/fr/design/mainframe/ElementCasePaneDelegate.java @@ -0,0 +1,166 @@ +package com.fr.design.mainframe; + +import com.fr.base.BaseUtils; +import com.fr.design.fun.MenuHandler; +import com.fr.design.menu.KeySetUtils; +import com.fr.general.Inter; +import com.fr.page.ReportSettingsProvider; +import com.fr.design.file.HistoryTemplateListPane; +import com.fr.design.DesignState; +import com.fr.design.roleAuthority.RolesAlreadyEditedPane; +import com.fr.design.actions.UpdateAction; +import com.fr.design.actions.cell.*; +import com.fr.design.actions.core.ActionUtils; +import com.fr.design.actions.edit.HyperlinkAction; +import com.fr.design.actions.edit.merge.MergeCellAction; +import com.fr.design.actions.edit.merge.UnmergeCellAction; +import com.fr.design.actions.columnrow.InsertColumnAction; +import com.fr.design.actions.columnrow.InsertRowAction; +import com.fr.design.actions.utils.DeprecatedActionManager; +import com.fr.design.event.TargetModifiedEvent; +import com.fr.design.event.TargetModifiedListener; +import com.fr.design.mainframe.cell.QuickEditorRegion; +import com.fr.design.menu.MenuDef; +import com.fr.design.menu.SeparatorDef; +import com.fr.report.worksheet.WorkSheet; +import com.fr.design.selection.SelectionEvent; +import com.fr.design.selection.SelectionListener; +import com.fr.stable.ArrayUtils; + +import javax.swing.*; + +/** + * 类说明: 设计面板中最上方的"插入" "单元格"下拉列表Menu模块. + * + * @author kunsnat E-mail:kunsnat@gmail.com + * @version 创建时间:2013-6-25 上午09:56:57 + */ +public class ElementCasePaneDelegate extends ElementCasePane { + + public ElementCasePaneDelegate(WorkSheet sheet) { + super(sheet); + this.addSelectionChangeListener(new SelectionListener() { + + @Override + public void selectionChanged(SelectionEvent e) { + //在编辑权限,所以要更新权限编辑面板 + if (BaseUtils.isAuthorityEditing()) { + AuthorityPropertyPane authorityPropertyPane = new AuthorityPropertyPane(ElementCasePaneDelegate.this); + authorityPropertyPane.populate(); + EastRegionContainerPane.getInstance().replaceUpPane(authorityPropertyPane); + EastRegionContainerPane.getInstance().replaceDownPane(RolesAlreadyEditedPane.getInstance()); + return; + } + + CellElementPropertyPane.getInstance().populate(ElementCasePaneDelegate.this); + QuickEditorRegion.getInstance().populate(getCurrentEditor()); + JTemplate editingTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); + if (editingTemplate != null && !editingTemplate.isUpMode()) { + EastRegionContainerPane.getInstance().replaceDownPane(CellElementPropertyPane.getInstance()); + EastRegionContainerPane.getInstance().replaceUpPane(QuickEditorRegion.getInstance()); + } + } + }); + this.addTargetModifiedListener(new TargetModifiedListener() { + @Override + public void targetModified(TargetModifiedEvent e) { + CellElementPropertyPane.getInstance().populate(ElementCasePaneDelegate.this); + } + }); + } + + @Override + protected boolean supportRepeatedHeaderFooter() { + return true; + } + + /** + * 选中目标的 对应Menu + * + * @return 返回MenuDef数组. + */ + public MenuDef[] menus4Target() { + if (BaseUtils.isAuthorityEditing()) { + return super.menus4Target(); + } + return (MenuDef[]) ArrayUtils.addAll(super.menus4Target(), new MenuDef[]{createInsertMenuDef(), createCellMenuDef()}); + } + + public int getMenuState() { + return DesignState.WORK_SHEET; + } + + /** + * 是否必须为可见范围. + * + * @return 不是必须在可见范围. + */ + public boolean mustInVisibleRange() { + return false; + } + + // 插入菜单 + private MenuDef createInsertMenuDef() { + MenuDef menuDef = new MenuDef(Inter.getLocText("M-Insert"), 'I'); + menuDef.setAnchor(MenuHandler.INSERT); + // 单元格菜单 + menuDef.addShortCut(DeprecatedActionManager.getCellMenu(this)); + + addInsertFloatMenuDef(menuDef); + menuDef.addShortCut(SeparatorDef.DEFAULT); + menuDef.addShortCut(new InsertRowAction(this)); + menuDef.addShortCut(new InsertColumnAction(this)); + return menuDef; + } + + + public JPanel getEastUpPane() { + QuickEditorRegion.getInstance().populate(getCurrentEditor()); + return QuickEditorRegion.getInstance(); + } + + + public JPanel getEastDownPane() { + CellElementPropertyPane.getInstance().populate(ElementCasePaneDelegate.this); + return CellElementPropertyPane.getInstance(); + } + + + private void addInsertFloatMenuDef(MenuDef menuDef) { + // 悬浮元素菜单 + MenuDef subMenuDef = new MenuDef(KeySetUtils.INSERT_FLOAT.getMenuName()); + subMenuDef.setIconPath("/com/fr/design/images/m_insert/float.png"); + menuDef.addShortCut(subMenuDef); + UpdateAction[] actions = ActionUtils.createFloatInsertAction(ElementCasePane.class, this); + for (int i = 0; i < actions.length; i++) { + subMenuDef.addShortCut(actions[i]); + } + } + + // 格式菜单 + private MenuDef createCellMenuDef() { + MenuDef menuDef = new MenuDef(KeySetUtils.CELL.getMenuKeySetName(), KeySetUtils.CELL.getMnemonic()); + + menuDef.addShortCut(new CellExpandAttrAction()); + menuDef.addShortCut(new CellWidgetAttrAction(this)); + menuDef.addShortCut(new GlobalStyleMenuDef(this)); + menuDef.addShortCut(new ConditionAttributesAction(this)); + + // 单元格形态 + menuDef.addShortCut(DeprecatedActionManager.getPresentMenu(this)); + + menuDef.addShortCut(new HyperlinkAction(this)); + menuDef.addShortCut(SeparatorDef.DEFAULT); + menuDef.addShortCut(new MergeCellAction(this)); + menuDef.addShortCut(new UnmergeCellAction(this)); + menuDef.addShortCut(SeparatorDef.DEFAULT); + menuDef.addShortCut(new CellAttributeAction()); + return menuDef; + } + + @Override + public ReportSettingsProvider getReportSettings() { + return this.getTarget().getReportSettings(); + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/FormatBrushAction.java b/designer/src/com/fr/design/mainframe/FormatBrushAction.java new file mode 100644 index 000000000..296fb6d20 --- /dev/null +++ b/designer/src/com/fr/design/mainframe/FormatBrushAction.java @@ -0,0 +1 @@ +package com.fr.design.mainframe; import com.fr.base.BaseUtils; import com.fr.base.Style; import com.fr.design.actions.ElementCaseAction; import com.fr.general.Inter; import com.fr.grid.selection.CellSelection; import com.fr.grid.selection.Selection; import com.fr.report.cell.DefaultTemplateCellElement; import com.fr.report.cell.TemplateCellElement; import com.fr.report.elementcase.TemplateElementCase; import javax.swing.*; import java.awt.*; import java.awt.event.*; /** * Author : daisy * Date: 13-8-7 * Time: 上午11:05 */ public class FormatBrushAction extends ElementCaseAction { private ElementCasePane ePane; private CellSelection oldSelection; public FormatBrushAction(ElementCasePane t) { super(t); this.setName(Inter.getLocText("M_Edit-FormatBrush")); this.setMnemonic('B'); this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/formatBrush.png")); this.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, KeyEvent.CTRL_MASK)); } public boolean executeActionReturnUndoRecordNeeded() { ePane = (ElementCasePane) getEditingComponent(); if (ePane != null) { Selection selection = ePane.getSelection(); if (!(selection instanceof CellSelection)) { return false; } oldSelection = ((CellSelection) selection).clone(); ePane.setFormatReferencedCell(oldSelection); int cellRectangleCount = oldSelection.getCellRectangleCount(); if (cellRectangleCount > 1) { //格式刷只支持单次选择的区域,如果用ctrl复选选中了多片区域,点击格式刷按钮时弹出提示 //判断是不是连续区域 //荣国是连续区域,那么这些长方形的长加起来应该等于 if (!isContinueArea()) { JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("Can_not_use_FormatBursh")); ePane.setFormatState(DesignerContext.FORMAT_STATE_NULL); ePane.getFormatBrush().setSelected(false); return false; } } //只对单个区域进行格式刷操作 ((ElementCasePane) DesignerContext.getReferencedElementCasePane()).getGrid().setNotShowingTableSelectPane(false); ePane.repaint(); return true; } return false; } /** * 判断是不是连续区域 * * @return */ private boolean isContinueArea() { int xStart = oldSelection.getCellRectangle(1).x; int xend = 0; int yStrat = oldSelection.getCellRectangle(1).y; int yend = 0; int totalNum = 0; for (int i = 0; i < oldSelection.getCellRectangleCount(); i++) { Rectangle temp = oldSelection.getCellRectangle(i); if (temp.getX() < xStart) { xStart = temp.x; } if (temp.getX() + temp.getWidth() > xend) { xend = (int) (temp.getX() + temp.getWidth()); } if (temp.getY() < yStrat) { yStrat = temp.y; } if (temp.getY() + temp.getHeight() > yend) { yend = (int) (temp.getY() + temp.getHeight()); } totalNum += (int) (temp.getWidth() * temp.getHeight()); } if ((xend - xStart) * (yend - yStrat) == totalNum) { oldSelection = new CellSelection(xStart, yStrat, (xend - xStart), (yend - yStrat)); ePane.setSelection(oldSelection); ePane.setFormatReferencedCell(oldSelection); return true; } return false; } public void updateFormatBrush(Style[][] referencedStyle, CellSelection cs, ElementCasePane reportPane) { //得到被参照的单元格的行列数 if (referencedStyle == null) { return; } int rowSpan = referencedStyle[0].length; int columnSpan = referencedStyle.length; //开始进行格式刷样式复制 TemplateElementCase elementCase = reportPane.getEditingElementCase(); int rowNum = cs.getRowSpan(); int columnNum = cs.getColumnSpan(); //如果只点选了一个,则自动补足 if (cs.getColumnSpan() * cs.getRowSpan() == 1) { rowNum = rowSpan; columnNum = columnSpan; } for (int j = 0; j < rowNum; j++) { for (int i = 0; i < columnNum; i++) { int column = i + cs.getColumn(); int row = j + cs.getRow(); TemplateCellElement cellElement = elementCase.getTemplateCellElement(column, row); if (cellElement == null) { cellElement = new DefaultTemplateCellElement(column, row); elementCase.addCellElement(cellElement); } cellElement.setStyle(referencedStyle[i % columnSpan][j % rowSpan]); } } } private Style[][] getOldStyles(CellSelection oldSelection) { Style[][] referencedStyle = new Style[oldSelection.getColumnSpan()][oldSelection.getRowSpan()]; int cellRectangleCount = oldSelection.getCellRectangleCount(); TemplateElementCase elementCase = ePane.getEditingElementCase(); for (int rect = 0; rect < cellRectangleCount; rect++) { Rectangle cellRectangle = oldSelection.getCellRectangle(rect); for (int j = 0; j < cellRectangle.height; j++) { for (int i = 0; i < cellRectangle.width; i++) { int column = i + cellRectangle.x; int row = j + cellRectangle.y; TemplateCellElement cellElement = elementCase.getTemplateCellElement(column, row); if (cellElement == null) { cellElement = new DefaultTemplateCellElement(column, row); elementCase.addCellElement(cellElement); } Style style = cellElement.getStyle(); if (style == null) { style = style.DEFAULT_STYLE; } referencedStyle[i][j] = style; } } } return referencedStyle; } } \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/InformationCollector.java b/designer/src/com/fr/design/mainframe/InformationCollector.java new file mode 100644 index 000000000..f7711efb7 --- /dev/null +++ b/designer/src/com/fr/design/mainframe/InformationCollector.java @@ -0,0 +1,493 @@ +/** + * + */ +package com.fr.design.mainframe; + +import com.fr.base.FRContext; +import com.fr.data.core.db.DBUtils; +import com.fr.data.core.db.dialect.DialectFactory; +import com.fr.data.core.db.dml.Delete; +import com.fr.data.core.db.dml.Select; +import com.fr.data.core.db.dml.Table; +import com.fr.design.DesignerEnvManager; +import com.fr.general.*; +import com.fr.general.http.HttpClient; +import com.fr.json.JSONArray; +import com.fr.json.JSONException; +import com.fr.record.DBRecordManager; +import com.fr.stable.*; +import com.fr.stable.xml.*; +import com.fr.third.javax.xml.stream.XMLStreamException; +import org.json.JSONObject; + +import java.io.*; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.text.DateFormat; +import java.util.*; + +/** + * @author neil + * + * @date: 2015-4-8-下午5:11:46 + */ +public class InformationCollector implements XMLReadable, XMLWriter { + + //3天上传一次 + private static final long DELTA = 3 * 24 * 3600 * 1000L; + private static final long SEND_DELAY = 30 * 1000L; + private static final String FILE_NAME = "fr.info"; + private static final String XML_START_STOP_LIST = "StartStopList"; + private static final String XML_START_STOP = "StartStop"; + private static final String XML_LAST_TIME = "LastTime"; + private static final String ATTR_START = "start"; + private static final String ATTR_STOP = "stop"; + private static final String XML_JAR = "JarInfo"; + private static final String XML_VERSION = "Version"; + private static final String XML_USERNAME = "Username"; + private static final String XML_UUID = "UUID"; + private static final String XML_KEY = "ActiveKey"; + private static final String XML_OS = "OS"; + + public static final String FUNCTIONS_INFO = "http://feedback.finedevelop.com:3000/monitor/function/record"; + public static final String USER_INFO = "http://feedback.finedevelop.com:3000/monitor/userinfo/record"; + public static final String TABLE_NAME = "fr_functionrecord"; + public static final String FUNC_COLUMNNAME = "func"; + + private static InformationCollector collector; + + //启动时间与关闭时间列表 + private List startStop = new ArrayList(); + //上一次的发送时间 + private String lastTime; + private StartStopTime current = new StartStopTime(); + + public static InformationCollector getInstance(){ + if (collector == null) { + collector = new InformationCollector(); + + readEncodeXMLFile(collector, collector.getInfoFile()); + } + + return collector; + } + + private static void readEncodeXMLFile(XMLReadable xmlReadable, File xmlFile){ + if (xmlFile == null || !xmlFile.exists()) { + return; + } + String charset = EncodeConstants.ENCODING_UTF_8; + try { + String decodeContent = getDecodeFileContent(xmlFile); + InputStream xmlInputStream = new ByteArrayInputStream(decodeContent.getBytes(charset)); + InputStreamReader inputStreamReader = new InputStreamReader(xmlInputStream, charset); + + XMLableReader xmlReader = XMLableReader.createXMLableReader(inputStreamReader); + + if (xmlReader != null) { + xmlReader.readXMLObject(xmlReadable); + } + xmlInputStream.close(); + } catch (FileNotFoundException e) { + FRContext.getLogger().error(e.getMessage()); + } catch (IOException e) { + FRContext.getLogger().error(e.getMessage()); + } catch (XMLStreamException e) { + FRContext.getLogger().error(e.getMessage()); + } + + } + + private static String getDecodeFileContent(File xmlFile) throws FileNotFoundException, UnsupportedEncodingException{ + InputStream encodeInputStream = new FileInputStream(xmlFile); + String encodeContent = IOUtils.inputStream2String(encodeInputStream); + return DesUtils.getDecString(encodeContent); + } + + private long getLastTimeMillis(){ + if (StringUtils.isEmpty(this.lastTime)) { + return 0; + } + + try { + return DateUtils.string2Date(this.lastTime, true).getTime(); + } catch (Exception e) { + return -1; + } + + } + + private byte[] getJSONContentAsByte(){ + JSONObject content = new JSONObject(); + + JSONArray startStopArray = new JSONArray(); + for (int i = 0; i < startStop.size(); i++) { + JSONObject jo = new JSONObject(); + jo.put(ATTR_START, startStop.get(i).getStartDate()); + jo.put(ATTR_STOP, startStop.get(i).getStopDate()); + startStopArray.put(jo); + } + DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); + content.put(XML_START_STOP, startStopArray); + content.put(XML_UUID, envManager.getUUID()); + content.put(XML_JAR, GeneralUtils.readBuildNO()); + content.put(XML_VERSION, ProductConstants.RELEASE_VERSION); + content.put(XML_USERNAME, envManager.getBBSName()); + content.put(XML_KEY, envManager.getActivationKey()); + content.put(XML_OS, System.getProperty("os.name")); + + try { + return content.toString().getBytes(EncodeConstants.ENCODING_UTF_8); + } catch (UnsupportedEncodingException e) { + FRContext.getLogger().error(e.getMessage()); + return ArrayUtils.EMPTY_BYTE_ARRAY; + } + } + + private void sendUserInfo(){ + long currentTime = new Date().getTime(); + long lastTime = getLastTimeMillis(); + + if (currentTime - lastTime <= DELTA) { + return; + } + byte[] content = getJSONContentAsByte(); + HttpClient hc = new HttpClient(USER_INFO); + hc.setContent(content); + if (!hc.isServerAlive()) { + return; + } + String res = hc.getResponseText(); + //服务器返回true,说明已经取得成功,清空当前记录的信息 + boolean success = ComparatorUtils.equals(new JSONObject(res).get("status"), "success"); + if (success){ + this.reset(); + } + } + + private void sendFunctionsInfo(){ + long currentTime = new Date().getTime(); + long lastTime = getLastTimeMillis(); + if (currentTime - lastTime <= DELTA) { + return; + } + + byte[] content = ArrayUtils.EMPTY_BYTE_ARRAY; + Connection conn = null; + Table table = new Table(TABLE_NAME); + + try { + conn = DBRecordManager.getDB().createConnection(); + ResultSet rs = selectAllFromLogDB(conn, table); + + if(rs == null){ + return; + } + content = getFunctionsContentAsByte(rs); + } catch (Exception e) { + FRContext.getLogger().error(e.getMessage()); + } finally { + DBUtils.closeConnection(conn); + } + + HttpClient httpClient = new HttpClient(FUNCTIONS_INFO); + httpClient.setContent(content); + httpClient.setTimeout(5000); + + if (!httpClient.isServerAlive()) { + return; + } + + String res = httpClient.getResponseText(); + boolean success = ComparatorUtils.equals(new JSONObject(res).get("status"), "success"); + //服务器返回true, 说明已经获取成功, 清空当前记录的信息 + if (success) { + deleteLogDB(conn, table); + //收集设计器信息的服务器下线了, 目测还要一段时间, 不在那边一起setLastTime了. + this.lastTime = dateToString(); + } + + } + + private void deleteLogDB(Connection conn, Table table) { + try { + conn = DBRecordManager.getDB().createConnection(); + Delete delete = new Delete(table); + delete.execute(conn); + } catch (Exception e) { + FRContext.getLogger().error(e.getMessage()); + } finally { + DBUtils.closeConnection(conn); + } + } + + + private byte[] getFunctionsContentAsByte(ResultSet rs) throws JSONException{ + com.fr.json.JSONObject content = new com.fr.json.JSONObject(); + HashMap resultMap = new HashMap(); + + try { + while (rs.next()) { + com.fr.json.JSONObject js = new com.fr.json.JSONObject(rs.getString(FUNC_COLUMNNAME)); + Map tempMap = js.toMap(); + for (Object key : tempMap.keySet()) { + if(resultMap.containsKey(key)){ + int cacheCount = Integer.parseInt(resultMap.get(key).toString()); + int currentCount = Integer.parseInt(tempMap.get(key).toString()); + resultMap.put(key, cacheCount + currentCount); + } else { + resultMap.put(key, tempMap.get(key)); + } + } + } + rs.close(); + } catch (SQLException e) { + //这边不记,可能还没建表 + } + + JSONArray functionArray = new JSONArray(); + for(Object key : resultMap.keySet()){ + com.fr.json.JSONObject jsonObject = new com.fr.json.JSONObject(); + jsonObject.put("point", key); + jsonObject.put("times", resultMap.get(key)); + functionArray.put(jsonObject); + } + + DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); + content.put("username", envManager.getBBSName()); + content.put("uuid", envManager.getUUID()); + content.put("functions", functionArray); + + try { + return content.toString().getBytes(EncodeConstants.ENCODING_UTF_8); + } catch (UnsupportedEncodingException e) { + FRContext.getLogger().error(e.getMessage()); + return ArrayUtils.EMPTY_BYTE_ARRAY; + } + } + + private ResultSet selectAllFromLogDB(Connection conn, Table table) { + + Select select = new Select(table, DialectFactory.generateDialect(conn)); + PreparedStatement ps; + ResultSet rs; + try { + ps = select.createPreparedStatement(conn); + } catch (SQLException e) { + return null; + } + + try { + rs = ps.executeQuery(); + } catch (SQLException e) { + try { + ps.close(); + } catch (SQLException e1) { + //这边不记,可能还没建表 + } + return null; + } + return rs; + } + + + /** + * 收集开始使用时间,发送信息 + */ + public void collectStartTime(){ + this.current.setStartDate(dateToString()); + + sendUserInfoInOtherThread(); + } + + private void sendUserInfoInOtherThread(){ + if (!DesignerEnvManager.getEnvManager().isJoinProductImprove() || !FRContext.isChineseEnv()) { + return; + } + + Thread sendThread = new Thread(new Runnable() { + + @Override + public void run() { + try { + //读取XML的5分钟后开始发请求连接服务器. + Thread.sleep(SEND_DELAY); + } catch (InterruptedException e) { + FRContext.getLogger().error(e.getMessage()); + } + sendFunctionsInfo(); + sendUserInfo(); + } + }); + sendThread.start(); + } + + /** + * 收集结束使用时间 + */ + public void collectStopTime(){ + this.current.setStopDate(dateToString()); + } + + private String dateToString(){ + DateFormat df = FRContext.getDefaultValues().getDateTimeFormat(); + return df.format(new Date()); + } + + private void reset(){ + this.startStop.clear(); + this.lastTime = dateToString(); + } + + private File getInfoFile() { + return new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), FILE_NAME)); + } + + /** + * 保存xml文件 + */ + public void saveXMLFile() { + File xmlFile = this.getInfoFile(); + try{ + ByteArrayOutputStream out = new ByteArrayOutputStream(); + XMLTools.writeOutputStreamXML(this, out); + out.flush(); + out.close(); + String fileContent = new String(out.toByteArray(), EncodeConstants.ENCODING_UTF_8); + String encodeCotent = DesUtils.getEncString(fileContent); + writeEncodeContentToFile(encodeCotent, xmlFile); + }catch (Exception e) { + FRContext.getLogger().error(e.getMessage()); + } + } + + + /** + * 将文件内容写到输出流中 + */ + private static void writeEncodeContentToFile(String fileContent, File file){ + BufferedWriter bw = null; + try { + FileOutputStream fos = new FileOutputStream(file); + OutputStreamWriter osw = new OutputStreamWriter(fos, EncodeConstants.ENCODING_UTF_8); + bw = new BufferedWriter(osw); + bw.write(fileContent); + } catch (Exception e) { + FRContext.getLogger().error(e.getMessage()); + } finally { + if(bw != null){ + try { + bw.close(); + } catch (IOException e) { + } + } + } + + } + + @Override + public void writeXML(XMLPrintWriter writer) { + startStop.add(current); + writer.startTAG("Info"); + //启停信息 + writeStartStopList(writer); + //上一次更新的时间 + writeTag(XML_LAST_TIME, this.lastTime, writer); + + writer.end(); + } + + private void writeStartStopList(XMLPrintWriter writer){ + //启停 + writer.startTAG(XML_START_STOP_LIST); + for (int i = 0; i < startStop.size(); i++) { + startStop.get(i).writeXML(writer); + } + writer.end(); + } + + private void writeTag(String tag, String content, XMLPrintWriter writer){ + if (StringUtils.isEmpty(content)) { + return; + } + + writer.startTAG(tag); + writer.textNode(content); + writer.end(); + } + + @Override + public void readXML(XMLableReader reader) { + if (reader.isChildNode()) { + String name = reader.getTagName(); + if (XML_START_STOP_LIST.equals(name)) { + readStartStopList(reader); + } else if(XML_LAST_TIME.equals(name)){ + readLastTime(reader); + } + } + } + + private void readLastTime(XMLableReader reader){ + String tmpVal; + if (StringUtils.isNotBlank(tmpVal = reader.getElementValue())) { + this.lastTime = tmpVal; + } + } + + private void readStartStopList(XMLableReader reader){ + startStop.clear(); + + reader.readXMLObject(new XMLReadable() { + public void readXML(XMLableReader reader) { + if (XML_START_STOP.equals(reader.getTagName())) { + StartStopTime startStopTime = new StartStopTime(); + reader.readXMLObject(startStopTime); + startStop.add(startStopTime); + } + } + }); + } + + private class StartStopTime implements XMLReadable, XMLWriter { + + private String startDate; + private String stopDate; + + public String getStartDate() { + return startDate; + } + + public void setStartDate(String startDate) { + this.startDate = startDate; + } + + public String getStopDate() { + return stopDate; + } + + public void setStopDate(String endDate) { + this.stopDate = endDate; + } + + public void writeXML(XMLPrintWriter writer) { + writer.startTAG(XML_START_STOP); + if (StringUtils.isNotEmpty(startDate)) { + writer.attr(ATTR_START, this.startDate); + } + if (StringUtils.isNotEmpty(stopDate)) { + writer.attr(ATTR_STOP, this.stopDate); + } + writer.end(); + } + + public void readXML(XMLableReader reader) { + this.startDate = reader.getAttrAsString(ATTR_START, StringUtils.EMPTY); + this.stopDate = reader.getAttrAsString(ATTR_STOP, StringUtils.EMPTY); + } + + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/JPolyWorkBook.java b/designer/src/com/fr/design/mainframe/JPolyWorkBook.java new file mode 100644 index 000000000..bfdb39664 --- /dev/null +++ b/designer/src/com/fr/design/mainframe/JPolyWorkBook.java @@ -0,0 +1,42 @@ +/** + * + */ +package com.fr.design.mainframe; + +import com.fr.main.impl.WorkBook; +import com.fr.report.poly.PolyWorkSheet; + +/** + * 聚合报表Book, 跟WorkBook区别在于不能放入WorkSheet. + * + * @author neil + * + * @date: 2015-2-5-上午8:58:39 + */ +public class JPolyWorkBook extends JWorkBook { + + private static final String DEFAULT_NAME = "Poly"; + + /** + * 构造函数 + */ + public JPolyWorkBook() { + super(new WorkBook(new PolyWorkSheet()), DEFAULT_NAME); + populateReportParameterAttr(); + } + + + /** + * 创建sheet名称tab面板 + * + * @param reportCompositeX 当前组件对象 + * + * @return sheet名称tab面板 + * + * @date 2015-2-5-上午11:42:12 + * + */ + public SheetNameTabPane createSheetNameTabPane(ReportComponentComposite reportCompositeX){ + return new PolySheetNameTabPane(reportCompositeX); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/JWorkBook.java b/designer/src/com/fr/design/mainframe/JWorkBook.java new file mode 100644 index 000000000..4ebddb199 --- /dev/null +++ b/designer/src/com/fr/design/mainframe/JWorkBook.java @@ -0,0 +1,900 @@ +package com.fr.design.mainframe; + +import com.fr.base.BaseUtils; +import com.fr.base.FRContext; +import com.fr.base.Parameter; +import com.fr.design.DesignModelAdapter; +import com.fr.design.ExtraDesignClassManager; +import com.fr.design.actions.AllowAuthorityEditAction; +import com.fr.design.actions.ExitAuthorityEditAction; +import com.fr.design.actions.file.WebPreviewUtils; +import com.fr.design.actions.file.export.*; +import com.fr.design.actions.report.ReportExportAttrAction; +import com.fr.design.actions.report.ReportParameterAction; +import com.fr.design.actions.report.ReportWebAttrAction; +import com.fr.design.constants.UIConstants; +import com.fr.design.data.datapane.TableDataTreePane; +import com.fr.design.designer.TargetComponent; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.event.TargetModifiedEvent; +import com.fr.design.event.TargetModifiedListener; +import com.fr.design.file.HistoryTemplateListPane; +import com.fr.design.file.MutilTempalteTabPane; +import com.fr.design.fun.PreviewProvider; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.icontainer.UIModeControlContainer; +import com.fr.design.gui.imenu.UIMenuItem; +import com.fr.design.mainframe.cell.QuickEditorRegion; +import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus; +import com.fr.design.menu.*; +import com.fr.design.module.DesignModuleFactory; +import com.fr.design.parameter.ParameterDefinitePane; +import com.fr.design.parameter.ParameterInputPane; +import com.fr.design.preview.PagePreview; +import com.fr.design.preview.ViewPreview; +import com.fr.design.preview.WritePreview; +import com.fr.design.roleAuthority.ReportAndFSManagePane; +import com.fr.design.roleAuthority.RolesAlreadyEditedPane; +import com.fr.design.selection.QuickEditor; +import com.fr.design.write.submit.DBManipulationPane; +import com.fr.design.write.submit.SmartInsertDBManipulationInWidgetEventPane; +import com.fr.design.write.submit.SmartInsertDBManipulationPane; +import com.fr.env.RemoteEnv; +import com.fr.file.FILE; +import com.fr.file.FileNodeFILE; +import com.fr.file.filetree.FileNode; +import com.fr.general.ComparatorUtils; +import com.fr.general.Inter; +import com.fr.general.ModuleContext; +import com.fr.general.web.ParameterConsts; +import com.fr.io.exporter.EmbeddedTableDataExporter; +import com.fr.main.TemplateWorkBook; +import com.fr.main.impl.WorkBook; +import com.fr.main.parameter.ReportParameterAttr; +import com.fr.poly.PolyDesigner; +import com.fr.privilege.finegrain.WorkSheetPrivilegeControl; +import com.fr.report.elementcase.TemplateElementCase; +import com.fr.report.worksheet.WorkSheet; +import com.fr.stable.ArrayUtils; +import com.fr.stable.StableUtils; +import com.fr.stable.StringUtils; +import com.fr.stable.module.Module; +import com.fr.stable.project.ProjectConstants; + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.FileOutputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * JWorkBook used to edit WorkBook. + */ +public class JWorkBook extends JTemplate { + + private static final String SHARE_SUFFIX = "_share"; + private static final String SHARE_FOLDER = "share"; + private static final int TOOLBARPANEDIMHEIGHT = 26; + + private UIModeControlContainer centerPane; + private ReportComponentComposite reportComposite; + private ParameterDefinitePane parameterPane; + + public JWorkBook() { + super(new WorkBook(new WorkSheet()), "WorkBook"); + populateReportParameterAttr(); + } + + public JWorkBook(WorkBook workBook, String fileName) { + super(workBook, fileName); + populateReportParameterAttr(); + } + + public JWorkBook(WorkBook workBook, FILE file) { + super(workBook, file); + populateReportParameterAttr(); + } + + @Override + protected UIModeControlContainer createCenterPane() { + parameterPane = ModuleContext.isModuleStarted(Module.FORM_MODULE) ? new ParameterDefinitePane() : null; + centerPane = new UIModeControlContainer(parameterPane, reportComposite = new ReportComponentComposite(this)) { + @Override + protected void onModeChanged() { + refreshToolArea(); + } + + @Override + protected void onResize(int distance) { + if (hasParameterPane()) { + parameterPane.setDesignHeight(distance); + fireTargetModified(); + } + } + }; + + reportComposite.addTargetModifiedListener(new TargetModifiedListener() { + + @Override + public void targetModified(TargetModifiedEvent e) { + JWorkBook.this.fireTargetModified(); + } + }); + + reportComposite.setParentContainer(centerPane); + return centerPane; + } + + /** + * 判断sheet权限 + * + * @param rolsName 角色 + */ + public void judgeSheetAuthority(String rolsName) { + boolean isCovered = reportComposite.getEditingTemplateReport().getWorkSheetPrivilegeControl().checkInvisible(rolsName); + centerPane.setSheeetCovered(isCovered); + centerPane.refreshContainer(); + } + + /** + * 在编辑的面板是被参考的面板时,取消格式刷 + */ + public void doConditionCancelFormat() { + if (ComparatorUtils.equals(reportComposite.centerCardPane.editingComponet.elementCasePane, DesignerContext.getReferencedElementCasePane())) { + cancelFormat(); + } + } + + /** + * 无条件取消格式刷 + */ + public void cancelFormat() { + DesignerContext.setFormatState(DesignerContext.FORMAT_STATE_NULL); + reportComposite.centerCardPane.editingComponet.elementCasePane.getGrid().setCursor(UIConstants.CELL_DEFAULT_CURSOR); + ((ElementCasePane) DesignerContext.getReferencedElementCasePane()).getGrid().setCursor(UIConstants.CELL_DEFAULT_CURSOR); + ((ElementCasePane) DesignerContext.getReferencedElementCasePane()).getGrid().setNotShowingTableSelectPane(true); + DesignerContext.setReferencedElementCasePane(null); + DesignerContext.setReferencedIndex(0); + this.repaint(); + } + + public int getEditingReportIndex() { + return reportComposite.getEditingIndex(); + } + + /** + * 创建权限细粒度面板 + * + * @return 返回权限细粒度面板 + */ + public AuthorityEditPane createAuthorityEditPane() { + if (centerPane.isUpEditMode()) { + return parameterPane.getParaDesigner().getAuthorityEditPane(); + } else { + WorkSheetPrivilegeControl workSheetPrivilegeControl = reportComposite.getEditingTemplateReport().getWorkSheetPrivilegeControl(); + if (workSheetPrivilegeControl.checkInvisible(ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName())) { + SheetAuthorityEditPane sheetEditedPane = new SheetAuthorityEditPane(reportComposite.getEditingWorkBook(), this.getEditingReportIndex()); + sheetEditedPane.populateDetials(); + return sheetEditedPane; + } + return reportComposite.getEditingReportComponent().createAuthorityEditPane(); + } + + } + + public ToolBarMenuDockPlus getToolBarMenuDockPlus() { + if (this.getEditingElementCasePane() == null) { + return JWorkBook.this; + } + this.getEditingElementCasePane().getGrid().setEditable(!BaseUtils.isAuthorityEditing()); + centerPane.needToShowCoverAndHidPane(); + if (centerPane.isUpEditMode()) { + return parameterPane; + } else { + return JWorkBook.this; + } + } + + private boolean hasParameterPane() { + return parameterPane != null; + } + + /** + * + */ + public void setAutoHeightForCenterPane() { + centerPane.setUpPaneHeight(hasParameterPane() ? parameterPane.getPreferredSize().height : 0); + } + + @Override + /** + * + */ + public void setComposite() { + super.setComposite(); + reportComposite.setComponents(); + } + + public JPanel getEastUpPane() { + if (BaseUtils.isAuthorityEditing()) { + return allowAuthorityUpPane(); + } else { + return exitEastUpPane(); + } + } + + private JPanel allowAuthorityUpPane() { + //初始时显示不支持权限编辑的情况 + //1.编辑参数面板,参数面板什么也没有选中 + //2.在报表主体选中的聚合块不是报表聚合块,是图标聚合块 + boolean isParameterNotSuppportAuthority = centerPane.isUpEditMode() && !parameterPane.getParaDesigner().isSupportAuthority(); + boolean isReportNotSupportAuthority = reportComposite.getEditingReportComponent() instanceof PolyDesigner + && !((PolyDesigner) reportComposite.getEditingReportComponent()).isSelectedECBolck(); + WorkSheetPrivilegeControl workSheetPrivilegeControl = reportComposite.getEditingTemplateReport().getWorkSheetPrivilegeControl(); + if (!centerPane.isUpEditMode() && workSheetPrivilegeControl.checkInvisible(ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName())) { + AuthoritySheetEditedPane sheetEditedPane = new AuthoritySheetEditedPane(reportComposite.getEditingWorkBook(), this.getEditingReportIndex()); + sheetEditedPane.populate(); + return sheetEditedPane; + } + boolean isSelectedDownSupport = !centerPane.isUpEditMode() && isReportNotSupportAuthority; + if (isParameterNotSuppportAuthority || isSelectedDownSupport) { + return new NoSupportAuthorityEdit(); + } + + return new AuthorityPropertyPane(this); + } + + private JPanel exitEastUpPane() { + if (centerPane.isUpEditMode()) { + return parameterPane.getParaDesigner().getEastUpPane(); + } + if (delegate4ToolbarMenuAdapter() instanceof PolyDesigner) { + return ((PolyDesigner) delegate4ToolbarMenuAdapter()).getEastUpPane(); + } else { + ElementCasePane casePane = ((ReportComponent) delegate4ToolbarMenuAdapter()).elementCasePane; + if (casePane != null) { + return casePane.getEastUpPane(); + } + } + return new JPanel(); + } + + public JPanel getEastDownPane() { + if (centerPane.isUpEditMode()) { + return parameterPane.getParaDesigner().getEastDownPane(); + } + if (delegate4ToolbarMenuAdapter() instanceof PolyDesigner) { + if (((PolyDesigner) delegate4ToolbarMenuAdapter()).getSelectionType() == PolyDesigner.SelectionType.NONE) { + return new JPanel(); + } else { + return ((PolyDesigner) delegate4ToolbarMenuAdapter()).getEastDownPane(); + } + } else { + ElementCasePane casePane = ((ReportComponent) delegate4ToolbarMenuAdapter()).elementCasePane; + if (casePane != null) { + return casePane.getEastDownPane(); + } + } + return new JPanel(); + } + + /** + * 移除选择 + */ + public void removeTemplateSelection() { + this.reportComposite.removeSelection(); + } + + public void setSheetCovered(boolean isCovered) { + centerPane.setSheeetCovered(isCovered); + } + + /** + * 刷新容器 + */ + public void refreshContainer() { + centerPane.refreshContainer(); + } + + /** + * 移除参数面板选择 + */ + public void removeParameterPaneSelection() { + parameterPane.getParaDesigner().removeSelection(); + } + + public int getToolBarHeight() { + return TOOLBARPANEDIMHEIGHT; + } + + /** + * 更新报表参数属性 + */ + public void populateReportParameterAttr() { + if (hasParameterPane()) { + parameterPane.populate(this); + setAutoHeightForCenterPane(); + } + } + + /** + * 更新ReportParameterAttr + */ + public void updateReportParameterAttr() { + if (hasParameterPane()) { + ReportParameterAttr rpt = this.parameterPane.update(this.getTarget().getReportParameterAttr()); + this.getTarget().setReportParameterAttr(rpt); + } + } + + /** + * 检查提交按钮 + */ + public void checkHasSubmitButton() { + if (parameterPane != null) { + parameterPane.checkSubmitButton(); + } + } + + // //////////////////////////////////////////////////////// + // //////////////////////OLD BELOW///////////////////////// + // //////////////////////////////////////////////////////// + + @Override + /** + * set target + */ + public void setTarget(WorkBook book) { + if (book == null) { + return; + } + + if (book.getReportCount() == 0) { + book.addReport(new WorkSheet()); + } + + super.setTarget(book); + } + + private TargetComponent delegate4ToolbarMenuAdapter() { + return this.reportComposite.getEditingReportComponent(); + } + + /** + * 复制 + */ + public void copy() { + this.delegate4ToolbarMenuAdapter().copy(); + } + + /** + * 剪切 + * + * @return 剪切成功返回true + */ + public boolean cut() { + return this.delegate4ToolbarMenuAdapter().cut(); + } + + /** + * 黏贴 + * + * @return 黏贴成功返回true + */ + public boolean paste() { + return this.delegate4ToolbarMenuAdapter().paste(); + } + + /** + * 停止编辑 + */ + public void stopEditing() { + reportComposite.stopEditing(); + if (!this.isSaved()) { + this.updateReportParameterAttr(); + this.delegate4ToolbarMenuAdapter().stopEditing(); + } + } + + /** + * 后缀 + * + * @return 后缀的字符串 + */ + public String suffix() { + return ".cpt"; + } + + + // //////////////////////////////////////////////////////////////////// + // ////////////////for toolbarMenuAdapter////////////////////////////// + // //////////////////////////////////////////////////////////////////// + + /** + * 文件菜单的子菜单 + * + * @return 子菜单 + */ + public ShortCut[] shortcut4FileMenu() { + return (ShortCut[]) ArrayUtils.addAll( + super.shortcut4FileMenu(), + BaseUtils.isAuthorityEditing() || (FRContext.getCurrentEnv() instanceof RemoteEnv) ? new ShortCut[0] : new ShortCut[]{this.createWorkBookExportMenu()} + ); + } + + /** + * 目标的菜单 + * + * @return 菜单 + */ + public MenuDef[] menus4Target() { + return (MenuDef[]) ArrayUtils.addAll( + super.menus4Target(), this.delegate4ToolbarMenuAdapter().menus4Target() + ); + } + + public int getMenuState() { + return this.delegate4ToolbarMenuAdapter().getMenuState(); + } + + private MenuDef createWorkBookExportMenu() { + MenuDef excelExportMenuDef = new MenuDef(KeySetUtils.EXCEL_EXPORT.getMenuKeySetName(), KeySetUtils.EXCEL_EXPORT.getMnemonic()); + excelExportMenuDef.setIconPath("/com/fr/design/images/m_file/excel.png"); + excelExportMenuDef + .addShortCut(new PageExcelExportAction(this), new ExcelExportAction(this), new PageToSheetExcelExportAction(this)); + // Export - MenuDef + MenuDef exportMenuDef = new MenuDef(KeySetUtils.EXPORT.getMenuName()); + exportMenuDef.setIconPath("/com/fr/design/images/m_file/export.png"); + + exportMenuDef.addShortCut(excelExportMenuDef, new PDFExportAction(this), new WordExportAction(this), new SVGExportAction(this), + new CSVExportAction(this), new TextExportAction(this), new EmbeddedExportExportAction(this)); + + return exportMenuDef; + } + + /** + * 权限细粒度情况下的子菜单 + * + * @return 子菜单 + */ + public ShortCut[] shortCuts4Authority() { + return new ShortCut[]{ + new NameSeparator(Inter.getLocText(new String[]{"DashBoard-Potence", "Edit"})), + BaseUtils.isAuthorityEditing() ? new ExitAuthorityEditAction(this) : new AllowAuthorityEditAction(this), + }; + + } + + /** + * 模板的子菜单 + * + * @return 子菜单 + */ + public ShortCut[] shortcut4TemplateMenu() { + return (ShortCut[]) ArrayUtils.addAll(new ShortCut[]{ + new ReportWebAttrAction(this), + new ReportExportAttrAction(this), + new ReportParameterAction(this), + new NameSeparator(Inter.getLocText("Utils-Current_Sheet")), + }, this.reportComposite.getEditingReportComponent().shortcut4TemplateMenu()); + } + + /** + * 模板的工具 + * + * @return 工具 + */ + public ToolBarDef[] toolbars4Target() { + return this.delegate4ToolbarMenuAdapter().toolbars4Target(); + } + + @Override + protected WorkBookUndoState createUndoState() { + return new WorkBookUndoState( + this, + this.reportComposite.getSelectedIndex(), + this.reportComposite.getEditingReportComponent().createEditingState() + ); + } + + @Override + protected void applyUndoState(WorkBookUndoState u) { + try { + this.setTarget((WorkBook) u.getWorkBook().clone()); + if (!BaseUtils.isAuthorityEditing()) { + if (u.getAuthorityType() != BaseUndoState.NORMAL_STATE) { + applyAll(u); + this.undoState = u; + return; + } + if (centerPane.isUpEditMode()) { + if (hasParameterPane()) { + parameterPane.populate(u.getApplyTarget()); + DesignModuleFactory.getFormHierarchyPane().refreshRoot(); + } + } else { + reportComposite.setSelectedIndex(u.getSelectedReportIndex()); + u.getSelectedEditingState().revert(); + TableDataTreePane.getInstance(DesignModelAdapter.getCurrentModelAdapter()).refreshDockingView(); + } + this.undoState = u; + } else { + //参数面板 + applyAll(u); + this.authorityUndoState = u; + } + + } catch (CloneNotSupportedException e) { + throw new RuntimeException(e); + } + } + + private void applyAll(WorkBookUndoState u) { + if (hasParameterPane()) { + parameterPane.populate(u.getApplyTarget()); + DesignModuleFactory.getFormHierarchyPane().refreshRoot(); + } + //报表主体 + reportComposite.setSelectedIndex(u.getSelectedReportIndex()); + u.getSelectedEditingState().revert(); + TableDataTreePane.getInstance(DesignModelAdapter.getCurrentModelAdapter()).refreshDockingView(); + //如果是在权限编辑状态下,则有工具栏 + DesignerContext.getDesignerFrame().resetToolkitByPlus(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()); + } + + /** + * 请求焦点 + */ + public void requestFocus() { + super.requestFocus(); + ReportComponent reportComponent = reportComposite.getEditingReportComponent(); + reportComponent.requestFocus(); + } + + /** + * @return + */ + public final TemplateElementCase getEditingElementCase() { + return this.reportComposite.getEditingReportComponent().getEditingElementCasePane().getEditingElementCase(); + } + + /** + * 获取当前workBook中的正在编辑的component对应的elementCasePane + * + * @return + */ + public final ElementCasePane getEditingElementCasePane() { + return this.reportComposite.getEditingReportComponent().getEditingElementCasePane(); + } + + /** + * 刷新所有的控件 + */ + public void refreshAllNameWidgets() { + if (parameterPane != null) { + parameterPane.refreshAllNameWidgets(); + } + } + + /** + * 为数据集刷新参数面板 + * + * @param oldName 旧名字 + * @param newName 新名字 + */ + public void refreshParameterPane4TableData(String oldName, String newName) { + if (parameterPane != null) { + parameterPane.refresh4TableData(oldName, newName); + } + } + + /** + * 恢复 + */ + public void revert() { + ElementCasePane epane = reportComposite.getEditingReportComponent().elementCasePane; + if (epane == null) { + return; + } + if (delegate4ToolbarMenuAdapter() instanceof PolyDesigner) { + PolyDesigner polyDesigner = (PolyDesigner) delegate4ToolbarMenuAdapter(); + if (polyDesigner.getSelectionType() == PolyDesigner.SelectionType.NONE || polyDesigner.getSelection() == null) { + QuickEditorRegion.getInstance().populate(QuickEditor.DEFAULT_EDITOR); + } else { + QuickEditorRegion.getInstance().populate(epane.getCurrentEditor()); + } + } else { + QuickEditorRegion.getInstance().populate(epane.getCurrentEditor()); + } + CellElementPropertyPane.getInstance().populate(epane); + } + + @Override + protected WorkBookModelAdapter createDesignModel() { + return new WorkBookModelAdapter(this); + } + + /** + * 表单的工具栏 + * + * @return 表单工具栏 + */ + public JPanel[] toolbarPanes4Form() { + if (centerPane.isUpEditMode() && hasParameterPane()) { + return parameterPane.toolbarPanes4Form(); + } + return new JPanel[0]; + } + + /** + * 表单的工具按钮 + * + * @return 工具按钮 + */ + public JComponent[] toolBarButton4Form() { + centerPane.needToShowCoverAndHidPane(); + if (centerPane.isUpEditMode() && hasParameterPane()) { + return parameterPane.toolBarButton4Form(); + } else { + return this.delegate4ToolbarMenuAdapter().toolBarButton4Form(); + } + } + + /** + * 权限细粒度状态下的工具面板 + * + * @return 工具面板 + */ + public JComponent toolBar4Authority() { + return new AuthorityToolBarPane(); + } + + /** + * 是否支持预览 + * + * @return 预览接口 + * + */ + public PreviewProvider[] supportPreview() { + return (PreviewProvider[])ArrayUtils.addAll(new PreviewProvider[]{ + new PagePreview(), new WritePreview(), new ViewPreview() + }, ExtraDesignClassManager.getInstance().getPreviewProviders()); + } + + /** + * 预览菜单项 + * + * @return 预览菜单项 + */ + public UIMenuItem[] createMenuItem4Preview() { + List menuItems = new ArrayList(); + PreviewProvider[] previewProviders = supportPreview(); + for (final PreviewProvider provider : previewProviders) { + UIMenuItem item = new UIMenuItem(provider.nameForPopupItem(), BaseUtils.readIcon(provider.iconPathForPopupItem())); + item.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + provider.onClick(JWorkBook.this); + } + }); + menuItems.add(item); + } + return menuItems.toArray(new UIMenuItem[menuItems.size()]); + } + + /** + * 预览按钮点击事件 + * + * @param provider 预览接口 + */ + public void previewMenuActionPerformed(PreviewProvider provider) { + setPreviewType(provider); + WebPreviewUtils.actionPerformed(this, provider.parametersForPreview(), ParameterConsts.REPORTLET); + } + + /** + * 是不是模板 + * + * @return 是则返回true + */ + public boolean isJWorkBook() { + return true; + } + + public void setAuthorityMode(boolean isUpMode) { + centerPane.setAuthorityMode(isUpMode); + } + + /** + * 是不是正在编辑参数面板 + * + * @return 是则返回true + */ + public boolean isUpMode() { + return centerPane.isUpEditMode(); + } + + /** + * 刷新参数和工具区域 + */ + public void refreshToolArea() { + populateReportParameterAttr(); + if (centerPane.isUpEditMode()) { + if (hasParameterPane()) { + DesignerContext.getDesignerFrame().resetToolkitByPlus(parameterPane); + parameterPane.initBeforeUpEdit(); + } + } else { + DesignerContext.getDesignerFrame().resetToolkitByPlus(JWorkBook.this); + if (delegate4ToolbarMenuAdapter() instanceof PolyDesigner) { + PolyDesigner polyDesigner = (PolyDesigner) delegate4ToolbarMenuAdapter(); + if (polyDesigner.getSelectionType() == PolyDesigner.SelectionType.NONE || polyDesigner.getSelection() == null) { + EastRegionContainerPane.getInstance().replaceDownPane(new JPanel()); + QuickEditorRegion.getInstance().populate(QuickEditor.DEFAULT_EDITOR); + } else { + EastRegionContainerPane.getInstance().replaceDownPane(CellElementPropertyPane.getInstance()); + } + EastRegionContainerPane.getInstance().replaceUpPane(QuickEditorRegion.getInstance()); + } else { + ElementCasePane casePane = ((ReportComponent) delegate4ToolbarMenuAdapter()).elementCasePane; + if (casePane != null) { + casePane.fireSelectionChangeListener(); + } + } + } + if (BaseUtils.isAuthorityEditing()) { + EastRegionContainerPane.getInstance().replaceUpPane(allowAuthorityUpPane()); + EastRegionContainerPane.getInstance().replaceDownPane(RolesAlreadyEditedPane.getInstance()); + } + centerPane.needToShowCoverAndHidPane(); + } + + @Override + /** + * + */ + public Icon getPreviewLargeIcon() { + PreviewProvider provider = getPreviewType(); + String iconPath = provider.iconPathForLarge(); + return BaseUtils.readIcon(iconPath); + } + + /** + * 获取当前workBook的参数及默认值 + * 同名参数的话模板参数覆盖全局参数 + * + * @return + */ + public Parameter[] getParameters() { + Parameter[] ps = this.parameterPane.getParameterArray(); + Parameter[] curPs = this.parameterPane.getAllParameters(); + for (int i = 0; i < ps.length; i++) { + for (int j = 0; j < curPs.length; j++) { + if (ComparatorUtils.equals(ps[i].getName(), curPs[j].getName())) { + ps[i].setValue(curPs[j].getValue()); + } + } + } + return ps; + } + + /** + * 请求单元格区域的焦点 + */ + public void requestGridFocus() { + reportComposite.centerCardPane.requestGrifFocus(); + } + + + /** + * 创建内置sql提交的pane + * + * @return 内置sql提交的pane + * @date 2014-10-14-下午7:39:27 + */ + public DBManipulationPane createDBManipulationPane() { + ElementCasePane epane = this.getEditingElementCasePane(); + return new SmartInsertDBManipulationPane(epane); + } + + /** + * 创建控件事件里内置sql提交的pane + * + * @return 内置sql提交的pane + * @date 2014-10-14-下午7:39:27 + */ + public DBManipulationPane createDBManipulationPaneInWidget() { + ElementCasePane epane = this.getEditingElementCasePane(); + return new SmartInsertDBManipulationInWidgetEventPane(epane); + } + + public Icon getIcon() { + return BaseUtils.readIcon("/com/fr/design/images/buttonicon/newcpts.png"); + } + + /** + * 创建sheet名称tab面板 + * + * @param reportCompositeX 当前组件对象 + * @return sheet名称tab面板 + * @date 2015-2-5-上午11:42:12 + */ + public SheetNameTabPane createSheetNameTabPane(ReportComponentComposite reportCompositeX) { + return new SheetNameTabPane(reportCompositeX); + } + + /** + * 将模板另存为可以分享出去的混淆后内置数据集模板 + * + * @return 是否另存成功 + */ + public boolean saveShareFile() { + FILE newFile = createNewEmptyFile(); + //如果文件已经打开, 那么就覆盖关闭掉他 + MutilTempalteTabPane.getInstance().closeFileTemplate(newFile); + final TemplateWorkBook tpl = this.getTarget(); + // 弹出输入参数 + java.util.Map parameterMap = inputParameters(tpl); + + try { + String fullPath = StableUtils.pathJoin(FRContext.getCurrentEnv().getPath(), newFile.getPath()); + FileOutputStream fileOutputStream = new FileOutputStream(fullPath); + EmbeddedTableDataExporter exporter = new EmbeddedTableDataExporter(); + exporter.export(fileOutputStream, (WorkBook) tpl, parameterMap); + } catch (Exception e1) { + FRContext.getLogger().error(e1.getMessage()); + } + + //打开导出的内置模板 + DesignerContext.getDesignerFrame().openTemplate(newFile); + return true; + } + + //创建新的空白模板 + private FILE createNewEmptyFile() { + String oldName = this.getEditingFILE().getName(); + oldName = oldName.replaceAll(ProjectConstants.CPT_SUFFIX, StringUtils.EMPTY); + String shareFileName = oldName + SHARE_SUFFIX; + String newFilePath = StableUtils.pathJoin(ProjectConstants.REPORTLETS_NAME, SHARE_FOLDER, shareFileName, shareFileName + ProjectConstants.CPT_SUFFIX); + FileNode node = new FileNode(newFilePath, false); + + FileNodeFILE newFile = new FileNodeFILE(node); + mkNewFile(newFile); + + return newFile; + } + + //输入导出内置数据集需要的参数 + private Map inputParameters(final TemplateWorkBook tpl) { + final java.util.Map parameterMap = new java.util.HashMap(); + DesignerFrame designerFrame = DesignerContext.getDesignerFrame(); + Parameter[] parameters = tpl.getParameters(); + if (!ArrayUtils.isEmpty(parameters)) {// 检查Parameter. + final ParameterInputPane pPane = new ParameterInputPane( + parameters); + pPane.showSmallWindow(designerFrame, new DialogActionAdapter() { + + @Override + public void doOk() { + parameterMap.putAll(pPane.update()); + } + }).setVisible(true); + } + + return parameterMap; + } + + /** + * 创建分享模板的按钮, 目前只有jworkbook实现了 + * + * @return 分享模板按钮 + */ + public UIButton[] createShareButton() { + return new UIButton[0]; + //产品想要重新设计下, 1现在的分享多列数据集很麻烦, 2想做成自动上传附件. +// return new UIButton[]{new ShareButton()}; + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/PolySheetNameTabPane.java b/designer/src/com/fr/design/mainframe/PolySheetNameTabPane.java new file mode 100644 index 000000000..68ced8beb --- /dev/null +++ b/designer/src/com/fr/design/mainframe/PolySheetNameTabPane.java @@ -0,0 +1,35 @@ +package com.fr.design.mainframe; + +import java.awt.Graphics2D; + +import com.fr.design.menu.MenuDef; + + +/** + * 获取 + * + * @date 2015-2-5-上午10:19:17 + * + */ +public class PolySheetNameTabPane extends SheetNameTabPane{ + + /** + * 构造函数 + */ + public PolySheetNameTabPane(ReportComponentComposite reportCompositeX) { + super(reportCompositeX); + } + + protected void paintAddButton(Graphics2D g2d){ + ADD_POLY_SHEET.paintIcon(this, g2d, iconLocation, 3); + } + + + protected void firstInsertActionPerformed(){ + new PolyReportInsertAction().actionPerformed(null); + } + + + protected void addInsertGridShortCut(MenuDef def){ + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/RGridLayout.java b/designer/src/com/fr/design/mainframe/RGridLayout.java new file mode 100644 index 000000000..4b4ae6abd --- /dev/null +++ b/designer/src/com/fr/design/mainframe/RGridLayout.java @@ -0,0 +1,157 @@ +package com.fr.design.mainframe; + +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Insets; +import java.awt.LayoutManager; + +/**custom the layout used in Finereport + */ +public class RGridLayout implements LayoutManager, java.io.Serializable { + public static final String GridCorner = "GridCorner"; + public static final String GridColumn = "GridColumn"; + public static final String GridRow = "GridRow"; + public static final String Grid = "Grid"; + + public static final String HorizontalBar = "HorizontalBar"; + public static final String VerticalBar = "VerticalBar"; + + protected Component gridCorner; + protected Component gridColumn; + protected Component gridRow; + protected Component grid; + + protected Component horizontalBar; + protected Component verticalBar; + + /** + * Constructs a new border layout with + * no gaps between components. + */ + public RGridLayout() { + } + + /** + */ + public void addLayoutComponent(String name, Component comp) { + if (RGridLayout.GridCorner.equals(name)) { + this.gridCorner = comp; + } else if (RGridLayout.GridColumn.equals(name)) { + this.gridColumn = comp; + } else if (RGridLayout.GridRow.equals(name)) { + this.gridRow = comp; + } else if (RGridLayout.Grid.equals(name)) { + this.grid = comp; + + //滚动条 + } else if (RGridLayout.HorizontalBar.equals(name)) { + this.horizontalBar = comp; + } else if (RGridLayout.VerticalBar.equals(name)) { + this.verticalBar = comp; + } + } + + /** + */ + public void removeLayoutComponent(Component comp) { + } + + /** + */ + public Dimension minimumLayoutSize(Container target) { + synchronized (target.getTreeLock()) { + Dimension dim = new Dimension(0, 0); + + Dimension gridRowMinimumSize = this.gridRow.getMaximumSize(); + Dimension gridColumnMinimumSize = this.gridColumn.getMaximumSize(); + Dimension gridMinimumSize = this.grid.getMaximumSize(); + Dimension verScrollBarMinimumSize = this.verticalBar.getMaximumSize(); + Dimension horScrollBarMinimumSize = this.horizontalBar.getMaximumSize(); + + //调整高度. + dim.width += gridRowMinimumSize.width + gridMinimumSize.width + + verScrollBarMinimumSize.width; + dim.height = gridColumnMinimumSize.height + gridMinimumSize.height + + horScrollBarMinimumSize.height; + + Insets insets = target.getInsets(); + dim.width += insets.left + insets.right; + dim.height += insets.top + insets.bottom; + + return dim; + } + } + + /** + */ + public Dimension preferredLayoutSize(Container target) { + synchronized (target.getTreeLock()) { + Dimension dim = new Dimension(0, 0); + + Dimension gridRowPreferredSize = this.gridRow.getPreferredSize(); + Dimension gridColumnPreferredSize = this.gridColumn.getPreferredSize(); + Dimension gridPreferredSize = this.grid.getPreferredSize(); + Dimension verScrollBarPreferredSize = this.verticalBar.getPreferredSize(); + Dimension horScrollBarPreferredSize = this.horizontalBar.getPreferredSize(); + + //调整高度. + dim.width += gridRowPreferredSize.width + gridPreferredSize.width + + verScrollBarPreferredSize.width; + dim.height = gridColumnPreferredSize.height + gridPreferredSize.height + + horScrollBarPreferredSize.height; + + Insets insets = target.getInsets(); + dim.width += insets.left + insets.right; + dim.height += insets.top + insets.bottom; + + return dim; + } + } + + /** + */ + public void layoutContainer(Container target) { + synchronized (target.getTreeLock()) { + Insets insets = target.getInsets(); + int top = insets.top; + int bottom = target.getHeight() - insets.bottom; + int left = insets.left; + int right = target.getWidth() - insets.right; + + Dimension gridRowPreferredSize = this.gridRow.getPreferredSize(); + Dimension gridColumnPreferredSize = this.gridColumn.getPreferredSize(); + Dimension verScrollBarPreferredSize = this.verticalBar.getPreferredSize(); +// Dimension horScrollBarPreferredSize = this.horizontalBar.getPreferredSize(); + + this.gridCorner.setBounds(left, top, + gridRowPreferredSize.width, gridColumnPreferredSize.height); + + //处理滚动条. + this.verticalBar.setBounds(right - verScrollBarPreferredSize.width, 0, + verScrollBarPreferredSize.width, bottom ); +// this.horizontalBar.setBounds(0, bottom - horScrollBarPreferredSize.height, +// right - verScrollBarPreferredSize.width, horScrollBarPreferredSize.height); + + //处理列和行 + this.gridColumn.setBounds(left + gridRowPreferredSize.width, top, + right - gridRowPreferredSize.width - verScrollBarPreferredSize.width, + gridColumnPreferredSize.height); + this.gridRow.setBounds(left, top + gridColumnPreferredSize.height, + gridRowPreferredSize.width, + bottom - gridColumnPreferredSize.height ); + + //Grid + this.grid.setBounds(left + gridRowPreferredSize.width, top + gridColumnPreferredSize.height, + right - gridRowPreferredSize.width - verScrollBarPreferredSize.width, + bottom - gridColumnPreferredSize.height); + } + } + + /** + */ + @Override + public String toString() { + return getClass().getName(); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/ReportComponent.java b/designer/src/com/fr/design/mainframe/ReportComponent.java new file mode 100644 index 000000000..6ca268545 --- /dev/null +++ b/designer/src/com/fr/design/mainframe/ReportComponent.java @@ -0,0 +1,76 @@ +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.mainframe; + +import javax.swing.JScrollBar; + +import com.fr.base.BaseUtils; +import com.fr.design.actions.AllowAuthorityEditAction; +import com.fr.design.actions.ExitAuthorityEditAction; +import com.fr.design.actions.report.ReportBackgroundAction; +import com.fr.design.actions.report.ReportFooterAction; +import com.fr.design.actions.report.ReportHeaderAction; +import com.fr.design.actions.report.ReportPageSetupAction; +import com.fr.design.designer.TargetComponent; +import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus; +import com.fr.design.menu.NameSeparator; +import com.fr.design.menu.ShortCut; +import com.fr.general.Inter; +import com.fr.report.report.TemplateReport; +import com.fr.design.selection.SelectableElement; +import com.fr.design.selection.Selectedable; + +/** + * @author richer + * @since 6.5.4 创建于2011-4-19 报表编辑面板 + */ +public abstract class ReportComponent extends TargetComponent implements Selectedable { + protected E elementCasePane; + public E getEditingElementCasePane() { + return elementCasePane; + } + public ReportComponent(T t) { + super(t); + } + + // TODO ALEX_SEP 这个方法有没有可能删掉 + public T getTemplateReport() { + return this.getTarget(); + } + public abstract JScrollBar getHorizontalScrollBar(); + + public abstract JScrollBar getVerticalScrollBar(); + + public abstract S getDefaultSelectElement(); + + + @Override + public ShortCut[] shortcut4TemplateMenu() { + return new ShortCut[]{ + new ReportPageSetupAction(this), + new ReportHeaderAction(this), + new ReportFooterAction(this), + new ReportBackgroundAction(this), + }; + } + + public void cancelFormat() { + return; + } + + + public ShortCut[] shortCuts4Authority() { + return new ShortCut[]{ + new NameSeparator(Inter.getLocText(new String[]{"DashBoard-Potence", "Edit"})), + BaseUtils.isAuthorityEditing() ? new ExitAuthorityEditAction(this) : new AllowAuthorityEditAction(this), + }; + + } + + + public ToolBarMenuDockPlus getToolBarMenuDockPlus() { + return new JWorkBook(); + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/ReportComponentCardPane.java b/designer/src/com/fr/design/mainframe/ReportComponentCardPane.java new file mode 100644 index 000000000..54c7f7657 --- /dev/null +++ b/designer/src/com/fr/design/mainframe/ReportComponentCardPane.java @@ -0,0 +1,140 @@ +package com.fr.design.mainframe; + +import java.awt.CardLayout; + +import javax.swing.JComponent; + +import com.fr.base.BaseUtils; +import com.fr.design.event.TargetModifiedEvent; +import com.fr.design.event.TargetModifiedListener; +import com.fr.design.file.HistoryTemplateListPane; +import com.fr.design.roleAuthority.ReportAndFSManagePane; +import com.fr.poly.PolyDesigner; +import com.fr.report.poly.PolyWorkSheet; +import com.fr.report.report.TemplateReport; +import com.fr.report.worksheet.WorkSheet; + +/** + * 中间的整个报表编辑区域 + * + * @editor zhou + * @since 2012-3-27下午12:12:11 + */ +public class ReportComponentCardPane extends JComponent implements TargetModifiedListener { + protected ReportComponent editingComponet; + + private CardLayout cl; + private WorkSheetDesigner sheetDezi; + private PolyDesigner polyDezi; + + public ReportComponentCardPane() { + this.setLayout(cl = new CardLayout()); + } + + public void requestGrifFocus() { + if (sheetDezi != null) { + sheetDezi.requestFocus(); + } + } + + protected void stopEditing() { + if (editingComponet != null) { + editingComponet.stopEditing(); + } + } + + protected boolean cut() { + if (editingComponet != null) { + return editingComponet.cut(); + } + + return false; + } + + protected void copy() { + if (editingComponet != null) { + editingComponet.copy(); + } + } + + protected boolean paste() { + if (editingComponet != null) { + return editingComponet.paste(); + } + + return false; + } + + // TODO ALEX_SEP 期望与TargetComponent那边合并,或者减少与JWorkBook之间的层次 + private java.util.List targetModifiedList = new java.util.ArrayList(); + + /** + * 添加 TargetModifiedListener + * + * @param l TargetModifiedListener + */ + public void addTargetModifiedListener(TargetModifiedListener l) { + targetModifiedList.add(l); + } + + /** + * Invoked when the target of the listener has changed the rpt content. + * + * @param e + */ + @Override + public void targetModified(TargetModifiedEvent e) { + for (TargetModifiedListener l : targetModifiedList) { + l.targetModified(e); + } + } + + protected void showJWorkSheet(WorkSheet sheet) { + if (sheetDezi == null) { + sheetDezi = new WorkSheetDesigner(sheet); + this.add(sheetDezi, "WS"); + sheetDezi.addTargetModifiedListener(this); + } else { + sheetDezi.setTarget(sheet); + } + cl.show(this, "WS"); + editingComponet = sheetDezi; + } + + protected void showPoly(PolyWorkSheet sheet) { + if (polyDezi == null) { + polyDezi = new PolyDesigner(sheet); + this.add(polyDezi, "PL"); + polyDezi.addTargetModifiedListener(this); + } else { + polyDezi.setTarget(sheet); + } + + cl.show(this, "PL"); + editingComponet = polyDezi; + } + + + protected void populate(TemplateReport tpl) { + if (tpl instanceof WorkSheet) { + showJWorkSheet((WorkSheet) tpl); + } else if (tpl instanceof PolyWorkSheet) { + showPoly((PolyWorkSheet) tpl); + } + if (BaseUtils.isAuthorityEditing()) { + JTemplate editingTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); + String selectedRoles = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); + editingTemplate.setSheetCovered(tpl.getWorkSheetPrivilegeControl().checkInvisible(selectedRoles)); + } + } + + protected TemplateReport update() { + if (polyDezi != null && polyDezi.isVisible()) { + return polyDezi.getTarget(); + } else if (sheetDezi != null && sheetDezi.isVisible()) { + return sheetDezi.getTarget(); + } + + return null; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/ReportComponentComposite.java b/designer/src/com/fr/design/mainframe/ReportComponentComposite.java new file mode 100644 index 000000000..533de694a --- /dev/null +++ b/designer/src/com/fr/design/mainframe/ReportComponentComposite.java @@ -0,0 +1,190 @@ +package com.fr.design.mainframe; + +import java.awt.BorderLayout; +import java.util.ArrayList; + +import javax.swing.JComponent; +import javax.swing.JPanel; +import javax.swing.JSplitPane; + +import com.fr.base.FRContext; +import com.fr.design.designer.EditingState; +import com.fr.design.event.TargetModifiedListener; +import com.fr.design.gui.icontainer.UIModeControlContainer; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.general.Inter; +import com.fr.grid.Grid; +import com.fr.main.impl.WorkBook; +import com.fr.report.report.TemplateReport; + +/** + * 整个报表编辑区域 包括滚动条、中间的grid或者聚合块、下面的sheetTab + * + * @editor zhou + * @since 2012-3-27下午12:12:05 + */ +public class ReportComponentComposite extends JComponent { + private JWorkBook parent; + private UIModeControlContainer parentContainer = null; + + protected ReportComponentCardPane centerCardPane; + private JPanel CellElementRegion; + + private java.util.List templateStateList = new ArrayList(); + + private SheetNameTabPane sheetNameTab; + + private JPanel hbarContainer; + + + /** + * Constructor with workbook.. + * + * @param workBook the current workbook. + */ + public ReportComponentComposite(JWorkBook jwb) { + this.parent = jwb; + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + this.add(centerCardPane = new ReportComponentCardPane(), BorderLayout.CENTER); + sheetNameTab = jwb.createSheetNameTabPane(this); + sheetNameTab.setSelectedIndex(0); + CellElementRegion = FRGUIPaneFactory.createBorderLayout_S_Pane(); + this.add(CellElementRegion, BorderLayout.NORTH); + this.add(createSouthControlPane(), BorderLayout.SOUTH); + } + + protected void doBeforeChange(int oldIndex) { + if (oldIndex >= 0) { + templateStateList.set(oldIndex, centerCardPane.editingComponet.createEditingState()); + } + } + + protected void doAfterChange(int newIndex) { + WorkBook workbook = getEditingWorkBook(); + if (workbook == null) { + FRContext.getLogger().error(Inter.getLocText("Read_failure") + "!"); + //AUGUST:加个报错,不然测试总是SB的认为打不开一个坏的excel文件就是BUG,也不知道去检查下源文件。 + return; + } + centerCardPane.populate(workbook.getTemplateReport(newIndex)); + if (parentContainer != null) { + parentContainer.setDownPane(ReportComponentComposite.this); + } + + if (templateStateList.size() > newIndex) { + EditingState reportPaneEditState = templateStateList.get(newIndex); + if (reportPaneEditState != null) { + reportPaneEditState.revert(); + } + } else { + while (templateStateList.size() <= newIndex) { + templateStateList.add(null); + } + centerCardPane.editingComponet.setSelection(centerCardPane.editingComponet.getDefaultSelectElement()); + } + + if (centerCardPane.editingComponet.elementCasePane == null) { + return; + } + Grid grid = centerCardPane.editingComponet.elementCasePane.getGrid(); + + if (!grid.hasFocus() && grid.isRequestFocusEnabled()) { + grid.requestFocus(); + } + } + + /** + * 移除选中状态 + * + * @date 2015-2-5-上午11:41:44 + * + */ + public void removeSelection() { + if (centerCardPane.editingComponet instanceof WorkSheetDesigner) { + ((WorkSheetDesigner) centerCardPane.editingComponet).removeSelection(); + } else { + centerCardPane.populate(centerCardPane.editingComponet.getTemplateReport()); + } + + } + + public TemplateReport getEditingTemplateReport() { + return centerCardPane.editingComponet.getTemplateReport(); + } + + public int getEditingIndex() { + return sheetNameTab.getSelectedIndex(); + } + + + public void setParentContainer(UIModeControlContainer parentContainer) { + this.parentContainer = parentContainer; + } + + + public void setComponents() { + CellElementRegion.removeAll(); + hbarContainer.removeAll(); + hbarContainer.add(centerCardPane.editingComponet.getHorizontalScrollBar()); + centerCardPane.editingComponet.getHorizontalScrollBar().setValue(centerCardPane.editingComponet.getHorizontalScrollBar().getValue()); + centerCardPane.editingComponet.getVerticalScrollBar().setValue(centerCardPane.editingComponet.getVerticalScrollBar().getValue()); + this.doLayout(); + } + + public int getSelectedIndex() { + return sheetNameTab.getSelectedIndex(); + } + + protected ReportComponent getEditingReportComponent() { + return this.centerCardPane.editingComponet; + } + + protected WorkBook getEditingWorkBook() { + return this.parent.getTarget(); + } + + /** + * 添加目标改变的监听 + * + * @param targetModifiedListener 对象修改监听器 + */ + public void addTargetModifiedListener(TargetModifiedListener targetModifiedListener) { + this.centerCardPane.addTargetModifiedListener(targetModifiedListener); + } + + private JComponent createSouthControlPane() { + hbarContainer = FRGUIPaneFactory.createBorderLayout_S_Pane(); + hbarContainer.add(centerCardPane.editingComponet.getHorizontalScrollBar()); + JSplitPane splitpane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sheetNameTab, hbarContainer); + splitpane.setBorder(null); + splitpane.setDividerSize(3); + splitpane.setResizeWeight(0.6); + return splitpane; + } + + public void setSelectedIndex(int selectedIndex) { + sheetNameTab.setSelectedIndex(selectedIndex); + centerCardPane.populate(getEditingWorkBook().getTemplateReport(selectedIndex)); + } + + /** + * 停止编辑 + */ + public void stopEditing() { + centerCardPane.stopEditing(); + } + + public void setComposite() { + DesignerContext.getDesignerFrame().resetToolkitByPlus(parent); + parent.setComposite(); + this.validate(); + this.repaint(40); + } + + /** + * 模板更新 + */ + public void fireTargetModified() { + parent.fireTargetModified(); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/SheetAuthorityEditPane.java b/designer/src/com/fr/design/mainframe/SheetAuthorityEditPane.java new file mode 100644 index 000000000..c6ed73719 --- /dev/null +++ b/designer/src/com/fr/design/mainframe/SheetAuthorityEditPane.java @@ -0,0 +1,169 @@ +package com.fr.design.mainframe; + +import com.fr.design.constants.LayoutConstants; +import com.fr.design.file.HistoryTemplateListPane; +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.roleAuthority.ReportAndFSManagePane; +import com.fr.design.roleAuthority.RolesAlreadyEditedPane; +import com.fr.general.ComparatorUtils; +import com.fr.general.Inter; +import com.fr.main.impl.WorkBook; +import com.fr.privilege.finegrain.WorkSheetPrivilegeControl; +import com.fr.report.worksheet.WorkSheet; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; + +/** + * Created by IntelliJ IDEA. + * Author : daisy + * Version: 6.5.6 + * Date: 14-1-17 + * Time: 上午10:56 + */ +public class SheetAuthorityEditPane extends AuthorityEditPane { + private static final int TOP_GAP = 11; + private static final int LEFT_GAP = 8; + private static final int ALIGNMENT_GAP = -3; + + private UICheckBox sheetVisible = new UICheckBox(Inter.getLocText("Widget-Visible")); + private WorkBook workBook = null; + private int selectedIndex = -1; + + private ItemListener itemListener = new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + String selectedRole = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); + if (ComparatorUtils.equals(selectedRole, Inter.getLocText("Role"))) { + return; + } + if (selectedRole == null) { + return; + } + + WorkSheetPrivilegeControl wpc = workBook.getTemplateReport(selectedIndex) + .getWorkSheetPrivilegeControl(); + if (sheetVisible.isSelected()) { + wpc.removeInvisibleRole(selectedRole); + } else { + wpc.addInvisibleRole(selectedRole); + } + JTemplate editingTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); + editingTemplate.setSheetCovered(!sheetVisible.isSelected()); + editingTemplate.fireTargetModified(); + editingTemplate.refreshContainer(); + RolesAlreadyEditedPane.getInstance().refreshDockingView(); + } + }; + + + public SheetAuthorityEditPane(WorkBook editingWorkBook, int selectedIndex) { + super(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()); + setLayout(new BorderLayout()); + type = new UILabel(); + name = new UILabel(); + checkPane = new JPanel(); + checkPane.setLayout(new BorderLayout()); + this.add(layoutText(), BorderLayout.WEST); + this.add(layoutPane(), BorderLayout.CENTER); + this.setBorder(BorderFactory.createEmptyBorder(TOP_GAP, LEFT_GAP, 0, 0)); + this.workBook = editingWorkBook; + sheetVisible.addItemListener(itemListener); + this.selectedIndex = selectedIndex; + } + + + private JPanel layoutText() { + double p = TableLayout.PREFERRED; + Component[][] components = new Component[][]{ + new Component[]{new UILabel(Inter.getLocText("Type") + ":", SwingConstants.RIGHT)}, + new Component[]{new UILabel(Inter.getLocText("WF-Name") + ":", SwingConstants.RIGHT)}, + new Component[]{new UILabel(Inter.getLocText("DashBoard-Potence") + ":", SwingConstants.RIGHT)}, + }; + double[] rowSize = {p, p, p}; + double[] columnSize = {p}; + int[][] rowCount = {{1}, {1}, {1}}; + return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); + } + + + private JPanel layoutPane() { + double f = TableLayout.FILL; + double p = TableLayout.PREFERRED; + Component[][] components = new Component[][]{ + new Component[]{type}, + new Component[]{name}, + new Component[]{checkPane}, + }; + double[] rowSize = {p, p, p}; + double[] columnSize = {f}; + int[][] rowCount = {{1}, {1}, {1}}; + return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); + } + + + /** + * 更新权限编辑面板的具体内容:类型、名称、权限面板 + */ + public void populateDetials() { + if (workBook.getTemplateReport(selectedIndex) instanceof WorkSheet) { + ((WorkSheet) workBook.getTemplateReport(selectedIndex)).setPaintSelection(false); + } + populateName(); + populateType(); + checkPane.removeAll(); + if (name.getText() == "") { + return; + } + checkPane.add(populateCheckPane(), BorderLayout.CENTER); + checkPane.setBorder(BorderFactory.createEmptyBorder(ALIGNMENT_GAP, 0, 0, 0)); + checkVisibleCheckBoxes(); + } + + /** + * 刷新类型 + */ + public void populateType() { + type.setText("sheet"); + } + + /** + * 更新名字 + */ + public void populateName() { + name.setText(workBook.getReportName(selectedIndex)); + } + + /** + * 更新复选框面板 + * + * @return 返回面板 + */ + public JPanel populateCheckPane() { + double f = TableLayout.FILL; + double p = TableLayout.PREFERRED; + Component[][] components = new Component[][]{ + new Component[]{sheetVisible}, + }; + double[] rowSize = {p}; + double[] columnSize = {f}; + int[][] rowCount = {{1}}; + return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); + } + + private void checkVisibleCheckBoxes() { + sheetVisible.removeItemListener(itemListener); + String selected = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); + if (selected == null) { + sheetVisible.setSelected(true); + } + sheetVisible.setSelected(!workBook.getTemplateReport(selectedIndex).getWorkSheetPrivilegeControl().checkInvisible(selected)); + sheetVisible.addItemListener(itemListener); + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/SheetNameTabPane.java b/designer/src/com/fr/design/mainframe/SheetNameTabPane.java new file mode 100644 index 000000000..350cf9a09 --- /dev/null +++ b/designer/src/com/fr/design/mainframe/SheetNameTabPane.java @@ -0,0 +1,933 @@ +package com.fr.design.mainframe; + +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.awt.geom.GeneralPath; +import java.awt.geom.Path2D; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.Icon; +import javax.swing.JComponent; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JPopupMenu; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; + +import com.fr.base.BaseUtils; +import com.fr.base.GraphHelper; +import com.fr.design.actions.UpdateAction; +import com.fr.design.constants.UIConstants; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.menu.MenuDef; +import com.fr.design.menu.SeparatorDef; +import com.fr.design.roleAuthority.ReportAndFSManagePane; +import com.fr.design.roleAuthority.RolesAlreadyEditedPane; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.general.ComparatorUtils; +import com.fr.general.Inter; +import com.fr.main.impl.WorkBook; +import com.fr.poly.PolyDesigner; +import com.fr.report.poly.PolyWorkSheet; +import com.fr.report.report.TemplateReport; +import com.fr.report.worksheet.WorkSheet; +import com.fr.stable.ProductConstants; + +/** + * NameTabPane of sheets + * + * @editor zhou + * @since 2012-3-26下午1:45:53 + */ +public class SheetNameTabPane extends JComponent implements MouseListener, MouseMotionListener { + + private static final Color LINE_COLOR = new Color(0xababab); + + private static final Icon ADD_WORK_SHEET = BaseUtils.readIcon("com/fr/base/images/oem/addworksheet.png"); + protected static final Icon ADD_POLY_SHEET = BaseUtils.readIcon("com/fr/design/images/sheet/addpolysheet.png"); + private static final Icon WORK_SHEET_ICON = BaseUtils.readIcon("com/fr/base/images/oem/worksheet.png"); + private static final Icon POLY_SHEET_ICON = BaseUtils.readIcon("com/fr/design/images/sheet/polysheet.png"); + private static final Image DESIGN_IMAGE = BaseUtils.readImage("com/fr/design/images/sheet/left_right_btn.png"); + private static final Icon LEFT_ICON = BaseUtils.createIcon(DESIGN_IMAGE, 0, 0, 14, 14); + private static final Icon RIGHT_ICON = BaseUtils.createIcon(DESIGN_IMAGE, 14, 0, 14, 14); + private static final Icon DISABLED_LEFT_ICON = BaseUtils.createIcon(DESIGN_IMAGE, 0, 14, 14, 14); + private static final Icon DISABLED_RIGHT_ICON = BaseUtils.createIcon(DESIGN_IMAGE, 14, 14, 14, 14); + + private static final int ICON_SEP_DISTANCE = 8; + private static final int TOOLBAR_HEIGHT = 16; + private static final int ADD_WIDTH_BY_SHEETNAME = 20; //sheet名字的文本到图标边框的距离 + private static final int GRID_TOSHEET_RIGHT = 20; // 添加grid按钮右侧距sheet面板右侧的距离 + private static final int POLY_TOSHEET_LEFT = 30; // 添加poly按钮左侧距sheet面板右侧的距离 + private static final int POLY_TOSHEET_RIGHT = 50; // 添加poly按钮右侧距sheet面板右侧的距离 + private static final int SHEET_ICON_GAP = 5; // 每个sheet图标之间的距离 + + private static final int GRAP = 12; // 给两个添加按钮与其他组件预留的间隔 + private static final int LEFT_CORNOR = 0;// 左角落. + private static final int RIGHT_CORNOR = 0;// 右角落 + + /** + * 左移和右移按钮 + */ + private UIButton leftButton; + private UIButton rightButton; + /** + * 鼠标按下时的坐标数组、鼠标放开时的坐标数组 + */ + private int[] xyPressedCoordinate = {0, 0}; + private int[] xyReleasedCoordinate = {0, 0}; + + /** + * 保存每个workSheet的宽度. + */ + private int[] widthArray; + + /** + * 这个数组用来记录鼠标drag过的区域里面的点. + */ + private List lineArray = new ArrayList(); + + /** + * 鼠标是否已经释放 + */ + private boolean isReleased = false; + + /** + * 是否越界 + */ + private boolean isOvertakeWidth = false; + + /** + * 能显示的tab个数 + */ + private int showCount = 0; + + /** + * 两个添加图标的位置。 + */ + protected int iconLocation; + + /** + * august: 当sheet的数量过多了,scrollIndex就有用了,用来表示最左边的sheet的Index + */ + private int scrollIndex = 0; + + /** + * 当超过最大宽度时,最右边的sheet的index + */ + private int lastOneIndex; + + /** + * 编辑的对象实例 + */ + private ReportComponentComposite reportComposite; + + private int selectedIndex = -1; + + private JPanel buttonPane; + + private boolean isAuthorityEditing = false; + + public SheetNameTabPane(ReportComponentComposite reportCompositeX) { + this.reportComposite = reportCompositeX; + this.setLayout(new BorderLayout(0, 0)); + this.addMouseListener(this); + this.addMouseMotionListener(this); + this.setBorder(null); + this.setForeground(new Color(99, 99, 99)); + leftButton = new UIButton(LEFT_ICON) { + public Dimension getPreferredSize() { + return new Dimension(super.getPreferredSize().width, TOOLBAR_HEIGHT); + } + }; + leftButton.set4ToolbarButton(); + leftButton.setDisabledIcon(DISABLED_LEFT_ICON); + rightButton = new UIButton(RIGHT_ICON) { + public Dimension getPreferredSize() { + return new Dimension(super.getPreferredSize().width, TOOLBAR_HEIGHT); + } + }; + rightButton.set4ToolbarButton(); + rightButton.setDisabledIcon(DISABLED_RIGHT_ICON); + buttonPane = new JPanel(new BorderLayout(3, 0)); + buttonPane.add(rightButton, BorderLayout.EAST); + buttonPane.add(leftButton, BorderLayout.CENTER); + this.add(buttonPane, BorderLayout.EAST); + leftButton.addActionListener(createLeftButtonActionListener()); + rightButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + int reportCount = reportComposite.getEditingWorkBook().getReportCount(); + if (selectedIndex <= (reportCount - 1) && scrollIndex < reportCount - showCount) { + scrollIndex = Math.min((showCount == 0 ? 1 : showCount) + scrollIndex, reportCount - showCount - 1); + repaint(); + } + } + }); + + } + + private ActionListener createLeftButtonActionListener() { + return new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + int s = scrollIndex; + if (s == lastOneIndex && s != 0) { + scrollIndex--; + lastOneIndex--; + repaint(); + } else { + while (s > lastOneIndex && showCount != 0) { + scrollIndex++; + lastOneIndex++; + repaint(); + } + while (s < lastOneIndex && scrollIndex > 0) { + scrollIndex--; + lastOneIndex--; + repaint(); + } + } + } + }; + } + + /** + * 设置选择index + * + * @param newIndex + */ + public void setSelectedIndex(int newIndex) { + doBeforeChange(selectedIndex); + selectedIndex = newIndex; + doAfterChange(newIndex); + } + + /** + * 在权限细粒度状态下,点击sheet,进入编辑sheet可见不可见状态 + */ + private void doWithAuthority() { + AuthoritySheetEditedPane sheetEditedPane = new AuthoritySheetEditedPane(reportComposite.getEditingWorkBook(), selectedIndex); + sheetEditedPane.populate(); + EastRegionContainerPane.getInstance().replaceUpPane(sheetEditedPane); + EastRegionContainerPane.getInstance().replaceDownPane(RolesAlreadyEditedPane.getInstance()); + } + + + /** + * /** + * selectedIndex 改变之前所做的事情 + * + * @param oldIndex + */ + protected void doBeforeChange(int oldIndex) { + reportComposite.doBeforeChange(oldIndex); + } + + /** + * selectedIndex 改变之后所做的事情 + * + * @param newIndex + */ + protected void doAfterChange(int newIndex) { + reportComposite.doAfterChange(newIndex); + } + + /** + * 得到选择的index + * + * @return + */ + public int getSelectedIndex() { + return selectedIndex; + } + + /** + * 鼠标拖拽 + * + * @param e 鼠标事件 + */ + public void mouseDragged(MouseEvent e) { + if (isAuthorityEditing) { + return; + } + lineArray.add(e.getPoint()); + repaint(); + } + + /** + * 鼠标移动 + * + * @param e 鼠标事件 + */ + public void mouseMoved(MouseEvent e) { + } + + private void checkButton(boolean buttonEnabled) { + leftButton.setEnabled(buttonEnabled); + rightButton.setEnabled(buttonEnabled); + } + + @Override + /** + * 画Tab + */ + public void paintComponent(Graphics g) { + super.paintComponent(g); + isAuthorityEditing = BaseUtils.isAuthorityEditing(); + showCount = 0; + // 开始画那些Tab. + Graphics2D g2d = (Graphics2D) g; + FontMetrics fm = GraphHelper.getFontMetrics(this.getFont()); + int charWidth = fm.charWidth('M'); + int textAscent = fm.getAscent(); + double textHeight = this.getSize().getHeight() - 1; + + widthArray = calculateWidthArray(); + int operationWidth = GRAP + ADD_WORK_SHEET.getIconWidth() + ICON_SEP_DISTANCE + ADD_POLY_SHEET.getIconWidth(); + double maxWidth = getWidth() - operationWidth - buttonPane.getWidth();// 最大宽度 + paintBackgroundAndLine(g2d, textHeight, maxWidth, charWidth, textAscent); + checkButton(showCount < widthArray.length); + + // richie:当linearray不为空时,说明有了鼠标拖动,下面画由于鼠标拖动产生的效果. + if (!lineArray.isEmpty()) { + paintDragTab(g2d, textHeight, charWidth, textAscent); + } + + // richie:鼠标松开时把drag的轨迹数组clear掉. + if (isReleased) { + lineArray.clear(); + } + } + + private void paintBackgroundAndLine(Graphics2D g2d, double textHeight, double maxWidth, int charWidth, int textAscent) { + showCount = 0; + int addIconlocation = 0; + WorkBook workBook = reportComposite.getEditingWorkBook(); + int reportCount = workBook.getReportCount(); + double textX = 0; + Icon sheeticon; + for (int i = scrollIndex; i < reportCount; i++) { + lastOneIndex = i; + TemplateReport templateReport = workBook.getTemplateReport(i); + boolean isNeedPaintedAuthority = false; + if (isAuthorityEditing) { + String selectedRoles = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); + isNeedPaintedAuthority = templateReport.getWorkSheetPrivilegeControl().checkInvisible(selectedRoles); + } + sheeticon = templateReport instanceof WorkSheet ? WORK_SHEET_ICON : POLY_SHEET_ICON; + String sheetName = workBook.getReportName(i); + if (i == selectedIndex) { + paintSelectedTab(g2d, sheeticon, textHeight, textX, sheetName, charWidth, textAscent, isNeedPaintedAuthority); + } else { + paintUnSelectedTab(g2d, sheeticon, textHeight, textX, sheetName, charWidth, textAscent, i, isNeedPaintedAuthority); + } + int width = widthArray[i]; + textX += width + 1; + addIconlocation += width; + if (i < widthArray.length - 1 && textX + widthArray[i + 1] + 1 > maxWidth) { + isOvertakeWidth = true; + break; + } else { + showCount++; + isOvertakeWidth = false; + } + int count = (int) (maxWidth) / width; + + if (i >= scrollIndex + count - 1) { + isOvertakeWidth = true; + } + } + + // 画两个添加sheet图标 + iconLocation = isOvertakeWidth ? (int) (maxWidth) : addIconlocation + GRAP; + + paintAddButton(g2d); + } + + protected void paintAddButton(Graphics2D g2d){ + ADD_WORK_SHEET.paintIcon(this, g2d, iconLocation, 3); + ADD_POLY_SHEET.paintIcon(this, g2d, iconLocation + ADD_WORK_SHEET.getIconWidth() + ICON_SEP_DISTANCE, 3); + } + + /** + * 画选中的tab + * + * @param g2d + * @param sheeticon + * @param textHeight + * @param textX + * @param sheetName + * @param charWidth + * @param textAscent + */ + private void paintSelectedTab(Graphics2D g2d, Icon sheeticon, double textHeight, double textX, String sheetName, int charWidth, int textAscent, boolean isNeedPaintAuthority) { + double[] x = {textX, textX, textX + LEFT_CORNOR, textX + widthArray[selectedIndex] - RIGHT_CORNOR, textX + widthArray[selectedIndex] + RIGHT_CORNOR}; + double[] y = {0, textHeight - LEFT_CORNOR, textHeight, textHeight, 0}; + if (isNeedPaintAuthority) { + g2d.setPaint(new GradientPaint(1, 1, UIConstants.AUTHORITY_SHEET_LIGHT, 1, getHeight() - 1, UIConstants.AUTHORITY_SHEET_DARK)); + } else { + g2d.setPaint(new GradientPaint(1, 1, Color.white, 1, getHeight() - 1, Color.white)); + } + GeneralPath generalPath = new GeneralPath(Path2D.WIND_EVEN_ODD, x.length); + generalPath.moveTo((float) x[0], (float) y[0]); + + for (int index = 1; index < x.length; index++) { + generalPath.lineTo((float) x[index], (float) y[index]); + } + generalPath.closePath(); + g2d.fill(generalPath); +// g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); +// g2d.setPaint(UIConstants.LINE_COLOR); +// if (selectedIndex == scrollIndex) { +// g2d.draw(new Line2D.Double(x[0], y[0], x[1], y[1])); +// } +// g2d.draw(new Line2D.Double(x[1], y[1], x[2], y[2])); +// g2d.draw(new Line2D.Double(x[2], y[2], x[3], y[3])); +// g2d.draw(new Line2D.Double(x[3], y[3], x[4], y[4])); +// g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); + sheeticon.paintIcon(this, g2d, (int) textX + charWidth, 2); + // peter:画字符 + g2d.setPaint(getForeground()); + g2d.drawString(sheetName, (int) textX + charWidth + 14, textAscent); + } + + /** + * 画不是选中状态的tab + * + * @param g2d + * @param sheetIcon + * @param textHeight + * @param textX + * @param sheetName + * @param charWidth + * @param textAscent + * @param i + */ + private void paintUnSelectedTab(Graphics2D g2d, Icon sheetIcon, double textHeight, double textX, String sheetName, int charWidth, int textAscent, int i, boolean isNeedPaintAuthority) { + Color tabBackground = UIConstants.SHEET_NORMAL; + int width = widthArray[i]; + double[] x = {textX, textX, textX + LEFT_CORNOR, textX + width - RIGHT_CORNOR, textX + width, textX + width}; + double[] y = {0, textHeight - LEFT_CORNOR, textHeight, textHeight, textHeight - RIGHT_CORNOR, 0}; + if (isNeedPaintAuthority) { + g2d.setPaint(UIConstants.AUTHORITY_SHEET_UNSELECTED); + } else{ + g2d.setPaint(tabBackground); + } + GeneralPath generalPath = new GeneralPath(Path2D.WIND_EVEN_ODD, x.length); + generalPath.moveTo((float) x[0], (float) y[0]); + + for (int index = 1; index < x.length; index++) { + generalPath.lineTo((float) x[index], (float) y[index]); + } + generalPath.closePath(); + g2d.fill(generalPath); + + g2d.setPaint(LINE_COLOR); +// if (i == scrollIndex) { +// g2d.draw(new Line2D.Double(x[0], y[0], x[1], y[1])); +// } +// g2d.draw(new Line2D.Double(x[1], y[1], x[2], y[2])); +// g2d.draw(new Line2D.Double(x[2], y[2], x[3], y[3])); +// g2d.draw(new Line2D.Double(x[3], y[3], x[4], y[4])); +// g2d.draw(new Line2D.Double(x[4], y[4], x[5], y[5])); + double startX = textX > 0 ? textX - 1 : textX; + g2d.drawRect((int)startX, 0, width, (int)textHeight); + + sheetIcon.paintIcon(this, g2d, (int) textX + charWidth, 2); + g2d.setPaint(getForeground()); + g2d.drawString(sheetName, (int) textX + charWidth + 14, textAscent); + } + + /** + * 画拖拽的轨迹 + * + * @param g2d + * @param textHeight + * @param charWidth + * @param textAscent + */ + private void paintDragTab(Graphics2D g2d, double textHeight, int charWidth, int textAscent) { + g2d.setPaint(UIManager.getColor("TabbedPane.darkShadow")); + Point lastPoint = lineArray.get(lineArray.size() - 1); + + // richie:鼠标拖动开始时的x坐标 + int startPointX = this.getPressedXY()[0]; + + // richie:当前选中的workSheet的宽度 + int width = widthArray[selectedIndex]; + int totalWidth = 0; + // richie:当前选中的workSheet之前的所有workSheets的总宽度 + for (int i = 0; i < selectedIndex; i++) { + totalWidth += widthArray[i]; + } + + int distance = startPointX - totalWidth; + + int[] x = {(int) lastPoint.getX() - distance, (int) lastPoint.getX() - distance, (int) lastPoint.getX() - distance + width, (int) lastPoint.getX() + width - distance}; + int[] y = {0, (int) (textHeight), (int) (textHeight), 0}; + g2d.drawPolygon(x, y, 4); + // peter:画字符 + g2d.setPaint(getForeground()); + // richie:把当前选中的workSheet的名字画到鼠标拖动产生的图形上. + g2d.drawString(reportComposite.getEditingWorkBook().getReportName(selectedIndex), (int) lastPoint.getX() - distance + charWidth, textAscent); + } + + /** + * 根据名字和个数计算出所有tab的宽度 + * + * @return + */ + private int[] calculateWidthArray() { + FontMetrics fm = GraphHelper.getFontMetrics(this.getFont()); + int charWidth = fm.charWidth('M'); + WorkBook workBook = reportComposite.getEditingWorkBook(); + int reportCount = workBook.getReportCount(); + int[] widthArray = new int[reportCount]; + for (int i = 0; i < reportCount; i++) { + String sheetName = workBook.getReportName(i); + widthArray[i] = fm.stringWidth(sheetName) + charWidth * 2 - 1 + ADD_WIDTH_BY_SHEETNAME; + } + return widthArray; + } + + private int[] getPressedXY() { + return this.xyPressedCoordinate; + } + + private void setPressedXY(int x, int y) { + this.xyPressedCoordinate[0] = x; + this.xyPressedCoordinate[1] = y; + } + + private int[] getReleasedXY() { + return this.xyReleasedCoordinate; + } + + private void setReleasedXY(int x, int y) { + this.xyReleasedCoordinate[0] = x; + this.xyReleasedCoordinate[1] = y; + } + + /** + * 鼠标点击事件 + * + * @param e 鼠标事件 + */ + public void mouseClicked(MouseEvent e) { + } + + /** + * 鼠标按下事件 + * + * @param evt 鼠标事件 + */ + public void mousePressed(MouseEvent evt) { + int reportcount = reportComposite.getEditingWorkBook().getReportCount(); + if (scrollIndex < 0 || scrollIndex >= reportcount) { + return; + } + reportComposite.stopEditing(); + int evtX = evt.getX(); + int evtY = evt.getY(); + this.setPressedXY(evtX, evtY); + boolean isBlank = true; + int textX = 0; + for (int i = scrollIndex; i <= lastOneIndex; i++) { + int textWidth = widthArray[i]; + if (evtX >= textX && evtX < textX + textWidth) { + setSelectedIndex(i); + isBlank = false; + reportComposite.setComposite(); + if (isAuthorityEditing) { + doWithAuthority(); + } + DesignerContext.getDesignerFrame().getContentFrame().repaint(); + break; + } + textX += textWidth; + } + + if (SwingUtilities.isLeftMouseButton(evt)) { + processLeftMouseButton(evtX); + } + if (isBlank) { + return; + } + if (SwingUtilities.isRightMouseButton(evt) && !isAuthorityEditing) { + processRightMouseButton(evtX, evtY); + } + } + + private void processRightMouseButton(int evtX, int evtY){ + MenuDef def = new MenuDef(); + addInsertGridShortCut(def); + def.addShortCut(new PolyReportInsertAction(), SeparatorDef.DEFAULT, new RemoveSheetAction(), new RenameSheetAction(), + new CopySheetAction()); + JPopupMenu tabPop = def.createJMenu().getPopupMenu(); + def.updateMenu(); + GUICoreUtils.showPopupMenu(tabPop, this, evtX - 1, evtY - 1); + } + + private void processLeftMouseButton(int evtX){ + if (evtX > iconLocation && evtX < iconLocation + GRID_TOSHEET_RIGHT) { + firstInsertActionPerformed(); + } else if (evtX > iconLocation + POLY_TOSHEET_LEFT && evtX < iconLocation + POLY_TOSHEET_RIGHT) { + new PolyReportInsertAction().actionPerformed(null); + } + + } + + protected void addInsertGridShortCut(MenuDef def){ + def.addShortCut(new GridReportInsertAction()); + } + + protected void firstInsertActionPerformed(){ + new GridReportInsertAction().actionPerformed(null); + } + + + /** + * 鼠标释放事件 + * + * @param e 鼠标事件 + */ + public void mouseReleased(MouseEvent e) { + this.isReleased = true; + this.setReleasedXY(e.getX(), e.getY()); + int width = 0; + for (int w : widthArray) { + width = width + w + SHEET_ICON_GAP; + } + if (isAuthorityEditing) { + return; + } + if (this.getPressedXY()[0] != this.getReleasedXY()[0] || this.getPressedXY()[1] != this.getReleasedXY()[1]) { + // 因为下面的操作会使得selectedIndex变化,所以要个量来保存开始的selectedIndex + int si = selectedIndex; + // richie:workSheet向右拖动 + int moveRighttDistance = this.getReleasedXY()[0] - this.getPressedXY()[0]; + // richie:向左拖动 + int moveLeftDistance = -moveRighttDistance; + // samuel:拖动范围超过宽度的一半才移动,并且不越界 + if (moveRighttDistance > widthArray[si] / 2 && this.getReleasedXY()[0] < width) { + move2Right(moveRighttDistance, si); + //拖拽触发保存 + reportComposite.fireTargetModified(); + this.repaint(100); + return; + } else if (moveLeftDistance > widthArray[si] / 2) { + move2Left(moveLeftDistance, si); + //拖拽触发保存 + reportComposite.fireTargetModified(); + this.repaint(100); + return; + } else { + setSelectedIndex(si); + DesignerContext.getDesignerFrame().getContentFrame().repaint(); + } + } + this.repaint(100); + } + + /** + * 右移动 + * + * @param moveRighttDistance 右侧移动距离 + * @param si 宽度坐标 + */ + private void move2Right(int moveRighttDistance, int si) { + int reportcount = reportComposite.getEditingWorkBook().getReportCount(); + if (selectedIndex < reportcount - 1) { + while (moveRighttDistance > widthArray[si] / 2) { + int i = selectedIndex; + this.exchangeWorkSheet(selectedIndex, selectedIndex + 1); + setSelectedIndex(selectedIndex + 1); + // richie:拖到越过所有的workSheet时,直接就作为最后一个workSheet + if (i > reportcount - 3) { + setSelectedIndex(reportcount - 1); + return; + } + moveRighttDistance -= widthArray[i + 1]; + } + + } else { + return; + } + } + + /** + * 左移动 + * + * @param moveLeftDistance 左侧距离 + * @param si 宽度坐标 + */ + private void move2Left(int moveLeftDistance, int si) { + if (selectedIndex > 0) { + while (moveLeftDistance > widthArray[si] / 2) { + int i = selectedIndex; + this.exchangeWorkSheet(selectedIndex, selectedIndex - 1); + setSelectedIndex(selectedIndex - 1); + // richie:拖到越过所有的workSheet时,直接就作为第一个workSheet + if (i < 2) { + setSelectedIndex(0); + return; + } + moveLeftDistance -= widthArray[i - 1]; + } + } else { + return; + } + } + + /** + * 鼠标进入事件 + * + * @param e 鼠标事件 + */ + public void mouseEntered(MouseEvent e) { + } + + /** + * 鼠标退出事件 + * + * @param e 鼠标事件 + */ + public void mouseExited(MouseEvent e) { + } + + /** + * exchange workSheet + * + * @param workBook + * @param index1 + * @param index2 + * @return workBook + */ + private void exchangeWorkSheet(int index1, int index2) { + WorkBook workbook = reportComposite.getEditingWorkBook(); + TemplateReport workSheet1 = workbook.getTemplateReport(index1); + String name1 = reportComposite.getEditingWorkBook().getReportName(index1); + + TemplateReport workSheet2 = workbook.getTemplateReport(index2); + String name2 = workbook.getReportName(index2); + workbook.addReport(index1, name2, workSheet2); + workbook.removeReport(index1 + 1); + workbook.addReport(index2, name1, workSheet1); + workbook.removeReport(index2 + 1); + } + + protected abstract class SheetInsertAction extends UpdateAction { + SheetInsertAction() { + this.setName(Inter.getLocText("Insert") + getTemplateReportType()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/base/images/cell/control/add.png")); + } + + @Override + public void actionPerformed(ActionEvent evt) { + if (isAuthorityEditing) { + return; + } + int insertPos = selectedIndex + 1; + if (isOvertakeWidth) { + scrollIndex++; + } + + reportComposite.getEditingWorkBook().addReport(insertPos, newTemplateReport()); + setSelectedIndex(insertPos); + + // sheet名字的公式也需要做相应的变化. + reportComposite.setComposite(); + reportComposite.fireTargetModified(); + ReportComponent ReportComponent = reportComposite.centerCardPane.editingComponet; + ReportComponent.setSelection(ReportComponent.getDefaultSelectElement()); + + + showCount = 1; + WorkBook workBook = reportComposite.getEditingWorkBook(); + int reportCount = workBook.getReportCount(); + double textX = 0; + for (int i = scrollIndex; i < reportCount; i++) { + widthArray = calculateWidthArray(); + int width = widthArray[i]; + textX += width + 1; + int operationWidth = GRAP + ADD_WORK_SHEET.getIconWidth() + ICON_SEP_DISTANCE + ADD_POLY_SHEET.getIconWidth(); + double maxWidth = getWidth() - operationWidth - buttonPane.getWidth();// 最大宽度 + if (i < widthArray.length - 1 && textX + widthArray[i + 1] + 1 > maxWidth) { + isOvertakeWidth = true; + scrollIndex++; + continue; + } else { + showCount++; + isOvertakeWidth = false; + } + } + + if (scrollIndex > 0 && showCount + scrollIndex < reportCount) { + scrollIndex++; + } + + DesignerContext.getDesignerFrame().getContentFrame().repaint(); + } + + protected abstract TemplateReport newTemplateReport(); + + protected abstract String getTemplateReportType(); + } + + protected class GridReportInsertAction extends SheetInsertAction { + + @Override + protected TemplateReport newTemplateReport() { + return new WorkSheet(); + } + + @Override + protected String getTemplateReportType() { + return Inter.getLocText("Report"); + } + } + + protected class PolyReportInsertAction extends SheetInsertAction { + @Override + protected TemplateReport newTemplateReport() { + return new PolyWorkSheet(); + } + + @Override + protected String getTemplateReportType() { + return Inter.getLocText("Poly"); + } + } + + private class RemoveSheetAction extends UpdateAction { + RemoveSheetAction() { + this.setName(Inter.getLocText("Remove")); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/base/images/cell/control/remove.png")); + } + + @Override + public void actionPerformed(ActionEvent e) { + if (isAuthorityEditing) { + return; + } + int count = reportComposite.getEditingWorkBook().getReportCount(); + if (count <= 1) { + JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(reportComposite), Inter.getLocText("At_least_one_visual_worksheet") + "!"); + return; + } + int returnValue = JOptionPane.showConfirmDialog(SwingUtilities.getWindowAncestor(reportComposite), Inter.getLocText("Des-Remove_WorkSheet"), ProductConstants.APP_NAME, + JOptionPane.OK_CANCEL_OPTION); + if (returnValue == JOptionPane.OK_OPTION) { + if (DesignerContext.getFormatState() != DesignerContext.FORMAT_STATE_NULL) { + doCancelFormat(); + } + reportComposite.getEditingWorkBook().removeReport(selectedIndex); + int insertPos = selectedIndex > 0 ? selectedIndex - 1 : 0; + setSelectedIndex(insertPos); + final int s = scrollIndex; + if (s < lastOneIndex && scrollIndex > 0) { + scrollIndex--; + lastOneIndex--; + } + reportComposite.setComposite(); + reportComposite.repaint(); + reportComposite.fireTargetModified(); + } + } + } + + + private void doCancelFormat() { + boolean isSameCase = ComparatorUtils.equals(reportComposite.centerCardPane.editingComponet.elementCasePane, DesignerContext.getReferencedElementCasePane()); + boolean isPolyContains = false; + if (reportComposite.centerCardPane.editingComponet instanceof PolyDesigner) { + isPolyContains = ((PolyDesigner) reportComposite.centerCardPane.editingComponet).containsBlocks(DesignerContext.getReferencedElementCasePane()); + } + boolean isDelPane = isSameCase || isPolyContains; + + if (isDelPane && this.selectedIndex == DesignerContext.getReferencedIndex()) { + DesignerContext.setFormatState(DesignerContext.FORMAT_STATE_NULL); + ((ElementCasePane) DesignerContext.getReferencedElementCasePane()).getGrid().setNotShowingTableSelectPane(true); + DesignerContext.setReferencedElementCasePane(null); + DesignerContext.setReferencedIndex(0); + this.repaint(); + + } + } + + private class RenameSheetAction extends UpdateAction { + RenameSheetAction() { + this.setName(Inter.getLocText("Rename")); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/base/images/cell/control/rename.png")); + } + + @Override + public void actionPerformed(ActionEvent e) { + if (selectedIndex < 0 || selectedIndex >= reportComposite.getEditingWorkBook().getReportCount()) { + return; + } + + String newName = JOptionPane.showInputDialog(reportComposite, Inter.getLocText("Rename") + ":", reportComposite.getEditingWorkBook().getReportName(selectedIndex)); + if (newName != null) { + // marks:判断是否重名 + boolean isExisted = false; + for (int i = 0; i < reportComposite.getEditingWorkBook().getReportCount(); i++) { + if (newName.equalsIgnoreCase(reportComposite.getEditingWorkBook().getReportName(i))) { + isExisted = true; + break; + } + } + if (!isExisted) { + reportComposite.getEditingWorkBook().setReportName(selectedIndex, newName); + reportComposite.getEditingReportComponent().fireTargetModified(); + // sheet名字的公式也需要做相应的变化. + reportComposite.repaint(); + } else { + JOptionPane.showMessageDialog(reportComposite, Inter.getLocText("Utils-The_Name_has_been_existed")); + } + } + } + } + + private class CopySheetAction extends UpdateAction { + CopySheetAction() { + this.setName(Inter.getLocText("Copy")); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/copy.png")); + } + + @Override + public void actionPerformed(ActionEvent e) { + TemplateReport tr; + try { + tr = (TemplateReport) reportComposite.getEditingWorkBook().getReport(selectedIndex).clone(); + } catch (CloneNotSupportedException ex) { + return; + } + + // 在需要复制的sheet后加上 + int index = selectedIndex; + reportComposite.getEditingWorkBook().addReport(index + 1, tr); + + String prefix = reportComposite.getEditingWorkBook().getReportName(index); + int times = 0; + for (int i = 0; i < reportComposite.getEditingWorkBook().getReportCount(); i++) { + if (reportComposite.getEditingWorkBook().getReportName(i).startsWith(prefix)) { + times++; + } + } + String suffix = "-" + Inter.getLocText("Copy") + times; + reportComposite.getEditingWorkBook().setReportName(index + 1, prefix + suffix); + setSelectedIndex(index + 1); + reportComposite.validate(); + reportComposite.repaint(100); + reportComposite.fireTargetModified(); + } + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/WorkBookModelAdapter.java b/designer/src/com/fr/design/mainframe/WorkBookModelAdapter.java new file mode 100644 index 000000000..acd192b86 --- /dev/null +++ b/designer/src/com/fr/design/mainframe/WorkBookModelAdapter.java @@ -0,0 +1,159 @@ +package com.fr.design.mainframe; + +import com.fr.base.Parameter; +import com.fr.base.TableData; +import com.fr.data.TableDataSource; +import com.fr.design.DesignModelAdapter; +import com.fr.design.bridge.DesignToolbarProvider; +import com.fr.form.ui.Widget; +import com.fr.main.impl.WorkBook; +import com.fr.main.parameter.ReportParameterAttr; +import com.fr.report.cell.CellElement; +import com.fr.report.cell.DefaultTemplateCellElement; +import com.fr.report.cell.FloatElement; +import com.fr.report.elementcase.ElementCase; +import com.fr.report.elementcase.TemplateElementCase; +import com.fr.report.report.Report; +import com.fr.script.Calculator; +import com.fr.stable.ParameterProvider; +import com.fr.stable.StringUtils; +import com.fr.stable.bridge.StableFactory; +import com.fr.stable.js.WidgetName; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +/** + * + * @author zhou + * @since 2012-7-26下午2:03:12 + */ +public class WorkBookModelAdapter extends DesignModelAdapter { + + public WorkBookModelAdapter(JWorkBook jworkbook) { + super(jworkbook); + } + + @Override + public Parameter[] getParameters() { + return this.getBook().getParameters(); + } + + // 报表参数 + @Override + public Parameter[] getReportParameters() { + ReportParameterAttr rpa = this.getBook().getReportParameterAttr(); + return rpa == null ? new Parameter[0] : rpa.getParameters(); + } + + // 数据源参数 + @Override + public Parameter[] getTableDataParameters() { + TableDataSource source = this.getBook(); + Calculator c = Calculator.createCalculator(); + c.setAttribute(TableDataSource.class, source); + java.util.List list = new java.util.ArrayList(); + java.util.Iterator nameIt = this.getBook().getTableDataNameIterator(); + while (nameIt.hasNext()) { + TableData td = source.getTableData(nameIt.next()); + if (td.getParameters(c) != null) { + list.addAll(java.util.Arrays.asList(td.getParameters(c))); + } + } + return list.toArray(new Parameter[list.size()]); + } + + /** + * 重命名TableData后的一些操作 + * @param oldName 旧名字 + * @param newName 新名字 + * @return 返回是否刷新. + */ + public boolean renameTableData(String oldName, String newName) { + if (super.renameTableData(oldName, newName)) { + if (this.getBook().getTableData(oldName) == null) { + jTemplate.refreshParameterPane4TableData(oldName,newName); + } + return true; + } + return false; + } + + /** + * 环境改变. + */ + public void envChanged() { + DesignToolbarProvider provider = StableFactory.getMarkedObject(DesignToolbarProvider.STRING_MARKED, DesignToolbarProvider.class); + if (provider != null) { + provider.refreshToolbar(); + } + jTemplate.refreshAllNameWidgets(); + } + + /** + * 参数改变. + */ + public void parameterChanged() { + jTemplate.updateReportParameterAttr(); + jTemplate.populateReportParameterAttr(); + } + + /** + * 控件改变. + */ + public void widgetConfigChanged() { + DesignToolbarProvider provider = StableFactory.getMarkedObject(DesignToolbarProvider.STRING_MARKED, DesignToolbarProvider.class); + if (provider != null) { + provider.refreshToolbar(); + } + jTemplate.refreshAllNameWidgets(); + } + + /** + * 返回控件的名字 + * @return widgetName 控件列表. + */ + public List getWidgetsName() { + List list = new ArrayList(); + WorkBook wb = this.getBook(); + for (int i = 0, len = wb.getReportCount(); i < len; i++) { + Report report = wb.getReport(i); + Iterator it = report.iteratorOfElementCase(); + while (it.hasNext()) { + ElementCase ec = (ElementCase)it.next(); + Iterator cs = ec.cellIterator(); + while (cs.hasNext()) { + CellElement ce = (CellElement)cs.next(); + if (ce instanceof DefaultTemplateCellElement) { + Widget widget = ((DefaultTemplateCellElement)ce).getWidget(); + if (widget != null && StringUtils.isNotEmpty(widget.getWidgetName())) { + list.add(new WidgetName(widget.getWidgetName())); + } + } + } + } + } + return list; + } + + /** + * 返回悬浮元素的名字数组 + * @return 返回数组. + */ + public String[] getFloatNames() { + TemplateElementCase elementCase = jTemplate.getEditingElementCase(); + + List nameList = new ArrayList(); + Iterator it = elementCase.floatIterator(); + while (it.hasNext()) { + nameList.add(it.next().getName()); + } + return nameList.toArray(new String[nameList.size()]); + } + + + public Widget[] getLinkableWidgets() { + return new Widget[0]; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/WorkBookUndoState.java b/designer/src/com/fr/design/mainframe/WorkBookUndoState.java new file mode 100644 index 000000000..e54f0da0d --- /dev/null +++ b/designer/src/com/fr/design/mainframe/WorkBookUndoState.java @@ -0,0 +1,39 @@ +package com.fr.design.mainframe; + +import com.fr.design.designer.EditingState; +import com.fr.main.impl.WorkBook; + +public class WorkBookUndoState extends BaseUndoState { + private WorkBook wb; + private int selectedReportIndex; + private EditingState editingState; + + public WorkBookUndoState(JWorkBook t, int selectedReportIndex, EditingState selectedEditingState) { + super(t); + + try { + this.wb = (WorkBook) t.getTarget().clone(); + } catch (CloneNotSupportedException e) { + throw new RuntimeException(e); + } + this.selectedReportIndex = selectedReportIndex; + this.editingState = selectedEditingState; + } + + public WorkBook getWorkBook() { + return wb; + } + + public int getSelectedReportIndex() { + return selectedReportIndex; + } + + public EditingState getSelectedEditingState() { + return editingState; + } + + @Override + public void applyState() { + this.getApplyTarget().applyUndoState(this); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/WorkSheetDesigner.java b/designer/src/com/fr/design/mainframe/WorkSheetDesigner.java new file mode 100644 index 000000000..d25812095 --- /dev/null +++ b/designer/src/com/fr/design/mainframe/WorkSheetDesigner.java @@ -0,0 +1,181 @@ +package com.fr.design.mainframe; + +import java.awt.BorderLayout; + +import javax.swing.*; + +import com.fr.design.DesignState; +import com.fr.design.actions.report.*; +import com.fr.design.designer.EditingState; +import com.fr.design.event.TargetModifiedEvent; +import com.fr.design.event.TargetModifiedListener; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.menu.*; +import com.fr.grid.selection.CellSelection; +import com.fr.grid.selection.Selection; +import com.fr.report.cell.CellElement; +import com.fr.report.elementcase.TemplateElementCase; +import com.fr.report.worksheet.WorkSheet; +import com.fr.design.selection.SelectionListener; +import com.fr.stable.ArrayUtils; + +public class WorkSheetDesigner extends ReportComponent { + + public WorkSheetDesigner(WorkSheet sheet) { + super(sheet); + + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + + elementCasePane = new ElementCasePaneDelegate(sheet); + this.add(elementCasePane, BorderLayout.CENTER); + elementCasePane.addTargetModifiedListener(new TargetModifiedListener() { + + @Override + public void targetModified(TargetModifiedEvent e) { + WorkSheetDesigner.this.fireTargetModified(); + } + }); + + } + + //august:以下方法貌似都可以放到父类中去 不过问题就是PolyDesigner可能用不到,它还得覆盖 + @Override + public void setTarget(WorkSheet t) { + super.setTarget(t); + + this.elementCasePane.setTarget(t); + } + + public int getMenuState() { + return DesignState.WORK_SHEET; + } + + + public AuthorityEditPane createAuthorityEditPane() { + ElementCasePaneAuthorityEditPane elementCasePaneAuthorityEditPane = new ElementCasePaneAuthorityEditPane(elementCasePane); + elementCasePaneAuthorityEditPane.populateDetials(); + return elementCasePaneAuthorityEditPane; + } + + + @Override + public EditingState createEditingState() { + return this.elementCasePane.createEditingState(); + } + +////////////////////////////////////////////////////////////////////// +//////////////////for toolbarMenuAdapter////////////////////////////// +////////////////////////////////////////////////////////////////////// + + @Override + public void copy() { + this.elementCasePane.copy(); + } + + @Override + public boolean paste() { + return this.elementCasePane.paste(); + } + + @Override + public boolean cut() { + return this.elementCasePane.cut(); + } + + @Override + public void stopEditing() { + this.elementCasePane.stopEditing(); + } + + @Override + public ToolBarDef[] toolbars4Target() { + return this.elementCasePane.toolbars4Target(); + } + + public JComponent[] toolBarButton4Form() { + return this.elementCasePane.toolBarButton4Form(); + } + + + @Override + public ShortCut[] shortcut4TemplateMenu() { + return (ShortCut[]) ArrayUtils.addAll(super.shortcut4TemplateMenu(), new ShortCut[]{ + new DottedSeparator(), + new ReportWriteAttrAction(this), + new ReportColumnsAction(this), + new ReportPageAttrAction(this), + new ReportEngineAttrAction(this) + }); + } + + + @Override + public MenuDef[] menus4Target() { + return this.elementCasePane.menus4Target(); + } + + @Override + public void requestFocus() { + super.requestFocus(); + elementCasePane.requestFocus(); + } + + @Override + public JScrollBar getHorizontalScrollBar() { + return elementCasePane.getHorizontalScrollBar(); + } + + public JScrollBar getVerticalScrollBar() { + return elementCasePane.getVerticalScrollBar(); + } + + public JPanel getEastUpPane() { + return elementCasePane.getEastUpPane(); + } + + public JPanel getEastDownPane() { + return elementCasePane.getEastDownPane(); + } + + + @Override + public Selection getSelection() { + return elementCasePane.getSelection(); + } + + @Override + public void setSelection(Selection selectElement) { + if (selectElement == null) { + selectElement = new CellSelection(); + } + this.elementCasePane.setSelection(selectElement); + } + + public void removeSelection() { + TemplateElementCase templateElementCase = this.elementCasePane.getEditingElementCase(); + if (templateElementCase instanceof WorkSheet) { + ((WorkSheet) templateElementCase).setPaintSelection(false); + } + elementCasePane.repaint(); + } + + @Override + public Selection getDefaultSelectElement() { + TemplateElementCase tpc = this.elementCasePane.getEditingElementCase(); + CellElement cellElement = tpc.getCellElement(0, 0); + return cellElement == null ? new CellSelection() : new CellSelection(0, 0, cellElement.getColumnSpan(), cellElement.getRowSpan()); + } + + @Override + public void addSelectionChangeListener(SelectionListener selectionListener) { + elementCasePane.addSelectionChangeListener(selectionListener); + } + + @Override + public void removeSelectionChangeListener(SelectionListener selectionListener) { + elementCasePane.removeSelectionChangeListener(selectionListener); + + } + + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/bbs/BBSBrowserDialog.java b/designer/src/com/fr/design/mainframe/bbs/BBSBrowserDialog.java new file mode 100644 index 000000000..718e4d24d --- /dev/null +++ b/designer/src/com/fr/design/mainframe/bbs/BBSBrowserDialog.java @@ -0,0 +1,93 @@ +package com.fr.design.mainframe.bbs; + +import java.awt.BorderLayout; +import java.awt.Canvas; +import java.awt.Frame; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.awt.SWT_AWT; +import org.eclipse.swt.browser.Browser; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +import com.fr.design.dialog.UIDialog; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.general.Inter; + +/** + * 封装浏览器的dialog + * + */ +public class BBSBrowserDialog extends UIDialog { + + private static final int WIDTH = 600; + private static final int HEIGHT = 400; + + private DisplayThread displayThread; + private Canvas canvas; + private String url; + + public BBSBrowserDialog(Frame parent) { + super(parent); + + this.displayThread = new DisplayThread(); + this.displayThread.start(); + this.canvas = new Canvas(); + setLayout(new BorderLayout()); + add(canvas, BorderLayout.CENTER); + + this.setSize(WIDTH, HEIGHT); + GUICoreUtils.centerWindow(this); + } + + @Override + public String getTitle() { + return Inter.getLocText("FR-Designer_Forum"); + } + + /** + * 通知组件可以显示了 + * + */ + public void addNotify() { + super.addNotify(); + Display dis = displayThread.getDisplay(); + dis.syncExec(new Runnable() { + + public void run() { + Shell shell = SWT_AWT.new_Shell(displayThread.getDisplay(), canvas); + shell.setLayout(new FillLayout()); + final Browser browser = new Browser(shell, SWT.NONE); + browser.setLayoutData(BorderLayout.CENTER); + browser.setUrl(url); + } + }); + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + /** + * 检测面板中内容合法性 + * + */ + public void checkValid() throws Exception { + } + + /** + * 在窗口中显示指定的url + * + * @param url 指定的url + * + */ + public void showWindow(String url){ + this.setUrl(url); + this.setVisible(true); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/bbs/BBSConstants.java b/designer/src/com/fr/design/mainframe/bbs/BBSConstants.java new file mode 100644 index 000000000..f294b302e --- /dev/null +++ b/designer/src/com/fr/design/mainframe/bbs/BBSConstants.java @@ -0,0 +1,72 @@ +/** + * + */ +package com.fr.design.mainframe.bbs; + +import com.fr.stable.StringUtils; + +import java.util.Properties; + +/** + * @author neil + * + * @date: 2015-3-10-上午9:50:13 + */ +public class BBSConstants { + + //获取当前登陆用户未读取消息条数 + public static final String GET_MESSAGE_URL = loadAttribute("GET_MESSAGE_URL", "http://feedback.finedevelop.com:3000/bbs/message/count"); + //默认打开的论坛窗口 + public static final String DEFAULT_URL = loadAttribute("DEFAULT_URL", "http://bbs.finereport.com/home.php?mod=space&do=pm"); + //默认模板分享的url + public static final String SHARE_URL = loadAttribute("SHARE_URL", "http://bbs.finereport.com/"); + //收集设计器的信息url + public static final String COLLECT_URL = loadAttribute("COLLECT_URL", "http://bbs.finereport.com/"); + //在线验证激活码 + public static final String VERIFY_URL = loadAttribute("VERIFY_URL", "http://bbs.finereport.com/"); + //获取论坛更新信息, 判断是否需要弹窗 + public static final String UPDATE_INFO_URL = loadAttribute("UPDATE_INFO_URL", "http://bbs.finereport.com/"); + //论坛手机版 + public static final String BBS_MOBILE_MOD = loadAttribute("BBS_MOBILE_MOD", "http://bbs.finereport.com/forum.php?mobile=1"); + //判断是否更新的关键字 + public static final String UPDATE_KEY = loadAttribute("UPDATE_KEY", "newIsPopup"); + + + private static final String GUEST_KEY = "USER"; + private static final String LINK_KEY = "LINK"; + private static final int GUEST_NUM = 5; + + //用户名信息数组 + public static final String[] ALL_GUEST = loadAllGuestsInfo(GUEST_KEY); + //用户论坛链接信息 + public static final String[] ALL_LINK = loadAllGuestsInfo(LINK_KEY); + + private static Properties PROP = null; + + //加载所有用户的信息, 用户名, 论坛连接 + private static String[] loadAllGuestsInfo(String key){ + String[] allGuests = new String[GUEST_NUM]; + for (int i = 0; i < GUEST_NUM; i++) { + allGuests[i] = loadAttribute(key + i, StringUtils.EMPTY); + } + + return allGuests; + } + //如果要定制, 直接改bbs.properties就行了 + private static String loadAttribute(String key, String defaultValue) { + if (PROP == null) { + PROP = new Properties(); + try { + PROP.load(BBSConstants.class.getResourceAsStream("/com/fr/design/mainframe/bbs/bbs.properties")); + } catch (Exception e) { + } + } + + String p = PROP.getProperty(key); + if (StringUtils.isEmpty(p)) { + p = defaultValue; + } + return p; + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/bbs/BBSDialog.java b/designer/src/com/fr/design/mainframe/bbs/BBSDialog.java new file mode 100644 index 000000000..3465d1793 --- /dev/null +++ b/designer/src/com/fr/design/mainframe/bbs/BBSDialog.java @@ -0,0 +1,146 @@ +package com.fr.design.mainframe.bbs; + +import com.fr.design.dialog.UIDialog; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.general.ComparatorUtils; +import com.fr.general.FRLogger; + +import javafx.application.Platform; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.concurrent.Worker; +import javafx.embed.swing.JFXPanel; +import javafx.scene.Group; +import javafx.scene.Scene; +import javafx.scene.web.WebEngine; +import javafx.scene.web.WebView; + +import javax.swing.*; + +import java.awt.*; +import java.io.IOException; +import java.net.URI; + +/** + * @author richie + * @date 2015-04-02 + * @since 8.0 + */ +public class BBSDialog extends UIDialog { + + private static final int WIDTH = 600; + private static final int HEIGHT = 400; + private static final int OUTER_WIDTH = 605; + private static final int OUTER_HEIGHT = 428; + + + private JFXPanel jfxPanel; + + + public BBSDialog(Frame parent) { + super(parent); + //setUndecorated(true); + JPanel panel = (JPanel) getContentPane(); + initComponents(panel); + setSize(new Dimension(OUTER_WIDTH, OUTER_HEIGHT)); + } + + private void initComponents(JPanel contentPane) { + contentPane.setLayout(new BorderLayout()); + jfxPanel = new JFXPanel(); + add(jfxPanel, BorderLayout.CENTER); + } + + private void disableLink(final WebEngine eng) { + try{ + // webView端不跳转 虽然webView可以指定本地浏览器打开某个链接,但是当本地浏览器跳转到指定链接的同时,webView也做了跳转, + // 为了避免出现在一个600*400的资讯框里加载整个网页的情况,webView不跳转到新网页 + Platform.runLater(new Runnable() { + @Override + public void run() { + eng.executeScript("history.go(0)"); + } + }); + }catch(Exception e){ + FRLogger.getLogger().error(e.getMessage()); + } + } + + /** + * 打开资讯框 + * @param url 资讯链接 + */ + public void showWindow(final String url){ + GUICoreUtils.centerWindow(this); + this.setResizable(false); + Platform.runLater(new Runnable() { + @Override + public void run() { + Group root = new Group(); + Scene scene = new Scene(root, WIDTH, HEIGHT); + jfxPanel.setScene(scene); + Double widthDouble = new Integer(WIDTH).doubleValue(); + Double heightDouble = new Integer(HEIGHT).doubleValue(); + WebView view = new WebView(); + view.setMinSize(widthDouble, heightDouble); + view.setPrefSize(widthDouble, heightDouble); + final WebEngine eng = view.getEngine(); + //webEngine的userAgent貌似支持移动设备的,任何其他浏览器的userAngent都会导致程序崩溃 + //eng.setUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) Apple/WebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.76 Safari/537.36"); + eng.load(url); + root.getChildren().add(view); + eng.locationProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, final String oldValue, String newValue) + { + disableLink(eng); + // webView好像默认以手机版显示网页,浏览器里过滤掉这个跳转 + if(ComparatorUtils.equals(newValue, url) || ComparatorUtils.equals(newValue, BBSConstants.BBS_MOBILE_MOD)){ + return; + } + openUrlAtLocalWebBrowser(eng,newValue); + } + }); + eng.getLoadWorker().stateProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, Worker.State oldValue, Worker.State newValue) { + if (newValue == Worker.State.SUCCEEDED){ + setVisible(true); + } + } + }); + } + }); + } + + // 在本地浏览器里打开url + private void openUrlAtLocalWebBrowser(WebEngine eng,String url){ + if(Desktop.isDesktopSupported()){ + try{ + //创建一个URI实例,注意不是URL + URI uri = URI.create(url); + //获取当前系统桌面扩展 + Desktop desktop = Desktop.getDesktop(); + //判断系统桌面是否支持要执行的功能 + if(desktop.isSupported(Desktop.Action.BROWSE)){ + //获取系统默认浏览器打开链接 + desktop.browse(uri); + } + }catch(NullPointerException e){ + //此为uri为空时抛出异常 + FRLogger.getLogger().error(e.getMessage()); + }catch(IOException e){ + //此为无法获取系统默认浏览器 + FRLogger.getLogger().error(e.getMessage()); + } + } + } + + /** + * 略 + */ + @Override + public void checkValid() throws Exception { + + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/bbs/BBSGuestPane.java b/designer/src/com/fr/design/mainframe/bbs/BBSGuestPane.java new file mode 100644 index 000000000..b86a0cc5c --- /dev/null +++ b/designer/src/com/fr/design/mainframe/bbs/BBSGuestPane.java @@ -0,0 +1,92 @@ +/** + * + */ +package com.fr.design.mainframe.bbs; + +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Desktop; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.net.URI; + +import javax.swing.JPanel; + +import com.fr.design.gui.ilable.ActionLabel; +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 com.fr.start.BBSGuestPaneProvider; + +/** + * @author neil + * + * @date: 2015-3-13-下午12:54:45 + */ +public class BBSGuestPane extends JPanel implements BBSGuestPaneProvider{ + + /** + * 构造函数 + */ + public BBSGuestPane() { + this.setLayout(FRGUIPaneFactory.createLabelFlowLayout()); + initTableContent(); + } + + private void initTableContent(){ + JPanel guestPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + //感谢标签 + JPanel infoPane = initInfoPane(); + guestPane.add(infoPane, BorderLayout.NORTH); + //用户名+超链 + JPanel userPane = initUserPane(); + guestPane.add(userPane, BorderLayout.CENTER); + + this.add(guestPane); + } + + private JPanel initUserPane(){ + double p = TableLayout.PREFERRED; + double[] rowSize = {p, p, p, p, p}; + double[] colSize = {p}; + + Component[][] components = new Component[rowSize.length][colSize.length]; + for (int i = 0; i < components.length; i++) { + String userName = BBSConstants.ALL_GUEST[i]; + String url = BBSConstants.ALL_LINK[i]; + components[i][0] = getURLActionLabel(userName, url); + } + + return TableLayoutHelper.createTableLayoutPane(components, rowSize, colSize); + } + + private JPanel initInfoPane(){ + JPanel infoPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + UILabel infoNorthLabel = new UILabel(Inter.getLocText("FR-Designer_Thank_guest")); + UILabel centerLabel = new UILabel(StringUtils.BLANK); + infoPane.add(infoNorthLabel, BorderLayout.NORTH); + infoPane.add(centerLabel, BorderLayout.CENTER); + + return infoPane; + } + + private ActionLabel getURLActionLabel(final String text, final String url){ + ActionLabel actionLabel = new ActionLabel(text); + actionLabel.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + try { + Desktop.getDesktop().browse(new URI(url)); + } catch (Exception exp) { + + } + } + }); + + return actionLabel; + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/bbs/BBSLoginDialog.java b/designer/src/com/fr/design/mainframe/bbs/BBSLoginDialog.java new file mode 100644 index 000000000..60545d7b6 --- /dev/null +++ b/designer/src/com/fr/design/mainframe/bbs/BBSLoginDialog.java @@ -0,0 +1,344 @@ +package com.fr.design.mainframe.bbs; + +import com.fr.design.DesignerEnvManager; +import com.fr.design.dialog.UIDialog; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.ilable.ActionLabel; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.ipasswordfield.UIPassWordField; +import com.fr.design.gui.itextfield.UITextField; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.general.ComparatorUtils; +import com.fr.general.FRFont; +import com.fr.general.FRLogger; +import com.fr.general.Inter; +import com.fr.general.http.HttpClient; +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.KeyListener; +import java.net.HttpURLConnection; +import java.net.URI; + +/** + * @author richie + * @date 2015-04-02 + * @since 8.0 + */ +public class BBSLoginDialog extends UIDialog { + + private static final int DIALOG_WIDTH = 400; + private static final int DIALOG_HEIGHT = 200; + private static final String URL = "http://bbs.finereport.com/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes&lssubmit=yes&inajax=1"; + private static final String PASSWORD_RESET_URL = "http://bbs.finereport.com/portal.php?mod=topic&topicid=2"; + private static final String REGISTER_URL = "http://bbs.finereport.com/member.php?mod=register"; + private static final String LOGIN_SUCCESS_FLAG = "http://bbs.finereport.com"; + private static final Font DEFAULT_FONT = FRFont.getInstance(FRFont.DEFAULT_FONTNAME, 0, 14); + private static final String TEST_CONNECTION_URL = "http://bbs.finereport.com/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes&lssubmit=yes&inajax=1&username=test&password=123456"; + private static final int TIME_OUT = 10000; + + private static final int BUTTON_WIDTH = 90; + private static final int V_GAP = 20; + private static final int BUTTON_H_GAP = 155; + private static final int NORTH_PANE_HEIGHT = 24; + private static final int FIELD_HEIGHT = 26; + private static final int FIELD_WIDTH = 204; + private static final int FLOWLAYOUT_H_GAP = 15; + + + private UILabel userLabel; + private UILabel passLabel; + private UITextField nameField; + private UIPassWordField passField; + private UIButton loginButton; + private UILabel tipLabel; + private BoxCenterAligmentPane passwordReset; + private BoxCenterAligmentPane registerLabel; + + private KeyListener keyListener = new KeyAdapter() { + public void keyPressed(KeyEvent e){ + int code = e.getKeyCode(); + if(KeyEvent.VK_ESCAPE == code){ + BBSLoginDialog.this.setVisible(false); + return; + } + + if(KeyEvent.VK_ENTER == code){ + login(); + } + } + }; + + // 用户登录状态label + private UserInfoLabel userInfoLabel; + + + public UILabel getTipLabel() { + return tipLabel; + } + + public void setTipLabel(UILabel tipLabel) { + this.tipLabel = tipLabel; + } + + + /** + * 构造函数 + * @param parent 父窗口 + * @param userInfoLabel 登录状态label + */ + public BBSLoginDialog(Frame parent,UserInfoLabel userInfoLabel) { + super(parent); + JPanel panel = (JPanel) getContentPane(); + initComponents(panel); + this.userInfoLabel = userInfoLabel; + setSize(new Dimension(DIALOG_WIDTH,DIALOG_HEIGHT)); + } + + private void initComponents(JPanel contentPane) { + this.setTitle(Inter.getLocText("FR-Designer-BBSLogin_Login-Title")); + tipLabel = new UILabel(Inter.getLocText("FR-Designer-BBSLogin_Login-Failure-Tip")); + userLabel = new UILabel(Inter.getLocText("FR-Designer-BBSLogin_Account")+":"); + passLabel = new UILabel(Inter.getLocText("FR-Designer-BBSLogin_Password")+":"); + nameField = new UITextField(); + passField = new UIPassWordField(); + loginButton = new UIButton(Inter.getLocText("FR-Designer-BBSLogin_Login")); + passwordReset = getURLActionLabel(PASSWORD_RESET_URL); + registerLabel = getURLActionLabel(REGISTER_URL); + loginButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent arg0) { + login(); + } + }); + + nameField.addKeyListener(keyListener); + passField.addKeyListener(keyListener); + loginButton.addKeyListener(keyListener); + + userLabel.setFont(DEFAULT_FONT); + passLabel.setFont(DEFAULT_FONT); + this.tipLabel.setVisible(false); + + contentPane.setLayout(new BorderLayout()); + + JPanel mainPane = new JPanel(); + mainPane.setLayout(new BorderLayout(0,V_GAP)); + + initNorthPane(mainPane); + + initCenterPane(mainPane); + + initSouthPane(mainPane); + + contentPane.add(mainPane,BorderLayout.NORTH); + + this.setResizable(false); + } + + + private void login(){ + if(nameField.getText().isEmpty()){ + tipForUsernameEmpty(); + nameField.requestFocus(); + return; + } + if(String.valueOf(passField.getPassword()).isEmpty()){ + tipForPasswordEmpty(); + passField.requestFocus(); + return; + } + if(!testConnection()){ + connectionFailue(); + return; + } + if(login(nameField.getText(),String.valueOf(passField.getPassword()))){ + loginSuccess(); + }else{ + loginFailure(); + } + + } + + private boolean testConnection(){ + HttpClient client = new HttpClient(TEST_CONNECTION_URL); + return client.isServerAlive(); + } + + private void initNorthPane(JPanel mainPane){ + JPanel northPane = new JPanel(); + northPane.setPreferredSize(new Dimension(DIALOG_WIDTH,NORTH_PANE_HEIGHT)); + northPane.add(tipLabel); + mainPane.add(northPane,BorderLayout.NORTH); + } + + private void initCenterPane(JPanel mainPane){ + JPanel loginPane = new JPanel(); + loginPane.setLayout(new GridLayout(2,1,0,V_GAP)); + + JPanel namePane = new JPanel(); + namePane.setLayout(new FlowLayout(FlowLayout.RIGHT,FLOWLAYOUT_H_GAP,0)); + namePane.add(userLabel); + nameField.setPreferredSize(new Dimension(FIELD_WIDTH,FIELD_HEIGHT)); + namePane.add(nameField); + namePane.add(passwordReset); + loginPane.add(namePane); + + JPanel passPane = new JPanel(); + passPane.setLayout(new FlowLayout(FlowLayout.RIGHT,FLOWLAYOUT_H_GAP,0)); + passPane.add(passLabel); + passPane.add(passField); + passField.setPreferredSize(new Dimension(FIELD_WIDTH,FIELD_HEIGHT)); + passPane.add(registerLabel); + loginPane.add(passPane); + + mainPane.add(loginPane,BorderLayout.CENTER); + } + + private void initSouthPane(JPanel mainPane){ + JPanel southPane = new JPanel(); + southPane.setLayout(new FlowLayout(FlowLayout.RIGHT,BUTTON_H_GAP,0)); + loginButton.setPreferredSize(new Dimension(BUTTON_WIDTH,FIELD_HEIGHT)); + loginButton.setFont(DEFAULT_FONT); + southPane.add(loginButton); + mainPane.add(southPane,BorderLayout.SOUTH); + } + + // 登录成功 + private void loginSuccess(){ + DesignerEnvManager.getEnvManager().setBBSPassword(String.valueOf(passField.getPassword())); + userInfoLabel.setUserName(nameField.getText()); + userInfoLabel.getUserInfoPane().markSignIn(nameField.getText()); + userInfoLabel.getUserInfoPane().getSwitchAccountLabel().setVisible(true); + BBSLoginDialog.this.setVisible(false); + } + + // 登录失败 + private void loginFailure(){ + setLoginFailureTxt(Inter.getLocText("FR-Designer-BBSLogin_Login-Failure-Tip")); + } + + public void tipForUsernameEmpty(){ + setLoginFailureTxt(Inter.getLocText("FR-Designer-BBSLogin_Username-Empty-Tip")); + } + + private void tipForPasswordEmpty(){ + setLoginFailureTxt(Inter.getLocText("FR-Designer-BBSLogin_Password-Empty-Tip")); + } + + private void setLoginFailureTxt(String errorTxt){ + tipLabel.setText(errorTxt); + tipLabel.setForeground(Color.RED); + tipLabel.repaint(); + tipLabel.setVisible(true); + } + + // 连接失败 + private void connectionFailue(){ + setLoginFailureTxt(Inter.getLocText("FR-Designer-BBSLogin_Connection-Failure")); + } + + /** + * 清楚登录信息 + */ + public void clearLoginInformation(){ + tipLabel.setText(StringUtils.EMPTY); + nameField.setText(StringUtils.EMPTY); + passField.setText(StringUtils.EMPTY); + } + + /** + * 显示登录窗口 + */ + public void showWindow(){ + GUICoreUtils.centerWindow(this); + setVisible(true); + } + + /** + * 无 + */ + @Override + public void checkValid() throws Exception { + + } + + /** + * 是否登陆成功 + * @param username 用户名 + * @param password 密码 + * @return 同上 + */ + public static boolean login(String username,String password){ + String url = URL + "&username=" + username + "&password=" + password; + HttpClient client = new HttpClient(url); + client.setTimeout(TIME_OUT); + if(client.getResponseCodeNoException() == HttpURLConnection.HTTP_OK){ + try { + String res = client.getResponseText("GBK"); + if(res.contains(LOGIN_SUCCESS_FLAG)){ + return true; + } + } catch (Exception e) { + FRLogger.getLogger().error(e.getMessage()); + } + } + return false; + } + + private BoxCenterAligmentPane getURLActionLabel(final String url){ + ActionLabel actionLabel = new ActionLabel(url); + if(ComparatorUtils.equals(url, PASSWORD_RESET_URL)){ + actionLabel.setText(Inter.getLocText("FR-Designer-BBSLogin_Forgot-Password")); + }else{ + actionLabel.setText(Inter.getLocText("FR-Designer-BBSLogin_Register-Account")); + } + + actionLabel.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + try { + Desktop.getDesktop().browse(new URI(url)); + } catch (Exception exp) { + + } + } + }); + + return new BoxCenterAligmentPane(actionLabel); + } + + class BoxCenterAligmentPane extends JPanel { + + private UILabel textLabel; + + public BoxCenterAligmentPane(String text) { + this(new UILabel(text)); + } + + public BoxCenterAligmentPane(UILabel label) { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + + JPanel centerPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); + this.add(centerPane, BorderLayout.CENTER); + + this.textLabel = label; + centerPane.add(textLabel); + } + + public void setFont(Font font) { + super.setFont(font); + + if (textLabel != null) { + textLabel.setFont(font); + } + } + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/bbs/DisplayThread.java b/designer/src/com/fr/design/mainframe/bbs/DisplayThread.java new file mode 100644 index 000000000..c3b3ce655 --- /dev/null +++ b/designer/src/com/fr/design/mainframe/bbs/DisplayThread.java @@ -0,0 +1,46 @@ +package com.fr.design.mainframe.bbs; + +import org.eclipse.swt.widgets.Display; + +public class DisplayThread extends Thread { + + private Display display; + Object sem = new Object(); + + /** + * 运行 + * + */ + public void run() { + synchronized (sem) { + display = Display.getDefault(); + sem.notifyAll(); + } + swtEventLoop(); + } + + private void swtEventLoop() { + while (true) { + try{ + if (!display.readAndDispatch()) { + display.sleep(); + } + }catch (Exception e) { + continue; + } + } + } + + public Display getDisplay() { + try { + synchronized (sem) { + while (display == null) { + sem.wait(); + } + return display; + } + } catch (Exception e) { + return null; + } + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/bbs/ExitLabel.java b/designer/src/com/fr/design/mainframe/bbs/ExitLabel.java new file mode 100644 index 000000000..c3436755a --- /dev/null +++ b/designer/src/com/fr/design/mainframe/bbs/ExitLabel.java @@ -0,0 +1,83 @@ +/** + * + */ +package com.fr.design.mainframe.bbs; + +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + + + +import com.fr.base.BaseUtils; +import com.fr.design.DesignerEnvManager; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.imenu.UIMenuItem; +import com.fr.design.gui.imenu.UIPopupMenu; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.general.Inter; +import com.fr.stable.StringUtils; + +/** + * @author neil + * + * @date: 2015-3-5-上午11:52:58 + */ +public class ExitLabel extends UILabel{ + + private static final int MENU_HEIGHT = 20; + + private UserInfoPane infoPane; + + /** + * 构造函数 + */ + public ExitLabel(UserInfoPane infoPane) { + this.infoPane = infoPane; + this.setIcon(BaseUtils.readIcon("/com/fr/design/mainframe/bbs/images/switch.png")); + this.addMouseListener(mouseListener); + } + + private MouseAdapter mouseListener = new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent e) { + UIPopupMenu menu = new UIPopupMenu(); + menu.setOnlyText(true); + menu.setPopupSize(infoPane.getWidth(),infoPane.getHeight()); + + UIMenuItem closeOther = new UIMenuItem(Inter.getLocText("FR-Designer-BBSLogin_Switch-Account")); + closeOther.addMouseListener(new MouseAdapter() { + + public void mousePressed(MouseEvent e) { + clearLoingInformation(); + updateInfoPane(); + }; + + }); + menu.add(closeOther); + + GUICoreUtils.showPopupMenu(menu, ExitLabel.this, 0, MENU_HEIGHT); + } + + private void clearLoingInformation(){ + DesignerEnvManager.getEnvManager().setBBSName(StringUtils.EMPTY); + DesignerEnvManager.getEnvManager().setBBSPassword(StringUtils.EMPTY); + } + + private void updateInfoPane(){ + infoPane.markUnSignIn(); + ExitLabel.this.setVisible(false); + BBSLoginDialog loginDialog = infoPane.getUserInfoLabel().getBbsLoginDialog(); + if(loginDialog == null){ + loginDialog = new BBSLoginDialog(DesignerContext.getDesignerFrame(), infoPane.getUserInfoLabel()); + infoPane.getUserInfoLabel().setBbsLoginDialog(loginDialog); + loginDialog.showWindow(); + } + loginDialog.getTipLabel().setVisible(false); + loginDialog.setModal(true); + loginDialog.clearLoginInformation(); + loginDialog.setVisible(true); + } + }; +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/bbs/UserInfoLabel.java b/designer/src/com/fr/design/mainframe/bbs/UserInfoLabel.java new file mode 100644 index 000000000..0f803d7f8 --- /dev/null +++ b/designer/src/com/fr/design/mainframe/bbs/UserInfoLabel.java @@ -0,0 +1,262 @@ +/** + * + */ +package com.fr.design.mainframe.bbs; + +import com.fr.base.FRContext; +import com.fr.design.DesignerEnvManager; +import com.fr.design.extra.LoginCheckContext; +import com.fr.design.extra.LoginCheckListener; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.mainframe.DesignerContext; +import com.fr.general.ComparatorUtils; +import com.fr.general.DateUtils; +import com.fr.general.http.HttpClient; +import com.fr.stable.EncodeConstants; +import com.fr.stable.StringUtils; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.net.URLEncoder; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; + +/** + * @author neil + * + * @date: 2015-3-4-上午9:05:52 + */ +public class UserInfoLabel extends UILabel{ + + //默认查询消息时间, 30s + private static final long CHECK_MESSAGE_TIME = 30 * 1000L; + //默认论坛检测到更新后的弹出延迟时间 + private static final long DELAY_TIME = 2 * 1000L; + private static final String MESSAGE_KEY = "messageCount"; + + private static final int MIN_MESSAGE_COUNT = 1; + + + //用户名 + private String userName; + //消息条数 + private int messageCount; + + private UserInfoPane userInfoPane; + private BBSLoginDialog bbsLoginDialog; + + public UserInfoPane getUserInfoPane() { + return userInfoPane; + } + + public void setUserInfoPane(UserInfoPane userInfoPane) { + this.userInfoPane = userInfoPane; + } + + public BBSLoginDialog getBbsLoginDialog() { + return bbsLoginDialog; + } + + public void setBbsLoginDialog(BBSLoginDialog bbsLoginDialog) { + this.bbsLoginDialog = bbsLoginDialog; + } + + public UserInfoLabel(UserInfoPane userInfoPane) { + this.userInfoPane = userInfoPane; + + String userName = DesignerEnvManager.getEnvManager().getBBSName(); + this.addMouseListener(userInfoAdapter); + this.setHorizontalAlignment(SwingConstants.CENTER); + this.setText(userName); + setUserName(userName); + LoginCheckContext.addLoginCheckListener(new LoginCheckListener() { + @Override + public void loginChecked() { + if (bbsLoginDialog == null) { + bbsLoginDialog = new BBSLoginDialog(DesignerContext.getDesignerFrame(), UserInfoLabel.this); + } + bbsLoginDialog.clearLoginInformation(); + bbsLoginDialog.tipForUsernameEmpty(); + bbsLoginDialog.setModal(true); + bbsLoginDialog.showWindow(); + } + }); + } + + /** + * showBBSDialog 弹出BBS资讯框 + */ + public static void showBBSDialog(){ + Thread showBBSThread = new Thread(new Runnable() { + + @Override + public void run() { + if(!FRContext.isChineseEnv()){ + return; + } + + String lastBBSNewsTime = DesignerEnvManager.getEnvManager().getLastShowBBSNewsTime(); + + try { + String today = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); + if (ComparatorUtils.equals(lastBBSNewsTime, today)) { + return; + } + Thread.sleep(DELAY_TIME); + } catch (InterruptedException e) { + FRContext.getLogger().error(e.getMessage()); + } + + HttpClient hc = new HttpClient(BBSConstants.UPDATE_INFO_URL); + if (!hc.isServerAlive()){ + return; + } + + String res = hc.getResponseText(); + if (res.indexOf(BBSConstants.UPDATE_KEY) == -1){ + return; + } + + try { + BBSDialog bbsLabel = new BBSDialog(DesignerContext.getDesignerFrame()); + bbsLabel.showWindow(BBSConstants.UPDATE_INFO_URL); + DesignerEnvManager.getEnvManager().setLastShowBBSNewsTime(DateUtils.DATEFORMAT2.format(new Date())); + } catch (Throwable e) { + + } + + } + }); + showBBSThread.start(); + } + + private void sleep(long millis){ + try { + Thread.sleep(millis); + } catch (InterruptedException e) { + FRContext.getLogger().error(e.getMessage()); + } + } + + public String getUserName() { + return userName; + } + + /** + * 重置当前用户名 + * + */ + public void resetUserName(){ + this.userName = StringUtils.EMPTY; + } + + public void setUserName(String userName) { + if(StringUtils.isEmpty(userName)){ + return; + } + + if(StringUtils.isEmpty(this.userName)){ + updateMessageCount(); + } + + //往designerenvmanger里写一下 + DesignerEnvManager.getEnvManager().setBBSName(userName); + this.userName = userName; + } + + private void updateMessageCount(){ + //启动获取消息更新的线程 + //登陆状态, 根据存起来的用户名密码, 每1分钟发起一次请求, 更新消息条数. + Thread updateMessageThread = new Thread(new Runnable() { + + @Override + public void run() { + sleep(CHECK_MESSAGE_TIME); + //从env中获取username, 因为如果注销的话, env的里username会被清空. + while(StringUtils.isNotEmpty(DesignerEnvManager.getEnvManager().getBBSName())){ + HashMap para = new HashMap(); + para.put("username", encode(encode(userName))); + HttpClient getMessage = new HttpClient(BBSConstants.GET_MESSAGE_URL, para); + getMessage.asGet(); + if(getMessage.isServerAlive()){ + try { + String res = getMessage.getResponseText(); + if (StringUtils.isNotEmpty(res)) { + setMessageCount(Integer.parseInt(res)); + } + } catch (Exception e) { + } + } + + sleep(CHECK_MESSAGE_TIME); + } + } + }); + updateMessageThread.start(); + } + + private String encode(String str){ + try { + return URLEncoder.encode(str, EncodeConstants.ENCODING_UTF_8); + } catch (UnsupportedEncodingException e) { + return str; + } + } + + public int getMessageCount() { + return messageCount; + } + + public void setMessageCount(int messageCount) { + // 当只有一条消息时,阅读之后,消息面板重置为只含用户名的状态 + if(this.messageCount == MIN_MESSAGE_COUNT && messageCount < MIN_MESSAGE_COUNT){ + this.setText(this.userName); + return; + } + if(this.messageCount == messageCount || messageCount < MIN_MESSAGE_COUNT){ + return; + } + + this.messageCount = messageCount; + StringBuilder sb = new StringBuilder(); + //内容eg: aaa(11) + sb.append(StringUtils.BLANK).append(this.userName) + .append("(").append(this.messageCount) + .append(")").append(StringUtils.BLANK); + + //更新面板Text + this.setText(sb.toString()); + } + + private MouseAdapter userInfoAdapter = new MouseAdapter() { + + public void mouseEntered(MouseEvent e) { + UserInfoLabel.this.setCursor(new Cursor(Cursor.HAND_CURSOR)); + }; + + @Override + public void mouseClicked(MouseEvent e) { + if(StringUtils.isNotEmpty(userName)){ + try { + Desktop.getDesktop().browse(new URI(BBSConstants.DEFAULT_URL)); + } catch (Exception exp) { + + } + return; + } + if(bbsLoginDialog == null){ + bbsLoginDialog = new BBSLoginDialog(DesignerContext.getDesignerFrame(),UserInfoLabel.this); + } + bbsLoginDialog.clearLoginInformation(); + bbsLoginDialog.setModal(true); + bbsLoginDialog.showWindow(); + } + + }; + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/bbs/UserInfoPane.java b/designer/src/com/fr/design/mainframe/bbs/UserInfoPane.java new file mode 100644 index 000000000..45593f2a6 --- /dev/null +++ b/designer/src/com/fr/design/mainframe/bbs/UserInfoPane.java @@ -0,0 +1,195 @@ +/** + * + */ +package com.fr.design.mainframe.bbs; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; + +import com.fr.base.FRContext; +import com.fr.design.DesignerEnvManager; +import com.fr.design.dialog.BasicPane; +import com.fr.design.mainframe.DesignerContext; +import com.fr.general.DateUtils; +import com.fr.general.FRLogger; +import com.fr.general.Inter; +import com.fr.stable.StringUtils; + + +/** + * @author neil + * + * @date: 2015-3-5-上午11:19:50 + */ +public class UserInfoPane extends BasicPane{ + + //默认未登录颜色 + private static final Color UN_LOGIN_BACKGROUND = new Color(210, 210, 210); + private static final Color LOGIN_BACKGROUND = new Color(184, 220, 242); + private static final int WIDTH = 104; + private static final int HEIGHT = 24; + + // 登录框弹出间隔时间 + private static final int LOGIN_DIFF_DAY = 7; + // 等待国际化等相关初始化工作完成之后再弹出登录框 + private static final int WAIT_TIME = 10000; + + private UserInfoLabel userInfoLabel; + private ExitLabel switchAccountLabel; + + + public UserInfoLabel getUserInfoLabel() { + return userInfoLabel; + } + + public void setUserInfoLabel(UserInfoLabel userInfoLabel) { + this.userInfoLabel = userInfoLabel; + } + + public ExitLabel getSwitchAccountLabel() { + return switchAccountLabel; + } + + public void setSwitchAccountLabel(ExitLabel switchAccountLabel) { + this.switchAccountLabel = switchAccountLabel; + } + + /** + * 构造函数 + */ + public UserInfoPane() { + this.setPreferredSize(new Dimension(WIDTH,HEIGHT)); + this.setLayout(new BorderLayout()); + + this.userInfoLabel = new UserInfoLabel(this); + this.switchAccountLabel = new ExitLabel(this); + + this.markUnSignIn(); + autoLogin(); + autoPushLoginDialog(); + + this.add(userInfoLabel, BorderLayout.CENTER); + this.add(switchAccountLabel, BorderLayout.EAST); + } + + // 后台自动登录 + private void autoLogin(){ + Thread bbsAutoLoginThread = new Thread(new Runnable() { + + @Override + public void run() { + String username = DesignerEnvManager.getEnvManager().getBBSName(); + String password = DesignerEnvManager.getEnvManager().getBBSPassword(); + if(!BBSLoginDialog.login(username, password)){ + markUnSignIn(); + }else{ + markSignIn(username); + } + } + }); + bbsAutoLoginThread.start(); + } + + // 计算xml保存的上次弹框时间和当前时间的时间差 + private int getDiffFromLastLogin(){ + String lastBBSTime = DesignerEnvManager.getEnvManager().getLastShowBBSTime(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + Date lastBBSDate = null; + try { + if(lastBBSTime != null){ + synchronized (this) { + lastBBSDate = sdf.parse(lastBBSTime); + } + Calendar calender = Calendar.getInstance(); + calender.setTime(lastBBSDate); + int dayOld = calender.get(Calendar.DAY_OF_YEAR); + calender.setTime(new Date()); + int dayNew = calender.get(Calendar.DAY_OF_YEAR); + return dayNew - dayOld; + } + } catch (ParseException e) { + FRLogger.getLogger().error(e.getMessage()); + } + return 1; + } + + private void autoPushLoginDialog(){ + Thread showBBSThread = new Thread(new Runnable() { + + @Override + public void run() { + try { + // 等国际化等加载完毕再启动线程弹出登录框 + Thread.sleep(WAIT_TIME); + if(!FRContext.isChineseEnv()){ + return; + } + + //七天弹一次, 如果xml中和当前时间相差小于7天, 就不弹了 + if(getDiffFromLastLogin() < LOGIN_DIFF_DAY){ + return; + } + + } catch (InterruptedException e) { + FRContext.getLogger().error(e.getMessage()); + } + + String userName = DesignerEnvManager.getEnvManager().getBBSName(); + if(StringUtils.isNotEmpty(userName)){ + return; + } + + BBSLoginDialog bbsLoginDialog = userInfoLabel.getBbsLoginDialog(); + if(bbsLoginDialog == null){ + bbsLoginDialog = new BBSLoginDialog(DesignerContext.getDesignerFrame(),userInfoLabel); + userInfoLabel.setBbsLoginDialog(bbsLoginDialog); + } + + bbsLoginDialog.showWindow(); + DesignerEnvManager.getEnvManager().setLastShowBBSTime(DateUtils.DATEFORMAT2.format(new Date())); + } + + }); + showBBSThread.start(); + } + + /** + * 标志未登录状态, 面板设置为灰色 + * + */ + public void markUnSignIn(){ + this.userInfoLabel.setText(Inter.getLocText("FR-Base_UnSignIn")); + this.switchAccountLabel.setVisible(false); + this.userInfoLabel.setOpaque(true); + this.userInfoLabel.setBackground(UN_LOGIN_BACKGROUND); + this.userInfoLabel.resetUserName(); + + } + + /** + * 标志登陆状态, 面包设置为蓝色 + * @param userName 用户名 + * + */ + public void markSignIn(String userName){ + this.userInfoLabel.setText(userName); + this.userInfoLabel.setUserName(userName); + this.switchAccountLabel.setVisible(true); + this.userInfoLabel.setOpaque(true); + this.userInfoLabel.setBackground(LOGIN_BACKGROUND); + this.switchAccountLabel.setOpaque(true); + this.switchAccountLabel.setBackground(LOGIN_BACKGROUND); + } + + @Override + protected String title4PopupWindow() { + return StringUtils.EMPTY; + } + + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/bbs/bbs.properties b/designer/src/com/fr/design/mainframe/bbs/bbs.properties new file mode 100644 index 000000000..44db03d46 --- /dev/null +++ b/designer/src/com/fr/design/mainframe/bbs/bbs.properties @@ -0,0 +1,19 @@ +#Created by JInto - www.guh-software.de +#Wed Apr 22 15:08:44 CST 2015 +COLLECT_URL=http://www.finereporthelp.com:8081/bbs/ReportServer?op=bbs&cmd=collect +DEFAULT_URL=http\://bbs.finereport.com/home.php?mod=space&do=notice +GET_MESSAGE_URL=http://feedback.finedevelop.com:3000/bbs/message/count +GET_SIGN_INFO_URL=http\://bbs.finereport.com +LINK0=http\://bbs.finereport.com/space-uid-55823.html +LINK1=http\://bbs.finereport.com/space-uid-56940.html +LINK2=http\://bbs.finereport.com/space-uid-51621.html +LINK3=http\://bbs.finereport.com/space-uid-52618.html +LINK4=http\://bbs.finereport.com/space-uid-48993.html +SHARE_URL=http\://bbs.finereport.com +USER0=\u6590\u6CE2\u90A3\u5951(\u5B59\u70B3\u6DA6) +USER1=deafire(\u674E\u5FD7\u4F1F) +USER2=\u963F\u8FEA(\u8C22\u8FEA) +USER3=bingjie(\u5F20\u8BB0\u82B1) +USER4=\u6D77\u7EF5\u5B9D\u5B9D(\u90DD\u6B63) +VERIFY_URL=http://www.finereporthelp.com:8081/bbs/ReportServer?op=bbs&cmd=verify +UPDATE_INFO_URL=http://bbs.finereport.com/source/plugin/infor/infor.html diff --git a/designer/src/com/fr/design/mainframe/bbs/images/switch.png b/designer/src/com/fr/design/mainframe/bbs/images/switch.png new file mode 100644 index 000000000..95ccd321e Binary files /dev/null and b/designer/src/com/fr/design/mainframe/bbs/images/switch.png differ diff --git a/designer/src/com/fr/design/mainframe/cell/CellElementEditPane.java b/designer/src/com/fr/design/mainframe/cell/CellElementEditPane.java new file mode 100644 index 000000000..78e0c00b0 --- /dev/null +++ b/designer/src/com/fr/design/mainframe/cell/CellElementEditPane.java @@ -0,0 +1,189 @@ +package com.fr.design.mainframe.cell; + +import java.awt.BorderLayout; +import java.awt.CardLayout; +import java.awt.Dimension; +import java.util.*; + +import javax.swing.Icon; +import javax.swing.JPanel; + +import com.fr.base.BaseUtils; +import com.fr.design.ExtraDesignClassManager; +import com.fr.design.fun.CellAttributeProvider; +import com.fr.design.gui.frpane.AttributeChangeListener; +import com.fr.design.gui.ibutton.UIHeadGroup; +import com.fr.design.gui.itabpane.TitleChangeListener; +import com.fr.design.mainframe.cell.settingpane.*; +import com.fr.design.dialog.BasicPane; +import com.fr.general.ComparatorUtils; +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.selection.CellSelection; +import com.fr.grid.selection.Selection; +import com.fr.report.cell.CellElement; +import com.fr.report.cell.DefaultTemplateCellElement; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.elementcase.TemplateElementCase; +import com.fr.design.utils.DesignUtils; + +/** + * the new 单元格属性表 !!!:只对当前选中的设置面板进行数据的populate和update操作 + * + * @author zhou + * @since 2012-5-8下午12:18:53 + */ +public class CellElementEditPane extends BasicPane { + private static int TIME_GAP = 80; + private List paneList; + private TemplateCellElement cellelement; + private ElementCasePane ePane; + private UIHeadGroup tabsHeaderIconPane; + + private boolean isEditing; + private int PaneListIndex; + private CardLayout card; + private JPanel center; + + private TitleChangeListener titleChangeListener = null; + + private CellAttributeProvider cellAttributeProvider = null; + + + public CellElementEditPane() { + setLayout(new BorderLayout()); + initPaneList(); + Icon[] iconArray = new Icon[paneList.size()]; + card = new CardLayout(); + center = new JPanel(card); + for (int i = 0; i < paneList.size(); i++) { + AbstractCellAttrPane pane = paneList.get(i); + iconArray[i] = BaseUtils.readIcon(pane.getIconPath()); + center.add(pane, pane.title4PopupWindow()); + } + + tabsHeaderIconPane = new UIHeadGroup(iconArray) { + @Override + public void tabChanged(int index) { + card.show(center, paneList.get(index).title4PopupWindow()); + paneList.get(index).populateBean(cellelement, ePane);// 设置面板变了,也要populate + paneList.get(index).addAttributeChangeListener(listener); + if (titleChangeListener != null) { + titleChangeListener.fireTitleChange(getSelectedTabName()); + } + } + }; + tabsHeaderIconPane.setNeedLeftRightOutLine(false); + this.add(tabsHeaderIconPane, BorderLayout.NORTH); + this.add(center, BorderLayout.CENTER); + } + + + public void setSelectedIndex(String... id) { + String firstid = id[0]; + for (int i = 0; i < paneList.size(); i++) { + if (ComparatorUtils.equals(firstid, paneList.get(i).title4PopupWindow())) { + tabsHeaderIconPane.setSelectedIndex(i); + if (id.length == 2) { + paneList.get(i).setSelectedByIds(1, id); + } + break; + } + } + } + + public void populate(ElementCasePane elementCasePane) { + if (isEditing) { + isEditing = false; + return; + } + if (elementCasePane == null) { + return; + } + this.ePane = elementCasePane; + Selection selection = ePane.getSelection(); + final TemplateElementCase elementCase = ePane.getEditingElementCase(); + if (elementCase != null && selection instanceof CellSelection) { + CellSelection cs = (CellSelection) selection; + // isSelectedOneCell()方法放在外面这儿一起算,因为它是比较耗时间的 + // 如果直接只传递elementCasePane,那么每个AbstratCellAttrPane都要算一次,很浪费时间 + + CellElement cellElement = elementCase.getCellElement(cs.getColumn(), cs.getRow()); + if (cellElement == null) { + cellElement = new DefaultTemplateCellElement(cs.getColumn(), cs.getRow()); + //默认选中的是A1单元格,所以若是A1单元格没有加到列表时要加上,否则在聚合报表时会出错 + if (cs.isSelectedOneCell(elementCasePane) && (cs.getColumn() + cs.getRow() == 0)) { + elementCase.addCellElement((TemplateCellElement) cellElement); + } + } + + cellelement = (TemplateCellElement) cellElement; + // 这儿只对当前选中的面板populate + paneList.get(tabsHeaderIconPane.getSelectedIndex()).populateBean(cellelement, ePane); + paneList.get(tabsHeaderIconPane.getSelectedIndex()).addAttributeChangeListener(listener); + } + } + + AttributeChangeListener listener = new AttributeChangeListener() { + @Override + public void attributeChange() { + boolean isChooseFatherPane = ComparatorUtils.equals(paneList.get(tabsHeaderIconPane.getSelectedIndex()).getGlobalName(), Inter.getLocText("FR-Designer_LeftParent")) || + ComparatorUtils.equals(paneList.get(tabsHeaderIconPane.getSelectedIndex()).getGlobalName(), Inter.getLocText("ExpandD-Up_Father_Cell")); + boolean isChooseExpandPane = ComparatorUtils.equals(paneList.get(tabsHeaderIconPane.getSelectedIndex()).getGlobalName(), Inter.getLocText("ExpandD-Expand_Direction")); + if (isChooseExpandPane || isChooseFatherPane) { + ePane.setSupportDefaultParentCalculate(true); + } + + if (ePane.getSelection() instanceof CellSelection) { + isEditing = true; + if (ePane.isSelectedOneCell()) { + paneList.get(tabsHeaderIconPane.getSelectedIndex()).updateBean(); + ePane.fireTargetModified(); + } else { + paneList.get(tabsHeaderIconPane.getSelectedIndex()).updateBeans(); + ePane.fireTargetModified(); + } + } else { + DesignUtils.errorMessage(Inter.getLocText(new String[]{"Not_use_a_cell_attribute_table_editing", "M_Insert-Float"}) + "!"); + } + ePane.setSupportDefaultParentCalculate(false); + } + }; + + public String getSelectedTabName() { + return paneList.get(tabsHeaderIconPane.getSelectedIndex()).title4PopupWindow(); + } + + /** + * 添加TitleChangeListener + * + * @param titleChangeListener titleChangeListener 监听 + */ + public void addTitleChangeListner(TitleChangeListener titleChangeListener) { + this.titleChangeListener = titleChangeListener; + } + + @Override + protected String title4PopupWindow() { + return Inter.getLocText("CellElement-Property_Table"); + } + + @Override + public Dimension getPreferredSize() { + return new Dimension(240, 340); + } + + private void initPaneList() { + paneList = new ArrayList(); + paneList.add(new CellExpandAttrPane()); + paneList.add(new CellStylePane()); + paneList.add(new CellPresentPane()); + paneList.add(new CellOtherSetPane()); + + cellAttributeProvider = ExtraDesignClassManager.getInstance().getCelllAttributeProvider(); + if (cellAttributeProvider != null){ + paneList.add((AbstractCellAttrPane) cellAttributeProvider.createCellAttributePane()); + } + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/cell/QuickEditorRegion.java b/designer/src/com/fr/design/mainframe/cell/QuickEditorRegion.java new file mode 100644 index 000000000..7ac79975a --- /dev/null +++ b/designer/src/com/fr/design/mainframe/cell/QuickEditorRegion.java @@ -0,0 +1,57 @@ +package com.fr.design.mainframe.cell; + +import java.awt.BorderLayout; + +import javax.swing.BorderFactory; +import javax.swing.JPanel; + +import com.fr.design.gui.ilable.UILabel; +import com.fr.general.Inter; +import com.fr.design.selection.QuickEditor; + +/** + * QuickEditorRegion + * + * @editor zhou + * @since 2012-3-23下午3:21:36 + */ + +public class QuickEditorRegion extends JPanel { + + public static QuickEditorRegion getInstance() { + return singleton; + } + + public static JPanel getEmptyEditor() { + if(EMPTY == null) { + EMPTY = new JPanel(new BorderLayout()); + UILabel content = new UILabel(Inter.getLocText(new String[]{"DataFunction-None", "HJS-Message", "Form-Widget_Property_Table"})+"!"); + content.setBorder(BorderFactory.createEmptyBorder(0, 70, 0, 0)); + EMPTY.add(content, BorderLayout.CENTER); + } + return EMPTY; + } + + private static QuickEditorRegion singleton = new QuickEditorRegion(); + private static JPanel EMPTY; + + private QuickEditorRegion() { + this.setLayout(new BorderLayout()); + } + + /** + * 传值 + * + * @param ePane + */ + public void populate(final QuickEditor quickEditor) { + this.removeAll(); + if(quickEditor.getComponentCount() == 0) { + this.add(getEmptyEditor(), BorderLayout.CENTER); + } else { + this.add(quickEditor, BorderLayout.CENTER); + } + validate(); + repaint(); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/cell/settingpane/AbstractCellAttrPane.java b/designer/src/com/fr/design/mainframe/cell/settingpane/AbstractCellAttrPane.java new file mode 100644 index 000000000..5808ad0bb --- /dev/null +++ b/designer/src/com/fr/design/mainframe/cell/settingpane/AbstractCellAttrPane.java @@ -0,0 +1,51 @@ +package com.fr.design.mainframe.cell.settingpane; + +import com.fr.design.mainframe.AbstractAttrPane; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.selection.CellSelection; +import com.fr.grid.selection.FloatSelection; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.elementcase.TemplateElementCase; + +/** + * 单元格属性表的每个tab对应的pane,已经实现了滚动条功能,如果页面装不下,会自动出来 + * 几点:子类不需要写构造函数了,所有的组件都放在createContentPane()方法生成的pane里面,它不需要考虑border。 + * + * @author zhou + * @since 2012-5-11下午4:02:18 + */ +public abstract class AbstractCellAttrPane extends AbstractAttrPane { + protected TemplateCellElement cellElement; + protected ElementCasePane elementCasePane; + protected CellSelection cs; + + protected abstract void populateBean(); + + public abstract void updateBeans(); + + public abstract void updateBean(TemplateCellElement cellElement); + + public void populateBean(TemplateCellElement cellElement, ElementCasePane epane) { + if (epane == null || cellElement == null) { + return; + } + removeAttributeChangeListener(); + this.cellElement = cellElement; + elementCasePane = epane; + if (elementCasePane.getSelection() instanceof FloatSelection) { + return; + } + //august:这边必须保存一个CellSelection的镜像,因为单元格属性的某些操作可能使得CellSelection发生变化,那么elementCasePane.getSelection()获取的就不是准确的了 + cs = (CellSelection) elementCasePane.getSelection(); + populateBean(); + } + + /** + * 分成两个方法的意义在于,这个面板如果是个对话框,那么可以传cellElement进来update, 方便重复使用面板 为了对话框做准备 + */ + public void updateBean() { + updateBean(this.cellElement); + TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); + elementCase.addCellElement(cellElement); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/cell/settingpane/CellExpandAttrPane.java b/designer/src/com/fr/design/mainframe/cell/settingpane/CellExpandAttrPane.java new file mode 100644 index 000000000..1b95b8569 --- /dev/null +++ b/designer/src/com/fr/design/mainframe/cell/settingpane/CellExpandAttrPane.java @@ -0,0 +1,200 @@ +package com.fr.design.mainframe.cell.settingpane; + +import com.fr.base.BaseUtils; +import com.fr.design.constants.LayoutConstants; +import com.fr.design.expand.ExpandLeftFatherPane; +import com.fr.design.expand.ExpandUpFatherPane; +import com.fr.design.expand.SortExpandAttrPane; +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.general.ComparatorUtils; +import com.fr.general.Inter; +import com.fr.report.cell.DefaultTemplateCellElement; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.cell.cellattr.CellExpandAttr; +import com.fr.report.elementcase.TemplateElementCase; +import com.fr.stable.Constants; + +import javax.swing.*; +import java.awt.*; + +/** + * 单元格扩展属性面板,是属性表面板的一个种类 + */ +public class CellExpandAttrPane extends AbstractCellAttrPane { + private UIButtonGroup expandDirectionButton; + private ExpandLeftFatherPane leftFatherPane; + private ExpandUpFatherPane rightFatherPane; + private UICheckBox horizontalExpandableCheckBox; + private UICheckBox verticalExpandableCheckBox; + private SortExpandAttrPane sortAfterExpand; + + /** + * + * @return + */ + public JPanel createContentPane() { + String[] nameArray = {Inter.getLocText("ExpandD-Not_Expand"), Inter.getLocText("Utils-Top_to_Bottom"), Inter.getLocText("Utils-Left_to_Right")}; + Icon[] iconArray = { + BaseUtils.readIcon("/com/fr/design/images/expand/none16x16.png"), + BaseUtils.readIcon("/com/fr/design/images/expand/vertical.png"), + BaseUtils.readIcon("/com/fr/design/images/expand/landspace.png") + }; + Byte[] valueArray = {Constants.NONE, Constants.TOP_TO_BOTTOM, Constants.LEFT_TO_RIGHT}; + expandDirectionButton = new UIButtonGroup(iconArray, valueArray); + expandDirectionButton.setAllToolTips(nameArray); + leftFatherPane = new ExpandLeftFatherPane(); + rightFatherPane = new ExpandUpFatherPane(); + horizontalExpandableCheckBox = new UICheckBox(Inter.getLocText("ExpandD-Horizontal_Extendable")); + verticalExpandableCheckBox = new UICheckBox(Inter.getLocText("ExpandD-Vertical_Extendable")); + sortAfterExpand = new SortExpandAttrPane(); + initAllNames(); + return layoutPane(); + } + + + private void initAllNames() { + expandDirectionButton.setGlobalName(Inter.getLocText("ExpandD-Expand_Direction")); + leftFatherPane.setGlobalName(Inter.getLocText("LeftParent")); + rightFatherPane.setGlobalName(Inter.getLocText("ExpandD-Up_Father_Cell")); + horizontalExpandableCheckBox.setGlobalName(Inter.getLocText("ExpandD-Expandable")); + verticalExpandableCheckBox.setGlobalName(Inter.getLocText("ExpandD-Expandable")); + } + + private JPanel layoutPane() { + double f = TableLayout.FILL; + double p = TableLayout.PREFERRED; + Component[][] components = new Component[][]{ + new Component[]{new UILabel(Inter.getLocText("ExpandD-Expand_Direction") + ":", SwingConstants.RIGHT), expandDirectionButton}, + new Component[]{new UILabel(Inter.getLocText("LeftParent") + ":", SwingConstants.RIGHT), leftFatherPane}, + new Component[]{new UILabel(Inter.getLocText("ExpandD-Up_Father_Cell") + ":", SwingConstants.RIGHT), rightFatherPane}, + new Component[]{new JSeparator(), null}, + new Component[]{new UILabel(Inter.getLocText("ExpandD-Expandable") + ":", SwingConstants.RIGHT), horizontalExpandableCheckBox}, + new Component[]{null, verticalExpandableCheckBox}, + new Component[]{new UILabel(Inter.getLocText("ExpandD-Sort_After_Expand") + ":", SwingConstants.RIGHT), sortAfterExpand}, + }; + double[] rowSize = {p, p, p, p, p, p, p, p, p, p, p, p, p}; + double[] columnSize = {p, f}; + int[][] rowCount = {{1, 1}, {1, 3}, {1, 3}, {1, 1}, {1, 1}, {1, 1}, {1, 3}}; + return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); + } + + + @Override + protected void populateBean() { + this.leftFatherPane.setElementCasePane(elementCasePane); + this.rightFatherPane.setElementCasePane(elementCasePane); + CellExpandAttr cellExpandAttr = cellElement.getCellExpandAttr(); + if (cellExpandAttr == null) { + cellExpandAttr = new CellExpandAttr(); + cellElement.setCellExpandAttr(cellExpandAttr); + } + expandDirectionButton.setSelectedItem(cellExpandAttr.getDirection()); + this.leftFatherPane.populate(cellExpandAttr); + this.rightFatherPane.populate(cellExpandAttr); + switch (cellExpandAttr.getExtendable()) { + case CellExpandAttr.Both_EXTENDABLE: + horizontalExpandableCheckBox.setSelected(true); + verticalExpandableCheckBox.setSelected(true); + break; + case CellExpandAttr.Vertical_EXTENDABLE: + horizontalExpandableCheckBox.setSelected(false); + verticalExpandableCheckBox.setSelected(true); + break; + case CellExpandAttr.Horizontal_EXTENDABLE: + horizontalExpandableCheckBox.setSelected(true); + verticalExpandableCheckBox.setSelected(false); + break; + default: { + horizontalExpandableCheckBox.setSelected(false); + verticalExpandableCheckBox.setSelected(false); + } + } + + sortAfterExpand.populate(cellExpandAttr); + } + + + @Override + public String getIconPath() { + return "com/fr/design/images/expand/cellAttr.gif"; + } + + @Override + public void updateBean(TemplateCellElement cellElement) { + CellExpandAttr cellExpandAttr = cellElement.getCellExpandAttr(); + if (cellExpandAttr == null) { + cellExpandAttr = new CellExpandAttr(); + cellElement.setCellExpandAttr(cellExpandAttr); + } + if (ComparatorUtils.equals(getGlobalName(), Inter.getLocText("ExpandD-Expand_Direction"))) { + cellExpandAttr.setDirection(expandDirectionButton.getSelectedItem()); + } + if (ComparatorUtils.equals(getGlobalName(), Inter.getLocText("LeftParent"))) { + this.leftFatherPane.update(cellExpandAttr); + } + if (ComparatorUtils.equals(getGlobalName(), Inter.getLocText("ExpandD-Up_Father_Cell"))) { + this.rightFatherPane.update(cellExpandAttr); + } + + + // extendable + if (ComparatorUtils.equals(getGlobalName(), Inter.getLocText("ExpandD-Expandable"))) { + if (horizontalExpandableCheckBox.isSelected()) { + if (verticalExpandableCheckBox.isSelected()) { + cellExpandAttr.setExtendable(CellExpandAttr.Both_EXTENDABLE); + } else { + cellExpandAttr.setExtendable(CellExpandAttr.Horizontal_EXTENDABLE); + } + } else { + if (verticalExpandableCheckBox.isSelected()) { + cellExpandAttr.setExtendable(CellExpandAttr.Vertical_EXTENDABLE); + } else { + cellExpandAttr.setExtendable(CellExpandAttr.None_EXTENDABLE); + } + } + } + + if (ComparatorUtils.equals(getGlobalName(), Inter.getLocText("ExpandD-Sort_After_Expand"))) { + sortAfterExpand.update(cellExpandAttr); + } + + } + + /** + * + */ + public void updateBeans() { + TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); + int cellRectangleCount = cs.getCellRectangleCount(); + for (int rect = 0; rect < cellRectangleCount; rect++) { + Rectangle cellRectangle = cs.getCellRectangle(rect); + // 需要先行后列地增加新元素。 + for (int j = 0; j < cellRectangle.height; j++) { + for (int i = 0; i < cellRectangle.width; i++) { + int column = i + cellRectangle.x; + int row = j + cellRectangle.y; + TemplateCellElement cellElement = elementCase.getTemplateCellElement(column, row); + if (cellElement == null) { + cellElement = new DefaultTemplateCellElement(column, row); + elementCase.addCellElement(cellElement); + } + updateBean(cellElement); + } + } + } + } + + /** + * + * @return + */ + public String title4PopupWindow() { + return Inter.getLocText("ExpandD-Expand_Attribute"); + } + + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/cell/settingpane/CellOtherSetPane.java b/designer/src/com/fr/design/mainframe/cell/settingpane/CellOtherSetPane.java new file mode 100644 index 000000000..ffeaae0d9 --- /dev/null +++ b/designer/src/com/fr/design/mainframe/cell/settingpane/CellOtherSetPane.java @@ -0,0 +1,398 @@ +package com.fr.design.mainframe.cell.settingpane; + +import java.awt.*; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; + +import com.fr.design.file.HistoryTemplateListPane; +import com.fr.design.gui.ilable.UILabel; + +import javax.swing.JPanel; +import javax.swing.JSeparator; +import javax.swing.SwingConstants; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +import com.fr.design.gui.ibutton.UIButtonGroup; +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.TableLayout; +import com.fr.design.layout.TableLayoutHelper; +import com.fr.design.mainframe.JTemplate; +import com.fr.design.editor.ValueEditorPane; +import com.fr.design.editor.ValueEditorPaneFactory; +import com.fr.general.ComparatorUtils; +import com.fr.general.Inter; +import com.fr.report.cell.DefaultTemplateCellElement; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.cell.cellattr.CellGUIAttr; +import com.fr.report.cell.cellattr.CellInsertPolicyAttr; +import com.fr.report.cell.cellattr.CellPageAttr; +import com.fr.report.elementcase.TemplateElementCase; + +/** + * @author zhou + * @since 2012-5-11下午5:24:31 + */ +public class CellOtherSetPane extends AbstractCellAttrPane { + // normal + private UIButtonGroup autoshrik; + + private UICheckBox previewCellContent; + private UICheckBox printAndExportContent; + private UICheckBox printAndExportBackground; + + private UIComboBox showContent; + + private UITextField tooltipTextField; + + private UITextField fileNameTextField; + + // 分页 + private UICheckBox pageBeforeRowCheckBox; + private UICheckBox pageAfterRowCheckBox; + private UICheckBox pageBeforeColumnCheckBox; + private UICheckBox pageAfterColumnCheckBox; + + private UICheckBox canBreakOnPaginateCheckBox; + private UICheckBox repeatCheckBox; + + // 插入行策略 + private UIButtonGroup insertRowPolicy; + private ValueEditorPane valueEditor; + + private JPanel southContentPane; + private JPanel defaultValuePane; + + /** + * 初始化 + * @return 面板 + */ + public JPanel createContentPane() { + final JPanel fileNamePane = createNormal(); + createOthers(); + double f = TableLayout.FILL; + double p = TableLayout.PREFERRED; + double[] rowSize1 = {p, p, p, p, p, p, p}; + double[] columnSize1 = {p, f}; + UILabel autoAdjustLabel = new UILabel(Inter.getLocText("Auto_Adjust_Size") + ":", SwingConstants.RIGHT); + autoAdjustLabel.setVerticalAlignment(UILabel.TOP); + Component[][] components1 = new Component[][]{ + new Component[]{autoAdjustLabel, autoshrik}, + new Component[]{new UILabel(Inter.getLocText("Preview") + ":", SwingConstants.RIGHT), previewCellContent}, + new Component[]{new UILabel(Inter.getLocText("CellWrite-Print_Export") + ":", SwingConstants.RIGHT), printAndExportContent}, + new Component[]{null, printAndExportBackground}, + new Component[]{new UILabel(Inter.getLocText("Show_Content") + ":", SwingConstants.RIGHT), showContent}, + new Component[]{null, fileNamePane}, + new Component[]{new UILabel(Inter.getLocText("CellWrite-ToolTip") + ":", SwingConstants.RIGHT), tooltipTextField}, + }; + JPanel northContentPane = TableLayoutHelper.createTableLayoutPane(components1, rowSize1, columnSize1); + double[] rowSize2 = {p, p, p, p, p, p}; + double[] columnSize2 = {p, f}; + Component[][] components2 = new Component[][]{ + new Component[]{new JSeparator(JSeparator.HORIZONTAL), null}, + new Component[]{new UILabel(Inter.getLocText("Pagination")), null}, + new Component[]{pageBeforeRowCheckBox, pageAfterRowCheckBox}, + new Component[]{pageBeforeColumnCheckBox, pageAfterColumnCheckBox}, + new Component[]{canBreakOnPaginateCheckBox, null}, + new Component[]{repeatCheckBox, null} + }; + JPanel centerContentPane = TableLayoutHelper.createTableLayoutPane(components2, rowSize2, columnSize2); + double[] rowSize3 = {p, p, p, p}; + double[] columnSize3 = {f}; + Component[][] components3 = new Component[][]{ + new Component[]{new JSeparator(JSeparator.HORIZONTAL)}, + new Component[]{new UILabel(Inter.getLocText("CellWrite-InsertRow_Policy"), SwingConstants.LEFT)}, + new Component[]{insertRowPolicy}, + new Component[]{defaultValuePane} + }; + southContentPane = TableLayoutHelper.createTableLayoutPane(components3, rowSize3, columnSize3); + JPanel contentsmallPane = new JPanel(new BorderLayout(0, 10)); + contentsmallPane.add(northContentPane, BorderLayout.NORTH); + contentsmallPane.add(centerContentPane, BorderLayout.CENTER); + JPanel contentPane = new JPanel(new BorderLayout(0, 10)); + contentPane.add(contentsmallPane, BorderLayout.NORTH); + contentPane.add(southContentPane, BorderLayout.CENTER); + initAllNames(); + return contentPane; + } + + + private JPanel createNormal() { + String[] AjustRowTypes = new String[]{ + Inter.getLocText("No"), Inter.getLocText("Utils-Row_Height"), Inter.getLocText("Utils-Column_Width"), Inter.getLocText("Default")}; + autoshrik = new UIButtonGroup(AjustRowTypes); + autoshrik.setTwoLine(); + autoshrik.setLayout(new GridLayout(2, 2, 1, 1)); + + previewCellContent = new UICheckBox(Inter.getLocText("CellWrite-Preview_Cell_Content")); + printAndExportContent = new UICheckBox(Inter.getLocText("CellWrite-Print_Content")); + printAndExportBackground = new UICheckBox(Inter.getLocText("CellWrite-Print_Background")); + + showContent = new UIComboBox(new String[]{Inter.getLocText("Default"), Inter.getLocText("CellWrite-Show_As_Image"), Inter.getLocText("CellWrite-Show_As_HTML"), + Inter.getLocText("ShowAsDownload")}); + final CardLayout fileNameLayout = new CardLayout(); + final JPanel fileNamePane = new JPanel(fileNameLayout); + JPanel fileNameCCPane = new JPanel(new BorderLayout(4, 0)); + + fileNameCCPane.add(new UILabel(Inter.getLocText("FileNameForDownload")), BorderLayout.WEST); + fileNameTextField = new UITextField(); + + tooltipTextField = new UITextField(); + tooltipTextField.getUI(); + fileNamePane.add(new JPanel(), "none"); + fileNamePane.add(fileNameCCPane, "content"); + fileNameCCPane.add(fileNameTextField, BorderLayout.CENTER); + + showContent.addItemListener(new ItemListener() { + + @Override + public void itemStateChanged(ItemEvent e) { + fileNameLayout.show(fileNamePane, showContent.getSelectedIndex() == 3 ? "content" : "none"); + } + }); + + tooltipTextField = new UITextField(); + tooltipTextField.getUI(); + return fileNamePane; + } + + private void createOthers() { + // 分页 + pageBeforeRowCheckBox = new UICheckBox(Inter.getLocText("CellWrite-Page_Before_Row")); + pageAfterRowCheckBox = new UICheckBox(Inter.getLocText("CellWrite-Page_After_Row")); + pageBeforeColumnCheckBox = new UICheckBox(Inter.getLocText("CellWrite-Page_Before_Column")); + pageAfterColumnCheckBox = new UICheckBox(Inter.getLocText("CellWrite-Page_After_Column")); + + canBreakOnPaginateCheckBox = new UICheckBox(Inter.getLocText("CellPage-Can_Break_On_Paginate")); + repeatCheckBox = new UICheckBox(Inter.getLocText("CellWrite-Repeat_Content_When_Paging")); + + // 插入行策略 + insertRowPolicy = new UIButtonGroup(new String[]{Inter.getLocText("CellWrite-InsertRow_NULL"), Inter.getLocText("CellWrite-InsertRow_DEFAULT"), + Inter.getLocText("CellWrite-InsertRow_COPY")}); + defaultValuePane = new JPanel(new BorderLayout(4, 0)); + valueEditor = ValueEditorPaneFactory.createBasicValueEditorPane(); + defaultValuePane.add(valueEditor, BorderLayout.CENTER); + defaultValuePane.setVisible(false); + + insertRowPolicy.addChangeListener(new ChangeListener() { + @Override + public void stateChanged(ChangeEvent e) { + defaultValuePane.setVisible(insertRowPolicy.getSelectedIndex() == 1); + } + }); + + } + + private void initAllNames() { + autoshrik.setGlobalName(Inter.getLocText("Auto_Adjust_Size")); + previewCellContent.setGlobalName(Inter.getLocText("Preview")); + printAndExportContent.setGlobalName(Inter.getLocText("CellWrite-Preview_Cell_Content")); + printAndExportBackground.setGlobalName(Inter.getLocText("CellWrite-Print_Background")); + showContent.setGlobalName(Inter.getLocText("Show_Content")); + fileNameTextField.setGlobalName(Inter.getLocText("Show_Content")); + tooltipTextField.setGlobalName(Inter.getLocText("CellWrite-ToolTip")); + pageBeforeRowCheckBox.setGlobalName(Inter.getLocText("CellWrite-Page_Before_Row")); + pageAfterRowCheckBox.setGlobalName(Inter.getLocText("CellWrite-Page_After_Row")); + pageBeforeColumnCheckBox.setGlobalName(Inter.getLocText("CellWrite-Page_Before_Column")); + pageAfterColumnCheckBox.setGlobalName(Inter.getLocText("CellWrite-Page_After_Column")); + canBreakOnPaginateCheckBox.setGlobalName(Inter.getLocText("CellPage-Can_Break_On_Paginate")); + repeatCheckBox.setGlobalName(Inter.getLocText("CellWrite-Repeat_Content_When_Paging")); + insertRowPolicy.setGlobalName(Inter.getLocText("CellWrite-InsertRow_Policy")); + valueEditor.setGlobalName(Inter.getLocText("CellWrite-InsertRow_Policy")); + } + + + @Override + public String getIconPath() { + return "com/fr/design/images/m_format/cellstyle/otherset.png"; + } + + @Override + protected void populateBean() { + CellGUIAttr cellGUIAttr = cellElement.getCellGUIAttr(); + if (cellGUIAttr == null) { + cellGUIAttr = CellGUIAttr.DEFAULT_CELLGUIATTR; + } + autoshrik.setSelectedIndex(cellGUIAttr.getAdjustMode()); + previewCellContent.setSelected(cellGUIAttr.isPreviewContent()); + printAndExportContent.setSelected(cellGUIAttr.isPrintContent()); + printAndExportBackground.setSelected(cellGUIAttr.isPrintBackground()); + if (cellGUIAttr.isShowAsImage()) { + showContent.setSelectedItem(Inter.getLocText("CellWrite-Show_As_Image")); + } else if (cellGUIAttr.isShowAsHTML()) { + showContent.setSelectedItem(Inter.getLocText("CellWrite-Show_As_HTML")); + } else if (cellGUIAttr.isShowAsDownload()) { + showContent.setSelectedItem(Inter.getLocText("ShowAsDownload")); + fileNameTextField.setText(cellGUIAttr.getFileName()); + } else { + showContent.setSelectedItem(Inter.getLocText("Default")); + } + tooltipTextField.setText(cellGUIAttr.getTooltipText()); + CellPageAttr cellPageAttr = cellElement.getCellPageAttr(); // 分页 + if (cellPageAttr == null) { + cellPageAttr = new CellPageAttr(); + } + this.pageBeforeRowCheckBox.setSelected(cellPageAttr.isPageBeforeRow()); + this.pageBeforeColumnCheckBox.setSelected(cellPageAttr.isPageBeforeColumn()); + this.pageAfterRowCheckBox.setSelected(cellPageAttr.isPageAfterRow()); + this.pageAfterColumnCheckBox.setSelected(cellPageAttr.isPageAfterColumn()); + this.canBreakOnPaginateCheckBox.setSelected(cellPageAttr.isCanBreakOnPaginate()); + this.repeatCheckBox.setSelected(cellPageAttr.isRepeat()); + CellInsertPolicyAttr cellInsertPolicyAttr = cellElement.getCellInsertPolicyAttr();// 插入 + if (cellInsertPolicyAttr == null) { + cellInsertPolicyAttr = new CellInsertPolicyAttr(); + } + if (ComparatorUtils.equals(CellInsertPolicyAttr.INSERT_POLICY_COPY, cellInsertPolicyAttr.getInsertPolicy())) { + insertRowPolicy.setSelectedIndex(2); + } else if (ComparatorUtils.equals(CellInsertPolicyAttr.INSERT_POLICY_DEFAULT, cellInsertPolicyAttr.getInsertPolicy())) { + insertRowPolicy.setSelectedIndex(1); + Object defaultValue = cellInsertPolicyAttr.getDefaultInsertValue(); + this.valueEditor.populate(defaultValue); + } else { + insertRowPolicy.setSelectedIndex(0); + } + defaultValuePane.setVisible(insertRowPolicy.getSelectedIndex() == 1); + southContentPane.setVisible(true); + JTemplate jTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); + if (!jTemplate.isJWorkBook()){ //表单中报表块编辑屏蔽掉 插入行策略 + southContentPane.setVisible(false); + } + } + + /** + * @param cellElement + */ + public void updateBean(TemplateCellElement cellElement) { + String fieldName = null; + CellGUIAttr cellNullGUIAttr = null; + CellGUIAttr cellGUIAttr = cellElement.getCellGUIAttr(); + if (cellGUIAttr == null) { + cellGUIAttr = new CellGUIAttr(); + } + + if (ComparatorUtils.equals(getGlobalName(), Inter.getLocText("Auto_Adjust_Size"))) { + cellGUIAttr.setAdjustMode(autoshrik.getSelectedIndex()); + } + + if (ComparatorUtils.equals(getGlobalName(), Inter.getLocText("Preview"))) { + cellGUIAttr.setPreviewContent(previewCellContent.isSelected()); + } + + if (ComparatorUtils.equals(getGlobalName(), Inter.getLocText("CellWrite-Preview_Cell_Content"))) { + cellGUIAttr.setPrintContent(printAndExportContent.isSelected()); + } + + if (ComparatorUtils.equals(getGlobalName(), Inter.getLocText("CellWrite-Print_Background"))) { + cellGUIAttr.setPrintBackground(printAndExportBackground.isSelected()); + } + + if (ComparatorUtils.equals(getGlobalName(), Inter.getLocText("Show_Content"))) { + cellGUIAttr.setShowAsDefault(showContent.getSelectedIndex() == 0); + cellGUIAttr.setShowAsImage(showContent.getSelectedIndex() == 1); + cellGUIAttr.setShowAsHTML(showContent.getSelectedIndex() == 2); + cellGUIAttr.setShowAsDownload(showContent.getSelectedIndex() == 3); + if (fileNameTextField.getText() == null || fileNameTextField.getText().trim().length() <= 0) { + cellGUIAttr.setFileName(fieldName); + } else if (showContent.getSelectedIndex() == 3) { + cellGUIAttr.setFileName(fileNameTextField.getText()); + } + } + + if (ComparatorUtils.equals(getGlobalName(), Inter.getLocText("CellWrite-ToolTip"))) { + if (tooltipTextField.getText() == null || tooltipTextField.getText().trim().length() <= 0) { + cellGUIAttr.setTooltipText(fieldName); + } else { + cellGUIAttr.setTooltipText(tooltipTextField.getText()); + } + } + // 如果与默认的CellGUIAttr相同,就不用保存这个属性了 + if (ComparatorUtils.equals(cellGUIAttr, CellGUIAttr.DEFAULT_CELLGUIATTR)) { + cellElement.setCellGUIAttr(cellNullGUIAttr); + } else { + cellElement.setCellGUIAttr(cellGUIAttr); + } + updatePageAttr(cellElement); + } + + + private void updatePageAttr(TemplateCellElement cellElement) { + + // 分页属性 + CellPageAttr cellPageAttr = cellElement.getCellPageAttr(); + if (cellPageAttr == null) { + cellPageAttr = new CellPageAttr(); + } + + if (ComparatorUtils.equals(getGlobalName(), Inter.getLocText("CellWrite-Page_Before_Row"))) { + cellPageAttr.setPageBeforeRow(this.pageBeforeRowCheckBox.isSelected()); + } + if (ComparatorUtils.equals(getGlobalName(), Inter.getLocText("CellWrite-Page_After_Row"))) { + cellPageAttr.setPageAfterRow(this.pageAfterRowCheckBox.isSelected()); + } + if (ComparatorUtils.equals(getGlobalName(), Inter.getLocText("CellWrite-Page_Before_Column"))) { + cellPageAttr.setPageBeforeColumn(this.pageBeforeColumnCheckBox.isSelected()); + } + if (ComparatorUtils.equals(getGlobalName(), Inter.getLocText("CellWrite-Page_After_Column"))) { + cellPageAttr.setPageAfterColumn(this.pageAfterColumnCheckBox.isSelected()); + } + if (ComparatorUtils.equals(getGlobalName(), Inter.getLocText("CellPage-Can_Break_On_Paginate"))) { + cellPageAttr.setCanBreakOnPaginate(canBreakOnPaginateCheckBox.isSelected()); + } + if (ComparatorUtils.equals(getGlobalName(), Inter.getLocText("CellWrite-Repeat_Content_When_Paging"))) { + cellPageAttr.setRepeat(this.repeatCheckBox.isSelected()); + } + + cellElement.setCellPageAttr(cellPageAttr); + + if (ComparatorUtils.equals(getGlobalName(), Inter.getLocText("CellWrite-InsertRow_Policy"))) { + // 插入 + CellInsertPolicyAttr cellInsertPolicyAttr = new CellInsertPolicyAttr(); + + if (insertRowPolicy.getSelectedIndex() == 2) { + cellInsertPolicyAttr.setInsertPolicy(CellInsertPolicyAttr.INSERT_POLICY_COPY); + } else if (insertRowPolicy.getSelectedIndex() == 1) { + cellInsertPolicyAttr.setInsertPolicy(CellInsertPolicyAttr.INSERT_POLICY_DEFAULT); + Object value = valueEditor.update(); + cellInsertPolicyAttr.setDefaultInsertValue(value); + } else { + cellInsertPolicyAttr.setInsertPolicy(CellInsertPolicyAttr.INSERT_POLICY_NULL); + } + cellElement.setCellInsertPolicyAttr(cellInsertPolicyAttr); + } + } + + /** + *存储 + */ + public void updateBeans() { + TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); + int cellRectangleCount = cs.getCellRectangleCount(); + for (int rect = 0; rect < cellRectangleCount; rect++) { + Rectangle cellRectangle = cs.getCellRectangle(rect); + // 需要先行后列地增加新元素。 + for (int j = 0; j < cellRectangle.height; j++) { + for (int i = 0; i < cellRectangle.width; i++) { + int column = i + cellRectangle.x; + int row = j + cellRectangle.y; + TemplateCellElement cellElement = elementCase.getTemplateCellElement(column, row); + if (cellElement == null) { + cellElement = new DefaultTemplateCellElement(column, row); + elementCase.addCellElement(cellElement); + } + updateBean(cellElement); + } + } + } + } + + /** + * 返回界面的标题 + * @return 标题 + */ + public String title4PopupWindow() { + return Inter.getLocText("Datasource-Other_Attributes"); + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/cell/settingpane/CellPresentPane.java b/designer/src/com/fr/design/mainframe/cell/settingpane/CellPresentPane.java new file mode 100644 index 000000000..0c357e30d --- /dev/null +++ b/designer/src/com/fr/design/mainframe/cell/settingpane/CellPresentPane.java @@ -0,0 +1,117 @@ +package com.fr.design.mainframe.cell.settingpane; + +import com.fr.base.present.Present; +import com.fr.design.present.PresentPane; +import com.fr.general.Inter; +import com.fr.report.cell.DefaultTemplateCellElement; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.elementcase.TemplateElementCase; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; + +/** + * @author zhou + * @since 2012-5-11下午5:24:35 + */ +public class CellPresentPane extends AbstractCellAttrPane { + private PresentPane presentPane; + + /** + * 初始化面板 + * @return 面板 + */ + public JPanel createContentPane() { + presentPane = new PresentPane(); + JPanel content = new JPanel(new BorderLayout()); + content.add(presentPane, BorderLayout.CENTER); + presentPane.addTabChangeListener(new ItemListener() { + + @Override + public void itemStateChanged(ItemEvent e) { + adjustValues(); + } + }); + return content; + } + + @Override + public String getIconPath() { + return "com/fr/design/images/data/source/dataDictionary.png"; + } + + @Override + public void updateBean(TemplateCellElement cellElement) { + cellElement.setPresent(presentPane.updateBean()); + } + + /** + * 保存 + */ + public void updateBeans() { + Present present = presentPane.updateBean(); + TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); + int cellRectangleCount = cs.getCellRectangleCount(); + for (int rect = 0; rect < cellRectangleCount; rect++) { + Rectangle cellRectangle = cs.getCellRectangle(rect); + // 需要先行后列地增加新元素。 + for (int j = 0; j < cellRectangle.height; j++) { + for (int i = 0; i < cellRectangle.width; i++) { + int column = i + cellRectangle.x; + int row = j + cellRectangle.y; + TemplateCellElement cellElement = elementCase.getTemplateCellElement(column, row); + if (cellElement == null) { + cellElement = new DefaultTemplateCellElement(column, row); + elementCase.addCellElement(cellElement); + } + cellElement.setPresent(present); + } + } + } + } + + @Override + protected void populateBean() { + //选中的所有单元格都有形态,属性表才会有内容,否则是初始值 + //主要是解决37664 + Present present = getSelectCellPresent(); + presentPane.populateBean(present); + } + + private Present getSelectCellPresent(){ + TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); + //按住ctrl选中多个cell块 + int cellRectangleCount = cs.getCellRectangleCount(); + + for (int rect = 0; rect < cellRectangleCount; rect++) { + Rectangle cellRectangle = cs.getCellRectangle(rect); + for (int j = 0; j < cellRectangle.height; j++) { + for (int i = 0; i < cellRectangle.width; i++) { + int column = i + cellRectangle.x; + int row = j + cellRectangle.y; + TemplateCellElement cellElement = elementCase.getTemplateCellElement(column, row); + if(cellElement == null || cellElement.getPresent() == null){ + return null; + } + } + } + } + return cellElement.getPresent(); + } + + /** + * 对话框标题 + * @return 标题 + */ + public String title4PopupWindow() { + return Inter.getLocText("FR-Chart-Style_Present"); + } + + public void setSelectedByIds(int level, String... id) { + presentPane.setSelectedByName(id[level]); + } + + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/cell/settingpane/CellStylePane.java b/designer/src/com/fr/design/mainframe/cell/settingpane/CellStylePane.java new file mode 100644 index 000000000..563b26bba --- /dev/null +++ b/designer/src/com/fr/design/mainframe/cell/settingpane/CellStylePane.java @@ -0,0 +1,116 @@ +package com.fr.design.mainframe.cell.settingpane; + +import java.awt.*; + +import javax.swing.JPanel; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +import com.fr.base.Style; +import com.fr.design.mainframe.cell.settingpane.style.StylePane; +import com.fr.general.Inter; +import com.fr.report.cell.DefaultTemplateCellElement; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.elementcase.TemplateElementCase; + +/** + * @author zhou + * @since 2012-5-11下午3:59:39 + */ +public class CellStylePane extends AbstractCellAttrPane { + private StylePane stylePane; + + @Override + public JPanel createContentPane() { + JPanel content = new JPanel(new BorderLayout()); + stylePane = new StylePane(); + content.add(stylePane, BorderLayout.CENTER); + stylePane.addPredefinedChangeListener(new ChangeListener() { + public void stateChanged(ChangeEvent e) { + attributeChanged(); + } + }); + stylePane.addCustomTabChangeListener(new ChangeListener() { + + @Override + public void stateChanged(ChangeEvent e) { + adjustValues();// 里面的Tab切换后要及时调整滚动条,因为一些界面可能不需要滚动条 + } + }); + return content; + } + + @Override + public String getIconPath() { + return "com/fr/design/images/m_format/cell.png"; + } + + @Override + public void updateBean(TemplateCellElement cellElement) { + cellElement.setStyle(stylePane.updateBean()); + } + + @Override + public void updateBeans() { + if (stylePane.getSelectedIndex() == 1) { + Style s = stylePane.updateBean(); + TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); + int cellRectangleCount = cs.getCellRectangleCount(); + for (int rect = 0; rect < cellRectangleCount; rect++) { + Rectangle cellRectangle = cs.getCellRectangle(rect); + for (int j = 0; j < cellRectangle.height; j++) { + for (int i = 0; i < cellRectangle.width; i++) { + int column = i + cellRectangle.x; + int row = j + cellRectangle.y; + TemplateCellElement cellElement = elementCase.getTemplateCellElement(column, row); + if (cellElement == null) { + cellElement = new DefaultTemplateCellElement(column, row); + elementCase.addCellElement(cellElement); + } + cellElement.setStyle(s); + } + } + } + } else { + TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); + int cellRectangleCount = cs.getCellRectangleCount(); + for (int rect = 0; rect < cellRectangleCount; rect++) { + Rectangle cellRectangle = cs.getCellRectangle(rect); + for (int j = 0; j < cellRectangle.height; j++) { + for (int i = 0; i < cellRectangle.width; i++) { + int column = i + cellRectangle.x; + int row = j + cellRectangle.y; + TemplateCellElement cellElement = elementCase.getTemplateCellElement(column, row); + if (cellElement == null) { + cellElement = new DefaultTemplateCellElement(column, row); + elementCase.addCellElement(cellElement); + } + Style style = cellElement.getStyle(); + if (style == null) { + style = style.DEFAULT_STYLE; + } + style = stylePane.updateStyle(style); + cellElement.setStyle(style); + } + } + } + stylePane.updateBorder();// border必须特别处理 + } + } + + @Override + protected void populateBean() { + stylePane.populateBean(cellElement.getStyle()); + stylePane.dealWithBorder(elementCasePane); + } + + @Override + public String title4PopupWindow() { + return Inter.getLocText("Style"); + } + + public void setSelectedByIds(int level, String... id) { + stylePane.setSelctedByName(id[level]); + } + +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/cell/settingpane/style/CustomStylePane.java b/designer/src/com/fr/design/mainframe/cell/settingpane/style/CustomStylePane.java new file mode 100644 index 000000000..7caadd105 --- /dev/null +++ b/designer/src/com/fr/design/mainframe/cell/settingpane/style/CustomStylePane.java @@ -0,0 +1,161 @@ +package com.fr.design.mainframe.cell.settingpane.style; + +import java.awt.*; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.event.ChangeListener; + +import com.fr.base.CellBorderStyle; +import com.fr.base.NameStyle; +import com.fr.base.Style; +import com.fr.design.actions.utils.ReportActionUtils; +import com.fr.design.gui.ibutton.FiveButtonLayout; +import com.fr.design.gui.style.AbstractBasicStylePane; +import com.fr.design.gui.style.AlignmentPane; +import com.fr.design.gui.style.BackgroundPane; +import com.fr.design.gui.style.BorderPane; +import com.fr.design.gui.style.FRFontPane; +import com.fr.design.gui.style.FormatPane; +import com.fr.design.style.BorderUtils; +import com.fr.design.dialog.BasicPane; +import com.fr.design.dialog.MultiTabPane; +import com.fr.general.Inter; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.stable.Constants; + + +/** + * 哎,复杂的原型图导致复杂的画法。非我所愿也 + * + * @author zhou + * @since 2012-5-24上午10:36:10 + */ +public class CustomStylePane extends MultiTabPane