/*
* Jacareto Copyright (c) 2002-2005
* Applied Computer Science Research Group, Darmstadt University of
* Technology, Institute of Mathematics & Computer Science,
* Ludwigsburg University of Education, and Computer Based
* Learning Research Group, Aachen University. All rights reserved.
*
* Jacareto is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* Jacareto is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with Jacareto; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
package jacareto.cleverphl.gui;
import com.jgoodies.forms.builder.PanelBuilder;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
import jacareto.cleverphl.CleverPHL;
import jacareto.system.Language;
import org.apache.regexp.RE;
import org.apache.regexp.RESyntaxException;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
/**
* Dialog for the search.
*
* @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
* @version 1.0
*/
public class FindDialog extends JDialog implements ActionListener {
public static final int SCOPE_ACTUAL_SESSION = 0;
public static final int SCOPE_ALL_SESSIONS = 1;
/** The CleverPHL instance. */
private CleverPHL cleverPHL;
/** The regular expression field. */
private JTextField findwhatField;
/** The button testing the regexp */
private JButton regexpTestButton;
private JCheckBox regexpCheckBox;
/** JRadiobuttons for the scope. */
private JRadioButton scopeActualSessionButton;
private JRadioButton scopeAllSessionsButton;
/** The buttons. */
private JButton okButton;
/** The buttons. */
private JButton cancelButton;
/** The results. */
private boolean okButtonPressed;
private String searchString;
private boolean isRegExp;
private int scope;
/**
* Creates a new dialog (visible).
*
* @param cleverPHL the CleverPHL instance
*/
public FindDialog (CleverPHL cleverPHL) {
super(cleverPHL.getMainFrame (), true);
this.cleverPHL = cleverPHL;
setName (cleverPHL.getCustomization ().getString ("Components.JacaretoComponent",
"JACARETO_COMPONENT"));
Language language = cleverPHL.getLanguage ();
//setLocationRelativeTo ( cleverPHL.getMainFrame() );
setTitle (language.getString ("CleverPHL.FindDialog.Title"));
okButton = new JButton(language.getString ("General.Ok"));
cancelButton = new JButton(language.getString ("General.Cancel"));
okButton.addActionListener (this);
cancelButton.addActionListener (this);
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
buttonPanel.add (okButton);
buttonPanel.add (cancelButton);
getContentPane ().setLayout (new BorderLayout());
getContentPane ().add (getSearchPanel (), BorderLayout.NORTH);
getContentPane ().add (buttonPanel, BorderLayout.CENTER);
Point ownerLoc = cleverPHL.getMainFrame ().getLocation ();
setLocation (((int) ownerLoc.getX ()) + 30, ((int) ownerLoc.getY ()) + 30);
pack ();
setResizable (false);
setVisible (true);
}
/**
* Returns the main panel of the dialog.
*
* @return the component
*/
private JComponent getSearchPanel () {
FormLayout layout = new FormLayout("10dlu,p,3dlu,left:p",
"p,3dlu,p,3dlu,p,7dlu,p,3dlu,p,3dlu,p");
PanelBuilder builder = new PanelBuilder(layout);
builder.setDefaultDialogBorder ();
CellConstraints cc = new CellConstraints();
findwhatField = new JTextField(20);
regexpTestButton = new JButton(this.cleverPHL.getLanguage ().getString ("CleverPHL.FindDialog.Test"));
regexpTestButton.addActionListener (this);
regexpCheckBox = new JCheckBox(this.cleverPHL.getLanguage ().getString ("CleverPHL.FindDialog.RegularExpression"));
regexpTestButton.setEnabled (regexpCheckBox.isSelected ());
regexpCheckBox.addActionListener (new ActionListener() {
public void actionPerformed (ActionEvent event) {
regexpTestButton.setEnabled (regexpCheckBox.isSelected ());
}
});
scopeActualSessionButton = new JRadioButton(this.cleverPHL.getLanguage ().getString ("CleverPHL.FindDialog.ScopeActualSession"));
scopeAllSessionsButton = new JRadioButton(this.cleverPHL.getLanguage ().getString ("CleverPHL.FindDialog.ScopeAllSessions"));
scopeActualSessionButton.setSelected (true);
ButtonGroup scopeGroup = new ButtonGroup();
scopeGroup.add (scopeActualSessionButton);
scopeGroup.add (scopeAllSessionsButton);
builder.addSeparator (this.cleverPHL.getLanguage ().getString ("CleverPHL.FindDialog.Search"),
cc.xyw (1, 1, 4));
builder.addLabel (this.cleverPHL.getLanguage ().getString ("CleverPHL.FindDialog.FindWhat") +
" :", cc.xy (2, 3));
builder.add (findwhatField, cc.xy (4, 3));
builder.add (regexpCheckBox, cc.xy (2, 5));
builder.add (regexpTestButton, cc.xy (4, 5));
builder.addSeparator (this.cleverPHL.getLanguage ().getString ("CleverPHL.FindDialog.Scope"),
cc.xyw (1, 7, 4));
builder.add (scopeActualSessionButton, cc.xy (2, 9));
builder.add (scopeAllSessionsButton, cc.xy (2, 11));
JPanel panel = builder.getPanel ();
return panel;
}
/**
* Called when a button has been pressed.
*
* @param event DOCUMENT ME!
*/
public void actionPerformed (ActionEvent event) {
if (event.getSource () == regexpTestButton) {
testRegEx ();
} else {
if (event.getSource () == okButton) {
okButtonPressed = true;
} else {
okButtonPressed = false;
}
searchString = findwhatField.getText ();
isRegExp = regexpCheckBox.isSelected ();
if (scopeActualSessionButton.isSelected ()) {
scope = SCOPE_ACTUAL_SESSION;
} else if (scopeAllSessionsButton.isSelected ()) {
scope = SCOPE_ALL_SESSIONS;
}
dispose ();
}
}
/**
* Tests the regular expression.
*/
private void testRegEx () {
try {
RE re = new RE(findwhatField.getText ());
} catch (RESyntaxException res) {
cleverPHL.getLogger ().info (cleverPHL.getLanguage ().getString ("CleverPHL.FindDialog.SyntaxCheck.NotCorrect"),
res);
return;
}
cleverPHL.getLogger ().info (cleverPHL.getLanguage ().getString ("CleverPHL.FindDialog.SyntaxCheck.Correct"));
}
/**
* Returns whether or not the ok button has been pressed.
*
* @return <code>true</code> if the ok button has been pressed, otherwise <code>false</code>
*/
public boolean okButtonPressed () {
return okButtonPressed;
}
/**
* Returns the search string.
*
* @return the string
*/
public String getSearchString () {
return searchString;
}
/**
* Returns whether or not the search string is a regular expression.
*
* @return <code>true</code> if the search string is a regular expression, otherwise
* <code>false</code>
*/
public boolean isRegExp () {
return isRegExp;
}
/**
* Returns the scope of the search.
*
* @return the scope.
*/
public int getScope () {
return scope;
}
}
|