-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
305 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
|
||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo"> | ||
<Properties> | ||
<Property name="title" type="java.lang.String" value="Find"/> | ||
</Properties> | ||
<SyntheticProperties> | ||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/> | ||
<SyntheticProperty name="generateCenter" type="boolean" value="false"/> | ||
</SyntheticProperties> | ||
<AuxValues> | ||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/> | ||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/> | ||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/> | ||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/> | ||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/> | ||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/> | ||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> | ||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> | ||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> | ||
</AuxValues> | ||
|
||
<Layout> | ||
<DimensionLayout dim="0"> | ||
<Group type="103" groupAlignment="0" attributes="0"> | ||
<Group type="102" attributes="0"> | ||
<EmptySpace max="-2" attributes="0"/> | ||
<Group type="103" groupAlignment="0" attributes="0"> | ||
<Group type="102" alignment="0" attributes="0"> | ||
<Component id="lblWhat" min="-2" max="-2" attributes="0"/> | ||
<EmptySpace max="32767" attributes="0"/> | ||
<Component id="txtSearch" min="-2" pref="323" max="-2" attributes="0"/> | ||
</Group> | ||
<Group type="102" alignment="1" attributes="0"> | ||
<Component id="chkMatchCase" min="-2" max="-2" attributes="0"/> | ||
<EmptySpace max="32767" attributes="0"/> | ||
<Component id="btCancel" min="-2" max="-2" attributes="0"/> | ||
<EmptySpace type="unrelated" max="-2" attributes="0"/> | ||
<Component id="btSearch" min="-2" max="-2" attributes="0"/> | ||
</Group> | ||
</Group> | ||
<EmptySpace max="-2" attributes="0"/> | ||
</Group> | ||
</Group> | ||
</DimensionLayout> | ||
<DimensionLayout dim="1"> | ||
<Group type="103" groupAlignment="0" attributes="0"> | ||
<Group type="102" alignment="1" attributes="0"> | ||
<EmptySpace max="-2" attributes="0"/> | ||
<Group type="103" groupAlignment="3" attributes="0"> | ||
<Component id="txtSearch" alignment="3" pref="25" max="32767" attributes="0"/> | ||
<Component id="lblWhat" alignment="3" min="-2" max="-2" attributes="0"/> | ||
</Group> | ||
<EmptySpace type="unrelated" max="-2" attributes="0"/> | ||
<Group type="103" groupAlignment="3" attributes="0"> | ||
<Component id="btSearch" alignment="3" min="-2" max="-2" attributes="0"/> | ||
<Component id="btCancel" alignment="3" min="-2" max="-2" attributes="0"/> | ||
<Component id="chkMatchCase" alignment="3" min="-2" max="-2" attributes="0"/> | ||
</Group> | ||
<EmptySpace min="-2" max="-2" attributes="0"/> | ||
</Group> | ||
</Group> | ||
</DimensionLayout> | ||
</Layout> | ||
<SubComponents> | ||
<Component class="javax.swing.JLabel" name="lblWhat"> | ||
<Properties> | ||
<Property name="text" type="java.lang.String" value="Find What: "/> | ||
</Properties> | ||
</Component> | ||
<Component class="javax.swing.JTextField" name="txtSearch"> | ||
<Events> | ||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="txtSearchActionPerformed"/> | ||
</Events> | ||
</Component> | ||
<Component class="javax.swing.JButton" name="btSearch"> | ||
<Properties> | ||
<Property name="text" type="java.lang.String" value=" Search "/> | ||
</Properties> | ||
<Events> | ||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btSearchActionPerformed"/> | ||
</Events> | ||
</Component> | ||
<Component class="javax.swing.JButton" name="btCancel"> | ||
<Properties> | ||
<Property name="text" type="java.lang.String" value=" Cancel "/> | ||
</Properties> | ||
<Events> | ||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btCancelActionPerformed"/> | ||
</Events> | ||
</Component> | ||
<Component class="javax.swing.JCheckBox" name="chkMatchCase"> | ||
<Properties> | ||
<Property name="text" type="java.lang.String" value="Match Case"/> | ||
</Properties> | ||
</Component> | ||
</SubComponents> | ||
</Form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package com.innoveworkshop.monicom; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import javax.swing.JOptionPane; | ||
import javax.swing.JTextArea; | ||
|
||
/** | ||
* | ||
* @author nathanpc | ||
*/ | ||
public class FindWindow extends javax.swing.JFrame { | ||
private String needle; | ||
private List<int[]> found; | ||
private int curr_index; | ||
private JTextArea field; | ||
|
||
/** | ||
* Creates new form FindWindow | ||
*/ | ||
public FindWindow(JTextArea field) { | ||
initComponents(); | ||
|
||
this.found = new ArrayList(); | ||
this.needle = ""; | ||
this.curr_index = 0; | ||
this.field = field; | ||
} | ||
|
||
/** | ||
* Populates the found list. | ||
* | ||
* @param haystack Text to perform the search on. | ||
*/ | ||
private void populateFoundList(String haystack) { | ||
int last_found = -1; | ||
found.clear(); | ||
|
||
while (haystack.indexOf(needle, last_found + 1) >= 0) { | ||
last_found = haystack.indexOf(needle, last_found + 1); | ||
|
||
int indexes[] = { last_found, last_found + needle.length() }; | ||
found.add(indexes); | ||
System.out.println("Found: " + indexes[0] + " - " + indexes[1]); | ||
} | ||
} | ||
|
||
/** | ||
* Performs a search action. | ||
*/ | ||
private void performSearch() { | ||
String text = txtSearch.getText(); | ||
String haystack = field.getText(); | ||
|
||
// Is this case sensitive? | ||
if (!chkMatchCase.isSelected()) { | ||
text = text.toLowerCase(); | ||
haystack = haystack.toLowerCase(); | ||
} | ||
|
||
// Check if it is a new string that the user is searching for. | ||
if (!text.equals(needle)) { | ||
needle = text; | ||
curr_index = 0; | ||
} | ||
|
||
// Grab the list of places where we found it. | ||
populateFoundList(haystack); | ||
|
||
// Nothing was found. | ||
if (found.isEmpty()) { | ||
Debug.println("FINDING", "No occurrences of " + needle + " found."); | ||
JOptionPane.showMessageDialog(null, "No occurrences of " + needle + " found.", | ||
"Nothing found", JOptionPane.INFORMATION_MESSAGE); | ||
|
||
return; | ||
} | ||
|
||
// Loop back the indexes if we have reached the end. | ||
if (curr_index == found.size()) { | ||
curr_index = 0; | ||
} | ||
|
||
// Go through the findings one at a time. | ||
int indexes[] = found.get(curr_index); | ||
field.select(indexes[0], indexes[1]); | ||
curr_index++; | ||
} | ||
|
||
/** | ||
* This method is called from within the constructor to initialize the form. | ||
* WARNING: Do NOT modify this code. The content of this method is always | ||
* regenerated by the Form Editor. | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents | ||
private void initComponents() { | ||
|
||
lblWhat = new javax.swing.JLabel(); | ||
txtSearch = new javax.swing.JTextField(); | ||
btSearch = new javax.swing.JButton(); | ||
btCancel = new javax.swing.JButton(); | ||
chkMatchCase = new javax.swing.JCheckBox(); | ||
|
||
setTitle("Find"); | ||
|
||
lblWhat.setText("Find What: "); | ||
|
||
txtSearch.addActionListener(new java.awt.event.ActionListener() { | ||
public void actionPerformed(java.awt.event.ActionEvent evt) { | ||
txtSearchActionPerformed(evt); | ||
} | ||
}); | ||
|
||
btSearch.setText(" Search "); | ||
btSearch.addActionListener(new java.awt.event.ActionListener() { | ||
public void actionPerformed(java.awt.event.ActionEvent evt) { | ||
btSearchActionPerformed(evt); | ||
} | ||
}); | ||
|
||
btCancel.setText(" Cancel "); | ||
btCancel.addActionListener(new java.awt.event.ActionListener() { | ||
public void actionPerformed(java.awt.event.ActionEvent evt) { | ||
btCancelActionPerformed(evt); | ||
} | ||
}); | ||
|
||
chkMatchCase.setText("Match Case"); | ||
|
||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); | ||
getContentPane().setLayout(layout); | ||
layout.setHorizontalGroup( | ||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | ||
.addGroup(layout.createSequentialGroup() | ||
.addContainerGap() | ||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | ||
.addGroup(layout.createSequentialGroup() | ||
.addComponent(lblWhat) | ||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) | ||
.addComponent(txtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 323, javax.swing.GroupLayout.PREFERRED_SIZE)) | ||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() | ||
.addComponent(chkMatchCase) | ||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) | ||
.addComponent(btCancel) | ||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) | ||
.addComponent(btSearch))) | ||
.addContainerGap()) | ||
); | ||
layout.setVerticalGroup( | ||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | ||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() | ||
.addContainerGap() | ||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) | ||
.addComponent(txtSearch, javax.swing.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE) | ||
.addComponent(lblWhat)) | ||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) | ||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) | ||
.addComponent(btSearch) | ||
.addComponent(btCancel) | ||
.addComponent(chkMatchCase)) | ||
.addContainerGap()) | ||
); | ||
|
||
pack(); | ||
}// </editor-fold>//GEN-END:initComponents | ||
|
||
private void btCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelActionPerformed | ||
this.setVisible(false); | ||
}//GEN-LAST:event_btCancelActionPerformed | ||
|
||
private void btSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSearchActionPerformed | ||
performSearch(); | ||
}//GEN-LAST:event_btSearchActionPerformed | ||
|
||
private void txtSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtSearchActionPerformed | ||
performSearch(); | ||
}//GEN-LAST:event_txtSearchActionPerformed | ||
|
||
|
||
// Variables declaration - do not modify//GEN-BEGIN:variables | ||
private javax.swing.JButton btCancel; | ||
private javax.swing.JButton btSearch; | ||
private javax.swing.JCheckBox chkMatchCase; | ||
private javax.swing.JLabel lblWhat; | ||
private javax.swing.JTextField txtSearch; | ||
// End of variables declaration//GEN-END:variables | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters