Beispiel #1
0
 private void AppendActionCursor(StringBuilder builder)
 {
     if (_widgetStyle.OwnerWidget.Events[EventType.OnClick] != null)
     {
         foreach (IInteractionCase interactionCase in _widgetStyle.OwnerWidget.Events[EventType.OnClick].Cases)
         {
             foreach (IInteractionAction action in interactionCase.Actions)
             {
                 if (action.ActionType == ActionType.OpenAction)
                 {
                     IInteractionOpenAction openAction = action as IInteractionOpenAction;
                     if (openAction != null && openAction.LinkType != LinkType.None)
                     {
                         builder.Append("\"cursor\":\"pointer\",");
                     }
                 }
                 else if (action.ActionType == ActionType.CloseAction)
                 {
                     builder.Append("\"cursor\":\"pointer\",");
                 }
                 else if (action.ActionType == ActionType.ShowHideAction)
                 {
                     IInteractionShowHideAction showAction = action as IInteractionShowHideAction;
                     if (showAction != null && showAction.TargetObjects.Count > 0)
                     {
                         // Only check the first item as all targets has the same setting for now.
                         IShowHideActionTarget target = showAction.TargetObjects[0];
                         if (target != null && target.VisibilityType != VisibilityType.None)
                         {
                             builder.Append("\"cursor\":\"pointer\",");
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #2
0
        public override string ToString()
        {
            StringBuilder builder = new StringBuilder();

            switch (_action.ActionType)
            {
            case ActionType.OpenAction:
            {
                IInteractionOpenAction openAction = _action as IInteractionOpenAction;
                if (openAction == null || openAction.LinkType == LinkType.None)
                {
                    return("");
                }

                builder.Append("{");
                builder.AppendFormat("\"action\":\"{0}\",", GetJsAction(_action.ActionType));

                if (openAction.LinkType == LinkType.LinkToPage)
                {
                    // http://bts1.navercorp.com/nhnbts/browse/DSTUDIO-2061
                    // If action is "Link to a page", I will always set "target" to  "openCurrentWindow" in js action.
                    builder.AppendFormat("\"target\":\"{0}\",", GetJsTarget(ActionOpenIn.CurrentWindow));

                    if (_service.RenderingDocument.Pages.Contains(openAction.LinkPageGuid))
                    {
                        builder.AppendFormat("\"url\":\"{0}\",", openAction.LinkPageGuid.ToString());
                    }
                }
                else if (openAction.LinkType == LinkType.LinkToUrl)
                {
                    builder.AppendFormat("\"target\":\"{0}\",", GetJsTarget(openAction.OpenIn));

                    if (!String.IsNullOrEmpty(openAction.ExternalUrl))
                    {
                        // Add http so that browser could know this is a external url
                        string url = openAction.ExternalUrl;
                        if (!url.StartsWith(@"http://"))
                        {
                            url = @"http://" + url;
                        }
                        builder.AppendFormat("\"url\":\"{0}\",", url);
                    }
                }

                JsHelper.RemoveLastComma(builder);
                builder.Append("}");
                break;
            }

            case ActionType.ShowHideAction:
            {
                IInteractionShowHideAction showHideAction = _action as IInteractionShowHideAction;
                if (showHideAction == null || showHideAction.TargetObjects.Count <= 0)
                {
                    return("");
                }

                // If all target objects VisibilityType is none, we don't issue action as well
                IShowHideActionTarget firstTarget = showHideAction.TargetObjects.FirstOrDefault <IShowHideActionTarget>(x => x.VisibilityType != VisibilityType.None);
                if (firstTarget == null)
                {
                    return("");
                }

                builder.Append("{");

                builder.AppendFormat("\"action\":\"{0}\",", GetJsAction(_action.ActionType));

                builder.Append("\"objectList\":[");
                foreach (IShowHideActionTarget target in showHideAction.TargetObjects)
                {
                    builder.Append("{");

                    builder.AppendFormat("\"id\":\"{0}\",", target.Guid.ToString());
                    builder.AppendFormat("\"type\":\"{0}\",", target.VisibilityType.ToString());
                    builder.AppendFormat("\"animateType\":\"{0}\",", target.AnimateType.ToString());
                    builder.AppendFormat("\"animateTime\":{0},", target.AnimateTime);

                    builder.Append("},");
                }

                JsHelper.RemoveLastComma(builder);
                builder.Append("]");

                builder.Append("}");
                break;
            }

            default:
                return("");
            }

            return(builder.ToString());
        }
Beispiel #3
0
        protected override void RunInternal()
        {
            Program.Service.NewDocument(DocumentType.Standard);
            IDocument document = Program.Service.Document;

            IMasterPage masterPage     = document.CreateMasterPage("Master 1");
            ITreeNode   masterPageNode = document.DocumentSettings.LayoutSetting.MasterPageTree.AddChild(TreeNodeType.MasterPage);

            masterPageNode.AttachedObject = masterPage;
            masterPage.Open();
            IPageView masterBaseView = masterPage.PageViews[document.AdaptiveViewSet.Base.Guid];

            IButton button = masterBaseView.CreateWidget(WidgetType.Button) as IButton;

            button.Annotation.SetTextValue("CreatedTime", DateTime.Now.ToString());

            // Size
            button.WidgetStyle.Height = 30;
            button.WidgetStyle.Width  = 100;

            // Location
            button.WidgetStyle.X = 0;
            button.WidgetStyle.Y = 0;
            button.WidgetStyle.Z = 0;

            // Text things
            button.Name    = "Button 1";
            button.Text    = "Button";
            button.Tooltip = "Html button.";

            IImage image = masterBaseView.CreateWidget(WidgetType.Image) as IImage;

            image.Annotation.SetTextValue("CreatedTime", DateTime.Now.ToString());
            image.WidgetStyle.Height = 267;
            image.WidgetStyle.Width  = 116;
            image.WidgetStyle.X      = 150;
            image.WidgetStyle.Y      = 100;
            image.WidgetStyle.Z      = 5;
            image.Name    = "4.png";
            image.Tooltip = "A png image has 116 x 267 in size";

            // It is a png image by default. Set image stream
            string imageFile = Path.Combine(Program.WORKING_IMAGES_DIRECTORY, "HangGame", "4.png");

            if (File.Exists(imageFile))
            {
                using (FileStream fileStream = new FileStream(imageFile, FileMode.Open, FileAccess.Read))
                {
                    MemoryStream imageStream = new MemoryStream();
                    fileStream.CopyTo(imageStream);
                    image.ImageStream = imageStream;
                }
            }

            IShape lable = masterBaseView.CreateWidget(WidgetType.Shape) as IShape;

            lable.ShapeType = ShapeType.Paragraph;
            lable.Annotation.SetTextValue("CreatedTime", DateTime.Now.ToString());
            lable.WidgetStyle.Height = 100;
            lable.WidgetStyle.Width  = 200;
            lable.WidgetStyle.X      = 350;
            lable.WidgetStyle.Y      = 300;
            lable.WidgetStyle.Z      = 9;
            lable.Name    = "Label 1";
            lable.Tooltip = "A label.";
            lable.SetRichText("Label");

            List <Guid> guidList = new List <Guid>();

            guidList.Add(image.Guid);
            guidList.Add(lable.Guid);
            masterBaseView.CreateGroup(guidList);

            IDocumentPage page     = document.CreatePage("Page 1");
            ITreeNode     pageNode = document.DocumentSettings.LayoutSetting.PageTree.AddChild(TreeNodeType.Page);

            pageNode.AttachedObject = page;
            page.Open();
            IPageView baseView = page.PageViews[document.AdaptiveViewSet.Base.Guid];

            IMaster master = baseView.CreateMaster(masterPage.Guid);

            IShape triangle = baseView.CreateWidget(WidgetType.Shape) as IShape;

            triangle.ShapeType = ShapeType.Triangle;
            triangle.Annotation.SetTextValue("CreatedTime", DateTime.Now.ToString());
            triangle.WidgetStyle.Height = 100;
            triangle.WidgetStyle.Width  = 100;
            triangle.WidgetStyle.X      = 650;
            triangle.WidgetStyle.Y      = 300;
            triangle.WidgetStyle.Z      = 11;
            triangle.Name    = "Triangle_Show_Hide";
            triangle.Tooltip = "A Triangle to triger Show or Hide.";
            triangle.SetRichText("Triangle_Show_Hide");

            IInteractionEvent          iEvent = triangle.Events[EventType.OnClick];
            IInteractionCase           iCase  = iEvent.CreateCase("clickCase");
            IInteractionShowHideAction action = iCase.CreateAction(ActionType.ShowHideAction) as IInteractionShowHideAction;

            action.AddTargetObject(master.Guid);
            action.SetAllVisibilityType(VisibilityType.Toggle);
            action.SetAllAnimateType(ShowHideAnimateType.SlideRight);
            action.SetAllAnimateTime(500);

            ISerializeWriter writer = document.CreateSerializeWriter(document.AdaptiveViewSet.Base.Guid);

            writer.AddWidget(triangle);
            writer.AddMaster(master);
            Stream stream = writer.WriteToStream();

            // Create another document
            DocumentService Service = new DocumentService();

            Service.NewDocument(DocumentType.Standard);
            IDocument document2 = Service.Document;

            IDocumentPage page2     = document2.CreatePage("Page 1");
            ITreeNode     pageNode2 = document2.DocumentSettings.LayoutSetting.PageTree.AddChild(TreeNodeType.Page);

            pageNode2.AttachedObject = page2;
            page2.Open();
            IPageView baseView2 = page2.PageViews[document2.AdaptiveViewSet.Base.Guid];

            baseView2.AddObjects(stream);

            string target = Path.Combine(Program.WORKING_DIRECTORY, _caseName + "_Target.pn");

            Service.Save(target);
            Service.Close();

            string source = Path.Combine(Program.WORKING_DIRECTORY, _caseName + "_Source.pn");

            Program.Service.Save(source);
            Program.Service.Close();
        }