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.Component;
025 import java.awt.Dimension;
026 import java.awt.GridBagConstraints;
027 import java.awt.GridBagLayout;
028 import java.awt.Insets;
029 import java.awt.event.ActionListener;
030 import java.awt.event.MouseListener;
031
032 import javax.swing.BorderFactory;
033 import javax.swing.DefaultListModel;
034 import javax.swing.GroupLayout;
035 import javax.swing.JButton;
036 import javax.swing.JComponent;
037 import javax.swing.JList;
038 import javax.swing.JPanel;
039 import javax.swing.JScrollPane;
040 import javax.swing.SwingConstants;
041 import javax.swing.border.TitledBorder;
042 import javax.swing.event.ListSelectionListener;
043
044 /**
045 * JPanel for repairing action.
046 * @author Lorenz Buehmann
047 *
048 */
049 public class RepairPanel extends JPanel{
050
051 private static final long serialVersionUID = -7411197973240429632L;
052
053 private JPanel contentPanel;
054
055 private DefaultListModel posFailureModel;
056 private DefaultListModel negFailureModel;
057
058 private JPanel posPanel;
059 private JScrollPane posScrollPane;
060 private JList posList;
061 private JPanel posButtonPanel;
062 private JButton posRepairButton;
063 private JButton posDeleteButton;
064 private JButton posRemoveButton;
065
066 private JPanel negPanel;
067 private JScrollPane negScrollPane;
068 private JList negList;
069 private JPanel negButtonPanel;
070 private JButton negRepairButton;
071 private JButton negDeleteButton;
072 private JButton negAddButton;
073
074
075 public RepairPanel() {
076
077 super();
078 posFailureModel = new DefaultListModel();
079 negFailureModel = new DefaultListModel();
080
081 this.setLayout(new java.awt.BorderLayout());
082
083 JPanel labelPanel = new JPanel();
084
085 contentPanel = getContentPanel();
086
087 add(contentPanel, BorderLayout.CENTER);
088 add(labelPanel, BorderLayout.SOUTH);
089 }
090
091 private JPanel getContentPanel() {
092 JPanel contentPanel = new JPanel();
093 GridBagLayout thisLayout = new GridBagLayout();
094 thisLayout.rowWeights = new double[] {0.1};
095 thisLayout.rowHeights = new int[] {7};
096 thisLayout.columnWeights = new double[] {0.5, 0.5};
097 thisLayout.columnWidths = new int[] {100, 100};
098 contentPanel.setLayout(thisLayout);
099 setPreferredSize(new Dimension(400, 300));
100 {
101 posPanel = new JPanel();
102 GridBagLayout posPanelLayout = new GridBagLayout();
103 contentPanel.add(posPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
104 posPanelLayout.rowWeights = new double[] {0.1};
105 posPanelLayout.rowHeights = new int[] {7};
106 posPanelLayout.columnWeights = new double[] {0.0, 0.5};
107 posPanelLayout.columnWidths = new int[] {80, 110};
108 posPanel.setLayout(posPanelLayout);
109 posPanel.setPreferredSize(new java.awt.Dimension(182, 275));
110 posPanel.setBorder(BorderFactory.createTitledBorder("positive examples"));
111 {
112 posScrollPane = new JScrollPane();
113 posPanel.add(posScrollPane, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
114 posScrollPane.setSize(126, 276);
115 {
116
117 posList = new JList(posFailureModel);
118 posScrollPane.setViewportView(posList);
119 posList.setPreferredSize(new java.awt.Dimension(85, 93));
120 posList.setSize(127, 273);
121 }
122 }
123 {
124 posButtonPanel = new JPanel();
125 posButtonPanel.setName("positive");
126 GroupLayout posButtonPanelLayout = new GroupLayout((JComponent) posButtonPanel);
127 posPanel.add(posButtonPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
128 posButtonPanel.setLayout(posButtonPanelLayout);
129 {
130 posRemoveButton = new JButton();
131 posRemoveButton.setName("posRemove");
132 posRemoveButton.setText("remove");
133 }
134 {
135 posDeleteButton = new JButton();
136 posDeleteButton.setName("posDelete");
137 posDeleteButton.setText("delete");
138 }
139 {
140 posRepairButton = new JButton();
141 posRepairButton.setName("posRepair");
142 posRepairButton.setText("repair");
143 }
144 posButtonPanelLayout.setHorizontalGroup(posButtonPanelLayout.createSequentialGroup()
145 .addGroup(posButtonPanelLayout.createParallelGroup()
146 .addGroup(GroupLayout.Alignment.LEADING, posButtonPanelLayout.createSequentialGroup()
147 .addComponent(posRemoveButton, GroupLayout.PREFERRED_SIZE, 68, GroupLayout.PREFERRED_SIZE)
148 .addGap(10))
149 .addComponent(posDeleteButton, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 78, GroupLayout.PREFERRED_SIZE)
150 .addGroup(GroupLayout.Alignment.LEADING, posButtonPanelLayout.createSequentialGroup()
151 .addComponent(posRepairButton, GroupLayout.PREFERRED_SIZE, 68, GroupLayout.PREFERRED_SIZE)
152 .addGap(10)))
153 .addContainerGap(22, 22));
154 posButtonPanelLayout.linkSize(SwingConstants.HORIZONTAL, new Component[] {posRepairButton, posDeleteButton, posRemoveButton});
155 posButtonPanelLayout.setVerticalGroup(posButtonPanelLayout.createSequentialGroup()
156 .addComponent(posRemoveButton, GroupLayout.PREFERRED_SIZE, 21, GroupLayout.PREFERRED_SIZE)
157 .addComponent(posDeleteButton, GroupLayout.PREFERRED_SIZE, 21, GroupLayout.PREFERRED_SIZE)
158 .addComponent(posRepairButton, GroupLayout.PREFERRED_SIZE, 21, GroupLayout.PREFERRED_SIZE)
159 .addContainerGap(213, 213));
160 posButtonPanelLayout.linkSize(SwingConstants.VERTICAL, new Component[] {posRepairButton, posDeleteButton, posRemoveButton});
161 }
162 }
163 {
164 negPanel = new JPanel();
165 GridBagLayout negPanelLayout = new GridBagLayout();
166 contentPanel.add(negPanel, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
167 negPanelLayout.rowWeights = new double[] {0.1};
168 negPanelLayout.rowHeights = new int[] {7};
169 negPanelLayout.columnWeights = new double[] {0.5, 0.0};
170 negPanelLayout.columnWidths = new int[] {110, 80};
171 negPanel.setLayout(negPanelLayout);
172 posPanel.setPreferredSize(new java.awt.Dimension(182, 275));
173 negPanel.setBorder(BorderFactory.createTitledBorder(null, "negative examples", TitledBorder.LEADING, TitledBorder.TOP));
174 {
175 negScrollPane = new JScrollPane();
176 negPanel.add(negScrollPane, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
177 {
178 negList = new JList(negFailureModel);
179 negScrollPane.setViewportView(negList);
180 negList.setPreferredSize(new java.awt.Dimension(85, 93));
181 negList.setSize(127, 273);
182 }
183 }
184 {
185 negButtonPanel = new JPanel();
186 negButtonPanel.setName("negative");
187 GroupLayout negButtonPanelLayout = new GroupLayout((JComponent) negButtonPanel);
188 negButtonPanel.setLayout(negButtonPanelLayout);
189 negPanel.add(negButtonPanel, new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
190 {
191 negAddButton = new JButton();
192 negAddButton.setName("negAdd");
193 negAddButton.setText("add");
194 }
195 {
196 negDeleteButton = new JButton();
197 negDeleteButton.setName("negDelete");
198 negDeleteButton.setText("delete");
199 }
200 {
201 negRepairButton = new JButton();
202 negRepairButton.setName("negRepair");
203 negRepairButton.setText("repair");
204 }
205 negButtonPanelLayout.setHorizontalGroup(negButtonPanelLayout.createSequentialGroup()
206 .addGroup(negButtonPanelLayout.createParallelGroup()
207 .addComponent(negAddButton, GroupLayout.Alignment.LEADING, 0, 79, Short.MAX_VALUE)
208 .addComponent(negDeleteButton, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 79, GroupLayout.PREFERRED_SIZE)
209 .addGroup(GroupLayout.Alignment.LEADING, negButtonPanelLayout.createSequentialGroup()
210 .addComponent(negRepairButton, GroupLayout.PREFERRED_SIZE, 72, GroupLayout.PREFERRED_SIZE)
211 .addGap(7)))
212 .addContainerGap());
213 negButtonPanelLayout.linkSize(SwingConstants.HORIZONTAL, new Component[] {negRepairButton, negDeleteButton, negAddButton});
214 negButtonPanelLayout.setVerticalGroup(negButtonPanelLayout.createSequentialGroup()
215 .addComponent(negAddButton, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
216 .addComponent(negDeleteButton, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
217 .addComponent(negRepairButton, GroupLayout.PREFERRED_SIZE, 21, GroupLayout.PREFERRED_SIZE)
218 .addContainerGap(213, 213));
219 negButtonPanelLayout.linkSize(SwingConstants.VERTICAL, new Component[] {negRepairButton, negDeleteButton, negAddButton});
220 }
221 }
222
223
224 return contentPanel;
225 }
226
227 /**
228 * Returns the list model for positive examples.
229 * @return list model
230 */
231 public DefaultListModel getPosFailureModel() {
232 return posFailureModel;
233 }
234
235 /**
236 * Returns the list model for negative examples.
237 * @return list model
238 */
239 public DefaultListModel getNegFailureModel() {
240 return negFailureModel;
241 }
242
243 /**
244 * Returns the list for positive examples.
245 * @return positive list
246 */
247 public javax.swing.JList getPosFailureList() {
248 return posList;
249 }
250
251 /**
252 * Returns the list for negative examples.
253 * @return negative list
254 */
255 public javax.swing.JList getNegFailureList() {
256 return negList;
257 }
258
259 /**
260 * adds the list selection listener for lists.
261 * @param l list selection listener
262 */
263 public void addSelectionListeners(ListSelectionListener l){
264 posList.addListSelectionListener(l);
265 negList.addListSelectionListener(l);
266 }
267
268 /**
269 * Adds the action listener to buttons.
270 * @param aL action listener
271 */
272 public void addActionListeners(ActionListener aL){
273 posRemoveButton.addActionListener(aL);
274 posDeleteButton.addActionListener(aL);
275 posRepairButton.addActionListener(aL);
276 negAddButton.addActionListener(aL);
277 negDeleteButton.addActionListener(aL);
278 negRepairButton.addActionListener(aL);
279 }
280
281 /**
282 * Adds mouse listener to lists.
283 * @param mL mouse listener
284 */
285 public void addMouseListeners(MouseListener mL){
286 posList.addMouseListener(mL);
287 negList.addMouseListener(mL);
288 }
289
290 /**
291 * Sets custom cell renderer to the lists.
292 * @param ore
293 */
294 public void setCellRenderers(ORE ore){
295 ColorListCellRenderer cell = new ColorListCellRenderer(ore);
296 posList.setCellRenderer(cell);
297 negList.setCellRenderer(cell);
298 }
299
300
301
302 }
303
304
305
306
307
308