Example usage for java.awt Component repaint

List of usage examples for java.awt Component repaint

Introduction

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

Prototype

public void repaint() 

Source Link

Document

Repaints this component.

Usage

From source file:Cal.java

/** Set just the day, on the current month */
public void setDayActive(int newDay) {

    clearDayActive();// w  w  w . j ava  2  s .  com

    // Set the new one
    if (newDay <= 0)
        dd = new GregorianCalendar().get(Calendar.DAY_OF_MONTH);
    else
        dd = newDay;
    // Now shade the correct square
    Component square = labs[(leadGap + newDay - 1) / 7][(leadGap + newDay - 1) % 7];
    square.setBackground(Color.red);
    square.repaint();
    activeDay = newDay;
}

From source file:edu.ku.brc.af.prefs.PreferencesDlg.java

/**
 * @param comp//from w  w  w . j av a 2s.  c o m
 * @param oldSize
 */
protected void showAndResizePane(final Component comp, final Dimension oldSize) {
    mainPanel.remove(currentComp);

    currentComp.setVisible(false);
    mainPanel.add(comp, BorderLayout.CENTER);
    comp.invalidate();
    comp.validate();
    comp.invalidate();
    comp.doLayout();
    comp.repaint();
    doLayout();
    repaint();
    currentComp = comp;
    currentComp.setVisible(true);

    Dimension oldWinDim = getSize();
    Dimension winDim = getSize();
    winDim.width += currentComp.getPreferredSize().width - oldSize.width;
    winDim.width = Math.max(winDim.width, 400);
    winDim.height = Math.max(winDim.height, 250);

    Dimension pSize = prefsToolbar.getPreferredSize();
    winDim.width = Math.max(winDim.width, pSize.width + 30);

    if (winDim.equals(oldWinDim)) // needed because JGoodies doesn't want to relayout when it is the same size.
    {
        winDim.height += 2;
    }
    setSize(winDim);
    currentComp.setSize(new Dimension(currentComp.getPreferredSize().width, oldSize.height));

    // Not sure why this combination works
    mainPanel.invalidate();
    mainPanel.validate();
    mainPanel.invalidate();
    mainPanel.doLayout();
    mainPanel.repaint();

    invalidate();
    validate();
    invalidate();
    doLayout();

    doLayout();
    repaint();
    // to here

    ((PrefsPanelIFace) comp).setShadeColor(null);

    // Without Animation
    comp.setVisible(true);
    winDim.height += currentComp.getPreferredSize().height - oldSize.height;
    winDim.height = Math.max(winDim.height, 250);
    setSize(winDim);
}

From source file:edu.ku.brc.ui.UIRegistry.java

/**
 * Clears the GlassPane, meaning it sets the mainComp visible again and sets the GlassPane to be hidden.
 *//*ww  w. j  ava  2 s  . c o m*/
public synchronized static void clearGlassPaneMsg() {
    Component mainComp = UIRegistry.get(UIRegistry.MAINPANE);
    if (mainComp != null && getGlassPane() != null && getGlassPane().isVisible()) {
        getGlassPane().setMaskingEvents(false);
        getGlassPane().setVisible(false);
        mainComp.setVisible(true);
        mainComp.repaint();

        Frame frame = (JFrame) get(FRAME);
        frame.setBounds(frameRect);
    }
    showingGlassPane = false;
}

From source file:fi.hoski.remote.ui.Admin.java

public static ActionListener createActionListener(final Component component,
        final ActionListener actionListener) {
    ActionListener al = new ActionListener() {

        @Override//from  ww w.  ja v  a  2 s  .  co  m
        public void actionPerformed(ActionEvent e) {
            try {
                component.setCursor(busyCursor);
                component.repaint();
                actionListener.actionPerformed(e);
            } finally {
                component.setCursor(defaultCursor);
            }
        }
    };
    return al;
}

From source file:freemind.controller.Controller.java

public void afterMapModuleChange(MapModule oldMapModule, Mode oldMode, MapModule newMapModule, Mode newMode) {
    ModeController newModeController;/*from   w  ww . ja v  a  2 s .c o  m*/
    if (newMapModule != null) {
        getFrame().setView(newMapModule.getView());
        setAllActions(true);
        if ((getView().getSelected() == null)) {
            moveToRoot();
        }
        lastOpened.mapOpened(newMapModule);
        ((MainToolBar) getToolbar()).setZoomComboBox(newMapModule.getView().getZoom());
        // old
        //            obtainFocusForSelected();
        newModeController = newMapModule.getModeController();
        newModeController.startupController();
        newModeController.setVisible(true);
        // old
        //            obtainFocusForSelected();
    } else {
        newModeController = newMode.getDefaultModeController();
        getFrame().setView(null);
        setAllActions(false);
    }
    setTitle();
    JToolBar newToolBar = newModeController.getModeToolBar();
    if (newToolBar != null) {
        toolbar.add(newToolBar);
        newToolBar.repaint();
    }
    /* new left toolbar. */
    Component newLeftToolBar = newModeController.getLeftToolBar();
    if (newLeftToolBar != null) {
        getFrame().getContentPane().add(newLeftToolBar, BorderLayout.WEST);
        if (leftToolbarVisible) {
            newLeftToolBar.setVisible(true);
            newLeftToolBar.repaint();
        } else {
            newLeftToolBar.setVisible(false);
        }
    }
    toolbar.validate();
    toolbar.repaint();
    MenuBar menuBar = getFrame().getFreeMindMenuBar();
    menuBar.updateMenus(newModeController);
    menuBar.revalidate();
    menuBar.repaint();
    // new
    obtainFocusForSelected();
}

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

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