craftleft.gif (3002 bytes)QuickTable
Home | API | Tutorial | Download | Support | Contact topblack.gif (108 bytes)


QuickTable User Cp  |  Register  |  Members  |  Search  |  Help
    |- QuickTable Discussion Forums > General QuickTable Support/Help Post New Topic   Post A Reply
Capturing events from the doFind dialog printer friendly version
next newest post | next oldest post
Author Messages
sabu
Private First Class

Gender: Male
Location: Minneapolis
Registered: Feb 2004
Status: Offline
Posts: 19

Click here to see the profile for sabu Send email to sabu Send private message to sabu Find more posts by sabu Edit or delete this message Reply w/Quote
Posted Wednesday, February 25, 2004 @ 14:53:53  

Is there any way to do it? I'd like to know the found row number after the button is clicked.
Admin
Board Owner

Gender: Unspecified
Location:
Registered: Jul 2003
Status: Offline
Posts: 9

Click here to see the profile for Admin Send email to Admin Send private message to Admin Find more posts by Admin Edit or delete this message Reply w/Quote
Posted Wednesday, February 25, 2004 @ 17:53:22  

The Find Dialong is provided as a convenient way to do a default find operation without user coding. So it is not flexible to give all advanced features. Instead by using find() method you can acheive all complex find features. I can publish the source code for the FindDialog and you can customize it for your use.

Ben

sabu
Private First Class

Gender: Male
Location: Minneapolis
Registered: Feb 2004
Status: Offline
Posts: 19

Click here to see the profile for sabu Send email to sabu Send private message to sabu Find more posts by sabu Edit or delete this message Reply w/Quote
Posted Thursday, February 26, 2004 @ 09:17:48  

That'd be cool. Let me know where to find it.

Thanx Ben,

Scott

echashnik
Private

Gender: Unspecified
Location:
Registered: Jan 2008
Status: Offline
Posts: 4

Click here to see the profile for echashnik Send email to echashnik Send private message to echashnik Find more posts by echashnik Edit or delete this message Reply w/Quote
Posted Tuesday, June 3, 2008 @ 12:40:35  

Ben,

Did you publish FindDialog code, where I can find it?

Thanks,
Eugene

Admin
Board Owner

Gender: Unspecified
Location:
Registered: Jul 2003
Status: Offline
Posts: 9

Click here to see the profile for Admin Send email to Admin Send private message to Admin Find more posts by Admin Edit or delete this message Reply w/Quote
Posted Wednesday, June 4, 2008 @ 21:37:59  

I have updated the code below. You need to make changes to below code to make it compile. This code is just for reference, you need to write yourn own based on the idea. I will not be able to provide any help with compile errors.

Code:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;

