Adam Tkac | 9219c82 | 2010-11-11 14:32:24 +0000 | [diff] [blame^] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
| 2 | * |
| 3 | * This is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This software is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this software; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 16 | * USA. |
| 17 | */ |
| 18 | |
| 19 | package com.tigervnc.vncviewer; |
| 20 | |
| 21 | import java.awt.*; |
| 22 | |
| 23 | public class MessageBox extends com.tigervnc.vncviewer.Dialog { |
| 24 | |
| 25 | public static final int MB_OK = 0; |
| 26 | public static final int MB_OKAYCANCEL = 1; |
| 27 | public static final int MB_YESNO = 2; |
| 28 | |
| 29 | public MessageBox(String msg, int flags) { |
| 30 | super(true); |
| 31 | GridLayout g = new GridLayout(0,1); |
| 32 | setLayout(g); |
| 33 | while (true) { |
| 34 | int i = msg.indexOf('\n'); |
| 35 | int j = (i==-1) ? msg.length() : i; |
| 36 | add(new Label(msg.substring(0, j))); |
| 37 | if (i==-1) break; |
| 38 | msg = msg.substring(j+1); |
| 39 | } |
| 40 | Panel p2 = new Panel(); |
| 41 | switch (flags & 3) { |
| 42 | case MB_OKAYCANCEL: |
| 43 | cancelButton = new Button("Cancel"); |
| 44 | // No break |
| 45 | case MB_OK: |
| 46 | okButton = new Button("OK"); |
| 47 | break; |
| 48 | case MB_YESNO: |
| 49 | okButton = new Button("Yes"); |
| 50 | cancelButton = new Button("No"); |
| 51 | break; |
| 52 | } |
| 53 | if (okButton != null) p2.add(okButton); |
| 54 | if (cancelButton != null) p2.add(cancelButton); |
| 55 | add("South", p2); |
| 56 | pack(); |
| 57 | showDialog(); |
| 58 | } |
| 59 | |
| 60 | public MessageBox(String msg) { |
| 61 | this(msg, MB_OK); |
| 62 | } |
| 63 | |
| 64 | |
| 65 | public boolean action(Event event, Object arg) { |
| 66 | if (event.target == okButton) { |
| 67 | ok = true; |
| 68 | endDialog(); |
| 69 | } else if (event.target == cancelButton) { |
| 70 | ok = false; |
| 71 | endDialog(); |
| 72 | } |
| 73 | return true; |
| 74 | } |
| 75 | |
| 76 | Button okButton, cancelButton; |
| 77 | |
| 78 | public boolean result() { |
| 79 | return ok; |
| 80 | } |
| 81 | |
| 82 | } |