Example usage for java.awt Component getClass

List of usage examples for java.awt Component getClass

Introduction

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

Prototype

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

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:labr_client.xml.ObjToXML.java

public static void saveProfile(Component[] comps, String profile) {

    try {/*from   w ww  .  j  a  v  a2  s  .  c o m*/
        if (comps != null) {
            JAXBContext context = JAXBContext.newInstance(LabrRequest.class);
            Marshaller m = context.createMarshaller();
            //for pretty-print XML in JAXB
            m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
            LabrRequest request = new LabrRequest();
            for (Component comp : comps) {

                if (comp.getName() != null) {

                    if (comp.getName().equals("name")) {
                        request.patient.name.setValue(((JTextField) comp).getText());
                        request.patient.name.setX(comp.getX());
                        request.patient.name.setY(comp.getY());
                        request.patient.name.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("firstName")) {
                        request.patient.firstName.setValue(((JTextField) comp).getText());
                        request.patient.firstName.setX(comp.getX());
                        request.patient.firstName.setY(comp.getY());
                        request.patient.firstName.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("birthDate")) {
                        request.patient.birthDate.setValue(((JFormattedTextField) comp).getText());
                        request.patient.birthDate.setX(comp.getX());
                        request.patient.birthDate.setY(comp.getY());
                        request.patient.birthDate.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("gender")) {
                        request.patient.gender.setValue((String) (((JComboBox) comp).getSelectedItem()));
                        request.patient.gender.setX(comp.getX());
                        request.patient.gender.setY(comp.getY());
                    } else if (comp.getName().equals("straatAndNumber")) {
                        request.patient.straatAndNumber.setValue(((JTextField) comp).getText());
                        request.patient.straatAndNumber.setX(comp.getX());
                        request.patient.straatAndNumber.setY(comp.getY());
                        request.patient.straatAndNumber.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("zip")) {
                        request.patient.zip.setValue(((JTextField) comp).getText());
                        request.patient.zip.setX(comp.getX());
                        request.patient.zip.setY(comp.getY());
                        request.patient.zip.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("city")) {
                        request.patient.city.setValue(((JTextField) comp).getText());
                        request.patient.city.setX(comp.getX());
                        request.patient.city.setY(comp.getY());
                        request.patient.city.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("country")) {
                        request.patient.country.setValue((String) (((JComboBox) comp).getSelectedItem()));
                        request.patient.country.setX(comp.getX());
                        request.patient.country.setY(comp.getY());
                    } else if (comp.getName().equals("nationalNumber")) {
                        request.patient.nationalNumber.setValue(((JTextField) comp).getText());
                        request.patient.nationalNumber.setX(comp.getX());
                        request.patient.nationalNumber.setY(comp.getY());
                        request.patient.nationalNumber.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("Save")) {
                        JButton jbut = (JButton) comp;
                        ImageIcon icon = (ImageIcon) jbut.getIcon();
                        request.buttons.save.setX(comp.getX());
                        request.buttons.save.setY(comp.getY());
                        request.buttons.save.setValue("Save");
                        if (icon != null) {
                            request.buttons.save.setIcon(icon.getDescription());
                        }
                    } else if (comp.getName().equals("Search")) {
                    } else if (comp.getName().equals("saveAndSend")) {
                        request.patient.nationalNumber.setValue(((JTextField) comp).getText());
                        request.patient.nationalNumber.setX(comp.getX());
                        request.patient.nationalNumber.setY(comp.getY());
                        request.patient.nationalNumber.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("print")) {
                        request.patient.nationalNumber.setValue(((JTextField) comp).getText());
                        request.patient.nationalNumber.setX(comp.getX());
                        request.patient.nationalNumber.setY(comp.getY());
                        request.patient.nationalNumber.setWidth(comp.getWidth());
                    } else {
                        Class<? extends Component> c = comp.getClass();
                        if (c.getSimpleName().equals("JLabel")) {
                            JLabel lbl = (JLabel) comp;
                            LabrXMLLabel l = new LabrXMLLabel();
                            l.setColor(String.valueOf(lbl.getForeground().getRGB()));
                            l.setSize(lbl.getFont().getSize());
                            l.setId(lbl.getName());
                            l.setValue(lbl.getText());
                            l.setX(lbl.getX());
                            l.setY(lbl.getY());
                            request.labels.getLabel().add(l);
                        }
                        ;
                        if (c.getSimpleName().equals("JCheckBox")) {
                            JCheckBox chbx = (JCheckBox) comp;
                            LabrXMLRequest req = new LabrXMLRequest();
                            req.setX(chbx.getX());
                            req.setY(chbx.getY());
                            req.setLoinc(chbx.getName());
                            req.setValue(chbx.getText());
                            req.setSelected(chbx.isSelected());
                            request.requests.getRequest().add(req);
                        }
                        ;
                        if (c.getSimpleName().equals("JTextBox")) {

                        }
                        ;
                    }
                }

            }
            m.marshal(request, new File(PublicVars.getUserData()[9] + "\\" + profile + ".xml"));
        }
    } catch (JAXBException e) {
        e.printStackTrace();
    }
}

From source file:labr_client.xml.ObjToXML.java

public static LabrRequest saveLabrRequest(Component[] comps) {

    try {//from w w w .  j  ava  2 s  . c  om
        if (comps != null) {
            JAXBContext context = JAXBContext.newInstance(LabrRequest.class);
            Marshaller m = context.createMarshaller();
            //for pretty-print XML in JAXB
            m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
            LabrRequest request = new LabrRequest();
            for (Component comp : comps) {

                if (comp.getName() != null) {

                    if (comp.getName().equals("name")) {
                        request.patient.name.setValue(((JTextField) comp).getText());
                        request.patient.name.setX(comp.getX());
                        request.patient.name.setY(comp.getY());
                        request.patient.name.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("firstName")) {
                        request.patient.firstName.setValue(((JTextField) comp).getText());
                        request.patient.firstName.setX(comp.getX());
                        request.patient.firstName.setY(comp.getY());
                        request.patient.firstName.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("birthDate")) {
                        request.patient.birthDate.setValue(((JFormattedTextField) comp).getText());
                        request.patient.birthDate.setX(comp.getX());
                        request.patient.birthDate.setY(comp.getY());
                        request.patient.birthDate.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("gender")) {
                        request.patient.gender.setValue((String) (((JComboBox) comp).getSelectedItem()));
                        request.patient.gender.setX(comp.getX());
                        request.patient.gender.setY(comp.getY());
                    } else if (comp.getName().equals("straatAndNumber")) {
                        request.patient.straatAndNumber.setValue(((JTextField) comp).getText());
                        request.patient.straatAndNumber.setX(comp.getX());
                        request.patient.straatAndNumber.setY(comp.getY());
                        request.patient.straatAndNumber.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("zip")) {
                        request.patient.zip.setValue(((JTextField) comp).getText());
                        request.patient.zip.setX(comp.getX());
                        request.patient.zip.setY(comp.getY());
                        request.patient.zip.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("city")) {
                        request.patient.city.setValue(((JTextField) comp).getText());
                        request.patient.city.setX(comp.getX());
                        request.patient.city.setY(comp.getY());
                        request.patient.city.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("country")) {
                        request.patient.country.setValue((String) (((JComboBox) comp).getSelectedItem()));
                        request.patient.country.setX(comp.getX());
                        request.patient.country.setY(comp.getY());
                    } else if (comp.getName().equals("nationalNumber")) {
                        request.patient.nationalNumber.setValue(((JTextField) comp).getText());
                        request.patient.nationalNumber.setX(comp.getX());
                        request.patient.nationalNumber.setY(comp.getY());
                        request.patient.nationalNumber.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("Save")) {
                        JButton jbut = (JButton) comp;
                        ImageIcon icon = (ImageIcon) jbut.getIcon();
                        request.buttons.save.setX(comp.getX());
                        request.buttons.save.setY(comp.getY());
                        request.buttons.save.setValue("Save");
                        if (icon != null) {
                            request.buttons.save.setIcon(icon.getDescription());
                        }
                    } else if (comp.getName().equals("Search")) {
                    } else if (comp.getName().equals("saveAndSend")) {
                        request.patient.nationalNumber.setValue(((JTextField) comp).getText());
                        request.patient.nationalNumber.setX(comp.getX());
                        request.patient.nationalNumber.setY(comp.getY());
                        request.patient.nationalNumber.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("print")) {
                        request.patient.nationalNumber.setValue(((JTextField) comp).getText());
                        request.patient.nationalNumber.setX(comp.getX());
                        request.patient.nationalNumber.setY(comp.getY());
                        request.patient.nationalNumber.setWidth(comp.getWidth());
                    } else {
                        Class<? extends Component> c = comp.getClass();
                        if (c.getSimpleName().equals("JLabel")) {
                            JLabel lbl = (JLabel) comp;
                            LabrXMLLabel l = new LabrXMLLabel();
                            l.setColor(String.valueOf(lbl.getForeground().getRGB()));
                            l.setSize(lbl.getFont().getSize());
                            l.setId(lbl.getName());
                            l.setValue(lbl.getText());
                            l.setX(lbl.getX());
                            l.setY(lbl.getY());
                            request.labels.getLabel().add(l);
                        }
                        ;
                        if (c.getSimpleName().equals("JCheckBox")) {
                            JCheckBox chbx = (JCheckBox) comp;
                            LabrXMLRequest req = new LabrXMLRequest();
                            req.setX(chbx.getX());
                            req.setY(chbx.getY());
                            req.setLoinc(chbx.getName());
                            req.setValue(chbx.getText());
                            req.setSelected(chbx.isSelected());
                            request.requests.getRequest().add(req);
                        }
                        ;
                        if (c.getSimpleName().equals("JTextBox")) {

                        }
                        ;
                    }
                }
            }
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddhhmm");
            String date = dateFormat.format(Calendar.getInstance().getTime());
            request.attributes.setTitle("LABR-" + PublicVars.getUserData()[5] + "-" + date);
            return request;
        }
        return null;
    } catch (JAXBException e) {
        e.printStackTrace();
        return null;
    }
}

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

/**
 * Animate multiple view properties at the same time. Example:
 * <pre>//from  w  w  w .j  a v  a  2s  .  c  o m
 * $.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;
}