Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Change color for item when you left click (Read 7928 times)
AncaZ
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 21
Joined: Feb 16th, 2017
Change color for item when you left click
Feb 22nd, 2017 at 2:42pm
Print Post  
Hello,

How can I change the color for an item when single click in a time slot?
From the gray bellow to another color.
Thank you.
  

item.PNG ( 13 KB | 192 Downloads )
item.PNG
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Change color for item when you left click
Reply #1 - Feb 22nd, 2017 at 3:30pm
Print Post  
Hi,

What you have highlighted above is not an item, but a cell. If you want to change the color of a cell when it is clicked, do the following:

1. Declare a private DateTime variable in your class, say, clickedDate:
Code
Select All
private DateTime clickedDate; 



2. Add a CalendarListener to the Calendar object so that you can listen to click events and perform custom drawing:
Code
Select All
calendar.addCalendarListener(new CalendarAdapter() {
	@Override
	public void dateClick(ResourceDateEvent e) {
		// ...
	}

	@Override
	public void draw(DrawEvent e) {
		// ...
	}
}); 



3. In the dateClick override, assign the clickedDate variable:
Code
Select All
@Override
public void dateClick(ResourceDateEvent e) {
	clickedDate = e.getDate();
} 



4. To customize the color of the clicked cell, use the draw override in the CalendarListener. First, specify that you want to custom-draw timetable cells by setting Calendar.CustomDraw to CustomDrawElements.TimetableCell:
Code
Select All
calendar.setCustomDraw(EnumSet.of(CustomDrawElements.TimetableCell)); 


Then, use the following code to perform the custom drawing:
Code
Select All
@Override
public void draw(DrawEvent e) {
	if (Objects.equals(e.getDate().add(e.getStartTime()), clickedDate)) {
		Rectangle bounds = new Rectangle(e.getBounds());
		Brushes.LightSteelBlue.applyTo(e.getGraphics(), bounds);
		e.getGraphics().fill(bounds);
		new Pen(Colors.DarkSlateBlue, 0).applyTo(e.getGraphics());
		bounds.width -= 1;
		bounds.height -= 1;
		e.getGraphics().draw(bounds);
	}
} 


I hope this helps.

Regards,
Meppy
  
Back to top
 
IP Logged
 
AncaZ
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 21
Joined: Feb 16th, 2017
Re: Change color for item when you left click
Reply #2 - Feb 23rd, 2017 at 9:49am
Print Post  
Hello,

It's not really working, because I made
@ItemViewerAttribute(viewerType = WachtrijElementAppoimentViewer.class)
public class WachtrijElementAppoiment extends Appointment.

And then I have something like:
public class WachtrijElementAppoimentViewer implements ItemViewer {



