package app.view.note;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.ComponentOrientation;
import java.awt.Dimension;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextField;
import org.ytreza.view.SpecialField;
import org.ytreza.view.controler.ButtonCopy;
import org.ytreza.view.controler.ButtonCreate;
import org.ytreza.view.controler.ButtonDelete;
import org.ytreza.view.field.FieldText;
import org.ytreza.view.field.pane.SubPane;
@SuppressWarnings("serial")
public class NoteMainPane extends SubPaneNote {
public NoteMainPane(NoteControler controler) {
super(controler);
}
@Override
protected void build() {
setLayout(new BorderLayout());
add(new PaneTag(getControler()), BorderLayout.NORTH);
add(new PaneCenter(getControler()), BorderLayout.CENTER);
add(new PaneButtons(getControler()), BorderLayout.SOUTH);
}
}
@SuppressWarnings("serial")
abstract class SubPaneNote extends SubPane {
private NoteControler controler;
public SubPaneNote(NoteControler controler) {
this.controler = controler;
build();
}
public NoteControler getControler() {
return controler;
}
}
@SuppressWarnings("serial")
class PaneTag extends SubPaneNote {
public PaneTag(NoteControler controler) {
super(controler);
}
@Override
protected void build() {
// AUTO_TODO Auto-generated method stub
setLayout(new BorderLayout());
setPreferredSize(new Dimension(10, 100));
JList fieldUnselectedTag = new JList();
getControler().setFieldTagUnselected(fieldUnselectedTag);
add(new JScrollPane(fieldUnselectedTag), BorderLayout.CENTER);
JList fieldSelectedTag = new JList();
fieldSelectedTag.setPreferredSize(new Dimension(1,20));
getControler().setFieldTagSelected(fieldSelectedTag);
add(new JScrollPane(fieldSelectedTag), BorderLayout.SOUTH);
}
}
@SuppressWarnings("serial")
class PaneCenter extends SubPaneNote {
public PaneCenter(NoteControler controler) {
super(controler);
}
@Override
protected void build() {
setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
PaneList paneList = new PaneList(getControler());
PaneNote paneNote = new PaneNote(getControler());
JSplitPane splitBetweenListAndNote = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
splitBetweenListAndNote.setDividerLocation(250);
splitBetweenListAndNote.setOneTouchExpandable(true);
splitBetweenListAndNote.add(paneList);
splitBetweenListAndNote.add(paneNote);
add(splitBetweenListAndNote);
}
}
@SuppressWarnings("serial")
class PaneButtons extends SubPaneNote{
public PaneButtons(NoteControler controler) {
super(controler);
// AUTO_TODO Auto-generated constructor stub
}
@Override
protected void build() {
setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
setBorder(BorderFactory.createEmptyBorder(4, 2, 2, 2));
add(new ButtonCreate(getControler()));
add(Box.createHorizontalStrut(5));
add(new ButtonCopy(getControler()));
add(Box.createHorizontalStrut(5));
add(new ButtonDelete(getControler()));
}
}
@SuppressWarnings("serial")
class PaneList extends SubPaneNote{
public PaneList(NoteControler controler) {
super(controler);
}
@Override
protected void build() {
setLayout(new BorderLayout());
setPreferredSize(new Dimension(500,500));
JList subjectList = new JList();
JTextField searchField = new JTextField(30);
// subjectList.setSearchField(searchField);
getControler().setFieldSubjectList(subjectList);
add(searchField, BorderLayout.NORTH);
add(new JScrollPane(subjectList), BorderLayout.CENTER);
}
}
@SuppressWarnings("serial")
class PaneNote extends SubPaneNote{
public PaneNote(NoteControler controler) {
super(controler);
}
@Override
protected void build() {
setLayout(new BorderLayout());
add(new FieldSubject((NoteControler) getControler()), BorderLayout.NORTH);
add(new FieldTextNote((NoteControler) getControler()).getComponent(),BorderLayout.CENTER);
add(new FieldNoteTagList((NoteControler) getControler()).getComponent(),BorderLayout.SOUTH);
}
}
class FieldTextNote implements SpecialField, FocusListener{
FieldText text;
private NoteControler controler;
public FieldTextNote (NoteControler controler) {
super();
text = new FieldText();
this.controler = controler;
controler.setFieldText(text);
text.addFocusListener(this);
}
@Override
public Component getComponent() {
return new JScrollPane(text);
}
@Override
public void focusLost(FocusEvent arg0) {
controler.onLostFocusOnText();
}
@Override
public void focusGained(FocusEvent arg0) {/* do nothing */}
}
@SuppressWarnings("serial")
class FieldSubject extends JTextField implements FocusListener{
private NoteControler controler;
public FieldSubject(NoteControler controler) {
super(35);
this.controler = controler;
controler.setFieldSubject(this);
this.addFocusListener(this);
}
@Override
public void focusLost(FocusEvent arg0) {
controler.onLostFocusOnSubject();
}
@Override
public void focusGained(FocusEvent arg0) {/* do nothing */}
}
class FieldNoteTagList implements SpecialField, FocusListener{
FieldText text;
private NoteControler controler;
public FieldNoteTagList (NoteControler controler) {
super();
text = new FieldText();
this.controler = controler;
controler.setFieldTagNote(text);
text.addFocusListener(this);
}
@Override
public Component getComponent() {
return new JScrollPane(text);
}
@Override
public void focusLost(FocusEvent arg0) {
controler.onLostFocusOnTagNote();
}
@Override
public void focusGained(FocusEvent arg0) {/* do nothing */}
}