001: /*
002: The contents of this file are subject to the Common Public Attribution License
003: Version 1.0 (the "License"); you may not use this file except in compliance with
004: the License. You may obtain a copy of the License at
005: http://www.projity.com/license . The License is based on the Mozilla Public
006: License Version 1.1 but Sections 14 and 15 have been added to cover use of
007: software over a computer network and provide for limited attribution for the
008: Original Developer. In addition, Exhibit A has been modified to be consistent
009: with Exhibit B.
010:
011: Software distributed under the License is distributed on an "AS IS" basis,
012: WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
013: specific language governing rights and limitations under the License. The
014: Original Code is OpenProj. The Original Developer is the Initial Developer and
015: is Projity, Inc. All portions of the code written by Projity are Copyright (c)
016: 2006, 2007. All Rights Reserved. Contributors Projity, Inc.
017:
018: Alternatively, the contents of this file may be used under the terms of the
019: Projity End-User License Agreeement (the Projity License), in which case the
020: provisions of the Projity License are applicable instead of those above. If you
021: wish to allow use of your version of this file only under the terms of the
022: Projity License and not to allow others to use your version of this file under
023: the CPAL, indicate your decision by deleting the provisions above and replace
024: them with the notice and other provisions required by the Projity License. If
025: you do not delete the provisions above, a recipient may use your version of this
026: file under either the CPAL or the Projity License.
027:
028: [NOTE: The text of this license may differ slightly from the text of the notices
029: in Exhibits A and B of the license at http://www.projity.com/license. You should
030: use the latest text at http://www.projity.com/license for your modifications.
031: You may not remove this license text from the source files.]
032:
033: Attribution Information: Attribution Copyright Notice: Copyright � 2006, 2007
034: Projity, Inc. Attribution Phrase (not exceeding 10 words): Powered by OpenProj,
035: an open source solution from Projity. Attribution URL: http://www.projity.com
036: Graphic Image as provided in the Covered Code as file: openproj_logo.png with
037: alternatives listed on http://www.projity.com/logo
038:
039: Display of Attribution Information is required in Larger Works which are defined
040: in the CPAL as a work which combines Covered Code or portions thereof with code
041: not governed by the terms of the CPAL. However, in addition to the other notice
042: obligations, all copies of the Covered Code in Executable and Source Code form
043: distributed must, as a form of attribution of the original author, include on
044: each user interface screen the "OpenProj" logo visible to all users. The
045: OpenProj logo should be located horizontally aligned with the menu bar and left
046: justified on the top left of the screen adjacent to the File menu. The logo
047: must be at least 100 x 25 pixels. When users click on the "OpenProj" logo it
048: must direct them back to http://www.projity.com.
049: */
050: package com.projity.pm.graphic.views;
051:
052: import java.awt.Dimension;
053: import java.awt.Point;
054:
055: import javax.swing.JScrollPane;
056:
057: import org.apache.commons.collections.Closure;
058:
059: import com.projity.graphic.configuration.GraphicConfiguration;
060: import com.projity.menu.MenuActionConstants;
061: import com.projity.menu.MenuManager;
062: import com.projity.pm.graphic.chart.ChartInfo;
063: import com.projity.pm.graphic.chart.ChartLegend;
064: import com.projity.pm.graphic.chart.TimeChartPanel;
065: import com.projity.pm.graphic.frames.DocumentFrame;
066: import com.projity.pm.graphic.model.cache.NodeModelCache;
067: import com.projity.pm.graphic.model.cache.NodeModelCacheFactory;
068: import com.projity.pm.graphic.model.cache.ReferenceNodeModelCache;
069: import com.projity.pm.graphic.spreadsheet.SpreadSheet;
070: import com.projity.pm.graphic.spreadsheet.selection.event.SelectionNodeEvent;
071: import com.projity.pm.graphic.spreadsheet.selection.event.SelectionNodeListener;
072: import com.projity.pm.graphic.timescale.CoordinatesConverter;
073: import com.projity.pm.graphic.timescale.ScaledScrollPane;
074: import com.projity.pm.graphic.views.synchro.Synchronizer;
075: import com.projity.undo.UndoController;
076: import com.projity.workspace.WorkspaceSetting;
077:
078: /**
079: *
080: */
081: public class ChartView extends SplittedView implements
082: SelectionNodeListener, BaseView {
083: /**
084: *
085: */
086: private static final long serialVersionUID = 3633037900192609747L;
087: ScaledScrollPane scrollPane = null;
088: ChartInfo chartInfo;
089: MenuManager menuManager;
090: DocumentFrame documentFrame;
091: private ChartLegend chartLegend;
092: private Closure transformerClosure;
093:
094: /**
095: * @param synchronizer
096: * @param manager
097: *
098: */
099: public ChartView(DocumentFrame documentFrame, boolean simple,
100: MenuManager menuManager, Synchronizer synchronizer,
101: Closure transformerClosure) {
102: super (synchronizer);
103: this .menuManager = menuManager;
104: this .documentFrame = documentFrame;
105: this .sync = false;
106: this .transformerClosure = transformerClosure;
107: chartInfo = new ChartInfo();
108: chartInfo.setProject(documentFrame.getProject());
109: chartInfo.setSimple(simple);
110: if (!simple) {
111: chartInfo.setCumulativeCostMode();
112: }
113: chartInfo.setChartView(this );
114: chartInfo.setCache(getCache());
115: setDeltaDivider(GraphicConfiguration.getInstance()
116: .getRowChartHeaderWidth());
117: setNeedVoidBar(false);
118: //setScaled(true);
119: }
120:
121: public void init(CoordinatesConverter coord) {
122: chartInfo.setCoord(coord);
123: super .init();
124:
125: }
126:
127: public void cleanUp() {
128: super .cleanUp();
129: chartInfo.getCoord().removeTimeScaleListener(scrollPane);
130: scrollPane = null;
131: chartInfo = null;
132: menuManager = null;
133: documentFrame = null;
134: }
135:
136: protected JScrollPane createLeftScrollPane() {
137: chartLegend = new ChartLegend(chartInfo);
138: chartInfo.setChartLegend(chartLegend);
139: return new JScrollPane(chartLegend.createContentPanel());
140: }
141:
142: protected JScrollPane createRightScrollPane() {
143: TimeChartPanel chartPanel = new TimeChartPanel(chartInfo);
144: chartPanel.setPreferredSize(new Dimension(0, 0)); //to avoid initial vertical scroll bar
145: chartInfo.setChartPanel(chartPanel);
146: scrollPane = new ScaledScrollPane(chartPanel, chartInfo
147: .getCoord(), documentFrame);
148: chartInfo.getAxisPanel().setPreferredSize(
149: new Dimension(GraphicConfiguration.getInstance()
150: .getRowChartHeaderWidth(), (int) chartPanel
151: .getPreferredSize().getHeight()));
152: chartPanel.configureScrollPaneHeaders(scrollPane, chartInfo
153: .getAxisPanel());
154: chartInfo.setChartPanel(chartPanel);
155: return scrollPane;
156: }
157:
158: public void activateEmptyRowHeader(boolean activate) {
159: scrollPane.activateEmptyRowHeader(activate);
160: }
161:
162: public void resetScrollPane() {
163: scrollPane.getViewport().add(chartInfo.getChartPanel());
164: }
165:
166: /**
167: * Pass message on to chart info mediator
168: */
169: public void selectionChanged(SelectionNodeEvent e) {
170: chartInfo.selectionChanged(e); // pass it along
171: }
172:
173: public int getHeaderComponentHeight() {
174: if (scrollPane == null)
175: return GraphicConfiguration.getInstance()
176: .getColumnHeaderHeight();
177: return scrollPane.getTimeScaleComponent().getHeight();
178: }
179:
180: public UndoController getUndoController() {
181: return null; // charts are read only
182: }
183:
184: public void zoomIn() {
185: chartInfo.getCoord().zoomIn();
186: }
187:
188: public void zoomOut() {
189: chartInfo.getCoord().zoomOut();
190: }
191:
192: public boolean canZoomIn() {
193: return chartInfo.getCoord().canZoomIn();
194: }
195:
196: public boolean canZoomOut() {
197: return chartInfo.getCoord().canZoomOut();
198: }
199:
200: public int getScale() {
201: return chartInfo.getCoord().getTimescaleManager()
202: .getCurrentScaleIndex();
203: }
204:
205: public SpreadSheet getSpreadSheet() {
206: return null;
207: }
208:
209: public boolean hasNormalMinWidth() {
210: return true;
211: }
212:
213: public String getViewName() {
214: if (chartInfo.isSimple())
215: return MenuActionConstants.ACTION_HISTOGRAM;
216: else
217: return MenuActionConstants.ACTION_CHARTS;
218: }
219:
220: public boolean showsTasks() {
221: return false;
222: }
223:
224: public boolean showsResources() {
225: return false;
226: }
227:
228: NodeModelCache cache = null;
229:
230: public NodeModelCache getCache() {
231: if (cache == null) // note that histogram and charts share same filtered cache
232: cache = NodeModelCacheFactory.getInstance()
233: .createFilteredCache(
234: (ReferenceNodeModelCache) documentFrame
235: .getResourceNodeModelCache(),
236: MenuActionConstants.ACTION_CHARTS,
237: transformerClosure);
238: return cache;
239: }
240:
241: public void onActivate(boolean activate) {
242: }
243:
244: public boolean isPrintable() {
245: return false;
246: }
247:
248: public void restoreWorkspace(WorkspaceSetting w, int context) {
249: Workspace ws = (Workspace) w;
250: chartInfo.setRestoring(true);
251: chartInfo.restoreWorkspace(ws.chartInfo, context);
252: scrollPane.restoreWorkspace(ws.scrollPane, context);
253: setDividerLocation(ws.dividerLocation);
254: chartLegend.setControlValues();
255: chartLegend.restoreWorkspace(ws.chartLegend, context);
256: getLeftScrollPane().getViewport().setViewPosition(
257: ws.legendViewPosition);
258: getRightScrollPane().getViewport().setViewPosition(
259: ws.chartViewPosition);
260: chartInfo.setRestoring(false);
261:
262: }
263:
264: public WorkspaceSetting createWorkspace(int context) {
265: Workspace ws = new Workspace();
266: ws.chartInfo = chartInfo.createWorkspace(context);
267: ws.scrollPane = scrollPane.createWorkspace(context);
268: ws.dividerLocation = getDividerLocation();
269: ws.chartLegend = chartLegend.createWorkspace(context);
270: ws.legendViewPosition = getLeftScrollPane().getViewport()
271: .getViewPosition();
272: ws.chartViewPosition = getRightScrollPane().getViewport()
273: .getViewPosition();
274: return ws;
275: }
276:
277: public static class Workspace implements WorkspaceSetting {
278: private static final long serialVersionUID = 5497933936501158451L;
279: WorkspaceSetting chartInfo;
280: WorkspaceSetting scrollPane;
281: WorkspaceSetting chartLegend;
282: int dividerLocation;
283: Point legendViewPosition;
284: Point chartViewPosition;
285:
286: public WorkspaceSetting getChartInfo() {
287: return chartInfo;
288: }
289:
290: public void setChartInfo(WorkspaceSetting chartInfo) {
291: this .chartInfo = chartInfo;
292: }
293:
294: public WorkspaceSetting getScrollPane() {
295: return scrollPane;
296: }
297:
298: public void setScrollPane(WorkspaceSetting scrollPane) {
299: this .scrollPane = scrollPane;
300: }
301:
302: public int getDividerLocation() {
303: return dividerLocation;
304: }
305:
306: public void setDividerLocation(int dividerLocation) {
307: this .dividerLocation = dividerLocation;
308: }
309:
310: public WorkspaceSetting getChartLegend() {
311: return chartLegend;
312: }
313:
314: public void setChartLegend(WorkspaceSetting chartLegend) {
315: this .chartLegend = chartLegend;
316: }
317:
318: public Point getLegendViewPosition() {
319: return legendViewPosition;
320: }
321:
322: public void setLegendViewPosition(Point legendViewPosition) {
323: this .legendViewPosition = legendViewPosition;
324: }
325:
326: public Point getChartViewPosition() {
327: return chartViewPosition;
328: }
329:
330: public void setChartViewPosition(Point chartViewPosition) {
331: this .chartViewPosition = chartViewPosition;
332: }
333: }
334:
335: public boolean canScrollToTask() {
336: // TODO Auto-generated method stub
337: return false;
338: }
339:
340: public void scrollToTask() {
341: // TODO Auto-generated method stub
342:
343: }
344:
345: }
|