Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the use of Weblaf from the UI #789

Closed
bevans2000 opened this issue Jan 4, 2023 · 45 comments
Closed

Remove the use of Weblaf from the UI #789

bevans2000 opened this issue Jan 4, 2023 · 45 comments
Assignees
Labels
deprecated to show whee deprecated errors come from or APIS improvement
Milestone

Comments

@bevans2000
Copy link
Member

Describe the bug
The use of Weblaf is providing problems in Java 17 and beyond, #788. The advantage of moving to Java 17 has been discussed in #437.
There is a potential workaround by changing the JVM arguments but it should be possible to run directly from the JAR file.

To Reproduce (Please provide steps)
Run the swing JAR file with no arguments on 3.4.1. The ui fails to render.

Expected and unexpected behavior
Replace the use of Weblaf classes with the vanilla Swing equivalent. This will be a change to a lot of ui files.

Specifications (please complete the following information):

  • Java version : Any Java17 or beyond
  • mars-sim build version : 3.4.1
@bevans2000 bevans2000 added improvement deprecated to show whee deprecated errors come from or APIS labels Jan 4, 2023
@bevans2000 bevans2000 self-assigned this Jan 4, 2023
@bevans2000
Copy link
Member Author

bevans2000 commented Jan 4, 2023

Initial build without com.alee creates 4K error 😂

Strategy will be to convert specific UI windows one at a time before dropping Weblaf from the pom.

@Urwumpe
Copy link
Contributor

Urwumpe commented Jan 4, 2023

Initial build without com.alee creates 4K error 😂

Yes, that isn't unexpected, just searching the code gives out a similar large number of usages. :D

Maybe you can start by concentrating all common boilerplate code into a common "Corporate Design" class, so that the dependencies on WebLAF are first concentrated there and we can eventually refactor this place. I remember seeing quite a lot of similar code around that just adds the WebLAF style to components. We could maybe replace this by introducting a "Mars-Sim style", which fills the role of WebLAF, but allows us to quickly change the look and feel part of the simulation later.

@bevans2000
Copy link
Member Author

We will start from the outside and work inwards, i.e. the less integrated windows moving towards the MainWindow last.
I'm good to do it but it's a question on what is the target release but that's part of our discussion #371

@bevans2000
Copy link
Member Author

I've converted the Crew Editor class as a trail. Pretty straight forward. This dialog had lots of controls so it was a good test. Other windows will be easier as they are read only.
Just need to choose the target release of 3.4 or 3.5, part of #437 discussion.

bevans2000 added a commit that referenced this issue Jan 4, 2023
Changes:
- Create IconManager to hold and load the various SVG icons replace alee version

Part of #789
bevans2000 added a commit that referenced this issue Jan 5, 2023
Changes:
- Person window & Tabs
- TabPanel provides an getIcon method to find icons.

Part of #789
@bevans2000
Copy link
Member Author

Thoughts on the target release for dropping weblaf and potentially moving to Java 17? I'm thinking 3.5.0.

I'm slowly dropping weblaf from the UI components.
After we need to tidy up how we handled icons. We have 2 ways of managing them based on SVG or PNG. We rely on the message bundle to define the source location but it would make more sense to have a separate "icon set" file that maps from icon id to the file name.

@Urwumpe
Copy link
Contributor

Urwumpe commented Jan 5, 2023

I don't like thinking too much in releases there, if its actually maintenance work. we should put it into the next minor version for sure, by semantic versioning, but I wouldn't mind if it takes until 3.6 to be finished.

Can you make a feature request for the icon set file? I think the idea makes sense, what about just making it a Java resource file, a plain key value format should be good enough there. Also, does it make sense to support both PNG and SVG?

@bevans2000
Copy link
Member Author

Yes I was thinking a Java resource file that is preloaded in the Icon manager. Part of the change would be to have a single one supporting SVG & PNG. Too much effort to change the existing SVG to PNG. Also needs to support default sizing, but I've an idea about that.
Once I've done all the Unit windows I will push it to master as a work in progress commit.

bevans2000 added a commit that referenced this issue Jan 6, 2023
Changes:
- Create IconManager to hold and load the various SVG icons replace alee version

Part of #789
bevans2000 added a commit that referenced this issue Jan 6, 2023
Changes:
- Person window & Tabs
- TabPanel provides an getIcon method to find icons.

