Example usage for com.lowagie.text Rectangle Rectangle

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

Introduction

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

Prototype

public Rectangle(float urx, float ury) 

Source Link

Document

Constructs a Rectangle -object starting from the origin (0, 0).

Usage

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

License:Open Source License

private void initGUI() {
    try {//from w  w w . java2 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();//w w  w .ja  v  a 2s  . 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.eclipse.birt.report.engine.emitter.pdf.PDFPage.java

License:Open Source License

public PDFPage(int pageWidth, int pageHeight, Document document, PdfWriter writer, PDFPageDevice pageDevice) {
    super(pageWidth, pageHeight);
    this.writer = writer;
    this.pageDevice = pageDevice;
    this.containerHeight = this.pageHeight;
    Rectangle pageSize = new Rectangle(this.pageWidth, this.pageHeight);
    document.setPageSize(pageSize);// ww  w. j a v  a  2s. co  m
    if (!document.isOpen())
        document.open();
    else
        document.newPage();
    this.contentByte = writer.getDirectContent();
}

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

License:Apache License

/**
 * N up.//from  ww w.j av  a 2 s  . c  o  m
 *
 * @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.encog.workbench.util.graph.DocumentPDF.java

License:Apache License

public static void writeChartAsPDF(OutputStream out, JFreeChart chart, int width, int height, FontMapper mapper)
        throws IOException {
    Rectangle pagesize = new Rectangle(width, height);
    Document document = new Document(pagesize, 50, 50, 50, 50);
    try {/*  ww w  .j av  a 2s  .  co m*/
        PdfWriter writer = PdfWriter.getInstance(document, out);
        document.addAuthor("JFreeChart");
        document.addSubject("Demonstration");
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        PdfTemplate tp = cb.createTemplate(width, height);
        Graphics2D g2 = tp.createGraphics(width, height, mapper);
        Rectangle2D r2D = new Rectangle2D.Double(0, 0, width, height);
        chart.draw(g2, r2D);
        g2.dispose();
        cb.addTemplate(tp, 0, 0);
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    }
}

From source file:org.encog.workbench.util.graph.DocumentPDF.java

License:Apache License

public static void savePDF(File filename, JFreeChart chart, int width, int height) {
    try {//from  w ww.  j  a  v  a 2 s .c  om
        // step 1
        Document document = new Document(new Rectangle(width, height));
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
        // step 3
        document.open();
        // step 4
        PdfContentByte canvas = writer.getDirectContent();
        Graphics2D g2 = canvas.createGraphics(width, height);
        Rectangle2D area = new Rectangle2D.Double(0, 0, width, height);
        chart.draw(g2, area);
        g2.dispose();
        // step 5
        document.close();
    } catch (DocumentException ex) {
        throw new WorkBenchError(ex);
    } catch (IOException ex) {
        throw new WorkBenchError(ex);
    }

}

From source file:org.forester.archaeopteryx.PdfExporter.java

License:Open Source License

