001: package tide.sources;
002:
003: import java.awt.EventQueue;
004: import tide.editor.MainEditorFrame;
005: import java.awt.event.*; //import snow.utils.storage.FileUtils;
006: import snow.utils.DateUtils;
007: import java.awt.BorderLayout;
008: import snow.utils.gui.CloseControlPanel;
009: import javax.swing.*;
010: import java.util.List;
011: import snow.sortabletable.*;
012:
013: /** Displays a practical table overview (filterable) of some project branch (sources or libs).
014: * <p>
015: * Double-click on an item to jump, ...
016: */
017: public final class SourcesExplorer extends JDialog {
018: final private List<? extends FileItem> items;
019: final private String[] columns = new String[] { "path",
020: "last-modified", "size [kB]", "#using", "#used",
021: "declared", "top type kind" };
022: final private JTable table;
023: final private SortableTableModel stm;
024: final private FileTableModel ftm;
025: final private Renderer renderer = new Renderer(); // todo
026: private final static String TITLE = "Project files explorer";
027:
028: public SourcesExplorer(final List<? extends FileItem> items,
029: JFrame parent, String title) {
030: super (parent, (title != null ? title : TITLE) + " ("
031: + items.size() + " files)", false);
032: this .items = items;
033:
034: final CloseControlPanel ccp = new CloseControlPanel(this ,
035: false, true, "Close");
036: add(ccp, BorderLayout.SOUTH);
037:
038: ftm = new FileTableModel();
039: stm = new SortableTableModel(ftm);
040: table = new JTable(stm);
041: stm.installGUI(table);
042: //table.setDefaultRenderer(Object.class, renderer);
043:
044: add(new JScrollPane(table), BorderLayout.CENTER);
045:
046: final MultiSearchPanel msp = new MultiSearchPanel("Filter: ",
047: null, stm);
048: add(msp, BorderLayout.NORTH);
049:
050: EventQueue.invokeLater(new Runnable() {
051: public void run() {
052: msp.requestFocus();
053: }
054: });
055:
056: setSize(850, 700);
057: setLocation(100, 10);
058: setVisible(true);
059:
060: table.addMouseListener(new MouseAdapter() {
061: @Override
062: public void mousePressed(MouseEvent me) {
063: //popup/or double click jump to TODO
064: if (me.getClickCount() == 2) {
065: int posMod = stm
066: .getIndexInUnsortedFromTablePos(table
067: .getSelectedRow());
068: FileItem fi = items.get(posMod);
069: MainEditorFrame.instance
070: .setSourceOrItemToEditOrView(fi, true);
071: }
072: }
073:
074: @Override
075: public void mouseReleased(MouseEvent me) {
076: }
077: });
078: }
079:
080: class FileTableModel extends FineGrainTableModel {
081: public Object getValueAt(int row, int col) {
082: FileItem it = items.get(row);
083: /*if(col==0)
084: {
085: return fileIcon;
086: }
087: else
088: */if (col == 0) {
089: return it.getJavaName();
090: }
091: if (col == 1) {
092: return DateUtils.formatDateAndTimeHuman(it
093: .getLastModified());
094: }
095: if (col == 2) {
096: return it.getFileSize() / 1000;
097: }
098:
099: if (it instanceof SourceFile) {
100: SourceFile sf = (SourceFile) it;
101: SourceFileDependencies sourceFileDependencies = sf.sourceFileDependencies;
102:
103: if (col == 3) {
104: if (sourceFileDependencies == null)
105: return "";
106: if (!sourceFileDependencies.areDependenciesActual())
107: return "na";
108: return sourceFileDependencies
109: .getClassesUsingThis_REF_().size();
110: }
111: if (col == 4) {
112: if (sourceFileDependencies == null)
113: return "";
114: if (!sourceFileDependencies.areDependenciesActual())
115: return "na";
116: return sourceFileDependencies
117: .getClassesUsedBy_REF_().size();
118: }
119: if (col == 5) {
120: if (sourceFileDependencies == null
121: || sourceFileDependencies
122: .getDeclaredTypesNames_REF_()
123: .isEmpty())
124: return "";
125: String dtn = ""
126: + sourceFileDependencies
127: .getDeclaredTypesNames_REF_();
128: return dtn.substring(1, dtn.length() - 1);
129: }
130: if (col == 6) {
131: return "" + sf.topKind;
132: }
133: } else {
134: if (col == 6) {
135: if (MainEditorFrame.instance.librariesPanel
136: .getTreeModel().knownInterfaces.contains(it
137: .getJavaName())) {
138: return "Interface";
139: } else if (MainEditorFrame.instance.librariesPanel
140: .getTreeModel().knownAnnotations
141: .contains(it.getJavaName())) {
142: return "Annotation";
143: }
144: return "";
145: }
146: }
147: return "?";
148: }
149:
150: int[] COLUMN_PREFERED_SIZES = new int[] { 26, 8, 4, 4, 4, 12, 4 };
151:
152: @Override
153: public int getPreferredColumnWidth(int column) {
154: if (column >= 0 && column < COLUMN_PREFERED_SIZES.length)
155: return COLUMN_PREFERED_SIZES[column];
156: return -1;
157: }
158:
159: @Override
160: public int compareForColumnSort(int row1, int row2, int col) {
161: if (col == 1) {
162: // Slow
163: return Long.valueOf(items.get(row1).getLastModified())
164: .compareTo(items.get(row2).getLastModified());
165: }
166:
167: if (col == 2) {
168: // Slow
169: return Long.valueOf(items.get(row1).getFileSize())
170: .compareTo(items.get(row2).getFileSize());
171: }
172: // use the getValueAt
173: return super .compareForColumnSort(row1, row2, col);
174: }
175:
176: @Override
177: public String getColumnName(int col) {
178: return columns[col];
179: }
180:
181: public int getRowCount() {
182: return items.size();
183: }
184:
185: public int getColumnCount() {
186: return columns.length;
187: }
188:
189: @Override
190: public boolean isCellEditable(int r, int c) {
191: return false;
192: }
193:
194: }
195:
196: class Renderer extends JLabel {
197: private final SourcesTreeIcon icon = new SourcesTreeIcon(false,
198: UIManager.getFont("Tree.font").getSize() + 2);
199:
200: //private final SourcesTreeIcon dirIcon = new SourcesTreeIcon(true, UIManager.getFont("Tree.font").getSize()+2);
201:
202: public void setupIcon(FileItem sf) {
203: if (sf instanceof SourceFile) {
204: SourceFile sff = (SourceFile) sf;
205: SourcesTreeRenderer.setupIconFor(icon, sff);
206: this .setIcon(icon);
207: repaint();
208: } else if (sf instanceof LibFileItem) {
209: LibFileItem lf = (LibFileItem) sf;
210: LibTreeRenderer.setupIconFor(icon, lf);
211: this.setIcon(icon);
212: repaint();
213: }
214: }
215: }
216:
217: }
|