1
2
3
4
5
6
7 package com.vikash.firsttool.UI;
8
9 import javax.swing.*;
10 import java.awt.*;
11 import java.awt.event.*;
12 import org.jgraph.graph.*;
13 /***
14 *
15 * @author studajb
16 */
17 public class TreeElementEditDialog extends JDialog{
18 JTextArea textarea;
19 DefaultGraphCell cell;
20 /*** Creates a new instance of TreeElementEditDialod */
21 public TreeElementEditDialog(Frame owner,boolean flag,final TreeElement treeelement, final DiagramElementTreeModel model) {
22 super(owner,flag);
23 cell=(DefaultGraphCell)treeelement.getUserObject();
24 setTitle("Edit the element");
25 Toolkit kit=Toolkit.getDefaultToolkit();
26 Dimension screensize=kit.getScreenSize();
27 int WIDTH=screensize.width;
28 int HEIGHT=screensize.height;
29
30 setSize(250,150);
31 setDialogLocation();
32 Container contentPane=getContentPane();
33
34 JLabel label=new JLabel("<html><b>"+"Type Elements Name"+"<b></html>");
35 textarea=new JTextArea(40,20);
36 textarea.setLineWrap(true);
37 textarea.setText(cell.toString());
38 textarea.selectAll();
39 JScrollPane scrollpane=new JScrollPane(textarea);
40 contentPane.add(label,BorderLayout.NORTH);
41 contentPane.add(scrollpane,BorderLayout.CENTER);
42
43 JPanel panel=new JPanel();
44 JButton okButton=new JButton("Ok");
45 okButton.addActionListener(new ActionListener(){
46 public void actionPerformed(ActionEvent e){
47
48 String edit=textarea.getText();
49 cell.setUserObject(edit);
50 if(treeelement.getInternalFrame()!=null){
51 AttributeMap map=treeelement.getInternalFrame().getGraph().getGraphLayoutCache().getMapping(cell,false).getAttributes();
52 treeelement.getInternalFrame().getGraph().getGraphLayoutCache().editCell(cell,map);
53 }
54 model.setTreeChanged(true);
55
56 setVisible(false);
57 dispose();
58 }
59 });
60 panel.add(okButton);
61
62 JButton cancelButton=new JButton("Cancel");
63 panel.add(cancelButton);
64 cancelButton.addActionListener(new ActionListener(){
65 public void actionPerformed(ActionEvent e){
66 setVisible(false);
67 dispose();
68 }
69
70 });
71 contentPane.add(panel,BorderLayout.SOUTH);
72
73 }
74 private void setDialogLocation() {
75 Dimension size = getSize();
76 Dimension p = getParent().getSize();
77 int x = (getParent().getX() - size.width)
78 + (int) ((size.width + p.width) / 2d);
79 int y = (getParent().getY() - size.height)
80 + (int) ((size.height + p.height) / 2d);
81 setLocation(x, y);
82 }
83
84
85 }