Example usage for java.awt GridBagConstraints CENTER

List of usage examples for java.awt GridBagConstraints CENTER

Introduction

In this page you can find the example usage for java.awt GridBagConstraints CENTER.

Prototype

int CENTER

To view the source code for java.awt GridBagConstraints CENTER.

Click Source Link

Document

Put the component in the center of its display area.

Usage

From source file:org.executequery.gui.browser.TableDataTab.java

private void init() throws Exception {

    if (displayRowCount) {

        initRowCountPanel();/*w w  w  . j  a v a 2 s  .  c o  m*/
    }

    canEditTableNotePanel = createCanEditTableNotePanel();
    canEditTableNoteConstraints = new GridBagConstraints(1, 1, 1, 1, 1.0, 0, GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 5), 0, 0);

    scroller = new JScrollPane();
    scrollerConstraints = new GridBagConstraints(1, 2, 1, 1, 1.0, 1.0, GridBagConstraints.SOUTHEAST,
            GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0);

    rowCountPanelConstraints = new GridBagConstraints(1, 3, 1, 1, 1.0, 0, GridBagConstraints.SOUTHWEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 5, 5, 5), 0, 0);

    errorLabelConstraints = new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0);

    tableDataChanges = new ArrayList<TableDataChange>();
    alwaysShowCanEditNotePanel = SystemProperties.getBooleanProperty(Constants.USER_PROPERTIES_KEY,
            "browser.always.show.table.editable.label");

    cancelPanel = new InterruptibleProcessPanel("Executing query for data...");

    EventMediator.registerListener(this);
}

From source file:org.nuxeo.launcher.sync.NuxeoSyncFrame.java

protected Component buildSyncPanel() {
    syncPanel = new JPanel();
    syncPanel.setBackground(new Color(55, 55, 55));
    syncPanel.setForeground(Color.WHITE);
    syncPanel.setLayout(new GridBagLayout());

    JLabel l = new JLabel("Server IP", SwingConstants.TRAILING);
    l.setForeground(Color.WHITE);
    GridBagConstraints c = new GridBagConstraints();
    c.weightx = 1.0;//  w  w w . ja  v a  2s . co m
    c.gridx = 0;
    c.gridy = 0;
    c.anchor = GridBagConstraints.EAST;
    c.insets = new Insets(0, 0, 0, 0);
    syncPanel.add(l, c);
    syncServerIpTextField = new JTextField(10);
    l.setLabelFor(syncServerIpTextField);
    c.gridx = 1;
    c.gridy = 0;
    c.anchor = GridBagConstraints.WEST;

    syncPanel.add(syncServerIpTextField, c);

    l = new JLabel("Port", SwingConstants.TRAILING);
    l.setForeground(Color.WHITE);
    c.gridx = 0;
    c.gridy = 2;
    c.anchor = GridBagConstraints.EAST;

    syncPanel.add(l, c);
    syncPortTextField = new JTextField(10);
    l.setLabelFor(syncPortTextField);
    c.gridx = 1;
    c.gridy = 2;
    c.anchor = GridBagConstraints.WEST;
    syncPanel.add(syncPortTextField, c);

    l = new JLabel("Login", SwingConstants.TRAILING);
    l.setForeground(Color.WHITE);
    c.gridx = 0;
    c.gridy = 3;
    c.anchor = GridBagConstraints.EAST;

    syncPanel.add(l, c);
    syncLoginTextField = new JTextField(10);
    l.setLabelFor(syncLoginTextField);
    c.gridx = 1;
    c.gridy = 3;
    c.anchor = GridBagConstraints.WEST;

    syncPanel.add(syncLoginTextField, c);

    l = new JLabel("Password", SwingConstants.TRAILING);
    l.setForeground(Color.WHITE);
    c.gridx = 0;
    c.gridy = 4;
    c.anchor = GridBagConstraints.EAST;

    syncPanel.add(l, c);
    syncPasswordField = new JPasswordField(10);
    l.setLabelFor(syncPasswordField);
    c.gridx = 1;
    c.gridy = 4;
    c.anchor = GridBagConstraints.WEST;
    syncPanel.add(syncPasswordField, c);

    syncButton = new JButton();
    c.fill = GridBagConstraints.NONE;
    c.gridx = 0;
    c.gridy = 5;
    c.gridwidth = 2;
    c.insets = new Insets(10, 0, 0, 0);
    c.anchor = GridBagConstraints.CENTER;
    // set the action to the button
    synchronizeAction = createSyncAction();
    syncButton.setAction(synchronizeAction);
    syncButton.setText("Synchronize");

    updateSyncButton();

    syncPanel.add(syncButton, c);

    errorMessageLabel = new JLabel("", SwingConstants.TRAILING);
    errorMessageLabel.setForeground(Color.RED);
    c.gridx = 0;
    c.gridy = 6;
    c.gridwidth = 2;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.insets = new Insets(10, 0, 0, 0);
    c.anchor = GridBagConstraints.CENTER;
    syncPanel.add(errorMessageLabel, c);
    return syncPanel;
}

