1 25 package org.jrobin.graph; 26 27 import java.text.SimpleDateFormat ; 28 29 34 class TimeGrid 35 { 36 private long startTime; 40 private long endTime; 41 42 private TimeAxisUnit tAxis; 43 44 45 57 TimeGrid( long startTime, long endTime, TimeAxisUnit tAxis, int firstDayOfWeek ) 58 { 59 this.startTime = startTime; 60 this.endTime = endTime; 61 this.tAxis = tAxis; 62 63 setTimeAxis( firstDayOfWeek ); 65 } 66 67 68 long getStartTime() { 72 return startTime; 73 } 74 75 long getEndTime() { 76 return endTime; 77 } 78 79 TimeMarker[] getTimeMarkers() { 80 return tAxis.getTimeMarkers( startTime, endTime ); 81 } 82 83 long getMajorGridWidth() { 84 return tAxis.getMajorGridWidth(); 85 } 86 87 boolean centerLabels() { 88 return tAxis.getCenterLabels(); 89 } 90 91 92 101 private void setTimeAxis( int firstDayOfWeek ) 102 { 103 if ( tAxis != null ) 104 return; 105 106 double days = (endTime - startTime) / 86400.0; 107 108 if ( days <= 0.75 / 24.0 ) { 109 tAxis = new TimeAxisUnit( TimeAxisUnit.MINUTE, 1, TimeAxisUnit.MINUTE, 5, new SimpleDateFormat ("HH:mm"), false, firstDayOfWeek ); 110 } 111 else if ( days <= 2.0 / 24.0 ) { 112 tAxis = new TimeAxisUnit( TimeAxisUnit.MINUTE, 5, TimeAxisUnit.MINUTE, 10, new SimpleDateFormat ("HH:mm"), false, firstDayOfWeek ); 113 } 114 else if ( days <= 3.0 / 24.0 ) { 115 tAxis = new TimeAxisUnit( TimeAxisUnit.MINUTE, 5, TimeAxisUnit.MINUTE, 20, new SimpleDateFormat ("HH:mm"), false, firstDayOfWeek ); 116 } 117 else if ( days <= 5.0 / 24.0 ) { 118 tAxis = new TimeAxisUnit( TimeAxisUnit.MINUTE, 10, TimeAxisUnit.MINUTE, 30, new SimpleDateFormat ("HH:mm"), false, firstDayOfWeek ); 119 } 120 else if ( days <= 10.0 / 24.0 ) { 121 tAxis = new TimeAxisUnit( TimeAxisUnit.MINUTE, 15, TimeAxisUnit.HOUR, 1, new SimpleDateFormat ("HH:mm"), false, firstDayOfWeek ); 122 } 123 else if ( days <= 15.0 / 24.0 ) { 124 tAxis = new TimeAxisUnit( TimeAxisUnit.MINUTE, 30, TimeAxisUnit.HOUR, 2, new SimpleDateFormat ("HH:mm"), false, firstDayOfWeek ); 125 } 126 else if ( days <= 20.0 / 24.0 ) { 127 tAxis = new TimeAxisUnit( TimeAxisUnit.HOUR, 1, TimeAxisUnit.HOUR, 1, new SimpleDateFormat ("HH"), true, firstDayOfWeek ); 128 } 129 else if ( days <= 36.0 / 24.0 ) { 130 tAxis = new TimeAxisUnit( TimeAxisUnit.HOUR, 1, TimeAxisUnit.HOUR, 4, new SimpleDateFormat ("HH:mm"), false, firstDayOfWeek ); 131 } 132 else if ( days <= 2 ) { 133 tAxis = new TimeAxisUnit( TimeAxisUnit.HOUR, 2, TimeAxisUnit.HOUR, 6, new SimpleDateFormat ("HH:mm"), false, firstDayOfWeek ); 134 } 135 else if ( days <= 3 ) { 136 tAxis = new TimeAxisUnit( TimeAxisUnit.HOUR, 3, TimeAxisUnit.HOUR, 12, new SimpleDateFormat ("HH:mm"), false, firstDayOfWeek ); 137 } 138 else if ( days < 8 ) { 139 tAxis = new TimeAxisUnit( TimeAxisUnit.HOUR, 6, TimeAxisUnit.DAY, 1, new SimpleDateFormat ("EEE dd"), true, firstDayOfWeek ); 140 } 141 else if ( days <= 14 ) { 142 tAxis = new TimeAxisUnit( TimeAxisUnit.HOUR, 12, TimeAxisUnit.DAY, 1, new SimpleDateFormat ("dd"), true, firstDayOfWeek ); 143 } 144 else if ( days <= 43 ) { 145 tAxis = new TimeAxisUnit( TimeAxisUnit.DAY, 1, TimeAxisUnit.WEEK, 1, new SimpleDateFormat ("'week' ww"), true, firstDayOfWeek ); 146 } 147 else if ( days <= 157 ) { 148 tAxis = new TimeAxisUnit( TimeAxisUnit.WEEK, 1, TimeAxisUnit.WEEK, 1, new SimpleDateFormat ("ww"), true, firstDayOfWeek ); 149 } 150 else { 151 tAxis = new TimeAxisUnit( TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, new SimpleDateFormat ("MMM"), true, firstDayOfWeek ); 152 } 153 } 154 } 155 | Popular Tags |