Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Clearing a NodeListView in JDiagram (Read 4093 times)
cgay1
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 3
Joined: Dec 2nd, 2020
Clearing a NodeListView in JDiagram
Dec 7th, 2020 at 1:56pm
Print Post  
I would like to change the nodes in a NodeListView, but unsuccessful clearing the list to add new nodes.  I have tried the following methods:
nodeList.removeAll();
nodeList.remove(0);    //cycling through the list
nodeList.clearNodes();

The .getNodesCount() returns the correct value but the display still has all the old nodes.  I have tried the .repaint() method and that does not do anything as far as I can tell.

Can someone help me refresh my NodeListView?

Thank you in advance,
-Chris Gay
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3435
Joined: Oct 19th, 2005
Re: Clearing a NodeListView in JDiagram
Reply #1 - Dec 7th, 2020 at 2:24pm
Print Post  
Our bad, we'll fix it for upcoming release. Try this for time being -

Code
Select All
nodeList.clearNodes();
((DefaultListModel)nodeList.getModel()).removeAllElements(); 



Alternatively, replace the nodeList with a new instance in its UI parent.

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


I Love MindFusion!

Posts: 3
Joined: Dec 2nd, 2020
Re: Clearing a NodeListView in JDiagram
Reply #2 - Dec 16th, 2020 at 9:43pm
Print Post  
I have tried a couple different ways to refresh the NodeListView based on your recommendations and still stuck.  I modified the Control.java sample app to illustrate what I would like to do.  Can you try the two menu items and help me?

Code (Java)
Select All
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package nodelistviewproblem;

/**
 *
 * @author chris
 */
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Rectangle;
import java.awt.event.HierarchyBoundsListener;
import java.awt.event.HierarchyEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowStateListener;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import com.mindfusion.drawing.*;
import com.mindfusion.diagramming.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;


