001    /**
002     * Copyright (C) 2007-2009, 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    package org.dllearner.tools.protege;
021    
022    import java.awt.Dimension;
023    
024    import javax.swing.DefaultListModel;
025    import javax.swing.JList;
026    import javax.swing.JPanel;
027    import javax.swing.JScrollPane;
028    import javax.swing.ListSelectionModel;
029    
030    /**
031     * This class is the panel for the suggest list.
032     * It shows the descriptions made by the DL-Learner.
033     * @author Christian Koetteritzsch
034     *
035     */
036    public class SuggestClassPanel extends JPanel {
037            
038            private static final long serialVersionUID = 724628423947230L;
039            
040             // Description List
041             
042            private final JList descriptions;
043            
044             // Panel for the description list
045             
046            private final JPanel suggestPanel;
047            
048             //Scroll panel if the suggestions are longer than the Panel itself
049    
050            private final JScrollPane suggestScroll;
051            /**
052             * This is the constructor for the suggest panel.
053             * It creates a new Scroll panel and puts the Suggest List in it. 
054             */
055            public SuggestClassPanel() {
056                    super();
057                    //renders scroll bars if necessary
058                    suggestScroll = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
059                    descriptions = new JList();
060                    descriptions.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
061                    suggestPanel = new JPanel();
062                    descriptions.setVisible(true);
063                    suggestPanel.add(descriptions);
064                    suggestScroll.setPreferredSize(new Dimension(460, 108));
065                    suggestScroll.setViewportView(descriptions);
066                    descriptions.setCellRenderer(new SuggestListCellRenderer());
067                    add(suggestScroll);
068            }
069            
070            /**
071             * this method adds an new Scroll Panel and returns the updated SuggestClassPanel.
072             * @return updated SuggestClassPanel
073             */
074            public SuggestClassPanel updateSuggestClassList() {
075                    add(suggestScroll);
076                    return this;
077                    
078            }
079            /**
080             * This method is called after the model for the suggest list is updated.
081             *  
082             * @param desc List model of descriptions made by the DL-Learner
083             */
084            public void setSuggestList(DefaultListModel desc) {
085                    descriptions.setModel(desc);
086                    repaint();
087            }
088            /**
089             * This method returns the current Description list.
090             * @return JList of Descriptions
091             */
092            public JList getSuggestList() {
093                    return descriptions;
094            }
095            
096            /**
097             * This method adds the suggest list to the Mouse Listener.
098             * @param action ActionHandler
099             */
100            public void addSuggestPanelMouseListener(ActionHandler action) {
101                    descriptions.addMouseListener(action);
102                    
103            }
104            
105    
106    }