Part of #789
bevans2000 added a commit that referenced this issue Jan 6, 2023
bevans2000 referenced this issue Jan 7, 2023
01.06.2023

- fix: correct NPE in MapTask in MapPanel when calling map.drawMap()
       Initialize map instance as surf map in constructor
- new: add QUARTER_RANGE, HALF_RANGE, and MAX_RANGE in Settlement
- change: rework missionRange in Settlement

Related to
#788 (comment)
bevans2000 added a commit that referenced this issue Jan 8, 2023
In addition convert time window and remove unused classes.

Part of #789
bevans2000 added a commit that referenced this issue Jan 8, 2023
bevans2000 added a commit that referenced this issue Jan 8, 2023
MonitorWindow now selects 1st Settlement
Correct empty lanel in Scientific Tool

Part of #789
@bevans2000
Copy link
Member Author

@mokun I have been slowly converting the UI code base and have completed about 75%. What I have noticed along the way is there is a lot of Font management going on with many Font instantiations going on. Also there seems to be a mixture of Fonts with some inconsistency.
Once we remove weblaf, I feel we should do a review of the Fonts and try to use the defaults in the UIManager as much as possible. Panel titles is a particular case were we have to specify a different font style.

@bevans2000
Copy link
Member Author

@mokun I have been slowly converting the UI code base and have completed about 75%. What I have noticed along the way is there is a lot of Font management going on with many Font instantiations going on. Also there seems to be a mixture of Fonts with some inconsistency. Once we remove weblaf, I feel we should do a review of the Fonts and try to use the defaults in the UIManager as much as possible. Panel titles is a particular case were we have to specify a different font style.

What I want to do is drop the use of explicit Fonts altogether and use HTML styling to "adjust" rendering where needed. For example on the Panel titles we would do "Panel Title". This means that we can use any font that is specified as part of the Look And Feel without overriding it.

@Urwumpe
Copy link
Contributor

Urwumpe commented Jan 10, 2023

I like the idea. Could it be implemented maybe even in a way, that we give the same kind of elements the same kind of styling throughout the UI?

@bevans2000
Copy link
Member Author

I like the idea. Could it be implemented maybe even in a way, that we give the same kind of elements the same kind of styling throughout the UI?

Yes I think so because there is mixture of styles. My thoughts are to push everything back to defaults and then customised only what is needed
Just realised that I didn't escape the html in my above comment but you get the idea.

@Urwumpe
Copy link
Contributor

Urwumpe commented Jan 10, 2023

Just realised that I didn't escape the html in my above comment but you get the idea.

My smartphone displayed the contents first as plain UTF-8, so yeah, I understood it. :D

bevans2000 added a commit that referenced this issue Jan 15, 2023
@bevans2000
Copy link
Member Author

@mokun Converting the Commander Tool today and it seems to have a few problems and unimplemented Tabs already. I'm not going to try and fix the issues I find.

mokun referenced this issue Jan 15, 2023
01.14.2023

- fix: correct conversionFuel2DriveEnergy in Vehicle
- fix: correct energyUsed calculation in calculateFuelUsed() in
OperateVehicle
- fix: correct instantaneous fuel consumption
- style: use textfields in MainDetailPanel

#795
@mokun
Copy link
Member

mokun commented Jan 15, 2023

it seems to have a few problems and unimplemented Tabs already

Yes. It's been a while since I updated the Commander Dashboard. I may have done once or twice just to keep it from breaking.

At first, I thought it was a great idea to implement many new and latest changes in the Dashboard's tabs in Command Mode because they are still being tested and can be "breaking".

But the Command Mode limits the player to work with one settlement only, and that we need to observe if those new changes work for all settlements or not, at some points, we decide to go directly with implementing changes in the Sandbox Mode.

That's said, we need to redefine what we want to do with Command Mode and the dashboard and the contents we want to put in all the tabs.

We have said that we come up with a tab for each division as a way of adding more interactivity to mars-sim by giving players more options to toggle in each division.

bevans2000 added a commit that referenced this issue Jan 15, 2023
Changes:
- CommanderWindow no longer uses weblaf
- CommanderWindow now uses FactoryMetaTask
Part of #789
@mokun
Copy link
Member

mokun commented Jan 19, 2023

Dont know but why are we using SVG fonts anyway? We are usi g way too many Fonts already.

It's scalable, you know

