Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKBJavaConnector/ECJClient/src/ec/display/SubpopulationPanel.java @ 6152

Last change on this file since 6152 was 6152, checked in by bfarka, 13 years ago

added ecj and custom statistics to communicate with the okb services #1441

File size: 6.9 KB
Line 
1/*
2  Copyright 2006 by Sean Paus
3  Licensed under the Academic Free License version 3.0
4  See the file "LICENSE" for more information
5*/
6
7
8/*
9 * Created on Apr 14, 2005 7:39:29 PM
10 *
11 * By: spaus
12 */
13package ec.display;
14
15import javax.swing.DefaultListModel;
16import javax.swing.JComponent;
17import javax.swing.JPanel;
18
19import java.awt.BorderLayout;
20
21import javax.swing.JList;
22
23import ec.EvolutionState;
24import ec.Setup;
25import ec.display.portrayal.IndividualPortrayal;
26import ec.display.portrayal.SimpleIndividualPortrayal;
27import ec.util.ParamClassLoadException;
28import ec.util.Parameter;
29import ec.util.ReflectedObject;
30
31import javax.swing.JScrollPane;
32import javax.swing.JSplitPane;
33import javax.swing.event.ListSelectionEvent;
34import javax.swing.event.ListSelectionListener;
35
36import javax.swing.JTree;
37/**
38 * @author spaus
39 */
40public class SubpopulationPanel
41    extends JPanel
42    implements EvolutionStateListener, Setup
43    {
44   
45    private final Console console;
46    private final int subPopNum;
47    private JList individualsList = null;
48    private JScrollPane individualListPane = null;
49    private JSplitPane subpopPane = null;
50    private JSplitPane individualDisplayPane = null;
51    private IndividualPortrayal portrayal = null;
52    private JScrollPane inspectionPane = null;
53    private JTree inspectionTree = null;
54    /**
55     *
56     */
57    public SubpopulationPanel(Console console, int subPopNum)
58        {
59        super();
60        this.console = console;
61        this.subPopNum = subPopNum;
62       
63        initialize();
64        }
65   
66    /**
67     * @param isDoubleBuffered
68     */
69    public SubpopulationPanel(Console console, int subPopNum, boolean isDoubleBuffered)
70        {
71        super(isDoubleBuffered);
72        this.console = console;
73        this.subPopNum = subPopNum;
74       
75        initialize();
76        }
77   
78    /**
79     * This method initializes this
80     *
81     * @return void
82     */
83    private  void initialize()
84        {
85        this.setLayout(new BorderLayout());
86        this.setSize(300,200);
87        this.add(getSubpopPane(), java.awt.BorderLayout.CENTER);
88        }
89   
90    /**
91     * This method initializes jList   
92     * 
93     * @return javax.swing.JList       
94     */   
95    private JList getIndividualsList()
96        {
97        if (individualsList == null)
98            {
99            individualsList = new JList();
100            individualsList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
101            int size = console.parameters.getInt(new Parameter("pop.subpop."+subPopNum+".size"),null);
102            DefaultListModel model = new DefaultListModel();
103            for (int i = 0; i < size; ++i)
104                {
105                model.add(i,new Integer(i));
106                }
107            individualsList.setModel(model);
108            individualsList.addListSelectionListener(new ListSelectionListener()
109                {
110                public void valueChanged(ListSelectionEvent evt)
111                    {
112                    if (evt.getValueIsAdjusting() == false)
113                        {
114                        JList source = (JList)evt.getSource();
115                        int idx = source.getSelectedIndex();
116                        inspectionTree.setModel(new ReflectedObject(console.state.population.subpops[subPopNum].individuals[idx]));
117                        portrayal.portrayIndividual(console.state,console.state.population.subpops[subPopNum].individuals[idx]);
118                        }
119                    }
120                });
121            }
122        return individualsList;
123        }
124   
125    public void postEvolution(EvolutionStateEvent evt)
126        {
127        int idx = individualsList.getSelectedIndex();
128        if (idx >= 0)
129            {
130            inspectionTree.setModel(new ReflectedObject(console.state.population.subpops[subPopNum].individuals[idx]));
131            portrayal.portrayIndividual(console.state,console.state.population.subpops[subPopNum].individuals[idx]);
132            }
133        }
134    /**
135     * This method initializes jScrollPane     
136     * 
137     * @return javax.swing.JScrollPane 
138     */   
139    private JScrollPane getIndividualListPane()
140        {
141        if (individualListPane == null)
142            {
143            individualListPane = new JScrollPane();
144            individualListPane.setViewportView(getIndividualsList());
145            individualListPane.setPreferredSize(new java.awt.Dimension(75,131));
146            }
147        return individualListPane;
148        }
149    /**
150     * This method initializes jSplitPane       
151     * 
152     * @return javax.swing.JSplitPane   
153     */   
154    private JSplitPane getSubpopPane()
155        {
156        if (subpopPane == null)
157            {
158            subpopPane = new JSplitPane();
159            subpopPane.setLeftComponent(getIndividualListPane());
160            subpopPane.setRightComponent(getIndividualDisplayPane());
161            subpopPane.setResizeWeight(0.0D);
162            subpopPane.setDividerLocation(100);
163            }
164        return subpopPane;
165        }
166   
167    /**
168     * This method initializes jSplitPane1 
169     *     
170     * @return javax.swing.JSplitPane       
171     */   
172    private JSplitPane getIndividualDisplayPane()
173        {
174        if (individualDisplayPane == null)
175            {
176            individualDisplayPane = new JSplitPane();
177            individualDisplayPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
178            individualDisplayPane.setTopComponent(getInspectionPane());
179            individualDisplayPane.setResizeWeight(0.5D);
180            }
181        return individualDisplayPane;
182        }
183
184    public void setup(EvolutionState state, Parameter base)
185        {
186        try
187            {
188            portrayal = (IndividualPortrayal)state.parameters.getInstanceForParameter(base.push("portrayal"),null,IndividualPortrayal.class);
189            }
190        catch (ParamClassLoadException ex)
191            {
192            // default to SimpleIndividualPortrayal
193            portrayal = new SimpleIndividualPortrayal();
194            }
195        portrayal.setup(state, base);
196        individualDisplayPane.setBottomComponent(new JScrollPane((JComponent)portrayal));
197        }
198    /**
199     * This method initializes jScrollPane 
200     *     
201     * @return javax.swing.JScrollPane     
202     */   
203    private JScrollPane getInspectionPane()
204        {
205        if (inspectionPane == null)
206            {
207            inspectionPane = new JScrollPane();
208            inspectionPane.setViewportView(getInspectionTree());
209            }
210        return inspectionPane;
211        }
212    /**
213     * This method initializes jTree       
214     *     
215     * @return javax.swing.JTree   
216     */   
217    private JTree getInspectionTree()
218        {
219        if (inspectionTree == null)
220            {
221            Object[] emptyTreeModel = new Object[0];
222            inspectionTree = new JTree(emptyTreeModel);
223            }
224        return inspectionTree;
225        }
226    }  //  @jve:decl-index=0:visual-constraint="423,73"
Note: See TracBrowser for help on using the repository browser.