Skip to content

Commit

Permalink
Merge pull request #68 from mkacct/gui
Browse files Browse the repository at this point in the history
Further improvements to GUI
  • Loading branch information
rhit-shirakrk authored May 9, 2024
2 parents 144204e + db90dff commit 4d2f238
Show file tree
Hide file tree
Showing 8 changed files with 328 additions and 158 deletions.
25 changes: 23 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<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>rhit.csse.csse374</groupId>
<groupId>rhit.csse.csse375</groupId>
<artifactId>LinterProject</artifactId>
<version>1.0-rc3</version>
<name>Linter</name>
<version>UNRELEASED</version>
<repositories>
<repository>
<id>central</id>
Expand All @@ -15,6 +16,10 @@
</snapshots>
</repository>
</repositories>
<properties>
<name>${project.name}</name>
<version>${project.version}</version>
</properties>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
Expand All @@ -36,6 +41,22 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>write-project-properties</goal>
</goals>
<configuration>
<outputFile>${project.build.outputDirectory}/product-info.properties</outputFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static void main(String[] args) throws IOException {
}

private static void printInfo() {
System.out.println(MessageFormat.format("{0} version {1}", ProductInfo.NAME, ProductInfo.VERSION));
System.out.println(MessageFormat.format("{0} version {1}", ProductInfo.getName(), ProductInfo.getVersion()));
System.out.println("usage: <command to run LinterProject> <classdir> [<config>]");
}
}
30 changes: 28 additions & 2 deletions src/main/java/general/ProductInfo.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
package general;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public final class ProductInfo {
public static final String NAME = "Linter";
public static final String VERSION = "UNRELEASED";
private static final String PRODUCT_INFO_RES_PATH = "/product-info.properties";

private static final ProductInfoReader READER = new ProductInfoReader();

public static String getName() {return READER.getProperty("name");}
public static String getVersion() {return READER.getProperty("version");}

private static final class ProductInfoReader {
private final Properties properties;

private ProductInfoReader() {
InputStream inputStream = this.getClass().getResourceAsStream(PRODUCT_INFO_RES_PATH);
this.properties = new Properties();
try {
this.properties.load(inputStream);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}

public String getProperty(String key) {
return this.properties.getProperty(key);
}
}
}
22 changes: 17 additions & 5 deletions src/main/java/gui/FilePicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.File;
import java.util.function.Consumer;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.JTextField;
Expand All @@ -23,13 +24,24 @@ public FilePicker(String targetPath, Consumer<String> pathUpdateHandler) {
super(new BorderLayout(GuiUtil.PAD, GuiUtil.PAD));
this.pathUpdateHandler = pathUpdateHandler;

this.pathField = new JTextField(targetPath, TEXT_FIELD_MIN_COLS);
this.pathField.putClientProperty(FlatClientProperties.PLACEHOLDER_TEXT, PATH_FIELD_PLACEHOLDER_TEXT);
GuiUtil.addTextFieldDocumentUpdateListener(this.pathField, (e) -> {
this.pathField = this.initPathField(targetPath);
this.initBrowseButton();
}

private JTextField initPathField(String targetPath) {
JTextField pathField = new JTextField(targetPath, TEXT_FIELD_MIN_COLS);
pathField.putClientProperty(FlatClientProperties.PLACEHOLDER_TEXT, PATH_FIELD_PLACEHOLDER_TEXT);
this.add(pathField, BorderLayout.CENTER);
GuiUtil.addTextFieldDocumentUpdateListener(pathField, (e) -> {
this.pathUpdateHandler.accept(this.getPath());
});
this.add(this.pathField, BorderLayout.CENTER);
this.add(GuiUtil.createButton(BROWSE_BUTTON_LABEL, (e) -> {this.browse();}), BorderLayout.LINE_END);
return pathField;
}

private JButton initBrowseButton() {
JButton browseButton = GuiUtil.createButton(BROWSE_BUTTON_LABEL, (e) -> {this.browse();});
this.add(browseButton, BorderLayout.LINE_END);
return browseButton;
}

private String getPath() {return this.pathField.getText();}
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/gui/GuiUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Window;
import java.awt.event.ActionListener;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
Expand All @@ -30,7 +32,7 @@ final class GuiUtil {
public static final int PAD = 8;

public static String formatTitle(String title) {
return (title != null) ? MessageFormat.format("{0} – {1}", ProductInfo.NAME, title) : ProductInfo.NAME;
return (title != null) ? MessageFormat.format("{0} – {1}", ProductInfo.getName(), title) : ProductInfo.getName();
}

public static void showError(Component parent, String message) {
Expand All @@ -46,6 +48,14 @@ public static void withWaitCursor(Component component, Runnable func) {
}
}

public static void initWindow(Window window, Window parent, Dimension minSize, int initHeight) {
window.setMinimumSize(minSize);
window.pack();
window.setSize(new Dimension(window.getWidth(), initHeight));
window.setLocationRelativeTo(parent);
window.setVisible(true);
}

public static JLabel createHeading(String text) {
JLabel label = new JLabel(text);
Font origFont = label.getFont();
Expand All @@ -59,7 +69,7 @@ public static JButton createButton(String text, ActionListener action) {
return button;
}

public static void setPaddedContentPane(RootPaneContainer component) {
public static void initPaddedContentPane(RootPaneContainer component) {
JPanel contentPane = new JPanel(new BorderLayout(GuiUtil.PAD, GuiUtil.PAD));
contentPane.setBorder(new EmptyBorder(GuiUtil.PAD, GuiUtil.PAD, GuiUtil.PAD, GuiUtil.PAD));
component.setContentPane(contentPane);
Expand Down
96 changes: 67 additions & 29 deletions src/main/java/gui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,45 @@
import general.ProductInfo;

class MainWindow extends JFrame implements Reloadable {
private static final int MIN_WIDTH = 640, MIN_HEIGHT = 360;
private static final Dimension MIN_SIZE = new Dimension(640, 360);
private static final int INIT_HEIGHT = 480;

private final App app;

private final Header header;
private final MainPanel mainPanel;
private final Footer footer;

MainWindow(App app) {
super(GuiUtil.formatTitle(null));
this.app = app;
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));

GuiUtil.setPaddedContentPane(this);

this.header = new Header();
this.add(this.header, BorderLayout.PAGE_START);
this.mainPanel = new MainPanel();
this.add(this.mainPanel, BorderLayout.CENTER);
this.footer = new Footer();
this.add(this.footer, BorderLayout.PAGE_END);

this.getRootPane().setDefaultButton(this.mainPanel.runButton);
GuiUtil.initPaddedContentPane(this);
this.initHeader();
MainPanel mainPanel = this.initMainPanel();
this.initFooter();
this.getRootPane().setDefaultButton(mainPanel.runButton);

this.pack();
this.setSize(new Dimension(this.getWidth(), this.getMinimumSize().height * 4 / 3));
this.setLocationRelativeTo(null);
this.setVisible(true);
GuiUtil.initWindow(this, null, MIN_SIZE, INIT_HEIGHT);
this.app.addReloader(this);
this.checkForConfigLoadException();
}

private Header initHeader() {
Header header = new Header();
this.add(header, BorderLayout.PAGE_START);
return header;
}

private MainPanel initMainPanel() {
MainPanel mainPanel = new MainPanel();
this.add(mainPanel, BorderLayout.CENTER);
return mainPanel;
}

private Footer initFooter() {
Footer footer = new Footer();
this.add(footer, BorderLayout.PAGE_END);
return footer;
}

private void exit(int status) {
this.dispose();
System.exit(status);
Expand Down Expand Up @@ -110,8 +116,20 @@ private class Header extends JPanel {
private Header() {
super(new BorderLayout(GuiUtil.PAD, GuiUtil.PAD));

this.add(new FilePicker(MainWindow.this.app.getTargetPath(), MainWindow.this.app::setTargetPath), BorderLayout.CENTER);
this.add(GuiUtil.createButton(SETTINGS_BUTTON_LABEL, (e) -> {MainWindow.this.openSettings();}), BorderLayout.LINE_END);
this.initFilePicker();
this.initSettingsButton();
}

private FilePicker initFilePicker() {
FilePicker filePicker = new FilePicker(MainWindow.this.app.getTargetPath(), MainWindow.this.app::setTargetPath);
this.add(filePicker, BorderLayout.CENTER);
return filePicker;
}

private JButton initSettingsButton() {
JButton settingsButton = GuiUtil.createButton(SETTINGS_BUTTON_LABEL, (e) -> {MainWindow.this.openSettings();});
this.add(settingsButton, BorderLayout.LINE_END);
return settingsButton;
}
}

Expand All @@ -127,20 +145,35 @@ private MainPanel() {
super(new BorderLayout(GuiUtil.PAD, GuiUtil.PAD));

JPanel header = new JPanel(new BorderLayout(GuiUtil.PAD, GuiUtil.PAD));
this.messageSummary = new JLabel();
header.add(this.messageSummary, BorderLayout.LINE_START);
this.runButton = GuiUtil.createButton(RUN_BUTTON_LABEL, (e) -> {this.runChecks();});
header.add(this.runButton, BorderLayout.LINE_END);
this.messageSummary = this.initMessageSummary(header);
this.runButton = this.initRunButton(header);
this.add(header, BorderLayout.PAGE_START);

this.messageDisplay = new MessageDisplay();
this.add(this.messageDisplay, BorderLayout.CENTER);
this.messageDisplay = this.initMessageDisplay();

this.reload();

MainWindow.this.app.addReloader(this);
}

private JLabel initMessageSummary(JPanel header) {
JLabel messageSummary = new JLabel();
header.add(messageSummary, BorderLayout.LINE_START);
return messageSummary;
}

private JButton initRunButton(JPanel header) {
JButton runButton = GuiUtil.createButton(RUN_BUTTON_LABEL, (e) -> {this.runChecks();});
header.add(runButton, BorderLayout.LINE_END);
return runButton;
}

private MessageDisplay initMessageDisplay() {
MessageDisplay messageDisplay = new MessageDisplay();
this.add(messageDisplay, BorderLayout.CENTER);
return messageDisplay;
}

private void runChecks() {
GuiUtil.withWaitCursor(MainWindow.this, () -> {
try {
Expand Down Expand Up @@ -196,9 +229,14 @@ private class Footer extends JPanel {
private Footer() {
super(new BorderLayout(GuiUtil.PAD, GuiUtil.PAD));

JLabel verLabel = new JLabel(MessageFormat.format("version {0}", ProductInfo.VERSION));
this.initVerLabel();
}

private JLabel initVerLabel() {
JLabel verLabel = new JLabel(MessageFormat.format("version {0}", ProductInfo.getVersion()));
verLabel.setHorizontalAlignment(JLabel.CENTER);
this.add(verLabel, BorderLayout.CENTER);
return verLabel;
}
}
}
13 changes: 9 additions & 4 deletions src/main/java/gui/MessageDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,19 @@ class MessageDisplay extends JScrollPane {
MessageDisplay() {
super(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

this.tree = new JTree();
this.setViewportView(this.tree);
ToolTipManager.sharedInstance().registerComponent(this.tree);
this.tree.setCellRenderer(new MessageCellRenderer());
this.tree = this.initTree();

this.clearMessages();
}

private JTree initTree() {
JTree tree = new JTree();
this.setViewportView(tree);
ToolTipManager.sharedInstance().registerComponent(tree);
tree.setCellRenderer(new MessageCellRenderer());
return tree;
}

void clearMessages() {
this.displayErrorMessageOnTree(NO_RESULTS_TEXT);
}
Expand Down
Loading

0 comments on commit 4d2f238

Please sign in to comment.