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

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

Introduction

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

Prototype

public CellConstraints xyw(int col, int row, int colSpan) 

Source Link

Document

Sets the column, row, width, and height; uses a height (row span) of 1 and the horizontal and vertical default alignments.

Examples:

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

Usage

From source file:edu.ku.brc.specify.config.init.TreeDefSetupPanel.java

License:Open Source License

/**
 * @param classType the class of the TreeDef
 * @param classTitle the already localized title of the actual tree
 * @param panelName the name of the panel
 * @param descKey L10N key to label description above the table
 * @param nextBtn the next button/*w  ww  .  j ava 2s  .  co m*/
 * @param dbPanel the 
 */
public TreeDefSetupPanel(final Class<?> classType, final String classTitle, final String panelName,
        final String helpContext, final String descKey, final JButton nextBtn, final JButton prevBtn,
        final DisciplinePanel disciplinePanel) {
    super(panelName, helpContext, nextBtn, prevBtn);

    this.classType = classType;
    this.classTitle = classTitle;
    this.disciplinePanel = disciplinePanel;

    if (classType == TaxonTreeDef.class || classType == GeographyTreeDef.class
            || classType == StorageTreeDef.class) {
        model = new TreeDefTableModel();
        if (classType != TaxonTreeDef.class) {
            loadTree(disciplinePanel != null && disciplinePanel.getDisciplineType() != null
                    ? disciplinePanel.getDisciplineType().getDisciplineType()
                    : null);
        }

        table = new JTable(model);
        directionCBX = UIHelper
                .createComboBox(new String[] { getResourceString("FORWARD"), getResourceString("REVERSE") });
        fullnameDisplayTxt = new JEditorPane();
        fullnameDisplayTxt.setBackground(Color.WHITE);
        fullnameDisplayTxt.setOpaque(true);
        fullnameDisplayTxt.setContentType("text/html");
        fullnameDisplayTxt.setEditable(false);

        table.setRowSelectionAllowed(false);
        table.setColumnSelectionAllowed(false);
        //table.setDefaultRenderer(String.class, new BiColorTableCellRenderer(false));

        model.addTableModelListener(new TableModelListener() {
            @Override
            public void tableChanged(TableModelEvent e) {
                updateBtnUI();
            }
        });

        JScrollPane spex = new JScrollPane(fullnameDisplayTxt, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        CellConstraints cc = new CellConstraints();
        PanelBuilder pb = new PanelBuilder(
                new FormLayout("p,2px,p,250px,f:p:g", "p,4px,min(p;250px),4px,p,4px,65px,2px,p"), this);

        JScrollPane sp = createScrollPane(table);
        sp.getViewport().setBackground(Color.WHITE);

        String lbl = getLocalizedMessage(descKey, classTitle);
        pb.add(createLabel(lbl, SwingConstants.CENTER), cc.xyw(1, 1, 4));
        pb.add(sp, cc.xyw(1, 3, 5));

        pb.add(createI18NFormLabel("DIRECTION"), cc.xy(1, 5));
        pb.add(directionCBX, cc.xy(3, 5));

        pb.add(createI18NFormLabel("EXAMPLE"), cc.xy(1, 7));
        pb.add(spex, cc.xywh(3, 7, 2, 3));

        makeTableHeadersCentered(table, true);

        directionCBX.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                updateBtnUI();
            }
        });

        table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {
                if (!e.getValueIsAdjusting()) {
                    updateBtnUI();

                    int inx = table.getSelectedColumn();
                    if (inx > -1) {
                        TreeDefRow row = treeDefList.get(table.getSelectedRow());
                        String msgKey = null;

                        if (row.isRequired() && (inx == 1 || inx == 3)) {
                            msgKey = inx == 1 ? "NO_CHANGE_INCL" : "NO_CHANGE_REQ";

                        } else if (inx == 4 && !row.isIncluded()) {
                            msgKey = "NO_CHANGE_INFN";
                        }

                        if (msgKey != null) {
                            final String mk = msgKey;
                            SwingUtilities.invokeLater(new Runnable() {
                                @Override
                                public void run() {
                                    showLocalizedMsg(mk);
                                }
                            });
                        }
                    }
                }
            }
        });

        updateBtnUI();
    }
}

From source file:edu.ku.brc.specify.config.ResImpExpMetaInfoDlg.java

License:Open Source License

