List of usage examples for java.awt Graphics drawLine
public abstract void drawLine(int x1, int y1, int x2, int y2);
(x1, y1)
and (x2, y2)
in this graphics context's coordinate system. From source file:jtrace.Scene.java
/** * Add a set of axes to an image. If the object parameter is not null, * the axes corresponding to the object's coordinate system are drawn. * // www .j a v a 2 s . com * @param image Image generated using scene's camera * @param object (Possibly null) object */ private void renderAxes(BufferedImage image, SceneObject object) { Graphics gr = image.getGraphics(); int[] origin, xhat, yhat, zhat; if (object == null) { origin = camera.getPixel(image.getWidth(), image.getHeight(), Vector3D.ZERO); xhat = camera.getPixel(image.getWidth(), image.getHeight(), Vector3D.PLUS_I); yhat = camera.getPixel(image.getWidth(), image.getHeight(), Vector3D.PLUS_J); zhat = camera.getPixel(image.getWidth(), image.getHeight(), Vector3D.PLUS_K); } else { origin = camera.getPixel(image.getWidth(), image.getHeight(), object.objectToSceneVector(Vector3D.ZERO)); xhat = camera.getPixel(image.getWidth(), image.getHeight(), object.objectToSceneVector(Vector3D.PLUS_I)); yhat = camera.getPixel(image.getWidth(), image.getHeight(), object.objectToSceneVector(Vector3D.PLUS_J)); zhat = camera.getPixel(image.getWidth(), image.getHeight(), object.objectToSceneVector(Vector3D.PLUS_K)); } String objName; if (object == null) objName = ""; else objName = "(" + object.getClass().getSimpleName() + ")"; gr.setColor(Color.red); gr.drawLine(origin[0], origin[1], xhat[0], xhat[1]); gr.setColor(Color.white); gr.drawString("x " + objName, xhat[0], xhat[1]); gr.setColor(Color.green); gr.drawLine(origin[0], origin[1], yhat[0], yhat[1]); gr.setColor(Color.white); gr.drawString("y " + objName, yhat[0], yhat[1]); gr.setColor(Color.blue); gr.drawLine(origin[0], origin[1], zhat[0], zhat[1]); gr.setColor(Color.white); gr.drawString("z " + objName, zhat[0], zhat[1]); }
From source file:edu.purdue.cc.bionet.ui.HeatMap.java
/** * This method retrieves a heatmap image from jfreechart and places it on the panel * along with black divider lines and labels to create a heat map graph. * /*from w ww . j ava 2 s.com*/ * @param g The Graphics for the jpanel. */ public void paintComponent(Graphics g) { super.paintComponent(g); if (moleculeList.size() > 0) { float tickStep; BufferedImage drawing = HeatMapUtilities.createHeatMapImage(this.getDataset(), this.spectrum); int leftEdge = this.getWidth() / 8; int topEdge = this.getHeight() / 32; int bottomEdge = this.getHeight() * 7 / 8; int rightEdge = this.getWidth() * 31 / 32; mapPosition = new Rectangle(leftEdge, topEdge, rightEdge - leftEdge, bottomEdge - topEdge); g.drawImage(drawing, leftEdge, topEdge, rightEdge - leftEdge, bottomEdge - topEdge, this.getBackground(), this); // y-axis int yAxisPos = leftEdge - 1; // g.drawLine( yAxisPos, topEdge, yAxisPos, bottomEdge ); tickStep = (bottomEdge - topEdge) / (float) moleculeList.size(); for (int i = 0; i <= moleculeList.size(); i++) { int tickY = Math.round(topEdge + i * tickStep); g.drawLine(rightEdge, tickY, yAxisPos - tickSize, tickY); if (i < moleculeList.size()) { String name = this.moleculeList.get(this.moleculeList.size() - 1 - i).toString(); g.drawString(name, yAxisPos - 4 - g.getFontMetrics().stringWidth(name), (int) (tickY + tickStep)); } } // x-axis int xAxisPos = bottomEdge; tickStep = (rightEdge - leftEdge) / (float) moleculeList.size(); // g.drawLine( leftEdge, xAxisPos, rightEdge, xAxisPos ); for (int i = 0; i <= moleculeList.size(); i++) { int tickX = (int) (leftEdge + i * tickStep); g.drawLine(tickX, topEdge, tickX, xAxisPos + tickSize); } // transform clockwise 90 degrees for the vertical text AffineTransform at = new AffineTransform(); at.quadrantRotate(3); Graphics2D g2d = (Graphics2D) g.create(); g2d.transform(at); for (int i = 0; i < moleculeList.size(); i++) { int tickX = Math.round(leftEdge + i * tickStep); String name = this.moleculeList.get(i).toString(); g2d.drawString(name, -(int) (xAxisPos + 4 + g.getFontMetrics().stringWidth(name)), (int) (tickX + tickStep)); } } }
From source file:AccessibleScrollDemo.java
public void paintComponent(Graphics g) { Rectangle drawHere = g.getClipBounds(); // Fill clipping area with dirty brown/orange. g.setColor(new Color(230, 163, 4)); g.fillRect(drawHere.x, drawHere.y, drawHere.width, drawHere.height); // Do the ruler labels in a small font that's black. g.setFont(new Font("SansSerif", Font.PLAIN, 10)); g.setColor(Color.black);//from w ww . j a v a 2 s. c om // Some vars we need. int end = 0; int start = 0; int tickLength = 0; String text = null; // Use clipping bounds to calculate first tick // and last tick location. if (orientation == HORIZONTAL) { start = (drawHere.x / increment) * increment; end = (((drawHere.x + drawHere.width) / increment) + 1) * increment; } else { start = (drawHere.y / increment) * increment; end = (((drawHere.y + drawHere.height) / increment) + 1) * increment; } // Make a special case of 0 to display the number // within the rule and draw a units label. if (start == 0) { text = Integer.toString(0) + (isMetric ? " cm" : " in"); tickLength = 10; if (orientation == HORIZONTAL) { g.drawLine(0, SIZE - 1, 0, SIZE - tickLength - 1); g.drawString(text, 2, 21); } else { g.drawLine(SIZE - 1, 0, SIZE - tickLength - 1, 0); g.drawString(text, 9, 10); } text = null; start = increment; } // ticks and labels for (int i = start; i < end; i += increment) { if (i % units == 0) { tickLength = 10; text = Integer.toString(i / units); } else { tickLength = 7; text = null; } if (tickLength != 0) { if (orientation == HORIZONTAL) { g.drawLine(i, SIZE - 1, i, SIZE - tickLength - 1); if (text != null) g.drawString(text, i - 3, 21); } else { g.drawLine(SIZE - 1, i, SIZE - tickLength - 1, i); if (text != null) g.drawString(text, 9, i + 3); } } } }
From source file:contactangle.ImageControl.java
@Override public void paintComponent(Graphics g) { super.paintComponent(g); if (img != null) g.drawImage(img, 0, 0, this); else//from w ww .ja v a 2 s . c o m g.drawString("NO IMAGE", 0, 15); g.setColor(Color.RED); if (x1 < x2 && y1 < y2) g.drawRect(x1, y1, x2 - x1, y2 - y1); else if (x1 >= x2 && y1 < y2) g.drawRect(x2, y1, x1 - x2, y2 - y1); else if (x1 < x2 && y1 >= y2) g.drawRect(x1, y2, x2 - x1, y1 - y2); else g.drawRect(x2, y2, x1 - x2, y1 - y2); if (valid && img != null) { if (x1 >= x2) { int temp = x1; x1 = x2; x2 = temp; } if (y1 >= y2) { int temp = y1; y1 = y2; y2 = temp; } choosenPoints = new ArrayList<Point>(); for (int y = y1; y < y2; y++) { for (int x = x1; x < x2; x++) { int pixelData = img.getRGB(x, y); if (pixelData == -1) choosenPoints.add(new Point(x, y)); } } SimpleRegression reg = new SimpleRegression(); for (Point p : choosenPoints) { reg.addData(p.x, p.y); } int firstX = choosenPoints.get(0).x; int firstY = choosenPoints.get(0).y; double slope = reg.getSlope(); g.setColor(Color.GREEN); g.drawLine(firstX, firstY, firstX + (70), firstY + (int) (slope * (70))); g.drawLine(firstX, firstY, firstX - (70), firstY - (int) (slope * (70))); double contactDegrees = (Math.atan(reg.getSlope()) / (2 * Math.PI)) * 360.0; DecimalFormat d = new DecimalFormat("##.###"); g.drawString("Contact Angle = ", 25, 25); g.drawString(d.format(contactDegrees) + " degrees", 25, 38); } }
From source file:BeanContainer.java
public void paintComponent(Graphics g) { super.paintComponent(g); Color colorRetainer = g.getColor(); g.setColor(getBackground());//www . ja va 2 s .c o m g.fillRect(0, 0, getWidth(), getHeight()); getBorder().paintBorder(this, g, 0, 0, getWidth(), getHeight()); m_calendar.setTime(new Date()); // get current time int hrs = m_calendar.get(Calendar.HOUR_OF_DAY); int min = m_calendar.get(Calendar.MINUTE); g.setColor(getForeground()); if (m_digital) { String time = "" + hrs + ":" + min; g.setFont(getFont()); FontMetrics fm = g.getFontMetrics(); int y = (getHeight() + fm.getAscent()) / 2; int x = (getWidth() - fm.stringWidth(time)) / 2; g.drawString(time, x, y); } else { int x = getWidth() / 2; int y = getHeight() / 2; int rh = getHeight() / 4; int rm = getHeight() / 3; double ah = ((double) hrs + min / 60.0) / 6.0 * Math.PI; double am = min / 30.0 * Math.PI; g.drawLine(x, y, (int) (x + rh * Math.sin(ah)), (int) (y - rh * Math.cos(ah))); g.drawLine(x, y, (int) (x + rm * Math.sin(am)), (int) (y - rm * Math.cos(am))); } g.setColor(colorRetainer); }
From source file:com.cburch.logisim.circuit.CircuitWires.java
void draw(ComponentDrawContext context, Collection<Component> hidden) { boolean showState = context.getShowState(); CircuitState state = context.getCircuitState(); Graphics g = context.getGraphics(); g.setColor(Color.BLACK);// w w w. j a va 2 s. com GraphicsUtil.switchToWidth(g, Wire.WIDTH); WireSet highlighted = context.getHighlightedWires(); BundleMap bmap = getBundleMap(); boolean isValid = bmap.isValid(); if (hidden == null || hidden.size() == 0) { for (Wire w : wires) { Location s = w.e0; Location t = w.e1; WireBundle wb = bmap.getBundleAt(s); if (!wb.isValid()) { g.setColor(Value.WIDTH_ERROR_COLOR); } else if (showState) { if (!isValid) g.setColor(Value.NIL_COLOR); else g.setColor(state.getValue(s).getColor()); } else { g.setColor(Color.BLACK); } if (highlighted.containsWire(w)) { GraphicsUtil.switchToWidth(g, Wire.WIDTH + 2); g.drawLine(s.getX(), s.getY(), t.getX(), t.getY()); GraphicsUtil.switchToWidth(g, Wire.WIDTH); } else { g.drawLine(s.getX(), s.getY(), t.getX(), t.getY()); } } for (Location loc : points.getSplitLocations()) { if (points.getComponentCount(loc) > 2) { WireBundle wb = bmap.getBundleAt(loc); if (wb != null) { if (!wb.isValid()) { g.setColor(Value.WIDTH_ERROR_COLOR); } else if (showState) { if (!isValid) g.setColor(Value.NIL_COLOR); else g.setColor(state.getValue(loc).getColor()); } else { g.setColor(Color.BLACK); } if (highlighted.containsLocation(loc)) { g.fillOval(loc.getX() - 5, loc.getY() - 5, 10, 10); } else { g.fillOval(loc.getX() - 4, loc.getY() - 4, 8, 8); } } } } } else { for (Wire w : wires) { if (!hidden.contains(w)) { Location s = w.e0; Location t = w.e1; WireBundle wb = bmap.getBundleAt(s); if (!wb.isValid()) { g.setColor(Value.WIDTH_ERROR_COLOR); } else if (showState) { if (!isValid) g.setColor(Value.NIL_COLOR); else g.setColor(state.getValue(s).getColor()); } else { g.setColor(Color.BLACK); } if (highlighted.containsWire(w)) { GraphicsUtil.switchToWidth(g, Wire.WIDTH + 2); g.drawLine(s.getX(), s.getY(), t.getX(), t.getY()); GraphicsUtil.switchToWidth(g, Wire.WIDTH); } else { g.drawLine(s.getX(), s.getY(), t.getX(), t.getY()); } } } // this is just an approximation, but it's good enough since // the problem is minor, and hidden only exists for a short // while at a time anway. for (Location loc : points.getSplitLocations()) { if (points.getComponentCount(loc) > 2) { int icount = 0; for (Component comp : points.getComponents(loc)) { if (!hidden.contains(comp)) ++icount; } if (icount > 2) { WireBundle wb = bmap.getBundleAt(loc); if (wb != null) { if (!wb.isValid()) { g.setColor(Value.WIDTH_ERROR_COLOR); } else if (showState) { if (!isValid) g.setColor(Value.NIL_COLOR); else g.setColor(state.getValue(loc).getColor()); } else { g.setColor(Color.BLACK); } if (highlighted.containsLocation(loc)) { g.fillOval(loc.getX() - 5, loc.getY() - 5, 10, 10); } else { g.fillOval(loc.getX() - 4, loc.getY() - 4, 8, 8); } } } } } } }
From source file:ru.spbspu.viewer.DataView.java
private void drawScaleFull() { int specHeigth = fullSpectrogram.getHeight() - cursor.getHeight() / 2; float limit = Integer.valueOf(spinnerLimitFreq.getValue().toString()); int frameWidth = Integer.valueOf(spinnerFrameWidth.getValue().toString()); BufferedImage scaleForFrame = new BufferedImage(SCALE_OF_SPECT, specHeigth, BufferedImage.TYPE_INT_RGB); Graphics g = scaleForFrame.getGraphics(); g.drawLine(5, 0, 5, specHeigth); Integer[] yAxis = new Integer[specHeigth / 8]; for (int i = 0; i < yAxis.length; i++) { yAxis[i] = (int) (i * (limit / 1024) * 100); }//from ww w .jav a2 s. c o m int j = 0; for (int i = specHeigth; i > 0; i -= specHeigth / 10) { g.drawString(yAxis[j].toString(), 7, i - 2); g.drawLine(0, i, 40, i); j++; } labelForFullScale.setIcon(new ImageIcon(scaleForFrame)); }
From source file:ru.spbspu.viewer.DataView.java
private void drawScale() { int specHeigth = spectrogram.getHeight() - cursor.getHeight() / 2; float limit = Integer.valueOf(spinnerLimitFreq.getValue().toString()); int frameWidth = Integer.valueOf(spinnerFrameWidth.getValue().toString()); BufferedImage scaleForFrame = new BufferedImage(SCALE_OF_SPECT, specHeigth, BufferedImage.TYPE_INT_RGB); Graphics g = scaleForFrame.getGraphics(); g.drawLine(5, 0, 5, specHeigth); Integer[] yAxis = new Integer[specHeigth / 8]; try {/*from w ww. j a v a2 s . co m*/ for (int i = 0; i < yAxis.length; i++) { yAxis[i] = (int) (i * (limit / 1024) * 100); } int j = 0; for (int i = specHeigth; i > 0; i -= specHeigth / 10) { g.drawString(yAxis[j].toString(), 7, i - 2); g.drawLine(0, i, 40, i); j++; } } catch (ArrayIndexOutOfBoundsException e) { System.out.println("To small window."); } labelForFrameScale.setIcon(new ImageIcon(scaleForFrame)); }
From source file:org.processmining.analysis.performance.advanceddottedchartanalysis.ui.DottedChartPanel.java
protected void drawVerticalLines(Graphics g, int imageWidth, int imageHeight) { int pixStart = 0; int yTop = BORDER; int yBottom = imageHeight - BORDER; String dateStr, timeStr;//from w ww . j a va 2 s . c om // adjust width adjustWidth(); long timeStart = 0; if (dcop.getTimeOption().equals(DottedChartModel.TIME_ACTUAL)) { timeStart = dcModel.getLogMinValueforScreen(); } long lastLable = Long.MIN_VALUE; long clipRightTs = coUtil.coord2timeMillis(coUtil.getClipR()); for (; timeStart < clipRightTs; timeStart += dca.getDottedChartOptionPanel().getWidthDivider()) { pixStart = coUtil.time2coord(timeStart) + BORDER; cal.setTimeInMillis(timeStart - timeOffset); g.setColor(colorTimeLine); g.drawLine(pixStart, yTop, pixStart, yBottom); g.setColor(dca.getSettingPanel().getFBcolor()); g.setColor(Color.black); // to be deleted if (dcop.getTimeOption().equals(DottedChartModel.TIME_ACTUAL)) { // if(lastLable+80>=pixStart+2) continue; // timeStr = String.valueOf(timeStart); // g.drawString(timeStr, pixStart+2, yTop); if (lastLable + 80 >= pixStart + 2) continue; dateStr = cal.get(Calendar.DAY_OF_MONTH) + "." + (cal.get(Calendar.MONTH) + 1) + "." + cal.get(Calendar.YEAR); g.drawString(dateStr, pixStart + 2, yTop); timeStr = cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND); g.drawString(timeStr, pixStart + 2, yTop + 10); } else if (dcop.getTimeOption().equals(DottedChartModel.TIME_RELATIVE_TIME)) { if (lastLable + 80 >= pixStart + 2) continue; long days = timeStart / 1000 / 60 / 60 / 24; long hours = (timeStart - days * 24 * 60 * 60 * 1000) / 1000 / 60 / 60; long minutes = (timeStart - days * 24 * 60 * 60 * 1000 - hours * 60 * 60 * 1000) / 1000 / 60; long seconds = (timeStart - days * 24 * 60 * 60 * 1000 - hours * 60 * 60 * 1000 - minutes * 60 * 1000) / 1000; timeStr = days + "days:" + hours + ":" + minutes + ":" + seconds; g.drawString(timeStr, pixStart + 2, yTop); } else if (dcop.getTimeOption().equals(DottedChartModel.TIME_RELATIVE_RATIO)) { if (lastLable + 40 >= pixStart + 2) continue; timeStr = timeStart / 100 + "." + (timeStart - timeStart / 100 * 100) + "%"; g.drawString(timeStr, pixStart + 2, yTop); } else if (dcop.getTimeOption().equals(DottedChartModel.TIME_LOGICAL) || dcop.getTimeOption().equals(DottedChartModel.TIME_LOGICAL_RELATIVE)) { if (lastLable + 20 >= pixStart + 2) continue; timeStr = String.valueOf(timeStart); g.drawString(timeStr, pixStart + 2, yTop); } lastLable = pixStart + 2; } }
From source file:org.prom5.analysis.performance.advanceddottedchartanalysis.ui.DottedChartPanel.java
protected void drawVerticalLines(Graphics g, int imageWidth, int imageHeight) { int pixStart = 0; int yTop = BORDER; int yBottom = imageHeight - BORDER; String dateStr, timeStr;/*from w w w .j a v a 2 s .c o m*/ // adjust width adjustWidth(); long timeStart = 0; if (dcop.getTimeOption().equals(DottedChartModel.TIME_ACTUAL)) { timeStart = dcModel.getLogMinValueforScreen(); } long lastLable = Long.MIN_VALUE; long clipRightTs = coUtil.coord2timeMillis(coUtil.getClipR()); for (; timeStart < clipRightTs; timeStart += dca.getDottedChartOptionPanel().getWidthDivider()) { pixStart = coUtil.time2coord(timeStart) + BORDER; cal.setTimeInMillis(timeStart - timeOffset); g.setColor(colorTimeLine); g.drawLine(pixStart, yTop, pixStart, yBottom); g.setColor(dca.getSettingPanel().getFBcolor()); g.setColor(Color.black); // to be deleted if (dcop.getTimeOption().equals(DottedChartModel.TIME_ACTUAL)) { // if(lastLable+80>=pixStart+2) continue; // timeStr = String.valueOf(timeStart); // g.drawString(timeStr, pixStart+2, yTop); if (lastLable + 80 >= pixStart + 2) continue; dateStr = cal.get(Calendar.DAY_OF_MONTH) + "." + (cal.get(Calendar.MONTH) + 1) + "." + cal.get(Calendar.YEAR); g.drawString(dateStr, pixStart + 2, yTop); timeStr = cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND); g.drawString(timeStr, pixStart + 2, yTop + 10); } else if (dcop.getTimeOption().equals(DottedChartModel.TIME_RELATIVE_TIME)) { if (lastLable + 80 >= pixStart + 2) continue; long days = timeStart / 1000 / 60 / 60 / 24; long hours = (timeStart - days * 24 * 60 * 60 * 1000) / 1000 / 60 / 60; long minutes = (timeStart - days * 24 * 60 * 60 * 1000 - hours * 60 * 60 * 1000) / 1000 / 60; long seconds = (timeStart - days * 24 * 60 * 60 * 1000 - hours * 60 * 60 * 1000 - minutes * 60 * 1000) / 1000; timeStr = days + "days:" + hours + ":" + minutes + ":" + seconds; g.drawString(timeStr, pixStart + 2, yTop); } else if (dcop.getTimeOption().equals(DottedChartModel.TIME_RELATIVE_RATIO)) { if (lastLable + 40 >= pixStart + 2) continue; timeStr = timeStart / 100 + "." + (timeStart - timeStart / 100 * 100) + "%"; g.drawString(timeStr, pixStart + 2, yTop); } else if (dcop.getTimeOption().equals(DottedChartModel.TIME_LOGICAL) || dcop.getTimeOption().equals(DottedChartModel.TIME_LOGICAL_RELATIVE)) { if (lastLable + 20 >= pixStart + 2) continue; timeStr = String.valueOf(timeStart); g.drawString(timeStr, pixStart + 2, yTop); } lastLable = pixStart + 2; } }