From source file:pcgui.SetupParametersPanel.java

/**
 * Create the frame./* w w w.  j  a  v a 2s .  c  o m*/
 * 
 * @param switcher
 * 
 * @param rootFrame
 */

public SetupParametersPanel(final PanelSwitcher switcher, JFrame rootFrame) {
    this.rootFrame = rootFrame;
    setLayout(new BorderLayout());

    JLabel headingLabel = new JLabel("Setup Parameters");
    headingLabel.setFont(new Font("Tahoma", Font.BOLD, 16));
    add(headingLabel, BorderLayout.NORTH);
    JButton saveBtn = new JButton("Save");
    final JButton runModifiedBtn = new JButton("Run");

    runModifiedBtn.setEnabled(false);

    runModifiedBtn.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            runModel();

        }
    });

    saveBtn.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            //creating separate copy of model so that changes in one doesn't effect other
            ArrayList<ArrayList<Object>> mod = new ArrayList<ArrayList<Object>>(model.getData());
            //call save model of modelsaver
            //TODO add visualization list and save to excel using similar method as below
            //TODO add modelname, should contain .xls/.xlsx extension
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_hhmmss");
            outputFile = importedFile.toString().replace(".mos", "") + "_" + sdf.format(new Date())
                    + "_FEORA_solution.xlsx";
            ModelSaver.saveInputModel(mod, outputFile);

            runModifiedBtn.setEnabled(true);

        }
    });

    JLabel label = new JLabel("Enter count of random value runs");
    repeatCount = new JTextField();
    repeatCount.setToolTipText("Enter count for which each combination of step variables is run ");
    repeatCount.setText("1");
    repeatCount.setPreferredSize(new Dimension(100, 20));

    JPanel runConfig = new JPanel();
    runConfig.setLayout(new GridLayout(2, 2));

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridwidth = GridBagConstraints.CENTER;

    JPanel configCount = new JPanel(new FlowLayout());
    JPanel configButtons = new JPanel(new FlowLayout());
    configCount.add(label);
    configCount.add(repeatCount);

    JButton btnLoadSavedConfiguration = new JButton("Load Saved Configuration");
    btnLoadSavedConfiguration.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser jFileChooser = new JFileChooser();

            File workingDirectory = new File(System.getProperty("user.dir"));

            jFileChooser.setCurrentDirectory(workingDirectory);

            jFileChooser.setFileFilter(new FileFilter() {

                @Override
                public String getDescription() {
                    // TODO Auto-generated method stub
                    return "Excel solution files";
                }

                @Override
                public boolean accept(File f) {
                    // TODO Auto-generated method stub
                    return f.isDirectory() || f.getName().endsWith(".xls") || f.getName().endsWith(".xlsx");

                }
            });
            int returnVal = jFileChooser.showOpenDialog(null);

            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = jFileChooser.getSelectedFile();

                // This is where a real application would open the file.

                if (file.getName().endsWith(".xls") || file.getName().endsWith(".xlsx")) {
                    String fileName = file.getAbsolutePath();
                    List<List<String>> savedConfig = ModelSaver.loadInputConfigFromExcel(fileName);
                    ArrayList<Symbol> symList = new ArrayList<Symbol>();

                    int i = 0;
                    for (List<String> list : savedConfig) {
                        //ignore the header row
                        if (i > 0) {
                            System.out.println("VariableName=" + list.get(0));
                            System.out.println("Datatype=" + list.get(1));
                            System.out.println("Type=" + list.get(2));
                            System.out.println("Value=" + list.get(3));
                            System.out.println("ExternalFile=" + list.get(4));
                            System.out.println("ExcelRange=" + list.get(5));
                            System.out.println("DistributionFunction=" + list.get(6));
                            System.out.println("OutputTracket=" + list.get(7));
                            Symbol sym = new Symbol<>();
                            sym.name = list.get(0);
                            sym.typeString = list.get(1);
                            sym.mode = list.get(2);
                            sym.set(list.get(3));
                            sym.externalFile = list.get(4);
                            sym.excelFileRange = list.get(5);
                            sym.distFunction = list.get(6);
                            sym.trackingEnabled = Boolean.parseBoolean(list.get(7));
                            symList.add(sym);
                        }
                        i++;

                    }
                    initParamList(symList, parser);
                }

            } else {
                //               System.out.println("Open command cancelled by user.");
            }

        }
    });
    configButtons.add(btnLoadSavedConfiguration);

    configButtons.add(saveBtn);
    configButtons.add(runModifiedBtn);
    runConfig.add(configCount);
    runConfig.add(configButtons);
    add(runConfig, BorderLayout.SOUTH);

    setVisible(true);
}

