commontransitions.java.svn-base

来自「j2me设计的界面包」· SVN-BASE 代码 · 共 479 行 · 第 1/2 页

SVN-BASE
479
字号
                motion = Motion.createSplineMotion(startOffset, dest, speed);                // make sure the destination is painted fully at least once                 // we must use a full buffer otherwise the clipping will take effect                Graphics g = buffer.getGraphics();                                // If this is a dialog render the tinted frame once since                 // tinting is expensive                if(getSource() instanceof Dialog) {                    paint(g, getDestination(), 0, 0);                } else {                    if(getDestination() instanceof Dialog) {                        paint(g, getSource(), 0, 0);                    } else {                        paint(g, source, -source.getAbsoluteX(), -source.getAbsoluteY());                    }                }                motion.start();            }        }                // for series 40 devices        System.gc();    }    /**     * @inheritDoc     */    public boolean animate() {        if(motion == null) {            return false;        }        position = motion.getValue();                // after the motion finished we need to paint one last time otherwise        // there will be a "bump" in sliding        if(firstFinished) {            return false;        }        boolean finished = motion.isFinished();        if(finished) {            if(!firstFinished) {                firstFinished = true;            }        }        return true;    }        /**     * @inheritDoc     */    public void paint(Graphics g) {        try {            switch (transitionType) {                case TYPE_SLIDE:                    // if this is an up or down slide                    if (slideType == SLIDE_HORIZONTAL) {                        paintSlideAtPosition(g, position, 0);                    } else {                        paintSlideAtPosition(g, 0, position);                    }                    return;                case TYPE_FADE:                    paintAlpha(g);                    return;            }        } catch(Throwable t) {            System.out.println("An exception occured during transition paint this might be valid in case of a resize in the middle of a transition");            t.printStackTrace();        }    }    private void paintAlpha(Graphics graphics) {        // this will always be invoked on the EDT so there is no race condition risk        if(rgbBuffer != null) {            Component src = getSource();            int w = src.getWidth();            int h = src.getHeight();            int position = this.position;            if (position > 255) {                position = 255;            } else {                if (position < 0) {                    position = 0;                }            }            int alpha = position << 24;            int size = w * h;            int[] bufferArray = rgbBuffer.getRGB();            for (int iter = 0 ; iter < size ; iter++) {                bufferArray[iter] = ((bufferArray[iter] & 0xFFFFFF) | alpha);            }            Component dest = getDestination();                            int x = dest.getAbsoluteX();            int y = dest.getAbsoluteY();                        graphics.setClip(x, y, w, h);            graphics.drawImage(buffer, x, y);            graphics.drawImage(rgbBuffer, x, y);        }    }    /**     * @inheritDoc     */    public void cleanup() {        super.cleanup();        buffer = null;        rgbBuffer = null;    }    private void paintSlideAtPosition(Graphics g, int slideX, int slideY) {        Component source = getSource();                // if this is the first form we can't do a slide transition since we have no source form        if (source == null) {             return;                   }                Component dest = getDestination();                        int w = source.getWidth();        int h = source.getHeight();                            if (slideType == SLIDE_HORIZONTAL) {            h = 0;        } else {            w = 0;        }        if(forward) {            w = -w;            h = -h;        } else {            slideX = -slideX;            slideY = -slideY;        }        g.setClip(source.getAbsoluteX(), source.getAbsoluteY(), source.getWidth(), source.getHeight());                    // dialog animation is slightly different...         if(source instanceof Dialog) {            g.drawImage(buffer, 0, 0);            paint(g, source, -slideX, -slideY);            return;        }                 if(dest instanceof Dialog) {            g.drawImage(buffer, 0, 0);            paint(g, dest, -slideX - w, -slideY - h);            return;        }                 g.setClip(source.getAbsoluteX(), source.getAbsoluteY(), source.getWidth(), source.getHeight());               g.clipRect(dest.getAbsoluteX(), dest.getAbsoluteY(), source.getWidth(), source.getHeight());        if(source.getParent() != null){            source.paintBackgrounds(g);            paint(g, source, slideX , slideY );        }else{            g.drawImage(buffer, slideX, slideY);                }        paint(g, dest, slideX + w, slideY + h);            }    private void paint(Graphics g, Component cmp, int x, int y) {        int cx = g.getClipX();        int cy = g.getClipY();        int cw = g.getClipWidth();        int ch = g.getClipHeight();        if(cmp instanceof Dialog) {            if(transitionType != TYPE_FADE) {                if(!(getSource() instanceof Dialog && getDestination() instanceof Dialog &&                         cmp == getDestination())) {                    Painter p = cmp.getStyle().getBgPainter();                    cmp.getStyle().setBgPainter(null);                    g.translate(x, y);                    Dialog dlg = (Dialog)cmp;                    g.setClip(0, 0, cmp.getWidth(), cmp.getHeight());                    dlg.getTitleComponent().paintComponent(g, false);                    g.setClip(0, 0, cmp.getWidth(), cmp.getHeight());                    dlg.getContentPane().paintComponent(g, false);                    g.translate(-x, -y);                    if(drawDialogMenu && dlg.getCommandCount() > 0) {                        Component menuBar = dlg.getSoftButton(0).getParent();                        g.setClip(0, 0, cmp.getWidth(), cmp.getHeight());                        menuBar.paintComponent(g, false);                    }                    g.setClip(cx, cy, cw, ch);                    cmp.getStyle().setBgPainter(p);                    return;                }            }             cmp.paintComponent(g, false);            return;        }        g.clipRect(cmp.getAbsoluteX(), cmp.getAbsoluteY(), cmp.getWidth(), cmp.getHeight());         g.translate(x, y);        g.clipRect(cmp.getAbsoluteX(), cmp.getAbsoluteY(), cmp.getWidth(), cmp.getHeight());        cmp.paintComponent(g, false);         g.translate(-x, -y);                g.setClip(cx, cy, cw, ch);    }        /**     * Motion represents the physical movement within a transition, it can     * be replaced by the user to provide a more appropriate physical feel     *      * @return the instanceo of the motion class used by this transition     */    public Motion getMotion() {        return motion;    }    /**     * Motion represents the physical movement within a transition, it can     * be replaced by the user to provide a more appropriate physical feel     *      * @param motion new instance of the motion class that will be used by the transition     */    public void setMotion(Motion motion) {        this.motion = motion;    }            public Transition copy(){        CommonTransitions retVal = null;        if(transitionType == TYPE_FADE){            retVal = CommonTransitions.createFade(speed);        }else if(transitionType == TYPE_SLIDE){            retVal = CommonTransitions.createSlide(slideType, forward, speed, drawDialogMenu);        }else if(transitionType == TYPE_EMPTY){            retVal = CommonTransitions.createEmpty();        }        return retVal;    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?