Example usage for javax.swing JComponent isShowing

List of usage examples for javax.swing JComponent isShowing

Introduction

In this page you can find the example usage for javax.swing JComponent isShowing.

Prototype

public boolean isShowing() 

Source Link

Document

Determines whether this component is showing on screen.

Usage

From source file:Main.java

public static void onShown(final JComponent component, final Runnable action) {
    component.addHierarchyListener(new HierarchyListener() {
        public void hierarchyChanged(final HierarchyEvent e) {
            if (e.getComponent() == component && (e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) > 0) {
                if (component.isShowing())
                    action.run();//  w ww .j  a va  2s .c  o m
            }
        }
    });
}

From source file:CheckThreadViolationRepaintManager.java

private void checkThreadViolations(JComponent c) {
    if (!SwingUtilities.isEventDispatchThread() && (completeCheck || c.isShowing())) {
        boolean repaint = false;
        boolean fromSwing = false;
        boolean imageUpdate = false;
        StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
        for (StackTraceElement st : stackTrace) {
            if (repaint && st.getClassName().startsWith("javax.swing.")) {
                fromSwing = true;/* w ww  .ja v  a 2s  . c  o  m*/
            }
            if (repaint && "imageUpdate".equals(st.getMethodName())) {
                imageUpdate = true;
            }
            if ("repaint".equals(st.getMethodName())) {
                repaint = true;
                fromSwing = false;
            }
        }
        if (imageUpdate) {
            // assuming it is java.awt.image.ImageObserver.imageUpdate(...)
            // image was asynchronously updated, that's ok
            return;
        }
        if (repaint && !fromSwing) {
            // no problems here, since repaint() is thread safe
            return;
        }
        // ignore the last processed component
        if (lastComponent != null && c == lastComponent.get()) {
            return;
        }
        lastComponent = new WeakReference<JComponent>(c);
        violationFound(c, stackTrace);
    }
}

From source file:com.haulmont.cuba.desktop.sys.DesktopToolTipManager.java

protected boolean isPointInComponent(Point point, JComponent component) {
    if (!component.isShowing())
        return false;

    Point componentLocation = component.getLocationOnScreen();
    Rectangle bounds = component.getBounds();
    return (((point.x >= componentLocation.x) && (point.x <= componentLocation.x + bounds.width))
            && (point.y >= componentLocation.y) && (point.y <= componentLocation.y + bounds.height));
}

From source file:com.haulmont.cuba.desktop.sys.DesktopToolTipManager.java

protected void showTooltip(JComponent field, String text) {
    if (!field.isShowing())
        return;//from ww w  .  j  a  va2 s.  c o  m

    if (StringUtils.isEmpty(text)) {
        return;
    }

    PointerInfo pointerInfo = MouseInfo.getPointerInfo();
    if (pointerInfo == null) {
        return;
    }

    if (toolTipWindow != null) {
        hideTooltip();
    }

    component = field;

    final JToolTip toolTip = new CubaToolTip();
    toolTip.setTipText(text);

    // Location to display tooltip
    Point location = getToolTipLocation(pointerInfo, toolTip.getTipText());

    final Popup tooltipContainer = PopupFactory.getSharedInstance().getPopup(field, toolTip, location.x,
            location.y);
    tooltipContainer.show();

    window = tooltipContainer;
    toolTipWindow = toolTip;

    tooltipShowing = true;
    if (!(field instanceof ToolTipButton)) {
        toolTip.addMouseListener(this);
        field.addMouseListener(this);
    }
}

From source file:lcmc.gui.ResourceGraph.java