@Override
public void createUI() {
    super.createUI();

    //HelpMgr.registerComponent(helpBtn, "ResImpExpMetaInfoDlg");

    DefaultComboBoxModel mimeModel = new DefaultComboBoxModel(
            new String[] { "XML", "Label", "Report", "Subreport" }); // I18N
    DefaultComboBoxModel typeModel = new DefaultComboBoxModel(
            new String[] { "Report", "Invoice", "WorkBench", "CollectionObject" }); // I18N

    DefaultComboBoxModel tblModel = new DefaultComboBoxModel(
            DBTableIdMgr.getInstance().getTablesForUserDisplay());

    mimeTypeCBX = createComboBox(mimeModel);

    nameTxt = createTextField();/*from   w  w  w  .  j  a va  2s  .  c  om*/
    descTxt = createTextField();

    CellConstraints cc = new CellConstraints();

    // Meta Info
    tableIdCBX = createComboBox(tblModel);
    reqsRecSetChk = createCheckBox("Is Record Set Required?");

    rptTypeCBX = createComboBox(typeModel);

    subReportsTxt = createTextField();
    actionsTxt = createTextField();

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

    int y = 1;
    JLabel lbl = createI18NFormLabel("Mime Type"); // I18N
    pb.add(lbl, cc.xy(1, y));
    pb.add(mimeTypeCBX, cc.xy(3, y));
    y += 2;

    lbl = createI18NFormLabel("Name"); // I18N
    pb.add(lbl, cc.xy(1, y));
    pb.add(nameTxt, cc.xy(3, y));
    y += 2;

    lbl = createI18NFormLabel("Description"); // I18N
    pb.add(lbl, cc.xy(1, y));
    pb.add(descTxt, cc.xyw(3, y, 2));
    y += 2;

    lbl = createI18NFormLabel("Table"); // I18N
    labels.add(lbl);
    pb.add(lbl, cc.xy(1, y));
    pb.add(tableIdCBX, cc.xy(3, y));
    y += 2;

    pb.add(reqsRecSetChk, cc.xy(3, y));
    y += 2;

    lbl = createI18NFormLabel("Report Type"); // I18N
    labels.add(lbl);
    pb.add(lbl, cc.xy(1, y));
    pb.add(rptTypeCBX, cc.xy(3, y));
    y += 2;

    lbl = createI18NFormLabel("Sub-Reports"); // I18N
    labels.add(lbl);
    pb.add(lbl, cc.xy(1, y));
    pb.add(subReportsTxt, cc.xyw(3, y, 2));
    y += 2;

    lbl = createI18NFormLabel("Action"); // I18N
    labels.add(lbl);
    pb.add(lbl, cc.xy(1, y));
    pb.add(actionsTxt, cc.xyw(3, y, 2));
    y += 2;

    pb.setDefaultDialogBorder();

    nameTxt.setText(FilenameUtils.getBaseName(fileName));

    contentPanel = pb.getPanel();
    mainPanel.add(contentPanel, BorderLayout.CENTER);
    pack();

    updateUI();

    mimeTypeCBX.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            updateUI();
        }
    });
}

From source file:edu.ku.brc.specify.config.SpecifyExceptionTracker.java

License:Open Source License

@Override
protected FeedBackSenderItem getFeedBackSenderItem(final Class<?> cls, final Exception exception) {
    CellConstraints cc = new CellConstraints();
    PanelBuilder pb = new PanelBuilder(new FormLayout("p,2px,p,f:p:g", "p,8px,p,2px, p,4px,p,2px,f:p:g"));

    Vector<Taskable> taskItems = new Vector<Taskable>(TaskMgr.getInstance().getAllTasks());
    Collections.sort(taskItems, new Comparator<Taskable>() {
        @Override// w w w  .  j av  a  2  s.  c om
        public int compare(Taskable o1, Taskable o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });

    final JTextArea commentsTA = createTextArea(3, 60);
    final JTextArea stackTraceTA = createTextArea(15, 60);
    final JCheckBox moreBtn;

    commentsTA.setWrapStyleWord(true);
    commentsTA.setLineWrap(true);

    //JLabel desc = createI18NLabel("UNHDL_EXCP", SwingConstants.LEFT);
    JEditorPane desc = new JEditorPane("text/html", getResourceString("UNHDL_EXCP"));
    desc.setEditable(false);
    desc.setOpaque(false);
    //desc.setFont(new Font(Font.SANS_SERIF, Font.BOLD, (new JLabel("X")).getFont().getSize()));

    JScrollPane sp = new JScrollPane(stackTraceTA, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);

    int y = 1;
    pb.add(desc, cc.xyw(1, y, 4));
    y += 2;
    pb.add(createI18NFormLabel("UNHDL_EXCP_CMM"), cc.xy(1, y));
    y += 2;
    pb.add(createScrollPane(commentsTA, true), cc.xyw(1, y, 4));
    y += 2;

    forwardImgIcon = IconManager.getIcon("Forward"); //$NON-NLS-1$
    downImgIcon = IconManager.getIcon("Down"); //$NON-NLS-1$
    moreBtn = new JCheckBox(getResourceString("LOGIN_DLG_MORE"), forwardImgIcon); //$NON-NLS-1$
    setControlSize(moreBtn);
    JButton copyBtn = createI18NButton("UNHDL_EXCP_COPY");

    PanelBuilder innerPB = new PanelBuilder(new FormLayout("p,2px,f:p:g", "p,2px,p:g,2px,p"));
    innerPB.add(createI18NLabel("UNHDL_EXCP_STK"), cc.xy(1, 1));
    innerPB.add(sp, cc.xyw(1, 3, 3));
    innerPB.add(copyBtn, cc.xy(1, 5));
    stackTracePanel = innerPB.getPanel();
    stackTracePanel.setVisible(false);

    pb.add(moreBtn, cc.xyw(1, y, 4));
    y += 2;
    pb.add(stackTracePanel, cc.xyw(1, y, 4));
    y += 2;

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    exception.printStackTrace(new PrintStream(baos));

    stackTraceTA.setText(baos.toString());

    moreBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (stackTracePanel.isVisible()) {
                stackTracePanel.setVisible(false);
                moreBtn.setIcon(forwardImgIcon);
            } else {
                stackTracePanel.setVisible(true);
                moreBtn.setIcon(downImgIcon);
            }
            if (dlg != null) {
                dlg.pack();
            }
        }
    });

    copyBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String taskName = getTaskName();
            FeedBackSenderItem item = new FeedBackSenderItem(taskName, "", "", commentsTA.getText(),
                    stackTraceTA.getText(), cls.getName());
            NameValuePair[] pairs = createPostParameters(item);

            StringBuilder sb = new StringBuilder();
            for (NameValuePair pair : pairs) {
                if (!pair.getName().equals("bug")) {
                    sb.append(pair.getName());
                    sb.append(": ");
                    if (pair.getName().equals("comments") || pair.getName().equals("stack_trace")) {
                        sb.append("\n");
                    }
                    sb.append(pair.getValue());
                    sb.append("\n");
                }
            }

            // Copy to Clipboard
            UIHelper.setTextToClipboard(sb.toString());
        }
    });

    pb.setDefaultDialogBorder();
    dlg = new CustomDialog((Frame) null, getResourceString("UnhandledExceptionTitle"), true,
            CustomDialog.OK_BTN, pb.getPanel());
    dlg.setOkLabel(getResourceString("UNHDL_EXCP_SEND"));

    dlg.createUI();
    stackTracePanel.setVisible(false);

    centerAndShow(dlg);

    String taskName = getTaskName();
    FeedBackSenderItem item = new FeedBackSenderItem(taskName, "", "", commentsTA.getText(),
            stackTraceTA.getText(), cls.getName());
    return item;
}

