private void showMessage(String messageText, int secondsToDisplay) { if (messageAnnotation != null) { this.removeRenderable(messageAnnotation); } messageAnnotation = new OutlinedTextAnnotation(messageText, messageFont); messageAnnotation.setValue(AVKey.VIEW_OPERATION, AVKey.VIEW_PAN); messageAnnotation.getAttributes().setSize(new Dimension(500, 500)); this.addRenderable(messageAnnotation); // 1- Taking an instance of Timer class. if (timer != null) { timer.cancel(); } timer = new Timer("FadeOut"); // 2- Taking an instance of class contains your repeated method. FadeInOutMessageTask t = new FadeInOutMessageTask(secondsToDisplay); timer.schedule(t, 0, 100); }
public void prepareForEye(boolean left) { float anchorPointX = WorldWindVRConstants.RenderHorizontalResolution / 4.0f; float anchorPointY = WorldWindVRConstants.RenderVerticalResolution / 2.0f; float messageWidth = messageAnnotation .getGraphicsContext() .getFontMetrics() .stringWidth(messageAnnotation.getOutlinedText()); float messageHeight = messageAnnotation.getGraphicsContext().getFontMetrics().getHeight(); anchorPointX -= (messageWidth / 2.0f); anchorPointY += messageHeight / 2.0f; // not sure why we need this anchorPointX += 100; // anchorPointY += 110 ; int pixelSeparation = 40; if (left) { messageAnnotation.setScreenPoint( new Point((int) (anchorPointX + pixelSeparation), (int) anchorPointY)); } else { messageAnnotation.setScreenPoint(new Point((int) (anchorPointX), (int) anchorPointY)); } }