Permalink
Browse files

Reimplemented the whole thing in JavaFX. Holy shit this is good.

  • Loading branch information...
1 parent 4343601 commit cdd44123b6788ef198b8d27d466f4645959f6704 SungilAhn committed Feb 17, 2017
Showing with 51 additions and 76 deletions.
  1. +47 −0 src/main/java/Launch.java
  2. +0 −49 src/main/java/Main.java
  3. +0 −27 src/main/java/View.java
  4. +4 −0 src/main/resources/text-area-bg.css
@@ -0,0 +1,47 @@
+import javafx.application.Application;
+import javafx.geometry.Rectangle2D;
+import javafx.scene.Scene;
+import javafx.scene.control.TextArea;
+import javafx.scene.image.Image;
+import javafx.scene.layout.*;
+import javafx.scene.text.Font;
+import javafx.stage.Screen;
+import javafx.stage.Stage;
+import javafx.stage.StageStyle;
+
+public class Launch extends Application {
+ private double width = 960, height = 600;
+
+ public static void main(String[] args) {
+ launch(args);
+ }
+
+ @Override
+ public void start(Stage primaryStage) {
+ VBox root = new VBox();
+
+ BackgroundImage bg = new BackgroundImage(new Image("background.jpg",960,600,false,true),
+ BackgroundRepeat.REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.DEFAULT,
+ BackgroundSize.DEFAULT);
+
+ TextArea textArea = new TextArea();
+ textArea.setWrapText(true);
+ textArea.setPrefSize(height, width);
+ textArea.setFont(Font.font("Lucida Grande", 22));
+
+ root.setBackground(new Background(bg));
+ root.getChildren().add(textArea);
+
+ Rectangle2D screenBounds = Screen.getPrimary().getVisualBounds();
+ primaryStage.setX((screenBounds.getWidth() - width) / 2);
+ primaryStage.setY((screenBounds.getHeight() - height) / 2);
+
+ Scene scene = new Scene(root, width, height);
+ scene.getStylesheets().add("text-area-bg.css");
+ primaryStage.setScene(scene);
+
+ primaryStage.initStyle(StageStyle.UNDECORATED);
+ primaryStage.setResizable(false);
+ primaryStage.show();
+ }
+}
@@ -1,49 +0,0 @@
-import javax.swing.*;
-import javax.swing.text.BadLocationException;
-import javax.swing.text.Style;
-import javax.swing.text.StyleConstants;
-import javax.swing.text.StyledDocument;
-import java.awt.*;
-import java.io.IOException;
-
-public class Main {
- public static final int WIDTH = 960, HEIGHT = 600;
- private static final String imgPath = "background.jpg";
-
- public static void main(String[] args) throws IOException {
- // logic goes here...
-
- // setting up GUI
- final JFrame frame = new JFrame();
- frame.setResizable(false);
- frame.setUndecorated(true);
- final View textArea = new View(imgPath);
- final StyledDocument doc = textArea.getStyledDocument();
- final Style style = textArea.addStyle("Default style", null);
- StyleConstants.setForeground(style, Color.white);
- // adjust font size and margins so that the editor is at most 75 characters wide
- // Swing freaks the f*** out with the caret position in HiDPI with certain fonts (e.g. Lucida Sans)
- StyleConstants.setFontSize(style, 22);
- StyleConstants.setFontFamily(style, "Lucida Grande");
- final JScrollPane scrollPane = new JScrollPane(textArea);
- // this still doesn't fix the wrapping...
- scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
-
- // loading the window
- SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- scrollPane.setPreferredSize(new Dimension(WIDTH, HEIGHT));
- frame.getContentPane().add(scrollPane);
- //textArea.setText("Some sample text here ...");
- try {
- doc.insertString(doc.getLength(), "You can type here: ", style);
- } catch (BadLocationException e) {
- e.printStackTrace();
- }
- frame.pack();
- frame.setLocationRelativeTo(null);
- frame.setVisible(true);
- }
- });
- }
-}
@@ -1,27 +0,0 @@
-import javax.imageio.ImageIO;
-import javax.swing.*;
-import java.awt.*;
-import java.awt.image.BufferedImage;
-import java.io.IOException;
-
-// the actual GUI
-public class View extends JTextPane {
- private BufferedImage image;
- private TexturePaint texturePaint;
-
- public View(String imgPath) throws IOException {
- super();
- image = ImageIO.read(getClass().getClassLoader().getResourceAsStream(imgPath));
- Rectangle rectangle = new Rectangle(0, 0, Main.WIDTH, Main.HEIGHT);
- texturePaint = new TexturePaint(image, rectangle);
- setOpaque(false);
- }
-
- @Override
- public void paintComponent(Graphics g) {
- Graphics2D g2 = (Graphics2D) g;
- g2.setPaint(texturePaint);
- g.fillRect(0, 0, getWidth(), getHeight());
- super.paintComponent(g);
- }
-}
@@ -0,0 +1,4 @@
+.text-area, .text-area .viewport, .text-area .content {
+ -fx-background-color: transparent ;
+ -fx-text-fill: white ;
+}

0 comments on commit cdd4412

Please sign in to comment.