Search in sources :

Example 1 with CheckBoxList

use of org.jivesoftware.spark.component.CheckBoxList in project Spark by igniterealtime.

the class DataFormUI method getFilledForm.

/**
 * Returns the answered DataForm.
 *
 * @return the answered DataForm.
 */
public Form getFilledForm() {
    // Now submit all information
    Iterator<String> valueIter = valueMap.keySet().iterator();
    Form answerForm = searchForm.createAnswerForm();
    while (valueIter.hasNext()) {
        String answer = valueIter.next();
        Object o = valueMap.get(answer);
        if (o instanceof JCheckBox) {
            boolean isSelected = ((JCheckBox) o).isSelected();
            answerForm.setAnswer(answer, isSelected);
        } else if (o instanceof JTextArea) {
            List<String> list = new ArrayList<>();
            String value = ((JTextArea) o).getText();
            StringTokenizer tokenizer = new StringTokenizer(value, ", ", false);
            while (tokenizer.hasMoreTokens()) {
                list.add(tokenizer.nextToken());
            }
            if (list.size() > 0) {
                answerForm.setAnswer(answer, list);
            }
        } else if (o instanceof JTextField) {
            String value = ((JTextField) o).getText();
            if (ModelUtil.hasLength(value)) {
                answerForm.setAnswer(answer, value);
            }
        } else if (o instanceof JComboBox) {
            Object v = ((JComboBox) o).getSelectedItem();
            String value;
            if (v instanceof FormField.Option) {
                value = ((FormField.Option) v).getValue();
            } else {
                value = (String) v;
            }
            List<String> list = new ArrayList<>();
            list.add(value);
            if (list.size() > 0) {
                answerForm.setAnswer(answer, list);
            }
        } else if (o instanceof CheckBoxList) {
            List<String> list = ((CheckBoxList) o).getSelectedValues();
            if (list.size() > 0) {
                answerForm.setAnswer(answer, list);
            }
        }
    }
    return answerForm;
}
Also used : JTextArea(javax.swing.JTextArea) JComboBox(javax.swing.JComboBox) Form(org.jivesoftware.smackx.xdata.Form) JTextField(javax.swing.JTextField) JCheckBox(javax.swing.JCheckBox) StringTokenizer(java.util.StringTokenizer) CheckBoxList(org.jivesoftware.spark.component.CheckBoxList) ArrayList(java.util.ArrayList) List(java.util.List) CheckBoxList(org.jivesoftware.spark.component.CheckBoxList) FormField(org.jivesoftware.smackx.xdata.FormField)

Example 2 with CheckBoxList

use of org.jivesoftware.spark.component.CheckBoxList in project Spark by igniterealtime.

the class DataFormUI method addField.

