/**
* FyLLGen - A Java based tool for collecting and distributing family data
*
* Copyright (C) 2007-2011 Christian Packenius
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.chris_soft.fyllgen.widget;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Rectangle;
import de.chris_soft.fyllgen.data.OptionData;
import de.chris_soft.fyllgen.data.Person;
import de.chris_soft.fyllgen.data.Relationship;
import de.chris_soft.fyllgen.data.RelationshipParentChild;
/**
* Eine kleine View, die einfach nur die Verbindung zwischen zwei beliebigen
* Personen anzeigt.
* @author Christian Packenius, 2008.
*/
public class FamilyModelShowPersonsConnection extends FamilyViewWithColumns implements FamilyModel {
/**
* Aktuell zu bearbeitende Person.
*/
private Person currentMainPerson;
/**
* Ma�e, werden bei jeder Neu-Anzeige aus den Optionen ermittelt.
*/
private int personWidth;
private int personHeight;
/**
* Liste darzustellender Personen. Jede dieser Personen ist mit den beiden
* Listennachbarn irgendwie verwandt.
*/
private final List<Person> personsList;
/**
* Constructor.
* @param familyComposite
* @param listFound
*/
public FamilyModelShowPersonsConnection(FamilyComposite familyComposite, List<Person> listFound) {
super(familyComposite);
personsList = listFound;
}
/**
* Baut alles neu auf.
* @param currentMainPerson Person, die aktuell bearbeitet wird.
* @param bounds Ungenutzt.
*/
public void rebuildPersons(Person currentMainPerson, Rectangle bounds) {
// Person merken.
this.currentMainPerson = currentMainPerson;
// Gr��en holen.
personWidth = OptionData.instance.getInt(OptionData.PERSON_WIDTH);
personHeight = OptionData.instance.getInt(OptionData.PERSON_HEIGHT);
// Alles l�schen, wird hier neu aufgebaut.
listGenerationsToView.clear();
listWidgetsLists.clear();
// Ohne Hauptperson keine Anzeige!
if (currentMainPerson == null) {
return;
}
// Eine Gesamtliste aller Personen sowie eine Liste je Generation.
listAllPersons.clear();
listAllPersonComposites.clear();
// Alle Personen in die Listen einordnen.
int index = 0;
Person lastPerson = null;
for (Person person : personsList) {
// Jede Person in die Liste aller Personen werfen.
listAllPersons.add(person);
listAllPersonComposites.add(null);
// Mal schauen, wie die Person zur letzt hinzugef�gten Person steht.
if (lastPerson != null) {
Relationship relship = lastPerson.getRelationship(person);
if (relship instanceof RelationshipParentChild) {
if (relship.partner1 == lastPerson) {
index++;
}
else {
index--;
}
}
}
// Person in einer Spaltenliste einf�gen.
// Hinten neu anh�ngen?
if (index == listGenerationsToView.size()) {
ArrayList<Person> listSingleGeneration = new ArrayList<Person>();
listSingleGeneration.add(person);
listGenerationsToView.add(listSingleGeneration);
}
// Vorne neu anh�ngen?
else if (index < 0) {
ArrayList<Person> listSingleGeneration = new ArrayList<Person>();
listSingleGeneration.add(person);
listGenerationsToView.add(0, listSingleGeneration);
index++;
}
// Irgendwo einf�gen?
else {
listGenerationsToView.get(index).add(person);
}
// Letzte Person merken.
lastPerson = person;
}
// Alle Widgets f�r die Personen erzeugen.
showAllPersons(listGenerationsToView);
}
/**
* Zeigt alle Generationen an, indem die PersonComposite-Objekte erzeugt
* werden.
*/
private void showAllPersons(List<List<Person>> listGenerationsToView) {
// Farben allokieren.
Color colorBorderCurrentPerson = OptionData.instance.getColor(OptionData.COLOR_BORDER_CURRENT_PERSON);
Color colorBorderNearPerson = OptionData.instance.getColor(OptionData.COLOR_BORDER_NEAR_PERSON);
Color colorBorderOtherPerson = OptionData.instance.getColor(OptionData.COLOR_BORDER_OTHER_PERSON);
// Erzeugt f�r alle Personen der angegebenen Liste jeweils ein Widget.
for (List<Person> personlist : listGenerationsToView) {
List<PersonView> pcList = new ArrayList<PersonView>();
listWidgetsLists.add(pcList);
for (Person person : personlist) {
PersonView pc = new PersonView(familyComposite, person);
pc.setSize(personWidth, personHeight);
if (person == currentMainPerson) {
pc.setBackground(colorBorderCurrentPerson);
}
else if (person.hasConnectionWith(currentMainPerson)) {
pc.setBackground(colorBorderNearPerson);
}
else {
pc.setBackground(colorBorderOtherPerson);
}
pcList.add(pc);
// Der Person das entsprechende Widget zuordnen.
int pi = listAllPersons.indexOf(person);
listAllPersonComposites.set(pi, pc);
}
}
// Farben wieder frei geben.
colorBorderCurrentPerson.dispose();
colorBorderNearPerson.dispose();
colorBorderOtherPerson.dispose();
}
/**
* @see de.chris_soft.fyllgen.widget.FamilyModel#clear()
*/
public void clear() {
listAllPersonComposites.clear();
listAllPersons.clear();
listGenerationsToView.clear();
listWidgetsLists.clear();
}
}