Commit 76cbee39 authored by Nils Vreman's avatar Nils Vreman
Browse files

Improved on the unfocusing when clicking somewhere aside from the label

parent a73b5ad9
...@@ -2,7 +2,7 @@ package gui.tasksetgui; ...@@ -2,7 +2,7 @@ package gui.tasksetgui;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.FocusListener; import java.awt.event.FocusListener;
import java.awt.event.FocusEvent; import java.awt.event.FocusEvent;
...@@ -11,7 +11,7 @@ import javax.swing.JTextField; ...@@ -11,7 +11,7 @@ import javax.swing.JTextField;
import gui.UpdateListener; import gui.UpdateListener;
public class TaskLabel extends JTextField implements FocusListener, MouseListener { public class TaskLabel extends JTextField implements FocusListener {
private String previousText; private String previousText;
private UpdateListener updateListener; private UpdateListener updateListener;
...@@ -25,8 +25,7 @@ public class TaskLabel extends JTextField implements FocusListener, MouseListene ...@@ -25,8 +25,7 @@ public class TaskLabel extends JTextField implements FocusListener, MouseListene
setDocument(new TaskLabelFilter()); setDocument(new TaskLabelFilter());
setText(text); setText(text);
// Add Listener for when mouse does something with object // Add Listener for when focus is placed inside
addMouseListener(this);
addFocusListener(this); addFocusListener(this);
// Add Listener that does something with object when <Enter> is pressed // Add Listener that does something with object when <Enter> is pressed
...@@ -37,6 +36,13 @@ public class TaskLabel extends JTextField implements FocusListener, MouseListene ...@@ -37,6 +36,13 @@ public class TaskLabel extends JTextField implements FocusListener, MouseListene
} }
} }
}); });
// Add Listener that does something When object is clicked
addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
markListener.markUpdate(this);
}
});
} }
/* /*
...@@ -55,37 +61,6 @@ public class TaskLabel extends JTextField implements FocusListener, MouseListene ...@@ -55,37 +61,6 @@ public class TaskLabel extends JTextField implements FocusListener, MouseListene
this.markListener = markListener; this.markListener = markListener;
} }
/*
* MouseListener Functions.
*/
/*
* Invoked when the mouse button has been clicked (pressed and released) on a component.
*/
public void mouseClicked(MouseEvent e) {
markListener.markUpdate(this);
}
/*
* Invoked when a mouse button has been pressed on a component.
*/
public void mousePressed(MouseEvent e) {}
/*
* Invoked when a mouse button has been released on a component.
*/
public void mouseReleased(MouseEvent e) {}
/*
* Invoked when the mouse enters a component.
*/
public void mouseEntered(MouseEvent e) {}
/*
* Invoked when the mouse exits a component.
*/
public void mouseExited(MouseEvent e) {}
/* /*
* FocusListener Functions. * FocusListener Functions.
*/ */
...@@ -102,7 +77,6 @@ public class TaskLabel extends JTextField implements FocusListener, MouseListene ...@@ -102,7 +77,6 @@ public class TaskLabel extends JTextField implements FocusListener, MouseListene
*/ */
public void focusLost(FocusEvent e) { public void focusLost(FocusEvent e) {
if (!previousText.equals(getText()) && getText().matches("[0-9]+")) { if (!previousText.equals(getText()) && getText().matches("[0-9]+")) {
System.out.println(getText());
updateListener.update(); updateListener.update();
} }
} }
......
package gui.tasksetgui; package gui.tasksetgui;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.BoxLayout; import javax.swing.BoxLayout;
import javax.swing.JPanel; import javax.swing.JPanel;
import java.awt.Dimension; import java.awt.Dimension;
...@@ -30,6 +32,12 @@ public class TasksetDisplay extends BoxPanel implements Observer, UpdateListener ...@@ -30,6 +32,12 @@ public class TasksetDisplay extends BoxPanel implements Observer, UpdateListener
this.taskset = taskset; this.taskset = taskset;
taskset.addObserver(this); taskset.addObserver(this);
addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
grabFocus();
}
});
add(header); add(header);
setMaximumSize(new Dimension(300, 35)); setMaximumSize(new Dimension(300, 35));
add(createVerticalStrut(offset)); add(createVerticalStrut(offset));
......
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