001/* 002 * Copyright (c) 2005 Einar Pehrson, Malin Johansson and Sofia Nilsson 003 * 004 * This file is part of 005 * CleanSheets Extension for Dependency Trees 006 * 007 * CleanSheets Extension for Dependency Trees is free software; you can 008 * redistribute it and/or modify it under the terms of the GNU General Public 009 * License as published by the Free Software Foundation; either version 2 of 010 * the License, or (at your option) any later version. 011 * 012 * CleanSheets Extension for Dependency Trees is distributed in the hope that 013 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied 014 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 015 * See the GNU General Public License for more details. 016 * 017 * You should have received a copy of the GNU General Public License 018 * along with CleanSheets Extension for Dependency Trees; if not, write to the 019 * Free Software Foundation, Inc., 59 Temple Place, Suite 330, 020 * Boston, MA 02111-1307 USA 021 */ 022package csheets.ext.deptree; 023 024import java.awt.GridLayout; 025 026import javax.swing.BorderFactory; 027import javax.swing.Icon; 028import javax.swing.ImageIcon; 029import javax.swing.JComponent; 030import javax.swing.JPanel; 031import javax.swing.JScrollPane; 032import javax.swing.border.TitledBorder; 033 034import csheets.ui.ctrl.UIController; 035import csheets.ui.ext.UIExtension; 036 037/** 038 * The user interface extension for dependency trees. 039 * @author Einar Pehrson 040 */ 041public class DependencyTreeUIExtension extends UIExtension { 042 043 /** The icon to display with the extension's name */ 044 private Icon icon; 045 046 /** A panel in which a precedents tree and a dependents tree is displayed */ 047 private JComponent sideBar; 048 049 /** 050 * Creates a new user interface extension.. 051 * @param extension the extension for which components are provided 052 * @param uiController the user interface controller 053 */ 054 public DependencyTreeUIExtension(DependencyTreeExtension extension, 055 UIController uiController) { 056 super(extension, uiController); 057 } 058 059 /** 060 * Returns an icon to display with the extension's name. 061 * @return an icon with a tree 062 */ 063 public Icon getIcon() { 064 if (icon == null) 065 icon = new ImageIcon( 066 DependencyTreeExtension.class.getResource("res/img/logo.gif")); 067 return icon; 068 } 069 070 /** 071 * Returns a panel in which a precedents tree and a dependents tree is 072 * displayed. 073 * @return a panel with two dependency trees 074 */ 075 public JComponent getSideBar() { 076 if (sideBar == null) { 077 sideBar = new JPanel(new GridLayout(2, 1)); 078 sideBar.setName(DependencyTreeExtension.NAME); 079 080 // Creates components 081 PrecedentsTree precedentsTree = new PrecedentsTree(uiController); 082 JScrollPane precedentsPane = new JScrollPane(precedentsTree); 083 DependentsTree dependentsTree = new DependentsTree(uiController); 084 JScrollPane dependentsPane = new JScrollPane(dependentsTree); 085 086 // Adds borders 087 TitledBorder border = BorderFactory.createTitledBorder("Precedents"); 088 border.setTitleJustification(TitledBorder.CENTER); 089 precedentsPane.setBorder(border); 090 border = BorderFactory.createTitledBorder("Dependents"); 091 border.setTitleJustification(TitledBorder.CENTER); 092 dependentsPane.setBorder(border); 093 094 // Creates side bar 095 sideBar.add(precedentsPane); 096 sideBar.add(dependentsPane); 097 } 098 return sideBar; 099 } 100}