From source file:org.gvsig.landregistryviewer.app.mainplugin.LandRegistryViewerExtension.java

/**
 * Create the view in the project. Add the blocks layer to the view, and
 * register the tool for get info of the blocks.
 *//*from w  w  w . j a va 2s .c o  m*/
private IView createViewWindow() throws LoadLayerException {
    I18nManager i18nManager = ToolsLocator.getI18nManager();
    ApplicationManager application = ApplicationLocator.getManager();

    ProjectManager projectManager = application.getProjectManager();

    // 1. Create a new view and set the name.
    ViewManager viewManager = (ViewManager) projectManager.getDocumentManager(ViewManager.TYPENAME);
    ViewDocument view = (ViewDocument) viewManager.createDocument();
    view.setName(i18nManager.getTranslation(MY_VIEW_NAME));

    // Setting view's projection to shapefile's known CRS
    view.getMapContext().setProjection(CRSFactory.getCRS("EPSG:23030"));

    // 2. Create a new layer with the blocks
    FLyrVect layer = (FLyrVect) application.getMapContextManager()
            .createLayer(i18nManager.getTranslation("_Blocks"), this.manager.getBlocks());

    // Add a new property to the layer to identify it.
    layer.setProperty("ViewerLayer", Boolean.TRUE);

    // 3. Add this layer to the mapcontext of the new view.
    view.getMapContext().getLayers().addLayer(layer);

    // 4. Add the view to the current project.
    projectManager.getCurrentProject().add(view);

    // 5. Force to show the view's window.
    IView viewWindow = (IView) viewManager.getMainWindow(view);
    application.getUIManager().addWindow(viewWindow, GridBagConstraints.CENTER);
    try {
        // 6. and maximise the window
        application.getUIManager().setMaximum((IWindow) viewWindow, true);
    } catch (PropertyVetoException e) {
        logger.info("Can't maximize view.", e);
    }

    // 7. Register the tool in the mapcontrol of the view to listen to point selections.
    ParcelsOfBlockListener listener = new ParcelsOfBlockListener();
    viewWindow.getMapControl().addBehavior(TOOL_NAME, new PointBehavior(listener));

    return viewWindow;
}

From source file:com.fisher.mainFrame.java

private void initComponents() {
    // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
    // Generated using JFormDesigner Evaluation license - nick xu
    dialogPane = new JPanel();
    contentPanel = new JPanel();
    scrollPaneLogArea = new JScrollPane();
    logArea = new JTextArea();
    buttonBar = new JPanel();
    startButton = new JButton();
    stopButton = new JButton();

    //======== this ========
    setTitle("Fish Transform Trading");
    Container contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());

    //======== dialogPane ========
    {//from   w  w w.  j  ava2  s  .c  o m
        dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12));
        dialogPane.setPreferredSize(new Dimension(758, 900));

        // JFormDesigner evaluation mark
        dialogPane.setBorder(new javax.swing.border.CompoundBorder(
                new javax.swing.border.TitledBorder(new javax.swing.border.EmptyBorder(0, 0, 0, 0),
                        "JFormDesigner Evaluation", javax.swing.border.TitledBorder.CENTER,
                        javax.swing.border.TitledBorder.BOTTOM,
                        new java.awt.Font("Dialog", java.awt.Font.BOLD, 12), java.awt.Color.red),
                dialogPane.getBorder()));
        dialogPane.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent e) {
                if ("border".equals(e.getPropertyName()))
                    throw new RuntimeException();
            }
        });

        dialogPane.setLayout(new BorderLayout());

        //======== contentPanel ========
        {

            //======== scrollPaneLogArea ========
            {
                scrollPaneLogArea.setViewportView(logArea);
            }

            GroupLayout contentPanelLayout = new GroupLayout(contentPanel);
            contentPanel.setLayout(contentPanelLayout);
            contentPanelLayout.setHorizontalGroup(contentPanelLayout.createParallelGroup()
                    .addComponent(scrollPaneLogArea, GroupLayout.DEFAULT_SIZE, 734, Short.MAX_VALUE));
            contentPanelLayout
                    .setVerticalGroup(contentPanelLayout.createParallelGroup()
                            .addGroup(contentPanelLayout
                                    .createSequentialGroup().addComponent(scrollPaneLogArea,
                                            GroupLayout.PREFERRED_SIZE, 225, GroupLayout.PREFERRED_SIZE)
                                    .addGap(0, 476, Short.MAX_VALUE)));
        }
        dialogPane.add(contentPanel, BorderLayout.CENTER);

        //======== buttonBar ========
        {
            buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0));
            buttonBar.setLayout(new GridBagLayout());
            ((GridBagLayout) buttonBar.getLayout()).columnWidths = new int[] { 0, 85, 80 };
            ((GridBagLayout) buttonBar.getLayout()).columnWeights = new double[] { 1.0, 0.0, 0.0 };

            //---- startButton ----
            startButton.setText("Start");
            startButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    startButtonActionPerformed(e);
                }
            });
            buttonBar.add(startButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.BOTH, new Insets(0, 0, 0, 5), 0, 0));

            //---- stopButton ----
            stopButton.setText("Stop");
            stopButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    stopButtonActionPerformed(e);
                }
            });
            buttonBar.add(stopButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
        }
        dialogPane.add(buttonBar, BorderLayout.SOUTH);
    }
    contentPane.add(dialogPane, BorderLayout.CENTER);
    pack();
    setLocationRelativeTo(getOwner());
    // JFormDesigner - End of component initialization  //GEN-END:initComponents
}

