Inheritance: GraphImageUserSettingsBase
    //*************************************************************************
    //  Constructor: AutomatedGraphImageUserSettingsDialog()
    //
    /// <summary>
    /// Initializes a new instance of the <see
    /// cref="AutomatedGraphImageUserSettingsDialog" /> class.
    /// </summary>
    ///
    /// <param name="automatedGraphImageUserSettingsUserSettings">
    /// The object being edited.
    /// </param>
    //*************************************************************************

    public AutomatedGraphImageUserSettingsDialog
    (
        AutomatedGraphImageUserSettings
            automatedGraphImageUserSettingsUserSettings
    )
    {
        Debug.Assert(automatedGraphImageUserSettingsUserSettings != null);
        automatedGraphImageUserSettingsUserSettings.AssertValid();

        m_oAutomatedGraphImageUserSettings =
            automatedGraphImageUserSettingsUserSettings;

        // Instantiate an object that saves and retrieves the position of this
        // dialog.  Note that the object automatically saves the settings when
        // the form closes.

        m_oAutomatedGraphImageUserSettingsDialogUserSettings =
            new AutomatedGraphImageUserSettingsDialogUserSettings(this);

        m_oHeaderFooterFont =
            m_oAutomatedGraphImageUserSettings.HeaderFooterFont;

        InitializeComponent();
        DoDataExchange(false);

        AssertValid();
    }
