Map image blinks while adding more layers to it - java

I have an application in java swing and geotools. I have displayed a map image and trying to add images as layers to it. When it adds layer it blinks and after some time at the call to addLayer function map image and other few layers disappear for some time. How to stop this? I am loging all the information at the same time in SQLite and then to my own customised file.
I have stopped trying refreshing all after addLayer function call. The all process should work smoothly without blinking and disappearing. Please Help.

The gt-swing module is really only intended for simple demonstrations. If you intend to use it in production you should add in off screen buffering to allow "fast" refreshes of the map without rereading all the displayed data.

Related

setImage often without blocking UI thread Android

I have an ImageView. When user presses button I want to change image (it is animation-list) and run this animation. I used to use setImageResource, but it blocks UI thread and causes lags. I can't predict what image I would set befor user presses button. I tried to preload drawables but it causes OOM, because I have about 30 xmls with animation-list. How can I solve It? To sum up, I want to fastly change image in my ImageView and then start frame animation on it.
I think you are performing a fetch operation on the UI thread for the image(either from storage or network call). That is what is causing the lag.
You might look into using a library to load up your images. There is one that is really easy to implement called Picasso. It's been around for a while too, so it should be easy to see some examples.

How to implement lazy rendering/pagination for an Android TextView

I have an Android app that offers syntax highlighting for source code files. It's performing very poorly for large files such as this and freezing the UI for 10+ seconds. I have profiled my app and a method out of my control appears to be taking up a lot of time on the main thread. I would like to implement lazy rendering / 'pagination' so that instead of coloring the whole file when the user loads it, I only color what the user sees at first, and color in uniformly-sized chunks as (s)he scrolls down. What are some approaches I can take to implementing this? Thanks.

LibGDX Saving progress when switching screen

How can I switch the screen and still save the progress of the current game? For example I have an additional screen, when you press tab key, that shows some information about the player (attributes, stats, etc.), but when you switch the screen again to resume your game the show method is called again and you lose everything... The only method I know is that before you hide the screen to save the game in some format and load it in show but I highly doubt that this is the proper way to do it, as there would be a real performance issue when you switch the screens very fast... I need a way to keep the data from the previous screen and not initialize it every time the screen is showed. This would also apply to the skill tree and inventory which also needs to be saved for the entire game session. The filed loading from save game file format should be done only once not every time a screen changes. Any ideas?

Creating all JPanels at program startup vs. creating them only when needed

As a general rule, should a program with multiple sections create everything at startup or should it wait to create each part when it is actually needed?
My specific case is a Java kiosk-style application that has multiple different sections. Each section is a different JPanel (with different buttons / JTables / JLabels / etc.) that does a specific task. This is an unfinished project that I haven't touched in a while, but I'm going to complete it and I'm looking at the code and trying to refactor what I think I should have done otherwise.
So far, the program is creating every single JPanel at startup, so whenever an user clicks on one of the button that changes which JPanel is shown, it it loaded instantly since it's already created. So far, I don't think it would matter that much performance-wise, but I'd like to know what is standard practice in this case.
I would not load all on start up, as it might make start up slow and also some panels are loaded which are not required. For example you have 4 panels loaded contact, about, pics, and feeds. Suppose you load all 4 at start up, what if user just visited only 2 of them and then close the application. Sometimes it is possible that user wants see only one panel but he has to wait for all panels to load at start up. So I will suggest to load panels as they are required. Load only primary data on frame, and then when user clicks on a button for first time which loads a panel, show a progress bar until that panel is loaded, and from the next time he clicks on button just display the panel with out waiting as it is loaded already by first click.
If your application is getting data from internet then loading all data on start up will also cost extra band width and data charges.
It depends on you project need.
If response time is important for end user , then your approach is correct.
else create the jpanel on demand
I think it depends a lot on how much it costs to create that JPanel. If it contains a JTable with a lot of information that it receives, for example, from a MySQL server over the network, then the cost of creating that JPanel is quite big.
In this case, I would create it only when it is needed. Maybe that JPanel is never needed while the program is running, so why spend all that time and resources creating it ?

How to show loading

I want to know how to show the loading of an application. Normally (let's say Netbeans IDE,)
the application will show how far it has loaded and how far to load. Also, loading classes as well can be seen in welcome page. How is this is done and how we can show our classes loading and loaded status (in a progress bar) in our applications? Also let's say that we have used Hibernate, and there is a login on first page, it takes time to start but only for the starting (I think it is because that the Hibernate factory is getting started and load its classes). The answer is hoped in Java.
I want to know how to show the loading of an application.
See the java.awt.SplashScreen class. But..
..show how far it has loaded and how far to load.
..with a customized image. Call SplashScreen.createGraphics() to get a Graphics object (from the image defined as a splash in the manifest) which can be drawn on. Draw the progress bar at an appropriate location on the Graphics object. For the progress bar, either use a JProgressBar as already mentioned, or to keep it lean (using pure AWT), draw one big Rectangle to represent the bar, and fill a smaller Rectangle to represent the progress.
See also How to Create a Splash Screen in the Java Tutorial. (Where you can see that image above.)
That sounds for using JProgressBar, combined with Splash Screen or JDialog.
Be sure that JProgressBar must be updated on the Event Dispatch Thread, more about that in Concurrency in Swing,
Then you have two choices as to how to update a JProgressBar correctly - by wrapping code into:
SwingWorker
Runnable/Thread
There is some support built into swing for this. See the tutorial on How to Use Progress Bars to get started.
Here is a very basic code:
JProgressBar progressBar;
progressBar = new JProgressBar(0, task.getLengthOfTask());
progressBar.setValue(33); // put here the percentage you want to display...
progressBar.setStringPainted(true);

Categories

Resources