private static List <Getter> SetupGetters(Type klass)
    {
        //Get all properties from the object
        PropertyInfo[] properties = klass.GetProperties();
        List <Getter>  gs         = new List <Getter>();

        /*
         * If obj type has no properties then just prints a new line!
         */
        if (properties != null && properties.Length != 0)
        {
            for (int i = 0; i < properties.Length; i++)
            {
                //Print all Properties and their respective values
                PropertyInfo p = properties[i];
                // 1. p.GetCustomAttributes(false); => 2. testar se é typeof(IgnoreAttribute)
                // 2. p.GetCustomAttributes(typeof(IgnoreAttribute), false);
                if (p.IsDefined(typeof(IgnoreAttribute)) == false)
                {
                    object[] attrs = p.GetCustomAttributes(typeof(LayoutAttribute), false);
                    if (attrs == null || attrs.Length == 0)
                    {
                        gs.Add(new Getter(p, null));
                    }
                    else
                    {
                        LayoutAttribute l = (LayoutAttribute)attrs[0];
                        gs.Add(new Getter(p, l));
                    }
                }
            }
        }
        return(gs);
    }
        public float GetAttribute(View v, LayoutAttribute attribute)
        {
            switch (attribute)
            {
            case LayoutAttribute.Left:
                return(v.Left);

                break;

            case LayoutAttribute.Right:
                return(v.Right);

                break;

            case LayoutAttribute.Top:
                return(v.Top);

                break;

            case LayoutAttribute.Bottom:
                return(v.Bottom);

                break;

            case LayoutAttribute.Width:
                return(v.Width);

            case LayoutAttribute.Height:
                return(v.Height);

            default:
                throw new NotImplementedException(string.Format("Attribute not implemented: {0}", attribute));
            }
        }
        public void SetAttribute(View v, LayoutAttribute attribute, float value)
        {
            int intVal = (int)value;

            switch (attribute)
            {
            case LayoutAttribute.Left:
                v.Left = intVal;
                break;

            case LayoutAttribute.Right:
                v.Right = intVal;
                break;

            case LayoutAttribute.Top:
                v.Top = intVal;
                break;

            case LayoutAttribute.Bottom:
                v.Bottom = intVal;
                break;

            case LayoutAttribute.Width:
            case LayoutAttribute.Height:
                break;

            default:
                throw new NotImplementedException(string.Format("Attribute not implemented: {0}", attribute));
            }
        }
Beispiel #4
0
 public static LayoutDrawer CreateLayoutDrawer(LayoutAttribute attr)
 {
     if (attrDrawerDic.TryGetValue(attr.GetType(), out Type drawerType))
     {
         return((LayoutDrawer)Activator.CreateInstance(drawerType, attr));
     }
     return(null);
 }
        public IRawLayout GetLayout(LayoutAttribute attribute)
        {
            var adapter = LayoutAdapters.FirstOrDefault(a => a.CanAdapt(attribute));

            var layout = adapter?.Adapt(attribute);

            return(layout);
        }
        public void Should_set_layout_to_view_results()
        {
            var result          = new ViewResult();
            var context         = new ResultExecutingContext(_controllerContext, result);
            var layoutAttribute = new LayoutAttribute("test");

            layoutAttribute.OnResultExecuting(context);

            Assert.That(result.MasterName, Is.EqualTo("test"));
        }
        protected ClLinearExpression GetExpressionFromViewAndAttribute(T view, LayoutAttribute attribute /*, out ClLinearEquation egality*/)
        {
            if (HasVariableForViewAndAttribute(view, attribute))
            {
                return(new ClLinearExpression(GetVariableFromViewAndAttribute(view, attribute)));
            }

            var compositeVariable = GetCompositeVariableFromViewAndAttribute(view, attribute);

            if (compositeVariable != null)
            {
                return(new ClLinearExpression(compositeVariable));
            }

            var variable   = GetVariableFromViewAndAttribute(view, attribute);
            var expression = new ClLinearExpression(variable);

            var greaterZero = new LayoutAttribute[] {
                LayoutAttribute.Width,
                LayoutAttribute.Height,
                LayoutAttribute.Top,
                LayoutAttribute.Bottom,
                LayoutAttribute.Left,
                LayoutAttribute.Right
            };

            if (greaterZero.Contains(attribute))
            {
                solver.AddConstraint(new ClLinearInequality(
                                         expression,
                                         Cl.Operator.GreaterThanOrEqualTo,
                                         new ClLinearExpression(0)
                                         ));
            }


            if (attribute == LayoutAttribute.Left || attribute == LayoutAttribute.Right)
            {
                solver.AddConstraint(new ClLinearInequality(
                                         GetVariableFromViewAndAttribute(view, LayoutAttribute.Right),
                                         Cl.Operator.GreaterThanOrEqualTo,
                                         GetVariableFromViewAndAttribute(view, LayoutAttribute.Left)
                                         ));
            }
            if (attribute == LayoutAttribute.Top || attribute == LayoutAttribute.Bottom)
            {
                solver.AddConstraint(new ClLinearInequality(
                                         GetVariableFromViewAndAttribute(view, LayoutAttribute.Bottom),
                                         Cl.Operator.GreaterThanOrEqualTo,
                                         GetVariableFromViewAndAttribute(view, LayoutAttribute.Top)
                                         ));
            }

            return(expression);
        }
        protected void AddVariableForViewAndAttribute(T view, LayoutAttribute attribute, ClVariable variable)
        {
            if (HasVariableForViewAndAttribute(view, attribute))
            {
                return;
            }

            var viewAndAttribute = new ViewAndLayoutAttribute <T> (view, attribute);

            variables.Add(viewAndAttribute, variable);
        }