Example #2
0
        //*************************************************************************
        //  Constructor: AutomatedGraphImageUserSettingsDialog()
        //
        /// <summary>
        /// Initializes a new instance of the <see
        /// cref="AutomatedGraphImageUserSettingsDialog" /> class.
        /// </summary>
        ///
        /// <param name="automatedGraphImageUserSettingsUserSettings">
        /// The object being edited.
        /// </param>
        //*************************************************************************

        public AutomatedGraphImageUserSettingsDialog
        (
            AutomatedGraphImageUserSettings
            automatedGraphImageUserSettingsUserSettings
        )
        {
            Debug.Assert(automatedGraphImageUserSettingsUserSettings != null);
            automatedGraphImageUserSettingsUserSettings.AssertValid();

            m_oAutomatedGraphImageUserSettings =
                automatedGraphImageUserSettingsUserSettings;

            // Instantiate an object that saves and retrieves the position of this
            // dialog.  Note that the object automatically saves the settings when
            // the form closes.

            m_oAutomatedGraphImageUserSettingsDialogUserSettings =
                new AutomatedGraphImageUserSettingsDialogUserSettings(this);

            m_oHeaderFooterFont =
                m_oAutomatedGraphImageUserSettings.HeaderFooterFont;

            InitializeComponent();
            DoDataExchange(false);

            AssertValid();
        }
    btnOptions_Click
    (
        object sender,
        EventArgs e
    )
    {
        AssertValid();

        // These are shared by several cases below.

        Form oUserSettingsDialog = null;
        NodeXLApplicationSettingsBase oUserSettings = null;

        switch ( (AutomationTasks)clbTasksToRun.SelectedValue )
        {
            case AutomationTasks.MergeDuplicateEdges:

                oUserSettings = new MergeDuplicateEdgesUserSettings();

                oUserSettingsDialog =
                    new MergeDuplicateEdgesUserSettingsDialog(
                    MergeDuplicateEdgesUserSettingsDialog.DialogMode.EditOnly,
                    (MergeDuplicateEdgesUserSettings)oUserSettings,
                    m_oThisWorkbook.InnerObject);

                break;

            case AutomationTasks.CalculateClusters:

                oUserSettings = new ClusterUserSettings();

                oUserSettingsDialog = new ClusterUserSettingsDialog(
                    ClusterUserSettingsDialog.DialogMode.EditOnly,
                    (ClusterUserSettings)oUserSettings);

                break;

            case AutomationTasks.CalculateGraphMetrics:

                ( new GraphMetricsDialog(
                    GraphMetricsDialog.DialogMode.EditOnly,
                    m_oThisWorkbook.InnerObject) ).ShowDialog();

                break;

            case AutomationTasks.AutoFillWorkbook:

                // ThisWorkbook manages the modeless AutoFillWorkbookDialog, so
                // tell ThisWorkbook to open the dialog.

                m_oThisWorkbook.AutoFillWorkbook(
                    AutoFillWorkbookDialog.DialogMode.EditOnly);

                break;

            case AutomationTasks.CreateSubgraphImages:

                ( new CreateSubgraphImagesDialog(
                    CreateSubgraphImagesDialog.DialogMode.EditOnly, null,
                    null) ).ShowDialog();

                break;

            case AutomationTasks.ReadWorkbook:

                oUserSettings = new GeneralUserSettings();

                oUserSettingsDialog = new GeneralUserSettingsDialog(
                    (GeneralUserSettings)oUserSettings,
                    m_oThisWorkbook.InnerObject);

                break;

            case AutomationTasks.SaveWorkbookIfNeverSaved:

                EditFolderToSaveWorkbookTo();

                break;

            case AutomationTasks.SaveGraphImageFile:

                oUserSettings = new AutomatedGraphImageUserSettings();

                oUserSettingsDialog =
                    new AutomatedGraphImageUserSettingsDialog(
                    (AutomatedGraphImageUserSettings)oUserSettings);

                break;

            case AutomationTasks.ExportToNodeXLGraphGallery:

                ( new ExportToNodeXLGraphGalleryDialog(
                    ExportToNodeXLGraphGalleryDialog.DialogMode.EditOnly,
                    m_oThisWorkbook.InnerObject, null) ).ShowDialog();

                break;

            case AutomationTasks.ExportToEmail:

                ( new ExportToEmailDialog(
                    ExportToEmailDialog.DialogMode.EditOnly,
                    m_oThisWorkbook.InnerObject, null) ).ShowDialog();

                break;

            default:

                Debug.Assert(false);
                break;
        }

        if (oUserSettingsDialog != null)
        {
            Debug.Assert(oUserSettings != null);

            if (oUserSettingsDialog.ShowDialog() == DialogResult.OK)
            {
                oUserSettings.Save();
            }
        }
    }
    SaveGraphImageFile
    (
        NodeXLControl oNodeXLControl,
        IEnumerable<LegendControlBase> oLegendControls,
        String sWorkbookFilePath
    )
    {
        Debug.Assert(oNodeXLControl != null);
        Debug.Assert(oLegendControls != null);
        Debug.Assert( !String.IsNullOrEmpty(sWorkbookFilePath) );

        AutomatedGraphImageUserSettings oAutomatedGraphImageUserSettings =
            new AutomatedGraphImageUserSettings();

        System.Drawing.Size oImageSizePx =
            oAutomatedGraphImageUserSettings.ImageSizePx;

        Int32 iWidth = oImageSizePx.Width;
        Int32 iHeight = oImageSizePx.Height;

        Boolean bIncludeHeader = oAutomatedGraphImageUserSettings.IncludeHeader;
        Boolean bIncludeFooter = oAutomatedGraphImageUserSettings.IncludeFooter;

        Debug.Assert(!bIncludeHeader ||
            oAutomatedGraphImageUserSettings.HeaderText != null);

        Debug.Assert(!bIncludeFooter ||
            oAutomatedGraphImageUserSettings.FooterText != null);

        GraphImageCompositor oGraphImageCompositor =
            new GraphImageCompositor(oNodeXLControl);

        UIElement oCompositeElement = oGraphImageCompositor.Composite(
            iWidth, iHeight,
            bIncludeHeader ? oAutomatedGraphImageUserSettings.HeaderText : null,
            bIncludeFooter ? oAutomatedGraphImageUserSettings.FooterText : null,
            oAutomatedGraphImageUserSettings.HeaderFooterFont, oLegendControls
            );

        System.Drawing.Bitmap oBitmap = WpfGraphicsUtil.VisualToBitmap(
            oCompositeElement, iWidth, iHeight);

        ImageFormat eImageFormat =
            oAutomatedGraphImageUserSettings.ImageFormat;

        String sImageFilePath = Path.ChangeExtension( sWorkbookFilePath,
            SaveableImageFormats.GetFileExtension(eImageFormat) );

        try
        {
            oBitmap.Save(sImageFilePath, eImageFormat);
        }
        catch (System.Runtime.InteropServices.ExternalException)
        {
            // When an image file already exists and is read-only, an
            // ExternalException is thrown.
            //
            // Note that this method is called from the
            // ThisWorkbook.GraphLaidOut event handler, so this exception can't
            // be handled by a TaskAutomator.AutomateOneWorkbook() exception
            // handler.

            FormUtil.ShowWarning( String.Format(
                "The image file \"{0}\" couldn't be saved.  Does a read-only"
                + " file with the same name already exist?"
                ,
                sImageFilePath
                ) );
        }
        finally
        {
            oBitmap.Dispose();

            oGraphImageCompositor.RestoreNodeXLControl();
        }
    }
