root/BH13SPARQLBuilder/src/hozo/sparql/gui/SparqlAccessorForm.java @ 105

リビジョン 17, 24.4 KB (コミッタ: kozaki, 11 年 前)

Commitし直します.

  • 属性 svn:mime-type の設定値 text/plain
行番号 
1package hozo.sparql.gui;
2
3import javax.swing.JPanel;
4import java.awt.BorderLayout;
5import java.awt.Container;
6import java.awt.Dimension;
7import java.awt.EventQueue;
8
9import javax.swing.ButtonGroup;
10import javax.swing.DefaultComboBoxModel;
11import javax.swing.JComboBox;
12import javax.swing.JFileChooser;
13import javax.swing.JFrame;
14import javax.swing.JMenuBar;
15import javax.swing.JOptionPane;
16import javax.swing.JSplitPane;
17import javax.swing.JTabbedPane;
18import javax.swing.JButton;
19import java.awt.event.ActionEvent;
20import java.awt.event.ActionListener;
21import java.awt.event.WindowAdapter;
22import java.awt.event.WindowEvent;
23
24import hozo.sparql.EndpointSettings;
25import hozo.sparql.EndpointSettingsManager;
26import hozo.sparql.SparqlResultSet;
27import hozo.sparql.SparqlUtil;
28import hozo.sparql.plugin.compare.ComparePanel;
29import hozo.sparql.plugin.compare.CompareSubjectPanel;
30
31import java.awt.FlowLayout;
32import java.io.File;
33import java.io.FileInputStream;
34import java.io.FileNotFoundException;
35import java.io.FileOutputStream;
36import java.util.List;
37import java.util.Map;
38
39import javax.swing.JRadioButton;
40
41import com.hp.hpl.jena.rdf.model.RDFNode;
42import javax.swing.JMenu;
43import javax.swing.JMenuItem;
44import javax.swing.JScrollPane;
45import javax.swing.JTextArea;
46import javax.swing.event.DocumentEvent;
47import javax.swing.event.DocumentListener;
48import javax.swing.text.BadLocationException;
49import javax.swing.text.Document;
50import javax.swing.text.Element;
51
52public class SparqlAccessorForm extends JFrame {
53
54        private static final long serialVersionUID = 1L;
55        private JPanel headerPanel = null;
56        private JPanel endpointPanel = null;  //  @jve:decl-index=0:visual-constraint="301,8"
57        private JComboBox endpointComboBox = null;
58        private JTabbedPane searchTypeTabbedPane = null;
59        private JPanel crossKeywordSearchPanel = null;
60        private JPanel keywordSearchPanel = null;
61        private JPanel sparqlSearchPanel = null;
62        private JPanel repositoryEditPanel = null;
63        private JButton addEndpointButton = null;
64        private JPanel footerPanel = null;  //  @jve:decl-index=0:visual-constraint="396,293"
65        private JButton saveButton = null;  //  @jve:decl-index=0:visual-constraint="630,305"
66
67        private JPanel radioPanel = null;
68        private JRadioButton tsvRadioButton = null;
69        private JRadioButton csvRadioButton = null;
70        private JRadioButton xlsxRadioButton = null;
71
72        private List<Map<String, RDFNode>> results;
73        private JMenuBar mainMenuBar = null;
74        private JMenu fileMenu = null;
75        private JMenu optionMenu = null;
76        private JMenuItem exitFileMenuItem = null;
77        private JMenuItem optionMenuItem = null;
78        private JMenuItem saveSettingFileMenuItem = null;
79        private JMenuItem compareMenuItem = null;
80        private JMenuItem compareSubjectMenuItem = null;
81
82        private String settingFile = "settings.xml";
83        private JSplitPane mainPanel = null;
84        private JPanel sparqlLogPanel = null;
85        private JScrollPane sparqlLogScrollPane = null;
86        private JTextArea sparqlLogTextArea = null;
87        private JMenu helpMenu = null;
88        private JMenuItem menuVersionItem = null;
89
90
91        /**
92         * This is the default constructor
93         */
94        public SparqlAccessorForm() {
95                super();
96                loadSetting();
97                initialize();
98        }
99
100        /**
101         * This method initializes this
102         *
103         * @return void
104         */
105        private void initialize() {
106//              this.setSize(370, 251);
107        this.setJMenuBar(getMainMenuBar());
108        this.addWindowListener(new WindowAdapter() {
109                @Override
110                public void windowClosing(WindowEvent e) {
111                        if (EndpointSettingsManager.instance.isChanged()){
112                                int option = JOptionPane.showConfirmDialog(getContentPane(), "繧ィ繝ウ繝峨�繧、繝ウ繝郁ィュ螳壹′螟画峩縺輔l縺ヲ縺�∪縺吶€ゆソ晏ュ倥@縺セ縺吶°��, "", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
113                                if (option == JOptionPane.YES_OPTION){
114                                        saveSetting(false);
115                                }
116                        }
117                }
118        });
119        Container compo = this.getContentPane();
120                compo.setLayout(new BorderLayout());
121                compo.add(getHeaderPanel(), BorderLayout.NORTH);
122                compo.add(getFooterPanel(), BorderLayout.SOUTH);
123                compo.add(getMainPanel(), BorderLayout.CENTER);
124        }
125
126        /**
127         * This method initializes headerPanel
128         *
129         * @return javax.swing.JPanel
130         */
131        private JPanel getHeaderPanel() {
132                if (headerPanel == null) {
133                        headerPanel = new JPanel();
134                        headerPanel.setLayout(new BorderLayout());
135                        headerPanel.add(getEndpointPanel(),  BorderLayout.NORTH);
136
137                }
138                return headerPanel;
139        }
140
141        /**
142         * This method initializes endpointPanel
143         *
144         * @return javax.swing.JPanel
145         */
146        private JPanel getEndpointPanel() {
147                if (endpointPanel == null) {
148                        endpointPanel = new JPanel();
149                        endpointPanel.setLayout(new BorderLayout());
150                        endpointPanel.add(getEndpointComboBox(), BorderLayout.CENTER);
151                        endpointPanel.add(getAddEndpointButton(), BorderLayout.EAST);
152                }
153                return endpointPanel;
154        }
155
156        /**
157         * This method initializes endpointComboBox
158         *
159         * @return javax.swing.JComboBox
160         */
161        private JComboBox getEndpointComboBox() {
162                if (endpointComboBox == null) {
163//                      String[] endpoints = {"http://ja.dbpedia.org/sparql", "http://dbpedia.org/sparql", "http://www.wikipediaontology.org/query/", "http://hozoviewer.ei.sanken.osaka-u.ac.jp/endpoint/dbpedia", "http://lod.ac/species/sparql", "http://lod.ac/sparql"};
164                        String[] endpoints = { "http://hozoviewer.ei.sanken.osaka-u.ac.jp/endpoint/dbpedia", "http://lod.ac/species/sparql", "http://lod.ac/sparql"};
165                        for (String ep : endpoints){
166                                EndpointSettingsManager.instance.getSetting(ep);
167                        }
168                        endpointComboBox = new JComboBox(endpoints);
169                        endpointComboBox.setEditable(true);
170                        endpointComboBox.addActionListener(new ActionListener() {
171
172                                @Override
173                                public void actionPerformed(ActionEvent arg0) {
174                                        setEditable();
175                                }
176                        });
177                }
178                return endpointComboBox;
179        }
180
181        public String getCurrentEndPoint(){
182                return (String)getEndpointComboBox().getSelectedItem();
183        }
184
185        /**
186         * This method initializes searchTypeTabbedPane
187         *
188         * @return javax.swing.JTabbedPane
189         */
190        private JTabbedPane getSearchTypeTabbedPane() {
191                if (searchTypeTabbedPane == null) {
192                        searchTypeTabbedPane = new JTabbedPane();
193                        searchTypeTabbedPane.addTab("Keyword Search", null, getKeywordSearchPanel(), null);
194                        searchTypeTabbedPane.addTab("Cross Search", null, getCrossKeywordSearchPanel(), null);
195                        searchTypeTabbedPane.addTab("SPARQL", null, getSparqlSearchPanel(), null);
196                        //searchTypeTabbedPane.addTab("SPARQL Builder", null, getSparqlBuilderPanel(), null);
197                        searchTypeTabbedPane.addTab("Edit", null, getRepositoryEditPanel(), null);
198                }
199                return searchTypeTabbedPane;
200        }
201
202        private void setEditable(){
203                EndpointSettings setting = EndpointSettingsManager.instance.getSetting(this.getCurrentEndPoint());
204
205                getSearchTypeTabbedPane().setEnabledAt(getSearchTypeTabbedPane().indexOfComponent(getRepositoryEditPanel()), setting.isEditable());
206        }
207
208        /**
209         * This method initializes keywordSearchPanel
210         *
211         * @return javax.swing.JPanel
212         */
213        private JPanel getKeywordSearchPanel() {
214                if (keywordSearchPanel == null) {
215                        keywordSearchPanel = new KeywordSearchPanel(this);
216                }
217                return keywordSearchPanel;
218        }
219
220        /**
221         * This method initializes crossKeywordSearchPanel
222         *
223         * @return javax.swing.JPanel
224         */
225        private JPanel getCrossKeywordSearchPanel() {
226                if (crossKeywordSearchPanel == null) {
227                        crossKeywordSearchPanel = new CrossKeywordSearchPanel(this);
228                }
229                return crossKeywordSearchPanel;
230        }
231
232        /**
233         * This method initializes sparqlSearchPanel
234         *
235         * @return javax.swing.JPanel
236         */
237        private JPanel getSparqlSearchPanel() {
238                if (sparqlSearchPanel == null) {
239                        sparqlSearchPanel = new SparqlSearchPanel(this);
240                }
241                return sparqlSearchPanel;
242        }
243       
244//      private JPanel getSparqlBuilderPanel(){
245//              return new SparqlBuilderPanel(this);
246//      }
247       
248        private JPanel getRepositoryEditPanel(){
249                if (repositoryEditPanel == null){
250                        repositoryEditPanel = new RepositoryKeywordSearchEditPanel(this);
251                }
252                return repositoryEditPanel;
253        }
254
255        /**
256         * This method initializes addEndpointButton
257         *
258         * @return javax.swing.JButton
259         */
260        private JButton getAddEndpointButton() {
261                if (addEndpointButton == null) {
262                        addEndpointButton = new JButton("New");
263                        addEndpointButton.addActionListener(new ActionListener() {
264
265                                @Override
266                                public void actionPerformed(ActionEvent e) {
267                                        boolean contains = false;
268                                        for (int i=0; i<getEndpointComboBox().getItemCount(); i++){
269                                                Object item = getEndpointComboBox().getItemAt(i);
270                                                if (item.equals(getCurrentEndPoint())){
271                                                        contains = true;
272                                                        break;
273                                                }
274                                        }
275                                        if (!contains){
276                                                EndpointSettingsManager.instance.getSetting(getCurrentEndPoint());
277                                                getEndpointComboBox().addItem(getCurrentEndPoint());
278                                        }
279                                }
280                        });
281                }
282                return addEndpointButton;
283        }
284
285        /**
286         * This method initializes footerPanel
287         *
288         * @return javax.swing.JPanel
289         */
290        private JPanel getFooterPanel() {
291                if (footerPanel == null) {
292                        footerPanel = new JPanel();
293                        footerPanel.setLayout(new BorderLayout());
294                        footerPanel.add(getSaveButton(), BorderLayout.EAST);
295                        footerPanel.add(getRadioPanel(), BorderLayout.CENTER);
296                }
297                return footerPanel;
298        }
299
300        /**
301         * This method initializes saveButton
302         *
303         * @return javax.swing.JButton
304         */
305        private JButton getSaveButton() {
306                if (saveButton == null) {
307                        saveButton = new JButton("Save Result");
308                        saveButton.addActionListener(new ActionListener() {
309
310                                @Override
311                                public void actionPerformed(ActionEvent arg0) {
312                                        save();
313                                }
314                        });
315                        saveButton.setEnabled(false);
316                }
317                return saveButton;
318        }
319
320        private int saveSetting(boolean needConfirm){
321                // 蜃コ蜉帛�豎コ螳�
322
323                // 遒コ隱阪ム繧、繧「繝ュ繧ー
324                if (needConfirm){
325                        int option = JOptionPane.showConfirmDialog(getContentPane(), "繧ィ繝ウ繝峨�繧、繝ウ繝郁ィュ螳壹r菫晏ュ倥@縺セ縺�, "", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
326                        if (option != JOptionPane.YES_OPTION){
327                                return JFileChooser.ABORT;
328                        }
329                }
330
331
332                File file = new File(settingFile);
333                try {
334                        EndpointSettings.outputXML(new FileOutputStream(file), EndpointSettingsManager.instance.getSettings());
335                        EndpointSettingsManager.instance.resetChanged();
336                } catch (FileNotFoundException e) {
337                        e.printStackTrace();
338                        return JFileChooser.ERROR;
339                }
340                return 0;
341
342                /*
343                // 繝輔ぃ繧、繝ォ驕ク謚槭ム繧、繧「繝ュ繧ー繧貞他縺ウ蜃コ縺�
344                JFileChooser fileChooser = new JFileChooser();
345                fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
346
347                // 繝輔ぃ繧、繝ォ驕ク謚樒オ先棡蜿門セ�
348                int result = fileChooser.showOpenDialog(this);
349                File file = fileChooser.getSelectedFile();
350                if (result == JFileChooser.CANCEL_OPTION || file == null) {
351                        // 繧ュ繝」繝ウ繧サ繝ォ謚シ荳九€√∪縺溘�縲√ヵ繧。繧、繝ォ驕ク謚槭↑縺励�縺溘a菴輔b縺励↑縺�
352                        return JFileChooser.ABORT;
353                }
354
355                try {
356                        EndpointSettings.outputXML(new FileOutputStream(file), EndpointSettingsManager.instance.getSettings());
357                        return 0;
358                } catch (FileNotFoundException e) {
359                        e.printStackTrace();
360                        return JFileChooser.ERROR;
361                }
362                */
363
364        }
365
366        private int loadSetting(){
367                File file = new File(settingFile);
368                try {
369                        EndpointSettings[] settings = EndpointSettings.inputXML(new FileInputStream(file));
370                        if (settings != null){
371                                EndpointSettingsManager.instance.setSettings(settings);
372                                EndpointSettingsManager.instance.resetChanged();
373
374                                for (EndpointSettings setting : settings){
375                                        DefaultComboBoxModel model = (DefaultComboBoxModel)getEndpointComboBox().getModel();
376                                        boolean exists = false;
377                                        for (int i=0; i<model.getSize(); i++){
378                                                String ep = (String)model.getElementAt(i);
379                                                if (setting.getEndpoint().equals(ep)){
380                                                        exists = true;
381                                                        break;
382                                                }
383                                        }
384                                        if (!exists){
385                                                model.addElement(setting.getEndpoint());
386                                        }
387                                }
388
389                                return 0;
390                        }
391                } catch (FileNotFoundException e) {
392                        saveSetting(false);
393                        e.printStackTrace();
394                        return JFileChooser.ERROR;
395                } finally {
396                        setEditable();
397                }
398                return JFileChooser.ERROR;
399
400                /*
401                // 繝輔ぃ繧、繝ォ驕ク謚槭ム繧、繧「繝ュ繧ー繧貞他縺ウ蜃コ縺�
402                JFileChooser fileChooser = new JFileChooser();
403                fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
404
405                // 繝輔ぃ繧、繝ォ驕ク謚樒オ先棡蜿門セ�
406                int result = fileChooser.showOpenDialog(this);
407                File file = fileChooser.getSelectedFile();
408                if (result == JFileChooser.CANCEL_OPTION || file == null) {
409                        // 繧ュ繝」繝ウ繧サ繝ォ謚シ荳九€√∪縺溘�縲√ヵ繧。繧、繝ォ驕ク謚槭↑縺励�縺溘a菴輔b縺励↑縺�
410                        return JFileChooser.ABORT;
411                }
412
413                try {
414                        EndpointSettings[] settings = EndpointSettings.inputXML(new FileInputStream(file));
415                        if (settings != null){
416                                EndpointSettingsManager.instance.setSettings(settings);
417                                return 0;
418                        }
419                } catch (FileNotFoundException e) {
420                        e.printStackTrace();
421                        return JFileChooser.ERROR;
422                }
423                return JFileChooser.ERROR;
424                */
425
426        }
427
428
429        private void save(){
430                // 蜃コ蜉帛�豎コ螳�
431                // 繝輔ぃ繧、繝ォ驕ク謚槭ム繧、繧「繝ュ繧ー繧貞他縺ウ蜃コ縺�
432                JFileChooser fileChooser = new JFileChooser();
433                fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
434
435                // 繝輔ぃ繧、繝ォ驕ク謚樒オ先棡蜿門セ�
436                int result = fileChooser.showOpenDialog(this);
437                File file = fileChooser.getSelectedFile();
438                if (result == JFileChooser.CANCEL_OPTION || file == null) {
439                        // 繧ュ繝」繝ウ繧サ繝ォ謚シ荳九€√∪縺溘�縲√ヵ繧。繧、繝ォ驕ク謚槭↑縺励�縺溘a菴輔b縺励↑縺�
440                        return;
441                }
442
443                try {
444                        SparqlUtil.saveResult(results, getSaveType(), file);
445                } catch(Exception e){
446                        e.printStackTrace();
447                }
448        }
449
450        private int getSaveType(){
451                if (getTsvRadioButton().isSelected()){
452                        return SparqlUtil.OUTPUT_TYPE_TSV;
453                }
454                if (getCsvRadioButton().isSelected()){
455                        return SparqlUtil.OUTPUT_TYPE_CSV;
456                }
457                if (getXlsxRadioButton().isSelected()){
458                        return SparqlUtil.OUTPUT_TYPE_XLS;
459                }
460
461                // 縺薙%縺ォ縺上k縺薙→縺ッ縺ェ縺�
462                return SparqlUtil.OUTPUT_TYPE_TSV;
463        }
464
465        void setProcessing(boolean isProcessing){
466                getEndpointComboBox().setEnabled(!isProcessing);
467                getAddEndpointButton().setEnabled(!isProcessing);
468                getSearchTypeTabbedPane().setEnabled(!isProcessing);
469                getSaveButton().setEnabled(false);
470        }
471
472        void setResults(SparqlResultSet set){
473                List<Map<String, RDFNode>> results = set.getDefaultResult();
474                boolean saveable = false;
475                if (results != null && results.size() > 0){
476                        saveable = true;
477                }
478                getSaveButton().setEnabled(saveable);
479
480                this.results = results;
481
482        }
483
484        /**
485         * This method initializes radioPanel
486         *
487         * @return javax.swing.JPanel
488         */
489        private JPanel getRadioPanel() {
490                if (radioPanel == null) {
491                        radioPanel = new JPanel();
492                        radioPanel.setLayout(new FlowLayout());
493                        radioPanel.add(getTsvRadioButton(), null);
494                        radioPanel.add(getCsvRadioButton(), null);
495                        radioPanel.add(getXlsxRadioButton(), null);
496                        ButtonGroup bg = new ButtonGroup();
497                        bg.add(getTsvRadioButton());
498                        bg.add(getCsvRadioButton());
499                        bg.add(getXlsxRadioButton());
500                        getTsvRadioButton().setSelected(true);
501                }
502                return radioPanel;
503        }
504
505        /**
506         * This method initializes tsvRadioButton
507         *
508         * @return javax.swing.JRadioButton
509         */
510        private JRadioButton getTsvRadioButton() {
511                if (tsvRadioButton == null) {
512                        tsvRadioButton = new JRadioButton("TSV");
513                }
514                return tsvRadioButton;
515        }
516
517        /**
518         * This method initializes csvRadioButton
519         *
520         * @return javax.swing.JRadioButton
521         */
522        private JRadioButton getCsvRadioButton() {
523                if (csvRadioButton == null) {
524                        csvRadioButton = new JRadioButton("CSV");
525                }
526                return csvRadioButton;
527        }
528
529        /**
530         * This method initializes xlsxRadioButton
531         *
532         * @return javax.swing.JRadioButton
533         */
534        private JRadioButton getXlsxRadioButton() {
535                if (xlsxRadioButton == null) {
536                        xlsxRadioButton = new JRadioButton("XLSX");
537                        xlsxRadioButton.setEnabled(false);
538                }
539                return xlsxRadioButton;
540        }
541
542        /**
543         * This method initializes mainMenuBar
544         *
545         * @return javax.swing.JMenuBar
546         */
547        private JMenuBar getMainMenuBar() {
548                if (mainMenuBar == null) {
549                        mainMenuBar = new JMenuBar();
550                        mainMenuBar.add(getFileMenu());
551                        mainMenuBar.add(getOptionMenu());
552                        mainMenuBar.add(getHelpMenu());
553                }
554                return mainMenuBar;
555        }
556
557        /**
558         * This method initializes fileMenu
559         *
560         * @return javax.swing.JMenu
561         */
562        private JMenu getFileMenu() {
563                if (fileMenu == null) {
564                        fileMenu = new JMenu("File");
565                        fileMenu.add(getSaveSettingFileMenuItem());
566//                      fileMenu.add(getLoadSettingMenuItem());
567                        fileMenu.add(getExitFileMenuItem());
568                }
569                return fileMenu;
570        }
571
572        /**
573         * This method initializes optionMenu
574         *
575         * @return javax.swing.JMenu
576         */
577        private JMenu getOptionMenu() {
578                if (optionMenu == null) {
579                        optionMenu = new JMenu("Option");
580                        optionMenu.add(getOptionMenuItem());
581
582                        // Java縺ッplugin蛹悶☆繧九�縺碁擇蛟偵↑縺ョ縺ァ縺薙%縺ォ繝吶ち縺ァ譖ク縺�
583                        optionMenu.add(getCompareMenuItem());
584                        optionMenu.add(getCompareSubjectMenuItem());
585                }
586                return optionMenu;
587        }
588
589        /**
590         * This method initializes exitFileMenuItem
591         *
592         * @return javax.swing.JMenuItem
593         */
594        private JMenuItem getExitFileMenuItem() {
595                if (exitFileMenuItem == null) {
596                        exitFileMenuItem = new JMenuItem("Exit");
597                        exitFileMenuItem.addActionListener(new ActionListener() {
598
599                                @Override
600                                public void actionPerformed(ActionEvent arg0) {
601                                        int option = JOptionPane.showConfirmDialog(getContentPane(), "邨ゆコ�@縺セ縺吶°��, "", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
602                                        if (option == JOptionPane.YES_OPTION){
603                                                System.exit(0);
604                                        }
605
606                                }
607                        });
608                }
609                return exitFileMenuItem;
610        }
611
612        private JMenuItem getCompareMenuItem() {
613                if (compareMenuItem == null) {
614                        compareMenuItem = new JMenuItem("Compare");
615                        compareMenuItem.addActionListener(new ActionListener() {
616                                public void actionPerformed(ActionEvent arg0) {
617//                                      openSettingDialog();
618                                        JFrame frame = new JFrame();
619                                        frame.setContentPane(new ComparePanel(frame));
620                                        frame.setSize(750, 500);
621
622                                        frame.setVisible(true);
623                                }
624                        });
625                }
626                return compareMenuItem;
627        }
628
629        private JMenuItem getCompareSubjectMenuItem() {
630                if (compareSubjectMenuItem == null) {
631                        compareSubjectMenuItem = new JMenuItem("Compare Subjects");
632                        compareSubjectMenuItem.addActionListener(new ActionListener() {
633                                public void actionPerformed(ActionEvent arg0) {
634//                                      openSettingDialog();
635                                        JFrame frame = new JFrame();
636                                        frame.setContentPane(new CompareSubjectPanel(frame));
637                                        frame.setSize(750, 500);
638
639                                        frame.setVisible(true);
640                                }
641                        });
642                }
643                return compareSubjectMenuItem;
644        }
645
646
647        /**
648         * This method initializes optionMenuItem
649         *
650         * @return javax.swing.JMenuItem
651         */
652        private JMenuItem getOptionMenuItem() {
653                if (optionMenuItem == null) {
654                        optionMenuItem = new JMenuItem("Option Setting");
655                        optionMenuItem.addActionListener(new ActionListener() {
656                                public void actionPerformed(ActionEvent arg0) {
657                                        openSettingDialog();
658                                }
659                        });
660                }
661                return optionMenuItem;
662        }
663
664        private void openSettingDialog(){
665                EndpointSettings setting = EndpointSettingsManager.instance.getSetting(this.getCurrentEndPoint());
666                OptionDialog od = new OptionDialog(this, setting);
667
668                od.setModal(true);
669                od.setVisible(true);
670                if (od.isOk()){
671                        setting.setUseCustomParam(od.isUseCustom());
672                        setting.setQueryKey(od.getQueryKey());
673                        setting.setOption(od.getOption());
674                        setting.setNamespaces(od.getNamespaces());
675                        setting.setEncoding(od.getEndoding());
676                        setting.setResultType(od.getResultType());
677
678                        setting.setEditable(od.isEditable());
679                        setting.setRepositoryURL(od.getRepositoryURL());
680                        setting.setRepository(od.getRepository());
681                        setting.setUser(od.getUser());
682                        setting.setPass(od.getPassword());
683
684                        setEditable();
685                }
686        }
687
688        /**
689         * This method initializes saveSettingFileMenuItem
690         *
691         * @return javax.swing.JMenuItem
692         */
693        private JMenuItem getSaveSettingFileMenuItem() {
694                if (saveSettingFileMenuItem == null) {
695                        saveSettingFileMenuItem = new JMenuItem("Save Settings");
696                        saveSettingFileMenuItem.addActionListener(new ActionListener() {
697
698                                @Override
699                                public void actionPerformed(ActionEvent arg0) {
700                                        int ret = saveSetting(true);
701                                        if (ret == JFileChooser.ABORT){
702                                                // 荳ュ譁ュ
703                                        } else if (ret == JFileChooser.ERROR){
704                                                // 繧ィ繝ゥ繝シ
705                                        } else {
706                                                // 謌仙粥
707                                        }
708                                }
709                        });
710                }
711                return saveSettingFileMenuItem;
712        }
713
714        /**
715         * This method initializes loadSettingMenuItem
716         *
717         * @return javax.swing.JMenuItem
718         *//*
719        private JMenuItem getLoadSettingMenuItem() {
720                if (loadSettingMenuItem == null) {
721                        loadSettingMenuItem = new JMenuItem("Load Settings");
722                        loadSettingMenuItem.addActionListener(new ActionListener() {
723
724                                @Override
725                                public void actionPerformed(ActionEvent e) {
726                                        int ret = loadSetting();
727                                        if (ret == JFileChooser.ABORT){
728                                                // 荳ュ譁ュ
729                                        } else if (ret == JFileChooser.ERROR){
730                                                // 繧ィ繝ゥ繝シ
731                                        } else {
732                                                // 謌仙粥
733                                        }
734                                }
735                        });
736                }
737                return loadSettingMenuItem;
738        }*/
739
740        /**
741         * This method initializes mainPanel
742         *
743         * @return javax.swing.JPanel
744         */
745        private JSplitPane getMainPanel() {
746                if (mainPanel == null) {
747                        mainPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, getSearchTypeTabbedPane(), getSparqlLogPanel());
748                        mainPanel.setDividerLocation(400);
749                }
750                return mainPanel;
751        }
752
753        /**
754         * This method initializes sparqlLogPanel
755         *
756         * @return javax.swing.JPanel
757         */
758        private JPanel getSparqlLogPanel() {
759                if (sparqlLogPanel == null) {
760                        sparqlLogPanel = new JPanel();
761                        sparqlLogPanel.setLayout(new BorderLayout());
762                        sparqlLogPanel.add(getSparqlLogScrollPane(), BorderLayout.CENTER);
763                }
764                return sparqlLogPanel;
765        }
766
767        /**
768         * This method initializes sparqlLogScrollPane
769         *
770         * @return javax.swing.JScrollPane
771         */
772        private JScrollPane getSparqlLogScrollPane() {
773                if (sparqlLogScrollPane == null) {
774                        sparqlLogScrollPane = new JScrollPane(getSparqlLogTextArea(), JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
775                        sparqlLogScrollPane.setPreferredSize(new Dimension(200, 300));
776                }
777                return sparqlLogScrollPane;
778        }
779
780        /**
781         * This method initializes sparqlLogTextArea
782         *
783         * @return javax.swing.JTextArea
784         */
785        private JTextArea getSparqlLogTextArea() {
786                if (sparqlLogTextArea == null) {
787                        sparqlLogTextArea = new JTextArea();
788                        sparqlLogTextArea.setEditable(false);
789                        sparqlLogTextArea.getDocument().addDocumentListener(new DocumentListener() {
790
791                                @Override
792                                public void removeUpdate(DocumentEvent arg0) {
793                                }
794
795                                @Override
796                                public void changedUpdate(DocumentEvent arg0) {
797                                }
798                                @Override
799                                public void insertUpdate(DocumentEvent e) {
800                                        final Document doc = sparqlLogTextArea.getDocument();
801                                        final Element root = doc.getDefaultRootElement();
802                                        if(root.getElementCount() <= 100){ // TODO 100縺ッ繝吶ち譖ク縺�
803                                                return;
804                                        }
805                                        EventQueue.invokeLater(new Runnable() {
806                                                @Override
807                                                public void run() {
808                                                        removeLines(doc, root);
809                                                }
810                                        });
811                                        sparqlLogTextArea.setCaretPosition(doc.getLength());
812                                }
813                                private void removeLines(Document doc, Element root) {
814                                        Element fl = root.getElement(0);
815                                        try{
816                                                doc.remove(0, fl.getEndOffset());
817                                        }catch(BadLocationException ble) {
818                                                System.out.println(ble);
819                                        }
820                                }
821                        });
822                }
823                return sparqlLogTextArea;
824        }
825
826        void addLogText(String log){
827                String[] logs = log.split("\n");
828                for (String l : logs){
829                        sparqlLogTextArea.append((sparqlLogTextArea.getDocument().getLength() > 0) ? "\n" + l : l);
830                }
831                sparqlLogTextArea.setCaretPosition(sparqlLogTextArea.getDocument().getLength());
832        }
833
834        /**
835         * This method initializes helpMenu
836         *
837         * @return javax.swing.JMenu
838         */
839        private JMenu getHelpMenu() {
840                if (helpMenu == null) {
841                        helpMenu = new JMenu("Help");
842                        helpMenu.add(getMenuVersionItem());
843                }
844                return helpMenu;
845        }
846
847        /**
848         * This method initializes menuVersionItem
849         *
850         * @return javax.swing.JMenuItem
851         */
852        private JMenuItem getMenuVersionItem() {
853                if (menuVersionItem == null) {
854                        menuVersionItem = new JMenuItem("Version");
855                        menuVersionItem.addActionListener(new ActionListener() {
856
857                                @Override
858                                public void actionPerformed(ActionEvent e) {
859                                        awakeVersionDialog();
860                                }
861                        });
862                }
863                return menuVersionItem;
864        }
865
866        private void awakeVersionDialog(){
867                // TODO
868                VersionDialog vd = new VersionDialog(this);
869
870                vd.setVisible(true);
871        }
872
873        public static void main(String args[]){
874                JFrame frame = new SparqlAccessorForm();
875                frame.setSize(900, 800);
876                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
877                frame.setVisible(true);
878        }
879}  //  @jve:decl-index=0:visual-constraint="10,10"
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。