How to disable visual graph (interconnection) modifications in JGraphT/JGraphX? - java

I have visualized relationships in my program with JGraphT's JGraphXAdapter.
Unfortunately, I need to allow user only visual modifications of the graph, i.e. moving/resizing nodes. But he still can edit something, despite the fact I disabled everything I found:
setLayout(new BorderLayout());
add(
new mxGraphComponent(
jgxAdapter = new JGraphXAdapter<Corpus, CorporaDirectory.CorporaGraphEdge>(
CorporaDirectory.getInstance().getCorporaGraphModel()
) {{
setCellsDeletable(false);
setCellsCloneable(false);
setCellsEditable(false);
setCellsDisconnectable(false);
setConnectableEdges(false);
setVertexLabelsMovable(false);
setSplitEnabled(false);
}}
)
);
specifically user still can add new edges:
UDPATE
If I set setEnablled(false) to mxGraphComponent then I get totally frozen graph.

Try using mxGraphComponent.setConnectable(false), it should disable connection handler in the graph component.

Related

org.graphstream.ui.layout.LayoutRunner run INFO: Layout 'SpringBox' process stopped. Is it a problem?

I use GraphStream in my application and to show graphs I use a FXViewer for every graph.
Initially I want to show the different graphs, without setting positions of nodes, so I use the enableAutoLayout() method:
ArrayList<FxViewer> viewers = new ArrayList<>();
foreach(Graph graph : graphList) {
FxViewer viewer = new FxViewer(graph, FxViewer.ThreadingModel.GRAPH_IN_GUI_THREAD);
viewer.addView(graph.getId(), new FxGraphRenderer());
viewer.enableAutoLayout();
viewers.add(viewer);
}
Next, I want to show the same graphs but with fixed positions setted manually and so, for every graph, I disable the autoLayout to the related FXViewer.
viewers.forEach(Viewer::disableAutoLayout);
But, for every time I disable the autoLayout to a FXViewer in my console appears this message:
org.graphstream.ui.layout.LayoutRunner run
INFO: Layout 'SpringBox' process stopped.
Is it a problem? Should I do something or I can just ignore this message?
For anyone who might have the same question, here is the answer from the team of GraphStream:
That message is emitted by the LayoutRunner that handles the graph layout in a different thread. That thread is stopped when you disable the auto layout. And as the log category says, it's just info, so nothing to worry about.

Netbeans adding actions to output window

I have a netbeans platform application,
The Output window consists of two tabs in which am able to embed one of the tab in to a separate component with the following reference,
http://wiki.netbeans.org/DevFaqOWTabEmbedding
However, when i tried adding actions to it , the actions are not coming up in UI .
IOContainer ioc = IOContainer.create(new IOC());
InputOutput io = IOProvider.getDefault().getIO("test",
new Action[]{
new OneAction(),
new TwoAction(),
new ThreeAction()},ioc);
am expecting the three actions to be shown in the newly created window.
Something like this,
But am getting only the white window.
However, if i don't embed the tab in to another component, the actions appear.
Any help?
IOC has empty implementation of IOContainer.Provider method
setToolbarActions(JComponent comp, Action[] toolbarActions)
you should add JToolbar in IOC and implement that method.

Chart Wont Show When I Run It?

I'm trying to make a simple pie chart appear on a jpanel in netbeans with JFreeChart and got this:
public void createPieChart()
{
DefaultPieDataset myPie = new DefaultPieDataset();
myPie.setValue("Apples",new Integer(12));
myPie.setValue("Oranges",new Integer(23));
myPie.setValue("Mangos",new Integer(7));
myPie.setValue("Pears",new Integer(22));
JFreeChart myChart = ChartFactory.createPieChart3D("Damo's Fruit Sales", myPie,true,true,true);
PiePlot3D pie3D = (PiePlot3D)myChart.getPlot();
ChartPanel myPanel = new ChartPanel(myChart);
lowerMain_PNL.removeAll();
lowerMain_PNL.add(myPanel,BorderLayout.CENTER);
lowerMain_PNL.revalidate();
}
I get no compiler errors and when it runs the window appears with the button, but when I press the button my pie chart doesn't appear. Anyone know what I could be missing?
Check the layout manager of lowerMain_PNL. Netbeans form designer uses GroupLayout by default, so unless you changed it, that's what you got. Adding to a container using GroupLayout at run time is tricky, especially if the component contains more than one subcomponent (And requires adding components to the layout, instead of using the usual add() methods).
Change it to BorderLayout instead, since you are using BorderLayout constraints.

Add JTree (CheckboxTree) to JDialog

