Example usage for com.lowagie.text Rectangle getHeight

List of usage examples for com.lowagie.text Rectangle getHeight

Introduction

In this page you can find the example usage for com.lowagie.text Rectangle getHeight.

Prototype

public float getHeight() 

Source Link

Document

Returns the height of the rectangle.

Usage

From source file:org.cytoscape.io.internal.write.graphics.PDFWriter.java

License:Open Source License

@Override
public void run(TaskMonitor taskMonitor) throws Exception {
    // TODO should be accomplished with renderer properties
    // view.setPrintingTextAsShape(!exportTextAsFont);

    taskMonitor.setProgress(0.0);//from   w  ww  .j  a  v a2 s .co  m
    taskMonitor.setStatusMessage("Creating PDF image...");

    logger.debug("PDF Rendering start");
    final Rectangle pageSize = PageSize.LETTER;
    final Document document = new Document(pageSize);

    logger.debug("Document created: " + document);

    final PdfWriter writer = PdfWriter.getInstance(document, stream);
    document.open();

    taskMonitor.setProgress(0.1);

    final PdfContentByte canvas = writer.getDirectContent();
    logger.debug("CB0 created: " + canvas.getClass());

    final float pageWidth = pageSize.getWidth();
    final float pageHeight = pageSize.getHeight();

    logger.debug("Page W: " + pageWidth + " Page H: " + pageHeight);
    final DefaultFontMapper fontMapper = new DefaultFontMapper();
    logger.debug("FontMapper created = " + fontMapper);
    Graphics2D g = null;
    logger.debug("!!!!! Enter block 2");

    engine.getProperties().setProperty("exportTextAsShape", new Boolean(!exportTextAsFont).toString());

    taskMonitor.setProgress(0.2);

    if (exportTextAsFont) {
        g = canvas.createGraphics(pageWidth, pageHeight, new DefaultFontMapper());
    } else {
        g = canvas.createGraphicsShapes(pageWidth, pageHeight);
    }

    taskMonitor.setProgress(0.4);

    logger.debug("##### G2D created: " + g);

    double imageScale = Math.min(pageSize.getWidth() / width, pageSize.getHeight() / height);
    g.scale(imageScale, imageScale);

    logger.debug("##### Start Rendering Phase 2: " + engine.toString());
    engine.printCanvas(g);
    logger.debug("##### Canvas Rendering Done: ");

    taskMonitor.setProgress(0.8);

    g.dispose();
    document.close();
    writer.close();

    stream.close();

    logger.debug("PDF rendering finished.");
    taskMonitor.setProgress(1.0);
}

From source file:org.deegree.igeo.commands.VectorPrintCommand.java

License:Open Source License

/**
 * initializes the {@link Document} required for printing using iText
 * //from  w ww . j  a  v a  2s. c o  m
 * @return graphic context ({@link Graphics2D}) of the initialized document
 * @throws FileNotFoundException
 * @throws DocumentException
 */
private Graphics2D initDocument() throws FileNotFoundException, DocumentException {
    String pageFormat = printDefinition.getPageFormat();
    Rectangle pageSize;
    if (pageFormat != null)
        pageSize = PageSize.getRectangle(pageFormat);
    else
        pageSize = new Rectangle(printDefinition.getPageWidth(), printDefinition.getPageHeight());
    LOG.logDebug("page size", pageSize);
    // create (pdf) document with selected pages size; set margin and PDF-version
    document = new Document(pageSize);
    document.setMargins(printDefinition.getAreaLeft(),
            printDefinition.getAreaLeft() + printDefinition.getAreaWidth(), printDefinition.getAreaTop(),
            printDefinition.getAreaTop() + printDefinition.getAreaHeight());

    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(printDefinition.getTargetFile()));
    writer.setPdfVersion(printDefinition.getPdfVersion());
    document.open();
    PdfContentByte cb = writer.getDirectContent();

    // create canvas
    Graphics2D g = cb.createGraphics(convert(pageSize.getWidth() / 72 * 25.4),
            convert(pageSize.getHeight() / 72 * 25.4));
    LOG.logDebug("canvas size",
            convert(pageSize.getWidth() / 72 * 25.4) + " " + convert(pageSize.getHeight() / 72 * 25.4));

    // required for correct scaling of raster symbols
    int i1 = convert(pageSize.getHeight() / 72 * 25.4);
    int i2 = convert_(pageSize.getHeight() / 72 * 25.4);
    g.translate(0, i1 - i2);
    g.scale(72d / printDefinition.getDpi(), 72d / printDefinition.getDpi());
    return g;
}

From source file:org.deegree.igeo.views.swing.print.VectorPrintDialog.java

