Skip to content

Commit 5007cdb

Browse files
committed
ASTDiff GUI: Enhance API
1 parent fc8507d commit 5007cdb

File tree

4 files changed

+47
-34
lines changed

4 files changed

+47
-34
lines changed

src/main/java/gui/webdiff/WebDiff.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,17 @@ public class WebDiff {
3737
public static final String HIGHLIGHT_CSS_URL = "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css";
3838
public static final String HIGHLIGHT_JS_URL = "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js";
3939
public static final String HIGHLIGHT_JAVA_URL = "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/java.min.js";
40-
public final int port = 6789;
40+
public int port = 6789;
4141

42-
private final String toolName = "RefactoringMiner";
42+
private String toolName = "RefactoringMiner";
43+
44+
public void setPort(int port) {
45+
this.port = port;
46+
}
47+
48+
public void setToolName(String toolName) {
49+
this.toolName = toolName;
50+
}
4351

4452
private final ProjectASTDiff projectASTDiff;
4553
private final String resourcesPath = "/web/";
@@ -63,7 +71,7 @@ public WebDiff(ProjectASTDiff projectASTDiff) {
6371
}
6472

6573
public void run() {
66-
killProcessOnPort(this.port);
74+
// killProcessOnPort(this.port);
6775
configureSpark(comparator, this.port);
6876
awaitInitialization();
6977
System.out.println(String.format("Starting server: %s:%d.", "http://127.0.0.1", this.port));
@@ -138,6 +146,14 @@ public void configureSpark(final DirComparator comparator, int port) {
138146
);
139147
return render(view);
140148
});
149+
get("/monaco-minimal/:id", (request, response) -> {
150+
int id = Integer.parseInt(request.params(":id"));
151+
MonacoView view = new MonacoView(
152+
toolName, comparator, request.pathInfo().split("/")[0], id
153+
);
154+
view.setButtons(false);
155+
return render(view);
156+
});
141157
get("/monaco-diff/:id", (request, response) -> {
142158
int id = Integer.parseInt(request.params(":id"));
143159
MonacoView view = new MonacoView(
@@ -146,6 +162,7 @@ public void configureSpark(final DirComparator comparator, int port) {
146162
view.setDecorate(false);
147163
return render(view);
148164
});
165+
149166
get("/left/:id", (request, response) -> {
150167
int id = Integer.parseInt(request.params(":id"));
151168
// String id = (request.params(":id"));

src/main/java/gui/webdiff/export/WebExporter.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,23 @@ public class WebExporter {
2323
final WebDiff webDiff;
2424
final String baseURL = "http://127.0.0.1";
2525
final String resourcePath = "src/main/resources/";
26-
final Set<String> viewers_path = Set.of(
26+
Set<String> viewers_path = Set.of(
2727
"monaco-page",
2828
"vanilla-diff"
2929
);
30-
final Set<String> otherPages = Set.of(
30+
Set<String> otherPages = Set.of(
3131
"singleView",
3232
"list"
3333
);
3434

35+
public void setViewers_path(Set<String> viewers_path) {
36+
this.viewers_path = viewers_path;
37+
}
38+
39+
public void setOtherPages(Set<String> otherPages) {
40+
this.otherPages = otherPages;
41+
}
42+
3543
final String baseFolder = "web";
3644
final String resourceFolderNameInFinalExport = "resources";
3745

src/main/java/gui/webdiff/viewers/monaco/MonacoCore.java

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public class MonacoCore {
6060
private final String srcFileContent;
6161
private final String dstFileContent;
6262
private final List<Refactoring> refactorings;
63+
private boolean minimal = false;
6364

6465
public MonacoCore(DirComparator comparator, Diff diff, int id, boolean isMovedDiff, String srcFileContent, String dstFileContent, List<Refactoring> refactorings) {
6566
this.comparator = comparator;
@@ -80,7 +81,14 @@ public void setShowFilenames(boolean showFilenames) {
8081
this.showFilenames = showFilenames;
8182
}
8283

84+
public void setMinimal(boolean minimal)
85+
{
86+
this.minimal = minimal;
87+
this.showFilenames = !minimal;
88+
}
89+
8390
public void addDiffContainers(HtmlCanvas html) throws IOException {
91+
8492
int offset = (showFilenames) ? 80 : 0;
8593
html.div(class_("row h-100"));
8694

@@ -89,7 +97,7 @@ public void addDiffContainers(HtmlCanvas html) throws IOException {
8997
html.h6(style("word-break: break-all; white-space: normal; overflow-wrap: break-word;"))
9098
.content(srcFileName);
9199
}
92-
String heightFormula = "";
100+
String heightFormula = "height : 100%;";
93101
if (showFilenames)
94102
heightFormula = "height: calc(100% - " + offset + "px);";
95103
html.div(class_("edc").id(getLeftContainerId()).style(heightFormula + "border: 1px solid grey; overflow: auto;"))._div()
@@ -105,32 +113,6 @@ public void addDiffContainers(HtmlCanvas html) throws IOException {
105113
._div();
106114
String code = "mymonaco(" + makeDiffConfig() + ");";
107115
html.macros().script(code); // Pass the config to the main function
108-
109-
110-
//
111-
// html.div(class_("row h-100"))
112-
// .div(class_("col-6 h-100"));
113-
// int offset = (showFilenames) ? 80 : 0;
114-
// if (showFilenames) {
115-
// html.h6(style("word-break: break-all; white-space: normal; overflow-wrap: break-word;"))
116-
// .content(srcFileName);
117-
// }
118-
//
119-
// String heightFormula = "height: calc(100% - " + offset + "px);";
120-
// html.div(id(getLeftContainerId()).style(heightFormula + "border:1px solid grey;"))._div()
121-
// ._div()
122-
// .div(class_("col-6 h-100"));
123-
//
124-
// if (showFilenames) {
125-
// html.h6(style("word-break: break-all; white-space: normal; overflow-wrap: break-word;"))
126-
// .content(dstFileName);
127-
// }
128-
//
129-
//
130-
// html.div(id(getRightContainerId()).style(heightFormula + "border:1px solid grey;"))._div()
131-
// ._div();
132-
// String code = "monaco(" + makeDiffConfig() + ");";
133-
// html.macros().script(code); // Pass the config to the main function
134116
}
135117

136118
String getLeftJsConfig() {
@@ -643,6 +625,7 @@ public String getDiffName() {
643625

644626
public String makeDiffConfig() {
645627
boolean spv = !showFilenames;
628+
if (minimal) spv = false;
646629
return "{ "
647630
+ "moved: " + this.isMoved
648631
+ ", id: " + id

src/main/java/gui/webdiff/viewers/monaco/MonacoView.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
public class MonacoView extends AbstractDiffView implements Renderable {
2121
final MonacoCore core;
2222
boolean decorate = true;
23-
23+
boolean _buttons = true;
2424
public MonacoView(String toolName, DirComparator comparator, String routePath, int id) {
2525
super(toolName,
2626
comparator.getProjectASTDiff().getMetaInfo(),
@@ -71,7 +71,7 @@ public void renderOn(HtmlCanvas html) throws IOException {
7171
.render(new Header())
7272
.body(class_("h-100").style("overflow: hidden;"))
7373
.div(class_("container-fluid h-100"))
74-
.if_(decorate)
74+
.if_(decorate && _buttons)
7575
.div(class_("row"))
7676
.render(new AbstractMenuBar(toolName, routePath, id, numOfDiffs, isMovedDiff, metaInfo){
7777
@Override
@@ -96,6 +96,10 @@ public String getLegendValue() {
9696
._html();
9797
}
9898

99+
public void setButtons(boolean b) {
100+
this._buttons = b;
101+
core.setMinimal(!b);
102+
}
99103

100104

101105
private static class Header implements Renderable {
@@ -117,6 +121,7 @@ public void renderOn(HtmlCanvas html) throws IOException {
117121
.macros().javascript("/dist/folding.js")
118122
.macros().javascript("/dist/decorations.js")
119123
.macros().javascript("/dist/monaco.js")
124+
.macros().javascript("/dist/listeners.js")
120125
._head();
121126
}
122127
}

0 commit comments

Comments
 (0)