Skip to content
This repository has been archived by the owner on Feb 4, 2024. It is now read-only.

Rework UI building #24

Merged
merged 9 commits into from
Apr 27, 2021
Merged

Rework UI building #24

merged 9 commits into from
Apr 27, 2021

Conversation

jaghaimo
Copy link
Owner

Closes #22

@jaghaimo jaghaimo mentioned this pull request Apr 27, 2021
Copy link
Contributor

@mnukka mnukka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit of history on lombok:

The granural control with @Getter @Setter was the first thing project lombok offered. However later on they added @Data annotation.

From my experience it is better to have granural control only when you really need it. Whenever possible, write least amount of code. In otherwords, use annotations on top of the class.

As you read the code from top to down, you will see right away on the class that "ok there are getters and setters", instead of going through full class and finding out for yourself.

For example Spring framework (REST applications / Dependency injection) has most of its annotations on class level. I think it is like in 80% of the java applications today so java devs are very used to such practice.

@@ -33,7 +33,9 @@ private CommodityTab(String title) {
}
}

@Setter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future, if you end up with a class where you have 3-4 setters and maybe some instance variables you are not necessarily exposing already then it is ok practice to just add @Data on the class itself not micromanaging individual properties with Getter/Setter functionality.

If there are some properties that you do not want to be made accessible through getters/setters then you can use

@Getter(value = AccessLevel.NONE)
@Setter(value = AccessLevel.NONE)
private Datatype myVariableName;

As the code is generated then having lombok generate a method that is not used vs human is wasting time on reading dead code - there is a difference. I would rather read less and have some dead functions in compile time. Most of the time it will not hurt anybody.

There are exceptions to everything of course. When you are writing a library for example then obviously the exposed api has to be thought through.

@@ -28,7 +26,7 @@ public static void fatal(Object logObject) {
}

private static Logger getLogger() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unsure if this helper is necessary. Logging elevation should be switched via configuration files. As a developer, you have full control over that file. In release build you can toggle logging elevation to be OFF.

This is generally how it is used and appropriate configuration settings are then in log4j.properties file. https://docs.oracle.com/cd/E29578_01/webhelp/cas_webcrawler/src/cwcg_config_log4j_file.html

public class SomeClass {
    private static final Logger LOG = Logger.getLogger(SomeClass.class);

This is an interesting workaround :D (below in the same file)

return Class.forName(Thread.currentThread().getStackTrace()[4].getClassName());

PS: I could do this change myself later on.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please. I wanted to have a no-brains logger without having to declare the logger in each class. Ideally, I'd like to have both class name, method and line number of the log:

fqdnClass.method(line number): message
stelnet.ui.Renderer.render(24): I have so much data but actual message is useless.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please. I wanted to have a no-brains logger without having to declare the logger in each class.

I see. In that case this helper justifies itself. I am used to writing that extra line myself to show the intent. Matter of preference.

@@ -25,12 +26,14 @@

public class ButtonManager {

@Getter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I would use class level @Getter instead

@Getter
public class ButtonManager {

@@ -3,12 +3,16 @@
import java.util.HashSet;
import java.util.Set;

import lombok.Getter;
import stelnet.filter.cargostack.CargoStackFilter;
import stelnet.filter.fleetmember.FleetMemberFilter;

public class FilterManager {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I would use class level @Getter instead

@Getter
public class FilterManager {


private final Size size;
private final String title;
public class Button extends Renderable implements ButtonHandler {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditch the @Getter @Setter and use

@Data
public class Button extends Renderable implements ButtonHandler {

If you really really do not want to expose title and handler via setters then you can:

@Setter(value = AccessLevel.NONE)
private int mySecret;

};

@Getter
private int horizontalDirection;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can add here also @Getter on top of the enum itself.

@@ -1,8 +1,12 @@
package stelnet.ui;

import lombok.Getter;

public class Position {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class level @Getter

Comment on lines +53 to +74
public Size getSize() {
if (size == null) {
LogHelper.warn("Null size found");
}
return size;
}

public Location getLocation() {
return location;
}

public Position getOffset() {
return offset;
}

public void setLocation(Location location) {
this.location = location;
}

public void setOffset(Position offset) {
this.offset = offset;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could add here class level @Getter and keep custom implementation of getSize

@@ -3,18 +3,18 @@
import com.fs.starfarer.api.ui.IntelUIAPI;
import com.fs.starfarer.api.ui.TooltipMakerAPI;

public class SimpleCallback implements Callable {
public class SimpleHandler implements ButtonHandler {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SimpleHandler vs EventHandler

@@ -1,23 +1,19 @@
package stelnet.ui;

import lombok.Getter;

public class Size {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class level getter annotation

@jaghaimo
Copy link
Owner Author

A bit of history on lombok:

The granural control with @Getter @Setter was the first thing project lombok offered. However later on they added @Data annotation.

From my experience it is better to have granural control only when you really need it. Whenever possible, write least amount of code. In otherwords, use annotations on top of the class.

As you read the code from top to down, you will see right away on the class that "ok there are getters and setters", instead of going through full class and finding out for yourself.

For example Spring framework (REST applications / Dependency injection) has most of its annotations on class level. I think it is like in 80% of the java applications today so java devs are very used to such practice.

Happy with @DaTa. I'll change it in another MR as I don't want to hold you up and won't have time today to make the change.

@jaghaimo jaghaimo merged commit aeed121 into master Apr 27, 2021
@jaghaimo jaghaimo deleted the 22-ui branch April 27, 2021 15:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clean-up GridRenderer and GridData
2 participants