1 /*
2 * File: TickScaler.java
3 * Copyright (c) 2004-2007 Peter Kliem (Peter.Kliem@jaret.de)
4 * A commercial license is available, see http://www.jaret.de.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20 package de.jaret.util.ui.timebars;
21
22 /**
23 * Simple helper for scaling minor and major tick distances for pixelpersecond value.
24 *
25 * @author Peter Kliem
26 * @version $Id: TickScaler.java 800 2008-12-27 22:27:33Z kliem $
27 */
28 public class TickScaler {
29 public static enum Range {
30 MONTH, WEEK, DAY, HOUR
31 };
32
33 private static final double _pixPerSecondLimits[] = {1.1574074074074073E-5, 2.3148148148148147E-5,
34 8.101851851851852E-5, 2.199074074074074E-4, 0.0008, 0.0015, 0.0025, 0.005, 0.01, 0.012, 0.05, 0.1, 0.5};
35
36 private static final int _majorTickMinutes[] = {24 * 60 * 7 * 4 * 2, 24 * 60 * 7 * 4, 24 * 60 * 7 * 2, 24 * 60 * 7,
37 24 * 60, 12 * 60, 360, 240, 120, 60, 15, 5, 2};
38
39 private static final int _minorTickMinutes[] = {24 * 60 * 7 * 4, 24 * 60 * 7 * 2, 24 * 60, 24 * 60, 240, 120, 60,
40 60, 30, 15, 5, 1, 1};
41
42 private static final Range _range[] = {Range.MONTH, Range.MONTH, Range.WEEK, Range.WEEK, Range.DAY, Range.HOUR,
43 Range.HOUR, Range.HOUR, Range.HOUR, Range.HOUR, Range.HOUR, Range.HOUR, Range.HOUR, Range.HOUR};
44
45 public static int getTickIdx(double pixPerSecond) {
46 for (int i = 0; i < _pixPerSecondLimits.length; i++) {
47 if (pixPerSecond <= _pixPerSecondLimits[i]) {
48 // System.out.println(i+":"+pixPerSecond +" "+
49 // _pixPerSecondLimits[i]);
50 return i;
51 }
52 // if (pixPerSecond > _pixPerSecondLimits[i]) {
53 // if (i==_pixPerSecondLimits.length-1 || pixPerSecond <
54 // _pixPerSecondLimits[i+1]){
55 // return i;
56 // }
57 // }
58 }
59 return _pixPerSecondLimits.length - 1;
60 }
61
62 public static int getMajorTickMinutes(int idx) {
63 return _majorTickMinutes[idx];
64 }
65
66 public static int getMinorTickMinutes(int idx) {
67 return _minorTickMinutes[idx];
68 }
69
70 public static Range getRange(int idx) {
71 return _range[idx];
72 }
73
74 }