From source file:gate.creole.kea.CorpusImporter.java

protected void initGUIComponents() {
    setLayout(new GridBagLayout());
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.gridy = 0;/*  ww  w.j  a va 2 s . c om*/
    constraints.gridx = GridBagConstraints.RELATIVE;
    constraints.weightx = 0;
    constraints.weighty = 0;
    constraints.fill = GridBagConstraints.BOTH;

    JPanel inputPanel = new JPanel(new GridBagLayout());
    inputPanel.setBorder(BorderFactory.createTitledBorder("Input"));
    GridBagConstraints constraints2 = new GridBagConstraints();
    constraints2.gridy = 0;
    constraints2.gridx = GridBagConstraints.RELATIVE;
    constraints2.weighty = 0;
    constraints2.weightx = 0;
    constraints2.fill = GridBagConstraints.BOTH;
    constraints2.insets = new Insets(2, 2, 2, 2);

    JLabel label = new JLabel("Source directory:");
    inputPanel.add(label, constraints2);
    sourceDirTField = new JTextField(30);
    inputPanel.add(sourceDirTField, constraints2);
    JButton openButton = new JButton(new SelectDirectoryAction());
    inputPanel.add(openButton, constraints2);

    constraints2.gridy = 1;
    label = new JLabel("Extension for text files:");
    inputPanel.add(label, constraints2);
    constraints2.gridwidth = 2;
    textExtensionTField = new JTextField(".txt");
    inputPanel.add(textExtensionTField, constraints2);
    constraints2.gridwidth = 1;

    constraints2.gridy = 2;
    label = new JLabel("Extension for keyphrase files:");
    inputPanel.add(label, constraints2);
    constraints2.gridwidth = 2;
    keyExtensionTField = new JTextField(".key");
    inputPanel.add(keyExtensionTField, constraints2);
    constraints2.gridwidth = 1;

    constraints2.gridy = 3;
    label = new JLabel("Encoding for input files:");
    inputPanel.add(label, constraints2);
    constraints2.gridwidth = 2;
    encodingTField = new JTextField("");
    inputPanel.add(encodingTField, constraints2);
    constraints2.gridwidth = 1;

    add(inputPanel, constraints);
    constraints.weightx = 1;
    add(Box.createHorizontalGlue(), constraints);
    constraints.weightx = 0;

    JPanel outputPanel = new JPanel();
    outputPanel.setLayout(new GridBagLayout());
    outputPanel.setBorder(BorderFactory.createTitledBorder("Output"));

    constraints2.gridy = 0;
    label = new JLabel("Corpus name:");
    outputPanel.add(label, constraints2);
    constraints2.weightx = 1;
    corpusNameTField = new JTextField("KEA Corpus");
    constraints2.weightx = 0;
    outputPanel.add(corpusNameTField, constraints2);

    constraints2.gridy = 1;
    label = new JLabel("Output annotation set:");
    outputPanel.add(label, constraints2);
    constraints2.weightx = 1;
    annotationSetTField = new JTextField("Key");
    constraints2.weightx = 0;
    outputPanel.add(annotationSetTField, constraints2);

    constraints2.gridy = 2;
    label = new JLabel("Keyphrase annotation type:");
    outputPanel.add(label, constraints2);
    constraints2.weightx = 1;
    annotationTypeTField = new JTextField("Keyphrase");
    constraints2.weightx = 0;
    outputPanel.add(annotationTypeTField, constraints2);

    constraints.gridy = 1;
    add(outputPanel, constraints);

    constraints.gridy = 2;
    constraints.fill = GridBagConstraints.NONE;
    constraints.anchor = GridBagConstraints.CENTER;
    add(new JButton(new ImportCorpusAction()), constraints);

    constraints.gridy = 3;
    constraints.weighty = 1;
    add(Box.createVerticalGlue(), constraints);
}

