You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
130 lines
3.0 KiB
130 lines
3.0 KiB
package application.customviews;
|
|
|
|
import application.helpers.Utils;
|
|
import application.helpers.wrappers.SubElement;
|
|
import application.res.Colors;
|
|
import application.res.Text;
|
|
import javafx.beans.property.BooleanProperty;
|
|
import javafx.beans.property.SimpleBooleanProperty;
|
|
import javafx.beans.value.ChangeListener;
|
|
import javafx.event.EventHandler;
|
|
import javafx.scene.control.Label;
|
|
import javafx.scene.input.MouseEvent;
|
|
import javafx.scene.layout.BorderPane;
|
|
import javafx.scene.layout.HBox;
|
|
import javafx.scene.shape.Circle;
|
|
|
|
/**
|
|
* This class represents one of the sub elements of the select view.
|
|
* {@link EntryView}s can contain sub elements like the information concerning
|
|
* the date of birth which is represented in this class. They can be selected on
|
|
* their own and the selection state is indicated by a circle on the left side
|
|
* of the sub element.
|
|
*
|
|
* @author Bianca
|
|
*
|
|
*/
|
|
|
|
public class SubEntryView extends HBox
|
|
{
|
|
/**
|
|
* Circle which indicates the selection state. Invisible / grey if not selected,
|
|
* green if selected.
|
|
*/
|
|
private Circle c;
|
|
/**
|
|
* Property which indicates whether the sub element is selected.
|
|
*/
|
|
private BooleanProperty selected;
|
|
/**
|
|
* Data of this sub element.
|
|
*/
|
|
private SubElement elem;
|
|
|
|
/**
|
|
* Initializes all attributes, sets up the view and draws the initial circle.
|
|
* Starts in the unselected state.
|
|
*
|
|
* @param elem The data of the sub element.
|
|
*/
|
|
public SubEntryView(SubElement elem)
|
|
{
|
|
this.elem=elem;
|
|
selected = new SimpleBooleanProperty(false);
|
|
BorderPane circleContainer = new BorderPane();
|
|
c = new Circle(10, Colors.grey);
|
|
circleContainer.setCenter(c);
|
|
getChildren().add(circleContainer);
|
|
getChildren().add(new Label(String.format(Text.F_ME_SAVE, Utils.shortenHKStrings(getName()), getValue())));
|
|
setOnMouseClicked(new EventHandler<MouseEvent>()
|
|
{
|
|
@Override
|
|
public void handle(MouseEvent event)
|
|
{
|
|
setSelected(!isSelected());
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
/**
|
|
* Returns the name / identifier of the sub element.
|
|
*
|
|
* @return The described value.
|
|
*/
|
|
public String getName()
|
|
{
|
|
return elem.getType();
|
|
}
|
|
|
|
/**
|
|
* Returns the value / entrycount of the sub element.
|
|
*
|
|
* @return The described value.
|
|
*/
|
|
public int getValue()
|
|
{
|
|
return elem.getValue();
|
|
}
|
|
|
|
/**
|
|
* Allows for a listener to be attached to the selected property of the sub
|
|
* element.
|
|
*
|
|
* @param listen Listener to add to the property
|
|
*/
|
|
public void addCheckListener(ChangeListener<Boolean> listen)
|
|
{
|
|
selected.addListener(listen);
|
|
}
|
|
|
|
/**
|
|
* Shows whether the element is selected or not.
|
|
*
|
|
* @return The describes value.
|
|
*/
|
|
public boolean isSelected()
|
|
{
|
|
return selected.get();
|
|
}
|
|
|
|
/**
|
|
* Changes the value of the selection of this element to the given selection and
|
|
* adjusts the circles color.
|
|
*
|
|
* @param value The value the selection should take.
|
|
*/
|
|
public void setSelected(boolean value)
|
|
{
|
|
if (value) //select
|
|
{
|
|
c.setFill(Colors.green);
|
|
}
|
|
else //remove selection
|
|
{
|
|
c.setFill(Colors.grey);
|
|
}
|
|
this.selected.set(value);
|
|
}
|
|
|
|
}
|