Skip to content

Commit

Permalink
0.8.15
Browse files Browse the repository at this point in the history
* renamed `prepareFixedPanels()` to `initializePanels()` for paneled pages
* test improvements:
  * some refactoring
  * import optimization
  * docs improvements
  • Loading branch information
Krumuvecis authored Jan 13, 2023
1 parent dec140e commit 75ab6c4
Show file tree
Hide file tree
Showing 51 changed files with 482 additions and 376 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.KruMF</groupId>
<artifactId>GraphicsEngine</artifactId>
<version>0.8.14</version>
<version>0.8.15</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/graphicsEngine/pages/AbstractPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public AbstractPage() {
}

//TODO: add javadoc
public AbstractPage(@Nullable List<ActionListener> actionListenerList,
public AbstractPage(@Nullable List<@Nullable ActionListener> actionListenerList,
@Nullable Color backgroundColor) {
super(
null,
Expand All @@ -31,6 +31,9 @@ public AbstractPage(@Nullable List<ActionListener> actionListenerList,
addListeners(actionListenerList);
}

//TODO: add javadoc
public abstract @NotNull String getPageKey();

/**
* Adds known listeners to this page.
* Override this to add custom listeners.
Expand All @@ -39,10 +42,7 @@ public AbstractPage(@Nullable List<ActionListener> actionListenerList,
*
* @return Remaining unknown listeners.
*/
public @NotNull List<ActionListener> addListeners(@Nullable List<ActionListener> list) {
public @NotNull List<@Nullable ActionListener> addListeners(@Nullable List<@Nullable ActionListener> list) {
return Objects.requireNonNullElse(list, new ArrayList<>());
}

//TODO: add javadoc
public abstract String getPageKey();
}
8 changes: 4 additions & 4 deletions src/main/java/graphicsEngine/pages/HeaderAndFooterPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public HeaderAndFooterPage(@Nullable List<ActionListener> actionListenerList,

//this has to be called manually in constructor in order to support custom parameters
//TODO: add javadoc
public final void prepareFixedPanels(@Nullable SimpleColorScheme headerAndFooterColors,
@Nullable SimpleColorScheme bodyColors,
@Nullable BorderProperties borderProperties) {
public final void initializePanels(@Nullable SimpleColorScheme headerAndFooterColors,
@Nullable SimpleColorScheme bodyColors,
@Nullable BorderProperties borderProperties) {
setLayout(new BorderLayout(0, 0));
setHeaderAndFooter(headerAndFooterColors, borderProperties);
addHeaderAndFooter();
Expand Down Expand Up @@ -66,7 +66,7 @@ private void addBody() {
}
}

//
//TODO: add javadoc
public @Nullable SimplePanel getPanelByLocation(@NotNull PanelLocation location) {
try {
return switch (location) {
Expand Down
7 changes: 4 additions & 3 deletions src/test/java/graphicsEngineDemo/d1_simplestDemo/Main.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package graphicsEngineDemo.d1_simplestDemo;

import org.jetbrains.annotations.NotNull;

import graphicsEngine.GraphicsAdapter;
import graphicsEngine.windows.WindowConfig;
import graphicsEngine.windows.WindowManager;
import graphicsEngine.windows.WindowUpdater;
import graphicsEngine.windows.WindowConfig;
import graphicsEngine.windows.windowTypes.SimpleWindow;

import org.jetbrains.annotations.NotNull;

/**
* Simplest possible use of the GraphicsEngine.
* Everything contained in just one class.
* See <b><code>ReadMe.md<code/></b> for more info.
*/
public class Main {

Expand Down
2 changes: 2 additions & 0 deletions src/test/java/graphicsEngineDemo/d1_simplestDemo/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

This is a demo demonstrating the simplest possible use of the Graphics Engine.

Starts a blank SimpleWindow.

Everything contained in just one class.

## Instructions
Expand Down

This file was deleted.

1 change: 1 addition & 0 deletions src/test/java/graphicsEngineDemo/d2_overlayDemo/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

/**
* GraphicsEngine demo demonstrating the use of overlays.
* See <b><code>ReadMe.md<code/></b> for more info.
*/
public class Main {
/**
Expand Down
20 changes: 0 additions & 20 deletions src/test/java/graphicsEngineDemo/d2_overlayDemo/Overlay.java

This file was deleted.

4 changes: 4 additions & 0 deletions src/test/java/graphicsEngineDemo/d2_overlayDemo/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

This is a demo for demonstrating the overlay functionality.

Launches a SinglePageWindow with an overlay.

Contains buttons for toggling overlay visibility and color.

## Instructions

Run `Main.main(String[] args)` to launch this demo.
70 changes: 32 additions & 38 deletions src/test/java/graphicsEngineDemo/d2_overlayDemo/Window.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,45 @@
package graphicsEngineDemo.d2_overlayDemo;

import graphicsEngine.pages.AbstractPage;
import graphicsEngine.windows.WindowConfig;
import graphicsEngine.windows.WindowManager;
import graphicsEngine.windows.windowTypes.SinglePageWindow;

import java.util.List;
import java.awt.Color;
import java.awt.event.ActionListener;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import graphicsEngine.windows.WindowConfig;
import graphicsEngine.windows.WindowManager;
import graphicsEngine.windows.windowTypes.SinglePageWindow;
import graphicsEngine.pages.AbstractPage;
import graphicsEngine.presets.SimpleOverlay;

import graphicsEngineDemo.d2_overlayDemo.page.Page;
import graphicsEngineDemo.d2_overlayDemo.overlay.Overlay;
import graphicsEngineDemo.d2_overlayDemo.buttons.ButtonListener;

/**
* The window to display.
*/
class Window extends SinglePageWindow {
private static final String WINDOW_TITLE = "Overlay demo";

private boolean overlayColorState;
private ButtonListener headerButtonListener;
public class Window extends SinglePageWindow {
private static final @NotNull String WINDOW_TITLE = "Overlay demo";
private @Nullable ButtonListener buttonListener;

//TODO: add javadoc
Window(@NotNull WindowManager windowManager) {
protected Window(@NotNull WindowManager windowManager) {
super(windowManager, new WindowConfig(), null, null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setTitle(WINDOW_TITLE);
setOverlay(new Overlay(buttonListener));
}

overlayColorState = false;
setOverlay(new Overlay(headerButtonListener));
/**
* Redundant as there is only one window.
* TODO: finish this javadoc
*
* @return The key of this window.
*/
@Override
public final @NotNull String getWindowKey() {
return "window";
}

/**
Expand All @@ -41,44 +52,27 @@ class Window extends SinglePageWindow {
*/
@Override
public @NotNull List<ActionListener> addListeners(@Nullable List<ActionListener> list) {
headerButtonListener = new ButtonListener(this);
buttonListener = new ButtonListener(this);
return super.addListeners(list);
}

/**
* Redundant as there is only one window.
* TODO: finish this javadoc
*
* @return The key of this window.
*/
@Override
public final @NotNull String getWindowKey() {
return "window";
}

/**
* Prepares a page to add to this window.
*
* @return An AbstractPage object.
*/
@Override
public final @NotNull AbstractPage getPage() {
return new Page(headerButtonListener, null);
return new Page(buttonListener, null);
}

//TODO: add javadoc
void toggleOverlayColor() {
overlayColorState = !overlayColorState;
if (overlayColorState) {
setOverlayColor(OverlayColors.GREEN);
} else {
setOverlayColor(OverlayColors.RED);
}
}

private void setOverlayColor(@Nullable Color color) {
public void toggleOverlayColor() {
try {
getOverlay().setColor(color);
@NotNull SimpleOverlay simpleOverlay = getOverlay(); //throws ClassCastException
if (simpleOverlay instanceof Overlay) {
((Overlay) simpleOverlay).toggleColor();
}
} catch (ClassCastException ignored) {
//glassPane does not contain a SimpleOverlay object
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package graphicsEngineDemo.d2_overlayDemo.buttons;

import java.awt.event.ActionListener;

import org.jetbrains.annotations.Nullable;

import graphicsEngine.parts.SimpleJButton;

/**
* A simple button for showing the overlay.
*/
public class Button1 extends SimpleJButton {
public static final String ACTION_COMMAND = "show";

public Button1(@Nullable ActionListener actionListener) {
super("Show", ACTION_COMMAND, actionListener);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package graphicsEngineDemo.d2_overlayDemo.buttons;

import java.awt.event.ActionListener;

import org.jetbrains.annotations.Nullable;

import graphicsEngine.parts.SimpleJButton;

/**
* A simple button for hiding the overlay.
*/
public class Button2 extends SimpleJButton {
public static final String ACTION_COMMAND = "hide";

public Button2(@Nullable ActionListener actionListener) {
super("Hide", ACTION_COMMAND, actionListener);
}
}
Loading

0 comments on commit 75ab6c4

Please sign in to comment.