import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.table.DefaultTableModel;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.MutableTreeNode;
import javax.swing.tree.TreePath;
public class test4 extends JFrame {
private static List<Object> list;
private DefaultTreeModel treeModel;
private JTree tree;
private NameSpaceMenu nameSpaceMenu = new NameSpaceMenu();
private AttributMenu attributMenu = new AttributMenu();
private ElementMenu elementMenu = new ElementMenu();
private JPanel paneledit;
private JPanel paneltree;
private JPanel panelparm;
public test4() {
list = new ArrayList<Object>();
DefaultMutableTreeNode root = new DefaultMutableTreeNode(
"EXTraEDIDefinition");
DefaultMutableTreeNode node = new DefaultMutableTreeNode("Main");
DefaultMutableTreeNode leaf;
node.add(leaf = new DefaultMutableTreeNode(new NameSpaceParent()));
leaf.add(new DefaultMutableTreeNode("Namensraum1"));
node.add(leaf = new DefaultMutableTreeNode(new AttributeParent()));
leaf.add(new DefaultMutableTreeNode("Attribut1"));
node.add(leaf = new DefaultMutableTreeNode(new ElementParent()));
leaf.add(new DefaultMutableTreeNode("Element1"));
root.add(node);
node = new DefaultMutableTreeNode("Verfahren 1");
node.add(leaf = new DefaultMutableTreeNode(new NameSpaceParent()));
leaf.add(new DefaultMutableTreeNode("Namensraum1"));
node.add(leaf = new DefaultMutableTreeNode(new AttributeParent()));
leaf.add(new DefaultMutableTreeNode("Attribut1"));
node.add(leaf = new DefaultMutableTreeNode(new ElementParent()));
leaf.add(new DefaultMutableTreeNode("Element1"));
root.add(node);
node = new DefaultMutableTreeNode("Verfahren 2");
node.add(leaf = new DefaultMutableTreeNode(new NameSpaceParent()));
leaf.add(new DefaultMutableTreeNode("Namensraum1"));
node.add(leaf = new DefaultMutableTreeNode(new AttributeParent()));
leaf.add(new DefaultMutableTreeNode("Attribut1"));
node.add(leaf = new DefaultMutableTreeNode(new ElementParent()));
leaf.add(new DefaultMutableTreeNode("Element1"));
root.add(node);
treeModel = new DefaultTreeModel(root);
tree = new JTree(treeModel);
paneltree = new JPanel();
paneltree.setBounds(0, 0, 400, 625);
paneltree.setLayout(new BorderLayout());
paneltree.add(tree);
paneledit = new JPanel();
paneledit.setBounds(400, 0, 170, 625);
paneledit.setLayout(new BorderLayout());
panelparm = new JPanel();
panelparm.setBounds(570, 0, 430, 625);
panelparm.setLayout(null);
panelparm.setBackground(new Color(230, 240, 240));
JScrollPane js1 = new JScrollPane(paneledit);
JScrollPane js2 = new JScrollPane(paneltree);
JScrollPane js3 = new JScrollPane(panelparm);
js3.setBounds(610, 10, 490, 606);
js3.setBorder(BorderFactory.createLineBorder(Color.GRAY));
JSplitPane jp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, js2, js1);
jp.setBounds(10, 10, 600, 606);
jp.setBorder(BorderFactory.createLineBorder(Color.GRAY));
jp.setOneTouchExpandable(true);
jp.setDividerLocation(290);
Dimension minimumSize = new Dimension(150, 600);
js1.setMinimumSize(minimumSize);
js2.setMinimumSize(minimumSize);
js3.setMinimumSize(minimumSize);
JPanel panel_all = new JPanel();
panel_all.setLayout(null);
panel_all.add(jp);
panel_all.add(js3);
panel_all.setBounds(10, 25, 1100, 650);
this.getContentPane().add(panel_all);
tree.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getModifiers() == 4)
checkPopup(e);
else if (e.getModifiers() == 16)
newWindow(e);
}
public void mouseReleased(MouseEvent e) {
if (e.getModifiers() == 4)
checkPopup(e);
else if (e.getModifiers() == 16)
;
}
public void checkPopup(MouseEvent e) {
TreePath path = tree.getPathForLocation(e.getX(), e.getY());
if (path == null)
return;
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path
.getLastPathComponent();
DefaultMutableTreeNode tmp = (DefaultMutableTreeNode) path
.getLastPathComponent();
Object obj = node.getUserObject();
if (obj instanceof NameSpaceParent)
nameSpaceMenu.showMenu(e.getPoint(), node);
else if (obj instanceof AttributeParent)
attributMenu.showMenu(e.getPoint(), node);
else if (obj instanceof ElementParent)
elementMenu.showMenu(e.getPoint(), node);
else if (node.isLeaf())
;
}
public void newWindow(MouseEvent e) {
TreePath path = tree.getPathForLocation(e.getX(), e.getY());
if (path == null)
return;
DefaultMutableTreeNode tmp = (DefaultMutableTreeNode) path
.getLastPathComponent();
if (tmp.toString().equals("Namensräume")) {
Panelvorlage panel = new Panelvorlage();
panel.prepare_namensraum();
}
}
});
}
class Panelvorlage extends JPanel {
private int counter1 = 0;
private JPanel panel_namensraum;
private JPanel panel_attribut;
private JPanel panel_element;
private JPanel panel_array;
private JPanel panel_anyxml;
private JCheckBox array_chk;
private JCheckBox anyxml_chk;
private JCheckBox element_chk;
private JCheckBox namensraum_chk;
private JCheckBox attribut_chk;
public void prepare_namensraum() {
namensraum_chk = new JCheckBox("Namensraum1");
namensraum_chk.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if(namensraum_chk.isSelected()){
JLabel name = new JLabel();
name.setBounds(10, 10, 120, 25);
JLabel parameter = new JLabel("Parameter");
parameter.setBounds(57, 10, 120, 25);
JLabel wert = new JLabel("Wert");
wert.setBounds(233, 10, 120, 25);
final JComboBox combo = new JComboBox();
combo.setBounds(15, 50, 150, 24);
String[] values = { "compressconditionProc",
"countTagBytes", "encrypt", "getParm", "getPref",
"getProc", "inhalt", "isBinary", "isDigest",
"isSignature", "mandatory", "name", "nameGetParm",
"nameSetParm", "parse", "pfad", "pref", "setParm",
"setProc", "signate", "valueId" };
for (String s : values)
combo.addItem(s);
final JTextField text = new JTextField("");
text.setBounds(180, 50, 150, 25);
String[] columnNames = { "Parameter", "Wert", };
Object[][] data = {};
final DefaultTableModel model = new DefaultTableModel(data,
columnNames);
final JTable table = new JTable(model);
final JScrollPane pane = new JScrollPane(table);
pane.setBounds(15, 90, 458, 32);
JButton button = new JButton("Add Parameter");
button.setBounds(350, 50, 120, 24);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
model.insertRow(counter1, new Object[] {
combo.getSelectedItem().toString(),
text.getText() });
counter1++;
if (pane.getSize().height < 470)
pane.setSize(pane.getSize().width, pane
.getSize().height + 16);
}
});
panelparm.add(parameter);
panelparm.add(wert);
panelparm.add(pane);
panelparm.add(name);
panelparm.add(combo);
panelparm.add(text);
panelparm.add(button);
panelparm.revalidate();
panelparm.repaint();
JCheckBox c1 = new JCheckBox("Namensraum" + counter1);
c1.setBounds(namensraum_chk.getBounds());
c1.setSize(c1.getSize().width, c1.getSize().height + 50);
panel_array.setLocation(panel_array.getX(), panel_array.getY() + 30);
panel_element.setLocation(panel_element.getX(), panel_element.getY() + 30);
panel_anyxml.setLocation(panel_anyxml.getX(), panel_anyxml.getY() + 30);
panel_attribut.setLocation(panel_attribut.getX(), panel_attribut.getY() + 30);
array_chk.setLocation(array_chk.getX(), array_chk.getY() + 30);
element_chk.setLocation(element_chk.getX(), element_chk.getY() + 30);
anyxml_chk.setLocation(anyxml_chk.getX(), anyxml_chk.getY() + 30);
attribut_chk.setLocation(attribut_chk.getX(), attribut_chk.getY() + 30);
panel_namensraum.add(c1);
panel_namensraum.setSize(panel_namensraum.getSize().width, panel_namensraum.getSize().height + 30);
}
else
;
}
});
namensraum_chk.setBounds(15, 35, 125, 25);
panel_namensraum = new JPanel();
panel_namensraum.setBounds(10, 30, 135, 35);
panel_namensraum.setLayout(new BorderLayout());
panel_namensraum.setBorder(BorderFactory.createEtchedBorder());
panel_namensraum.add(namensraum_chk);
attribut_chk = new JCheckBox("Attribut1");
attribut_chk.setBounds(15, 100, 125, 25);
panel_attribut = new JPanel();
panel_attribut.setBounds(10, 95, 135, 35);
panel_attribut.setLayout(new BorderLayout());
panel_attribut.setBorder(BorderFactory.createEtchedBorder());
panel_attribut.add(attribut_chk);
element_chk = new JCheckBox("Element1");
element_chk.setBounds(15, 150, 125, 25);
panel_element = new JPanel();
panel_element.setBounds(10, 145, 135, 35);
panel_element.setBorder(BorderFactory.createEtchedBorder());
panel_element.add(element_chk);
array_chk = new JCheckBox("Array1");
array_chk.setBounds(15, 200, 125, 25);
panel_array = new JPanel();
panel_array.setBounds(10, 195, 135, 35);
panel_array.setBorder(BorderFactory.createEtchedBorder());
panel_array.add(array_chk);
anyxml_chk = new JCheckBox("AnyXml1");
anyxml_chk.setBounds(15, 250, 125, 25);
panel_anyxml = new JPanel();
panel_anyxml.setBounds(10, 245, 135, 35);
panel_anyxml.setBorder(BorderFactory.createEtchedBorder());
panel_anyxml.add(anyxml_chk);
JLabel labeltyp = new JLabel("Typenauswahl");
labeltyp.setBounds(15, 5, 110, 25);
this.add(labeltyp);
this.add(panel_namensraum);
this.add(panel_attribut);
this.add(panel_element);
this.add(panel_array);
this.add(panel_anyxml);
this.add(attribut_chk);
this.add(element_chk);
this.add(array_chk);
this.add(anyxml_chk);
this.setLayout(null);
this.revalidate();
this.repaint();
paneledit.add(this);
paneledit.revalidate();
paneledit.repaint();
}
public void prepare_attribut() {
JCheckBox namensraum_chk = new JCheckBox("Namensraum1");
namensraum_chk.setBounds(15, 15, 110, 25);
JCheckBox attribut_chk = new JCheckBox("Attribut1");
attribut_chk.setBounds(15, 15, 110, 25);
JCheckBox element_chk = new JCheckBox("Element1");
element_chk.setBounds(15, 15, 110, 25);
JCheckBox array_chk = new JCheckBox("Array1");
array_chk.setBounds(15, 15, 110, 25);
JCheckBox anyxml_chk = new JCheckBox("AnyXml1");
anyxml_chk.setBounds(15, 15, 110, 25);
JComboBox combo = new JComboBox();
String[] values = { "compressconditionProc", "countTagBytes",
"encrypt", "getParm", "getPref", "getProc", "inhalt",
"isBinary", "isDigest", "isSignature", "mandatory", "name",
"nameGetParm", "nameSetParm", "parse", "pfad", "pref",
"setParm", "setProc", "signate", "valueId" };
for (String s : values)
combo.addItem(s);
}
public void prepare_element() {
JCheckBox namensraum_chk = new JCheckBox("Namensraum1");
namensraum_chk.setBounds(15, 15, 110, 25);
JCheckBox attribut_chk = new JCheckBox("Attribut1");
attribut_chk.setBounds(15, 15, 110, 25);
JCheckBox element_chk = new JCheckBox("Element1");
element_chk.setBounds(15, 15, 110, 25);
JCheckBox array_chk = new JCheckBox("Array1");
array_chk.setBounds(15, 15, 110, 25);
JCheckBox anyxml_chk = new JCheckBox("AnyXml1");
anyxml_chk.setBounds(15, 15, 110, 25);
JComboBox combo = new JComboBox();
String[] values = { "compressconditionProc", "countTagBytes",
"encrypt", "getParm", "getPref", "getProc", "inhalt",
"isBinary", "isDigest", "isSignature", "mandatory", "name",
"nameGetParm", "nameSetParm", "parse", "pfad", "pref",
"setParm", "setProc", "signate", "valueId" };
for (String s : values)
combo.addItem(s);
}
public void prepare_array() {
JCheckBox namensraum_chk = new JCheckBox("Namensraum1");
namensraum_chk.setBounds(15, 15, 110, 25);
JCheckBox attribut_chk = new JCheckBox("Attribut1");
attribut_chk.setBounds(15, 15, 110, 25);
JCheckBox element_chk = new JCheckBox("Element1");
element_chk.setBounds(15, 15, 110, 25);
JCheckBox array_chk = new JCheckBox("Array1");
array_chk.setBounds(15, 15, 110, 25);
JCheckBox anyxml_chk = new JCheckBox("AnyXml1");
anyxml_chk.setBounds(15, 15, 110, 25);
JComboBox combo = new JComboBox();
String[] values = { "compressconditionProc", "countTagBytes",
"encrypt", "getParm", "getPref", "getProc", "inhalt",
"isBinary", "isDigest", "isSignature", "mandatory", "name",
"nameGetParm", "nameSetParm", "parse", "pfad", "pref",
"setParm", "setProc", "signate", "valueId" };
for (String s : values)
combo.addItem(s);
}
public void prepare_anyxml() {
JCheckBox namensraum_chk = new JCheckBox("Namensraum1");
namensraum_chk.setBounds(15, 15, 110, 25);
JCheckBox attribut_chk = new JCheckBox("Attribut1");
attribut_chk.setBounds(15, 15, 110, 25);
JCheckBox element_chk = new JCheckBox("Element1");
element_chk.setBounds(15, 15, 110, 25);
JCheckBox array_chk = new JCheckBox("Array1");
array_chk.setBounds(15, 15, 110, 25);
JCheckBox anyxml_chk = new JCheckBox("AnyXml1");
anyxml_chk.setBounds(15, 15, 110, 25);
JComboBox combo = new JComboBox();
String[] values = { "compressconditionProc", "countTagBytes",
"encrypt", "getParm", "getPref", "getProc", "inhalt",
"isBinary", "isDigest", "isSignature", "mandatory", "name",
"nameGetParm", "nameSetParm", "parse", "pfad", "pref",
"setParm", "setProc", "signate", "valueId" };
for (String s : values)
combo.addItem(s);
}
public void clear() {
paneledit.removeAll();
}
}
private static int counter_namensraum = 2;
private static int counter_attribut = 2;
private static int counter_element = 2;
class NameSpaceMenu extends JPopupMenu {
private MutableTreeNode node;
public NameSpaceMenu() {
JMenuItem item;
item = new JMenuItem("Namesraum hinzufügen");
this.add(item);
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
DefaultMutableTreeNode child = new DefaultMutableTreeNode(
"Namensraum" + counter_namensraum);
counter_namensraum++;
treeModel.insertNodeInto(child, node, node.getChildCount());
tree.scrollPathToVisible(new TreePath(child.getPath()));
}
});
item = new JMenuItem("Namesraum entfernen");
this.add(item);
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
TreePath currentSelection = tree.getSelectionPath();
if (currentSelection != null) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode)
currentSelection.getLastPathComponent();
DefaultTreeModel model = ((DefaultTreeModel) tree
.getModel());
model.removeNodeFromParent(node.getLastLeaf());
counter_namensraum--;
}
}
});
}
public void showMenu(Point p, MutableTreeNode node) {
if (node.isLeaf() == false)
this.node = node;
super.show(tree, p.x, p.y);
}
}
class AttributMenu extends JPopupMenu {
private MutableTreeNode node;
public AttributMenu() {
JMenuItem item;
item = new JMenuItem("Attribut hinzufügen");
this.add(item);
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
DefaultMutableTreeNode child = new DefaultMutableTreeNode(
"Attribut" + counter_attribut);
counter_attribut++;
treeModel.insertNodeInto(child, node, node.getChildCount());
tree.scrollPathToVisible(new TreePath(child.getPath()));
}
});
item = new JMenuItem("Attribut entfernen");
this.add(item);
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
TreePath currentSelection = tree.getSelectionPath();
if (currentSelection != null) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode)
currentSelection.getLastPathComponent();
DefaultTreeModel model = ((DefaultTreeModel) tree
.getModel());
model.removeNodeFromParent(node.getLastLeaf());
counter_attribut--;
}
}
});
}
public void showMenu(Point p, MutableTreeNode node) {
if (node.isLeaf() == false)
this.node = node;
super.show(tree, p.x, p.y);
}
}
class ElementMenu extends JPopupMenu {
private MutableTreeNode node;
public ElementMenu() {
JMenuItem item;
item = new JMenuItem("Element hinzufügen");
this.add(item);
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
DefaultMutableTreeNode child = new DefaultMutableTreeNode(
"Element" + counter_element);
counter_element++;
treeModel.insertNodeInto(child, node, node.getChildCount());
tree.scrollPathToVisible(new TreePath(child.getPath()));
}
});
item = new JMenuItem("Element entfernen");
this.add(item);
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
TreePath currentSelection = tree.getSelectionPath();
if (currentSelection != null) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode)
currentSelection.getLastPathComponent();
DefaultTreeModel model = ((DefaultTreeModel) tree
.getModel());
model.removeNodeFromParent(node.getLastLeaf());
counter_element--;
}
}
});
}
public void showMenu(Point p, MutableTreeNode node) {
if (node.isLeaf() == false)
this.node = node;
super.show(tree, p.x, p.y);
}
}
class NameSpaceParent {
public String toString() {
return "Namensräume";
}
}
class AttributeParent {
public String toString() {
return "Attribute";
}
}
class ElementParent {
public String toString() {
return "Elemente";
}
}
public static void main(String[] args) {
JFrame frame = new test4();
frame.setTitle("XML-Converter");
frame.setBounds(0, 0, 1127, 664);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}