From 153bc2c8d66a694f9f8229eac172356a0801c6b5 Mon Sep 17 00:00:00 2001 From: Bram Veenboer Date: Wed, 18 May 2011 19:45:22 +0000 Subject: [PATCH] GUI aangepast en uitgebreid. Begin gemaakt met het controleren of een applicatie is afgelosten -> isAlive events sturen? --- java/src/pm/GUI.java | 60 +++++++++++++++++++ java/src/pm/Main.java | 21 +++++-- java/src/pm/Manager.java | 3 - java/src/pm/Selector.java | 35 ++++------- java/src/pm/Worker.java | 4 +- .../pm/application/ApplicationSelector.java | 14 ----- .../application/itunes/iTunesApplication.java | 6 +- java/src/pm/device/DeviceSelector.java | 14 ----- java/src/pm/selector/SelectButton.java | 5 +- 9 files changed, 99 insertions(+), 63 deletions(-) create mode 100644 java/src/pm/GUI.java delete mode 100644 java/src/pm/application/ApplicationSelector.java delete mode 100644 java/src/pm/device/DeviceSelector.java diff --git a/java/src/pm/GUI.java b/java/src/pm/GUI.java new file mode 100644 index 0000000..f7c6013 --- /dev/null +++ b/java/src/pm/GUI.java @@ -0,0 +1,60 @@ +package pm; + +import java.awt.GridLayout; +import java.awt.TextArea; + +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JSeparator; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class GUI extends JFrame { + protected Log log = LogFactory.getLog(getClass()); + protected static final long serialVersionUID = 1L; + + protected static final String TITLE = "Mimis GUI"; + protected static final String APPLICATION_TITLE = "Applications"; + protected static final String DEVICE_TITLE = "Devices"; + + public GUI(Application[] applicationArray, Device[] deviceArray) { + super(TITLE); + setLayout(new GridLayout(0, 1)); + //add(new JSeparator()); + JPanel controlPanel = createControlPanel(applicationArray, deviceArray); + JPanel feedbackPanel = createFeedbackPanel(); + add(controlPanel); + add(feedbackPanel); + setResizable(false); + setVisible(true); + pack(); + } + + protected JPanel createControlPanel(Application[] applicationArray, Device[] deviceArray) { + JPanel controlPanel = new JPanel(new GridLayout(1, 0)); + Selector applicationSelector = new Selector(APPLICATION_TITLE); + for (Application application : applicationArray) { + applicationSelector.add(application, application.title()); + } + controlPanel.add(applicationSelector); + + + Selector deviceSelector = new Selector(DEVICE_TITLE); + for (Device device : deviceArray) { + deviceSelector.add(device, device.title()); + } + controlPanel.add(deviceSelector); + + return controlPanel; + } + + protected JPanel createFeedbackPanel() { + JPanel feedbackPanel = new JPanel(); + TextArea textArea = new TextArea(); + textArea.setEditable(false); + feedbackPanel.add(textArea); + return feedbackPanel; + } +} diff --git a/java/src/pm/Main.java b/java/src/pm/Main.java index 90ea837..c300cf9 100644 --- a/java/src/pm/Main.java +++ b/java/src/pm/Main.java @@ -3,13 +3,19 @@ package pm; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import pm.application.ApplicationSelector; import pm.application.cmd.windows.gomplayer.GomPlayerApplication; import pm.application.cmd.windows.winamp.WinampApplication; import pm.application.cmd.windows.wmp.WMPApplication; import pm.application.itunes.iTunesApplication; import pm.application.mpc.MPCApplication; import pm.application.vlc.VLCApplication; +import pm.device.javainput.extreme3d.Extreme3DDevice; +import pm.device.javainput.rumblepad.RumblepadDevice; +import pm.device.jintellitype.JIntellitypeDevice; +import pm.device.network.NetworkDevice; +import pm.device.panel.PanelDevice; +import pm.device.player.PlayerDevice; +import pm.device.wiimote.WiimoteDevice; import pm.event.router.LocalRouter; import pm.util.ArrayCycle; import pm.value.Action; @@ -17,7 +23,6 @@ import pm.value.Action; public class Main extends Manager { protected Log log = LogFactory.getLog(getClass()); protected ArrayCycle applicationCycle; - protected ApplicationSelector applicationSelector; public Main() { super(new LocalRouter()); @@ -48,9 +53,17 @@ public class Main extends Manager { new WMPApplication(), new MPCApplication(), new VLCApplication(), - new WinampApplication()}; - applicationSelector = new ApplicationSelector(applicationArray); + new WinampApplication()}; applicationCycle = new ArrayCycle(applicationArray); + Device[] deviceArray = new Device[] { + new WiimoteDevice(), + new PanelDevice(), + new JIntellitypeDevice(), + new PlayerDevice(), + new RumblepadDevice(), + new Extreme3DDevice(), + new NetworkDevice()}; + GUI gui = new GUI(applicationArray, deviceArray); eventRouter.set(applicationCycle.current()); super.start(false); } diff --git a/java/src/pm/Manager.java b/java/src/pm/Manager.java index c18779a..685bb43 100644 --- a/java/src/pm/Manager.java +++ b/java/src/pm/Manager.java @@ -5,7 +5,6 @@ import java.util.ArrayList; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import pm.device.DeviceSelector; import pm.device.javainput.extreme3d.Extreme3DDevice; import pm.device.javainput.rumblepad.RumblepadDevice; import pm.device.jintellitype.JIntellitypeDevice; @@ -18,7 +17,6 @@ import pm.event.EventRouter; public abstract class Manager extends EventHandler { protected Log log = LogFactory.getLog(getClass()); - protected DeviceSelector deviceSelector; protected ArrayList deviceList; @@ -37,7 +35,6 @@ public abstract class Manager extends EventHandler { new RumblepadDevice(), new Extreme3DDevice(), new NetworkDevice()}; - deviceSelector = new DeviceSelector(deviceArray); } public void exit() { diff --git a/java/src/pm/Selector.java b/java/src/pm/Selector.java index bfa9820..8394901 100644 --- a/java/src/pm/Selector.java +++ b/java/src/pm/Selector.java @@ -2,39 +2,28 @@ package pm; import java.awt.GridLayout; -import javax.swing.JFrame; +import javax.swing.JLabel; import javax.swing.JPanel; +import javax.swing.SwingConstants; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import pm.selector.SelectButton; -import pm.selector.Selectable; -public class Selector extends JFrame { +public class Selector extends JPanel { protected Log log = LogFactory.getLog(getClass()); protected static final long serialVersionUID = 1L; - - //protected ArrayList activatableArray; - - public Selector(T[] activatableArray) { - createPanel(activatableArray); - setUndecorated(true); - pack(); - setResizable(false); - setVisible(true); + + public Selector(String title) { + setLayout(new GridLayout(0, 1)); + add(new JLabel(title, SwingConstants.CENTER)); log.debug("Selector constructed"); } - - protected void createPanel(T[] activatableArray) { - JPanel panel = new JPanel(new GridLayout(0, 1)); - for (T selectable : activatableArray) { - String title = selectable.title(); - SelectButton button = new SelectButton(selectable); - button.setText(title); - panel.add(button); - log.debug(String.format("Item added: %s", title)); - } - add(panel); + + protected void add(T worker, String title) { + SelectButton button = new SelectButton(worker, title); + add(button); + log.debug(String.format("Item added: %s", title)); } } diff --git a/java/src/pm/Worker.java b/java/src/pm/Worker.java index 0e32e8d..9de782c 100644 --- a/java/src/pm/Worker.java +++ b/java/src/pm/Worker.java @@ -56,7 +56,7 @@ public abstract class Worker implements Runnable { start(); } synchronized (this) { - notify(); + notifyAll(); } active = true; } @@ -74,7 +74,7 @@ public abstract class Worker implements Runnable { public final void run() { while (running) { - if (active) { + if (active()) { work(); } else { try { diff --git a/java/src/pm/application/ApplicationSelector.java b/java/src/pm/application/ApplicationSelector.java deleted file mode 100644 index 35f0175..0000000 --- a/java/src/pm/application/ApplicationSelector.java +++ /dev/null @@ -1,14 +0,0 @@ -package pm.application; - -import pm.Application; -import pm.Selector; - -public class ApplicationSelector extends Selector { - protected static final long serialVersionUID = 1L; - - protected final static String TITLE = "MIMIS Application Selector"; - - public ApplicationSelector(Application[] applicationArray) { - super(applicationArray); - } -} \ No newline at end of file diff --git a/java/src/pm/application/itunes/iTunesApplication.java b/java/src/pm/application/itunes/iTunesApplication.java index 8bd8ca3..cf6b417 100644 --- a/java/src/pm/application/itunes/iTunesApplication.java +++ b/java/src/pm/application/itunes/iTunesApplication.java @@ -23,7 +23,11 @@ public class iTunesApplication extends Application implements iTunesEventsInterf super(TITLE); iTunes = new iTunes(); } - + + /*public boolean active() { + return active; + }*/ + public void activate() { synchronized (iTunes) { iTunes.connect(); diff --git a/java/src/pm/device/DeviceSelector.java b/java/src/pm/device/DeviceSelector.java deleted file mode 100644 index cb1daaa..0000000 --- a/java/src/pm/device/DeviceSelector.java +++ /dev/null @@ -1,14 +0,0 @@ -package pm.device; - -import pm.Device; -import pm.Selector; - -public class DeviceSelector extends Selector { - protected static final long serialVersionUID = 1L; - - protected final static String TITLE = "MIMIS Device Selector"; - - public DeviceSelector(Device[] deviceArray) { - super(deviceArray); - } -} \ No newline at end of file diff --git a/java/src/pm/selector/SelectButton.java b/java/src/pm/selector/SelectButton.java index 420cbe9..813f821 100644 --- a/java/src/pm/selector/SelectButton.java +++ b/java/src/pm/selector/SelectButton.java @@ -9,14 +9,15 @@ import org.apache.commons.logging.LogFactory; import pm.Worker; -public class SelectButton extends JToggleButton implements ItemListener { +public class SelectButton extends JToggleButton implements ItemListener { protected Log log = LogFactory.getLog(getClass()); protected static final long serialVersionUID = 1L; protected T activatable; - public SelectButton(T activatable) { + public SelectButton(T activatable, String title) { this.activatable = activatable; + setText(title); addItemListener(this); }