Example usage for java.awt Window setVisible

List of usage examples for java.awt Window setVisible

Introduction

In this page you can find the example usage for java.awt Window setVisible.

Prototype

public void setVisible(boolean b) 

Source Link

Document

Shows or hides this Window depending on the value of parameter b .

Usage

From source file:de.codesourcery.eve.skills.ui.components.impl.PasswordComponent.java

public static ICipherProvider createCipherProvider(String title, String message, Mode mode,
        final Window parent) {

    final PasswordComponent comp = new PasswordComponent(title, message, mode);

    final IPasswordProvider passwordProvider = new IPasswordProvider() {

        @Override//from   w  w  w  .  j a v  a  2 s  .c o  m
        public char[] getPassword() {

            final Window window = ComponentWrapper.wrapComponent(parent, comp);

            window.setVisible(true);
            return comp.getPassword1();
        }
    };

    return new PasswordCipherProvider(passwordProvider);
}

From source file:com.all.app.ApplicationUtils.java

public static void showFrameAndWaitForClose(Window window) {
    try {/*w w  w  .  j  a  v a 2s.c  om*/
        final Semaphore lock = new Semaphore(0);
        window.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                lock.release();
            }
        });
        window.setVisible(true);
        lock.acquire();
    } catch (Exception e) {
        LOG.error(e, e);
    }
}

From source file:Main.java

public static Window showCentered(Component parent, Window window) {
    if (null == window)
        throw new IllegalArgumentException("window null");

    if (window instanceof Dialog) {
        Dialog dialog = (Dialog) window;

        boolean isResizable = dialog.isResizable();

        dialog.setResizable(true);/*from w ww . j a v  a 2  s .c  om*/
        dialog.pack();
        dialog.setResizable(isResizable);
    } else {
        window.pack();
    }

    Dimension windowSize = window.getPreferredSize();

    int newX;
    int newY;

    if (null == parent) {
        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();

        newX = (screen.width - windowSize.width) / 2;
        newY = (screen.height - windowSize.height) / 2;
    } else {
        Dimension parentSize = parent.getSize();
        Point loc = parent.getLocation();

        newX = (parentSize.width - windowSize.width) / 2 + loc.x;
        newY = (parentSize.height - windowSize.height) / 2 + loc.y;

        if (0 > newX)
            newX = 0;
        if (0 > newY)
            newY = 0;
    }

    window.setLocation(newX, newY);
    window.setVisible(true);

    return window;
}

From source file:Main.java

public static Window showBelow(Component parent, Window window, int horizontalAlignment) {
    final int DISTANCE = 2;

    if (null == parent)
        throw new IllegalArgumentException("parent null");
    if (null == window)
        throw new IllegalArgumentException("parent null");
    if (!((SwingConstants.LEADING == horizontalAlignment) || (SwingConstants.TRAILING == horizontalAlignment)
            || (SwingConstants.CENTER == horizontalAlignment)
            || (SwingConstants.SOUTH == horizontalAlignment))) {

        throw new IllegalArgumentException("Illegal horizontal alignment " + horizontalAlignment
                + " should be either SwingConstants.LEADING or "
                + "SwingConstants.TRAILING or SwingConstants.CENTER");
    }//from   w w w  . j  av a  2 s.  c om

    window.pack();

    Dimension windowSize = window.getPreferredSize();
    Dimension parentSize = parent.getSize();

    Point loc = parent.getLocationOnScreen();

    int newX;

    if ((SwingConstants.CENTER == horizontalAlignment) || (SwingConstants.SOUTH == horizontalAlignment)) {

        newX = (parentSize.width - windowSize.width) / 2 + loc.x;
    } else if (SwingConstants.TRAILING == horizontalAlignment) {
        newX = loc.x + parentSize.width - windowSize.width;
    } else {
        newX = loc.x;
    }

    window.setLocation(newX, (loc.y + parentSize.height + DISTANCE));

    window.setVisible(true);

    return window;
}

From source file:org.uncommons.watchmaker.swing.evolutionmonitor.EvolutionMonitor.java

/**
 * Helper method for showing the evolution monitor in a frame or dialog.
 * @param newWindow The frame or dialog used to show the evolution monitor.
 *//*from ww  w  .ja va 2 s . c o  m*/
