Begin gemaakt aan de ApplicationSelector. Om een of andere reden werkt de ChangeListener niet. Ik ben ook nog niet tevreden over de naamgeving en de twee oerlelijke arrays.
This commit is contained in:
94
java/src/pm/ApplicationSelector.java
Normal file
94
java/src/pm/ApplicationSelector.java
Normal file
@@ -0,0 +1,94 @@
|
||||
package pm;
|
||||
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
|
||||
import javax.swing.AbstractButton;
|
||||
import javax.swing.ButtonModel;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JToggleButton;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
import pm.exception.application.ApplicationExitException;
|
||||
import pm.exception.application.ApplicationInitialiseException;
|
||||
import pm.util.ArrayCycle;
|
||||
|
||||
public class ApplicationSelector extends JFrame {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
protected final static String TITLE = "MIMIS Application Selector";
|
||||
|
||||
protected ArrayCycle<Application> applicationCycle;
|
||||
|
||||
protected JToggleButton gomPlayer;
|
||||
protected JToggleButton windowsMediaPlayer;
|
||||
protected JToggleButton iTunes;
|
||||
protected JToggleButton mediaPlayerClassic;
|
||||
protected JToggleButton vlc;
|
||||
protected JToggleButton winamp;
|
||||
|
||||
protected JToggleButton[] applicationButtons = {gomPlayer, windowsMediaPlayer, iTunes, mediaPlayerClassic, vlc, winamp};
|
||||
protected String[] applicationNames = {"GOM Player", "Windows Media Player", "iTunes", "Media Player Classic", "VLC", "Winamp"};;
|
||||
|
||||
public ApplicationSelector(ArrayCycle<Application> applicationCycle) {
|
||||
super(TITLE);
|
||||
System.out.println("Application Selector started");
|
||||
this.applicationCycle = applicationCycle;
|
||||
createButtons();
|
||||
layoutButtons();
|
||||
pack();
|
||||
setResizable(false);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
protected void createButtons() {
|
||||
for (int i = 0; i < applicationButtons.length; i++) {
|
||||
try {
|
||||
String applicationName = applicationNames[i];
|
||||
applicationButtons[i] = new JToggleButton(applicationName);
|
||||
Application application = (Application) Class.forName(applicationName).newInstance();
|
||||
ToggleChangeListener toggleChangeListener = new ToggleChangeListener(application);
|
||||
applicationButtons[i].addChangeListener(toggleChangeListener);
|
||||
System.out.println("App added");
|
||||
} catch (ClassNotFoundException e) {
|
||||
} catch (InstantiationException e) {
|
||||
} catch (IllegalAccessException e) {}
|
||||
}
|
||||
}
|
||||
|
||||
protected void layoutButtons() {
|
||||
JPanel applicationPanel = new JPanel(new GridLayout(0, 1));
|
||||
for (int i = 0; i < applicationButtons.length; i++) {
|
||||
applicationPanel.add(applicationButtons[i]);
|
||||
}
|
||||
add(applicationPanel);
|
||||
}
|
||||
|
||||
protected class ToggleChangeListener implements ChangeListener {
|
||||
Application application;
|
||||
|
||||
public ToggleChangeListener(Application application) {
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
public void stateChanged(ChangeEvent changeEvent) {
|
||||
System.out.println("Event!");
|
||||
AbstractButton abstractButton = (AbstractButton) changeEvent.getSource();
|
||||
ButtonModel buttonModel = abstractButton.getModel();
|
||||
boolean armed = buttonModel.isArmed();
|
||||
boolean pressed = buttonModel.isPressed();
|
||||
boolean selected = buttonModel.isSelected();
|
||||
System.out.println("Changed: " + armed + "/" + pressed + "/" + selected);
|
||||
/*try {
|
||||
application.initialise();
|
||||
application.start();
|
||||
applicationCycle.add(application);
|
||||
} catch (ApplicationInitialiseException e) {}*/
|
||||
/*applicationCycle.remove(application);
|
||||
application.exit();*/
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package pm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import pm.application.itunes.iTunesApplication;
|
||||
import pm.event.spreader.LocalSpreader;
|
||||
import pm.exception.application.ApplicationExitException;
|
||||
import pm.exception.application.ApplicationInitialiseException;
|
||||
@@ -12,10 +11,12 @@ import pm.value.Action;
|
||||
|
||||
public class Main extends Manager {
|
||||
protected ArrayCycle<Application> applicationCycle;
|
||||
|
||||
protected ApplicationSelector applicationSelector;
|
||||
|
||||
public Main() {
|
||||
super(new LocalSpreader());
|
||||
applicationCycle = new ArrayCycle<Application>();
|
||||
applicationSelector = new ApplicationSelector(applicationCycle);
|
||||
}
|
||||
|
||||
protected void action(Action action) {
|
||||
@@ -37,9 +38,9 @@ public class Main extends Manager {
|
||||
|
||||
public void initialise() throws DeviceInitialiseException {
|
||||
super.initialise();
|
||||
add(new iTunesApplication());
|
||||
log.error("main init");
|
||||
startApplications();
|
||||
//add(new iTunesApplication());
|
||||
//log.error("main init");
|
||||
//startApplications();
|
||||
}
|
||||
|
||||
public void exit() {
|
||||
@@ -47,7 +48,7 @@ public class Main extends Manager {
|
||||
stop();
|
||||
}
|
||||
|
||||
protected void startApplications() {
|
||||
/*protected void startApplications() {
|
||||
ArrayList<Application> removeList = new ArrayList<Application>();
|
||||
for (Application application : applicationCycle) {
|
||||
try {
|
||||
@@ -62,9 +63,9 @@ public class Main extends Manager {
|
||||
remove(application);
|
||||
}
|
||||
eventSpreader.set(applicationCycle.current());
|
||||
}
|
||||
}*/
|
||||
|
||||
protected void exitApplications() {
|
||||
/*protected void exitApplications() {
|
||||
System.out.println("Exit applications...");
|
||||
for (Application application : applicationCycle) {
|
||||
try {
|
||||
@@ -72,15 +73,15 @@ public class Main extends Manager {
|
||||
} catch (ApplicationExitException e) {}
|
||||
}
|
||||
System.out.println("Exit main...");
|
||||
}
|
||||
}*/
|
||||
|
||||
protected void add(Application application) {
|
||||
/*protected void add(Application application) {
|
||||
applicationCycle.add(application);
|
||||
}
|
||||
}*/
|
||||
|
||||
protected void remove(Application application) {
|
||||
/*protected void remove(Application application) {
|
||||
applicationCycle.remove(application);
|
||||
}
|
||||
}*/
|
||||
|
||||
public void start() {
|
||||
log.info("LocalManager!");
|
||||
|
||||
@@ -21,8 +21,8 @@ public class Panel extends JFrame implements HoldButtonListener {
|
||||
protected PanelButtonListener panelButtonListener;
|
||||
protected ClassLoader classLoader;
|
||||
|
||||
protected JTextArea feedbackArea;
|
||||
protected JScrollPane scrollPane;
|
||||
//protected JTextArea feedbackArea;
|
||||
//protected JScrollPane scrollPane;
|
||||
|
||||
protected HoldButton previousButton;
|
||||
protected HoldButton rewindButton;
|
||||
@@ -87,11 +87,11 @@ public class Panel extends JFrame implements HoldButtonListener {
|
||||
|
||||
protected void layoutControls() {
|
||||
setLayout(new BorderLayout());
|
||||
layoutFeedbackPanel();
|
||||
//layoutFeedbackPanel();
|
||||
layoutControlPanel();
|
||||
}
|
||||
|
||||
protected void layoutFeedbackPanel() {
|
||||
/*protected void layoutFeedbackPanel() {
|
||||
JPanel feedbackPanel = new JPanel();
|
||||
feedbackArea = new JTextArea(10, 32);
|
||||
feedbackArea.setEditable(false);
|
||||
@@ -126,7 +126,7 @@ public class Panel extends JFrame implements HoldButtonListener {
|
||||
|
||||
JScrollBar scrollBar = scrollPane.getVerticalScrollBar();
|
||||
scrollBar.setValue(scrollBar.getMaximum());
|
||||
}
|
||||
}*/
|
||||
|
||||
protected void layoutControlPanel() {
|
||||
JPanel controlPanel = new JPanel();
|
||||
@@ -203,7 +203,7 @@ public class Panel extends JFrame implements HoldButtonListener {
|
||||
}
|
||||
|
||||
/* Feedback */
|
||||
public void addFeedback(String format, Object... args) {
|
||||
/*public void addFeedback(String format, Object... args) {
|
||||
feedbackArea.append(String.format(format, args));
|
||||
JScrollBar scrollBar = scrollPane.getVerticalScrollBar();
|
||||
scrollBar.setValue(scrollBar.getMaximum());
|
||||
@@ -211,5 +211,5 @@ public class Panel extends JFrame implements HoldButtonListener {
|
||||
|
||||
public void clearFeedback() {
|
||||
feedbackArea.setText("");
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@@ -6,14 +6,31 @@ public class ArrayCycle<E> extends ArrayList<E> {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
protected int index = 0;
|
||||
//protected Object nonEmpty;
|
||||
|
||||
public ArrayCycle(E... elementArary) {
|
||||
//nonEmpty = new Object();
|
||||
for (E element : elementArary) {
|
||||
add(element);
|
||||
}
|
||||
}
|
||||
|
||||
/*public boolean add(E element) {
|
||||
boolean result = super.add(element);
|
||||
synchronized (nonEmpty) {
|
||||
nonEmpty.notifyAll();
|
||||
}
|
||||
return result;
|
||||
}*/
|
||||
|
||||
public E current() {
|
||||
/*while (index == 0) {
|
||||
synchronized (nonEmpty) {
|
||||
try {
|
||||
nonEmpty.wait();
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
}*/
|
||||
return this.get(index);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user