Commit 91a440f6 authored by Nils Vreman's avatar Nils Vreman
Browse files

Added ScheduLearn project to my project folder

parents
package gui.menu;
import javax.swing.JMenu;
public class HelpMenu extends JMenu {
public HelpMenu() {
super("Help");
add(new LicenceMenuItem());
//JMenu helpMenu = new JMenu("Help Center");
//helpMenu.add(new FileHelpItem());
//helpMenu.add(new StrategyHelpItem());
//helpMenu.add(new TasksetHelpItem());
//helpMenu.add(new ScheduleHelpItem());
//add(helpMenu);
add(new HelpMenuItem());
}
}
package gui.menu;
import javax.swing.JMenuItem;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import gui.menu.help.HelpMenuPane;
public class HelpMenuItem extends JMenuItem implements ActionListener {
public HelpMenuItem() {
super("Help");
addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
new HelpMenuPane();
}
}
package gui.menu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class LicenceMenuItem extends JMenuItem implements ActionListener {
public LicenceMenuItem() {
super("Licence");
addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "Licence text");
}
}
package gui.menu;
import tasks.Taskset;
import model.Status;
import gui.ScheduLearn;
import javax.swing.JFileChooser;
import java.io.FileNotFoundException;
public class LoadMenuItem extends OpenMenuItem {
private Taskset taskset;
public LoadMenuItem(ScheduLearn gui, Taskset taskset, Status status) {
super(gui, status, "Open File");
this.taskset = taskset;
}
protected void openAction(String path) throws FileNotFoundException {
try {
taskset.load(path);
} catch (FileNotFoundException e) {
throw e;
}
}
protected int openDialog(JFileChooser fileChooser) {
return fileChooser.showOpenDialog(gui);
}
}
package gui.menu;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenuItem;
import model.SchedulingModel;
import model.Status;
public class MatchMenuItem extends JMenuItem implements ActionListener {
private SchedulingModel scheduleMdl;
private Status status;
public MatchMenuItem(SchedulingModel scheduleMdl, Status status) {
super("Match");
this.scheduleMdl = scheduleMdl;
this.status = status;
addActionListener(this);
}
public void actionPerformed(ActionEvent event) {
status.setStatus((scheduleMdl.match()) ? "The solution is correct" : "The solution is wrong");
}
}
package gui.menu;
import model.SchedulingModel;
import strategy.NoneStrategy;
public class NoneStrategyMenuItem extends StrategyMenuItem {
public NoneStrategyMenuItem(SchedulingModel scheduleMdl) {
super(scheduleMdl, new NoneStrategy(), "None");
}
}
package gui.menu;
import gui.ScheduLearn;
import model.Status;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import javax.swing.JFileChooser;
import javax.swing.JMenuItem;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
public abstract class OpenMenuItem extends JMenuItem implements ActionListener {
protected ScheduLearn gui;
protected Status status;
public OpenMenuItem(ScheduLearn gui, Status status, String title) {
super(title);
this.gui = gui;
this.status = status;
addActionListener(this);
}
protected abstract void openAction(String path) throws FileNotFoundException;
protected abstract int openDialog(JFileChooser fileChooser);
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser(".");
FileFilter filter = new FileNameExtensionFilter("ScheduLearn files", "sl");
fileChooser.setFileFilter(filter);
int option = openDialog(fileChooser);
if (option == fileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
try {
openAction(file.toString());
} catch (FileNotFoundException error) {
status.setStatus(error.getMessage());
}
}
}
}
package gui.menu;
import model.SchedulingModel;
import strategy.RMS;
public class RMSStrategyMenuItem extends StrategyMenuItem {
public RMSStrategyMenuItem(SchedulingModel scheduleMdl) {
super(scheduleMdl, new RMS(), "RMS");
}
}
package gui.menu;
import tasks.Taskset;
import model.Status;
import gui.ScheduLearn;
import javax.swing.JFileChooser;
import java.io.FileNotFoundException;
public class SaveMenuItem extends OpenMenuItem {
private Taskset taskset;
public SaveMenuItem(ScheduLearn gui, Taskset taskset, Status status) {
super(gui, status, "Save As");
this.taskset = taskset;
}
protected void openAction(String path) throws FileNotFoundException {
try {
taskset.save(path);
} catch (FileNotFoundException e) {
throw e;
}
}
protected int openDialog(JFileChooser fileChooser) {
return fileChooser.showSaveDialog(gui);
}
}
package gui.menu;
import model.SchedulingModel;
import model.Status;
import gui.CurrentSlot;
import gui.ScheduLearn;
import tasks.Taskset;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
public class ScheduLearnMenuBar extends JMenuBar {
public ScheduLearnMenuBar(ScheduLearn gui,
SchedulingModel scheduleMdl,
Taskset taskset,
Status status) {
JMenu file = new JMenu("File");
JMenu edit = new JMenu("Edit");
JMenu strategy = new JMenu("Strategy");
JMenu help = new HelpMenu();
file.add(new SaveMenuItem(gui, taskset, status));
file.add(new LoadMenuItem(gui, taskset, status));
edit.add(new MatchMenuItem(scheduleMdl, status));
edit.add(new ClearCellsMenuItem(scheduleMdl));
edit.add(new ClearTasksetMenuItem(taskset));
edit.add(new ClearAllMenuItem(scheduleMdl));
strategy.add(new NoneStrategyMenuItem(scheduleMdl));
strategy.add(new EDFStrategyMenuItem(scheduleMdl));
strategy.add(new RMSStrategyMenuItem(scheduleMdl));
add(file);
add(edit);
add(strategy);
add(help);
}
}
package gui.menu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ScheduleHelpItem extends JMenuItem implements ActionListener {
public ScheduleHelpItem() {
super("Schedule");
addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "Schedule text");
}
}
package gui.menu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class StrategyHelpItem extends JMenuItem implements ActionListener {
public StrategyHelpItem() {
super("Strategy");
addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "Strategy text");
}
}
package gui.menu;
import strategy.SchedulingStrategy;
import model.SchedulingModel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenuItem;
public abstract class StrategyMenuItem extends JMenuItem implements ActionListener {
private SchedulingStrategy strategy;
private SchedulingModel scheduleMdl;
public StrategyMenuItem(SchedulingModel scheduleMdl, SchedulingStrategy strategy, String title) {
super(title);
this.scheduleMdl = scheduleMdl;
this.strategy = strategy;
addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
scheduleMdl.setStrategy(strategy);
}
}
package gui.menu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class TasksetHelpItem extends JMenuItem implements ActionListener {
public TasksetHelpItem() {
super("Taskset");
addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "Taskset text");
}
}
package gui.menu.help;
public interface EventListener {
/*
* The function to be performed when the observable class is being altered.
*/
public void update(String tab);
}
package gui.menu.help;
public class FileTab extends TabPanel {
private static final String[] listOptions = new String[] {
"Save",
"Load"};
private static final String[] helpTexts = new String[] {
"Save",
"Load"};
public FileTab() {
super(listOptions, helpTexts);
}
}
package gui.menu.help;
import static java.awt.BorderLayout.CENTER;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;
import java.awt.Dimension;
public class HelpMenuPane extends JFrame {
public HelpMenuPane() {
super("Help Center");
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.addTab("File Handling", new FileTab());
tabbedPane.addTab("Strategy", new StrategyTab());
tabbedPane.addTab("Taskset", new TasksetTab());
tabbedPane.addTab("Schedule", new ScheduleTab());
tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
tabbedPane.setPreferredSize(new Dimension(400, 400));
add(CENTER, tabbedPane);
pack();
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setResizable(false);
setVisible(true);
}
}
package gui.menu.help;
import javax.swing.JTextField;
import javax.swing.BorderFactory;
import javax.swing.border.BevelBorder;
public class HelpTextField extends JTextField {
public HelpTextField(String text) {
super(text);
setEditable(false);
setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
}
}
package gui.menu.help;
import javax.swing.JList;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.BorderFactory;
import javax.swing.border.BevelBorder;
public class OptionList extends JList {
private EventListener listener;
public OptionList(String[] items) {
super(items);
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
setLayoutOrientation(JList.VERTICAL);
setVisibleRowCount(-1);
setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
listener.update(getSelectedValue().toString());
}
}
});
}
public void addListener(EventListener listener) {
this.listener = listener;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment