OOP-Projects-Java

Log | Files | Refs | README

commit f9c5c72f1f9f5aad5c7eca831456211b04d92a20
parent 2833b94a511fe8802c60593812c1b8159214e8f9
Author: William Lindholm <william_lindholm@outlook.com>
Date:   Wed, 15 Feb 2023 15:30:53 +0100

Fixed merge conflicts

Diffstat:
MOOP2023_a22willi_a21liltr_assignment2/src/assignment2/GUI.java | 1-
MOOP2023_a22willi_a21liltr_assignment2/src/assignment2/WorkTask.java | 89+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
2 files changed, 80 insertions(+), 10 deletions(-)

diff --git a/OOP2023_a22willi_a21liltr_assignment2/src/assignment2/GUI.java b/OOP2023_a22willi_a21liltr_assignment2/src/assignment2/GUI.java @@ -104,7 +104,6 @@ public class GUI implements ActionListener { else { t = new WorkTask(); } - taskHandler.taskCreated(t); } } diff --git a/OOP2023_a22willi_a21liltr_assignment2/src/assignment2/WorkTask.java b/OOP2023_a22willi_a21liltr_assignment2/src/assignment2/WorkTask.java @@ -2,12 +2,17 @@ package assignment2; import java.awt.BorderLayout; +import java.awt.Color; import java.awt.Component; import java.awt.Dimension; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JLabel; +import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.border.TitledBorder; @@ -17,14 +22,16 @@ import se.his.it401g.todo.TaskInputListener; import se.his.it401g.todo.TaskListener; /** - * Implements a simple study task type, following the Task.java interface class. + * Implements a simple work task type, following the Task.java interface class. * * This file licensed under the <a href="https://creativecommons.org/licenses/by/4.0/">Creative Commons (CC) BY 4.0 license</a>. * * @author Dr. Erik Billing, University of Skovde * */ -public class WorkTask extends JPanel implements Task { + +// Custom task +public class WorkTask extends JPanel implements Task, ActionListener { /** * The editable text field. @@ -41,6 +48,9 @@ public class WorkTask extends JPanel implements Task { */ JCheckBox completed = new JCheckBox(); + //comment + JPanel colourBlock = new JPanel(); + /** * The task listener used for reporting changes to the main application. */ @@ -54,23 +64,44 @@ public class WorkTask extends JPanel implements Task { this.text = new JTextField("New task",20); this.textLabel = new JLabel(); this.textLabel.setVisible(false); - JPanel center = new JPanel(); - center.add(text); - center.add(textLabel); - add(center); TaskInputListener inputListener = new TaskInputListener(this, text, textLabel); this.text.addKeyListener(inputListener); this.textLabel.addMouseListener(inputListener); + JPanel center = new JPanel(); + center.add(text); + center.add(textLabel); + add(center,BorderLayout.CENTER); + + GridLayout eastGrid = new GridLayout(1, 2, 5, 0); + JPanel east = new JPanel(); + + east.setLayout(eastGrid); + add(east, BorderLayout.EAST); + + // how to make remove, colour center aligned vertically in the box. JButton remove = new JButton("Remove"); - add(remove,BorderLayout.EAST); remove.addActionListener(inputListener); + east.add(remove); + + JButton colour = new JButton("Choose Colour!"); + colour.addActionListener(this); + east.add(colour); + + GridLayout grid = new GridLayout(0,2); + JPanel west = new JPanel(); + west.setLayout(grid); + add(west, BorderLayout.WEST); + + colourBlock.setBackground(Color.white); + colourBlock.setSize(new Dimension(20, 50)); + west.add(colourBlock); - add(completed,BorderLayout.WEST); completed.addItemListener(inputListener); + west.add(completed); - setMaximumSize(new Dimension(1000,50)); + setMaximumSize(new Dimension(1000,75)); setBorder(new TitledBorder(getTaskType())); } @@ -96,6 +127,8 @@ public class WorkTask extends JPanel implements Task { @Override public boolean isComplete() { + // set strikethrough on text when iscomplete is true. + return completed.isSelected(); } @@ -105,4 +138,42 @@ public class WorkTask extends JPanel implements Task { return this; } + @Override + public void actionPerformed(ActionEvent e) { + String choice = chooseColour(); + if (!choice.isEmpty()) { + setColour(choice); + } + + } + + private String chooseColour() { + String[] options = {"None", "Red", "Blue", "Green"}; + + Object choice = JOptionPane.showInputDialog(null, "Choose colour!", "Options", JOptionPane.DEFAULT_OPTION, null, options, "0"); + if (choice != null) { + return choice.toString(); //return selected sorting type + } + return ""; //user cancelled, returning empty string, no sorting will ensue. + } + + private void setColour(String colour) { + switch(colour) { + case "None": + colourBlock.setBackground(Color.white); + break; + case "Red": + colourBlock.setBackground(Color.red); + break; + case "Blue": + colourBlock.setBackground(Color.blue); + break; + case "Green": + colourBlock.setBackground(Color.green); + break; + default: + break; + } + } + }