Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to. (Read 1256 times)
Bruno Dufour
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 15
Joined: Jul 28th, 2022
How to.
Jul 28th, 2022 at 9:30pm
Print Post  
we are testing Scheduling components to see if it will fit into our application.

I'm trying to create ZONES inside the Resource time line (see attach file) to define unavailable time allocations (examples: weekends, close hours like 6pm to 8am we are closed, lunch time, etc.) To do so, I have implement the method draw from the CalendarAdapter.

The draw method get CalendarDrawEvent as a parameter.

I was expecting this parameter to return the start date and end date of each cell to be drawn. It looks that it always returns the same values.

I guess I am not doing the right thing. What is the right way to do it?

(note: I took the Zone sample to develop my code)


====



See below my calendar implementation. Notice the draw method.
The event returns :

    aCalendar = new Calendar();
        aCalendar.addCalendarListener(new CalendarAdapter() {
            public void draw(CalendarDrawEvent e) {
                calendar_Draw(e);
            }
            public void itemCreating(ItemConfirmEvent e) {
                onCalendarItemCreating(e);
            }
            public void itemModifying(ItemModifyConfirmEvent e) {
                onItemModifying(e);
            }
            public void itemCreated(ItemEvent e) {
                onItemCreated(e);
            }
            public void itemClick(ItemMouseEvent e) {
                onItemClick(e);
            }
            public void itemDrawing (CalendarDrawEvent e)
            {

                System.out.println("xxxcellstart: "+e.getStartTime()+" end: "+e.getEndTime()+" date:"+e.getDate()+" e.getend()"+e.getEndTime()+" e.get"+e.getIndex());
            }

            public void drawing(CalendarDrawEvent e) {
                calendar_Draw(e);
                System.out.println("x22xxcellstart: "+e.getStartTime()+" end: "+e.getEndTime()+" date:"+e.getDate()+" e.getend()"+e.getEndTime()+" e.get"+e.getIndex());
            }

        });

        aCalendar.setCurrentTime(DateTime.now());

        java.util.Calendar lCalendar = java.util.Calendar.getInstance();
        Date lBegin = lCalendar.getTime();
        lCalendar.roll(java.util.Calendar.MONTH,6);
        Date lEnd = lCalendar.getTime();

        aCalendar.setDate(new DateTime(lBegin));
        aCalendar.setEndDate(new DateTime(lEnd));

        aCalendar.setTheme(ThemeType.Light);
        aCalendar.getMonthSettings().setWeekHeaderStyle(MonthWeekHeaderStyle.Left);
        aCalendar.getListViewSettings().setCellUnits(TimeUnit.Month);
      //  aCalendar.setCustomDraw(EnumSet.of(CustomDrawElements.TimetableCell));

        EnumSet<ListViewHeaderStyles> style = aCalendar.getListViewSettings().getHeaderStyle();
        style.add(ListViewHeaderStyles.Subheader);
        style.add(ListViewHeaderStyles.SubheaderPerCell);

        aCalendar.getResourceViewSettings().setViewStyle(ResourceViewStyle.Lanes);
        aCalendar.getResourceViewSettings().getMiddleTimelineSettings().setUnit(TimeUnit
.Day);
        aCalendar.getResourceViewSettings().getMiddleTimelineSettings().setFormat("d");
        aCalendar.getResourceViewSettings().getBottomTimelineSettings().setUnit(TimeUnit
.Hour);
        aCalendar.getResourceViewSettings().getBottomTimelineSettings().setFormat("HH:mm
");

        aCalendar.getTimetableSettings().setShowInfoHeader(true);
        aCalendar.getTimetableSettings().setVisibleColumns(3);

        aCalendar.getTimetableSettings().setSnapInterval(Duration.fromMinutes(1));
        aCalendar.setInteractiveItemType(cSimpleZoneEvent.class);
        aCalendar.setCurrentView(CalendarView.ResourceView);
        aCalendar.setCustomDraw(EnumSet.of(CustomDrawElements.ResourceViewTimeline));

....


METHOD Calendar_draw:



  protected void calendar_Draw(CalendarDrawEvent e) {
        Pen pen = new Pen(new Color(32, 159, 218));
        Brush brush = new SolidBrush(new Color(32, 159, 218, 75));

        AwtGraphics g = new AwtGraphics(e.getGraphics());
        Rectangle bounds = new Rectangle(e.getBounds().x, e.getBounds().y,
                e.getBounds().width - 1, e.getBounds().height - 1);

        g.fillRectangle(brush, bounds);
        g.drawRectangle(pen, bounds);

      //  if (e.getElement() == CustomDrawElements.TimetableCell)
        if (e.getElement() == CustomDrawElements.ResourceViewTimeline)
        {
            DateTime cellStart = DateTime.op_Addition(e.getDate(), e.getStartTime());
            DateTime cellEnd = DateTime.op_Addition(cellStart, aCalendar.getTimetableSettings().getCellTime());
            boolean zone = false;
            boolean zoneStart = false;
            boolean zoneEnd = false;
            boolean type = false;

            System.out.println("cellstart: "+cellStart+" end: "+cellEnd+" date:"+e.getDate()+" e.getend()"+e.getEndTime()+" e.get"+e.getIndex());

            


cellStart and cellEnd always returns the same values...
?


  

debugzone.png ( 17 KB | 86 Downloads )
debugzone.png
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: How to.
Reply #1 - Jul 29th, 2022 at 7:07am
Print Post  
If you want to check if specific hours from bottom timeline are within specific range, use the CustomDrawElements.ResourceViewTimelineCell instead (adding Cell suffix to your code). Then this should report the one-hour intervals from your screenshot:

Code
Select All
if (e.getElement() == CustomDrawElements.ResourceViewTimelineCell)
{
    DateTime cellStart = DateTime.op_Addition(e.getDate(), e.getStartTime());
    DateTime cellEnd = DateTime.op_Addition(e.getDate(), e.getEndTime());
    System.out.println(cellStart);
    System.out.println(cellEnd);
    ... 

  
Back to top
 
IP Logged
 
Bruno Dufour
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 15
Joined: Jul 28th, 2022
Re: How to.
Reply #2 - Jul 29th, 2022 at 7:34pm
Print Post  
Thanks for your fast answer.

I get time zone on the header thanks to your proposal.


But.

What we are looking for is to have a way to identify in the graph when each resource
may be ready to work. Each resource may have a different schedule (some machines work 24 hours a day, other only 8., some may work 10 hours but with 15 minutes unavailabilities....) I need to be able to draw and identify (to lock these zones too...  cannot allocate  tasks there) unavailable time for each of them.


Is it possible to solve that?
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: How to.
Reply #3 - Jul 30th, 2022 at 12:12pm
Print Post  
Set CustomDrawElements.ResourceViewCell if you need to draw inside the resource lanes instead of headers. Checking whether current cell intersects occupied time could look like this:

Code
Select All
static class TimeRange
{
	TimeRange(DateTime start, DateTime end)
	{
		this.start = start;
		this.end = end;
	}

	DateTime start;
	DateTime end;
}

List<TimeRange> occupied = new ArrayList<TimeRange>();

TimeRange occupiedPart(DateTime start, DateTime end)
{
	for (TimeRange r : occupied)
	{
		if (end.isLessThanOrEqual(r.start))
			continue;
		if (r.end.isLessThanOrEqual(start))
			continue;
		DateTime from = start.isLessThan(r.start) ? r.start : start;
		DateTime to = end.isLessThan(r.end) ? end : r.end;
		return new TimeRange(from, to);
	}
	return null;
} 



Since you are using the range selector which allows zooming, cells could be different than a whole hour, and you might want to fill them only partially:

Code
Select All
void calendar_Draw(CalendarDrawEvent e)
{
    AwtGraphics g = new AwtGraphics(e.getGraphics());
    Brush brush = new SolidBrush(new Color(255, 0, 0, 75));

    if (e.getElement() == CustomDrawElements.ResourceViewCell)
    {
        DateTime cellStart = DateTime.op_Addition(e.getDate(), e.getStartTime());
        DateTime cellEnd = DateTime.op_Addition(e.getDate(), e.getEndTime());

        TimeRange occupied = occupiedPart(cellStart, cellEnd);
        if (occupied != null)
        {
        	double ticksPerPixel =
        		(cellEnd.getTicks() - cellStart.getTicks()) /
        		e.getBounds().getWidth();

        	double startDx = (occupied.start.getTicks() - cellStart.getTicks()) / ticksPerPixel;
        	double endDx = (occupied.end.getTicks() - cellEnd.getTicks()) / ticksPerPixel;

        	Rectangle2D occupiedRect = new Rectangle2D.Double();
        	occupiedRect.setFrameFromDiagonal(
        		e.getBounds().getMinX() + startDx, e.getBounds().getMinY(),
        		e.getBounds().getMaxX() + endDx, e.getBounds().getMaxY());

            g.fillRectangle(brush, occupiedRect);
        }
    }
} 



I guess you will also be considering the e.getResource() value in all this, e.g. you could store a HashMap<Resource, occupied_time_list>, or your own resource model objects could store the list.

Instead of all the custom drawing, you could maybe represent unavailable times as locked items in the schedule, and just style those items.

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