added javafx parts and style
This commit is contained in:
@@ -9,22 +9,22 @@ import java.util.Scanner;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
System.out.print("Enter a starting URL : ");
|
||||
String startUrl = scanner.nextLine().trim();
|
||||
System.out.print("Enter a word to search for : ");
|
||||
String word = scanner.nextLine().trim();
|
||||
System.out.print("Enter the maximum amount of pages the crawler should visit : ");
|
||||
int amount = Integer.parseInt(scanner.nextLine().trim());
|
||||
System.out.print("Should the crawler save the links with hits? (Y/N) : ");
|
||||
boolean save = getChoice(scanner.nextLine());
|
||||
System.out.print("Do you want to enable debug mode? (Y/N) : ");
|
||||
boolean debug = getChoice(scanner.nextLine());
|
||||
if (debug) System.out.println("[INFO] - Debug mode enabled");
|
||||
// Application.launch(Visualiser.class);
|
||||
CrawlThread t = new CrawlThread(amount,save,debug,startUrl,word);
|
||||
t.start();
|
||||
System.out.println(t.getCrawler().getResultPages());
|
||||
// Scanner scanner = new Scanner(System.in);
|
||||
// System.out.print("Enter a starting URL : ");
|
||||
// String startUrl = scanner.nextLine().trim();
|
||||
// System.out.print("Enter a word to search for : ");
|
||||
// String word = scanner.nextLine().trim();
|
||||
// System.out.print("Enter the maximum amount of pages the crawler should visit : ");
|
||||
// int amount = Integer.parseInt(scanner.nextLine().trim());
|
||||
// System.out.print("Should the crawler save the links with hits? (Y/N) : ");
|
||||
// boolean save = getChoice(scanner.nextLine());
|
||||
// System.out.print("Do you want to enable debug mode? (Y/N) : ");
|
||||
// boolean debug = getChoice(scanner.nextLine());
|
||||
// if (debug) System.out.println("[INFO] - Debug mode enabled");
|
||||
Application.launch(Visualiser.class);
|
||||
// CrawlThread t = new CrawlThread(amount,save,debug,startUrl,word);
|
||||
// t.start();
|
||||
// System.out.println(t.getCrawler().getResultPages());
|
||||
}
|
||||
|
||||
private static boolean getChoice(String choice) {
|
||||
|
||||
@@ -2,25 +2,37 @@ package main.java.webcrawler.visualiser;
|
||||
|
||||
import javafx.animation.AnimationTimer;
|
||||
import javafx.application.Application;
|
||||
import javafx.embed.swing.JFXPanel;
|
||||
import javafx.scene.Group;
|
||||
import javafx.geometry.HPos;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.canvas.Canvas;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
import org.jfree.fx.FXGraphics2D;
|
||||
import org.jfree.fx.ResizableCanvas;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Line2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
public class Visualiser extends Application {
|
||||
private double frameTime = 0;
|
||||
private BorderPane pane;
|
||||
private ResizableCanvas canvas;
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
BorderPane pane = new BorderPane();
|
||||
ResizableCanvas canvas = new ResizableCanvas(this::draw, pane);
|
||||
pane = new BorderPane();
|
||||
canvas = new ResizableCanvas(this::draw, pane);
|
||||
canvas.setWidth(1600);
|
||||
canvas.setHeight(800);
|
||||
pane.setCenter(canvas);
|
||||
initGUIElements();
|
||||
FXGraphics2D g2d = new FXGraphics2D(canvas.getGraphicsContext2D());
|
||||
draw(g2d);
|
||||
primaryStage.setScene(new Scene(pane));
|
||||
@@ -29,9 +41,10 @@ public class Visualiser extends Application {
|
||||
|
||||
new AnimationTimer() {
|
||||
long last = -1;
|
||||
|
||||
@Override
|
||||
public void handle(long now) {
|
||||
if(last == -1)
|
||||
if (last == -1)
|
||||
last = now;
|
||||
update((now - last) / 1000000000.0);
|
||||
last = now;
|
||||
@@ -40,7 +53,53 @@ public class Visualiser extends Application {
|
||||
}.start();
|
||||
}
|
||||
|
||||
private void initGUIElements() {
|
||||
HBox top = new HBox(200);
|
||||
top.getStyleClass().add("content");
|
||||
top.setPadding(new Insets(10, 10, 10, 10));
|
||||
top.setPrefWidth(canvas.getWidth());
|
||||
top.setPrefHeight(200);
|
||||
pane.setTop(top);
|
||||
pane.getStylesheets().add(getClass().getResource("../../../resources/stylesheets/visualiser.css").toExternalForm());
|
||||
|
||||
// start url, word to search, amount of pages, debug (?)
|
||||
TextField urlField = new TextField();
|
||||
urlField.setPromptText("Enter the starting url");
|
||||
TextField wordField = new TextField();
|
||||
wordField.setPromptText("Enter the word to search for");
|
||||
TextField amountField = new TextField();
|
||||
amountField.setPromptText("Maximum amount of pages the crawler should visit..");
|
||||
VBox content = new VBox(10);
|
||||
content.setAlignment(Pos.CENTER_LEFT);
|
||||
content.setMinWidth(400);
|
||||
content.setPadding(new Insets(0, 0, 0, 100));
|
||||
content.getChildren().addAll(
|
||||
new Label("Starting url:"),
|
||||
urlField,
|
||||
new Label("Word to search for:"),
|
||||
wordField,
|
||||
new Label("Maximum amount of pages the crawler should visit:"),
|
||||
amountField);
|
||||
top.getChildren().add(content);
|
||||
|
||||
ListView<String> debugWindow = new ListView<>();
|
||||
debugWindow.setMinWidth(1100);
|
||||
top.setAlignment(Pos.CENTER_LEFT);
|
||||
top.getChildren().add(debugWindow);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void draw(FXGraphics2D graphics) {
|
||||
graphics.setBackground(new Color(43, 43, 46));
|
||||
graphics.clearRect(0, 0, (int) canvas.getWidth(), (int) canvas.getHeight());
|
||||
|
||||
graphics.setColor(Color.red);
|
||||
graphics.draw(new Rectangle2D.Double(10, 10, 500, 500));
|
||||
}
|
||||
|
||||
|
||||
private void updateFrame() {
|
||||
|
||||
}
|
||||
|
||||
@@ -52,8 +111,4 @@ public class Visualiser extends Application {
|
||||
this.frameTime = 0d;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateFrame() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
28
src/main/resources/stylesheets/visualiser.css
Normal file
28
src/main/resources/stylesheets/visualiser.css
Normal file
@@ -0,0 +1,28 @@
|
||||
.content {
|
||||
-fx-background-color: #2b2b2e;
|
||||
-fx-font-family: Consolas;
|
||||
-fx-border-style: solid;
|
||||
-fx-border-width: 0.5px;
|
||||
-fx-border-color: #9cb8ae;
|
||||
}
|
||||
|
||||
.label {
|
||||
-fx-text-fill: #13e89a;
|
||||
}
|
||||
|
||||
.text-field {
|
||||
-fx-background-color: #7a7a7a;
|
||||
}
|
||||
|
||||
.text-field:focused {
|
||||
-fx-text-fill: #13e89a;
|
||||
}
|
||||
|
||||
.list-view {
|
||||
-fx-background-color: black;
|
||||
}
|
||||
|
||||
.list-cell {
|
||||
-fx-background-color: black;
|
||||
-fx-text-fill: #00d60e;
|
||||
}
|
||||
Reference in New Issue
Block a user