public static void drawPolygon( 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) { 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); g.drawPolygon(myPoly); }
// From: http://forum.java.sun.com/thread.jspa?threadID=378460&tstart=135 void drawArrow( Graphics2D g2d, int xCenter, int yCenter, int x, int y, float stroke, BasicStroke drawStroke) { double aDir = Math.atan2(xCenter - x, yCenter - y); // Line can be dashed. g2d.setStroke(drawStroke); g2d.drawLine(x, y, xCenter, yCenter); // make the arrow head solid even if dash pattern has been specified g2d.setStroke(lineStroke); Polygon tmpPoly = new Polygon(); int i1 = 12 + (int) (stroke * 2); // make the arrow head the same size regardless of the length length int i2 = 6 + (int) stroke; tmpPoly.addPoint(x, y); tmpPoly.addPoint(x + xCor(i1, aDir + .5), y + yCor(i1, aDir + .5)); tmpPoly.addPoint(x + xCor(i2, aDir), y + yCor(i2, aDir)); tmpPoly.addPoint(x + xCor(i1, aDir - .5), y + yCor(i1, aDir - .5)); tmpPoly.addPoint(x, y); // arrow tip g2d.drawPolygon(tmpPoly); // Remove this line to leave arrow head unpainted: g2d.fillPolygon(tmpPoly); }
/** * 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); }
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) { 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); g.fillPolygon(myPoly); }
public static void drawPolygon( Graphics g, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) { Polygon myPoly = new Polygon(); myPoly.addPoint(x1, y1); myPoly.addPoint(x2, y2); myPoly.addPoint(x3, y3); myPoly.addPoint(x4, y4); g.drawPolygon(myPoly); }
public void printLoop(int n, float x[], float y[]) { // Need to swap the y component Polygon P = new Polygon(); for (int i = 0; i < n; i++) P.addPoint(Math.round(x[i]), Math.round(height - y[i])); poly_draw.add(P); poly_draw_color.add(curColor); }
/** * Adds a polygon. Note that the vertices of the polygon are passed using a float[][] and NOT a * float[]. Eg. * * <p>{{x0, y0, z0}, {x1, y1, z1}, ...} * * <p>We *flatten* the data once it is encapsulated inside this class; outside this class we want * clarity; inside this class we want speed! */ public int addPolygon(float[][] vs, Color c, boolean doubleSided) { Polygon polygon = new Polygon(vs.length, c, doubleSided); for (int i = 0; i < vs.length; i++) { polygon.addPoint(this.addPoint(vs[i][0], vs[i][1], vs[i][2])); } polygons[polynext] = polygon; // if this was the last polygon then we may now set the bounding box if (polynext == polygons.length - 1) { this.box.setBB(); } return polynext++; }
public Notebook(int tabsPostion, int tabsStyle) { pages = new Vector(); setTabsInfo(tabsPostion, tabsStyle); fReg = new Font("Helvetica", Font.PLAIN, 12); fSel = new Font("Helvetica", Font.BOLD, 12); setLayout(this); dbLeft = new Button("<<"); dbRight = new Button(">>"); add(dbLeft); add(dbRight); oobj = new Panel(); oobj.setLayout(card = new CardLayout()); add(oobj); nullPoly = new Polygon(); nullPoly.addPoint(0, 0); nullPoly.addPoint(1, 1); nullPoly.addPoint(0, 0); iTabsStyle = TOP; }
private Polygon justPolygon(Polygon p, boolean isTop) { Polygon p2 = new Polygon(); Rectangle r = p.getBoundingBox(); int x, y, i; for (i = 0; i < p.npoints; ++i) { x = p.xpoints[i]; if (p.xpoints[i] >= r.x + r.width - 1) x = p.xpoints[i] - 1; if (p.xpoints[i] == r.x) x = p.xpoints[i] + 2; y = p.ypoints[i]; if (!isTop && p.ypoints[i] >= r.y + r.height - 1) y = p.ypoints[i] - 1; if (isTop && p.ypoints[i] == r.y) y = p.ypoints[i] + 2; p2.addPoint(x, y); } return p2; }
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 printPoly(int n, float x[], float y[]) { Polygon P = new Polygon(); for (int i = 0; i < n; i++) P.addPoint(Math.round(x[i]), Math.round(height - y[i])); poly_fill.add(P); poly_fill_color.add(curColor); }
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 }
public void processPolygonSpline(boolean shiftDown) { mCurrPC.setBatchModeOn(); if (!shiftDown) mCurrPC.unselectAll(); // loop on spline pts to construct a Polygon Polygon srcArea = new Polygon(); for (int s = 0; s < mSplinePoints.size(); s++) { Point p = (Point) mSplinePoints.elementAt(s); int x = p.x - mLeft - 5; int y = p.y - mTop - 5; srcArea.addPoint(x, y); } mSplinePoints.removeAllElements(); // search for matches byte[] currFilterResults = fdm.getResults(); double[] yArray1 = getYArray1(); double[] xArray1 = getXArray1(); double[] yArray2 = getYArray2(); double[] xArray2 = getXArray2(); Point p1 = new Point(); Point p2 = new Point(); for (int i = 0; i < mCurrPC.getSize(); i++) { if (!mIgnoreFilter && (mCurrPC.isDeleted(i) || currFilterResults[i] != 4 || !mCurrPC.isSelectedLayer(i))) continue; double yi = yArray1[i]; double xi = xArray1[i]; double xi2 = Float.NaN; double yi2 = Float.NaN; double xx2 = Float.NaN; double yy2 = Float.NaN; // correct the X value if necessary xi = correctX(xi); double xx1 = (xi - winXOrigin) * winXScale; double yy1 = (yi - winYOrigin) * winYScale; // correct the Y coordinate if necessary yy1 = correctY(yy1); if (!isYAxisScaler()) { yi2 = yArray2[i]; yy2 = (yi2 - winYOrigin) * winYScale; ; yy2 = correctY(yy2); } else yy2 = yy1; if (!isXAxisScaler()) { xi2 = xArray2[i]; xi2 = correctX(xi2); xx2 = (xi2 - winXOrigin) * winXScale; } else xx2 = xx1; p1.setLocation((int) xx1, (int) yy1); p2.setLocation((int) xx2, (int) yy2); if (srcArea.contains(p1) || srcArea.contains(p2)) { mCurrPC.select(i); } } mViewManager.invalidateAllViews(); mCurrPC.setBatchModeOff(); }
public void processSectionSpline(boolean shiftDown) { mCurrPC.setBatchModeOn(); if (!shiftDown) mCurrPC.unselectAll(); // loop on spline pts for (int s = 0; s < mSplinePoints.size() - 2; s++) { Point p1 = (Point) mSplinePoints.elementAt(s); Point p2 = (Point) mSplinePoints.elementAt(s + 1); int x1 = p1.x - mLeft - 5; int y1 = p1.y - mTop - 5; int x2 = p2.x - mLeft - 5; int y2 = p2.y - mTop - 5; // construct the search polygon double dx = x1 - x2; double dy = y1 - y2; int width1 = ComputeSectionPixelWidth(p1); int width2 = ComputeSectionPixelWidth(p2); if (dx == 0 && dy == 0) return; double dist = (double) Math.pow(dx * dx + dy * dy, 0.5f); double p1x = x1 + (double) width1 * (-dy / dist); double p1y = y1 + (double) width1 * (dx / dist); double p2x = x1 - (double) width1 * (-dy / dist); double p2y = y1 - (double) width1 * (dx / dist); double p3x = x2 + (double) width2 * (-dy / dist); double p3y = y2 + (double) width2 * (dx / dist); double p4x = x2 - (double) width2 * (-dy / dist); double p4y = y2 - (double) width2 * (dx / dist); Polygon srcArea = new Polygon(); srcArea.addPoint((int) p2x, (int) p2y); srcArea.addPoint((int) p1x, (int) p1y); srcArea.addPoint((int) p3x, (int) p3y); srcArea.addPoint((int) p4x, (int) p4y); // search for matches byte[] currFilterResults = fdm.getResults(); double[] yArray1 = getYArray1(); double[] xArray1 = getXArray1(); double[] yArray2 = getYArray2(); double[] xArray2 = getXArray2(); mCurrPC.setBatchModeOn(); for (int i = 0; i < mCurrPC.getSize(); i++) { if (!mIgnoreFilter && (mCurrPC.isDeleted(i) || currFilterResults[i] != 4 || !mCurrPC.isSelectedLayer(i))) continue; double yi = yArray1[i]; double xi = xArray1[i]; double xi2 = Float.NaN; double yi2 = Float.NaN; double xx2 = Float.NaN; double yy2 = Float.NaN; // correct the X value if necessary xi = correctX(xi); double xx1 = (xi - winXOrigin) * winXScale; double yy1 = (yi - winYOrigin) * winYScale; // correct the Y coordinate if necessary yy1 = correctY(yy1); if (!isYAxisScaler()) { yi2 = yArray2[i]; yy2 = (yi2 - winYOrigin) * winYScale; ; yy2 = correctY(yy2); } else yy2 = yy1; if (!isXAxisScaler()) { xi2 = xArray2[i]; xi2 = correctX(xi2); xx2 = (xi2 - winXOrigin) * winXScale; } else xx2 = xx1; if (srcArea.contains(new Point((int) xx1, (int) yy1)) || srcArea.contains(new Point((int) xx2, (int) yy2))) { mCurrPC.select(i); } } } // for splines mSplinePoints.removeAllElements(); mViewManager.invalidateAllViews(); mCurrPC.setBatchModeOff(); }
private void addPoint2D(Polygon po, Point2D p) { po.addPoint((int) p.x, (int) p.z); }
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; }