private void showWindow(Window newWindow) {
    if (window != null) {
        window.remove(getGUIComponent());
        window.setVisible(false);
        window.dispose();
        window = null;
    }
    newWindow.add(getGUIComponent(), BorderLayout.CENTER);
    newWindow.pack();
    newWindow.setVisible(true);
    this.window = newWindow;
}

From source file:edu.unc.LCCC.caBIG.DWD.javaCode.visualization.SetUpPlotWindow.java

public void windowClosing(WindowEvent e) {
    Window w = e.getWindow();
    w.setVisible(false);
    w.dispose();
    System.exit(0);
}

From source file:gmgen.GMGenSystem.java

private void mPreferencesActionPerformed(ActionEvent event) {
    Window dialog = new PreferencesDialog(this, true, rootNode);
    dialog.setVisible(true);
}

From source file:io.github.jeddict.reveng.klass.RevEngWizardDescriptor.java

private EntityMappings generateJPAModel(final ProgressReporter reporter, EntityMappings entityMappings,
        final FileObject sourcePackage, final Set<String> entities, final FileObject targetFilePath,
        final String targetFileName, final boolean includeReference, final boolean softWrite,
        final boolean autoOpen) throws IOException, ProcessInterruptedException {

    int progressIndex = 0;
    String progressMsg = getMessage(RevEngWizardDescriptor.class, "MSG_Progress_JPA_Model_Pre"); //NOI18N;
    reporter.progress(progressMsg, progressIndex++);

    List<String> missingEntities = new ArrayList<>();
    SourceExplorer source = new SourceExplorer(sourcePackage, entityMappings, entities, includeReference);
    for (String entityClassFQN : entities) {
        try {/*from  www  .  ja v a  2 s  .  co m*/
            source.createClass(entityClassFQN);
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
            missingEntities.add(entityClassFQN);
        }
    }

    progressIndex = loadJavaClasses(reporter, progressIndex, source.getClasses(), entityMappings);
    List<ClassExplorer> classes = checkReferencedClasses(source, missingEntities, includeReference);
    while (!classes.isEmpty()) {
        progressIndex = loadJavaClasses(reporter, progressIndex, classes, entityMappings);
        classes = checkReferencedClasses(source, missingEntities, includeReference);
    }

    if (!missingEntities.isEmpty()) {
        final String title, _package;
        StringBuilder message = new StringBuilder();
        if (missingEntities.size() == 1) {
            title = "Conflict detected - Entity not found";
            message.append(JavaSourceParserUtil.simpleClassName(missingEntities.get(0))).append(" Entity is ");
        } else {
            title = "Conflict detected - Entities not found";
            message.append("Entities ").append(missingEntities.stream()
                    .map(e -> JavaSourceParserUtil.simpleClassName(e)).collect(toList())).append(" are ");
        }
        if (isEmpty(entityMappings.getPackage())) {
            _package = "<default_root_package>";
        } else {
            _package = entityMappings.getPackage();
        }
        message.append("missing in Project classpath[").append(_package)
                .append("]. \n Would like to cancel the process ?");
        SwingUtilities.invokeLater(() -> {
            JButton cancel = new JButton("Cancel import process (Recommended)");
            JButton procced = new JButton("Procced");
            cancel.addActionListener((ActionEvent e) -> {
                Window w = SwingUtilities.getWindowAncestor(cancel);
                if (w != null) {
                    w.setVisible(false);
                }
                StringBuilder sb = new StringBuilder();
                sb.append('\n').append("You have following option to resolve conflict :").append('\n')
                        .append('\n');
                sb.append(
                        "1- New File > Persistence > JPA Diagram from Reverse Engineering (Manually select entities)")
                        .append('\n');
                sb.append(
                        "2- Recover missing entities manually > Reopen diagram file >  Import entities again");
                NotifyDescriptor nd = new NotifyDescriptor.Message(sb.toString(),
                        NotifyDescriptor.INFORMATION_MESSAGE);
                DialogDisplayer.getDefault().notify(nd);
            });
            procced.addActionListener(e -> {
                Window window = SwingUtilities.getWindowAncestor(cancel);
                if (nonNull(window)) {
                    window.setVisible(false);
                }
                manageEntityMapping(entityMappings);
                if (nonNull(targetFilePath) && nonNull(targetFileName)) {
                    JPAModelerUtil.createNewModelerFile(entityMappings, targetFilePath, targetFileName,
                            softWrite, autoOpen);
                }
            });

            JOptionPane.showOptionDialog(WindowManager.getDefault().getMainWindow(), message.toString(), title,
                    OK_CANCEL_OPTION, ERROR_MESSAGE, UIManager.getIcon("OptionPane.errorIcon"),
                    new Object[] { cancel, procced }, cancel);
        });

    } else {
        manageEntityMapping(entityMappings);
        if (nonNull(targetFilePath) && nonNull(targetFileName)) {
            JPAModelerUtil.createNewModelerFile(entityMappings, targetFilePath, targetFileName, softWrite,
                    autoOpen);
        }
        return entityMappings;
    }

    throw new ProcessInterruptedException();
}

From source file:org.keyboardplaying.xtt.ui.UIController.java

/** Builds and shows the main window. */
public void showMainWindow() {
    /* Create UI. */
    JPanel pane = new JPanel(new GridBagLayout());

    /* Arrange the components */
    GridBagConstraints c;// w ww  .j  a v  a 2 s. c o  m

    c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = 0;
    c.gridwidth = 2;
    c.fill = GridBagConstraints.BOTH;
    pane.add(makeProjectActionButton("action.construct", "action-construct", ImageSize.W_16, constructAction),
            c);

    c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = 1;
    c.gridwidth = 2;
    c.fill = GridBagConstraints.BOTH;
    pane.add(makeProjectActionButton("action.deconstruct", "action-deconstruct", ImageSize.W_16,
            deconstructAction), c);

    c = new GridBagConstraints();
    c.gridx = 2;
    c.gridy = 0;
    c.gridheight = 2;
    c.fill = GridBagConstraints.BOTH;
    pane.add(makeActionButton(null, "icon-settings", ImageSize.W_32, settingsAction), c);

    Window window = makeWindow("app.name", "icon-timetracker", pane);
    window.addWindowListener(new WindowAdapter() {

        /*
         * (non-Javadoc)
         *
         * @see java.awt.event.WindowAdapter#windowClosing(java.awt.event. WindowEvent)
         */
        @Override
        public void windowClosing(WindowEvent e) {
            super.windowClosing(e);
            Frame[] windows = JFrame.getFrames();
            for (Frame w : windows) {
                w.dispose();
            }
        }
    });
    window.setVisible(true);
}

From source file:net.schweerelos.parrot.CombinedParrotApp.java

@SuppressWarnings("serial")
private JToggleButton setupNavigatorButton(final String name, final String accelerator,
        final NavigatorComponent navigator) {
    final Component component = navigator.asJComponent();
    AbstractAction showNavigatorAction = new AbstractAction(name) {
        @Override//from www  .  j av  a 2s .  c  om
        public void actionPerformed(ActionEvent e) {
            if (!(e.getSource() instanceof JToggleButton)) {
                return;
            }
            final Window window;
            if (component instanceof Window) {
                window = (Window) component;
            } else {
                window = SwingUtilities.getWindowAncestor(component);
            }
            JToggleButton button = (JToggleButton) e.getSource();
            boolean show = button.isSelected();
            if (show) {
                if (window != CombinedParrotApp.this && preferredFrameLocations.containsKey(window)) {
                    window.setLocation(preferredFrameLocations.get(window));
                }
            }
            if (navigator.tellSelectionWhenShown()) {
                Collection<NodeWrapper> selectedNodes = activeMainView.getSelectedNodes();
                navigator.setSelectedNodes(selectedNodes);
            }
            component.setVisible(show);
            if (show) {
                window.setVisible(true);
            } else if (window != CombinedParrotApp.this) {
                window.setVisible(false);
            }
        }
    };
    showNavigatorAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control " + accelerator));
    final JToggleButton button = new JToggleButton(showNavigatorAction);
    button.setToolTipText("Show " + name.toLowerCase());
    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            button.setToolTipText((button.isSelected() ? "Hide " : "Show ") + name.toLowerCase());
        }
    });
    final Window window;
    if (component instanceof Window) {
        window = (Window) component;
    } else {
        window = SwingUtilities.getWindowAncestor(component);
    }
    if (window != null) {
        window.addComponentListener(new ComponentAdapter() {
            @Override
            public void componentHidden(ComponentEvent e) {
                button.setSelected(false);
                if (window != CombinedParrotApp.this) {
                    preferredFrameLocations.put(window, window.getLocation());
                }
            }

            @Override
            public void componentShown(ComponentEvent e) {
                button.setSelected(true);
            }
        });
    }
    return button;
}