Class that converts font size values between those used in the Excel workbook and those used in the NodeXL graph.
Inheritance: Object
        //*************************************************************************
        //  Constructor: ReadWorkbookContext()
        //
        /// <summary>
        /// Initializes a new instance of the <see cref="ReadWorkbookContext" />
        /// class.
        /// </summary>
        //*************************************************************************

        public ReadWorkbookContext()
        {
            m_bIgnoreVertexLocations   = true;
            m_bFillIDColumns           = false;
            m_bPopulateVertexWorksheet = false;
            m_bReadEdgeWeights         = false;
            m_bReadGroups = false;
            m_bReadVertexColorFromGroups   = true;
            m_bReadVertexShapeFromGroups   = true;
            m_bReadVertexLabels            = false;
            m_bReadEdgeLabels              = false;
            m_bReadGroupLabels             = false;
            m_bReadVertexImages            = false;
            m_oDefaultVertexImageSize      = new Nullable <Single>();
            m_eDefaultVertexShape          = VertexShape.Disk;
            m_bReadAllEdgeAndVertexColumns = false;
            m_oGraphRectangle              = Rectangle.FromLTRB(0, 0, 100, 100);
            m_oColorConverter2             = new ColorConverter2();
            m_oBooleanConverter            = new BooleanConverter();
            m_oFontSizeConverter           = new FontSizeConverter();
            m_oEdgeWidthConverter          = new EdgeWidthConverter();
            m_oEdgeStyleConverter          = new EdgeStyleConverter();
            m_oVertexRadiusConverter       = new VertexRadiusConverter();

            m_oVertexLocationConverter =
                new VertexLocationConverter(m_oGraphRectangle);

            m_oVertexNameDictionary  = new Dictionary <String, IVertex>();
            m_oEdgeRowIDDictionary   = new Dictionary <Int32, IIdentityProvider>();
            m_oVertexRowIDDictionary = new Dictionary <Int32, IIdentityProvider>();

            AssertValid();
        }
        ReadLabelFontSize
        (
            ExcelTableReader.ExcelTableRow oRow,
            FontSizeConverter oFontSizeConverter,
            IEdge oEdge
        )
        {
            Debug.Assert(oRow != null);
            Debug.Assert(oFontSizeConverter != null);
            AssertValid();

            String sLabelFontSize;

            if (!oRow.TryGetNonEmptyStringFromCell(
                    EdgeTableColumnNames.LabelFontSize, out sLabelFontSize))
            {
                return;
            }

            Single fLabelFontSize;

            if (!Single.TryParse(sLabelFontSize, out fLabelFontSize))
            {
                Range oInvalidCell = oRow.GetRangeForCell(
                    EdgeTableColumnNames.LabelFontSize);

                OnWorkbookFormatError(String.Format(

                                          "The cell {0} contains an invalid label font size.  The label"
                                          + " font size, which is optional, must be a number.  Any"
                                          + " number is acceptable, although {1} is used for any number"
                                          + " less than {1} and {2} is used for any number greater than"
                                          + " {2}."
                                          ,
                                          ExcelUtil.GetRangeAddress(oInvalidCell),
                                          FontSizeConverter.MinimumFontSizeWorkbook,
                                          FontSizeConverter.MaximumFontSizeWorkbook
                                          ),

                                      oInvalidCell
                                      );
            }

            oEdge.SetValue(ReservedMetadataKeys.PerEdgeLabelFontSize,
                           oFontSizeConverter.WorkbookToGraph(fLabelFontSize));
        }
    //*************************************************************************
    //  Constructor: ReadWorkbookContext()
    //
    /// <summary>
    /// Initializes a new instance of the <see cref="ReadWorkbookContext" />
    /// class.
    /// </summary>
    //*************************************************************************

    public ReadWorkbookContext()
    {
        m_bIgnoreVertexLocations = true;
        m_bFillIDColumns = false;
        m_bPopulateVertexWorksheet = false;
        m_bReadEdgeWeights = false;
        m_bReadGroups = false;
        m_bReadVertexColorFromGroups = true;
        m_bReadVertexShapeFromGroups = true;
        m_bReadVertexLabels = false;
        m_bReadEdgeLabels = false;
        m_bReadGroupLabels = false;
        m_bReadVertexImages = false;
        m_oDefaultVertexImageSize = new Nullable<Single>();
        m_eDefaultVertexShape = VertexShape.Disk;
        m_bReadAllEdgeAndVertexColumns = false;
        m_oGraphRectangle = Rectangle.FromLTRB(0, 0, 100, 100);
        m_oColorConverter2 = new ColorConverter2();
        m_oBooleanConverter = new BooleanConverter();
        m_oFontSizeConverter = new FontSizeConverter();
        m_oEdgeWidthConverter = new EdgeWidthConverter();
        m_oEdgeStyleConverter = new EdgeStyleConverter();
        m_oVertexRadiusConverter = new VertexRadiusConverter();

        m_oVertexLocationConverter =
            new VertexLocationConverter(m_oGraphRectangle);

        m_oVertexNameDictionary = new Dictionary<String, IVertex>();
        m_oEdgeRowIDDictionary = new Dictionary<Int32, IIdentityProvider>();
        m_oVertexRowIDDictionary = new Dictionary<Int32, IIdentityProvider>();

        AssertValid();
    }
