Example usage for javax.swing JDialog getContentPane

List of usage examples for javax.swing JDialog getContentPane

Introduction

In this page you can find the example usage for javax.swing JDialog getContentPane.

Prototype

public Container getContentPane() 

Source Link

Document

Returns the contentPane object for this dialog.

Usage

From source file:Main.java

/**
 * Initialises the {@link JDialog} for the {@link JComponent}.
 * /*from  w  w  w .j av  a 2s.co  m*/
 * @param dialog
 * @param component
 * @param parentComponent
 */
private static void initDialog(final JDialog dialog, final JComponent component,
        final Component parentComponent) {
    dialog.setResizable(true);
    dialog.setComponentOrientation(component.getComponentOrientation());
    Container contentPane = dialog.getContentPane();

    contentPane.setLayout(new BorderLayout());
    contentPane.add(component, BorderLayout.CENTER);

    final int buttonWidth = 75;

    final JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
    buttonPanel.setBorder(BorderFactory.createEmptyBorder(2, 4, 4, 4));

    buttonPanel.add(Box.createHorizontalGlue());

    @SuppressWarnings("serial")
    final Action closeAction = new AbstractAction("Close") {
        @Override
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    };

    final JButton button = new JButton(closeAction);
    fixWidth(button, buttonWidth);
    buttonPanel.add(button);

    contentPane.add(buttonPanel, BorderLayout.SOUTH);

    if (JDialog.isDefaultLookAndFeelDecorated()) {
        boolean supportsWindowDecorations = UIManager.getLookAndFeel().getSupportsWindowDecorations();
        if (supportsWindowDecorations) {
            dialog.setUndecorated(true);
            component.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
        }
    }
    dialog.pack();
    dialog.setLocationRelativeTo(parentComponent);
    WindowAdapter adapter = new WindowAdapter() {
        //         private boolean gotFocus = false;
        public void windowClosing(WindowEvent we) {
            fireAction(we.getSource(), closeAction, "close");
        }
    };
    dialog.addWindowListener(adapter);
    dialog.addWindowFocusListener(adapter);
}

From source file:com.limegroup.gnutella.gui.GUIUtils.java

/**
 * Adds a hide action to a JDialog./*from   w  w w.j a  va 2s  .c o m*/
 */
public static void addHideAction(JDialog jd) {
    addHideAction((JComponent) jd.getContentPane());
}

From source file:Main.java

/**
 * Adds a glass layer to the dialog to intercept all key events. If the
 * espace key is pressed, the dialog is disposed (either with a fadeout
 * animation, or directly)./* w ww  . j a  v  a  2s.c o  m*/
 */
public static void addEscapeToCloseSupport(final JDialog dialog) {
    LayerUI<Container> layerUI = new LayerUI<Container>() {

        private boolean closing = false;

        @Override
        public void installUI(JComponent c) {
            super.installUI(c);
            ((JLayer) c).setLayerEventMask(AWTEvent.KEY_EVENT_MASK);
        }

        @Override
        public void uninstallUI(JComponent c) {
            super.uninstallUI(c);
            ((JLayer) c).setLayerEventMask(0);
        }

        @Override
        public void eventDispatched(AWTEvent e, JLayer<? extends Container> l) {
            if (e instanceof KeyEvent && ((KeyEvent) e).getKeyCode() == KeyEvent.VK_ESCAPE) {
                if (closing) {
                    return;
                }
                closing = true;
                fadeOut(dialog);
            }
        }
    };

    JLayer<Container> layer = new JLayer<Container>(dialog.getContentPane(), layerUI);
    dialog.setContentPane(layer);
}

From source file:ca.nengo.ui.util.DialogPlotter.java

@Override
protected void showChart(JFreeChart chart, String title) {
    JPanel panel = new ChartPanel(chart);

    JDialog dialog = new JDialog(parent, title);
    dialog.getContentPane().add(panel, BorderLayout.CENTER);

    dialog.pack();/*from ww w  .  ja v a 2 s .  c  o m*/
    dialog.setVisible(true);
}

From source file:Modelos.Grafica.java

