GraphEditor.java

Go to the documentation of this file.
00001 package edu.rice.cs.hpc.viewer.graph;
00002 
00003 import java.io.IOException;
00004 
00005 import org.eclipse.jface.dialogs.MessageDialog;
00006 import org.eclipse.ui.IEditorPart;
00007 import org.eclipse.ui.IEditorReference;
00008 import org.eclipse.ui.IWorkbench;
00009 import org.eclipse.ui.IWorkbenchPage;
00010 import org.eclipse.ui.PlatformUI;
00011 import org.eclipse.ui.preferences.ScopedPreferenceStore;
00012 import org.swtchart.Chart;
00013 import org.swtchart.ILineSeries;
00014 import org.swtchart.ISeries;
00015 import org.swtchart.ISeriesSet;
00016 import org.swtchart.LineStyle;
00017 import org.swtchart.ISeries.SeriesType;
00018 
00019 import edu.rice.cs.hpc.data.experiment.metric.MetricRaw;
00020 import edu.rice.cs.hpc.data.experiment.scope.Scope;
00021 import edu.rice.cs.hpc.viewer.framework.Activator;
00022 import edu.rice.cs.hpc.viewer.metric.ThreadLevelDataFile;
00023 import edu.rice.cs.hpc.viewer.metric.ThreadLevelDataManager;
00024 import edu.rice.cs.hpc.viewer.util.PreferenceConstants;
00025 
00026 public abstract class GraphEditor extends GraphEditorBase {
00027 
00028     static private final int DEFAULT_DIAMETER = 3;
00029     static protected int diameter;
00030     
00031     public GraphEditor() {
00032         ScopedPreferenceStore objPref = (ScopedPreferenceStore)Activator.getDefault().getPreferenceStore();
00033         diameter = objPref.getInt(PreferenceConstants.P_GRAPH_DOT_DIAMETER);
00034         
00035         if (diameter < 1)
00036             diameter = DEFAULT_DIAMETER;
00037     }
00038     
00039     /*****
00040      * change the size of the dot
00041      * @param di
00042      */
00043     static public void setSymbolSize(int di) {
00044         
00045         if (diameter == di)
00046             return;
00047         
00048         diameter = di;
00049         GraphEditor.updateChange();
00050     }
00051     
00052     /*****
00053      * refresh the graph updated with the value of diameter
00054      */
00055     private void refresh() {
00056         Chart chart = this.getChart();
00057         if (chart != null) {
00058             ISeriesSet seriesSet = chart.getSeriesSet();
00059             if (seriesSet != null) {
00060                 ISeries series[] = seriesSet.getSeries();
00061                 for (ISeries serie : series) {
00062                     ((ILineSeries) serie).setSymbolSize(diameter); 
00063                 }
00064                 chart.redraw();
00065             }
00066         }
00067     }
00068     
00069     
00070     /***
00071      * make changes to all the graph editor
00072      */
00073     static private void updateChange() {
00074         IWorkbench workbench = PlatformUI.getWorkbench();
00075         IWorkbenchPage page  = workbench.getActiveWorkbenchWindow().getActivePage();
00076         
00077         IEditorReference editors[] = page.getEditorReferences();
00078         for(IEditorReference editor: editors) {
00079             IEditorPart editorPart = editor.getEditor(false);
00080             if (editorPart instanceof GraphEditor) {
00081                 ((GraphEditor)editorPart).refresh();
00082             }
00083         }
00084     }
00085     
00086     
00087     //========================================================================
00088     // Protected method
00089     //========================================================================
00090     
00091     
00098     protected void plotData(Scope scope, MetricRaw metric ) {
00099         
00100         double y_values[];
00101         try {
00102             y_values = this.getValuesY(threadData, scope, metric);
00103             
00104             double []x_values;
00105 
00106             x_values = this.getValuesX(threadData, scope, metric);
00107 
00108             Chart chart = this.getChart();
00109 
00110             // -----------------------------------------------------------------
00111             // create scatter series
00112             // -----------------------------------------------------------------
00113             ILineSeries scatterSeries = (ILineSeries) chart.getSeriesSet()
00114                     .createSeries(SeriesType.LINE, metric.getDisplayName() );
00115             scatterSeries.setLineStyle(LineStyle.NONE);
00116             scatterSeries.setSymbolSize(diameter);
00117             
00118             // -----------------------------------------------------------------
00119             // set the values x and y to the plot
00120             // -----------------------------------------------------------------
00121             scatterSeries.setXSeries(x_values);
00122             scatterSeries.setYSeries(y_values);
00123             
00124             String axis_x = this.getXAxisTitle( threadData.getThreadLevelDataFile(metric.getID()) );
00125             chart.getAxisSet().getXAxis(0).getTitle().setText( axis_x );
00126             chart.getAxisSet().getYAxis(0).getTitle().setText( "Metric Value" );
00127 
00128         } catch (IOException e) {
00129             MessageDialog.openError(getSite().getShell(), "File to open the file", 
00130                     "Error while openging the file: " + e.getMessage());
00131         }
00132     }
00133 
00134     /***
00135      * retrieve the title of the X axis
00136      * @param type
00137      * @return
00138      */
00139     protected abstract String getXAxisTitle(ThreadLevelDataFile data);
00140 
00141     /*****
00142      * retrieve the value of Xs
00143      * @param objManager
00144      * @param scope
00145      * @param metric
00146      * @return
00147      */
00148     protected abstract double[] getValuesX(ThreadLevelDataManager objManager, Scope scope, MetricRaw metric);
00149     
00150     /*****
00151      * retrieve the value of Y
00152      * @param objManager
00153      * @param scope
00154      * @param metric
00155      * @return
00156      */
00157     protected abstract double[] getValuesY(ThreadLevelDataManager objManager, Scope scope, MetricRaw metric)
00158              throws IOException;
00159 
00160 
00161 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1