⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 booksearchdbobserver.java

📁 此文档针对开发人员和测试人员。第二章对软件进行了全面的描述。第三章对接口进行了分析。第四章对软件实现的功能进行概述。第五章对软件后续开发实现提出的要求。第六章提出其他一些在软件开发过程中需要注意的问题
💻 JAVA
字号:
package com.ciash.bms.observer.impl;


import com.ciash.bms.observer.BookSearchObserver;
import java.util.Vector;

import com.ciash.bms.gui.search.loader.BookLoaderPanel;
import com.ciash.bms.gui.uiInter.SearchUI;
import java.util.Collection;
import javax.swing.JOptionPane;
import com.ciash.bms.model.impl.BookSearchModel;
import java.util.Iterator;
import com.ciash.bms.entity.Book;


/**
 * 书籍搜索观察者实例,该类实现了所有BookSearchObserver方法
 */

public class BookSearchDBObserver
implements BookSearchObserver {

    private SearchUI searchUI;
    private BookSearchModel bookSearchModel;
    private Vector updaters = new Vector();

    public BookSearchDBObserver(BookSearchModel bookSearchModel
        , SearchUI searchUI) {
        this.setBookSearchModel(bookSearchModel);
        this.setSearchUI(searchUI);
    }

    public BookSearchDBObserver(){
    }
    // ---------------------------------------------------------------------------------------------
    // 实现自 接口 BookSearchController
    public void findBookById() {
        allClear();
        String info = getSearchUI().getSearchInfo();
        Book b = bookSearchModel.findBookById(info);
        if (b == null) {
            warning("书籍");
            return;
        }
        installAll(b);
    }

    public void findBookByAuthor() {
        allClear();
        String info = getSearchUI().getSearchInfo();
        Collection c = bookSearchModel.findBookByAuthor(info);
        checkBooks(c);
        installAll(c);
    }

    public void findBookByUserId() {
        allClear();
        String info = getSearchUI().getSearchInfo();
        Collection c = bookSearchModel.findBookByUserId(info);
        checkBooks(c);
        installAll(c);
    }

    public void findBookByName() {
        allClear();
        String info = getSearchUI().getSearchInfo();
        Collection c = bookSearchModel.findBookByName(info);
        checkBooks(c);
        installAll(c);
    }

    public void findBookByConcern() {
        allClear();
        String info = getSearchUI().getSearchInfo();
        Collection c = bookSearchModel.findBookByConcern(info);
        checkBooks(c);
        installAll(c);
    }

    public void update() {
    }

    public void addBookResultUpdater(BookLoaderPanel updater) {
        updaters.add(updater);
    }

    public void removeBookResultUpdater(BookLoaderPanel updater) {
        updaters.remove(updater);
    }

    public BookLoaderPanel getBookResultUpdater(int i) {
        return (BookLoaderPanel) updaters.get(i);
    }

    // ---------------------------------------------------------------------------------------------
    private void allClear() {
        Iterator it = updaters.iterator();
        while (it.hasNext()) {
            BookLoaderPanel updater = (BookLoaderPanel) it.next();
            updater.clearResult();
        }
    }

    private void installAll(Collection c) {
        Iterator it = updaters.iterator();
        while (it.hasNext()) {
            BookLoaderPanel updater = (BookLoaderPanel) it.next();
            updater.install(c);
        }
    }

    private void installAll(Book b) {
        Iterator it = updaters.iterator();
        while (it.hasNext()) {
            BookLoaderPanel updater = (BookLoaderPanel) it.next();
            updater.installBook(b);
        }
    }

    private void checkBooks(Collection c) {
        if (c.size() == 0) {
            warning("书籍");
            return;
        }
    }

    private void warning(String info) {
        JOptionPane.showMessageDialog(null, "没有找到相关的" + info, "提示!"
            , JOptionPane.WARNING_MESSAGE);
    }

	public void setSearchUI(SearchUI searchUI) {
		this.searchUI = searchUI;
	}

	public SearchUI getSearchUI() {
		return searchUI;
	}

	public void setBookSearchModel(BookSearchModel bookSearchModel) {
		this.bookSearchModel = bookSearchModel;
	}

	public BookSearchModel getBookSearchModel() {
		return bookSearchModel;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -