Skip to content

Commit

Permalink
More Themes
Browse files Browse the repository at this point in the history
Started working on themes and saving settings.
  • Loading branch information
AndusDEV committed Sep 25, 2021
1 parent d1e1d06 commit 8ca8356
Show file tree
Hide file tree
Showing 15 changed files with 141 additions and 42 deletions.
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@
<artifactId>rsyntaxtextarea</artifactId>
<version>3.1.3</version>
</dependency>

<dependency>
<groupId>com.fifesoft</groupId>
<artifactId>autocomplete</artifactId>
<version>3.1.2</version>
</dependency>

<dependency>
<groupId>com.fifesoft</groupId>
<artifactId>rstaui</artifactId>
<version>3.1.2</version>
</dependency>
</dependencies>

</project>
2 changes: 1 addition & 1 deletion src/main/java/pl/andus/skeditor/Constants.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package pl.andus.skeditor;

public class Constants {
static String version = "1.2";
static String version = "1.3";
}
86 changes: 45 additions & 41 deletions src/main/java/pl/andus/skeditor/Main.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
package pl.andus.skeditor;

import org.fife.ui.autocomplete.*;
import org.fife.ui.rsyntaxtextarea.*;
import org.fife.ui.rtextarea.RTextScrollPane;

import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.text.BadLocationException;
import javax.swing.text.Highlighter;
import javax.swing.text.JTextComponent;
import java.awt.*;
import java.io.*;
import java.security.KeyStore;

import static pl.andus.skeditor.Themes.*;

