001/* 002 * Copyright 2010-2015 Institut Pasteur. 003 * 004 * This file is part of Icy. 005 * 006 * Icy is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * Icy is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with Icy. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package icy.gui.frame; 020 021import icy.gui.dialog.ConfirmDialog; 022 023import javax.swing.JDialog; 024import javax.swing.JOptionPane; 025 026/** 027 * ConfirmFrame class.<br> 028 * Almost same as ConfirmDialog except it is not modal so you have to check<br> 029 * for both <code>ready()</code> and <code>confirmed()</code> methods. 030 * 031 * @author Stephane 032 */ 033public class ConfirmFrame extends JOptionPane 034{ 035 /** 036 * 037 */ 038 private static final long serialVersionUID = 2833505262575458420L; 039 040 public ConfirmFrame(final String title, final String message, final int optionType) 041 { 042 super(message, JOptionPane.QUESTION_MESSAGE, optionType); 043 044 setInitialValue(initialValue); 045 setComponentOrientation(getRootFrame().getComponentOrientation()); 046 JDialog dialog = createDialog(null, title); 047 dialog.setModal(false); 048 dialog.setAlwaysOnTop(true); 049 050 selectInitialValue(); 051 dialog.show(); 052 } 053 054 public ConfirmFrame(final String title, final String message) 055 { 056 this(title, message, YES_NO_OPTION); 057 } 058 059 public ConfirmFrame(final String message) 060 { 061 this("Confirmation", message, YES_NO_OPTION); 062 } 063 064 /** 065 * Return true if user confirmed 066 */ 067 public boolean confirmed() 068 { 069 final Object v = getValue(); 070 071 if (v instanceof Integer) 072 return ConfirmDialog.getBooleanReturnValue(((Integer) v).intValue()); 073 074 return false; 075 } 076 077 /** 078 * Return true if user made choice. 079 */ 080 public boolean ready() 081 { 082 return (getValue() != JOptionPane.UNINITIALIZED_VALUE); 083 } 084}