From source file:edu.ku.brc.specify.conversion.ConvertVerifier.java

License:Open Source License

/**
 * Loads the dialog/*from   w ww .j a v  a  2  s  . co  m*/
 * @param hashNames every other one is the new name
 * @return the list of selected DBs
 */
private boolean selectedDBsToConvert() {
    final JTextField itUserNameTF = UIHelper.createTextField("root", 15);
    final JPasswordField itPasswordTF = UIHelper.createPasswordField("", 15);

    final JTextField hostNameTF = UIHelper.createTextField("localhost", 15);

    CellConstraints cc = new CellConstraints();
    PanelBuilder pb = new PanelBuilder(new FormLayout("p,2px,p,f:p:g", "p,2px,p,2px,p,8px,p"));

    int y = 1;
    pb.addSeparator("IT User", cc.xyw(1, y, 4));
    y += 2;
    pb.add(UIHelper.createLabel("Username:", SwingConstants.RIGHT), cc.xy(1, y));
    pb.add(itUserNameTF, cc.xy(3, y));
    y += 2;

    pb.add(UIHelper.createLabel("Password:", SwingConstants.RIGHT), cc.xy(1, y));
    pb.add(itPasswordTF, cc.xy(3, y));
    y += 2;

    pb.add(UIHelper.createLabel("Host Name:", SwingConstants.RIGHT), cc.xy(1, y));
    pb.add(hostNameTF, cc.xy(3, y));
    y += 2;

    PanelBuilder panel = new PanelBuilder(new FormLayout("f:p:g,10px,f:p:g", "f:p:g"));
    panel.add(new JLabel(IconManager.getIcon("SpecifyLargeIcon")), cc.xy(1, 1));
    panel.add(pb.getPanel(), cc.xy(3, 1));

    CustomDialog dlg = new CustomDialog(null, "Database Info", true, panel.getPanel());
    ((JPanel) dlg.getContentPanel()).setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    UIHelper.centerAndShow(dlg);

    dlg.dispose();
    if (dlg.isCancelled()) {
        return false;
    }

    hostName = hostNameTF.getText();
    itUsrPwd.first = itUserNameTF.getText();
    itUsrPwd.second = ((JTextField) itPasswordTF).getText();

    return true;
}

From source file:edu.ku.brc.specify.conversion.OldDBStatsDlg.java

License:Open Source License

