001: /*
002: * Gruntspud
003: *
004: * Copyright (C) 2002 Brett Smith.
005: *
006: * Written by: Brett Smith <t_magicthize@users.sourceforge.net>
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Library General Public License
010: * as published by the Free Software Foundation; either version 2 of
011: * the License, or (at your option) any later version.
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU Library General Public License for more details.
016: *
017: * You should have received a copy of the GNU Library General Public
018: * License along with this program; if not, write to the Free Software
019: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
020: */
021:
022: package gruntspud.ui.view;
023:
024: import gruntspud.CVSFileNode;
025: import gruntspud.Constants;
026: import gruntspud.GruntspudContext;
027: import gruntspud.SortCriteria;
028:
029: import javax.swing.Icon;
030: import javax.swing.JComponent;
031:
032: /**
033: * Description of the Class
034: *
035: *@author magicthize
036: *@created 26 May 2002
037: */
038: public class ToggledCVSView extends AbstractCVSView implements
039: CompoundView {
040: //
041: private boolean flat;
042: private FlatCVSView flatView;
043: private FileCVSView fileView;
044: private SortCriteria flatSortCriteria;
045: private SortCriteria fileSortCriteria;
046: private GruntspudContext context;
047:
048: /**
049: * Creates a new ToggledCVSView object.
050: *
051: * @param context DOCUMENT ME!
052: * @param fileSortCriteria DOCUMENT ME!
053: * @param flatSortCriteria DOCUMENT ME!
054: * @param fileTextMask DOCUMENT ME!
055: * @param flatTextMask DOCUMENT ME!
056: */
057: public ToggledCVSView(GruntspudContext context,
058: SortCriteria fileSortCriteria,
059: SortCriteria flatSortCriteria, String fileTextMask,
060: String flatTextMask) {
061: super ("Toggled", null, "Toggled");
062:
063: this .context = context;
064:
065: flatView = new FlatCVSView(flatSortCriteria, flatTextMask);
066: fileView = new FileCVSView(fileSortCriteria,
067: Constants.FILE_TABLE_GEOMETRY, fileTextMask);
068: flat = false;
069: }
070:
071: /**
072: * DOCUMENT ME!
073: *
074: * @param view DOCUMENT ME!
075: */
076: public void setSelectedView(View view) {
077: }
078:
079: /**
080: * DOCUMENT ME!
081: *
082: * @return DOCUMENT ME!
083: */
084: public int getViewCount() {
085: return 2;
086: }
087:
088: /**
089: * DOCUMENT ME!
090: *
091: * @param node DOCUMENT ME!
092: */
093: public void refilterAndResort() {
094: fileView.refilterAndResort();
095: flatView.refilterAndResort();
096: }
097:
098: /**
099: * DOCUMENT ME!
100: *
101: * @param v DOCUMENT ME!
102: *
103: * @return DOCUMENT ME!
104: */
105: public View getView(int v) {
106: return (v == 0) ? fileView : ((v == 1) ? flatView : null);
107: }
108:
109: /**
110: * DOCUMENT ME!
111: *
112: * @param view DOCUMENT ME!
113: *
114: * @return DOCUMENT ME!
115: */
116: public boolean containsView(View view) {
117: return (view == flatView) || (view == fileView);
118: }
119:
120: /**
121: * DOCUMENT ME!
122: *
123: * @param view DOCUMENT ME!
124: *
125: * @return DOCUMENT ME!
126: */
127: public boolean isViewVisible(View view) {
128: return ((view == flatView) && flat)
129: || ((view == fileView) && !flat);
130: }
131:
132: /**
133: * DOCUMENT ME!
134: *
135: * @param name DOCUMENT ME!
136: *
137: * @return DOCUMENT ME!
138: */
139: public boolean containsView(String name) {
140: View v = getView(name);
141:
142: return v != null;
143: }
144:
145: /**
146: * DOCUMENT ME!
147: *
148: * @param view DOCUMENT ME!
149: *
150: * @return DOCUMENT ME!
151: */
152: public View getView(String view) {
153: if (view.equals(flatView.getViewName())) {
154: return flatView;
155: }
156:
157: if (view.equals(fileView.getViewName())) {
158: return fileView;
159: }
160:
161: return null;
162: }
163:
164: /**
165: * DOCUMENT ME!
166: *
167: * @param l DOCUMENT ME!
168: */
169: public void addViewListener(ViewListener l) {
170: super .addViewListener(l);
171: flatView.addViewListener(l);
172: fileView.addViewListener(l);
173: }
174:
175: /**
176: * DOCUMENT ME!
177: *
178: * @param l DOCUMENT ME!
179: */
180: public void removeViewListener(ViewListener l) {
181: super .removeViewListener(l);
182: flatView.removeViewListener(l);
183: fileView.removeViewListener(l);
184: }
185:
186: /**
187: * DOCUMENT ME!
188: */
189: public void toggleFlatMode() {
190: viewDeselected();
191: flat = !flat;
192: viewSelected();
193: fireViewEvent(new ViewEvent(this , ViewEvent.VIEW_CHANGED, true));
194: }
195:
196: /**
197: * DOCUMENT ME!
198: *
199: * @param manager DOCUMENT ME!
200: */
201: public void start(ViewManager manager) {
202: super .start(manager);
203: flatView.start(manager);
204: fileView.start(manager);
205: }
206:
207: /**
208: * DOCUMENT ME!
209: */
210: public void stop() {
211: flatView.stop();
212: fileView.stop();
213: }
214:
215: private AbstractCVSView getVisibleView() {
216: return flat ? flatView : fileView;
217: }
218:
219: /**
220: * DOCUMENT ME!
221: *
222: * @return DOCUMENT ME!
223: */
224: public String getViewToolTipText() {
225: return getVisibleView().getViewToolTipText();
226: }
227:
228: /**
229: * DOCUMENT ME!
230: *
231: * @return DOCUMENT ME!
232: */
233: public JComponent getViewComponent() {
234: return getVisibleView().getViewComponent();
235: }
236:
237: /**
238: * DOCUMENT ME!
239: *
240: * @return DOCUMENT ME!
241: */
242: public String getViewName() {
243: return getVisibleView().getViewName();
244: }
245:
246: /**
247: * DOCUMENT ME!
248: *
249: * @return DOCUMENT ME!
250: */
251: public Icon getViewIcon() {
252: return getVisibleView().getViewIcon();
253: }
254:
255: /**
256: * DOCUMENT ME!
257: *
258: * @return DOCUMENT ME!
259: */
260: public boolean canClose() {
261: return (((flatView == null) || ((flatView != null) && flatView
262: .canClose())) && ((fileView == null) || ((fileView != null) && fileView
263: .canClose())));
264: }
265:
266: /**
267: * DOCUMENT ME!
268: *
269: * @return DOCUMENT ME!
270: */
271: public boolean closing() {
272: return (((flatView == null) || ((flatView != null) && flatView
273: .closing())) && ((fileView == null) || ((fileView != null) && fileView
274: .closing())));
275: }
276:
277: /**
278: * DOCUMENT ME!
279: *
280: * @param node DOCUMENT ME!
281: */
282: public void reload(CVSFileNode node) {
283: fileView.reload(node);
284: flatView.reload(node);
285: }
286:
287: /**
288: * DOCUMENT ME!
289: *
290: * @param node DOCUMENT ME!
291: */
292: public void setRootNode(CVSFileNode node) {
293: fileView.setRootNode(node);
294: flatView.setRootNode(node);
295: }
296:
297: /**
298: * DOCUMENT ME!
299: *
300: * @param cwdNode DOCUMENT ME!
301: */
302: public void setCWDNode(CVSFileNode cwdNode) {
303: fileView.setCWDNode(cwdNode);
304: flatView.setCWDNode(cwdNode);
305: }
306:
307: /**
308: * DOCUMENT ME!
309: *
310: * @return DOCUMENT ME!
311: */
312: public CVSFileNode getCWDNode() {
313: return getVisibleView().getCWDNode();
314: }
315:
316: /**
317: * DOCUMENT ME!
318: *
319: * @param nodes DOCUMENT ME!
320: */
321: public void setSelectedNodes(CVSFileNode[] nodes) {
322: fileView.setSelectedNodes(nodes);
323: flatView.setSelectedNodes(nodes);
324: }
325:
326: /**
327: * DOCUMENT ME!
328: *
329: * @param nodes DOCUMENT ME!
330: */
331: public void updateNode(CVSFileNode node) {
332: fileView.updateNode(node);
333: flatView.updateNode(node);
334: }
335:
336: /**
337: * DOCUMENT ME!
338: */
339: public void viewDeselected() {
340: getVisibleView().viewDeselected();
341: }
342:
343: /**
344: * DOCUMENT ME!
345: */
346: public void viewSelected() {
347: getVisibleView().viewSelected();
348: }
349:
350: /**
351: * DOCUMENT ME!
352: *
353: * @return DOCUMENT ME!
354: */
355: public CVSFileNode[] getSelectedNodes() {
356: return getVisibleView().getSelectedNodes();
357: }
358:
359: public void viewEventNotify(ViewEvent evt) {
360: super .viewEventNotify(evt);
361: fileView.viewEventNotify(evt);
362: flatView.viewEventNotify(evt);
363: }
364:
365: public boolean isFlatMode() {
366: return flat;
367: }
368: }
|