/** * Loads the drawing. By convention this method is invoked on a worker thread. * * @param progress A ProgressIndicator to inform the user about the progress of the operation. * @return The Drawing that was loaded. */ protected Drawing loadDrawing(ProgressIndicator progress) throws IOException { Drawing drawing = createDrawing(); if (getParameter("datafile") != null) { URL url = new URL(getDocumentBase(), getParameter("datafile")); URLConnection uc = url.openConnection(); // Disable caching. This ensures that we always request the // newest version of the drawing from the server. // (Note: The server still needs to set the proper HTTP caching // properties to prevent proxies from caching the drawing). if (uc instanceof HttpURLConnection) { ((HttpURLConnection) uc).setUseCaches(false); } // Read the data into a buffer int contentLength = uc.getContentLength(); InputStream in = uc.getInputStream(); try { if (contentLength != -1) { in = new BoundedRangeInputStream(in); ((BoundedRangeInputStream) in).setMaximum(contentLength + 1); progress.setProgressModel((BoundedRangeModel) in); progress.setIndeterminate(false); } BufferedInputStream bin = new BufferedInputStream(in); bin.mark(512); // Read the data using all supported input formats // until we succeed IOException formatException = null; for (InputFormat format : drawing.getInputFormats()) { try { bin.reset(); } catch (IOException e) { uc = url.openConnection(); in = uc.getInputStream(); in = new BoundedRangeInputStream(in); ((BoundedRangeInputStream) in).setMaximum(contentLength + 1); progress.setProgressModel((BoundedRangeModel) in); bin = new BufferedInputStream(in); bin.mark(512); } try { bin.reset(); format.read(bin, drawing, true); formatException = null; break; } catch (IOException e) { formatException = e; } } if (formatException != null) { throw formatException; } } finally { in.close(); } } return drawing; }
/** Reads the view from the specified uri. */ @Override public void read(URI f, URIChooser chooser) throws IOException { try { final Drawing drawing = createDrawing(); InputFormat inputFormat = drawing.getInputFormats().get(0); inputFormat.read(f, drawing, true); SwingUtilities.invokeAndWait( new Runnable() { @Override public void run() { view.getDrawing().removeUndoableEditListener(undo); view.setDrawing(drawing); view.getDrawing().addUndoableEditListener(undo); undo.discardAllEdits(); } }); } catch (InterruptedException e) { InternalError error = new InternalError(); e.initCause(e); throw error; } catch (InvocationTargetException e) { InternalError error = new InternalError(); e.initCause(e); throw error; } }
@Override public void mouseMoved(MouseEvent evt) { Point point = evt.getPoint(); updateCursor(editor.findView((Container) evt.getSource()), point); DrawingView view = editor.findView((Container) evt.getSource()); updateCursor(view, point); if (view == null || editor.getActiveView() != view) { clearHoverHandles(); } else { // Search first, if one of the selected figures contains // the current mouse location. Only then search for other // figures. This search sequence is consistent with the // search sequence of the SelectionTool. Figure figure = null; Point2D.Double p = view.viewToDrawing(point); for (Figure f : view.getSelectedFigures()) { if (f.contains(p)) { figure = f; } } if (figure == null) { figure = view.findFigure(point); Drawing drawing = view.getDrawing(); while (figure != null && !figure.isSelectable()) { figure = drawing.findFigureBehind(p, figure); } } updateHoverHandles(view, figure); } }
public void executePress(Point p, Drawing dwg) { // Get the color we want the ellipse to have from the drawing Color c = dwg.getColor(); // Create the ellipse and store it in the instance variable s = new Ellipse(p.x, p.y, 0, 0, c); // Store the starting click point oP oP = p; // Add the ellipse to the drawing dwg.add(s); // Record history dwg.recordHistoryItem(new HistoryAction(s, dwg, false)); }
/** Load a Drawing from a file */ protected void loadDrawing(StorageFormat restoreFormat, String file) { try { Drawing restoredDrawing = restoreFormat.restore(file); if (restoredDrawing != null) { restoredDrawing.setTitle(file); newWindow(restoredDrawing); } else { showStatus("Unknown file type: could not open file '" + file + "'"); } } catch (IOException e) { showStatus("Error: " + e); } }
/** * Constructor * * @param d the drawing * @exception IOException */ public BlipStoreEntry(Drawing d) throws IOException { super(EscherRecordType.BSE); type = BlipType.PNG; setVersion(2); setInstance(type.getValue()); byte[] imageData = d.getImageBytes(); imageDataLength = imageData.length; data = new byte[imageDataLength + IMAGE_DATA_OFFSET]; System.arraycopy(imageData, 0, data, IMAGE_DATA_OFFSET, imageDataLength); referenceCount = d.getReferenceCount(); write = true; }
private void drawBalance(Graphics g) // POST: Draws the balance of the current player { Font font; // Font used to draw balance String message; // Message for balance Color oldColor; // Sets for color int x1; // Upper-left x coordinate int y1; // Upper-left y coordinate int x2; // Bottom-right x coordinate int y2; // Bottom-right y coordinate int width; // Width of the dialogue box int height; // Height of the dialogue box int offset; // Offset so the dialogue box is positioned int balance; // Offset so the dialogue box is positioned User player; // User value for the player player = usersArray[0]; balance = player.getBalance(); oldColor = g.getColor(); x1 = ScaledPoint.scalerToX(0.72); y1 = ScaledPoint.scalerToY(0.81); x2 = ScaledPoint.scalerToX(0.88); y2 = ScaledPoint.scalerToY(0.86); width = x2 - x1; height = y2 - y1; message = "Balance:"; font = Drawing.getFont(message, width, height, FONTNAME, FONTSTYLE); offset = (width - getFontMetrics(font).stringWidth(message)) / 2; g.setColor(Color.WHITE); g.drawString(message, x1 + offset, y2); x1 = ScaledPoint.scalerToX(0.72); y1 = ScaledPoint.scalerToY(0.865); x2 = ScaledPoint.scalerToX(0.88); y2 = ScaledPoint.scalerToY(0.915); width = x2 - x1; height = y2 - y1; message = "$" + Integer.toString(balance); font = Drawing.getFont(message, width, height, FONTNAME, FONTSTYLE); offset = (width - getFontMetrics(font).stringWidth(message)) / 2; g.drawString(message, x1 + offset, y2); g.setColor(oldColor); }
private void drawStoreMessage(Graphics g) // PRE: g must be initialized. // POST: Draws the store's dialogue box beneath the store image. { int x1; // Upper-left x coordinate. int y1; // Upper-left y coordinate. int x2; // Bottom-right x coordinate. int y2; // Bottom-right y coordinate. int width; // Width of dialogue box. int height; // Height of dialogue box. int numLines; // Number of lines in dialogue box. String message; // Message to be printed. x1 = ScaledPoint.scalerToX(storeMessagePos[0].getXScaler() + 0.01); y1 = ScaledPoint.scalerToY(storeMessagePos[0].getYScaler() + 0.01); x2 = ScaledPoint.scalerToX(storeMessagePos[1].getXScaler() - 0.01); y2 = ScaledPoint.scalerToY(storeMessagePos[1].getYScaler() - 0.01); width = x2 - x1; height = y2 - y1; Drawing.drawRoundedRect(g, storeMessagePos, Color.WHITE); switch (store) // change message based on value of store. { case 0: message = "If yer lookin' for a weapon, you've come to the right place."; break; case 1: message = "Welcome! You'll not find tougher steel elsewhere."; break; case 2: message = "Come! I guarantee you'll find something that catches your eye!"; break; case 3: message = "Some say that many of my goods are trash... They're right."; break; default: message = "I don't know how you got here..."; } numLines = 1; while (!(Drawing.drawWrappedString(g, message, numLines++, x1, y1, width, height))) ; // while we need more lines for the message }
public synchronized void draw() { gw.clear(1, 1, 1); gw.setColor(0, 0, 0); gw.setupForDrawing(); gw.setCoordinateSystemToWorldSpaceUnits(); gw.enableAlphaBlending(); drawing.draw(gw); gw.setCoordinateSystemToPixels(); for (int j = 0; j < Constant.NUM_USERS; ++j) { userContexts[j].draw(gw); } // Draw some text to indicate the number of fingers touching the user interface. // This is useful for debugging. int totalNumCursors = 0; String s = "["; for (int j = 0; j < Constant.NUM_USERS; ++j) { totalNumCursors += userContexts[j].getNumCursors(); s += (j == 0 ? "" : "+") + userContexts[j].getNumCursors(); } s += " contacts]"; if (totalNumCursors > 0) { gw.setColor(0, 0, 0); gw.setFontHeight(Constant.TEXT_HEIGHT); gw.drawString(Constant.TEXT_HEIGHT, 2 * Constant.TEXT_HEIGHT, s); } }
private void showHelp(Graphics g) // PRE: g must be initialized. // POST: Displays the help image to the screen. { JOptionPane.showMessageDialog(this, "Once you are satisfied, click anywhere to continue!"); Drawing.drawImage(g, 0, 0, getWidth(), getHeight(), ".\\images\\help.jpg"); }
public void paintComponent(Graphics g) { super.paintComponent(g); // Clear screen. g.setColor(Color.white); g.fillRect(0, 0, getWidth(), getHeight()); // draw entire component grey g.setColor(Fonts.sub_color); g.fillRect(0, 0, getWidth(), getHeight()); // Write title. g.setColor(Color.BLACK); g.setFont(Fonts.big); g.drawString("Ear", 20, 150); g.drawString("Training", 20, 200); // Write "Choose Difficulty". g.setFont(Fonts.italic); g.drawString("Choose Difficulty", 20, 300); // Draw piano image keyboard.setDimensions(250, 0, getWidth(), getHeight()); keyboard.paintComponent(g); mainMenu.paintComponent(g); }
private Figure findConnectableFigure(Point2D.Double p, Drawing drawing) { for (Figure f : drawing.getFiguresFrontToBack()) { if (!f.includes(getOwner()) && f.canConnect() && f.contains(p)) { return f; } } return null; }
static Drawing drawMesh() { Drawing d = new Drawing(); Mesh m = new Mesh(); int n = 100; double s = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) { // Mesh m1 = new Mesh(m); int p1 = m.point(i * s, j * s, k * s); int p2 = m.point(i * s + s, j * s, k * s); int p3 = m.point(i * s + s, j * s + s, k * s); int p4 = m.point(i * s, j * s + s, k * s); int p5 = m.point(i * s, j * s, k * s + s); int p6 = m.point(i * s + s, j * s, k * s + s); int p7 = m.point(i * s + s, j * s + s, k * s + s); int p8 = m.point(i * s, j * s + s, k * s + s); m.setResult(p1, (i + j + k) * 0.1); m.setResult(p2, (i + j + k) * 0.1); m.setResult(p3, (i + j + k) * 0.1); m.setResult(p4, (i + j + k) * 0.1); m.setResult(p5, (i + j + k) * 0.1); m.setResult(p6, (i + j + k) * 0.1); m.setResult(p7, (i + j + k) * 0.1); m.setResult(p8, (i + j + k) * 0.1); m.hexahedron(p1, p2, p3, p4, p5, p6, p7, p8); } } } System.out.println("Created"); System.out.print("Assembling..."); m.assemble(); System.out.println("done."); d.addMesh(m); return d; }
static Drawing draw() { Drawing d = new Drawing(); d.setCheckIntersection(false); Shape box = d.box(1, 1, 1); box = d.fillet(box, 0.2); d.moveTo(0.5, 0, 0.5); Shape cone = d.cone(0.2, 0.3, 1, Math.PI * 2); Shape fig = d.cut(box, cone); d.delete(cone); return d; }
private Figure findConnectableFigure(int x, int y, Drawing drawing) { FigureEnumeration fe = drawing.figuresReverse(); while (fe.hasNextFigure()) { Figure figure = fe.nextFigure(); if (!figure.includes(getConnection()) && figure.canConnect() && figure.containsPoint(x, y)) { return figure; } } return null; }
protected void loadDrawing(String param) { if (param == fgUntitled) { fDrawing.release(); initDrawing(); return; } String filename = getParameter(param); if (filename != null) { readDrawing(filename); } }
private Figure findConnectableFigure(int x, int y, Drawing drawing) { FigureEnumeration k = drawing.figuresReverse(); while (k.hasMoreElements()) { Figure figure = k.nextFigure(); if (!figure.includes(getConnection()) && figure.canConnect()) { if (figure.containsPoint(x, y)) { return figure; } } } return null; }
public void setData(String text) { if (text != null && text.length() > 0) { InputStream in = null; try { Object result = null; Drawing drawing = createDrawing(); // Try to read the data using all known input formats. for (InputFormat fmt : drawing.getInputFormats()) { try { fmt.read(in, drawing); in = new ByteArrayInputStream(text.getBytes("UTF8")); result = drawing; break; } catch (IOException e) { result = e; } } if (result instanceof IOException) { throw (IOException) result; } setDrawing(drawing); } catch (Throwable e) { getDrawing().removeAllChildren(); SVGTextFigure tf = new SVGTextFigure(); tf.setText(e.getMessage()); tf.setBounds(new Point2D.Double(10, 10), new Point2D.Double(100, 100)); getDrawing().add(tf); e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (IOException ex) { ex.printStackTrace(); } } } } }
private void drawStoreName(Graphics g) // PRE: g must be initialized. // POST: Draws the store name along with a rounded border at the top of the window. { int rectWidth; // The width of the drawing area. int rectHeight; // The height of the drawing area. String storeName; // The name of the store. Font font; // The font to be used. rectWidth = nameLocation[1].getScaledX() - nameLocation[0].getScaledX(); rectHeight = nameLocation[1].getScaledY() - nameLocation[0].getScaledY(); switch (store) // set message based on store value. { case 0: storeName = "Raneac's Crucible"; break; case 1: storeName = "The Iron Maiden"; break; case 2: storeName = "The Grand Bazaar"; break; default: storeName = "Miko's Wares"; } font = Drawing.getFont(storeName, rectWidth, rectHeight, FONTNAME, FONTSTYLE); g.setFont(font); g.setColor(Color.WHITE); g.drawString( storeName, nameLocation[0].getScaledX(), (int) (nameLocation[1].getScaledY() * .98)); Drawing.drawRoundedRect(g, nameLocation, Color.WHITE); }
@Override public void informButtonClicked(ButtonType buttonType, int buttonId) { Drawing nextView = null; switch (buttonId) { case 62: nextView = new PitchTrainingUI(); break; case 64: nextView = new AdvancedPitchTrainingUI(); break; case 65: nextView = new IntervalTrainingUI(); break; case 67: nextView = new ChordTrainingUI(); break; case 69: nextView = new AdvancedChordTrainingUI(); break; } nextView.switchToView(); JFrameStack.pushPanel(nextView); }
private void readFromStorableInput(String filename) { try { URL url = new URL(getCodeBase(), filename); InputStream stream = url.openStream(); StorableInput input = new StorableInput(stream); fDrawing.release(); fDrawing = (Drawing) input.readStorable(); view().setDrawing(fDrawing); } catch (IOException e) { initDrawing(); showStatus("Error:" + e); } }
public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source == testMenuItem1) { System.out.println("testMenuItem1 has been selected"); } else if (source == testMenuItem2) { System.out.println("testMenuItem2 has been selected"); } else if (source == frameAllButton) { gw.frame(drawing.getBoundingRectangle(), true); multitouchFramework.requestRedraw(); } else if (source == testButton1) { System.out.println("testButton1 has been selected"); } else if (source == testButton2) { System.out.println("testButton2 has been selected"); } }
static Drawing testMesh() { Drawing d = new Drawing(); d.setTransparency(0.9); Shape s = d.box(2, 2, 2); Shape s1 = d.box(1, 1, 1); s = d.cut(s, s1); d.moveTo(0, 2, 0); Shape s2 = d.box(0.2, 2, 0.2); s.setMeshSize(0.3); s2.setMeshSize(0.1); // d.fuse(s, s2); d.save("test.brep"); return d; }
public void testOneSeriePlot() throws Exception { Workbook wb = new XSSFWorkbook(); Sheet sheet = new SheetBuilder(wb, plotData).build(); Drawing drawing = sheet.createDrawingPatriarch(); ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30); Chart chart = drawing.createChart(anchor); ChartAxis bottomAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.BOTTOM); ChartAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT); ScatterChartData scatterChartData = chart.getChartDataFactory().createScatterChartData(); ChartDataSource<String> xs = DataSources.fromStringCellRange(sheet, CellRangeAddress.valueOf("A1:J1")); ChartDataSource<Number> ys = DataSources.fromNumericCellRange(sheet, CellRangeAddress.valueOf("A2:J2")); ScatterChartSerie serie = scatterChartData.addSerie(xs, ys); assertNotNull(serie); assertEquals(1, scatterChartData.getSeries().size()); assertTrue(scatterChartData.getSeries().contains(serie)); chart.plot(scatterChartData, bottomAxis, leftAxis); }
private void readFromObjectInput(String filename) { try { URL url = new URL(getCodeBase(), filename); InputStream stream = url.openStream(); ObjectInput input = new ObjectInputStream(stream); fDrawing.release(); fDrawing = (Drawing) input.readObject(); view().setDrawing(fDrawing); } catch (IOException e) { initDrawing(); showStatus("Error: " + e); } catch (ClassNotFoundException e) { initDrawing(); showStatus("Class not found: " + e); } }
/** @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Shape tri = new Triangle(); Shape tri1 = new Triangle(); Shape cir = new Circle(); Drawing drawing = new Drawing(); drawing.add(tri); drawing.add(tri1); drawing.add(cir); drawing.draw("Red"); drawing.clear(); drawing.add(tri); drawing.add(cir); drawing.draw("Green"); }
static Drawing drawBox() { Drawing d = new Drawing(); d.setLineWidth(2); d.setCheckIntersection(false); Shape box = d.box(1, 1, 1); int n = 15; double dist = 1.1; Shape line = d.array(box, n, dist, 0, 0); Shape area = d.array(line, n, 0, dist, 0); Shape cube = d.array(area, n, 0, 0, dist); d.setCheckIntersection(true); return d; }
@Override protected void paintComponent(Graphics g) { if (numberGroup == null) return; // No display if count is null super.paintComponent(g); // Find the panel size and bar width and interval dynamically int width = getWidth(); int height = getHeight(); int interval = (width - 40) / numberGroup.length; int individualWidth = (int) (((width - 40) / numberGroup.length) * 0.9); // The maximum count has the highest bar int maxCount = numberGroup.length; // x is the start position for the first bar in the histogram int x = 20; /* * Draw a horizontal base line */ g.drawLine(10, height - 45, width - 10, height - 45); // 45 pixels from bottom for (int i = 0; i < numberGroup.length; i++) { // Find the bar height int barHeight = (int) (((double) numberGroup[i] / (double) maxCount) * (height - 55)); /* * Display a rectangle bar, set color according to the height */ // g.setColor(new Color(255,128,i*25)); setRectColor(g, i); g.fillRect(x, height - 45 - barHeight, individualWidth, barHeight); // Display the number under the base line g.drawString((i + 1) + "", x, height - 30); // Move x for displaying the next number x += interval; } }
/** * Draw the macro contents. * * @param g the graphic context. * @param coordSys the coordinate system. * @param layerV the vector containing all layers. */ private void drawMacroContents(GraphicsInterface g, MapCoordinates coordSys, Vector layerV) { /* in the macro primitive, the the virtual point represents the position of the reference point of the macro to be drawn. */ if (changed) { changed = false; x1 = virtualPoint[0].x; y1 = virtualPoint[0].y; macroCoord.setXMagnitude(coordSys.getXMagnitude()); macroCoord.setYMagnitude(coordSys.getYMagnitude()); macroCoord.setXCenter(coordSys.mapXr(x1, y1)); macroCoord.setYCenter(coordSys.mapYr(x1, y1)); macroCoord.setOrientation((o + coordSys.getOrientation()) % 4); macroCoord.mirror = m ^ coordSys.mirror; macroCoord.isMacro = true; macroCoord.resetMinMax(); macro.setChanged(true); } if (getSelected()) { new SelectionActions(macro).setSelectionAll(true); selected = true; } else if (selected) { new SelectionActions(macro).setSelectionAll(false); selected = false; } macro.setDrawOnlyLayer(drawOnlyLayer); macro.setDrawOnlyPads(drawOnlyPads); drawingAgent = new Drawing(macro); drawingAgent.draw(g, macroCoord); if (macroCoord.getXMax() > macroCoord.getXMin() && macroCoord.getYMax() > macroCoord.getYMin()) { coordSys.trackPoint(macroCoord.getXMax(), macroCoord.getYMax()); coordSys.trackPoint(macroCoord.getXMin(), macroCoord.getYMin()); } }
private void drawStoreImage(Graphics g) // PRE: g must be initialized. // POST: Draws the image associated with the store at the storeImage location. // All images should be located in the \images\ directory. { String filePath; // the image file path int x; // x coordinate of upper-right corner of image. int y; // y coordinate of upper-right corner of image. int width; // width of image int height; // height of image x = storeImage[0].getScaledX(); y = storeImage[0].getScaledY(); width = storeImage[1].getScaledX() - storeImage[0].getScaledX(); height = storeImage[1].getScaledY() - storeImage[0].getScaledY(); switch (store) // initialize file path to image based on store { case 0: filePath = ".\\images\\weaponSmith.jpg"; break; case 1: filePath = ".\\images\\armorSmith.jpg"; break; case 2: filePath = ".\\images\\accessoryMerchant.jpg"; break; case 3: filePath = ".\\images\\generalMerchant.png"; break; default: filePath = ".\\images\\generalMerchant.png"; } Drawing.drawImage(g, x, y, width, height, filePath); }