/** Starts the animation if vertex is being tested. */
public final void startTestAnimation(final JComponent component, final CountDownLatch startTestLatch) {
    mTestAnimationListLock.lock();//from  www.j  ava2  s. c o m
    mTestOnlyFlag.lock();
    testOnlyFlag = false;
    mTestOnlyFlag.unlock();
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            Tools.setMenuOpaque(component, false);
        }
    });
    if (testAnimationList.isEmpty()) {
        mTestAnimationThreadLock.lock();
        if (testAnimationThread == null) {
            /* start test animation thread */
            testAnimationThread = new Thread(new Runnable() {
                @Override
                public void run() {
                    FOREVER: while (true) {
                        try {
                            startTestLatch.await();
                        } catch (InterruptedException ignored) {
                            Thread.currentThread().interrupt();
                        }
                        mTestOnlyFlag.lock();
                        testOnlyFlag = !testOnlyFlag;
                        final boolean testOnlyFlagLast = testOnlyFlag;
                        mTestOnlyFlag.unlock();
                        repaint();
                        int sleep = 300;
                        if (testOnlyFlag) {
                            sleep = 1200;
                        }
                        for (int s = 0; s < sleep; s += animInterval) {
                            mTestOnlyFlag.lock();
                            if (testOnlyFlag == testOnlyFlagLast) {
                                mTestOnlyFlag.unlock();
                            } else {
                                mTestOnlyFlag.unlock();
                                repaint();
                            }
                            if (!component.isShowing()) {
                                stopTestAnimation(component);
                            }
                            mTestAnimationListLock.lock();

                            if (testAnimationList.isEmpty()) {
                                mTestAnimationListLock.unlock();
                                mTestOnlyFlag.lock();
                                testOnlyFlag = false;
                                mTestOnlyFlag.unlock();
                                repaint();
                                mTestAnimationThreadLock.lock();
                                testAnimationThread = null;
                                mTestAnimationThreadLock.unlock();
                                break FOREVER;
                            }
                            mTestAnimationListLock.unlock();
                            Tools.sleep(animInterval);
                        }
                    }
                }
            });
            testAnimationThread.start();
        }
        mTestAnimationThreadLock.unlock();
    }
    testAnimationList.add(component);
    mTestAnimationListLock.unlock();
}

From source file:lcmc.common.ui.ResourceGraph.java

/** Starts the animation if vertex is being tested. */
public final void startTestAnimation(final JComponent component, final CountDownLatch startTestLatch) {
    final int animInterval = (int) (1000 / mainData.getAnimFPS());
    mTestAnimationListLock.lock();//from  w w  w .  j  a  v  a2 s.  c  o m
    mRunModeFlag.lock();
    runModeFlag = Application.RunMode.LIVE;
    mRunModeFlag.unlock();
    swingUtils.invokeLater(new Runnable() {
        @Override
        public void run() {
            Tools.setMenuOpaque(component, false);
        }
    });
    if (testAnimationList.isEmpty()) {
        mTestAnimationThreadLock.lock();
        if (testAnimationThread == null) {
            /* start test animation thread */
            testAnimationThread = new Thread(new Runnable() {
                @Override
                public void run() {
                    FOREVER: while (true) {
                        try {
                            startTestLatch.await();
                        } catch (final InterruptedException ignored) {
                            Thread.currentThread().interrupt();
                        }
                        mRunModeFlag.lock();
                        final Application.RunMode runModeFlagLast;
                        try {
                            /* invert run mode */
                            if (Application.isTest(runModeFlag)) {
                                runModeFlag = Application.RunMode.LIVE;
                            } else {
                                runModeFlag = Application.RunMode.TEST;
                            }
                            runModeFlagLast = runModeFlag;
                        } finally {
                            mRunModeFlag.unlock();
                        }
                        repaint();
                        int sleep = 300;
                        if (Application.isTest(runModeFlag)) {
                            sleep = 1200;
                        }
                        for (int s = 0; s < sleep; s += animInterval) {
                            mRunModeFlag.lock();
                            if (runModeFlag == runModeFlagLast) {
                                mRunModeFlag.unlock();
                            } else {
                                mRunModeFlag.unlock();
                                repaint();
                            }
                            if (!component.isShowing()) {
                                stopTestAnimation(component);
                            }
                            mTestAnimationListLock.lock();

                            if (testAnimationList.isEmpty()) {
                                mTestAnimationListLock.unlock();
                                mRunModeFlag.lock();
                                try {
                                    runModeFlag = Application.RunMode.LIVE;
                                } finally {
                                    mRunModeFlag.unlock();
                                }
                                repaint();
                                mTestAnimationThreadLock.lock();
                                try {
                                    testAnimationThread = null;
                                } finally {
                                    mTestAnimationThreadLock.unlock();
                                }
                                break FOREVER;
                            }
                            mTestAnimationListLock.unlock();
                            Tools.sleep(animInterval);
                        }
                    }
                }
            });
            testAnimationThread.start();
        }
        mTestAnimationThreadLock.unlock();
    }
    testAnimationList.add(component);
    mTestAnimationListLock.unlock();
}

From source file:tk.tomby.tedit.core.ThreadSafeRepaintManager.java

/**
 * DOCUMENT ME!//from  w w w. j  av  a 2s.c  om
 *
 * @param c DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 */
private boolean isShowing(JComponent c) {
    return c.isShowing();
}