예제 #1
0
        /// <summary>
        /// Opens the json.
        /// </summary>
        /// <param name="objects">The objects.</param>
        public void OpenJson(List <JsonObject> objects)
        {
            List <KeyValuePair <int, Control> > ctrls = new List <KeyValuePair <int, Control> >();

            foreach (JsonObject obj in objects)
            {
                if (obj is Config)
                {
                    Config config = obj as Config;
                    Enum.TryParse <Paper>(config.Paper, out Paper paper);
                    Enum.TryParse <ColorType>(config.Color, out ColorType color);
                    Enum.TryParse <Sticky>(config.Sticky, out Sticky sticky);

                    (this.Parent as NemonicForm).ChangePaper(paper);
                    (this.Parent as NemonicForm).ChangeColor(color);
                    this.ChangeSticky(paper, sticky);
                }
                else if (obj is TemplateLayer)
                {
                    TemplateLayer layer = obj as TemplateLayer;
                    this.ChangeTemplate(NemonicApp.ByteToImage(layer.image));
                }
                else if (obj is TransparentImage.ImageLayer)
                {
                    TransparentImage.ImageLayer layer = obj as TransparentImage.ImageLayer;

                    TransparentImage imageBox = new TransparentImage()
                    {
                        Location = new Point(layer.x, layer.y),
                        Image    = NemonicApp.ByteToImage(layer.image),
                        Size     = new Size(layer.width, layer.height)
                    };

                    ctrls.Add(new KeyValuePair <int, Control>(layer.priority, imageBox));
                }
                else if (obj is TransparentRichText.RichTextLayer)
                {
                    TransparentRichText.RichTextLayer layer = obj as TransparentRichText.RichTextLayer;
                    this.Layer_TextField.Font = layer.font;
                    this.Layer_TextField.SelectAll();
                    this.Layer_TextField.SelectionAlignment = layer.align;
                    this.Layer_TextField.DeselectAll();
                    this.Layer_TextField.Text = layer.text;
                }
            }

            ctrls.Sort(delegate(KeyValuePair <int, Control> A, KeyValuePair <int, Control> B)
            {
                return(B.Key.CompareTo(A.Key));
            });

            foreach (KeyValuePair <int, Control> element in ctrls)
            {
                this.AddCtrl(element.Value);
            }
        }
예제 #2
0
        //TODO: Json File 정보를 조합하여, 이미지를 만들어 반영해야 한다.
        public MemoElement(TabCtrl control, string path, Action hide) : base(control, path)
        {
            InitializeComponent();

            this.Item              = Button_Memo;
            this.Item.DoubleClick += Item_DoubleClick;
            this.Item.KeyDown     += Item_KeyDown;

            this.Title      = Label_Title;
            this.Title.Text = Path.GetFileNameWithoutExtension(this.RootPath);

            //Json 파일에서 Image 파일을 생성하는 과정

            //바쁜 대기라, 매우 나쁜 코드지만 더 나은 코드가 생각나지 않는다.
            bool   isReady = false;
            string json    = string.Empty;

            while (!isReady)
            {
                try
                {
                    json    = File.ReadAllText(this.RootPath);
                    isReady = true;
                }
                catch (Exception e)
                {
                    Console.WriteLine("Busy Wait Error!\n\t" + e.StackTrace);
                    //isReady = false;
                }
            }
            //Json 정보 해석
            JsonSerializerSettings settings = new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.All
            };
            List <JsonObject> objects = JsonConvert.DeserializeObject <List <JsonObject> >(json, settings);

            foreach (JsonObject obj in objects)
            {
                if (obj is Thumbnail)
                {
                    //Thumbnail 정보를 찾아, Element의 이미지로 세팅
                    Thumbnail thumbnail = obj as Thumbnail;
                    this.Item.BackgroundImage       = NemonicApp.ByteToImage(thumbnail.image);
                    this.Item.BackgroundImageLayout = ImageLayout.Zoom;
                }
            }

            this.HideSettings = hide;
        }