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

Added ScheduLearn project to my project folder

parents
1,3,3
1,4,3
1,4,4
1,6,6
2,5,3
2,4,4
2,20,15
all:
javac gui/ScheduLearn.java
java gui.ScheduLearn
clean:
find . -name "*.class" -type f -delete
**Edit a file, create a new file, and clone from Bitbucket in under 2 minutes**
When you're done, you can delete the content in this README and update the file with details for others getting started with your repository.
*We recommend that you open this README in another tab as you perform the tasks below. You can [watch our video](https://youtu.be/0ocf7u76WSo) for a full demo of all the steps in this tutorial. Open the video in a new tab to avoid leaving Bitbucket.*
---
## Edit a file
You’ll start by editing this README file to learn how to edit a file in Bitbucket.
1. Click **Source** on the left side.
2. Click the README.md link from the list of files.
3. Click the **Edit** button.
4. Delete the following text: *Delete this line to make a change to the README from Bitbucket.*
5. After making your change, click **Commit** and then **Commit** again in the dialog. The commit page will open and you’ll see the change you just made.
6. Go back to the **Source** page.
---
## Create a file
Next, you’ll add a new file to this repository.
1. Click the **New file** button at the top of the **Source** page.
2. Give the file a filename of **contributors.txt**.
3. Enter your name in the empty file space.
4. Click **Commit** and then **Commit** again in the dialog.
5. Go back to the **Source** page.
Before you move on, go ahead and explore the repository. You've already seen the **Source** page, but check out the **Commits**, **Branches**, and **Settings** pages.
---
## Clone a repository
Use these steps to clone from SourceTree, our client for using the repository command-line free. Cloning allows you to work on your files locally. If you don't yet have SourceTree, [download and install first](https://www.sourcetreeapp.com/). If you prefer to clone from the command line, see [Clone a repository](https://confluence.atlassian.com/x/4whODQ).
1. You’ll see the clone button under the **Source** heading. Click that button.
2. Now click **Check out in SourceTree**. You may need to create a SourceTree account or log in.
3. When you see the **Clone New** dialog in SourceTree, update the destination path and name if you’d like to and then click **Clone**.
4. Open the directory you just created to see your repository’s files.
Now that you're more familiar with your Bitbucket repository, go ahead and add a new file locally. You can [push your change back to Bitbucket with SourceTree](https://confluence.atlassian.com/x/iqyBMg), or you can [add, commit,](https://confluence.atlassian.com/x/8QhODQ) and [push from the command line](https://confluence.atlassian.com/x/NQ0zDQ).
## PROBLEMS
1. EDF IS STILL WRONG :( Take into consideration distance to deadline, not just deadline size.
## TODO
1. Write "Help" documentation
2. Add schedulability checks
## FIXED
1. Fix issue with taskset not arranging correctly when tasks are added before scheduling algorithm is choosen. *FIXED*
2. EDF is implemented poorly. It is wrong when sorting by priority (when time till deadline is equal). *Think it works fine now*
3. Fix Strategy-based priority assignment *- WORKS CORRECTLY?*
4. Make space between buttons on left and the taskset-list. *- FIXED BUT NEEDS REVISITING*
## SUGGESTIONS
*- Add Task, Change Task, Remove Task på samma rad*
*- Markeringsfunktion i guit för Change Task och Remove Task, användarvänligt*
- Spara taskset-värden när man klickar någon annanstans i GUI:t
*- Lägg till Taskset rubrik, som Schedule och Solution*
*- Alternativ till Task-panelen för användarvänlighet:
Bort med alla 3 knapparna, lägg ett "+"-tecken under den task som är längst ner för Add Task. Lägg till ett litet "x" till höger om varje task för Remove Task, och slutligen gör alla värdena ändringsbara direkt i guit genom en enkel klick. Särskilt priority så lägger sig allt i rätt ordning också.*
*- Bort med översta (3,3)*
*- File-menyn ändra till "Save As..." och "Open File..." eller "Open Project...". Ta bort Close, det är redundant*
- Hover-funktion på typ allt i guit där det efter 1 sek dyker upp en liten bubbla som förklarar vad det man hoverar är för något. Användarvänligt
*- Påminnelse ifall man inte vill spara projektet innan man stänger ned programmet, ifall man ändrat något. Detta görs enkelt om du håller reda på states med historik*
package analysis;
public interface Schedulability {
/*
* Return: True if sufficient Schedulability analysis passed, False else
*/
public boolean sufficient(); //NOTE: NEEDS MORE WORK
/*
* Return: True if necessary Schedulability analysis passed, False else
*/
public boolean necessary(); //NOTE: NEEDS MORE WORK
}
package gui;
import javax.swing.JPanel;
import static java.awt.BorderLayout.CENTER;
import static java.awt.BorderLayout.WEST;
public class ActionPanel extends BorderPanel {
protected ActionPanel(JPanel tasksetPanel, JPanel schedulePanel) {
add(WEST, tasksetPanel);
add(CENTER, schedulePanel);
}
}
package gui;
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JPanel;
public class BorderPanel extends JPanel {
protected BorderPanel() {
super(new BorderLayout(2, 2));
setBackground(Color.DARK_GRAY);
}
}
package gui;
import java.awt.Color;
import javax.swing.Box;
public class BoxPanel extends Box {
protected BoxPanel(int type) {
super(type);
setBackground(Color.LIGHT_GRAY);
}
}
package gui;
import java.util.Observer;
import java.util.Observable;
import java.awt.Color;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import gui.CurrentSlot;
public class CurrentLabel extends JLabel implements Observer {
private CurrentSlot currentSlot;
public CurrentLabel(CurrentSlot currentSlot) {
super(currentSlot.toString(), SwingConstants.LEFT);
setBackground(Color.WHITE);
setOpaque(true);
this.currentSlot = currentSlot;
currentSlot.addObserver(this);
}
public void update(Observable o, Object arg) {
setText(currentSlot.toString());
}
}
package gui;
import java.util.Observable;
public class CurrentSlot extends Observable {
private String curAdress;
private int curTask, curSlot;
public CurrentSlot(int curTask, int curSlot) {
this.curTask = curTask;
this.curSlot = curSlot;
this.curAdress = "(" + curTask + "," + curSlot + ")";
}
public void setCurrentSlot(int newCurTask, int newCurSlot) {
curTask = newCurTask;
curSlot = newCurSlot;
curAdress = "(" + curTask + "," + curSlot + ")";
setChanged();
notifyObservers();
}
public void setCurrentSlot(String adress) {
if (adress.isEmpty()) return;
curAdress = adress;
String[] str = curAdress.replaceAll("\\D+"," ").trim().split(" "); //Extracts all numbers in string form
curTask = Integer.parseInt(str[0]);
curSlot = Integer.parseInt(str[1]);
setChanged();
notifyObservers();
}
public String toString() { return curAdress; }
public int getCurrentTask() { return curTask; }
public int getCurrentSlot() { return curSlot; }
}
package gui;
import java.awt.Color;
import java.awt.GridLayout;
import javax.swing.JPanel;
public class GridPanel extends JPanel {
public GridPanel(int rows, int columns) {
super(new GridLayout(rows, columns, 2, 2));
setBackground(Color.LIGHT_GRAY);
}
}
package gui;
import static java.awt.BorderLayout.CENTER;
import static java.awt.BorderLayout.NORTH;
import static java.awt.BorderLayout.SOUTH;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JOptionPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import tasks.Taskset;
import model.SchedulingModel;
import model.Status;
import gui.menu.ScheduLearnMenuBar;
import gui.schedulegui.SchedulePanel;
import gui.tasksetgui.TasksetPanel;
public class ScheduLearn extends JFrame {
public ScheduLearn() {
super("ScheduLearn");
int rows = 5, cols = 20;
Status status = new Status();
Taskset ts = new Taskset();
CurrentSlot currentSlot = new CurrentSlot(1, 1);
StatusLabel statusLabel = new StatusLabel(status);
SchedulingModel scheduleMdl = new SchedulingModel(ts, status);
// ................
JPanel tasksetPanel = new TasksetPanel(ts, status);
JPanel schedulePanel = new SchedulePanel(scheduleMdl, currentSlot, rows, cols);
JPanel actionPanel = new ActionPanel(tasksetPanel, schedulePanel);
// ................
add(CENTER, statusLabel);
add(SOUTH, actionPanel);
setJMenuBar(new ScheduLearnMenuBar(this, scheduleMdl, ts, status));
pack();
// Create Closing mechanism
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event) {
confirmAndExit();
}
});
setResizable(false);
setVisible(true);
}
// Used to confirm that the application should be exited.
public void confirmAndExit() {
if (JOptionPane.showConfirmDialog(
this,
"Are you sure you want to quit?",
"Please confirm",
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
System.exit(0);
}
}
public static void main(String[] args) {
new ScheduLearn();
}
}
package gui;
import java.awt.Color;
import java.awt.Font;
import java.util.Observable;
import java.util.Observer;
import javax.swing.BorderFactory;
import javax.swing.border.BevelBorder;
import javax.swing.SwingConstants;
import javax.swing.JLabel;
import model.Status;
public class StatusLabel extends JLabel implements Observer {
private final float FONT_SIZE = 16;
public StatusLabel(Status status) {
super(" ", SwingConstants.LEFT);
setBackground(Color.WHITE);
setOpaque(true);
setFont(getFont().deriveFont( FONT_SIZE ));
status.addObserver(this);
setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED, Color.LIGHT_GRAY, Color.DARK_GRAY));
}
public void update(Observable observable, Object object) {
setText((String)object);
}
}
package gui;
/*
* NOTE: TWO INTERFACES ARE NEEDED SUCH THAT THE UI ISN'T UPDATED WHEN MARKED.
*/
public interface UpdateListener {
/*
* The function to be performed when the observable class is updated.
* Object obj is the object calling the update;
*/
public void update(Object Obj);
// or null
public default void update() { this.update(null); }
}
package gui.menu;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenuItem;
import model.SchedulingModel;
class ClearAllMenuItem extends JMenuItem implements ActionListener {
private SchedulingModel scheduleMdl;
public ClearAllMenuItem(SchedulingModel scheduleMdl) {
super("Clear all");
this.scheduleMdl = scheduleMdl;
addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
scheduleMdl.clearAll();
}
}
package gui.menu;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenuItem;
import java.util.NoSuchElementException;
import java.util.Set;
import model.SchedulingModel;
class ClearCellsMenuItem extends JMenuItem implements ActionListener {
private SchedulingModel scheduleMdl;
public ClearCellsMenuItem(SchedulingModel scheduleMdl) {
super("Clear cells");
this.scheduleMdl = scheduleMdl;
addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
scheduleMdl.clearAllCells();
}
}
package gui.menu;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenuItem;
import java.util.NoSuchElementException;
import java.util.Set;
import tasks.Taskset;
class ClearTasksetMenuItem extends JMenuItem implements ActionListener {
private Taskset taskset;
public ClearTasksetMenuItem(Taskset taskset) {
super("Clear taskset");
this.taskset = taskset;
addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
while (taskset.nbrTasks() > 0) {
try {
taskset.removeTask(1);
} catch (NoSuchElementException error) {}
}
}
}
package gui.menu;
import model.SchedulingModel;
import strategy.EDF;
public class EDFStrategyMenuItem extends StrategyMenuItem {
public EDFStrategyMenuItem(SchedulingModel scheduleMdl) {
super(scheduleMdl, new EDF(), "EDF");
}
}
package gui.menu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class FileHelpItem extends JMenuItem implements ActionListener {
public FileHelpItem() {
super("File");
addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "File text");
}
}
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");
}
}