001/* 002 * Copyright (c) 2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: aschultz $' 006 * '$Date: 2010-12-23 19:01:04 +0000 (Thu, 23 Dec 2010) $' 007 * '$Revision: 26600 $' 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 030/** 031 * 032 */ 033package org.kepler.gui.component; 034 035import java.awt.BorderLayout; 036import java.awt.Dimension; 037import java.awt.GridLayout; 038import java.awt.event.ActionEvent; 039import java.awt.event.ActionListener; 040 041import javax.swing.JButton; 042import javax.swing.JCheckBox; 043import javax.swing.JFrame; 044import javax.swing.JPanel; 045 046import org.kepler.objectmanager.library.LibSearch; 047import org.kepler.objectmanager.library.LibSearchConfiguration; 048import org.kepler.util.StaticResources; 049 050/** 051 * @author Aaron Schultz 052 * 053 */ 054public class SearchConfigurationFrame extends JFrame implements ActionListener { 055 056 private JPanel _cbPane; 057 private JCheckBox cbName; 058 private JCheckBox cbClassName; 059 private JCheckBox cbOntName; 060 private JCheckBox cbOntClassName; 061 private JCheckBox cbFolderName; 062 private JCheckBox cbKarName; 063 private JCheckBox cbLocalRepo; 064 065 private JPanel _controls; 066 private JButton _okButton; 067 private JButton _cancelButton; 068 069 private LibSearchConfiguration _LibSearchConfig; 070 071 /** 072 * Constructor accepts a title for the frame. 073 * 074 * @param title 075 * the title to appear at the top of the frame 076 */ 077 public SearchConfigurationFrame(String title) { 078 super(title); 079 080 setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 081 setSize(new Dimension(350, 350)); 082 083 _LibSearchConfig = new LibSearchConfiguration(); 084 085 JPanel layoutPanel = new JPanel(); 086 layoutPanel.setLayout(new BorderLayout()); 087 088 _cbPane = new JPanel(new GridLayout(8,1)); 089 initCheckBoxes(); 090 layoutPanel.add(_cbPane, BorderLayout.CENTER); 091 092 _controls = new JPanel(); 093 initControls(); 094 layoutPanel.add(_controls, BorderLayout.SOUTH); 095 096 getContentPane().add(layoutPanel); 097 } 098 099 protected void initCheckBoxes() { 100 101 // Name check box 102 cbName = new JCheckBox( 103 StaticResources.getDisplayString( 104 "components.search.configuration.options.componentName", 105 "Component Name")); 106 if (_LibSearchConfig.contains(LibSearch.TYPE_NAME)){ 107 cbName.setSelected(true); 108 } 109 _cbPane.add(cbName); 110 111 // Ontology Class Name Checkbox 112 cbOntClassName = new JCheckBox( 113 StaticResources.getDisplayString( 114 "components.search.configuration.options.ontologyClassName", 115 "Ontology Class Name")); 116 if (_LibSearchConfig.contains(LibSearch.TYPE_ONTCLASSNAME)){ 117 cbOntClassName.setSelected(true); 118 } 119 _cbPane.add(cbOntClassName); 120 121 // Ontology Name Checkbox 122 cbOntName = new JCheckBox( 123 StaticResources.getDisplayString( 124 "components.search.configuration.options.ontologyName", 125 "Ontology Name")); 126 if (_LibSearchConfig.contains(LibSearch.TYPE_ONTOLOGY)){ 127 cbOntName.setSelected(true); 128 } 129 _cbPane.add(cbOntName); 130 131 /* TODO add folder names to LibSearch 132 // Folder Name check box 133 cbFolderName = new JCheckBox("Folder Name"); 134 if (_LibSearchConfig.contains(LibSearch.TYPE_FOLDERNAME)){ 135 cbFolderName.setSelected(true); 136 } 137 _cbPane.add(cbFolderName); 138 */ 139 140 // Kar Name check box 141 cbKarName = new JCheckBox( 142 StaticResources.getDisplayString( 143 "components.search.configuration.options.karName", 144 "KAR Name")); 145 if (_LibSearchConfig.contains(LibSearch.TYPE_KARNAME)){ 146 cbKarName.setSelected(true); 147 } 148 _cbPane.add(cbKarName); 149 150 // Local Repo check box 151 cbLocalRepo = new JCheckBox( 152 StaticResources.getDisplayString( 153 "components.search.configuration.options.localRepositoryName", 154 "Local Repository Name")); 155 if (_LibSearchConfig.contains(LibSearch.TYPE_LOCALREPO)){ 156 cbLocalRepo.setSelected(true); 157 } 158 _cbPane.add(cbLocalRepo); 159 160 // TODO: get this working again 161 /* Class Name Checkbox 162 cbClassName = new JCheckBox("Component Java Class Name"); 163 if (_LibSearchConfig.contains(LibSearch.TYPE_CLASSNAME)){ 164 cbClassName.setSelected(true); 165 } 166 _cbPane.add(cbClassName); 167 */ 168 169 } 170 171 /** 172 * Initialize the control buttons. 173 */ 174 protected void initControls() { 175 176 _okButton = new JButton( 177 StaticResources.getDisplayString( 178 "general.OK", 179 "Ok")); 180 _okButton.addActionListener(this); 181 _controls.add(_okButton); 182 183 _cancelButton = new JButton( 184 StaticResources.getDisplayString( 185 "general.CANCEL", 186 "Cancel")); 187 _cancelButton.addActionListener(this); 188 _controls.add(_cancelButton); 189 } 190 191 public void dispose() { 192 193 super.dispose(); 194 } 195 196 /* 197 * (non-Javadoc) 198 * 199 * @see 200 * java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) 201 */ 202 public void actionPerformed(ActionEvent e) { 203 204 if (e.getSource() == _okButton) { 205 206 if (cbName.isSelected()) { 207 if (!_LibSearchConfig.contains(LibSearch.TYPE_NAME)){ 208 _LibSearchConfig.addSearchType(LibSearch.TYPE_NAME); 209 } 210 } else { 211 _LibSearchConfig.removeSearchType(LibSearch.TYPE_NAME); 212 } 213 214 /* TODO get this working again 215 if (cbClassName.isSelected()) { 216 if (!_LibSearchConfig.contains(LibSearch.TYPE_CLASSNAME)){ 217 _LibSearchConfig.addSearchType(LibSearch.TYPE_CLASSNAME); 218 } 219 } else { 220 _LibSearchConfig.removeSearchType(LibSearch.TYPE_CLASSNAME); 221 } 222 */ 223 224 if (cbOntClassName.isSelected()) { 225 if (!_LibSearchConfig.contains(LibSearch.TYPE_ONTCLASSNAME)){ 226 _LibSearchConfig.addSearchType(LibSearch.TYPE_ONTCLASSNAME); 227 } 228 } else { 229 _LibSearchConfig.removeSearchType(LibSearch.TYPE_ONTCLASSNAME); 230 } 231 232 if (cbOntName.isSelected()) { 233 if (!_LibSearchConfig.contains(LibSearch.TYPE_ONTOLOGY)){ 234 _LibSearchConfig.addSearchType(LibSearch.TYPE_ONTOLOGY); 235 } 236 } else { 237 _LibSearchConfig.removeSearchType(LibSearch.TYPE_ONTOLOGY); 238 } 239 240 /* TODO add folder search to LibSearch 241 if (cbFolderName.isSelected()) { 242 if (!_LibSearchConfig.contains(LibSearch.TYPE_FOLDERNAME)){ 243 _LibSearchConfig.addSearchType(LibSearch.TYPE_FOLDERNAME); 244 } 245 } else { 246 _LibSearchConfig.removeSearchType(LibSearch.TYPE_FOLDERNAME); 247 } 248 */ 249 250 if (cbKarName.isSelected()) { 251 if (!_LibSearchConfig.contains(LibSearch.TYPE_KARNAME)){ 252 _LibSearchConfig.addSearchType(LibSearch.TYPE_KARNAME); 253 } 254 } else { 255 _LibSearchConfig.removeSearchType(LibSearch.TYPE_KARNAME); 256 } 257 258 if (cbLocalRepo.isSelected()) { 259 if (!_LibSearchConfig.contains(LibSearch.TYPE_LOCALREPO)){ 260 _LibSearchConfig.addSearchType(LibSearch.TYPE_LOCALREPO); 261 } 262 } else { 263 _LibSearchConfig.removeSearchType(LibSearch.TYPE_LOCALREPO); 264 } 265 266 _LibSearchConfig.serializeToDisk(); 267 268 dispose(); 269 270 } else if (e.getSource() == _cancelButton) { 271 272 dispose(); 273 274 } 275 276 } 277}