public class Main extends JFrame {

static RSyntaxTextArea textArea = new RSyntaxTextArea(45, 150);
static JMenuBar menuBar = new JMenuBar();
static SyntaxScheme scheme = textArea.getSyntaxScheme();
static RTextScrollPane sp = new RTextScrollPane(textArea);
static JPanel cp = new JPanel(new BorderLayout());

public Main() {
// Menu

JMenuBar menuBar = new JMenuBar();

JMenu fileMenu = new JMenu("File");
JMenu editMenu = new JMenu("Edit");
JMenu templateMenu = new JMenu("Templates");
Expand Down Expand Up @@ -63,9 +66,16 @@ public Main() {

JMenuItem lightTheme = new JMenuItem("Light");
JMenuItem darkTheme = new JMenuItem("Dark");
JMenu nSkyTheme = new JMenu("Night Sky");
JMenuItem nSkyLight = new JMenuItem("Light");
JMenuItem nSkyDark = new JMenuItem("Dark");

nSkyTheme.add(nSkyLight);
nSkyTheme.add(nSkyDark);

themesMenu.add(lightTheme);
themesMenu.add(darkTheme);
themesMenu.add(nSkyTheme);

JMenuItem about = new JMenuItem("About");

Expand All @@ -82,19 +92,18 @@ public Main() {
AbstractTokenMakerFactory atmf = (AbstractTokenMakerFactory) TokenMakerFactory.getDefaultInstance();
atmf.putMapping("text/sk", "pl.andus.skeditor.sksyntax");

JPanel cp = new JPanel(new BorderLayout());

textArea.setSyntaxEditingStyle("text/sk");
textArea.setCodeFoldingEnabled(true);
textArea.setHyperlinksEnabled(true);
RTextScrollPane sp = new RTextScrollPane(textArea);
cp.add(sp);

SyntaxScheme scheme = textArea.getSyntaxScheme();
menuBar.setBackground(Color.white);
textArea.setCurrentLineHighlightColor(new Color(255, 236, 121));
textArea.setBackground(Color.white);
textArea.setForeground(Color.black);
CompletionProvider provider = createCompletionProvider();
AutoCompletion ac = new AutoCompletion(provider);
ac.install(textArea);
scheme.getStyle(Token.RESERVED_WORD).foreground = Color.blue;
scheme.getStyle(Token.RESERVED_WORD_2).foreground = Color.orange;
scheme.getStyle(Token.COMMENT_KEYWORD).foreground = Color.magenta;
Expand Down Expand Up @@ -147,7 +156,7 @@ public Main() {
int r = j.showSaveDialog(null);

if (r == JFileChooser.APPROVE_OPTION) {
File fi = new File(j.getSelectedFile().getAbsolutePath());
File fi = new File(j.getSelectedFile().getAbsolutePath() + ".sk");

try {
FileWriter wr = new FileWriter(fi, false);
Expand Down Expand Up @@ -204,43 +213,38 @@ public Main() {
onLeaveTemp.addActionListener(e -> textArea.insert("\n\non leave:\n" +
" broadcast \"&9Player &c&l%player% &9left the server\"\n", textArea.getCaretPosition()));

lightTheme.addActionListener(e -> {
// menu
menuBar.setBackground(Color.white);
// textarea
textArea.setCurrentLineHighlightColor(new Color(255, 236, 121));
textArea.setBackground(Color.white);
textArea.setForeground(Color.black);
// text
scheme.getStyle(Token.RESERVED_WORD).foreground = Color.blue;
scheme.getStyle(Token.RESERVED_WORD_2).foreground = Color.orange;
scheme.getStyle(Token.COMMENT_KEYWORD).foreground = Color.magenta;
scheme.getStyle(Token.DATA_TYPE).foreground = new Color(53, 154, 255);
scheme.getStyle(Token.OPERATOR).foreground = new Color(178, 51, 197);
scheme.getStyle(Token.LITERAL_NUMBER_DECIMAL_INT).foreground = Color.lightGray;
});
lightTheme.addActionListener(e -> Light());

darkTheme.addActionListener(e -> {
// menu
menuBar.setBackground(Color.darkGray);
// textarea
textArea.setCurrentLineHighlightColor(Color.gray);
textArea.setBackground(Color.darkGray);
textArea.setForeground(Color.white);
//text
scheme.getStyle(Token.RESERVED_WORD).foreground = new Color(53, 154, 255);
scheme.getStyle(Token.RESERVED_WORD_2).foreground = Color.orange;
scheme.getStyle(Token.COMMENT_KEYWORD).foreground = Color.magenta;
scheme.getStyle(Token.DATA_TYPE).foreground = new Color(53, 154, 255);
scheme.getStyle(Token.OPERATOR).foreground = new Color(178, 51, 197);
scheme.getStyle(Token.LITERAL_NUMBER_DECIMAL_INT).foreground = Color.lightGray;
});
darkTheme.addActionListener(e -> Dark());

nSkyLight.addActionListener(e -> NightSky(false));
nSkyDark.addActionListener(e -> NightSky(true));

about.addActionListener(e -> new About());
}

public static void main(String[] args) {
SwingUtilities.invokeLater(() -> new Main().setVisible(true));
SwingUtilities.invokeLater(() -> {
try {
String laf = UIManager.getSystemLookAndFeelClassName();
UIManager.setLookAndFeel(laf);
} catch (Exception ignored) {}
new Main().setVisible(true);
});
}

private CompletionProvider createCompletionProvider() {
DefaultCompletionProvider provider = new DefaultCompletionProvider();

provider.addCompletion(new ShorthandCompletion(provider, "cmd", "command:", "Command"));
provider.addCompletion(new BasicCompletion(provider, "if"));
provider.addCompletion(new BasicCompletion(provider, "else"));
provider.addCompletion(new BasicCompletion(provider, "trigger"));
provider.addCompletion(new BasicCompletion(provider, "permission"));
provider.addCompletion(new BasicCompletion(provider, "permission message"));
provider.addCompletion(new BasicCompletion(provider, "variables"));

return provider;
}

}
Expand Down
73 changes: 73 additions & 0 deletions src/main/java/pl/andus/skeditor/Themes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package pl.andus.skeditor;

import org.fife.ui.rsyntaxtextarea.Token;

import java.awt.*;

import static pl.andus.skeditor.Main.*;

public class Themes {
public static void Light() {
// menu
menuBar.setBackground(Color.white);
// textarea
textArea.setCurrentLineHighlightColor(new Color(255, 236, 121));
textArea.setBackground(Color.white);
textArea.setForeground(Color.black);
// text
scheme.getStyle(Token.RESERVED_WORD).foreground = Color.blue;
scheme.getStyle(Token.RESERVED_WORD_2).foreground = Color.orange;
scheme.getStyle(Token.COMMENT_KEYWORD).foreground = Color.magenta;
scheme.getStyle(Token.DATA_TYPE).foreground = new Color(53, 154, 255);
scheme.getStyle(Token.OPERATOR).foreground = new Color(178, 51, 197);
scheme.getStyle(Token.LITERAL_NUMBER_DECIMAL_INT).foreground = Color.lightGray;
}

public static void Dark() {
// menu
menuBar.setBackground(Color.darkGray);
// textarea
textArea.setCurrentLineHighlightColor(Color.gray);
textArea.setBackground(Color.darkGray);
textArea.setForeground(Color.white);
//text
scheme.getStyle(Token.RESERVED_WORD).foreground = new Color(53, 154, 255);
scheme.getStyle(Token.RESERVED_WORD_2).foreground = Color.orange;
scheme.getStyle(Token.COMMENT_KEYWORD).foreground = Color.magenta;
scheme.getStyle(Token.DATA_TYPE).foreground = new Color(53, 154, 255);
scheme.getStyle(Token.OPERATOR).foreground = new Color(178, 51, 197);
scheme.getStyle(Token.LITERAL_NUMBER_DECIMAL_INT).foreground = Color.lightGray;
}

public static void NightSky(boolean dark) {
if(dark) {
// menu
menuBar.setBackground(Color.darkGray);
// textarea
textArea.setCurrentLineHighlightColor(Color.gray);
textArea.setBackground(Color.darkGray);
textArea.setForeground(Color.white);
//text
scheme.getStyle(Token.RESERVED_WORD).foreground = new Color(53, 154, 255);
scheme.getStyle(Token.RESERVED_WORD_2).foreground = Color.orange;
scheme.getStyle(Token.COMMENT_KEYWORD).foreground = Color.magenta;
scheme.getStyle(Token.DATA_TYPE).foreground = new Color(53, 154, 255);
scheme.getStyle(Token.OPERATOR).foreground = new Color(178, 51, 197);
scheme.getStyle(Token.LITERAL_NUMBER_DECIMAL_INT).foreground = Color.lightGray;
} else {
// menu
menuBar.setBackground(Color.white);
// textarea
textArea.setCurrentLineHighlightColor(new Color(255, 236, 121));
textArea.setBackground(Color.white);
textArea.setForeground(Color.black);
// text
scheme.getStyle(Token.RESERVED_WORD).foreground = Color.blue;
scheme.getStyle(Token.RESERVED_WORD_2).foreground = Color.orange;
scheme.getStyle(Token.COMMENT_KEYWORD).foreground = Color.magenta;
scheme.getStyle(Token.DATA_TYPE).foreground = new Color(53, 154, 255);
scheme.getStyle(Token.OPERATOR).foreground = new Color(178, 51, 197);
scheme.getStyle(Token.LITERAL_NUMBER_DECIMAL_INT).foreground = Color.lightGray;
}
}
}
Binary file added src/main/resources/night.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added target/SkriptEditor-1.1.jar
Binary file not shown.
Binary file added target/classes/night.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified target/classes/pl/andus/skeditor/Constants.class
Binary file not shown.
Binary file modified target/classes/pl/andus/skeditor/Main.class
Binary file not shown.
Binary file modified target/classes/pl/andus/skeditor/ShowDialog.class
Binary file not shown.
Binary file added target/classes/pl/andus/skeditor/Themes.class
Binary file not shown.
5 changes: 5 additions & 0 deletions target/maven-archiver/pom.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Generated by Maven
#Fri Sep 24 16:04:22 CEST 2021
version=1.1
groupId=pl.andus
artifactId=SkriptEditor
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
C:\Users\Mr_an\Documents\Projekty\IdeaProjects\SkriptEditor\src\main\java\pl\andus\skeditor\Themes.java
C:\Users\Mr_an\Documents\Projekty\IdeaProjects\SkriptEditor\src\main\java\pl\andus\skeditor\About.java
C:\Users\Mr_an\Documents\Projekty\IdeaProjects\SkriptEditor\src\main\java\pl\andus\skeditor\Constants.java
C:\Users\Mr_an\Documents\Projekty\IdeaProjects\SkriptEditor\src\main\java\pl\andus\skeditor\Main.java
C:\Users\Mr_an\Documents\Projekty\IdeaProjects\SkriptEditor\src\main\java\pl\andus\skeditor\sksyntax.java
Empty file.

0 comments on commit 8ca8356

Please sign in to comment.