📄 myimage.java
字号:
} } } } /** * Draws the given process state in this image. */ private void draw( StateInterval state, double py, Graphics g1, Graphics g2 ) { /* double timeDiff = state.info.begT - begT; double effT = (timeDiff > 0)? timeDiff : 0.0; double lenT = endT - begT; int maxW = canvas.getW (effT, lenT); int w = canvas.getW (effT, state.info.endT - begT); if (w > maxW) w = maxW; int x = canvas.getEvtXCord (effT); */ boolean startflag = (state.info.begT >= begT) ? true : false; boolean endflag = (state.info.endT <= endT) ? true : false; // The origin is set at the X = begT int x1 = canvas.getEvtXCord( state.info.begT - begT ); int x2 = canvas.getEvtXCord( state.info.endT - begT ); // Define the interval segment to be drawn within the range of image buffer int x = startflag ? x1 : 0; int w = endflag ? x2 - x : canvas.getEvtXCord( endT - begT ) - x; if (!(x == prev_state_beg_pos && (w == 0 || w == 1))) { double diff = state.info.level * canvas.yDensity * canvas.nestFactor; double height = canvas.yDensity - diff; int y = (int)Math.rint (py - height / 2.0); int h = (int)Math.rint (height); //Done so that when state dialog has to pop up it uses these values state.y = y; state.h = h; if (state.h == 0) state.h = 1; Color c = state.info.stateDef.color; displayRect (g1, c, x, y, w, h, startflag, endflag); if (g2 != null && !state.info.blink) displayRect (g2, c, x, y, w, h, startflag, endflag); } prev_state_beg_pos = x; } private void displayRect (Graphics g, Color c, int x, int y, int w, int h, boolean startflag, boolean endflag) { g.setColor (c); if (w == 0) w = 1; if (h == 0) h = 1; g.fillRect (x, y, w, h); g.setColor (Color.white); g.drawLine (x, y, x + w - 1, y); g.drawLine (x, y + h - 1, x + w - 1, y + h - 1); if (startflag) g.drawLine (x, y, x, y + h - 1); if (endflag) g.drawLine (x + w - 1, y, x + w - 1, y + h - 1); } /** * Draws Process time Line */ private void draw (StateGroup p, double py, Graphics g1, Graphics g2) { int y = (int)Math.rint (py); //Used for locating arrows p.y = y; g1.setColor (Color.red); g1.drawLine (0, y, _xPix - 1, y); if (g2 != null) { g2.setColor (Color.red); g2.drawLine (0, y, _xPix - 1, y); } } /** * Check whether the given arrow should be drawn in this image or not. */ private boolean check( ArrowInfo arrow, double b, double e ) { int start_idx, end_idx; if ( ! ( arrow.begT < begT && arrow.endT < begT ) && ! ( arrow.begT > endT && arrow.endT > endT ) ) { StateGroupList visible_groups = canvas.all_states.visible; try { start_idx = visible_groups.GetSeqIndexAt( arrow.begGroupID ); end_idx = visible_groups.GetSeqIndexAt( arrow.endGroupID ); } catch ( IndexOutOfBoundsException err ) { return false; } int group_size = visible_groups.size(); if ( start_idx < group_size && end_idx < group_size ) { if ( ( (StateGroup) visible_groups.elementAt(start_idx) ).dispStatus && ( (StateGroup) visible_groups.elementAt(end_idx) ).dispStatus ) return true; } } return false; } /** * Draw the arrow representing a message in the given image. */ private void draw( ArrowInfo arrow, Graphics g, Color arrow_color ) { // definition: arrow_head is earlier( less ) than the arrow_tail in time double arrow_head_T, arrow_tail_T; boolean IsForwardArrow = arrow.endT >= arrow.begT; if ( IsForwardArrow ) { arrow_head_T = arrow.begT; arrow_tail_T = arrow.endT; } else { arrow_head_T = arrow.endT; arrow_tail_T = arrow.begT; } // plot coordinates to be passed to displayArrow() int head_Xp, tail_Xp, head_Yp, tail_Yp; boolean IsHeadInImg = arrow_head_T >= begT && arrow_head_T <= endT; boolean IsTailInImg = arrow_tail_T <= endT && arrow_tail_T >= begT; // The origin is set at the X = begT int head_X = canvas.getEvtXCord( arrow_head_T - begT ); int tail_X = canvas.getEvtXCord( arrow_tail_T - begT ); // Define the arrow segment to be drawn within the range of image buffer head_Xp = IsHeadInImg ? head_X : 0; tail_Xp = IsTailInImg ? tail_X : canvas.getEvtXCord( endT - begT ); if ( ! ( arrow.begGroupID == arrow.endGroupID && ( Math.abs( tail_Xp - head_Xp ) <= 1 ) && head_Xp == prev_arrow_beg_pos ) ) { int head_idx, tail_idx; double slope = 0.0; StateGroupList visible_groups = canvas.all_states.visible; if ( IsForwardArrow ) { head_idx = visible_groups.GetSeqIndexAt( arrow.begGroupID ); tail_idx = visible_groups.GetSeqIndexAt( arrow.endGroupID ); } else { head_idx = visible_groups.GetSeqIndexAt( arrow.endGroupID ); tail_idx = visible_groups.GetSeqIndexAt( arrow.begGroupID ); } double head_Y = canvas.GetStateGroupYCord( head_idx ); double tail_Y = canvas.GetStateGroupYCord( tail_idx ); if ( !IsHeadInImg || !IsTailInImg ) slope = ( tail_Y - head_Y ) / ( tail_X - head_X ); head_Yp = IsHeadInImg ? (int) Math.rint( head_Y ) : (int) Math.rint( head_Y - slope * head_X ); tail_Yp = IsTailInImg ? (int) Math.rint( tail_Y ) : (int) Math.rint( head_Y + slope * ( tail_Xp - head_X ) ); debug.println( "draw_Arrow( [" + begT + "+" + (arrow.begT-begT) + "," + head_idx + "] " + "= {" + head_X + "," + head_Y + "}, " + "+ {" + (tail_X-head_X) + "," + (tail_Y-head_Y) + "}" ); if ( IsForwardArrow ) displayArrow( g, arrow_color, head_Xp, head_Yp, IsHeadInImg, tail_Xp, tail_Yp, IsTailInImg ); else displayArrow( g, arrow_color, tail_Xp, tail_Yp, IsTailInImg, head_Xp, head_Yp, IsHeadInImg ); } prev_arrow_beg_pos = head_Xp; } private void displayArrow( Graphics g, Color arrow_color, int x1, int y1, boolean startflag, int x2, int y2, boolean endflag) { //Drawing arrow line if (g instanceof PrintGraphics) g.setColor (printLineColor); // else g.setColor (normLineColor); else g.setColor (arrow_color); g.drawLine (x1, y1, x2, y2); //Draw circle which gives info. about message if ( startflag ) { g.setColor (circleColor); g.fillOval (x1 - lrad, y1 - lrad, lrad * 2, lrad * 2); brad = (int)Math.rint (canvas.yDensity / 2); if (brad > 10) brad = 10; if (brad < 3) brad = 3; g.drawOval (x1 - brad, y1 - brad, brad * 2, brad * 2); } //Draw arrowhead if ( endflag ) { double halfangle = (Math.PI / 360.0) * angle; double dx = (double) Math.abs(x2 - x1); double dy = (double) Math.abs(y2 - y1); double a1 = Math.atan (dy / dx); double radtodeg = 180.0 / Math.PI; int startangle = 0; if (y1 < y2 && x2 > x1) // Forward : Downward startangle = (int)Math.rint (radtodeg * (Math.PI - a1 - halfangle)); else if (y1 > y2 && x2 > x1) // Forward : Upward startangle = (int)Math.rint (radtodeg * (Math.PI + a1 - halfangle)); else if (y1 > y2 && x1 > x2) // Backward : Upward startangle = (int)Math.rint (radtodeg * ((2.0 * Math.PI) - a1 - halfangle)); else if (y1 < y2 && x1 > x2) // Backward : Downward startangle = (int)Math.rint (radtodeg * (a1 - halfangle)); else if (y1 == y2) { startangle = (int)Math.rint (radtodeg * (Math.PI - halfangle)); if (x1 > x2) startangle += 180; } else if (x1 == x2) { startangle = (int)Math.rint (radtodeg * (Math.PI / 2.0 - halfangle)); if (y1 > y2) startangle += 180; } if (g instanceof PrintGraphics) g.setColor (printLineColor); // else g.setColor (normLineColor); else g.setColor (arrow_color); ht = (int)Math.rint (canvas.yDensity); if (ht > 20) ht = 20; g.fillArc (x2 - ht, y2 - ht, ht * 2, ht * 2, startangle, angle); } } /** * checks whether the given time is valid for this image */ private boolean check (double time, double b, double e) {return (time >= b && time <= e)? true : false;} /** * Draw ruler in specified graphics context */ void drawTimeRuler (Graphics g) { g.setColor (canvas.parent.rulerColor); g.fillRect (0, 0, _xPix, canvas.rulerHt); g.setColor (Color.black); g.drawLine (0, 0, _xPix, 0); double inchT = canvas.getTime (canvas.dpi); if (inchT <= 0) return; int i = (int)Math.rint (begT / inchT); //Start time double t = i * inchT; // while (t < endT && t < canvas.maxT) { while ( t < endT ) { int xcord = i * canvas.dpi - canvas.getEvtXCord (begT); String t1 = (new Float (t)).toString (), t2 = null; if (t1.indexOf ('E') == -1) { int index = max; if (index > t1.length ()) index = t1.length (); t2 = t1.substring (0, index); } else { int exp = t1.indexOf ('E'); String e = t1.substring (exp, t1.length ()); int si = 5; if (exp < si) si = exp; String a = t1.substring (0, si); t2 = a + e; } g.drawString ("|", xcord - 2, canvas.lineSize - canvas.fDescent); g.drawString (t2, xcord - (int)Math.rint ((double)canvas.fm.stringWidth (t2) / 2.0), 2 * canvas.lineSize - canvas.fDescent); t = (++i * inchT); } } void kill () { for (int i = 0; i < dispA.length; i++) { if (dispA [i].img1 != null) { dispA [i].img1.flush (); dispA [i].img1 = null; } if (dispA [i].img2 != null) { dispA [i].img2.flush (); dispA [i].img2 = null; } } if (rulerImg != null) rulerImg.flush (); rulerImg = null; } protected void finalize() throws Throwable {super.finalize();}}class Display { Image img1; Image img2; int dtype; public Display (int d, Image i1, Image i2) { dtype = d; img1 = i1; img2 = i2; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -