summaryrefslogtreecommitdiffstats
path: root/src/de/fhswf/in/inf/java2/aufgabe02/CardChangeEvent.java
blob: 2050536a2b0533fca06a9d7675b459bd8c33b323 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
 * Class CardChangeEvent.
 */

package de.fhswf.in.inf.java2.aufgabe02;

import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Node;
import javafx.scene.control.Label;

/**
 * Generic handler for loading Labels on button click.
 *
 * @author $Author: $
 * @version $Revision: $, $Date: $ UTC
 */
public class CardChangeEvent implements EventHandler<ActionEvent>
{

   private ObservableList<Node> children;

   private String labelName;

   private Label label = null;

   /**
    * Adds an eventHandler for the button so that a label is loaded into the
    * stack pane.
    *
    */
   public CardChangeEvent(ObservableList<Node> children, String labelName)
   {
      if (children == null)
      {
         throw new IllegalArgumentException("children can't be null.");
      }

      if (labelName == null)
      {
         throw new IllegalArgumentException("labelName can't be null.");
      }

      if (labelName.isEmpty())
      {
         throw new IllegalArgumentException("labelName can't be empty.");
      }

      this.children = children;
      this.labelName = labelName;
   }

   /*
    * (non-Javadoc)
    * 
    * @see javafx.event.EventHandler#handle(javafx.event.Event)
    */
   @Override
   public void handle(ActionEvent event)
   {
      for (Node node : children)
      {
         node.setVisible(false);
      }

      if (label == null)
      {
         label = new Label(labelName);
         children.add(label);
      }

      label.setVisible(true);
   }
}