|
/******************************************************************************
Copyright (C) 2005 MakeLogic
This program 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.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Date : 14th December 2005
Authors : MakeLogic
Design : Ujjwal
Developer : Dharma
********************************************************************************/
package com.makeLogic.utils;
import com.makeLogic.Tail;
import com.makeLogic.TailMDI;
import com.makeLogic.TailInternalFrame;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
/**
* Summary description for FindDialogEastComp.
*/
public class FindDialogEastComp extends JPanel{
FindDialog findDialog;
FindDialogCenterComp findDialogCenterComp;
TailInternalFrame internalFrame;
//..Contains the array of all the internal frames
JInternalFrame tailInternalArray[];
public int internalArrayCounter = 0;
String lastSearchText = "";
public static int lastSearchIndex;
public static boolean isSearchingAllDocs;
public FindDialogEastComp(FindDialog findDialog,FindDialogCenterComp findDialogCenterComp)
{
//
// TODO: Add Constructor Logic here
//
this.findDialog = findDialog;
this.findDialogCenterComp = findDialogCenterComp;
//..Traverse all the opened InternalFrames
tailInternalArray = getFindDialog().getMDI().getDesktop().getAllFrames();
//..Set default as current doc search
isSearchingAllDocs = false;
lastSearchIndex = -2;
lastSearchText = null;
//..Set GridBagLayout
GridLayout gridLayout = new GridLayout(4,1,2,3);
setLayout(gridLayout);
//..Set the border
setBorder(new EmptyBorder(4,4,4,4));
//..Find Next Button
JButton findNext = new JButton("Find Next");
add(findNext);
findNext.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
//..Verify for singled document search or all document search
String searchString = getFindDialogCenterComp().getSearchText();
boolean isMatchCaseSelected = getFindDialogCenterComp().isMatchCaseSelected();
boolean isCurrentSelected = getFindDialogCenterComp().isCurrentSelected();
if(isCurrentSelected == false)
{
//..if isSearchingAllDocs is true.. continue prev search
//..else intialize var again
if(isSearchingAllDocs == false)
{
//..mark isSearchingAllDocs as true
isSearchingAllDocs = true;
//..Intialize variables and search
//lastSearchIndex = 0;
internalArrayCounter = 0;
//..Traverse all the opened InternalFrames
tailInternalArray = getFindDialog().getMDI().getDesktop().getAllFrames();
}
//..Get the current selected frame, and get the text
internalFrame = (TailInternalFrame)tailInternalArray[internalArrayCounter];
//..Debug
internalFrame.getTextPane().grabFocus();
//String selectedFrameText = internalFrame.getText();
String selectedFrameText = internalFrame.getDocumentString();
int startIndex = -2;
//..Check if MatchCase selected or not
if(isMatchCaseSelected == true)
{
//..Find the location of the searchString in the FrameText
startIndex = selectedFrameText.indexOf(searchString);
}
else
{
//..Find the location of the searchString in the FrameText
startIndex = selectedFrameText.toUpperCase().indexOf(searchString.toUpperCase());
}
if(lastSearchIndex >= startIndex)
{
//..Check if MatchCase selected or not
if(isMatchCaseSelected == true)
{
startIndex = selectedFrameText.indexOf(searchString,(lastSearchIndex+searchString.length()));
lastSearchIndex = startIndex;
}
else
{
startIndex = selectedFrameText.toUpperCase().indexOf(searchString.toUpperCase(),(lastSearchIndex+searchString.length()));
lastSearchIndex = startIndex;
}
}
else
{
if(lastSearchIndex == -2)
{
if(startIndex == -1)
{
//..Increment the counter and move the InternalFrame
internalArrayCounter++;
lastSearchIndex = -2;
try
{
//..Verify if all docs traversed, if so show MessageDlg
if(tailInternalArray.length <= internalArrayCounter)
{
JOptionPane.showMessageDialog(Tail.tailMDI, "Find reached end of all documents.", "MakeLogic - Tail", JOptionPane.INFORMATION_MESSAGE);
//..Set last SearchIndex to -2
lastSearchIndex = -2;
internalArrayCounter = 0;
//..Traverse all the opened InternalFrames
tailInternalArray = getFindDialog().getMDI().getDesktop().getAllFrames();
}
else
{
//..Set the focus to another Document.
tailInternalArray[internalArrayCounter].setSelected(true);
}
return;
}
catch(Exception ex)
{
//..Do nothing
}
}
else
{
lastSearchIndex = startIndex;
}
}
else
{
//..Increment the counter and move the InternalFrame
internalArrayCounter++;
lastSearchIndex = -2;
try
{
//..Verify if all docs traversed, if so show MessageDlg
if(tailInternalArray.length <= internalArrayCounter)
{
JOptionPane.showMessageDialog(Tail.tailMDI, "Find reached end of all documents.", "MakeLogic - Tail", JOptionPane.INFORMATION_MESSAGE);
//..Set last SearchIndex to -2
lastSearchIndex = -2;
internalArrayCounter = 0;
//..Traverse all the opened InternalFrames
tailInternalArray = getFindDialog().getMDI().getDesktop().getAllFrames();
}
else
{
//..Set the focus to another Document.
tailInternalArray[internalArrayCounter].setSelected(true);
}
return;
}
catch(Exception ex)
{
//..Do nothing
}
}
}
if(startIndex != -1)
{
//findField.setText("start: "+startIndex+" end: "+(startIndex+searchString.length()));
internalFrame.setSelectedText(startIndex,(startIndex+searchString.length()));
//internalFrame.setSelectedText(0,15);
}
else
{
//..Show that the string is not found
}
}
else
{
//..mark isSearchingAllDocs as false
isSearchingAllDocs = false;
//..For a Single Doc search
//..Get the current selected frame, and get the text
internalFrame = (TailInternalFrame)getFindDialog().getMDI().getDesktop().getSelectedFrame();
//..Debug
internalFrame.getTextPane().grabFocus();
//String selectedFrameText = internalFrame.getText();
String selectedFrameText = internalFrame.getDocumentString();
//..Verify if null
if(lastSearchText == null)
{
lastSearchText = searchString;
}
//..Verify if the searchText has been changed
if(!lastSearchText.equals(searchString))
{
//..Reset the variables and start the search
lastSearchIndex = -2;
}
int startIndex = -2;
//..Check if MatchCase selected or not
if(isMatchCaseSelected == true)
{
//..Find the location of the searchString in the FrameText
startIndex = selectedFrameText.indexOf(searchString);
}
else
{
//..Find the location of the searchString in the FrameText
startIndex = selectedFrameText.toUpperCase().indexOf(searchString.toUpperCase());
}
if(lastSearchIndex >= startIndex)
{
//..Check if MatchCase selected or not
if(isMatchCaseSelected == true)
{
startIndex = selectedFrameText.indexOf(searchString,(lastSearchIndex+searchString.length()));
lastSearchIndex = startIndex;
}
else
{
startIndex = selectedFrameText.toUpperCase().indexOf(searchString.toUpperCase(),(lastSearchIndex+searchString.length()));
lastSearchIndex = startIndex;
}
}
else
{
if(lastSearchIndex == -2)
{
if(startIndex == -1)
{
//..Show that the string is not found
JOptionPane.showMessageDialog(Tail.tailMDI, "Cannot find \""+searchString+"\"", "MakeLogic - Tail", JOptionPane.INFORMATION_MESSAGE);
}
else
{
lastSearchIndex = startIndex;
}
}
else
{
JOptionPane.showMessageDialog(Tail.tailMDI, "Find reached the starting point of the search.", "MakeLogic - Tail", JOptionPane.INFORMATION_MESSAGE);
//..Set last SearchIndex to -2
lastSearchIndex = -2;
}
}
if(startIndex != -1)
{
//findField.setText("start: "+startIndex+" end: "+(startIndex+searchString.length()));
internalFrame.setSelectedText(startIndex,(startIndex+searchString.length()));
}
else
{
/*
if(lastSearchIndex == 0)
{
//..Show that the string is not found
JOptionPane.showMessageDialog(null, "Cannot find \""+searchString+"\"", "MakeLogic - Tail", JOptionPane.INFORMATION_MESSAGE);
}
*/
}
}
}
}
);
//..Cancel Button
JButton cancelButton = new JButton("Cancel");
add(cancelButton);
cancelButton.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
TailMDI.findDialogOpened = false;
getFindDialog().dispose();
}
}
);
}
//..return the FindDialog object
public FindDialog getFindDialog()
{
return findDialog;
}
//..return the FindDialogCenterComp object
public FindDialogCenterComp getFindDialogCenterComp()
{
return findDialogCenterComp;
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Founder of MakeLogic - A Mobile Solutions and XML Web Services Company. B-Tech engineer from India's reputed IITs.
Designed and Authored products like MicroGraphs, MakeLogic VersionManager and MakeLogic Device Broker. Pls see http://www.makelogic.com
MakeLogic is a strategic business partner of Microsoft, Sun, IBM, HP and Citrix.
Contact : madanuuk@makelogic.com OR +91 - 40 - 55322433