1 | package jp.ac.osaka_u.sanken.sparql.gui;
|
---|
2 |
|
---|
3 | import javax.swing.Box;
|
---|
4 | import javax.swing.BoxLayout;
|
---|
5 | import javax.swing.JDialog;
|
---|
6 |
|
---|
7 | import com.hp.hpl.jena.rdf.model.Model;
|
---|
8 | import com.hp.hpl.jena.rdf.model.RDFNode;
|
---|
9 | import com.hp.hpl.jena.rdf.model.impl.ResourceImpl;
|
---|
10 |
|
---|
11 | import javax.swing.JPanel;
|
---|
12 |
|
---|
13 | import java.awt.Component;
|
---|
14 | import java.awt.GridBagLayout;
|
---|
15 | import java.awt.Dimension;
|
---|
16 | import javax.swing.JTextField;
|
---|
17 | import java.awt.GridBagConstraints;
|
---|
18 | import javax.swing.JLabel;
|
---|
19 | import java.awt.Insets;
|
---|
20 | import java.awt.event.ActionEvent;
|
---|
21 | import java.awt.event.ActionListener;
|
---|
22 |
|
---|
23 | import javax.swing.JButton;
|
---|
24 |
|
---|
25 | public class TripleEditDialog extends JDialog {
|
---|
26 |
|
---|
27 | /**
|
---|
28 | *
|
---|
29 | */
|
---|
30 | private static final long serialVersionUID = -8353265680791711240L;
|
---|
31 | private RDFNode s;
|
---|
32 | private RDFNode p;
|
---|
33 | private RDFNode o;
|
---|
34 | private Model model;
|
---|
35 | private JPanel mainPanel = null;
|
---|
36 | private JTextField subjectTextField = null;
|
---|
37 | private JTextField propertyTextField = null;
|
---|
38 | private JTextField objectTextField = null;
|
---|
39 | private JLabel subjectLabel = null;
|
---|
40 | private JLabel propertyLabel = null;
|
---|
41 | private JLabel objectLabel = null;
|
---|
42 | private JPanel buttonPanel = null;
|
---|
43 | private JButton okButton = null;
|
---|
44 | private JButton cancelButton = null;
|
---|
45 |
|
---|
46 | public boolean ok = false;
|
---|
47 |
|
---|
48 | public TripleEditDialog(RDFNode s, RDFNode p, RDFNode o, Model model){
|
---|
49 | this.s = s;
|
---|
50 | this.p = p;
|
---|
51 | this.o = o;
|
---|
52 | this.model = model;
|
---|
53 | initialize();
|
---|
54 |
|
---|
55 | this.getSubjectTextField().setText(s.toString());
|
---|
56 | this.getPropertyTextField().setText(p.toString());
|
---|
57 | if (o != null){
|
---|
58 | this.getObjectTextField().setText(o.toString());
|
---|
59 | }
|
---|
60 | this.setModal(true);
|
---|
61 | }
|
---|
62 |
|
---|
63 | public RDFNode getSubject(){
|
---|
64 | if (s == null && this.getSubjectTextField().getText().isEmpty()){
|
---|
65 | return null;
|
---|
66 | }
|
---|
67 |
|
---|
68 | if (s != null && s.toString().equals(this.getSubjectTextField().getText())){
|
---|
69 | return s;
|
---|
70 | }
|
---|
71 |
|
---|
72 | return getRDFNodeFromString(this.getSubjectTextField().getText());
|
---|
73 | }
|
---|
74 |
|
---|
75 | public RDFNode getProperty(){
|
---|
76 | if (p == null && this.getPropertyTextField().getText().isEmpty()){
|
---|
77 | return null;
|
---|
78 | }
|
---|
79 |
|
---|
80 | if (p != null && p.toString().equals(this.getPropertyTextField().getText())){
|
---|
81 | return p;
|
---|
82 | }
|
---|
83 |
|
---|
84 | return getRDFNodeFromString(this.getPropertyTextField().getText());
|
---|
85 | }
|
---|
86 |
|
---|
87 | public RDFNode getObject(){
|
---|
88 | if (o == null && this.getObjectTextField().getText().isEmpty()){
|
---|
89 | return null;
|
---|
90 | }
|
---|
91 |
|
---|
92 | if (o != null && o.toString().equals(this.getObjectTextField().getText())){
|
---|
93 | return o;
|
---|
94 | }
|
---|
95 |
|
---|
96 | return getRDFNodeFromString(this.getObjectTextField().getText());
|
---|
97 | }
|
---|
98 |
|
---|
99 | private RDFNode getRDFNodeFromString(String str){
|
---|
100 | if (str.startsWith("http://")){
|
---|
101 | ResourceImpl ri = new ResourceImpl(str);
|
---|
102 | return ri;
|
---|
103 | }
|
---|
104 |
|
---|
105 | return model.createLiteral(str);
|
---|
106 |
|
---|
107 | }
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * This method initializes this
|
---|
111 | *
|
---|
112 | */
|
---|
113 | private void initialize() {
|
---|
114 | this.setSize(new Dimension(999, 157));
|
---|
115 | this.setContentPane(getMainPanel());
|
---|
116 | }
|
---|
117 | /**
|
---|
118 | * This method initializes mainPanel
|
---|
119 | *
|
---|
120 | * @return javax.swing.JPanel
|
---|
121 | */
|
---|
122 | private JPanel getMainPanel() {
|
---|
123 | if (mainPanel == null) {
|
---|
124 | GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
|
---|
125 | gridBagConstraints6.gridx = 2;
|
---|
126 | gridBagConstraints6.fill = GridBagConstraints.HORIZONTAL;
|
---|
127 | gridBagConstraints6.gridy = 2;
|
---|
128 | GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
|
---|
129 | gridBagConstraints5.gridx = 2;
|
---|
130 | gridBagConstraints5.gridy = 0;
|
---|
131 | objectLabel = new JLabel();
|
---|
132 | objectLabel.setText("Object");
|
---|
133 | GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
|
---|
134 | gridBagConstraints4.gridx = 1;
|
---|
135 | gridBagConstraints4.gridy = 0;
|
---|
136 | propertyLabel = new JLabel();
|
---|
137 | propertyLabel.setText("Property");
|
---|
138 | GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
|
---|
139 | gridBagConstraints3.gridx = 0;
|
---|
140 | gridBagConstraints3.gridy = 0;
|
---|
141 | subjectLabel = new JLabel();
|
---|
142 | subjectLabel.setText("Subject");
|
---|
143 | GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
|
---|
144 | gridBagConstraints2.fill = GridBagConstraints.HORIZONTAL;
|
---|
145 | gridBagConstraints2.gridy = 1;
|
---|
146 | gridBagConstraints2.weightx = 1.0;
|
---|
147 | gridBagConstraints2.insets = new Insets(0, 10, 0, 10);
|
---|
148 | gridBagConstraints2.gridx = 2;
|
---|
149 | GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
|
---|
150 | gridBagConstraints1.fill = GridBagConstraints.HORIZONTAL;
|
---|
151 | gridBagConstraints1.gridy = 1;
|
---|
152 | gridBagConstraints1.weightx = 1.0;
|
---|
153 | gridBagConstraints1.insets = new Insets(0, 10, 0, 10);
|
---|
154 | gridBagConstraints1.gridx = 1;
|
---|
155 | GridBagConstraints gridBagConstraints = new GridBagConstraints();
|
---|
156 | gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
---|
157 | gridBagConstraints.gridy = 1;
|
---|
158 | gridBagConstraints.weightx = 1.0;
|
---|
159 | gridBagConstraints.insets = new Insets(0, 10, 0, 10);
|
---|
160 | gridBagConstraints.gridx = 0;
|
---|
161 | mainPanel = new JPanel();
|
---|
162 | mainPanel.setLayout(new GridBagLayout());
|
---|
163 | mainPanel.add(getSubjectTextField(), gridBagConstraints);
|
---|
164 | mainPanel.add(getPropertyTextField(), gridBagConstraints1);
|
---|
165 | mainPanel.add(getObjectTextField(), gridBagConstraints2);
|
---|
166 | mainPanel.add(subjectLabel, gridBagConstraints3);
|
---|
167 | mainPanel.add(propertyLabel, gridBagConstraints4);
|
---|
168 | mainPanel.add(objectLabel, gridBagConstraints5);
|
---|
169 | mainPanel.add(getButtonPanel(), gridBagConstraints6);
|
---|
170 | }
|
---|
171 | return mainPanel;
|
---|
172 | }
|
---|
173 |
|
---|
174 | /**
|
---|
175 | * This method initializes subjectTextField
|
---|
176 | *
|
---|
177 | * @return javax.swing.JTextField
|
---|
178 | */
|
---|
179 | private JTextField getSubjectTextField() {
|
---|
180 | if (subjectTextField == null) {
|
---|
181 | subjectTextField = new JTextField();
|
---|
182 | subjectTextField.setEditable(false);
|
---|
183 | }
|
---|
184 | return subjectTextField;
|
---|
185 | }
|
---|
186 |
|
---|
187 | /**
|
---|
188 | * This method initializes propertyTextField
|
---|
189 | *
|
---|
190 | * @return javax.swing.JTextField
|
---|
191 | */
|
---|
192 | private JTextField getPropertyTextField() {
|
---|
193 | if (propertyTextField == null) {
|
---|
194 | propertyTextField = new JTextField();
|
---|
195 | }
|
---|
196 | return propertyTextField;
|
---|
197 | }
|
---|
198 |
|
---|
199 | /**
|
---|
200 | * This method initializes objectTextField
|
---|
201 | *
|
---|
202 | * @return javax.swing.JTextField
|
---|
203 | */
|
---|
204 | private JTextField getObjectTextField() {
|
---|
205 | if (objectTextField == null) {
|
---|
206 | objectTextField = new JTextField();
|
---|
207 | }
|
---|
208 | return objectTextField;
|
---|
209 | }
|
---|
210 |
|
---|
211 | /**
|
---|
212 | * This method initializes buttonPanel
|
---|
213 | *
|
---|
214 | * @return javax.swing.JPanel
|
---|
215 | */
|
---|
216 | private JPanel getButtonPanel() {
|
---|
217 | if (buttonPanel == null) {
|
---|
218 | buttonPanel = new JPanel();
|
---|
219 | buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
|
---|
220 | buttonPanel.setAlignmentX(Component.RIGHT_ALIGNMENT);
|
---|
221 | buttonPanel.add(getOkButton());
|
---|
222 | buttonPanel.add(Box.createRigidArea(new Dimension(10, 10)));
|
---|
223 | buttonPanel.add(getCancelButton());
|
---|
224 | }
|
---|
225 | return buttonPanel;
|
---|
226 | }
|
---|
227 |
|
---|
228 | /**
|
---|
229 | * This method initializes okButton
|
---|
230 | *
|
---|
231 | * @return javax.swing.JButton
|
---|
232 | */
|
---|
233 | private JButton getOkButton() {
|
---|
234 | if (okButton == null) {
|
---|
235 | okButton = new JButton("OK");
|
---|
236 | okButton.addActionListener(new ActionListener() {
|
---|
237 |
|
---|
238 | @Override
|
---|
239 | public void actionPerformed(ActionEvent arg0) {
|
---|
240 | ok = true;
|
---|
241 | setVisible(false);
|
---|
242 | }
|
---|
243 | });
|
---|
244 | }
|
---|
245 | return okButton;
|
---|
246 | }
|
---|
247 |
|
---|
248 | /**
|
---|
249 | * This method initializes cancelButton
|
---|
250 | *
|
---|
251 | * @return javax.swing.JButton
|
---|
252 | */
|
---|
253 | private JButton getCancelButton() {
|
---|
254 | if (cancelButton == null) {
|
---|
255 | cancelButton = new JButton("CANCEL");
|
---|
256 | cancelButton.addActionListener(new ActionListener() {
|
---|
257 |
|
---|
258 | @Override
|
---|
259 | public void actionPerformed(ActionEvent e) {
|
---|
260 | ok = false;
|
---|
261 | setVisible(false);
|
---|
262 | }
|
---|
263 | });
|
---|
264 | }
|
---|
265 | return cancelButton;
|
---|
266 | }
|
---|
267 |
|
---|
268 | } // @jve:decl-index=0:visual-constraint="86,101"
|
---|