Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java @ 1700:13a9ee6cebef
Fix most labels in w-diff diagrams; refactoring to allow easier adoption of
labels in LongitudinalSectionGenerator subclasses.
flys-artifacts/trunk@2934 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Tue, 11 Oct 2011 10:44:12 +0000 |
parents | 2a6baa9e1576 |
children | 6e59208839ae |
comparison
equal
deleted
inserted
replaced
1699:608859aa5a7e | 1700:13a9ee6cebef |
---|---|
40 { | 40 { |
41 /** The logger that is used in this generator. */ | 41 /** The logger that is used in this generator. */ |
42 private static Logger logger = | 42 private static Logger logger = |
43 Logger.getLogger(LongitudinalSectionGenerator.class); | 43 Logger.getLogger(LongitudinalSectionGenerator.class); |
44 | 44 |
45 public static final String I18N_CHART_TITLE = | 45 /** Key to look up internationalized String for annotations label. */ |
46 "chart.longitudinal.section.title"; | |
47 | |
48 public static final String I18N_ANNOTATIONS_LABEL = | 46 public static final String I18N_ANNOTATIONS_LABEL = |
49 "chart.longitudinal.annotations.label"; | 47 "chart.longitudinal.annotations.label"; |
50 | 48 |
51 public static final String I18N_CHART_SUBTITLE = | 49 /** Whether or not the plot is inverted (left-right). */ |
52 "chart.longitudinal.section.subtitle"; | |
53 | |
54 public static final String I18N_XAXIS_LABEL = | |
55 "chart.longitudinal.section.xaxis.label"; | |
56 | |
57 public static final String I18N_YAXIS_LABEL = | |
58 "chart.longitudinal.section.yaxis.label"; | |
59 | |
60 public static final String I18N_2YAXIS_LABEL = | |
61 "chart.longitudinal.section.yaxis.second.label"; | |
62 | |
63 public static final String I18N_CHART_TITLE_DEFAULT = "W-L\u00e4ngsschnitt"; | |
64 public static final String I18N_XAXIS_LABEL_DEFAULT = "km"; | |
65 public static final String I18N_YAXIS_LABEL_DEFAULT = "W [NN + m]"; | |
66 public static final String I18N_2YAXIS_LABEL_DEFAULT = "Q [m\u00b3/s]"; | |
67 | |
68 | |
69 protected boolean inverted; | 50 protected boolean inverted; |
70 | 51 |
71 | 52 |
72 public LongitudinalSectionGenerator() { | 53 public LongitudinalSectionGenerator() { |
73 super(); | 54 super(); |
74 } | 55 } |
75 | 56 |
76 | 57 |
77 protected String getChartTitle() { | |
78 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT); | |
79 } | |
80 | |
81 public boolean isInverted() { | 58 public boolean isInverted() { |
82 return inverted; | 59 return inverted; |
83 } | 60 } |
84 | 61 |
62 | |
85 public void setInverted(boolean inverted) { | 63 public void setInverted(boolean inverted) { |
86 this.inverted = inverted; | 64 this.inverted = inverted; |
87 } | 65 } |
88 | 66 |
67 | |
68 /** | |
69 * Get internationalized title for chart. | |
70 */ | |
71 public String getChartTitle() { | |
72 return msg("chart.longitudinal.section.title", "W-L\u00e4ngsschnitt"); | |
73 } | |
74 | |
75 | |
76 /** | |
77 * Gets key to look up internationalized String for the charts subtitle. | |
78 * @return key to look up translated subtitle. | |
79 */ | |
80 protected String getChartSubtitleKey() { | |
81 return "chart.longitudinal.section.subtitle"; | |
82 } | |
83 | |
84 | |
85 /** | |
86 * Add (internationalized) subtitle to chart. | |
87 * @see getChartSubtitleKey | |
88 */ | |
89 @Override | 89 @Override |
90 protected void addSubtitles(JFreeChart chart) { | 90 protected void addSubtitles(JFreeChart chart) { |
91 double[] dist = getRange(); | 91 double[] dist = getRange(); |
92 | |
93 Object[] args = new Object[] { | 92 Object[] args = new Object[] { |
94 getRiverName(), | 93 getRiverName(), |
95 dist[0], | 94 dist[0], |
96 dist[1] | 95 dist[1] |
97 }; | 96 }; |
98 | 97 |
99 String subtitle = msg(I18N_CHART_SUBTITLE, "", args); | 98 String subtitle = msg(getChartSubtitleKey(), "", args); |
100 chart.addSubtitle(new TextTitle(subtitle)); | 99 chart.addSubtitle(new TextTitle(subtitle)); |
101 } | 100 } |
102 | 101 |
103 | 102 |
103 /** | |
104 * Get internationalized label for the x axis. | |
105 */ | |
104 protected String getXAxisLabel() { | 106 protected String getXAxisLabel() { |
105 FLYSArtifact flys = (FLYSArtifact) master; | 107 FLYSArtifact flys = (FLYSArtifact) master; |
106 | 108 |
107 return msg( | 109 return msg( |
108 I18N_XAXIS_LABEL, | 110 "chart.longitudinal.section.xaxis.label", |
109 I18N_XAXIS_LABEL_DEFAULT, | 111 "km", |
110 new Object[] { FLYSUtils.getRiver(flys).getName() }); | 112 new Object[] { FLYSUtils.getRiver(flys).getName() }); |
111 } | 113 } |
112 | 114 |
113 | 115 |
116 /** | |
117 * Get internationalized label for the y axis. | |
118 */ | |
114 protected String getYAxisLabel() { | 119 protected String getYAxisLabel() { |
115 FLYSArtifact flys = (FLYSArtifact) master; | 120 FLYSArtifact flys = (FLYSArtifact) master; |
116 | 121 |
117 String unit = FLYSUtils.getRiver(flys).getWstUnit().getName(); | 122 String unit = FLYSUtils.getRiver(flys).getWstUnit().getName(); |
118 | 123 |
119 return msg( | 124 return msg( |
120 I18N_YAXIS_LABEL, | 125 "chart.longitudinal.section.yaxis.label", |
121 I18N_YAXIS_LABEL_DEFAULT, | 126 "W [NN + m]", |
122 new Object[] { unit }); | 127 new Object[] { unit }); |
123 } | 128 } |
124 | 129 |
125 | 130 |
131 /** | |
132 * Get default value for the second Y-Axis' label (if no translation was | |
133 * found). | |
134 */ | |
135 protected String get2YAxisDefaultLabel() { | |
136 return "Q [m\u00b3/s]"; | |
137 } | |
138 | |
139 | |
140 /** | |
141 * Get key for internationalization of the second Y-Axis' label. | |
142 */ | |
143 protected String get2YAxisLabelKey() { | |
144 return "chart.longitudinal.section.yaxis.second.label"; | |
145 } | |
146 | |
147 | |
148 /** | |
149 * Adjust the axis to meet LongitudinalSection diagram demands. | |
150 * (e.g. add second Y-axis with internationalized label, trigger | |
151 * inversion). | |
152 * @param see get2YAxisLabelKey, get2YAxisDefaultLabel | |
153 */ | |
154 @Override | |
126 protected void adjustAxes(XYPlot plot) { | 155 protected void adjustAxes(XYPlot plot) { |
127 super.adjustAxes(plot); | 156 super.adjustAxes(plot); |
128 | 157 |
129 NumberAxis qAxis = new NumberAxis( | 158 NumberAxis qAxis = new NumberAxis( |
130 msg(I18N_2YAXIS_LABEL, I18N_2YAXIS_LABEL_DEFAULT)); | 159 msg(get2YAxisLabelKey(), get2YAxisDefaultLabel())); |
131 | 160 |
132 plot.setRangeAxis(1, qAxis); | 161 plot.setRangeAxis(1, qAxis); |
133 | 162 |
134 Font font = plot.getRangeAxis(0).getLabelFont(); | 163 Font font = plot.getRangeAxis(0).getLabelFont(); |
135 qAxis.setLabelFont(font); | 164 qAxis.setLabelFont(font); |