class FindFrame extends JDialog
{
JPanel buttonPanel = new JPanel();
JPanel mainPanel = new JPanel();
JPanel replacePanel = new JPanel();
JPanel findPanel = new JPanel();
BorderLayout borderLayout1 = new BorderLayout();
JLabel jLabel1 = new JLabel();
JComboBox findCombo = new JComboBox();
JLabel jLabel2 = new JLabel();
JComboBox replaceCombo = new JComboBox();
GridBagLayout gridBagLayout1 = new GridBagLayout();
GridBagLayout gridBagLayout2 = new GridBagLayout();
JButton nextButton = new JButton();
JButton previousButton = new JButton();
JButton replaceAllButton = new JButton();
JButton closeButton = new JButton();
JPanel jPanel1 = new JPanel();
JCheckBox startCheckbox = new JCheckBox();

//comment to change UI
DBTable dbTable;
//vector which contains the column number which should be searched
Vector columnVector;
Point lastLoc = new Point(0,1);

boolean find = true;

FindFrame(Frame f,DBTable dbTable)
{
super(f,false);
this.dbTable = dbTable;

try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
//end uncomment

FindFrame()
{
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}

private void jbInit() throws Exception
{
dbTable.setFnt(this);
mainPanel.setLayout(borderLayout1);
findPanel.setLayout(gridBagLayout1);
replacePanel.setLayout(gridBagLayout2);
jLabel1.setText(dbTable.getString("TextToFind"));
jLabel1.setLabelFor(findCombo);
dbTable.setFnt(jLabel1);
jLabel2.setLabelFor(replaceCombo);
dbTable.setFnt(jLabel2);
nextButton.setText(dbTable.getString("FindNext"));
getRootPane().setDefaultButton(nextButton);
dbTable.setFnt(nextButton);
previousButton.setText(dbTable.getString("FindPrevious"));
dbTable.setFnt(previousButton);
replaceAllButton.setText(dbTable.getString("ReplaceAll"));
dbTable.setFnt(replaceAllButton);
closeButton.setText(dbTable.getString("Close"));
dbTable.setFnt(closeButton);
startCheckbox.setText(dbTable.getString("FromSelectedRow"));
dbTable.setFnt(startCheckbox);
jLabel2.setText(dbTable.getString("ReplaceWith"));
findCombo.setEditable(true);
replaceCombo.setEditable(true);
this.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
((FlowLayout)buttonPanel.getLayout()).setAlignment(FlowLayout.CENTER);
((FlowLayout)buttonPanel.getLayout()).setVgap(3);
buttonPanel.add(nextButton, null);
buttonPanel.add(previousButton, null);
buttonPanel.add(replaceAllButton, null);
buttonPanel.add(closeButton, null);
this.getContentPane().add(mainPanel, BorderLayout.CENTER);
mainPanel.add(findPanel, BorderLayout.NORTH);
findPanel.add(jLabel1, new SimpleGridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(7, 20, 0, 0), 0, 9));
findPanel.add(findCombo, new SimpleGridBagConstraints(1, 0, 1, 1, 1.0, 1.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(7, 5, 0, 0), 0, 0));
mainPanel.add(replacePanel, BorderLayout.CENTER);
replacePanel.add(jLabel2, new SimpleGridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 0, 9));
replacePanel.add(replaceCombo, new SimpleGridBagConstraints(1, 0, 1, 1, 1.0, 1.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(7, 5, 0, 0), 0, 0));
mainPanel.add(jPanel1, BorderLayout.SOUTH);

((FlowLayout)jPanel1.getLayout()).setAlignment(FlowLayout.CENTER);
((FlowLayout)jPanel1.getLayout()).setVgap(3);
jPanel1.add(startCheckbox, null);

FindAction findAction = new FindAction();
nextButton.addActionListener(findAction);
previousButton.addActionListener(findAction);
replaceAllButton.addActionListener(findAction);
closeButton.addActionListener(findAction);
startCheckbox.addActionListener(findAction);
findCombo.addActionListener(findAction);

ChangeListener cl = new ChangeListener();
findCombo.addItemListener(cl);
replaceCombo.addItemListener(cl);
}

void resetFont(Font fnt)
{
setFont(fnt);
jLabel1.setFont(fnt);
nextButton.setFont(fnt);
previousButton.setFont(fnt);
replaceAllButton.setFont(fnt);
closeButton.setFont(fnt);
startCheckbox.setFont(fnt);
jLabel2.setFont(fnt);
}

public void setFind()
{
find = true;
replacePanel.setVisible(false);
nextButton.setText(dbTable.getString("FindNext"));
previousButton.setText(dbTable.getString("FindPrevious"));
replaceAllButton.setVisible(false);
setSize(440,150);
}

public void setReplace()
{
find = false;
replacePanel.setVisible(true);
nextButton.setText(dbTable.getString("ReplaceNext"));
previousButton.setText(dbTable.getString("ReplacePrevious"));
replaceAllButton.setVisible(true);
setSize(440,190);
}

