Ejemplo n.º 1
0
        /// <summary>Loads the image from the given file</summary>
        /// <param name="filename">The file to load from</param>
        public void LoadFromFile(String filename)
        {
            XmlTextReader reader = null;
            try
            {
                // Open the file
                reader = new XmlTextReader(filename);

                // Read to the root and determine the file version
                int version = 0;
                while(reader.Read())
                {
                    if(reader.NodeType == XmlNodeType.Element && reader.Name == "schets")
                    {
                        // Determine the version
                        while(reader.MoveToNextAttribute())
                        {
                            if(reader.Name == "version")
                            {
                                try
                                {
                                    version = reader.ReadContentAsInt();
                                    break;
                                }
                                catch(Exception)
                                { throw new Exception("De versie lijkt in een verkeerd formaat te staan."); }
                            }
                        }

                        break;
                    }
                }

                if(version != 1)
                    throw new Exception("Foutieve bestandsversie: " + version + ".");

                // Read the layers
                try
                {
                    layers.Clear();
                    while (reader.Read())
                    {
                        if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "schets")
                            break;
                        else if (reader.NodeType == XmlNodeType.Element && reader.Name.StartsWith("layer"))
                        {
                            // Determine the layer type
                            Layer layer = null;
                            switch (reader.Name)
                            {
                                case LayerText.XML_NAME:
                                    layer = new LayerText(new Point(0, 0), Color.Black, "");
                                    break;

                                case LayerLine.XML_NAME:
                                    layer = new LayerLine(new Point(0, 0), new Point(1, 1), 3.0f, Color.Black);
                                    break;

                                case LayerRectFilled.XML_NAME:
                                    layer = new LayerRectFilled(new Point(0, 0), new Point(1, 1), Color.Black);
                                    break;

                                case LayerRectOpen.XML_NAME:
                                    layer = new LayerRectOpen(new Point(0, 0), new Point(1, 1), 3.0f, Color.Black);
                                    break;

                                case LayerEllipseFilled.XML_NAME:
                                    layer = new LayerEllipseFilled(new Point(0, 0), new Point(1, 1), Color.Black);
                                    break;

                                case LayerEllipseOpen.XML_NAME:
                                    layer = new LayerEllipseOpen(new Point(0, 0), new Point(1, 1), 3.0f, Color.Black);
                                    break;

                                case LayerPath.XML_NAME:
                                    layer = new LayerPath(new Point(0, 0), 3.0f, Color.Black);
                                    break;

                                case LayerBitmap.XML_NAME:
                                    layer = new LayerBitmap(new Point(0, 0), new Bitmap(1,1));
                                    break;
                            }

                            // Read the actual layer contents
                            if (layer != null)
                            {
                                layer.ReadFromXml(reader);
                                layers.Add(layer);
                            }
                        }
                        else throw new Exception(reader.Name);
                    }
                }
                catch(XmlException e)
                { throw new Exception(e.Message); }
                catch(Exception e)
                { throw new Exception("Er is een onverwachte fout opgetreden! Foutmelding: " + e.Message); }
            }
            catch(UnauthorizedAccessException)
            { throw new Exception("U heeft niet de juiste rechten om het bestand te openen voor lezen."); }
            catch(System.IO.DirectoryNotFoundException)
            { throw new Exception("Kon het bestand niet vinden."); }
            finally
            {
                // Close the file
                reader.Close();
            }
        }
Ejemplo n.º 2
0
 public override void Letter(SchetsControl s, char c)
 {
     if (c >= 32)
     {
         // If we're editting a layer, add the character to the layer
         // if we're not editting a layer, we create a new text layer containing the character
         if(edittingLayer == null)
         {
             s.Schets.Layers.Add(edittingLayer = new LayerText(this.startpunt, color, new String(c, 1)));
             ((LayerText) edittingLayer).Editting = true;
         }
         else
             ((LayerText) edittingLayer).Text += c;
         s.Invalidate();
     }
     else if(c == '\b' && edittingLayer != null && ((LayerText) edittingLayer).Text.Length > 0)
     {
         // If the user pressed backspace
         ((LayerText)edittingLayer).Text = ((LayerText)edittingLayer).Text.Substring(0, ((LayerText)edittingLayer).Text.Length - 1);
         s.Invalidate();
     }
 }