implemented JSearchBar
parent
8f4be74177
commit
a72323cd2d
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry kind="src" path="src"/>
|
<classpathentry kind="src" path="src"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/Java SE 8 [1.8.0_151]"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Manifest-version: 1.0
|
||||||
|
Created-by: Niclas Thobaben (DrBender GmbH)
|
|
@ -1,25 +1,16 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<jardesc>
|
<jardesc>
|
||||||
<jar path="/Users/niclasthobaben/Desktop/DrBender_Dev/bin/libs/nt.UI.jar"/>
|
<jar path="/Users/niclasthobaben/Desktop/DrBender_Dev/bin/libs/nt.UI.jar"/>
|
||||||
<options buildIfNeeded="true" compress="true" descriptionLocation="/nt.UI/src/nt.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="false" overwrite="false" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
|
<options buildIfNeeded="true" compress="false" descriptionLocation="/nt.UI/src/nt.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="false" overwrite="true" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
|
||||||
<storedRefactorings deprecationInfo="true" structuralOnly="false"/>
|
<storedRefactorings deprecationInfo="true" structuralOnly="false"/>
|
||||||
<selectedProjects/>
|
<selectedProjects/>
|
||||||
<manifest generateManifest="false" manifestLocation="/nt.CLI/META-INF/MANIFEST.MF" manifestVersion="1.0" reuseManifest="false" saveManifest="false" usesManifest="true">
|
<manifest generateManifest="false" manifestLocation="/nt.UI/META-INF/MANIFEST.MF" manifestVersion="1.0" reuseManifest="false" saveManifest="false" usesManifest="true">
|
||||||
<sealing sealJar="false">
|
<sealing sealJar="false">
|
||||||
<packagesToSeal/>
|
<packagesToSeal/>
|
||||||
<packagesToUnSeal/>
|
<packagesToUnSeal/>
|
||||||
</sealing>
|
</sealing>
|
||||||
</manifest>
|
</manifest>
|
||||||
<selectedElements exportClassFiles="true" exportJavaFiles="false" exportOutputFolder="false">
|
<selectedElements exportClassFiles="true" exportJavaFiles="false" exportOutputFolder="false">
|
||||||
<javaElement handleIdentifier="=nt.UI/src<nt.UI.display"/>
|
<javaElement handleIdentifier="=nt.UI/src"/>
|
||||||
<javaElement handleIdentifier="=nt.UI/src<nt.UI.util"/>
|
|
||||||
<javaElement handleIdentifier="=nt.UI/src<nt"/>
|
|
||||||
<file path="/nt.UI/src/.DS_Store"/>
|
|
||||||
<file path="/nt.UI/.classpath"/>
|
|
||||||
<javaElement handleIdentifier="=nt.UI/src<nt.UI.control"/>
|
|
||||||
<javaElement handleIdentifier="=nt.UI/src<nt.UI.control.interfaces"/>
|
|
||||||
<javaElement handleIdentifier="=nt.UI/src<nt.UI"/>
|
|
||||||
<file path="/nt.UI/.gitignore"/>
|
|
||||||
<file path="/nt.UI/.project"/>
|
|
||||||
</selectedElements>
|
</selectedElements>
|
||||||
</jardesc>
|
</jardesc>
|
||||||
|
|
|
@ -10,6 +10,7 @@ import javax.swing.JScrollPane;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
import javax.swing.JWindow;
|
import javax.swing.JWindow;
|
||||||
|
|
||||||
|
import nt.UI.control.interfaces.DefaultSearchBarFinder;
|
||||||
import nt.UI.control.interfaces.SearchBarFinder;
|
import nt.UI.control.interfaces.SearchBarFinder;
|
||||||
|
|
||||||
public class JSearchBar extends JSearchTextField{
|
public class JSearchBar extends JSearchTextField{
|
||||||
|
@ -23,6 +24,9 @@ public class JSearchBar extends JSearchTextField{
|
||||||
protected String lastEntered = "";
|
protected String lastEntered = "";
|
||||||
private final JSearchBarController controller;
|
private final JSearchBarController controller;
|
||||||
|
|
||||||
|
public JSearchBar() {
|
||||||
|
this(new DefaultSearchBarFinder());
|
||||||
|
}
|
||||||
public JSearchBar(SearchBarFinder finder) {
|
public JSearchBar(SearchBarFinder finder) {
|
||||||
this.finder = finder;
|
this.finder = finder;
|
||||||
this.dropDown = new SearchDropDown();
|
this.dropDown = new SearchDropDown();
|
||||||
|
|
|
@ -112,8 +112,7 @@ public class JSearchBarController extends KeyAdapter implements DocumentListener
|
||||||
|
|
||||||
if(e.getKeyCode()==KeyEvent.VK_ENTER) {
|
if(e.getKeyCode()==KeyEvent.VK_ENTER) {
|
||||||
searchBar.txtSearch.setText(list.getSelectedValue());
|
searchBar.txtSearch.setText(list.getSelectedValue());
|
||||||
System.out.println(list.getSelectedValue());
|
searchBar.finder.acceptedResult(list.getSelectedValue());
|
||||||
System.out.println(searchBar.txtSearch.getText());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package nt.UI.control;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
|
import java.awt.FlowLayout;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
@ -16,6 +17,10 @@ import javax.swing.border.EmptyBorder;
|
||||||
import javax.swing.border.LineBorder;
|
import javax.swing.border.LineBorder;
|
||||||
|
|
||||||
import nt.UI.NtUIHelper;
|
import nt.UI.NtUIHelper;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.GridBagLayout;
|
||||||
|
import java.awt.GridBagConstraints;
|
||||||
|
import java.awt.Insets;
|
||||||
|
|
||||||
public class JSearchTextField extends JPanel{
|
public class JSearchTextField extends JPanel{
|
||||||
|
|
||||||
|
@ -25,41 +30,60 @@ public class JSearchTextField extends JPanel{
|
||||||
protected JTextField txtSearch;
|
protected JTextField txtSearch;
|
||||||
protected JButton btnCancel;
|
protected JButton btnCancel;
|
||||||
private Component horizontalStrut;
|
private Component horizontalStrut;
|
||||||
private Component horizontalStrut_1;
|
|
||||||
|
|
||||||
public JSearchTextField() {
|
public JSearchTextField() {
|
||||||
super();
|
super();
|
||||||
setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
|
|
||||||
|
|
||||||
Font symbols = NtUIHelper.getSymbolFont().deriveFont(18f);
|
Font symbols = NtUIHelper.getSymbolFont().deriveFont(18f);
|
||||||
|
GridBagLayout gridBagLayout = new GridBagLayout();
|
||||||
horizontalStrut_1 = Box.createHorizontalStrut(20);
|
gridBagLayout.columnWidths = new int[]{42, 31, 255, 53, 0};
|
||||||
add(horizontalStrut_1);
|
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);
|
||||||
lblLens = new JLabel("\uE116");
|
lblLens = new JLabel("\uE116");
|
||||||
lblLens.setFont(symbols);
|
lblLens.setFont(symbols);
|
||||||
add(lblLens);
|
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);
|
||||||
|
|
||||||
horizontalStrut = Box.createHorizontalStrut(10);
|
horizontalStrut = Box.createHorizontalStrut(10);
|
||||||
add(horizontalStrut);
|
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);
|
||||||
|
|
||||||
txtSearch = new JTextField();
|
txtSearch = new JTextField();
|
||||||
txtSearch.setText("search");
|
txtSearch.setText("search");
|
||||||
txtSearch.setBorder(new EmptyBorder(0, 0, 0, 0));
|
txtSearch.setBorder(new EmptyBorder(0, 0, 0, 0));
|
||||||
txtSearch.setBackground(getBackground());
|
txtSearch.setBackground(getBackground());
|
||||||
add(txtSearch);
|
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);
|
||||||
txtSearch.setColumns(10);
|
txtSearch.setColumns(10);
|
||||||
|
|
||||||
btnCancel = new JButton("\uE10f");
|
btnCancel = new JButton("\uE10f");
|
||||||
btnCancel.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
||||||
btnCancel.setBorderPainted(false);
|
btnCancel.setBorderPainted(false);
|
||||||
btnCancel.setFont(symbols);
|
btnCancel.setFont(symbols);
|
||||||
btnCancel.setOpaque(false);
|
btnCancel.setOpaque(false);
|
||||||
btnCancel.setVisible(false);
|
GridBagConstraints gbc_btnCancel = new GridBagConstraints();
|
||||||
add(btnCancel);
|
gbc_btnCancel.fill = GridBagConstraints.VERTICAL;
|
||||||
|
gbc_btnCancel.gridx = 3;
|
||||||
|
gbc_btnCancel.gridy = 0;
|
||||||
|
add(btnCancel, gbc_btnCancel);
|
||||||
|
setMinimumSize(btnCancel.getMinimumSize());
|
||||||
|
|
||||||
setBorder(new LineBorder(Color.LIGHT_GRAY));
|
setBorder(new LineBorder(Color.LIGHT_GRAY));
|
||||||
setPreferredSize(btnCancel.getPreferredSize());
|
setPreferredSize(new Dimension(376, 56));
|
||||||
setMinimumSize(btnCancel.getMinimumSize());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addActionListener(ActionListener l) {
|
public void addActionListener(ActionListener l) {
|
||||||
|
@ -70,7 +94,6 @@ public class JSearchTextField extends JPanel{
|
||||||
}
|
}
|
||||||
public void showCancelButton(boolean b) {
|
public void showCancelButton(boolean b) {
|
||||||
this.btnCancel.setVisible(b);
|
this.btnCancel.setVisible(b);
|
||||||
System.out.println(b);
|
|
||||||
revalidate();
|
revalidate();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package nt.UI.control.interfaces;
|
||||||
|
|
||||||
|
public class DefaultSearchBarFinder implements SearchBarFinder{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getSearchResults(String token) {
|
||||||
|
return new String[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void acceptedResult(String result) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -3,5 +3,6 @@ package nt.UI.control.interfaces;
|
||||||
public interface SearchBarFinder {
|
public interface SearchBarFinder {
|
||||||
|
|
||||||
public String[] getSearchResults(String token);
|
public String[] getSearchResults(String token);
|
||||||
|
public void acceptedResult(String result);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,88 @@
|
||||||
|
package nt.UI.display;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import javax.swing.Icon;
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JTable;
|
||||||
|
import javax.swing.table.TableCellRenderer;
|
||||||
|
|
||||||
|
import nt.UI.util.IconResizer;
|
||||||
|
import nt.UI.util.Icons;
|
||||||
|
|
||||||
|
public class ObjTableCellRenderer implements TableCellRenderer{
|
||||||
|
|
||||||
|
private HashMap<Class<?>, Icon> mappedIcons = new HashMap<>();
|
||||||
|
private Color bgEven = new Color(Integer.decode("#e8e8e8"));
|
||||||
|
private Color bgOdd = Color.WHITE;
|
||||||
|
private Color bgSelect = new Color(Integer.decode("#5e87ed"));
|
||||||
|
|
||||||
|
public ObjTableCellRenderer() {
|
||||||
|
putIcon(String.class, Icons.STRING_SYMBOL_URL);
|
||||||
|
putIcon(Long.class, Icons.NUMBER_SYMBOL_URL);
|
||||||
|
putIcon(Integer.class, Icons.NUMBER_SYMBOL_URL);
|
||||||
|
putIcon(Short.class, Icons.NUMBER_SYMBOL_URL);
|
||||||
|
putIcon(Float.class, Icons.NUMBER_SYMBOL_URL);
|
||||||
|
putIcon(Double.class, Icons.NUMBER_SYMBOL_URL);
|
||||||
|
putIcon(Object.class, Icons.OBJECT_SYMBOL_URL);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
|
||||||
|
int row, int column) {
|
||||||
|
JLabel label = new JLabel(value == null? "" : value.toString());;
|
||||||
|
if (column == 0) {
|
||||||
|
Class<?> clazz = value.getClass();
|
||||||
|
if(clazz == String.class) {
|
||||||
|
try {
|
||||||
|
clazz = Class.forName(value.toString());
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
clazz = value.getClass();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Icon icon = mappedIcons.get(clazz);
|
||||||
|
icon = icon == null ? new ImageIcon(Icons.FILE_SYMBOL_URL) : icon;
|
||||||
|
|
||||||
|
int fHeight = table.getFontMetrics(table.getFont()).getHeight() - 4;
|
||||||
|
int iWidth = (int) ((fHeight / (float) icon.getIconHeight()) * icon.getIconWidth());
|
||||||
|
icon = IconResizer.resizeIcon(icon, iWidth, fHeight);
|
||||||
|
|
||||||
|
label.setIcon(icon);
|
||||||
|
}
|
||||||
|
|
||||||
|
Color bg = (row % 2)==0?bgEven:bgOdd;
|
||||||
|
bg = isSelected? bgSelect : bg;
|
||||||
|
Color fg = isSelected? table.getSelectionForeground() : table.getForeground();
|
||||||
|
label.setIconTextGap(10);
|
||||||
|
label.setFont(table.getFont());
|
||||||
|
label.setOpaque(true);
|
||||||
|
label.setBackground(bg);
|
||||||
|
label.setForeground(fg);
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void putIcon(Class<?> clazz, Icon icon) {
|
||||||
|
this.mappedIcons.put(clazz, icon);
|
||||||
|
}
|
||||||
|
public void putIcon(Class<?> clazz, URL url) {
|
||||||
|
putIcon(clazz, new ImageIcon(url));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Color getBackgroundEven() {
|
||||||
|
return this.bgEven;
|
||||||
|
}
|
||||||
|
public void setBackgroundEven(Color bg) {
|
||||||
|
this.bgEven = bg;
|
||||||
|
}
|
||||||
|
public Color getBackgroundOdd() {
|
||||||
|
return this.bgOdd;
|
||||||
|
}
|
||||||
|
public void setBackgroundOdd(Color bg) {
|
||||||
|
this.bgOdd = bg;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -58,6 +58,10 @@ public class UITestMain extends JFrame{
|
||||||
}
|
}
|
||||||
return results.toArray(new String[0]);
|
return results.toArray(new String[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void acceptedResult(String result) {
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
DefaultTreeModel model = new DefaultTreeModel(new DefaultMutableTreeNode("root"));
|
DefaultTreeModel model = new DefaultTreeModel(new DefaultMutableTreeNode("root"));
|
||||||
|
|
Loading…
Reference in New Issue