JTextPane editor large file & performance - swing

I'm using a JTextPane to edit XML files. A jflex parser split xml file in tokens and using a custom document (extends
DefaultStyledDocument) i color syntax:
doc.setCharacterAttributes(token.getCharBegin() + change,
token.getCharEnd() - token.getCharBegin(),
Token_Styles_Define.getStyle(token.getDescription()), true);
My problem is to load and edit large xml file, for exemple a 400kb xml file takes 30 seconds and for 700kb 1Mb i get java heap space.
I google it and i found :
" Define a limit that JTextPane/JEditorPane can handle well (like 500KB or 1MB). You'll only need to load a chunk of the file into the control with this size.
Start by loading the 1st partition of the file.
Then you need to interact with the scroll container and see if it has reached the end/beginning of the current chunk of the file. If so, show a nice waiting cursor and load the previous/next chunk to memory and into the text control.
The loading chunk is calculated from your current cursor position in the file (offset).
loading chunk = offset - limit/2 to offset + limit/2
The text on the JTextPane/JEditorPane must not change when loading chunks or else the user feels like is in another position of the file.
This is not a trivial solution but if you don't find any other 3rd party control to do this I would go this way. " (bruno conde)
Is this a good solution and can anybody give me an exemple (link tutorial project) ? or are any other solution?
How can we improve jtextpane performance?
Thx

A megabyte of text in a JTextPane should not be an issue. On my desktop, adding a 1MB string with setText() takes ~1.6 seconds, but once loaded there is no noticeable lag.
Try is disabling the syntax highlighting. That is the most likely source of the delay.

Related

How to adjust page size while publishing?

Software: Octave v7.1.0
There seems to be no option of defining the page size while doing publish ("FILE", "pdf") . The manual for pdf is: 11.11.1 docs.octave/.../Publish.
It's kinda surprising as it's a one word addition to the output TeX file : a4paper. I can do this manually each time I publish but being able to specify it somehow within the publish function would be awesome.
Surprisingly, there are plenty options for specifying page size in figures and images. Search for papertype at: 15.3.3.2 docs.octave/.../Figure-Properties
I searched with "Matlab" and found this page, and it fetched the results for "Matlab Report Generator" mlreportgen which seems a different thing.
I'd be interested to listen about other ways of doing it automatically too (like adding that word in TeX file via shell scripting and text string manipulation maybe).
As directed by #cris-luengo in the pointer comment to the linked manual, one solution can be to edit (or create) the function files (to used by the publish function) with the desired changes to specify the paper size.
The function files location can be found by:
opening the function file in octave gui and then proceeding from there:
edit (fullfile (fileparts (which ("publish")), "private", "__publish_html_output__.m"))
or, executing the following in octave REPL/command line:
fullfile (fileparts (which ("publish")), "private")
There, among other files, 2 files will be:
__publish_html_output__.m
__publish_latex_output__.m
Edit the _latex_ containing file to add ,a4paper (or other predefined size in latex) alongwith 10pt in the line '\documentclass[10pt]{article}',, optionally with a comment in a proceeding newline as a reminder that you added it, something like: '% Modification: specify a4paper',
If pdf format were directly specified as a new function file, then I'd have preferred to modify its copy and calling that directly in publish(), but since the publish pdf eventually calls publish latex, so, the only option at hand in this method seems to edit the original publish latex function file itself.

PhpStorm isn't doing code completion with large file

