Revision 41187 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.labeling.app/org.gvsig.labeling.app.mainplugin/src/main/java/org/gvsig/labeling/gui/layerproperties/DefaultLabeling.java
DefaultLabeling.java | ||
---|---|---|
31 | 31 |
import java.awt.event.ActionListener; |
32 | 32 |
import java.awt.event.ItemEvent; |
33 | 33 |
import java.awt.event.ItemListener; |
34 |
import java.awt.geom.Rectangle2D; |
|
34 | 35 |
import java.beans.PropertyChangeEvent; |
35 | 36 |
|
36 | 37 |
import javax.swing.JButton; |
37 | 38 |
import javax.swing.JCheckBox; |
39 |
import javax.swing.JOptionPane; |
|
38 | 40 |
import javax.swing.JPanel; |
39 | 41 |
import javax.swing.JSplitPane; |
40 | 42 |
|
... | ... | |
51 | 53 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingStrategy; |
52 | 54 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.IPlacementConstraints; |
53 | 55 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.IZoomConstraints; |
56 |
import org.gvsig.fmap.mapcontext.rendering.symbols.styles.ILabelStyle; |
|
54 | 57 |
import org.gvsig.gui.beans.swing.JBlank; |
55 | 58 |
import org.gvsig.i18n.Messages; |
56 | 59 |
import org.gvsig.labeling.gui.styling.LayerPreview; |
... | ... | |
225 | 228 |
if(!lcProp.isAccepted()){ break; }; |
226 | 229 |
lc = lcProp.getLabelClass(); |
227 | 230 |
eval = checkValidSQL(lc); |
231 |
if (eval) { |
|
232 |
/* |
|
233 |
* Show warning if number of expressions != number of |
|
234 |
* rectangles |
|
235 |
*/ |
|
236 |
checkRectangles(lc); |
|
237 |
} |
|
228 | 238 |
} |
229 | 239 |
setLabel(lc); |
230 | 240 |
} |
231 | 241 |
} |
232 | 242 |
|
233 |
private boolean checkValidSQL(ILabelClass lc){ |
|
243 |
|
|
244 |
|
|
245 |
|
|
246 |
/** |
|
247 |
* Checks whether the number of expressions euqls the number |
|
248 |
* of rectangles in the style |
|
249 |
* |
|
250 |
* @param lc |
|
251 |
* @return |
|
252 |
*/ |
|
253 |
private void checkRectangles(ILabelClass lc) { |
|
254 |
|
|
255 |
ILabelStyle lbl_sty = lc.getLabelStyle(); |
|
256 |
if (lbl_sty != null) { |
|
257 |
String[] lbl_exps = lc.getLabelExpressions(); |
|
258 |
Rectangle2D[] lbl_rects = lbl_sty.getTextBounds(); |
|
259 |
int empty = countEmpty(lbl_exps); |
|
260 |
|
|
261 |
if (lbl_exps != null && lbl_rects != null |
|
262 |
&& |
|
263 |
(empty > 0 || |
|
264 |
(lbl_exps.length != lbl_rects.length))) { |
|
265 |
|
|
266 |
String[] pars = new String[3]; |
|
267 |
pars[0] = Integer.toString(lbl_exps.length); |
|
268 |
pars[1] = Integer.toString(empty); |
|
269 |
pars[2] = Integer.toString(lbl_rects.length); |
|
270 |
|
|
271 |
JOptionPane.showMessageDialog( |
|
272 |
ApplicationLocator.getManager().getRootComponent(), |
|
273 |
Messages.getText( |
|
274 |
"_There_are_N_expressions_N_are_empty_and_N_rectangles_" + |
|
275 |
"Check_label_expressions_and_background_image_properties", |
|
276 |
pars), |
|
277 |
Messages.getText("label_expression_editor"), |
|
278 |
JOptionPane.WARNING_MESSAGE); |
|
279 |
|
|
280 |
} |
|
281 |
} |
|
282 |
|
|
283 |
} |
|
284 |
|
|
285 |
|
|
286 |
private int countEmpty(String[] strs) { |
|
287 |
if (strs == null || strs.length == 0) { |
|
288 |
return 0; |
|
289 |
} else { |
|
290 |
int resp = 0; |
|
291 |
for (int i=0; i<strs.length; i++) { |
|
292 |
if (strs[i] == null || strs[i].trim().length() == 0) { |
|
293 |
resp++; |
|
294 |
} |
|
295 |
} |
|
296 |
return resp; |
|
297 |
} |
|
298 |
} |
|
299 |
|
|
300 |
|
|
301 |
private boolean checkValidSQL(ILabelClass lc){ |
|
234 | 302 |
|
235 | 303 |
String sqlQuery = lc.getSQLQuery(); |
236 | 304 |
if (sqlQuery != null && sqlQuery.trim().length() > 0) { |
Also available in: Unified diff