1 | // Jomic - a viewer for comic book archives. |
2 | // Copyright (C) 2004-2011 Thomas Aglassinger |
3 | // |
4 | // This program 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 3 of the License, or |
7 | // (at your option) any later version. |
8 | // |
9 | // This program 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 program. If not, see <http://www.gnu.org/licenses/>. |
16 | package net.sf.jomic.tools; |
17 | |
18 | import java.net.MalformedURLException; |
19 | import java.net.URL; |
20 | |
21 | import javax.swing.JOptionPane; |
22 | |
23 | /** |
24 | * Exception to be thrown if a component is missing, but can be downloaded from somewhere. |
25 | * |
26 | * @author Thomas Aglassinger |
27 | */ |
28 | public class ItemMustBeDownloadedException extends RuntimeException |
29 | { |
30 | private LocaleTools localeTools; |
31 | private URL uri; |
32 | |
33 | public ItemMustBeDownloadedException(String newMessage, String newUri) { |
34 | super(newMessage); |
35 | assert newUri != null; |
36 | localeTools = LocaleTools.instance(); |
37 | try { |
38 | uri = new URL(newUri); |
39 | } catch (MalformedURLException error) { |
40 | String message = localeTools.getMessage("errors.cannotParseUrl", newUri); |
41 | IllegalArgumentException error2 = new IllegalArgumentException(message); |
42 | |
43 | error2.initCause(error); |
44 | throw error2; |
45 | } |
46 | } |
47 | |
48 | /** |
49 | * Show dialog with a "Go to download page" button. |
50 | */ |
51 | public void show(String title) { |
52 | String goToDownloadPage = localeTools.getMessage("buttons.goToDownloadPage"); |
53 | String cancel = localeTools.getCancelText(); |
54 | Object[] options = {goToDownloadPage, cancel}; |
55 | int selection = |
56 | JOptionPane.showOptionDialog( |
57 | null, |
58 | getMessage(), |
59 | title, |
60 | JOptionPane.YES_NO_OPTION, |
61 | JOptionPane.ERROR_MESSAGE, |
62 | null, |
63 | options, |
64 | options[0]); |
65 | |
66 | if (selection == JOptionPane.YES_OPTION) { |
67 | SystemTools.instance().openURL(uri.toString()); |
68 | } |
69 | } |
70 | |
71 | /** |
72 | * Show dialog with a "Go to download page" button. |
73 | */ |
74 | public void show() { |
75 | String title = ErrorTools.instance().getTitle(JOptionPane.ERROR_MESSAGE); |
76 | |
77 | show(title); |
78 | } |
79 | } |