public void SVGCreate(LingTreeTree Tree, StringBuilder sb, string sLineColor, double dLineWidth) { LingTreeNode Node; Font font = GetTextFont(Tree); Color clr = GetTextColor(Tree); // Draw this node if (Tree.ShowFlatView) { // adjust lex and gloss Y coordinates if (Type == NodeType.Lex) { YCoord = Tree.LexBottomYCoord; YUpperMid = Tree.LexBottomYUpperMid; } if (Type == NodeType.Gloss) { YCoord = Tree.GlossBottomYCoord; } } string sClrName = LingTreeNode.SVGConvertColorToSVGColorString(clr); SVGDrawString(Content, sb, font, sClrName); // Draw daughter nodes Node = Daughter; while (Node != null) { Node.SVGCreate(Tree, sb, sLineColor, dLineWidth); if (Type == NodeType.NonTerminal) { if (!Node.Triangle) { if (!Node.OmitLine) { SVGDrawLine(sb, sLineColor, dLineWidth, Node.XMid, Node.YUpperMid, XMid, YLowerMid); } } else { #if DoTrace Console.WriteLine("\tDrawing triangle: Node = {0},\tXCoord = {1}", Node.Content, Node.XCoord); #endif int ix = Node.XCoord + m_iTriangleOffset; Point[] apt = { new Point(ix, Node.YCoord), new Point(XMid, YLowerMid), new Point(ix + (Node.Width - 2 * m_iTriangleOffset), Node.YCoord), new Point(ix, Node.YCoord) }; SVGDrawLines(sb, sLineColor, dLineWidth, apt); } } Node = Node.Sister; } }
void AdjustXValues(LingTreeTree tree, int iAdjust) { // adjust this node XCoord += iAdjust; XMid += iAdjust; tree.HorizontalOffset = tree.HorizontalOffset + iAdjust; // adjust any daughter nodes LingTreeNode NextDaughter = Daughter; while (NextDaughter != null) { NextDaughter.AdjustXValues(tree, iAdjust); NextDaughter = NextDaughter.Sister; } }
/// <summary> /// Determine the Y-axis coordinate for this node /// </summary> /// <param name="iVerticalOffset">vertical offset up to this node</param> /// <param name="Tree">the tree itself</param> /// <param name="grfx">grpahics info</param> public void CalculateYCoordinate(int iVerticalOffset, LingTreeTree Tree, Graphics grfx) { LingTreeNode Node; // Determine Y-axis coordinates for this node YCoord = iVerticalOffset; YLowerMid = YCoord + Height + m_iYCoordAdjustment; YUpperMid = YCoord - m_iYCoordAdjustment; if (YLowerMid > Tree.YSize) { Tree.YSize = YLowerMid; // Keep track of total height for scrolling } if (Type == NodeType.Lex) { // keep track of lowest for "flat" view if (YCoord > Tree.LexBottomYCoord) { Tree.LexBottomYCoord = YCoord; } if (YUpperMid > Tree.LexBottomYUpperMid) { Tree.LexBottomYUpperMid = YUpperMid; } } if (Type == NodeType.Gloss) { // keep track of lowest for "flat" view if (YCoord > Tree.GlossBottomYCoord) { Tree.GlossBottomYCoord = YCoord; } } // Determine Y-axis coordinate for any daughters Node = Daughter; while (Node != null) { int iDaughterYCoordinate = YCoord + Tree.GetMaxLevelHeight(Level); if (Node.Type != NodeType.Gloss) { iDaughterYCoordinate += Tree.VerticalGap; } else { iDaughterYCoordinate += Tree.LexGlossGapAdjustment; } Node.CalculateYCoordinate(iDaughterYCoordinate, Tree, grfx); Node = Node.Sister; } }
/////////////////////////////////////////////////////////////////////////////// // NAME // CalculateMaxHeight // ARGUMENTS // pTree - pointer to tree this node is in // pDC - pointer to the device context // DESCRIPTION // Determine the maximum height at each level in the tree // It assumes that the height of this and all other nodes hav already been established // RETURN VALUE // none // public void CalculateMaxHeight(LingTreeTree Tree, Graphics grfx) { LingTreeNode Node; // Determine the height for this node CalculateHeight(Tree, grfx); // calculate max height of all daughters Node = Daughter; while (Node != null) { Node.CalculateMaxHeight(Tree, grfx); Node = Node.Sister; } // set tree's maximum height at this node's level if (Tree.GetMaxLevelHeight(Level) < Height) { Tree.SetMaxLevelHeight(Level, Height); } }
/////////////////////////////////////////////////////////////////////////////// // NAME // GetTextFont // ARGUMENTS // Tree - tree this node is in // DESCRIPTION // Set font for this node // RETURN VALUE // font of the node type // Font GetTextFont(LingTreeTree Tree) { if (Type == NodeType.NonTerminal) { return(Tree.NTFont); } else if (Type == NodeType.Lex) { return(Tree.LexFont); } else if (Type == NodeType.Gloss) { return(Tree.GlossFont); } else // should never happen, but... { return(Tree.NTFont); } }
/////////////////////////////////////////////////////////////////////////////// // NAME // GetTextColor // ARGUMENTS // Tree - tree this node is in // DESCRIPTION // Set color for this node // RETURN VALUE // color of the node type // Color GetTextColor(LingTreeTree Tree) { if (Type == NodeType.NonTerminal) { return(Tree.NTColor); } else if (Type == NodeType.Lex) { return(Tree.LexColor); } else if (Type == NodeType.Gloss) { return(Tree.GlossColor); } else // should never happen, but... { return(Tree.NTColor); } }
/////////////////////////////////////////////////////////////////////////////// // NAME // CalculateWidth // ARGUMENTS // pTree - pointer to tree this node is in // pDC - pointer to the device context // DESCRIPTION // Calculate the width of this node // RETURN VALUE // none // public void CalculateWidth(LingTreeTree Tree, Graphics grfx) { Font font = GetTextFont(Tree); int i = Content.IndexOf("/s"); if (i != -1) { // have a regular subscript Width = CalculateWidthWithSuperOrSubScript(i, font, grfx, false); } else { i = Content.IndexOf("/_"); if (i != -1) { // have an italic subscript Width = CalculateWidthWithSuperOrSubScript(i, font, grfx, true); } else { i = Content.IndexOf("/S"); if (i != -1) { // have a regular superscript Width = CalculateWidthWithSuperOrSubScript(i, font, grfx, false); } else { i = Content.IndexOf("/^"); if (i != -1) { // have an italic superscript Width = CalculateWidthWithSuperOrSubScript(i, font, grfx, true); } else { Width = (int)Math.Ceiling(grfx.MeasureString(Content, font).Width); } } } } }
/////////////////////////////////////////////////////////////////////////////// // NAME // CalculateXCoordinate // ARGUMENTS // pTree - pointer to tree this node is in // pDC - pointer to the device context // iMaxColWidth - maximum width of the current column // DESCRIPTION // Determine the X-axis coordinate for this node // It assumes that the width of this and all other nodes have // already been established. // It also assumes that higher branching nodes are not wider than the // total width of their daughters (which may not always be true...) // RETURN VALUE // The X-axis coordinate at the mid-point of this node // public int CalculateXCoordinate(LingTreeTree Tree, Graphics grfx, int iMaxColWidth) { XMid = 0; // Determine the width for this node CalculateWidth(Tree, grfx); if (Daughter != null) { // is a non-terminal node LingTreeNode NextDaughter = Daughter.Sister; if (NextDaughter != null) { // node branches if (iMaxColWidth < m_iWidth) iMaxColWidth = m_iWidth; // remember widest node in the column } else { // only one daughter, so could be in a column if (iMaxColWidth < Width) iMaxColWidth = Width; // remember widest node in the column } int iLeftMost = Daughter.CalculateXCoordinate(Tree, grfx, iMaxColWidth); int iRightMost = iLeftMost; while (NextDaughter != null) { // calculate coordinates for other daughters iRightMost = NextDaughter.CalculateXCoordinate(Tree, grfx, iMaxColWidth); NextDaughter = NextDaughter.Sister; } // take mid point between first & last daughter XMid = (iLeftMost + iRightMost) / 2; if (iRightMost > iLeftMost) { if (m_iWidth > (iRightMost - iLeftMost)) { int iAdjust = (m_iWidth - (iRightMost - iLeftMost))/2; m_iXMid += iAdjust; NextDaughter = Daughter; while (NextDaughter != null) { NextDaughter.AdjustXValues(Tree, iAdjust); NextDaughter = NextDaughter.Sister; } } } } else { // is a terminal node if (iMaxColWidth < Width) iMaxColWidth = Width; // this might be the widest node in the column XMid = (int)Tree.HorizontalOffset + // Offset from last terminal node plus iMaxColWidth/2; // half the width of this column Tree.HorizontalOffset = XMid + // have a new offset for next terminal node Tree.HorizontalGap + // gap between terminal nodes plus iMaxColWidth/2; // half the width of the widest node in this column } XCoord = XMid - Width/2; // adjust for width of this node int iEnd = XCoord + Width; if (Triangle) { iEnd += Tree.HorizontalGap/2; } if (iEnd > Tree.XSize) Tree.XSize = iEnd; // Keep track of total width for scrolling #if DoTrace Console.WriteLine("{0}\tXSize = {1},\tWidth = {2},\tXCoord = {3},\tYCoord = {4}, \tXMid = {4}", Content, Tree.XSize, Width, XCoord, YCoord, XMid); #endif return XMid; }
/////////////////////////////////////////////////////////////////////////////// // NAME // CalculateWidth // ARGUMENTS // pTree - pointer to tree this node is in // pDC - pointer to the device context // DESCRIPTION // Calculate the width of this node // RETURN VALUE // none // public void CalculateWidth(LingTreeTree Tree, Graphics grfx) { Font font = GetTextFont(Tree); int i = Content.IndexOf("/s"); if (i != -1) { // have a regular subscript Width = CalculateWidthWithSuperOrSubScript(i, font, grfx, false); } else { i = Content.IndexOf("/_"); if (i != -1) { // have an italic subscript Width = CalculateWidthWithSuperOrSubScript(i, font, grfx, true); } else { i = Content.IndexOf("/S"); if (i != -1) { // have a regular superscript Width = CalculateWidthWithSuperOrSubScript(i, font, grfx, false); } else { i = Content.IndexOf("/^"); if (i != -1) { // have an italic superscript Width = CalculateWidthWithSuperOrSubScript(i, font, grfx, true); } else Width = (int)Math.Ceiling(grfx.MeasureString(Content, font).Width); } } } }
/////////////////////////////////////////////////////////////////////////////// // NAME // CalculateMaxHeight // ARGUMENTS // pTree - pointer to tree this node is in // pDC - pointer to the device context // DESCRIPTION // Determine the maximum height at each level in the tree // It assumes that the height of this and all other nodes hav already been established // RETURN VALUE // none // public void CalculateMaxHeight(LingTreeTree Tree, Graphics grfx) { LingTreeNode Node; // Determine the height for this node CalculateHeight(Tree, grfx); // calculate max height of all daughters Node = Daughter; while (Node != null) { Node.CalculateMaxHeight(Tree, grfx); Node = Node.Sister; } // set tree's maximum height at this node's level if (Tree.GetMaxLevelHeight(Level) < Height) Tree.SetMaxLevelHeight(Level , Height); }
/////////////////////////////////////////////////////////////////////////////// // NAME // CalculateHeight // ARGUMENTS // pTree - pointer to tree this node is in // pDC - pointer to the device context // DESCRIPTION // Calculate the height of this node // RETURN VALUE // none // public void CalculateHeight(LingTreeTree Tree, Graphics grfx) { Font font = GetTextFont(Tree); Height = (int)Math.Ceiling(grfx.MeasureString(Content, font).Height); }
void MenuFileCloseOnClick(object obj, EventArgs ea) { if (m_bIsDirty) { LingTreeAppOnClosing(null, null); } #if Old tree = new LingTreeTree(Application.ProductVersion); #else pnlForTree.Controls.Clear(); tree = new LingTreeTree(Application.ProductVersion); tree.Parent = pnlForTree; // tree.Paint += new PaintEventHandler(TreePanelOnPaint); tree.m_LingTreeNodeClickedEvent += new LingTreeNodeClickedEventHandler(OnNodeClicked); pnlForTree.Controls.Add(tree); #endif initTreeToDefaultValues(); initTree(); m_strTreeFile = null; tree.Description = m_strNewDescriptionMessage; rtbTreeDescription.Text = tree.Description; rtbTreeDescription.SelectAll(); setIsDirty(false); m_strSVG = null; }
void loadTree() { try { #if UseXmlSerialization XmlSerializer mySerializer = new XmlSerializer(tree.GetType()); StreamReader myReader = new StreamReader(m_strTreeFile); tree = (LingTreeTree)mySerializer.Deserialize(myReader); tree.setFontsFromXml(); myReader.Close(); #else XmlDocument doc = new XmlDocument(); doc.Load(m_strTreeFile); tree.Description = GetNodeContent("/LingTreeTree/Description", doc); tree.VerticalGap = GetIntFromNodeContent("/LingTreeTree/VerticalGap", doc); tree.HorizontalGap = GetIntFromNodeContent("/LingTreeTree/HorizontalGap", doc); tree.InitialXCoord = GetIntFromNodeContent("/LingTreeTree/InitialXCoord", doc); tree.InitialYCoord = GetIntFromNodeContent("/LingTreeTree/InitialYCoord", doc); tree.HorizontalOffset = GetIntFromNodeContent("/LingTreeTree/HorizontalOffset", doc); tree.LexGlossGapAdjustment = GetIntFromNodeContent("/LingTreeTree/LexGlossGapAdjustment", doc); tree.TrySmoothing = GetBoolFromNodeContent("/LingTreeTree/TrySmoothing", doc); tree.TryPixelOffset = GetBoolFromNodeContent("/LingTreeTree/TryPixelOffset", doc); tree.GlossFontFace = GetNodeContent("/LingTreeTree/GlossFontFace", doc); tree.GlossFontSize = GetIntFromNodeContent("/LingTreeTree/GlossFontSize", doc); tree.GlossFontStyle = GetFontStyleFromNodeContent("/LingTreeTree/GlossFontStyle", doc); tree.LexFontFace = GetNodeContent("/LingTreeTree/LexFontFace", doc); tree.LexFontSize = GetIntFromNodeContent("/LingTreeTree/LexFontSize", doc); tree.LexFontStyle = GetFontStyleFromNodeContent("/LingTreeTree/LexFontStyle", doc); tree.NTFontFace = GetNodeContent("/LingTreeTree/NTFontFace", doc); tree.NTFontSize = GetIntFromNodeContent("/LingTreeTree/NTFontSize", doc); tree.NTFontStyle = GetFontStyleFromNodeContent("/LingTreeTree/NTFontStyle", doc); tree.GlossColorArgb = GetIntFromNodeContent("/LingTreeTree/GlossColorArgb", doc); tree.LexColorArgb = GetIntFromNodeContent("/LingTreeTree/LexColorArgb", doc); tree.NTColorArgb = GetIntFromNodeContent("/LingTreeTree/NTColorArgb", doc); tree.LinesColorArgb = GetIntFromNodeContent("/LingTreeTree/LinesColorArgb", doc); tree.BackgroundColorArgb = GetIntFromNodeContent("/LingTreeTree/BackgroundColorArgb", doc); if (tree.BackgroundColorArgb == 0) tree.BackgroundColorArgb = -1; // use white instead of transparent since transparent crashes tree.LineWidth = GetIntFromNodeContent("/LingTreeTree/LineWidth", doc); tree.CustomColors = GetCustomColorsFromNodeContent(doc); tree.NTFont = new Font(tree.NTFontFace, tree.NTFontSize, tree.NTFontStyle); tree.GlossFont = new Font(tree.GlossFontFace, tree.GlossFontSize, tree.GlossFontStyle); tree.LexFont = new Font(tree.LexFontFace, tree.LexFontSize, tree.LexFontStyle); #endif } catch (Exception exc) { MessageBox.Show("An error occurred while trying to load the tree description file: " + exc.Message, "Load error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } setIsDirty(false); }
/////////////////////////////////////////////////////////////////////////////// // NAME // GetTextColor // ARGUMENTS // Tree - tree this node is in // DESCRIPTION // Set color for this node // RETURN VALUE // color of the node type // Color GetTextColor(LingTreeTree Tree) { if (Type == NodeType.NonTerminal) { return Tree.NTColor; } else if (Type == NodeType.Lex) { return Tree.LexColor; } else if (Type == NodeType.Gloss) { return Tree.GlossColor; } else // should never happen, but... { return Tree.NTColor; } }
public void SVGCreate(LingTreeTree Tree, StringBuilder sb, string sLineColor, double dLineWidth) { LingTreeNode Node; Font font = GetTextFont(Tree); Color clr = GetTextColor(Tree); // Draw this node if (Tree.ShowFlatView) { // adjust lex and gloss Y coordinates if (Type == NodeType.Lex) { YCoord = Tree.LexBottomYCoord; YUpperMid = Tree.LexBottomYUpperMid; } if (Type == NodeType.Gloss) { YCoord = Tree.GlossBottomYCoord; } } string sClrName = LingTreeNode.SVGConvertColorToSVGColorString(clr); SVGDrawString(Content, sb, font, sClrName); // Draw daughter nodes Node = Daughter; while (Node != null) { Node.SVGCreate(Tree, sb, sLineColor, dLineWidth); if (Type == NodeType.NonTerminal) { if (!Node.Triangle) { if (!Node.OmitLine) { SVGDrawLine(sb, sLineColor, dLineWidth, Node.XMid, Node.YUpperMid, XMid, YLowerMid); } } else { #if DoTrace Console.WriteLine("\tDrawing triangle: Node = {0},\tXCoord = {1}", Node.Content, Node.XCoord); #endif int ix = Node.XCoord + m_iTriangleOffset; Point[] apt = {new Point(ix, Node.YCoord), new Point(XMid, YLowerMid), new Point(ix + (Node.Width - 2 * m_iTriangleOffset), Node.YCoord), new Point(ix, Node.YCoord)}; SVGDrawLines(sb, sLineColor, dLineWidth, apt); } } Node = Node.Sister; } }
/// <summary> /// Determine the Y-axis coordinate for this node /// </summary> /// <param name="iVerticalOffset">vertical offset up to this node</param> /// <param name="Tree">the tree itself</param> /// <param name="grfx">grpahics info</param> public void CalculateYCoordinate(int iVerticalOffset, LingTreeTree Tree, Graphics grfx) { LingTreeNode Node; // Determine Y-axis coordinates for this node YCoord = iVerticalOffset; YLowerMid = YCoord + Height + m_iYCoordAdjustment; YUpperMid = YCoord - m_iYCoordAdjustment; if (YLowerMid > Tree.YSize) Tree.YSize = YLowerMid; // Keep track of total height for scrolling if (Type == NodeType.Lex) { // keep track of lowest for "flat" view if (YCoord > Tree.LexBottomYCoord) Tree.LexBottomYCoord = YCoord; if (YUpperMid > Tree.LexBottomYUpperMid) Tree.LexBottomYUpperMid = YUpperMid; } if (Type == NodeType.Gloss) { // keep track of lowest for "flat" view if (YCoord > Tree.GlossBottomYCoord) Tree.GlossBottomYCoord = YCoord; } // Determine Y-axis coordinate for any daughters Node = Daughter; while (Node != null) { int iDaughterYCoordinate = YCoord + Tree.GetMaxLevelHeight(Level); if (Node.Type != NodeType.Gloss) iDaughterYCoordinate += Tree.VerticalGap; else iDaughterYCoordinate += Tree.LexGlossGapAdjustment; Node.CalculateYCoordinate(iDaughterYCoordinate, Tree, grfx); Node = Node.Sister; } }
/////////////////////////////////////////////////////////////////////////////// // NAME // Draw // ARGUMENTS // pTree - pointer to tree this node is in // pDC - pointer to a device context // DESCRIPTION // Draw this node and all subnodes // RETURN VALUE // none // public void Draw(LingTreeTree Tree, Graphics grfx, Color color, double dLineWidth) { LingTreeNode Node; Pen pen = new Pen(color, (float)dLineWidth); Font font = GetTextFont(Tree); Color clr = GetTextColor(Tree); SolidBrush brush = new SolidBrush(clr); // Draw this node if (Tree.ShowFlatView) { // adjust lex and gloss Y coordinates if (Type == NodeType.Lex) { YCoord = Tree.LexBottomYCoord; YUpperMid = Tree.LexBottomYUpperMid; } if (Type == NodeType.Gloss) { YCoord = Tree.GlossBottomYCoord; } } DrawString(Content, grfx, font, brush); // Draw daughter nodes Node = Daughter; while (Node != null) { Node.Draw(Tree, grfx, color, dLineWidth); if (Type == NodeType.NonTerminal) { if (Tree.TrySmoothing && // when smoothing, set smoothing values (((Node.XMid != XMid) && // when have slanted lines or (Node.YUpperMid != YLowerMid)) || Node.Triangle)) // when are doing a triangle (which will have slanted lines) { grfx.SmoothingMode = SmoothingMode.HighQuality; if (Tree.TryPixelOffset) { grfx.PixelOffsetMode = PixelOffsetMode.HighQuality; } else { grfx.PixelOffsetMode = PixelOffsetMode.None; } } else { grfx.SmoothingMode = SmoothingMode.None; grfx.PixelOffsetMode = PixelOffsetMode.None; } if (!Node.Triangle) { if (!Node.OmitLine) { grfx.DrawLine(pen, Node.XMid, Node.YUpperMid, XMid, YLowerMid); } } else { #if DoTrace Console.WriteLine("\tDrawing triangle: Node = {0},\tXCoord = {1}", Node.Content, Node.XCoord); #endif int ix = Node.XCoord + m_iTriangleOffset; Point[] apt = { new Point(ix, Node.YCoord), new Point(XMid, YLowerMid), new Point(ix + (Node.Width - 2 * m_iTriangleOffset), Node.YCoord), new Point(ix, Node.YCoord) }; grfx.DrawLines(pen, apt); } } Node = Node.Sister; } pen.Dispose(); brush.Dispose(); }
/////////////////////////////////////////////////////////////////////////////// // NAME // CalculateXCoordinate // ARGUMENTS // pTree - pointer to tree this node is in // pDC - pointer to the device context // iMaxColWidth - maximum width of the current column // DESCRIPTION // Determine the X-axis coordinate for this node // It assumes that the width of this and all other nodes have // already been established. // It also assumes that higher branching nodes are not wider than the // total width of their daughters (which may not always be true...) // RETURN VALUE // The X-axis coordinate at the mid-point of this node // public int CalculateXCoordinate(LingTreeTree Tree, Graphics grfx, int iMaxColWidth) { XMid = 0; // Determine the width for this node CalculateWidth(Tree, grfx); if (Daughter != null) { // is a non-terminal node LingTreeNode NextDaughter = Daughter.Sister; if (NextDaughter != null) { // node branches if (iMaxColWidth < m_iWidth) { iMaxColWidth = m_iWidth; // remember widest node in the column } } else { // only one daughter, so could be in a column if (iMaxColWidth < Width) { iMaxColWidth = Width; // remember widest node in the column } } int iLeftMost = Daughter.CalculateXCoordinate(Tree, grfx, iMaxColWidth); int iRightMost = iLeftMost; while (NextDaughter != null) { // calculate coordinates for other daughters iRightMost = NextDaughter.CalculateXCoordinate(Tree, grfx, iMaxColWidth); NextDaughter = NextDaughter.Sister; } // take mid point between first & last daughter XMid = (iLeftMost + iRightMost) / 2; if (iRightMost > iLeftMost) { if (m_iWidth > (iRightMost - iLeftMost)) { int iAdjust = (m_iWidth - (iRightMost - iLeftMost)) / 2; m_iXMid += iAdjust; NextDaughter = Daughter; while (NextDaughter != null) { NextDaughter.AdjustXValues(Tree, iAdjust); NextDaughter = NextDaughter.Sister; } } } } else { // is a terminal node if (iMaxColWidth < Width) { iMaxColWidth = Width; // this might be the widest node in the column } XMid = (int)Tree.HorizontalOffset + // Offset from last terminal node plus iMaxColWidth / 2; // half the width of this column Tree.HorizontalOffset = XMid + // have a new offset for next terminal node Tree.HorizontalGap + // gap between terminal nodes plus iMaxColWidth / 2; // half the width of the widest node in this column } XCoord = XMid - Width / 2; // adjust for width of this node int iEnd = XCoord + Width; if (Triangle) { iEnd += Tree.HorizontalGap / 2; } if (iEnd > Tree.XSize) { Tree.XSize = iEnd; // Keep track of total width for scrolling } #if DoTrace Console.WriteLine("{0}\tXSize = {1},\tWidth = {2},\tXCoord = {3},\tYCoord = {4}, \tXMid = {4}", Content, Tree.XSize, Width, XCoord, YCoord, XMid); #endif return(XMid); }
/////////////////////////////////////////////////////////////////////////////// // NAME // Draw // ARGUMENTS // pTree - pointer to tree this node is in // pDC - pointer to a device context // DESCRIPTION // Draw this node and all subnodes // RETURN VALUE // none // public void Draw(LingTreeTree Tree, Graphics grfx, Color color, double dLineWidth) { LingTreeNode Node; Pen pen = new Pen(color, (float) dLineWidth); Font font = GetTextFont(Tree); Color clr = GetTextColor(Tree); SolidBrush brush = new SolidBrush(clr); // Draw this node if (Tree.ShowFlatView) { // adjust lex and gloss Y coordinates if (Type == NodeType.Lex) { YCoord = Tree.LexBottomYCoord; YUpperMid = Tree.LexBottomYUpperMid; } if (Type == NodeType.Gloss) { YCoord = Tree.GlossBottomYCoord; } } DrawString(Content, grfx, font, brush); // Draw daughter nodes Node = Daughter; while (Node != null) { Node.Draw(Tree, grfx, color, dLineWidth); if (Type == NodeType.NonTerminal) { if (Tree.TrySmoothing && // when smoothing, set smoothing values ( ((Node.XMid != XMid) && // when have slanted lines or (Node.YUpperMid != YLowerMid)) || Node.Triangle) ) // when are doing a triangle (which will have slanted lines) { grfx.SmoothingMode = SmoothingMode.HighQuality; if (Tree.TryPixelOffset) grfx.PixelOffsetMode = PixelOffsetMode.HighQuality; else grfx.PixelOffsetMode = PixelOffsetMode.None; } else { grfx.SmoothingMode = SmoothingMode.None; grfx.PixelOffsetMode = PixelOffsetMode.None; } if (!Node.Triangle) { if (!Node.OmitLine) { grfx.DrawLine(pen, Node.XMid, Node.YUpperMid, XMid, YLowerMid); } } else { #if DoTrace Console.WriteLine("\tDrawing triangle: Node = {0},\tXCoord = {1}", Node.Content, Node.XCoord); #endif int ix = Node.XCoord + m_iTriangleOffset; Point[] apt = {new Point(ix, Node.YCoord), new Point(XMid, YLowerMid), new Point(ix + (Node.Width - 2 * m_iTriangleOffset), Node.YCoord), new Point(ix, Node.YCoord)}; grfx.DrawLines(pen, apt); } } Node = Node.Sister; } pen.Dispose(); brush.Dispose(); }
private void InitPcPatrBrowser(string sStartupPath) { m_sStartUpPath = sStartupPath; // Create temp files for Feature structure info and Interlinear m_sFSFile = Path.GetTempFileName(); m_sInterFile = Path.GetTempFileName(); // // Required for Windows Form Designer support // InitializeComponent(); richTextBox1.Text = m_ksGrammarMessage; InitToolBar(); InitStatusBar(); InitMenuItems(); pnlTreeFeat.Controls.Add(pnlTree); pnlTreeFeat.Controls.Add(splitterBetweenTreeAndFeat); pnlTreeFeat.Controls.Add(pnlFeatureStructure); pnlTreeFeat.BorderStyle = BorderStyle.Fixed3D; pnlTree.Paint += new PaintEventHandler(TreePanelOnPaint); m_tree = new LingTreeTree(); m_tree.m_LingTreeNodeClickedEvent += new LingTreeNodeClickedEventHandler(OnNodeClicked); pnlTree.Controls.Add(m_tree); m_treeTransform = new XslCompiledTransform(); m_treeTransform.Load(Path.Combine(sStartupPath, @"..\..\Transforms\PcPatrToLingTree.xsl")); m_fsTransform = new XslCompiledTransform(); m_fsTransform.Load(Path.Combine(m_sStartUpPath, @"..\..\Transforms\ShowFS.xsl")); m_interlinearTransform = new XslCompiledTransform(); m_interlinearTransform.Load(Path.Combine(sStartupPath, @"..\..\Transforms\ShowInterlinear.xsl")); InitInterlinearBrowser(); InitFeatureStructureBrowser(); InitLanguageInfo(); EnableDisableItems(); SetTitle(); // set position on screen m_RectNormal = DesktopBounds; m_fNeedToSaveLanguageInfo = false; }
public LingTreeApp(string strInitFileName) { BackColor = SystemColors.Window; if (BackColor.ToArgb() == 0) BackColor = Color.White; if (m_clrTreeBackgroundColor.ToArgb() == 0) m_clrTreeBackgroundColor = Color.White; ForeColor = SystemColors.WindowText; ResizeRedraw = true; try { RegistryKey regkey = Registry.CurrentUser.OpenSubKey(m_strRegKey); if (regkey != null) { retrieveRegistryInfo(regkey); regkey.Close(); } } catch { } // Allow handling of user closing the form this.Closing += new CancelEventHandler(LingTreeAppOnClosing); // // Required for Windows Form Designer support // InitializeComponent(); pnlForTree = new Panel(); pnlForTree.Parent = this; pnlForTree.Dock = DockStyle.Fill; pnlForTree.AutoScroll = true; #if TreeNotControl pnlTree = new Panel(); pnlTree.Parent = pnlForTree; pnlTree.Dock = DockStyle.None; pnlTree.AutoScroll = true; pnlTree.Paint += new PaintEventHandler(TreePanelOnPaint); pnlTree.Size = new Size(10, 10); // give it an initial size pnlTree.Location = new Point(0, 0); #else pnlForTree.Paint += new PaintEventHandler(TreePanelOnPaint); #endif Splitter split = new Splitter(); split.Parent = this; split.Dock = DockStyle.Top; split.BackColor = SystemColors.ScrollBar; rtbTreeDescription = new RichTextBox(); rtbTreeDescription.Parent = this; rtbTreeDescription.Dock = DockStyle.Top; rtbTreeDescription.Height = m_iDescriptionBoxHeight; rtbTreeDescription.BorderStyle = BorderStyle.Fixed3D; rtbTreeDescription.KeyUp += new KeyEventHandler(DescriptionOnKeyUp); rtbTreeDescription.TextChanged += new EventHandler(DescriptionOnTextChanged); InitMenu(); InitToolBar(); InitStatusBar(); AutoScroll = true; // create the tree with all the right parameters tree = new LingTreeTree(Application.ProductVersion); tree.GlossColor = Color.Green; tree.NTColor = Color.Red; tree.LexColor = Color.Blue; #if !TreeNotControl tree.Parent = pnlForTree; // tree.Paint += new PaintEventHandler(TreePanelOnPaint); tree.m_LingTreeNodeClickedEvent += new LingTreeNodeClickedEventHandler(OnNodeClicked); pnlForTree.Controls.Add(tree); #endif if (strInitFileName != null) { m_strTreeFile = strInitFileName; } if (File.Exists(m_strTreeFile)) { loadTree(); rtbTreeDescription.Text = tree.Description; ParseTreeDescription(); setFontsInTreeDescription(); #if !TryToFixSVGColors CreateSVG(); #else m_strSVG = tree.CreateSVG(CreateGraphics(), m_clrTreeLinesColor.Name); #endif } else { if ((strInitFileName != null) && (DialogResult.OK == MessageBox.Show(m_strTreeFile + " could not be found! Please navigate to where it is located or click on Cancel to start a new tree description.", "Initial File Not Found!", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation))) { MenuFileOpenOnClick(null, null); } else { rtbTreeDescription.Text = m_strNewDescriptionMessage; rtbTreeDescription.SelectAll(); } } setIsDirty(false); // also allocate the temporary/work RichTextBox rtbTemp = new RichTextBox(); // set position on screen m_RectNormal = DesktopBounds; }
/////////////////////////////////////////////////////////////////////////////// // NAME // GetTextFont // ARGUMENTS // Tree - tree this node is in // DESCRIPTION // Set font for this node // RETURN VALUE // font of the node type // Font GetTextFont(LingTreeTree Tree) { if (Type == NodeType.NonTerminal) { return Tree.NTFont; } else if (Type == NodeType.Lex) { return Tree.LexFont; } else if (Type == NodeType.Gloss) { return Tree.GlossFont; } else // should never happen, but... { return Tree.NTFont; } }
public void Detach() { // Detach the events and delete the form tree.m_LingTreeNodeClickedEvent += new LingTreeNodeClickedEventHandler(OnNodeClicked); tree = null; }