public ChartPanel mostrarGrafica(Window owner) {
    ChartPanel panel = new ChartPanel(chart);
    JDialog ventana;
    ventana = new JDialog(owner, "Grafica");
    ventana.getContentPane().add(panel);
    ventana.pack();/*w ww  .  j av a2 s .  c  om*/
    ventana.setVisible(true);
    //ventana.dispose();
    ventana.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    return panel;
}

From source file:Main.java

/**
 * Adds a glass layer to the dialog to intercept all key events. If the
 * espace key is pressed, the dialog is disposed (either with a fadeout
 * animation, or directly)./*from   w  w w. ja  v  a  2 s  .c om*/
 */
public static void addEscapeToCloseSupport(final JDialog dialog, final boolean fadeOnClose) {
    LayerUI<Container> layerUI = new LayerUI<Container>() {
        private boolean closing = false;

        @Override
        public void installUI(JComponent c) {
            super.installUI(c);
            ((JLayer) c).setLayerEventMask(AWTEvent.KEY_EVENT_MASK);
        }

        @Override
        public void uninstallUI(JComponent c) {
            super.uninstallUI(c);
            ((JLayer) c).setLayerEventMask(0);
        }

        @Override
        public void eventDispatched(AWTEvent e, JLayer<? extends Container> l) {
            if (e instanceof KeyEvent && ((KeyEvent) e).getKeyCode() == KeyEvent.VK_ESCAPE) {
                if (closing)
                    return;
                closing = true;
                if (fadeOnClose)
                    fadeOut(dialog);
                else
                    dialog.dispose();
            }
        }
    };

    JLayer<Container> layer = new JLayer<>(dialog.getContentPane(), layerUI);
    dialog.setContentPane(layer);
}

From source file:IHM.GialogGraph.java

public void Show() {
    VisualizationViewer<String, String> vv;
    vv = new VisualizationViewer<>(new CircleLayout<String, String>(JungGraph), dim);

    Transformer<String, String> transformer = new Transformer<String, String>() {
        @Override/*from   ww  w . ja va 2 s . co m*/
        public String transform(String arg0) {
            return arg0;
        }
    };
    vv.getRenderContext().setVertexLabelTransformer(transformer);
    transformer = new Transformer<String, String>() {
        @Override
        public String transform(String arg0) {
            return arg0;
        }
    };
    vv.getRenderContext().setEdgeLabelTransformer(transformer);
    vv.getRenderer().setVertexRenderer(new MyRenderer());
    DefaultModalGraphMouse<String, Number> graphMouse = new DefaultModalGraphMouse<String, Number>();
    vv.setGraphMouse(graphMouse);
    graphMouse.setMode(ModalGraphMouse.Mode.PICKING);

    JDialog frame = new JDialog(MymainWidow);
    frame.getContentPane().add(vv);
    frame.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    frame.addWindowListener(new WindowListener() {

        @Override
        public void windowOpened(WindowEvent e) {

        }

        @Override
        public void windowClosing(WindowEvent e) {
            MymainWidow.enable();
        }

        @Override
        public void windowClosed(WindowEvent e) {
            MymainWidow.enable();
        }

        @Override
        public void windowIconified(WindowEvent e) {

        }

        @Override
        public void windowDeiconified(WindowEvent e) {

        }

        @Override
        public void windowActivated(WindowEvent e) {

        }

        @Override
        public void windowDeactivated(WindowEvent e) {

        }
    });
    frame.pack();
    frame.setLocationRelativeTo(MymainWidow);
    frame.setResizable(true);
    frame.setVisible(true);
}

From source file:org.yccheok.jstock.gui.charting.DynamicChart.java

public void showNewJDialog(java.awt.Frame parent, String title) {
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(this.price);

    JFreeChart freeChart = ChartFactory.createTimeSeriesChart(title, GUIBundle.getString("DynamicChart_Date"),
            GUIBundle.getString("DynamicChart_Price"), dataset, true, true, false);

    freeChart.setAntiAlias(true);//from   w w w.j  av a 2s  .c o m

    XYPlot plot = freeChart.getXYPlot();
    NumberAxis rangeAxis1 = (NumberAxis) plot.getRangeAxis();
    DecimalFormat format = new DecimalFormat("00.00");
    rangeAxis1.setNumberFormatOverride(format);

    XYItemRenderer renderer1 = plot.getRenderer();
    renderer1.setBaseToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("h:mm:ss a"), new DecimalFormat("0.00#")));

    org.yccheok.jstock.charting.Utils.applyChartTheme(freeChart);

    ChartPanel _chartPanel = new ChartPanel(freeChart, true, true, true, true, true);
    JDialog dialog = new JDialog(parent, title, false);
    dialog.getContentPane().add(_chartPanel, java.awt.BorderLayout.CENTER);
    dialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    final java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    dialog.setBounds((screenSize.width - 750) >> 1, (screenSize.height - 600) >> 1, 750, 600);
    dialog.setVisible(true);
}

From source file:net.sf.jabref.util.Util.java

/**
 * Automatically add links for this set of entries, based on the globally stored list of external file types. The
 * entries are modified, and corresponding UndoEdit elements added to the NamedCompound given as argument.
 * Furthermore, all entries which are modified are added to the Set of entries given as an argument.
 * <p>//w ww . j  av a 2 s.  c o  m
 * The entries' bibtex keys must have been set - entries lacking key are ignored. The operation is done in a new
 * thread, which is returned for the caller to wait for if needed.
 *
 * @param entries          A collection of BibEntry objects to find links for.
 * @param ce               A NamedCompound to add UndoEdit elements to.
 * @param changedEntries   MODIFIED, optional. A Set of BibEntry objects to which all modified entries is added.
 *                         This is used for status output and debugging
 * @param singleTableModel UGLY HACK. The table model to insert links into. Already existing links are not
 *                         duplicated or removed. This parameter has to be null if entries.count() != 1. The hack has been
 *                         introduced as a bibtexentry does not (yet) support the function getListTableModel() and the
 *                         FileListEntryEditor editor holds an instance of that table model and does not reconstruct it after the
 *                         search has succeeded.
 * @param metaData         The MetaData providing the relevant file directory, if any.
 * @param callback         An ActionListener that is notified (on the event dispatch thread) when the search is finished.
 *                         The ActionEvent has id=0 if no new links were added, and id=1 if one or more links were added. This
 *                         parameter can be null, which means that no callback will be notified.
 * @param diag             An instantiated modal JDialog which will be used to display the progress of the autosetting. This
 *                         parameter can be null, which means that no progress update will be shown.
 * @return the thread performing the autosetting
 */
public static Runnable autoSetLinks(final Collection<BibEntry> entries, final NamedCompound ce,
        final Set<BibEntry> changedEntries, final FileListTableModel singleTableModel, final MetaData metaData,
        final ActionListener callback, final JDialog diag) {
    final Collection<ExternalFileType> types = ExternalFileTypes.getInstance().getExternalFileTypeSelection();
    if (diag != null) {
        final JProgressBar prog = new JProgressBar(JProgressBar.HORIZONTAL, 0, types.size() - 1);
        final JLabel label = new JLabel(Localization.lang("Searching for files"));
        prog.setIndeterminate(true);
        prog.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        diag.setTitle(Localization.lang("Autosetting links"));
        diag.getContentPane().add(prog, BorderLayout.CENTER);
        diag.getContentPane().add(label, BorderLayout.SOUTH);

        diag.pack();
        diag.setLocationRelativeTo(diag.getParent());
    }

    Runnable r = new Runnable() {

        @Override
        public void run() {
            // determine directories to search in
            List<File> dirs = new ArrayList<>();
            List<String> dirsS = metaData.getFileDirectory(Globals.FILE_FIELD);
            for (String dirs1 : dirsS) {
                dirs.add(new File(dirs1));
            }

            // determine extensions
            Collection<String> extensions = new ArrayList<>();
            for (final ExternalFileType type : types) {
                extensions.add(type.getExtension());
            }

            // Run the search operation:
            Map<BibEntry, List<File>> result;
            if (Globals.prefs.getBoolean(JabRefPreferences.AUTOLINK_USE_REG_EXP_SEARCH_KEY)) {
                String regExp = Globals.prefs.get(JabRefPreferences.REG_EXP_SEARCH_EXPRESSION_KEY);
                result = RegExpFileSearch.findFilesForSet(entries, extensions, dirs, regExp);
            } else {
                result = FileUtil.findAssociatedFiles(entries, extensions, dirs);
            }

            boolean foundAny = false;
            // Iterate over the entries:
            for (Entry<BibEntry, List<File>> entryFilePair : result.entrySet()) {
                FileListTableModel tableModel;
                String oldVal = entryFilePair.getKey().getField(Globals.FILE_FIELD);
                if (singleTableModel == null) {
                    tableModel = new FileListTableModel();
                    if (oldVal != null) {
                        tableModel.setContent(oldVal);
                    }
                } else {
                    assert entries.size() == 1;
                    tableModel = singleTableModel;
                }
                List<File> files = entryFilePair.getValue();
                for (File f : files) {
                    f = FileUtil.shortenFileName(f, dirsS);
                    boolean alreadyHas = false;
                    //System.out.println("File: "+f.getPath());
                    for (int j = 0; j < tableModel.getRowCount(); j++) {
                        FileListEntry existingEntry = tableModel.getEntry(j);
                        //System.out.println("Comp: "+existingEntry.getLink());
                        if (new File(existingEntry.link).equals(f)) {
                            alreadyHas = true;
                            break;
                        }
                    }
                    if (!alreadyHas) {
                        foundAny = true;
                        ExternalFileType type;
                        Optional<String> extension = FileUtil.getFileExtension(f);
                        if (extension.isPresent()) {
                            type = ExternalFileTypes.getInstance().getExternalFileTypeByExt(extension.get());
                        } else {
                            type = new UnknownExternalFileType("");
                        }
                        FileListEntry flEntry = new FileListEntry(f.getName(), f.getPath(), type);
                        tableModel.addEntry(tableModel.getRowCount(), flEntry);

                        String newVal = tableModel.getStringRepresentation();
                        if (newVal.isEmpty()) {
                            newVal = null;
                        }
                        if (ce != null) {
                            // store undo information
                            UndoableFieldChange change = new UndoableFieldChange(entryFilePair.getKey(),
                                    Globals.FILE_FIELD, oldVal, newVal);
                            ce.addEdit(change);
                        }
                        // hack: if table model is given, do NOT modify entry
                        if (singleTableModel == null) {
                            entryFilePair.getKey().setField(Globals.FILE_FIELD, newVal);
                        }
                        if (changedEntries != null) {
                            changedEntries.add(entryFilePair.getKey());
                        }
                    }
                }
            }

            // handle callbacks and dialog
            // FIXME: The ID signals if action was successful :/
            final int id = foundAny ? 1 : 0;
            SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                    if (diag != null) {
                        diag.dispose();
                    }
                    if (callback != null) {
                        callback.actionPerformed(new ActionEvent(this, id, ""));
                    }
                }
            });
        }
    };
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            // show dialog which will be hidden when the task is done
            if (diag != null) {
                diag.setVisible(true);
            }
        }
    });
    return r;
}

From source file:es.emergya.ui.base.Message.java

private void inicializar(final String texto) {
    log.trace("inicializar(" + texto + ")");
    final Message message_ = this;

    SwingUtilities.invokeLater(new Runnable() {

        @Override//from  ww  w  .  j  a  v a 2 s.  c  o  m
        public void run() {
            log.trace("Sacamos un nuevo mensaje: " + texto);
            JDialog frame = new JDialog(window.getFrame(), true);
            frame.setUndecorated(true);
            frame.getContentPane().setBackground(Color.WHITE);
            frame.setLocation(150, window.getHeight() - 140);
            frame.setSize(new Dimension(window.getWidth() - 160, 130));
            frame.setName("Incoming Message");
            frame.setBackground(Color.WHITE);
            frame.getRootPane().setBorder(new MatteBorder(4, 4, 4, 4, color));

            frame.setLayout(new BorderLayout());
            if (font != null)
                frame.setFont(font);

            JLabel icon = new JLabel(new ImageIcon(this.getClass().getResource("/images/button-ok.png")));
            icon.setToolTipText("Cerrar");

            icon.removeMouseListener(null);
            icon.addMouseListener(new Cerrar(frame, message_));

            JLabel text = new JLabel(texto);
            text.setBackground(Color.WHITE);
            text.setForeground(Color.BLACK);
            frame.add(text, BorderLayout.WEST);
            frame.add(icon, BorderLayout.EAST);

            frame.setVisible(true);
        }
    });
}