From source file:org.pentaho.ui.xul.swing.SwingElement.java

public void layout() {
    super.layout();
    double totalFlex = 0.0;

    if (isVisible() == false) {
        resetContainer();//from w w w.  j  a  va  2  s. com
        return;
    }

    for (Element comp : getChildNodes()) {
        // if (comp.getManagedObject() == null) {
        // continue;
        // }
        if (((XulComponent) comp).getFlex() > 0) {
            flexLayout = true;
            totalFlex += ((XulComponent) comp).getFlex();
        }
    }

    double currentFlexTotal = 0.0;

    Align alignment = (getAlign() != null) ? Align.valueOf(this.getAlign().toUpperCase()) : null;

    for (int i = 0; i < getChildNodes().size(); i++) {
        XulComponent comp = (XulComponent) getChildNodes().get(i);
        gc.fill = GridBagConstraints.BOTH;

        if (comp instanceof XulSplitter) {
            JPanel prevContainer = container;
            container = new ScrollablePanel(new GridBagLayout());
            container.setOpaque(false);

            final JSplitPane splitter = new JSplitPane(
                    (this.getOrientation() == Orient.VERTICAL) ? JSplitPane.VERTICAL_SPLIT
                            : JSplitPane.HORIZONTAL_SPLIT,
                    prevContainer, container);
            splitter.setContinuousLayout(true);

            final double splitterSize = currentFlexTotal / totalFlex;
            splitter.setResizeWeight(splitterSize);
            if (totalFlex > 0) {
                splitter.addComponentListener(new ComponentListener() {
                    public void componentHidden(ComponentEvent arg0) {
                    }

                    public void componentMoved(ComponentEvent arg0) {
                    }

                    public void componentShown(ComponentEvent arg0) {
                    }

                    public void componentResized(ComponentEvent arg0) {
                        splitter.setDividerLocation(splitterSize);
                        splitter.removeComponentListener(this);
                    }

                });

            }

            if (!flexLayout) {
                if (this.getOrientation() == Orient.VERTICAL) { // VBox and such
                    gc.weighty = 1.0;
                } else {
                    gc.weightx = 1.0;
                }

                prevContainer.add(Box.createGlue(), gc);
            }
            setManagedObject(splitter);
        }

        Object maybeComponent = comp.getManagedObject();
        if (maybeComponent == null || !(maybeComponent instanceof Component)) {
            continue;
        }
        if (this.getOrientation() == Orient.VERTICAL) { // VBox and such
            gc.gridheight = comp.getFlex() + 1;
            gc.gridwidth = GridBagConstraints.REMAINDER;
            gc.weighty = (totalFlex == 0) ? 0 : (comp.getFlex() / totalFlex);
        } else {
            gc.gridwidth = comp.getFlex() + 1;
            gc.gridheight = GridBagConstraints.REMAINDER;
            gc.weightx = (totalFlex == 0) ? 0 : (comp.getFlex() / totalFlex);
        }

        currentFlexTotal += comp.getFlex();

        if (this.getOrientation() == Orient.VERTICAL) { // VBox and such
            if (alignment != null) {
                gc.fill = GridBagConstraints.NONE;
                switch (alignment) {
                case START:
                    gc.anchor = GridBagConstraints.WEST;
                    break;
                case CENTER:
                    gc.anchor = GridBagConstraints.CENTER;
                    break;
                case END:
                    gc.anchor = GridBagConstraints.EAST;
                    break;
                }
            }

        } else {
            if (alignment != null) {
                gc.fill = GridBagConstraints.NONE;
                switch (alignment) {
                case START:
                    gc.anchor = GridBagConstraints.NORTH;
                    break;
                case CENTER:
                    gc.anchor = GridBagConstraints.CENTER;
                    break;
                case END:
                    gc.anchor = GridBagConstraints.SOUTH;
                    break;
                }
            }
        }

        Component component = (Component) maybeComponent;

        if (comp.getWidth() > 0 || comp.getHeight() > 0) {
            Dimension minSize = component.getMinimumSize();
            Dimension prefSize = component.getPreferredSize();

            if (comp.getWidth() > 0) {
                minSize.width = comp.getWidth();
                prefSize.width = comp.getWidth();
            }
            if (comp.getHeight() > 0) {
                minSize.height = comp.getHeight();
                prefSize.height = comp.getHeight();
            }
            component.setMinimumSize(minSize);
            component.setPreferredSize(prefSize);
        }

        container.add(component, gc);

        if (i + 1 == getChildNodes().size() && !flexLayout) {
            if (this.getOrientation() == Orient.VERTICAL) { // VBox and such
                gc.weighty = 1.0;

            } else {
                gc.weightx = 1.0;

            }
            container.add(Box.createGlue(), gc);
        }
    }

}

