⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 omarrowhead.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                    // need to have the newEndX/Y point at the                    // original start.                    newEndX = xpoints[origStart];                    newEndY = ypoints[origStart];                    if (arrowLocation != 100) {                        // find out where the location should be, but                        // in                        // reverse.                        dx = xpoints[origStart] - xpoints[origEnd];                        dy = ypoints[origStart] - ypoints[origEnd];                        int offset = 0;                        // Straight up or down                        if (dx == 0) {                            // doesn't matter, start and end the same                            newEndX = xpoints[origEnd];                            // calculate the percentage from start of line                            offset = (int) ((float) dy * (arrowLocation / 100.0f));                            // set the end at the begining...                            newEndY = ypoints[origEnd] + offset;                        } else {                            dd = Math.abs((float) dy / (float) dx);                            // If the line moves more x than y                            if (Math.abs(dx) > Math.abs(dy)) {                                // set the x                                newEndX = xpoints[origEnd]                                        + (int) ((float) dx * (arrowLocation / 100.0));                                // find the y for that x and set that                                newEndY = ypoints[origEnd];                                offset = (int) ((float) Math.abs(xpoints[origEnd]                                        - newEndX) * dd);                                if (dy < 0) {                                    newEndY -= offset;                                } else {                                    newEndY += offset;                                }                            } else {                                // switch everything...set y end                                newEndY = ypoints[origEnd]                                        + (int) ((float) dy * (arrowLocation / 100.0));                                // initialize the x to beginning                                newEndX = xpoints[origEnd];                                // calculate the difference x has to                                // move based on y end                                offset = (int) ((float) Math.abs(ypoints[origEnd]                                        - newEndY) / dd);                                // set the end                                if (dx < 0) {                                    newEndX -= offset;                                } else {                                    newEndX += offset;                                }                            }                        }                    } // if (arrowLocation != 100)                    if (start[1] < 0) {                        start[1] = 0;                    }                    // which point do we copy to?                    if (numArrows == 2) {                        // we copy the backwards arrow to                        // sPoint2/ePoint2                        sPoint2.x = xpoints[origEnd];                        sPoint2.y = ypoints[origEnd];                        ePoint2.x = newEndX;                        ePoint2.y = newEndY;                    } else {                        // we copy the backwards arrow to                        // sPoint1/ePoint1                        sPoint1.x = xpoints[origEnd];                        sPoint1.y = ypoints[origEnd];                        ePoint1.x = newEndX;                        ePoint1.y = newEndY;                    }                } // end if needBackwardArrow.                if (needForwardArrow(arrowDirection)) {                    newEndX = xpoints[origEnd];                    newEndY = ypoints[origEnd];                    if (arrowLocation != 100) {                        // find out where the location should be.                        dx = xpoints[origEnd] - xpoints[origStart];                        dy = ypoints[origEnd] - ypoints[origStart];                        int offset = 0;                        // Straight up or down                        if (dx == 0) {                            // doesn't matter, start and end the same                            newEndX = xpoints[origStart];                            // calculate the percentage from start of                            // line                            offset = (int) ((float) dy * (arrowLocation / 100.0f));                            // set the end at the begining...                            newEndY = ypoints[origStart] + offset;                        } else {                            dd = Math.abs((float) dy / (float) dx);                            // If the line moves more x than y                            if (Math.abs(dx) > Math.abs(dy)) {                                // set the x                                newEndX = xpoints[origStart]                                        + (int) ((float) dx * (arrowLocation / 100.0f));                                // find the y for that x and set that                                newEndY = ypoints[origStart];                                offset = (int) ((float) Math.abs(xpoints[origStart]                                        - newEndX) * dd);                                if (dy < 0) {                                    newEndY -= offset;                                } else {                                    newEndY += offset;                                }                            } else {                                // switch everything...set y end                                newEndY = ypoints[origStart]                                        + (int) ((float) dy * (arrowLocation / 100.0));                                // initialize the x to beginning                                newEndX = xpoints[origStart];                                // calculate the difference x has to                                // move                                // based on y end                                offset = (int) ((float) Math.abs(ypoints[origStart]                                        - newEndY) / dd);                                // set the end                                if (dx < 0) {                                    newEndX -= offset;                                } else {                                    newEndX += offset;                                }                            }                        }                    } // end if (arrowLocation != 100)                    // finally, copy the results to sPoint1/ePoint1                    // no longer needed: if (start[0] < 0) { start[0]                    // = 0;                    // }                    sPoint1.x = xpoints[origStart];                    sPoint1.y = ypoints[origStart];                    ePoint1.x = newEndX;                    ePoint1.y = newEndY;                }                break;            case OMLine.CURVED_LINE:                Debug.message("arrowheads",                        "createArrowHeads(): Curved line arrowhead");                if (needBackwardArrow(arrowDirection)) {                    Debug.message("arrowheads",                            "createArrowHeads(): direction backward and");                    // compute the backward index....                    int bindex = pointIndex                            - (int) ((float) pointIndex * (float) (arrowLocation / 100.0));                    if (bindex == 0) {                        bindex = 1;                    }                    if (numArrows == 2) {                        // copy it to s/ePoint2                        sPoint2.x = xpoints[bindex];                        sPoint2.y = ypoints[bindex];                        ePoint2.x = xpoints[bindex - 1];                        ePoint2.y = ypoints[bindex - 1];                    } else {                        // copy it to s/ePoint1                        sPoint1.x = xpoints[bindex];                        sPoint1.y = ypoints[bindex];                        ePoint1.x = xpoints[bindex - 1];                        ePoint1.y = ypoints[bindex - 1];                    }                } // end if (needBackwardArrow(arrowDirection))                if (needForwardArrow(arrowDirection)) {                    int findex = (int) ((float) pointIndex * (float) (arrowLocation / 100.0));                    if (findex == pointIndex) {                        findex = findex - 1;                    }                    sPoint1.x = xpoints[findex];                    sPoint1.y = ypoints[findex];                    ePoint1.x = xpoints[findex + 1];                    ePoint1.y = ypoints[findex + 1];                } // end if (needForwardArrow(arrowDirection))                break;            } // end switch(drawingLinetype)                        pointVec.add(sPoint1.clone());            pointVec.add(ePoint1.clone());                        if (numArrows > 1) {                pointVec.add(sPoint2.clone());                pointVec.add(ePoint2.clone());            }                    }        Point[] ret = new Point[pointVec.size()];        int i = 0;        for (Iterator it = pointVec.iterator();it.hasNext(); i++) {            ret[i] = (Point)it.next();        }                return ret;    }    private static boolean needBackwardArrow(int arrowDir) {        return (arrowDir == ARROWHEAD_DIRECTION_BACKWARD || arrowDir == ARROWHEAD_DIRECTION_BOTH);    }    private static boolean needForwardArrow(int arrowDir) {        return (arrowDir == ARROWHEAD_DIRECTION_FORWARD || arrowDir == ARROWHEAD_DIRECTION_BOTH);    }    public int getArrowDirectionType() {        return arrowDirectionType;    }    public void setArrowDirectionType(int arrowDirectionType) {        this.arrowDirectionType = arrowDirectionType;    }    public int getLocation() {        return location;    }    public void setLocation(int location) {        if (location < 1)            this.location = 1;        else if (location > 100)            this.location = 100;        else            this.location = location;    }    public Shape getShape() {        return shape;    }    public void setShape(Shape shape) {        this.shape = shape;    }    public int getWingLength() {        return wingLength;    }    public void setWingLength(int wingLength) {        this.wingLength = wingLength;    }    public int getWingTip() {        return wingTip;    }    public void setWingTip(int wingTip) {        this.wingTip = wingTip;    }}

⌨️ 快捷键说明

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