Skip to content

Commit

Permalink
Merge branch 'uri'
Browse files Browse the repository at this point in the history
  • Loading branch information
bengtmartensson committed Mar 17, 2024
2 parents bd32213 + abeef40 commit 7ed66df
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 35 deletions.
8 changes: 6 additions & 2 deletions src/main/java/org/harctoolbox/guicomponents/GuiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,14 @@ public boolean confirm(String message, int optionType) {
// rationale: too easy to confuse file names and URLs,
// thereby too error prone.

public void browse(File file) throws MalformedURLException, URISyntaxException {
public void browse(File file) {
browse(file.toURI());
}

public void browse(URL url) throws URISyntaxException {
browse(url.toURI());
}

@SuppressWarnings("UseOfSystemOutOrSystemErr")
public void browse(URI uri) {
if (uri == null || uri.toString().isEmpty()) {
Expand Down Expand Up @@ -300,7 +304,7 @@ else if (Desktop.isDesktopSupported())
*/
public void open(File file) throws IOException {
if (useXdbOpen)
xdgOpen(file.getAbsolutePath());
xdgOpen(file.toURI().toString());
else if (Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) {
try {
Desktop.getDesktop().open(file);
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/org/harctoolbox/guicomponents/HelpPopup.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,16 @@
*/
public class HelpPopup extends javax.swing.JDialog {

private static String baseUrl = null;
private static URL baseUrl = null;

public static void setBaseUrl(String newBaseUrl) {
public static void setBaseUrl(URL newBaseUrl) {
baseUrl = newBaseUrl;
}

public static void setBaseUrl(File file) throws MalformedURLException {
setBaseUrl(file.toURI().toURL());
}

private final String payload;
private final boolean isHtml;
private final GuiUtils guiUtils;
Expand All @@ -71,18 +75,16 @@ private HelpPopup(Window parent, String helpText, boolean isHtml, String title)
textPane.addHyperlinkListener((HyperlinkEvent e) -> {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
try {
URL url = e.getURL();
if (url == null)
url = new URL(baseUrl + e.getDescription());
guiUtils.browse(url.toURI());
URL url = e.getURL() != null ? e.getURL() : new URL(baseUrl, e.getDescription());
guiUtils.browse(url);
} catch (URISyntaxException | MalformedURLException ex) {
guiUtils.error(ex);
}
}
});
}
}

/**
* Creates a help popup.
*
Expand Down
32 changes: 6 additions & 26 deletions src/main/java/org/harctoolbox/irscrutinizer/GuiMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private void setupProperties(String propsfilename, boolean verbose) throws Malfo
if (verbose)
properties.setVerbose(true);
Importer.setProperties(properties);
HelpPopup.setBaseUrl(new File(properties.mkPathAbsolute(properties.getProtocolDocfilePath())).toURI().toURL().toString());
HelpPopup.setBaseUrl(new File(properties.mkPathAbsolute(properties.getProtocolDocfilePath())));
SelectFile.restoreFromString(properties.getFileselectordirs());
Exporter.setCreatingUser(properties.getCreatingUser());
Exporter.setEncoding(properties.getExportCharsetName());
Expand Down Expand Up @@ -7125,19 +7125,11 @@ private void homePageMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//
}//GEN-LAST:event_homePageMenuItemActionPerformed

private void mainDocuMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mainDocuMenuItemActionPerformed
try {
guiUtils.browse(new File(properties.mkPathAbsolute(properties.getHelpfilePath())));
} catch (MalformedURLException | URISyntaxException ex) {
guiUtils.error(ex);
}
guiUtils.browse(new File(properties.mkPathAbsolute(properties.getHelpfilePath())));
}//GEN-LAST:event_mainDocuMenuItemActionPerformed

private void protocolSpecMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_protocolSpecMenuItemActionPerformed
try {
guiUtils.browse(new File(properties.mkPathAbsolute(properties.getProtocolDocfilePath())));
} catch (MalformedURLException | URISyntaxException ex) {
guiUtils.error(ex);
}
guiUtils.browse(new File(properties.mkPathAbsolute(properties.getProtocolDocfilePath())));
}//GEN-LAST:event_protocolSpecMenuItemActionPerformed

private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
Expand Down Expand Up @@ -8589,11 +8581,7 @@ private void importIrTransHelpButtonActionPerformed(java.awt.event.ActionEvent e
}//GEN-LAST:event_importIrTransHelpButtonActionPerformed

private void releaseNotesMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_releaseNotesMenuItemActionPerformed
try {
guiUtils.browse(new File(properties.mkPathAbsolute(properties.getReleaseNotesPath())));
} catch (URISyntaxException | MalformedURLException ex) {
guiUtils.error(ex);
}
guiUtils.browse(new File(properties.mkPathAbsolute(properties.getReleaseNotesPath())));
}//GEN-LAST:event_releaseNotesMenuItemActionPerformed

private void importSignalAsMode2MenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importSignalAsMode2MenuItemActionPerformed
Expand Down Expand Up @@ -8975,19 +8963,11 @@ private void downloadsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {/
}//GEN-LAST:event_downloadsMenuItemActionPerformed

private void irpTransmogrifierHelpMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_irpTransmogrifierHelpMenuItemActionPerformed
try {
guiUtils.browse(new File(properties.mkPathAbsolute(properties.getIrpTransmogrifierHelpfilePath())));
} catch (MalformedURLException | URISyntaxException ex) {
guiUtils.error(ex);
}
guiUtils.browse(new File(properties.mkPathAbsolute(properties.getIrpTransmogrifierHelpfilePath())));
}//GEN-LAST:event_irpTransmogrifierHelpMenuItemActionPerformed

private void glossaryMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_glossaryMenuItemActionPerformed
try {
guiUtils.browse(new File(properties.mkPathAbsolute(properties.getGlossaryFilePath())));
} catch (MalformedURLException | URISyntaxException ex) {
guiUtils.error(ex);
}
guiUtils.browse(new File(properties.mkPathAbsolute(properties.getGlossaryFilePath())));
}//GEN-LAST:event_glossaryMenuItemActionPerformed

private void rawAddTestSignalMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rawAddTestSignalMenuItemActionPerformed
Expand Down

0 comments on commit 7ed66df

Please sign in to comment.