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:net.sqs2.omr.app.MarkReaderControllerImpl.java

public void userExit() {
    Window window = RemoteWindowDecorator.inactivate(getNetworkPeer().getRMIPort());
    window.setVisible(false);
    try {//from  w ww .  j a  v  a  2 s  .c  o m
        SQSHttpdManager.getEXIgridHttpd().stop();
    } catch (Exception ignore) {
        ignore.printStackTrace();
    }
    userShutdown();
    System.runFinalization();
    System.exit(0);
}

From source file:net.technicpack.launcher.ui.InstallerFrame.java

public InstallerFrame(ResourceLoader resources, StartupParameters params, TechnicSettings settings,
        Window mainFrame) {
    this.settings = settings;
    this.resources = resources;
    this.params = params;
    this.mainFrame = mainFrame;

    mainFrame.setVisible(false);

    addGlassPane();/*from www.  j  a va 2 s.c  o m*/

    relocalize(resources);
}

From source file:org.isatools.isacreatorconfigurator.configui.FieldInterface.java

private void showPopupInCenter(Window container) {
    Container parent = main;/*from w w w .j a  va2s  .c o m*/
    Point parentLocation = parent.getLocationOnScreen();

    Dimension parentSize = parent.getSize();

    int calcedXLoc = (parentLocation.x) + ((parentSize.width) / 2) - (container.getWidth() / 2);
    int calcedYLoc = (parentLocation.y) + ((parentSize.height) / 2) - (container.getHeight() / 2);

    container.setVisible(true);
    container.setLocation(calcedXLoc, calcedYLoc);
    container.toFront();
    container.requestFocusInWindow();
}

From source file:org.netbeans.jpa.modeler.jcre.wizard.RevEngWizardDescriptor.java

public static EntityMappings generateJPAModel(ProgressReporter reporter, Set<String> entities, Project project,
        FileObject packageFileObject, String fileName, boolean includeReference, boolean softWrite,
        boolean autoOpen) throws IOException, ProcessInterruptedException {
    int progressIndex = 0;
    String progressMsg = NbBundle.getMessage(RevEngWizardDescriptor.class, "MSG_Progress_JPA_Model_Pre"); //NOI18N;
    reporter.progress(progressMsg, progressIndex++);

    String version = getModelerFileVersion();

    final EntityMappings entityMappingsSpec = EntityMappings.getNewInstance(version);
    entityMappingsSpec.setGenerated();//from  www.  j a  v  a  2  s  .  co m

    if (!entities.isEmpty()) {
        String entity = entities.iterator().next();
        entityMappingsSpec.setPackage(JavaIdentifiers.getPackageName(entity));
    }

    List<String> missingEntities = new ArrayList<>();
    for (String entityClass : entities) {
        progressMsg = NbBundle.getMessage(RevEngWizardDescriptor.class, "MSG_Progress_JPA_Class_Parsing",
                entityClass + ".java");//NOI18N
        reporter.progress(progressMsg, progressIndex++);
        JPAModelGenerator.generateJPAModel(entityMappingsSpec, project, entityClass, packageFileObject,
                missingEntities);
    }

    if (includeReference) {
        List<ManagedClass> classes = new ArrayList<>(entityMappingsSpec.getEntity());
        // manageSiblingAttribute for MappedSuperClass and Embeddable is not required for (DBRE) DB REV ENG CASE
        classes.addAll(entityMappingsSpec.getMappedSuperclass());
        classes.addAll(entityMappingsSpec.getEmbeddable());

        for (ManagedClass<IPersistenceAttributes> managedClass : classes) {
            for (RelationAttribute attribute : new ArrayList<>(
                    managedClass.getAttributes().getRelationAttributes())) {
                String entityClass = StringUtils.isBlank(entityMappingsSpec.getPackage())
                        ? attribute.getTargetEntity()
                        : entityMappingsSpec.getPackage() + '.' + attribute.getTargetEntity();
                if (!entities.contains(entityClass)) {
                    progressMsg = NbBundle.getMessage(RevEngWizardDescriptor.class,
                            "MSG_Progress_JPA_Class_Parsing", entityClass + ".java");//NOI18N
                    reporter.progress(progressMsg, progressIndex++);
                    JPAModelGenerator.generateJPAModel(entityMappingsSpec, project, entityClass,
                            packageFileObject, missingEntities);
                    entities.add(entityClass);
                }
            }
        }
    }

    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 (StringUtils.isEmpty(entityMappingsSpec.getPackage())) {
            _package = "<default_root_package>";
        } else {
            _package = entityMappingsSpec.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((ActionEvent e) -> {
                Window w = SwingUtilities.getWindowAncestor(cancel);
                if (w != null) {
                    w.setVisible(false);
                }
                manageEntityMappingspec(entityMappingsSpec);
                JPAModelerUtil.createNewModelerFile(entityMappingsSpec, packageFileObject, fileName, 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 {
        manageEntityMappingspec(entityMappingsSpec);
        JPAModelerUtil.createNewModelerFile(entityMappingsSpec, packageFileObject, fileName, softWrite,
                autoOpen);
        return entityMappingsSpec;
    }

    throw new ProcessInterruptedException();
}

From source file:org.opendatakit.briefcase.ui.CharsetConverterDialog.java

private synchronized void updatePreview() {
    final String filePath = getFilePath();
    if (filePath == null || filePath.trim().length() == 0) {
        return;/*w  w  w . j  a  v  a2s.co m*/
    }

    final Window pleaseWaitWindow = ODKOptionPane.showMessageDialog(this, "Creating preview, please wait...");

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            File file = new File(filePath);
            BufferedReader bufferedReader = null;
            try {
                bufferedReader = new BufferedReader(
                        new InputStreamReader(new FileInputStream(file), getCharsetName()));
                List<String> lines = new ArrayList<String>();
                int N = 100;
                String line;
                int c = 0;
                while ((line = bufferedReader.readLine()) != null && c < N) {
                    lines.add(line);
                }

                previewArea.setText(join(lines, LINE_SEPARATOR));
                previewArea.setCaretPosition(0);

            } catch (Exception ex) {
                ex.printStackTrace();

                JOptionPane.showMessageDialog(CharsetConverterDialog.this, ex.getMessage(),
                        "Error reading file...", JOptionPane.ERROR_MESSAGE);
            } finally {
                IOUtils.closeQuietly(bufferedReader);

                pleaseWaitWindow.setVisible(false);
                pleaseWaitWindow.dispose();
            }
        }
    });
}

From source file:org.openmrs.test.BaseContextSensitiveTest.java

/**
 * Utility method for obtaining username and password through Swing interface for tests. Any
 * tests extending the org.openmrs.BaseTest class may simply invoke this method by name.
 * Username and password are returned in a two-member String array. If the user aborts, null is
 * returned. <b> <em>Do not call for non-interactive tests, since this method will try to
 * render an interactive dialog box for authentication!</em></b>
 * /*from w w  w . j ava  2 s .c  om*/
 * @param message string to display above username field
 * @return Two-member String array containing username and password, respectively, or
 *         <code>null</code> if user aborts dialog
 */
public static synchronized String[] askForUsernameAndPassword(String message) {

    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {

    }

    if (message == null || "".equals(message))
        message = "Enter username/password to authenticate to OpenMRS...";

    JPanel panel = new JPanel(new GridBagLayout());
    JLabel usernameLabel = new JLabel("Username");
    usernameLabel.setFont(font);
    usernameField = new JTextField(20);
    usernameField.setFont(font);
    JLabel passwordLabel = new JLabel("Password");
    passwordLabel.setFont(font);
    JPasswordField passwordField = new JPasswordField(20);
    passwordField.setFont(font);
    panel.add(usernameLabel, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.EAST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 5, 0));
    panel.add(usernameField, new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    panel.add(passwordLabel, new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.EAST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 5, 0));
    panel.add(passwordField, new GridBagConstraints(1, 1, 1, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));

    frame = new JFrame();
    Window window = new Window(frame);
    frame.setVisible(true);
    frame.setTitle("JUnit Test Credentials");

    // We use a TimerTask to force focus on username, but still use
    // JOptionPane for model dialog
    TimerTask later = new TimerTask() {

        @Override
        public void run() {
            if (frame != null) {
                // bring the dialog's window to the front
                frame.toFront();
                usernameField.grabFocus();
            }
        }
    };
    // try setting focus half a second from now
    new Timer().schedule(later, 500);

    // attention grabber for those people that aren't as observant
    TimerTask laterStill = new TimerTask() {

        @Override
        public void run() {
            if (frame != null) {
                frame.toFront(); // bring the dialog's window to the
                // front
                usernameField.grabFocus();
            }
        }
    };
    // if the user hasn't done anything in 10 seconds, tell them the window
    // is there
    new Timer().schedule(laterStill, 10000);

    // show the dialog box
    int response = JOptionPane.showConfirmDialog(window, panel, message, JOptionPane.OK_CANCEL_OPTION);

    // clear out the window so the timer doesn't screw up
    laterStill.cancel();
    frame.setVisible(false);
    window.setVisible(false);
    frame = null;

    // response of 2 is the cancel button, response of -1 is the little red
    // X in the top right
    return (response == 2 || response == -1 ? null
            : new String[] { usernameField.getText(), String.valueOf(passwordField.getPassword()) });
}

