/** * Returns the maximum amount of space the layout can use. * * @param the Container for which this layout manager is being used * @return a Dimension object containing the layout's maximum size */ public Dimension maximumLayoutSize(Container target) { Dimension cpd; int cpWidth = Integer.MAX_VALUE; int cpHeight = Integer.MAX_VALUE; int mbWidth = Integer.MAX_VALUE; int mbHeight = Integer.MAX_VALUE; int tpWidth = Integer.MAX_VALUE; int tpHeight = Integer.MAX_VALUE; Insets i = target.getInsets(); JRootPane root = (JRootPane) target; if (root.getContentPane() != null) { cpd = root.getContentPane().getMaximumSize(); if (cpd != null) { cpWidth = cpd.width; cpHeight = cpd.height; } } int maxHeight = Math.max(Math.max(cpHeight, mbHeight), tpHeight); // Only overflows if 3 real non-MAX_VALUE heights, sum to > MAX_VALUE // Only will happen if sums to more than 2 billion units. Not likely. if (maxHeight != Integer.MAX_VALUE) { maxHeight = cpHeight + mbHeight + tpHeight + i.top + i.bottom; } int maxWidth = Math.max(Math.max(cpWidth, mbWidth), tpWidth); // Similar overflow comment as above if (maxWidth != Integer.MAX_VALUE) { maxWidth += i.left + i.right; } return new Dimension(maxWidth, maxHeight); }
/** * Returns the minimum amount of space the layout needs. * * @param the Container for which this layout manager is being used * @return a Dimension object containing the layout's minimum size */ public Dimension minimumLayoutSize(Container parent) { Dimension cpd; int cpWidth = 0; int cpHeight = 0; int mbWidth = 0; int mbHeight = 0; int tpWidth = 0; Insets i = parent.getInsets(); JRootPane root = (JRootPane) parent; if (root.getContentPane() != null) { cpd = root.getContentPane().getMinimumSize(); } else { cpd = root.getSize(); } if (cpd != null) { cpWidth = cpd.width; cpHeight = cpd.height; } return new Dimension( Math.max(Math.max(cpWidth, mbWidth), tpWidth) + i.left + i.right, cpHeight + mbHeight + tpWidth + i.top + i.bottom); }
/** * Returns the amount of space the layout would like to have. * * @param the Container for which this layout manager is being used * @return a Dimension object containing the layout's preferred size */ public Dimension preferredLayoutSize(Container parent) { Dimension cpd, tpd; int cpWidth = 0; int cpHeight = 0; int mbWidth = 0; int mbHeight = 0; int tpWidth = 0; Insets i = parent.getInsets(); JRootPane root = (JRootPane) parent; if (root.getContentPane() != null) { cpd = root.getContentPane().getPreferredSize(); } else { cpd = root.getSize(); } if (cpd != null) { cpWidth = cpd.width; cpHeight = cpd.height; } if (root.getWindowDecorationStyle() != JRootPane.NONE && (root.getUI() instanceof RootPaneUI)) { JComponent titlePane = ((RootPaneUI) root.getUI()).getTitlePane(); if (titlePane != null) { tpd = titlePane.getPreferredSize(); if (tpd != null) { tpWidth = tpd.width; } } } return new Dimension( Math.max(Math.max(cpWidth, mbWidth), tpWidth) + i.left + i.right, cpHeight + mbHeight + tpWidth + i.top + i.bottom); }
/** * Returns the maximum amount of space the layout can use. * * @param the Container for which this layout manager is being used * @return a Dimension object containing the layout's maximum size */ public Dimension maximumLayoutSize(Container target) { Dimension cpd, mbd, tpd; int cpWidth = Integer.MAX_VALUE; int cpHeight = Integer.MAX_VALUE; int mbWidth = Integer.MAX_VALUE; int mbHeight = Integer.MAX_VALUE; int tpWidth = Integer.MAX_VALUE; int tpHeight = Integer.MAX_VALUE; Insets i = target.getInsets(); JRootPane root = (JRootPane) target; if (root.getContentPane() != null) { cpd = root.getContentPane().getMaximumSize(); if (cpd != null) { cpWidth = cpd.width; cpHeight = cpd.height; } } if (root.getMenuBar() != null) { mbd = root.getMenuBar().getMaximumSize(); if (mbd != null) { mbWidth = mbd.width; mbHeight = mbd.height; } } if (root.getWindowDecorationStyle() != JRootPane.NONE && (root.getUI() instanceof HokageRootPaneUI)) { JComponent titlePane = ((HokageRootPaneUI) root.getUI()).getTitlePane(); if (titlePane != null) { tpd = titlePane.getMaximumSize(); if (tpd != null) { tpWidth = tpd.width; tpHeight = tpd.height; } } } int maxHeight = Math.max(Math.max(cpHeight, mbHeight), tpHeight); // Only overflows if 3 real non-MAX_VALUE heights, sum to > MAX_VALUE // Only will happen if sums to more than 2 billion units. Not likely. if (maxHeight != Integer.MAX_VALUE) { maxHeight = cpHeight + mbHeight + tpHeight + i.top + i.bottom; } int maxWidth = Math.max(Math.max(cpWidth, mbWidth), tpWidth); // Similar overflow comment as above if (maxWidth != Integer.MAX_VALUE) { maxWidth += i.left + i.right; } return new Dimension(maxWidth, maxHeight); }
/** * Returns a partial token. * * @param token input text * @param start start position * @param end end position * @return resulting text */ public static byte[] subtoken(final byte[] token, final int start, final int end) { int s = Math.max(0, start); final int e = Math.min(end, token.length); if (s == 0 && e == token.length) return token; if (s >= e) return EMPTY; int t = Math.max(0, s - 4); for (; t != s && t < e; t += cl(token, t)) { if (t >= s) s = t; } for (; t < e; t += cl(token, t)) ; return Arrays.copyOfRange(token, s, t); }
public void run() { try { if (myPreviousThread != null) myPreviousThread.join(); Thread.sleep(delay); log("> run MouseMoveThread " + x + ", " + y); while (!hasFocus()) { Thread.sleep(1000); } int x1 = lastMouseX; int x2 = x; int y1 = lastMouseY; int y2 = y; // shrink range by 1 px on both ends // manually move this 1px to trip DND code if (x1 != x2) { int dx = x - lastMouseX; if (dx > 0) { x1 += 1; x2 -= 1; } else { x1 -= 1; x2 += 1; } } if (y1 != y2) { int dy = y - lastMouseY; if (dy > 0) { y1 += 1; y2 -= 1; } else { y1 -= 1; y2 += 1; } } robot.setAutoDelay(Math.max(duration / 100, 1)); robot.mouseMove(x1, y1); int d = 100; for (int t = 0; t <= d; t++) { x1 = (int) easeInOutQuad( (double) t, (double) lastMouseX, (double) x2 - lastMouseX, (double) d); y1 = (int) easeInOutQuad( (double) t, (double) lastMouseY, (double) y2 - lastMouseY, (double) d); robot.mouseMove(x1, y1); } robot.mouseMove(x, y); lastMouseX = x; lastMouseY = y; robot.waitForIdle(); robot.setAutoDelay(1); } catch (Exception e) { log("Bad parameters passed to mouseMove"); e.printStackTrace(); } log("< run MouseMoveThread"); }
/** * Computes CPU usage (fraction of 1.0) between <code>start[1]</code> and <code>end[1]</code> time * points [1.0 corresponds to 100% utilization of all processors]. * * @throws IllegalArgumentException if start and end time points are less than #MIN_ELAPSED_TIME * ms apart. * @throws IllegalArgumentException if either argument is null * @param start,end long[2]: [0] system time stamp, [1] process CPU time (as returned by * makeCPUUsageSnapshot()). */ public static double getProcessCPUUsage(long[] start, long[] end) { if (start == null) throw new IllegalArgumentException("null input: start"); if (end == null) throw new IllegalArgumentException("null input: end"); // if (end[0] < start[0] + MIN_ELAPSED_TIME) throw new IllegalArgumentException("end time must // be at least " + MIN_ELAPSED_TIME + " ms later than start time"); end[0] = Math.max(end[0], start[0] + MIN_ELAPSED_TIME); return ((double) (end[1] - start[1])) / (double) (end[0] - start[0]); }
public void run() { try { if (myPreviousThread != null) myPreviousThread.join(); Thread.sleep(delay); log("> run MouseWheelThread " + amount); while (!hasFocus()) { Thread.sleep(1000); } int dir = 1; if (System.getProperty("os.name").toUpperCase().indexOf("MAC") != -1) { // yay for Apple dir = -1; } robot.setAutoDelay(Math.max(duration / Math.abs(amount), 1)); for (int i = 0; i < Math.abs(amount); i++) { robot.mouseWheel(amount > 0 ? dir : -dir); } robot.setAutoDelay(1); } catch (Exception e) { log("Bad parameters passed to mouseWheel"); e.printStackTrace(); } log("< run MouseWheelThread "); }
/** * Returns a substring of the specified token. Note that this method does not correctly split UTF8 * character; use {@link #subtoken} instead. * * @param token input token * @param start start position * @param end end position * @return substring */ public static byte[] substring(final byte[] token, final int start, final int end) { final int s = Math.max(0, start); final int e = Math.min(end, token.length); if (s == 0 && e == token.length) return token; return s >= e ? EMPTY : Arrays.copyOfRange(token, s, e); }