Example #5
0
        btnOptions_Click
        (
            object sender,
            EventArgs e
        )
        {
            AssertValid();

            // These are shared by several cases below.

            Form oUserSettingsDialog = null;
            NodeXLApplicationSettingsBase oUserSettings = null;

            switch ((AutomationTasks)clbTasksToRun.SelectedValue)
            {
            case AutomationTasks.MergeDuplicateEdges:

                oUserSettings = new MergeDuplicateEdgesUserSettings();

                oUserSettingsDialog =
                    new MergeDuplicateEdgesUserSettingsDialog(
                        MergeDuplicateEdgesUserSettingsDialog.DialogMode.EditOnly,
                        (MergeDuplicateEdgesUserSettings)oUserSettings,
                        m_oThisWorkbook.InnerObject);

                break;

            case AutomationTasks.CalculateClusters:

                oUserSettings = new ClusterUserSettings();

                oUserSettingsDialog = new ClusterUserSettingsDialog(
                    ClusterUserSettingsDialog.DialogMode.EditOnly,
                    (ClusterUserSettings)oUserSettings);

                break;

            case AutomationTasks.CalculateGraphMetrics:

                (new GraphMetricsDialog(
                     GraphMetricsDialog.DialogMode.EditOnly,
                     m_oThisWorkbook.InnerObject)).ShowDialog();

                break;

            case AutomationTasks.AutoFillWorkbook:

                // ThisWorkbook manages the modeless AutoFillWorkbookDialog, so
                // tell ThisWorkbook to open the dialog.

                m_oThisWorkbook.AutoFillWorkbook(
                    AutoFillWorkbookDialog.DialogMode.EditOnly);

                break;

            case AutomationTasks.CreateSubgraphImages:

                (new CreateSubgraphImagesDialog(
                     CreateSubgraphImagesDialog.DialogMode.EditOnly, null,
                     null)).ShowDialog();

                break;

            case AutomationTasks.ReadWorkbook:

                oUserSettings = new GeneralUserSettings();

                oUserSettingsDialog = new GeneralUserSettingsDialog(
                    (GeneralUserSettings)oUserSettings,
                    m_oThisWorkbook.InnerObject);

                break;

            case AutomationTasks.SaveWorkbookIfNeverSaved:

                EditFolderToSaveWorkbookTo();

                break;

            case AutomationTasks.SaveGraphImageFile:

                oUserSettings = new AutomatedGraphImageUserSettings();

                oUserSettingsDialog =
                    new AutomatedGraphImageUserSettingsDialog(
                        (AutomatedGraphImageUserSettings)oUserSettings);

                break;

            case AutomationTasks.ExportToNodeXLGraphGallery:

                (new ExportToNodeXLGraphGalleryDialog(
                     ExportToNodeXLGraphGalleryDialog.DialogMode.EditOnly,
                     m_oThisWorkbook.InnerObject, null)).ShowDialog();

                break;

            case AutomationTasks.ExportToEmail:

                (new ExportToEmailDialog(
                     ExportToEmailDialog.DialogMode.EditOnly,
                     m_oThisWorkbook.InnerObject, null)).ShowDialog();

                break;

            default:

                Debug.Assert(false);
                break;
            }

            if (oUserSettingsDialog != null)
            {
                Debug.Assert(oUserSettings != null);

                if (oUserSettingsDialog.ShowDialog() == DialogResult.OK)
                {
                    oUserSettings.Save();
                }
            }
        }
Example #6
0
        SaveGraphImageFile
        (
            NodeXLControl oNodeXLControl,
            IEnumerable <LegendControlBase> oLegendControls,
            String sWorkbookFilePath
        )
        {
            Debug.Assert(oNodeXLControl != null);
            Debug.Assert(oLegendControls != null);
            Debug.Assert(!String.IsNullOrEmpty(sWorkbookFilePath));

            AutomatedGraphImageUserSettings oAutomatedGraphImageUserSettings =
                new AutomatedGraphImageUserSettings();

            System.Drawing.Size oImageSizePx =
                oAutomatedGraphImageUserSettings.ImageSizePx;

            Int32 iWidth  = oImageSizePx.Width;
            Int32 iHeight = oImageSizePx.Height;

            Boolean bIncludeHeader = oAutomatedGraphImageUserSettings.IncludeHeader;
            Boolean bIncludeFooter = oAutomatedGraphImageUserSettings.IncludeFooter;

            Debug.Assert(!bIncludeHeader ||
                         oAutomatedGraphImageUserSettings.HeaderText != null);

            Debug.Assert(!bIncludeFooter ||
                         oAutomatedGraphImageUserSettings.FooterText != null);

            GraphImageCompositor oGraphImageCompositor =
                new GraphImageCompositor(oNodeXLControl);

            UIElement oCompositeElement = oGraphImageCompositor.Composite(
                iWidth, iHeight,
                bIncludeHeader ? oAutomatedGraphImageUserSettings.HeaderText : null,
                bIncludeFooter ? oAutomatedGraphImageUserSettings.FooterText : null,
                oAutomatedGraphImageUserSettings.HeaderFooterFont, oLegendControls
                );

            System.Drawing.Bitmap oBitmap = WpfGraphicsUtil.VisualToBitmap(
                oCompositeElement, iWidth, iHeight);

            ImageFormat eImageFormat =
                oAutomatedGraphImageUserSettings.ImageFormat;

            String sImageFilePath = Path.ChangeExtension(sWorkbookFilePath,
                                                         SaveableImageFormats.GetFileExtension(eImageFormat));

            try
            {
                oBitmap.Save(sImageFilePath, eImageFormat);
            }
            catch (System.Runtime.InteropServices.ExternalException)
            {
                // When an image file already exists and is read-only, an
                // ExternalException is thrown.
                //
                // Note that this method is called from the
                // ThisWorkbook.GraphLaidOut event handler, so this exception can't
                // be handled by a TaskAutomator.AutomateOneWorkbook() exception
                // handler.

                FormUtil.ShowWarning(String.Format(
                                         "The image file \"{0}\" couldn't be saved.  Does a read-only"
                                         + " file with the same name already exist?"
                                         ,
                                         sImageFilePath
                                         ));
            }
            finally
            {
                oBitmap.Dispose();

                oGraphImageCompositor.RestoreNodeXLControl();
            }
        }