1 17 package org.apache.ldap.server.db.gui ; 18 19 20 import javax.swing.*; 21 import javax.swing.border.TitledBorder ; 22 import java.awt.*; 23 import java.awt.event.ActionListener ; 24 import java.awt.event.WindowAdapter ; 25 import java.awt.event.WindowEvent ; 26 27 28 34 public class FilterDialog extends JDialog 35 { 36 private static final long serialVersionUID = 3760565295319626294L; 37 38 public static final String RUN_MODE = "Run" ; 39 public static final String LOAD_MODE = "Load" ; 40 public static final String DEBUG_MODE = "Debug" ; 41 public static final String ANNOTATE_MODE = "Annotate" ; 42 43 public static final String UNLIMITED = "Unlimited" ; 44 45 public static final String BASE_SCOPE = "Base Object" ; 46 public static final String SINGLE_SCOPE = "Single Level" ; 47 public static final String SUBTREE_SCOPE = "Subtree Level" ; 48 49 public static final String LOAD_CMD = "Load" ; 50 public static final String SEARCH_CMD = "Search" ; 51 public static final String CANCEL_CMD = "Cancel" ; 52 53 private JPanel m_northPnl = new JPanel() ; 54 private JPanel m_centerPnl = new JPanel() ; 55 private JTextArea m_filterText = new JTextArea() ; 56 private JLabel m_scopeLbl = new JLabel() ; 57 private JComboBox m_scopeChoice = new JComboBox() ; 58 private JLabel m_limitLbl = new JLabel() ; 59 private JTextField m_limitField = new JTextField() ; 60 private JPanel m_southPnl = new JPanel() ; 61 private JButton m_searchBut = new JButton() ; 62 private JButton m_cancelBut = new JButton() ; 63 private JScrollPane m_scrollPane = new JScrollPane() ; 64 private final String m_mode ; 65 private JTextField m_baseText = new JTextField(); 66 private JPanel m_basePnl = new JPanel(); 67 private JLabel jLabel1 = new JLabel(); 68 69 70 public FilterDialog(String a_mode, JFrame parent, boolean modal) 71 { 72 super(parent, modal) ; 73 m_mode = a_mode ; 74 initGUI() ; 75 } 76 77 78 public void addActionListener(ActionListener l_listener) 79 { 80 m_searchBut.addActionListener(l_listener) ; 81 m_cancelBut.addActionListener(l_listener) ; 82 } 83 84 85 86 89 private void initGUI() { 90 m_baseText.setText(""); 91 addWindowListener( 92 new WindowAdapter () { 93 public void windowClosing(WindowEvent evt) { 94 closeDialog(evt); 95 } 96 }) ; 97 pack() ; 98 99 getContentPane().setLayout(new java.awt.GridBagLayout ()) ; 100 getContentPane().add(m_northPnl, 101 new java.awt.GridBagConstraints (0, 0, 1, 1, 0.9, 0.0, java.awt.GridBagConstraints.NORTH, java.awt.GridBagConstraints.BOTH, 102 new java.awt.Insets (5, 5, 6, 0), 0, 0)); 103 getContentPane().add(m_centerPnl, 104 new GridBagConstraints(0, 1, 1, 1, 0.9, 0.9, 105 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 106 new Insets(10, 10, 10, 10), 0, 0)); 107 getContentPane().add(m_southPnl, 108 new GridBagConstraints(0, 2, 1, 1, 1.0, 0.0, 109 GridBagConstraints.SOUTH, GridBagConstraints.BOTH, 110 new Insets(0, 0, 2, 0), 0, 0)) ; 111 m_northPnl.setLayout(new GridBagLayout()) ; 112 m_northPnl.setBorder(null) ; 113 m_northPnl.add(m_scopeLbl, 114 new java.awt.GridBagConstraints (0, 0, 1, 1, 0.2, 0.0, java.awt.GridBagConstraints.CENTER, java.awt.GridBagConstraints.NONE, 115 new java.awt.Insets (5, 0, 5, 0), 0, 0)); 116 m_northPnl.add(m_scopeChoice, 117 new java.awt.GridBagConstraints (1, 0, 1, 1, 1.0, 0.0, java.awt.GridBagConstraints.CENTER, java.awt.GridBagConstraints.HORIZONTAL, 118 new java.awt.Insets (9, 0, 7, 5), 0, 0)); 119 m_northPnl.add(m_limitLbl, 120 new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, 121 GridBagConstraints.CENTER, GridBagConstraints.NONE, 122 new Insets(5, 10, 5, 5), 0, 0)) ; 123 m_northPnl.add(m_limitField, 124 new java.awt.GridBagConstraints (3, 0, 1, 1, 1.0, 0.0, java.awt.GridBagConstraints.CENTER, java.awt.GridBagConstraints.HORIZONTAL, 125 new java.awt.Insets (11, 0, 9, 10), 0, 0)); 126 m_northPnl.add(m_basePnl, 127 new java.awt.GridBagConstraints (0, 1, 4, 1, 0.0, 0.0, java.awt.GridBagConstraints.CENTER, java.awt.GridBagConstraints.BOTH, 128 new java.awt.Insets (5, 10, 5, 10), 0, 0)); 129 m_filterText.setText("") ; 130 m_filterText.setBorder(null) ; 131 m_centerPnl.setLayout(new BorderLayout()) ; 132 m_centerPnl.setBorder(BorderFactory.createTitledBorder( 133 BorderFactory.createLineBorder( 134 new Color(153, 153, 153), 1), "Search Filter", 135 TitledBorder.LEADING, TitledBorder.TOP, 136 new Font("SansSerif", 0, 14), new Color(60, 60, 60))) ; 137 m_scrollPane.getViewport().add(m_filterText); 138 m_centerPnl.add(m_scrollPane, BorderLayout.CENTER) ; 139 m_scopeLbl.setText("Scope:") ; 140 m_scopeLbl.setFont(new java.awt.Font ("Dialog", java.awt.Font.PLAIN, 14)); 141 m_scopeChoice.setSize(new java.awt.Dimension (115, 25)); 142 m_scopeChoice.setMaximumSize(new Dimension(32767,25)) ; 143 m_scopeChoice.setMinimumSize(new java.awt.Dimension (115, 25)); 144 m_scopeChoice.setPreferredSize(new Dimension(115, 25)) ; 145 m_scopeChoice.addItem(BASE_SCOPE) ; 146 m_scopeChoice.addItem(SINGLE_SCOPE) ; 147 m_scopeChoice.addItem(SUBTREE_SCOPE) ; 148 149 m_limitLbl.setText("Limit:") ; 150 m_limitField.setText("Unlimited") ; 151 m_limitField.setHorizontalAlignment(JTextField.CENTER) ; 152 m_southPnl.setLayout(new FlowLayout(FlowLayout.CENTER, 15, 5)) ; 153 m_southPnl.add(m_searchBut) ; 154 155 if ( m_mode != LOAD_MODE ) 156 { 157 m_searchBut.setText( SEARCH_CMD ) ; 158 m_searchBut.setActionCommand( SEARCH_CMD ) ; 159 m_southPnl.add( m_cancelBut ) ; 160 } 161 else 162 { 163 m_searchBut.setText( LOAD_CMD ) ; 164 m_searchBut.setActionCommand( LOAD_CMD ) ; 165 } 166 167 m_cancelBut.setText(CANCEL_CMD) ; 168 m_cancelBut.setActionCommand(CANCEL_CMD) ; 169 setBounds(new java.awt.Rectangle (0,0,595,331)); 170 m_basePnl.setLayout(new java.awt.GridBagLayout ()); 171 m_basePnl.add(jLabel1, 172 new java.awt.GridBagConstraints (0, 0, 1, 1, 0.0, 0.0, java.awt.GridBagConstraints.WEST, java.awt.GridBagConstraints.NONE, 173 new java.awt.Insets (0, 0, 0, 0), 0, 0)); 174 m_basePnl.add(m_baseText, 175 new java.awt.GridBagConstraints (1, 0, 1, 1, 1.0, 0.0, java.awt.GridBagConstraints.EAST, java.awt.GridBagConstraints.HORIZONTAL, 176 new java.awt.Insets (5, 5, 5, 0), 0, 0)); 177 jLabel1.setText("Search Base:"); 178 jLabel1.setFont(new java.awt.Font ("SansSerif", java.awt.Font.PLAIN, 14)); 179 180 if(m_mode == RUN_MODE) { 181 setTitle("Search Filter Dialog: Execute mode") ; 182 } else if(m_mode == LOAD_MODE) { 183 setTitle("Search Filter Dialog: Load mode") ; 184 } else if(m_mode == DEBUG_MODE) { 185 setTitle("Search Filter Dialog: Debug mode") ; 186 } else if(m_mode == ANNOTATE_MODE) { 187 setTitle("Search Filter Dialog: Annotate mode") ; 188 this.m_scopeChoice.setEnabled(false) ; 189 this.m_limitField.setEnabled(false) ; 190 this.m_baseText.setEnabled(false) ; 191 } else { 192 throw new RuntimeException ("Unrecognized mode.") ; 193 } 194 } 195 196 197 200 public void closeDialog(WindowEvent evt) 201 { 202 setVisible(false) ; 203 dispose() ; 204 } 205 206 207 public String getScope() 208 { 209 int l_selected = m_scopeChoice.getSelectedIndex() ; 210 return (String ) m_scopeChoice.getItemAt(l_selected) ; 211 } 212 213 214 231 232 public String getLimit() 233 { 234 return m_limitField.getText() ; 235 } 236 237 249 250 public String getFilter() 251 { 252 return this.m_filterText.getText() ; 253 } 254 255 256 public void setBase(String a_base) 257 { 258 this.m_baseText.setText(a_base) ; 259 } 260 261 262 public void setScope(String a_scope) 263 { 264 this.m_scopeChoice.setSelectedItem(a_scope) ; 265 } 266 267 268 public String getBase() 269 { 270 return this.m_baseText.getText() ; 271 } 272 } 273 | Popular Tags |