@Urwumpe
Copy link
Contributor

Urwumpe commented Jan 19, 2023

It's scalable, you know

That applies to most vector fonts today, including OTF and TTF.

Also, it makes the UI design pretty chaotic to use too many fonts. Its like an early 1990s homepage.

@bevans2000
Copy link
Member Author

We should be able to use standard fonts from the UIManager I think.

@mokun
Copy link
Member

mokun commented Jan 19, 2023

Sorry. my mistake. I meant to say SVG icons, not fonts.

@Urwumpe
Copy link
Contributor

Urwumpe commented Jan 20, 2023

Sorry. my mistake. I meant to say SVG icons, not fonts.

Ah, that makes way more sense now. :)

Well, we already use SVG images for the settlement map, can't we use this as starting point to create a custom button class which renders a SVG image?

@mokun
Copy link
Member

mokun commented Jan 20, 2023

Yea. We may be able to come up with that with what's shown here

Or try something like this.

In case of weblaf, it uses SVG Salamander, as explained in here.

May we can replicate what's done in weblaf using SVG Salamander since it looks like it's a more direct and faster approach.

@mokun
Copy link
Member

mokun commented Jan 20, 2023

Batik uses a lot of separate libraries and is very bloated and is something like ~8 (or 3.2 compressed) MB in size. I bet Batik also uses a lot of other dependencies.

In comparison, currently, our mars-sim binary jar stands at about ~45 MB (compressed).

image

image

Can we switch to using SVG Salamander (< 400 KB uncompressed) for displaying the image of each building as well as svg fonts ?

@bevans2000
Copy link
Member Author

That sounds good but let's focus on dropping weblaf first. Then as part of #791 we can consolidate how we manage icons. Control that in our own iconmanager class to allow us to be specific for vehicles, settlements etc. Then icon and image loading will be one pla e and hence easier to replace.

@mokun
Copy link
Member

mokun commented Jan 20, 2023

But we currently reply on weblaf's own icon manager for rendering svg-based icons.

So, in order to drop weblaf, we may need to figure out a replacement for reading svg icons at the same time.

@bevans2000
Copy link
Member Author

I've already started changing the SVG loading

bevans2000 added a commit that referenced this issue Jan 21, 2023
Changes:
- Remove Weblaf from the popupunitmenu class
- Reworked PopupUnitMenu to only build items needed.
- Removed basic weblaf compoennts from the ToolToolBar
- Move openBrowser method to MainWidnow to provide resuse
Part of #789
bevans2000 added a commit that referenced this issue Jan 22, 2023
Changes:
- Create a new SwingHelper class to hold comman reused logic
- MarsCalendar popup & toolbar button changed to use a JDialog create byt SwingHelper
- SwingHelper refactor the popup logic  in PopUpUnitMenu to supprot any floating popup window.
- OpenBrowser method moved from MainWindow to the SwingHelper class
- Remove some unused classes

Part of #789
bevans2000 added a commit that referenced this issue Jan 27, 2023
Changes:
- Remove weblaf from NavigationWindow
- Use ActionCommand for options menu in NavigationWindow
- Remove weblaf from SettlementTransparentPanel
- Rework image icons in SettlementTransparentPanel

Part of #789
bevans2000 added a commit that referenced this issue Jan 28, 2023
The weblaf UIManager is interferring with the standard JToolbar by adding an extra Margin & different layout.
This means the new toolbar is slightly heighter than the old one but will revisit it once weblaf is totally removed.

Changes:
- ToolToolBar is using the basic JToolbar class now
- ToolToolBar uses a single action listener emthod and the ActionCommand pattern to execute the correct action.
- Toolbar now control s the various date labels.
- Date fields are now basic JLabels and not text fields.
- Remvoed all the displaying of date/time logic from MainWindow

Part of #789
@bevans2000
Copy link
Member Author

@mokun I worked on this last night and the only bit of WebLaf left is the pause overlay in the MainWindow. I don't know how to replace this at the moment; I think a JLayer could be used but not sure.
So the question is could we drop the Pause Overlay in the short term to progress to continue with the upgrade to Java 17?
I will commit my changes tonight.

@mokun
Copy link
Member

mokun commented Feb 1, 2023

could we drop the Pause Overlay in the short term to progress to continue with the upgrade to Java 17?

Yes we may as well drop it. We'll find another way to pause

