private static void UpdateAnchors(ElementWindow elementWindow, List <IElement> elements) { ElementDescriptor mainDescriptor = elementWindow.ElementDescriptor; foreach (IElement element in elements) { ElementDescriptor elementDescriptor = element.ElementDescriptor; FrameworkElement control = (FrameworkElement)element; if (elementDescriptor.Anchor1.HasValue) { System.Drawing.Point elementPos = elementDescriptor.Pos.GetValueOrDefault(); System.Drawing.Size windowSize = mainDescriptor.Size.GetValueOrDefault(); double offset1X = elementPos.X - (windowSize.Width * elementDescriptor.Anchor1.Value.X / 100); double offset1Y = elementPos.Y - (windowSize.Height * elementDescriptor.Anchor1.Value.Y / 100); double left = (elementWindow.ActualWidth * elementDescriptor.Anchor1.Value.X / 100) + offset1X; double top = (elementWindow.ActualHeight * elementDescriptor.Anchor1.Value.Y / 100) + offset1Y; Canvas.SetLeft(control, left); Canvas.SetTop(control, top); if (elementDescriptor.Anchor2.HasValue) { System.Drawing.Size elementSize = elementDescriptor.Size.GetValueOrDefault(); double offset2X = (elementPos.X + elementSize.Width) - (windowSize.Width * elementDescriptor.Anchor2.Value.X / 100); double offset2Y = (elementPos.Y + elementSize.Height) - (windowSize.Height * elementDescriptor.Anchor2.Value.Y / 100); control.Width = (elementWindow.ActualWidth * elementDescriptor.Anchor2.Value.X / 100) + offset2X - left; control.Height = (elementWindow.ActualHeight * elementDescriptor.Anchor2.Value.Y / 100) + offset2Y - top; } } } }
// public override DrawElement CreateControl() { ElementWindow obj = new ElementWindow(); //ElementPropertyWindow prop = new ElementPropertyWindow(); //prop.InitDefaultProperty(); //prop.InitPropertyMap(); obj.Text = "Window"; obj.Location = new Point(0, 0); obj.Width = 550; // Get From Prop obj.Height = 400; //Get From Prop obj.CreateControlButton(); //obj.Property = prop; Image img = FactroryImage.getInstance().getImage(IMAGES.ControlBox_png); obj.ListImage.Add(img); Add(obj); //m_Property = prop; base.CreateControl(); return(obj); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public static bool CheckIfProcessExists(BaseNetwork network, NetworkElement networkElement, Attribute parentAttribute, Attribute attribute, string newValue, out string errorMessage, ElementWindow inputWindow = null) /// /// \brief Determine if process exists. /// /// \par Description. /// - This method is activated by the GUI after a value in one of the target processors /// for the message was changed. /// - The method checks whether there is a process with id equals to the new value in the network /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 09/05/2018 /// /// \param network (BaseNetwork) - The network. /// \param networkElement (NetworkElement) - The network element. /// \param parentAttribute (Attribute) - The parent attribute. /// \param attribute (Attribute) - The attribute. /// \param newValue (string) - The new value. /// \param [out] errorMessage (out string) - Message describing the error. /// \param inputWindow (Optional) (ElementWindow) - The input window. /// /// \return True if it succeeds, false if it fails. //////////////////////////////////////////////////////////////////////////////////////////////////// public static bool CheckIfProcessExists(BaseNetwork network, NetworkElement networkElement, Attribute parentAttribute, Attribute attribute, string newValue, out string errorMessage, ElementWindow inputWindow = null) { errorMessage = ""; try { errorMessage = "The value has to be int"; int id = int.Parse(newValue); errorMessage = "There is no processor with id :" + newValue; network.Processes.First(p => p.ea[ne.eak.Id] == id); errorMessage = ""; return(true); } catch { return(false); } }
public static ElementWindow CreateWindowFromDescriptor(WindowDescriptor windowDescriptor) { ElementDescriptorMain mainDescriptor = windowDescriptor.MainElementDescriptor; ElementWindow elementWindow = new ElementWindow(); List <IElement> elements = new List <IElement>(); elementWindow.ElementDescriptor = mainDescriptor; foreach (ElementDescriptor elementDescriptor in windowDescriptor.ElementDescriptors) { if (elementDescriptor != mainDescriptor) { try { IElement element = CreateElementFromDescriptor(elementDescriptor); elements.Add(element); elementWindow.Children.Add((UIElement)element); } catch (Exception e) { Console.WriteLine("Error while creating an interface element: " + e.Message); } } } elementWindow.ChildElements = elements.ToArray(); elementWindow.Margin = new Thickness(0, 0, 0, 0); elementWindow.HorizontalAlignment = HorizontalAlignment.Stretch; elementWindow.VerticalAlignment = VerticalAlignment.Stretch; elementWindow.SizeChanged += (object sender, SizeChangedEventArgs e) => UpdateAnchors(elementWindow, elements); return(elementWindow); }
// public void CreateWindow() { FactoryShape factory = FactoryManager.getInstance().GetSelectedTool(); ElementWindow model = (ElementWindow)factory.CreateControl(); m_Window = (ElementWindow)model; model.Container = m_Canvas; bool[] hotSpot = { false, false }; mSceneCanvas.Add(model); ElementProperty prop = FactoryActionParam.CreateParam(model); model.Property = prop; factory.PopulatePropertyList(prop); m_GridView.Tag = prop; m_ActionWindow = new ActionAdd(factory); m_ActionWindow.Model = model; // Assign a copy of Param..... m_ActionWindow.SetParam(prop); mHostory.ExcuteAction(m_ActionWindow); //mSceneCanvas.Canvas.Invalidate(); PopulateControlList(); ElementTracker.Instance.AttachHotSpotObserver(this); //m_Window.PropertyChangeObserver = this; model.OnSizeChanged(); }
private void StartAppWatcher(string elementName, FindWindowMethod method) { windowElement = GetAppElement(elementName, method); // (...) // You may want to to something if the watched application is already running when you start your app Automation.AddAutomationEventHandler(WindowPattern.WindowOpenedEvent, AutomationElement.RootElement, TreeScope.Subtree, (elm, e) => { AutomationElement element = elm as AutomationElement; try { if (element == null || element.Current.ProcessId == currentProcessId) { return; } if (windowElement == null) { windowElement = GetAppElement(elementName, method); } if (windowElement == null || windowElement.ProcessId != element.Current.ProcessId) { return; } // If the Window is a MessageBox generated by the watched app, attach the handler if (element.Current.ClassName == "#32770") { buttonElement = element; var msgBoxButton = element.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "OK")); if (msgBoxButton != null && msgBoxButton.GetSupportedPatterns().Any(p => p.Equals(InvokePattern.Pattern))) { Automation.AddAutomationEventHandler( InvokePattern.InvokedEvent, msgBoxButton, TreeScope.Element, DialogButtonHandler = new AutomationEventHandler(MessageBoxButtonHandler)); } } } catch (ElementNotAvailableException) { // Ignore: this exception may be raised if you show a modal dialog, // in your own app, that blocks the execution. When the dialog is closed, // AutomationElement element is no longer available } }); Automation.AddAutomationEventHandler(WindowPattern.WindowClosedEvent, AutomationElement.RootElement, TreeScope.Subtree, (elm, e) => { AutomationElement element = elm as AutomationElement; if (element == null || element.Current.ProcessId == currentProcessId || windowElement == null) { return; } if (windowElement.ProcessId == element.Current.ProcessId) { if (windowElement.MainWindowTitle == element.Current.Name) { windowElement = null; } } }); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public bool CheckPermition(PermitionTypes permitionType, ElementWindow sender) /// /// \brief Check permition. /// /// \par Description. /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 25/07/2017 /// /// \param permitionType (PermitionTypes) - Type of the permition. /// \param sender (ElementWindow) - The sender. /// /// \return True if it succeeds, false if it fails. //////////////////////////////////////////////////////////////////////////////////////////////////// public bool CheckPermition(PermitionTypes permitionType, ElementWindow sender) { // If the sender is an ElementWindow currently presented the check should be bypasses if (Permissions.IsWindowPresented(sender)) { return(true); } return(permissions[(int)MainWindow.ActivationPhase, (int)permitionType]); }
/// <summary> /// Any UI to be displayed after the scaffolder has been selected from the Add Scaffold dialog. /// Any validation on the input for values in the UI should be completed before returning from this method. /// </summary> /// <returns></returns> public override bool ShowUIAndValidate() { // Bring up the selection dialog and allow user to select a model type ElementWindow window = new ElementWindow(_viewModel); bool? showDialog = window.ShowDialog(); Validate(); return(showDialog ?? false); }
// /// <summary>generates xml for a dialog resource item</summary> /// <param name="dlg"> /// The dialog to be converted</param> /// <param name="vals"> /// String tokens</param> /// <param name="ParentNode"> /// Parent xml node for the menu item.</param> /// /// private void WriteDialog(ElementWindow dlg, XmlElement parentNode) { SetItemAttribs(dlg, parentNode); // write each of the items foreach (DrawElement child in dlg.List) { XmlElement nodeChild = m_XmlDom.CreateElement("", child.Factory.Name, ""); SetItemAttribs(child, nodeChild); parentNode.AppendChild(nodeChild); } }
private void ShowMappingWindow(MappingModel mappingModel) { XmlElement newMapping = mConfiguration.ConfigXml.CreateElement(MappingName); IElementConfiguration elementConfiguration = new ElementConfiguration(mConfiguration, mappingModel.Node, newMapping); ElementWindow elementWindow = new ElementWindow(elementConfiguration, DefinitionFactory.Create(MappingDescriptor.Mapping, elementConfiguration), WindowSizeLocationFactory.Create(MappingDescriptor.Mapping), new AddSaveStrategy <MappingModel>(mappingModel, model => Mappings.Add(model), newMapping)); mMessageBoxService.ShowWindow(elementWindow); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public static bool IsWindowPresented(ElementWindow window) /// /// \brief Query if 'window' is window presented. /// /// \par Description. /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 25/07/2017 /// /// \param window (ElementWindow) - The window. /// /// \return True if window presented, false if not. //////////////////////////////////////////////////////////////////////////////////////////////////// public static bool IsWindowPresented(ElementWindow window) { if (window != null) { foreach (Window w in Application.Current.Windows) { if (w == window) { return(true); } } } return(false); }
private void ShowParamWindow(ParamModel paramModel) { XmlElement newParam = mConfiguration.ConfigXml.CreateElement(ParamDescriptor.Param.ElementName); IElementConfiguration configuration = new ElementConfiguration(mConfiguration, paramModel.Node, newParam); ISaveStrategy saveStrategy = new AddSaveStrategy <ParamModel>(paramModel, AddModel, newParam); Window paramWindow = new ElementWindow(configuration, DefinitionFactory.Create(ParamDescriptor.Param, configuration), WindowSizeLocationFactory.Create(ParamDescriptor.Param), saveStrategy); mMessageBoxService.ShowWindow(paramWindow); }
private void ShowFilterWindow(FilterModel filterModel) { XmlElement newFilter = mConfiguration.ConfigXml.CreateElementWithAttribute("filter", "type", filterModel.Descriptor.TypeNamespace); IElementConfiguration configuration = new ElementConfiguration(mConfiguration, filterModel.Node, newFilter); ISaveStrategy saveStrategy = new AddSaveStrategy <FilterModel>(filterModel, Add, newFilter); Window filterWindow = new ElementWindow(configuration, DefinitionFactory.Create(filterModel.Descriptor, configuration), WindowSizeLocationFactory.Create(filterModel.Descriptor), saveStrategy); mMessageBoxService.ShowWindow(filterWindow); }
//this is how the window will look void OnGUI() { //Section Title GUILayout.Label("Editing Element Effectiveness", EditorStyles.boldLabel); //set the backgrount / box color to that of the element GUI.backgroundColor = EManager.Elements[Row].elementColor; //draw the attacking element GUILayout.Box(EManager.Elements[Row].symbol); //reset color GUI.backgroundColor = Color.white; //text GUILayout.Label("Will deal"); //the multiplyer newMultiplyer = EditorGUILayout.FloatField(newMultiplyer); //text GUILayout.Label("Times damage to"); //modify the box's background color to match the defending element's color and then draw the element's symbowl GUI.backgroundColor = EManager.Elements[Row].EffectivenessOnElement[Col].element.elementColor; GUILayout.Box(EManager.Elements[Row].EffectivenessOnElement[Col].element.symbol); //reset the color GUI.backgroundColor = Color.white; //a button to apply the change made to the effectiveness and return to the Element window if (GUILayout.Button("Save changes")) { CurrentMultiplyer = newMultiplyer; EditorUtility.SetDirty(EManager.Elements[Row]); ElementWindow.ShowWindow(EManager); AssetDatabase.SaveAssets(); this.Close(); } //a button to return to the element window without applying the changes if (GUILayout.Button("Camcel")) { ElementWindow.ShowWindow(); this.Close(); } }
// public void CreateElementWindow(XmlNode node) { FactoryShape factory = FactoryManager.getInstance().GetFactory(node.Name); ElementWindow model = (ElementWindow)factory.CreateControl(); m_Window = (ElementWindow)model; model.Container = m_Canvas; bool[] hotSpot = { false, false }; mSceneCanvas.Add(model); ElementProperty prop = FactoryActionParam.CreateParam(model); model.Property = prop; factory.PopulatePropertyList(prop); m_GridView.Tag = prop; foreach (XmlAttribute attr in node.Attributes) { prop.SetValue(attr.Name, attr.Value); } //FIXME use Factory for action... m_ActionWindow = new ActionAdd(factory); m_ActionWindow.Model = model; // Assign a copy of Param..... m_ActionWindow.SetParam(prop); mHostory.ExcuteAction(m_ActionWindow); //mSceneCanvas.Canvas.Invalidate(); PopulateControlList(); ElementTracker.Instance.AttachHotSpotObserver(this); //m_Window.PropertyChangeObserver = this; model.OnSizeChanged(); foreach (XmlNode child in node.ChildNodes) { // We only need Control elements.. if (child.Name == "Properties") { continue; } // CreateChildlement(child); } }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public CreateAttributeDialog(List<dynamic> existingKeys, bool enableEditableCheckBox, bool createKey, bool stringKeyOnly = true) /// /// \brief Constructor. /// /// \par Description. /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 09/05/2017 /// /// \brief #### Description. /// /// \param existingKeys (List<dynamic>) - The existing keys (for avoiding duplicate keys). /// \param enableEditableCheckBox (bool) - true to enable, false to disable the editable check box. /// \param createKey (bool) - true to create key for the attribute. /// \param stringKeyOnly (Optional) (bool) - true to string key only. //////////////////////////////////////////////////////////////////////////////////////////////////// public CreateAttributeDialog(ElementWindow callingWindow, Prms prms) { this.prms = prms; this.callingWindow = callingWindow; InitializeComponent(); if (!prms.createKey) { DockPanel_Key.Visibility = Visibility.Collapsed; Label_SelectAttributeKey.Visibility = Visibility.Collapsed; } else { InitKeyComboBoxes(); } FillEndInputOperationsListBox(); FillInputFieldListBox(); FillTypesListBox(); CheckBox_Edditable.IsEnabled = prms.enableEditableCheckBox; }
// private void m_Canvas_MouseDown(object sender, MouseEventArgs e) { mSceneCanvas.onMouseDown(e); ElementWindow window = m_Window;//(DrawElementWindow)m_ActionWindow.mModel; if (ElementTracker.Instance.FindHotSpot(e.Location) == null) { ElementTracker.Instance.HitObj = window.GetHitItem(e.Location); if (ElementTracker.Instance.HitObj == null) { ElementTracker.Instance.HitObj = window; ElementTracker.Instance.ShowHotSpot(false, 1); ElementTracker.Instance.ShowHotSpot(false, 2); } // Click on Diff Object UpdatePropertyList(ElementTracker.Instance.HitObj); } ElementTracker.Instance.onMouseDown(e); m_Canvas.Invalidate(); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public static bool EventTriggerChanged(BaseNetwork network, NetworkElement networkElement, Attribute parentAttribute, Attribute attribute, string newValue, out string errorMessage, ElementWindow inputWindow = null) /// /// \brief Event trigger changed. /// /// \par Description. /// - This method is activated by the GUI when the Trigger was changed /// - The purpose of this method is to disable all the other fields if the /// Event is initialize and enable all the fields otherwise /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 09/05/2018 /// /// \param network (BaseNetwork) - The network. /// \param networkElement (NetworkElement) - The network element. /// \param parentAttribute (Attribute) - The parent attribute. /// \param attribute (Attribute) - The attribute. /// \param newValue (string) - The new value. /// \param [out] errorMessage (out string) - Message describing the error. /// \param inputWindow (Optional) (ElementWindow) - The input window. /// /// \return True if it succeeds, false if it fails. //////////////////////////////////////////////////////////////////////////////////////////////////// public static bool EventTriggerChanged(BaseNetwork network, NetworkElement networkElement, Attribute parentAttribute, Attribute attribute, string newValue, out string errorMessage, ElementWindow inputWindow = null) { // Get All the childes of the parent attribute List <ElementWindow.ControlsAttributeLink> links = inputWindow.controlsAttributeLinks.Values.Where(l => l.parentAttribute == parentAttribute && l.attribute != attribute).ToList(); if (newValue == "Initialize") { foreach (ElementWindow.ControlsAttributeLink link in links) { link.newValueControl.IsEnabled = false; ((Control)link.newValueControl).Background = Brushes.LightGray; string defaultValue = ""; inputWindow.ChangeValue(defaultValue, link.attribute); } } else { string prevValue = inputWindow.controlsAttributeLinks.Values.First(l => l.attribute == attribute).existingNewValue; if (prevValue == "Initialize") { foreach (ElementWindow.ControlsAttributeLink link in links) { link.newValueControl.IsEnabled = true; ((Control)link.newValueControl).Background = Brushes.White; inputWindow.ChangeValue(link.existingValueTextBox.Text, link.attribute); } } } errorMessage = ""; return(true); }