001: /* ====================================================================
002: * The JRefactory License, Version 1.0
003: *
004: * Copyright (c) 2001 JRefactory. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * 3. The end-user documentation included with the redistribution,
019: * if any, must include the following acknowledgment:
020: * "This product includes software developed by the
021: * JRefactory (http://www.sourceforge.org/projects/jrefactory)."
022: * Alternately, this acknowledgment may appear in the software itself,
023: * if and wherever such third-party acknowledgments normally appear.
024: *
025: * 4. The names "JRefactory" must not be used to endorse or promote
026: * products derived from this software without prior written
027: * permission. For written permission, please contact seguin@acm.org.
028: *
029: * 5. Products derived from this software may not be called "JRefactory",
030: * nor may "JRefactory" appear in their name, without prior written
031: * permission of Chris Seguin.
032: *
033: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
034: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
035: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
036: * DISCLAIMED. IN NO EVENT SHALL THE CHRIS SEGUIN OR
037: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
038: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
039: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
040: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
041: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
042: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
043: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
044: * SUCH DAMAGE.
045: * ====================================================================
046: *
047: * This software consists of voluntary contributions made by many
048: * individuals on behalf of JRefactory. For more information on
049: * JRefactory, please see
050: * <http://www.sourceforge.org/projects/jrefactory>.
051: */
052: package org.acm.seguin.ide.common;
053:
054: import java.awt.Color;
055: import java.awt.Font;
056: import java.awt.GridBagConstraints;
057: import java.awt.GridBagLayout;
058: import java.awt.Insets;
059: import java.util.Iterator;
060: import java.util.TreeMap;
061: import javax.swing.Icon;
062: import javax.swing.ImageIcon;
063: import javax.swing.JLabel;
064: import javax.swing.JPanel;
065: import org.acm.seguin.summary.FileSummary;
066: import org.acm.seguin.summary.PackageSummary;
067: import org.acm.seguin.summary.SummaryTraversal;
068: import org.acm.seguin.summary.TypeSummary; //import org.acm.seguin.uml.ClassIcon;
069: //import org.acm.seguin.uml.InterfaceIcon;
070: import net.sourceforge.jrefactory.uml.UMLPackage;
071: import net.sourceforge.jrefactory.uml.UMLSettings;
072:
073: /**
074: * Holds the list of classes
075: *
076: *@author Chris Seguin
077: *@created October 18, 2001
078: */
079: public class ClassListPanel extends JPanel {
080: private PackageSummary summary;
081: private UMLPackage umlPackage;
082:
083: /**
084: * Constructor for the ClassListPanel object
085: *
086: *@param init Description of Parameter
087: *@param initPackage Description of Parameter
088: */
089: public ClassListPanel(PackageSummary init, UMLPackage initPackage) {
090: summary = init;
091: umlPackage = initPackage;
092: umlPackage.setClassListPanel(this );
093:
094: init();
095: }
096:
097: /**
098: * Adds a feature to the TypeToPanel attribute of the ClassListPanel object
099: *
100: *@param nextType The feature to be added to the TypeToPanel attribute
101: *@param gbc The feature to be added to the TypeToPanel attribute
102: *@param count The feature to be added to the TypeToPanel attribute
103: */
104: private void addTypeToPanel(TypeSummary nextType,
105: GridBagConstraints gbc, int count) {
106: JumpToTypeAdapter jumpToType = new JumpToTypeAdapter(
107: umlPackage, nextType);
108:
109: //Icon icon;
110: //if (nextType.isInterface()) {
111: // //icon = new InterfaceIcon(8, 8);
112: //}
113: //else {
114: // icon = new ClassIcon(8, 8);
115: //}
116: Icon icon = nextType.isInterface() ? UMLSettings.interfacePublicIcon
117: : UMLSettings.classPublicIcon;
118: IconPanel classPanel = new IconPanel(icon);
119: gbc.gridx = 0;
120: gbc.gridy = count;
121: add(classPanel, gbc);
122: classPanel.addMouseListener(jumpToType);
123:
124: JLabel classLabel = new JLabel(nextType.getName(), JLabel.LEFT);
125: gbc.gridx = 1;
126: add(classLabel, gbc);
127: classLabel.addMouseListener(jumpToType);
128: }
129:
130: /**
131: * Initializes the panel
132: */
133: private void init() {
134: setLayout(new GridBagLayout());
135: setBackground(Color.white);
136:
137: GridBagConstraints gbc = new GridBagConstraints();
138:
139: JLabel title;
140: if (summary == null) {
141: title = new JLabel("Unknown");
142: } else {
143: title = new JLabel(summary.getName());
144: }
145: title.setFont(new Font("Dialog", Font.BOLD, 14));
146: gbc.gridx = 0;
147: gbc.gridy = 0;
148: gbc.gridwidth = 2;
149: gbc.insets = new Insets(0, 10, 0, 10);
150: add(title, gbc);
151:
152: gbc.gridwidth = 1;
153: gbc.fill = GridBagConstraints.BOTH;
154:
155: int count = 1;
156: Iterator iter = listTypes();
157: while (iter.hasNext()) {
158: TypeSummary next = (TypeSummary) iter.next();
159: addTypeToPanel(next, gbc, count);
160: count++;
161: }
162:
163: repaint();
164: }
165:
166: /**
167: * Creates a list of type summaries
168: *
169: *@return Description of the Returned Value
170: */
171: private Iterator listTypes() {
172: TreeMap map = new TreeMap();
173:
174: Iterator iter = null;
175: if (summary != null) {
176: iter = summary.getFileSummaries();
177: }
178: while ((iter != null) && iter.hasNext()) {
179: FileSummary nextFileSummary = (FileSummary) iter.next();
180: Iterator iter2 = nextFileSummary.getTypes();
181: while ((iter2 != null) && iter2.hasNext()) {
182: TypeSummary nextType = (TypeSummary) iter2.next();
183: map.put(nextType.getName(), nextType);
184: }
185: }
186:
187: return map.values().iterator();
188: }
189:
190: /**
191: * Used to reload the class list
192: *
193: *@param init Description of Parameter
194: */
195: public void load(PackageSummary init) {
196: summary = init;
197: removeAll();
198: init();
199: }
200:
201: /**
202: * The main program for the ClassListPanel class
203: *
204: *@param args The command line arguments
205: */
206: public static void main(String[] args) {
207: (new SummaryTraversal("c:\\temp\\download")).run();
208: javax.swing.JFrame frame = new javax.swing.JFrame("Class List");
209: frame.getContentPane().add(
210: new ClassListPanel(PackageSummary
211: .getPackageSummary("java.lang"), null));
212: frame.pack();
213: frame.setVisible(true);
214: frame.addWindowListener(new ExitOnCloseAdapter());
215: }
216: }
|