Package javax.swing

Examples of javax.swing.SpringLayout$SpringProxy


     */
    public static void makeGrid(Container parent,
                                int rows, int cols,
                                int initialX, int initialY,
                                int xPad, int yPad) {
        SpringLayout layout;
        try {
            layout = (SpringLayout)parent.getLayout();
        } catch (ClassCastException exc) {
            System.err.println("The first argument to makeGrid must use SpringLayout.");
            return;
        }

        Spring xPadSpring = Spring.constant(xPad);
        Spring yPadSpring = Spring.constant(yPad);
        Spring initialXSpring = Spring.constant(initialX);
        Spring initialYSpring = Spring.constant(initialY);
        int max = rows * cols;

        //Calculate Springs that are the max of the width/height so that all
        //cells have the same size.
        Spring maxWidthSpring = layout.getConstraints(parent.getComponent(0)).
                                    getWidth();
        Spring maxHeightSpring = layout.getConstraints(parent.getComponent(0)).
                                    getWidth();
        for (int i = 1; i < max; i++) {
            SpringLayout.Constraints cons = layout.getConstraints(
                                            parent.getComponent(i));

            maxWidthSpring = Spring.max(maxWidthSpring, cons.getWidth());
            maxHeightSpring = Spring.max(maxHeightSpring, cons.getHeight());
        }

        //Apply the new width/height Spring. This forces all the
        //components to have the same size.
        for (int i = 0; i < max; i++) {
            SpringLayout.Constraints cons = layout.getConstraints(
                                            parent.getComponent(i));

            cons.setWidth(maxWidthSpring);
            cons.setHeight(maxHeightSpring);
        }

        //Then adjust the x/y constraints of all the cells so that they
        //are aligned in a grid.
        SpringLayout.Constraints lastCons = null;
        SpringLayout.Constraints lastRowCons = null;
        for (int i = 0; i < max; i++) {
            SpringLayout.Constraints cons = layout.getConstraints(
                                                 parent.getComponent(i));
            if (i % cols == 0) { //start of new row
                lastRowCons = lastCons;
                cons.setX(initialXSpring);
            } else { //x position depends on previous component
                cons.setX(Spring.sum(lastCons.getConstraint(SpringLayout.EAST),
                                     xPadSpring));
            }

            if (i / cols == 0) { //first row
                cons.setY(initialYSpring);
            } else { //y position depends on previous row
                cons.setY(Spring.sum(lastRowCons.getConstraint(SpringLayout.SOUTH),
                                     yPadSpring));
            }
            lastCons = cons;
        }

        //Set the parent's size.
        SpringLayout.Constraints pCons = layout.getConstraints(parent);
        pCons.setConstraint(SpringLayout.SOUTH,
                            Spring.sum(
                                Spring.constant(yPad),
                                lastCons.getConstraint(SpringLayout.SOUTH)));
        pCons.setConstraint(SpringLayout.EAST,
View Full Code Here


    /* Used by makeCompactGrid. */
    private static SpringLayout.Constraints getConstraintsForCell(
                                                int row, int col,
                                                Container parent,
                                                int cols) {
        SpringLayout layout = (SpringLayout) parent.getLayout();
        Component c = parent.getComponent(row * cols + col);
        return layout.getConstraints(c);
    }
View Full Code Here

     */
    public static void makeCompactGrid(Container parent,
                                       int rows, int cols,
                                       int initialX, int initialY,
                                       int xPad, int yPad) {
        SpringLayout layout;
        try {
            layout = (SpringLayout)parent.getLayout();
        } catch (ClassCastException exc) {
            System.err.println("The first argument to makeCompactGrid must use SpringLayout.");
            return;
        }

        //Align all cells in each column and make them the same width.
        Spring x = Spring.constant(initialX);
        for (int c = 0; c < cols; c++) {
            Spring width = Spring.constant(0);
            for (int r = 0; r < rows; r++) {
                width = Spring.max(width,
                                   getConstraintsForCell(r, c, parent, cols).
                                       getWidth());
            }
            for (int r = 0; r < rows; r++) {
                SpringLayout.Constraints constraints =
                        getConstraintsForCell(r, c, parent, cols);
                constraints.setX(x);
                constraints.setWidth(width);
            }
            x = Spring.sum(x, Spring.sum(width, Spring.constant(xPad)));
        }

        //Align all cells in each row and make them the same height.
        Spring y = Spring.constant(initialY);
        for (int r = 0; r < rows; r++) {
            Spring height = Spring.constant(0);
            for (int c = 0; c < cols; c++) {
                height = Spring.max(height,
                                    getConstraintsForCell(r, c, parent, cols).
                                        getHeight());
            }
            for (int c = 0; c < cols; c++) {
                SpringLayout.Constraints constraints =
                        getConstraintsForCell(r, c, parent, cols);
                constraints.setY(y);
                constraints.setHeight(height);
            }
            y = Spring.sum(y, Spring.sum(height, Spring.constant(yPad)));
        }

        //Set the parent's size.
        SpringLayout.Constraints pCons = layout.getConstraints(parent);
        pCons.setConstraint(SpringLayout.SOUTH, y);
        pCons.setConstraint(SpringLayout.EAST, x);
    }
View Full Code Here

        topPanel.add(selectionPanel, topConst);

        // CHECK_BOX
        mixOptionsPanel.setBorder(BorderFactory.createTitledBorder(GettextResource.gettext(config
                .getI18nResourceBundle(), "Mix options")));
        mixOptionsPanelLayout = new SpringLayout();
        mixOptionsPanel.setLayout(mixOptionsPanelLayout);
        mixOptionsPanel.setPreferredSize(new Dimension(200, 110));
        mixOptionsPanel.setMinimumSize(new Dimension(160, 105));
        optionsChecksPanel.setLayout(new BoxLayout(optionsChecksPanel, BoxLayout.LINE_AXIS));
        optionsChecksPanel.add(Box.createRigidArea(new Dimension(5, 0)));

        reverseFirstCheckbox.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Reverse first document"));
        reverseFirstCheckbox.setSelected(false);
        optionsChecksPanel.add(reverseFirstCheckbox);
        optionsChecksPanel.add(Box.createRigidArea(new Dimension(10, 0)));

        reverseSecondCheckbox.setText(GettextResource
                .gettext(config.getI18nResourceBundle(), "Reverse second document"));
        reverseSecondCheckbox.setSelected(true);
        optionsChecksPanel.add(reverseSecondCheckbox);
        mixOptionsPanel.add(optionsChecksPanel);

        stepTextField.setText(Integer.toString(MixParsedCommand.DEFAULT_STEP));
        secondStepTextField.setText(Integer.toString(MixParsedCommand.DEFAULT_STEP));

        GroupLayout optionFieldsLayout = new GroupLayout(optionsFieldsPanel);
        optionsFieldsPanel.setLayout(optionFieldsLayout);
        optionFieldsLayout.setAutoCreateGaps(true);

        optionFieldsLayout
                .setHorizontalGroup(optionFieldsLayout.createSequentialGroup().addGroup(
                        optionFieldsLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(stepLabel)
                                .addComponent(secondStepLabel)).addGroup(
                        optionFieldsLayout.createParallelGroup().addComponent(stepTextField).addComponent(
                                secondStepTextField)));

        optionFieldsLayout.setVerticalGroup(optionFieldsLayout.createSequentialGroup().addGroup(
                optionFieldsLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(stepLabel)
                        .addComponent(stepTextField)).addGroup(
                optionFieldsLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(secondStepLabel)
                        .addComponent(secondStepTextField)));

        mixOptionsPanel.add(optionsFieldsPanel);

        topConst.fill = GridBagConstraints.HORIZONTAL;
        topConst.weightx = 0.0;
        topConst.weighty = 0.0;
        topConst.gridwidth = 3;
        topConst.gridheight = 1;
        topConst.gridx = 0;
        topConst.gridy = 2;
        topPanel.add(mixOptionsPanel, topConst);

        // END_CHECK_BOX

        stepLabel.setText(GettextResource.gettext(config.getI18nResourceBundle(),
                "Number of pages to switch from the first document to the other"));
        secondStepLabel.setText(GettextResource.gettext(config.getI18nResourceBundle(),
                "Number of pages to switch from the second document to the other"));

        StringBuilder sb = new StringBuilder("<html><body><b>");
        sb.append(GettextResource.gettext(config.getI18nResourceBundle(), "Mix options"));
        sb.append("</b><p>");
        sb.append(GettextResource.gettext(config.getI18nResourceBundle(),
                "Tick the boxes if you want to reverse the first or the second document (or both)."));
        sb.append("</p><p>");
        sb.append(GettextResource.gettext(config.getI18nResourceBundle(),
                "Set the number of pages to switch from the first document to the other one (default is 1)."));
        sb.append("</p><p>");
        sb.append(GettextResource.gettext(config.getI18nResourceBundle(),
                "Set the number of pages to switch from the second document to the other one (default is 1)."));
        sb.append("</p></body></html>");

        optionsHelpLabel = new JHelpLabel(sb.toString(), true);
        mixOptionsPanel.add(optionsHelpLabel);

        stepTextField.setPreferredSize(new Dimension(45, 20));
        secondStepTextField.setPreferredSize(new Dimension(45, 20));

        GridBagConstraints c = new GridBagConstraints();
        c.fill = GridBagConstraints.BOTH;
        c.ipady = 5;
        c.weightx = 1.0;
        c.weighty = 1.0;
        c.gridwidth = 3;
        c.gridx = 0;
        c.gridy = 0;
        c.insets = new Insets(0, 0, 10, 0);
        add(topPanel, c);

        selectionPanel.addPopupMenuAction(new SetOutputPathSelectionTableAction(selectionPanel, destinationTextField,
                DEFAULT_OUPUT_NAME));

        // DESTINATION_PANEL
        destinationPanelLayout = new SpringLayout();
        destinationPanel.setLayout(destinationPanelLayout);
        destinationPanel.setBorder(BorderFactory.createTitledBorder(GettextResource.gettext(config
                .getI18nResourceBundle(), "Destination output file")));
        destinationPanel.setPreferredSize(new Dimension(200, 160));
        destinationPanel.setMinimumSize(new Dimension(160, 150));
View Full Code Here

  private void initialize(
    )
  {
    window = new JFrame("PDF Clown Sample Viewer");
    SpringLayout springLayout = new SpringLayout();

    window.getContentPane().setLayout(springLayout);
    window.setName("main");
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.setFocusable(true);
    {
      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
      Dimension windowSize = new Dimension(
        (int)(screenSize.getWidth()*.6),
        (int)(screenSize.getHeight()*.6)
        );
      int x = (int)(screenSize.getWidth() - windowSize.width) / 2;
      int y = (int)(screenSize.getHeight() - windowSize.height) / 2;

      window.setBounds(x,y,windowSize.width,windowSize.height);
    }

    {
      final JTabbedPane mainTabbedPane = new JTabbedPane();
      mainTabbedPane.setPreferredSize(new Dimension(0, 400));
      mainTabbedPane.setMinimumSize(new Dimension(0, 300));
      window.getContentPane().add(mainTabbedPane,BorderLayout.CENTER);

      final JMenuBar menuBar = new JMenuBar();
      window.setJMenuBar(menuBar);
      final JMenu fileMenu = new JMenu();
      menuBar.add(fileMenu);
      fileMenu.setName("fileMenu");
      fileMenu.setText("File");
      fileMenu.setMnemonic(KeyEvent.VK_F);
      {
        final JMenuItem openMenuItem = new JMenuItem();
        openMenuItem.setText("Open...");
        fileMenu.add(openMenuItem);
        openMenuItem.addMouseListener(
          new MouseAdapter()
          {
            @Override
            public void mousePressed(
              MouseEvent e
              )
            {showOpenFileDialog();}
          }
          );
        fileMenu.addSeparator();
        final JMenuItem exitMenuItem = new JMenuItem();
        exitMenuItem.setText("Exit");
        fileMenu.add(exitMenuItem);
        exitMenuItem.addMouseListener(
          new MouseAdapter()
          {
            @Override
            public void mousePressed(
              MouseEvent e
              )
            {System.exit(1);}
          }
          );
      }

      springLayout.putConstraint(SpringLayout.SOUTH, mainTabbedPane, 0, SpringLayout.SOUTH, window.getContentPane());
      springLayout.putConstraint(SpringLayout.EAST, mainTabbedPane, 0, SpringLayout.EAST, window.getContentPane());
      springLayout.putConstraint(SpringLayout.NORTH, mainTabbedPane, 0, SpringLayout.NORTH, window.getContentPane());
      springLayout.putConstraint(SpringLayout.WEST, mainTabbedPane, 0, SpringLayout.WEST, window.getContentPane());

      domInspector = new PdfInspectorSample();
      mainTabbedPane.addTab(
        "DOM Inspector",
        null,
View Full Code Here

        selectionPanel.addPopupMenuAction(new SetOutputPathSelectionTableAction(selectionPanel, destinationTextField, DEFAULT_OUPUT_NAME));

        // END_BROWSE_FILE_CHOOSER

        // OPTION_PANEL
        layoutOptionPanel = new SpringLayout();
        optionPanel.setLayout(layoutOptionPanel);
        optionPanel.setBorder(BorderFactory.createTitledBorder(GettextResource.gettext(config.getI18nResourceBundle(),
                "Merge options")));
        optionPanel.setMinimumSize(new Dimension(50, 50));
        optionPanel.setPreferredSize(new Dimension(50, 60));

        topConst.fill = GridBagConstraints.HORIZONTAL;
        topConst.weightx = 0.0;
        topConst.weighty = 0.0;
        topConst.gridwidth = 3;
        topConst.gridheight = 1;
        topConst.gridx = 0;
        topConst.gridy = 2;
        topPanel.add(optionPanel, topConst);

        mergeTypeCheck.setText(GettextResource.gettext(config.getI18nResourceBundle(), "PDF documents contain forms"));
        mergeTypeCheck.setSelected(false);
        optionPanel.add(mergeTypeCheck);

        String helpText = "<html><body><b>"
                + GettextResource.gettext(config.getI18nResourceBundle(), "Merge type")
                + "</b><ul>"
                + "<li><b>"
                + GettextResource.gettext(config.getI18nResourceBundle(), "Unchecked")
                + ":</b> "
                + GettextResource.gettext(config.getI18nResourceBundle(),
                        "Use this merge type for standard pdf documents")
                + ".</li>"
                + "<li><b>"
                + GettextResource.gettext(config.getI18nResourceBundle(), "Checked")
                + ":</b> "
                + GettextResource.gettext(config.getI18nResourceBundle(),
                        "Use this merge type for pdf documents containing forms")
                + "."
                + "<br><b>"
                + GettextResource.gettext(config.getI18nResourceBundle(), "Note")
                + ":</b> "
                + GettextResource.gettext(config.getI18nResourceBundle(),
                        "Setting this option the documents will be completely loaded in memory") + ".</li>"
                + "</ul></body></html>";
        mergeTypeHelpLabel = new JHelpLabel(helpText, true);
        optionPanel.add(mergeTypeHelpLabel);
        // END_OPTION_PANEL

        GridBagConstraints c = new GridBagConstraints();
        c.fill = GridBagConstraints.BOTH;
        c.ipady = 5;
        c.weightx = 1.0;
        c.weighty = 1.0;
        c.gridwidth = 3;
        c.gridx = 0;
        c.gridy = 0;
        c.insets = new Insets(0, 0, 10, 0);
        add(topPanel, c);

        // DESTINATION_PANEL
        layoutDestinationPanel = new SpringLayout();
        destinationPanel.setLayout(layoutDestinationPanel);
        destinationPanel.setBorder(BorderFactory.createTitledBorder(GettextResource.gettext(config
                .getI18nResourceBundle(), "Destination output file")));
        destinationPanel.setPreferredSize(new Dimension(200, 160));
        destinationPanel.setMinimumSize(new Dimension(160, 150));
View Full Code Here

        result.add(planePage, BorderLayout.CENTER);
        return result;
    }

    public JComponent buildPlanePage(GPOptionGroup[] optionGroups) {
        final JComponent optionsPanel = new JPanel(new SpringLayout());
        for (int i = 0; i < optionGroups.length; i++) {
            optionsPanel.add(createGroupComponent(optionGroups[i]));
        }
        SpringUtilities.makeCompactGrid(optionsPanel, optionGroups.length, 1,
                0, 0, 5, 5);
View Full Code Here

        });
        return resultPanel;
    }

    public JComponent createGroupComponent(GPOptionGroup group) {
        JPanel optionsPanel = new JPanel(new SpringLayout());
        if (group.isTitled()) {
            Border lineBorder = BorderFactory.createMatteBorder(1,0,0,0,Color.BLACK);
            optionsPanel.setBorder(BorderFactory.createTitledBorder(lineBorder,myi18n
                    .getOptionGroupLabel(group)));
        }
View Full Code Here

     * @param yPad
     *            y padding between cells
     */
    public static void makeGrid(Container parent, int rows, int cols,
            int initialX, int initialY, int xPad, int yPad) {
        SpringLayout layout;
        try {
            layout = (SpringLayout) parent.getLayout();
        } catch (ClassCastException exc) {
            System.err
                    .println("The first argument to makeGrid must use SpringLayout.");
            return;
        }

        Spring xPadSpring = Spring.constant(xPad);
        Spring yPadSpring = Spring.constant(yPad);
        Spring initialXSpring = Spring.constant(initialX);
        Spring initialYSpring = Spring.constant(initialY);
        int max = rows * cols;

        // Calculate Springs that are the max of the width/height so that all
        // cells have the same size.
        Spring maxWidthSpring = layout.getConstraints(parent.getComponent(0))
                .getWidth();
        Spring maxHeightSpring = layout.getConstraints(parent.getComponent(0))
                .getWidth();
        for (int i = 1; i < max; i++) {
            SpringLayout.Constraints cons = layout.getConstraints(parent
                    .getComponent(i));

            maxWidthSpring = Spring.max(maxWidthSpring, cons.getWidth());
            maxHeightSpring = Spring.max(maxHeightSpring, cons.getHeight());
        }

        // Apply the new width/height Spring. This forces all the
        // components to have the same size.
        for (int i = 0; i < max; i++) {
            SpringLayout.Constraints cons = layout.getConstraints(parent
                    .getComponent(i));

            cons.setWidth(maxWidthSpring);
            cons.setHeight(maxHeightSpring);
        }

        // Then adjust the x/y constraints of all the cells so that they
        // are aligned in a grid.
        SpringLayout.Constraints lastCons = null;
        SpringLayout.Constraints lastRowCons = null;
        for (int i = 0; i < max; i++) {
            SpringLayout.Constraints cons = layout.getConstraints(parent
                    .getComponent(i));
            if (i % cols == 0) { // start of new row
                lastRowCons = lastCons;
                cons.setX(initialXSpring);
            } else { // x position depends on previous component
                cons.setX(Spring.sum(lastCons.getConstraint(SpringLayout.EAST),
                        xPadSpring));
            }

            if (i / cols == 0) { // first row
                cons.setY(initialYSpring);
            } else { // y position depends on previous row
                cons.setY(Spring.sum(lastRowCons
                        .getConstraint(SpringLayout.SOUTH), yPadSpring));
            }
            lastCons = cons;
        }

        // Set the parent's size.
        SpringLayout.Constraints pCons = layout.getConstraints(parent);
        pCons.setConstraint(SpringLayout.SOUTH, Spring.sum(Spring
                .constant(yPad), lastCons.getConstraint(SpringLayout.SOUTH)));
        pCons.setConstraint(SpringLayout.EAST, Spring.sum(
                Spring.constant(xPad), lastCons
                        .getConstraint(SpringLayout.EAST)));
View Full Code Here

    }

    /* Used by makeCompactGrid. */
    private static SpringLayout.Constraints getConstraintsForCell(int row,
            int col, Container parent, int cols) {
        SpringLayout layout = (SpringLayout) parent.getLayout();
        Component c = parent.getComponent(row * cols + col);
        return layout.getConstraints(c);
    }
View Full Code Here

TOP

Related Classes of javax.swing.SpringLayout$SpringProxy

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.