GUI aangepast en uitgebreid. Begin gemaakt met het controleren of een applicatie is afgelosten -> isAlive events sturen?
This commit is contained in:
60
java/src/pm/GUI.java
Normal file
60
java/src/pm/GUI.java
Normal file
@@ -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<Application> applicationSelector = new Selector<Application>(APPLICATION_TITLE);
|
||||
for (Application application : applicationArray) {
|
||||
applicationSelector.add(application, application.title());
|
||||
}
|
||||
controlPanel.add(applicationSelector);
|
||||
|
||||
|
||||
Selector<Device> deviceSelector = new Selector<Device>(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;
|
||||
}
|
||||
}
|
||||
@@ -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<Application> 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<Application>(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);
|
||||
}
|
||||
|
||||
@@ -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<Device> deviceList;
|
||||
|
||||
@@ -37,7 +35,6 @@ public abstract class Manager extends EventHandler {
|
||||
new RumblepadDevice(),
|
||||
new Extreme3DDevice(),
|
||||
new NetworkDevice()};
|
||||
deviceSelector = new DeviceSelector(deviceArray);
|
||||
}
|
||||
|
||||
public void exit() {
|
||||
|
||||
@@ -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<T extends Worker & Selectable> extends JFrame {
|
||||
public class Selector<T extends Worker> extends JPanel {
|
||||
protected Log log = LogFactory.getLog(getClass());
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
//protected ArrayList<T> 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<T> button = new SelectButton<T>(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<T> button = new SelectButton<T>(worker, title);
|
||||
add(button);
|
||||
log.debug(String.format("Item added: %s", title));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package pm.application;
|
||||
|
||||
import pm.Application;
|
||||
import pm.Selector;
|
||||
|
||||
public class ApplicationSelector extends Selector<Application> {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
protected final static String TITLE = "MIMIS Application Selector";
|
||||
|
||||
public ApplicationSelector(Application[] applicationArray) {
|
||||
super(applicationArray);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package pm.device;
|
||||
|
||||
import pm.Device;
|
||||
import pm.Selector;
|
||||
|
||||
public class DeviceSelector extends Selector<Device> {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
protected final static String TITLE = "MIMIS Device Selector";
|
||||
|
||||
public DeviceSelector(Device[] deviceArray) {
|
||||
super(deviceArray);
|
||||
}
|
||||
}
|
||||
@@ -9,14 +9,15 @@ import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import pm.Worker;
|
||||
|
||||
public class SelectButton<T extends Worker & Selectable> extends JToggleButton implements ItemListener {
|
||||
public class SelectButton<T extends Worker> 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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user