Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / jigsaw / src / org / w3c / tools / widgets / StringChoice.java
diff --git a/JMCR-Stable/real-world application/jigsaw/src/org/w3c/tools/widgets/StringChoice.java b/JMCR-Stable/real-world application/jigsaw/src/org/w3c/tools/widgets/StringChoice.java
new file mode 100644 (file)
index 0000000..caaa71f
--- /dev/null
@@ -0,0 +1,155 @@
+// StringChoice.java\r
+// $Id: StringChoice.java,v 1.1 2010/06/15 12:20:36 smhuang Exp $\r
+// (c) COPYRIGHT MIT and INRIA, 1998.\r
+// Please first read the full copyright statement in file COPYRIGHT.html\r
+\r
+package org.w3c.tools.widgets;\r
+\r
+import java.awt.BorderLayout;\r
+import java.awt.Choice;\r
+import java.awt.Container;\r
+import java.awt.GridLayout;\r
+import java.awt.TextComponent;\r
+import java.awt.TextField;\r
+\r
+import java.awt.event.ActionListener;\r
+import java.awt.event.ItemEvent;\r
+import java.awt.event.ItemListener;\r
+import java.awt.event.TextListener;\r
+\r
+\r
+/**\r
+ * @version $Revision: 1.1 $\r
+ * @author  Benoît Mahé (bmahe@w3.org)\r
+ */\r
+\r
+public class StringChoice extends BorderPanel {\r
+\r
+    class IListener implements ItemListener {\r
+\r
+       public void itemStateChanged(ItemEvent e) {\r
+           if (e.getStateChange() == ItemEvent.SELECTED) {\r
+               text.setText((String)e.getItem());\r
+           }\r
+       }\r
+       \r
+    }\r
+\r
+    public static final int ONE_LINE  = 1;\r
+    public static final int TWO_LINES = 2;\r
+\r
+    private Choice    choice = null;\r
+    private TextField text   = null;\r
+\r
+    public synchronized void addActionListener(ActionListener l) {\r
+       text.addActionListener(l);\r
+    }\r
+\r
+    public synchronized void removeActionListener(ActionListener l) {\r
+       text.removeActionListener(l);\r
+    }\r
+\r
+    public synchronized void addTextListener(TextListener l) {\r
+       text.addTextListener(l);\r
+    }\r
+\r
+    public void removeTextListener(TextListener l) {\r
+       text.removeTextListener(l);\r
+    }\r
+\r
+    public synchronized void addItemListener(ItemListener l) {\r
+       choice.addItemListener(l);\r
+    }\r
+\r
+    public synchronized void removeItemListener(ItemListener l) {\r
+       choice.removeItemListener(l);\r
+    }\r
+\r
+    public void addItem(String item) {\r
+       choice.addItem(item);\r
+    }\r
+\r
+    public void addItems(String items[]) {\r
+       for (int i = 0 ; i < items.length ; i++) {\r
+           if (items[i] != null)\r
+               addItem(items[i]);\r
+       }\r
+    }\r
+\r
+    public synchronized void select(String str) {\r
+       choice.select(str);\r
+    }\r
+\r
+    public synchronized void remove(String item) {\r
+       choice.remove(item);\r
+    }\r
+\r
+    public void removeAll() {\r
+       choice.removeAll();\r
+    }\r
+\r
+    public void setText(String stext) {\r
+       text.setText(stext);\r
+    }\r
+\r
+    public String getText() {\r
+       return text.getText();\r
+    }\r
+\r
+    private void build(int type) {\r
+       text = new TextField(20);\r
+       choice = new Choice();\r
+       choice.addItemListener( new IListener() );\r
+       switch(type) {\r
+       case ONE_LINE:\r
+           setLayout( new BorderLayout(5,5));\r
+           add(text,"West");\r
+           add(choice,"Center");\r
+           break;\r
+       case TWO_LINES:\r
+       default:\r
+           setLayout(new GridLayout(2,1,5,5));\r
+           add(choice);\r
+           add(text);\r
+           break;\r
+       }\r
+    }\r
+\r
+    /**\r
+     * Get a "one line" String choice with no border.\r
+     */\r
+    public StringChoice() {\r
+       super(IN,0);\r
+       build(ONE_LINE);\r
+    }\r
+\r
+    /**\r
+     * Get a StringChoice widget.\r
+     * @param type The posisionning (ONE_LINE, TWO_LINES)\r
+     */\r
+    public StringChoice(int type) {\r
+       super(IN, 0);\r
+       build(type);\r
+    }\r
+\r
+    /**\r
+     * Get a StringChoice widget.\r
+     * @param type The posisionning (ONE_LINE, TWO_LINES)\r
+     * @param border The border type (SOLID, RAISED, LOWERED, IN, OUT)\r
+     */\r
+    public StringChoice(int type, int border) {\r
+       super(border);\r
+       build(type);\r
+    }\r
+\r
+    /**\r
+     * Get a StringChoice widget.\r
+     * @param type The posisionning (ONE_LINE, TWO_LINES)\r
+     * @param border The border type (SOLID, RAISED, LOWERED, IN, OUT)\r
+     * @param thickness The border's thickness.\r
+     */\r
+    public StringChoice(int type, int border, int thickness) {\r
+       super(border, thickness);\r
+       build(type);\r
+    }\r
+}\r