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