@bevans2000
Copy link
Member Author

could we drop the Pause Overlay in the short term to progress to continue with the upgrade to Java 17?

Yes we may as well drop it. We'll find another way to pause

Ok. To be clear, the pause logic is working, I've replaced the WebSwitch class. The pause overlay I haven't managed to migrate yet, I think the answer is to use a JLayer but I don't understand

@mokun
Copy link
Member

mokun commented Feb 1, 2023

I've replaced the WebSwitch class.

So what do you replace with ?

@mokun
Copy link
Member

mokun commented Feb 1, 2023

Shall we look for a more lightweight LAF library that's Java 17 compatible and provide more decent UI elements than what Swing provides ?

bevans2000 added a commit that referenced this issue Feb 1, 2023
Remove the weblaf components from the MainWindow status bar.

Changes:
- Create a new JMemoryMeter component based on JProgressBar
- Replace Webmemorybar with the new JMemoryMeter component
- Replace WebSwitch with a JToggleButton for the pause button
- PauseButton uses a ItemListner to flip the image when it is activated
- OverlayCheckBox is enabled all times to accomodate the new pause logic
- Displaying of the overlay is covered by a new method displayOverlay
- Remove use of weblaf IconManager from MSPIconManager
- Remove unused static finals and methods

Part of #789
@bevans2000
Copy link
Member Author

I've replaced the WebSwitch class.

So what do you replace with ?

Just pushed a commit

@bevans2000
Copy link
Member Author

Shall we look for a more lightweight LAF library that's Java 17 compatible and provide more decent UI elements than what Swing provides ?

I don't mind but the question is do we need anything beyond basic Swing? You wanted to look at doing a different UI client but I see JavaFX is no longer supported within the JavaSE.

@bevans2000
Copy link
Member Author

bevans2000 commented Feb 1, 2023

I've just done the least part to remove the weblaf including the look and feel raking it back to vanilla Swing. It works but look rough, also it highlights where they is specific customization in the code. It looks like we have some extra styling on the monitor tables. I think we should carry on with this approach and get back to basic Swing. Then use a look and feel class like FlatLAF. https://www.formdev.com/flatlaf/

Flatlaf can help us with fonts as well, https://www.formdev.com/flatlaf/typography/#set_font.
We can use the consolidate our use of Fonts by using styles in the UIManager instead of explicitly creating them

@mokun
Copy link
Member

mokun commented Feb 1, 2023

And we may use Radiance for theming, adding better image, font and text rendering.

It also supports SVG Transcoder.

It supports Java 17.

@bevans2000
Copy link
Member Author

Ok, do we want to start using custom components again? But I think the idea of theming is the right direction. We need to strip out all the custom Font and Color assignments and rely on the UIManager stylingmaybe leave SettlementMapPanel alone.
We need to pick a style for heading/title labels

@bevans2000
Copy link
Member Author

bevans2000 commented Feb 2, 2023

Yeah, it's finished. 🥳
The only causality has been the blocking pause overlay in the main window. This has been removed as it proved difficult to convert the WebOverlay class. We need to decide on a new strategy for presenting the paused state to the user.
Follow-up activity is to clean up the use of Fonts & Colors and fall back to the styling from the UIManager and hence the look and feel class. #801

@mokun
Copy link
Member

mokun commented Feb 4, 2023

We actually have been using one of the Radiance's component called Trident for animation.

		<!-- trident animation library is required by steelseries.extras in mars-sim-ui
		     https://search.maven.org/artifact/org.pushing-pixels/radiance-trident
		     https://mvnrepository.com/artifact/org.pushing-pixels/radiance-trident/1.0.2 : 78KB
		     https://github.com/kirill-grouchnikov/radiance/blob/master/docs/trident/trident.md 79KB -->
		<!-- Note: steelseries requires 1.0.2. 2.0.1 does NOT work.  -->
		<dependency>
		  <groupId>org.pushing-pixels</groupId>
		  <artifactId>radiance-trident</artifactId>
		  <version>4.5.0</version>
		</dependency>

The steelseries gauges requires it internally, I think. We used to use the source code of the steelseries. Now we have already switched to its maven artifact.

We may or may not need Trident explicitly anymore.

Shall we start using Radiance ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecated to show whee deprecated errors come from or APIS improvement
Projects
None yet
Development

No branches or pull requests

3 participants