📄 searchwindows.java
字号:
//#condition MUJMAIL_SEARCH/*MujMail - Simple mail client for J2MECopyright (C) 2008 David Hauzar <david.hauzar.mujmail@gmail.com>This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe 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 ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */package mujmail.search;import mujmail.util.SaveableBooleanValue;import java.util.Enumeration;import java.util.Vector;import javax.microedition.lcdui.ChoiceGroup;import javax.microedition.lcdui.Command;import javax.microedition.lcdui.CommandListener;import javax.microedition.lcdui.DateField;import javax.microedition.lcdui.Displayable;import javax.microedition.lcdui.Form;import javax.microedition.lcdui.StringItem;import javax.microedition.lcdui.TextField;import mujmail.Lang;import mujmail.MujMail;import mujmail.PersistentBox;/** * The collection of forms that enables user to enter search settings and to * run search. * @author David Hauzar */public class SearchWindows { private final MujMail mujmail; private SearchSettings searchSettings; /** true for original user interface. */ private static final boolean ORIGINAL_UI = false; public SearchWindows(MujMail mujmail) { this.mujmail = mujmail; } /** * Displays the dialog where user can enter search settings and start the * search. */ public void newSearch() { searchSettings = new SearchSettings(); searchSettings.addAllSearchableBoxes(); startAddSearchPhraseWindow(); } /** * If the search box is not empty, displays it. If it is empty, displays * the window with search settings. */ public void displaySearchWindow() { if (!mujmail.getSearchBox().isEmpty()) { displaySearchBox(); } else { newSearch(); } } private class MyChoiceGroup extends ChoiceGroup { public MyChoiceGroup(String header, int mode) { super(header, mode); } /** * Saves selected state of items corresponding to items in this choice * group. * Note that vector items must have the same length or must be longer * than the number of items in this choice group. * @param items the vector of object implementing SaveableBooleanValue * interface. */ public void saveSelectedStateOfCorrespondingItems(Vector items) { for (int i = 0; i < size(); i++) { SaveableBooleanValue item = (SaveableBooleanValue) items.elementAt(i); item.saveBoolean(isSelected(i)); } } /** * Gets elements from vector items that have the same index as items that * are selected in this choice group. * Note that vector items must have the same length or must be longer * than the number of items in this choice group. * @param items the items to be filtered. * @return elements from vector items that correspond to selected items * in this choice group. */ public Vector getItemsCorrespondingToSelected(Vector items) { Vector correspondingToSelected = new Vector(); for (int i = 0; i < size(); i++) { if (isSelected(i)) { correspondingToSelected.addElement(items.elementAt(i)); } } return correspondingToSelected; } /** * Gets elements from enumeration items that have the same position as * items that are selected in this choice group. * Note that enumeration items must have the same length or must be longer * than the number of items in this choice group. * @param items the items to be filtered. * @return elements from enumeration items that correspond to selected items * in this choice group. */ public Vector getItemsCorrespondingToSelected(Enumeration items) { Vector correspondingToSelected = new Vector(); int i = 0; while (items.hasMoreElements()) { Object item = items.nextElement(); if (isSelected(i)) { correspondingToSelected.addElement(item); } i++; } return correspondingToSelected; } } /** * Shows windows where user can append new serching phrase. * * Let user enter search settings and returns it. * search settings entered by the user. * null if user presses cancel button * */ private void startAddSearchPhraseWindow() { mujmail.getDisplay().setCurrent(new AddSearchPhraseForm()); } /** * Do search and display search results. */ private void doSearchDisplayResults() { mujmail.getSearchBox().startSearchInNewThreadDisplayResults(searchSettings); } private void displaySearchBox() { mujmail.getDisplay().setCurrent( mujmail.getSearchBox() ); } /** * Form that displays search settings. */ private class SearchSettingsForm extends Form { private final Command ok; private final MyChoiceGroup boxes; private final DateField dateFrom; private final DateField dateTo; private final StringItem dateHeader; public SearchSettingsForm(AddSearchPhraseForm previousPhrase) { super(Lang.get(Lang.SEA_ADVANCED_SETTINGS)); dateHeader = new StringItem(Lang.get(Lang.SEA_DATE_INTERVAL), ""); append(dateHeader); dateFrom = new DateField(Lang.get(Lang.SEA_DATE_FROM), DateField.DATE); append(dateFrom); dateTo = new DateField(Lang.get(Lang.SEA_DATE_TO), DateField.DATE); append(dateTo); boxes = new MyChoiceGroup(Lang.get(Lang.SEA_SEARCH_IN_MAILBOXES), ChoiceGroup.MULTIPLE); addBoxesInWhichSearch(); append(boxes); ok = new Command(Lang.get(Lang.BTN_OK), Command.OK, 1); addCommand(ok); setCommandListener(new SearchSettingsCommandListener(this, previousPhrase)); } private void addBoxesInWhichSearch() { Vector searchableBoxes = PersistentBox.getPersistentBoxes(); for (int i = 0; i < searchableBoxes.size(); i++) { PersistentBox searchableBox = (PersistentBox) searchableBoxes.elementAt(i); boxes.append(searchableBox.getName(), null); boxes.setSelectedIndex(i, searchableBox.loadBoolean()); } } } /** * Listens for events of given SearchSettingsForm */ private class SearchSettingsCommandListener implements CommandListener { private final SearchSettingsForm searchSettingsForm; private final AddSearchPhraseForm previousPhrase; public SearchSettingsCommandListener(SearchSettingsForm searchSettingsForm, AddSearchPhraseForm previusPhrase) { this.searchSettingsForm = searchSettingsForm; this.previousPhrase = previusPhrase; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -