|
What this is
Other links
The source code/* * 08/30/2001 - 10:37:18 * * FindAll.java - Find all * Copyright (C) 2001 Romain Guy & Grant Stead * romain.guy@jext.org * www.jext.org * * 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 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.text.*; import javax.swing.event.*; import java.util.ArrayList; import gnu.regexp.*; import org.jext.*; import org.jext.gui.*; import org.jext.event.*; import org.jext.search.*; public class FindAll extends JPanel implements ActionListener, JextListener { private JList results; private JextFrame parent; private JComboBox fieldSearch; private DefaultListModel resultModel; private JTextField fieldSearchEditor; private JextHighlightButton find, unHighlight; private JextCheckBox useRegexp, ignoreCase, highlight, allFiles; public FindAll(JextFrame parent) { this.parent = parent; parent.addJextListener(this); setLayout(new BorderLayout()); fieldSearch = new JComboBox(); fieldSearch.setRenderer(new ModifiedCellRenderer()); fieldSearch.setEditable(true); fieldSearchEditor = (JTextField) fieldSearch.getEditor().getEditorComponent(); fieldSearchEditor.addKeyListener(new KeyHandler()); FontMetrics fm = getFontMetrics(fieldSearch.getFont()); Dimension size; //= new Dimension(20 * fm.charWidth('m'), fieldSearch.getSize().height); //fieldSearch.setPreferredSize(size); add(fieldSearch, BorderLayout.NORTH); JPanel pane2 = new JPanel(); pane2.setLayout(new GridLayout(5, 1)); pane2.add(ignoreCase = new JextCheckBox(Jext.getProperty("find.ignorecase.label"), "on".equals(Jext.getProperty("ignorecase.all")))); pane2.add(useRegexp = new JextCheckBox(Jext.getProperty("find.useregexp.label"), "on".equals(Jext.getProperty("useregexp.all")))); pane2.add(highlight = new JextCheckBox(Jext.getProperty("find.all.highlight.label"), "on".equals(Jext.getProperty("highlight.all")))); pane2.add(allFiles = new JextCheckBox(Jext.getProperty("find.allFiles.label"), "on".equals(Jext.getProperty("allfiles.all")))); JToolBar toolBar = new JToolBar(); toolBar.setFloatable(false); toolBar.add(find = new JextHighlightButton(Jext.getProperty("find.all.button"), org.jext.Utilities.getIcon("images/menu_find" + Jext.getProperty("jext.look.icons") + ".gif", Jext.class))); toolBar.add(unHighlight = new JextHighlightButton(Jext.getProperty("find.all.unHighlight"))); pane2.add(toolBar); find.setToolTipText(Jext.getProperty("find.all.tip")); find.addActionListener(this); unHighlight.addActionListener(this); add(pane2, BorderLayout.SOUTH); resultModel = new DefaultListModel(); results = new JList(); results.setCellRenderer(new ModifiedCellRenderer()); results.addListSelectionListener(new ListHandler()); results.setModel(resultModel); size = new Dimension(20 * fm.charWidth('m'), 10 * results.getFixedCellHeight()); JScrollPane scroller = new JScrollPane(results, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); scroller.setMaximumSize(size); scroller.setPreferredSize(size); add(scroller, BorderLayout.CENTER); String s; for (int i = 0; i < 25; i++) { s = Jext.getProperty("search.all.history." + i); if (s != null) fieldSearch.addItem(s); else break; } s = Jext.getProperty("find.all"); addSearchHistory(s); fieldSearch.setSelectedItem(s); } public void exit() { Jext.setProperty("find.all", fieldSearchEditor.getText()); for (int i = 0; i < fieldSearch.getItemCount(); i++) Jext.setProperty("search.all.history." + i, (String) fieldSearch.getItemAt(i)); for (int i = fieldSearch.getItemCount(); i < 25; i++) Jext.unsetProperty("search.all.history." + i); Jext.setProperty("useregexp.all", (useRegexp.isSelected() ? "on" : "off")); Jext.setProperty("ignorecase.all", (ignoreCase.isSelected() ? "on" : "off")); Jext.setProperty("highlight.all", (highlight.isSelected() ? "on" : "off")); Jext.setProperty("allfiles.all", (allFiles.isSelected() ? "on" : "off")); removeHighlights(); parent.getTextArea().repaint(); } private void removeHighlights() { JextTextArea[] areas = parent.getTextAreas(); for (int i = 0; i < areas.length; i++) { SearchHighlight h = areas[i].getSearchHighlight(); if (h != null) h.disable(); } } private void addSearchHistory() { addSearchHistory(fieldSearchEditor.getText()); } private void addSearchHistory(String c) { if ((c == null) || (c.equals(""))) return; for (int i = 0; i < fieldSearch.getItemCount(); i++) { if (((String) fieldSearch.getItemAt(i)).equals(c)) { fieldSearch.setSelectedIndex(i); return; } } fieldSearch.insertItemAt(c, 0); fieldSearch.setSelectedIndex(0); if (fieldSearch.getItemCount() > 25) { for (int i = 24; i < fieldSearch.getItemCount(); i++) fieldSearch.removeItemAt(i); } } public void actionPerformed(ActionEvent evt) { if (evt.getSource() == find) findAll(); else if (evt.getSource() == unHighlight) { removeHighlights(); parent.getTextArea().repaint(); } } public void findText() { String text = parent.getTextArea().getSelectedText(); fieldSearchEditor.setText(text); fieldSearchEditor.requestFocus(); findAll(); if ((text != null) && (text.length() > 0)) { ListModel model = results.getModel(); for (int index=0; index |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.