private void addField(String label, JComponent comp, String variable) {
    if (!(comp instanceof JCheckBox)) {
        this.add(new JLabel(label), new GridBagConstraints(0, row, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
    }
    if (comp instanceof JTextArea) {
        this.add(new JScrollPane(comp), new GridBagConstraints(1, row, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 100, 50));
    } else if (comp instanceof JCheckBox) {
        this.add(comp, new GridBagConstraints(0, row, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
    } else if (comp instanceof CheckBoxList) {
        this.add(comp, new GridBagConstraints(1, row, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 50));
    } else {
        this.add(comp, new GridBagConstraints(1, row, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
    }
    valueMap.put(variable, comp);
    row++;
}
Also used : JCheckBox(javax.swing.JCheckBox) JScrollPane(javax.swing.JScrollPane) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) JTextArea(javax.swing.JTextArea) CheckBoxList(org.jivesoftware.spark.component.CheckBoxList) JLabel(javax.swing.JLabel)

Example 3 with CheckBoxList

use of org.jivesoftware.spark.component.CheckBoxList in project Spark by igniterealtime.

the class DataFormDialog method updateRoomConfiguration.

private void updateRoomConfiguration(Form submitForm, MultiUserChat chat) {
    for (Object o1 : valueMap.keySet()) {
        String answer = (String) o1;
        Object o = valueMap.get(answer);
        if (o instanceof JCheckBox) {
            boolean isSelected = ((JCheckBox) o).isSelected();
            submitForm.setAnswer(answer, isSelected);
        } else if (o instanceof JTextArea) {
            List<String> list = new ArrayList<>();
            String value = ((JTextArea) o).getText();
            StringTokenizer tokenizer = new StringTokenizer(value, ", ", false);
            while (tokenizer.hasMoreTokens()) {
                list.add(tokenizer.nextToken());
            }
            if (list.size() > 0) {
                submitForm.setAnswer(answer, list);
            }
        } else if (o instanceof JTextField) {
            String value = ((JTextField) o).getText();
            if (ModelUtil.hasLength(value)) {
                submitForm.setAnswer(answer, value);
            }
        } else if (o instanceof JComboBox) {
            String value = (String) ((JComboBox) o).getSelectedItem();
            List<String> list = new ArrayList<>();
            list.add(value);
            if (list.size() > 0) {
                submitForm.setAnswer(answer, list);
            }
        } else if (o instanceof CheckBoxList) {
            List<String> list = ((CheckBoxList) o).getSelectedValues();
            if (list.size() > 0) {
                submitForm.setAnswer(answer, list);
            }
        }
    }
    try {
        chat.sendConfigurationForm(submitForm);
        RoomInfo info = MultiUserChatManager.getInstanceFor(SparkManager.getConnection()).getRoomInfo(chat.getRoom());
        // remove bookmark if any for non persistent room
        if (!info.isPersistent()) {
            BookmarkManager.getBookmarkManager(SparkManager.getConnection()).removeBookmarkedConference(info.getRoom());
        }
    } catch (XMPPException | SmackException e) {
        Log.error(e);
        MessageDialog.showErrorDialog(Res.getString("group.send_config.error"), e);
    }
}
Also used : JTextArea(javax.swing.JTextArea) JComboBox(javax.swing.JComboBox) SmackException(org.jivesoftware.smack.SmackException) RoomInfo(org.jivesoftware.smackx.muc.RoomInfo) JTextField(javax.swing.JTextField) JCheckBox(javax.swing.JCheckBox) StringTokenizer(java.util.StringTokenizer) CheckBoxList(org.jivesoftware.spark.component.CheckBoxList) ArrayList(java.util.ArrayList) List(java.util.List) CheckBoxList(org.jivesoftware.spark.component.CheckBoxList) XMPPException(org.jivesoftware.smack.XMPPException)

Example 4 with CheckBoxList

use of org.jivesoftware.spark.component.CheckBoxList in project Spark by igniterealtime.

the class DataFormDialog method addField.

private void addField(String label, JComponent comp, String variable) {
    if (!(comp instanceof JCheckBox)) {
        JLabel formLabel = new JLabel(label);
        formLabel.setFont(new Font("dialog", Font.BOLD, 10));
        this.add(formLabel, new GridBagConstraints(0, row, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
    }
    if (comp instanceof JTextArea) {
        JScrollPane pane = new JScrollPane(comp);
        pane.setBorder(BorderFactory.createTitledBorder(Res.getString("group.comma.delimited")));
        this.add(pane, new GridBagConstraints(1, row, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 75, 50));
    } else if (comp instanceof JCheckBox) {
        this.add(comp, new GridBagConstraints(0, row, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
    } else if (comp instanceof CheckBoxList) {
        this.add(comp, new GridBagConstraints(1, row, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 75, 50));
    } else {
        this.add(comp, new GridBagConstraints(1, row, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 75, 0));
    }
    valueMap.put(variable, comp);
    row++;
}
Also used : JCheckBox(javax.swing.JCheckBox) JScrollPane(javax.swing.JScrollPane) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) JTextArea(javax.swing.JTextArea) CheckBoxList(org.jivesoftware.spark.component.CheckBoxList) JLabel(javax.swing.JLabel) Font(java.awt.Font)

Example 5 with CheckBoxList

use of org.jivesoftware.spark.component.CheckBoxList in project Spark by igniterealtime.

the class DataFormUI method buildUI.

private void buildUI(Form form) {
    // Add default answers to the form to submit
    for (final FormField field : form.getFields()) {
        String variable = field.getVariable();
        String label = field.getLabel();
        FormField.Type type = field.getType();
        List<String> valueList = field.getValues();
        if (type.equals(FormField.Type.bool)) {
            String o = valueList.get(0);
            boolean isSelected = o.equals("1");
            JCheckBox box = new JCheckBox(label);
            box.setSelected(isSelected);
            addField(label, box, variable);
        } else if (type.equals(FormField.Type.text_single) || type.equals(FormField.Type.jid_single)) {
            String v = "";
            if (valueList.size() > 0) {
                v = valueList.get(0);
            }
            addField(label, new JTextField(v), variable);
        } else if (type.equals(FormField.Type.text_multi) || type.equals(FormField.Type.jid_multi)) {
            StringBuilder buf = new StringBuilder();
            for (FormField.Option option : field.getOptions()) {
                buf.append(option);
            }
            addField(label, new JTextArea(buf.toString()), variable);
        } else if (type.equals(FormField.Type.text_private)) {
            addField(label, new JPasswordField(), variable);
        } else if (type.equals(FormField.Type.list_single)) {
            JComboBox box = new JComboBox();
            for (final FormField.Option option : field.getOptions()) {
                box.addItem(option);
            }
            if (valueList.size() > 0) {
                String defaultValue = valueList.get(0);
                box.setSelectedItem(defaultValue);
            }
            addField(label, box, variable);
        } else if (type.equals(FormField.Type.list_multi)) {
            CheckBoxList checkBoxList = new CheckBoxList();
            for (final String value : field.getValues()) {
                checkBoxList.addCheckBox(new JCheckBox(value), value);
            }
            addField(label, checkBoxList, variable);
        }
    }
}
Also used : JTextArea(javax.swing.JTextArea) JComboBox(javax.swing.JComboBox) JTextField(javax.swing.JTextField) JCheckBox(javax.swing.JCheckBox) JPasswordField(javax.swing.JPasswordField) CheckBoxList(org.jivesoftware.spark.component.CheckBoxList) FormField(org.jivesoftware.smackx.xdata.FormField)

Aggregations

JCheckBox (javax.swing.JCheckBox)8 JTextArea (javax.swing.JTextArea)8 CheckBoxList (org.jivesoftware.spark.component.CheckBoxList)8 JComboBox (javax.swing.JComboBox)5 JTextField (javax.swing.JTextField)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 FormField (org.jivesoftware.smackx.xdata.FormField)4 GridBagConstraints (java.awt.GridBagConstraints)3 Insets (java.awt.Insets)3 StringTokenizer (java.util.StringTokenizer)3 JLabel (javax.swing.JLabel)3 JScrollPane (javax.swing.JScrollPane)3 JPasswordField (javax.swing.JPasswordField)2 Form (org.jivesoftware.smackx.xdata.Form)2 Font (java.awt.Font)1 KeyAdapter (java.awt.event.KeyAdapter)1 KeyEvent (java.awt.event.KeyEvent)1 Iterator (java.util.Iterator)1 SmackException (org.jivesoftware.smack.SmackException)1