From source file:org.pentaho.reporting.engine.classic.core.modules.gui.base.PreviewPane.java

private void closeToolbar() {
    if (toolBar == null) {
        return;/*from w w w.j a v a  2 s  .  c  om*/
    }
    if (toolBar.getParent() != toolbarHolder) {
        // ha!, we detected that the toolbar is floating ...
        // Log.debug (currentToolbar.getParent());
        final Window w = SwingUtilities.windowForComponent(toolBar);
        if (w != null) {
            w.setVisible(false);
            w.dispose();
        }
    }
    toolBar.setVisible(false);
}

From source file:processing.app.Base.java

/**
 * Show the About box./*from   w w w  .java2 s .c  o m*/
 */
@SuppressWarnings("serial")
public void handleAbout() {
    final Image image = Theme.getLibImage("about", activeEditor, Theme.scale(475), Theme.scale(300));
    final Window window = new Window(activeEditor) {
        public void paint(Graphics graphics) {
            Graphics2D g = Theme.setupGraphics2D(graphics);
            g.drawImage(image, 0, 0, null);

            Font f = new Font("SansSerif", Font.PLAIN, Theme.scale(11));
            g.setFont(f);
            g.setColor(new Color(0, 151, 156));
            g.drawString(BaseNoGui.VERSION_NAME_LONG, Theme.scale(33), Theme.scale(20));
        }
    };
    window.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            window.dispose();
        }
    });
    int w = image.getWidth(activeEditor);
    int h = image.getHeight(activeEditor);
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    window.setBounds((screen.width - w) / 2, (screen.height - h) / 2, w, h);
    window.setLocationRelativeTo(activeEditor);
    window.setVisible(true);
}

From source file:util.ui.UiUtilities.java

/**
 * Centers a window to its parent frame and shows it.
 * <p>//from   w w w . ja  va2s. com
 * If the window has no parent frame it will be centered to the screen.
 *
 * @param win
 *          The window to center and show.
 */
public static void centerAndShow(Window win) {
    Dimension wD = win.getSize();
    Dimension frameD;
    Point framePos;
    Frame frame = JOptionPane.getFrameForComponent(win);

    // Should this window be centered to its parent frame?
    boolean centerToParentFrame = (frame != null) && (frame != win) && frame.isShowing();

    // Center to parent frame or to screen
    if (centerToParentFrame) {
        frameD = frame.getSize();
        framePos = frame.getLocation();
    } else {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        // dual head, use first screen
        if (ge.getScreenDevices().length > 1) {
            try {
                GraphicsDevice gd = ge.getDefaultScreenDevice();
                GraphicsConfiguration config = gd.getConfigurations()[0];
                frameD = config.getBounds().getSize();
                framePos = config.getBounds().getLocation();
            } catch (RuntimeException e) {
                frameD = Toolkit.getDefaultToolkit().getScreenSize();
                framePos = new Point(0, 0);
            }
        }
        // single screen only
        else {
            frameD = Toolkit.getDefaultToolkit().getScreenSize();
            framePos = new Point(0, 0);
        }
    }

    Point wPos = new Point(framePos.x + (frameD.width - wD.width) / 2,
            framePos.y + (frameD.height - wD.height) / 2);
    wPos.x = Math.max(0, wPos.x); // Make x > 0
    wPos.y = Math.max(0, wPos.y); // Make y > 0
    win.setLocation(wPos);
    win.setVisible(true);
}