nt.UI/src/nt/UI/control/JSearchTextField.java

119 lines
3.4 KiB
Java
Raw Normal View History

2018-06-20 17:09:48 +02:00
package nt.UI.control;
import java.awt.Color;
import java.awt.Component;
2018-06-22 15:58:11 +02:00
import java.awt.FlowLayout;
2018-06-20 17:09:48 +02:00
import java.awt.Font;
import java.awt.event.ActionListener;
import javax.swing.Box;
2018-06-20 17:09:48 +02:00
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
2018-06-20 17:09:48 +02:00
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import nt.UI.NtUIHelper;
2018-06-22 15:58:11 +02:00
import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
2018-06-20 17:09:48 +02:00
public class JSearchTextField extends JPanel{
private static final long serialVersionUID = 1L;
private JLabel lblLens;
protected JTextField txtSearch;
protected JButton btnCancel;
private Component horizontalStrut;
public JSearchTextField() {
super();
Font symbols = NtUIHelper.getSymbolFont().deriveFont(18f);
2018-06-22 15:58:11 +02:00
GridBagLayout gridBagLayout = new GridBagLayout();
gridBagLayout.columnWidths = new int[]{42, 31, 255, 53, 0};
gridBagLayout.rowHeights = new int[]{29, 0};
gridBagLayout.columnWeights = new double[]{0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE};
gridBagLayout.rowWeights = new double[]{1.0, Double.MIN_VALUE};
setLayout(gridBagLayout);
2018-06-20 17:09:48 +02:00
lblLens = new JLabel("\uE116");
lblLens.setFont(symbols);
2018-06-22 15:58:11 +02:00
GridBagConstraints gbc_lblLens = new GridBagConstraints();
gbc_lblLens.fill = GridBagConstraints.VERTICAL;
gbc_lblLens.insets = new Insets(0, 0, 0, 5);
gbc_lblLens.gridx = 0;
gbc_lblLens.gridy = 0;
add(lblLens, gbc_lblLens);
2018-06-20 17:09:48 +02:00
horizontalStrut = Box.createHorizontalStrut(10);
2018-06-22 15:58:11 +02:00
GridBagConstraints gbc_horizontalStrut = new GridBagConstraints();
gbc_horizontalStrut.fill = GridBagConstraints.VERTICAL;
gbc_horizontalStrut.anchor = GridBagConstraints.WEST;
gbc_horizontalStrut.insets = new Insets(0, 0, 0, 5);
gbc_horizontalStrut.gridx = 1;
gbc_horizontalStrut.gridy = 0;
add(horizontalStrut, gbc_horizontalStrut);
2018-06-20 17:09:48 +02:00
2018-06-20 17:20:44 +02:00
txtSearch = new JTextField();
2018-06-20 17:09:48 +02:00
txtSearch.setText("search");
txtSearch.setBorder(new EmptyBorder(0, 0, 0, 0));
txtSearch.setBackground(getBackground());
2018-06-22 15:58:11 +02:00
GridBagConstraints gbc_txtSearch = new GridBagConstraints();
gbc_txtSearch.fill = GridBagConstraints.BOTH;
gbc_txtSearch.insets = new Insets(0, 0, 0, 5);
gbc_txtSearch.gridx = 2;
gbc_txtSearch.gridy = 0;
add(txtSearch, gbc_txtSearch);
2018-06-20 17:09:48 +02:00
txtSearch.setColumns(10);
btnCancel = new JButton("\uE10f");
btnCancel.setBorderPainted(false);
btnCancel.setFont(symbols);
btnCancel.setOpaque(false);
2018-06-22 15:58:11 +02:00
GridBagConstraints gbc_btnCancel = new GridBagConstraints();
gbc_btnCancel.fill = GridBagConstraints.VERTICAL;
gbc_btnCancel.gridx = 3;
gbc_btnCancel.gridy = 0;
add(btnCancel, gbc_btnCancel);
setMinimumSize(btnCancel.getMinimumSize());
2018-06-20 17:09:48 +02:00
setBorder(new LineBorder(Color.LIGHT_GRAY));
2018-06-22 15:58:11 +02:00
setPreferredSize(new Dimension(376, 56));
2018-06-20 17:09:48 +02:00
}
public void addActionListener(ActionListener l) {
this.btnCancel.addActionListener(l);
}
public void removeActionListener(ActionListener l) {
this.btnCancel.removeActionListener(l);
}
public void showCancelButton(boolean b) {
this.btnCancel.setVisible(b);
revalidate();
}
@Override
public void setBackground(Color bg) {
super.setBackground(bg);
for(Component c : getComponents()) {
c.setBackground(bg);
}
}
@Override
public void setForeground(Color fg) {
super.setForeground(fg);
for(Component c : getComponents()) {
c.setForeground(fg);
}
}
}