📄 programcanvas.java
字号:
return ret; } /** * Draw the image data which is before and after the current Image */ private void centralizeH () { double t = currImg.endT - currImg.begT; if (currImg.endT < maxT) { int nextId = getNext (currImg.imgIdH); if (img [nextId].begT != currImg.endT || img [nextId].endT != (currImg.endT + t)) renderNextH (1); } if (currImg.begT > 0.0) { int prevId = getPrev (currImg.imgIdH); if (img [prevId].endT != currImg.begT || img [prevId].begT != (currImg.begT - t))renderPrevH (1); } } /** * Draw the image data for the nth image before the current one */ private void renderPrevH (int n) { int prevId = getPrev (currImg.imgIdH); double tL = getTime (_xPix); img [prevId].drawRegion (currImg.begT - n * tL, currImg.begT - (n - 1) * tL); } /** * Draw the image data for the nth image after the current one */ private void renderNextH (int n) { int nextId = getNext (currImg.imgIdH); double tL = getTime (_xPix); img [nextId].drawRegion (currImg.endT + (n - 1) * tL, currImg.endT + n * tL); } /** * Return the image # where the given scrollbar position points to */ private int getCurrGridH (int x) {return x / _xPix;} //-------------------------------------------------------------------------------- /** * place the given StateInfo object in the stateVector of corresponding process */ private void addState (StateInfo event) { int pid = event.procId; if (event.endT > maxT) maxT = event.endT; if ((proct - 1) < pid) addProcess (pid); JProcess currProc = (JProcess)procVector.elementAt (pid); ProcessState ps = new ProcessState (event, currProc); currProc.procStateVector.addElement (ps); } /** * Create a new JProcess object if needed */ private void addProcess (int pid) { for (int x = proct; pid > proct - 1; x++) { JProcess currProc = new JProcess (x); procVector.addElement (currProc); proct ++; } } //Methods describing horizontal and vertical position------------------------------- private void calcYDensity () { yDensity = eachDispIHt / (proct + ((proct + 1) / 5.0)); } double getProcYCord (int pid) { return (hBWt + ((2 * pid + 1) * yDensity / 2.0) + ((pid + 1) * yDensity / 5.0)); } double getEvtYCord (int procId) { //This method calculates the y co-ordinate of the given event w.r.t the //y co-ordinate of the time line for the related processor //yDensity contains pixels / eventHeight return getProcYCord (procId) - yDensity / 2.0; } /** * This method calculates the x co-ordinate of the givent event from its * starting time */ int getEvtXCord (double t) { return (int)(Math.rint (t * xDensity)); } double getTime (int pos) { double time = (1.0 / xDensity) * pos; return time; } /** * This method gets the length for the given event based on its starting and * ending timestamps */ int getW (double begT, double endT) { return ((int)Math.rint (endT * xDensity) - (int)Math.rint (begT * xDensity)); } void updateH () { maxH = getW (0, maxT); } //--------------------------------------------------------------------------------------- /** * Return index of the process where the given y position is placed */ int findIndex (int y) { int index = -1; for (int i = 0; i < proct; i++) { int a = (int)Math.rint (getEvtYCord (i)); int b = a + (int)Math.rint (yDensity); if (y >= a && y <= b) {index = i; break;} } return index; } /** * Return the state upon which the given x and y coordinates are placed */ private ProcessState findState (int x, int y) { int dIndex = y / eachDispHt; if (((Integer)dtypeV.elementAt (dIndex)).intValue () != CONST.TIMELINES) return null; int index = findIndex (y % eachDispHt); y = y % eachDispHt; if (index != -1) { JProcess currProc = (JProcess)(procVector.elementAt (index)); if (currProc.dispStatus) { Enumeration e = currProc.procStateVector.elements (); while (e.hasMoreElements ()) { ProcessState currState = (ProcessState)(e.nextElement()); //Determining using position (less accurate) if (currState.info.stateDef.checkbox.isSelected () && (getEvtXCord (currState.info.begT - currImg.begT) <= cursorPos) && (cursorPos <= getEvtXCord (currState.info.endT - currImg.begT)) && checkLevel (currState, y)) return currState; } } } return null; } /** * Method checks whether the given y coordinate is valid above the given state */ private boolean checkLevel (ProcessState currState, int y) { //This check is not very efficient as for small nestFactors differentiating between //nested states may not yield correct results. Here we give preference to the boundry //of the inner state over the outer state --> y => currState.pt.y && y <= (curr....... //A choice had to be made and we chose this. if (y >= currState.y && y <= (currState.y + currState.h)) return true; return false; } /** * This method returns the index in the given vector of the process with the * given procId */ int getIndex (Vector v, int procId) { Enumeration enum = v.elements (); int index = 0; while (enum.hasMoreElements ()) { JProcess currProc = (JProcess)(enum.nextElement ()); if (currProc.procId == procId) break; index ++; } return index; } /** * Return the ArrowInfo object upon which the given x and y coordinates are placed */ private ArrowInfo findMsg (int x, int y) { if (arrowDispStatus) { int dIndex = y / eachDispHt; if (((Integer)dtypeV.elementAt (dIndex)).intValue () != CONST.TIMELINES) return null; int index = findIndex (y % eachDispHt); y = y % eachDispHt; if (index != -1) { JProcess currProc = (JProcess)(procVector.elementAt (index)); Enumeration enum = parent.quiver.arrowVector.elements (); while (enum.hasMoreElements ()) { ArrowInfo arrow = (ArrowInfo)enum.nextElement (); if (arrow.begProcId == currProc.procId) { int x1 = getEvtXCord (arrow.begT - currImg.begT); int y1 = currProc.y; if (((x1 - img [0].brad) <= (x - _xPix)) && ((x - _xPix) <= (x1 + img [0].brad)) && ((y1 - img [0].brad) <= y) && (y <= (y1 + img [0].brad))) return arrow; } } } } return null; } void calcArrowLens () { Enumeration enum = parent.quiver.arrowVector.elements (); while (enum.hasMoreElements ()) { ArrowInfo arrow = (ArrowInfo)enum.nextElement (); arrow.lenT = arrow.size / (double)(arrow.endT - arrow.begT); } } //Event Handler methods---------------------------------------------------------------- //Events may be generated when the mouse is pressed, released or moved and also if //keyboard keys 'Z' or 'T' are pressed private void setupEventHandlers () { this.enableEvents (AWTEvent.MOUSE_MOTION_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK | AWTEvent.KEY_EVENT_MASK); } /** * Handles the event when the mouse is moved */ public void processMouseMotionEvent (MouseEvent e) { if (e.getID () == MouseEvent.MOUSE_MOVED) { adjustTimeField (e.getX ()); adjustElTimeField (); } else super.processMouseMotionEvent (e); } /** * Handles the event when the mouse is pressed or released */ public void processMouseEvent (MouseEvent e) { if (e.getID () == MouseEvent.MOUSE_PRESSED && parent.dtype == CONST.TIMELINES) { message = handleMsgDlg (e); if (!message) handleEventDlg (e); } else super.processMouseEvent (e); } /** * Check if a state dialog is to be displayed?? */ private void handleEventDlg (MouseEvent e) { int x = e.getX (), y = e.getY (); if (y >= allDispHt) return; ProcessState currEvt = findState (x, y); if (currEvt != null) { StateDlg sd = new StateDlg (parent, currEvt); Point p = getLocationOnScreen (); int tx = x, ty = y; tx += p.x; ty += p.y; sd.setLocation (tx, ty); sd.setVisible (true); } } /** * Check if a message dialog is to be displayed?? */ private boolean handleMsgDlg (MouseEvent e) { int x = e.getX (), y = e.getY (); if (y >= allDispHt) return false; ArrowInfo arrow = findMsg (x, y); if (arrow != null) { MsgDlg md = new MsgDlg (parent, arrow); Point p = getLocationOnScreen (); int tx = x, ty = y; tx += p.x; ty += p.y; md.setLocation (tx, ty); md.setVisible (true); return true; } return false; } /** * Handles the event when the key is pressed */ public void processKeyEvent (KeyEvent e) { int keyCode = e.getKeyCode (); if (e.getID () == KeyEvent.KEY_PRESSED) { if (keyCode == KeyEvent.VK_Z) lockZoom (); else if (keyCode == KeyEvent.VK_T) fixElTimePointer (currTime); } else super.processKeyEvent (e); } //--------------------------------------------------------------------------------------- /** * lock zoom at the current cursor position */ private void lockZoom () { if (zoomLkLineDispStatus) { zXTime = currTime; repaint (); } } /** * fix the elapsed time line to the given time */ void fixElTimePointer (double time) { if (elTLineDispStatus) { elapsedPoint = time; //Refresh (); // currImg.reDrawElTimeLine (); //Not yet implemented repaint (); } } //Methods controlling zooming of data-------------------------------------------------- /** * zoom in horizontally */ void zoomInH () {waitCursor (); zoomH (zF); normalCursor ();} /** * zoom in Vertically */ void zoomOutH () {waitCursor (); zoomH (1 / zF); normalCursor ();} /** * reset view so that all the data fits in a viewport */ void resetView () { waitCursor (); changeConst (1 / zoomH); if (maxH != widthCan) { maxT = tMaxT; xDensity = widthCan / maxT; maxT += (endGap / xDensity); xDensity = widthCan / maxT; updateH (); } adjustZoomImg (0); normalCursor (); } /** * method called whenever a horizontal zoom is performed */ void zoomH (double z) { //Calculations required whenever a horizontal zoom is needed. int tmaxH = maxH; zDist = getW (getTime (tbegH), zXTime); changeConst (z); //Get the scrollbar Position in the zoomed Image int xcord = getEvtXCord (zXTime); sbPos = ((tmaxH > widthCan || maxH > widthCan) && xcord > zDist)? xcord - zDist : 0; if (sbPos + parent.hbar.getVisibleAmount () >= maxH) sbPos = maxH - parent.hbar.getVisibleAmount (); if (sbPos < 0) sbPos = 0; //Get the appropriate image adjustZoomImg (sbPos); } private void changeConst (double z) { zoomH *= z; xDensity *= z; updateH (); } // public void update (Graphics g) {paint (g);} private void adjustZoomImg (int sbPos) { getImgH (getCurrGridH (sbPos)); bflagH = false; fflagH = false; tbegH = sbPos; if (sbPos > 0) { int extra = getW (currImg.begT, zXTime) - zDist;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -