1 package com.ontotext.gate.vr.dialog;
2
3 import javax.swing.*;
4 import java.awt.*;
5 import java.awt.event.*;
6 import java.util.*;
7
8 import gate.creole.ontology.*;
9 import gate.util.*;
10
11 import com.ontotext.gate.vr.*;
12
13 public class EditClassURIDialog extends JDialog {
14
15
16 private OntologyEditor editor;
17
18
19 private TClass clas;
20
21
22 private Taxonomy ontology;
23
24 protected GridBagLayout gridBagLayout1 = new GridBagLayout();
25 protected JButton btnOk = new JButton();
26 protected JButton btnCancel = new JButton();
27 protected JLabel jLabel1 = new JLabel();
28 protected JComboBox comboURI = new JComboBox();
29
30
33 public EditClassURIDialog(OntologyEditor e, TClass c) {
34 if ( null == e )
35 throw new GateRuntimeException("editor is null, on constructing EditClassURIDialog");
36
37 if ( null == c )
38 throw new GateRuntimeException("ontology class is null, on constructing EditClassURIDialog");
39
40 ontology = c.getOntology();
41
42 if ( null == ontology )
43 throw new gate.util.GateRuntimeException("ontology is null, on constructing EditClassURIDialog");
44
45 clas = c;
46 editor = e;
47
48 try {
49 jbInit();
50 }
51 catch(Exception ex) {
52 ex.printStackTrace();
53 }
54
55 }
57 private void jbInit() throws Exception {
58 btnOk.setBorder(BorderFactory.createEtchedBorder());
59 btnOk.setText("OK");
60 this.getContentPane().setLayout(gridBagLayout1);
61 this.setTitle("");
62
63
64
65 this.setSize(new Dimension(389, 111));
66
67 this.addKeyListener(new EnterEscListener());
68 btnCancel.setBorder(BorderFactory.createEtchedBorder());
69 btnCancel.setText("Cancel");
70
71 jLabel1.setText("URI ");
72
73 comboURI = new JComboBox(new Vector(editor.getAllURIs(ontology)));
74 comboURI.setSelectedItem(clas.getURI());
75 comboURI.setEditable(true);
76
77 this.getContentPane().add(comboURI, new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0
78 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(14, 0, 14, 0), -1, 0));
79 this.getContentPane().add(jLabel1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
80 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(6, 0, 6, 0), 0, 0));
81 this.getContentPane().add(btnCancel, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0
82 ,GridBagConstraints.SOUTH, GridBagConstraints.NONE, new Insets(0, 0, 0, 19), 0, 0));
83 this.getContentPane().add(btnOk, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
84 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 22, 0, 0), 27, 0));
85
86
87 btnOk.addActionListener(new BtnListener());
88 btnCancel.addActionListener(new BtnListener());
89 this.addKeyListener(new EnterEscListener());
90
91 }
93
94 private class BtnListener implements ActionListener {
95 public void actionPerformed(ActionEvent e) {
96 if (btnCancel == e.getSource()) {
97 EditClassURIDialog.this.setVisible(false);
98 }
100 if (btnOk == e.getSource()) {
101
102 if (null == editor)
103 throw new GateRuntimeException("reference to the editor not set \n"
104 +"in EditClassURIDialog");
105
106 if (null == ontology)
107 throw new GateRuntimeException("reference to the ontology not set \n"
108 +"in EditClassURIDialog");
109
110 clas.setURI(
111 (String)EditClassURIDialog.this.comboURI.getModel().getSelectedItem());
112
113 EditClassURIDialog.this.setVisible(false);
114 } } }
118
119
120 private class EnterEscListener implements KeyListener {
121 public void keyTyped(KeyEvent kev){};
122 public void keyReleased(KeyEvent kev) {};
123 public void keyPressed(KeyEvent kev) {
124 if (kev.VK_ENTER == kev.getKeyCode()) {
125 if (null == editor)
126 throw new GateRuntimeException("reference to the editor not set \n"
127 +"in EditClassURIDialog");
128
129 if (null == ontology )
130 throw new GateRuntimeException(
131 "reference to the ontolgy to be renamed is null \n"
132 +"in EditClassURIDialog");
133
134 clas.setURI(
135 (String)EditClassURIDialog.this.comboURI.getModel().getSelectedItem());
136
137 EditClassURIDialog.this.setVisible(false);
138
139 } else {
141 if (kev.VK_ESCAPE == kev.getKeyCode()) {
142 EditClassURIDialog.this.setVisible(false);
143 } } } }
147
148
149 }