@Override
public void createUI() {
    setOkLabel("Continue");

    super.createUI();

    String[] queries = {//from   ww  w  .  j a  v  a 2 s  .c  o m
            "SELECT COUNT(*) FROM collectionobject co1 LEFT JOIN collectionobject co2 ON co1.DerivedFromID = co2.CollectionObjectID WHERE co1.DerivedFromID is not NULL AND co2.CollectionObjectID is NULL",
            "SELECT COUNT(*) FROM taxonname WHERE RankID iS NULL", "SELECT COUNT(*) FROM collectionobject",
            "SELECT COUNT(*) FROM collectionobjectcatalog", "SELECT COUNT(*) FROM taxonname",
            "SELECT COUNT(*) FROM determination", "SELECT COUNT(*) FROM agent",
            "SELECT COUNT(*) FROM agent WHERE LENGTH(Name) > 50",
            "SELECT COUNT(*) FROM agent WHERE LENGTH(LastName) > 50",
            "SELECT COUNT(*) FROM agent WHERE LastName LIKE '%;%'",
            "SELECT COUNT(c.AgentID) FROM collectingevent ce INNER JOIN collectors c ON ce.CollectingEventID = c.CollectingEventID "
                    + "INNER JOIN agent a ON c.AgentID = a.AgentID WHERE a.LastName LIKE '%;%'",
            "SELECT COUNT(*) FROM authors au INNER JOIN agent a ON au.AgentID = a.AgentID WHERE a.LastName LIKE '%;%'",
            "SELECT COUNT(*) FROM accessionagents aagt INNER JOIN agentaddress aa ON aagt.AgentAddressID = aa.AgentAddressID "
                    + "INNER JOIN agent a ON aa.AgentID = a.AgentID WHERE a.LastName LIKE '%;%'",
            "SELECT COUNT(*) FROM borrowagents ba INNER JOIN agentaddress aa ON ba.AgentAddressID = aa.AgentAddressID INNER JOIN agent a ON aa.AgentID = a.AgentID WHERE a.LastName LIKE '%;%'",
            "SELECT COUNT(*) FROM loanagents la INNER JOIN agentaddress aa ON la.AgentAddressID = aa.AgentAddressID INNER JOIN agent a ON aa.AgentID = a.AgentID WHERE a.LastName LIKE '%;%'",
            "SELECT COUNT(ID) FROM (SELECT DISTINCT ce.LocalityID as ID FROM collectingevent ce LEFT JOIN locality loc ON loc.localityid = ce.LocalityID  WHERE loc.LocalityID IS NULL) AS T1",
            "SELECT COUNT(*) FROM shipment", null, };

    String[] descs = { "Stranded Preparations", "Number of Taxon with a NULL RankId", "CollectionObjects Table",
            "Collection Object Catalogs Table", "Taxon", "Determinations", "Agents", "Agent Names Truncated",
            "Agent Last Names Truncated", "Agent Last Names with ';'", "Collector Last Names with ';'",
            "Author Last Names with ';'", "Accession Agents Last Names with ';'",
            "Borrow Agent Last Names with ';'", "Loan Agent Last Names with ';'",
            "Collecting Events with NULL Localities", "Number of Shipments",
            "Stranded Agents Last Names with ';'", };

    Integer[] errors = { 0, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE,
            Integer.MAX_VALUE, Integer.MAX_VALUE, 0, 0, 0, 0, 0, // Authors
            0, // Accession Agents
            0, // Stranded
            0, // Borrow
            0, // Loan
            0, // CE no Locality
            0, // # Shipments
    };

    for (int i = 0; i < queries.length; i++) {

        int count = queries[i] != null ? BasicSQLUtils.getCountAsInt(oldDBConn, queries[i]) : 0;

        statsData.add(
                new Triple<String, Integer, Boolean>(descs[i], count, errors[i] != null && count > errors[i]));
    }

    Triple<String, Integer, Boolean> stranded = statsData.get(errors.length - 1);
    stranded.second = getStrandedAgentsCount();
    stranded.third = stranded.second > errors[errors.length - 1];

    JTable table = new JTable(new StatsModel());
    table.setPreferredScrollableViewportSize(
            new Dimension(table.getPreferredScrollableViewportSize().width, 10 * table.getRowHeight()));
    table.getColumnModel().getColumn(0).setCellRenderer(new StatTblCellRenderer());
    table.getColumnModel().getColumn(1).setCellRenderer(new StatTblCellRenderer());

    CellConstraints cc = new CellConstraints();
    PanelBuilder pb = new PanelBuilder(new FormLayout("p,2px,f:p:g", "f:p:g,10px,p,2px,f:p:g,4px,p"));
    pb.add(UIHelper.createScrollPane(table, true), cc.xyw(1, 1, 3));

    String sql = "SELECT DISTINCT(CNAME), L, F, M FROM (SELECT a.LastName AS L, a.FirstName AS F, a.MiddleInitial AS M, "
            + "CONCAT(a.LastName, CONCAT(IFNULL(a.FirstName, ''), IFNULL(a.MiddleInitial, ''))) AS CNAME FROM "
            + "collectingevent ce INNER JOIN collectors c ON ce.CollectingEventID = c.CollectingEventID "
            + "INNER JOIN agent a ON c.AgentID = a.AgentID "
            + "WHERE a.LastName LIKE '%;%' OR a.FirstName LIKE '%,%') T1";

    Vector<Object[]> collRows = BasicSQLUtils.query(oldDBConn, sql);

    Object[][] rows = new Object[collRows.size()][4];
    int i = 0;
    for (Object[] row : collRows) {
        rows[i][0] = row[0];
        rows[i][1] = row[1];
        rows[i][2] = row[2];
        rows[i][3] = row[3];
        i++;
    }

    //pb.addSeparator("Collectors with Semicolons", cc.xyw(1, 3, 3));
    JTable collTable = new JTable(rows, new Object[] { "Combined", "Last Name", "First Name", "Middle" });
    //pb.add(UIHelper.createScrollPane(collTable, true), cc.xyw(1, 5, 3));

    collTable.setPreferredScrollableViewportSize(
            new Dimension(collTable.getPreferredScrollableViewportSize().width, 10 * collTable.getRowHeight()));

    doFixAgentsChkbx = UIHelper.createCheckBox("Fix Agents");
    //pb.add(doFixAgentsChkbx, cc.xyw(3, 7, 1));

    contentPanel = pb.getPanel();
    mainPanel.add(contentPanel, BorderLayout.CENTER);

    pack();
}