    /** {@inheritDoc} */
    @Override
    public void draw(ItemDrawContext itemDrawContext) {

...

Coloring a cell at click can not be changed from styles?
Something like:
Style workTimeCellStyle = getTimetableSettings().getWorkTimeCellStyle(); or
   Style cellStyle =  getTimetableSettings().getCellStyle(); ?

I tried this, but they dont work


Thank you.
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Change color for item when you left click
Reply #3 - Feb 23rd, 2017 at 1:08pm
Print Post  
Hi,

Appointments (and their custom viewers, if any) have no influence on how cells are drawn in the Timetable view. You cannot style individual cells in the view therefore you need to rely on custom drawing to customize the appearance of specific cells. My code above should work regardless of whether you use custom item viewers.

You can post your complete project here (or as a personal message) and I will look into it.

Regards,
Meppy
  
Back to top
 
IP Logged
 
AncaZ
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 21
Joined: Feb 16th, 2017
Re: Change color for item when you left click
Reply #4 - Feb 23rd, 2017 at 1:20pm
Print Post  
The peace of code you wrote from draw method, does not compile:
  

draw.PNG ( 19 KB | 176 Downloads )
draw.PNG
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Change color for item when you left click
Reply #5 - Feb 23rd, 2017 at 3:40pm
Print Post  
What kind of errors do you get?
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Change color for item when you left click
Reply #6 - Feb 24th, 2017 at 9:28am
Print Post  
Hi,

I was targeting the new (still unreleased) version of the control where there are some API changes. Here is a modified version of the code, which should compile:

Code
Select All
calendar.setCustomDraw(CustomDrawElements.TimetableCell);
calendar.addCalendarListener(new CalendarAdapter() {
	@Override
	public void dateClick(ResourceDateEvent e) {
		clickedDate = e.getDate();
	}

	@Override
	public void draw(DrawEvent e) {
		if (Objects.equals(e.getDate().add(e.getStartTime()), clickedDate)) {
			Rectangle bounds = new Rectangle(e.getBounds());
			e.getGraphics().fillRectangle(Brushes.LightSteelBlue, bounds);
			bounds = new Rectangle(bounds.getX(), bounds.getY(), bounds.getWidth() - 1, bounds.getHeight() - 1);
			e.getGraphics().drawRectangle(new Pen(Colors.DarkSlateBlue, 0), bounds);
		}
	}
}); 


Regards,
Meppy
  
Back to top
 
IP Logged
 
AncaZ
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 21
Joined: Feb 16th, 2017
Re: Change color for item when you left click
Reply #7 - Feb 24th, 2017 at 10:25am
Print Post  
Thank you.. Now this works Smiley

I have another question, how can I change the color for when I draw an appoitment?
  

draw2.PNG ( 7 KB | 170 Downloads )
draw2.PNG
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Change color for item when you left click
Reply #8 - Feb 24th, 2017 at 11:44am
Print Post  
Use the Brush property of Item.Style (and/or Item.PointedStyle, Item.SelectedStyle, Item.SelectedPointedStyle for the various states of the item):

Code
Select All
app.getStyle().setBrush(Brushes.Orange); 



Regards,
Meppy
  
Back to top
 
IP Logged
 
AncaZ
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 21
Joined: Feb 16th, 2017
Re: Change color for item when you left click
Reply #9 - Feb 24th, 2017 at 1:48pm
Print Post  
app.getStyle().setBrush(Brushes.Orange); sets the style for when the item is not selected.
I want a different color for the moment I'm drawing the appointment. Then other color for when the appointment is selected. Is that possible?
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Change color for item when you left click
Reply #10 - Feb 24th, 2017 at 2:41pm
Print Post  
Use app.getSelectedStyle().setBrush(Brushes.Orange); for when the appointment is selected.

Regards,
Meppy
  
Back to top
 
IP Logged
 
AncaZ
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 21
Joined: Feb 16th, 2017
Re: Change color for item when you left click
Reply #11 - Feb 24th, 2017 at 3:30pm
Print Post  
For when the appointment is selected is working.
What I need is a different color at the moment of drawing an appointment. Is that possible?
Thank you.
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Change color for item when you left click
Reply #12 - Feb 27th, 2017 at 8:01am
Print Post  
Hi,

What do you mean by "at the moment of drawing an appointment"? If you are creating items while dragging (that is, Calendar.setEnableDragCreate is set to true) and want to change the color of the item while it is created, use the following code:

Code
Select All
calendar.addCalendarListener(new CalendarAdapter() {
	@Override
	public void itemCreating(ItemConfirmEvent e) {
		e.getItem().getSelectedStyle().setBrush(Brushes.Orange);
		super.itemCreating(e);
	}

	@Override
	public void itemCreated(com.mindfusion.scheduling.model.ItemEvent e) {
		e.getItem().getSelectedStyle().setBrush(null);
		super.itemCreated(e);
	}
}); 


The item color is changed during creation interaction and reverted back to the default once the item is created.

Regards,
Meppy
  
Back to top
 
IP Logged
 
AncaZ
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 21
Joined: Feb 16th, 2017
Re: Change color for item when you left click
Reply #13 - Feb 28th, 2017 at 3:02pm
Print Post  
It works. Thank you Smiley
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint