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.GateRuntimeException;
10
11 import com.ontotext.gate.vr.*;
12
13
14 public class EditURIDialog extends JDialog {
15
16
17 private OntologyEditor editor;
18
19 private Taxonomy ontology;
20 protected GridBagLayout gridBagLayout1 = new GridBagLayout();
21 protected JButton btnOk = new JButton();
22 protected JButton btnCancel = new JButton();
23 protected JLabel jLabel1 = new JLabel();
24 protected JComboBox comboURI = new JComboBox();
25
26
29 public EditURIDialog(OntologyEditor e, Taxonomy o) {
30 if ( null == e )
31 throw new GateRuntimeException("editor is null, on constructing EditURIDialog");
32
33 if ( null == o )
34 throw new GateRuntimeException("ontology is null, on constructing EditURIDialog");
35
36 ontology = o;
37 editor = e;
38
39 try {
40 jbInit();
41 }
42 catch(Exception ex) {
43 ex.printStackTrace();
44 }
45
46 }
48 private void jbInit() throws Exception {
49 btnOk.setBorder(BorderFactory.createEtchedBorder());
50 btnOk.setText("OK");
51 this.getContentPane().setLayout(gridBagLayout1);
52 this.setTitle("");
53
54
55
56 this.setSize(new Dimension(360, 101));
57
58 this.addKeyListener(new EnterEscListener());
59 btnCancel.setBorder(BorderFactory.createEtchedBorder());
60 btnCancel.setText("Cancel");
61 jLabel1.setText("URI ");
62
63 comboURI = new JComboBox(new Vector(editor.getAllURIs()));
64 comboURI.setSelectedItem(ontology.getDefaultNameSpace());
65 comboURI.setEditable(true);
66
67 this.getContentPane().add(jLabel1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
68 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(6, 16, 6, 0), 11, 0));
69 this.getContentPane().add(comboURI, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
70 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(19, 3, 9, 19), 24, 0));
71 this.getContentPane().add(btnOk, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
72 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 178, 2, 0), 21, 0));
73 this.getContentPane().add(btnCancel, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0
74 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(6, 9, 3, 10), 6, 0));
75
76
77 btnOk.addActionListener(new BtnListener());
78 btnCancel.addActionListener(new BtnListener());
79 this.addKeyListener(new EnterEscListener());
80
81 }
83
84 private class BtnListener implements ActionListener {
85 public void actionPerformed(ActionEvent e) {
86 if (btnCancel == e.getSource()) {
87 EditURIDialog.this.setVisible(false);
88 }
90 if (btnOk == e.getSource()) {
91
92 if (null == editor)
93 throw new GateRuntimeException("reference to the editor not set \n"
94 +"in EditURIDialog");
95
96 if (null == ontology)
97 throw new GateRuntimeException("reference to the ontology not set \n"
98 +"in EditURIDialog");
99
100 ontology.setDefaultNameSpace(
101 (String)EditURIDialog.this.comboURI.getModel().getSelectedItem());
102
103 EditURIDialog.this.setVisible(false);
104 } } }
108
109 private class EnterEscListener implements KeyListener {
110 public void keyTyped(KeyEvent kev){};
111 public void keyReleased(KeyEvent kev) {};
112 public void keyPressed(KeyEvent kev) {
113 if (kev.VK_ENTER == kev.getKeyCode()) {
114 if (null == editor)
115 throw new GateRuntimeException("reference to the editor not set \n"
116 +"in EditURIDialog");
117
118 if (null == ontology )
119 throw new GateRuntimeException(
120 "reference to the ontolgy to be renamed is null \n"
121 +"in EditURIDialog");
122
123 ontology.setDefaultNameSpace(
124 (String)EditURIDialog.this.comboURI.getModel().getSelectedItem());
125
126 EditURIDialog.this.setVisible(false);
127
128 } else {
130 if (kev.VK_ESCAPE == kev.getKeyCode()) {
131 EditURIDialog.this.setVisible(false);
132 } } } }
137 }