-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0960815
commit eab2f9f
Showing
4 changed files
with
145 additions
and
76 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
core/launcher/src/main/java/org/phoebus/product/LaunchErrorDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (C) 2024 European Spallation Source ERIC. | ||
*/ | ||
|
||
package org.phoebus.product; | ||
|
||
import javax.swing.*; | ||
import javax.swing.border.EmptyBorder; | ||
import java.awt.*; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.PrintStream; | ||
import java.io.PrintWriter; | ||
import java.io.StringWriter; | ||
|
||
/** | ||
* Minimal Swing dialog showing an error message as extracted from | ||
* an {@link Exception}. | ||
*/ | ||
public class LaunchErrorDialog extends JFrame { | ||
|
||
/** | ||
* Access method. | ||
* @param exception The {@link Exception} from which to | ||
* extract text shown in the dialog. | ||
*/ | ||
public static void show(Exception exception){ | ||
new LaunchErrorDialog(exception).setVisible(true); | ||
} | ||
|
||
private LaunchErrorDialog(Exception exception){ | ||
setSize(600, 300); | ||
setTitle(Messages.launchErrorTitle); | ||
String message = exception.getMessage(); | ||
// If there is no exception message, use stack track instead | ||
if(message == null) { | ||
StringWriter stringWriter = new StringWriter(); | ||
PrintWriter printWriter = new PrintWriter(stringWriter); | ||
exception.printStackTrace(printWriter); | ||
message = stringWriter.toString(); | ||
} | ||
JTextArea jTextArea = new JTextArea(message); | ||
jTextArea.setBorder(new EmptyBorder(10, 10, 10, 10)); | ||
jTextArea.setLineWrap(true); | ||
add(jTextArea, BorderLayout.CENTER); | ||
// Exit when the JFrame is closed | ||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
// Center on screen | ||
setLocationRelativeTo(null); | ||
setVisible(true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
core/launcher/src/main/java/org/phoebus/product/Messages.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (C) 2019 European Spallation Source ERIC. | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
* | ||
*/ | ||
|
||
package org.phoebus.product; | ||
|
||
import org.phoebus.framework.nls.NLS; | ||
|
||
public class Messages { | ||
|
||
static | ||
{ | ||
// initialize resource bundle | ||
NLS.initializeMessages(Messages.class); | ||
} | ||
|
||
private Messages() | ||
{ | ||
} | ||
|
||
public static String launchErrorTitle; | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
core/launcher/src/main/resources/org/phoebus/product/messages.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# | ||
# Copyright (C) 2024 European Spallation Source ERIC. | ||
# | ||
|
||
launchErrorTitle=Launch Failed |