]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scenegraph.swing/src/org/simantics/scenegraph/swing/ListBoxNode.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.scenegraph.swing / src / org / simantics / scenegraph / swing / ListBoxNode.java
index 78767e195630bdadf43cda6bcbdac2e0bc5cff4f..6bfd7092fffb0569cccf0999e9461d60a077f1d5 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.scenegraph.swing;\r
-\r
-import java.awt.Color;\r
-import java.awt.Font;\r
-import java.awt.event.ActionEvent;\r
-import java.awt.event.ActionListener;\r
-import java.awt.event.FocusEvent;\r
-import java.awt.event.FocusListener;\r
-import java.awt.event.KeyEvent;\r
-import java.awt.event.KeyListener;\r
-import java.beans.PropertyChangeEvent;\r
-import java.beans.PropertyChangeListener;\r
-import java.util.List;\r
-\r
-import javax.swing.DefaultListModel;\r
-import javax.swing.JList;\r
-import javax.swing.JScrollPane;\r
-\r
-import org.simantics.scenegraph.utils.DummyComponent;\r
-\r
-public class ListBoxNode extends ComponentNode<JScrollPane> implements FocusListener, PropertyChangeListener, KeyListener {\r
-    /**\r
-     * \r
-     */\r
-    private static final long serialVersionUID = 7073028693751719102L;\r
-\r
-    protected boolean editable = true;\r
-    protected Object value = "";\r
-    protected String tooltip = "";\r
-    protected double borderWidth = 0;\r
-\r
-    protected transient ActionListener actionListener = null;\r
-\r
-    protected Font font = null;\r
-    protected Color color = null;\r
-    protected List<String> items = null;\r
-    \r
-    protected transient JList list = null;\r
-    \r
-    @Override\r
-    public String toString() {\r
-        return super.toString() + "[editable=" + editable + ", value=" + value + "]";\r
-    }\r
-    \r
-    @Override\r
-    public void init() {\r
-       list = new JList(new DefaultListModel());\r
-        component = new JScrollPane(list);\r
-        list.setEnabled(editable);\r
-        component.setEnabled(editable);\r
-//        component.addChangeListener(this);\r
-        list.addFocusListener(this);\r
-        list.addKeyListener(this);\r
-        list.setLocation(0, 0);\r
-        \r
-        super.init();\r
-    }\r
-\r
-    @SyncField("items")\r
-    public void setItems(List<String> items) {\r
-        this.items = items;\r
-        DefaultListModel model = (DefaultListModel)list.getModel();\r
-        model.clear();\r
-        for(String item : items) {\r
-               model.addElement(item);\r
-        }\r
-        if(items.size() > 0)\r
-               list.setSelectedValue(items.get(0), true);\r
-    }\r
-\r
-    @SyncField("editable")\r
-    public void setEditable(boolean value) {\r
-        this.editable = value;\r
-\r
-        if(component != null) {\r
-            component.setEnabled(value);\r
-        }\r
-    }\r
-\r
-    @PropertySetter("Stroke Width")\r
-    @SyncField("borderWidth")\r
-    public void setBorderWidth(Float borderWidth) {\r
-        this.borderWidth = borderWidth;\r
-//        if(component != null) {\r
-//            ((TextField)component).setBorder(borderWidth);\r
-//        }\r
-    }\r
-\r
-    @SyncField("value")\r
-    public void setValue(Object value) {\r
-        this.value = value;\r
-        // RemoteViewer does not have component initialized\r
-        if (component != null && value != null) {\r
-            //System.out.println("MonitorNode.setText(" + value + ")");\r
-               list.setSelectedValue(value, true);\r
-            component.repaint();\r
-        }\r
-    }\r
-\r
-    @SyncField("tooltip")\r
-    public void setToolTipText(String tooltip) {\r
-        this.tooltip = tooltip;\r
-        if (component != null) {\r
-            component.setToolTipText(tooltip);\r
-        }\r
-    }\r
-\r
-    @PropertySetter("Font")\r
-    @SyncField("font")\r
-    public void setFont(Font font) {\r
-        this.font = font;\r
-        if (component != null) {\r
-            setComponentFont(font);\r
-        }\r
-    }\r
-\r
-    @PropertySetter("Color")\r
-    @SyncField("color")\r
-    public void setColor(Color color) {\r
-        this.color = color;\r
-        if (component != null) {\r
-            component.setForeground(color);\r
-        }\r
-    }\r
-    \r
-    public Object getValue() {\r
-        return value;\r
-    }\r
-\r
-    public Font getFont() {\r
-        return font;\r
-    }\r
-\r
-    @Override\r
-    public void propertyChange(PropertyChangeEvent evt) {\r
-        if("value".equals(evt.getPropertyName()) && component != null) {\r
-               list.setSelectedValue(evt.getNewValue(), true);\r
-            component.repaint();\r
-        } else if("editable".equals(evt.getPropertyName()) && component != null) {\r
-            component.setEnabled((Boolean)evt.getNewValue());\r
-        }\r
-    }\r
-\r
-\r
-    public void setActionListener(ActionListener actionListener) {\r
-        this.actionListener = actionListener;\r
-    }\r
-\r
-    void loseFocus() {\r
-        if (component != null)\r
-            if (component.isFocusOwner())\r
-                if (container.getParent() != null)\r
-                    container.getParent().requestFocusInWindow(); // Lose focus\r
-    }\r
-\r
-    @Override\r
-    public void focusGained(FocusEvent arg0) {\r
-    }\r
-\r
-    @Override\r
-    public void focusLost(FocusEvent arg0) {\r
-        if (component != null) {\r
-            ActionEvent e = new ActionEvent(component, ActionEvent.ACTION_PERFORMED, (String) list.getSelectedValue());\r
-            performAction(e);\r
-        }\r
-    }\r
-\r
-    /**\r
-     * Wrapper method to send event to serverside\r
-     * \r
-     * @param e\r
-     */\r
-    @ServerSide\r
-    public void performAction(ActionEvent e) {\r
-        if (actionListener != null) {\r
-            //System.out.println("MonitorNode.performAction(" + e + ")");\r
-            actionListener.actionPerformed(e);\r
-        }\r
-    }\r
-\r
-    @Override\r
-    public void keyPressed(KeyEvent e) {\r
-    }\r
-\r
-    @Override\r
-    public void keyTyped(KeyEvent e) {\r
-    }\r
-\r
-    @Override\r
-    public void keyReleased(KeyEvent e) {\r
-        if (e.getModifiers() == 0 && e.getKeyCode() == KeyEvent.VK_ESCAPE) {\r
-            // ESC without modifiers == CANCEL edit\r
-            // TODO: signal about cancellation\r
-            loseFocus();\r
-        }\r
-    }\r
-\r
-    /**\r
-     * Quick hack to test widget feature..\r
-     * FIXME: Use existing methods or variables..\r
-     * \r
-     * @param input\r
-     */\r
-    public void input(String input) {\r
-        ActionEvent e = new ActionEvent(new DummyComponent(), ActionEvent.ACTION_PERFORMED, input);\r
-        performAction(e);\r
-    }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.scenegraph.swing;
+
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.util.List;
+
+import javax.swing.DefaultListModel;
+import javax.swing.JList;
+import javax.swing.JScrollPane;
+
+import org.simantics.scenegraph.utils.DummyComponent;
+
+public class ListBoxNode extends ComponentNode<JScrollPane> implements FocusListener, PropertyChangeListener, KeyListener {
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 7073028693751719102L;
+
+    protected boolean editable = true;
+    protected Object value = "";
+    protected String tooltip = "";
+    protected double borderWidth = 0;
+
+    protected transient ActionListener actionListener = null;
+
+    protected Font font = null;
+    protected Color color = null;
+    protected List<String> items = null;
+    
+    protected transient JList list = null;
+    
+    @Override
+    public String toString() {
+        return super.toString() + "[editable=" + editable + ", value=" + value + "]";
+    }
+    
+    @Override
+    public void init() {
+       list = new JList(new DefaultListModel());
+        component = new JScrollPane(list);
+        list.setEnabled(editable);
+        component.setEnabled(editable);
+//        component.addChangeListener(this);
+        list.addFocusListener(this);
+        list.addKeyListener(this);
+        list.setLocation(0, 0);
+        
+        super.init();
+    }
+
+    @SyncField("items")
+    public void setItems(List<String> items) {
+        this.items = items;
+        DefaultListModel model = (DefaultListModel)list.getModel();
+        model.clear();
+        for(String item : items) {
+               model.addElement(item);
+        }
+        if(items.size() > 0)
+               list.setSelectedValue(items.get(0), true);
+    }
+
+    @SyncField("editable")
+    public void setEditable(boolean value) {
+        this.editable = value;
+
+        if(component != null) {
+            component.setEnabled(value);
+        }
+    }
+
+    @PropertySetter("Stroke Width")
+    @SyncField("borderWidth")
+    public void setBorderWidth(Float borderWidth) {
+        this.borderWidth = borderWidth;
+//        if(component != null) {
+//            ((TextField)component).setBorder(borderWidth);
+//        }
+    }
+
+    @SyncField("value")
+    public void setValue(Object value) {
+        this.value = value;
+        // RemoteViewer does not have component initialized
+        if (component != null && value != null) {
+            //System.out.println("MonitorNode.setText(" + value + ")");
+               list.setSelectedValue(value, true);
+            component.repaint();
+        }
+    }
+
+    @SyncField("tooltip")
+    public void setToolTipText(String tooltip) {
+        this.tooltip = tooltip;
+        if (component != null) {
+            component.setToolTipText(tooltip);
+        }
+    }
+
+    @PropertySetter("Font")
+    @SyncField("font")
+    public void setFont(Font font) {
+        this.font = font;
+        if (component != null) {
+            setComponentFont(font);
+        }
+    }
+
+    @PropertySetter("Color")
+    @SyncField("color")
+    public void setColor(Color color) {
+        this.color = color;
+        if (component != null) {
+            component.setForeground(color);
+        }
+    }
+    
+    public Object getValue() {
+        return value;
+    }
+
+    public Font getFont() {
+        return font;
+    }
+
+    @Override
+    public void propertyChange(PropertyChangeEvent evt) {
+        if("value".equals(evt.getPropertyName()) && component != null) {
+               list.setSelectedValue(evt.getNewValue(), true);
+            component.repaint();
+        } else if("editable".equals(evt.getPropertyName()) && component != null) {
+            component.setEnabled((Boolean)evt.getNewValue());
+        }
+    }
+
+
+    public void setActionListener(ActionListener actionListener) {
+        this.actionListener = actionListener;
+    }
+
+    void loseFocus() {
+        if (component != null)
+            if (component.isFocusOwner())
+                if (container.getParent() != null)
+                    container.getParent().requestFocusInWindow(); // Lose focus
+    }
+
+    @Override
+    public void focusGained(FocusEvent arg0) {
+    }
+
+    @Override
+    public void focusLost(FocusEvent arg0) {
+        if (component != null) {
+            ActionEvent e = new ActionEvent(component, ActionEvent.ACTION_PERFORMED, (String) list.getSelectedValue());
+            performAction(e);
+        }
+    }
+
+    /**
+     * Wrapper method to send event to serverside
+     * 
+     * @param e
+     */
+    @ServerSide
+    public void performAction(ActionEvent e) {
+        if (actionListener != null) {
+            //System.out.println("MonitorNode.performAction(" + e + ")");
+            actionListener.actionPerformed(e);
+        }
+    }
+
+    @Override
+    public void keyPressed(KeyEvent e) {
+    }
+
+    @Override
+    public void keyTyped(KeyEvent e) {
+    }
+
+    @Override
+    public void keyReleased(KeyEvent e) {
+        if (e.getModifiers() == 0 && e.getKeyCode() == KeyEvent.VK_ESCAPE) {
+            // ESC without modifiers == CANCEL edit
+            // TODO: signal about cancellation
+            loseFocus();
+        }
+    }
+
+    /**
+     * Quick hack to test widget feature..
+     * FIXME: Use existing methods or variables..
+     * 
+     * @param input
+     */
+    public void input(String input) {
+        ActionEvent e = new ActionEvent(new DummyComponent(), ActionEvent.ACTION_PERFORMED, input);
+        performAction(e);
+    }
+}