diff game/IDMContainer.java @ 49:e6da5c71be28

Add more code to IDM widgets, do preliminary work for integrating them.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 22 Feb 2011 10:52:08 +0200
parents
children 496e616ff09d
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/game/IDMContainer.java	Tue Feb 22 10:52:08 2011 +0200
@@ -0,0 +1,58 @@
+/*
+ * Ristipolku IDM widget container
+ * (C) Copyright 2011 Matti 'ccr' Hämäläinen <ccr@tnsp.org>
+ */
+package game;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.util.*;
+
+
+public class IDMContainer extends IDMWidget
+{
+    ArrayList<IDMWidget> widgets;
+
+    public IDMContainer()
+    {
+        widgets = new ArrayList<IDMWidget>();
+    }
+    
+    public void add(IDMWidget widget)
+    {
+        widgets.add(widget);
+    }
+    
+    public void paint(Graphics2D g)
+    {
+        for (IDMWidget widget : widgets)
+            widget.paint(g);
+    }
+    
+    public void mousePressed(MouseEvent e)
+    {
+        for (IDMWidget widget : widgets)
+        {
+            if (widget.contains(e.getPoint()))
+                widget.mousePressed(e);
+        }
+    }
+
+    public void mouseReleased(MouseEvent e)
+    {
+        for (IDMWidget widget : widgets)
+        {
+            widget.mousePressed(e);
+        }
+    }
+
+    public boolean keyPressed(KeyEvent e)
+    {
+        for (IDMWidget widget : widgets)
+        {
+            if (widget.keyPressed(e))
+                return true;
+        }
+        return false;
+    }
+}