public void paint(Graphics g) { super.paint(g); Dimension size = getSize(); double w = size.getWidth() - 50; double h = size.getHeight() + 20; try { readFile(); } catch (IOException e) { System.err.println("IO issue"); } barWidth = ((int) (w / numBars)) - 20; pos = 5; int xPos[] = {pos, pos, pos, pos}; int yPos[] = {pos, pos, pos, pos}; maxVal = maxValue(values); double barH, ratio; for (int i = 0; i < numBars - 1; i++) { Color col[] = new Color[numBars]; for (int j = 0; j < numBars - 1; j++) { col[j] = new Color((int) (Math.random() * 0x1000000)); } ratio = (double) values[i] / (double) maxVal; barH = ((h) * ratio) - 10; xPos[0] = pos; xPos[2] = pos + barWidth; xPos[1] = xPos[0]; xPos[3] = xPos[2]; yPos[0] = (int) h; yPos[1] = (int) barH; yPos[2] = yPos[1]; yPos[3] = yPos[0]; System.out.println( "xPos:" + xPos[1] + " yPos:" + yPos[0] + " h:" + h + " barH:" + barH + " ratio:" + ratio + " pos:" + pos); int stringPtsY[] = { ((i + 1) * 20) + 180, ((i + 1) * 20) + 200, ((i + 1) * 20) + 200, ((i + 1) * 20) + 180 }; int stringPtsX[] = {600, 600, 580, 580}; g.setColor(col[i]); g.fillPolygon(xPos, yPos, xPos.length); g.fillPolygon(stringPtsX, stringPtsY, 4); g.setColor(Color.black); g.drawString(labels[i], 610, ((i + 1) * 20) + 195); pos = pos + barWidth + 10; } }
/** * Draws a solid "filled-in" irregular polygon using between 3 and 12 sets of provided * coordinates. <br> * Examples: <br> * Expo.fillPolygon(g,100,300,200,100,300,300); // for a triangle * Expo.fillPolygon(g,525,300,600,250,650,250,725,300,725,350,650,400); // for a hexagon */ public static void fillPolygon(Graphics g, int x1, int y1, int x2, int y2, int x3, int y3) { Polygon myPoly = new Polygon(); myPoly.addPoint(x1, y1); myPoly.addPoint(x2, y2); myPoly.addPoint(x3, y3); g.fillPolygon(myPoly); }
/** * Draws a solid "filled in" star with a specified number of points.<br> * The center of this star is specified by centerX,centerY and its size is specified by radius * <br> * (As in the radius of the circle the star would fit inside). <br> * Precondition: points >= 2 <br> * Example: <br> * Expo.fillStar(g,300,200,100,8); <br> * Draws a solid star with 8 points and a radius of 100 pixels whose center is located at the * coordinate (300,200). */ public static void fillStar(Graphics g, int centerX, int centerY, int radius, int points) { int halfRadius = getHalfRadius(radius, points); int p = points; points *= 2; int xCoord[] = new int[points]; int yCoord[] = new int[points]; int currentRadius; for (int k = 0; k < points; k++) { if (k % 2 == 0) currentRadius = radius; else currentRadius = halfRadius; xCoord[k] = (int) Math.round(Math.cos(twoPI * k / points - halfPI) * currentRadius) + centerX; yCoord[k] = (int) Math.round(Math.sin(twoPI * k / points - halfPI) * currentRadius) + centerY; } int x = (p - 5) / 2 + 1; if (p >= 5 && p <= 51) switch (p % 4) { case 1: yCoord[x] = yCoord[x + 1] = yCoord[points - x - 1] = yCoord[points - x]; break; case 2: yCoord[x] = yCoord[x + 1] = yCoord[points - x - 1] = yCoord[points - x]; yCoord[x + 3] = yCoord[x + 4] = yCoord[points - x - 4] = yCoord[points - x - 3]; break; case 3: yCoord[x + 2] = yCoord[x + 3] = yCoord[points - x - 3] = yCoord[points - x - 2]; } g.fillPolygon(xCoord, yCoord, points); }
public static void fillPolygon( Graphics g, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, int x5, int y5, int x6, int y6, int x7, int y7, int x8, int y8, int x9, int y9, int x10, int y10) { Polygon myPoly = new Polygon(); myPoly.addPoint(x1, y1); myPoly.addPoint(x2, y2); myPoly.addPoint(x3, y3); myPoly.addPoint(x4, y4); myPoly.addPoint(x5, y5); myPoly.addPoint(x6, y6); myPoly.addPoint(x7, y7); myPoly.addPoint(x8, y8); myPoly.addPoint(x9, y9); myPoly.addPoint(x10, y10); g.fillPolygon(myPoly); }
public static void drawArrow(Graphics g, int x1, int y1, int x2, int y2, int lineWidth) { // Draw line using user defined drawline() which can specify line width drawLine(g, x1, y1, x2, y2, lineWidth); // Calculate x-y values for arrow head calcValues(x1, y1, x2, y2); g.fillPolygon(xValues, yValues, 3); }
/* ウィンドウの描画 */ public void draw(Graphics g) { super.draw(g); // ウィンドウ描画 if (active) { /* 選択肢リストの描画 */ for (int y = 0; y < select_list.length; y++) { int my = posY + AROUND_Y + (MessageString.FONT_HEIGHT + INTERVAL_Y) * y; for (int x = 0; x < select_list[y].length; x++) { int mx = posX + AROUND_X + (row_width + INTERVAL_X) * x; message.drawMessage(g, mx, my, select_list[y][x]); } } /* カーソルの描画 */ int cx = posX + AROUND_X + (row_width + INTERVAL_X) * select_point.x - MessageString.FONT_WIDTH; int cy = posY + AROUND_Y + (MessageString.FONT_HEIGHT + INTERVAL_Y) * select_point.y + MessageString.FONT_WIDTH / 2; int[] xPoints = {cx, cx + MessageString.FONT_WIDTH / 2, cx}; int[] yPoints = {cy, cy + MessageString.FONT_HEIGHT / 4, cy + MessageString.FONT_HEIGHT / 2}; g.setColor(Color.WHITE); g.fillPolygon(xPoints, yPoints, 3); } }
/** * Draws this polygon on the screen. If any of the points are not visible (ie. behind the * camera) then do not attempt to draw this polygon. */ void draw(Graphics g) { if (n <= 1) return; g.setColor(getColor()); for (int i = 0; i < n; i++) { if (!visibles[points[i] / 3]) return; xs[i] = (int) ps_[points[i] + 1]; ys[i] = (int) ps_[points[i] + 2]; } g.fillPolygon(xs, ys, xs.length); }
/** * Draws a solid "filled in" regular polygon with a specified number of sides.<br> * The center of this polygon is specified by centerX,centerY and its size is specified by radius * <br> * (As in the radius of the circle the regular polygon would fit inside). <br> * Precondition: sides >= 3 <br> * Example: Expo.fillRegularPolygon(g,300,200,100,8); Draws a solid "filled-in" regular octagon * with a radius of 100 pixels whose center is located at the coordinate (300,200). */ public static void fillRegularPolygon( Graphics g, int centerX, int centerY, int radius, int sides) { int xCoord[] = new int[sides]; int yCoord[] = new int[sides]; double rotate; if (sides % 2 == 1) rotate = halfPI; else rotate = halfPI + Math.PI / sides; for (int k = 0; k < sides; k++) { xCoord[k] = (int) Math.round(Math.cos(twoPI * k / sides - rotate) * radius) + centerX; yCoord[k] = (int) Math.round(Math.sin(twoPI * k / sides - rotate) * radius) + centerY; } if (sides == 3) yCoord[1] = yCoord[2]; g.fillPolygon(xCoord, yCoord, sides); }
public static void drawLine(Graphics g, int x1, int y1, int x2, int y2, int lineWidth) { if (lineWidth == 1) g.drawLine(x1, y1, x2, y2); else { double angle; double halfWidth = ((double) lineWidth) / 2.0; double deltaX = (double) (x2 - x1); double deltaY = (double) (y2 - y1); if (x1 == x2) angle = Math.PI; else angle = Math.atan(deltaY / deltaX) + Math.PI / 2; int xOffset = (int) (halfWidth * Math.cos(angle)); int yOffset = (int) (halfWidth * Math.sin(angle)); int[] xCorners = {x1 - xOffset, x2 - xOffset + 1, x2 + xOffset + 1, x1 + xOffset}; int[] yCorners = {y1 - yOffset, y2 - yOffset, y2 + yOffset + 1, y1 + yOffset + 1}; g.fillPolygon(xCorners, yCorners, 4); } }
public static void fillPolygon( Graphics g, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, int x5, int y5, int x6, int y6) { Polygon myPoly = new Polygon(); myPoly.addPoint(x1, y1); myPoly.addPoint(x2, y2); myPoly.addPoint(x3, y3); myPoly.addPoint(x4, y4); myPoly.addPoint(x5, y5); myPoly.addPoint(x6, y6); g.fillPolygon(myPoly); }
public void paint(Graphics g) { // do normal painting first super.paint(g); // draw polys ListIterator<Polygon> II = poly_draw.listIterator(0); ListIterator<Color> CC = poly_draw_color.listIterator(0); while (II.hasNext()) { Polygon P = II.next(); Color C = CC.next(); g.setColor(C); g.drawPolygon(P); } // fill polys II = poly_fill.listIterator(0); CC = poly_fill_color.listIterator(0); while (II.hasNext()) { Polygon P = II.next(); Color C = CC.next(); g.setColor(C); g.fillPolygon(P); } }
public void paint(Graphics g) { // Draw Grid g.drawRect(10, 10, 780, 580); g.drawLine(400, 10, 400, 590); g.drawLine(10, 300, 790, 300); Random rnd = new Random(1234); for (int k = 10; k <= 400; k += 10) { // The first box lines g.drawLine(k, 20, k, 290); } // The dimentions of the lines for (int k = 10; k <= 290; k += 10) { // The second box lines g.drawLine(420, k, 770, k); // The dimestions int red = rnd.nextInt(256); // The colors int green = rnd.nextInt(256); int blue = rnd.nextInt(256); g.setColor(new Color(red, green, blue)); // The randomness of colors } for (int k = 1; k <= 100; k++) { // The 3rd circles int x = rnd.nextInt(330); // the random of x lo int y = rnd.nextInt(230); // the randm of y int red = rnd.nextInt(256); // the random of colors int green = rnd.nextInt(256); int blue = rnd.nextInt(256); g.setColor(new Color(red, green, blue)); g.fillOval(x + 10, y + 300, 50, 50); } // the place of all the ovals Polygon side1 = new Polygon(); // blue side of cube side1.addPoint(600, 410); side1.addPoint(635, 410); side1.addPoint(635, 480); side1.addPoint(600, 445); g.setColor(Color.blue); g.fillPolygon(side1); Polygon side2 = new Polygon(); // green side of cube side2.addPoint(510, 380); side2.addPoint(550, 410); side2.addPoint(550, 495); side2.addPoint(510, 455); g.setColor(Color.green); g.fillPolygon(side2); Polygon side3 = new Polygon(); // yellow side of cube side3.addPoint(550, 445); side3.addPoint(600, 445); side3.addPoint(635, 480); side3.addPoint(550, 495); g.setColor(Color.yellow); g.fillPolygon(side3); Polygon side4 = new Polygon(); // red side of cube side4.addPoint(510, 380); side4.addPoint(550, 410); side4.addPoint(635, 410); side4.addPoint(600, 380); g.setColor(Color.red); g.fillPolygon(side4); // TODO Auto-generated method stub // TODO Auto-generated method stub }
@Override public void paintComponent(Graphics g) { super.paintComponent(g); int width = getWidth() - rightMargin - leftMargin - 10; int height = getHeight() - topMargin - bottomMargin; if (width <= 0 || height <= 0) { // not enough room to paint anything return; } Color oldColor = g.getColor(); Font oldFont = g.getFont(); Color fg = getForeground(); Color bg = getBackground(); boolean bgIsLight = (bg.getRed() > 200 && bg.getGreen() > 200 && bg.getBlue() > 200); ((Graphics2D) g) .setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (smallFont == null) { smallFont = oldFont.deriveFont(9.0F); } r.x = leftMargin - 5; r.y = topMargin - 8; r.width = getWidth() - leftMargin - rightMargin; r.height = getHeight() - topMargin - bottomMargin + 16; if (border == null) { // By setting colors here, we avoid recalculating them // over and over. border = new BevelBorder( BevelBorder.LOWERED, getBackground().brighter().brighter(), getBackground().brighter(), getBackground().darker().darker(), getBackground().darker()); } border.paintBorder(this, g, r.x, r.y, r.width, r.height); // Fill background color g.setColor(bgColor); g.fillRect(r.x + 2, r.y + 2, r.width - 4, r.height - 4); g.setColor(oldColor); long tMin = Long.MAX_VALUE; long tMax = Long.MIN_VALUE; long vMin = Long.MAX_VALUE; long vMax = 1; int w = getWidth() - rightMargin - leftMargin - 10; int h = getHeight() - topMargin - bottomMargin; if (times.size > 1) { tMin = Math.min(tMin, times.time(0)); tMax = Math.max(tMax, times.time(times.size - 1)); } long viewRangeMS; if (viewRange > 0) { viewRangeMS = viewRange * MINUTE; } else { // Display full time range, but no less than a minute viewRangeMS = Math.max(tMax - tMin, 1 * MINUTE); } // Calculate min/max values for (Sequence seq : seqs) { if (seq.size > 0) { for (int i = 0; i < seq.size; i++) { if (seq.size == 1 || times.time(i) >= tMax - viewRangeMS) { long val = seq.value(i); if (val > Long.MIN_VALUE) { vMax = Math.max(vMax, val); vMin = Math.min(vMin, val); } } } } else { vMin = 0L; } if (unit == Unit.BYTES || !seq.isPlotted) { // We'll scale only to the first (main) value set. // TODO: Use a separate property for this. break; } } // Normalize scale vMax = normalizeMax(vMax); if (vMin > 0) { if (vMax / vMin > 4) { vMin = 0; } else { vMin = normalizeMin(vMin); } } g.setColor(fg); // Axes // Draw vertical axis int x = leftMargin - 18; int y = topMargin; FontMetrics fm = g.getFontMetrics(); g.drawLine(x, y, x, y + h); int n = 5; if (("" + vMax).startsWith("2")) { n = 4; } else if (("" + vMax).startsWith("3")) { n = 6; } else if (("" + vMax).startsWith("4")) { n = 4; } else if (("" + vMax).startsWith("6")) { n = 6; } else if (("" + vMax).startsWith("7")) { n = 7; } else if (("" + vMax).startsWith("8")) { n = 8; } else if (("" + vMax).startsWith("9")) { n = 3; } // Ticks ArrayList<Long> tickValues = new ArrayList<Long>(); tickValues.add(vMin); for (int i = 0; i < n; i++) { long v = i * vMax / n; if (v > vMin) { tickValues.add(v); } } tickValues.add(vMax); n = tickValues.size(); String[] tickStrings = new String[n]; for (int i = 0; i < n; i++) { long v = tickValues.get(i); tickStrings[i] = getSizeString(v, vMax); } // Trim trailing decimal zeroes. if (decimals > 0) { boolean trimLast = true; boolean removedDecimalPoint = false; do { for (String str : tickStrings) { if (!(str.endsWith("0") || str.endsWith("."))) { trimLast = false; break; } } if (trimLast) { if (tickStrings[0].endsWith(".")) { removedDecimalPoint = true; } for (int i = 0; i < n; i++) { String str = tickStrings[i]; tickStrings[i] = str.substring(0, str.length() - 1); } } } while (trimLast && !removedDecimalPoint); } // Draw ticks int lastY = Integer.MAX_VALUE; for (int i = 0; i < n; i++) { long v = tickValues.get(i); y = topMargin + h - (int) (h * (v - vMin) / (vMax - vMin)); g.drawLine(x - 2, y, x + 2, y); String s = tickStrings[i]; if (unit == Unit.PERCENT) { s += "%"; } int sx = x - 6 - fm.stringWidth(s); if (y < lastY - 13) { if (checkLeftMargin(sx)) { // Wait for next repaint return; } g.drawString(s, sx, y + 4); } // Draw horizontal grid line g.setColor(Color.lightGray); g.drawLine(r.x + 4, y, r.x + r.width - 4, y); g.setColor(fg); lastY = y; } // Draw horizontal axis x = leftMargin; y = topMargin + h + 15; g.drawLine(x, y, x + w, y); long t1 = tMax; if (t1 <= 0L) { // No data yet, so draw current time t1 = System.currentTimeMillis(); } long tz = timeDF.getTimeZone().getOffset(t1); long tickInterval = calculateTickInterval(w, 40, viewRangeMS); if (tickInterval > 3 * HOUR) { tickInterval = calculateTickInterval(w, 80, viewRangeMS); } long t0 = tickInterval - (t1 - viewRangeMS + tz) % tickInterval; while (t0 < viewRangeMS) { x = leftMargin + (int) (w * t0 / viewRangeMS); g.drawLine(x, y - 2, x, y + 2); long t = t1 - viewRangeMS + t0; String str = formatClockTime(t); g.drawString(str, x, y + 16); // if (tickInterval > (1 * HOUR) && t % (1 * DAY) == 0) { if ((t + tz) % (1 * DAY) == 0) { str = formatDate(t); g.drawString(str, x, y + 27); } // Draw vertical grid line g.setColor(Color.lightGray); g.drawLine(x, topMargin, x, topMargin + h); g.setColor(fg); t0 += tickInterval; } // Plot values int start = 0; int nValues = 0; int nLists = seqs.size(); if (nLists > 0) { nValues = seqs.get(0).size; } if (nValues == 0) { g.setColor(oldColor); return; } else { Sequence seq = seqs.get(0); // Find starting point for (int p = 0; p < seq.size; p++) { if (times.time(p) >= tMax - viewRangeMS) { start = p; break; } } } // Optimization: collapse plot of more than four values per pixel int pointsPerPixel = (nValues - start) / w; if (pointsPerPixel < 4) { pointsPerPixel = 1; } // Draw graphs // Loop backwards over sequences because the first needs to be painted on top for (int i = nLists - 1; i >= 0; i--) { int x0 = leftMargin; int y0 = topMargin + h + 1; Sequence seq = seqs.get(i); if (seq.isPlotted && seq.size > 0) { // Paint twice, with white and with color for (int pass = 0; pass < 2; pass++) { g.setColor((pass == 0) ? Color.white : seq.color); int x1 = -1; long v1 = -1; for (int p = start; p < nValues; p += pointsPerPixel) { // Make sure we get the last value if (pointsPerPixel > 1 && p >= nValues - pointsPerPixel) { p = nValues - 1; } int x2 = (int) (w * (times.time(p) - (t1 - viewRangeMS)) / viewRangeMS); long v2 = seq.value(p); if (v2 >= vMin && v2 <= vMax) { int y2 = (int) (h * (v2 - vMin) / (vMax - vMin)); if (x1 >= 0 && v1 >= vMin && v1 <= vMax) { int y1 = (int) (h * (v1 - vMin) / (vMax - vMin)); if (y1 == y2) { // fillrect is much faster g.fillRect(x0 + x1, y0 - y1 - pass, x2 - x1, 1); } else { Graphics2D g2d = (Graphics2D) g; Stroke oldStroke = null; if (seq.transitionStroke != null) { oldStroke = g2d.getStroke(); g2d.setStroke(seq.transitionStroke); } g.drawLine(x0 + x1, y0 - y1 - pass, x0 + x2, y0 - y2 - pass); if (oldStroke != null) { g2d.setStroke(oldStroke); } } } } x1 = x2; v1 = v2; } } // Current value long v = seq.value(seq.size - 1); if (v >= vMin && v <= vMax) { if (bgIsLight) { g.setColor(seq.color); } else { g.setColor(fg); } x = r.x + r.width + 2; y = topMargin + h - (int) (h * (v - vMin) / (vMax - vMin)); // a small triangle/arrow g.fillPolygon(new int[] {x + 2, x + 6, x + 6}, new int[] {y, y + 3, y - 3}, 3); } g.setColor(fg); } } int[] valueStringSlots = new int[nLists]; for (int i = 0; i < nLists; i++) valueStringSlots[i] = -1; for (int i = 0; i < nLists; i++) { Sequence seq = seqs.get(i); if (seq.isPlotted && seq.size > 0) { // Draw current value // TODO: collapse values if pointsPerPixel >= 4 long v = seq.value(seq.size - 1); if (v >= vMin && v <= vMax) { x = r.x + r.width + 2; y = topMargin + h - (int) (h * (v - vMin) / (vMax - vMin)); int y2 = getValueStringSlot(valueStringSlots, y, 2 * 10, i); g.setFont(smallFont); if (bgIsLight) { g.setColor(seq.color); } else { g.setColor(fg); } String curValue = getFormattedValue(v, true); if (unit == Unit.PERCENT) { curValue += "%"; } int valWidth = fm.stringWidth(curValue); String legend = (displayLegend ? seq.name : ""); int legendWidth = fm.stringWidth(legend); if (checkRightMargin(valWidth) || checkRightMargin(legendWidth)) { // Wait for next repaint return; } g.drawString(legend, x + 17, Math.min(topMargin + h, y2 + 3 - 10)); g.drawString(curValue, x + 17, Math.min(topMargin + h + 10, y2 + 3)); // Maybe draw a short line to value if (y2 > y + 3) { g.drawLine(x + 9, y + 2, x + 14, y2); } else if (y2 < y - 3) { g.drawLine(x + 9, y - 2, x + 14, y2); } } g.setFont(oldFont); g.setColor(fg); } } g.setColor(oldColor); }
public void paint(Graphics g) { Rectangle r = bounds(); // paint the box int width = r.width - TF_LEFT + TF_RIGHT; if (width < 0) width = 0; int height = r.height - TF_TOP + TF_BOTTOM; if (height < 0) height = 0; if (r.width > lastWidth) firstVisibleTab = 0; lastWidth = r.width; int col = TF_LEFT; int row; Color c = g.getColor(); g.setColor(getBackground()); g.fillRect(0, 0, r.width, r.height); if (iTabsPosition == TOP) row = TF_TOP; else row = TF_TOP - TF_BTN_HEIGHT; // draw border g.setColor(Color.white); g.drawLine(col, row, (col + width - 1), row); g.drawLine(col, row, col, (row + height - 1)); g.setColor(Color.gray); g.drawLine((col + 2), (row + height - 2), (col + width - 2), (row + height - 2)); g.drawLine((col + width - 2), (row + 2), (col + width - 2), (row + height - 2)); g.setColor(Color.black); g.drawLine((col + 1), (row + height - 1), (col + width - 1), (row + height - 1)); g.drawLine((col + width - 1), (row + 1), (col + width - 1), (row + height - 1)); // paint the tabs, and record areas int x1; int x2 = TF_LEFT + 8; int y1; int y2; int x3 = 0; int x4 = TF_LEFT; int sze = pages.size(); String sLabel; Font f = g.getFont(); FontMetrics fm = getFontMetrics(fReg); FontMetrics fms = getFontMetrics(fSel); int labelWidth = 0; Polygon p; int w; NotebookPage[] npages = new NotebookPage[sze]; for (w = 0; w < sze; ++w) { npages[w] = (NotebookPage) pages.elementAt(w); npages[w].poly = nullPoly; } // make sure there is a polygon for each tab if (firstVisibleTab > 0) x4 += 2; int xStep = 1; for (w = firstVisibleTab; w < sze; w++) { int fheight = fm.getHeight() - fms.getDescent(); if (w == curIndex) fheight = fms.getHeight() - fms.getDescent(); p = new Polygon(); if (npages[w].hidden) { y1 = TF_TOP - TF_BTN_HEIGHT; y2 = TF_TOP - 1; x1 = x4 - 1; x2 = x1 + 1; x3 = x1; x4 = x2; p.addPoint(x1, y1); p.addPoint(x1, y2); p.addPoint(x2, y2); p.addPoint(x2, y1); npages[w].poly = p; // xStep++; continue; } try { sLabel = npages[w].label; if (w == curIndex) labelWidth = fms.stringWidth(sLabel); else labelWidth = fm.stringWidth(sLabel); if (npages[w].img != null) labelWidth += IMAGE_SIZE; if (iTabsPosition == TOP) { y1 = TF_TOP - TF_BTN_HEIGHT; y2 = TF_TOP - 1; } else { y1 = r.height + TF_BOTTOM + 1; y2 = r.height + TF_BOTTOM - TF_BTN_HEIGHT; } if (iTabsStyle == ROUNDED) { x1 = x4 + 2; x2 = x1 + labelWidth + 13; } else { x1 = x2 - 7; x2 = x1 + labelWidth + 28; } // check to see if this tab would draw too far if ((x2 + 36 - TF_RIGHT) > r.width) break; // draw the outside edge of the tab if (iTabsPosition == TOP) { // if current tab, it extends further if (w == curIndex) { y1 -= 3; x1 -= 2; } g.setColor(Color.white); g.drawLine(x1 + 2, y1, x2, y1); // draw the border between tabs if not covered by the current one g.drawLine(x1, y1 + 2, x1, y2); x3 = x1; g.drawLine(x1 + 1, y1 + 1, x1 + 1, y1 + 1); g.setColor(Color.gray); g.drawLine(x2, y1, x2, y2); g.setColor(Color.black); g.drawLine(x2 + 1, y1 + 2, x2 + 1, y2); x4 = x2; } else { if (iTabsStyle == SQUARE) { g.setColor(Color.gray); g.drawLine(x1 + 9, y1, x2 - 9, y1); g.setColor(Color.black); // left \ slanted line if (w == 0 || w == curIndex) { g.drawLine(x1, y2, x1 + 9, y1); p.addPoint(x1, y2); } else { g.drawLine(x1 + 4, y1 - 9, x1 + 9, y1); p.addPoint(x1 + 9, y2); p.addPoint(x1 + 4, y1 - 9); } p.addPoint(x1 + 9, y1); p.addPoint(x2 - 9, y1); if ((w + xStep) == curIndex) { g.drawLine(x2 - 5, y1 - 9, x2 - 9, y1); p.addPoint(x2 - 5, y1); p.addPoint(x2 - 9, y2); } else { g.drawLine(x2, y2, x2 - 9, y1); p.addPoint(x2, y2); } if (w == 1 || w == curIndex) p.addPoint(x1, y2); else p.addPoint(x1 + 9, y2); } else { // if current tab, it extends further if (w == curIndex) { y1 += 3; x1 -= 2; } g.setColor(Color.white); if (curIndex == (w + xStep)) g.drawLine(x1 + 2, y1, x2 - 2, y1); else g.drawLine(x1 + 2, y1, x2, y1); // draw the border between tabs if not covered by the current one if (curIndex != (w - xStep)) { g.drawLine(x1, y1 - 2, x1, y2); x3 = x1; } else x3 = x1 + 1; g.drawLine(x1 + 1, y1 - 1, x1 + 1, y1 - 1); if (curIndex != (w + xStep)) { g.setColor(Color.gray); g.drawLine(x2, y1, x2, y2); g.setColor(Color.black); g.drawLine(x2 + 1, y1 - 2, x2 + 1, y2); x4 = x2; } else x4 = x2 - 1; } } // draw the inside edge of the tab if (w == curIndex) { if (iTabsPosition == TOP) ++y2; else --y2; g.setColor(getBackground()); g.drawLine(x1 + 1, y2, x2, y2); if (iTabsPosition == BOTTOM) g.drawLine(x1 + 1, y2 - 1, x2, y2 - 1); g.setFont(fSel); } else g.setFont(fReg); // if (iTabsPosition == TOP) if (iTabsStyle == ROUNDED) { p.addPoint(x3 - 1, y2 + 1); p.addPoint(x4 + 1, y2 + 1); p.addPoint(x4 + 1, y1 - 1); p.addPoint(x3 + 2, y1 - 1); p.addPoint(x3 - 1, y1 + 2); p.addPoint(x3 - 1, y2 + 1); } npages[w].poly = p; g.setColor(npages[w].color); Polygon p2 = justPolygon(p, iTabsPosition == TOP); g.fillPolygon(p2); // Boolean bool = (Boolean) vEnabled.elementAt(w); // if (bool.booleanValue()) g.setColor(caption); // else // g.setColor(Color.gray); int dx = (npages[w].img == null) ? 0 : IMAGE_SIZE; int xx = x1 + 8 + dx; int yy = y1 + 15; if (iTabsStyle == TOP) { } else if (iTabsStyle == ROUNDED) { yy = y1 - 6; } else { xx = x1 + 14 + dx; yy = y1 - 4; } int imgy = yy - fheight / 2; if (npages[w].img != null) { int imgH = npages[w].img.getHeight(this); int imgW = npages[w].img.getWidth(this); imgy = imgy - imgH / 2 + 1; g.drawImage(npages[w].img, xx - IMAGE_SIZE - 2, imgy, imgW, imgH, this); } g.drawString(sLabel, xx, yy); } catch (ArrayIndexOutOfBoundsException e) { } xStep = 1; } // do I need to show arrows because there are too many tabs??? if ((firstVisibleTab > 0) || (w < sze)) { dbLeft.show(); dbRight.show(); if (firstVisibleTab > 0) dbLeft.enable(); else dbLeft.disable(); if (w < sze) dbRight.enable(); else dbRight.disable(); } else { dbLeft.hide(); dbRight.hide(); } g.setFont(f); g.setColor(c); if (mark && curIndex >= 0) drawMark(g, npages[curIndex].poly); npages = null; }
public void Draw_Arrow(Graphics g) { double arrow_angle; int[] arrow_x = new int[3]; int[] arrow_y = new int[3]; int[] arrow_pt = new int[2]; double gradient, constant; double distance, temp_dist; double mid_x_diff, mid_y_diff; double arrow_ratio; double trans_pts_x, trans_pts_y; trans_pts_x = 0.00; trans_pts_y = 0.00; arrow_ratio = 0.00; mid_x_diff = 0.00; mid_y_diff = 0.00; distance = 0.00; temp_dist = 0.00; gradient = 0.00; constant = 0.00; arrow_x[0] = 0; arrow_x[1] = 0; arrow_x[2] = 0; arrow_y[0] = 0; arrow_y[1] = 0; arrow_y[2] = 0; arrow_angle = 0.00; arrow_angle = (start_angle + arc_angle / 2) * Math.PI / 180; // if (num_arcs != 1) { arrow_x[0] = (int) Math.round(img_mid_x + img_cir * Math.cos(arrow_angle)); arrow_y[0] = (int) Math.round(img_mid_y - img_cir * Math.sin(arrow_angle)); // } // else { // arrow_x[0] = mid_pt_x; // arrow_y[0] = mid_pt_y; // g.drawString("1", (int)arrow_x[0], (int)arrow_y[0]); // } /*calculate the distance between the midpt (on arc) and start node*/ mid_x_diff = Math.abs(arrow_x[0] - start_x); mid_y_diff = Math.abs(arrow_y[0] - start_y); distance = Math.sqrt((mid_x_diff * mid_x_diff) + (mid_y_diff * mid_y_diff)); temp_dist = distance - HEAD_DISTANCE; arrow_ratio = temp_dist / distance; arrow_x[1] = (int) ((arrow_x[0] - start_x) * arrow_ratio + start_x); arrow_y[1] = (int) ((arrow_y[0] - start_y) * arrow_ratio + start_y); // calculate the gradient of the tangent // equation of the circle is (x-c)^2 + (y-d)^2 = R^2 // equation of the line is y = mx + c gradient = ((-1) * (arrow_x[0] - img_mid_x)) / (arrow_y[0] - img_mid_y); // find the constant value of the line constant = arrow_y[0] - gradient * arrow_x[0]; arrow_pt = Translated_Point(constant, arrow_x, arrow_y, gradient); arrow_x[2] = arrow_pt[0]; arrow_y[2] = arrow_pt[1]; if (num_arcs == 1 && testcase != 10) { /*x and y distances between mid pts and arc mid pts */ trans_pts_x = arrow_x[0] - mid_pt_x; trans_pts_y = arrow_y[0] - mid_pt_y; arrow_x[0] = mid_pt_x; arrow_y[0] = mid_pt_y; arrow_x[1] = arrow_x[1] - (int) trans_pts_x; arrow_y[1] = arrow_y[1] - (int) trans_pts_y; arrow_x[2] = arrow_x[2] - (int) trans_pts_x; arrow_y[2] = arrow_y[2] - (int) trans_pts_y; } else if (num_arcs == 1 && testcase == 10) { System.out.println("hello..."); arrow_x[0] = (int) (start_x - diameter); arrow_y[0] = (int) start_y; arrow_x[1] = (int) (diameter / 4 + arrow_x[0]); arrow_y[1] = (int) (diameter / 6 - arrow_y[0]); arrow_x[2] = (int) (diameter / 4 - arrow_x[0]); arrow_y[2] = (int) (diameter / 6 - arrow_y[0]); } g.setColor(arrow_colour); g.fillPolygon(arrow_x, arrow_y, 3); if (value != 0) { g.setColor(value_colour); if (show_cost) { Display_Value(g, arrow_x, arrow_y); } } }
public void paint(Graphics g) { // clears the area that the pannel is on gBuffer.setColor(Color.white); gBuffer.fillRect(0, 0, 65, 415); // pannel gBuffer.setColor(Color.black); gBuffer.drawRect(5, 15, 60, 400); // color buttons gBuffer.setColor(Color.black); // first column gBuffer.fillRect(15, 20, 20, 20); gBuffer.setColor(Color.red); gBuffer.fillRect(15, 40, 20, 20); gBuffer.setColor(Color.blue); gBuffer.fillRect(15, 60, 20, 20); gBuffer.setColor(Color.green); gBuffer.fillRect(15, 80, 20, 20); gBuffer.setColor(Color.yellow); gBuffer.fillRect(15, 100, 20, 20); gBuffer.setColor(Color.gray); // second column gBuffer.fillRect(35, 20, 20, 20); gBuffer.setColor(Color.magenta); gBuffer.fillRect(35, 40, 20, 20); gBuffer.setColor(Color.cyan); gBuffer.fillRect(35, 60, 20, 20); gBuffer.setColor(Color.orange); gBuffer.fillRect(35, 80, 20, 20); gBuffer.setColor(Color.pink); gBuffer.fillRect(35, 100, 20, 20); gBuffer.setColor(Color.black); // draw first column button outlines gBuffer.drawRect(15, 20, 20, 20); gBuffer.drawRect(15, 40, 20, 20); gBuffer.drawRect(15, 60, 20, 20); gBuffer.drawRect(15, 80, 20, 20); gBuffer.drawRect(15, 100, 20, 20); gBuffer.fillRect(15, 20, 20, 20); gBuffer.drawRect(35, 20, 20, 20); // draw second column button outlines gBuffer.drawRect(35, 40, 20, 20); gBuffer.drawRect(35, 60, 20, 20); gBuffer.drawRect(35, 80, 20, 20); gBuffer.drawRect(35, 100, 20, 20); // pen button design gBuffer.setColor(Color.black); gBuffer.drawRect(23, 125, 3, 20); penta = new Polygon(); penta.addPoint(23, 145); penta.addPoint(26, 145); penta.addPoint(25, 148); gBuffer.drawPolygon(penta); // brush button design gBuffer.setColor(Color.gray); gBuffer.fillRect(45, 128, 3, 10); penta = new Polygon(); penta.addPoint(45, 138); penta.addPoint(48, 138); penta.addPoint(51, 141); penta.addPoint(42, 141); gBuffer.drawPolygon(penta); gBuffer.setColor(Color.black); gBuffer.drawRect(42, 141, 9, 5); gBuffer.drawLine(45, 146, 45, 144); gBuffer.drawLine(48, 146, 48, 143); // roller button design gBuffer.setColor(Color.black); // handle gBuffer.fillRect(23, 155, 3, 10); gBuffer.drawRect(19, 165, 9, 4); gBuffer.setColor(Color.white); // roller front gBuffer.fillOval(27, 166, 4, 4); gBuffer.setColor(Color.black); // roller round side gBuffer.drawOval(27, 166, 3, 3); // spray paint button design gBuffer.setColor(Color.black); // top of can penta = new Polygon(); penta.addPoint(43, 156); penta.addPoint(48, 160); penta.addPoint(43, 163); gBuffer.drawPolygon(penta); gBuffer.setColor(Color.blue); // spray button gBuffer.fillRect(42, 155, 2, 3); for (int n = 0; n <= 20; n++) // paint spray { x = 39 + ((int) (3 * Math.cos((rnd.nextDouble() * 2 * Math.PI)))); y = 157 + ((int) (3 * Math.sin((rnd.nextDouble() * 2 * Math.PI)))); gBuffer.fillRect(x, y, 1, 1); } penta = new Polygon(); // can penta.addPoint(43, 163); penta.addPoint(48, 160); penta.addPoint(53, 172); penta.addPoint(48, 177); gBuffer.fillPolygon(penta); gBuffer.setColor(Color.black); gBuffer.drawPolygon(penta); // rubber band drawing button design (20,185,30,205); gBuffer.setColor(Color.black); for (int a = 18, b = 200; a <= 35; a += 4, b += 2) { gBuffer.drawLine(18, 183, a, b); } // eraser button design gBuffer.setColor(Color.yellow); // top penta = new Polygon(); penta.addPoint(45, 185); penta.addPoint(50, 185); penta.addPoint(45, 200); penta.addPoint(40, 200); gBuffer.fillPolygon(penta); gBuffer.setColor(Color.black); // outline gBuffer.drawPolygon(penta); gBuffer.setColor(Color.yellow); // side penta = new Polygon(); penta.addPoint(50, 185); penta.addPoint(45, 200); penta.addPoint(48, 204); penta.addPoint(52, 189); gBuffer.fillPolygon(penta); gBuffer.setColor(Color.black); // outline gBuffer.drawPolygon(penta); penta = new Polygon(); // front penta.addPoint(40, 200); penta.addPoint(45, 200); penta.addPoint(48, 204); penta.addPoint(43, 204); gBuffer.drawPolygon(penta); // clear button design gBuffer.setColor(Color.black); gBuffer.setFont(new Font("Arial", Font.BOLD, 20)); gBuffer.drawString("Clear", 10, 239); gBuffer.drawRect(10, 220, 50, 25); gBuffer.setColor(Color.cyan); switch (numSize) { case 1: gBuffer.drawRect(15, 120, 20, 30); break; case 2: gBuffer.drawRect(35, 120, 20, 30); break; case 3: gBuffer.drawRect(15, 150, 20, 30); break; case 4: gBuffer.drawRect(35, 150, 20, 30); break; case 5: gBuffer.drawRect(15, 180, 20, 30); break; case 6: gBuffer.drawRect(35, 180, 20, 30); break; } if ((numSize == 4) || (numSize == 6)) { // draw different size buttons for spray paint, eraser, and rubber band gBuffer.setColor(Color.white); gBuffer.fillRect(20, 265, 35, 75); gBuffer.setColor(Color.cyan); switch (size) { case 1: gBuffer.drawRect(26, 271, 18, 18); break; case 2: gBuffer.drawRect(26, 291, 18, 18); break; case 3: gBuffer.drawRect(26, 311, 18, 18); } gBuffer.setColor(Color.black); gBuffer.drawRect(20, 265, 30, 70); // size pannel gBuffer.drawRect(25, 270, 20, 20); // small gBuffer.drawRect(25, 290, 20, 20); // medium gBuffer.drawRect(25, 310, 20, 20); // large if (numSize == 4) { for (int n = 0; n <= 20; n++) { x = 35 + ((int) (4 * Math.cos((rnd.nextDouble() * 2 * Math.PI)))); y = 280 + ((int) (4 * Math.sin((rnd.nextDouble() * 2 * Math.PI)))); gBuffer.fillRect(x, y, 1, 1); } for (int n = 0; n <= 40; n++) { x = 34 + ((int) (6 * Math.cos((rnd.nextDouble() * 2 * Math.PI)))); y = 300 + ((int) (6 * Math.sin((rnd.nextDouble() * 2 * Math.PI)))); gBuffer.fillRect(x, y, 1, 1); } for (int n = 0; n <= 70; n++) { x = 35 + ((int) (8 * Math.cos((rnd.nextDouble() * 2 * Math.PI)))); y = 319 + ((int) (8 * Math.sin((rnd.nextDouble() * 2 * Math.PI)))); gBuffer.fillRect(x, y, 1, 1); } switch (size) { case 1: s = 4; break; case 2: s = 6; break; case 3: s = 8; } } else if (numSize == 6) { gBuffer.drawRect(33, 278, 4, 4); gBuffer.drawRect(32, 297, 7, 7); gBuffer.drawRect(30, 315, 10, 10); switch (size) { case 1: s = 4; break; case 2: s = 7; break; case 3: s = 10; } } } else { gBuffer.setColor(Color.white); gBuffer.fillRect(20, 265, 35, 75); } // draw pannel and buttons g.drawImage(virtualMem, 0, 0, this); // changing what color it draws with switch (numColor) { case 1: gBuffer.setColor(Color.black); break; case 2: gBuffer.setColor(Color.red); break; case 3: gBuffer.setColor(Color.blue); break; case 4: gBuffer.setColor(Color.green); break; case 5: gBuffer.setColor(Color.yellow); break; case 6: gBuffer.setColor(Color.gray); break; case 7: gBuffer.setColor(Color.magenta); break; case 8: gBuffer.setColor(Color.cyan); break; case 9: gBuffer.setColor(Color.orange); break; case 10: gBuffer.setColor(Color.pink); break; case 11: gBuffer.setColor(Color.white); break; default: gBuffer.setColor(Color.black); } // changing how it draws switch (numDraw) { case 1: // clear drawing gBuffer.setColor(Color.white); gBuffer.fillRect(0, 0, appletWidth, appletHeight); g.drawImage(virtualMem, 0, 0, this); numDraw = 0; repaint(); break; default: switch (numSize) { case 1: // draw with pen if (!first) { gBuffer.drawLine(oldX, oldY, newX, newY); g.drawImage(virtualMem, 0, 0, this); } else first = false; break; case 2: // draw with brush if (!first) { gBuffer.fillRect(oldX, oldY, 4, 4); g.drawImage(virtualMem, 0, 0, this); } else first = false; break; case 3: // draw with roller if (!first) { gBuffer.fillRect(oldX, oldY, 10, 10); g.drawImage(virtualMem, 0, 0, this); } else first = false; break; case 4: // draw with spray paint if (!first) { for (int n = 0; n <= 20; n++) { x = oldX + ((int) (s * Math.cos((rnd.nextDouble() * 2 * Math.PI)))); y = oldY + ((int) (s * Math.sin((rnd.nextDouble() * 2 * Math.PI)))); gBuffer.fillRect(x, y, 1, 1); g.drawImage(virtualMem, 0, 0, this); } } else first = false; break; case 5: // draw with rubber band style if (!first) { gBuffer.drawLine(startX, startY, endX, endY); g.drawImage(virtualMem, 0, 0, this); } else first = false; break; case 6: // eraser drawer if (!first) { gBuffer.fillRect(oldX, oldY, s, s); g.drawImage(virtualMem, 0, 0, this); } else first = false; break; default: // default to drawing with pen if (!first) { gBuffer.drawLine(oldX, oldY, newX, newY); g.drawImage(virtualMem, 0, 0, this); } else first = false; } } }
public void paint(Graphics g) { // Draw Grid g.drawRect(0, 0, 780, 580); g.drawLine(400, 0, 400, 580); g.drawLine(0, 300, 780, 300); Random rndInt = new Random(1234); // Draw Random Squares for (int k = 1; k <= 1000; k++) { int x = rndInt.nextInt(385); int y = rndInt.nextInt(275); int red = rndInt.nextInt(256); int green = rndInt.nextInt(120); int blue = rndInt.nextInt(120); g.setColor(new Color(red, green, blue)); g.fillRect(x, y, 15, 15); } // Draw Random Lines for (int k = 1; k <= 1000; k++) { int x1 = rndInt.nextInt(350); int y1 = rndInt.nextInt(300); int x2 = rndInt.nextInt(370); int y2 = rndInt.nextInt(300); g.drawLine(x1 + 400, y1, x2 + 400, y2); int red = rndInt.nextInt(100); int green = rndInt.nextInt(100); int blue = rndInt.nextInt(100); g.setColor(new Color(red, green, blue)); } // Draw Random Circles for (int k = 1; k <= 1000; k++) { int x3 = rndInt.nextInt(385); int y3 = rndInt.nextInt(272); int red = rndInt.nextInt(240); int green = rndInt.nextInt(255); int blue = rndInt.nextInt(255); g.setColor(new Color(red, green, blue)); g.drawOval(x3, y3 + 300, 11, 11); } // Draw 3-D Box { g.setColor(Color.blue); int x[] = {575, 675, 675, 575}; int y[] = {425, 425, 525, 525}; g.drawPolygon(x, y, 4); g.fillPolygon(x, y, 4); } { g.setColor(Color.yellow); int x1[] = {525, 575, 575, 525}; int y1[] = {375, 425, 525, 475}; g.drawPolygon(x1, y1, 4); g.fillPolygon(x1, y1, 4); } { g.setColor(Color.green); int x2[] = {525, 625, 625, 575}; int y2[] = {375, 375, 425, 425}; g.drawPolygon(x2, y2, 4); g.fillPolygon(x2, y2, 4); } { g.setColor(Color.red); int x3[] = {625, 625, 675}; int y3[] = {375, 425, 425}; g.drawPolygon(x3, y3, 3); g.fillPolygon(x3, y3, 3); } }