License:Open Source License

private void initGUI() {
    try {//from  w w  w .j a va 2 s . co  m
        {
            GridBagLayout thisLayout = new GridBagLayout();
            thisLayout.rowWeights = new double[] { 0.0, 0.0 };
            thisLayout.rowHeights = new int[] { 531, 16 };
            thisLayout.columnWeights = new double[] { 0.1, 0.1 };
            thisLayout.columnWidths = new int[] { 7, 20 };
            getContentPane().setLayout(thisLayout);
            {
                pnButtons = new JPanel();
                FlowLayout pnButtonsLayout = new FlowLayout();
                pnButtonsLayout.setAlignment(FlowLayout.LEFT);
                pnButtons.setLayout(pnButtonsLayout);
                getContentPane().add(pnButtons, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
                        GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
                {
                    btPrint = new JButton(Messages.getMessage(getLocale(), "$MD11785"),
                            IconRegistry.getIcon("accept.png"));
                    pnButtons.add(btPrint);
                    btPrint.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent event) {
                            if (tfOutputFile.getText().trim().length() < 3) {
                                DialogFactory.openWarningDialog(appContainer.getViewPlatform(),
                                        VectorPrintDialog.this, Messages.get("$MD11817"),
                                        Messages.get("$MD11818"));
                            } else {
                                doPrint();
                            }
                        }
                    });
                }
                {
                    btCancel = new JButton(Messages.getMessage(getLocale(), "$MD11786"),
                            IconRegistry.getIcon("cancel.png"));
                    btCancel.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            VectorPrintDialog.this.dispose();
                        }
                    });
                    pnButtons.add(btCancel);

                }
            }
            {
                pnHelp = new JPanel();
                FlowLayout pnHelpLayout = new FlowLayout();
                pnHelpLayout.setAlignment(FlowLayout.RIGHT);
                pnHelp.setLayout(pnHelpLayout);
                getContentPane().add(pnHelp, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,
                        GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
                {
                    btHelp = new JButton(Messages.getMessage(getLocale(), "$MD11787"),
                            IconRegistry.getIcon("help.png"));
                    pnHelp.add(btHelp);
                    btHelp.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            HelpFrame hf = HelpFrame.getInstance(new HelpManager(appContainer));
                            hf.setVisible(true);
                            hf.gotoModule("Print");
                        }
                    });
                }
            }
            {
                pnPrint = new JPanel();
                GridBagLayout pnPrintLayout = new GridBagLayout();
                getContentPane().add(pnPrint, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0,
                        GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
                pnPrint.setBorder(
                        BorderFactory.createTitledBorder(Messages.getMessage(getLocale(), "$MD11788")));
                pnPrintLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.1 };
                pnPrintLayout.rowHeights = new int[] { 78, 111, 126, 65, 60, 7 };
                pnPrintLayout.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.1 };
                pnPrintLayout.columnWidths = new int[] { 117, 158, 151, 7 };
                pnPrint.setLayout(pnPrintLayout);
                {
                    pnPreview = new PreviewPanel();
                    pnPreview.setLayout(new BorderLayout());
                    pnPrint.add(pnPreview, new GridBagConstraints(0, 0, 2, 3, 0.0, 0.0,
                            GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
                    pnPreview.setBorder(
                            BorderFactory.createTitledBorder(Messages.getMessage(getLocale(), "$MD11789")));
                    {
                        lbPageSize = new JLabel();
                        pnPreview.add(lbPageSize, BorderLayout.SOUTH);
                        lbPageSize.setText(Messages.getMessage(getLocale(), "$MD11790"));
                    }
                }
                {
                    pnFile = new JPanel();
                    FlowLayout pnFileLayout = new FlowLayout();
                    pnFileLayout.setAlignment(FlowLayout.LEFT);
                    pnFile.setLayout(pnFileLayout);
                    pnPrint.add(pnFile, new GridBagConstraints(0, 5, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                            GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
                    pnFile.setBorder(
                            BorderFactory.createTitledBorder(Messages.getMessage(getLocale(), "$MD11791")));
                    {
                        btLoad = new JButton(Messages.getMessage(getLocale(), "$MD11792"),
                                IconRegistry.getIcon("open.gif"));
                        pnFile.add(btLoad);
                        btLoad.addActionListener(new ActionListener() {

                            public void actionPerformed(ActionEvent event) {
                                doLoadSettings();
                            }
                        });
                    }
                    {
                        btSave = new JButton(Messages.getMessage(getLocale(), "$MD11793"),
                                IconRegistry.getIcon("save.gif"));
                        pnFile.add(btSave);
                        btSave.addActionListener(new ActionListener() {

                            public void actionPerformed(ActionEvent event) {
                                doSaveSettings();
                            }
                        });
                    }
                }
                {
                    pnLayoutPosition = new JPanel();
                    GridBagLayout pnLayoutPositionLayout = new GridBagLayout();
                    pnLayoutPositionLayout.rowWeights = new double[] { 0.0, 0.1, 0.1, 0.1 };
                    pnLayoutPositionLayout.rowHeights = new int[] { 39, 7, 7, 7 };
                    pnLayoutPositionLayout.columnWeights = new double[] { 0.0, 0.0, 0.1 };
                    pnLayoutPositionLayout.columnWidths = new int[] { 69, 95, 7 };
                    pnLayoutPosition.setLayout(pnLayoutPositionLayout);
                    pnPrint.add(pnLayoutPosition, new GridBagConstraints(2, 0, 2, 2, 0.0, 0.0,
                            GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
                    pnLayoutPosition.setBorder(
                            BorderFactory.createTitledBorder(Messages.getMessage(getLocale(), "$MD11848")));
                    {
                        lb1 = new JLabel(Messages.getMessage(getLocale(), "$MD11794"));
                        pnLayoutPosition.add(lb1,
                                new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 0), 0, 0));
                    }
                    {
                        lb2 = new JLabel(Messages.getMessage(getLocale(), "$MD11794"));
                        pnLayoutPosition.add(lb2,
                                new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 0), 0, 0));
                    }
                    {
                        lb3 = new JLabel(Messages.getMessage(getLocale(), "$MD11794"));
                        pnLayoutPosition.add(lb3,
                                new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 0), 0, 0));
                    }
                    {
                        lb4 = new JLabel(Messages.getMessage(getLocale(), "$MD11794"));
                        pnLayoutPosition.add(lb4,
                                new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 0), 0, 0));
                    }
                    {
                        spLeft = new JSpinner(new SpinnerNumberModel(20, 0, 100000, 1));
                        pnLayoutPosition.add(spLeft,
                                new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
                        spLeft.addChangeListener(printSizeListener);
                    }
                    {
                        spTop = new JSpinner(new SpinnerNumberModel(20, 0, 100000, 1));
                        pnLayoutPosition.add(spTop,
                                new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
                        spTop.addChangeListener(printSizeListener);
                    }
                    {
                        spWidth = new JSpinner(new SpinnerNumberModel(150, 10, 100000, 1));
                        pnLayoutPosition.add(spWidth,
                                new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
                        spWidth.addChangeListener(printSizeListener);
                    }
                    {
                        spHeight = new JSpinner(new SpinnerNumberModel(200, 10, 100000, 1));
                        pnLayoutPosition.add(spHeight,
                                new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
                        spHeight.addChangeListener(printSizeListener);
                    }
                    {
                        lbLeft = new JLabel(Messages.getMessage(getLocale(), "$MD11795"));
                        pnLayoutPosition.add(lbLeft,
                                new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 0), 0, 0));
                    }
                    {
                        lbTop = new JLabel(Messages.getMessage(getLocale(), "$MD11796"));
                        pnLayoutPosition.add(lbTop,
                                new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 0), 0, 0));
                    }
                    {
                        lbWidth = new JLabel(Messages.getMessage(getLocale(), "$MD11797"));
                        pnLayoutPosition.add(lbWidth,
                                new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 0), 0, 0));
                    }
                    {
                        lbHeight = new JLabel(Messages.getMessage(getLocale(), "$MD11798"));
                        pnLayoutPosition.add(lbHeight,
                                new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 0), 0, 0));
                    }
                }
                {
                    pnMapCoord = new JPanel();
                    GridBagLayout pnMapCoordLayout = new GridBagLayout();
                    pnPrint.add(pnMapCoord, new GridBagConstraints(2, 2, 2, 1, 0.0, 0.0,
                            GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
                    pnMapCoord.setBorder(
                            BorderFactory.createTitledBorder(Messages.getMessage(getLocale(), "$MD11799")));
                    pnMapCoordLayout.rowWeights = new double[] { 0.1, 0.1 };
                    pnMapCoordLayout.rowHeights = new int[] { 7, 7 };
                    pnMapCoordLayout.columnWeights = new double[] { 0.0, 0.1, 0.1 };
                    pnMapCoordLayout.columnWidths = new int[] { 68, 7, 7 };
                    pnMapCoord.setLayout(pnMapCoordLayout);
                    {
                        lbMapLeft = new JLabel(Messages.getMessage(getLocale(), "$MD11800"));
                        pnMapCoord.add(lbMapLeft,
                                new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 0), 0, 0));
                    }
                    {
                        lbMapBottom = new JLabel(Messages.getMessage(getLocale(), "$MD11801"));
                        pnMapCoord.add(lbMapBottom,
                                new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 0), 0, 0));
                    }
                    {
                        spMapLeft = new JSpinner(new SpinnerNumberModel(0, -9E9, 9E9, 0.5));
                        spMapLeft.setValue(mapModel.getEnvelope().getMin().getX());
                        pnMapCoord.add(spMapLeft,
                                new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 9), 0, 0));
                        spMapLeft.addChangeListener(printSizeListener);
                    }
                    {
                        spMapBottom = new JSpinner(new SpinnerNumberModel(0, -9E9, 9E9, 0.5));
                        spMapBottom.setValue(mapModel.getEnvelope().getMin().getY());
                        pnMapCoord.add(spMapBottom,
                                new GridBagConstraints(1, 1, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 9), 0, 0));
                        spMapBottom.addChangeListener(printSizeListener);
                    }
                }
                {
                    pnScale = new JPanel();
                    GridBagLayout pnScaleLayout = new GridBagLayout();
                    pnPrint.add(pnScale, new GridBagConstraints(2, 3, 2, 2, 0.0, 0.0, GridBagConstraints.CENTER,
                            GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
                    pnScale.setBorder(
                            BorderFactory.createTitledBorder(Messages.getMessage(getLocale(), "$MD11802")));
                    pnScaleLayout.rowWeights = new double[] { 0.1, 0.1 };
                    pnScaleLayout.rowHeights = new int[] { 7, 7 };
                    pnScaleLayout.columnWeights = new double[] { 0.1, 0.1 };
                    pnScaleLayout.columnWidths = new int[] { 7, 7 };
                    pnScale.setLayout(pnScaleLayout);
                    {
                        rbConst = new JRadioButton(Messages.getMessage(getLocale(), "$MD11803"));
                        pnScale.add(rbConst,
                                new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 0), 0, 0));
                        rbConst.setSelected(true);
                        bg.add(rbConst);
                    }
                    {
                        rbVariable = new JRadioButton(Messages.getMessage(getLocale(), "$MD11804"));
                        pnScale.add(rbVariable,
                                new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 0), 0, 0));
                        bg.add(rbVariable);
                    }
                    {
                        int[] sc = StringTools.toArrayInt(Messages.getMessage(getLocale(), "$MD11805"), ",; ");
                        ListEntry[] le = new ListEntry[sc.length];
                        for (int i = 0; i < sc.length; i++) {
                            le[i] = new ListEntry("1:" + sc[i], sc[i]);
                        }
                        cbScale = new JComboBox(new DefaultComboBoxModel(le));
                        cbScale.setSelectedIndex(6);
                        pnScale.add(cbScale,
                                new GridBagConstraints(0, 1, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 9), 0, 0));
                        cbScale.setEditable(true);
                        cbScale.addActionListener(new ActionListener() {

                            public void actionPerformed(ActionEvent e) {
                                Object o = cbScale.getSelectedItem();
                                if (o instanceof String) {
                                    try {
                                        // handle use defined scales
                                        ListEntry le = null;
                                        if (((String) o).indexOf(":") > 0) {
                                            String[] t = StringTools.toArray((String) o, ":", false);
                                            le = new ListEntry((String) o, Integer.parseInt(t[1].trim()));
                                        } else {
                                            le = new ListEntry("1:" + o, Integer.parseInt((String) o));
                                        }
                                        ((DefaultComboBoxModel) cbScale.getModel()).addElement(le);
                                        cbScale.setSelectedItem(le);
                                    } catch (Exception ex) {
                                        DialogFactory.openWarningDialog(appContainer.getViewPlatform(),
                                                VectorPrintDialog.this, Messages.get("$MD11821"),
                                                Messages.get("$MD11822"));
                                        return;
                                    }
                                }
                                updatePreview();
                            }
                        });
                    }
                }
                {
                    pnFormat = new JPanel();
                    GridBagLayout pnFormatLayout = new GridBagLayout();
                    pnPrint.add(pnFormat, new GridBagConstraints(0, 3, 2, 1, 0.0, 0.0,
                            GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
                    pnFormat.setBorder(
                            BorderFactory.createTitledBorder(Messages.getMessage(getLocale(), "$MD11806")));
                    pnFormatLayout.rowWeights = new double[] { 0.1 };
                    pnFormatLayout.rowHeights = new int[] { 7 };
                    pnFormatLayout.columnWeights = new double[] { 0.1 };
                    pnFormatLayout.columnWidths = new int[] { 7 };
                    pnFormat.setLayout(pnFormatLayout);
                    {
                        String[] tmp = StringTools.toArray(Messages.getMessage(getLocale(), "$MD11807"), ",;",
                                true);
                        ListEntry[] le = new ListEntry[tmp.length / 2 + 1];
                        le[0] = new ListEntry(Messages.getMessage(getLocale(), "$MD11829"), null);
                        for (int i = 0; i < tmp.length; i += 2) {
                            le[i / 2 + 1] = new ListEntry(tmp[i], tmp[i + 1]);
                        }
                        cbPageFormat = new JComboBox(new DefaultComboBoxModel(le));
                        cbPageFormat.setSelectedIndex(2);

                        pnFormat.add(cbPageFormat,
                                new GridBagConstraints(0, 0, 3, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 9), 0, 0));

                        // width
                        lbPageWidth = new JLabel(Messages.getMessage(getLocale(), "$MD11831"));
                        pnFormat.add(lbPageWidth,
                                new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 15, 0, 0), 0, 0));
                        tfPageWidth = new JSpinner(
                                new SpinnerNumberModel(inMM(PageSize.A4.getWidth()), 0, 6080, 1));
                        pnFormat.add(tfPageWidth,
                                new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 0), 0, 0));

                        tfPageWidth.setEnabled(false);
                        lbPageUnitW = new JLabel(Messages.getMessage(getLocale(), "$MD11832"));
                        pnFormat.add(lbPageUnitW,
                                new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 15), 0, 0));

                        // height
                        lbPageHeight = new JLabel(Messages.getMessage(getLocale(), "$MD11830"));
                        pnFormat.add(lbPageHeight,
                                new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 15, 0, 0), 0, 0));
                        tfPageHeight = new JSpinner(
                                new SpinnerNumberModel(inMM(PageSize.A4.getHeight()), 0, 6080, 1));
                        pnFormat.add(tfPageHeight,
                                new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 0), 0, 0));
                        tfPageHeight.setEnabled(false);
                        lbPageUnitH = new JLabel(Messages.getMessage(getLocale(), "$MD11832"));
                        pnFormat.add(lbPageUnitH,
                                new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 15), 0, 0));

                        cbPageFormat.addActionListener(new ActionListener() {

                            public void actionPerformed(ActionEvent e) {

                                int width;
                                int height;
                                ListEntry le = (ListEntry) ((JComboBox) e.getSource()).getSelectedItem();
                                if (le.value != null) {
                                    String value = (String) le.value;
                                    Rectangle rect = PageSize.getRectangle(value);
                                    width = (int) Math.round(rect.getWidth() / 72 * 25.4);
                                    height = (int) Math.round(rect.getHeight() / 72 * 25.4);
                                    tfPageWidth.setEnabled(false);
                                    tfPageHeight.setEnabled(false);
                                } else {
                                    tfPageWidth.setEnabled(true);
                                    tfPageHeight.setEnabled(true);
                                    width = ((Number) tfPageWidth.getValue()).intValue();
                                    height = ((Number) tfPageHeight.getValue()).intValue();
                                }
                                // if page format has been changed max size of printed map must be changed
                                // for new map size (millimeter) left and top border must be considered to
                                // ensure that printed map does not overlap paper at the right and at the bottom

                                width -= (((Number) spLeft.getValue()).intValue() * 2);
                                height -= (((Number) spTop.getValue()).intValue() * 2);
                                spWidth.setValue(width);
                                spHeight.setValue(height);
                                // preview of printed area must be updated
                                updatePreview();
                            }
                        });
                    }
                }
                {
                    pnDPI = new JPanel();
                    GridBagLayout pnDPILayout = new GridBagLayout();
                    pnPrint.add(pnDPI, new GridBagConstraints(0, 4, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                            GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
                    pnDPI.setBorder(
                            BorderFactory.createTitledBorder(Messages.getMessage(getLocale(), "$MD11808")));
                    pnDPILayout.rowWeights = new double[] { 0.1 };
                    pnDPILayout.rowHeights = new int[] { 7 };
                    pnDPILayout.columnWeights = new double[] { 0.1 };
                    pnDPILayout.columnWidths = new int[] { 7 };
                    pnDPI.setLayout(pnDPILayout);
                    {
                        final DefaultComboBoxModel cbDPIModel = new DefaultComboBoxModel(
                                new Integer[] { 72, 96, 150, 300, 600, 1200, 2400 });
                        cbDPI = new JComboBox();
                        pnDPI.add(cbDPI, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 9), 0, 0));
                        cbDPI.setModel(cbDPIModel);
                        cbDPI.setEditable(true);
                        cbDPI.addActionListener(new ActionListener() {

                            public void actionPerformed(ActionEvent e) {
                                Object o = cbDPI.getSelectedItem();
                                if (o instanceof String) {
                                    try {
                                        Integer i = Integer.parseInt(o.toString());
                                        cbDPIModel.addElement(i);
                                        cbDPI.setSelectedItem(i);
                                    } catch (Exception ex) {
                                        DialogFactory.openWarningDialog(appContainer.getViewPlatform(),
                                                VectorPrintDialog.this, Messages.get("$MD11819"),
                                                Messages.get("$MD11820"));
                                    }
                                }
                            }
                        });
                    }
                }
                {
                    pnOutput = new JPanel();
                    GridBagLayout pnOutputLayout = new GridBagLayout();
                    pnOutputLayout.rowWeights = new double[] { 0.1 };
                    pnOutputLayout.rowHeights = new int[] { 7 };
                    pnOutputLayout.columnWeights = new double[] { 0.1, 0.0, 0.1 };
                    pnOutputLayout.columnWidths = new int[] { 7, 94, 7 };
                    pnOutput.setLayout(pnOutputLayout);
                    pnPrint.add(pnOutput, new GridBagConstraints(2, 5, 2, 1, 0.0, 0.0,
                            GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
                    pnOutput.setBorder(
                            BorderFactory.createTitledBorder(Messages.getMessage(getLocale(), "$MD11809")));
                    {
                        btOutputFile = new JButton(Messages.get("$MD11823"));
                        btOutputFile.addActionListener(new ActionListener() {

                            public void actionPerformed(ActionEvent e) {
                                Preferences prefs = Preferences.userNodeForPackage(VectorPrintDialog.class);
                                File file = GenericFileChooser.showSaveDialog(FILECHOOSERTYPE.externalResource,
                                        appContainer, VectorPrintDialog.this, prefs, "print definition",
                                        IGeoFileFilter.PDF);
                                tfOutputFile.setText(file.getAbsolutePath());
                            }
                        });
                        pnOutput.add(btOutputFile,
                                new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 9), 0, 0));
                    }
                    {
                        tfOutputFile = new JTextField();
                        pnOutput.add(tfOutputFile,
                                new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                                        GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 0), 0, 0));
                    }
                }
            }
        }
        pnPreview.setAreaLeft(((Number) spLeft.getValue()).intValue());
        pnPreview.setAreaTop(((Number) spTop.getValue()).intValue());
        pnPreview.setAreaWidth(((Number) spWidth.getValue()).intValue());
        pnPreview.setAreaHeight(((Number) spHeight.getValue()).intValue());
        Rectangle rect;
        ListEntry le = (ListEntry) cbPageFormat.getSelectedItem();
        if (le.value != null) {
            rect = PageSize.getRectangle((String) le.value);
        } else {
            rect = new Rectangle(inPt(((Number) tfPageWidth.getValue()).intValue()),
                    inPt(((Number) tfPageHeight.getValue()).intValue()));
        }
        pnPreview.setPageSize(rect);
        this.setBounds(300, 200, 530, 609);
    } catch (Exception e) {
        e.printStackTrace();
    }

    DefaultMapModule<Container> mapModule = getAssignedMapModule();
    final Container jco = mapModule.getMapContainer();
    jco.addMouseListener(ml);
    jco.addMouseMotionListener(mml);
    isActive = true;
    final MapTool<Container> mapTool = mapModule.getMapTool();
    mapTool.addChangeListener(this);

    addWindowFocusListener(new WindowFocusListener() {

        @Override
        public void windowLostFocus(WindowEvent e) {
        }

        @Override
        public void windowGainedFocus(WindowEvent e) {
            mapTool.resetState();
            // it is required to add the listeners again, cause it seems some other module removes all...
            jco.addMouseListener(ml);
            jco.addMouseMotionListener(mml);
            isActive = true;
        }
    });
}

