Example usage for com.jgoodies.forms.layout CellConstraints xywh

List of usage examples for com.jgoodies.forms.layout CellConstraints xywh

Introduction

In this page you can find the example usage for com.jgoodies.forms.layout CellConstraints xywh.

Prototype

public CellConstraints xywh(int col, int row, int colSpan, int rowSpan) 

Source Link

Document

Sets the column, row, width, and height; uses default alignments.

Examples:

 cc.xywh(1, 3, 2, 1); cc.xywh(1, 3, 7, 3); 

Usage

From source file:de.erdesignerng.visual.editor.table.TableEditorView.java

License:Open Source License

public DefaultTabbedPaneTab getIndexGeneralTab() {

    if (indexGeneralTab == null) {
        indexGeneralTab = new DefaultTabbedPaneTab(indexTabbedPane, ERDesignerBundle.GENERAL);

        String colDef = "2dlu,left:40dlu,2dlu,60dlu:grow,2dlu,20dlu,2dlu";
        String rowDef = "2dlu,p,2dlu,fill:40dlu:grow,2dlu,p,2dlu,p,2dlu,p,4dlu,p,2dlu,p,2dlu,p,2dlu,p,2dlu,p,2dlu,p,2dlu,p,2dlu";

        FormLayout layout = new FormLayout(colDef, rowDef);
        indexGeneralTab.setLayout(layout);

        CellConstraints cons = new CellConstraints();

        indexGeneralTab.add(getLabel1(), cons.xywh(2, 2, 1, 1));
        indexGeneralTab.add(getIndexName(), cons.xywh(4, 2, 3, 1));

        indexGeneralTab.add(getIndexFieldList().getScrollPane(), cons.xywh(2, 4, 5, 1));

        indexGeneralTab.add(getRemoveFromIndexButton(), cons.xy(6, 6));

        indexGeneralTab.add(getAddIndexAttribute(), cons.xy(2, 8));
        indexGeneralTab.add(getIndexAttribute(), cons.xy(4, 8));
        indexGeneralTab.add(getAddAttributeToIndexButton(), cons.xy(6, 8));

        indexGeneralTab.add(getAddIndexExpression(), cons.xy(2, 10));
        indexGeneralTab.add(getIndexExpression(), cons.xy(4, 10));
        indexGeneralTab.add(getAddExpressionToIndexButton(), cons.xy(6, 10));

        indexGeneralTab.add(getPrimaryIndex(), cons.xywh(4, 12, 3, 1));
        indexGeneralTab.add(getUniqueIndex(), cons.xywh(4, 14, 3, 1));
        indexGeneralTab.add(getNotUniqueIndex(), cons.xywh(4, 16, 3, 1));
        indexGeneralTab.add(getSpatialIndex(), cons.xywh(4, 18, 3, 1));
        indexGeneralTab.add(getFulltextIndex(), cons.xywh(4, 20, 3, 1));
        indexGeneralTab.setName("IndexGeneralTab");
    }//from   w  ww. j  ava 2  s.c o m

    return indexGeneralTab;
}

From source file:de.erdesignerng.visual.editor.table.TableEditorView.java

License:Open Source License

public DefaultTabbedPaneTab getTableCommentsTab() {

    if (tableCommentsTab == null) {
        tableCommentsTab = new DefaultTabbedPaneTab(mainTabbedPane, ERDesignerBundle.COMMENTS);

        String rowDef = "2dlu,p,100dlu:grow,p,2dlu";
        String colDef = "2dlu,40dlu:grow,2dlu";

        FormLayout layout = new FormLayout(colDef, rowDef);
        tableCommentsTab.setLayout(layout);

        CellConstraints cons = new CellConstraints();

        tableCommentsTab.add(getEntityComment().getScrollPane(), cons.xywh(2, 2, 1, 3));
        tableCommentsTab.setName("MainCommentsTab");
        tableCommentsTab.setVisible(false);
    }//from  w  w w. j a v a2s .c o  m

    return tableCommentsTab;
}

From source file:de.fhwedel.coinflip.gui.UserInterface.java

private void initComponents() {
    // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
    // Generated using JFormDesigner Evaluation license - Mervyn McCreight
    DefaultComponentFactory compFactory = DefaultComponentFactory.getInstance();
    label1 = compFactory.createLabel("Server IP:");
    ipTextField = new JTextField();
    label2 = compFactory.createLabel("Server Port:");
    portTextField = new JTextField();
    playButton = new JButton();
    protocolProgessBar = new JProgressBar();
    progressLabel = new JLabel();
    separator1 = compFactory.createSeparator("Available Players", SwingConstants.CENTER);
    scrollPane1 = new JScrollPane();
    playerMap = new JTable();
    refreshButton = new JButton();
    CellConstraints cc = new CellConstraints();

    // ======== this ========
    setTitle("SRA CoinFlip Client");
    setResizable(false);/*from ww  w.  ja v a 2  s.co m*/
    Container contentPane = getContentPane();
    contentPane
            .setLayout(new FormLayout("default, $lcgap, 40dlu, $lcgap, 62dlu, $lcgap, 41dlu, $lcgap, default",
                    "8*(default, $lgap), $lgap, 10dlu, default, $lgap, 64dlu, 2*($lgap, default)"));

    // ---- label1 ----
    label1.setText("Server IP:");
    label1.setLabelFor(ipTextField);
    contentPane.add(label1, cc.xy(3, 3, CellConstraints.LEFT, CellConstraints.DEFAULT));

    // ---- ipTextField ----
    ipTextField.setToolTipText("Enter Server-IP here ...");
    contentPane.add(ipTextField, cc.xywh(5, 3, 3, 1));

    // ---- label2 ----
    label2.setLabelFor(portTextField);
    contentPane.add(label2, cc.xy(3, 5, CellConstraints.LEFT, CellConstraints.DEFAULT));

    // ---- portTextField ----
    portTextField.setToolTipText("Enter Server-Port here...");
    contentPane.add(portTextField, cc.xywh(5, 5, 3, 1));

    // ---- playButton ----
    playButton.setText("Play");
    playButton.setFocusable(false);
    playButton.setFocusPainted(false);
    playButton.addActionListener(this::playButtonOnClick);
    contentPane.add(playButton, cc.xy(5, 9));

    // ---- protocolProgessBar ----
    protocolProgessBar.setMaximum(9);
    protocolProgessBar.setStringPainted(true);
    protocolProgessBar.setFocusable(false);
    contentPane.add(protocolProgessBar, cc.xywh(3, 13, 5, 1));

    // ---- progressLabel ----
    progressLabel.setText("Waiting...");
    progressLabel.setFont(UIManager.getFont("Label.font"));
    progressLabel.setHorizontalAlignment(SwingConstants.CENTER);
    contentPane.add(progressLabel, cc.xywh(3, 15, 6, 1));
    contentPane.add(separator1, cc.xywh(1, 18, 9, 1));

    // ======== scrollPane1 ========
    {

        // ---- playerMap ----
        playerMap.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        playerMap.setShowVerticalLines(false);
        playerMap.setShowHorizontalLines(false);
        scrollPane1.setViewportView(playerMap);
    }
    contentPane.add(scrollPane1, cc.xywh(3, 21, 5, 1));

    // ---- refreshButton ----
    refreshButton.setText("Refresh");
    refreshButton.addActionListener(this::refreshButtonClick);
    contentPane.add(refreshButton, cc.xy(5, 23));
    pack();
    setLocationRelativeTo(getOwner());
    // JFormDesigner - End of component initialization //GEN-END:initComponents
}

