Example usage for org.apache.poi.hslf.usermodel HSLFPictureShape HSLFPictureShape

List of usage examples for org.apache.poi.hslf.usermodel HSLFPictureShape HSLFPictureShape

Introduction

In this page you can find the example usage for org.apache.poi.hslf.usermodel HSLFPictureShape HSLFPictureShape.

Prototype

public HSLFPictureShape(HSLFPictureData data) 

Source Link

Document

Create a new Picture

Usage

From source file:io.github.jeddict.jpa.modeler.specification.export.ExportManagerImpl.java

License:Apache License

@Override
public void export(JPAModelerScene scene, FileType format, File file) {
    try {//w w w .  ja  va2  s.c o  m
        HSLFSlideShow ppt = new HSLFSlideShow();
        int width = 0, height = 0;
        HSLFSlide slide = ppt.createSlide();
        for (IBaseElementWidget baseElementWidget : scene.getBaseElements()) {
            if (baseElementWidget instanceof INodeWidget) {
                INodeWidget nodeWidget = (INodeWidget) baseElementWidget;
                Rectangle rect = nodeWidget.getSceneViewBound();

                HSLFGroupShape group = new HSLFGroupShape();
                slide.addShape(group);

                if (width < rect.x + rect.width) {
                    width = rect.x + rect.width;
                }
                if (height < rect.y + rect.height) {
                    height = rect.y + rect.height;
                }

                HSLFTextBox shape = new HSLFTextBox();
                shape.setAnchor(new java.awt.Rectangle(rect.x, rect.y, rect.width, rect.height));
                shape.setFillColor(Color.WHITE);
                shape.setLineColor(Color.BLACK);

                if (baseElementWidget instanceof PersistenceClassWidget) {
                    PersistenceClassWidget<? extends ManagedClass> entityWidget = (PersistenceClassWidget) baseElementWidget;
                    HSLFTextRun classTextRun = shape.setText(entityWidget.getName());
                    classTextRun.setFontSize(18.);
                    classTextRun.setFontFamily("Arial");
                    classTextRun.setBold(true);
                    classTextRun.setUnderlined(true);
                    classTextRun.setFontColor(Color.BLACK);
                    classTextRun.getTextParagraph().setTextAlign(TextAlign.LEFT);
                    Class category = null;
                    for (AttributeWidget attributeWidget : entityWidget.getAllAttributeWidgets(false)) {
                        if (category == null || !category.isAssignableFrom(attributeWidget.getClass())) {
                            HSLFTextRun categoryTextRun = null;
                            if (attributeWidget instanceof BasicAttributeWidget) {
                                if (category == BasicCollectionAttributeWidget.class) {
                                    continue;
                                }
                                category = BasicAttributeWidget.class;
                                categoryTextRun = shape.appendText("Basic", true);
                            } else if (attributeWidget instanceof BasicCollectionAttributeWidget) {
                                if (category == BasicAttributeWidget.class) {
                                    continue;
                                }
                                category = BasicCollectionAttributeWidget.class;
                                categoryTextRun = shape.appendText("Basic", true);
                            } else if (attributeWidget instanceof RelationAttributeWidget) {
                                category = RelationAttributeWidget.class;
                                categoryTextRun = shape.appendText("Relation", true);
                            } else if (attributeWidget instanceof VersionAttributeWidget) {
                                category = VersionAttributeWidget.class;
                                categoryTextRun = shape.appendText("Version", true);
                            } else if (attributeWidget instanceof TransientAttributeWidget) {
                                category = TransientAttributeWidget.class;
                                categoryTextRun = shape.appendText("Transient", true);
                            } else if (attributeWidget instanceof EmbeddedAttributeWidget) {
                                category = EmbeddedAttributeWidget.class;
                                categoryTextRun = shape.appendText("Embedded", true);
                            } else if (attributeWidget instanceof IdAttributeWidget) {
                                category = IdAttributeWidget.class;
                                categoryTextRun = shape.appendText("PrimaryKey", true);
                            } else if (attributeWidget instanceof EmbeddedIdAttributeWidget) {
                                category = EmbeddedIdAttributeWidget.class;
                                categoryTextRun = shape.appendText("Embedded Id", true);
                            } else {
                                category = null;
                                categoryTextRun = shape.appendText("Attribute", true);
                            }
                            categoryTextRun.setFontSize(10.);
                            categoryTextRun.setFontFamily("Arial");
                            categoryTextRun.setBold(true);
                            categoryTextRun.setUnderlined(true);
                            categoryTextRun.setFontColor(Color.GRAY);
                            categoryTextRun.getTextParagraph().setTextAlign(TextAlign.CENTER);
                        }
                        HSLFTextRun attrTextRun = shape.appendText(attributeWidget.getLabel(), true);
                        attrTextRun.setFontSize(16.);
                        attrTextRun.setFontFamily("Arial");
                        attrTextRun.setBold(false);
                        attrTextRun.setUnderlined(false);
                        attrTextRun.setFontColor(Color.BLACK);
                        attrTextRun.getTextParagraph().setTextAlign(TextAlign.LEFT);
                    }
                    group.addShape(shape);
                }

            } else {
                EdgeWidget edgeWidget = (EdgeWidget) baseElementWidget;

                Path2D.Double path = new Path2D.Double();
                Point initPoint = null, moveTo = null;
                for (java.awt.Point point : edgeWidget.getControlPoints()) {
                    if (initPoint == null) {
                        initPoint = point;
                        path.moveTo(point.x, point.y);
                    } else {
                        path.lineTo(point.x, point.y);
                    }
                    moveTo = point;
                }

                HSLFGroupShape group = new HSLFGroupShape();
                slide.addShape(group);

                HSLFFreeformShape shape = new HSLFFreeformShape();
                shape.setPath(path);
                shape.setFillColor(null);
                group.addShape(shape);

                if (edgeWidget instanceof GeneralizationFlowWidget) {
                    byte[] targetAnchor = getImageArray(GENERALIZATION_ICON);
                    HSLFPictureData targetPictureData = ppt.addPicture(targetAnchor,
                            PictureData.PictureType.PNG);
                    HSLFPictureShape targetPictureShape = new HSLFPictureShape(targetPictureData);
                    group.addShape(targetPictureShape);
                    targetPictureShape.moveTo(moveTo.x - 6, moveTo.y - 3);
                } else {
                    //source anchor
                    Image sourceAnchorImage = ((IconAnchorShape) edgeWidget.getSourceAnchorShape()).getImage();
                    byte[] sourceAnchor = getImageArray(sourceAnchorImage);
                    HSLFPictureData sourcePictureData = ppt.addPicture(sourceAnchor,
                            PictureData.PictureType.PNG);
                    HSLFPictureShape sourcePictureShape = new HSLFPictureShape(sourcePictureData);
                    group.addShape(sourcePictureShape);
                    sourcePictureShape.moveTo(initPoint.x - 6, initPoint.y - 5);

                    //target anchor
                    Image targetAnchorImage = ((IconAnchorShape) edgeWidget.getTargetAnchorShape()).getImage();
                    byte[] targetAnchor = getImageArray(targetAnchorImage);
                    HSLFPictureData targetPictureData = ppt.addPicture(targetAnchor,
                            PictureData.PictureType.PNG);
                    HSLFPictureShape targetPictureShape = new HSLFPictureShape(targetPictureData);
                    group.addShape(targetPictureShape);
                    targetPictureShape.moveTo(moveTo.x - 6, moveTo.y - 5);
                }
            }
        }
        ppt.setPageSize(new Dimension(width + 20, height + 20));
        FileOutputStream out = new FileOutputStream(file);
        ppt.write(out);
        out.close();
    } catch (IOException ex) {
        scene.getModelerFile().handleException(ex);
    }
}

