Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Shape drag and drop with support for colors (Read 4631 times)
nsandhu
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 16
Joined: Aug 22nd, 2011
Shape drag and drop with support for colors
Oct 17th, 2011 at 9:50pm
Print Post  
I am following the Flowchart example, but the drag and drop shapes supported via the ShapeLibrary do not seem to have pen/brush color or styles! Is there another way to support drag and drop of shapes along with their styling onto an existing diagram?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Shape drag and drop with support for colors
Reply #1 - Oct 18th, 2011 at 8:09am
Print Post  
Do you mean you want to see color and text styles in the property panel shown in the lower right? That's a simple JPanel that hosts labels and drop-downs showing a few property values. You can add more controls to it (it's called _fontBoxPanel) to show additional color and text formatting properties, or perhaps replace the whole panel with a JTable whose model lists the properties you need.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
nsandhu
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 16
Joined: Aug 22nd, 2011
Re: Shape drag and drop with support for colors
Reply #2 - Oct 19th, 2011 at 4:00pm
Print Post  
I actually meant the ShapeListBox which uses the ShapeLibrary does not seem to support line or fill colors on the shapes.
How would I go about making a component that had a number of pre-defined shapes (with text inside them) so that when dragged from that component onto the main diagram, a copy of the shape would be placed at the desired location.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Shape drag and drop with support for colors
Reply #3 - Oct 19th, 2011 at 4:51pm
Print Post  
If you are following the Flowcharter example, it doesn't actually use a ShapeListBox, but a standard Swing JList with a custom model and renderer.

You can add a fillColor attribute to the shape icons by adding the following members to the Node class in FlowcharterFrame.java:

Code
Select All
private class Node
{
	public Node(AnchorPattern anchor,
com.mindfusion.diagramming.Shape template, String name) {
		_anchor = anchor;
		_template = template;
		_name = name;
		_fillColor = Color.white;
	}

	public Node(AnchorPattern anchor,
com.mindfusion.diagramming.Shape template, String name, Color fillColor) {
		_anchor = anchor;
		_template = template;
		_name = name;
		_fillColor = fillColor;
	}

	...

	public Color getFillColor() {
		return _fillColor;
	}

	private Color _fillColor;
} 



and then use the new Node constructor when initializing the _nodes array in the frame class constructor.

To change the appearance of shape icons, find the "//node renderer" comment and add the following lines after the setShape call:

Code
Select All
box.setBrush(new SolidBrush(s.getFillColor()));
box.setText(s.getText()); 



and also change the icons size to one that will fit your texts.

If you prefer using the ShapeListBox control, you can access the ShapeNodes hosted inside it by calling ShapeListBox.getModel().getElement() and typecasting to ShapeNode. Then you can change the attributes of these ShapeNodes to display different colors, texts, etc.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
nsandhu
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 16
Joined: Aug 22nd, 2011
Re: Shape drag and drop with support for colors
Reply #4 - Oct 19th, 2011 at 5:38pm
Print Post  
Thanks. That makes sense.

Can i store the fill and color attributes in the shapelibrary or some other format or do i need to do that in my own custom format? In other words, it seems that the shape library format does not support the color/fill attributes?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Shape drag and drop with support for colors
Reply #5 - Oct 19th, 2011 at 6:39pm
Print Post  
Unfortunately the Shape class and shape libraries only define the geometry of ShapeNodes, so there's no built-in support for color attributes.

We have a NodeListView control in our WPF/Silverlight products whose elements are DiagramNode -derived objects and are cloned upon drag-and-drop onto the diagram. We could port this to Java for the next release if it will work better for you; you will be able to set any attributes on the ShapeNodes in the list then.

What you can do now using a ShapeListBox (or a JList as in Flowcharter) is to associate color attributes with shape identifiers in a separate file, and then set the colors on the internal nodes as shown in the previous post. Alternatively, you could add your own xml elements to the shape library file and load them using the Java XML API.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint