comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java @ 2059:522826b41ffa

Compute better step width for W/Q input. flys-artifacts/trunk@3551 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 28 Dec 2011 08:28:13 +0000
parents 355495661a1c
children 3ffb7195173f
comparison
equal deleted inserted replaced
2058:f97cf2e350c9 2059:522826b41ffa
42 /** The default step width for Qs. */ 42 /** The default step width for Qs. */
43 public static final String DEFAULT_STEP_Q = "50"; 43 public static final String DEFAULT_STEP_Q = "50";
44 44
45 /** The default step width for Qs. */ 45 /** The default step width for Qs. */
46 public static final String DEFAULT_STEP_W = "30"; 46 public static final String DEFAULT_STEP_W = "30";
47
48 /** The max number of steps for Qs and Ws. */
49 public static final int MAX_STEPS = 30;
47 50
48 /** The name of the 'mode' field. */ 51 /** The name of the 'mode' field. */
49 public static final String WQ_MODE = "wq_mode"; 52 public static final String WQ_MODE = "wq_mode";
50 53
51 /** Them name fo the 'free' field. */ 54 /** Them name fo the 'free' field. */
235 cr, new String[] {"maxQ", new Double(minmaxQ[1]).toString()}); 238 cr, new String[] {"maxQ", new Double(minmaxQ[1]).toString()});
236 return new Element[] { maxW, maxQ }; 239 return new Element[] { maxW, maxQ };
237 } 240 }
238 else { 241 else {
239 Element stepW = createItem( 242 Element stepW = createItem(
240 cr, new String[] {"stepW", DEFAULT_STEP_W}); 243 cr, new String[] {
244 "stepW",
245 String.valueOf(getStepsW(minmaxW[0], minmaxW[1]))});
241 Element stepQ = createItem( 246 Element stepQ = createItem(
242 cr, new String[] {"stepQ", DEFAULT_STEP_Q}); 247 cr, new String[] {
248 "stepQ",
249 String.valueOf(getStepsW(minmaxQ[0], minmaxQ[1]))});
243 return new Element[] { stepW, stepQ }; 250 return new Element[] { stepW, stepQ };
244 } 251 }
252 }
253
254
255 protected static double getStepsW(double min, double max) {
256 double diff = min < max ? max - min : min - max;
257 double step = diff / MAX_STEPS;
258
259 if (step < 1000) {
260 return getSteps(step, 100);
261 }
262 else if (step < 100) {
263 return getSteps(step, 10);
264 }
265 else if (step < 10) {
266 return getSteps(step, 1);
267 }
268 else {
269 return step;
270 }
271 }
272
273
274 protected static double getStepsQ(double min, double max) {
275 double diff = min < max ? max - min : min - max;
276 double step = diff / MAX_STEPS;
277
278 if (step < 1000) {
279 return getSteps(step, 100);
280 }
281 else if (step < 100) {
282 return getSteps(step, 10);
283 }
284 else if (step < 10) {
285 return getSteps(step, 1);
286 }
287 else {
288 return step;
289 }
290 }
291
292
293 protected static double getSteps(double steps, double factor) {
294 int fac = (int) steps / 10;
295 double diff = steps - fac * 10;
296
297 if (diff == 0) {
298 return steps;
299 }
300
301 return 10d * (fac + 1);
245 } 302 }
246 303
247 304
248 protected Element createItem(XMLUtils.ElementCreator cr, Object obj) { 305 protected Element createItem(XMLUtils.ElementCreator cr, Object obj) {
249 Element item = ProtocolUtils.createArtNode(cr, "item", null, null); 306 Element item = ProtocolUtils.createArtNode(cr, "item", null, null);

http://dive4elements.wald.intevation.org