Example usage for java.awt Rectangle getHeight

List of usage examples for java.awt Rectangle getHeight

Introduction

In this page you can find the example usage for java.awt Rectangle getHeight.

Prototype

public double getHeight() 

Source Link

Document

Returns the height of the bounding Rectangle in double precision.

Usage

From source file:org.apache.fop.render.pdf.pdfbox.PDFBoxAdapter.java

/**
 * Creates a stream (from FOP's PDF library) from a PDF page parsed with PDFBox.
 * @param sourceDoc the source PDF the given page to be copied belongs to
 * @param page the page to transform into a stream
 * @param key value to use as key for the stream
 * @param atdoc adjustment for stream//from w w w.j  av a  2 s . c o  m
 * @param fontinfo fonts
 * @param pos rectangle
 * @return the stream
 * @throws IOException if an I/O error occurs
 */
public String createStreamFromPDFBoxPage(PDDocument sourceDoc, PDPage page, String key, AffineTransform atdoc,
        FontInfo fontinfo, Rectangle pos) throws IOException {
    handleAnnotations(sourceDoc, page, atdoc);
    if (pageNumbers.containsKey(targetPage.getPageIndex())) {
        pageNumbers.get(targetPage.getPageIndex()).set(0, targetPage.makeReference());
    }
    PDResources sourcePageResources = page.getResources();
    PDStream pdStream = getContents(page);

    COSDictionary fonts = (COSDictionary) sourcePageResources.getCOSObject().getDictionaryObject(COSName.FONT);
    COSDictionary fontsBackup = null;
    UniqueName uniqueName = new UniqueName(key, sourcePageResources);
    String newStream = null;
    if (fonts != null && pdfDoc.isMergeFontsEnabled()) {
        fontsBackup = new COSDictionary(fonts);
        MergeFontsPDFWriter m = new MergeFontsPDFWriter(fonts, fontinfo, uniqueName, parentFonts, currentMCID);
        newStream = m.writeText(pdStream);
        //            if (newStream != null) {
        //                for (Object f : fonts.keySet().toArray()) {
        //                    COSDictionary fontdata = (COSDictionary)fonts.getDictionaryObject((COSName)f);
        //                    if (getUniqueFontName(fontdata) != null) {
        //                        fonts.removeItem((COSName)f);
        //                    }
        //                }
        //            }
    }
    if (newStream == null) {
        PDFWriter writer = new PDFWriter(uniqueName, currentMCID);
        newStream = writer.writeText(pdStream);
        currentMCID = writer.getCurrentMCID();

    }
    pdStream = new PDStream(sourceDoc, new ByteArrayInputStream(newStream.getBytes("ISO-8859-1")));
    mergeXObj(sourcePageResources.getCOSObject(), fontinfo, uniqueName);
    PDFDictionary pageResources = (PDFDictionary) cloneForNewDocument(sourcePageResources.getCOSObject());

    PDFDictionary fontDict = (PDFDictionary) pageResources.get("Font");
    if (fontDict != null && pdfDoc.isMergeFontsEnabled()) {
        for (Map.Entry<String, Typeface> fontEntry : fontinfo.getUsedFonts().entrySet()) {
            Typeface font = fontEntry.getValue();
            if (font instanceof FOPPDFFont) {
                FOPPDFFont pdfFont = (FOPPDFFont) font;
                if (pdfFont.getRef() == null) {
                    pdfFont.setRef(new PDFDictionary());
                    pdfDoc.assignObjectNumber(pdfFont.getRef());
                }
                fontDict.put(fontEntry.getKey(), pdfFont.getRef());
            }
        }
    }
    updateXObj(sourcePageResources.getCOSObject(), pageResources);
    if (fontsBackup != null) {
        sourcePageResources.getCOSObject().setItem(COSName.FONT, fontsBackup);
    }

    COSStream originalPageContents = pdStream.getCOSObject();

    bindOptionalContent(sourceDoc);

    PDFStream pageStream;
    Set filter;
    //        if (originalPageContents instanceof COSStreamArray) {
    //            COSStreamArray array = (COSStreamArray)originalPageContents;
    //            pageStream = new PDFStream();
    //            InputStream in = array.getUnfilteredStream();
    //            OutputStream out = pageStream.getBufferOutputStream();
    //            IOUtils.copyLarge(in, out);
    //            filter = FILTER_FILTER;
    //        } else {
    pageStream = (PDFStream) cloneForNewDocument(originalPageContents);
    filter = Collections.EMPTY_SET;
    //        }
    if (pageStream == null) {
        pageStream = new PDFStream();
    }
    if (originalPageContents != null) {
        transferDict(originalPageContents, pageStream, filter);
    }

    transferPageDict(fonts, uniqueName, sourcePageResources);

    PDRectangle mediaBox = page.getMediaBox();
    PDRectangle cropBox = page.getCropBox();
    PDRectangle viewBox = cropBox != null ? cropBox : mediaBox;

    //Handle the /Rotation entry on the page dict
    int rotation = PDFUtil.getNormalizedRotation(page);

    //Transform to FOP's user space
    float w = (float) pos.getWidth() / 1000f;
    float h = (float) pos.getHeight() / 1000f;
    if (rotation == 90 || rotation == 270) {
        float tmp = w;
        w = h;
        h = tmp;
    }
    atdoc.setTransform(AffineTransform.getScaleInstance(w / viewBox.getWidth(), h / viewBox.getHeight()));
    atdoc.translate(0, viewBox.getHeight());
    atdoc.rotate(-Math.PI);
    atdoc.scale(-1, 1);
    atdoc.translate(-viewBox.getLowerLeftX(), -viewBox.getLowerLeftY());

    rotate(rotation, viewBox, atdoc);

    StringBuilder boxStr = new StringBuilder();
    boxStr.append(PDFNumber.doubleOut(mediaBox.getLowerLeftX())).append(' ')
            .append(PDFNumber.doubleOut(mediaBox.getLowerLeftY())).append(' ')
            .append(PDFNumber.doubleOut(mediaBox.getWidth())).append(' ')
            .append(PDFNumber.doubleOut(mediaBox.getHeight())).append(" re W n\n");
    return boxStr.toString() + IOUtils.toString(pdStream.createInputStream(null), "ISO-8859-1");
}

