www.pudn.com > Java_UML_library.rar > FindTitleDialog.java


// 
//  Unified Library Application 
//  Case study in Unified Modeling Language Toolkit 
// 
//  FindTitleDialog.java 
// 
// 
//  Copyright (c) 1998 John Wiley & Sons, Inc. All rights reserved. 
//  Reproduction or translations of this work beyond that permitted 
//  in Section 117 of the 1976 United States Copyright Act without 
//  the express written permission of the copyright owner is unlawful. 
//  Requests for further information should be addressed to Permissions 
//  Department, John Wiley & Sons, Inc. The purchaser may make back-up 
//  copies for his/her own use only and not for distribution or resale. 
//  The Publisher assumes no responsibility for errors, omissions, or 
//  damages, caused by the use of these programs of from the use of the 
//  information contained herein. 
 
package ui; 
import util.*; 
import bo.*; 
import java.awt.*; 
 
 
public class FindTitleDialog extends Dialog { 
	private ResultOfFindTitle reswindow; 
	private Title current; 
 
	void findButton_Clicked(Event event) 
	{ 
		if (titleSearchRadioButton.getState() == true) 
		{ 
    		String name = nameField.getText(); 
    		current = 
    		    Title.findOnName(name); 
		} 
		else 
		if (authorSearchRadioButton.getState() == true) 
		{ 
		    String author = authorField.getText(); 
		    current = 
		        Title.findOnAuthor(author); 
		} 
		else 
		if (isbnSearchRadioButton.getState() == true) 
		{ 
		    String isbn = isbnField.getText(); 
		    current = 
		        Title.findOnISBN(isbn); 
		} 
		if (current == null) 
		{ 
		    nameField.setText(""); 
    		authorField.setText(""); 
    		isbnField.setText(""); 
    		noItemsField.setText(""); 
    		typeField.setText(""); 
		} 
		else 
		{ 
		    nameField.setText(current.getTitle()); 
		    authorField.setText(current.getAuthor()); 
		    isbnField.setText(current.getISBN()); 
		    typeField.setText(current.getTypeAsString()); 
		    noItemsField.setText(Integer.toString(current.getNoItems())); 
		} 
	} 
 
	void okButton_Clicked(Event event) 
	{ 
		if (current != null) 
		    reswindow.resultTitle(current.getObjId()); 
		dispose(); 
	} 
 
	void cancelButton_Clicked(Event event) 
	{ 
		dispose(); 
	} 
 
	public FindTitleDialog(Frame parent, boolean modal) { 
 
	    super(parent, modal); 
        reswindow = (ResultOfFindTitle) parent; 
		//{{INIT_CONTROLS 
		setLayout(null); 
		addNotify(); 
		resize(insets().left + insets().right + 567,insets().top + insets().bottom + 199); 
		titleLabel = new java.awt.Label("Title Name"); 
		titleLabel.reshape(insets().left + 12,insets().top + 24,84,24); 
		add(titleLabel); 
		nameField = new java.awt.TextField(); 
		nameField.reshape(insets().left + 132,insets().top + 24,183,24); 
		add(nameField); 
		authorField = new java.awt.TextField(); 
		authorField.reshape(insets().left + 132,insets().top + 60,183,24); 
		add(authorField); 
		label1 = new java.awt.Label("ISBN / Nr"); 
		label1.reshape(insets().left + 12,insets().top + 96,84,24); 
		add(label1); 
		isbnField = new java.awt.TextField(); 
		isbnField.reshape(insets().left + 132,insets().top + 96,183,24); 
		add(isbnField); 
		label2 = new java.awt.Label("Author"); 
		label2.reshape(insets().left + 12,insets().top + 60,84,24); 
		add(label2); 
		Group1 = new CheckboxGroup(); 
		titleSearchRadioButton = new java.awt.Checkbox("Title Search", Group1, false); 
		titleSearchRadioButton.reshape(insets().left + 348,insets().top + 24,108,24); 
		add(titleSearchRadioButton); 
		authorSearchRadioButton = new java.awt.Checkbox("Author Search", Group1, false); 
		authorSearchRadioButton.reshape(insets().left + 348,insets().top + 60,108,24); 
		add(authorSearchRadioButton); 
		isbnSearchRadioButton = new java.awt.Checkbox("ISBN Search", Group1, false); 
		isbnSearchRadioButton.reshape(insets().left + 348,insets().top + 96,108,24); 
		add(isbnSearchRadioButton); 
		findButton = new java.awt.Button("Find"); 
		findButton.reshape(insets().left + 480,insets().top + 24,60,24); 
		add(findButton); 
		okButton = new java.awt.Button("Select"); 
		okButton.reshape(insets().left + 480,insets().top + 120,60,24); 
		add(okButton); 
		cancelButton = new java.awt.Button("Close"); 
		cancelButton.reshape(insets().left + 480,insets().top + 156,60,24); 
		add(cancelButton); 
		noItemsField = new java.awt.TextField(); 
		noItemsField.setEditable(false); 
		noItemsField.reshape(insets().left + 132,insets().top + 168,45,24); 
		noItemsField.setBackground(new Color(12632256)); 
		add(noItemsField); 
		label3 = new java.awt.Label("Items available"); 
		label3.reshape(insets().left + 12,insets().top + 168,108,24); 
		add(label3); 
		label4 = new java.awt.Label("Title type"); 
		label4.reshape(insets().left + 12,insets().top + 132,84,24); 
		add(label4); 
		typeField = new java.awt.TextField(); 
		typeField.setEditable(false); 
		typeField.reshape(insets().left + 132,insets().top + 132,134,24); 
		typeField.setBackground(new Color(12632256)); 
		add(typeField); 
		setTitle("Find Title"); 
		//}} 
		titleSearchRadioButton.setState(true); 
		nameField.requestFocus(); 
	} 
 
	public FindTitleDialog(Frame parent, String title, boolean modal) { 
	    this(parent, modal); 
	    setTitle(title); 
	} 
 
    public synchronized void show() { 
    	Rectangle bounds = getParent().bounds(); 
 
    	move(bounds.x,bounds.y); 
 
    	super.show(); 
    } 
 
	public boolean handleEvent(Event event) { 
	    if(event.id == Event.WINDOW_DESTROY) { 
	        dispose(); 
	        return true; 
	    } 
		if (event.target == findButton && event.id == Event.ACTION_EVENT) { 
			findButton_Clicked(event); 
			return true; 
		} 
		if (event.target == okButton && event.id == Event.ACTION_EVENT) { 
			okButton_Clicked(event); 
			return true; 
		} 
		if (event.target == cancelButton && event.id == Event.ACTION_EVENT) { 
			cancelButton_Clicked(event); 
			return true; 
		} 
		return super.handleEvent(event); 
	} 
 
	//{{DECLARE_CONTROLS 
	java.awt.Label titleLabel; 
	java.awt.TextField nameField; 
	java.awt.TextField authorField; 
	java.awt.Label label1; 
	java.awt.TextField isbnField; 
	java.awt.Label label2; 
	java.awt.Checkbox titleSearchRadioButton; 
	CheckboxGroup Group1; 
	java.awt.Checkbox authorSearchRadioButton; 
	java.awt.Checkbox isbnSearchRadioButton; 
	java.awt.Button findButton; 
	java.awt.Button okButton; 
	java.awt.Button cancelButton; 
	java.awt.TextField noItemsField; 
	java.awt.Label label3; 
	java.awt.Label label4; 
	java.awt.TextField typeField; 
	//}} 
}