Beispiel #9
0
        public void GetLayout_WithNullAttribute_ShouldReturnNull()
        {
            // Arrange
            var             sut       = new LayoutAdapterProvider();
            LayoutAttribute attribute = null;

            // Act
            var result = sut.GetLayout(attribute);

            // Assert
            Assert.IsNull(result);
        }
Beispiel #10
0
        private static List <ControlAdapter> CreateControlAdapters(Control declaring, Control control)
        {
            List <ControlAdapter> res = new List <ControlAdapter>();

            foreach (Control c in control.Controls)
            {
                ControlAdapter ca = null;
                FieldInfo      fi = ReflectiveControlSearch(declaring, c);

                if (c is Panel)
                {
                    Object[] o = fi.GetCustomAttributes(typeof(LayoutAttribute), false);

                    if (o.Count() > 0)
                    {
                        LayoutAttribute la = (LayoutAttribute)o[0];
                        ca = new PanelAdapter(null, la.LayoutManager, (Panel)c);
                    }
                    else
                    {
                        ca = new ControlAdapter(null, c);
                    }
                }
                else
                {
                    ca = new ControlAdapter(null, c);
                }

                Object[] hfa = fi.GetCustomAttributes(typeof(HorizontalFixedAttribute), false);
                if (hfa.Count() > 0)
                {
                    ca.HorizontalFix = true;
                }

                hfa = fi.GetCustomAttributes(typeof(VerticalFixedAttribute), false);
                if (hfa.Count() > 0)
                {
                    ca.VerticalFix = true;
                }


                ca.VirtualX      = c.Location.X;
                ca.VirtualY      = c.Location.Y;
                ca.VirtualWidth  = c.Width;
                ca.VirtualHeight = c.Height;
                res.Add(ca);
            }

            return(res);
        }
