From aa56006ced50b4488013083474f9c3140cbd689d Mon Sep 17 00:00:00 2001 From: cyklon73 <87936307+cyklon73@users.noreply.github.com> Date: Sun, 14 Aug 2022 02:04:19 +0200 Subject: [PATCH] Add files via upload --- .../java/de/cyklon/duckscript/ide/IDE.java | 11 +++ .../java/de/cyklon/duckscript/ide/Main.java | 89 +++++++++++++++++++ .../de/cyklon/duckscript/ide/util/Util.java | 16 ++++ 3 files changed, 116 insertions(+) create mode 100644 src/main/java/de/cyklon/duckscript/ide/IDE.java create mode 100644 src/main/java/de/cyklon/duckscript/ide/Main.java create mode 100644 src/main/java/de/cyklon/duckscript/ide/util/Util.java diff --git a/src/main/java/de/cyklon/duckscript/ide/IDE.java b/src/main/java/de/cyklon/duckscript/ide/IDE.java new file mode 100644 index 0000000..6d46728 --- /dev/null +++ b/src/main/java/de/cyklon/duckscript/ide/IDE.java @@ -0,0 +1,11 @@ +package de.cyklon.duckscript.ide; + +import fr.theshark34.swinger.Swinger; + +public class IDE { + + public static void main(String[] args) { + new Main(); + } + +} diff --git a/src/main/java/de/cyklon/duckscript/ide/Main.java b/src/main/java/de/cyklon/duckscript/ide/Main.java new file mode 100644 index 0000000..3f57fae --- /dev/null +++ b/src/main/java/de/cyklon/duckscript/ide/Main.java @@ -0,0 +1,89 @@ +package de.cyklon.duckscript.ide; + +import de.cyklon.duckscript.lang.FileHelper; +import de.cyklon.duckscript.lang.exceptions.CompilerException; +import de.cyklon.duckscript.lang.interpreter.Interpreter; + +import javax.swing.*; +import javax.swing.plaf.basic.BasicScrollBarUI; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.io.IOException; + +public class Main extends JFrame { + + private boolean darkMode = false; + private static final File temp = new File(System.getProperty("user.dir")); + + public Main() { + int height = 600, width = 1000; + + Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); + setLocation(d.width / 2 - width / 2, d.height / 2 - height / 2); + Image duck = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/DuckIcon.png")); + setIconImage(duck); + setResizable(false); + setSize(width, height); + setTitle("DuckScript - IDE"); + setLayout(null); + setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + + JTextArea textArea = new JTextArea(); + //textArea.setBounds(80, 55, 600, 450); + JScrollPane scroll = new JScrollPane(textArea); + scroll.setBounds(80, 55, 600, 450); + + JButton startButton = new JButton(); + startButton.setBounds(800, 20, 20, 20); + startButton.setBackground(new Color(0, 169, 3)); + startButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + run(textArea.getText()); + } + }); + add(startButton); + + if (darkMode) { + getContentPane().setBackground(new Color(40, 40, 40)); + + textArea.setBackground(new Color(50, 50, 50)); + textArea.setForeground(new Color(200, 200, 200)); + + scroll.getVerticalScrollBar().setBackground(new Color(50, 50, 50)); + scroll.getHorizontalScrollBar().setBackground(new Color(50, 50, 50)); + scroll.getVerticalScrollBar().setUI(new BasicScrollBarUI() { + @Override + protected void configureScrollBarColors() { + this.thumbColor = new Color(200, 200, 200); + } + }); + scroll.getHorizontalScrollBar().setUI(new BasicScrollBarUI() { + @Override + protected void configureScrollBarColors() { + this.thumbColor = new Color(200, 200, 200); + } + }); + } else { + getContentPane().setBackground(new Color(220, 220, 220)); + + textArea.setBackground(new Color(180, 180, 180)); + } + add(scroll); + + setVisible(true); + } + + private static void run(String code) { + try { + File path = new File(temp, "temp.ds"); + FileHelper.writeFile(code, path); + Interpreter.interpret(path); + } catch (IOException | CompilerException e) { + throw new RuntimeException(e); + } + } + +} diff --git a/src/main/java/de/cyklon/duckscript/ide/util/Util.java b/src/main/java/de/cyklon/duckscript/ide/util/Util.java new file mode 100644 index 0000000..371dac2 --- /dev/null +++ b/src/main/java/de/cyklon/duckscript/ide/util/Util.java @@ -0,0 +1,16 @@ +package de.cyklon.duckscript.ide.util; + +import java.awt.*; +import java.net.URL; + +public class Util { + + public static URL getResource(String name) { + return Util.class.getResource(name); + } + + public static Image getImageResource(String name) { + return Toolkit.getDefaultToolkit().getImage(getResource(name)); + } + +}