From source file:demo.JXPickerDemoForm.java

License:Open Source License

private void initComponents() {
    // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
    DefaultComponentFactory compFactory = DefaultComponentFactory.getInstance();
    label7 = new JLabel();
    panel1 = new JPanel();
    lookAndFeelMetal = new JRadioButton();
    lookAndFeelSystem = new JRadioButton();
    lookAndFeelMotif = new JRadioButton();
    lookAndFeelGoodies = new JRadioButton();
    goodiesFormsSeparator1 = compFactory.createSeparator("");
    label1 = new JLabel();
    comboBox1 = new JComboBox();
    label2 = new JLabel();
    listPicker = new JXPicker();
    label3 = new JLabel();
    treePicker = new JXPicker();
    label5 = new JLabel();
    xDatePicker1 = new JXDatePicker();
    label4 = new JLabel();
    datePicker = new JXPicker();
    label6 = new JLabel();
    scrollPane1 = new JScrollPane();
    table = new JTable();
    aListScrollPane = new JScrollPane();
    list = new JList();
    monthView = new JXMonthView();
    aTableEditorScrollPane = new JScrollPane();
    tableEditorTree = new JTree();
    tableEditorPicker = new JXPicker();
    aTreeScrollPane = new JScrollPane();
    tree = new JTree();
    CellConstraints cc = new CellConstraints();

    //======== this ========
    setBorder(Borders.DLU7_BORDER);/*from w  w w .  j  av a  2  s.  c  o  m*/
    setLayout(new FormLayout(
            new ColumnSpec[] { new ColumnSpec(ColumnSpec.RIGHT, Sizes.DEFAULT, FormSpec.NO_GROW),
                    FormFactory.UNRELATED_GAP_COLSPEC, new ColumnSpec("max(default;150dlu):grow") },
            new RowSpec[] { FormFactory.DEFAULT_ROWSPEC, FormFactory.LINE_GAP_ROWSPEC,
                    FormFactory.DEFAULT_ROWSPEC, FormFactory.UNRELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
                    FormFactory.UNRELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
                    FormFactory.UNRELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
                    FormFactory.UNRELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
                    FormFactory.UNRELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
                    FormFactory.UNRELATED_GAP_ROWSPEC,
                    new RowSpec(RowSpec.FILL, Sizes.DEFAULT, FormSpec.DEFAULT_GROW) }));

    //---- label7 ----
    label7.setText("Look and Feel:");
    add(label7, cc.xy(1, 1));

    //======== panel1 ========
    {
        panel1.setLayout(new FormLayout(new ColumnSpec[] { FormFactory.DEFAULT_COLSPEC,
                FormFactory.UNRELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
                FormFactory.UNRELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
                FormFactory.UNRELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC },
                RowSpec.decodeSpecs("default")));

        //---- lookAndFeelMetal ----
        lookAndFeelMetal.setText("Metal");
        lookAndFeelMetal.setSelected(true);
        panel1.add(lookAndFeelMetal, cc.xy(1, 1));

        //---- lookAndFeelSystem ----
        lookAndFeelSystem.setText("System");
        panel1.add(lookAndFeelSystem, cc.xy(3, 1));

        //---- lookAndFeelMotif ----
        lookAndFeelMotif.setText("Motif");
        panel1.add(lookAndFeelMotif, cc.xy(5, 1));

        //---- lookAndFeelGoodies ----
        lookAndFeelGoodies.setText("JGoodies Plastic XP");
        panel1.add(lookAndFeelGoodies, cc.xy(7, 1));
    }
    add(panel1, cc.xy(3, 1));
    add(goodiesFormsSeparator1, cc.xywh(1, 3, 3, 1));

    //---- label1 ----
    label1.setText("JComboBox:");
    add(label1, cc.xy(1, 5));

    //---- comboBox1 ----
    comboBox1.setModel(new DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3" }));
    add(comboBox1, cc.xy(3, 5));

    //---- label2 ----
    label2.setText("JXPicker w/ JList:");
    add(label2, cc.xy(1, 7));

    //---- listPicker ----
    listPicker.setPopupComponent(aListScrollPane);
    add(listPicker, cc.xy(3, 7));

    //---- label3 ----
    label3.setText("JXPicker w/ JTree:");
    add(label3, cc.xy(1, 9));

    //---- treePicker ----
    treePicker.setPopupComponent(aTreeScrollPane);
    add(treePicker, cc.xy(3, 9));

    //---- label5 ----
    label5.setText("JXDatePicker:");
    add(label5, cc.xy(1, 11));
    add(xDatePicker1, cc.xy(3, 11));

    //---- label4 ----
    label4.setText("JXPicker w/ JXMonthView:");
    add(label4, cc.xy(1, 13));

    //---- datePicker ----
    datePicker.setPopupComponent(monthView);
    add(datePicker, cc.xy(3, 13));

    //---- label6 ----
    label6.setText("JTable w/ JXPicker Cell Editor");
    add(label6, cc.xy(1, 15));

    //======== scrollPane1 ========
    {

        //---- table ----
        table.setModel(
                new DefaultTableModel(new Object[][] { { null }, { null }, { null }, }, new String[] { null }));
        table.setPreferredScrollableViewportSize(new Dimension(0, 50));
        scrollPane1.setViewportView(table);
    }
    add(scrollPane1, cc.xy(3, 15));

    //======== aListScrollPane ========
    {
        aListScrollPane.setBackground(null);
        aListScrollPane.setFocusable(false);

        //---- list ----
        list.setModel(new AbstractListModel() {
            String[] values = { "Item 1", "Item 2", "Item 3" };

            public int getSize() {
                return values.length;
            }

            public Object getElementAt(int i) {
                return values[i];
            }
        });
        list.setFocusable(false);
        list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        aListScrollPane.setViewportView(list);
    }

    //---- monthView ----
    monthView.setFocusable(false);
    monthView.setBorder(LineBorder.createBlackLineBorder());

    //======== aTableEditorScrollPane ========
    {
        aTableEditorScrollPane.setViewportView(tableEditorTree);
    }

    //---- tableEditorPicker ----
    tableEditorPicker.setPopupComponent(aTableEditorScrollPane);

    //======== aTreeScrollPane ========
    {
        aTreeScrollPane.setViewportView(tree);
    }

    //---- buttonGroup1 ----
    ButtonGroup buttonGroup1 = new ButtonGroup();
    buttonGroup1.add(lookAndFeelMetal);
    buttonGroup1.add(lookAndFeelSystem);
    buttonGroup1.add(lookAndFeelMotif);
    buttonGroup1.add(lookAndFeelGoodies);
    // JFormDesigner - End of component initialization  //GEN-END:initComponents
}

From source file:edu.byu.plugins.editors.dialogs.BYU_ResourceLookup.java

License:Open Source License

private void initComponents() {
    // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
    // Generated using JFormDesigner non-commercial license
    dialogPane = new JPanel();
    HeaderPanel = new JPanel();
    mainHeaderPanel = new JPanel();
    mainHeaderLabel = new JLabel();
    panel3 = new JPanel();
    subHeaderLabel = new JLabel();
    contentPane = new JPanel();
    label3 = new JLabel();
    label4 = new JLabel();
    scrollPane1 = new JScrollPane();
    lookupTable = new DomainSortableTable(Resources.class, filterField);
    label1 = new JLabel();
    filterField = new JTextField();
    buttonBar = new JPanel();
    select = new JButton();
    linkButton = new JButton();
    createButton = new JButton();
    doneButton = new JButton();
    CellConstraints cc = new CellConstraints();

    //======== this ========
    setModal(true);//from   w w  w .  j  av a 2  s .  co m
    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            thisWindowClosing();
        }
    });
    Container contentPane2 = getContentPane();
    contentPane2.setLayout(new BorderLayout());

    //======== dialogPane ========
    {
        dialogPane.setBorder(null);
        dialogPane.setBackground(new Color(200, 205, 232));
        dialogPane.setLayout(new BorderLayout());

        //======== HeaderPanel ========
        {
            HeaderPanel.setBackground(new Color(80, 69, 57));
            HeaderPanel.setOpaque(false);
            HeaderPanel.setFont(new Font("Trebuchet MS", Font.PLAIN, 13));
            HeaderPanel
                    .setLayout(new FormLayout(
                            new ColumnSpec[] {
                                    new ColumnSpec(
                                            Sizes.bounded(Sizes.MINIMUM, Sizes.dluX(100), Sizes.dluX(200))),
                                    new ColumnSpec(ColumnSpec.FILL, Sizes.DEFAULT, FormSpec.DEFAULT_GROW) },
                            RowSpec.decodeSpecs("default")));

            //======== mainHeaderPanel ========
            {
                mainHeaderPanel.setBackground(new Color(80, 35, 45));
                mainHeaderPanel.setFont(new Font("Trebuchet MS", Font.PLAIN, 13));
                mainHeaderPanel
                        .setLayout(
                                new FormLayout(
                                        new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC,
                                                new ColumnSpec(ColumnSpec.FILL, Sizes.DEFAULT,
                                                        FormSpec.DEFAULT_GROW) },
                                        new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC,
                                                FormFactory.DEFAULT_ROWSPEC,
                                                FormFactory.RELATED_GAP_ROWSPEC }));

                //---- mainHeaderLabel ----
                mainHeaderLabel.setText("Main Header");
                mainHeaderLabel.setFont(new Font("Trebuchet MS", Font.PLAIN, 18));
                mainHeaderLabel.setForeground(Color.white);
                mainHeaderPanel.add(mainHeaderLabel, cc.xy(2, 2));
            }
            HeaderPanel.add(mainHeaderPanel, cc.xy(1, 1));

            //======== panel3 ========
            {
                panel3.setBackground(new Color(66, 60, 111));
                panel3.setFont(new Font("Trebuchet MS", Font.PLAIN, 13));
                panel3.setLayout(new FormLayout(
                        new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC,
                                new ColumnSpec(ColumnSpec.FILL, Sizes.DEFAULT, FormSpec.DEFAULT_GROW),
                                FormFactory.UNRELATED_GAP_COLSPEC },
                        new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
                                FormFactory.RELATED_GAP_ROWSPEC }));

                //---- subHeaderLabel ----
                subHeaderLabel.setText("Lookup Resource");
                subHeaderLabel.setFont(new Font("Trebuchet MS", Font.PLAIN, 18));
                subHeaderLabel.setForeground(Color.white);
                panel3.add(subHeaderLabel, cc.xy(2, 2));
            }
            HeaderPanel.add(panel3, cc.xy(2, 1));
        }
        dialogPane.add(HeaderPanel, BorderLayout.NORTH);

        //======== contentPane ========
        {
            contentPane.setBackground(new Color(231, 188, 251));
            contentPane.setOpaque(false);
            contentPane
                    .setLayout(
                            new FormLayout(
                                    new ColumnSpec[] { FormFactory.UNRELATED_GAP_COLSPEC,
                                            FormFactory.DEFAULT_COLSPEC,
                                            FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
                                            new ColumnSpec(ColumnSpec.FILL, Sizes.DEFAULT,
                                                    FormSpec.DEFAULT_GROW),
                                            FormFactory.UNRELATED_GAP_COLSPEC },
                                    new RowSpec[] { FormFactory.UNRELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.LINE_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.LINE_GAP_ROWSPEC,
                                            new RowSpec(RowSpec.FILL, Sizes.DEFAULT, FormSpec.DEFAULT_GROW),
                                            FormFactory.LINE_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
                                            FormFactory.LINE_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
                                            FormFactory.UNRELATED_GAP_ROWSPEC }));

            //---- label3 ----
            label3.setText("Double click on a Resource to select it.");
            contentPane.add(label3, cc.xywh(2, 2, 3, 1));

            //---- label4 ----
            label4.setText("Or hit enter if a Resource is highlighted.");
            contentPane.add(label4, cc.xywh(2, 4, 3, 1));

            //======== scrollPane1 ========
            {
                scrollPane1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

                //---- lookupTable ----
                lookupTable.setPreferredScrollableViewportSize(new Dimension(450, 300));
                lookupTable.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent e) {
                        lookupTableMouseClicked(e);
                    }
                });
                lookupTable.addKeyListener(new KeyAdapter() {
                    @Override
                    public void keyTyped(KeyEvent e) {
                        lookupTableKeyTyped(e);
                    }
                });
                scrollPane1.setViewportView(lookupTable);
            }
            contentPane.add(scrollPane1, cc.xywh(2, 6, 3, 1));

            //---- label1 ----
            label1.setText("Filter:");
            contentPane.add(label1, cc.xy(2, 8));
            contentPane.add(filterField, cc.xy(4, 8));

            //======== buttonBar ========
            {
                buttonBar.setBorder(Borders.BUTTON_BAR_GAP_BORDER);
                buttonBar.setBackground(new Color(231, 188, 251));
                buttonBar.setOpaque(false);
                buttonBar
                        .setLayout(new FormLayout(
                                new ColumnSpec[] { FormFactory.DEFAULT_COLSPEC,
                                        FormFactory.LABEL_COMPONENT_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
                                        FormFactory.LABEL_COMPONENT_GAP_COLSPEC, FormFactory.BUTTON_COLSPEC,
                                        FormFactory.RELATED_GAP_COLSPEC, FormFactory.BUTTON_COLSPEC },
                                RowSpec.decodeSpecs("pref")));

                //---- select ----
                select.setText("Select");
                select.setOpaque(false);
                select.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        selectActionPerformed();
                    }
                });
                buttonBar.add(select, cc.xy(1, 1));

                //---- linkButton ----
                linkButton.setText("Link");
                linkButton.setOpaque(false);
                linkButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        linkButtonActionPerformed();
                    }
                });
                buttonBar.add(linkButton, cc.xy(3, 1));

                //---- createButton ----
                createButton.setText("Create Resource");
                createButton.setOpaque(false);
                createButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        createButtonActionPerformed(e);
                    }
                });
                buttonBar.add(createButton, cc.xy(5, 1));

                //---- doneButton ----
                doneButton.setText("Close Window");
                doneButton.setOpaque(false);
                doneButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        doneButtonActionPerformed(e);
                    }
                });
                buttonBar.add(doneButton, cc.xy(7, 1));
            }
            contentPane.add(buttonBar, cc.xywh(2, 10, 3, 1, CellConstraints.RIGHT, CellConstraints.DEFAULT));
        }
        dialogPane.add(contentPane, BorderLayout.CENTER);
    }
    contentPane2.add(dialogPane, BorderLayout.CENTER);
    pack();
    setLocationRelativeTo(getOwner());
    // JFormDesigner - End of component initialization  //GEN-END:initComponents
}

