/** Sets the time of the next scheduled raid */ private void setNextRaid(Info info) { String raidTime = info.getMessage().substring(13); raidTime = substituteTimeZone(raidTime); try { SimpleDateFormat parser = new SimpleDateFormat("yyyy-MM-dd HH:mm z"); Date date = parser.parse(raidTime); TimeZone z = parser.getTimeZone(); GregorianCalendar cal = new GregorianCalendar(z); cal.setTime(date); raids.put(info.getChannel(), cal); saveRaids(); info.sendMessage("Raid time set."); } catch (ParseException e) { info.sendMessage( "Date format was bad. Date format is like \"2008-11-26 21:45 EST\". You entered " + raidTime); } }
private StringBuilder getHeader(String symbol1, String symbol2) { StringBuilder header = new StringBuilder(); String appInfo = JArbitrager.APP_NAME + ", version " + JArbitrager.VERSION; header.append("# This historical data file was created by ").append(appInfo).append(LINE_SEP); header .append("# Each line represents a 1-second snapshot of the market and contains ") .append(BackTestFileReader.COLUMNS) .append(" columns:") .append(LINE_SEP); header.append("# 1. date in the MMddyy format").append(LINE_SEP); header.append("# 2. time in the HHmmss format").append(LINE_SEP); header.append("# 3. best bid for the first instrument").append(LINE_SEP); header.append("# 4. best ask for the first instrument").append(LINE_SEP); header.append("# 5. best bid for the second instrument").append(LINE_SEP); header.append("# 6. best ask for the second instrument").append(LINE_SEP); header.append(LINE_SEP); header.append("instruments=").append(symbol1).append(",").append(symbol2).append(LINE_SEP); header.append("timeZone=").append(dateFormat.getTimeZone().getID()).append(LINE_SEP); return header; }
// Invoked by timer when interval ends @Override public void actionPerformed(ActionEvent event) { Font font = panel.getFont(); // Create a new attributed string with the new time Date current = new Date(); Calendar cal = panel.getCalendar(); cal.setTime(current); long blink = ((System.currentTimeMillis() - startTime) / (BLINK_INTERVAL)) % 2; // To format current time using specific pattern. SimpleDateFormat df; // //////////////////////////////////// // Draw standard digital-type clock // // //////////////////////////////////// // Hour24 mode df = new SimpleDateFormat( "HH" + panel.getPadding1() + "mm" + panel.getPadding1() + "ss", panel.getLocale()); String str = df.format(current); String temp = ""; int tmpLen1 = 0; df.applyPattern("SSS"); temp = " " + panel.getPadding2() + df.format(current).substring(0, 3); tmpLen1 = temp.length(); str += temp; temp = ""; // ////////////// // Draw AM/PM // // ////////////// int tmpLen2 = 0; // mode df.applyPattern("a"); temp = " " + df.format(current); tmpLen2 = temp.length(); str += temp; temp = ""; // timezone df.applyPattern("Z"); StringBuffer sb = new StringBuffer("GMT"); sb.append(df.format(current)); sb.insert(6, ":"); df.applyPattern("zzzz"); temp = " " + df.format(current) + " (" + df.getTimeZone().getID() + ", " + sb + ")"; String str2 = temp; temp = ""; // ////////////////////////// // Format the time string // // ////////////////////////// timeString = null; timeString = new AttributedString(str); // Render main time area timeString.addAttribute(TextAttribute.FONT, font, 0, 6 + 2 * panel.getPadding1().length()); timeString.addAttribute(TextAttribute.FOREGROUND, panel.getForeground()); // Do blinking if reach alarm point timeString.addAttribute( TextAttribute.FOREGROUND, panel.getForeground(), 0, 6 + 2 * panel.getPadding1().length()); // Render padding1, do blinking timeString.addAttribute( TextAttribute.FOREGROUND, blink == 0 ? panel.getForeground() : panel.getBackground(), 2, 2 + panel.getPadding1().length()); timeString.addAttribute( TextAttribute.FOREGROUND, blink == 0 ? panel.getForeground() : panel.getBackground(), 2 + panel.getPadding1().length() + 2, 4 + 2 * panel.getPadding1().length()); // Render stopwatch timeString.addAttribute( TextAttribute.FONT, new Font( font.getName(), font.getStyle(), font.getSize() - SHRINK > 1 ? font.getSize() - SHRINK : 1), 6 + 2 * panel.getPadding1().length(), 6 + 2 * panel.getPadding1().length() + tmpLen1); // Render am/pm area timeString.addAttribute( TextAttribute.FONT, new Font( font.getName(), font.getStyle(), font.getSize() - SHRINK - 4 > 1 ? font.getSize() - SHRINK - 4 : 1), str.length() - tmpLen2, str.length()); // Create a new text layout and signal the panel that it needs // repainting textLayout = null; textLayout = new TextLayout(timeString.getIterator(), Clock.frc); // Render timezone, drawing at another line. timezoneString = null; timezoneString = new AttributedString(str2); timezoneString.addAttribute( TextAttribute.FONT, new Font( font.getName(), font.getStyle(), font.getSize() - SHRINK - 4 > 1 ? font.getSize() - SHRINK - 4 : 1)); timezoneString.addAttribute(TextAttribute.FOREGROUND, panel.getForeground()); textTimezoneLayout = null; textTimezoneLayout = new TextLayout(timezoneString.getIterator(), Clock.frc); // To keep the clock size fit for // actual size in time. panel.setSize(getPreferredSize(panel)); panel.repaint(); current = null; df = null; }