This is probably a simple question, I'm not very used to Java programming. But I need to create a dialog with a CheckboxTree (a variant of JTree with checkboxes, see http://www.javaworld.com/javaworld/jw-09-2007/jw-09-checkboxtree.html)
Please note: I have created the JDialog in the graphical environment of NetBeans, so it has generated code for adding buttons etc. So I need to know how to add this tree after the creation of the main parts, so to speak... Maybe that's the problem, because if I do something like this:
JPanel panel = new JPanel();
this.setContentPane(panel);
Then I actually see the tree showing up in the dialog, but all the buttons and all are gone...
I have been able to add it to a JFrame and an optionspane, but I want it in a custom JDialog. Could anyone please explain to me in very simple terms what I need to do?
Here are my feeble attempts so far:
Constructor for the JDialog:
public MetadataUI(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
Container panel = getContentPane();
panel.add(getTree());
panel.repaint();
this.pack();
}
getTree method that creates the checkboxtree:
private static CheckboxTree getTree() {
DefaultMutableTreeNode root, child;
root = new DefaultMutableTreeNode("root");
child = new DefaultMutableTreeNode("Colors");
root.add(child);
child.add(new DefaultMutableTreeNode("Cyan"));
child.add(new DefaultMutableTreeNode("Magenta"));
child.add(new DefaultMutableTreeNode("Yellow"));
child.add(new DefaultMutableTreeNode("Black"));
CheckboxTree checkboxTree = new CheckboxTree(root);
checkboxTree.setVisible(true);
return checkboxTree;
}
This repainting and all that is the last attempt based on something I found Googling, but it made no difference whatsoever, so I'm guessing I'm way off.
The simplest way to add the tree and make it visible would be appreciated. It seems to work exactly as a JTree with regards to adding it, but I cannot make it work. So even if no one has experience with this particular checkboxtree plugin, the same (simplest) code for using a JTree in a JDialog would probably do!
EDIT:
In response to Andrew, here is the same thing (my best attempt) with a regular JTree:
private static JTree getTree() {
DefaultMutableTreeNode root, child;
root = new DefaultMutableTreeNode("root");
child = new DefaultMutableTreeNode("Colors");
root.add(child);
child.add(new DefaultMutableTreeNode("Cyan"));
child.add(new DefaultMutableTreeNode("Magenta"));
child.add(new DefaultMutableTreeNode("Yellow"));
child.add(new DefaultMutableTreeNode("Black"));
JTree tree = new JTree(root);
tree.setVisible(true);
return tree;
}
EDIT 2:
In response to Maxim, I'm confused. Things that are obvious to you are probably lost on me. Borrowing some stuff from your code this is the best I could come up with (doesn't work):
public MetadataUI(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
JScrollPane s = new JScrollPane();
s.getViewport().add(getTree());
getContentPane().add(s, BorderLayout.CENTER);
setVisible(true);
}
If you indeed created your JDialog with Netbeans GUI (it's a JDialog form) and the component you are trying to integrate into what you already have provides a zero argument constructor, try the following:
open your existing JDialog in Design mode
In the Navigator view right-click [JDialog] or whatever your top-level node is (should be a sibling of "Other Components") and select Add From Palette > Beans > Choose Bean
enter a fully qualified name for the class which represents your JTree component (ex. com.example.jtree.SomeJTreeComponent) and confirm. If the component is trully a JTree it will probably get added without any problems.
(optional) At this point the tree may or may not be enclosed within a JScrollPane. If it is not, you can manually achieve this by repeating parts of step 2. on your newly added component and choosing Enclose in this time around.
You will need to program other stuff by hand. I suggest you read a JTree Tutorial or refer to the documentation of your 3rd party component to help you through it.
You might also want to read more about the tool you are using to build your GUI.

Frame Showing Problem

I have made one project which is showing the inventory of the stock of one store.
In that inventory the software should store data of the products with their images.
There is one problem...
Bcz of the lots of stock, the screen on which is image is loading taking a lot of time.
So, i thought i should give the frame in which there will be on label which will show the "Loading Software".
But now when i am setting visible = true for that frame, but bcz of that images screen class loading problem my frame is not showing correctly. I have put screen shot, now my code.
JFrame f;
try{
f = new JFrame("This is a test");
f.setSize(300, 300);
Container content = f.getContentPane();
content.setBackground(Color.white);
content.setLayout(new FlowLayout());
JLabel jl = new JLabel();
jl.setText("Loading Please Wait....");
content.add(jl);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}catch(Exception e){
e.printStackTrace();
}
initComponents();
try {
addInverntory = new AddInventoryScreen();
showstock = new showStock(); // this class will take big time.
mf = new mainForm();
f.setVisible(false);
}catch (Exception ex) {
ex.printStackTrace();
}
How Can show some message that, other class is loading or "Loading Software" kind of thing in this situation.
Just For the know....this class is not screen on which the image will load.
It's hard to answer this because it's not clear what the effects (Swing-wise) are of the calls to new AddInventoryScreen(); and new showStock();. You should only touch the UI that the user sees right at the end (when all the processing is done).
You should really spin off methods that will take a long time into their own Thread (see SwingWorker. There are alternatives for Java 5.0). That way, the UI won't be blocked while it's processing.
Maybe what you want is a Splash Screen?
Try calling validate(); and pack(); methods before calling f.setVisible(true);
Your code can be
validate();
pack();
f.setVisible(false);
I think one big problem in your code (maybe not the only one however) is the fact that you should use a different thread for long operations.
GUI operations (creating swing components, adding them to panels, changing labels...) are to be performed exclusively in the "EDT" and must be short (typically, less than 100ms or even 50ms).
Long operations can be easily done by another thread if you use the SwingWorker API (part of JDK 1.6).

Categories

Resources