From source file:edu.ku.brc.specify.conversion.SpecifyDBConverter.java

License:Open Source License

/**
 * Loads the dialog//ww  w  . ja va 2s  .c o  m
 * @param hashNames every other one is the new name
 * @return the list of selected DBs
 */
public boolean selectedDBsToConvert(final boolean useITOnly) {
    final JTextField itUserNameTF = UIHelper.createTextField("root", 15);
    final JPasswordField itPasswordTF = UIHelper.createPasswordField("", 15);

    final JTextField masterUserNameTF = UIHelper.createTextField("Master", 15);
    final JPasswordField masterPasswordTF = UIHelper.createPasswordField("Master", 15);

    final JTextField hostNameTF = UIHelper.createTextField("localhost", 15);

    CellConstraints cc = new CellConstraints();
    PanelBuilder pb = new PanelBuilder(new FormLayout("p,2px,p,f:p:g",
            "p,2px,p,2px,p,4px," + (useITOnly ? "" : "p,2px,p,2px,") + "p,8px,p,4px"));

    int y = 1;
    pb.addSeparator("IT User", cc.xyw(1, y, 4));
    y += 2;
    pb.add(UIHelper.createLabel("Username:", SwingConstants.RIGHT), cc.xy(1, y));
    pb.add(itUserNameTF, cc.xy(3, y));
    y += 2;

    pb.add(UIHelper.createLabel("Password:", SwingConstants.RIGHT), cc.xy(1, y));
    pb.add(itPasswordTF, cc.xy(3, y));
    y += 2;

    if (!useITOnly) {
        pb.addSeparator("Master User", cc.xyw(1, y, 4));
        y += 2;
        pb.add(UIHelper.createLabel("Username:", SwingConstants.RIGHT), cc.xy(1, y));
        pb.add(masterUserNameTF, cc.xy(3, y));
        y += 2;

        pb.add(UIHelper.createLabel("Password:", SwingConstants.RIGHT), cc.xy(1, y));
        pb.add(masterPasswordTF, cc.xy(3, y));
        y += 2;
    }

    pb.add(UIHelper.createLabel("Host Name:", SwingConstants.RIGHT), cc.xy(1, y));
    pb.add(hostNameTF, cc.xy(3, y));
    y += 2;

    if (System.getProperty("user.name").equals("rods")) {
        itPasswordTF.setText("root"); // password for converter database
    } else {
        itPasswordTF.requestFocus();
    }

    PanelBuilder panel = new PanelBuilder(new FormLayout("f:p:g,10px,f:p:g", "f:p:g"));
    panel.add(new JLabel(IconManager.getIcon("SpecifyConv")), cc.xy(1, 1));
    panel.add(pb.getPanel(), cc.xy(3, 1));
    panel.setDefaultDialogBorder();

    CustomDialog dlg = new CustomDialog(null, "Specify Converter", true, panel.getPanel());
    UIHelper.centerAndShow(dlg);

    dlg.dispose();
    if (dlg.isCancelled()) {
        return false;
    }

    hostName = hostNameTF.getText();
    itUsrPwd.first = itUserNameTF.getText();
    itUsrPwd.second = ((JTextField) itPasswordTF).getText();

    masterUsrPwd.first = masterUserNameTF.getText();
    masterUsrPwd.second = ((JTextField) masterPasswordTF).getText();

    return true;
}

From source file:edu.ku.brc.specify.dbsupport.cleanuptools.AgentCleanupListDlg.java

License:Open Source License