Example #4
0
        btnOK_Click
        (
            object sender,
            EventArgs e
        )
        {
            AssertValid();

            if (!DoDataExchange(true))
            {
                return;
            }

            // If the caller is going to force the workbook to be reread, there
            // is no point in editing the edges' metadata.

            if (!m_oEditedEdgeAttributes.WorkbookMustBeReread)
            {
                this.UseWaitCursor = true;

                EdgeWidthConverter oEdgeWidthConverter = new EdgeWidthConverter();
                EdgeStyleConverter oEdgeStyleConverter = new EdgeStyleConverter();
                AlphaConverter     oAlphaConverter     = new AlphaConverter();
                FontSizeConverter  oFontSizeConverter  = new FontSizeConverter();

                foreach (IEdge oEdge in m_oNodeXLControl.SelectedEdges)
                {
                    SetValue <Color>(oEdge, ReservedMetadataKeys.PerColor,
                                     m_oEditedEdgeAttributes.Color);

                    SetSingleValue(oEdge, ReservedMetadataKeys.PerEdgeWidth,
                                   m_oEditedEdgeAttributes.Width, oEdgeWidthConverter);

                    SetValue <EdgeStyle>(oEdge, ReservedMetadataKeys.PerEdgeStyle,
                                         m_oEditedEdgeAttributes.Style);

                    SetSingleValue(oEdge, ReservedMetadataKeys.PerAlpha,
                                   m_oEditedEdgeAttributes.Alpha, oAlphaConverter);

                    if (m_oEditedEdgeAttributes.Visibility.HasValue)
                    {
                        Debug.Assert(m_oEditedEdgeAttributes.Visibility.Value ==
                                     EdgeWorksheetReader.Visibility.Hide);

                        oEdge.SetValue(ReservedMetadataKeys.Visibility,
                                       VisibilityKeyValue.Hidden);
                    }

                    SetStringValue(oEdge, ReservedMetadataKeys.PerEdgeLabel,
                                   m_oEditedEdgeAttributes.Label);

                    SetValue <Color>(oEdge,
                                     ReservedMetadataKeys.PerEdgeLabelTextColor,
                                     m_oEditedEdgeAttributes.LabelTextColor);

                    if (m_oEditedEdgeAttributes.LabelFontSize.HasValue)
                    {
                        oEdge.SetValue(ReservedMetadataKeys.PerEdgeLabelFontSize,
                                       oFontSizeConverter.WorkbookToGraph(
                                           m_oEditedEdgeAttributes.LabelFontSize.Value));
                    }
                }

                m_oNodeXLControl.DrawGraph();

                this.UseWaitCursor = false;
            }

            DialogResult = DialogResult.OK;
            this.Close();
        }
    ReadLabelFontSize
    (
        ExcelTableReader.ExcelTableRow oRow,
        FontSizeConverter oFontSizeConverter,
        IEdge oEdge
    )
    {
        Debug.Assert(oRow != null);
        Debug.Assert(oFontSizeConverter != null);
        AssertValid();

        String sLabelFontSize;

        if ( !oRow.TryGetNonEmptyStringFromCell(
            EdgeTableColumnNames.LabelFontSize, out sLabelFontSize) )
        {
            return;
        }

        Single fLabelFontSize;

        if ( !Single.TryParse(sLabelFontSize, out fLabelFontSize) )
        {
            Range oInvalidCell = oRow.GetRangeForCell(
                EdgeTableColumnNames.LabelFontSize);

            OnWorkbookFormatError( String.Format(

                "The cell {0} contains an invalid label font size.  The label"
                + " font size, which is optional, must be a number.  Any"
                + " number is acceptable, although {1} is used for any number"
                + " less than {1} and {2} is used for any number greater than"
                + " {2}."
                ,
                ExcelUtil.GetRangeAddress(oInvalidCell),
                FontSizeConverter.MinimumFontSizeWorkbook,
                FontSizeConverter.MaximumFontSizeWorkbook
                ),

                oInvalidCell
            );
        }

        oEdge.SetValue(ReservedMetadataKeys.PerEdgeLabelFontSize, 
            oFontSizeConverter.WorkbookToGraph(fLabelFontSize) );
    }