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

📄 basicparalleldisplayui.java

📁 一个java版本数据分析显示程序
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                        oldScale = comp.getAxisScale(activeAxis);            oldOffset = comp.getAxisOffset(activeAxis);                        clickValue = ((float)oldMouseY - borderV) / (comp.getHeight() - 2*borderV);             clickAxisValue = comp.getAxisOffset(activeAxis) +  clickValue * comp.getAxisScale(activeAxis);        }                switch (comp.getEditMode()){            case ParallelDisplay.REORDER:                 dragAxis = true;                break;            case ParallelDisplay.BRUSH:                inBrush = true;                                if (inAngularBrush && angularPhase1){                    angularPhase1 = false;                                        angularStartX = angularCurX;                    angularStartY = angularCurY;                }                else {                    if (activeAxis != -1) {                        brushHoverStart = oldMouseY - borderV;                        brushHoverEnd = oldMouseY - borderV;                        brushHoverX = oldMouseX - borderH;                        inAngularBrush = false;                    }                    else {                        inAngularBrush = true;                        angularPhase1 = true;                        angularRefX = e.getX() - borderH;                        angularRefY = e.getY() - borderV;                        angularCurX = angularRefX;                        angularCurY = angularRefY;                        angularRegion = hoverRegion;                    }                }                                    dragBrush = new Brush(comp.getNumRecords(), comp.getColorPreference("brushColor"));                if (e.isControlDown()){                    brushmode = BRUSH_INTERSECT;                }                else if (e.isShiftDown()){                    brushmode = BRUSH_ADD;                }                else if (e.isAltDown()){                    brushmode = BRUSH_SUBTRACT;                }                else {                    brushmode = BRUSH_NORMAL;                }                hoverRecord = -1;                                if (brushImg == null) {                    brushImg = new BufferedImage(comp.getWidth(), comp.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);                    Graphics2D ig = brushImg.createGraphics();                    //fill with transparent white                    ig.setColor(new Color(1.0f, 1.0f, 1.0f, 0.0f));                    ig.fillRect(0,0,comp.getWidth(), comp.getHeight());                }        }            }     /**     * Invoked when a mouse button is pressed on a component and then     * dragged.  Mouse drag events will continue to be delivered to     * the component where the first originated until the mouse button is     * released (regardless of whether the mouse position is within the     * bounds of the component).     *     * Depending on the current mode, this method performs scaling, translating     * or reordering of axes.     *     * @param e The mouse event.     */    public void mouseDragged(MouseEvent e) {        ParallelDisplay comp = (ParallelDisplay)e.getComponent();                int mouseX = e.getX();        int mouseY = e.getY();                setMetaInfo(null,0,0);                switch (comp.getEditMode()){            case ParallelDisplay.SCALE:                 if (activeAxis != -1){                    float way = ((float)(oldMouseY - mouseY)) / (comp.getHeight() - 2*borderV);                    comp.setAxisScale(activeAxis, oldScale + (way * oldScale)) ;                     float newValue = clickValue * (comp.getAxisScale(activeAxis) - oldScale);                    comp.setAxisOffset(activeAxis, oldOffset - newValue);                                        renderRegion(activeAxis - 1, activeAxis + 1);                }                break;            case ParallelDisplay.TRANSLATE:                 if (activeAxis != -1){                    float way = ((float)(oldMouseY - mouseY)) / (comp.getHeight() - 2*borderV);                    way *= comp.getAxisScale(activeAxis);                    comp.setAxisOffset(activeAxis, oldOffset + way);                    renderRegion(activeAxis - 1, activeAxis + 1);                }                break;            case ParallelDisplay.REORDER:                if (activeAxis != -1){                    int deltaX = mouseX - oldMouseX;                    int num = activeAxis + deltaX / stepx;                                        if (num < 0) num = 0;                    if (num >= numDimensions) num = numDimensions-1;                                        dragX = mouseX;                                        if (activeAxis != num) {                        comp.swapAxes(activeAxis, num);                                                                        //System.out.println("setting repaint axes: " + (Math.min(num,activeAxis) - 1) + ", " + (Math.max(num,activeAxis) + 1));                                                renderRegion(Math.min(num,activeAxis) - 1, Math.max(num,activeAxis) + 1);                        activeAxis = num;                        hoverAxis = num;                        oldMouseX = stepx * num + borderH;                      }                    // to display hoverAxis                    comp.repaint();                }                break;            case ParallelDisplay.BRUSH:                if ( !inAngularBrush){                    brushHoverEnd = mouseY - borderV;                    float releaseValue = ((float)mouseY - borderV) / (comp.getHeight() - 2*borderV);                    releaseValue = comp.getAxisOffset(activeAxis) +  releaseValue * comp.getAxisScale(activeAxis);                    float lowerBound = Math.min(clickAxisValue, releaseValue);                    float upperBound = Math.max(clickAxisValue, releaseValue);                    boolean doSoft = comp.getBoolPreference("softBrush");                    float radius = 0.0f;                    int ids[];                    if (doSoft){                        radius = comp.getFloatPreference("brushRadius") * (upperBound - lowerBound);                        if (radius == 0.0f) {                            System.out.println("radius is zero");                            doSoft = false;                        }                        ids = comp.getRecordsByValueRange(activeAxis, lowerBound - radius, upperBound + radius);                    }                    else {                        ids = comp.getRecordsByValueRange(activeAxis, lowerBound, upperBound);                    }                    int id = 0;                    for (int i=0; i<comp.getNumRecords(); i++){                        float brushVal = 0.0f;                        if ((ids.length > 0) && (i == ids[id])){                            //record is inside brush region                                                        brushVal = 1.0f;                                                        if (doSoft){                                float val = comp.getValue(i, activeAxis);                                if (val < lowerBound) {                                    brushVal = 1.0f - ( -val + lowerBound ) / radius;                                }                                if (val > upperBound) {                                    brushVal = 1.0f - ( val - upperBound ) / radius;                                }                            }                                                        if (id < ids.length-1) id++;                        }                                                dragBrush.setBrushValue(i, brushVal);                    }                                                                        }                else {  //  angular brushing                    angularCurX = mouseX - borderH;                    angularCurY = mouseY - borderV;                    if (!angularPhase1){                        float maxratio = (angularRefY - angularStartY) / (float)(angularStartX - angularRefX);                        float tempratio = (angularRefY - angularCurY) / (float)(angularCurX - angularRefX);                        float minratio = Math.min(maxratio, tempratio);                        maxratio = Math.max(maxratio, tempratio);                                                angularAngle1 = (float)Math.atan(maxratio);                        angularAngle2 = (float)Math.atan(minratio);                                                //System.out.println("a1: " + angularAngle1 + " a2: " + angularAngle2);                                                for (int i=0; i<dragBrush.getNumValues(); i++){                            float val1 = (comp.getValue(i, angularRegion) - comp.getAxisOffset(angularRegion)) / comp.getAxisScale(angularRegion) * (comp.getHeight() - 2 * borderV);                            float val2 = (comp.getValue(i, angularRegion+1) - comp.getAxisOffset(angularRegion+1)) / comp.getAxisScale(angularRegion+1) * (comp.getHeight() - 2 * borderV);                            float ratio =  (val1 - val2) / stepx;                                                        //System.out.println("val1: " + val1 + " val2: " + val2 + " ratio: " + ratio + "minratio: " + minratio + " maxratio: " + maxratio);                            //System.out.println("axis1: " + angularRegion);                            if (ratio >= minratio && ratio <= maxratio){                                //System.out.println("setting brush num " + i + " ratio: " + ratio + " minratio: " + minratio + " maxratio: " + maxratio);                                dragBrush.setBrushValue(i, 1.0f);                            }                            else {                                dragBrush.setBrushValue(i, 0.0f);                            }                        }                    }                }                if (brushmode == BRUSH_INTERSECT){                    tempBrush = comp.getCurrentBrush().intersect(dragBrush);                }                else if (brushmode == BRUSH_ADD){                    tempBrush = comp.getCurrentBrush().add(dragBrush);                }                else if (brushmode == BRUSH_SUBTRACT){                    tempBrush = comp.getCurrentBrush().subtract(dragBrush);                }                else {                    tempBrush = dragBrush;                }                comp.fireBrushModified(tempBrush);                                if (tempBrush.getNumBrushed() > 0){                    brushThread.setBrush(tempBrush);                    renderBrush();                    // to see brush line in realtime                }                comp.repaint();                break;                            }            }            /**     * Invoked when the mouse has been clicked on a component.     *     * Checks if the click hit an arrow and inverts the corresponding axis.     *     * @param e The mouse event.     */    public void mouseClicked(MouseEvent e) {        ParallelDisplay comp = (ParallelDisplay)e.getComponent();                        //arrow clicked or invert mode        if ((comp.getEditMode() == ParallelDisplay.INVERT) || (e.getY() <= 25 && e.getY()>12)) {            if (hoverAxis != -1){                comp.setAxisOffset(hoverAxis, comp.getAxisOffset(hoverAxis) + comp.getAxisScale(hoverAxis));                comp.setAxisScale(hoverAxis, comp.getAxisScale(hoverAxis) * -1);                renderRegion(activeAxis - 1, activeAxis + 1);                                }        }                    }        /**     * Invoked when the mouse enters a component.     */    public void mouseEntered(MouseEvent e) {    }     /**     * Invoked when the mouse button has been moved on a component     * (with no buttons no down).     *     * Displays tooltips if mouse is hovering over axes or records.     *     * @param e The mouse event.     */    public void mouseMoved(MouseEvent e) {        ParallelDisplay comp = (ParallelDisplay)e.getComponent();        if ( inBrush ){            if (inAngularBrush && angularPhase1){                angularCurX = e.getX() - borderH;                angularCurY = e.getY() - borderV;                comp.repaint();            }        }        else {            int mousex = e.getX() - borderH;            int mousey = e.getY() - borderV;            int oldAxis = hoverAxis;            int oldRecord = hoverRecord;            hoverAxis = -1;            for (int i=0; i<numDimensions; i++){                if ((mousex > (i*stepx - 6)) && (mousex < (i*stepx + 6))) {                    hoverAxis = i;                }                if ((mousex > i*stepx) && (mousex < (i+1)*stepx)){                    comp.popupMenu.setTargetRegion(i+1);                    hoverRegion = i;                }            }                        if (mousex < 0) comp.popupMenu.setTargetRegion(0);            hoverRecord = getRecordByCoordinates(mousex, mousey, comp);            if ((oldAxis != hoverAxis) || (oldRecord != hoverRecord)){                if (hoverAxis != -1){                    setMetaInfo(comp.getAxisLabel(hoverAxis), mousex, mousey);                    switch (comp.getEditMode()){                        case ParallelDisplay.REORDER:                            comp.setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));                            break;                        case ParallelDisplay.SCALE:                            comp.setCursor(Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR));                            break;                        case ParallelDisplay.TRANSLATE:                            comp.setCursor(Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR));                            break;                        case ParallelDisplay.INVERT:                            comp.setCursor(Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR));                            break;                        case ParallelDisplay.BRUSH:                            comp.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));                            break;                    }                }                else {                    setMetaInfo(null,0,0);                    comp.resetCursor();                }                if (hoverRecord != -1) {                    setMetaInfo(comp.getRecordLabel(hoverRecord), mousex, mousey);                }                comp.repaint();            }        }      }        /**     * Helper method to display a tooltip on hover.     */    private void setMetaInfo(String text, int x, int y){        metaText = text;        metaX = x;        metaY = y;    }        /**     * Returns the record that goes through the screen coordinates x,y. The first     * record that is found is returned.     *     * @param x The x screen coordinate.     * @param y The y screen coordinate.     * @param comp The "parent" component.     *     * @return The recordnumber of the first record found passing through the given point.     */     public int getRecordByCoordinates(int x, int y, ParallelDisplay comp){        for (int i=0; i<numDimensions - 1; i++){            if ((x >= i*stepx) && (x < (i+1)*stepx)) {                float part = (x - i*stepx) / (float)stepx;                for (int j=0; j<numRecords; j++){                    float recVal = (1-part) * getYValue(j,i,comp) + part * getYValue(j,i+1,comp);                                        if (Math.abs(recVal - y) < 3.0) return j;                }                break;            }        }                return -1;    }        }

⌨️ 快捷键说明

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