SmartNotes/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/TypeSelector.java

126 lines
3.6 KiB
Java

package com.madeorsk.smartnotes;
import com.madeorsk.smartnotes.notes.ListNote;
import com.madeorsk.smartnotes.notes.Note;
import com.madeorsk.smartnotes.notes.TextNote;
import javafx.animation.FadeTransition;
import javafx.scene.Cursor;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.util.Duration;
public class TypeSelector extends HBox
{
public TypeSelector(final NotesExplorer explorer, final Note note)
{
this.setSpacing(15);
TypeItem textNoteItem = new TypeItem("/com/madeorsk/smartnotes/res/TextNoteChoice.png");
{
if (note instanceof TextNote)
textNoteItem.setSelected(true);
else
{
textNoteItem.setOnMouseClicked((MouseEvent event) -> {
Note textNote = new TextNote();
textNote.setName(note.getName());
textNote.setTextContent(note.getTextContent());
textNote.setNoteColor(note.getNoteColor());
explorer.replaceNote(note, textNote);
explorer.requestSave(textNote);
SmartNotes.instance.setContent(textNote.getEditBox(explorer));
});
}
}
this.getChildren().add(textNoteItem);
TypeItem listNoteItem = new TypeItem("/com/madeorsk/smartnotes/res/ListNoteChoice.png");
{
if (note instanceof ListNote)
listNoteItem.setSelected(true);
else
{
listNoteItem.setOnMouseClicked((MouseEvent event) -> {
Note listNote = new ListNote();
listNote.setName(note.getName());
listNote.setTextContent(note.getTextContent());
listNote.setNoteColor(note.getNoteColor());
explorer.replaceNote(note, listNote);
explorer.requestSave(listNote);
SmartNotes.instance.setContent(listNote.getEditBox(explorer));
});
}
}
this.getChildren().add(listNoteItem);
TypeItem imageNoteItem = new TypeItem("/com/madeorsk/smartnotes/res/ImageNoteChoice.png");
{
} //TODO Next versions.
this.getChildren().add(imageNoteItem);
TypeItem soundNoteItem = new TypeItem("/com/madeorsk/smartnotes/res/SoundNoteChoice.png");
{
} //TODO Next versions.
this.getChildren().add(soundNoteItem);
TypeItem videoNoteItem = new TypeItem("/com/madeorsk/smartnotes/res/VideoNoteChoice.png");
{
} //TODO Next versions.
this.getChildren().add(videoNoteItem);
TypeItem positionNoteItem = new TypeItem("/com/madeorsk/smartnotes/res/PositionNoteChoice.png");
{
} //TODO Next versions.
this.getChildren().add(positionNoteItem);
}
private class TypeItem extends VBox
{
private boolean selected;
public TypeItem(String typeIconPath)
{
this.setId("imageButton");
this.setCursor(Cursor.HAND);
this.getChildren().add(new ImageView(new Image(typeIconPath)));
this.setOpacity(0.4);
this.setOnMouseEntered((MouseEvent e) -> {
if (!TypeItem.this.isSelected())
{
FadeTransition transition = new FadeTransition(Duration.millis(200), TypeItem.this);
transition.setFromValue(0.4);
transition.setToValue(1.0);
transition.play();
}
});
this.setOnMouseExited((MouseEvent e) -> {
if (!TypeItem.this.isSelected())
{
FadeTransition transition = new FadeTransition(Duration.millis(200), TypeItem.this);
transition.setFromValue(1.0);
transition.setToValue(0.4);
transition.play();
}
});
}
public void setSelected(boolean selected)
{
this.selected = selected;
if (this.selected)
this.setOpacity(1.0);
else
{
FadeTransition transition = new FadeTransition(Duration.millis(200), TypeItem.this);
transition.setFromValue(1.0);
transition.setToValue(0.4);
transition.play();
}
}
public boolean isSelected()
{
return this.selected;
}
}
}