From source file:org.deegree.igeo.views.swing.print.VectorPrintDialog.java

License:Open Source License

private void updatePreview() {
    if (isVisible()) {
        movePreviewRectangle();//from  w ww. j av  a  2  s .c o m

        Rectangle r;
        int pw;
        int ph;
        ListEntry le = (ListEntry) cbPageFormat.getSelectedItem();
        if (le.value != null) {
            tfPageWidth.setEnabled(false);
            tfPageHeight.setEnabled(false);
            r = PageSize.getRectangle((String) le.value);
            pw = (int) Math.round(r.getWidth() / 72 * 25.4);
            ph = (int) Math.round(r.getHeight() / 72 * 25.4);
        } else {
            tfPageWidth.setEnabled(true);
            tfPageHeight.setEnabled(true);
            pw = ((Number) tfPageWidth.getValue()).intValue();
            ph = ((Number) tfPageHeight.getValue()).intValue();
            r = new Rectangle(inPt(pw), inPt(ph));
        }

        lbPageSize.setText(Messages.getMessage(getLocale(), "$MD11816", pw, ph));
        pnPreview.setAreaLeft(((Number) spLeft.getValue()).intValue());
        pnPreview.setAreaTop(((Number) spTop.getValue()).intValue());
        pnPreview.setAreaWidth(((Number) spWidth.getValue()).intValue());
        pnPreview.setAreaHeight(((Number) spHeight.getValue()).intValue());
        pnPreview.setPageSize(r);
        pnPreview.repaint();
    }
}

