@ -1,21 +1,38 @@
package com.fr.design.mainframe.theme.preview ;
import com.fr.base.BaseFormula ;
import com.fr.base.background.ColorBackground ;
import com.fr.base.theme.FormTheme ;
import com.fr.chart.base.ChartConstants ;
import com.fr.chart.chartattr.ChartCollection ;
import com.fr.chart.chartattr.Title ;
import com.fr.chart.chartdata.NormalChartData ;
import com.fr.chart.charttypes.ChartTypeManager ;
import com.fr.design.i18n.Toolkit ;
import com.fr.design.layout.FRGUIPaneFactory ;
import com.fr.design.mainframe.theme.TemplateThemePreviewPane ;
import com.fr.design.mainframe.theme.preview.ecpreview.ECComponentPreviewPane ;
import com.fr.design.utils.ComponentUtils ;
import com.fr.general.Background ;
import com.fr.log.FineLoggerFactory ;
import com.fr.plugin.chart.PiePlot4VanChart ;
import com.fr.plugin.chart.attr.axis.VanChartAxis ;
import com.fr.plugin.chart.base.AttrLabel ;
import com.fr.plugin.chart.base.VanChartTools ;
import com.fr.plugin.chart.column.VanChartColumnPlot ;
import com.fr.plugin.chart.type.RadiusType ;
import com.fr.plugin.chart.vanchart.VanChart ;
import com.fr.stable.Constants ;
import com.fr.stable.StringUtils ;
import javax.swing.JComponent ;
import javax.swing.JPanel ;
import java.util.ArrayList ;
import java.awt.BorderLayout ;
import java.awt.Color ;
import java.awt.Component ;
import java.awt.Dimension ;
import java.awt.Graphics ;
import java.awt.geom.Rectangle2D ;
import java.util.ArrayList ;
/ * *
* @author Starryi
@ -23,33 +40,58 @@ import java.util.ArrayList;
* Created by Starryi on 2021 / 8 / 13
* /
public class FormThemePreviewPane extends TemplateThemePreviewPane < FormTheme > {
private ECComponentPreviewPane elementCasePane ;
private ECComponentPreviewPane elementCasePane ;
private Background background ;
private ComponentPreviewPane testPreviewPane ;
private ChartComponentPreviewPane columnChartPreviewPane ;
private ChartComponentPreviewPane pieChartPreviewPane ;
public FormThemePreviewPane ( ) {
setLayout ( FRGUIPaneFactory . createBorderLayout ( ) ) ;
JPanel content = new UINoOpaquePanel ( ) ;
content . setLayout ( new BorderLayout ( ) ) ;
content . add ( createChartContent ( ) , BorderLayout . CENTER ) ;
content . add ( elementCasePane = new ECComponentPreviewPane ( ) , BorderLayout . SOUTH ) ;
JPanel northPane = FRGUIPaneFactory . createBorderLayout_NO_Opaque_Pane ( ) ;
add ( content , BorderLayout . CENTER ) ;
}
northPane . add ( testPreviewPane = new ComponentPreviewPane ( true ) {
@Override
protected Component createContentPane ( ) {
return new UINoOpaquePanel ( ) ;
private JPanel createChartContent ( ) {
JPanel chartContent = new UINoOpaquePanel ( ) ;
chartContent . setLayout ( new BorderLayout ( ) ) ;
JPanel columnChartPanel = new UINoOpaquePanel ( ) {
public Dimension getPreferredSize ( ) {
return new Dimension ( 300 , 368 ) ;
}
} , BorderLayout . CENTER ) ;
content . add ( northPane , BorderLayout . CENTER ) ;
} ;
columnChartPanel . setLayout ( new BorderLayout ( ) ) ;
columnChartPreviewPane = createChartPreviewPane ( initColumnChart ( ) , 300 , 368 ) ;
columnChartPanel . add ( columnChartPreviewPane , BorderLayout . CENTER ) ;
add ( content , BorderLayout . CENTER ) ;
JPanel pieChartPanel = new UINoOpaquePanel ( ) {
public Dimension getPreferredSize ( ) {
return new Dimension ( 217 , 368 ) ;
}
} ;
pieChartPanel . setLayout ( new BorderLayout ( ) ) ;
pieChartPreviewPane = createChartPreviewPane ( initPieChart ( ) , 300 , 368 ) ;
pieChartPanel . add ( pieChartPreviewPane , BorderLayout . CENTER ) ;
chartContent . add ( columnChartPanel , BorderLayout . WEST ) ;
chartContent . add ( pieChartPanel , BorderLayout . EAST ) ;
return chartContent ;
}
private ChartComponentPreviewPane createChartPreviewPane ( ChartCollection chartCollection , int width , int height ) {
ChartComponentPreviewPane chartComponentPreviewPane = new ChartComponentPreviewPane ( true ) ;
chartComponentPreviewPane . getContentPane ( ) . populate ( chartCollection ) ;
chartComponentPreviewPane . getContentPane ( ) . setCallbackEvent ( this ) ;
return chartComponentPreviewPane ;
}
@Override
public void refresh ( FormTheme theme ) {
background = theme . getBodyStyle ( ) . getStyle ( ) . getBackground ( ) ;
elementCasePane . refresh ( theme ) ;
testPreviewPane . refresh ( theme ) ;
columnChartPreviewPane . refresh ( theme ) ;
pieChartPreviewPane . refresh ( theme ) ;
repaint ( ) ;
}
@ -68,4 +110,93 @@ public class FormThemePreviewPane extends TemplateThemePreviewPane<FormTheme> {
}
//柱形图
private ChartCollection initColumnChart ( ) {
try {
VanChart chart = ( VanChart ) ChartTypeManager . getInstance ( ) . getCharts ( VanChartColumnPlot . VAN_CHART_COLUMN_PLOT_ID ) [ 0 ] . clone ( ) ;
chart . getTitle ( ) . setTitleVisible ( false ) ;
VanChartTools vanChartTools = chart . getVanChartTools ( ) ;
vanChartTools . setSort ( false ) ;
vanChartTools . setExport ( false ) ;
vanChartTools . setFullScreen ( false ) ;
VanChartColumnPlot plot = chart . getPlot ( ) ;
AttrLabel defaultAttrLabel = plot . getDefaultAttrLabel ( ) ;
defaultAttrLabel . setEnable ( true ) ;
defaultAttrLabel . getAttrLabelDetail ( ) . getBorder ( ) . setBorderStyle ( 0 ) ;
defaultAttrLabel . getAttrLabelDetail ( ) . getBackground ( ) . setBackground ( null ) ;
plot . getConditionCollection ( ) . getDefaultAttr ( ) . addDataSeriesCondition ( defaultAttrLabel ) ;
plot . getLegend ( ) . setPosition ( Constants . TOP ) ;
plot . setPlotStyle ( ChartConstants . STYLE_NONE ) ;
plot . setSeriesOverlapPercent ( 30 ) ;
plot . setCategoryIntervalPercent ( 30 ) ;
VanChartAxis defaultYAxis = plot . getDefaultYAxis ( ) ;
Title title = new Title ( ) ;
title . setTextObject ( Toolkit . i18nText ( "Fine-Design_Chart_Axis_Title" ) ) ;
title . getTextAttr ( ) . setRotation ( - 90 ) ;
title . getTextAttr ( ) . setThemed ( true ) ;
defaultYAxis . setTitle ( title ) ;
defaultYAxis . setShowAxisTitle ( true ) ;
defaultYAxis . setCustomMaxValue ( true ) ;
defaultYAxis . setCustomMinValue ( true ) ;
defaultYAxis . setCustomMainUnit ( true ) ;
defaultYAxis . setMaxValue ( BaseFormula . createFormulaBuilder ( ) . build ( "=600" ) ) ;
defaultYAxis . setMinValue ( BaseFormula . createFormulaBuilder ( ) . build ( "=0" ) ) ;
defaultYAxis . setMainUnit ( BaseFormula . createFormulaBuilder ( ) . build ( "=200" ) ) ;
Object [ ] category = {
Toolkit . i18nText ( "Fine-Design_Chart_Category" ) + "1" ,
Toolkit . i18nText ( "Fine-Design_Chart_Category" ) + "2" ,
Toolkit . i18nText ( "Fine-Design_Chart_Category" ) + "3" ,
Toolkit . i18nText ( "Fine-Design_Chart_Category" ) + "4"
} ;
Object [ ] series = {
Toolkit . i18nText ( "Fine-Design_Chart_Series" ) + "1" ,
Toolkit . i18nText ( "Fine-Design_Chart_Series" ) + "2"
} ;
Object [ ] [ ] value = {
{ "250" , "540" , "300" , "410" } ,
{ "180" , "190" , "170" , "100" } ,
} ;
NormalChartData normalChartData = new NormalChartData ( category , series , value ) ;
chart . setPreViewChartData ( normalChartData ) ;
ChartCollection chartCollection = new ChartCollection ( chart ) ;
return chartCollection ;
} catch ( Exception ex ) {
FineLoggerFactory . getLogger ( ) . error ( ex . getMessage ( ) , ex ) ;
}
return null ;
}
//饼图
private ChartCollection initPieChart ( ) {
try {
VanChart chart = ( VanChart ) ChartTypeManager . getInstance ( ) . getCharts ( PiePlot4VanChart . VAN_CHART_PIE_PLOT ) [ 0 ] . clone ( ) ;
chart . getTitle ( ) . setTitleVisible ( false ) ;
VanChartTools vanChartTools = chart . getVanChartTools ( ) ;
vanChartTools . setSort ( false ) ;
vanChartTools . setExport ( false ) ;
vanChartTools . setFullScreen ( false ) ;
PiePlot4VanChart plot = chart . getPlot ( ) ;
plot . getLegend ( ) . setPosition ( Constants . BOTTOM ) ;
plot . setPlotStyle ( ChartConstants . STYLE_NONE ) ;
plot . setInnerRadiusPercent ( 75 ) ;
plot . getRadius ( ) . setRadiusType ( RadiusType . FIXED ) ;
plot . getRadius ( ) . setRadius ( 80 ) ;
Object [ ] category = { StringUtils . EMPTY } ;
Object [ ] series = { "A1" , "B1" , "C1" , "D1" , "E1" , "F1" , "G1" , "H1" } ;
Object [ ] [ ] value = { { 45 } , { 24 } , { 12 } , { 8 } , { 5 } , { 3 } , { 2 } , { 1 } , } ;
NormalChartData normalChartData = new NormalChartData ( category , series , value ) ;
chart . setPreViewChartData ( normalChartData ) ;
ChartCollection chartCollection = new ChartCollection ( chart ) ;
return chartCollection ;
} catch ( Exception ex ) {
FineLoggerFactory . getLogger ( ) . error ( ex . getMessage ( ) , ex ) ;
}
return null ;
}
}