List of usage examples for java.awt Rectangle getX
public double getX()
From source file:com.projity.pm.graphic.spreadsheet.common.CommonSpreadSheet.java
public boolean editCellAt(int row, int column, EventObject e) { boolean b = super.editCellAt(row, column, e); if (b && editorComp != null) { // System.out.println("editing cell at " + row + " " + column); Component comp;/*from www .ja v a 2 s .c om*/ boolean nameCell = false; if (editorComp instanceof NameCellComponent) { nameCell = true; NameCellComponent nameCellComp = (NameCellComponent) editorComp; comp = nameCellComp.getTextComponent(); } else comp = editorComp; if (comp instanceof KeyboardFocusable) ((KeyboardFocusable) comp).selectAll(e == null); else if (comp instanceof ChangeAwareTextField) { ChangeAwareTextField text = ((ChangeAwareTextField) comp); if (e == null) { text.selectAll(); } else if (e instanceof MouseEvent) { if (nameCell) { MouseEvent me = (MouseEvent) e; Rectangle bounds = text.getBounds(null); Rectangle cell = getCellRect(row, column, false); bounds.setFrame(cell.getX() + bounds.getX(), cell.getY() + bounds.getY(), bounds.getWidth(), bounds.getHeight()); if (bounds.contains(me.getPoint())) { text.selectAllOnNextCaretUpdate(); //to avoid diselection when the cell is clicked } else { //because if it's outside there's no caret update text.requestFocus(); text.selectAll(); } } else text.selectAllOnNextCaretUpdate(); //to avoid diselection when the cell is clicked } text.resetChange(); } } return b; }
From source file:gov.lanl.adore.djatoka.plugin.ExtractPDF.java
/** * Extracts region defined in DjatokaDecodeParam as BufferedImage * @param input absolute file path of PDF file. * @param params DjatokaDecodeParam instance containing region and transform settings. * @return extracted region as a BufferedImage * @throws DjatokaException/*www .j ava 2s . co m*/ */ @Override public BufferedImage process(String input, DjatokaDecodeParam params) throws DjatokaException { logger.debug("ExtractPDF.process:\n\tinput: " + input + "\n\tparams: " + params); if (input == null) throw new DjatokaException("Unknown failure while converting file: no image produced."); try { setPDFCommandsPath(); } catch (IllegalStateException e) { logger.error("Failed to set PDF commands path: ", e); throw e; } int page_number = 1 + params.getCompositingLayer(); // From 0-based to 1-based. int status = 0; BufferedImage processedImage = null; try { /* // First get max physical dim of bounding box of the page // to compute the DPI to ask for.. otherwise some AutoCAD // drawings can produce enormous files even at 75dpi, for // 48" drawings.. int dpi = 0; Dimension pageSize = getPDFPageSize(input, page_number); if (pageSize == null) { logger.error("Sanity check: Did not find \"Page " + page_number + " size\" line in output of pdfinfo, file="+input); throw new IllegalArgumentException("Failed to get \"Page " + page_number + " size\" of PDF with pdfinfo."); } else { double w = pageSize.getWidth(); double h = pageSize.getHeight(); int maxdim = (int)Math.max(Math.abs(w), Math.abs(h)); dpi = Math.min(MAX_DPI, (MAX_PX * 72 / maxdim)); logger.debug("DPI: pdfinfo method got dpi="+dpi+" for max dim="+maxdim+" (points, 1/72\")"); } */ // Scale int dpi = getScaledDPI(params); // Requires Sun JAI imageio additions to read ppm directly. // this will get "-[0]+1.ppm" appended to it by pdftoppm File outPrefixF = File.createTempFile("pdftopng", "out"); String outPrefix = outPrefixF.toString(); outPrefixF.delete(); //String pdfCmd[] = PDFTOPPM_COMMAND.clone(); ArrayList<String> pdfCmd = new ArrayList<String>(Arrays.asList(PDFTOPPM_COMMAND)); pdfCmd.set(PDFTOPPM_COMMAND_POSITION_BIN, pdftoppmPath); pdfCmd.set(PDFTOPPM_COMMAND_POSITION_FIRSTPAGE, "" + page_number); pdfCmd.set(PDFTOPPM_COMMAND_POSITION_LASTPAGE, "" + page_number); pdfCmd.set(PDFTOPPM_COMMAND_POSITION_DPI, String.valueOf(dpi)); pdfCmd.set(PDFTOPPM_COMMAND_POSITION_FILE, input.toString()); pdfCmd.set(PDFTOPPM_COMMAND_POSITION_OUTPUTFILE, outPrefix); // Crop Rectangle crop = getCropParam(params); if (crop != null) { String[] cropParams = { "-x", "" + (int) crop.getX(), "-y", "" + (int) crop.getY(), "-W", "" + (int) crop.getWidth(), "-H", "" + (int) crop.getHeight() }; pdfCmd.addAll(PDFTOPPM_COMMAND_POSITION_OPTIONAL_EXTRAS, Arrays.asList(cropParams)); } String[] pdfCmdA = pdfCmd.toArray(new String[pdfCmd.size()]); logger.debug("Running pdftoppm command: " + Arrays.deepToString(pdfCmdA)); //logger.debug("Running pdftoppm command: " + pdfCmd.toString()); File outf = null; Process pdfProc = null; try { pdfProc = Runtime.getRuntime().exec(pdfCmdA); status = pdfProc.waitFor(); logger.debug("status: " + status); // pdftoppm uses variable numbers of padding 0s to the output prefix. // E.g., may be prefix-000001.png, prefix-001.png or even prefix-01.png. // Version 0.12.3 (Poppler, not XPDF) seems to consider the total number of pages. // So, for example, in a PDF with 90 pages, the output will be "prefix-02.png"; // for a PDF with 350 pages, the output will be "prefix-002.png". // FIXME: try some approach where the PDF number of pages is considered without // running pdfinfo command again, thus making it simpler to determine the number // of padding zeros. Right now we going "brute force" because we do not know if // it is feasable to once again run the pdfinfo command. String tests[] = { outPrefix + "-" + page_number + ".png", outPrefix + "-0" + page_number + ".png", outPrefix + "-00" + page_number + ".png", outPrefix + "-000" + page_number + ".png", outPrefix + "-0000" + page_number + ".png", outPrefix + "-00000" + page_number + ".png" }; for (String outname : tests) { if ((new File(outname)).exists()) { outf = new File(outname); break; } } logger.debug("PDFTOPPM output is: " + outf + ", exists=" + outf != null ? outf.exists() : "!"); processedImage = ImageIO.read(outf); // Rotate if (params.getRotationDegree() > 0) { processedImage = ImageProcessingUtils.rotate(processedImage, params.getRotationDegree()); } } catch (InterruptedException e) { logger.error("Failed converting PDF file to image: ", e); throw new IllegalArgumentException("Failed converting PDF file to image: ", e); } finally { if (outf != null) outf.delete(); // Our exec() should not produce any output, but we want to stay safe. // http://mark.koli.ch/2011/01/leaky-pipes-remember-to-close-your-streams-when-using-javas-runtimegetruntimeexec.html org.apache.commons.io.IOUtils.closeQuietly(pdfProc.getOutputStream()); org.apache.commons.io.IOUtils.closeQuietly(pdfProc.getInputStream()); org.apache.commons.io.IOUtils.closeQuietly(pdfProc.getErrorStream()); } } catch (Exception e) { logger.error("Failed converting PDF file to image: ", e); throw new IllegalArgumentException("Failed converting PDF file to image: ", e); } finally { if (status != 0) logger.error("PDF conversion proc failed, exit status=" + status + ", file=" + input); } return processedImage; }
From source file:liveDriftCorrectionGUI.java
private LMA fitRois(float[][] imgData, Roi iRois, double[] InitParam) { Rectangle rec_ = iRois.getBounds(); double[][] img; img = new double[(int) rec_.getWidth()][(int) rec_.getHeight()]; for (int iCol = (int) rec_.getX(); iCol < rec_.getX() + rec_.getWidth(); iCol++) { for (int iRow = (int) rec_.getY(); iRow < rec_.getY() + rec_.getHeight(); iRow++) { int cX = iCol - (int) rec_.getX(); int cY = iRow - (int) rec_.getY(); //ReportingUtils.showMessage(Float.toString(imgData[iCol][iRow])); img[cX][cY] = (double) imgData[iCol][iRow]; }//from w w w . ja va2 s . com } double[][] InitConbineData; InitConbineData = LM2DGaussFit.GenerateDataPoint((int) rec_.getWidth(), (int) rec_.getHeight(), img); LMA lma = new LMA(new LM2DGaussFit.LM2DGaussFunction(), InitParam, InitConbineData); lma.maxIterations = 100; lma.fit(); return lma; }
From source file:com.projity.pm.graphic.spreadsheet.SpreadSheet.java
public boolean isOnIcon(MouseEvent e) { Point p = e.getPoint();/* ww w . jav a 2s. c o m*/ int row = rowAtPoint(p); int col = columnAtPoint(p); Rectangle bounds = getCellRect(row, col, false); SpreadSheetModel model = (SpreadSheetModel) getModel(); GraphicNode node = model.getNode(row); return NameCellComponent.isOnIcon( new Point((int) (p.getX() - bounds.getX()), (int) (p.getY() - bounds.getY())), bounds.getSize(), model.getCache().getLevel(node)); }
From source file:com.projity.pm.graphic.spreadsheet.SpreadSheet.java
public boolean isOnText(MouseEvent e) { Point p = e.getPoint();// w w w . j av a 2s .c o m int row = rowAtPoint(p); int col = columnAtPoint(p); Rectangle bounds = getCellRect(row, col, false); SpreadSheetModel model = (SpreadSheetModel) getModel(); GraphicNode node = model.getNode(row); return NameCellComponent.isOnText( new Point((int) (p.getX() - bounds.getX()), (int) (p.getY() - bounds.getY())), bounds.getSize(), model.getCache().getLevel(node)); }
From source file:com.projity.pm.graphic.gantt.GanttRenderer.java
public void updateShapes(ListIterator nodeIterator) { Rectangle bounds = ((GanttParams) graphInfo).getGanttBounds(); CoordinatesConverter coord = ((GanttParams) graphInfo).getCoord(); if (coord == null) return;//from w ww.j a v a 2 s. c o m double rowHeight = ((GanttParams) graphInfo).getRowHeight(); int i0 = (int) Math.floor(bounds.getY() / rowHeight); int i1 = (int) Math.ceil(bounds.getMaxY() / rowHeight); double t0 = coord.toTime(bounds.getX()); double t1 = coord.toTime(bounds.getMaxX()); GraphicNode node; for (ListIterator i = nodeIterator; i.hasNext();) { node = (GraphicNode) i.next(); node.setRow(i.previousIndex()); if (i.previousIndex() >= i0 && i.previousIndex() < i1) { if (!node.isVoid()) updateShape(node); } } }
From source file:org.yccheok.jstock.gui.charting.InvestmentFlowLayerUI.java
private void solveConflict() { if (this.investPoint == null || this.ROIPoint == null) { /* No conflict to be solved. */ return;/* ww w. j a va 2 s . co m*/ } /* Take border into consideration. */ final Rectangle ROIRectWithBorder = new Rectangle((Rectangle) this.ROIRect); final Rectangle investRectWithBorder = new Rectangle((Rectangle) this.investRect); ROIRectWithBorder.setLocation((int) ROIRectWithBorder.getX() - 1, (int) ROIRectWithBorder.getY() - 1); ROIRectWithBorder.setSize((int) ROIRectWithBorder.getWidth() + 2, (int) ROIRectWithBorder.getHeight() + 2); investRectWithBorder.setLocation((int) investRectWithBorder.getX() - 1, (int) investRectWithBorder.getY() - 1); investRectWithBorder.setSize((int) investRectWithBorder.getWidth() + 2, (int) investRectWithBorder.getHeight() + 2); if (false == ROIRectWithBorder.intersects(investRectWithBorder)) { return; } final Rectangle oldROIRect = new Rectangle((Rectangle) this.ROIRect); final Rectangle oldInvestRect = new Rectangle((Rectangle) this.investRect); // Move to Down. if (this.ROIRect.getY() > this.investRect.getY()) { ((Rectangle) this.ROIRect).translate(0, (int) (this.investRect.getY() + this.investRect.getHeight() - this.ROIRect.getY() + 4)); } else { ((Rectangle) this.investRect).translate(0, (int) (this.ROIRect.getY() + this.ROIRect.getHeight() - this.investRect.getY() + 4)); } if ((this.drawArea.getY() + this.drawArea.getHeight()) > (this.ROIRect.getY() + this.ROIRect.getHeight()) && (this.drawArea.getY() + this.drawArea.getHeight()) > (this.investRect.getY() + this.investRect.getHeight())) { return; } this.ROIRect.setRect(oldROIRect); this.investRect.setRect(oldInvestRect); // Move to Up. if (this.ROIRect.getY() > this.investRect.getY()) { ((Rectangle) this.investRect).translate(0, -(int) (this.investRect.getY() + this.investRect.getHeight() - this.ROIRect.getY() + 4)); } else { ((Rectangle) this.ROIRect).translate(0, -(int) (this.ROIRect.getY() + this.ROIRect.getHeight() - this.investRect.getY() + 4)); } if ((this.drawArea.getY() < this.ROIRect.getY()) && (this.drawArea.getY() < this.investRect.getY())) { return; } this.ROIRect.setRect(oldROIRect); this.investRect.setRect(oldInvestRect); }
From source file:com.projity.pm.graphic.gantt.GanttRenderer.java
public void paintNonWorkingDays(Graphics2D g2, Rectangle bounds) { BarFormat calFormat = getCalendarFormat(); if (calFormat == null) return;/*w w w .j a v a2 s .com*/ //non working days Color oldColor = g2.getColor(); Paint oldPaint = g2.getPaint(); CoordinatesConverter coord = ((GanttParams) graphInfo).getCoord(); Project project = coord.getProject(); WorkingCalendar wc = (WorkingCalendar) project.getWorkCalendar(); if (coord.getTimescaleManager().isShowWholeDays()) { boolean useScale2 = coord.getTimescaleManager().getCurrentScaleIndex() == 0; //valid only for current time scales TimeIterator i = coord.getTimeIterator(bounds.getX(), bounds.getMaxX(), useScale2); long startNonworking = -1L, endNonWorking = -1L; Calendar cal = DateTime.calendarInstance(); PredefinedPaint paint = (PredefinedPaint) calFormat.getMiddle().getPaint();//new PredefinedPaint(PredefinedPaint.DOT_LINE,Colors.VERY_LIGHT_GRAY,Color.WHITE); paint.applyPaint(g2, useTextures()); while (i.hasNext()) { TimeInterval interval = i.next(); long s = interval.getStart(); if (CalendarService.getInstance().getDay(wc, s).isWorking()) { if (startNonworking != -1L) { drawNonWorking(g2, startNonworking, endNonWorking, cal, coord, bounds, useScale2); startNonworking = endNonWorking = -1L; } } else { if (startNonworking == -1L) startNonworking = s; endNonWorking = s; } } if (startNonworking != -1L) { drawNonWorking(g2, startNonworking, endNonWorking, cal, coord, bounds, useScale2); startNonworking = endNonWorking = -1L; } } if (container != null) { //scale2 separation lines TimeIterator i = coord.getTimeIterator(bounds.getX(), bounds.getMaxX(), true); g2.setPaint(new PredefinedPaint(PredefinedPaint.DOT_LINE2, Color.GRAY, g2.getBackground())); while (i.hasNext()) { TimeInterval interval = i.next(); int startX = (int) Math.round(coord.toX(interval.getStart())); g2.drawLine(startX, bounds.y, startX, bounds.y + bounds.height); } //project start int projectStartX = (int) Math.round(coord.toX(project.getStart())); if (projectStartX >= bounds.getX() && projectStartX <= bounds.getMaxX()) { g2.setPaint(new PredefinedPaint(PredefinedPaint.DASH_LINE, Color.GRAY, g2.getBackground())); g2.drawLine(projectStartX, bounds.y, projectStartX, bounds.y + bounds.height); } //project start long statusDate = project.getStatusDate(); if (statusDate != 0) { int statusDateX = (int) Math.round(coord.toX(statusDate)); if (statusDateX >= bounds.getX() && statusDateX <= bounds.getMaxX()) { g2.setPaint(new PredefinedPaint(PredefinedPaint.DOT_LINE2, Color.GREEN, g2.getBackground())); g2.drawLine(statusDateX, bounds.y, statusDateX, bounds.y + bounds.height); } } if (oldColor != null) g2.setColor(oldColor); if (oldPaint != null) g2.setPaint(oldPaint); } }
From source file:com.t3.macro.api.views.TokenView.java
/** * Returns a set of the parts of a token that can be seen by this token. * @param target the token of which we want to check what this token can see * @return the set of visible token parts *//*from ww w . ja v a 2s . c om*/ public EnumSet<TokenPart> getVisibleTokenParts(TokenView target) { if (!token.getHasSight()) return EnumSet.noneOf(TokenPart.class); ZoneRenderer zr = TabletopTool.getFrame().getZoneRenderer(token.getZone()); Zone zone = zr.getZone(); Area tokensVisibleArea = zr.getZoneView().getVisibleArea(token); if (tokensVisibleArea == null) return EnumSet.noneOf(TokenPart.class); if (target == null) throw new NullPointerException(); if (!target.isVisible() || (target.token.isVisibleOnlyToOwner() && !AppUtil.playerOwns(target.token))) { return EnumSet.noneOf(TokenPart.class); } Grid grid = zone.getGrid(); Rectangle bounds = target.token.getFootprint(grid).getBounds(grid, grid.convert(new ZonePoint(target.token.getX(), target.token.getY()))); if (!target.token.isSnapToGrid()) bounds = target.token.getBounds(zone); EnumSet<TokenPart> ret = EnumSet.noneOf(TokenPart.class); int x = (int) bounds.getX(); int y = (int) bounds.getY(); int w = (int) bounds.getWidth(); int h = (int) bounds.getHeight(); int halfX = x + (w) / 2; int halfY = y + (h) / 2; if (tokensVisibleArea.intersects(bounds)) { if (tokensVisibleArea.contains(new Point(x, y))) ret.add(TokenPart.TOP_LEFT); if (tokensVisibleArea.contains(new Point(x, y + h))) if (tokensVisibleArea.contains(new Point(x + w, y))) ret.add(TokenPart.TOP_RIGHT); if (tokensVisibleArea.contains(new Point(x + w, y + h))) ret.add(TokenPart.BOTTOM_LEFT); if (tokensVisibleArea.contains(new Point(halfX, halfY))) ret.add(TokenPart.BOTTOM_RIGHT); } return ret; }
From source file:knop.psfj.BeadImage.java
/** * Gets the enlarged frame.//from w ww.j a v a 2 s . c o m * * @param r the r * @return the enlarged frame */ public Rectangle getEnlargedFrame(Rectangle r) { Rectangle rn = new Rectangle(); int f = frameSize; if (frameSize * frameSize >= imageWidth * imageHeight * 0.8) { rn.setLocation(0, 0); rn.setSize(imageWidth, imageHeight); return rn; } int x = MathUtils.round(r.getX() + r.getWidth() / 2 - f / 2); int y = MathUtils.round(r.getY() + r.getHeight() / 2 - f / 2); x -= 1; y -= 1; int w = f; int h = f; rn.setLocation(x, y); rn.setSize(w, h); return rn; }