Esempio n. 1
0
  public Gui(Town town) {
    this.town = town;

    setTitle("Simple example");
    setSize(300, 200);
    setLocationRelativeTo(null);
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    JPanel panel = new JPanel();
    getContentPane().add(panel);

    panel.setLayout(new GridLayout(1, 2));

    JPanel leftPanel = new JPanel();
    leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.PAGE_AXIS));
    panel.add(leftPanel);
    // panel.setLayout(new BorderLayout());
    // panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

    peopleNames = town.getAllPeopleNames();
    people = town.getAllPeople();

    list = new JList<Person>(people);
    list.setCellRenderer(new PersonListRenderer());
    list.setVisible(true);
    list.addListSelectionListener(this);

    JScrollPane pane = new JScrollPane();
    pane.getViewport().add(list);
    pane.setPreferredSize(new Dimension(250, 200));

    search = new JTextField("");
    search.addActionListener(this);
    search.setMaximumSize(new Dimension(Integer.MAX_VALUE, search.getPreferredSize().height));
    personName = new JLabel("Name");
    lAge = new JLabel("");
    lBirth = new JLabel("");
    lDeath = new JLabel("");
    lEyeColor = new JLabel("");
    lHairColor = new JLabel("");
    lHeight = new JLabel("");
    lInt = new JLabel("");
    lFriends = new JLabel("");

    relations = new JList<Person>();
    relations.setCellRenderer(new PersonRelationListRenderer());
    relations.addMouseListener(new PersonClickBehavior(this));
    father = new JList<Person>();
    father.setCellRenderer(new PersonListRenderer());
    father.addMouseListener(new PersonClickBehavior(this));
    // father.setMaximumSize(new Dimension(Integer.MAX_VALUE, father.getPreferredSize().height));
    mother = new JList<Person>();
    mother.setCellRenderer(new PersonListRenderer());
    mother.addMouseListener(new PersonClickBehavior(this));
    // mother.setMaximumSize(new Dimension(Integer.MAX_VALUE, mother.getPreferredSize().height));

    eventList = new JList<String>();
    eventList.addListSelectionListener(this);
    eventText = new JTextArea("Blank Text");

    leftPanel.add(search);
    leftPanel.add(pane);

    JPanel personPanel = new JPanel();
    personPanel.setLayout(new BoxLayout(personPanel, BoxLayout.PAGE_AXIS));
    personPanel.add(personName);
    personPanel.add(lAge);
    personPanel.add(lBirth);
    personPanel.add(lDeath);
    personPanel.add(lEyeColor);
    personPanel.add(lHairColor);
    personPanel.add(lHeight);
    personPanel.add(lInt);
    personPanel.add(lFriends);
    personPanel.add(relations);

    JPanel eventPanel = new JPanel();
    eventPanel.setLayout(new BoxLayout(eventPanel, BoxLayout.PAGE_AXIS));

    JPanel familyPanel = new JPanel();
    familyPanel.setLayout(new BoxLayout(familyPanel, BoxLayout.PAGE_AXIS));

    JScrollPane familyScrollPane = new JScrollPane();
    familyScrollPane.getViewport().add(relations);

    JPanel parentPanel = new JPanel();

    JPanel fatherPanel = new JPanel();

    JLabel fatherLabel = new JLabel("Father");
    fatherPanel.add(fatherLabel);
    fatherPanel.add(father);

    JPanel motherPanel = new JPanel();

    JLabel motherLabel = new JLabel("Mother");
    motherPanel.add(motherLabel);
    motherPanel.add(mother);

    parentPanel.add(fatherPanel);
    parentPanel.add(motherPanel);

    familyPanel.add(parentPanel);
    familyPanel.add(familyScrollPane);

    JScrollPane eventScrollPane = new JScrollPane();
    eventScrollPane.getViewport().add(eventList);
    eventPanel.add(eventScrollPane);
    // eventPanel.add(eventText);

    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.addTab("Person", personPanel);
    tabbedPane.addTab("Family", familyPanel);
    tabbedPane.addTab("Events", eventPanel);

    panel.add(tabbedPane);

    // panel.add(list);
  }