From source file:org.apache.fop.render.pdf.pdfbox.PDFBoxImageHandler.java

public void handleImage(RenderingContext context, Image image, Rectangle pos) throws IOException {
    assert context instanceof PDFRenderingContext;
    PDFRenderingContext pdfContext = (PDFRenderingContext) context;
    PDFContentGenerator generator = pdfContext.getGenerator();
    assert image instanceof ImagePDF;
    ImagePDF pdfImage = (ImagePDF) image;

    float x = (float) pos.getX() / 1000f;
    float y = (float) pos.getY() / 1000f;
    //        float w = (float)pos.getWidth() / 1000f;
    float h = (float) pos.getHeight() / 1000f;

    AffineTransform pageAdjust = new AffineTransform();
    AffineTransform at = generator.getAffineTransform();
    if (at != null) {
        pageAdjust.setToTranslation((float) (generator.getState().getTransform().getTranslateX()),
                (float) (generator.getState().getTransform().getTranslateY() - h - y));
    }/*ww  w. j av  a2 s.  c  o  m*/
    FontInfo fontinfo = (FontInfo) context.getHint("fontinfo");
    String stream = createStreamForPDF(pdfImage, pdfContext.getPage(), pdfContext.getUserAgent(), pageAdjust,
            fontinfo, pos, pdfContext.getPageNumbers(), pdfContext.getPdfLogicalStructureHandler(),
            pdfContext.getCurrentSessionStructElem());

    if (stream == null) {
        return;
    }
    if (pageAdjust.getScaleX() != 0) {
        pageAdjust.translate(x * (1 / pageAdjust.getScaleX()), -y * (1 / -pageAdjust.getScaleY()));
    }
    generator.placeImage(pageAdjust, stream);
}

From source file:org.apache.fop.render.ps.PSImageHandlerEPS.java

