public void buildPopulationBox() { rebuilding = true; populationBox.removeAll(); peopleList = new ArrayList<Object>(); famList = new ArrayList<Family>(); peopleList.addAll(ctxt.individualCensus); String plur = (peopleList.size() == 1 ? "" : "s"); populationBox.setLayout(new BoxLayout(populationBox, BoxLayout.PAGE_AXIS)); populationBox.setBorder( BorderFactory.createTitledBorder( BorderFactory.createLineBorder(Color.blue), "Current Population")); populationBox.setAlignmentX(0.5f); populationBox.add(Box.createRigidArea(new Dimension(8, 0))); indivLabel = new JLabel("Contains " + peopleList.size() + " Individual" + plur); indivLabel.setAlignmentX(0.5f); populationBox.add(indivLabel); if (peopleList.size() > 0) { JPanel indivBtnBox = new JPanel(); indivBtnBox.setLayout(new BoxLayout(indivBtnBox, BoxLayout.LINE_AXIS)); Dimension sizer2 = new Dimension(350, 50); String[] indMenu = genIndMenu(peopleList); indPick = new JComboBox(indMenu); indPick.addActionListener(listener); indPick.setActionCommand("view/edit person"); indPick.setMinimumSize(sizer2); indPick.setMaximumSize(sizer2); indPick.setBorder( BorderFactory.createTitledBorder( BorderFactory.createLineBorder(Color.blue), "View/Edit Person")); indivBtnBox.add(indPick); populationBox.add(indivBtnBox); } // end of if-any-people-exist famList.addAll(ctxt.familyCensus); // end of filtering deleted records plur = (famList.size() == 1 ? "y" : "ies"); famLabel = new JLabel("Contains " + famList.size() + " Famil" + plur); famLabel.setAlignmentX(0.5f); populationBox.add(Box.createRigidArea(new Dimension(0, 4))); populationBox.add(famLabel); if (famList.size() > 0) { JPanel famBtnBox = new JPanel(); famBtnBox.setLayout(new BoxLayout(famBtnBox, BoxLayout.LINE_AXIS)); Dimension sizer2 = new Dimension(350, 50); String[] famMenu = genFamMenu(famList); famPick = new JComboBox(famMenu); famPick.addActionListener(listener); famPick.setActionCommand("view/edit family"); famPick.setMinimumSize(sizer2); famPick.setMaximumSize(sizer2); famPick.setBorder( BorderFactory.createTitledBorder( BorderFactory.createLineBorder(Color.blue), "View/Edit Family")); famBtnBox.add(famPick); populationBox.add(famBtnBox); } // end of if-any-families-exist rebuilding = false; } // end of method buildPopulationBox
public LabFrame() throws HeadlessException { super(title); JPanel pnl, pnl1; data = new LabData(); alRootEntities.addAll(data.findRootEntities()); JMenuBar mb = new JMenuBar(); for (MenuElement e : menus) { mb.add(e.getItem()); } setJMenuBar(mb); splMain = new JSplitPane(); getContentPane().add(splMain); desktop = new JDesktopPane(); desktop.setPreferredSize(new Dimension(400, 200)); splMain.setRightComponent(desktop); lmEntities = new EntityListModel(); lstEntities = new JList(lmEntities); lstEntities.getSelectionModel().addListSelectionListener(lmEntities); lstEntities.addMouseListener(dblClickListener); JScrollPane scpList = new JScrollPane(lstEntities); pnl = new JPanel(new BorderLayout(4, 4)); pnl.add(scpList, BorderLayout.CENTER); pnl1 = new JPanel(null); pnl1.setLayout(new BoxLayout(pnl1, BoxLayout.X_AXIS)); pnl1.add(Box.createHorizontalGlue()); pnl1.add(new JButton(actNewEntity)); pnl1.add(Box.createHorizontalGlue()); pnl1.add(new JButton(actDelEntity)); pnl1.add(Box.createHorizontalGlue()); pnl.add(pnl1, BorderLayout.SOUTH); splMain.setLeftComponent(pnl); il = new InternalFrameAdapter() { @Override public void internalFrameClosed(InternalFrameEvent e) { Object sel = ((EntityFrame) e.getInternalFrame()).content; mapEntityFrames.remove(sel); } @Override public void internalFrameActivated(InternalFrameEvent e) { setTitle(title + " - " + e.getInternalFrame().getTitle()); Object sel = ((EntityFrame) e.getInternalFrame()).content; lstEntities.setSelectedValue(sel, true); } }; pack(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); updateState(); }