I've just installed this library. PhpStorm does its usual code completion, except for the \XeroAPI\XeroPHP\Api\AccountingApi class. The \XeroAPI\XeroPHP\Api\IdentityApi class in the same folder works just fine.
The file is quite big - 2,560KB. If I delete roughly half of the 65,000 lines from the class (and it works whether it's the first half or the second half) then I get my code completion back. In fact, I can delete just the last 3,000 or so lines (getting the file down to 2,499KB) and it works.
I've also tried a quick regex find/replace to remove all the #throws PHPDoc comments. This got the file down to 2,491KB and hey presto, code completion works fine.
If I had to make a guess I'd say it's not doing code completion with source files over 2.5MB or something, but I can't find any setting for this.
Any way to get code completion going with this file short of deleting stuff from it (which will be restored next time I do a Composer update anyway)?
Based on your info (especially the mentioned file size and the fact that it starts to work after reducing it) you have hit a limit of max file size that IDE is willing to parse and index.
Solution: configure idea.max.intellisense.filesize option using Help | Edit Custom Properties command. By default it has a value of 2500 (size in KB). Set it to 3000 or so (to cover your file size) and restart IDE (it reads and applies settings from idea.properties file on start only).
idea.max.intellisense.filesize=3000
P.S. Do not put that value too big as it may cause other performance issues.

Perform action before save (`on_pre_save`)

import sublime_plugin
class Test(sublime_plugin.EventListener):
def on_pre_save(self, view):
view.set_syntax_file("Packages/Python/Python.tmLanguage")
Here is simple example. Logically (from my point of view), it should change syntax before saving, and so, the file should be saved as <filename>.py.
But actually, the syntax will be changed after the save operation. So, if I originally worked with js file, it will be saved as js, not py.
I'm wondering why on_pre_save works so strange, or, in other words, is there any difference between on_pre_save and on_post_save. Also, and that's my practical interest, how I can perform some arbitrary(1) action right before saving?
(1) I've specifically use the word "arbitrary", because I don't mean only syntax changes. It may be something different. For example, change the font from Consolas to Times New Roman.
The on_pre_save event happens just before a file buffer is written to disk, and allows you to take any action that you might want to take before the file on disk changes, for example making some change to the content of the buffer (e.g. "reformat on save").
The on_post_save event happens just after the file buffer has been written to disk, allowing you to take any action you might want to take after a save operation, for example examining the contents of the buffer once it's "final" (e.g. "lint on save", which if done through an external tool requires the changes to be on disk and not just in memory).
In either case the file name of the file has already been selected by the user at the time the event happens. For a new file, that means that on_pre_save doesn't happen until after they've selected the name and location of the file. For an existing file, save just resaves with the same filename.
To answer your question, you can do most any "arbitrary" thing you want in the on_pre_save to have it happen prior to when a save happens. It's also possible to change the filename in that situation if you really want to.
Note however that changing the filename out from under the user without asking them first is decidedly bad UX. Additionally, if you change the filename to a file that already exists from within on_pre_save sublime will blindly overwrite the file with no warnings, which is also Bad Mojo.
For something that's going to alter the name and location of the file on disk, the more appropriate way to go is have a command the user has to explicitly invoke to make that happen so that they're fully aware of what's going on.
As requested in a comment and for completeness, here's an example that does what you wanted your example code above to do.
The important thing to note here is that you have to be extremely careful about the situation that you trigger this event in. As written above, your plugin would make it impossible to ever save any kind of file ever due to it swapping over to a python file instead.
In this example it's constrained to only take effect on a text file, turning it into a python file. Note however that if there was a python file with that name already in that location, it would overwrite it without warning you that it's about to happen.
Be extremely wary with this code; it's quite easy to accidentally stop yourself from being able to save files with the correct name, which could for example stop you from being able to use Sublime to fix the code, amongst other nasty issues.
import sublime_plugin
import os
class TestListener(sublime_plugin.EventListener):
def on_pre_save(self, view):
# This part is extremely important because as mentioned above it's
# entirely disconcerting for your save operation to gank your
# filename and make it suddenly be something else without any
# warning. If you're not careful you might destroy your ability to
# use sublime to fix your plugin, for example.
if not view.file_name().endswith(".txt"):
print("Doing nothing for: ", view.file_name())
return
# HUGE WARNING: This CAN and WILL willfully clobber over any file
# that already happens to exist without any warning to you
# whatsoever, and is most decidedly a Bad Idea(tm)
python_name = os.path.splitext(view.file_name())[0] + ".py"
view.retarget(python_name)

highchart save image using exporting java and phantomjs

I was able to setup exporting module using java and phantomjs. I am also able to see the image file getting generated in temp folder but it gets deleted after some time 30 secs to be exact. After going through API definition I found something called as async which caught my eyes. I tried playing around with this option but didnt worked. Image file gets deleted evertime, I want to permanently save this file on file system. Any pointers in this directions would be very helpful.
Thanks
Open AbstractPool.java file, in line 117 you can find:
Collection<File> oldFiles = FileUtils.listFiles(TempDir.outputDir.toFile(),filter, null);
for (File file : oldFiles) {
file.delete();
}
Simply delete that lines, and should be enough. Or above that lines you can set higher fixedRate.
In addition to Pawel's answer you can also change the time limit in the app-convert.properties file:
# Keep files in the temp folder for a certain retentionTime, defined in miliseconds
retentionTime = 30000
That is the default. So, 30s makes sense.

application crashed when i decompressing a big file(300MB) by deng.fzip.FZip in action script 3.0

as the title describe,i used a third-party pacakge 'deng.fzip.FZip' to decompress a big file,about 300MB,the application crashed.I found that fzip.load(url:URLRequest) function is synchronous,not asynchronous.I think the reason maybe fzip load the total data to itself,then cause the application out of memory.how to decompress a big big .zip file in action script 3.0 ?
thx in advance!
Keep in mind that synchronous methods cannot execute for longer than 15 sec in Flash Player (can be longer in AIR) no matter what timeout you set in the Publish settings.
Your best bet is to open the Class that does the decompressing and in that loop make a small check:
// before loop
var startingTime:int = getTimer();
// inside the loop
if (getTimer() - startingTime > TIMEOUT_VARIABLE_HERE)
{
// save the i position, break the loop, set timeout for, let's say, 30 ms and start the loop with i = your saved i when breaking out of the loop.
}
It's not a fancy solution that fixes your problem in one second, but it's a really good, robust way to fix the actual problem.
Not sure if that's related, but a small note: officially Flash Player supports file's no larger than 100 MB.
However I've seen myself some flash games (in alpha testing) that consumed over 2GB of memory and still ran well.