Beispiel #11
0
        public static string GetAttributeValueByName(XmlTag tag, XmlAttributeTypes _type, string defaultValue)
        {
            string          value = string.Empty;
            string          name  = _type.ToString();
            LayoutAttribute attr  = new LayoutAttribute();

            attr = tag.LSTAttributes.Find(
                delegate(LayoutAttribute attObj)
            {
                return(Utils.CompareStrings(attObj.Name, name));
            }
                );
            return(attr == null ? defaultValue : attr.Value);
        }
        protected ClVariable GetVariableFromViewAndAttribute(T view, LayoutAttribute attribute)
        {
            ClVariable variable         = null;
            var        viewAndAttribute = new ViewAndLayoutAttribute <T> (view, attribute);

            if (!variables.TryGetValue(viewAndAttribute, out variable))
            {
                var value = viewEngine.GetAttribute(view, attribute);
                var name  = string.Format("{0}.{1}", viewEngine.GetViewName(view), attribute.ToString());

                variable = new ClVariable(name, value);
                variables.Add(viewAndAttribute, variable);
            }

            return(variable);
        }
    public static void Log(object obj)
    {
        //Print on screen the type of the object
        Type klass = obj.GetType();

        Console.Write("{0}:", klass.Name);

        //Get all properties from the object
        PropertyInfo[] properties = klass.GetProperties();

        /*
         * If obj type has no properties then just prints a new line!
         */
        if (properties == null || properties.Length == 0)
        {
            Console.WriteLine();
            return;
        }
        for (int i = 0; i < properties.Length; i++)
        {
            //Print all Properties and their respective values
            PropertyInfo p = properties[i];
            // 1. p.GetCustomAttributes(false); => 2. testar se é typeof(IgnoreAttribute)
            // 2. p.GetCustomAttributes(typeof(IgnoreAttribute), false);
            if (p.IsDefined(typeof(IgnoreAttribute)) == false)
            {
                object[] attrs = p.GetCustomAttributes(typeof(LayoutAttribute), false);
                object   val   = p.GetValue(obj);
                if (attrs == null || attrs.Length == 0)
                {
                    Console.Write(p.Name + "=" + val + ", ");
                }
                else
                {
                    if (p.PropertyType != typeof(double))
                    {
                        throw new InvalidOperationException("You cannot use Layout attribute on non double properties such as : " + p.Name + " of " + klass.Name);
                    }
                    LayoutAttribute l = (LayoutAttribute)attrs[0];
                    Console.Write(p.Name + "=" + ((double)val).ToString(l.Format) + ", ");
                }
            }
        }
        Console.WriteLine();
    }
        protected void Init()
        {
            solver           = new ClSimplexSolver();
            solver.AutoSolve = false;

            var stayVariables = new LayoutAttribute[] {
                LayoutAttribute.Left,
                LayoutAttribute.Top
            };

            foreach (var attribute in stayVariables)
            {
                var variable = GetVariableFromViewAndAttribute(_rootView, attribute);
                variable.ChangeValue(0);

                _stayVariables.Add(attribute, variable);
                solver.AddStay(variable);
            }
        }
    public static void Log(object obj)
    {
        //Print on screen the type of the object
        Type klass = obj.GetType();

        Console.Write("{0}: ", klass.Name);

        //Get all properties from the object
        PropertyInfo[] properties = klass.GetProperties();

        /*
         * If obj type has no properties then just prints a new line!
         */
        if (properties == null || properties.Length == 0)
        {
            Console.WriteLine();
            return;
        }
        for (int i = 0; i < properties.Length; i++)
        {
            //Print all Properties and their respective values
            PropertyInfo p = properties[i];
            // 1. p.GetCustomAttributes(false); => 2. testar se é typeof(IgnoreAttribute)
            // 2. p.GetCustomAttributes(typeof(IgnoreAttribute), false);
            if (p.IsDefined(typeof(IgnoreAttribute)) == false)
            {
                object[] attrs = p.GetCustomAttributes(typeof(LayoutAttribute), false);
                object   val   = p.GetValue(obj);
                if (attrs == null || attrs.Length == 0)
                {
                    Console.Write(p.Name + "=" + val + ", ");
                }
                else
                {
                    LayoutAttribute l = (LayoutAttribute)attrs[0];
                    Console.Write(p.Name + "=" + l.Format(val) + ", ");
                }
            }
        }
        Console.WriteLine();
    }
        XElement ActivityFromTypeDefinition(TypeDefinition type, string name, int targetSdkVersion)
        {
            if (name.StartsWith("_"))
            {
                throw new InvalidActivityNameException(string.Format("Activity name '{0}' is invalid, because activity namespaces may not begin with an underscore.", type.FullName));
            }

            return(ToElement(type, name,
                             ActivityAttribute.FromTypeDefinition,
                             aa => aa.ToElement(Resolver, PackageName, targetSdkVersion),
                             (aa, element) => {
                if (aa.MainLauncher)
                {
                    AddLauncherIntentElements(element);
                }
                var la = LayoutAttribute.FromTypeDefinition(type);
                if (la != null)
                {
                    element.Add(la.ToElement(Resolver, PackageName));
                }
            }));
        }