public class NodeListViewProblem extends JFrame
{
	public NodeListViewProblem()
	{
		setTitle("MindFusion.Diagramming Sample: Controls");
		setSize(1060, 740);
		setVisible(true);

		mainPanel = new JPanel();
		mainPanel.setLayout(new BorderLayout());


		rulerPanel = new JPanel()
		{
			@Override
			public boolean isOptimizedDrawingEnabled(){
				return false;
			}

			private static final long serialVersionUID = 1L;
		};

		rulerPanel.setBounds(0, 0, 940, 730);
		rulerPanel.setVisible(true);
		rulerPanel.setLayout(null);

		JMenuBar mBar = new JMenuBar();
                JMenu mbtnList = new JMenu("List");
                JMenuItem mnuNodeListTwo = new JMenuItem("Node List 2");
                JMenuItem mnuRemove = new JMenuItem("Remove");
		mbtnList.add(mnuNodeListTwo);
                mbtnList.add(mnuRemove);
                mBar.add(mbtnList);
                this.setJMenuBar(mBar);

		diagram = new Diagram();
		diagram.setMeasureUnit(GraphicsUnit.Millimeter);

		ShapeNode helloNode = new ShapeNode(diagram);
		helloNode.setBounds(50, 20,100, 50);
		helloNode.setTextBrush(new SolidBrush(Color.black));
		helloNode.setEnableStyledText(true);
		String txt = "This sample demonstrates the auxiliary controls available " +
			"with MindFusion.JPack: the <b>Overview</b>, the <b>Ruler</b>, the <b>ZoomControl</b> and the <b>NodeListView</b>.";
		helloNode.setEditedText(txt);


		diagram.add(helloNode);
		diagram.setBounds(new Rectangle(0,0,640, 860));
		diagram.setAutoResize(AutoResize.RightAndDown);

		view = new DiagramView(diagram);
		view.setVisible(true);


		ruler = new Ruler();
		ruler.setDiagramView(view);
		ruler.setSize(917, 703);

		zoomer = new ZoomControl();
		zoomer.setView(view);
		zoomer.setLocation(50, 50);
		zoomer.setVisible(true);

                nodeList = new NodeListView();
                nodeList.setSize(110, 800);
                nodeList.setDefaultNodeSize(new Dimension(40,40));
                nodeList.setFixedCellHeight(50);
                nodeList.setFixedCellWidth(110);
                nodeList.setIconSize(new Dimension(25,25));
                nodeList.setIconMargin(new Dimension(5, 5));
                nodeList.setVisible(true);

		ShapeNode currentNode = new ShapeNode();
		String[] shapeNames = {"Actor", "Arrow", "Arrow1", "Arrow2", "Arrow3", "Arrow4", "Arrow5", "Arrow6", "Arrow7",
				"Arrow8", "Arrow9", "Recrangle", "Circle", "Cube", "Cylinder", "RoundRect", "BackSlash", "BeginLoop",
				"BowArrow", "Cloud", "Collate", "ConeDown", "ConeUp", "ConnectedIssues", "CreateRequest"};
		for(int i = 0; i<shapeNames.length; i++)
		{
			currentNode.setShape(Shape.fromId(shapeNames[i]));
			nodeList.addNode(new ShapeNode(currentNode),
					shapeNames[i]);
		}
		nodeListViewScroll = new JScrollPane(nodeList);
		nodeListViewScroll.setVisible(true);

		rulerPanel.add(zoomer);
		rulerPanel.add(ruler);

		mainPanel.add(rulerPanel,BorderLayout.CENTER);
		mainPanel.add(nodeListViewScroll, BorderLayout.EAST);

		mainPanel.addHierarchyBoundsListener(new HierarchyBoundsListener(){

			@Override
			public void ancestorMoved(HierarchyEvent e)
			{

			}

			@Override
			public void ancestorResized(HierarchyEvent e)
			{
				int nlw = nodeList.getWidth();
				rulerPanel.setBounds(0,0,mainPanel.getWidth()-nlw-18, mainPanel.getHeight());
				ruler.setBounds(0,0,mainPanel.getWidth()-nlw-17, mainPanel.getHeight());
				overview.revalidate();
				overview.repaint();
			}

		});
		this.addWindowStateListener(new WindowStateListener(){

			@Override
			public void windowStateChanged(WindowEvent e)
			{
				int nlw = nodeList.getWidth();
				rulerPanel.setBounds(0,0,mainPanel.getWidth()-nlw-18, mainPanel.getHeight());
				ruler.setBounds(0,0,mainPanel.getWidth()-nlw-17, mainPanel.getHeight());
				ruler.revalidate();
				ruler.repaint();
				overview.revalidate();
				overview.repaint();
			}

		});
		mnuNodeListTwo.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {

                        nodeList = new NodeListView();
                        nodeList.setSize(110, 800);
                        nodeList.setDefaultNodeSize(new Dimension(40,40));
                        nodeList.setFixedCellHeight(50);
                        nodeList.setFixedCellWidth(110);
                        nodeList.setIconSize(new Dimension(25,25));
                        nodeList.setIconMargin(new Dimension(5, 5));
                        nodeList.setVisible(true);

                        ShapeNode currentNode = new ShapeNode();
                        String[] shapeNames = {"Actor", "Arrow", "Arrow1", "ConeUp", "ConnectedIssues", "CreateRequest" };
                        for(int i = 0; i<shapeNames.length; i++)
                        {
                                currentNode.setShape(Shape.fromId(shapeNames[i]));
                                nodeList.addNode(new ShapeNode(currentNode),
                                                shapeNames[i]);
                        }
                        nodeListViewScroll = new JScrollPane(nodeList);
                        nodeListViewScroll.setVisible(true);
                        nodeListViewScroll.repaint();
                    }
                });


		mnuRemove.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {

                        nodeList.removeAll();
                        nodeList.clearNodes();
                        nodeList.repaint();

                    }
                });



                this.add(mainPanel);


        }



	public void createOverview(){

		overview = new Overview();
		overview.setDiagramView(view);
		overview.setFitAll(true);
		overview.setBackgroundColor(new Color(170, 170, 200));

		JPanel overviewPanel = new JPanel();

		overviewPanel.setLayout(new GridLayout(1,1));
		overviewPanel.add(overview);

		JFrame overviewFrame = new JFrame("Overview");
		overviewFrame.add(overviewPanel);
		overviewFrame.setVisible(true);
		overviewFrame.setSize(300, 300);
		overviewFrame.setLocation(1065, 0);
		overviewFrame.setAlwaysOnTop(true);

	}

	private Ruler ruler;
	private Diagram diagram;
	private DiagramView view;
	private ZoomControl zoomer;
	private JPanel rulerPanel;
	private Overview overview;
	private JPanel mainPanel;
	private NodeListView nodeList;
	private JScrollPane nodeListViewScroll;


	public static void main(String[] args){
		NodeListViewProblem c = new NodeListViewProblem();
		c.setVisible(true);
		c.createOverview();
		c.setDefaultCloseOperation(EXIT_ON_CLOSE);
	}

	private static final long serialVersionUID = 1L;
} 


  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3435
Joined: Oct 19th, 2005
Re: Clearing a NodeListView in JDiagram
Reply #3 - Dec 17th, 2020 at 11:13am
Print Post  
Try this -

Code
Select All
mnuRemove.addActionListener(new ActionListener()
{
	@Override
	public void actionPerformed(ActionEvent e)
	{
	/*    nodeList.removeAll();
		nodeList.clearNodes();
		nodeList.repaint(); */

		// import javax.swing.DefaultListModel;
		nodeList.clearNodes();
		((DefaultListModel)nodeList.getModel()).removeAllElements();

	}
}); 



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