Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.KrumSpace</groupId>
<artifactId>StellarSystems</artifactId>
<version>0.14</version>
<version>0.15</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/baryGraphics/panels/ObserverDrawPanel.java
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 commonGraphics.panels.graphicalPanels.CenteredDrawPanel;
import commonGraphics.panels.graphicalPanels.ScaledDrawInterface;
import baryGraphics.Observer;

//
Expand Down
25 changes: 8 additions & 17 deletions src/test/java/commonGraphics/AbstractWindow.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,26 @@
package commonGraphics;

import java.util.Objects;
import java.awt.Point;
import java.awt.Dimension;
import javax.swing.WindowConstants;
import javax.swing.JFrame;

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

//
public abstract class AbstractWindow extends JFrame {
private static final @NotNull Dimension DEFAULT_WINDOW_SIZE = new Dimension(1200, 850);
private static final @NotNull Point DEFAULT_WINDOW_LOCATION = new Point(50, 50);
private static final int DEFAULT_CLOSE_OPERATION = WindowConstants.EXIT_ON_CLOSE;
private static final @NotNull String DEFAULT_WINDOW_TITLE = "An unnamed window";

//Creates a new window.
public AbstractWindow(@Nullable Dimension size, @Nullable Point location, @Nullable String title) {
public AbstractWindow(@Nullable WindowSettings windowSettings) {
super();
setWindowConfig(size, location, title);
setWindowConfig(Objects.requireNonNullElse(windowSettings, new WindowSettings()));
setVisible(true);
}

private void setWindowConfig(@Nullable Dimension desiredSize,
@Nullable Point desiredLocation,
@Nullable String desiredTitle) {
setSize(Objects.requireNonNullElse(desiredSize, DEFAULT_WINDOW_SIZE));
setLocation(Objects.requireNonNullElse(desiredLocation, DEFAULT_WINDOW_LOCATION));
setDefaultCloseOperation(DEFAULT_CLOSE_OPERATION);
setTitle(Objects.requireNonNullElse(desiredTitle, DEFAULT_WINDOW_TITLE));
@SuppressWarnings("MagicConstant")
private void setWindowConfig(@NotNull WindowSettings windowSettings) {
setSize(windowSettings.getWindowSize());
setLocation(windowSettings.getWindowLocation());
setDefaultCloseOperation(windowSettings.getCloseOperation());
setTitle(windowSettings.getWindowTitle());
}

//doesn't get called automatically by AbstractWindow
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/commonGraphics/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,10 @@ _Check code for more info..._
Commonly used side panels

_Check code for more info..._


## graphicalPanels

Simple graphical panels.

_Check code for more info..._
12 changes: 4 additions & 8 deletions src/test/java/commonGraphics/UpdatingWindow.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package commonGraphics;

import java.awt.Point;
import java.awt.Dimension;

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

Expand All @@ -15,15 +12,14 @@ public abstract class UpdatingWindow extends AbstractWindow {
private final @NotNull WindowUpdater windowUpdater;

//with default frame rate
public UpdatingWindow(@Nullable Dimension size, @Nullable Point location, @Nullable String title) {
super(size, location, title);
public UpdatingWindow(@Nullable WindowSettings windowSettings) {
super(windowSettings);
windowUpdater = new WindowUpdater(this);
}

//with custom frame rate
public UpdatingWindow(@Nullable Dimension size, @Nullable Point location, @Nullable String title,
long frameRate) {
super(size, location, title);
public UpdatingWindow(@Nullable WindowSettings windowSettings, long frameRate) {
super(windowSettings);
windowUpdater = new WindowUpdater(this, frameRate);
}

Expand Down
54 changes: 54 additions & 0 deletions src/test/java/commonGraphics/WindowSettings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package commonGraphics;

import java.util.Objects;
import java.awt.Dimension;
import java.awt.Point;
import javax.swing.WindowConstants;

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

//
public class WindowSettings {
private static final @NotNull Dimension DEFAULT_WINDOW_SIZE = new Dimension(1200, 850);
private static final @NotNull Point DEFAULT_WINDOW_LOCATION = new Point(50, 50);
private static final int DEFAULT_CLOSE_OPERATION = WindowConstants.EXIT_ON_CLOSE;
private static final @NotNull String DEFAULT_WINDOW_TITLE = "An unnamed window";
private final @NotNull Dimension windowSize;
private final @NotNull Point windowLocation;
private final int closeOperation;
private final @NotNull String windowTitle;

//
public WindowSettings(@Nullable Dimension size, @Nullable Point location, @Nullable String title) {
windowSize = Objects.requireNonNullElse(size, DEFAULT_WINDOW_SIZE);
windowLocation = Objects.requireNonNullElse(location, DEFAULT_WINDOW_LOCATION);
closeOperation = DEFAULT_CLOSE_OPERATION;
windowTitle = Objects.requireNonNullElse(title, DEFAULT_WINDOW_TITLE);
}

//
public WindowSettings() {
this(null, null, null);
}

//
public final @NotNull Dimension getWindowSize() {
return windowSize;
}

//
public final @NotNull Point getWindowLocation() {
return windowLocation;
}

//
public final int getCloseOperation() {
return closeOperation;
}

//
public final @NotNull String getWindowTitle() {
return windowTitle;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package baryGraphics.panels;
package commonGraphics.panels.graphicalPanels;

import java.awt.Color;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package baryGraphics.panels;
package commonGraphics.panels.graphicalPanels;

import org.jetbrains.annotations.NotNull;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import static commonGraphics.ColorUtils.TRANSPARENT_BLACK;
import commonGraphics.panels.FixedHorizontalPanel;

//
//a horizontal section for a vertical side-panel
public abstract class AbstractSectionPanel extends FixedHorizontalPanel {
//
public AbstractSectionPanel(int height,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import commonGraphics.panels.FixedVerticalPanel;

//
//an abstract vertically-fixed side-panel, intended to be used in the main panel
public abstract class AbstractSidePanel extends FixedVerticalPanel implements SectionContainerInterface {
//
public AbstractSidePanel(int width, @Nullable Color background,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package commonGraphics.panels.sidePanels;

//
//for panels that contain section-panels
public interface SectionContainerInterface {
void addSections();
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import commonGraphics.panels.sidePanels.AbstractSidePanel;
import commonGraphics.UpdatingWindow;

//
//a common left side-panel
public abstract class CommonLeftSidePanel extends AbstractSidePanel {
private static final int DEFAULT_PANEL_WIDTH = 200;
private static final @Nullable Color DIAGONAL_COLOR = null;
Expand Down
7 changes: 1 addition & 6 deletions src/test/java/demo/graphics/DemoWindow.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package demo.graphics;

import java.awt.Point;
import java.awt.Dimension;
import java.awt.Color;
import java.awt.LayoutManager;
import javax.swing.BoxLayout;
Expand All @@ -19,9 +17,6 @@

//A graphical window for demo.
public final class DemoWindow extends UpdatingWindow {
private static final @NotNull Dimension WINDOW_SIZE = new Dimension(1200, 850);
private static final @NotNull Point WINDOW_LOCATION = new Point(50, 50);
private static final @NotNull String WINDOW_TITLE = "Bary window!";
private static final long FRAME_RATE = 60;
private static final @NotNull Color
MAIN_PANEL_BACKGROUND_COLOR = getGray(50, 255),
Expand All @@ -32,7 +27,7 @@ public final class DemoWindow extends UpdatingWindow {

//Creates a new window.
public DemoWindow(@NotNull BaryUniverse universe) {
super(WINDOW_SIZE, WINDOW_LOCATION, WINDOW_TITLE, FRAME_RATE);
super(new DemoWindowSettings(), FRAME_RATE);
this.universe = universe;
observer = new Observer();
addPanels();
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/demo/graphics/DemoWindowSettings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package demo.graphics;

import java.awt.Dimension;
import java.awt.Point;

import org.jetbrains.annotations.NotNull;

import commonGraphics.WindowSettings;

//
public class DemoWindowSettings extends WindowSettings {
private static final @NotNull Dimension WINDOW_SIZE = new Dimension(1200, 850);
private static final @NotNull Point WINDOW_LOCATION = new Point(50, 50);
private static final @NotNull String WINDOW_TITLE = "Bary window!";

//
DemoWindowSettings() {
super(WINDOW_SIZE, WINDOW_LOCATION, WINDOW_TITLE);
}
}
9 changes: 2 additions & 7 deletions src/test/java/planetTest/graphics/TestWindow.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package planetTest.graphics;

import java.awt.Point;
import java.awt.Dimension;
import java.awt.Color;
import java.awt.LayoutManager;
import javax.swing.BoxLayout;
Expand All @@ -16,21 +14,18 @@

//A graphical window for planetary testing purposes.
public final class TestWindow extends UpdatingWindow {
private static final @NotNull Dimension WINDOW_SIZE = new Dimension(700, 500);
private static final @NotNull Point WINDOW_LOCATION = new Point(50, 50);
private static final @NotNull String WINDOW_TITLE = "Planet test";
private static final @NotNull Color
MAIN_PANEL_BACKGROUND_COLOR = getGray(50, 255),
MAIN_PANEL_BORDER_COLOR = getGray(40, 255);
private final @NotNull PlanetContainer planetContainer;

//
public TestWindow(@NotNull PlanetContainer planetContainer) {
super(WINDOW_SIZE, WINDOW_LOCATION, WINDOW_TITLE); //default frame rate
super(new TestWindowSettings()); //default frame rate
this.planetContainer = planetContainer;
//observer = new Observer();
addPanels();
//addKeyListener(new DemoKeyListener(observer));
//addKeyListener();
revalidate();
startUpdating();
}
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/planetTest/graphics/TestWindowSettings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package planetTest.graphics;

import java.awt.Dimension;
import java.awt.Point;

import org.jetbrains.annotations.NotNull;

import commonGraphics.WindowSettings;

//
public class TestWindowSettings extends WindowSettings {
private static final @NotNull Dimension WINDOW_SIZE = new Dimension(700, 500);
private static final @NotNull Point WINDOW_LOCATION = new Point(50, 50);
private static final @NotNull String WINDOW_TITLE = "Planet test";

//
TestWindowSettings() {
super(WINDOW_SIZE, WINDOW_LOCATION, WINDOW_TITLE);
}
}
41 changes: 6 additions & 35 deletions src/test/java/planetTest/graphics/panels/CentralPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,28 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import baryGraphics.panels.CenteredDrawPanel;
import baryGraphics.panels.ScaledDrawInterface;
import planetTest.planetModel.Planet;
import planetTest.planetModel.PlanetContainer;
import planetTest.planetGraphics.PlanetDrawPanel;

//
public final class CentralPanel extends CenteredDrawPanel implements ScaledDrawInterface {
private static final double DEFAULT_SCALE = 2.0;
private static final @NotNull Color
BACKGROUND = Color.black,
TEXT_COLOR = Color.white;
private double scale;
private final @NotNull PlanetContainer planetContainer;
public final class CentralPanel extends PlanetDrawPanel {
private static final @NotNull Color TEXT_COLOR = Color.white;

//
public CentralPanel(@NotNull PlanetContainer planetContainer,
@Nullable Color borderColor, @Nullable Color diagonalColor) {
super(
BACKGROUND,
planetContainer,
borderColor, true,
diagonalColor, true);
scale = DEFAULT_SCALE;
this.planetContainer = planetContainer;
}

//
@Override
public double getScale() {
return scale;
}

//
@Override
public void mainPaint(@NotNull Graphics g) {
@Nullable Planet planet = planetContainer.getPlanet();
if (planet != null) paintPlanet(g, planet);
super.mainPaint(g);
g.setColor(TEXT_COLOR);
g.drawString("A planet test", 100, 100);
// paint more stuff here, if needed
}

private void paintPlanet(@NotNull Graphics g, @NotNull Planet planet) {
g.setColor(planet.getColor());
double scaledRadius = scaleValue(planet.getRadius());
double @NotNull []
relativeLocation = new double[2], // relative to yet non-implemented observer
drawLocation = applyDrawCenterOffset(scaleLocation(relativeLocation));
int scaledIntegerDiameter = (int) (scaledRadius * 2);
g.fillOval(
(int) (drawLocation[0] - scaledRadius),
(int) (drawLocation[1] - scaledRadius),
scaledIntegerDiameter, scaledIntegerDiameter);
// Paint more stuff here, if needed.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ final class ThirdSection extends AbstractSectionPanel {
//
@Override
public void mainPaint(@NotNull Graphics g) {
g.setColor(TEXT_COLOR);
drawInfoLine(g, "Blank section", 1);
g.setColor(HEADING_COLOR);
drawInfoLine(g, "Blank section", 1);
g.setColor(TEXT_COLOR);
drawInfoLine(g, "For future use", 2);
// Paint more stuff here, if needed.
}
Expand Down
Loading