/** * This method runs the Runnable and measures how long it takes. * * @param r is the Runnable for the task that we want to measure * @return the time it took to execute this task */ public static long time(Runnable r) { long time = -System.currentTimeMillis(); r.run(); time += System.currentTimeMillis(); System.out.println("Took " + time + "ms"); return time; }
public abstract static class Message { public final long time = System.currentTimeMillis(); public abstract Text text(); public abstract Tex tex(); public abstract Coord sz(); }
public void changeStateIfNeeded() { if (!isFocusOwner()) { return; } long currentTime = System.currentTimeMillis(); if (cursorShouldChangeBlinkState(currentTime)) { myCursorIsShown = !myCursorIsShown; myLastCursorChange = currentTime; myCursorHasChanged = false; repaint(); } }
private class Notification { public final Channel chan; public final Text chnm; public final Channel.Message msg; public final long time = System.currentTimeMillis(); private Notification(Channel chan, Channel.Message msg) { this.chan = chan; this.msg = msg; this.chnm = chansel.nf.render(chan.name(), Color.WHITE); } }
public void drawsmall(GOut g, Coord br, int h) { Coord c; if (qline != null) { if ((rqline == null) || !rqline.text.equals(qline.line)) { String pre = String.format("%s> ", qline.chan.name()); rqline = qfnd.render(pre + qline.line); rqpre = pre.length(); } c = br.sub(0, 20); g.chcolor(24, 24, 16, 200); g.frect(c, rqline.tex().sz()); g.chcolor(); g.image(rqline.tex(), c); int lx = rqline.advance(qline.point + rqpre); g.line(new Coord(br.x + lx + 1, br.y - 18), new Coord(br.x + lx + 1, br.y - 6), 1); } else { c = br.sub(0, 5); } long now = System.currentTimeMillis(); synchronized (notifs) { for (Iterator<Notification> i = notifs.iterator(); i.hasNext(); ) { Notification n = i.next(); if (now - n.time > 5000) { i.remove(); continue; } if ((c.y -= n.msg.sz().y) < br.y - h) break; g.chcolor(24, 24, 16, 200); g.frect(c, n.chnm.tex().sz().add(n.msg.tex().sz().x + selw, 0)); g.chcolor(); g.image(n.chnm.tex(), c, br.sub(0, h), br.add(selw - 10, 0)); g.image(n.msg.tex(), c.add(selw, 0)); } } }
public void cursorChanged() { myCursorHasChanged = true; myLastCursorChange = System.currentTimeMillis(); repaint(); }
/** * Creates a CPU usage data snapshot by associating CPU time used with system time. The resulting * data can be fed into getProcessCPUUsage(long[],long[]). * * @return long[2] [0] current system time stamp, [1] process CPU time */ public static long[] makeCPUUsageSnapshot() { return new long[] {System.currentTimeMillis(), getProcessCPUTime()}; }