From source file:com.sec.ose.osi.ui.frm.main.report.JPanExportReport.java

private JPanel getJPanelForDocumentExportInfo() {
    if (jPanelForDocumentExportInfo == null) {
        GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
        gridBagConstraints5.fill = GridBagConstraints.HORIZONTAL;
        gridBagConstraints5.gridx = -1;//from   w w w .  jav  a2 s. c o  m
        gridBagConstraints5.gridy = -1;
        gridBagConstraints5.gridwidth = 1;
        gridBagConstraints5.anchor = GridBagConstraints.CENTER;
        gridBagConstraints5.weightx = 1.0;
        gridBagConstraints5.weighty = 0.0;
        gridBagConstraints5.insets = new Insets(0, 0, 10, 5); //  margin // top, left, bottom, right
        jPanelForDocumentExportInfo = new JPanel();
        jPanelForDocumentExportInfo.setLayout(new GridBagLayout());
        jPanelForDocumentExportInfo.setBorder(BorderFactory.createTitledBorder(null, "Report Export Location",
                TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION,
                new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
        jPanelForDocumentExportInfo.add(getJPanelDocumentExportInfo(), gridBagConstraints5);
    }
    return jPanelForDocumentExportInfo;
}

From source file:org.pentaho.ui.xul.swing.tags.SwingGrid.java

@Override
public void layout() {

    if (this.getChildNodes().size() < 2) {
        logger.warn("Grid does not contain Column and Row children");
        return;// w  ww .  ja  va2  s.co  m
    }

    XulComponent columns = this.getChildNodes().get(0);
    XulComponent rows = this.getChildNodes().get(1);

    int colCount = 0;
    int rowCount = 0;
    float colFlexTotal = 0;
    float rowTotalFlex = 0;
    for (XulComponent col : columns.getChildNodes()) {
        if (col.getFlex() > 0) {
            colFlexTotal += col.getFlex();
        }
        colCount++;
    }

    for (XulComponent row : rows.getChildNodes()) {
        if (row.getFlex() > 0) {
            rowTotalFlex += row.getFlex();
        }
        rowCount++;
    }

    for (XulComponent row : rows.getChildNodes()) {
        gc.gridx = 0;

        for (XulComponent xulComp : row.getChildNodes()) {
            gc.weightx = 0.0;
            gc.gridwidth = 1;
            gc.gridheight = 1;
            gc.weighty = 0.0;
            gc.anchor = GridBagConstraints.NORTHWEST;
            gc.fill = GridBagConstraints.NONE;

            Component comp = (Component) xulComp.getManagedObject();
            float colFlex = columns.getChildNodes().get(gc.gridx).getFlex();
            int rowFlex = row.getFlex();

            Align colAlignment = null;
            Align rowAlignment = null;
            String colAlignmentStr = xulComp.getAlign();
            String rowAlignStr = row.getAlign();
            if (colAlignmentStr != null) {
                colAlignment = Align.valueOf(colAlignmentStr);
            }
            if (rowAlignStr != null) {
                rowAlignment = Align.valueOf(rowAlignStr);
            }

            if (colFlex > 0) {
                gc.weightx = (colFlex / colFlexTotal);
            }
            if (rowFlex > 0) {
                gc.weighty = (rowFlex / rowTotalFlex);
            }
            if (colAlignment == Align.STRETCH && xulComp.getFlex() > 0) {
                gc.fill = GridBagConstraints.BOTH;
            } else if (colAlignment == Align.STRETCH) {
                gc.fill = GridBagConstraints.HORIZONTAL;
            } else if (xulComp.getFlex() > 0) {
                gc.fill = GridBagConstraints.VERTICAL;
            }

            if (row.getChildNodes().indexOf(xulComp) + 1 == row.getChildNodes().size()) {
                gc.gridwidth = GridBagConstraints.REMAINDER;
            } else {
                gc.gridwidth = 1;
            }
            if (rows.getChildNodes().indexOf(row) + 1 == rows.getChildNodes().size()) {
                gc.gridheight = GridBagConstraints.REMAINDER;
            } else {
                gc.gridheight = 1;
            }

            // gc.gridheight = row.getFlex() + 1;

            if (colAlignment != null && rowAlignment != null) {
                switch (rowAlignment) {
                case START:
                    switch (colAlignment) {
                    case START:
                        gc.anchor = GridBagConstraints.NORTHWEST;
                        break;
                    case CENTER:
                        gc.anchor = GridBagConstraints.NORTH;
                        break;
                    case END:
                        gc.anchor = GridBagConstraints.NORTHEAST;
                        break;
                    }
                    break;
                case CENTER:
                    switch (colAlignment) {
                    case START:
                        gc.anchor = GridBagConstraints.WEST;
                        break;
                    case CENTER:
                        gc.anchor = GridBagConstraints.CENTER;
                        break;
                    case END:
                        gc.anchor = GridBagConstraints.EAST;
                        break;
                    }
                    break;
                case END:
                    switch (colAlignment) {
                    case START:
                        gc.anchor = GridBagConstraints.SOUTHWEST;
                        break;
                    case CENTER:
                        gc.anchor = GridBagConstraints.SOUTH;
                        break;
                    case END:
                        gc.anchor = GridBagConstraints.SOUTHEAST;
                        break;
                    }
                }
            } else if (rowAlignment != null) {
                switch (rowAlignment) {
                case START:
                    gc.anchor = GridBagConstraints.NORTHWEST;
                    break;
                case CENTER:
                    gc.anchor = GridBagConstraints.WEST;
                    break;
                case END:
                    gc.anchor = GridBagConstraints.SOUTHWEST;
                    break;
                }
            } else if (colAlignment != null) {

                switch (colAlignment) {
                case START:
                    gc.anchor = GridBagConstraints.NORTHWEST;
                    break;
                case CENTER:
                    gc.anchor = GridBagConstraints.NORTH;
                    break;
                case END:
                    gc.anchor = GridBagConstraints.NORTHEAST;
                    break;
                }
            }

            if (comp.getWidth() > 0 || comp.getHeight() > 0) {
                Dimension minSize = comp.getMinimumSize();
                Dimension prefSize = comp.getPreferredSize();

                if (comp.getWidth() > 0) {
                    minSize.width = comp.getWidth();
                    prefSize.width = comp.getWidth();
                }
                if (comp.getHeight() > 0) {
                    minSize.height = comp.getHeight();
                    prefSize.height = comp.getHeight();
                }
                comp.setMinimumSize(minSize);
                comp.setPreferredSize(prefSize);
            } else {
                comp.setPreferredSize(comp.getMinimumSize());
            }

            grid.add(comp, gc);
            gc.gridx++;
        }

        gc.gridy++;
    }

    if (rowTotalFlex == 0) {
        // Add in an extra row at the bottom to push others up
        gc.gridy++;
        gc.weighty = 1;
        gc.fill = gc.REMAINDER;
        grid.add(Box.createGlue(), gc);
    }
    this.initialized = true;
}

From source file:com.sshtools.common.ui.SshToolsConnectionPanel.java

/**
 *
 *
 * @param parent/* w w w.  j ava2s .  c  o  m*/
 * @param profile
 * @param optionalTabs
 *
 * @return
 */
public static SshToolsConnectionProfile showConnectionDialog(Component parent,
        SshToolsConnectionProfile profile, SshToolsConnectionTab[] optionalTabs) {
    //  If no properties are provided, then use the default
    if (profile == null) {
        int port = DEFAULT_PORT;
        String port_S = Integer.toString(DEFAULT_PORT);
        port_S = PreferencesStore.get(SshTerminalPanel.PREF_DEFAULT_SIMPLE_PORT, port_S);
        try {
            port = Integer.parseInt(port_S);
        } catch (NumberFormatException e) {
            log.warn("Could not parse the port number from defaults file (property name"
                    + SshTerminalPanel.PREF_DEFAULT_SIMPLE_PORT + ", property value= " + port_S + ").");
        }
        profile = new SshToolsConnectionProfile();
        profile.setHost(PreferencesStore.get(SshToolsApplication.PREF_CONNECTION_LAST_HOST, ""));
        profile.setPort(PreferencesStore.getInt(SshToolsApplication.PREF_CONNECTION_LAST_PORT, port));
        profile.setUsername(PreferencesStore.get(SshToolsApplication.PREF_CONNECTION_LAST_USER, ""));

    }

    final SshToolsConnectionPanel conx = new SshToolsConnectionPanel(true);

    if (optionalTabs != null) {
        for (int i = 0; i < optionalTabs.length; i++) {
            conx.addTab(optionalTabs[i]);
        }
    }

    conx.setConnectionProfile(profile);

    JDialog d = null;
    Window w = (Window) SwingUtilities.getAncestorOfClass(Window.class, parent);

    if (w instanceof JDialog) {
        d = new JDialog((JDialog) w, "Connection Profile", true);
    } else if (w instanceof JFrame) {
        d = new JDialog((JFrame) w, "Connection Profile", true);
    } else {
        d = new JDialog((JFrame) null, "Connection Profile", true);
    }

    final JDialog dialog = d;

    class UserAction {
        boolean connect;
    }

    final UserAction userAction = new UserAction();

    //  Create the bottom button panel
    final JButton cancel = new JButton("Cancel");
    cancel.setMnemonic('c');
    cancel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            userAction.connect = false;
            dialog.setVisible(false);
        }
    });

    final JButton connect = new JButton("Connect");
    connect.setMnemonic('t');
    connect.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            if (conx.validateTabs()) {
                userAction.connect = true;
                dialog.setVisible(false);
            }
        }
    });
    dialog.getRootPane().setDefaultButton(connect);

    JPanel buttonPanel = new JPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.anchor = GridBagConstraints.CENTER;
    gbc.insets = new Insets(6, 6, 0, 0);
    gbc.weighty = 1.0;
    UIUtil.jGridBagAdd(buttonPanel, connect, gbc, GridBagConstraints.RELATIVE);
    UIUtil.jGridBagAdd(buttonPanel, cancel, gbc, GridBagConstraints.REMAINDER);

    JPanel southPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 0, 0));
    southPanel.add(buttonPanel);

    //
    JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    mainPanel.add(conx, BorderLayout.CENTER);
    mainPanel.add(southPanel, BorderLayout.SOUTH);

    // Show the dialog
    dialog.getContentPane().setLayout(new GridLayout(1, 1));
    dialog.getContentPane().add(mainPanel);
    dialog.pack();
    dialog.setResizable(false);
    UIUtil.positionComponent(SwingConstants.CENTER, dialog);

    //show the simple box and act on the answer.
    SshToolsSimpleConnectionPrompt stscp = SshToolsSimpleConnectionPrompt.getInstance();
    StringBuffer sb = new StringBuffer();
    userAction.connect = !stscp.getHostname(sb, profile.getHost());

    boolean advanced = stscp.getAdvanced();

    if (advanced) {
        userAction.connect = false;
        profile.setHost(sb.toString());
        conx.hosttab.setConnectionProfile(profile);
        dialog.setVisible(true);
    }

    // Make sure we didn't cancel
    if (!userAction.connect) {
        return null;
    }

    conx.applyTabs();
    if (!advanced)
        profile.setHost(sb.toString());
    if (!advanced) {
        int port = DEFAULT_PORT;
        String port_S = Integer.toString(DEFAULT_PORT);
        port_S = PreferencesStore.get(SshTerminalPanel.PREF_DEFAULT_SIMPLE_PORT, port_S);
        try {
            port = Integer.parseInt(port_S);
        } catch (NumberFormatException e) {
            log.warn("Could not parse the port number from defaults file (property name"
                    + SshTerminalPanel.PREF_DEFAULT_SIMPLE_PORT + ", property value= " + port_S + ").");
        }
        profile.setPort(port);
    }
    if (!advanced)
        profile.setUsername("");

    PreferencesStore.put(SshToolsApplication.PREF_CONNECTION_LAST_HOST, profile.getHost());
    // only save user inputed configuration
    if (advanced) {
        PreferencesStore.put(SshToolsApplication.PREF_CONNECTION_LAST_USER, profile.getUsername());
        PreferencesStore.putInt(SshToolsApplication.PREF_CONNECTION_LAST_PORT, profile.getPort());
    }
    // Return the connection properties
    return profile;
}