/* Copyright @ 2001-2002, The Institute for Genomic Research (TIGR). All rights reserved. This software is provided "AS IS". TIGR makes no warranties, express or implied, including no representation or warranty with respect to the performance of the software and derivatives or their safety, effectiveness, or commercial viability. TIGR does not warrant the merchantability or fitness of the software and derivatives for any particular purpose, or that they may be exploited without infringing the copyrights, patent rights or property rights of others. TIGR shall not be liable for any claim, demand or action for any loss, harm, illness or other damage or injury arising from access to or use of the software or associated information, including without limitation any direct, indirect, incidental, exemplary, special or consequential damages. This software program may not be sold, leased, transferred, exported or otherwise disclaimed to anyone, in whole or in part, without the prior written consent of TIGR. */ /* * $RCSfile: ConfirmUsers.java,v $ * $Revision: 1.3 $ * $Date: 2005/01/12 21:07:10 $ * $Author: jli $ * $State: Exp $ */ /*************************************************************************** * Author: Jerry Li * Copyright: TIGR 2002-2004 * Date: Created: 02/07/2003 and modified: 02/07/2003 * Descp: presents a dialog to users for confirmation. ***************************************************************************/ package org.tigr.util; import java.awt.Dimension; import java.awt.GridBagLayout; import java.awt.Toolkit; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.border.BevelBorder; import org.tigr.util.awt.GBA; public class ConfirmUsers extends JDialog implements ActionListener{ public static int YES_NO = 1; public static int YES_NO_HELP = 2; public static int YES_ALL_NO_CANCEL = 3; public static int YES_NO_CANCEL = 4; private JPanel messagePL, buttonPL; private JTextArea infoBoard; private JButton yesBtn, noBtn, yesAllBtn, cancelBtn; public JButton helpBtn; private Dimension screenSize; private GBA gba; private String info; private int confirm, showBtn; private final int NO_FILE = 0; private final int ONE_FILE = 1; private final int ALL_FILES = 2; private final int QUIT = -1; public ConfirmUsers (JFrame frame, String title, String msg, boolean modal) { super(frame, title, modal); info = new String(msg); showBtn = 0; confirm = -1; makeFace(); } public ConfirmUsers (JFrame frame, String title, String msg, int buttonPolicy, boolean modal) { super(frame, title, modal); showBtn = buttonPolicy; info = new String(msg); confirm = -1; makeFace(); } /**************************************************************************** * METHOD: makeFace * DESCREPTION: creates a window * PARAMETERS: str --- the message that will be showed. * RETURNED: nothing. ***************************************************************************/ public void makeFace() { int sizeX, sizeY, btnWide, btnHigh, x, y; gba = new GBA(); BevelBorder high = new BevelBorder(0); sizeX = 400; sizeY = 150; btnWide = 65; btnHigh = 23; addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent we){ confirm = QUIT; cancel(); } }); messagePL = new JPanel(new GridBagLayout()); buttonPL = new JPanel(new GridBagLayout()); buttonPL.setSize(sizeX, btnHigh + 6); buttonPL.setPreferredSize(buttonPL.getSize()); infoBoard = new JTextArea(info); infoBoard.setPreferredSize(new Dimension(sizeX, sizeY)); infoBoard.setBackground(this.getBackground()); infoBoard.setCaretColor(this.getBackground()); infoBoard.setEditable(false); infoBoard.setWrapStyleWord(true); infoBoard.setLineWrap(true); yesBtn = new JButton ("Yes"); yesBtn.setBorder(high); yesBtn.setPreferredSize(new Dimension(btnWide, btnHigh)); yesBtn.addActionListener(this); yesAllBtn = new JButton ("Yes to All"); yesAllBtn.setBorder(high); yesAllBtn.setPreferredSize(new Dimension(btnWide, btnHigh)); yesAllBtn.addActionListener(this); noBtn = new JButton ("No"); noBtn.setBorder(high); noBtn.setPreferredSize(new Dimension(btnWide, btnHigh)); noBtn.addActionListener(this); cancelBtn = new JButton ("Cancel"); cancelBtn.setBorder(high); cancelBtn.setPreferredSize(new Dimension(btnWide, btnHigh)); cancelBtn.addActionListener(this); helpBtn = new JButton ("Help"); helpBtn.setBorder(high); helpBtn.setPreferredSize(new Dimension(btnWide, btnHigh)); this.getContentPane().add(messagePL); gba.add(messagePL, infoBoard, 0, 0, 1, 1, 1, 1, GBA.B, GBA.C, 15, 10, 5, 10); gba.add(messagePL, buttonPL, 0, 1, 1, 1, 1, 1, GBA.B, GBA.C, 5, 5, 5, 5); gba.add(buttonPL, yesBtn, 0, 0, 1, 1, 0, 0, GBA.NONE, GBA.C, 0, 5, 0, 3); gba.add(buttonPL, noBtn, 2, 0, 1, 1, 0, 0, GBA.NONE, GBA.C, 0, 3, 0, 3); if(showBtn == YES_ALL_NO_CANCEL){ gba.add(buttonPL, yesAllBtn, 1, 0, 1, 1, 0, 0, GBA.NONE, GBA.C, 0, 3, 0, 3); gba.add(buttonPL, cancelBtn, 3, 0, 1, 1, 0, 0, GBA.NONE, GBA.C, 0, 3, 0, 3); } else if(showBtn == YES_NO){ } else if(showBtn == YES_NO_CANCEL){ gba.add(buttonPL, cancelBtn, 3, 0, 1, 1, 0, 0, GBA.NONE, GBA.C, 0, 3, 0, 3); } else if(showBtn == YES_NO_HELP){ gba.add(buttonPL, helpBtn, 4, 0, 1, 1, 0, 0, GBA.NONE, GBA.C, 0, 3, 0, 5); } else { gba.add(buttonPL, yesAllBtn, 1, 0, 1, 1, 0, 0, GBA.NONE, GBA.C, 0, 3, 0, 3); gba.add(buttonPL, cancelBtn, 3, 0, 1, 1, 0, 0, GBA.NONE, GBA.C, 0, 3, 0, 3); gba.add(buttonPL, helpBtn, 4, 0, 1, 1, 0, 0, GBA.NONE, GBA.C, 0, 3, 0, 5); } resize(sizeX, sizeY + buttonPL.getHeight()); screenSize = Toolkit.getDefaultToolkit().getScreenSize(); x = (screenSize.width-sizeX)>>1; y = (screenSize.height-sizeY)>>1; setLocation(x, y); setResizable(false); show(); pack(); } public void actionPerformed(ActionEvent ae){ if(ae.getSource() == yesBtn){ confirm = ONE_FILE; } else if (ae.getSource() == yesAllBtn){ confirm = ALL_FILES; } else if(ae.getSource() == noBtn){ confirm = NO_FILE; } cancel(); } public void cancel() { this.setVisible(false); dispose(); } public int getConfirmed() { return confirm; } }