diff --git a/src/main/java/com/rohitawate/everest/controllers/DashboardController.java b/src/main/java/com/rohitawate/everest/controllers/DashboardController.java index dc7a6cb..616786c 100644 --- a/src/main/java/com/rohitawate/everest/controllers/DashboardController.java +++ b/src/main/java/com/rohitawate/everest/controllers/DashboardController.java @@ -43,6 +43,8 @@ import javafx.fxml.FXMLLoader; import javafx.fxml.Initializable; import javafx.scene.Parent; import javafx.scene.control.*; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; import javafx.scene.input.KeyCode; import javafx.scene.layout.HBox; import javafx.scene.layout.StackPane; @@ -52,9 +54,11 @@ import org.fxmisc.flowless.VirtualizedScrollPane; import javax.ws.rs.ProcessingException; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import java.awt.*; import java.io.FileNotFoundException; import java.io.IOException; import java.net.MalformedURLException; +import java.net.URI; import java.net.URL; import java.time.LocalDateTime; import java.util.ArrayList; @@ -154,31 +158,33 @@ public class DashboardController implements Initializable { responseArea.selectAll(); responseArea.copy(); responseArea.deselect(); - snackbar.show("Response rawBody copied to clipboard.", 5000); + snackbar.show("Response body copied to clipboard.", 5000); }); responseTypeBox.getItems().addAll("JSON", "XML", "HTML", "PLAIN TEXT"); responseTypeBox.valueProperty().addListener(change -> { String type = responseTypeBox.getValue(); - try { - switch (type) { - case "JSON": + HighlightMode mode; + switch (type) { + case "JSON": + try { JsonNode node = EverestUtilities.jsonMapper.readTree(responseArea.getText()); responseArea.setText(EverestUtilities.jsonMapper.writeValueAsString(node), HighlightMode.JSON); - break; - case "XML": - responseArea.setText(responseArea.getText(), HighlightMode.XML); - break; - case "HTML": - responseArea.setText(responseArea.getText(), HighlightMode.HTML); - break; - default: - responseArea.setText(responseArea.getText(), HighlightMode.PLAIN); - } - } catch (IOException e) { - Services.loggingService.logWarning("Response could not be parsed.", e, LocalDateTime.now()); + } catch (IOException e) { + Services.loggingService.logWarning("Response could not be parsed.", e, LocalDateTime.now()); + } + return; + case "XML": + mode = HighlightMode.XML; + break; + case "HTML": + mode = HighlightMode.XML; + break; + default: + mode = HighlightMode.PLAIN; } + responseArea.setMode(mode); }); errorTitle.setText("Oops... That's embarrassing!"); @@ -427,6 +433,18 @@ public class DashboardController implements Initializable { case "text/html": responseTypeBox.setValue("HTML"); responseArea.setText(responseBody, HighlightMode.HTML); + if (Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { + snackbar.show("Open link in browser?", "YES", 5000, e -> { + snackbar.close(); + new Thread(() -> { + try { + Desktop.getDesktop().browse(new URI(addressField.getText())); + } catch (Exception ex) { + Services.loggingService.logWarning("Invalid URL encountered while opening in browser.", ex, LocalDateTime.now()); + } + }).start(); + }); + } break; default: responseTypeBox.setValue("PLAIN TEXT"); @@ -566,6 +584,16 @@ public class DashboardController implements Initializable { * @param state - State of the dashboard */ public void setState(DashboardState state) { + /* + The only value from a set of constants in the state.json file is the httpMethod + which, if manipulated to a non-standard value by the user, would still + be loaded into the httpMethodBox, causing severe errors while making requests. + + To prevent this, we check if it is a standard value (GET, POST, PUT, PATCH or DELETE) and + only then proceed to applying the rest of the state values to the Dashboard. + + This is an extreme case, but still something to be taken care of. + */ boolean validMethod = false; for (String method : httpMethods) { if (state.httpMethod.equals(method)) diff --git a/src/main/java/com/rohitawate/everest/controllers/HomeWindowController.java b/src/main/java/com/rohitawate/everest/controllers/HomeWindowController.java index 1f74384..5f787a7 100644 --- a/src/main/java/com/rohitawate/everest/controllers/HomeWindowController.java +++ b/src/main/java/com/rohitawate/everest/controllers/HomeWindowController.java @@ -333,7 +333,7 @@ public class HomeWindowController implements Initializable { int relativityIndex = controller.getRelativityIndex(searchString); - // Split the string into words and get total relativity index as sum of individual indices. + // Split the string into words and get total relativity index as the sum of individual indices. String words[] = searchString.split("\\s"); for (String word : words) relativityIndex += controller.getRelativityIndex(word); diff --git a/src/main/java/com/rohitawate/everest/misc/EverestUtilities.java b/src/main/java/com/rohitawate/everest/misc/EverestUtilities.java index deb09eb..1a62d11 100644 --- a/src/main/java/com/rohitawate/everest/misc/EverestUtilities.java +++ b/src/main/java/com/rohitawate/everest/misc/EverestUtilities.java @@ -57,7 +57,7 @@ public class EverestUtilities { } catch (IOException e) { e.printStackTrace(); } - Services.loggingService.logInfo("BugReporter was copied to installation folder.", LocalDateTime.now()); + Services.loggingService.logInfo("BugReporter was copied to installation directory.", LocalDateTime.now()); }).start(); } diff --git a/src/main/resources/css/Adreana.css b/src/main/resources/css/Adreana.css index 37d91cd..4fd703f 100644 --- a/src/main/resources/css/Adreana.css +++ b/src/main/resources/css/Adreana.css @@ -306,7 +306,7 @@ } .visualizerLabel { - -fx-font-family: "Liberation Mono", monospace; + -fx-font-family: "Liberation Mono", "Consolas", "Courier New", "Monaco", "DejaVu Sans Mono", monospace; } .visualizerRootLabel { @@ -374,3 +374,8 @@ -fx-text-fill: white; -fx-alignment: center; } + +.jfx-snackbar-action .text { + -fx-fill: azure; + -fx-font-weight: bold; +} diff --git a/src/main/resources/css/syntax/Moondust.css b/src/main/resources/css/syntax/Moondust.css index 793da02..7abf263 100644 --- a/src/main/resources/css/syntax/Moondust.css +++ b/src/main/resources/css/syntax/Moondust.css @@ -14,7 +14,7 @@ * limitations under the License. */ -/*General rules for EverestCodeArea*/ +/* General rules for EverestCodeArea */ .everest-code-area { -fx-background-color: #282828; @@ -22,7 +22,7 @@ .everest-code-area .text { -fx-fill: #ababab; - -fx-font-family: "Liberation Mono", monospace; + -fx-font-family: "Liberation Mono", "Consolas", "Courier New", "Monaco", "DejaVu Sans Mono", monospace; -fx-font-size: 17px; } @@ -34,7 +34,7 @@ -fx-fill: azure !important; } -/*Common to JSON and XML*/ +/* Common to JSON and XML */ .xml_bracket, .json_curly { @@ -52,7 +52,7 @@ -fx-fill: cornflowerblue !important; } -/*JSON-specific*/ +/* JSON-specific */ .json_array { -fx-fill: limegreen !important; @@ -68,7 +68,7 @@ -fx-font-weight: bold; } -/*XML-specific*/ +/* XML-specific */ .xml_attribute { -fx-fill: darkviolet !important;