Java 类com.intellij.util.ui.Animator 实例源码

项目:intellij-ce-playground    文件:DialogEarthquakeShaker.java   
public void startShake() {
  myNaturalLocation = myDialog.getLocation();
  myStartTime = System.currentTimeMillis();
  new Animator("EarthQuake", 10, 70, true) {
    @Override
    public void paintNow(int frame, int totalFrames, int cycle) {
      final long elapsed = System.currentTimeMillis() - myStartTime;
      final double waveOffset = (elapsed % 70) / 70d;
      final double angle = waveOffset * 2d * Math.PI;
      final int shakenX = (int)((Math.sin(angle) * 10) + myNaturalLocation.x);
      myDialog.setLocation(shakenX, myNaturalLocation.y);
      myDialog.repaint();
      if (elapsed > 150) {
        suspend();
        myDialog.setLocation(myNaturalLocation);
        myDialog.repaint();
        Disposer.dispose(this);
      }
    }
  }.resume();
}
项目:tools-idea    文件:DialogEarthquakeShaker.java   
public void startShake() {
  myNaturalLocation = myDialog.getLocation();
  myStartTime = System.currentTimeMillis();
  new Animator("EarthQuake", 10, 70, true) {
    @Override
    public void paintNow(int frame, int totalFrames, int cycle) {
      final long elapsed = System.currentTimeMillis() - myStartTime;
      final double waveOffset = (elapsed % 70) / 70d;
      final double angle = waveOffset * 2d * Math.PI;
      final int shakenX = (int)((Math.sin(angle) * 10) + myNaturalLocation.x);
      myDialog.setLocation(shakenX, myNaturalLocation.y);
      myDialog.repaint();
      if (elapsed > 150) {
        suspend();
        myDialog.setLocation(myNaturalLocation);
        myDialog.repaint();
        Disposer.dispose(this);
      }
    }
  }.resume();
}
项目:consulo    文件:DialogEarthquakeShaker.java   
public void startShake() {
  myNaturalLocation = myDialog.getLocation();
  myStartTime = System.currentTimeMillis();
  new Animator("EarthQuake", 10, 70, true) {
    @Override
    public void paintNow(int frame, int totalFrames, int cycle) {
      final long elapsed = System.currentTimeMillis() - myStartTime;
      final double waveOffset = (elapsed % 70) / 70d;
      final double angle = waveOffset * 2d * Math.PI;
      final int shakenX = (int)((Math.sin(angle) * 10) + myNaturalLocation.x);
      myDialog.setLocation(shakenX, myNaturalLocation.y);
      myDialog.repaint();
      if (elapsed > 150) {
        suspend();
        myDialog.setLocation(myNaturalLocation);
        myDialog.repaint();
        Disposer.dispose(this);
      }
    }
  }.resume();
}
项目:intellij-ce-playground    文件:LoadingDecorator.java   
public LoadingDecorator(JComponent content, Disposable parent, int startDelayMs, boolean useMinimumSize) {
  myPane = new MyLayeredPane(useMinimumSize ? content : null);
  myLoadingLayer = new LoadingLayer();
  myDelay = startDelayMs;
  myStartAlarm = new Alarm(Alarm.ThreadToUse.SHARED_THREAD, parent);

  setLoadingText("Loading...");


  myFadeOutAnimator = new Animator("Loading", 10, 500, false) {
    public void paintNow(final int frame, final int totalFrames, final int cycle) {
      myLoadingLayer.setAlpha(1f - ((float)frame) / ((float)totalFrames));
    }

    @Override
    protected void paintCycleEnd() {
      myLoadingLayer.setVisible(false);
      myLoadingLayer.setAlpha(-1);
    }
  };
  Disposer.register(parent, myFadeOutAnimator);


  myPane.add(content, JLayeredPane.DEFAULT_LAYER, 0);
  myPane.add(myLoadingLayer, JLayeredPane.DRAG_LAYER, 1);

  Disposer.register(parent, myLoadingLayer.myProgress);
}
项目:tools-idea    文件:LoadingDecorator.java   
public LoadingDecorator(JComponent content, Disposable parent, int startDelayMs) {
  myLoadingLayer = new LoadingLayer();
  myDelay = startDelayMs;
  myStartAlarm = new Alarm(Alarm.ThreadToUse.SHARED_THREAD, parent);

  setLoadingText("Loading...");


  myFadeOutAnimator = new Animator("Loading", 10, 500, false) {
    public void paintNow(final int frame, final int totalFrames, final int cycle) {
      myLoadingLayer.setAlpha(1f - ((float)frame) / ((float)totalFrames));
    }

    @Override
    protected void paintCycleEnd() {
      myLoadingLayer.setVisible(false);
      myLoadingLayer.setAlpha(-1);
    }
  };
  Disposer.register(parent, myFadeOutAnimator);


  myPane.add(content, 0, JLayeredPane.DEFAULT_LAYER);
  myPane.add(myLoadingLayer, 1, JLayeredPane.DRAG_LAYER);

  Disposer.register(parent, myLoadingLayer.myProgress);
}
项目:consulo    文件:LoadingDecorator.java   
public LoadingDecorator(JComponent content, @Nonnull Disposable parent, int startDelayMs, boolean useMinimumSize, @Nonnull AsyncProcessIcon icon) {
  myPane = new MyLayeredPane(useMinimumSize ? content : null);
  myLoadingLayer = new LoadingLayer(icon);
  myDelay = startDelayMs;
  myStartAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, parent);

  setLoadingText("Loading...");


  myFadeOutAnimator = new Animator("Loading", 10, 500, false) {
    public void paintNow(final int frame, final int totalFrames, final int cycle) {
      myLoadingLayer.setAlpha(1f - ((float)frame) / ((float)totalFrames));
    }

    @Override
    protected void paintCycleEnd() {
      myLoadingLayer.setVisible(false);
      myLoadingLayer.setAlpha(-1);
    }
  };
  Disposer.register(parent, myFadeOutAnimator);


  myPane.add(content, JLayeredPane.DEFAULT_LAYER, 0);
  myPane.add(myLoadingLayer, JLayeredPane.DRAG_LAYER, 1);

  Disposer.register(parent, myLoadingLayer.myProgress);
}
项目:consulo    文件:IntelliJButtonlessScrollBarUI.java   
private Animator createAnimator() {
  return new Animator("Adjustment fadeout", FRAMES_COUNT, FRAMES_COUNT * 50, false) {
    @Override
    public void paintNow(int frame, int totalFrames, int cycle) {
      myAnimationColorShift = getAnimationColorShift();
      if (frame > DELAY_FRAMES) {
        myAnimationColorShift *= 1 - ((double)(frame - DELAY_FRAMES)) / ((double)(totalFrames - DELAY_FRAMES));
      }

      if (scrollbar != null) {
        scrollbar.repaint(((IntelliJButtonlessScrollBarUI)scrollbar.getUI()).getThumbBounds());
      }
    }
  };
}
项目:intellij-ce-playground    文件:ScrollingModelImpl.java   
public AnimatedScrollingRunnable(int startHOffset,
                                 int startVOffset,
                                 int endHOffset,
                                 int endVOffset) throws NoAnimationRequiredException {
  myStartHOffset = startHOffset;
  myStartVOffset = startVOffset;
  myEndHOffset = endHOffset;
  myEndVOffset = endVOffset;

  myHDist = Math.abs(myEndHOffset - myStartHOffset);
  myVDist = Math.abs(myEndVOffset - myStartVOffset);

  myMaxDistToScroll = myEditor.getLineHeight() * 50;
  myTotalDist = Math.sqrt((double)myHDist * myHDist + (double)myVDist * myVDist);
  myScrollDist = Math.min(myTotalDist, myMaxDistToScroll);
  myAnimationDuration = calcAnimationDuration();
  if (myAnimationDuration < SCROLL_INTERVAL * 2) {
    throw new NoAnimationRequiredException();
  }
  myStepCount = myAnimationDuration / SCROLL_INTERVAL - 1;
  double firstStepTime = 1.0 / myStepCount;
  double firstScrollDist = 5.0;
  if (myTotalDist > myScrollDist) {
    firstScrollDist *= myTotalDist / myScrollDist;
    firstScrollDist = Math.min(firstScrollDist, myEditor.getLineHeight() * 5);
  }
  myPow = myScrollDist > 0 ? setupPow(firstStepTime, firstScrollDist / myScrollDist) : 1;

  myAnimator = new Animator("Animated scroller", myStepCount, SCROLL_DURATION, false, true) {
    @Override
    public void paintNow(int frame, int totalFrames, int cycle) {
      double time = ((double)(frame + 1)) / (double)totalFrames;
      double fraction = timeToFraction(time);

      final int hOffset = (int)(myStartHOffset + (myEndHOffset - myStartHOffset) * fraction + 0.5);
      final int vOffset = (int)(myStartVOffset + (myEndVOffset - myStartVOffset) * fraction + 0.5);

      _scrollHorizontally(hOffset);
      _scrollVertically(vOffset);
    }

    @Override
    protected void paintCycleEnd() {
      if (!isDisposed()) { // Animator will invoke paintCycleEnd() even if it was disposed
        finish(true);
      }
    }
  };

  myAnimator.resume();
}
项目:intellij-ce-playground    文件:SheetMessage.java   
void startAnimation (final boolean enlarge) {
  staticImage = myController.getStaticImage();
  JPanel staticPanel = new JPanel() {
    @Override
    public void paint(@NotNull Graphics g) {
      super.paint(g);
      if (staticImage != null) {
        Graphics2D g2d = (Graphics2D) g.create();


        g2d.setBackground(new JBColor(new Color(255, 255, 255, 0), new Color(110, 110, 110, 0)));
        g2d.clearRect(0, 0, myController.SHEET_NC_WIDTH, myController.SHEET_NC_HEIGHT);


        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.95f));

        int multiplyFactor = staticImage.getWidth(null)/myController.SHEET_NC_WIDTH;

        g.drawImage(staticImage, 0, 0,
                    myController.SHEET_NC_WIDTH, imageHeight,
                    0, staticImage.getHeight(null) - imageHeight * multiplyFactor,
                    staticImage.getWidth(null), staticImage.getHeight(null),
                    null);
      }
    }
  };
  staticPanel.setOpaque(false);
  staticPanel.setSize(myController.SHEET_NC_WIDTH,myController.SHEET_NC_HEIGHT);
  myWindow.setContentPane(staticPanel);

  Animator myAnimator = new Animator("Roll Down Sheet Animator", myController.SHEET_NC_HEIGHT ,
                                     TIME_TO_SHOW_SHEET, false) {
    @Override
    public void paintNow(int frame, int totalFrames, int cycle) {
      setPositionRelativeToParent();
      float percentage = (float)frame/(float)totalFrames;
      imageHeight = enlarge ? (int)(((float)myController.SHEET_NC_HEIGHT) * percentage):
                    (int)(myController.SHEET_NC_HEIGHT - percentage * myController.SHEET_HEIGHT);
      myWindow.repaint();
    }

    @Override
    protected void paintCycleEnd() {
      setPositionRelativeToParent();
      if (enlarge) {
        imageHeight = myController.SHEET_NC_HEIGHT;
        staticImage = null;
        myWindow.setContentPane(myController.getPanel(myWindow));

        IJSwingUtilities.moveMousePointerOn(myWindow.getRootPane().getDefaultButton());
        myController.requestFocus();
      } else {
        if (restoreFullScreenButton) {
          FullScreenUtilities.setWindowCanFullScreen(myParent, true);
        }
        myParent.removeComponentListener(myPositionListener);
        myController.dispose();
        myWindow.dispose();
      }
    }
  };

  myAnimator.resume();

}
项目:tools-idea    文件:ScrollingModelImpl.java   
public AnimatedScrollingRunnable(int startHOffset,
                                 int startVOffset,
                                 int endHOffset,
                                 int endVOffset) throws NoAnimationRequiredException {
  myStartHOffset = startHOffset;
  myStartVOffset = startVOffset;
  myEndHOffset = endHOffset;
  myEndVOffset = endVOffset;

  myHDist = Math.abs(myEndHOffset - myStartHOffset);
  myVDist = Math.abs(myEndVOffset - myStartVOffset);

  myMaxDistToScroll = myEditor.getLineHeight() * 50;
  myTotalDist = Math.sqrt((double)myHDist * myHDist + (double)myVDist * myVDist);
  myScrollDist = Math.min(myTotalDist, myMaxDistToScroll);
  myAnimationDuration = calcAnimationDuration();
  if (myAnimationDuration < SCROLL_INTERVAL * 2) {
    throw new NoAnimationRequiredException();
  }
  myStepCount = myAnimationDuration / SCROLL_INTERVAL - 1;
  double firstStepTime = 1.0 / myStepCount;
  double firstScrollDist = 5.0;
  if (myTotalDist > myScrollDist) {
    firstScrollDist *= myTotalDist / myScrollDist;
    firstScrollDist = Math.min(firstScrollDist, myEditor.getLineHeight() * 5);
  }
  myPow = myScrollDist > 0 ? setupPow(firstStepTime, firstScrollDist / myScrollDist) : 1;

  myStartCommand = CommandProcessor.getInstance().getCurrentCommand();

  myAnimator = new Animator("Animated scroller", myStepCount, SCROLL_DURATION, false, true) {
    @Override
    public void paintNow(int frame, int totalFrames, int cycle) {
      double time = ((double)(frame + 1)) / (double)totalFrames;
      double fraction = timeToFraction(time);

      final int hOffset = (int)(myStartHOffset + (myEndHOffset - myStartHOffset) * fraction + 0.5);
      final int vOffset = (int)(myStartVOffset + (myEndVOffset - myStartVOffset) * fraction + 0.5);

      _scrollHorizontally(hOffset);
      _scrollVertically(vOffset);
    }

    @Override
    protected void paintCycleEnd() {
      finish(true);
    }
  };

  myAnimator.resume();
}
项目:consulo    文件:ScrollingModelImpl.java   
public AnimatedScrollingRunnable(int startHOffset,
                                 int startVOffset,
                                 int endHOffset,
                                 int endVOffset) throws NoAnimationRequiredException {
  myStartHOffset = startHOffset;
  myStartVOffset = startVOffset;
  myEndHOffset = endHOffset;
  myEndVOffset = endVOffset;

  myHDist = Math.abs(myEndHOffset - myStartHOffset);
  myVDist = Math.abs(myEndVOffset - myStartVOffset);

  myMaxDistToScroll = myEditor.getLineHeight() * 50;
  myTotalDist = Math.sqrt((double)myHDist * myHDist + (double)myVDist * myVDist);
  myScrollDist = Math.min(myTotalDist, myMaxDistToScroll);
  myAnimationDuration = calcAnimationDuration();
  if (myAnimationDuration < SCROLL_INTERVAL * 2) {
    throw new NoAnimationRequiredException();
  }
  myStepCount = myAnimationDuration / SCROLL_INTERVAL - 1;
  double firstStepTime = 1.0 / myStepCount;
  double firstScrollDist = 5.0;
  if (myTotalDist > myScrollDist) {
    firstScrollDist *= myTotalDist / myScrollDist;
    firstScrollDist = Math.min(firstScrollDist, myEditor.getLineHeight() * 5);
  }
  myPow = myScrollDist > 0 ? setupPow(firstStepTime, firstScrollDist / myScrollDist) : 1;

  myAnimator = new Animator("Animated scroller", myStepCount, SCROLL_DURATION, false, true) {
    @Override
    public void paintNow(int frame, int totalFrames, int cycle) {
      double time = ((double)(frame + 1)) / (double)totalFrames;
      double fraction = timeToFraction(time);

      final int hOffset = (int)(myStartHOffset + (myEndHOffset - myStartHOffset) * fraction + 0.5);
      final int vOffset = (int)(myStartVOffset + (myEndVOffset - myStartVOffset) * fraction + 0.5);

      _scrollHorizontally(hOffset);
      _scrollVertically(vOffset);
    }

    @Override
    protected void paintCycleEnd() {
      if (!isDisposed()) { // Animator will invoke paintCycleEnd() even if it was disposed
        finish(true);
      }
    }
  };

  myAnimator.resume();
}
项目:consulo    文件:SheetMessage.java   
void startAnimation (final boolean enlarge) {
  staticImage = myController.getStaticImage();
  JPanel staticPanel = new JPanel() {
    @Override
    public void paint(@Nonnull Graphics g) {
      super.paint(g);
      if (staticImage != null) {
        Graphics2D g2d = (Graphics2D) g.create();


        g2d.setBackground(new JBColor(new Color(255, 255, 255, 0), new Color(110, 110, 110, 0)));
        g2d.clearRect(0, 0, myController.SHEET_NC_WIDTH, myController.SHEET_NC_HEIGHT);


        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.95f));

        int multiplyFactor = staticImage.getWidth(null)/myController.SHEET_NC_WIDTH;

        g.drawImage(staticImage, 0, 0,
                    myController.SHEET_NC_WIDTH, imageHeight,
                    0, staticImage.getHeight(null) - imageHeight * multiplyFactor,
                    staticImage.getWidth(null), staticImage.getHeight(null),
                    null);
      }
    }
  };
  staticPanel.setOpaque(false);
  staticPanel.setSize(myController.SHEET_NC_WIDTH,myController.SHEET_NC_HEIGHT);
  myWindow.setContentPane(staticPanel);

  Animator myAnimator = new Animator("Roll Down Sheet Animator", myController.SHEET_NC_HEIGHT ,
                                     TIME_TO_SHOW_SHEET, false) {
    @Override
    public void paintNow(int frame, int totalFrames, int cycle) {
      setPositionRelativeToParent();
      float percentage = (float)frame/(float)totalFrames;
      imageHeight = enlarge ? (int)(((float)myController.SHEET_NC_HEIGHT) * percentage):
                    (int)(myController.SHEET_NC_HEIGHT - percentage * myController.SHEET_HEIGHT);
      myWindow.repaint();
    }

    @Override
    protected void paintCycleEnd() {
      setPositionRelativeToParent();
      if (enlarge) {
        imageHeight = myController.SHEET_NC_HEIGHT;
        staticImage = null;
        myWindow.setContentPane(myController.getPanel(myWindow));

        IJSwingUtilities.moveMousePointerOn(myWindow.getRootPane().getDefaultButton());
        myController.requestFocus();
      } else {
        if (restoreFullScreenButton) {
          FullScreenUtilities.setWindowCanFullScreen(myParent, true);
        }
        myParent.removeComponentListener(myPositionListener);
        myController.dispose();
        myWindow.dispose();
        DialogWrapper.cleanupRootPane(myWindow.getRootPane());
      }
    }
  };

  myAnimator.resume();

}