protected static boolean checkIdle(final Point p) throws NimbitsException { final Calendar c = Calendar.getInstance(); c.add(Calendar.SECOND, p.getIdleSeconds() * -1); boolean retVal = false; final List<Entity> result = EntityServiceFactory.getInstance() .getEntityByKey( UserServiceFactory.getServerInstance().getAdmin(), p.getOwner(), EntityType.user); if (!result.isEmpty()) { final User u = (User) result.get(0); final List<Value> v = ValueServiceFactory.getInstance().getCurrentValue(p); if (p.getIdleSeconds() > 0 && !v.isEmpty() && v.get(0).getTimestamp().getTime() <= c.getTimeInMillis() && !p.getIdleAlarmSent()) { p.setIdleAlarmSent(true); EntityServiceFactory.getInstance().addUpdateEntity(u, p); // PointServiceFactory.getInstance().updatePoint(u, p); final Value va = ValueFactory.createValueModel(v.get(0), AlertType.IdleAlert); SubscriptionServiceFactory.getInstance().processSubscriptions(u, p, va); retVal = true; } } return retVal; }
/** * Translate coordinates from one window into another. Optimized for XAWT - uses cached data when * possible. Preferable over pure XTranslateCoordinates. * * @return coordinates relative to dst, or null if error happened */ static Point toOtherWindow(long src, long dst, int x, int y) { Point rpt = new Point(0, 0); // Check if both windows belong to XAWT - then no X calls are necessary XBaseWindow srcPeer = XToolkit.windowToXWindow(src); XBaseWindow dstPeer = XToolkit.windowToXWindow(dst); if (srcPeer != null && dstPeer != null) { // (x, y) is relative to src rpt.x = x + srcPeer.getAbsoluteX() - dstPeer.getAbsoluteX(); rpt.y = y + srcPeer.getAbsoluteY() - dstPeer.getAbsoluteY(); } else if (dstPeer != null && XlibUtil.isRoot(src, dstPeer.getScreenNumber())) { // from root into peer rpt.x = x - dstPeer.getAbsoluteX(); rpt.y = y - dstPeer.getAbsoluteY(); } else if (srcPeer != null && XlibUtil.isRoot(dst, srcPeer.getScreenNumber())) { // from peer into root rpt.x = x + srcPeer.getAbsoluteX(); rpt.y = y + srcPeer.getAbsoluteY(); } else { rpt = XlibUtil.translateCoordinates(src, dst, new Point(x, y)); } return rpt; }