First commit
This commit is contained in:
commit
efa05579c1
104
.gitignore
vendored
Normal file
104
.gitignore
vendored
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
target/
|
||||||
|
|
||||||
|
# Compiled class file
|
||||||
|
*.class
|
||||||
|
|
||||||
|
# Log file
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# BlueJ files
|
||||||
|
*.ctxt
|
||||||
|
|
||||||
|
# Mobile Tools for Java (J2ME)
|
||||||
|
.mtj.tmp/
|
||||||
|
|
||||||
|
# Package Files #
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.nar
|
||||||
|
*.ear
|
||||||
|
*.zip
|
||||||
|
*.tar.gz
|
||||||
|
*.rar
|
||||||
|
|
||||||
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
|
hs_err_pid*
|
||||||
|
replay_pid*
|
||||||
|
|
||||||
|
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||||
|
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||||
|
|
||||||
|
# User-specific stuff
|
||||||
|
.idea/**/workspace.xml
|
||||||
|
.idea/**/tasks.xml
|
||||||
|
.idea/**/usage.statistics.xml
|
||||||
|
.idea/**/dictionaries
|
||||||
|
.idea/**/shelf
|
||||||
|
|
||||||
|
# AWS User-specific
|
||||||
|
.idea/**/aws.xml
|
||||||
|
|
||||||
|
# Generated files
|
||||||
|
.idea/**/contentModel.xml
|
||||||
|
|
||||||
|
# Sensitive or high-churn files
|
||||||
|
.idea/**/dataSources/
|
||||||
|
.idea/**/dataSources.ids
|
||||||
|
.idea/**/dataSources.local.xml
|
||||||
|
.idea/**/sqlDataSources.xml
|
||||||
|
.idea/**/dynamic.xml
|
||||||
|
.idea/**/uiDesigner.xml
|
||||||
|
.idea/**/dbnavigator.xml
|
||||||
|
|
||||||
|
# Gradle
|
||||||
|
.idea/**/gradle.xml
|
||||||
|
.idea/**/libraries
|
||||||
|
|
||||||
|
# Gradle and Maven with auto-import
|
||||||
|
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||||
|
# since they will be recreated, and may cause churn. Uncomment if using
|
||||||
|
# auto-import.
|
||||||
|
# .idea/artifacts
|
||||||
|
# .idea/compiler.xml
|
||||||
|
# .idea/jarRepositories.xml
|
||||||
|
# .idea/modules.xml
|
||||||
|
# .idea/*.iml
|
||||||
|
# .idea/modules
|
||||||
|
# *.iml
|
||||||
|
# *.ipr
|
||||||
|
|
||||||
|
# CMake
|
||||||
|
cmake-build-*/
|
||||||
|
|
||||||
|
# Mongo Explorer plugin
|
||||||
|
.idea/**/mongoSettings.xml
|
||||||
|
|
||||||
|
# File-based project format
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
out/
|
||||||
|
|
||||||
|
# mpeltonen/sbt-idea plugin
|
||||||
|
.idea_modules/
|
||||||
|
|
||||||
|
# JIRA plugin
|
||||||
|
atlassian-ide-plugin.xml
|
||||||
|
|
||||||
|
# Cursive Clojure plugin
|
||||||
|
.idea/replstate.xml
|
||||||
|
|
||||||
|
# SonarLint plugin
|
||||||
|
.idea/sonarlint/
|
||||||
|
|
||||||
|
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||||
|
com_crashlytics_export_strings.xml
|
||||||
|
crashlytics.properties
|
||||||
|
crashlytics-build.properties
|
||||||
|
fabric.properties
|
||||||
|
|
||||||
|
# Editor-based Rest Client
|
||||||
|
.idea/httpRequests
|
||||||
|
|
||||||
|
# Android studio 3.1+ serialized cache file
|
||||||
|
.idea/caches/build_file_checksums.ser
|
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
13
.idea/compiler.xml
Normal file
13
.idea/compiler.xml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<annotationProcessing>
|
||||||
|
<profile name="Maven default annotation processors profile" enabled="true">
|
||||||
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
|
<outputRelativeToContentRoot value="true" />
|
||||||
|
<module name="codesize" />
|
||||||
|
</profile>
|
||||||
|
</annotationProcessing>
|
||||||
|
</component>
|
||||||
|
</project>
|
7
.idea/discord.xml
Normal file
7
.idea/discord.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="DiscordProjectSettings">
|
||||||
|
<option name="show" value="PROJECT_FILES" />
|
||||||
|
<option name="description" value="" />
|
||||||
|
</component>
|
||||||
|
</project>
|
7
.idea/encodings.xml
Normal file
7
.idea/encodings.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding">
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
20
.idea/jarRepositories.xml
Normal file
20
.idea/jarRepositories.xml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="RemoteRepositoriesConfiguration">
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Central Repository" />
|
||||||
|
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Maven Central repository" />
|
||||||
|
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="jboss.community" />
|
||||||
|
<option name="name" value="JBoss Community repository" />
|
||||||
|
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||||
|
</remote-repository>
|
||||||
|
</component>
|
||||||
|
</project>
|
19
.idea/misc.xml
Normal file
19
.idea/misc.xml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
<component name="MavenProjectsManager">
|
||||||
|
<option name="originalFiles">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/pom.xml" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
<component name="SwUserDefinedSpecifications">
|
||||||
|
<option name="specTypeByUrl">
|
||||||
|
<map />
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
87
pom.xml
Normal file
87
pom.xml
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>xyz.mrmelon54</groupId>
|
||||||
|
<artifactId>codesize</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<properties>
|
||||||
|
<java.version>17</java.version>
|
||||||
|
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||||
|
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
|
<timestamp>${maven.build.timestamp}</timestamp>
|
||||||
|
</properties>
|
||||||
|
<organization>
|
||||||
|
<name>MrMelon</name>
|
||||||
|
<url>https://mrmelon54.xyz</url>
|
||||||
|
</organization>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<version>3.3.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>single</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<mainClass>xyz.mrmelon54.codesize.Main</mainClass>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
<descriptorRefs>
|
||||||
|
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||||
|
</descriptorRefs>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.formdev</groupId>
|
||||||
|
<artifactId>flatlaf</artifactId>
|
||||||
|
<version>2.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
<version>2.9.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.swinglabs.swingx</groupId>
|
||||||
|
<artifactId>swingx-common</artifactId>
|
||||||
|
<version>1.6.5-1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.harawata</groupId>
|
||||||
|
<artifactId>appdirs</artifactId>
|
||||||
|
<version>1.2.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.jiconfont</groupId>
|
||||||
|
<artifactId>jiconfont-swing</artifactId>
|
||||||
|
<version>1.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.jiconfont</groupId>
|
||||||
|
<artifactId>jiconfont-google_material_design_icons</artifactId>
|
||||||
|
<version>2.2.0.2</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
151
src/main/java/xyz/mrmelon54/codesize/CodeSize.java
Normal file
151
src/main/java/xyz/mrmelon54/codesize/CodeSize.java
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
package xyz.mrmelon54.codesize;
|
||||||
|
|
||||||
|
import xyz.mrmelon54.codesize.components.InfoPanel;
|
||||||
|
import xyz.mrmelon54.codesize.enums.Theme;
|
||||||
|
import xyz.mrmelon54.codesize.ex.CannotCreateConfigFolderException;
|
||||||
|
import xyz.mrmelon54.codesize.ui.PresetSelector;
|
||||||
|
import xyz.mrmelon54.codesize.utils.AboutDialog;
|
||||||
|
import xyz.mrmelon54.codesize.utils.ComponentUtils;
|
||||||
|
import xyz.mrmelon54.codesize.utils.Settings;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.border.EmptyBorder;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class CodeSize extends JFrame {
|
||||||
|
public final Settings settings;
|
||||||
|
private JTextField pathField;
|
||||||
|
private JTextField regexField;
|
||||||
|
private InfoPanel infoPanel;
|
||||||
|
|
||||||
|
public CodeSize(Settings settings) {
|
||||||
|
super("Code Size");
|
||||||
|
this.settings = settings;
|
||||||
|
|
||||||
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
setPreferredSize(new Dimension(600, 600));
|
||||||
|
setMinimumSize(new Dimension(600, 600));
|
||||||
|
setContentPane(createMainPanel());
|
||||||
|
setJMenuBar(createMenuBar());
|
||||||
|
}
|
||||||
|
|
||||||
|
private JPanel createMainPanel() {
|
||||||
|
pathField = ComponentUtils.fixedTextFieldHeight(new JTextField());
|
||||||
|
regexField = ComponentUtils.fixedTextFieldHeight(new JTextField());
|
||||||
|
infoPanel = new InfoPanel();
|
||||||
|
|
||||||
|
JButton browseButton = new JButton("Browse");
|
||||||
|
browseButton.addActionListener(e -> browseForFolder());
|
||||||
|
JButton presetButton = new JButton("Preset");
|
||||||
|
presetButton.addActionListener(e -> presetForRegex());
|
||||||
|
JButton searchButton = new JButton("Search");
|
||||||
|
searchButton.addActionListener(e -> searchCodeFiles());
|
||||||
|
|
||||||
|
Box pathRow = Box.createHorizontalBox();
|
||||||
|
pathRow.add(pathField);
|
||||||
|
pathRow.add(Box.createHorizontalStrut(8));
|
||||||
|
pathRow.add(browseButton);
|
||||||
|
|
||||||
|
Box regexRow = Box.createHorizontalBox();
|
||||||
|
regexRow.add(regexField);
|
||||||
|
regexRow.add(Box.createHorizontalStrut(8));
|
||||||
|
regexRow.add(presetButton);
|
||||||
|
regexRow.add(Box.createHorizontalStrut(8));
|
||||||
|
regexRow.add(searchButton);
|
||||||
|
|
||||||
|
Box mainBox = Box.createVerticalBox();
|
||||||
|
mainBox.add(pathRow);
|
||||||
|
mainBox.add(Box.createVerticalStrut(8));
|
||||||
|
mainBox.add(regexRow);
|
||||||
|
mainBox.add(Box.createVerticalStrut(8));
|
||||||
|
mainBox.add(infoPanel);
|
||||||
|
|
||||||
|
JPanel mainPanel = new JPanel();
|
||||||
|
mainPanel.setLayout(new BorderLayout());
|
||||||
|
mainPanel.setBorder(new EmptyBorder(8, 8, 8, 8));
|
||||||
|
mainPanel.setPreferredSize(new Dimension(600, 600));
|
||||||
|
mainPanel.setMinimumSize(new Dimension(600, 600));
|
||||||
|
mainPanel.add(mainBox, BorderLayout.CENTER);
|
||||||
|
return mainPanel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private JMenuBar createMenuBar() {
|
||||||
|
JMenuBar menuBar = new JMenuBar();
|
||||||
|
|
||||||
|
// File menu
|
||||||
|
JMenu fileMenu = new JMenu("File");
|
||||||
|
fileMenu.setMnemonic(KeyEvent.VK_F);
|
||||||
|
menuBar.add(fileMenu);
|
||||||
|
|
||||||
|
// Theme menu
|
||||||
|
JMenu themeMenu = new JMenu("Theme");
|
||||||
|
ButtonGroup bg = new ButtonGroup();
|
||||||
|
for (Theme value : Theme.values()) {
|
||||||
|
JRadioButtonMenuItem themeRadioButton = new JRadioButtonMenuItem(value.toString(), settings.theme == value);
|
||||||
|
themeMenu.add(themeRadioButton);
|
||||||
|
bg.add(themeRadioButton);
|
||||||
|
themeRadioButton.addActionListener(e -> {
|
||||||
|
changeTheme(value);
|
||||||
|
settings.theme = value;
|
||||||
|
try {
|
||||||
|
settings.save();
|
||||||
|
} catch (IOException | CannotCreateConfigFolderException ex) {
|
||||||
|
System.out.println("Failed to save settings");
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
fileMenu.add(themeMenu);
|
||||||
|
|
||||||
|
// Quit item
|
||||||
|
JMenuItem quitItem = fileMenu.add(new JMenuItem("Quit"));
|
||||||
|
quitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, KeyEvent.CTRL_DOWN_MASK));
|
||||||
|
quitItem.addActionListener(e -> CodeSize.this.dispatchEvent(new WindowEvent(CodeSize.this, WindowEvent.WINDOW_CLOSING)));
|
||||||
|
|
||||||
|
// Help menu
|
||||||
|
JMenu helpMenu = new JMenu("Help");
|
||||||
|
helpMenu.setMnemonic(KeyEvent.VK_H);
|
||||||
|
menuBar.add(helpMenu);
|
||||||
|
|
||||||
|
// About item
|
||||||
|
JMenuItem aboutMenuItem = helpMenu.add(new JMenuItem("About"));
|
||||||
|
aboutMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.CTRL_DOWN_MASK));
|
||||||
|
aboutMenuItem.addActionListener(e -> AboutDialog.show(CodeSize.this));
|
||||||
|
return menuBar;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void changeTheme(Theme theme) {
|
||||||
|
theme.triggerSetup();
|
||||||
|
SwingUtilities.updateComponentTreeUI(this);
|
||||||
|
pack();
|
||||||
|
setLocationRelativeTo(null);
|
||||||
|
revalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void browseForFolder() {
|
||||||
|
JFileChooser fileChooser = new JFileChooser();
|
||||||
|
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||||||
|
int option = fileChooser.showOpenDialog(this);
|
||||||
|
if (option == JFileChooser.APPROVE_OPTION) {
|
||||||
|
File file = fileChooser.getSelectedFile();
|
||||||
|
pathField.setText(file.getAbsolutePath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void presetForRegex() {
|
||||||
|
PresetSelector presetSelector = new PresetSelector(this);
|
||||||
|
presetSelector.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void searchCodeFiles() {
|
||||||
|
System.out.println("Search code files");
|
||||||
|
}
|
||||||
|
}
|
35
src/main/java/xyz/mrmelon54/codesize/Main.java
Normal file
35
src/main/java/xyz/mrmelon54/codesize/Main.java
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package xyz.mrmelon54.codesize;
|
||||||
|
|
||||||
|
import jiconfont.icons.google_material_design_icons.GoogleMaterialDesignIcons;
|
||||||
|
import jiconfont.swing.IconFontSwing;
|
||||||
|
import xyz.mrmelon54.codesize.ex.CannotCreateConfigFolderException;
|
||||||
|
import xyz.mrmelon54.codesize.utils.BuildInfoUtils;
|
||||||
|
import xyz.mrmelon54.codesize.utils.Settings;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
IconFontSwing.register(GoogleMaterialDesignIcons.getIconFont());
|
||||||
|
BuildInfoUtils.load();
|
||||||
|
|
||||||
|
Settings settings = Settings.load();
|
||||||
|
if (settings == null) {
|
||||||
|
System.out.println("Creating default settings file");
|
||||||
|
settings = new Settings();
|
||||||
|
try {
|
||||||
|
settings.save();
|
||||||
|
} catch (IOException | CannotCreateConfigFolderException ex) {
|
||||||
|
JOptionPane.showMessageDialog(null, "Failed to save settings file");
|
||||||
|
ex.printStackTrace();
|
||||||
|
System.exit(1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CodeSize codeSize = new CodeSize(settings);
|
||||||
|
codeSize.changeTheme(settings.theme);
|
||||||
|
codeSize.run();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package xyz.mrmelon54.codesize.callback;
|
||||||
|
|
||||||
|
import xyz.mrmelon54.codesize.utils.Preset;
|
||||||
|
|
||||||
|
public interface PresetCallback {
|
||||||
|
void changePreset(Preset preset);
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
package xyz.mrmelon54.codesize.components;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class InfoPanel extends Box {
|
||||||
|
public InfoPanelItem totalFiles = new InfoPanelItem("Total Files");
|
||||||
|
public InfoPanelItem totalSize = new InfoPanelItem("Total Size");
|
||||||
|
public InfoPanelItem averageSize = new InfoPanelItem("Average Size");
|
||||||
|
public InfoPanelItem maxSize = new InfoPanelItem("Max Size");
|
||||||
|
public InfoPanelItem totalLines = new InfoPanelItem("Total Lines");
|
||||||
|
public InfoPanelItem averageLines = new InfoPanelItem("Average Lines");
|
||||||
|
public InfoPanelItem maxLines = new InfoPanelItem("Max Lines");
|
||||||
|
public InfoPanelItem minLines = new InfoPanelItem("Min Lines");
|
||||||
|
private final List<InfoPanelItem> values = new ArrayList<>();
|
||||||
|
|
||||||
|
public InfoPanel() {
|
||||||
|
super(BoxLayout.Y_AXIS);
|
||||||
|
values.add(totalFiles);
|
||||||
|
values.add(totalSize);
|
||||||
|
values.add(averageSize);
|
||||||
|
values.add(maxSize);
|
||||||
|
values.add(totalLines);
|
||||||
|
values.add(averageLines);
|
||||||
|
values.add(maxLines);
|
||||||
|
values.add(minLines);
|
||||||
|
values.forEach(infoPanelItem -> add(infoPanelItem.component));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateValues() {
|
||||||
|
values.forEach(InfoPanelItem::updateValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class InfoPanelItem {
|
||||||
|
private final String label;
|
||||||
|
private float value;
|
||||||
|
private final JLabel component;
|
||||||
|
|
||||||
|
public InfoPanelItem(String label) {
|
||||||
|
this.label = label;
|
||||||
|
component = new JLabel();
|
||||||
|
updateValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateValue() {
|
||||||
|
component.setText(label + ": " + value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(float v) {
|
||||||
|
value = v;
|
||||||
|
updateValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
49
src/main/java/xyz/mrmelon54/codesize/enums/Theme.java
Normal file
49
src/main/java/xyz/mrmelon54/codesize/enums/Theme.java
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package xyz.mrmelon54.codesize.enums;
|
||||||
|
|
||||||
|
import com.formdev.flatlaf.FlatDarkLaf;
|
||||||
|
import com.formdev.flatlaf.FlatLaf;
|
||||||
|
import com.formdev.flatlaf.FlatLightLaf;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.plaf.metal.DefaultMetalTheme;
|
||||||
|
import javax.swing.plaf.metal.MetalLookAndFeel;
|
||||||
|
import javax.swing.plaf.metal.OceanTheme;
|
||||||
|
import javax.swing.plaf.nimbus.NimbusLookAndFeel;
|
||||||
|
|
||||||
|
public enum Theme {
|
||||||
|
System(() -> setLookAndFeelIgnored(UIManager.getSystemLookAndFeelClassName())),
|
||||||
|
Light(FlatLightLaf::setup),
|
||||||
|
Dark(FlatDarkLaf::setup),
|
||||||
|
Metal(() -> {
|
||||||
|
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
|
||||||
|
FlatLaf.setup(new MetalLookAndFeel());
|
||||||
|
}),
|
||||||
|
Ocean(() -> {
|
||||||
|
MetalLookAndFeel.setCurrentTheme(new OceanTheme());
|
||||||
|
FlatLaf.setup(new MetalLookAndFeel());
|
||||||
|
}),
|
||||||
|
Nimbus(() -> FlatLaf.setup(new NimbusLookAndFeel()));
|
||||||
|
|
||||||
|
private static void setLookAndFeelIgnored(String name) {
|
||||||
|
try {
|
||||||
|
UIManager.setLookAndFeel(name);
|
||||||
|
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException |
|
||||||
|
UnsupportedLookAndFeelException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final SetupTheme setupTheme;
|
||||||
|
|
||||||
|
Theme(SetupTheme setupTheme) {
|
||||||
|
this.setupTheme = setupTheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void triggerSetup() {
|
||||||
|
setupTheme.setup();
|
||||||
|
}
|
||||||
|
|
||||||
|
private interface SetupTheme {
|
||||||
|
void setup();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package xyz.mrmelon54.codesize.ex;
|
||||||
|
|
||||||
|
public class CannotCreateConfigFolderException extends Exception {
|
||||||
|
public CannotCreateConfigFolderException() {
|
||||||
|
super("Cannot create config folder exception");
|
||||||
|
}
|
||||||
|
}
|
41
src/main/java/xyz/mrmelon54/codesize/ui/PresetSelector.java
Normal file
41
src/main/java/xyz/mrmelon54/codesize/ui/PresetSelector.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package xyz.mrmelon54.codesize.ui;
|
||||||
|
|
||||||
|
import xyz.mrmelon54.codesize.CodeSize;
|
||||||
|
import xyz.mrmelon54.codesize.utils.Preset;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class PresetSelector extends JDialog {
|
||||||
|
private final CodeSize codeSize;
|
||||||
|
|
||||||
|
public PresetSelector(CodeSize codeSize) {
|
||||||
|
super(codeSize, "Choose Preset", true);
|
||||||
|
this.codeSize = codeSize;
|
||||||
|
setResizable(false);
|
||||||
|
Dimension d = new Dimension(400, 400);
|
||||||
|
setSize(d);
|
||||||
|
setPreferredSize(d);
|
||||||
|
setMinimumSize(d);
|
||||||
|
setMaximumSize(d);
|
||||||
|
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||||
|
setContentPane(createMainPanel());
|
||||||
|
setLocationRelativeTo(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private JPanel createMainPanel() {
|
||||||
|
JList<Preset> presetList = new JList<>();
|
||||||
|
DefaultListModel<Preset> presetListModel = new DefaultListModel<>();
|
||||||
|
presetList.setModel(presetListModel);
|
||||||
|
for (Preset preset : codeSize.settings.presets) presetListModel.addElement(preset);
|
||||||
|
|
||||||
|
JPanel mainPanel = new JPanel();
|
||||||
|
mainPanel.setLayout(new BorderLayout());
|
||||||
|
mainPanel.add(presetList, BorderLayout.CENTER);
|
||||||
|
return mainPanel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
11
src/main/java/xyz/mrmelon54/codesize/utils/AboutDialog.java
Normal file
11
src/main/java/xyz/mrmelon54/codesize/utils/AboutDialog.java
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package xyz.mrmelon54.codesize.utils;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public class AboutDialog {
|
||||||
|
public static void show(JFrame frame) {
|
||||||
|
Properties buildProps = BuildInfoUtils.getBuildProps();
|
||||||
|
JOptionPane.showMessageDialog(frame, String.format("Version: %s\nProperty of %s", buildProps.getProperty("appVersion"), buildProps.getProperty("appAuthor")), "Code Size", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
}
|
||||||
|
}
|
22
src/main/java/xyz/mrmelon54/codesize/utils/ArrayUtils.java
Normal file
22
src/main/java/xyz/mrmelon54/codesize/utils/ArrayUtils.java
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package xyz.mrmelon54.codesize.utils;
|
||||||
|
|
||||||
|
|
||||||
|
import java.lang.reflect.Array;
|
||||||
|
import java.util.function.IntFunction;
|
||||||
|
|
||||||
|
public record ArrayUtils<T>(IntFunction<T[]> generator) {
|
||||||
|
public T[] concat(T[] a, T[] b) {
|
||||||
|
if (a == null && b == null) return null;
|
||||||
|
if (a == null) return b;
|
||||||
|
if (b == null) return a;
|
||||||
|
final int aLen = Array.getLength(a);
|
||||||
|
final int bLen = Array.getLength(b);
|
||||||
|
if (aLen == 0) return b;
|
||||||
|
if (bLen == 0) return a;
|
||||||
|
|
||||||
|
T[] result = generator.apply(aLen + bLen);
|
||||||
|
System.arraycopy(a, 0, result, 0, aLen);
|
||||||
|
System.arraycopy(b, 0, result, aLen, bLen);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package xyz.mrmelon54.codesize.utils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public class BuildInfoUtils {
|
||||||
|
private static Properties buildProps;
|
||||||
|
|
||||||
|
public static void load() {
|
||||||
|
buildProps = new Properties();
|
||||||
|
InputStream input = ClassLoader.getSystemResourceAsStream("build.properties");
|
||||||
|
try {
|
||||||
|
buildProps.load(input);
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Failed to read settings file");
|
||||||
|
e.printStackTrace();
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Properties getBuildProps() {
|
||||||
|
return buildProps;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package xyz.mrmelon54.codesize.utils;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
|
public class BuiltinPresets {
|
||||||
|
private final Preset[] presets;
|
||||||
|
|
||||||
|
public BuiltinPresets() {
|
||||||
|
InputStream resourceAsStream = getClass().getResourceAsStream("/presets.json");
|
||||||
|
if (resourceAsStream == null) throw new RuntimeException("'presets.json' is missing");
|
||||||
|
this.presets = new Gson().fromJson(new InputStreamReader(resourceAsStream), Preset[].class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Preset[] getBuiltinPresets() {
|
||||||
|
return presets;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package xyz.mrmelon54.codesize.utils;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class ComponentUtils {
|
||||||
|
public static JTextField fixedTextFieldHeight(JTextField textField) {
|
||||||
|
textField.setMaximumSize(new Dimension(textField.getMaximumSize().width, textField.getPreferredSize().height));
|
||||||
|
return textField;
|
||||||
|
}
|
||||||
|
}
|
12
src/main/java/xyz/mrmelon54/codesize/utils/DirUtils.java
Normal file
12
src/main/java/xyz/mrmelon54/codesize/utils/DirUtils.java
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package xyz.mrmelon54.codesize.utils;
|
||||||
|
|
||||||
|
import net.harawata.appdirs.AppDirsFactory;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public class DirUtils {
|
||||||
|
public static String getConfigDir() {
|
||||||
|
Properties buildProps = BuildInfoUtils.getBuildProps();
|
||||||
|
return AppDirsFactory.getInstance().getUserConfigDir(buildProps.getProperty("appId"), buildProps.getProperty("appVersion"), buildProps.getProperty("appAuthor"));
|
||||||
|
}
|
||||||
|
}
|
4
src/main/java/xyz/mrmelon54/codesize/utils/Pair.java
Normal file
4
src/main/java/xyz/mrmelon54/codesize/utils/Pair.java
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
package xyz.mrmelon54.codesize.utils;
|
||||||
|
|
||||||
|
public record Pair<T, U>(T t, U u) {
|
||||||
|
}
|
15
src/main/java/xyz/mrmelon54/codesize/utils/Preset.java
Normal file
15
src/main/java/xyz/mrmelon54/codesize/utils/Preset.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package xyz.mrmelon54.codesize.utils;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class Preset {
|
||||||
|
public UUID uuid;
|
||||||
|
public String name;
|
||||||
|
public String regex;
|
||||||
|
public boolean builtin;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
78
src/main/java/xyz/mrmelon54/codesize/utils/Settings.java
Normal file
78
src/main/java/xyz/mrmelon54/codesize/utils/Settings.java
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
package xyz.mrmelon54.codesize.utils;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import xyz.mrmelon54.codesize.enums.Theme;
|
||||||
|
import xyz.mrmelon54.codesize.ex.CannotCreateConfigFolderException;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class Settings {
|
||||||
|
private static final File settingsFile = new File(DirUtils.getConfigDir(), "settings.json");
|
||||||
|
private static final BuiltinPresets builtinPresets = new BuiltinPresets();
|
||||||
|
|
||||||
|
public Theme theme;
|
||||||
|
public Preset[] presets;
|
||||||
|
|
||||||
|
public Settings() {
|
||||||
|
this.theme = Theme.System;
|
||||||
|
this.presets = new Preset[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean assureAppDirExists() {
|
||||||
|
if (settingsFile.getParentFile().exists()) return true;
|
||||||
|
return settingsFile.getParentFile().mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assureBuiltinPresetsExist() {
|
||||||
|
Preset[] pre1 = builtinPresets.getBuiltinPresets();
|
||||||
|
Preset[] pre2 = Arrays.stream(presets).filter(preset -> {
|
||||||
|
for (Preset p : pre1) if (preset.uuid.equals(p.uuid)) return false;
|
||||||
|
return true;
|
||||||
|
}).toArray(Preset[]::new);
|
||||||
|
presets = new ArrayUtils<>(Preset[]::new).concat(pre1, pre2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Settings load() {
|
||||||
|
if (!assureAppDirExists()) return null;
|
||||||
|
Gson gson = new Gson();
|
||||||
|
Settings s;
|
||||||
|
try {
|
||||||
|
s = gson.fromJson(new FileReader(settingsFile), Settings.class);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
System.out.println("Failed to read settings file");
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
s.assureBuiltinPresetsExist();
|
||||||
|
|
||||||
|
// return loading config
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save() throws IOException, CannotCreateConfigFolderException {
|
||||||
|
assureBuiltinPresetsExist();
|
||||||
|
File dir = settingsFile.getParentFile();
|
||||||
|
if (!dir.exists() && !dir.mkdirs()) throw new CannotCreateConfigFolderException();
|
||||||
|
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||||
|
FileWriter fileWriter = null;
|
||||||
|
try {
|
||||||
|
fileWriter = new FileWriter(settingsFile);
|
||||||
|
gson.toJson(this, fileWriter);
|
||||||
|
fileWriter.flush();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Failed to write settings file");
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (fileWriter != null) {
|
||||||
|
try {
|
||||||
|
fileWriter.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Failed to close settings file");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
4
src/main/resources/build.properties
Normal file
4
src/main/resources/build.properties
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
appId=${project.groupId}.${project.artifactId}
|
||||||
|
appVersion=${project.version}
|
||||||
|
appAuthor=${project.organization.name}
|
||||||
|
buildTimestamp=${timestamp}
|
32
src/main/resources/presets.json
Normal file
32
src/main/resources/presets.json
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"uuid": "bf50e9e9-5e87-4107-b063-15e72e5ef0eb",
|
||||||
|
"name": "Visual Studio Solution",
|
||||||
|
"regex": "(?<!AssemblyAttributes|AssemblyInfo)\\.(cs|vb)$",
|
||||||
|
"builtin": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"uuid": "58f57a83-8743-4329-ac65-9d77a702bd88",
|
||||||
|
"name": "Java Project",
|
||||||
|
"regex": "\\.(java)$",
|
||||||
|
"builtin": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"uuid": "1b71b0a9-365d-45ff-8159-4a1acd869be0",
|
||||||
|
"name": "Node Project",
|
||||||
|
"regex": "\\.(js)$",
|
||||||
|
"builtin": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"uuid": "47dae138-fe78-4226-bd49-5e1836bc27c8",
|
||||||
|
"name": "Python Project",
|
||||||
|
"regex": "\\.(py)$",
|
||||||
|
"builtin": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"uuid": "d48c4b12-8218-4dea-ba3d-28516b29b402",
|
||||||
|
"name": "Website Project",
|
||||||
|
"regex": "\\.(html|js|css|php)$",
|
||||||
|
"builtin": true
|
||||||
|
}
|
||||||
|
]
|
Loading…
Reference in New Issue
Block a user