001/* 002 * Copyright (c) 2004-2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: welker $' 006 * '$Date: 2010-05-06 05:21:26 +0000 (Thu, 06 May 2010) $' 007 * '$Revision: 24234 $' 008 * 009 * Permission is hereby granted, without written agreement and without 010 * license or royalty fees, to use, copy, modify, and distribute this 011 * software and its documentation for any purpose, provided that the above 012 * copyright notice and the following two paragraphs appear in all copies 013 * of this software. 014 * 015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 019 * SUCH DAMAGE. 020 * 021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 026 * ENHANCEMENTS, OR MODIFICATIONS. 027 * 028 */ 029 030package org.kepler.sms.gui; 031 032/** 033 * 034 */ 035 036import java.awt.Dimension; 037import java.awt.Frame; 038import java.awt.event.ActionEvent; 039import java.awt.event.ActionListener; 040import java.util.Vector; 041 042import javax.swing.BorderFactory; 043import javax.swing.Box; 044import javax.swing.BoxLayout; 045import javax.swing.JButton; 046import javax.swing.JDialog; 047import javax.swing.JLabel; 048import javax.swing.JList; 049import javax.swing.JPanel; 050import javax.swing.JScrollPane; 051import javax.swing.ListSelectionModel; 052import javax.swing.SwingConstants; 053 054import org.kepler.sms.NamedOntClass; 055 056public class OntoClassSearchDialog extends JDialog { 057 058 private NamedOntClass _namedClass = null; 059 private JList _choiceList = new JList(); 060 061 protected NamedOntClass getChoice() { 062 return _namedClass; 063 } 064 065 public static NamedOntClass showDialog(Frame aFrame, Vector choices) { 066 OntoClassSearchDialog d = new OntoClassSearchDialog(aFrame, choices); 067 return d.getChoice(); 068 } 069 070 protected OntoClassSearchDialog(Frame aFrame, Vector choices) { 071 super(aFrame, true); 072 setTitle("Search Results"); 073 074 JPanel pane = new JPanel(); 075 pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS)); 076 pane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); 077 078 // add the label 079 JPanel msgPanel = new JPanel(); 080 msgPanel.setLayout(new BoxLayout(msgPanel, BoxLayout.X_AXIS)); 081 msgPanel 082 .add(new JLabel("Select a matching class:", SwingConstants.LEFT)); 083 msgPanel.add(Box.createHorizontalGlue()); 084 pane.add(msgPanel); 085 086 // add the choice list 087 JScrollPane choiceView = new JScrollPane(_choiceList); 088 _choiceList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 089 _choiceList.setListData(choices); 090 _choiceList.setSelectedIndex(0); 091 choiceView.setMinimumSize(new Dimension(250, 200)); 092 choiceView.setMaximumSize(new Dimension(Short.MAX_VALUE, 200)); 093 choiceView.setPreferredSize(new Dimension(250, 200)); 094 pane.add(choiceView); 095 096 // add space between namespace and property 097 pane.add(Box.createRigidArea(new Dimension(0, 5))); 098 099 // add the button pane 100 101 JPanel btnPanel = new JPanel(); 102 btnPanel.setLayout(new BoxLayout(btnPanel, BoxLayout.X_AXIS)); 103 JButton okBtn = new JButton("OK"); 104 JButton cancelBtn = new JButton("Cancel"); 105 btnPanel.add(okBtn); 106 btnPanel.add(Box.createRigidArea(new Dimension(15, 0))); 107 btnPanel.add(cancelBtn); 108 pane.add(btnPanel); 109 110 // add listeners to the buttons 111 okBtn.addActionListener(new ActionListener() { 112 public void actionPerformed(ActionEvent ev) { 113 _namedClass = (NamedOntClass) _choiceList.getSelectedValue(); 114 // exit the window 115 dispose(); 116 } 117 }); 118 119 cancelBtn.addActionListener(new ActionListener() { 120 public void actionPerformed(ActionEvent ev) { 121 _namedClass = null; 122 // exit the window 123 dispose(); 124 } 125 }); 126 127 // set up the dialog 128 this.setContentPane(pane); 129 this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); 130 131 this.pack(); 132 this.show(); 133 } 134}