From source file:edu.ku.brc.af.auth.UserAndMasterPasswordMgr.java

License:Open Source License

/**
 * Displays a dialog used for editing the Master Username and Password.
 * @param isLocal whether u/p is stored locally or not
 * @param usrName//ww  w  .  jav  a 2 s.c  o m
 * @param dbName
 * @param masterPath the path to the password
 * @return whether to ask for the information because it wasn't found
 */
protected boolean askForInfo(final Boolean isLocal, final String usrName, final String dbName,
        final String masterPath) {
    loadAndPushResourceBundle("masterusrpwd");

    FormLayout layout = new FormLayout("p, 2px, f:p:g, 4px, p, 4px, p, 4px, p", "p,2px,p,2px,p,2dlu,p,2dlu,p");

    PanelBuilder pb = new PanelBuilder(layout);
    pb.setDefaultDialogBorder();

    ButtonGroup group = new ButtonGroup();
    final JRadioButton isNetworkRB = new JRadioButton(getResourceString("IS_NET_BASED"));
    final JRadioButton isPrefBasedRB = new JRadioButton(getResourceString("IS_ENCRYPTED_KEY"));
    isPrefBasedRB.setSelected(true);
    group.add(isNetworkRB);
    group.add(isPrefBasedRB);

    final JTextField keyTxt = createTextField(35);
    final JTextField urlTxt = createTextField(35);
    final JLabel keyLbl = createI18NFormLabel("ENCRYPTED_USRPWD");
    final JLabel urlLbl = createI18NFormLabel("URL");
    final JButton createBtn = createI18NButton("CREATE_KEY");

    final JButton copyCBBtn = createIconBtn("ClipboardCopy", IconManager.IconSize.Std24, "CPY_TO_CB_TT", null);
    final JButton pasteCBBtn = createIconBtn("ClipboardPaste", IconManager.IconSize.Std24, "CPY_FROM_CB_TT",
            null);

    // retrieves the encrypted key for the current settings in the dialog
    String dbNameFromForm = AppPreferences.getLocalPrefs().get("login.databases_selected", null);
    if (isNotEmpty(dbNameFromForm) && isNotEmpty(usersUserName)) {
        String masterKey = getMasterPrefPath(usersUserName, dbNameFromForm, true);
        if (isNotEmpty(masterKey)) {
            String encryptedKey = AppPreferences.getLocalPrefs().get(masterKey, null);
            if (isNotEmpty(encryptedKey) && !encryptedKey.startsWith("http")) {
                keyTxt.setText(encryptedKey);
            }
        }
    }

    CellConstraints cc = new CellConstraints();

    int y = 1;
    pb.add(createI18NFormLabel("MASTER_LOC"), cc.xywh(1, y, 1, 3));
    pb.add(isPrefBasedRB, cc.xy(3, y));
    y += 2;
    pb.add(isNetworkRB, cc.xy(3, y));
    y += 2;

    pb.addSeparator("", cc.xyw(1, y, 9));
    y += 2;
    pb.add(keyLbl, cc.xy(1, y));
    pb.add(keyTxt, cc.xy(3, y));
    pb.add(createBtn, cc.xy(5, y));
    pb.add(copyCBBtn, cc.xy(7, y));
    pb.add(pasteCBBtn, cc.xy(9, y));
    y += 2;

    pb.add(urlLbl, cc.xy(1, y));
    pb.add(urlTxt, cc.xy(3, y));
    y += 2;

    boolean isEditMode = isLocal != null && isNotEmpty(masterPath);
    if (isEditMode) {
        isPrefBasedRB.setSelected(isLocal);
        if (isLocal) {
            keyTxt.setText(masterPath);
        } else {
            urlTxt.setText(masterPath);
        }
    }

    copyCBBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            // Copy to Clipboard
            UIHelper.setTextToClipboard(keyTxt.getText());
        }
    });

    pasteCBBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            keyTxt.setText(UIHelper.getTextFromClipboard());
        }
    });

    final CustomDialog dlg = new CustomDialog((Frame) null, getResourceString("MASTER_TITLE"), true,
            CustomDialog.OKCANCELHELP, pb.getPanel());
    if (!isEditMode) {
        dlg.setOkLabel(getResourceString("CONT"));
        dlg.setCancelLabel(getResourceString("BACK"));
    }
    dlg.setHelpContext("MASTERPWD_MAIN");
    dlg.createUI();
    dlg.getOkBtn().setEnabled(false);
    urlLbl.setEnabled(false);
    urlTxt.setEnabled(false);
    copyCBBtn.setEnabled(true);
    pasteCBBtn.setEnabled(true);

    DocumentListener dl = new DocumentAdaptor() {
        @Override
        protected void changed(DocumentEvent e) {
            dlg.getOkBtn().setEnabled((isPrefBasedRB.isSelected() && !keyTxt.getText().isEmpty())
                    || (isNetworkRB.isSelected() && !urlTxt.getText().isEmpty()));
        }
    };
    keyTxt.getDocument().addDocumentListener(dl);
    urlTxt.getDocument().addDocumentListener(dl);

    ChangeListener chgListener = new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            boolean isNet = isNetworkRB.isSelected();
            keyLbl.setEnabled(!isNet);
            keyTxt.setEnabled(!isNet);
            createBtn.setEnabled(!isNet);
            copyCBBtn.setEnabled(!isNet);
            pasteCBBtn.setEnabled(!isNet);
            urlLbl.setEnabled(isNet);
            urlTxt.setEnabled(isNet);
            dlg.getOkBtn().setEnabled((isPrefBasedRB.isSelected() && !keyTxt.getText().isEmpty())
                    || (isNetworkRB.isSelected() && !urlTxt.getText().isEmpty()));
        }
    };

    isNetworkRB.addChangeListener(chgListener);
    isPrefBasedRB.addChangeListener(chgListener);

    boolean isPref = AppPreferences.getLocalPrefs().getBoolean(getIsLocalPrefPath(usrName, dbName, true), true);
    isNetworkRB.setSelected(!isPref);
    isPrefBasedRB.setSelected(isPref);

    createBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String[] keys = getUserNamePasswordKey();
            if (keys != null && keys.length == 4) {
                String encryptedStr = encrypt(keys[0], keys[1], keys[3]);
                if (encryptedStr != null) {
                    keyTxt.setText(encryptedStr);
                    dlg.getOkBtn().setEnabled(true);

                    usersUserName = keys[2];
                }
            }
        }
    });

    popResourceBundle();

    dlg.setVisible(true);

    if (!dlg.isCancelled()) {
        String value;
        if (isNetworkRB.isSelected()) {
            value = StringEscapeUtils.escapeHtml(urlTxt.getText());
        } else {
            value = keyTxt.getText();
        }

        AppPreferences.getLocalPrefs().putBoolean(getIsLocalPrefPath(usrName, dbName, true),
                !isNetworkRB.isSelected());
        AppPreferences.getLocalPrefs().put(getMasterPrefPath(usrName, dbName, true), value);
        return true;
    }
    return false;
}

