root / org.gvsig.chart / trunk / org.gvsig.chart / org.gvsig.chart.app / org.gvsig.chart.app.layoutplugin / src / main / java / org / gvsig / project / documents / layout / frames / FFrameChart.java @ 77
History | View | Annotate | Download (5.34 KB)
1 |
package org.gvsig.project.documents.layout.frames; |
---|---|
2 |
|
3 |
import java.awt.Font; |
4 |
import java.awt.Graphics2D; |
5 |
import java.awt.font.FontRenderContext; |
6 |
import java.awt.geom.AffineTransform; |
7 |
import java.awt.geom.Rectangle2D; |
8 |
import java.awt.image.BufferedImage; |
9 |
|
10 |
import org.gvsig.andami.PluginServices; |
11 |
import org.gvsig.app.project.documents.chart.ChartDocument; |
12 |
import org.gvsig.app.project.documents.layout.fframes.FFrame; |
13 |
import org.gvsig.app.project.documents.layout.fframes.FFramePicture; |
14 |
import org.gvsig.chart.ChartService; |
15 |
import org.gvsig.compat.print.PrintAttributes; |
16 |
import org.gvsig.fmap.geom.Geometry; |
17 |
import org.gvsig.tools.ToolsLocator; |
18 |
import org.gvsig.tools.dynobject.DynStruct; |
19 |
import org.gvsig.tools.persistence.PersistenceManager; |
20 |
import org.gvsig.tools.persistence.PersistentState; |
21 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
22 |
|
23 |
public class FFrameChart extends FFrame { |
24 |
|
25 |
public static final String PERSISTENCE_DEFINITION_NAME = "FFrameChart"; |
26 |
|
27 |
private static final String ASSOCIATED_CHART = "assoc_chart"; |
28 |
|
29 |
protected ChartDocument chartDoc = null; |
30 |
|
31 |
private boolean legendVisible; |
32 |
|
33 |
private boolean axisLabels; |
34 |
|
35 |
public ChartDocument getChartDoc() {
|
36 |
return chartDoc;
|
37 |
} |
38 |
|
39 |
|
40 |
public static void registerPersistent() { |
41 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
42 |
if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) { |
43 |
DynStruct definition = |
44 |
manager.addDefinition(FFrameChart.class, |
45 |
PERSISTENCE_DEFINITION_NAME, |
46 |
"FFrameChart persistence definition", null, null); |
47 |
|
48 |
definition.extend(manager |
49 |
.getDefinition(FFrame.PERSISTENCE_DEFINITION_NAME)); |
50 |
|
51 |
definition.addDynFieldObject(ASSOCIATED_CHART).setClassOfValue(ChartDocument.class).setMandatory(true);
|
52 |
} |
53 |
} |
54 |
|
55 |
|
56 |
public String getName() { |
57 |
return PERSISTENCE_DEFINITION_NAME;
|
58 |
} |
59 |
|
60 |
public String getNameFFrame() { |
61 |
return PluginServices.getText(this, "chart") + num; |
62 |
} |
63 |
|
64 |
public void print(Graphics2D g, AffineTransform at, Geometry shape, |
65 |
PrintAttributes properties) { |
66 |
draw(g, at, null, null); |
67 |
} |
68 |
|
69 |
@Override
|
70 |
public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv, |
71 |
BufferedImage imgBase) {
|
72 |
if (chartDoc == null) |
73 |
return;
|
74 |
ChartService chS = ((ChartService) chartDoc.getChartService()).clone(); |
75 |
if (chS != null) { |
76 |
chS.getChartProperties().setIsLegendVisible(this.getLegendVisible());
|
77 |
|
78 |
int axisCount = chS.getDomainAxis().size();
|
79 |
for(int i=0; i<axisCount; i++){ |
80 |
chS.getDomainAxis().get(i).setIsChartAxisTitleVisible(false);
|
81 |
} |
82 |
axisCount = chS.getRangeAxis().size(); |
83 |
for(int i=0; i<axisCount; i++){ |
84 |
chS.getRangeAxis().get(i).setIsChartAxisTitleVisible(false);
|
85 |
} |
86 |
|
87 |
//chS.setAxisVisibles(false);
|
88 |
|
89 |
Rectangle2D.Double r = getBoundingBox(at);
|
90 |
g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2), r.y |
91 |
+ (r.height / 2));
|
92 |
double x = r.getMinX();
|
93 |
double y = r.getMinY();
|
94 |
double w = r.getWidth();
|
95 |
double h = r.getHeight();
|
96 |
|
97 |
if (intersects(rv, r) || w != 0 || h != 0) { // comprueba que no cae fuera de la pantalla |
98 |
// Ajustamos el tama?o del texto.
|
99 |
FontRenderContext frc = g.getFontRenderContext();
|
100 |
int scaledFontSize;
|
101 |
|
102 |
// TODO myScale es la escala sobre la que se extraen todos los
|
103 |
// escalados. Esto
|
104 |
// funciona bien tal cual est? si la ratio de aspecto
|
105 |
// (alto/ancho) del folio es constante
|
106 |
// porque se toma como medidas el ancho del folio real y el
|
107 |
// ancho del folio en pantalla.
|
108 |
// No se que pasar? si la ratio cambia, por ejemplo si se usan
|
109 |
// USLetter en lugar de DIN A4
|
110 |
double myScale = at.getScaleX() * 0.0234; // FLayoutUtilities.fromSheetDistance(folio.getAncho(),at)/rv.getWidth(); |
111 |
if(rv != null){ |
112 |
myScale = r.getWidth()/rv.getWidth(); |
113 |
} |
114 |
// Aqu? se ajusta a partir de las caracter?sticas de la
|
115 |
// fuente, una nueva fuente con el tama?o ajustado.
|
116 |
|
117 |
chS.draw(g, r.getBounds()); |
118 |
chS.scaleFonts(myScale); |
119 |
|
120 |
chS.draw(g, r.getBounds()); |
121 |
|
122 |
// restauramos
|
123 |
//chS.scaleFonts(myScale);
|
124 |
} |
125 |
} |
126 |
} |
127 |
|
128 |
@Override
|
129 |
public void loadFromState(PersistentState state) |
130 |
throws PersistenceException {
|
131 |
super.loadFromState(state);
|
132 |
chartDoc = (ChartDocument) state.get(ASSOCIATED_CHART); |
133 |
} |
134 |
|
135 |
@Override
|
136 |
public void saveToState(PersistentState state) throws PersistenceException { |
137 |
super.saveToState(state);
|
138 |
state.set(ASSOCIATED_CHART, chartDoc); |
139 |
} |
140 |
|
141 |
|
142 |
public void setChartDoc(ChartDocument chartSelected) { |
143 |
this.chartDoc = chartSelected;
|
144 |
} |
145 |
|
146 |
|
147 |
public void setLegendVisible(boolean selected) { |
148 |
this.legendVisible = selected;
|
149 |
} |
150 |
|
151 |
public boolean getLegendVisible(){ |
152 |
return this.legendVisible; |
153 |
} |
154 |
|
155 |
|
156 |
public void setAxisLabels(boolean selected) { |
157 |
this.axisLabels = selected;
|
158 |
} |
159 |
|
160 |
public boolean getAxisLabels(){ |
161 |
return this.axisLabels; |
162 |
} |
163 |
|
164 |
} |