Beispiel #17
0
        static string SimpleTypeName(Type t)
        {
            if (t == typeof(byte))
            {
                return("xs:byte");
            }
            if (t == typeof(int))
            {
                return("xs:integer");
            }
            if (t == typeof(long))
            {
                return("xs:long");
            }
            if (t == typeof(string))
            {
                return("xs:string");
            }
            if (t == typeof(bool))
            {
                return("xs:boolean");
            }

            TargetAttribute ta = (TargetAttribute)Attribute.GetCustomAttribute(t, typeof(TargetAttribute));

            if (ta != null)
            {
                return(ta.Name);
            }

            LayoutAttribute la = (LayoutAttribute)Attribute.GetCustomAttribute(t, typeof(LayoutAttribute));

            if (la != null)
            {
                return(la.Name);
            }

            return(t.Name);
        }
Beispiel #18
0
        public ILayout CreateLayout(Control control, bool inherit)
        {
            try
            {
                Object[] tmp = control.GetType().GetCustomAttributes(typeof(LayoutAttribute), inherit);
                if (tmp.Count() > 0)
                {
                    LayoutAttribute l = (LayoutAttribute)tmp[0];

                    foreach (ILayoutFactory lf in _factories)
                    {
                        if (lf.GetType() == l.LayoutManager)
                        {
                            return(lf.CreateLayout(control));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ContextCorruptedException("Layout couldn't be created. (" + ex.Message + ")");
            }
            throw new ContextCorruptedException("Layout couldn't be created. (No LayoutFactory found.)");
        }
Beispiel #19
0
 public virtual bool CanAdapt(LayoutAttribute attribute)
 {
     return(attribute is TAttribute);
 }
Beispiel #20
0
 public virtual IRawLayout Adapt(LayoutAttribute attribute)
 {
     return(Adapt(attribute as TAttribute));
 }
Beispiel #21
0
 public BeginHorizontalDrawer(LayoutAttribute attr) : base(attr)
 {
 }
Beispiel #22
0
 public EndIndentDrawer(LayoutAttribute attr) : base(attr)
 {
 }
        public double GetValue(T view, LayoutAttribute attribute)
        {
            var variable = GetVariableFromViewAndAttribute(view, attribute);

            return(variable.Value);
        }
        internal void OnGUILayout()
        {
            foreach (var drawer in layoutDrawers)
            {
                LayoutAttribute attr = drawer.GetAttr <LayoutAttribute>();
                if (attr.Occasion == LayoutOccasion.Before)
                {
                    drawer.OnGUILayout();
                }
            }

            bool isVisible = IsVisible();

            if (isVisible)
            {
                foreach (var drawer in controlDrawers)
                {
                    drawer.OnStartGUILayout();
                }

                foreach (var drawer in decoratorDrawers)
                {
                    drawer.OnGUILayout();
                }

                foreach (var drawer in verificationDrawers)
                {
                    drawer.OnGUILayout();
                }

                string label = FieldName;
                if (labelDrawer != null)
                {
                    label = labelDrawer.GetLabel();
                }
                if (!string.IsNullOrEmpty(label))
                {
                    label = UnityEditor.ObjectNames.NicifyVariableName(label);
                }
                if (contentDrawer != null)
                {
                    contentDrawer.OnGUILayout(label);
                }
                else if (drawerObject != null)
                {
                    if (!IsArrayElement)
                    {
                        UnityEditor.EditorGUILayout.LabelField(label);
                        UnityEditor.EditorGUI.indentLevel++;
                        {
                            drawerObject.OnGUILayout();
                        }
                        UnityEditor.EditorGUI.indentLevel--;
                    }
                    else
                    {
                        UnityEditor.EditorGUILayout.BeginHorizontal();
                        {
                            UnityEditor.EditorGUILayout.LabelField(label, UnityEngine.GUILayout.Width(25));
                            UnityEditor.EditorGUILayout.BeginVertical();
                            {
                                drawerObject.OnGUILayout();
                            }
                            UnityEditor.EditorGUILayout.EndVertical();
                        }
                        UnityEditor.EditorGUILayout.EndHorizontal();
                    }
                }
                else if (drawerObject == null)
                {
                    if (!DrawerUtility.IsTypeSupported(ValueType))
                    {
                        EGUI.BeginGUIColor(UnityEngine.Color.red);
                        {
                            UnityEditor.EditorGUILayout.LabelField(string.IsNullOrEmpty(label) ? "" : label, $"The type isn't supported.type = {ValueType}");
                        }
                        EGUI.EndGUIColor();
                    }
                    else if (Value == null)
                    {
                        UnityEditor.EditorGUILayout.BeginHorizontal();
                        {
                            UnityEditor.EditorGUILayout.PrefixLabel(label);
                            if (UnityEngine.GUILayout.Button("Create"))
                            {
                                Value = DrawerUtility.CreateInstance(ValueType);

                                if (DrawerUtility.IsTypeSupported(ValueType))
                                {
                                    if (ValueType.IsStructOrClassType() && Value != null)
                                    {
                                        drawerObject = new DrawerObject(Value);
                                    }
                                }
                            }
                        }
                        UnityEditor.EditorGUILayout.EndHorizontal();
                    }
                    else
                    {
                        EGUI.BeginGUIColor(UnityEngine.Color.red);
                        {
                            UnityEditor.EditorGUILayout.LabelField(string.IsNullOrEmpty(label) ? "" : label, "Unknown Drawer");
                        }
                        EGUI.EndGUIColor();
                    }
                }

                foreach (var drawer in controlDrawers)
                {
                    drawer.OnEndGUILayout();
                }
            }

            foreach (var drawer in layoutDrawers)
            {
                LayoutAttribute attr = drawer.GetAttr <LayoutAttribute>();
                if (attr.Occasion == LayoutOccasion.After)
                {
                    drawer.OnGUILayout();
                }
            }
        }
        protected ClVariable GetCompositeVariableFromViewAndAttribute(T view, LayoutAttribute attribute)
        {
            if (HasVariableForViewAndAttribute(view, attribute))
            {
                return(GetVariableFromViewAndAttribute(view, attribute));
            }

            switch (attribute)
            {
            case LayoutAttribute.Width:
            {
                var leftVar  = GetVariableFromViewAndAttribute(view, LayoutAttribute.Left);
                var rightVar = GetVariableFromViewAndAttribute(view, LayoutAttribute.Right);

                var widthExpression = Cl.Minus(
                    new ClLinearExpression(rightVar),
                    new ClLinearExpression(leftVar)
                    );

                var widthVariable = new ClVariable(viewEngine.GetViewName(view) + ".Width");

                solver.AddConstraint(new ClLinearEquation(
                                         widthVariable,
                                         widthExpression,
                                         ClStrength.Required
                                         ));

                AddVariableForViewAndAttribute(view, attribute, widthVariable);
                return(widthVariable);
            }

            case LayoutAttribute.Height:
            {
                var topVar    = GetVariableFromViewAndAttribute(view, LayoutAttribute.Top);
                var bottomVar = GetVariableFromViewAndAttribute(view, LayoutAttribute.Bottom);

                var heightExpression = Cl.Minus(
                    new ClLinearExpression(bottomVar),
                    new ClLinearExpression(topVar)
                    );

                var heightVariable = new ClVariable(viewEngine.GetViewName(view) + ".Height");

                solver.AddConstraint(new ClLinearEquation(
                                         heightVariable,
                                         heightExpression,
                                         ClStrength.Required
                                         ));


                solver.AddConstraint(new ClLinearInequality(
                                         heightVariable,
                                         Cl.Operator.GreaterThanOrEqualTo,
                                         new ClLinearExpression(0)
                                         ));


                AddVariableForViewAndAttribute(view, attribute, heightVariable);
                return(heightVariable);
            }

            case LayoutAttribute.CenterX:
            {
                var leftVar  = GetVariableFromViewAndAttribute(view, LayoutAttribute.Left);
                var rightVar = GetVariableFromViewAndAttribute(view, LayoutAttribute.Right);

                var centerXExpression = Cl.Plus(
                    Cl.Divide(new ClLinearExpression(leftVar), new ClLinearExpression(2)),
                    Cl.Divide(new ClLinearExpression(rightVar), new ClLinearExpression(2))
                    );

                var centerXVariable = new ClVariable(viewEngine.GetViewName(view) + ".CenterX");
                solver.AddConstraint(new ClLinearEquation(
                                         centerXVariable,
                                         centerXExpression,
                                         ClStrength.Required
                                         ));

                AddVariableForViewAndAttribute(view, attribute, centerXVariable);
                return(centerXVariable);
            }

            case LayoutAttribute.CenterY:
            {
                var topVar    = GetVariableFromViewAndAttribute(view, LayoutAttribute.Top);
                var bottomVar = GetVariableFromViewAndAttribute(view, LayoutAttribute.Bottom);

                var centerYExpression = Cl.Plus(
                    Cl.Divide(new ClLinearExpression(topVar), new ClLinearExpression(2)),
                    Cl.Divide(new ClLinearExpression(bottomVar), new ClLinearExpression(2))
                    );

                var centerYVariable = new ClVariable(viewEngine.GetViewName(view) + ".CenterY");
                solver.AddConstraint(new ClLinearEquation(
                                         centerYVariable,
                                         centerYExpression,
                                         ClStrength.Required
                                         ));

                AddVariableForViewAndAttribute(view, attribute, centerYVariable);
                return(centerYVariable);
            }
            }

            return(null);
        }
 public BeginIndentDrawer(LayoutAttribute attr) : base(attr)
 {
 }
Beispiel #27
0
        protected Variable GetCompositeVariableFromViewAndAttribute(T view, LayoutAttribute attribute, Variable leftVar, Variable rightVar, Variable topVar, Variable bottomVar)
        {
            switch (attribute)
            {
            case LayoutAttribute.Width:
            {
                var widthExpression = kiwi.kiwi.__minus__(
                    rightVar,
                    leftVar
                    );

                var widthVariable = new Variable(viewEngine.GetViewName(view) + ".Width");

                solver.addConstraint(new Constraint(
                                         kiwi.kiwi.__minus__(widthVariable, widthExpression),
                                         RelationalOperator.OP_EQ,
                                         kiwi.kiwi.required));

                AddVariableForViewAndAttribute(view, attribute, widthVariable);
                return(widthVariable);
            }

            case LayoutAttribute.Height:
            {
                var heightExpression = kiwi.kiwi.__minus__(
                    bottomVar,
                    topVar
                    );

                var heightVariable = new Variable(viewEngine.GetViewName(view) + ".Height");

                solver.addConstraint(new Constraint(
                                         kiwi.kiwi.__minus__(heightVariable, heightExpression),
                                         RelationalOperator.OP_EQ,
                                         kiwi.kiwi.required));

                AddVariableForViewAndAttribute(view, attribute, heightVariable);
                return(heightVariable);
            }

            case LayoutAttribute.CenterX:
            {
                var centerXExpression = kiwi.kiwi.__plus__(
                    kiwi.kiwi.__div__(leftVar, 2),
                    kiwi.kiwi.__div__(rightVar, 2)
                    );

                var centerXVariable = new Variable(viewEngine.GetViewName(view) + ".CenterX");
                solver.addConstraint(new Constraint(
                                         kiwi.kiwi.__minus__(centerXVariable, centerXExpression),
                                         RelationalOperator.OP_EQ,
                                         kiwi.kiwi.required
                                         ));

                AddVariableForViewAndAttribute(view, attribute, centerXVariable);
                return(centerXVariable);
            }

            case LayoutAttribute.CenterY:
            {
                var centerYExpression = kiwi.kiwi.__plus__(
                    kiwi.kiwi.__div__(topVar, 2),
                    kiwi.kiwi.__div__(bottomVar, 2)
                    );

                var centerYVariable = new Variable(viewEngine.GetViewName(view) + ".CenterY");
                solver.addConstraint(new Constraint(
                                         kiwi.kiwi.__minus__(centerYVariable, centerYExpression),
                                         RelationalOperator.OP_EQ,
                                         kiwi.kiwi.required
                                         ));

                AddVariableForViewAndAttribute(view, attribute, centerYVariable);
                return(centerYVariable);
            }
            }

            return(null);
        }
 public Getter(PropertyInfo p, LayoutAttribute l)
 {
     this.Prop   = p;
     this.Layout = l;
 }
        protected bool HasVariableForViewAndAttribute(T view, LayoutAttribute attribute)
        {
            var viewAndAttribute = new ViewAndLayoutAttribute <T>(view, attribute);

            return(variables.ContainsKey(viewAndAttribute));
        }
Beispiel #30
0
 protected LayoutDrawer(LayoutAttribute attr) : base(attr)
 {
 }