From source file:edu.ku.brc.af.core.expresssearch.RelatedTableInfoPanel.java

License:Open Source License

/**
 * //from   ww w .j  av a  2s  . c  o  m
 */
protected void createUI() {
    setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));

    relatedTablesList = new JList(relatedTablesModel);
    TableNameRenderer nameRender = new TableNameRenderer(IconManager.IconSize.Std24);
    nameRender.setUseIcon("PlaceHolder"); //$NON-NLS-1$
    relatedTablesList.setCellRenderer(nameRender);

    CellConstraints cc = new CellConstraints();
    PanelBuilder pb = new PanelBuilder(new FormLayout("p:g,8px,p,2px,f:p:g", //$NON-NLS-1$
            "p,2px,p,2px,p,2px,t:p:g,f:p:g,2px,p"), this); //$NON-NLS-1$
    //pb.add(createI18NLabel("ES_RELATED_ACTIVATE"), cc.xy(1, 1));

    JScrollPane sp = new JScrollPane(relatedTablesList, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    pb.add(createI18NLabel("RelatedTableInfoPanel.ES_RELATED_SEARCHES"), cc.xy(1, 1)); //$NON-NLS-1$
    pb.add(sp, cc.xywh(1, 3, 1, 6));

    activeCBX = createCheckBox("                      "); //$NON-NLS-1$
    pb.add(activeLbl = createI18NLabel("RelatedTableInfoPanel.ES_RELATED_ACTIVATE", SwingConstants.RIGHT), //$NON-NLS-1$
            cc.xy(3, 3));
    pb.add(activeCBX, cc.xy(5, 3));

    relatedTableDescTA = new JTextArea(8, 40);
    relatedTableDescTA.setEditable(false);
    relatedTableDescTA.setWrapStyleWord(true);
    relatedTableDescTA.setBackground(Color.WHITE);
    relatedTableDescTA.setLineWrap(true);
    sp = new JScrollPane(relatedTableDescTA, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    pb.add(descLbl = createI18NLabel("RelatedTableInfoPanel.ES_RELATED_DESC", SwingConstants.RIGHT), //$NON-NLS-1$
            cc.xy(3, 5));
    pb.add(sp, cc.xy(5, 5));

    PanelBuilder btnPB = new PanelBuilder(new FormLayout("p,f:p:g,p", "p")); //$NON-NLS-1$ //$NON-NLS-2$
    selectAllBtn = createButton(getResourceString("RelatedTableInfoPanel.SELECTALL")); //$NON-NLS-1$
    deselectAllBtn = createButton(getResourceString("RelatedTableInfoPanel.DESELECTALL")); //$NON-NLS-1$
    btnPB.add(selectAllBtn, cc.xy(1, 1));
    btnPB.add(deselectAllBtn, cc.xy(3, 1));
    pb.add(btnPB.getPanel(), cc.xy(1, 10));

    activeCBX.addChangeListener(new ChangeListener() {

        /* (non-Javadoc)
         * @see javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent)
         */
        public void stateChanged(ChangeEvent e) {
            RelatedQuery rq = (RelatedQuery) relatedTablesList.getSelectedValue();
            if (rq != null) {
                rq.setIsActive(activeCBX.isSelected());
                relatedTablesList.repaint();
            }
        }
    });

    relatedTablesList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        //@Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                rtRelatedTableSelected();
                updateEnableUI();
            }
        }
    });

    selectAllBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setAllActive(true);
        }

    });

    deselectAllBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setAllActive(false);
        }

    });

    updateEnableUI();
}