//when row selection is changed in main dbtable
//it can be notified to find frame using this method
public void setRow(int row)
{
if( startCheckbox.isSelected())
{
if( row >= 0 )
lastLoc = new Point(row, -1);
else
lastLoc = new Point(0, -1);
}
}

class ChangeListener implements ItemListener{
public void itemStateChanged(ItemEvent e)
{
JComboBox cb = (JComboBox)e.getSource();
String text =(String)cb.getSelectedItem();
if(text == null || "".equals(text))
return;

boolean exists= false;
for(int i=0; i< cb.getItemCount(); i++)
{
if( text.equals(cb.getItemAt(i)))
{
exists=true;
break;
}
}

if(!exists)
cb.addItem(text);
}
}

void findNext()
{

//if user has not entered the find text show error dialog
if( ! validateInput())
return;

String findText = (String)findCombo.getSelectedItem();

//if the column model is changed, recreate the column Vector
refreshColumnVector(dbTable.getTable());

//move the search pointer to next row/column
if( dbTable.lastLoc == -1 )
{

if( lastLoc.y == columnVector.size()-1)
{
lastLoc.x = lastLoc.x +1;
lastLoc.y = 0;
}
else
lastLoc.y = lastLoc.y + 1;
}

lastLoc = dbTable.find(lastLoc.x, lastLoc.y,findText,columnVector, true);

}

class FindAction implements ActionListener{
public void actionPerformed(ActionEvent e)
{

JTable jt = dbTable.getTable();

if(e.getSource() == closeButton)
{
setVisible(false);
return;
}
else if( e.getSource() == startCheckbox)
{
if( startCheckbox.isSelected() )
{
int startRow = jt.getSelectedRow();
if( startRow >= 0 )
lastLoc = new Point(startRow, -1);
else
lastLoc = new Point(0, -1);
}
else
lastLoc = new Point(0, -1);

return;
}

if( find )
{
if( e.getSource() == nextButton || e.getSource() == findCombo)
{
findNext();
}
else if(e.getSource() == previousButton)
{
//if user has not entered the find text show error dialog
if( ! validateInput())
return;

String findText = (String)findCombo.getSelectedItem();

//if the column model is changed, recreate the column Vector
refreshColumnVector(jt);

//move the search pointer to previous row/column
if( dbTable.lastLoc == -1 )
{

if( lastLoc.y == 0)
{
lastLoc.x = lastLoc.x -1;
lastLoc.y = columnVector.size()-1;
}
else
lastLoc.y = lastLoc.y - 1;

}
lastLoc = dbTable.find(lastLoc.x, lastLoc.y,findText,columnVector, false);

}
}
else
{
if( e.getSource() == nextButton || e.getSource() == findCombo)
{
if( ! validateInput())
return;

String findText = (String)findCombo.getSelectedItem();
String replaceText = (String)replaceCombo.getSelectedItem();

//if the column model is changed, recreate the column Vector
refreshColumnVector(jt);

//move the search pointer to next row/column
if( lastLoc.y == columnVector.size()-1)
{
lastLoc.x = lastLoc.x +1;
lastLoc.y = 0;
}
else
lastLoc.y = lastLoc.y + 1;

setVisible(false);
lastLoc = dbTable.replace(lastLoc.x, lastLoc.y,findText, replaceText, columnVector, true);
}
else if(e.getSource() == previousButton)
{
if( ! validateInput())
return;

String findText = (String)findCombo.getSelectedItem();
String replaceText = (String)replaceCombo.getSelectedItem();

//if the column model is changed, recreate the column Vector
refreshColumnVector(jt);

//move the search pointer to previous row/column
if( lastLoc.y == 0)
{
lastLoc.x = lastLoc.x -1;
lastLoc.y = columnVector.size()-1;
}
else
lastLoc.y = lastLoc.y - 1;

setVisible(false);
lastLoc = dbTable.replace(lastLoc.x, lastLoc.y,findText,replaceText,columnVector, false);

}
else if(e.getSource() == replaceAllButton)
{
//if user has not entered the find text show error dialog
String findText = (String)findCombo.getSelectedItem();
if( findText == null || "".equals(findText))
{
//add code to show dialog
return;
}

String replaceText = (String)replaceCombo.getSelectedItem();
if( replaceText == null || "".equals(replaceText))
{
//add code to show dialog
return;
}

//if the column model is changed, recreate the column Vector
refreshColumnVector(jt);

setVisible(false);
lastLoc = dbTable.replaceAll(0,1,findText, replaceText, columnVector);
}
}

jt.repaint();
}
}

