Skip to content
2 changes: 1 addition & 1 deletion src/test/java/commonGraphics/AbstractKeyListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public UndefinedKeyActionException(int keyCode) {

//
private static final class KeyActionUpdater extends AbstractUpdater {
private static final long UPDATE_DELAY = 20; // ms
private static final long UPDATE_DELAY = 16; // ms
private final @NotNull AbstractKeyListener listener;

//
Expand Down
23 changes: 21 additions & 2 deletions src/test/java/commonGraphics/ColorUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,29 @@

//Color utilities.
public final class ColorUtils {
public static final @NotNull Color TRANSPARENT_BLACK = new Color(0, 0, 0, 0);
private static final int OPAQUE_ALPHA = 255;

//gets a gray color from brightness and alpha
@SuppressWarnings("unused")
public static final @NotNull Color TRANSPARENT_BLACK = getGray(0, 0);

/**
* Gets a gray color from brightness and alpha.
*
* @param brightness A brightness value 0-255 (inclusive).
* @param alpha Alpha value for transparency, 0-255 (inclusive). Lower values are more transparent.
* @return A gray color.
*/
public static @NotNull Color getGray(int brightness, int alpha) {
return new Color(brightness, brightness, brightness, alpha);
}

/**
* Gets an opaque gray color from brightness.
*
* @param brightness A brightness value 0-255 (inclusive).
* @return An opaque gray color.
*/
public static @NotNull Color getOpaqueGray(int brightness) {
return getGray(brightness, OPAQUE_ALPHA);
}
}
12 changes: 8 additions & 4 deletions src/test/java/commonGraphics/panels/MinimalPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static commonGraphics.ColorUtils.TRANSPARENT_BLACK;
import static consoleUtils.SimplePrinting.printLine;

//a minimal panel with most common features
public abstract class MinimalPanel extends JPanel {
Expand All @@ -22,7 +22,7 @@ public MinimalPanel(@Nullable Color background,
@Nullable Color borderColor, boolean drawBorders,
@Nullable Color diagonalColor, boolean drawDiagonals) {
super();
setBackground(Objects.requireNonNullElse(background, TRANSPARENT_BLACK));
setBackground(background);
this.borderColor = Objects.requireNonNullElse(borderColor, DEFAULT_BORDERS_AND_DIAGONALS_COLOR);
this.drawBorders = drawBorders;
this.diagonalColor = Objects.requireNonNullElse(diagonalColor, DEFAULT_BORDERS_AND_DIAGONALS_COLOR);
Expand All @@ -44,8 +44,8 @@ public final void setDrawDiagonals(boolean drawDiagonals) {

//
@Override
protected void paintComponent(@NotNull Graphics g) {
super.paintComponent(g);
public void paint(@NotNull Graphics g) {
super.paint(g);
mainPaint(g);
finalPaint(g);
}
Expand Down Expand Up @@ -73,4 +73,8 @@ private void drawPanelDiagonals(@NotNull Graphics g, int width, int height) {
g.drawLine(0, 0, width, height);
g.drawLine(0, height, width, 0);
}

public void printSizeToConsole(@NotNull String message) {
printLine(message + " size: " + getWidth() + " x " + getHeight());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import org.jetbrains.annotations.Nullable;

import static commonGraphics.ColorUtils.TRANSPARENT_BLACK;
import commonGraphics.panels.FixedHorizontalPanel;

//a horizontal section for a vertical side-panel
Expand All @@ -14,7 +13,7 @@ public AbstractSectionPanel(int height,
@Nullable Color borderColor, boolean drawBorders,
@Nullable Color diagonalColor, boolean drawDiagonals) {
super(
height, TRANSPARENT_BLACK,
height, null,
borderColor, drawBorders,
diagonalColor, drawDiagonals);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static commonGraphics.ColorUtils.TRANSPARENT_BLACK;
import commonGraphics.panels.MinimalPanel;
import commonGraphics.panels.sidePanels.SectionContainerInterface;

Expand All @@ -17,7 +16,7 @@ public abstract class CommonTopSection extends MinimalPanel implements SectionCo
//
public CommonTopSection(@Nullable Color borderColor, @Nullable Color diagonalColor) {
super(
TRANSPARENT_BLACK,
null,
borderColor, false,
diagonalColor, false);
this.borderColor = borderColor;
Expand Down
48 changes: 43 additions & 5 deletions src/test/java/playerTest/graphics/TestWindow.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package playerTest.graphics;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.LayoutManager;
import java.awt.BorderLayout;
import javax.swing.BoxLayout;

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

import static commonGraphics.ColorUtils.getGray;
import static consoleUtils.SimplePrinting.printLine;

import commonGraphics.panels.MinimalPanel;
import commonGraphics.UpdatingWindow;
import playerTest.graphics.panels.leftSidePanel.LeftSidePanel;
import playerTest.graphics.panels.CentralPanel;
import playerTest.graphics.panels.centralPanel.CentralPanel;
import playerTest.graphics.panels.rightSidePanel.RightSidePanel;

//
Expand All @@ -33,9 +39,41 @@ public TestWindow() {
public void addPanels() {
LayoutManager layout = new BoxLayout(getContentPane(), BoxLayout.X_AXIS);
getContentPane().setLayout(layout);
add(new LeftSidePanel(this, MAIN_PANEL_BACKGROUND_COLOR, MAIN_PANEL_BORDER_COLOR));
add(new CentralPanel(MAIN_PANEL_BORDER_COLOR, MAIN_PANEL_BORDER_COLOR));
add(new RightSidePanel(MAIN_PANEL_BACKGROUND_COLOR, MAIN_PANEL_BORDER_COLOR));
// Add more panels here, if needed.
@NotNull LeftSidePanel leftSidePanel = new LeftSidePanel(
this,
MAIN_PANEL_BACKGROUND_COLOR, MAIN_PANEL_BORDER_COLOR);
add(leftSidePanel);
@NotNull CentralAndRightPanel centralAndRightPanel = new CentralAndRightPanel(
MAIN_PANEL_BACKGROUND_COLOR, MAIN_PANEL_BORDER_COLOR);
add(centralAndRightPanel);

//debugging:
revalidate();
leftSidePanel.printSizeToConsole("Left side panel created,");
centralAndRightPanel.printSizeToConsole("CentralAndRightPanel created,");
}

//
private static final class CentralAndRightPanel extends MinimalPanel {
//
CentralAndRightPanel(@Nullable Color mainPanelBackgroundColor, @Nullable Color mainPanelBorderColor) {
super(null, null, false, null, false);
printLine("Creating CentralAndRightPanel");
LayoutManager layout = new BorderLayout();
setLayout(layout);
@NotNull RightSidePanel rightSidePanel = new RightSidePanel(mainPanelBackgroundColor, mainPanelBorderColor);
//add(rightSidePanel, BorderLayout.EAST);
@NotNull CentralPanel centralPanel = new CentralPanel(mainPanelBackgroundColor, mainPanelBorderColor);
add(centralPanel);
revalidate();

//debugging:
rightSidePanel.printSizeToConsole("Right side panel created,");
centralPanel.printSizeToConsole("Central panel created,");
}

//
@Override
public void mainPaint(@NotNull Graphics g) {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package playerTest.graphics.panels.centralPanel;

import java.awt.Color;
import java.awt.Graphics;

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

import static commonGraphics.ColorUtils.getGray;
import static commonGraphics.StringUtils.drawNumberedString;
import static consoleUtils.SimplePrinting.printLine;

import commonGraphics.panels.sidePanels.AbstractSectionPanel;

//
final class BottomSection extends AbstractSectionPanel {
private static final int PANEL_HEIGHT = 300;
private static final int @NotNull [] TEXT_LOCATION = new int [] {10, 10};
private static final @NotNull Color
HEADING_COLOR = Color.white,
TEXT_COLOR = getGray(170, 255);

//
BottomSection(@Nullable Color borderColor, @Nullable Color diagonalColor) {
super(
PANEL_HEIGHT,
borderColor, true,
diagonalColor, true);
printLine("Creating central panel bottom section");
printSizeToConsole("");
}

//
@Override
public void mainPaint(@NotNull Graphics g) {
g.setColor(HEADING_COLOR);
drawInfoLine(g, "Bottom section", 1);
//TODO: improve this
g.setColor(TEXT_COLOR);
drawInfoLine(g, "Coming soon...", 2);
// Paint more stuff here, if needed.
}

@SuppressWarnings("SameParameterValue")
private void drawInfoLine(@NotNull Graphics g, @Nullable String line, int lineNumber) {
drawNumberedString(g, line, TEXT_LOCATION, lineNumber);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package playerTest.graphics.panels.centralPanel;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.LayoutManager;
import java.awt.BorderLayout;

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

import static consoleUtils.SimplePrinting.printLine;

import commonGraphics.panels.MinimalPanel;
import commonGraphics.panels.sidePanels.SectionContainerInterface;

//
public final class CentralPanel extends MinimalPanel implements SectionContainerInterface {
private final @Nullable Color sectionBorderColor, sectionDiagonalColor;

//
public CentralPanel(@Nullable Color background, @Nullable Color borderColor) {
super(
background,
borderColor, true,
borderColor, true);
printLine("Creating central panel");
this.sectionBorderColor = borderColor;
this.sectionDiagonalColor = borderColor;
addSections();
}

@Override
public void addSections(){
LayoutManager layout = new BorderLayout();
setLayout(layout);
//TODO: fix this
@NotNull BottomSection bottomSection = new BottomSection(sectionBorderColor, sectionDiagonalColor);
add(bottomSection, BorderLayout.SOUTH);
@NotNull MainPanel mainPanel = new MainPanel(sectionBorderColor, sectionDiagonalColor);
add(mainPanel);
//validate();
revalidate();

//debugging:
//bottomSection.printSizeToConsole("Central bottom section created,");
mainPanel.printSizeToConsole("Main panel created,");
}

//
@Override
public void mainPaint(@NotNull Graphics g) {
printLine("asd 1");
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package playerTest.graphics.panels;
package playerTest.graphics.panels.centralPanel;

import java.awt.Color;
import java.awt.Graphics;
Expand All @@ -9,22 +9,27 @@
import commonGraphics.panels.graphicalPanels.CenteredDrawPanel;
import commonGraphics.panels.graphicalPanels.ScaledDrawInterface;

import static consoleUtils.SimplePrinting.printLine;
import static consoleUtils.stringTools.NumberFormatter.doubleToString;

//
public final class CentralPanel extends CenteredDrawPanel implements ScaledDrawInterface {
public class MainPanel extends CenteredDrawPanel implements ScaledDrawInterface {
private static final double DEFAULT_SCALE = 2.0;
private static final @NotNull Color
BACKGROUND = Color.black,
TEXT_COLOR = Color.white;
TEXT_COLOR = Color.red;//Color.white;
@SuppressWarnings("FieldMayBeFinal")
private double scale;

//
public CentralPanel(@Nullable Color borderColor, @Nullable Color diagonalColor) {
public MainPanel(@Nullable Color borderColor, @Nullable Color diagonalColor) {
super(
BACKGROUND,
null,//BACKGROUND,
borderColor, false,
diagonalColor, true);
/*diagonalColor*/Color.red, true);
printLine("Creating main panel");
scale = DEFAULT_SCALE;
printSizeToConsole("");
}

//
Expand All @@ -38,6 +43,7 @@ public double getScale() {
public void mainPaint(@NotNull Graphics g) {
g.setColor(TEXT_COLOR);
g.drawString("A player test", 100, 100);
g.drawString("Scale: " + doubleToString(scale, 3), 100, 120);
// Paint more stuff here, if needed.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static consoleUtils.SimplePrinting.printLine;

import commonGraphics.UpdatingWindow;
import commonGraphics.panels.sidePanels.commonLeftSidePanel.CommonLeftSidePanel;
import commonGraphics.panels.sidePanels.commonLeftSidePanel.CommonTopSection;
Expand All @@ -18,8 +20,9 @@ public LeftSidePanel(@NotNull UpdatingWindow window,
@Nullable Color background, @Nullable Color borderColor) {
super(
window, background,
borderColor, true, true,
DIAGONAL_COLOR, false, false);
Color.red/*borderColor*/, true, true,
DIAGONAL_COLOR, true, true);
printLine("Creating left side panel");
addSections();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static commonGraphics.ColorUtils.TRANSPARENT_BLACK;
import commonGraphics.panels.MinimalPanel;
import commonGraphics.panels.sidePanels.SectionContainerInterface;

Expand All @@ -23,7 +22,7 @@ final class BottomSection extends MinimalPanel implements SectionContainerInterf
//
BottomSection(@Nullable Color borderColor, boolean drawSectionBorders,
@Nullable Color diagonalColor, boolean drawSectionDiagonals) {
super(TRANSPARENT_BLACK, borderColor, DRAW_PANEL_BORDERS, diagonalColor, DRAW_PANEL_DIAGONALS);
super(null, borderColor, DRAW_PANEL_BORDERS, diagonalColor, DRAW_PANEL_DIAGONALS);
sectionBorderColor = borderColor;
this.drawSectionBorders = drawSectionBorders;
sectionDiagonalColor = diagonalColor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import org.jetbrains.annotations.Nullable;

import static consoleUtils.SimplePrinting.printLine;

import commonGraphics.panels.sidePanels.AbstractSidePanel;

//
Expand All @@ -22,6 +24,7 @@ public RightSidePanel(@Nullable Color background, @Nullable Color borderColor) {
PANEL_WIDTH, background,
borderColor, true,
null, false);
printLine("Creating right side panel");
this.sectionBorderColor = borderColor;
this.sectionDiagonalColor = borderColor;
addSections();
Expand Down
Loading