Example usage for javax.swing SwingUtilities getWindowAncestor

List of usage examples for javax.swing SwingUtilities getWindowAncestor

Introduction

In this page you can find the example usage for javax.swing SwingUtilities getWindowAncestor.

Prototype

public static Window getWindowAncestor(Component c) 

Source Link

Document

Returns the first Window ancestor of c, or null if c is not contained inside a Window.

Usage

From source file:de.tbuchloh.kiskis.gui.widgets.PasswordElement.java

protected void onCreateByTemplate() {
    final Window parent = SwingUtilities.getWindowAncestor(this);
    final PasswordGeneratorDialog dlg = new PasswordGeneratorDialog((Frame) parent);
    dlg.setVisible(true);//  w w w.  jav  a2s  . c  o m
    final String pwd = dlg.getPassword();
    if (pwd != null) {
        _pwdField.setText(pwd);
        fireContentChangedEvent(true);
        updatePwdField();
    }
}

From source file:com.rapidminer.gui.new_plotter.gui.ColorSchemeDialog.java

/**
 * @param key//from www . j  av  a  2s  . c  o  m
 * @param arguments
 */
public ColorSchemeDialog(Component actionComp, String key, PlotConfiguration plotConfig, Object... arguments) {
    super(actionComp != null ? SwingUtilities.getWindowAncestor(actionComp) : null, key,
            ModalityType.APPLICATION_MODAL, arguments);
    this.plotConfig = plotConfig;

    initializing = true;

    nominalColorListModel = new DefaultListModel<Color>();
    gradientStartColorComboBoxModel = new DefaultComboBoxModel<Color>();
    gradientEndColorComboBoxModel = new DefaultComboBoxModel<Color>();
    colorSchemeComboBoxModel = new DefaultComboBoxModel<Object>();

    this.setResizable(false);

    createPreviewPlotBackend(new JPanel().getBackground(),
            plotConfig.getActiveColorScheme().getColors().size());

    createComponents();
    save(plotConfig.getColorSchemes(), plotConfig.getActiveColorScheme().getName());

    initializing = false;

    adaptPreviewPlots();

    setLocationRelativeTo(actionComp);

}

From source file:com.digitalgeneralists.assurance.ui.components.ScanPathMappingPanel.java

private void displayExclusionDialog(FileReference selectedItem) {
    Window parent = SwingUtilities.getWindowAncestor(this.getParent());
    JDialog exclusionDialog = this.dialogFactory.createExclusionDialogInstance(parent,
            ModalityType.APPLICATION_MODAL, this, selectedItem);
    exclusionDialog.setVisible(true);/*  ww  w.  ja v  a 2  s .c om*/
}

From source file:com.digitalgeneralists.assurance.ui.components.ScanLaunchPanel.java

private void displayDefinitionDialog(ScanDefinition selectedItem) {
    Window parent = SwingUtilities.getWindowAncestor(this.getParent());
    JDialog scanDefinitionDialog = this.dialogFactory.createScanDefinitionDialogInstance(parent,
            ModalityType.APPLICATION_MODAL, this, selectedItem);
    scanDefinitionDialog.setVisible(true);
}

From source file:eu.ggnet.dwoss.redtape.document.DocumentUpdateView.java

@Override
public boolean pre(CloseType type) {
    if (type == CloseType.CANCEL)
        return true;
    if (controller == null)
        return true;
    if (customerId == 0) {
        JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(this), "Bitte Kunden whlen");
        return false;
    }/*from   w  w w.  j a  va 2s. com*/
    if (document.getPositions().isEmpty()) {
        JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(this),
                "Ein Dokument muss mindestens eine Position enthalten.");
        return false;
    }

    if (document.getPositions(PositionType.SHIPPING_COST).size() > 1) {
        JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(this),
                "Es sind mehr als eine Position des Types Versandkosten enthalten.");
        return false;
    }
    if (!ValidationUtil.isValidOrShow(SwingUtilities.getWindowAncestor(this), document))
        return false;
    if (accessCos != null) {
        for (Component component : this.getComponents()) {
            accessCos.remove(component);
        }
    }
    if (Client.hasFound(ShippingCostService.class))
        return controller.optionalRecalcShippingCost();
    else
        return true;
}

From source file:de.tbuchloh.kiskis.gui.widgets.PasswordElement.java

protected void onTestPassword() {
    final CrackPasswordDialog dlg = new CrackPasswordDialog((Frame) SwingUtilities.getWindowAncestor(this),
            getPwd());/*from   w ww  . ja v a 2s .  c o  m*/
    dlg.setVisible(true);
}

From source file:Forms.CreateGearForm.java

private void lintSpec(final GearSpec spec) {
    LintGearSpecWorker worker = new LintGearSpecWorker(spec) {
        @Override//from   w  w w .  j  a v a2 s  . c  om
        protected void done() {
            super.done();

            if (result.getPassed()) {
                if (saveSpec(spec)) {
                    JFrame frame = (JFrame) SwingUtilities.getWindowAncestor(MasterPanel);
                    frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
                }
            } else {
                showLintErrorDialog(result);
            }
        }
    };
    worker.execute();
}

From source file:com.floreantpos.customer.DefaultCustomerListView.java

private void closeDialog(boolean canceled) {
    Window windowAncestor = SwingUtilities.getWindowAncestor(DefaultCustomerListView.this);
    if (windowAncestor instanceof POSDialog) {
        ((POSDialog) windowAncestor).setCanceled(false);
        windowAncestor.dispose();/*from  ww  w.j a v a2s  .c  om*/
    }
}

From source file:aurelienribon.gdxsetupui.ui.panels.LibrarySelectionPanel.java

private void browse(String libraryName) {
    File file = libsSelectedFiles.get(libraryName);
    String path = file != null ? file.getPath() : ".";
    JFrame frame = (JFrame) SwingUtilities.getWindowAncestor(this);

    JFileChooser chooser = new JFileChooser(new File(path));
    chooser.setFileFilter(new FileNameExtensionFilter("Zip files (*.zip)", "zip"));
    chooser.setDialogTitle("Please select the zip archive for \"" + libraryName + "\"");

    if (chooser.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) {
        select(libraryName, chooser.getSelectedFile());
    }//from   w w  w .jav a  2  s  . c o m
}

From source file:Forms.CreateGearForm.java

private Boolean saveSpec(GearSpec spec) {

    //Get top level frame
    JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(MasterPanel);

    //Create dialog for choosing gearspec file
    FileDialog fd = new FileDialog(topFrame, "Save .gearspec file", FileDialog.SAVE);
    fd.setDirectory(System.getProperty("user.home"));
    // Gets the name that is specified for the spec in the beginning
    fd.setFile(spec.getName() + ".gearspec");
    fd.setVisible(true);//from   w  ww  . j  ava  2s .c  om
    //Get file
    String filename = fd.getFile();
    if (filename == null) {
        System.out.println("You cancelled the choice");
        return false;
    } else {
        System.out.println("You chose " + filename);

        //Get spec file
        File specFile = new File(fd.getDirectory() + Utils.pathSeparator() + filename);

        //Serialize spec to string
        String gearString = gson.toJson(spec);

        try {
            //If it exists, set it as the selected file path
            if (specFile.exists()) {
                FileUtils.forceDelete(specFile);
            }

            //Write new spec
            FileUtils.write(specFile, gearString);
        } catch (IOException e) {
            e.printStackTrace();
            showSaveErrorDialog();
            return false;
        }

        return true;
    }
}