private void refreshColumnVector(JTable jt)
{
int colCount = jt.getColumnCount();

if( columnVector == null)
columnVector = new Vector();

if( colCount != columnVector.size() )
{
columnVector.removeAllElements();
for( int i= 0; i< colCount; i++ )
columnVector.addElement(new Integer(i+1));
}
}

//validate whether user has entered a find or replace text
private boolean validateInput()
{
//if user has not entered the find text show error dialog
String findText = (String)findCombo.getSelectedItem();
if( findText == null || "".equals(findText))
{
//add code to show dialog
return false;
}

if( !find )
{
String replaceText = (String)replaceCombo.getSelectedItem();
if( replaceText == null || "".equals(replaceText))
{
//add code to show dialog
return false;
}
}
return true;
}

public void setVisible(boolean visible)
{
if(visible)
{
if( startCheckbox.isSelected() )
{
int startRow = dbTable.getTable().getSelectedRow();
if( startRow >= 0 )
lastLoc = new Point(startRow, -1);
else
lastLoc = new Point(0, -1);
}
else
lastLoc = new Point(0, -1);

center();

toFront();
findCombo.requestDefaultFocus();
findCombo.requestFocus();
}
else
{
dbTable.lastLoc =-1;
}

super.setVisible(visible);
}

public void center()
{
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();

setLocation(dim.width / 2 - getSize().width / 2,
dim.height / 2 - getSize().height / 2);

}

}


echashnik
Private

Gender: Unspecified
Location:
Registered: Jan 2008
Status: Offline
Posts: 4

Click here to see the profile for echashnik Send email to echashnik Send private message to echashnik Find more posts by echashnik Edit or delete this message Reply w/Quote
Posted Thursday, June 5, 2008 @ 09:31:44  

Ben,

Thanks a lot for your code and for your response.
Is it possible to publish ReplaceDialog as well.

Best regards,
Eugene

Admin
Board Owner

Gender: Unspecified
Location:
Registered: Jul 2003
Status: Offline
Posts: 9

Click here to see the profile for Admin Send email to Admin Send private message to Admin Find more posts by Admin Edit or delete this message Reply w/Quote
Posted Thursday, June 5, 2008 @ 13:16:18  

This FinddFrame is both find & replace. based on setFind() or setReplace() method calls the appearance will change.

Instead of copying this code and modifying, try to to see whether you can extend this class and acheive the necessary changes.

echashnik
Private

Gender: Unspecified
Location:
Registered: Jan 2008
Status: Offline
Posts: 4

Click here to see the profile for echashnik Send email to echashnik Send private message to echashnik Find more posts by echashnik Edit or delete this message Reply w/Quote
Posted Thursday, June 5, 2008 @ 13:20:44  

Ben,

Thanks again - I didn't notice this.
Sure, I'll try to extend the code.

Sincerely,
Eugene

Post New Topic   Post A Reply Jump to:
Contact Us | QuickTable - A Java DBGrid | Privacy Policy All times are GMT -5 Hours.
Welcome to QuickTable Forums, Guest!  
Login
Username :
Password :
In order to fully utilize the abilities of this board, you are required to register as a member. Registration is free, and allows you to do lots of things including turning on or off certain features of this board. Register now!
Powered by CuteCast v2.0 BETA 2
Copyright © 2001-2003 ArtsCore Studios