Commits

Rui Vieira committed 9989a63

Commit of SelectableList

Comments (0)

Files changed (2)

src/main/java/org/ruivieira/orwell/components/SelectableList.form

+<?xml version="1.0" encoding="UTF-8"?>
+<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.ruivieira.orwell.components.SelectableList">
+  <grid id="27dc6" binding="mainPanel" custom-create="true" layout-manager="FormLayout">
+    <rowspec value="center:max(d;4px):noGrow"/>
+    <rowspec value="top:3px:noGrow"/>
+    <rowspec value="center:24px:noGrow"/>
+    <rowspec value="top:3px:noGrow"/>
+    <rowspec value="center:max(d;4px):noGrow"/>
+    <rowspec value="top:3px:noGrow"/>
+    <rowspec value="center:max(d;4px):noGrow"/>
+    <rowspec value="top:100px:grow"/>
+    <rowspec value="center:max(d;4px):noGrow"/>
+    <colspec value="fill:100px:grow"/>
+    <colspec value="fill:3px:noGrow"/>
+    <colspec value="fill:max(d;4px):noGrow"/>
+    <constraints>
+      <xy x="20" y="20" width="176" height="203"/>
+    </constraints>
+    <properties/>
+    <border type="none"/>
+    <children>
+      <component id="22619" class="org.ruivieira.orwell.OComboBox" binding="myCombobox">
+        <constraints>
+          <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
+          <forms/>
+        </constraints>
+        <properties/>
+      </component>
+      <scrollpane id="5f2ad">
+        <constraints>
+          <grid row="2" column="0" row-span="6" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
+          <forms defaultalign-vert="false"/>
+        </constraints>
+        <properties/>
+        <border type="none"/>
+        <children>
+          <component id="fc43c" class="org.ruivieira.orwell.components.MyListbox" binding="myListbox">
+            <constraints/>
+          </component>
+        </children>
+      </scrollpane>
+      <component id="8c625" class="javax.swing.JButton" binding="jBAdd">
+        <constraints>
+          <grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+          <forms/>
+        </constraints>
+        <properties>
+          <text value="&amp;Add"/>
+        </properties>
+      </component>
+      <component id="474dd" class="javax.swing.JButton" binding="jBRemove">
+        <constraints>
+          <grid row="6" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+          <forms/>
+        </constraints>
+        <properties>
+          <text value="&amp;Remove"/>
+        </properties>
+      </component>
+      <component id="c60ff" class="javax.swing.JButton" binding="jBAddAll">
+        <constraints>
+          <grid row="4" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+          <forms/>
+        </constraints>
+        <properties>
+          <text value="A&amp;dd all"/>
+        </properties>
+      </component>
+    </children>
+  </grid>
+</form>

src/main/java/org/ruivieira/orwell/components/SelectableList.java

+package org.ruivieira.orwell.components;
+
+import com.jgoodies.forms.layout.CellConstraints;
+import com.jgoodies.forms.layout.FormLayout;
+import org.ruivieira.orwell.OComboBox;
+
+import javax.swing.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.List;
+
+/**
+ * Author: rvieira
+ * Date: 07/11/11
+ * Time: 15:55
+ */
+public class SelectableList {
+    public OComboBox myCombobox;
+    public JPanel mainPanel;
+    public MyListbox myListbox;
+    public JButton jBAdd;
+    public JButton jBAddAll;
+    public JButton jBRemove;
+
+    public SelectableList() {
+        $$$setupUI$$$();
+        jBAddAll.addActionListener(new ActionListener() {
+            @Override
+            public void actionPerformed(ActionEvent actionEvent) {
+                myListbox.clearAll();
+                setSelected(myCombobox.getAllItemsAsStrings());
+            }
+        });
+        jBAdd.addActionListener(new ActionListener() {
+            @Override
+            public void actionPerformed(ActionEvent actionEvent) {
+                String newValue = myCombobox.getSelectedString();
+                myListbox.addItem(newValue);
+            }
+        });
+    }
+
+    public void setSelected(List items) {
+        myListbox.clearAll();
+        for (Object item : items) {
+            myListbox.addItem(item);
+        }
+    }
+
+    public List<String> getList() {
+        return myListbox.getAllItemsAsStrings();
+    }
+
+    public void clearChoices() {
+        myCombobox.clearAll();
+    }
+
+    public void setChoices(List<String> values) {
+        myCombobox.clearAll();
+        myCombobox.addItemsVector(values);
+    }
+
+    void setComboboxMaximumRowCount(int _rowCount) {
+        myCombobox.setMaximumRowCount(_rowCount);
+    }
+
+
+    private void createUIComponents() {
+        mainPanel = new JPanel();
+
+        // Listbox initialisation
+        myListbox.clearAll();
+        myListbox.setModel(new DefaultListModel());
+        myListbox.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
+    }
+
+    /**
+     * Method generated by IntelliJ IDEA GUI Designer
+     * >>> IMPORTANT!! <<<
+     * DO NOT edit this method OR call it in your code!
+     *
+     * @noinspection ALL
+     */
+    private void $$$setupUI$$$() {
+        createUIComponents();
+        mainPanel.setLayout(new FormLayout("fill:100px:grow,fill:3px:noGrow,fill:max(d;4px):noGrow", "center:max(d;4px):noGrow,top:3px:noGrow,center:24px:noGrow,top:3px:noGrow,center:max(d;4px):noGrow,top:3px:noGrow,center:max(d;4px):noGrow,top:100px:grow,center:max(d;4px):noGrow"));
+        myCombobox = new OComboBox();
+        CellConstraints cc = new CellConstraints();
+        mainPanel.add(myCombobox, cc.xy(1, 1));
+        final JScrollPane scrollPane1 = new JScrollPane();
+        mainPanel.add(scrollPane1, cc.xywh(1, 3, 1, 6, CellConstraints.DEFAULT, CellConstraints.FILL));
+        myListbox = new MyListbox();
+        scrollPane1.setViewportView(myListbox);
+        jBAdd = new JButton();
+        jBAdd.setText("Add");
+        jBAdd.setMnemonic('A');
+        jBAdd.setDisplayedMnemonicIndex(0);
+        mainPanel.add(jBAdd, cc.xy(3, 3));
+        jBRemove = new JButton();
+        jBRemove.setText("Remove");
+        jBRemove.setMnemonic('R');
+        jBRemove.setDisplayedMnemonicIndex(0);
+        mainPanel.add(jBRemove, cc.xy(3, 7));
+        jBAddAll = new JButton();
+        jBAddAll.setText("Add all");
+        jBAddAll.setMnemonic('D');
+        jBAddAll.setDisplayedMnemonicIndex(1);
+        mainPanel.add(jBAddAll, cc.xy(3, 5));
+    }
+
+    /**
+     * @noinspection ALL
+     */
+    public JComponent $$$getRootComponent$$$() {
+        return mainPanel;
+    }
+}