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