/// <summary> /// Draws the bounds that represent the currently-visible area of the network. /// </summary> private void drawBounds() { GRLimits vl = __networkJComponent.getVisibleDataLimits(); if (vl == null) { return; } GRDrawingAreaUtil.setColor(__drawingArea, GRColor.green); double lx = vl.getLeftX(); double by = vl.getBottomY(); double rx = vl.getRightX(); double ty = vl.getTopY(); GRDrawingAreaUtil.drawLine(__drawingArea, lx, by, rx, by); GRDrawingAreaUtil.drawLine(__drawingArea, lx, ty, rx, ty); GRDrawingAreaUtil.drawLine(__drawingArea, lx, by, lx, ty); GRDrawingAreaUtil.drawLine(__drawingArea, rx, by, rx, ty); }
/// <summary> /// Draws the outline of the legend. /// </summary> public virtual void drawLegend() { GRLimits l = __networkJComponent.getLegendDataLimits(); if (l == null) { return; } GRDrawingAreaUtil.setColor(__drawingArea, GRColor.white); double lx = l.getLeftX(); double by = l.getBottomY(); double rx = l.getRightX(); double ty = l.getTopY(); GRDrawingAreaUtil.fillRectangle(__drawingArea, lx, by, l.getWidth(), l.getHeight()); GRDrawingAreaUtil.setColor(__drawingArea, GRColor.black); GRDrawingAreaUtil.drawLine(__drawingArea, lx, by, rx, by); GRDrawingAreaUtil.drawLine(__drawingArea, lx, ty, rx, ty); GRDrawingAreaUtil.drawLine(__drawingArea, lx, by, lx, ty); GRDrawingAreaUtil.drawLine(__drawingArea, rx, by, rx, ty); }
/// <summary> /// Paints the screen. </summary> /// <param name="g"> the Graphics context to use for painting. </param> public virtual void paint(Graphics g) { // sets the graphics in the base class appropriately (double-buffered // if doing double-buffered drawing, single-buffered if not) setGraphics(g); // Set up drawing limits based on current window size... setLimits(getLimits(true)); // first time through, do the following ... if (!__initialized) { // one time ONLY, do the following. __height = getBounds().height; __width = getBounds().width; __initialized = true; setupDoubleBuffer(0, 0, getBounds().width, getBounds().height); repaint(); __forceRefresh = true; } // only do the following if explicitly instructed to ... if (__forceRefresh) { clear(); GRDrawingAreaUtil.setColor(__drawingArea, GRColor.black); setAntiAlias(true); drawNetworkLines(); setAntiAlias(true); drawLegend(); setAntiAlias(true); if (__drawMargin) { GRLimits margins = __networkJComponent.getMarginLimits(); int lx = (int)margins.getLeftX(); int rx = (int)margins.getRightX(); int by = (int)margins.getBottomY(); int ty = (int)margins.getTopY(); __drawingArea.setFloatLineDash(__bigDashes, 0); GRDrawingAreaUtil.setColor(__drawingArea, GRColor.cyan); GRDrawingAreaUtil.drawLine(__drawingArea, lx, by, rx, by); GRDrawingAreaUtil.drawLine(__drawingArea, lx, ty, rx, ty); GRDrawingAreaUtil.drawLine(__drawingArea, lx, by, lx, ty); GRDrawingAreaUtil.drawLine(__drawingArea, rx, by, rx, ty); __drawingArea.setFloatLineDash(null, 0); } setAntiAlias(true); if (__drawInchGrid) { __drawingArea.setFloatLineDash(__smallDashes, 0); double maxX = __networkJComponent.getTotalWidth(); double maxY = __networkJComponent.getTotalHeight(); double leftX = __networkJComponent.getDataLeftX(); double bottomY = __networkJComponent.getDataBottomY(); double printScale = __networkJComponent.getPrintScale(); GRDrawingAreaUtil.setColor(__drawingArea, GRColor.red); int j = 0; int minY = (int)(__networkJComponent.convertAbsY(0) + bottomY); int tempMaxY = (int)(__networkJComponent.convertAbsY(maxY) + bottomY); for (int i = 0; i < maxX; i += ((72 / printScale) / 2)) { j = (int)(__networkJComponent.convertAbsX(i) + leftX); GRDrawingAreaUtil.drawLine(__drawingArea, j, minY, j, tempMaxY); GRDrawingAreaUtil.drawText(__drawingArea, "" + ((double)i / (72 / printScale)), j, minY, 0, GRText.CENTER_X | GRText.BOTTOM); } int minX = (int)(__networkJComponent.convertAbsX(0) + leftX); int tempMaxX = (int)(__networkJComponent.convertAbsX(maxX) + leftX); for (int i = 0; i < maxY; i += ((72 / printScale) / 2)) { j = (int)(__networkJComponent.convertAbsY(i) + bottomY); GRDrawingAreaUtil.drawLine(__drawingArea, minX, j, tempMaxX, j); GRDrawingAreaUtil.drawText(__drawingArea, "" + ((double)i / (72 / printScale)), minX, j, 0, GRText.CENTER_Y | GRText.LEFT); } __drawingArea.setFloatLineDash(null, 0); } GRDrawingAreaUtil.setColor(__drawingArea, GRColor.black); GRLimits drawingLimits = __networkJComponent.getTotalDataLimits(); GRDrawingAreaUtil.drawLine(__drawingArea, drawingLimits.getLeftX(), drawingLimits.getBottomY(), drawingLimits.getRightX(), drawingLimits.getBottomY()); GRDrawingAreaUtil.drawLine(__drawingArea, drawingLimits.getLeftX(), drawingLimits.getTopY(), drawingLimits.getRightX(), drawingLimits.getTopY()); GRDrawingAreaUtil.drawLine(__drawingArea, drawingLimits.getLeftX(), drawingLimits.getTopY(), drawingLimits.getLeftX(), drawingLimits.getBottomY()); GRDrawingAreaUtil.drawLine(__drawingArea, drawingLimits.getRightX(), drawingLimits.getTopY(), drawingLimits.getRightX(), drawingLimits.getBottomY()); setAntiAlias(true); drawBounds(); } // displays the graphics showDoubleBuffer(g); }
/// <summary> /// Draws the network between all the nodes. /// </summary> private void drawNetworkLines() { bool dash = false; float[] dashes = new float[] { 5f, 4f }; float offset = 0; double[] x = new double[2]; double[] y = new double[2]; HydrologyNode ds = null; HydrologyNode dsRealNode = null; HydrologyNode holdNode = null; HydrologyNode holdNode2 = null; HydrologyNode node = null; HydrologyNode nodeTop = __network.getMostUpstreamNode(); GRDrawingAreaUtil.setLineWidth(__drawingArea, 1); for (node = nodeTop; node != null; node = StateMod_NodeNetwork.getDownstreamNode(node, StateMod_NodeNetwork.POSITION_COMPUTATIONAL)) { // move ahead and skip and blank or unknown nodes (which won't // be drawn, anyways -- check buildNodeArray()), so that // connections are only between visible nodes if (holdNode == node) { GRDrawingAreaUtil.setLineWidth(__drawingArea, 1); return; } holdNode2 = node; while (node.getType() == HydrologyNode.NODE_TYPE_UNKNOWN) { node = StateMod_NodeNetwork.getDownstreamNode(node, StateMod_NodeNetwork.POSITION_COMPUTATIONAL); if (node == null || node == holdNode2) { GRDrawingAreaUtil.setLineWidth(__drawingArea, 1); return; } } ds = node.getDownstreamNode(); if (ds == null || node.getType() == HydrologyNode.NODE_TYPE_END) { GRDrawingAreaUtil.setLineWidth(__drawingArea, 1); return; } dsRealNode = StateMod_NodeNetwork.findNextRealOrXConfluenceDownstreamNode(node); // if the confluence of the reach (as opposed to a trib coming // in) then this is the last real node in disappearing stream. // Use the end node for the downstream node. dash = false; if (dsRealNode == StateMod_NodeNetwork.getDownstreamNode(node, StateMod_NodeNetwork.POSITION_REACH)) { dash = true; } // move ahead and skip and blank or unknown nodes (which won't // be drawn, anyways -- check buildNodeArray()), so that // connections are only between visible nodes holdNode2 = ds; while (ds.getType() == HydrologyNode.NODE_TYPE_UNKNOWN) { ds = ds.getDownstreamNode(); if (ds == null || ds == holdNode2) { GRDrawingAreaUtil.setLineWidth(__drawingArea, 1); return; } } x[0] = node.getX(); y[0] = node.getY(); x[1] = ds.getX(); y[1] = ds.getY(); GRDrawingAreaUtil.setColor(__drawingArea, GRColor.black); GRDrawingAreaUtil.setLineWidth(__drawingArea, 1); if (dash) { __drawingArea.setFloatLineDash(dashes, offset); GRDrawingAreaUtil.drawLine(__drawingArea, x, y); __drawingArea.setFloatLineDash(null, (float)0); } else { GRDrawingAreaUtil.drawLine(__drawingArea, x, y); } holdNode = node; } GRDrawingAreaUtil.setLineWidth(__drawingArea, 1); }