Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Calendar Print (Read 479 times)
Raeees
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 19
Joined: Dec 11th, 2024
Calendar Print
Feb 6th, 2025 at 2:58pm
Print Post  
Hi,

I would like to know if its possible to save the calendar as a png without displaying it in a JFrame.

Essentially i will be running the resourceView application on a server (no display) and i wish to know if its possible to save content from the calendar knowing i dont have a GUI. This is the line i use to get the graphics when i have a GUI and save it in the format i need, it cant be applied the other way around
Code (Java)
Select All
calendar.print(graphics, format,0); 



Its probably a more common issue in java swing, so any insights in the request will be appreciated
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3357
Joined: Oct 19th, 2005
Re: Calendar Print
Reply #1 - Feb 7th, 2025 at 7:28am
Print Post  
Hi,

Try calling Calendar.createImage method and saving to png using ImageIO.

You might get HeadlessException setting up a Calendar instance on server. Our developers added a lot of checks for these into our diagram component (e.g. https://mindfusion.eu/Forum/YaBB.pl?num=1218051540), let us know if you encounter any with the calendar.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Raeees
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 19
Joined: Dec 11th, 2024
Re: Calendar Print
Reply #2 - Feb 7th, 2025 at 4:34pm
Print Post  
Hi again,
it doesnt seem to work, isnt the object calendar depended on the GUI to save/print anything?
When i use the line ''calendar.createImage()'' in this line, i get
Code (Java)
Select All
BufferedImage bImg = calendar.createImage(true);
		if(ImageIO.write(bImg, "png", new File("SavePNG.png"))){
			System.out.println("saved image");
		}
		else{
			System.out.println("image not saved");
		} 


i get this error
Error: java.lang.NullPointerException: Cannot invoke "java.awt.image.BufferedImage.createGraphics()" because "<local7>" is null

thanks again
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3357
Joined: Oct 19th, 2005
Re: Calendar Print
Reply #3 - Feb 10th, 2025 at 8:40am
Print Post  
Hi,

Apaprently createImage is getting null bitmap from base JComponent.createImage when calendar hasn't been added to the UI. This build adds some fall-back code to create the image explicitly when base returns null:

https://mindfusion.eu/_temp/JPlanner_createImage.zip

You must also call setBounds before createImage, or the calendar will pass zero values to the Image constructor, when not assigned size by a parent frame:

Code
Select All
Calendar calendar = new Calendar();
calendar.setBounds(
	new Rectangle(0, 0, 600, 400));
BufferedImage image = calendar.createImage(...); 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Raeees
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 19
Joined: Dec 11th, 2024
Re: Calendar Print
Reply #4 - Feb 10th, 2025 at 3:41pm
Print Post  
Hey,
This was very much helpful but i am getting another issue regarding
Code (Java)
Select All
calendar.setViewport(calendar.getDate(), calendar.getEndDate(), true); 



When i save the calendar, the viewport is not within the ''StartDate'' and ''EndDate'' i setup. is it because viewport is dependant on the container's size? Which in this case, i do not have because there is no GUI.

FYI, the new jar you provided does not include the fix you made in the old post
https://mindfusion.eu/Forum/YaBB.pl?num=1731680248/13

reply#13


Cordially.
« Last Edit: Feb 10th, 2025 at 5:15pm by Raeees »  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3357
Joined: Oct 19th, 2005
Re: Calendar Print
Reply #5 - Feb 11th, 2025 at 12:23pm
Print Post  
Hi,

That reaches a calendar.getGraphics() call, again returning null when not in the UI, and the view is left with some default values. Our developer will try to add fall-back handling later this week.

Quote:
FYI, the new jar you provided does not include the fix you made in the old post
https://mindfusion.eu/Forum/YaBB.pl?num=1731680248/13

reply#13


It should be included. Are you sure you are seeing same exception stack trace (esp. the Calendar.mousePressed line if you are testing on server now)?

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Raeees
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 19
Joined: Dec 11th, 2024
Re: Calendar Print
Reply #6 - Feb 12th, 2025 at 3:39pm
Print Post  
Hi,
That was an error from my part, it works and there is no exception anymore

I'll be waiting for the changes provided by your developper

Thanks again for the assistance.


Cordially
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3357
Joined: Oct 19th, 2005
Re: Calendar Print
Reply #7 - Feb 13th, 2025 at 12:48pm
Print Post  
Hi,

Try new build here -

https://mindfusion.eu/_temp/JPlanner_createImage.zip

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Raeees
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 19
Joined: Dec 11th, 2024
Re: Calendar Print
Reply #8 - Feb 18th, 2025 at 4:08pm
Print Post  
Hi, i still get errors
so just to go back through all the necessaries i need for this to work
- i set System.setProperty("java.awt.headless", "true");
- create the calendar, setBounds(0,0, 700, 400);
- calendar.setViewport(startDate, endDate, true);
- BufferedImage image = calendar.createImage(true, 700,400);
- i call ImageIO.write(...)

This still gives me the folllowing error.
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3357
Joined: Oct 19th, 2005
Re: Calendar Print
Reply #9 - Feb 19th, 2025 at 9:29am
Print Post  
Hi,

This build replaces a few more calendar.getGraphics calls -

https://mindfusion.eu/_temp/JPlanner_createImage.zip

If not working, please attach a test project reproducing the error.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Raeees
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 19
Joined: Dec 11th, 2024
Re: Calendar Print
Reply #10 - Feb 21st, 2025 at 1:59pm
Print Post  
Hi,
So far its working alright, but i need to know something. How do i disable displaying lanes that arent fully fitting in the chosen bounds. the purpose of this is to figure out where to break page when printing, some lanes are cut in half with this (as shown in the image). i tried using
Code (Java)
Select All
calendar.getElementBounds(CalendarElement.ResourceViewHeader,8).getBounds().getMaxY() 


but this didnt work because it cannot tell when the lane is fully displayed or not.
Maybe adding another overloaded method for calendar.createImage() to include elementalBounds? this way we may be able to cut printing according to fully visible lanes

Cordially
« Last Edit: Feb 21st, 2025 at 7:14pm by Raeees »  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3357
Joined: Oct 19th, 2005
Re: Calendar Print
Reply #11 - Feb 24th, 2025 at 2:52pm
Print Post  
Hi,

Maybe implement a separate measure pass by calling calendar.setBounds with a very large initial height, and collect the ElementBounds.height values for each resource row, to know what area they would occupy if having infinite space. Then on second pass call setBounds with actual target image size, and implement pagination by exporting subsets of the resources whose total height is smaller than image height.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint