Skip to content

Commit a2a1d9a

Browse files
committed
Deprecate usages of java.awt.Color for removal.
We have quite a lot of deprecations lately, but times change, so things will get deprecated. This is how life works and deprecations are vital for a healthy API.
1 parent 576bf39 commit a2a1d9a

12 files changed

Lines changed: 77 additions & 28 deletions

File tree

src/main/java/de/geolykt/starloader/api/empire/Alliance.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package de.geolykt.starloader.api.empire;
22

3-
import java.awt.Color;
43
import java.util.ArrayList;
54

65
import org.jetbrains.annotations.NotNull;
76

7+
import com.badlogic.gdx.graphics.Color;
8+
89
import snoddasmannen.galimulator.GalColor;
910

1011
public interface Alliance extends Dateable {
@@ -31,9 +32,18 @@ public interface Alliance extends Dateable {
3132
* This method can be preferable over {@link #getColor()} as latter is only present within Galimulator proper
3233
* while this component is provided by most Java SE implementations starloader will run on.
3334
*
34-
* @return The {@link Color} of the alliance
35+
* @return The {@link java.awt.Color} of the alliance
36+
* @deprecated java.awt.Color getters and setters are scheduled for purging in a future version
37+
*/
38+
@Deprecated(forRemoval = true, since = "1.5.0")
39+
public @NotNull java.awt.Color getAWTColor();
40+
41+
/**
42+
* Obtains the Color of the Alliance used for UI.
43+
*
44+
* @return The {@link GalColor} of the alliance
3545
*/
36-
public @NotNull Color getAWTColor();
46+
public @NotNull Color getGDXColor();
3747

3848
/**
3949
* Obtains the Color of the Alliance used for UI.

src/main/java/de/geolykt/starloader/api/empire/Empire.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package de.geolykt.starloader.api.empire;
22

3-
import java.awt.Color;
4-
53
import org.jetbrains.annotations.NotNull;
64

5+
import com.badlogic.gdx.graphics.Color;
6+
77
import de.geolykt.starloader.api.Galimulator;
88
import de.geolykt.starloader.api.Identifiable;
99

@@ -26,15 +26,27 @@ public default int getAge() {
2626
}
2727

2828
/**
29-
* The galimulator color is used for multiple interfaces as well as to paint the
29+
* The empire color is used for multiple interfaces as well as to paint the
3030
* territory of an empire to a constant color, the color as such should not
3131
* change without reason to not confuse the user.
3232
* This method can be preferable over {@link #getColor()} as latter is only present within Galimulator proper
3333
* while this component is provided by the JVM
3434
*
35-
* @return The AWT {@link Color} assigned to the empire
35+
* @return The AWT {@link java.awt.Color} assigned to the empire
36+
* @deprecated java.awt.Color getters and setters are scheduled for purging in a future version
37+
*/
38+
@Deprecated(forRemoval = true, since = "1.5.0")
39+
public @NotNull java.awt.Color getAWTColor();
40+
41+
/**
42+
* The empire color is used for multiple interfaces as well as to paint the
43+
* territory of an empire to a constant color, the color as such should not
44+
* change without reason to not confuse the user.
45+
*
46+
* @return The GDX {@link Color} assigned to the empire
3647
*/
37-
public @NotNull Color getAWTColor();
48+
@NotNull
49+
public Color getGDXColor();
3850

3951
/**
4052
* The year the empire collapsed, or -1 if the empire did not collapse.
@@ -44,7 +56,7 @@ public default int getAge() {
4456
public int getCollapseYear();
4557

4658
/**
47-
* The galimulator color is used for multiple interfaces as well as to paint the
59+
* The empire color is used for multiple interfaces as well as to paint the
4860
* territory of an empire to a constant color, the color as such should not
4961
* change without reason to not confuse the user.
5062
*

src/main/java/de/geolykt/starloader/api/gui/FlagComponent.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ public interface FlagComponent {
1919
* of this class. However this is cached once per instance of the underlying Galimulator-specific color object.
2020
*
2121
* @return The color that should be used to render the {@link FlagSymbol}. Converted to the AWT Color object.
22+
* @deprecated java.awt.Color getters and setters are scheduled for purging in a future version
2223
*/
2324
@NotNull
25+
@Deprecated(forRemoval = true, since = "1.5.0")
2426
public java.awt.Color getAWTColor();
2527

2628
/**

src/main/java/de/geolykt/starloader/api/gui/graph/LineChart.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,11 @@ protected float getLineThickness() {
132132
return 2.0F;
133133
}
134134

135-
protected @NotNull Color getColor(Object o) {
135+
protected @NotNull Color getColor(@NotNull Object o) {
136136
if (o instanceof Empire) {
137-
java.awt.Color awtColor = ((Empire) o).getAWTColor();
138-
return new Color(awtColor.getRed() / 255.0F, awtColor.getGreen() / 255.0F, awtColor.getBlue() / 255.0F, awtColor.getAlpha() / 255.0F);
137+
return ((Empire) o).getGDXColor();
139138
} else if (o instanceof Alliance) {
140-
java.awt.Color awtColor = ((Alliance) o).getAWTColor();
141-
return new Color(awtColor.getRed() / 255.0F, awtColor.getGreen() / 255.0F, awtColor.getBlue() / 255.0F, awtColor.getAlpha() / 255.0F);
139+
return ((Alliance) o).getGDXColor();
142140
} else {
143141
Color c = new Color(o.hashCode());
144142
c.a = 1.0F;

src/main/java/de/geolykt/starloader/api/gui/screen/ScreenBuilder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ public void addComponentProvider(@NotNull ComponentProvider provider) {
113113
* All RGBA channels will be used and the default value is an Orange-ish color.
114114
*
115115
* @param awtColor The color to use as an Java AWT Color. It will get transformed into Galimulator's internal Color type later on.
116+
*
117+
* @deprecated java.awt.Color getters and setters are scheduled for purging in a future version
116118
*/
119+
@Deprecated(forRemoval = true, since = "1.5.0")
117120
public abstract void setHeaderColor(@NotNull Color awtColor);
118121

119122
/**

src/main/java/de/geolykt/starloader/apimixins/AllianceMixins.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import de.geolykt.starloader.api.event.EventManager;
1717
import de.geolykt.starloader.api.event.alliance.AllianceJoinEvent;
1818
import de.geolykt.starloader.api.event.alliance.AllianceLeaveEvent;
19-
import de.geolykt.starloader.impl.AWTColorAccesor;
2019

2120
import snoddasmannen.galimulator.GalColor;
2221

@@ -73,8 +72,9 @@ public boolean c(snoddasmannen.galimulator.Empire var1) { // hasMember
7372
}
7473

7574
@Override
75+
@Deprecated(forRemoval = true, since = "1.5.0")
7676
public @NotNull Color getAWTColor() {
77-
return ((AWTColorAccesor) getColor()).asAWTColor();
77+
return ((de.geolykt.starloader.impl.AWTColorAccesor) getColor()).asAWTColor();
7878
}
7979

8080
@Override
@@ -93,6 +93,12 @@ public int getFoundationYear() {
9393
return nameIdentifier;
9494
}
9595

96+
@SuppressWarnings("null")
97+
@Override
98+
public com.badlogic.gdx.graphics.@NotNull Color getGDXColor() {
99+
return c().getGDXColor();
100+
}
101+
96102
@SuppressWarnings({ "unchecked", "null" })
97103
@Override
98104
@NotNull

src/main/java/de/geolykt/starloader/apimixins/EmpireAnnalsMixins.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import de.geolykt.starloader.api.Galimulator;
1010
import de.geolykt.starloader.api.empire.ActiveEmpire;
1111
import de.geolykt.starloader.api.empire.Empire;
12-
import de.geolykt.starloader.impl.AWTColorAccesor;
1312

1413
import snoddasmannen.galimulator.GalColor;
1514

@@ -35,8 +34,9 @@ public class EmpireAnnalsMixins implements Empire {
3534
public String nameIdentifier;
3635

3736
@Override
37+
@Deprecated(forRemoval = true, since = "1.5.0")
3838
public @NotNull Color getAWTColor() {
39-
return ((AWTColorAccesor) getColor()).asAWTColor();
39+
return ((de.geolykt.starloader.impl.AWTColorAccesor) getColor()).asAWTColor();
4040
}
4141

4242
@Override
@@ -61,6 +61,12 @@ public int getFoundationYear() {
6161
return birthYear;
6262
}
6363

64+
@SuppressWarnings("null")
65+
@Override
66+
public com.badlogic.gdx.graphics.@NotNull Color getGDXColor() {
67+
return getColor().getGDXColor();
68+
}
69+
6470
@Override
6571
public int getStarCount() {
6672
if (deathYear != -1) {

src/main/java/de/geolykt/starloader/apimixins/EmpireMixins.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
import de.geolykt.starloader.api.registry.Registry;
5353
import de.geolykt.starloader.api.registry.RegistryKeyed;
5454
import de.geolykt.starloader.api.registry.RegistryKeys;
55-
import de.geolykt.starloader.impl.AWTColorAccesor;
5655

5756
import snoddasmannen.galimulator.EmpireAchievement.EmpireAchievementType;
5857
import snoddasmannen.galimulator.EmpireSpecial;
@@ -408,8 +407,9 @@ public Alliance getAlliance() {
408407
}
409408

410409
@Override
410+
@Deprecated(forRemoval = true, since = "1.5.0")
411411
public @NotNull Color getAWTColor() {
412-
return ((AWTColorAccesor) getColor()).asAWTColor();
412+
return ((de.geolykt.starloader.impl.AWTColorAccesor) getColor()).asAWTColor();
413413
}
414414

415415
@Override
@@ -476,6 +476,12 @@ public int getFoundationYear() {
476476
return birthMilliYear;
477477
}
478478

479+
@SuppressWarnings("null")
480+
@Override
481+
public com.badlogic.gdx.graphics.@NotNull Color getGDXColor() {
482+
return getColor().getGDXColor();
483+
}
484+
479485
@SuppressWarnings("null")
480486
@Override
481487
public @NotNull Random getInternalRandom() {

src/main/java/de/geolykt/starloader/apimixins/FlagItemMixins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import de.geolykt.starloader.api.gui.FlagComponent;
1010
import de.geolykt.starloader.api.gui.FlagSymbol;
11-
import de.geolykt.starloader.impl.AWTColorAccesor;
1211

1312
import snoddasmannen.galimulator.FlagItem;
1413
import snoddasmannen.galimulator.FlagItem.BuiltinSymbols;
@@ -46,8 +45,9 @@ public class FlagItemMixins implements FlagComponent {
4645

4746
@Override
4847
@NotNull
48+
@Deprecated(forRemoval = true, since = "1.5.0")
4949
public Color getAWTColor() {
50-
return ((AWTColorAccesor) color).asAWTColor();
50+
return ((de.geolykt.starloader.impl.AWTColorAccesor) color).asAWTColor();
5151
}
5252

5353
@SuppressWarnings("null")

src/main/java/de/geolykt/starloader/apimixins/GalColorMixins.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@
66
import org.spongepowered.asm.mixin.Mixin;
77
import org.spongepowered.asm.mixin.Shadow;
88

9-
import de.geolykt.starloader.impl.AWTColorAccesor;
10-
119
import snoddasmannen.galimulator.GalColor;
1210

11+
/**
12+
* Mixin that implements the AWTColorAccessor on to the GalColor class.
13+
*
14+
* @deprecated The AWTColorAccess class is deprecated for removal and there is no other reason for this class to exist.
15+
*/
16+
@Deprecated(forRemoval = true, since = "1.5.0")
1317
@Mixin(GalColor.class)
14-
public class GalColorMixins implements AWTColorAccesor {
18+
public class GalColorMixins implements de.geolykt.starloader.impl.AWTColorAccesor {
1519

1620
@Shadow
1721
public float a;

0 commit comments

Comments
 (0)