From source file:org.netbeans.jpa.modeler.specification.export.ExportManagerImpl.java

License:Apache License

@Override
public void export(JPAModelerScene scene, FileType format, File file) {
    try {/*ww w .  ja  v a 2s. com*/
        HSLFSlideShow ppt = new HSLFSlideShow();
        int width = 0, height = 0;
        HSLFSlide slide = ppt.createSlide();
        for (IBaseElementWidget baseElementWidget : scene.getBaseElements()) {
            if (baseElementWidget instanceof INodeWidget) {
                INodeWidget nodeWidget = (INodeWidget) baseElementWidget;
                Rectangle rect = nodeWidget.getSceneViewBound();

                HSLFGroupShape group = new HSLFGroupShape();
                slide.addShape(group);

                if (width < rect.x + rect.width) {
                    width = rect.x + rect.width;
                }
                if (height < rect.y + rect.height) {
                    height = rect.y + rect.height;
                }

                HSLFTextBox shape = new HSLFTextBox();
                shape.setAnchor(new java.awt.Rectangle(rect.x, rect.y, rect.width, rect.height));
                shape.setFillColor(Color.WHITE);
                shape.setLineColor(Color.BLACK);

                if (baseElementWidget instanceof PersistenceClassWidget) {
                    PersistenceClassWidget<? extends ManagedClass> entityWidget = (PersistenceClassWidget) baseElementWidget;
                    HSLFTextRun classTextRun = shape.setText(entityWidget.getName());
                    classTextRun.setFontSize(18.);
                    classTextRun.setFontFamily("Arial");
                    classTextRun.setBold(true);
                    classTextRun.setUnderlined(true);
                    classTextRun.setFontColor(Color.BLACK);
                    classTextRun.getTextParagraph().setAlignment(TextAlign.LEFT);
                    Class category = null;
                    for (AttributeWidget attributeWidget : entityWidget.getAllAttributeWidgets(false)) {
                        if (category == null || !category.isAssignableFrom(attributeWidget.getClass())) {
                            HSLFTextRun categoryTextRun = null;
                            if (attributeWidget instanceof BasicAttributeWidget) {
                                if (category == BasicCollectionAttributeWidget.class) {
                                    continue;
                                }
                                category = BasicAttributeWidget.class;
                                categoryTextRun = shape.appendText("Basic", true);
                            } else if (attributeWidget instanceof BasicCollectionAttributeWidget) {
                                if (category == BasicAttributeWidget.class) {
                                    continue;
                                }
                                category = BasicCollectionAttributeWidget.class;
                                categoryTextRun = shape.appendText("Basic", true);
                            } else if (attributeWidget instanceof RelationAttributeWidget) {
                                category = RelationAttributeWidget.class;
                                categoryTextRun = shape.appendText("Relation", true);
                            } else if (attributeWidget instanceof VersionAttributeWidget) {
                                category = VersionAttributeWidget.class;
                                categoryTextRun = shape.appendText("Version", true);
                            } else if (attributeWidget instanceof TransientAttributeWidget) {
                                category = TransientAttributeWidget.class;
                                categoryTextRun = shape.appendText("Transient", true);
                            } else if (attributeWidget instanceof EmbeddedAttributeWidget) {
                                category = EmbeddedAttributeWidget.class;
                                categoryTextRun = shape.appendText("Embedded", true);
                            } else if (attributeWidget instanceof IdAttributeWidget) {
                                category = IdAttributeWidget.class;
                                categoryTextRun = shape.appendText("PrimaryKey", true);
                            } else if (attributeWidget instanceof EmbeddedIdAttributeWidget) {
                                category = EmbeddedIdAttributeWidget.class;
                                categoryTextRun = shape.appendText("Embedded Id", true);
                            } else {
                                category = null;
                                categoryTextRun = shape.appendText("Attribute", true);
                            }
                            categoryTextRun.setFontSize(10.);
                            categoryTextRun.setFontFamily("Arial");
                            categoryTextRun.setBold(true);
                            categoryTextRun.setUnderlined(true);
                            categoryTextRun.setFontColor(Color.GRAY);
                            categoryTextRun.getTextParagraph().setAlignment(TextAlign.CENTER);
                        }
                        HSLFTextRun attrTextRun = shape.appendText(attributeWidget.getLabel(), true);
                        attrTextRun.setFontSize(16.);
                        attrTextRun.setFontFamily("Arial");
                        attrTextRun.setBold(false);
                        attrTextRun.setUnderlined(false);
                        attrTextRun.setFontColor(Color.BLACK);
                        attrTextRun.getTextParagraph().setAlignment(TextAlign.LEFT);
                    }
                    group.addShape(shape);
                }

            } else {
                EdgeWidget edgeWidget = (EdgeWidget) baseElementWidget;

                java.awt.geom.GeneralPath path = new java.awt.geom.GeneralPath();
                Point initPoint = null, moveTo = null;
                for (java.awt.Point point : edgeWidget.getControlPoints()) {
                    if (initPoint == null) {
                        initPoint = point;
                        path.moveTo(point.x, point.y);
                    } else {
                        path.lineTo(point.x, point.y);
                    }
                    moveTo = point;
                }

                HSLFGroupShape group = new HSLFGroupShape();
                slide.addShape(group);

                HSLFFreeformShape shape = new HSLFFreeformShape();
                shape.setPath(path);
                shape.setFillColor(null);
                group.addShape(shape);

                if (edgeWidget instanceof GeneralizationFlowWidget) {
                    byte[] targetAnchor = getImageArray(GENERALIZATION);
                    HSLFPictureData targetPictureData = ppt.addPicture(targetAnchor,
                            PictureData.PictureType.PNG);
                    HSLFPictureShape targetPictureShape = new HSLFPictureShape(targetPictureData);
                    group.addShape(targetPictureShape);
                    targetPictureShape.moveTo(moveTo.x - 6, moveTo.y - 3);
                } else {
                    //source anchor
                    Image sourceAnchorImage = ((IconAnchorShape) edgeWidget.getSourceAnchorShape()).getImage();
                    byte[] sourceAnchor = getImageArray(sourceAnchorImage);
                    HSLFPictureData sourcePictureData = ppt.addPicture(sourceAnchor,
                            PictureData.PictureType.PNG);
                    HSLFPictureShape sourcePictureShape = new HSLFPictureShape(sourcePictureData);
                    group.addShape(sourcePictureShape);
                    sourcePictureShape.moveTo(initPoint.x - 6, initPoint.y - 5);

                    //target anchor
                    Image targetAnchorImage = ((IconAnchorShape) edgeWidget.getTargetAnchorShape()).getImage();
                    byte[] targetAnchor = getImageArray(targetAnchorImage);
                    HSLFPictureData targetPictureData = ppt.addPicture(targetAnchor,
                            PictureData.PictureType.PNG);
                    HSLFPictureShape targetPictureShape = new HSLFPictureShape(targetPictureData);
                    group.addShape(targetPictureShape);
                    targetPictureShape.moveTo(moveTo.x - 6, moveTo.y - 5);
                }
            }
        }
        ppt.setPageSize(new Dimension(width + 20, height + 20));
        FileOutputStream out = new FileOutputStream(file);
        ppt.write(out);
        out.close();
    } catch (IOException ex) {
        scene.getModelerFile().handleException(ex);
    }
}