/** {@inheritDoc} */
public void handleImage(RenderingContext context, Image image, Rectangle pos) throws IOException {
    PSRenderingContext psContext = (PSRenderingContext) context;
    PSGenerator gen = psContext.getGenerator();
    ImageRawEPS eps = (ImageRawEPS) image;

    float x = (float) pos.getX() / 1000f;
    float y = (float) pos.getY() / 1000f;
    float w = (float) pos.getWidth() / 1000f;
    float h = (float) pos.getHeight() / 1000f;

    ImageInfo info = image.getInfo();/*ww w . ja  v a2  s.c om*/
    Rectangle2D bbox = eps.getBoundingBox();
    if (bbox == null) {
        bbox = new Rectangle2D.Double();
        bbox.setFrame(new Point2D.Double(), info.getSize().getDimensionPt());
    }
    InputStream in = eps.createInputStream();
    try {
        String resourceName = info.getOriginalURI();
        if (resourceName == null) {
            resourceName = "inline image";
        }
        PSImageUtils.renderEPS(in, resourceName, new Rectangle2D.Float(x, y, w, h), bbox, gen);
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:org.broad.igv.variant.VariantTrack.java

/**
 * Draws the "greenbar" type background.  Also, rather bizarrely, draws the sample names.
 *
 * @param g2D//  w w w  . ja v a  2  s  .co  m
 * @param bandRectangle
 * @param visibleRectangle
 * @param type
 */
private void drawBackground(Graphics2D g2D, Rectangle bandRectangle, Rectangle visibleRectangle,
        BackgroundType type) {

    if (getDisplayMode() == DisplayMode.COLLAPSED) {
        return;
    }

    boolean coloredLast = true;
    Rectangle textRectangle = new Rectangle(bandRectangle);
    textRectangle.height--;

    int bandFontSize = Math.min(fontSize, (int) bandRectangle.getHeight() - 1);
    Font font = FontManager.getFont(bandFontSize);
    Font oldFont = g2D.getFont();
    g2D.setFont(font);

    if (grouped) {
        for (Map.Entry<String, List<String>> sampleGroup : samplesByGroups.entrySet()) {
            int y0 = bandRectangle.y;

            List<String> sampleList = sampleGroup.getValue();
            coloredLast = colorBand(g2D, bandRectangle, visibleRectangle, coloredLast, textRectangle,
                    sampleList, type);
            bandRectangle.y += GROUP_BORDER_WIDTH;

            if (type == BackgroundType.NAME && bandRectangle.height < 3) {
                String group = sampleGroup.getKey();
                if (group != null) {
                    g2D.setColor(Color.black);
                    g2D.setFont(oldFont);
                    int y2 = bandRectangle.y;
                    Rectangle textRect = new Rectangle(bandRectangle.x, y0, bandRectangle.width, y2 - y0);
                    GraphicUtils.drawWrappedText(group, textRect, g2D, true);
                }
            }

        }

    } else {
        coloredLast = colorBand(g2D, bandRectangle, visibleRectangle, coloredLast, textRectangle, allSamples,
                type);
    }
    g2D.setFont(oldFont);
}

From source file:org.eclipse.jubula.rc.javafx.tester.adapter.TreeTableOperationContext.java

@Override
public Rectangle getNodeBounds(final Object node) {
    scrollNodeToVisible(node);//from   w  ww. j  a  va2s  . c  om
    return EventThreadQueuerJavaFXImpl.invokeAndWait("getNodeBounds", new Callable<Rectangle>() { //$NON-NLS-1$

        @Override
        public Rectangle call() throws Exception {
            TreeTableView<?> treeTable = getTree();
            treeTable.layout();
            TreeItem<?> item = (TreeItem<?>) node;
            List<TreeTableCell> cells = new NodeTraverseHelper<TreeTableCell>().getInstancesOf(treeTable,
                    TreeTableCell.class);
            for (TreeTableCell<?, ?> cell : cells) {
                // Nullchecks because of the virtual flow cells
                // are created which might not be associated
                // with a row or an item
                TreeTableRow<?> ttRow = cell.getTreeTableRow();
                if (ttRow == null) {
                    continue;
                }
                TreeItem<?> checkItem = ttRow.getTreeItem();
                if (checkItem == null) {
                    continue;
                }
                if (item != null && checkItem.equals(item)
                        && treeTable.getColumns().indexOf(cell.getTableColumn()) == m_column) {
                    Rectangle b = NodeBounds.getAbsoluteBounds(cell);
                    Rectangle treeB = NodeBounds.getAbsoluteBounds(treeTable);
                    return new Rectangle(Math.abs(treeB.x - b.x), Math.abs(treeB.y - b.y),
                            Rounding.round(b.getWidth()), Rounding.round(b.getHeight()));
                }
            }
            return null;
        }
    });
}

From source file:org.eclipse.jubula.rc.swing.listener.RecordActions.java

/**
 * creates CAP for Click in Component//w w w. jav  a 2 s.  c om
 * @param id IComponentIdentifier
 * @param me MouseEvent
 * @param source Component
 */
protected void clickInComponent(IComponentIdentifier id, MouseEvent me, Component source) {
    int clickcount = me.getClickCount();
    if (clickcount < 1) {
        clickcount = 1;
    }
    String clCount = (new Integer(clickcount).toString());
    String mbutton = (new Integer(me.getButton()).toString());
    Action a = m_recordHelper.compSysToAction(id, "CompSystem.ClickDirect"); //$NON-NLS-1$          
    Rectangle bounds = me.getComponent().getBounds();
    int percentX = (int) (me.getX() / bounds.getWidth() * 100);
    String percentXString = new Integer(percentX).toString();
    int percentY = (int) (me.getY() / bounds.getHeight() * 100);
    String percentYString = new Integer(percentY).toString();
    String units = Constants.REC_UNITS;
    List parValues = new LinkedList();
    parValues.add(clCount);
    parValues.add(mbutton);
    parValues.add(percentXString);
    parValues.add(units);
    parValues.add(percentYString);
    parValues.add(units);

    String logName = createLogicalName(source, id);

    createCAP(a, id, parValues, logName);
}

From source file:org.freecine.filmscan.ScanStrip.java

/**
 Try to find perforation corners using (modified) Hough transform. After the
 hough transform, matching pairs of top and bottom corners are found and
 clustered into pointClusterws list./*  w ww.  java  2  s.c  o m*/
 */
void houghTransform() {

    // Siebel transform of stripImage
    KernelJAI sxKernel = new KernelJAI(3, 3,
            new float[] { -1.0f, 0.0f, 1.0f, -2.0f, 0.0f, 2.0f, -1.0f, 0.0f, 1.0f });
    KernelJAI syKernel = new KernelJAI(3, 3,
            new float[] { -1.0f, -2.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 2.0f, 1.0f });

    RenderedImage dblImg = FormatDescriptor.create(stripImage, DataBuffer.TYPE_DOUBLE, null);
    RenderedImage sxImg = ConvolveDescriptor.create(dblImg, sxKernel, null);
    RenderedImage syImg = ConvolveDescriptor.create(dblImg, syKernel, null);

    SampleModel sm = sxImg.getSampleModel();
    int nbands = sm.getNumBands();
    double[] sxPixel = new double[nbands];
    double[] syPixel = new double[nbands];

    /*
     We are interested only in the left side of the strip as the 
     perforations are there
     */
    Rectangle perfArea = new Rectangle(0, 0, stripImage.getWidth() / 4, stripImage.getHeight());
    RectIter sxIter = RectIterFactory.create(sxImg, perfArea);
    RectIter syIter = RectIterFactory.create(syImg, perfArea);

    int width = (int) perfArea.getWidth();
    int height = (int) perfArea.getHeight();

    /*
     We use 2 accumulators - one for detecting the upper right corner,
     one for lower right corner. As the original is huge and the detaile we 
     are looking for are tiny, we use a sliding window that stores only the 
     relevant part of accumulator.
     */
    int accumHeight = (int) maxCornerRadius + 2;
    int[][] startAccum = new int[(int) (maxCornerRadius - minCornerRadius)][width * accumHeight];
    int[][] endAccum = new int[(int) (maxCornerRadius - minCornerRadius)][width * accumHeight];

    List<Point> startCorners = new ArrayList<Point>();
    List<Point> endCorners = new ArrayList<Point>();
    int y = 0;
    int maxVal = 0;
    if (analysisListener != null) {
        analysisListener.scanAnalysisProgress(0, height);
    }
    while (!sxIter.nextLineDone() && !syIter.nextLineDone()) {
        if (y % 1000 == 0 && y > 0) {
            System.out.println("" + y + " lines analyzed");
        }
        sxIter.startPixels();
        syIter.startPixels();
        int x = 0;
        while (!sxIter.nextPixelDone() && !syIter.nextPixelDone()) {
            sxIter.getPixel(sxPixel);
            syIter.getPixel(syPixel);
            double isq = sxPixel[0] * sxPixel[0] + syPixel[0] * syPixel[0];
            if (isq > EDGE_MIN_GRADIENT * EDGE_MIN_GRADIENT) {
                // This seems like a border
                if (syPixel[0] <= 0 && sxPixel[0] >= 0) {
                    // Upper right corner candidate
                    double intensity = Math.sqrt(isq);
                    for (double r = minCornerRadius; r < maxCornerRadius; r += 1.0) {
                        double cx = (double) x - r * sxPixel[0] / intensity;
                        double cy = (double) y - r * syPixel[0] / intensity;
                        if (cx > 0.0) {
                            int accumLine = (int) cy % accumHeight;
                            startAccum[(int) (r - minCornerRadius)][(int) cx + width * accumLine]++;
                            if (startAccum[(int) (r - minCornerRadius)][(int) cx
                                    + width * accumLine] > maxVal) {
                                maxVal = startAccum[(int) (r - minCornerRadius)][(int) cx + width * accumLine];
                            }
                        }
                    }
                }
                if (syPixel[0] >= 0 && sxPixel[0] >= 0) {
                    // Lower right corner candidate
                    double intensity = Math.sqrt(isq);
                    for (double r = minCornerRadius; r < maxCornerRadius; r += 1.0) {
                        double cx = (double) x - r * sxPixel[0] / intensity;
                        double cy = (double) y - r * syPixel[0] / intensity;
                        if (cx > 0.0 && cy > 0.0) {
                            int accumLine = (int) cy % accumHeight;
                            endAccum[(int) (r - minCornerRadius)][(int) cx + width * accumLine]++;
                            if (endAccum[(int) (r - minCornerRadius)][(int) cx + width * accumLine] > maxVal) {
                                maxVal = endAccum[(int) (r - minCornerRadius)][(int) cx + width * accumLine];
                            }
                        }
                    }
                }
            }
            x++;
        }
        y++;

        /*
         1 line processed - check if there are corner candidates in the 
         accumulator line we are going to overwrite
         */
        int y2 = y - accumHeight;
        int l = y % accumHeight;
        if (y2 > 0) {
            for (int n = 0; n < perfArea.getWidth(); n++) {
                for (int r = 0; r < (int) (maxCornerRadius - minCornerRadius); r++) {
                    if (startAccum[r][n + width * l] >= CORNER_MIN_HOUGH) {
                        // Is this a local maxima?
                        int val = startAccum[r][n + width * l];
                        if (val == getLocalMaxima(startAccum, r, n, y, width)) {
                            startCorners.add(new Point(n, y));
                            System.out.println(String.format("Found corner, quality = %d, r = %d, (%d, %d)",
                                    val, r, n, y));
                            // imageDataSingleArray[n+width*y] = (byte) 0xff;
                        }
                    }
                    if (endAccum[r][n + width * l] > CORNER_MIN_HOUGH) {
                        // Is this a local maxima?
                        int val = endAccum[r][n + width * l];
                        if (val == getLocalMaxima(endAccum, r, n, y2, width)) {
                            endCorners.add(new Point(n, y2));
                            System.out.println(String.format("Found end corner, quality = %d, r = %d, (%d, %d)",
                                    val, r, n, y2));
                            // imageDataSingleArray[n+width*y2] = (byte) 0x80;
                        }
                    }
                }
            }
        }
        // Zero the line just analyzed - it will be reused for the next line
        for (int n = 0; n < perfArea.getWidth(); n++) {
            for (int r = 0; r < (int) (maxCornerRadius - minCornerRadius); r++) {
                startAccum[r][n + width * (y % accumHeight)] = 0;
                endAccum[r][n + width * (y % accumHeight)] = 0;
            }
        }
        if ((y % 100 == 1) && analysisListener != null) {
            analysisListener.scanAnalysisProgress(y - 1, height);
        }
    }

    if (analysisListener != null) {
        analysisListener.scanAnalysisProgress(height, height);
    }

    /*
     Find perforations, i.e. pairs of start and end corners that are within
     the specified range from each other
     */
    for (Point sp : startCorners) {
        for (Point ep : endCorners) {
            if (ep.y - sp.y > CC_MAX_DIST) {
                break;
            }
            if (Math.abs(ep.x - sp.x) < 10 && ep.y - sp.y > CC_MIN_DIST) {
                Perforation p = new Perforation();
                p.x = (ep.x + sp.x) >> 1;
                p.y = (ep.y + sp.y) >> 1;
                // imageDataSingleArray[p.x+width*p.y] = (byte) 0x40;
                addPointToCluster(p.x, p.y);
            }
        }
    }

    System.out.println(String.format("%d clusters:", pointClusters.size()));
    for (PointCluster c : pointClusters) {
        System.out.println(
                String.format("  (%d, %d) %d points", c.getCentroidX(), c.getCentroidY(), c.getPointCount()));
        // imageDataSingleArray[c.getCentroidX()+width*c.getCentroidY()] = (byte) 0xff;
    }

}

From source file:org.mitre.mpf.wfm.camel.operations.detection.trackmerging.TrackMergingProcessor.java

private boolean intersects(Track track1, Track track2, double segMinOverlap) {
    if (!StringUtils.equalsIgnoreCase(track1.getType(), track2.getType())) {
        // Tracks of different types should not be candidates for merger. Ex: It would make no sense to merge a motion and speech track.
        return false;
    } else if (StringUtils.equalsIgnoreCase(track1.getType(), "SPEECH")) {
        // Speech tracks should not be candidates for merger.
        return false;
    }//from w w w  .j a v  a  2  s .  c  o  m

    Detection track1End = track1.getDetections().last();
    Detection track2End = track2.getDetections().first();

    Detection first = (track1End.getMediaOffsetFrame() < track2End.getMediaOffsetFrame()) ? track1End
            : track2End;
    Detection second = (first == track1End) ? track2End : track1End;

    Rectangle rectangle1 = new Rectangle(first.getX(), first.getY(), first.getWidth(), first.getHeight());
    Rectangle rectangle2 = new Rectangle(second.getX(), second.getY(), second.getWidth(), second.getHeight());

    if (rectangle1.getWidth() == 0 || rectangle2.getWidth() == 0 || rectangle1.getHeight() == 0
            || rectangle1.getHeight() == 0) {
        return false;
    }

    Rectangle intersection = rectangle1.intersection(rectangle2);
    if (intersection.isEmpty()) {
        return false;
    }

    double intersectArea = intersection.getHeight() * intersection.getWidth();
    double unionArea = (rectangle2.getHeight() * rectangle2.getWidth())
            + (rectangle1.getHeight() * rectangle1.getWidth()) - intersectArea;
    double percentOverlap = intersectArea / unionArea;

    return percentOverlap > segMinOverlap;
}

From source file:org.netbeans.jbatch.modeler.specification.model.job.util.JobUtil.java

public static void updateDiagramFlowElement(BatchPlane plane, Widget widget) {
    //Diagram Model
    if (widget instanceof NodeWidget) { //reverse ref
        NodeWidget nodeWidget = (NodeWidget) widget;

        Rectangle rec = nodeWidget.getSceneViewBound();

        BatchShape shape = new BatchShape();
        shape.setBounds(new Bounds(rec));//(new Bounds(flowNodeWidget.getBounds()));
        shape.setBatchElement(((BaseElementWidget) nodeWidget).getId());
        shape.setId(((BaseElementWidget) nodeWidget).getId() + "_gui");
        if (nodeWidget.getLabelManager() != null && nodeWidget.getLabelManager().isVisible()
                && nodeWidget.getLabelManager().getLabel() != null
                && !nodeWidget.getLabelManager().getLabel().trim().isEmpty()) {
            Rectangle bound = nodeWidget.getLabelManager().getLabelWidget().getParentWidget()
                    .getPreferredBounds();
            bound = nodeWidget.getLabelManager().getLabelWidget().getParentWidget().convertLocalToScene(bound);

            Rectangle rec_label = new Rectangle(bound.x, bound.y, (int) bound.getWidth(),
                    (int) bound.getHeight());

            BatchLabel label = new BatchLabel();
            label.setBounds(new Bounds(rec_label));
            shape.setBatchLabel(label);/*from   w  w w .j a v a2  s.  c om*/
        }
        plane.addDiagramElement(shape);

        ShapeDesign shapeDesign = null;// BatchShapeDesign XML Location Change Here
        if (nodeWidget instanceof FlowNodeWidget) {
            FlowNode flowNode = (FlowNode) ((FlowNodeWidget) nodeWidget).getBaseElementSpec();
            if (flowNode.getExtensionElements() == null) {
                flowNode.setExtensionElements(new ExtensionElements());
            }
            ExtensionElements extensionElements = flowNode.getExtensionElements();
            for (Object obj : extensionElements.getAny()) {
                if (obj instanceof Element) { //first time save
                    Element element = (Element) obj;
                    if ("ShapeDesign".equals(element.getNodeName())) {
                        shapeDesign = getBatchShapeDesign(nodeWidget);
                        extensionElements.getAny().remove(obj);
                        extensionElements.getAny().add(shapeDesign);
                        break;
                    }
                } else if (obj instanceof ShapeDesign) {
                    shapeDesign = getBatchShapeDesign(nodeWidget);
                    extensionElements.getAny().remove(obj);
                    extensionElements.getAny().add(shapeDesign);
                    break;
                }
            }
        }

        if (shapeDesign == null) {
            if (nodeWidget instanceof FlowNodeWidget) {
                FlowNode flowNode = (FlowNode) ((FlowNodeWidget) nodeWidget).getBaseElementSpec();
                ExtensionElements extensionElements = flowNode.getExtensionElements();
                shapeDesign = getBatchShapeDesign(nodeWidget);
                extensionElements.getAny().add(shapeDesign);
            }
        }

        //            if (nodeWidget instanceof SubProcessWidget) {   //Sub_Commented
        //                SubProcessWidget subProcessWidget = (SubProcessWidget) nodeWidget;
        //                for (FlowElementWidget flowElementChildrenWidget : subProcessWidget.getFlowElements()) {
        //                    updateDiagramFlowElement(plane, (Widget) flowElementChildrenWidget);
        //                }
        //            }
    } else if (widget instanceof EdgeWidget) {
        EdgeWidget edgeWidget = (EdgeWidget) widget;
        BatchEdge edge = new BatchEdge();
        for (java.awt.Point point : edgeWidget.getControlPoints()) {
            edge.addWaypoint(point);
        }
        edge.setBatchElement(((BaseElementWidget) edgeWidget).getId());
        edge.setId(((BaseElementWidget) edgeWidget).getId() + "_gui");

        if (widget instanceof SequenceFlowWidget) {
            if (edgeWidget.getLabelManager() != null && edgeWidget.getLabelManager().isVisible()
                    && edgeWidget.getLabelManager().getLabel() != null
                    && !edgeWidget.getLabelManager().getLabel().trim().isEmpty()) {
                Rectangle bound = edgeWidget.getLabelManager().getLabelWidget().getParentWidget()
                        .getPreferredBounds();
                bound = edgeWidget.getLabelManager().getLabelWidget().getParentWidget()
                        .convertLocalToScene(bound);

                Rectangle rec = new Rectangle(bound.x, bound.y, (int) bound.getWidth(),
                        (int) bound.getHeight());

                BatchLabel label = new BatchLabel();
                label.setBounds(new Bounds(rec));
                edge.setBatchLabel(label);
            }
        }
        plane.addDiagramElement(edge);

    } else {
        throw new InvalidElmentException("Invalid Batch Element");
    }

}

From source file:org.netbeans.jbpmn.modeler.specification.bpmn.model.conversation.util.BPMNConversationUtil.java

public static void updateDiagramFlowElement(BPMNPlane plane, Widget widget) {
    //Diagram Model
    if (widget instanceof NodeWidget) { //reverse ref
        NodeWidget nodeWidget = (NodeWidget) widget;
        Rectangle rec = nodeWidget.getSceneViewBound();

        BPMNShape shape = new BPMNShape();
        shape.setBounds(new Bounds(rec));//(new Bounds(flowNodeWidget.getBounds()));
        shape.setBpmnElement(((BaseElementWidget) nodeWidget).getId());
        shape.setId(((BaseElementWidget) nodeWidget).getId() + "_gui");
        if (nodeWidget.getLabelManager() != null && nodeWidget.getLabelManager().isVisible()
                && nodeWidget.getLabelManager().getLabel() != null
                && !nodeWidget.getLabelManager().getLabel().trim().isEmpty()) {
            Rectangle bound = nodeWidget.getLabelManager().getLabelWidget().getParentWidget()
                    .getPreferredBounds();
            bound = nodeWidget.getLabelManager().getLabelWidget().getParentWidget().convertLocalToScene(bound);

            Rectangle rec_label = new Rectangle(bound.x, bound.y, (int) bound.getWidth(),
                    (int) bound.getHeight());

            BPMNLabel label = new BPMNLabel();
            label.setBounds(new Bounds(rec_label));
            shape.setBPMNLabel(label);/*from   w w  w  .  j a  v a  2  s .c  om*/
        }
        plane.addDiagramElement(shape);
        ShapeDesign shapeDesign = null;// BPMNShapeDesign XML Location Change Here
        if (nodeWidget instanceof CollaborationNodeWidget) {
            TCollaborationNode collaborationNode = (TCollaborationNode) ((CollaborationNodeWidget) nodeWidget)
                    .getBaseElementSpec();
            if (collaborationNode.getExtensionElements() == null) {
                collaborationNode.setExtensionElements(new TExtensionElements());
            }
            TExtensionElements extensionElements = collaborationNode.getExtensionElements();
            for (Object obj : extensionElements.getAny()) {
                if (obj instanceof Element) { //first time save
                    Element element = (Element) obj;
                    if ("ShapeDesign".equals(element.getNodeName())) {
                        shapeDesign = getBPMNShapeDesign(nodeWidget);
                        extensionElements.getAny().remove(obj);
                        extensionElements.getAny().add(shapeDesign);
                        break;
                    }
                } else if (obj instanceof ShapeDesign) {
                    shapeDesign = getBPMNShapeDesign(nodeWidget);
                    extensionElements.getAny().remove(obj);
                    extensionElements.getAny().add(shapeDesign);
                    break;
                }
            }
        }

        if (shapeDesign == null) {
            if (nodeWidget instanceof CollaborationNodeWidget) {
                TCollaborationNode collaborationNode = (TCollaborationNode) ((CollaborationNodeWidget) nodeWidget)
                        .getBaseElementSpec();
                TExtensionElements extensionElements = collaborationNode.getExtensionElements();
                shapeDesign = getBPMNShapeDesign(nodeWidget);
                extensionElements.getAny().add(shapeDesign);
            }
        }
        //            shape.setBpmnShapeDesign(getBPMNShapeDesign(nodeWidget));
        //            if (nodeWidget instanceof SubProcessWidget) {
        //                SubProcessWidget subProcessWidget = (SubProcessWidget) nodeWidget;
        //                for (FlowElementWidget flowElementChildrenWidget : subProcessWidget.getFlowElements()) {
        //                    updateDiagramFlowElement(plane, (Widget) flowElementChildrenWidget);
        //                }
        //            }
    } else if (widget instanceof EdgeWidget) {
        EdgeWidget edgeWidget = (EdgeWidget) widget;
        BPMNEdge edge = new BPMNEdge();
        for (java.awt.Point point : edgeWidget.getControlPoints()) {
            edge.addWaypoint(point);
        }
        edge.setBpmnElement(((BaseElementWidget) edgeWidget).getId());
        edge.setId(((BaseElementWidget) edgeWidget).getId() + "_gui");

        if (widget instanceof ConversationLinkWidget || widget instanceof MessageFlowWidget) { // AssociationWidget has no label
            if (edgeWidget.getLabelManager() != null && edgeWidget.getLabelManager().isVisible()
                    && edgeWidget.getLabelManager().getLabel() != null
                    && !edgeWidget.getLabelManager().getLabel().trim().isEmpty()) {
                Rectangle bound = edgeWidget.getLabelManager().getLabelWidget().getParentWidget()
                        .getPreferredBounds();
                bound = edgeWidget.getLabelManager().getLabelWidget().getParentWidget()
                        .convertLocalToScene(bound);

                Rectangle rec = new Rectangle(bound.x, bound.y, (int) bound.getWidth(),
                        (int) bound.getHeight());

                BPMNLabel label = new BPMNLabel();
                label.setBounds(new Bounds(rec));
                edge.setBPMNLabel(label);
            }
        }
        plane.addDiagramElement(edge);

    } else {
        throw new InvalidElmentException("Invalid BPMN Element");
    }

}