@Override
public void createUI() {
    setCancelLabel(getResourceString("CLOSE"));
    setOkLabel(getResourceString("CLNUP_AGT_CHOOSE"));

    super.createUI();

    CellConstraints cc = new CellConstraints();

    PanelBuilder btnPB = new PanelBuilder(new FormLayout("f:p:g,p,f:p:g,p,f:p:g", "p")); //$NON-NLS-1$ //$NON-NLS-2$
    selectAllBtn = createI18NButton("SELECTALL"); //$NON-NLS-1$
    deselectAllBtn = createI18NButton("DESELECTALL"); //$NON-NLS-1$
    btnPB.add(selectAllBtn, cc.xy(2, 1));
    btnPB.add(deselectAllBtn, cc.xy(4, 1));

    PanelBuilder pb = new PanelBuilder(
            new FormLayout("p,2px,f:p:g", (topMsg != null ? "p,2px," : "") + "p,2px,p,2px,p"));

    model = new FindItemTableModel();
    table = new JTable(model);
    UIHelper.makeTableHeadersCentered(table, false);

    TableCellRenderer tcr = table.getDefaultRenderer(Integer.class);
    DefaultTableCellRenderer dtcr = (DefaultTableCellRenderer) tcr;
    dtcr.setHorizontalAlignment(SwingConstants.CENTER);

    int y = 1;/*from  w  w  w. ja  va 2 s .c  om*/
    if (topMsg != null) {
        pb.add(createLabel(topMsg, SwingConstants.CENTER), cc.xyw(1, y, 3));
        y += 2;
    }
    pb.add(createScrollPane(table), cc.xyw(1, y, 3));
    y += 2;
    pb.add(btnPB.getPanel(), cc.xyw(1, y, 3));

    pb.setDefaultDialogBorder();
    contentPanel = pb.getPanel();
    mainPanel.add(contentPanel, BorderLayout.CENTER);
    pack();

    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                //updateBtnUI();
            }
        }
    });

    table.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            super.mouseClicked(e);

            if (e.getClickCount() == 2) {
                //getOkBtn().setEnabled(true);
                //getOkBtn().doClick();
            }
        }
    });

    selectAllBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            doSetSelection(true);
            getOkBtn().setEnabled(true);
        }
    });
    deselectAllBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            doSetSelection(false);
            getOkBtn().setEnabled(false);
        }
    });
}

From source file:edu.ku.brc.specify.dbsupport.cleanuptools.CountryClearProcesser.java

License:Open Source License

/**
 * @return//w  w  w . j a va 2  s . com
 */
@SuppressWarnings("rawtypes")
public boolean start() {
    CellConstraints cc = new CellConstraints();
    countriesCBX = createCheckBox(getResourceString("CLNUP_GEO_ALL_COUNTRIES"));
    countriesCBX.setEnabled(true);

    countryIds.clear();
    String sql = "SELECT g.GeographyID, g.Name, g2.Name FROM geography g LEFT JOIN geography g2 ON g.ParentID = g2.GeographyID "
            + "WHERE g.Name IS NOT NULL && LENGTH(g.Name) > 0 AND g.RankID = 200 AND g.GeographyTreeDefID = GEOTREEDEFID ORDER BY g.Name";
    sql = adjustSQL(sql);

    Vector<Object[]> rows = query(sql);
    Object[] titles = new Object[rows.size() + 1];
    int i = 0;
    titles[i++] = getResourceString("CLNUP_GEO_NONE");
    countryIds.add(-1);
    for (Object[] r : rows) {
        countryIds.add((Integer) r[0]);
        String countryStr = (String) r[1];
        String contStr = (String) r[2];
        titles[i++] = countryStr != null ? (countryStr + " (" + contStr + ")") : countryStr;
    }

    sql = String.format(
            "SELECT Name FROM geographytreedefitem WHERE GeographyTreeDefID = GEOTREEDEFID AND RankID = %d",
            200);
    String countryName = BasicSQLUtils.querySingleObj(adjustSQL(sql));

    spCountriesLbl = createFormLabel(countryName);
    spCountriesCmbx = createComboBox(titles);

    spCountriesCmbx.setSelectedIndex(0);

    PanelBuilder pb = new PanelBuilder(new FormLayout("p,2px,f:p:g", "p,4px,p,4px,p,4px,p"));

    JLabel label = createI18NLabel("CLNUP_GEO_CLEAR_DESC");
    pb.add(label, cc.xyw(1, 1, 3));
    pb.add(countriesCBX, cc.xyw(1, 3, 3));
    pb.add(spCountriesLbl, cc.xy(1, 5));
    pb.add(spCountriesCmbx, cc.xy(3, 5));

    pb.setDefaultDialogBorder();
    final CustomDialog dlg = new CustomDialog((Frame) getTopWindow(),
            getResourceString("CLNUP_GEO_CLEAR_TITLE"), true, pb.getPanel()); // I18N

    countriesCBX.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            boolean isSel = countriesCBX.isSelected();
            spCountriesCmbx.setEnabled(!isSel);
            spCountriesLbl.setEnabled(!isSel);
            dlg.getOkBtn().setEnabled(isSel || spCountriesCmbx.getSelectedIndex() > 0);
        }
    });

    // Special
    spCountriesCmbx.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            boolean isSel = spCountriesCmbx.getSelectedIndex() > 0;
            countriesCBX.setEnabled(!isSel);

            dlg.getOkBtn().setEnabled(isSel || countriesCBX.isSelected());
        }
    });

    dlg.setOkLabel(getResourceString("Clear"));
    dlg.createUI();
    dlg.getOkBtn().setEnabled(false);

    centerAndShow(dlg);
    if (!dlg.isCancelled()) {
        clearISOCodes();
    }
    return true;
}

From source file:edu.ku.brc.specify.dbsupport.cleanuptools.GeographyAssignISOs.java

