queryfilter.java

来自「全面实现ilog地功能,没有使用第三方lib.」· Java 代码 · 共 76 行

JAVA
76
字号
/* * This source code is part of TWaver 1.3.1 * * SERVA Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * Copyright 2000-2005 SERVA Software, Inc. All rights reserved. */package demo.table;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JTextField;

import twaver.table.TTable;
import twaver.table.TTableRowFilter;

public class QueryFilter extends JPanel implements TTableRowFilter, ActionListener{
	
	private TTable table;
	
	private JComboBox filedSelection;
	private JTextField textField;
	private String ALL = "<html><font color=red>-- select column --</font><html>";
	
	public QueryFilter(TTable table){
		this.table = table;
		
		List list = new ArrayList();
		list.add(ALL);
		list.addAll(table.getTableModel().getRawColumn());
		this.filedSelection = new JComboBox(list.toArray());
		
		this.textField = new JTextField();
		this.textField.setPreferredSize(new Dimension(50, textField.getPreferredSize().height));
		this.textField.addActionListener(this);
		this.textField.setToolTipText("please input key word for search");
		this.filedSelection.addActionListener(this);
		
		this.setLayout(new BorderLayout());
		this.add(filedSelection, BorderLayout.WEST);
		this.add(textField, BorderLayout.CENTER);
	}
	
	public boolean isVisible(TTable table, Vector rowData) {
		Object item = this.filedSelection.getSelectedItem();
		if(item == ALL){
			return true;
		}
		String text = textField.getText();
		if(text == null || text.trim().equals("")){
			return true;
		}
		int index = table.getTableModel().getRawColumn().indexOf(item);
		Object value = rowData.get(index);
		if(value != null){
			if(value.toString().toLowerCase().indexOf(text.toLowerCase()) >= 0){
				return true;
			}
		}
		return false;
	}

	public void actionPerformed(ActionEvent e) {
		table.getTableModel().publishData();
	}
	
	
}

⌨️ 快捷键说明

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