components/visual-panels/core/src/java/vpanels/panel/com/oracle/solaris/vp/panel/swing/view/FilterField.java
changeset 827 0944d8c0158b
equal deleted inserted replaced
826:c6aad84d2493 827:0944d8c0158b
       
     1 /*
       
     2  * CDDL HEADER START
       
     3  *
       
     4  * The contents of this file are subject to the terms of the
       
     5  * Common Development and Distribution License (the "License").
       
     6  * You may not use this file except in compliance with the License.
       
     7  *
       
     8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
       
     9  * or http://www.opensolaris.org/os/licensing.
       
    10  * See the License for the specific language governing permissions
       
    11  * and limitations under the License.
       
    12  *
       
    13  * When distributing Covered Code, include this CDDL HEADER in each
       
    14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
       
    15  * If applicable, add the following below this CDDL HEADER, with the
       
    16  * fields enclosed by brackets "[]" replaced with your own identifying
       
    17  * information: Portions Copyright [yyyy] [name of copyright owner]
       
    18  *
       
    19  * CDDL HEADER END
       
    20  */
       
    21 
       
    22 /*
       
    23  * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
       
    24  */
       
    25 
       
    26 package com.oracle.solaris.vp.panel.swing.view;
       
    27 
       
    28 import java.awt.Color;
       
    29 import javax.swing.*;
       
    30 import javax.swing.event.DocumentEvent;
       
    31 import com.oracle.solaris.vp.util.misc.finder.Finder;
       
    32 import com.oracle.solaris.vp.util.swing.*;
       
    33 
       
    34 /**
       
    35  * A simple live filter entry box.  Could be extended to track history,
       
    36  * sport a clear button, etc.  For now it is just a JTextField.
       
    37  */
       
    38 public class FilterField extends Box
       
    39 {
       
    40     private static final Color COLOR_UNMATCHED =
       
    41 	ColorUtil.lighter(Color.RED, .9f);
       
    42 
       
    43     private JTextField field_;
       
    44     private String text_ = "";
       
    45     private FilterListener listener_ = null;
       
    46 
       
    47     public interface FilterListener
       
    48     {
       
    49 	public void filterUpdate(FilterField field);
       
    50     }
       
    51 
       
    52     public FilterField(int columns)
       
    53     {
       
    54 	super(BoxLayout.LINE_AXIS);
       
    55 
       
    56 	setOpaque(false);
       
    57 
       
    58 	JLabel label = new JLabel(Finder.getString(
       
    59 	    "objects.header.filter.label"));
       
    60 	field_ = new JTextField();
       
    61 	field_.setColumns(columns);
       
    62 
       
    63 	field_.getDocument().addDocumentListener(new DocumentAdapter() {
       
    64 	    @Override
       
    65 	    public void docUpdate(DocumentEvent e)
       
    66 	    {
       
    67 		text_ = field_.getText();
       
    68 		update();
       
    69 	    }
       
    70 	});
       
    71 
       
    72 	add(label);
       
    73 	add(createHorizontalStrut(GUIUtil.getHalfGap()));
       
    74 	add(field_);
       
    75     }
       
    76 
       
    77     public String getText()
       
    78     {
       
    79 	return (text_);
       
    80     }
       
    81 
       
    82     public void setFilterListener(FilterListener listener)
       
    83     {
       
    84 	listener_ = listener;
       
    85     }
       
    86 
       
    87     private void update()
       
    88     {
       
    89 	if (listener_ != null)
       
    90 	    listener_.filterUpdate(this);
       
    91     }
       
    92 
       
    93     public void setUnmatched(boolean unmatched)
       
    94     {
       
    95 	if (unmatched)
       
    96 	    field_.setBackground(COLOR_UNMATCHED);
       
    97 	else
       
    98 	    field_.setBackground(null);
       
    99     }
       
   100 }