From source file:edu.ku.brc.af.tasks.subpane.formeditor.RowColDefPanel.java

License:Open Source License

protected void createUI(final int numInUse, @SuppressWarnings("hiding") final boolean isRow) {
    CellConstraints cc = new CellConstraints();
    PanelBuilder pb = new PanelBuilder(new FormLayout("max(125px;p):g,16px,p", "p,2px,p,2px,p:g")); //$NON-NLS-1$ //$NON-NLS-2$

    propsPanel = new DefItemPropPanel(numInUse, isRow);

    ActionListener addAL = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            addItem();// ww w. ja va  2 s .  co  m
        }
    };

    ActionListener delAL = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            delItem();
        }
    };

    controlPanel = new EditDeleteAddPanel(null, delAL, addAL);
    controlPanel.getAddBtn().setEnabled(true);

    itemList = new JList(new DefaultListModel());
    itemList.setCellRenderer(new DefItemRenderer(IconManager.IconSize.Std16));
    JScrollPane sp = UIHelper.createScrollPane(itemList);
    pb.addSeparator((isRow ? "Row" : "Column") + " Items", cc.xy(1, 1)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    pb.add(sp, cc.xy(1, 3));
    pb.add(controlPanel, cc.xy(1, 5));

    pb.addSeparator("Properties", cc.xy(3, 1)); //$NON-NLS-1$
    pb.add(propsPanel, cc.xywh(3, 3, 1, 3));

    itemList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                itemSelected();
            }
        }
    });

    add(pb.getPanel(), BorderLayout.CENTER);
}

