Example usage for java.awt Rectangle getClass

List of usage examples for java.awt Rectangle getClass

Introduction

In this page you can find the example usage for java.awt Rectangle getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:Main.java

public static void main(String[] args) {
    Rectangle r = new Rectangle(100, 325);
    Class c = r.getClass();
    try {//  w  w w.  j  a  va2  s .  c  om
        Field heightField = c.getField("height");
        heightField.setInt(r, 1000);
        Integer heightValue = (Integer) heightField.get(r);
        System.out.println("Height: " + heightValue.toString());
    } catch (Exception e) {
        System.out.println(e);
    }
}

From source file:Main.java

public static void main(String[] args) {
    Rectangle r = new Rectangle(100, 325);
    Class c = r.getClass();
    try {/* w w w.  j  a v a 2s.com*/
        Field heightField = c.getField("height");
        Integer heightValue = (Integer) heightField.get(r);
        System.out.println("Height: " + heightValue.toString());
    } catch (NoSuchFieldException e) {
        System.out.println(e);
    } catch (SecurityException e) {
        System.out.println(e);
    } catch (IllegalAccessException e) {
        System.out.println(e);
    }
}

From source file:SampleGet.java

static void printHeight(Rectangle r) {
    Field heightField;/*  ww  w .j a  v a  2 s  . co  m*/
    Integer heightValue;
    Class c = r.getClass();
    try {
        heightField = c.getField("height");
        heightValue = (Integer) heightField.get(r);
        System.out.println("Height: " + heightValue.toString());
    } catch (NoSuchFieldException e) {
        System.out.println(e);
    } catch (SecurityException e) {
        System.out.println(e);
    } catch (IllegalAccessException e) {
        System.out.println(e);
    }
}

From source file:SampleSet.java

static void modifyWidth(Rectangle r, Integer widthParam) {
    Field widthField;//from   w w  w  . j  av  a 2 s .  co  m
    Integer widthValue;
    Class c = r.getClass();
    try {
        widthField = c.getField("width");
        widthField.set(r, widthParam);
    } catch (NoSuchFieldException e) {
        System.out.println(e);
    } catch (IllegalAccessException e) {
        System.out.println(e);
    }
}

From source file:self.philbrown.javaQuery.$.java

/**
 * Animate multiple view properties at the same time. Example:
 * <pre>//from   w w w.  ja v a  2s.c om
 * $.with(myView).animate(new QuickMap(QuickEntry.qe("alpha", .8f), QuickEntry.qe("width", 50%)), 400, Easing.LINEAR, null);
 * </pre>
 * @param properties mapping of property names and final values to animate
 * @param options the options for setting the duration, easing, etc of the animation
 * @return this
 */
public $ animate(Map<String, Object> properties, final AnimationOptions options) {
    List<Animator> animations = new ArrayList<Animator>();
    for (Entry<String, Object> entry : properties.entrySet()) {
        final String key = entry.getKey();
        //Java sometimes will interpret these Strings as Numbers, so some trickery is needed below
        Object value = entry.getValue();

        for (final Component view : this.views) {
            Animator anim = null;
            if (value instanceof String)
                value = getAnimationValue(view, key, (String) value);
            //final Object fValue = value;
            if (value != null) {
                //special color cases
                if (key.equals("alpha") || key.equals("red") || key.equals("green") || key.equals("blue")) {
                    if (key.equals("alpha") && view instanceof JComponent) {
                        ((JComponent) view).setOpaque(false);
                    }
                    try {
                        final Method getComponent = Color.class
                                .getMethod(Log.buildString("get", capitalize(key)));
                        final int colorComponent = (Integer) getComponent.invoke(view.getBackground());
                        final ColorHelper color = new ColorHelper(view.getBackground());
                        final Method setComponent = ColorHelper.class.getMethod(
                                Log.buildString("set", capitalize(key)), new Class<?>[] { int.class });
                        anim = new Animator();

                        //if integer - assume 0-255
                        if (value instanceof Integer || is(value, int.class)) {
                            anim.addTarget(PropertySetter.getTarget(color, key, colorComponent,
                                    Integer.parseInt(value.toString())));
                        }
                        //if float - assume 0.0-1.0
                        else if (value instanceof Float || is(value, float.class)) {
                            anim.addTarget(PropertySetter.getTarget(color, key, colorComponent,
                                    (int) (255 * Float.parseFloat(value.toString()))));
                        }
                        anim.addTarget(new TimingTargetAdapter() {

                            @Override
                            public void timingEvent(Animator source, double fraction) {
                                double d = source.getInterpolator().interpolate(fraction);
                                try {
                                    setComponent.invoke(color, (int) d);
                                    view.setBackground(color.getColor());
                                    //                              if (view instanceof JComponent)
                                    //                                 ((JComponent) view).revalidate();
                                    view.repaint();
                                } catch (Throwable t) {
                                    if (options.debug())
                                        t.printStackTrace();
                                }
                            }
                        });
                    } catch (Throwable t) {
                        if (options.debug())
                            t.printStackTrace();
                    }

                } else {
                    final Rectangle params = view.getBounds();
                    try {
                        final Field field = params.getClass().getField(key);
                        if (field != null) {
                            anim = new Animator();
                            anim.addTarget(PropertySetter.getTarget(params, key, field.get(params), value));

                            anim.addTarget(new TimingTargetAdapter() {

                                @Override
                                public void timingEvent(Animator source, double fraction) {
                                    Rectangle bounds = view.getBounds();
                                    double d = source.getInterpolator().interpolate(fraction);
                                    try {
                                        field.set(bounds, d);
                                    } catch (Throwable t) {
                                        if (options.debug())
                                            t.printStackTrace();
                                    }
                                    view.setBounds(bounds);
                                    view.repaint();
                                    if (options.progress() != null) {
                                        options.progress().invoke($.with(view), key, d,
                                                source.getDuration() - source.getTotalElapsedTime());
                                    }
                                }

                            });
                        }

                    } catch (Throwable t) {

                        if (options.debug())
                            Log.w("$", String.format(Locale.US, "%s is not a LayoutParams attribute.", key));
                    }

                    if (anim == null) {
                        anim = new Animator();
                        Object first;
                        try {
                            final Method getter = view.getClass()
                                    .getMethod(Log.buildString("get", capitalize(key)));
                            first = getter.invoke(view);
                        } catch (Throwable t) {
                            first = 0;
                        }

                        anim.addTarget(PropertySetter.getTarget(view, key, first, value));

                        if (options.progress() != null) {
                            anim.addTarget(new TimingTargetAdapter() {

                                @Override
                                public void timingEvent(Animator source, double fraction) {
                                    double d = source.getInterpolator().interpolate(fraction);
                                    if (options.progress() != null) {
                                        options.progress().invoke($.with(view), key, d,
                                                source.getDuration() - source.getTotalElapsedTime());
                                    }
                                }

                            });
                        }
                    }
                }

                if (options.repeatCount() >= 1)
                    anim.setRepeatCount(options.repeatCount());
                if (options.reverse())
                    anim.setRepeatBehavior(Animator.RepeatBehavior.REVERSE);
                animations.add(anim);
            }

        }
    }
    AnimatorSet animation = animationWithOptions(options, animations);
    animation.start();

    return this;
}