static String writePhylogenyToPdf(final String file_name, final TreePanel tree_panel, int width, int height)
        throws IOException {
    if (height < HEIGHT_LIMIT) {
        height = HEIGHT_LIMIT;//from ww w.j  a v  a2s  . c om
    }
    if (width < WIDTH_LIMIT) {
        width = WIDTH_LIMIT;
    }
    final Phylogeny phylogeny = tree_panel.getPhylogeny();
    if ((phylogeny == null) || phylogeny.isEmpty()) {
        return "";
    }
    if (tree_panel.getMainPanel().getTreeFontSet().getSmallFont().getSize() < 1) {
        throw new IOException("fonts are too small for PDF export");
    }
    final File file = new File(file_name);
    if (file.isDirectory()) {
        throw new IOException("[" + file_name + "] is a directory");
    }
    final Document document = new Document();
    document.setPageSize(new Rectangle(width, height));
    document.setMargins(WIDTH_LIMIT / 2, WIDTH_LIMIT / 2, HEIGHT_LIMIT / 2, HEIGHT_LIMIT / 2);
    PdfWriter writer = null;
    try {
        writer = PdfWriter.getInstance(document, new FileOutputStream(file_name));
    } catch (final DocumentException e) {
        throw new IOException(e);
    }
    document.open();
    final DefaultFontMapper mapper = new DefaultFontMapper();
    FontFactory.registerDirectories();
    if (Util.isWindows()) {
        mapper.insertDirectory("C:\\WINDOWS\\Fonts\\");
    } else if (Util.isMac()) {
        mapper.insertDirectory("/Library/Fonts/");
        mapper.insertDirectory("/System/Library/Fonts/");
    } else {
        mapper.insertDirectory("/usr/X/lib/X11/fonts/TrueType/");
        mapper.insertDirectory("/usr/X/lib/X11/fonts/Type1/");
        mapper.insertDirectory("/usr/share/fonts/default/TrueType/");
        mapper.insertDirectory("/usr/share/fonts/default/Type1/");
    }
    final PdfContentByte cb = writer.getDirectContent();
    final Graphics2D g2 = cb.createGraphics(width, height, mapper);
    try {
        tree_panel.paintPhylogeny(g2, true, false, width - WIDTH_LIMIT, height - HEIGHT_LIMIT, 0, 0);
    } catch (final Exception e) {
        Util.unexpectedException(e);
    } finally {
        try {
            g2.dispose();
            document.close();
        } catch (final Exception e) {
            //Do nothing.
        }
    }
    String msg = file.toString();
    if ((width > 0) && (height > 0)) {
        msg += " [size: " + width + ", " + height + "]";
    }
    return msg;
}

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

License:Open Source License

@Override
public void calculateSize(PdfContext context) {
    @SuppressWarnings("deprecation")
    float width = getConstraint().getWidth();
    @SuppressWarnings("deprecation")
    float height = getConstraint().getHeight();
    image = context.getImage(getImagePath());
    if (width == 0 && height == 0) {
        width = image.getWidth();/*from  ww w.j  a  v a2s.  c  o m*/
        height = image.getHeight();
    } else if (width == 0) {
        width = image.getWidth() / image.getHeight() * height;
    } else if (height == 0) {
        height = image.getHeight() / image.getWidth() * width;
    }
    setBounds(new Rectangle(width, height));
}

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());
    }//  w ww .  java  2s.  co  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.LegendForLayerComponentImpl.java

License:Open Source License

@SuppressWarnings("deprecation")
@Override//from  ww  w . j a  v a 2 s. com
public void calculateSize(PdfContext context) {
    float marginX = -1.0f;
    LegendViaUrlComponent legendViaUrlComponent = null;

    for (PrintComponent<?> child : children) {
        if (marginX < 0f && child instanceof LabelComponent && null != child.getConstraint()) {
            marginX = child.getConstraint().getMarginX();
        } else if (child instanceof LegendViaUrlComponent) {
            legendViaUrlComponent = (LegendViaUrlComponent) child;
        }
    }
    if (marginX >= 0) {
        for (PrintComponent<?> child : children) {
            assert (child instanceof LabelComponent || null != child
                    .getConstraint()) : "For Non-label children of LegendForLayerComponent getConstraint() must be non-null";
            // This is required because its difficult to create a constraint instance here
            if (!(child instanceof LabelComponent) && (null != child.getConstraint())) {
                // Set the left margin (marginX) of the item in the legend (e.g an image
                // presenting the legend symbols of the concerning layer)

                if (child.getConstraint().getMarginX() <= 0) {
                    child.getConstraint().setMarginX(marginX * 1.5F); // 1.5 times the margin
                } // of the title (usually the layers label)
            }

        }
    }
    super.calculateSize(context);

    if (null != legendViaUrlComponent && !legendViaUrlComponent.isVisible()) {
        // Force zero-sized bounds for this component (layer title + legend graphic are not shown)
        setBounds(new Rectangle(0, 0));
        visible = false;
    }
}