Changeset 5665
- Timestamp:
- 10/09/08 12:12:17 (6 weeks ago)
- Location:
- branches/ProtocolEditor/src
- Files:
-
- 2 modified
-
ui/components/AlarmSetter.java (modified) (2 diffs)
-
util/DefaultExport.java (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/ProtocolEditor/src/ui/components/AlarmSetter.java
r5385 r5665 189 189 } 190 190 191 int timeUnit = getTimeUnits(secs); 192 int timeValue = getTimeValue(secs); 193 194 setTimeUnitChooserIndex(timeUnit); 195 setTimeSpinnerValue(timeValue); 196 } 197 198 /** 199 * Returns the value needed to describe the alarm seconds in the 200 * units returned by {@link #getTimeUnits(int)}; 201 * eg If alarmSecs = 3600, this method will return 1, and 202 * {@link #getTimeUnits(int)} will return {@link HOURS}; 203 * 204 * @param alarmSecs time in seconds 205 * @return int see above. 206 */ 207 public static int getTimeValue(int alarmSecs) { 191 208 int timeUnit; 192 209 int timeValue; 193 210 211 if (alarmSecs == 0) return 0; 212 194 213 // need to work out what the units are 195 214 for (timeUnit = 0; timeUnit<timeUnits.length; timeUnit++) { 196 timeValue = secs/secondsInTimeUnit[timeUnit];215 timeValue = alarmSecs/secondsInTimeUnit[timeUnit]; 197 216 // if timeValue > 0 then this is the units you want 198 217 if (timeValue > 0) { 199 218 200 219 // if it is an exact match 201 if (secs == timeValue * secondsInTimeUnit[timeUnit]) { 202 setTimeUnitChooserIndex(timeUnit); 203 setTimeSpinnerValue(timeValue); 204 return; 220 if (alarmSecs == timeValue * secondsInTimeUnit[timeUnit]) { 221 return timeValue; 205 222 } else { 206 223 … … 209 226 if (timeUnit < timeUnits.length -1) { 210 227 timeUnit++; 211 timeValue = secs/secondsInTimeUnit[timeUnit]; 212 setTimeUnitChooserIndex(timeUnit); 213 setTimeSpinnerValue(timeValue); 214 return; 228 timeValue = alarmSecs/secondsInTimeUnit[timeUnit]; 229 return timeValue; 215 230 } 231 } 232 } 233 } 234 return 0; 235 } 236 237 238 public static String alarmSecsToString(String alarmSecs) { 239 240 try { 241 int secs = Integer.parseInt(alarmSecs); 242 243 boolean alarmBefore = false; 244 if (secs < 0) { // alarm before event 245 alarmBefore = true; 246 secs = secs * -1; 247 } 248 249 if (secs == 0) return "No alarm"; 250 251 int value = getTimeValue(secs); 252 String units = "No alarm"; 253 if (getTimeUnits(secs) < timeUnits.length) { 254 units = timeUnits[getTimeUnits(secs)]; 255 } 256 257 return value + " " + units + (alarmBefore ? " Before" : " After"); 258 259 } catch (NumberFormatException ex) { 260 ex.printStackTrace(); 261 return ""; 262 } 263 } 264 265 266 /** 267 * Returns the units needed to describe the alarm seconds 268 * {@link DAYS}, {@link HOURS}, or {@link MINS} 269 * 270 * @param alarmSecs 271 * @return int the units index {@link DAYS}, {@link HOURS}, or {@link MINS} 272 */ 273 public static int getTimeUnits(int alarmSecs) { 274 275 int timeUnit; 276 int timeValue; 277 278 // need to work out what the units are 279 for (timeUnit = 0; timeUnit<timeUnits.length; timeUnit++) { 280 timeValue = alarmSecs/secondsInTimeUnit[timeUnit]; 281 // if timeValue > 0 then this is the units you want 282 if (timeValue > 0) { 216 283 284 // if it is an exact match 285 if (alarmSecs == timeValue * secondsInTimeUnit[timeUnit]) { 286 return timeUnit; 287 } else { 288 289 // if any seconds are left over (eg user sets 90 minutes or 36 hours) 290 // try smaller units 291 if (timeUnit < timeUnits.length -1) { 292 return timeUnit + 1; 293 } 217 294 } 218 219 295 } 220 296 } 297 return NO_ALARM; 221 298 } 222 299 -
branches/ProtocolEditor/src/util/DefaultExport.java
r5339 r5665 1 package util;2 3 import java.awt.Color;4 import java.io.File;5 import java.io.FileWriter;6 import java.io.PrintWriter;7 import java.util.ArrayList;8 import java.util.HashMap;9 import java.util.Iterator;10 import java.util.LinkedHashMap;11 import java.util.List;12 import java.util.Map;13 14 import tree.DataField;15 import tree.DataFieldConstants;16 import tree.DataFieldNode;17 import tree.IAttributeSaver;18 import ui.formFields.FormField;19 1 20 2 /* … … 40 22 */ 41 23 24 package util; 25 26 import java.awt.Color; 27 import java.io.BufferedReader; 28 import java.io.File; 29 import java.io.FileNotFoundException; 30 import java.io.FileReader; 31 import java.io.FileWriter; 32 import java.io.IOException; 33 import java.io.PrintWriter; 34 import java.text.SimpleDateFormat; 35 import java.util.ArrayList; 36 import java.util.HashMap; 37 import java.util.Iterator; 38 import java.util.List; 39 import java.util.Map; 40 41 import tree.DataField; 42 import tree.DataFieldConstants; 43 import tree.DataFieldNode; 44 import tree.IAttributeSaver; 45 import ui.components.AlarmSetter; 46 import ui.formFields.FormField; 47 42 48 public class DefaultExport 43 49 implements IExport { … … 81 87 public String TABLE_DATA_END = ""; 82 88 83 89 /** 90 * Exports the given dataField nodes as a String. 91 * This method works by creating a temporary file, delegating the 92 * export to that file, using {@link #export(File, List)} and then 93 * converting the file to a String. The temp file is deleted before 94 * returning the String. 95 * 96 * @param rootNodes A list of the nodes to export 97 * @return String A string representation of the export. 98 */ 99 public String exportToString(List<DataFieldNode> rootNodes) 100 { 101 File tempFile = new File("temp"); 102 103 export(tempFile, rootNodes); 104 105 StringBuffer fileData = new StringBuffer(1000); 106 BufferedReader reader; 107 try { 108 reader = new BufferedReader(new FileReader(tempFile)); 109 char[] buf = new char[1024]; 110 int numRead=0; 111 while((numRead=reader.read(buf)) != -1){ 112 String readData = String.valueOf(buf, 0, numRead); 113 fileData.append(readData); 114 buf = new char[1024]; 115 } 116 reader.close(); 117 } catch (FileNotFoundException e) { 118 // TODO Auto-generated catch block 119 e.printStackTrace(); 120 } catch (IOException e) { 121 // TODO Auto-generated catch block 122 e.printStackTrace(); 123 } 124 125 String exportString = fileData.toString(); 126 127 //tempFile.delete(); 128 129 return exportString; 130 } 84 131 85 132 /** … … 98 145 exportPreferences.put(SHOW_URL, true); 99 146 exportPreferences.put(SHOW_TABLE_DATA, true); 100 exportPreferences.put(SHOW_OTHER_ATTRIBUTES, true);147 exportPreferences.put(SHOW_OTHER_ATTRIBUTES, false); 101 148 102 149 export(file, rootNodes, exportPreferences); … … 214 261 else divHeader = DIV; 215 262 216 if (true) {217 String colour = dataField.getAttribute(DataFieldConstants.BACKGROUND_COLOUR);263 String colour = dataField.getAttribute(DataFieldConstants.BACKGROUND_COLOUR); 264 if (colour != null) { 218 265 Color bgColour = FormField.getColorFromString(colour); 219 266 if (bgColour != null) { … … 250 297 outputStream.println(SPAN_END); 251 298 299 if (DataFieldConstants.DATE_TIME_FIELD.equals(inputType)) { 300 String date = "Date: "; 301 String UTCmillisecs = dataField.getAttribute(DataFieldConstants.UTC_MILLISECS); 302 if (UTCmillisecs != null) { 303 SimpleDateFormat sdf = new SimpleDateFormat("MMM d, yyyy"); 304 date = date + sdf.format(new Long(UTCmillisecs)); 305 } else { 306 date = date + "none set."; 307 } 308 309 String time = dataField.getAttribute(DataFieldConstants.SECONDS); 310 if (time != null) { 311 SimpleDateFormat sdf = new SimpleDateFormat("HH:mm"); 312 date = date + " at " + sdf.format(new Long(time + "000")) + "."; 313 } 314 315 String alarmSecs = dataField.getAttribute(DataFieldConstants.ALARM_SECONDS); 316 if (alarmSecs != null) { 317 date = date + " Alarm: " + AlarmSetter.alarmSecsToString(alarmSecs); 318 } 319 date = DIV_CLASS_ATTRIBUTE + date + DIV_END; 320 321 outputStream.print(date); 322 } 323 252 324 if ((showDefaultValues) && (allAttributes.get(DataFieldConstants.DEFAULT) != null)) { 253 325 outputStream.print(DIV_CLASS_ATTRIBUTE + "Default Value = " +
