001 /**
002 * Copyright (C) 2007-2008, Jens Lehmann
003 *
004 * This file is part of DL-Learner.
005 *
006 * DL-Learner is free software; you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation; either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * DL-Learner is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with this program. If not, see <http://www.gnu.org/licenses/>.
018 *
019 */
020
021 package org.dllearner.tools.ore;
022
023 import java.awt.BorderLayout;
024 import java.awt.Dimension;
025 import java.awt.GridBagConstraints;
026 import java.awt.GridBagLayout;
027 import java.awt.Insets;
028 import java.awt.event.ActionListener;
029 import java.awt.geom.Ellipse2D;
030 import java.awt.geom.RoundRectangle2D;
031 import java.util.Dictionary;
032 import java.util.Hashtable;
033
034 import javax.swing.BorderFactory;
035 import javax.swing.BoxLayout;
036 import javax.swing.DefaultListModel;
037 import javax.swing.JButton;
038 import javax.swing.JLabel;
039 import javax.swing.JList;
040 import javax.swing.JPanel;
041 import javax.swing.JScrollPane;
042 import javax.swing.JSlider;
043 import javax.swing.event.ListSelectionListener;
044
045 import org.jdesktop.swingx.JXBusyLabel;
046 import org.jdesktop.swingx.icon.EmptyIcon;
047 import org.jdesktop.swingx.painter.BusyPainter;
048
049
050 /**
051 * The wizard panel where list and buttons for learning step are shown.
052 * @author Lorenz Buehmann
053 *
054 */
055 public class LearningPanel extends JPanel{
056
057 private static final long serialVersionUID = -7411197973240429632L;
058
059 private JPanel contentPanel;
060
061
062 private DefaultListModel listModel;
063
064 private JLabel statusLabel;
065 private JXBusyLabel loadingLabel;
066
067
068
069 private JList resultList;
070 private JScrollPane listScrollPane;
071 private JPanel listPanel;
072 private JPanel noisePanel;
073 private JSlider noiseSlider;
074 private JLabel noiseLabel;
075 private JButton stopButton;
076 private JButton startButton;
077 private JPanel buttonPanel;
078 private JPanel buttonSliderPanel;
079 private JLabel conceptLabel;
080 private JLabel accuracyLabel;
081
082 public LearningPanel() {
083
084 super();
085 listModel = new DefaultListModel();
086
087 JPanel statusPanel = new JPanel();
088 statusLabel = new JLabel();
089 loadingLabel = new JXBusyLabel(new Dimension(15, 15));
090 BusyPainter<Object> painter = new BusyPainter<Object>(
091 new RoundRectangle2D.Float(0, 0, 6.0f, 2.6f, 10.0f, 10.0f),
092 new Ellipse2D.Float(2.0f, 2.0f, 11.0f, 11.0f));
093 painter.setTrailLength(2);
094 painter.setPoints(7);
095 painter.setFrame(-1);
096 loadingLabel.setPreferredSize(new Dimension(15, 15));
097 loadingLabel.setIcon(new EmptyIcon(15, 15));
098 loadingLabel.setBusyPainter(painter);
099 statusPanel.add(loadingLabel);
100 statusPanel.add(statusLabel);
101
102 contentPanel = getContentPanel();
103 setLayout(new java.awt.BorderLayout());
104
105 add(contentPanel, BorderLayout.CENTER);
106 add(statusPanel, BorderLayout.SOUTH);
107 {
108 buttonSliderPanel = new JPanel();
109 this.add(buttonSliderPanel, BorderLayout.EAST);
110 GridBagLayout buttonSliderPanelLayout = new GridBagLayout();
111 buttonSliderPanelLayout.rowWeights = new double[] {0.0, 0.0};
112 buttonSliderPanelLayout.rowHeights = new int[] {126, 7};
113 buttonSliderPanelLayout.columnWeights = new double[] {0.1};
114 buttonSliderPanelLayout.columnWidths = new int[] {7};
115 buttonSliderPanel.setLayout(buttonSliderPanelLayout);
116 {
117 buttonPanel = new JPanel();
118 BoxLayout buttonPanelLayout = new BoxLayout(buttonPanel, javax.swing.BoxLayout.X_AXIS);
119 buttonPanel.setLayout(buttonPanelLayout);
120 buttonSliderPanel.add(buttonPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
121 {
122 startButton = new JButton();
123 buttonPanel.add(startButton);
124 startButton.setText("Start");
125 }
126 {
127 stopButton = new JButton();
128 buttonPanel.add(stopButton);
129 stopButton.setText("Stop");
130 }
131 }
132 {
133 noisePanel = new JPanel();
134 BoxLayout noisePanelLayout = new BoxLayout(noisePanel, javax.swing.BoxLayout.Y_AXIS);
135 noisePanel.setLayout(noisePanelLayout);
136 buttonSliderPanel.add(noisePanel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
137 {
138 noiseLabel = new JLabel();
139 noisePanel.add(noiseLabel);
140 noiseLabel.setText("noise");
141 }
142 {
143 noiseSlider = new JSlider(0, 100, 0);
144 noiseSlider.setPaintTicks(true);
145 noiseSlider.setMajorTickSpacing(10);
146 noiseSlider.setMinorTickSpacing(5);
147 Dictionary<Integer, JLabel> map = new Hashtable<Integer, JLabel>();
148 map.put(new Integer(0), new JLabel("0%"));
149 map.put(new Integer(50), new JLabel("50%"));
150 map.put(new Integer(100), new JLabel("100%"));
151 noiseSlider.setLabelTable(map);
152 noiseSlider.setPaintLabels(true);
153 noisePanel.add(noiseSlider);
154 }
155 }
156 }
157 }
158
159 private JPanel getContentPanel() {
160
161 {
162 listPanel = new JPanel();
163 GridBagLayout jPanel1Layout = new GridBagLayout();
164 jPanel1Layout.rowWeights = new double[] {0.0, 0.5};
165 jPanel1Layout.rowHeights = new int[] {16, 400};
166 jPanel1Layout.columnWeights = new double[] {0.0, 0.5};
167 jPanel1Layout.columnWidths = new int[] {50, 700};
168 listPanel.setLayout(jPanel1Layout);
169 listPanel.setBorder(BorderFactory.createTitledBorder("Learned Classes"));
170 {
171 listScrollPane = new JScrollPane();
172 listPanel.add(listScrollPane, new GridBagConstraints(0, 1, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
173 {
174
175 resultList = new JList(listModel);
176 listScrollPane.setViewportView(resultList);
177 }
178 }
179 {
180 accuracyLabel = new JLabel();
181 listPanel.add(accuracyLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
182 accuracyLabel.setText("Accuracy");
183 }
184 {
185 conceptLabel = new JLabel();
186 listPanel.add(conceptLabel, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
187 conceptLabel.setText("Class");
188 }
189 }
190
191
192
193
194 return listPanel;
195 }
196
197 public void addStartButtonListener(ActionListener a){
198 startButton.addActionListener(a);
199 }
200
201 public void addStopButtonListener(ActionListener a){
202 stopButton.addActionListener(a);
203 }
204
205 public JLabel getStatusLabel() {
206 return statusLabel;
207 }
208
209 public JXBusyLabel getLoadingLabel() {
210 return loadingLabel;
211 }
212
213 public JButton getStartButton() {
214 return startButton;
215 }
216
217 public JButton getStopButton() {
218 return stopButton;
219 }
220
221 public DefaultListModel getListModel() {
222
223 return (DefaultListModel)resultList.getModel();
224 }
225
226 public javax.swing.JList getResultList() {
227 return resultList;
228 }
229
230 public void addSelectionListener(ListSelectionListener l){
231 resultList.addListSelectionListener(l);
232 }
233
234 public double getNoise(){
235 return noiseSlider.getValue();
236 }
237
238
239 }
240
241
242
243
244
245