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:
Bram Veenboer
2011-05-10 18:51:21 +00:00
parent dab8e9494b
commit bf6af992e3
5 changed files with 133 additions and 20 deletions

View File

@@ -12,5 +12,6 @@
<classpathentry kind="lib" path="lib/nativeloader-200505172341.jar"/> <classpathentry kind="lib" path="lib/nativeloader-200505172341.jar"/>
<classpathentry kind="lib" path="cfg"/> <classpathentry kind="lib" path="cfg"/>
<classpathentry kind="lib" path="resource"/> <classpathentry kind="lib" path="resource"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View 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();*/
}
}
}

View File

@@ -2,7 +2,6 @@ package pm;
import java.util.ArrayList; import java.util.ArrayList;
import pm.application.itunes.iTunesApplication;
import pm.event.spreader.LocalSpreader; import pm.event.spreader.LocalSpreader;
import pm.exception.application.ApplicationExitException; import pm.exception.application.ApplicationExitException;
import pm.exception.application.ApplicationInitialiseException; import pm.exception.application.ApplicationInitialiseException;
@@ -12,10 +11,12 @@ import pm.value.Action;
public class Main extends Manager { public class Main extends Manager {
protected ArrayCycle<Application> applicationCycle; protected ArrayCycle<Application> applicationCycle;
protected ApplicationSelector applicationSelector;
public Main() { public Main() {
super(new LocalSpreader()); super(new LocalSpreader());
applicationCycle = new ArrayCycle<Application>(); applicationCycle = new ArrayCycle<Application>();
applicationSelector = new ApplicationSelector(applicationCycle);
} }
protected void action(Action action) { protected void action(Action action) {
@@ -37,9 +38,9 @@ public class Main extends Manager {
public void initialise() throws DeviceInitialiseException { public void initialise() throws DeviceInitialiseException {
super.initialise(); super.initialise();
add(new iTunesApplication()); //add(new iTunesApplication());
log.error("main init"); //log.error("main init");
startApplications(); //startApplications();
} }
public void exit() { public void exit() {
@@ -47,7 +48,7 @@ public class Main extends Manager {
stop(); stop();
} }
protected void startApplications() { /*protected void startApplications() {
ArrayList<Application> removeList = new ArrayList<Application>(); ArrayList<Application> removeList = new ArrayList<Application>();
for (Application application : applicationCycle) { for (Application application : applicationCycle) {
try { try {
@@ -62,9 +63,9 @@ public class Main extends Manager {
remove(application); remove(application);
} }
eventSpreader.set(applicationCycle.current()); eventSpreader.set(applicationCycle.current());
} }*/
protected void exitApplications() { /*protected void exitApplications() {
System.out.println("Exit applications..."); System.out.println("Exit applications...");
for (Application application : applicationCycle) { for (Application application : applicationCycle) {
try { try {
@@ -72,15 +73,15 @@ public class Main extends Manager {
} catch (ApplicationExitException e) {} } catch (ApplicationExitException e) {}
} }
System.out.println("Exit main..."); System.out.println("Exit main...");
} }*/
protected void add(Application application) { /*protected void add(Application application) {
applicationCycle.add(application); applicationCycle.add(application);
} }*/
protected void remove(Application application) { /*protected void remove(Application application) {
applicationCycle.remove(application); applicationCycle.remove(application);
} }*/
public void start() { public void start() {
log.info("LocalManager!"); log.info("LocalManager!");

View File

@@ -21,8 +21,8 @@ public class Panel extends JFrame implements HoldButtonListener {
protected PanelButtonListener panelButtonListener; protected PanelButtonListener panelButtonListener;
protected ClassLoader classLoader; protected ClassLoader classLoader;
protected JTextArea feedbackArea; //protected JTextArea feedbackArea;
protected JScrollPane scrollPane; //protected JScrollPane scrollPane;
protected HoldButton previousButton; protected HoldButton previousButton;
protected HoldButton rewindButton; protected HoldButton rewindButton;
@@ -87,11 +87,11 @@ public class Panel extends JFrame implements HoldButtonListener {
protected void layoutControls() { protected void layoutControls() {
setLayout(new BorderLayout()); setLayout(new BorderLayout());
layoutFeedbackPanel(); //layoutFeedbackPanel();
layoutControlPanel(); layoutControlPanel();
} }
protected void layoutFeedbackPanel() { /*protected void layoutFeedbackPanel() {
JPanel feedbackPanel = new JPanel(); JPanel feedbackPanel = new JPanel();
feedbackArea = new JTextArea(10, 32); feedbackArea = new JTextArea(10, 32);
feedbackArea.setEditable(false); feedbackArea.setEditable(false);
@@ -126,7 +126,7 @@ public class Panel extends JFrame implements HoldButtonListener {
JScrollBar scrollBar = scrollPane.getVerticalScrollBar(); JScrollBar scrollBar = scrollPane.getVerticalScrollBar();
scrollBar.setValue(scrollBar.getMaximum()); scrollBar.setValue(scrollBar.getMaximum());
} }*/
protected void layoutControlPanel() { protected void layoutControlPanel() {
JPanel controlPanel = new JPanel(); JPanel controlPanel = new JPanel();
@@ -203,7 +203,7 @@ public class Panel extends JFrame implements HoldButtonListener {
} }
/* Feedback */ /* Feedback */
public void addFeedback(String format, Object... args) { /*public void addFeedback(String format, Object... args) {
feedbackArea.append(String.format(format, args)); feedbackArea.append(String.format(format, args));
JScrollBar scrollBar = scrollPane.getVerticalScrollBar(); JScrollBar scrollBar = scrollPane.getVerticalScrollBar();
scrollBar.setValue(scrollBar.getMaximum()); scrollBar.setValue(scrollBar.getMaximum());
@@ -211,5 +211,5 @@ public class Panel extends JFrame implements HoldButtonListener {
public void clearFeedback() { public void clearFeedback() {
feedbackArea.setText(""); feedbackArea.setText("");
} }*/
} }

View File

@@ -6,14 +6,31 @@ public class ArrayCycle<E> extends ArrayList<E> {
protected static final long serialVersionUID = 1L; protected static final long serialVersionUID = 1L;
protected int index = 0; protected int index = 0;
//protected Object nonEmpty;
public ArrayCycle(E... elementArary) { public ArrayCycle(E... elementArary) {
//nonEmpty = new Object();
for (E element : elementArary) { for (E element : elementArary) {
add(element); add(element);
} }
} }
/*public boolean add(E element) {
boolean result = super.add(element);
synchronized (nonEmpty) {
nonEmpty.notifyAll();
}
return result;
}*/
public E current() { public E current() {
/*while (index == 0) {
synchronized (nonEmpty) {
try {
nonEmpty.wait();
} catch (InterruptedException e) {}
}
}*/
return this.get(index); return this.get(index);
} }