Package de.chris_soft.fyllgen.widget

Source Code of de.chris_soft.fyllgen.widget.FamilyModelUniSex

/**
* 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;

/**
* Dies ist das UniSex-Familien-Modell. Es nimmt sich die aktuelle Person und
* stellt alle Vor- und Nachfahren mit dem gleichen Geschlecht wie diese Person
* dar.
* @author Christian Packenius, Juli 2008.
*/
public class FamilyModelUniSex 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;

  /**
   * Konstruktor.
   * @param familyComposite
   */
  public FamilyModelUniSex(FamilyComposite familyComposite) {
    super(familyComposite);
  }

  /**
   * Baut alles neu auf.
   * @param currentMainPerson Person, die aktuell bearbeitet wird.
   * @param bounds
   */
  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();

    // Aktuelle Person in einzelne Liste.
    ArrayList<Person> listSingleGeneration = new ArrayList<Person>();
    listSingleGeneration.add(currentMainPerson);
    listAllPersons.add(currentMainPerson);
    listGenerationsToView.add(listSingleGeneration);

    // Geschlecht der Person ermitteln.
    String currSex = currentMainPerson.getValueView(Person.SEX);

    // Alle Vorfahren einf�gen.
    while (listSingleGeneration.size() > 0) {
      // Neue Generation erzeugen.
      listSingleGeneration = new ArrayList<Person>();
      listGenerationsToView.add(0, listSingleGeneration);

      // Schleife �ber die Generation "danach".
      for (Person child : listGenerationsToView.get(1)) {
        for (Person parent : child.getParents()) {
          if (parent.getValueView(Person.SEX).equals(currSex) && !listAllPersons.contains(parent)) {
            listSingleGeneration.add(parent);
            listAllPersons.add(parent);
          }
        }
      }
    }
    listGenerationsToView.remove(0);

    // Alle Nachfahren einf�gen.
    while (listGenerationsToView.get(listGenerationsToView.size() - 1).size() > 0) {
      // Neue Generation erzeugen.
      listSingleGeneration = new ArrayList<Person>();
      listGenerationsToView.add(listSingleGeneration);

      // Schleife �ber die Generation "davor".
      for (Person parent : listGenerationsToView.get(listGenerationsToView.size() - 2)) {
        for (Person child : parent.getChildren()) {
          if (child.getValueView(Person.SEX).equals(currSex) && !listAllPersons.contains(child)) {
            listSingleGeneration.add(child);
            listAllPersons.add(child);
          }
        }
      }
    }
    listGenerationsToView.remove(listGenerationsToView.size() - 1);

    // Noch die Liste der Composite-Objekte zu den Personen vorbereiten.
    for (int i = 0; i < listAllPersons.size(); i++) {
      listAllPersonComposites.add(null);
    }

    // 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();
  }
}
TOP

Related Classes of de.chris_soft.fyllgen.widget.FamilyModelUniSex

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.