From source file:org.drools.verifier.doc.DroolsDocsComponentFactory.java

License:Apache License

public void onEndPage(PdfWriter writer, Document document) {

    try {//  w  w  w. ja v a 2s.c  o  m
        Image image = Image.getInstance(DroolsDocsBuilder.class.getResource("guvnor-webapp.png")); // TODO this image never existed
        image.setAlignment(Image.RIGHT);
        image.scaleAbsolute(100, 30);
        Rectangle page = document.getPageSize();
        PdfPTable head = new PdfPTable(2);

        PdfPCell cell1 = new PdfPCell(image);
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell1.setBorder(0);

        head.addCell(cell1);

        PdfPCell cell2 = new PdfPCell(new Phrase(currentDate, DroolsDocsComponentFactory.HEADER_FOOTER_TEXT));
        cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell2.setBorder(0);

        head.addCell(cell2);

        head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
        head.writeSelectedRows(0, -1, document.leftMargin(),
                page.getHeight() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent());

    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}

From source file:org.efaps.esjp.common.file.FileUtil_Base.java

License:Apache License

/**
 * N up.//from  www  .j a va  2 s. c om
 *
 * @param _parameter Parameter as passed by the eFaps API
 * @param _file the file
 * @param _fileName the file name
 * @return the file
 * @throws EFapsException on error
 */
public File nUpPdf(final Parameter _parameter, final File _file, final String _fileName) throws EFapsException {
    final File ret = getFile(_fileName, "pdf");
    try {
        final int pow = Integer.parseInt(getProperty(_parameter, "NUpPow", "1"));
        final boolean duplicate = "true".equalsIgnoreCase(getProperty(_parameter, "NUpDuplicate", "true"));
        final File destFile = new File(_file.getPath() + ".tmp");
        FileUtils.copyFile(_file, destFile);
        final OutputStream outputStream = new FileOutputStream(ret);
        final PdfReader pdfReader = new PdfReader(new FileInputStream(destFile));

        final Rectangle pageSize = pdfReader.getPageSize(1);

        final Rectangle newSize = pow % 2 == 0 ? new Rectangle(pageSize.getWidth(), pageSize.getHeight())
                : new Rectangle(pageSize.getHeight(), pageSize.getWidth());

        Rectangle unitSize = new Rectangle(pageSize.getWidth(), pageSize.getHeight());

        for (int i = 0; i < pow; i++) {
            unitSize = new Rectangle(unitSize.getHeight() / 2, unitSize.getWidth());
        }

        final int n = (int) Math.pow(2, pow);
        final int r = (int) Math.pow(2, pow / 2);
        final int c = n / r;

        final Document document = new Document(newSize, 0, 0, 0, 0);

        // Create a writer for the outputstream
        final PdfWriter writer = PdfWriter.getInstance(document, outputStream);
        document.open();
        PdfImportedPage page;
        final PdfContentByte cb = writer.getDirectContent();
        // Create a new page in the target for each source page.
        Rectangle currentSize;
        float offsetX;
        float offsetY;
        float factor;

        final int total = pdfReader.getNumberOfPages();
        for (int i = 0; i < total;) {
            if (i % n == 0) {
                document.newPage();
            }
            currentSize = pdfReader.getPageSize(++i);

            factor = Math.min(unitSize.getWidth() / currentSize.getWidth(),
                    unitSize.getHeight() / currentSize.getHeight());
            offsetX = unitSize.getWidth() * (i % n % c)
                    + (unitSize.getWidth() - currentSize.getWidth() * factor) / 2f;
            offsetY = newSize.getHeight() - (unitSize.getHeight() * (i % n % c) + 1)
                    + (unitSize.getHeight() - currentSize.getHeight() * factor) / 2f;

            page = writer.getImportedPage(pdfReader, i);

            cb.addTemplate(page, factor, 0, 0, factor, offsetX, offsetY);

            if (duplicate) {
                for (int y = i + 1; y <= pow + 1; y++) {
                    factor = Math.min(unitSize.getWidth() / currentSize.getWidth(),
                            unitSize.getHeight() / currentSize.getHeight());
                    offsetX = unitSize.getWidth() * (y % n % c)
                            + (unitSize.getWidth() - currentSize.getWidth() * factor) / 2f;
                    offsetY = newSize.getHeight() - unitSize.getHeight() * (y % n / c + 1)
                            + (unitSize.getHeight() - currentSize.getHeight() * factor) / 2f;
                    cb.addTemplate(page, factor, 0, 0, factor, offsetX, offsetY);
                }
            }
        }
        outputStream.flush();
        document.close();
        outputStream.close();
    } catch (final FileNotFoundException e) {
        LOG.error("FileNotFoundException", e);
    } catch (final IOException e) {
        LOG.error("IOException", e);
    } catch (final DocumentException e) {
        LOG.error("DocumentException", e);
    }
    return ret;
}

From source file:org.geomajas.plugin.print.command.print.LayoutAsSinglePageDoc.java

License:Open Source License

private static float getPageSizeRelativeToA3(PrintGetTemplateExtRequest request) {
    Rectangle r;
    if (request.getPageSize() != null) {
        r = PageSize.getRectangle(request.getPageSize());
    } else if (request.getTemplate().getPage().getLayoutConstraint().getWidth() > 0
            && request.getTemplate().getPage().getLayoutConstraint().getHeight() > 0) {
        float width = request.getTemplate().getPage().getLayoutConstraint().getWidth();
        float height = request.getTemplate().getPage().getLayoutConstraint().getHeight();
        r = new Rectangle(0, 0, width, height);
    } else {//from w w  w  . j ava 2 s. c  om
        return 1.0f;
    }
    return (r.getWidth() / PageSize.A3.getWidth() + r.getHeight() / PageSize.A3.getHeight()) / 2;
}

From source file:org.geomajas.plugin.print.component.impl.LabelComponentImpl.java

License:Open Source License

@Override
public void calculateSize(PdfContext context) {
    assert (null != getText()) : "getText() must be non-null";

    if (getMaxWidthText() > 0.0) {
        limitTextWidth(context, getMaxWidthText());
    }/*from ww w  .j a v a 2s .  c o m*/
    Rectangle textSize = context.getTextSize(getText(), getFont());

    float margin = getMargin(); // Get the specified value
    if (margin <= 0.0f) {
        margin = 0.5f * getFont().getSize();
    }
    float width = textSize.getWidth() + 2.0f * margin;
    float height = textSize.getHeight() + 2.0f * margin;

    if (null != getConstraint()) {
        if (getConstraint().getWidth() > 0.0f) {
            width = getConstraint().getWidth();
        }
        if (getConstraint().getHeight() > 0.0f) {
            height = getConstraint().getHeight();
        }
    }
    setBounds(new Rectangle(width, height));
}

From source file:org.geomajas.plugin.print.component.impl.LegendGraphicComponentImpl.java

License:Open Source License

@SuppressWarnings("deprecation")
@Override//  w  w w.  j  av  a2  s  .  c  om
public void calculateSize(PdfContext context) {
    LegendComponent legendComponent = getLegend();
    assert (null != legendComponent) : "LegendGraphicComponent must be an instance of LegendComponent";
    assert (null != legendComponent
            .getFont()) : "LegendGraphicComponent must be an instance of LegendComponent";

    Rectangle textSize = context.getTextSize(label, legendComponent.getFont());
    float margin = 0.25f * legendComponent.getFont().getSize();
    getConstraint().setMarginX(margin);
    getConstraint().setMarginY(margin);
    setBounds(new Rectangle(textSize.getHeight(), textSize.getHeight()));
}

From source file:org.geomajas.plugin.print.component.impl.LegendIconComponentImpl.java

License:Open Source License

@SuppressWarnings("deprecation")
@Override/*  ww w.j a va  2  s .  c  o m*/
public void calculateSize(PdfContext context) {
    LegendComponent legendComponent = getLegend();
    assert (null != legendComponent) : "LegendGraphicComponent must be a descendant of a LegendComponent";

    Rectangle textSize = context.getTextSize(label, legendComponent.getFont());
    float margin = 0.25f * legendComponent.getFont().getSize();
    if (getConstraint().getMarginX() <= 0.0) {
        getConstraint().setMarginX(margin);
    }
    if (getConstraint().getMarginY() <= 0.0) {
        getConstraint().setMarginY(margin);
    }
    setBounds(new Rectangle(textSize.getHeight(), textSize.getHeight()));
}