License:Open Source License

/**
 * @return// w  w w. j a  va2 s .  c o m
 */
@SuppressWarnings("rawtypes")
public boolean buildAsyncOrig(final int earthId) {
    String sql = adjustSQL(
            "SELECT COUNT(*) FROM geography WHERE GeographyCode IS NOT NULL AND RankID = 100 AND GeographyTreeDefID = GEOTREEDEFID");
    int numContinentsWithNames = BasicSQLUtils.getCountAsInt(sql);

    continentsCBX = createCheckBox("All Continents"); // I18N

    CellConstraints cc = new CellConstraints();
    PanelBuilder pb1 = new PanelBuilder(new FormLayout("f:p:g", "p,4px,p,4px,p,8px"));
    countriesCBX = createCheckBox("All Countries");
    stateCBX = createCheckBox("All States");
    countiesCBX = createCheckBox("All Counties");
    pb1.add(countriesCBX, cc.xy(1, 1));
    pb1.add(stateCBX, cc.xy(1, 3));
    //pb1.add(countiesCBX,   cc.xy(1, 5));

    allCountriesRB = new JRadioButton("Choose the Geography level to be processed"); //L18N
    singleCountryRB = new JRadioButton("Choose an individual Country");
    btnGroup = new ButtonGroup();
    btnGroup.add(this.allCountriesRB);
    btnGroup.add(this.singleCountryRB);

    if (numContinentsWithNames == 0) {
        continentsCBX.setEnabled(false);
        continentsCBX.setSelected(true);
    }

    countriesCBX.setEnabled(true);
    stateCBX.setEnabled(false);
    countiesCBX.setEnabled(false);

    countryIds.clear();
    sql = "SELECT g.GeographyID, g.Name, g2.Name FROM geography g LEFT JOIN geography g2 ON g.ParentID = g2.GeographyID "
            + "WHERE g.Name IS NOT NULL && LENGTH(g.Name) > 0 AND g.RankID = 200 AND g.GeographyTreeDefID = GEOTREEDEFID ORDER BY g.Name";
    sql = adjustSQL(sql);

    Vector<Object[]> rows = query(sql);
    Object[] titles = new Object[rows.size() + 1];
    int i = 0;
    titles[i++] = "None"; // I18N
    countryIds.add(-1);
    for (Object[] r : rows) {
        countryIds.add((Integer) r[0]);
        String countryStr = (String) r[1];
        String contStr = (String) r[2];
        titles[i++] = countryStr != null ? (countryStr + " (" + contStr + ")") : countryStr;
    }

    PanelBuilder pb2 = new PanelBuilder(new FormLayout("8px,p,2px,f:p:g", "p,4px,p,8px"));
    spCountriesLbl = createFormLabel("Country"); // I18N
    spCountriesCmbx = createComboBox(titles);
    spStatesCBX = createCheckBox("States (Required)"); // I18N
    spCountiesCBX = createCheckBox("Counties"); // I18N

    pb2.add(spCountriesLbl, cc.xy(2, 1));
    pb2.add(spCountriesCmbx, cc.xy(4, 1));
    pb2.add(spStatesCBX, cc.xyw(1, 3, 4));
    //pb2.add(spCountiesCBX,   cc.xyw(1, 5, 4));

    spCountriesCmbx.setSelectedIndex(0);

    spStatesCBX.setSelected(true);
    spStatesCBX.setEnabled(false);
    spCountiesCBX.setEnabled(false);

    String rowDef = createDuplicateJGoodiesDef("p", "4px", 8);
    PanelBuilder pb = new PanelBuilder(new FormLayout("16px,f:p:g", rowDef));

    pb.addSeparator("Continents to be processed", cc.xyw(1, 1, 2));
    pb.add(continentsCBX, cc.xyw(1, 3, 2));

    pb.addSeparator("Countries to be processed", cc.xyw(1, 5, 2));
    pb.add(allCountriesRB, cc.xyw(1, 7, 2));
    pb.add(pb1.getPanel(), cc.xyw(2, 9, 1));

    pb.add(singleCountryRB, cc.xyw(1, 11, 2));
    pb.add(pb2.getPanel(), cc.xyw(2, 13, 1));

    pb.add(createGeoStatsPanel(), cc.xyw(1, 15, 2));

    pb.setDefaultDialogBorder();
    final CustomDialog dlg = new CustomDialog((Frame) getTopWindow(), "ISO Code Processing", true,
            CustomDialog.OKCANCELHELP, pb.getPanel()); // I18N
    dlg.setHelpContext("GeoCleanUpLevelChooser");

    // Setup actions
    ChangeListener rbChangeListener = new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            radioSelected(dlg);
        }
    };
    allCountriesRB.addChangeListener(rbChangeListener);
    singleCountryRB.addChangeListener(null);

    countriesCBX.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            boolean isSel = countriesCBX.isSelected();
            stateCBX.setEnabled(isSel);
            countiesCBX.setEnabled(false);
            if (!isSel) {
                stateCBX.setSelected(false);
                countiesCBX.setSelected(false);
            }
            calcGeoStats();
            dlg.getOkBtn().setEnabled(isSel || spCountriesCmbx.getSelectedIndex() > 0);
        }
    });

    stateCBX.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            countiesCBX.setEnabled(stateCBX.isSelected());
            if (!stateCBX.isSelected()) {
                countiesCBX.setSelected(false);
            }
            calcGeoStats();
        }
    });

    // Special
    spCountriesCmbx.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            boolean isSel = spCountriesCmbx.getSelectedIndex() > 0;
            spStatesCBX.setSelected(isSel);
            spCountiesCBX.setEnabled(isSel);
            if (!isSel) {
                spStatesCBX.setSelected(false);
                spCountiesCBX.setSelected(false);
            }
            calcGeoStats();
            dlg.getOkBtn().setEnabled(isSel || countriesCBX.isSelected());

        }
    });

    spStatesCBX.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            spCountiesCBX.setEnabled(stateCBX.isSelected());
            calcGeoStats();
        }
    });

    allCountriesRB.setSelected(true);

    dlg.createUI();
    dlg.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); // Must be called after 'createUI'
    dlg.getOkBtn().setEnabled(false);

    // AUTO Don't show Dialog because it is automatically setting what to do 
    centerAndShow(dlg);

    if (dlg.isCancelled()) {
        return false;
    }

    connectToDB();

    if (true) // AUTO 
    {
        doAllCountries = new boolean[] { countriesCBX.isSelected(), stateCBX.isSelected(),
                countiesCBX.isSelected(), false };
        doInvCountry = new boolean[] { spCountriesCmbx.getSelectedIndex() > 0, spStatesCBX.isSelected(),
                spCountiesCBX.isSelected(), false };
        doIndvCountryId = doInvCountry[0] ? countryIds.get(spCountriesCmbx.getSelectedIndex()) : null;
    } else {
        int indexOfUSA = getUnitedStatesIndex(titles);
        if (indexOfUSA == -1) {
            Vector<Object> nameList = new Vector<Object>();
            Collections.addAll(nameList, titles);
            JList list = createList(nameList);

            JScrollPane sp = createScrollPane(list);
            pb = new PanelBuilder(new FormLayout("f:p:g", "p,8px,f:p:g"));
            pb.add(createLabel("Select the United States"), cc.xy(1, 1));
            pb.add(sp, cc.xy(1, 3));
            pb.setDefaultDialogBorder();
            final CustomDialog askDlg = new CustomDialog((Frame) getTopWindow(), "Choose", true,
                    CustomDialog.OKCANCELHELP, pb.getPanel()); // I18N
            dlg.setHelpContext("GeoCleanUpLevelChooser");
            centerAndShow(askDlg);
            if (!askDlg.isCancelled()) {
                indexOfUSA = list.getSelectedIndex();
            }
        }

        doAllCountries = new boolean[] { true, false, false, false };
        doInvCountry = new boolean[] { indexOfUSA > -1, true, false, false };
        doIndvCountryId = doInvCountry[0] ? countryIds.get(indexOfUSA) : null;
    }

    // Check to see if it needs indexing.
    boolean shouldIndex = luceneSearch.shouldIndex();

    if (shouldIndex) {
        frame = new ProgressFrame("Building Geography Authority..."); // I18N
        frame.getCloseBtn().setVisible(false);
        frame.turnOffOverAll();
        frame.setDesc("Loading Geonames data..."); // I18N
        frame.pack();
        frame.setSize(450, frame.getBounds().height + 10);
        UIHelper.centerAndShow(frame, 450, frame.getBounds().height + 10);

        luceneSearch.startIndexingProcessAsync(earthId, frame, new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                frame.setVisible(false);
                frame = null;
                if (((Boolean) e.getSource())) {
                    GeographyAssignISOs.this.startTraversal();
                }
            }
        });

    } else {
        sql = "SELECT Name, geonameId, iso_alpha2 FROM countryinfo";
        for (Object[] row : query(sql)) {
            countryInfo.add(new GeoSearchResultsItem((String) row[0], (Integer) row[1], (String) row[2]));
        }
        startTraversal();
    }

    return true;
}

From source file:edu.ku.brc.specify.dbsupport.cleanuptools.GeographyAssignISOs.java

License:Open Source License

private JPanel createGeoStatsPanel() {
    CellConstraints cc = new CellConstraints();

    PanelBuilder pb = new PanelBuilder(new FormLayout("p,2px,p,f:p:g,", "p,8px,p,4px,p"));
    countriesTotalLabel = UIHelper.createLabel("");
    statesTotalLabel = UIHelper.createLabel("");

    pb.addSeparator("Unassigned Geography Counts", cc.xyw(1, 1, 4)); // I18N
    pb.add(createFormLabel("Countries"), cc.xy(1, 3));
    pb.add(createFormLabel("States"), cc.xy(1, 5));
    pb.add(countriesTotalLabel, cc.xy(3, 3));
    pb.add(statesTotalLabel, cc.xy(3, 5));
    return pb.getPanel();
}