From source file:edu.ku.brc.af.tasks.subpane.formeditor.ViewSetSelectorPanel.java

License:Open Source License

/**
 * /*from  w w  w. j  a va  2  s . c  o  m*/
 */
@SuppressWarnings("unchecked") //$NON-NLS-1$
public ViewSetSelectorPanel(final BasicFormPreviewPanel previewPanel) {
    this.previewPanel = previewPanel;

    Vector<String> levelsVec = new Vector<String>();
    SpecifyUser user = AppContextMgr.getInstance().getClassObject(SpecifyUser.class);
    @SuppressWarnings("unused")
    Hashtable<Discipline, Boolean> usedColTypes = new Hashtable<Discipline, Boolean>();

    levelsVec.add(user.getUserType());

    //        for (Agent agent : user.getAgents())
    //        {
    //            // XXX Commented Out
    //            /*Discipline ct = agent.getDiscipline();
    //            if (usedColTypes.get(ct) == null)
    //            {
    //                levelsVec.add(ct.getName());
    //                usedColTypes.put(ct, true);
    //            }*/
    //        }
    levelsVec.add("BackStop"); //$NON-NLS-1$

    addBtn = UIHelper.createIconBtn("PlusSign", "", new ActionListener() { //$NON-NLS-1$ //$NON-NLS-2$
        public void actionPerformed(ActionEvent arg0) {
            addControl();
        }
    });

    delBtn = UIHelper.createIconBtn("MinusSign", "", new ActionListener() { //$NON-NLS-1$ //$NON-NLS-2$
        public void actionPerformed(ActionEvent arg0) {
            delControl(TYPE.SelectedObj);
        }
    });

    ActionListener addViewAL = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            addView();
        }
    };

    ActionListener delViewAL = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            delView();
        }
    };

    viewControlPanel = new EditDeleteAddPanel(null, delViewAL, addViewAL);

    ActionListener addAltViewAL = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            addAltView();
        }
    };

    ActionListener delAltViewAL = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            delAltView();
        }
    };

    altViewControlPanel = new EditDeleteAddPanel(null, delAltViewAL, addAltViewAL);

    ActionListener addDefViewAL = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            addViewDef();
        }
    };

    ActionListener delDefViewAL = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            delViewDef();
        }
    };

    viewDefControlPanel = new EditDeleteAddPanel(null, delDefViewAL, addDefViewAL);

    ActionListener saveAL = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            save();
        }
    };
    EditDeleteAddPanel saveControlPanel = new EditDeleteAddPanel(null, null, saveAL);
    saveControlPanel.getAddBtn().setIcon(IconManager.getIcon("Save", IconManager.IconSize.Std16)); //$NON-NLS-1$
    saveControlPanel.getAddBtn().setEnabled(true);

    setLayout(new BorderLayout());

    levelsList = new JList(levelsVec);
    panel = new EditorPropPanel(controlHash, subcontrolHash, null, true, this);
    //panel.setFormViewDef(null);

    PanelBuilder pb = new PanelBuilder(new FormLayout("p,4px,p, 6px,10px,6px, p,6px,p, 6px,10px,6px, p,f:p:g", //$NON-NLS-1$
            "p,2px,f:p:g,2px,p,10px,p,4px")); //$NON-NLS-1$
    CellConstraints cc = new CellConstraints();

    String[] labels = new String[] { "User Level", "ViewSets", " ", "Views", "AltViews", " ", "View Defs" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
    int x = 1;
    for (String label : labels) {
        pb.add(createLabel(label, SwingConstants.CENTER), cc.xy(x, 1));
        x += 2;
    }

    Color vsFGColor = new Color(224, 224, 224);
    Color vsBGColor = new Color(124, 124, 124);

    Dimension ps = new Dimension(200, 150);

    x = 1;
    JScrollPane sp = createScrollPane(levelsList);
    pb.add(sp, cc.xy(x, 3));
    x += 2;

    viewSetsList = new JList(new DefaultListModel());
    sp = createScrollPane(viewSetsList);
    sp.setPreferredSize(ps);
    pb.add(sp, cc.xy(x, 3));
    x += 2;

    pb.add(new VerticalSeparator(vsFGColor, vsBGColor), cc.xy(x, 3));
    x += 2;

    viewsList = new JList(new DefaultListModel());
    sp = new JScrollPane(viewsList, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    sp.setPreferredSize(ps);
    pb.add(sp, cc.xy(x, 3));
    x += 2;

    altViewsList = new JList(new DefaultListModel());
    sp = createScrollPane(altViewsList);
    sp.setPreferredSize(ps);
    pb.add(sp, cc.xy(x, 3));
    x += 2;

    pb.add(new VerticalSeparator(vsFGColor, vsBGColor), cc.xy(x, 3));
    x += 2;

    viewDefsList = new JList(new DefaultListModel());
    sp = createScrollPane(viewDefsList);
    sp.setPreferredSize(ps);
    pb.add(sp, cc.xy(x, 3));
    x += 2;

    pb.add(saveControlPanel, cc.xy(1, 5));
    //pb.add(createLabel(" "),     cc.xy(3, 5));
    //pb.add(createLabel(" "),     cc.xy(5, 5));
    pb.add(viewControlPanel, cc.xy(7, 5));
    pb.add(altViewControlPanel, cc.xy(9, 5));
    //pb.add(createLabel(" "),     cc.xy(11, 5));
    pb.add(viewDefControlPanel, cc.xy(13, 5));

    pb.addSeparator("View Def Editor", cc.xywh(1, 7, 13, 1)); //$NON-NLS-1$

    add(pb.getPanel(), BorderLayout.NORTH);

    pb = new PanelBuilder(new FormLayout("max(250px;p),4px,f:p:g", "t:p")); //$NON-NLS-1$ //$NON-NLS-2$

    PanelBuilder inner = new PanelBuilder(new FormLayout("max(250px;p)", "t:p,2px,t:p")); //$NON-NLS-1$ //$NON-NLS-2$
    tree = new JTree();
    ((DefaultTreeModel) tree.getModel()).setRoot(null);
    sp = createScrollPane(tree);
    inner.add(sp, cc.xy(1, 1));

    PanelBuilder btnPb = new PanelBuilder(new FormLayout("f:p:g,p,2px,p", "p")); //$NON-NLS-1$ //$NON-NLS-2$
    btnPb.add(delBtn, cc.xy(2, 1));
    btnPb.add(addBtn, cc.xy(4, 1));
    inner.add(btnPb.getPanel(), cc.xy(1, 3));

    pb.add(inner.getPanel(), cc.xy(1, 1));
    pb.add(panel, cc.xy(3, 1));

    add(pb.getPanel(), BorderLayout.CENTER);

    tree.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent e) {
            treeSelected();
        }
    });

    levelsList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                levelSelected();
            }
        }
    });

    viewSetsList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                viewSetSelected();
            }
        }
    });

    viewsList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                viewSelected();
            }
        }
    });

    altViewsList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                altViewSelected();
            }
        }
    });

    viewDefsList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                viewDefSelected();
            }
        }
    });

    tree.addMouseListener(new MouseAdapter() {

        protected void doPopup(MouseEvent e) {
            if (e.isPopupTrigger()) {
                int xc = e.getX();
                int yc = e.getY();
                TreePath path = tree.getPathForLocation(xc, yc);
                if (path != null) {
                    tree.setSelectionPath(path);
                }

                treeSelected();

                DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree.getSelectionModel()
                        .getSelectionPath().getLastPathComponent();

                if (selectedCell != null || selectedRow != null) {
                    new TreePopupMenu((Component) e.getSource(), e, selectedCell);

                } else if (selectedNode.getUserObject() instanceof FormViewDef) {
                    new TreePopupMenu((Component) e.getSource(), e);
                }
            }
        }

        public void mouseReleased(MouseEvent e) {
            doPopup(e);
        }

        public void mousePressed(MouseEvent e) {
            doPopup(e);
        }
    });

    XStream xstream = new XStream();
    xstream.alias("control", Control.class); //$NON-NLS-1$
    xstream.useAttributeFor(Control.class, "type"); //$NON-NLS-1$
    xstream.useAttributeFor(Attr.class, "type"); //$NON-NLS-1$
    xstream.useAttributeFor(Attr.class, "name"); //$NON-NLS-1$
    xstream.useAttributeFor(Attr.class, "required"); //$NON-NLS-1$
    xstream.useAttributeFor(Attr.class, "defaultValue"); //$NON-NLS-1$
    xstream.aliasAttribute("default", "defaultValue"); //$NON-NLS-1$ //$NON-NLS-2$

    xstream.alias("uicontrols", Vector.class); //$NON-NLS-1$
    xstream.alias("attr", Attr.class); //$NON-NLS-1$
    xstream.alias("param", Param.class); //$NON-NLS-1$
    xstream.alias("subcontrol", SubControl.class); //$NON-NLS-1$
    xstream.aliasAttribute("desc", "desc"); //$NON-NLS-1$ //$NON-NLS-2$
    xstream.aliasAttribute(Attr.class, "values", "values"); //$NON-NLS-1$ //$NON-NLS-2$
    xstream.useAttributeFor(SubControl.class, "type"); //$NON-NLS-1$

    try {
        controls = (Vector<Control>) xstream.fromXML(FileUtils.readFileToString(new File("UIControls.xml"))); //$NON-NLS-1$
        for (Control control : controls) {
            controlHash.put(control.getType(), control);
            if (control.getSubcontrols() != null) {
                for (SubControl sc : control.getSubcontrols()) {
                    //System.out.println(" ["+sc.getType()+"]  ");
                    subcontrolHash.put(sc.getType(), sc);
                }
            }
        }

    } catch (IOException ex) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ViewSetSelectorPanel.class, ex);
        ex.printStackTrace();
    }
}

