GUI knoppen gemaakt. Er is een probleem dat applicaties die al gestart zijn voordat mimis start niet afgesloten kunnen worden.
This commit is contained in:
@@ -8,6 +8,7 @@ import javax.swing.JButton;
|
|||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JToggleButton;
|
||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
import javax.swing.WindowConstants;
|
import javax.swing.WindowConstants;
|
||||||
|
|
||||||
@@ -55,7 +56,7 @@ public class GUI extends JFrame {
|
|||||||
protected JPanel createManagerPanel(Manager<?> manager, String title) {
|
protected JPanel createManagerPanel(Manager<?> manager, String title) {
|
||||||
JPanel panel = new JPanel(new GridLayout(0, 1));
|
JPanel panel = new JPanel(new GridLayout(0, 1));
|
||||||
panel.add(new JLabel(title, SwingConstants.CENTER));
|
panel.add(new JLabel(title, SwingConstants.CENTER));
|
||||||
for (JButton button : manager.getButtons()) {
|
for (JToggleButton button : manager.getButtons()) {
|
||||||
panel.add(button);
|
panel.add(button);
|
||||||
}
|
}
|
||||||
return panel;
|
return panel;
|
||||||
|
|||||||
@@ -4,8 +4,9 @@ import java.util.Calendar;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.swing.JButton;
|
import javax.swing.JToggleButton;
|
||||||
|
|
||||||
|
import mimis.exception.worker.ActivateException;
|
||||||
import mimis.manager.Exitable;
|
import mimis.manager.Exitable;
|
||||||
import mimis.manager.SelectButton;
|
import mimis.manager.SelectButton;
|
||||||
import mimis.manager.Titled;
|
import mimis.manager.Titled;
|
||||||
@@ -41,17 +42,16 @@ public class Manager<T extends Worker & Titled & Exitable> extends Worker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected JButton[] getButtons() {
|
protected JToggleButton[] getButtons() {
|
||||||
return buttonMap.values().toArray(new JButton[]{});
|
return buttonMap.values().toArray(new JToggleButton[]{});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void work() {
|
protected void work() {
|
||||||
long before = Calendar.getInstance().getTimeInMillis();
|
long before = Calendar.getInstance().getTimeInMillis();
|
||||||
for (T manageable : manageableArray) {
|
for (T manageable : manageableArray) {
|
||||||
boolean active = manageable.active();
|
boolean active = manageable.active();
|
||||||
//buttonMap.get(manageable).getModel().setArmed(active);
|
SelectButton<T> button = buttonMap.get(manageable);
|
||||||
|
button.setPressed(active);
|
||||||
buttonMap.get(manageable).getModel().setPressed(active);
|
|
||||||
}
|
}
|
||||||
long after = Calendar.getInstance().getTimeInMillis();
|
long after = Calendar.getInstance().getTimeInMillis();
|
||||||
int sleep = INTERVAL - (int) (after - before);
|
int sleep = INTERVAL - (int) (after - before);
|
||||||
|
|||||||
@@ -97,6 +97,6 @@ public abstract class Worker implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void work();
|
protected abstract void work();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
package mimis.manager;
|
package mimis.manager;
|
||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.MouseListener;
|
||||||
|
|
||||||
import javax.swing.Action;
|
import javax.swing.Action;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JToggleButton;
|
||||||
|
|
||||||
import mimis.Worker;
|
import mimis.Worker;
|
||||||
import mimis.exception.worker.ActivateException;
|
import mimis.exception.worker.ActivateException;
|
||||||
import mimis.exception.worker.DeactivateException;
|
import mimis.exception.worker.DeactivateException;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
public class SelectButton<T extends Worker & Titled> extends JButton implements ActionListener {
|
public class SelectButton<T extends Worker & Titled> extends JToggleButton implements MouseListener {
|
||||||
protected Log log = LogFactory.getLog(getClass());
|
protected Log log = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
protected static final long serialVersionUID = 1L;
|
protected static final long serialVersionUID = 1L;
|
||||||
@@ -21,22 +24,35 @@ public class SelectButton<T extends Worker & Titled> extends JButton implements
|
|||||||
this.activatable = activatable;
|
this.activatable = activatable;
|
||||||
setText(activatable.title());
|
setText(activatable.title());
|
||||||
setFocusable(false);
|
setFocusable(false);
|
||||||
addActionListener(this);
|
addMouseListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void actionPerformed(ActionEvent event) {
|
public void mouseClicked(MouseEvent event) {
|
||||||
if (activatable.active()) {
|
if (activatable.active()) {
|
||||||
try {
|
try {
|
||||||
|
log.trace("Uit");
|
||||||
activatable.deactivate();
|
activatable.deactivate();
|
||||||
} catch (DeactivateException e) {
|
} catch (DeactivateException e) {
|
||||||
log.error(e);
|
log.error(e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
|
log.trace("Aan");
|
||||||
activatable.activate();
|
activatable.activate();
|
||||||
} catch (ActivateException e) {
|
} catch (ActivateException e) {
|
||||||
log.error(e);
|
log.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void mouseEntered(MouseEvent e) {}
|
||||||
|
public void mouseExited(MouseEvent e) {}
|
||||||
|
public void mousePressed(MouseEvent e) {}
|
||||||
|
public void mouseReleased(MouseEvent e) {}
|
||||||
|
|
||||||
|
public void setPressed(boolean pressed) {
|
||||||
|
if (!isSelected() && pressed || isSelected() && !pressed) {
|
||||||
|
doClick();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user