From source file:edu.ku.brc.af.tasks.subpane.StatsPane.java

License:Open Source License

/**
 * Loads all the panels.//from ww w .j a  va  2 s  .c  o m
 */
protected void init() {
    JComponent parentComp = upperDisplayComp != null ? upperDisplayComp : this;
    for (Component c : comps) {
        parentComp.remove(c);
    }
    comps.clear();

    if (centerPanel != null) {
        remove(centerPanel);
    }

    Element rootElement = null;
    try {
        rootElement = AppContextMgr.getInstance().getResourceAsDOM(resourceName);
        if (rootElement == null) {
            throw new RuntimeException("Couldn't find resource [" + resourceName + "]"); //$NON-NLS-1$ //$NON-NLS-2$
        }

        // count up rows and column
        StringBuilder rowsDef = new StringBuilder(128);

        boolean hasResBundle = false;
        Element panelEl = (Element) rootElement.selectObject("/panel");
        String resBundleName = XMLHelper.getAttr(panelEl, "resource", null);
        if (StringUtils.isNotEmpty(resBundleName)) {
            hasResBundle = true;
            UIRegistry.loadAndPushResourceBundle(resBundleName);
        }

        List<?> rows = rootElement.selectNodes("/panel/row"); //$NON-NLS-1$
        int maxCols = 0;
        for (Object obj : rows) {
            Element rowElement = (Element) obj;
            List<?> boxes = rowElement.selectNodes("box"); //$NON-NLS-1$
            maxCols = Math.max(maxCols, boxes.size());
            if (rowsDef.length() > 0) {
                rowsDef.append(",15dlu,"); //$NON-NLS-1$
            }
            rowsDef.append("top:p"); //$NON-NLS-1$
        }

        int preferredWidth = PREFERREDWIDTH;
        int spacing = SPACING;

        String colDefs = createDuplicateJGoodiesDef("f:min(" + preferredWidth + "px;p)", spacing + "px", //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
                maxCols);
        FormLayout formLayout = new FormLayout(colDefs, rowsDef.toString());
        PanelBuilder builder = new PanelBuilder(formLayout);
        CellConstraints cc = new CellConstraints();

        int y = 1;
        for (Object obj : rows) {
            Element rowElement = (Element) obj;

            int x = 1;
            List<?> boxes = rowElement.selectNodes("box"); //$NON-NLS-1$
            for (Object bo : boxes) {
                Element boxElement = (Element) bo;

                String type = getAttr(boxElement, "type", "box"); //$NON-NLS-1$ //$NON-NLS-2$
                int colSpan = getAttr(boxElement, "colspan", 1); //$NON-NLS-1$

                Component comp = null;
                if (type.equalsIgnoreCase("bar chart")) //$NON-NLS-1$
                {
                    String statName = getAttr(boxElement, "name", null); //$NON-NLS-1$

                    if (isNotEmpty(statName)) {
                        BarChartPanel bcp = (BarChartPanel) StatsMgr.createStatPane(statName);
                        int width = colSpan > 1 ? ((maxCols * preferredWidth) + ((maxCols - 1) * spacing))
                                : preferredWidth;
                        // We start by assuming the chart will be square which is why we use
                        // preferredWidth as the height, and then we calculate the new width
                        bcp.setPreferredChartSize(width, preferredWidth);
                        comp = bcp;
                        //comp.setSize(new Dimension(preferredWidth, preferredWidth));
                        //comp.setPreferredSize(new Dimension(preferredWidth, preferredWidth));
                        //comp.invalidate();
                        //comp.doLayout();
                        //System.out.println(comp.getSize());
                        validate();
                        doLayout();
                        repaint();
                    }

                } else // The default is "Box"
                {
                    comp = processBox(boxElement, hasResBundle);
                }

                if (comp != null) {
                    comps.add(comp);

                    if (colSpan == 1) {
                        builder.add(comp, cc.xy(x, y));

                    } else {
                        builder.add(comp, cc.xywh(x, y, colSpan, 1));
                    }
                    x += 2;
                }
            } // boxes
            y += 2;
        }

        if (hasResBundle) {
            UIRegistry.popResourceBundle();
        }

        setBackground(bgColor);

        JPanel statPanel = builder.getPanel();
        statPanel.setBackground(Color.WHITE);

        boolean hasUpper = upperDisplayComp != null;

        builder = new PanelBuilder(new FormLayout("C:P:G", hasUpper ? "50px,p,20px,p" : "p")); //$NON-NLS-1$ //$NON-NLS-2$

        if (hasUpper) {
            y = 2;
            builder.add(upperDisplayComp, cc.xy(1, y));
            y += 2;

        } else {
            y = 1;
        }

        builder.add(statPanel, cc.xy(1, y));
        centerPanel = builder.getPanel();

        centerPanel.setBackground(Color.WHITE);

        //For Tiling
        if (isTiled()) {
            centerPanel.setOpaque(false);
            setOpaque(false);
            statPanel.setOpaque(false);
        }

        centerPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

        add(centerPanel, BorderLayout.CENTER);

        if (updateBtn == null) {
            PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g,p,4px", "4px,p,4px"));
            //pb.setOpaque(false);
            updateBtn = new FadeBtn(UIRegistry.getResourceString("STS_UPDATE"));
            pb.add(updateBtn, cc.xy(2, 2));
            pb.getPanel().setBackground(bgColor);
            add(pb.getPanel(), BorderLayout.SOUTH);

            updateBtn.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    init();
                }
            });
        }

        centerPanel.validate();
        validate();
        doLayout();

    } catch (Exception ex) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(StatsPane.class, ex);
        log.error(ex);
        ex.printStackTrace();
    }

}