implemented JSearchBar
parent
8f4be74177
commit
a72323cd2d
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<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"/>
|
||||
</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"?>
|
||||
<jardesc>
|
||||
<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"/>
|
||||
<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">
|
||||
<packagesToSeal/>
|
||||
<packagesToUnSeal/>
|
||||
</sealing>
|
||||
</manifest>
|
||||
<selectedElements exportClassFiles="true" exportJavaFiles="false" exportOutputFolder="false">
|
||||
<javaElement handleIdentifier="=nt.UI/src<nt.UI.display"/>
|
||||
<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"/>
|
||||
<javaElement handleIdentifier="=nt.UI/src"/>
|
||||
</selectedElements>
|
||||
</jardesc>
|
||||
|
|
|
@ -10,6 +10,7 @@ import javax.swing.JScrollPane;
|
|||
import javax.swing.JTextField;
|
||||
import javax.swing.JWindow;
|
||||
|
||||
import nt.UI.control.interfaces.DefaultSearchBarFinder;
|
||||
import nt.UI.control.interfaces.SearchBarFinder;
|
||||
|
||||
public class JSearchBar extends JSearchTextField{
|
||||
|
@ -23,6 +24,9 @@ public class JSearchBar extends JSearchTextField{
|
|||
protected String lastEntered = "";
|
||||
private final JSearchBarController controller;
|
||||
|
||||
public JSearchBar() {
|
||||
this(new DefaultSearchBarFinder());
|
||||
}
|
||||
public JSearchBar(SearchBarFinder finder) {
|
||||
this.finder = finder;
|
||||
this.dropDown = new SearchDropDown();
|
||||
|
|
|
@ -112,8 +112,7 @@ public class JSearchBarController extends KeyAdapter implements DocumentListener
|
|||
|
||||
if(e.getKeyCode()==KeyEvent.VK_ENTER) {
|
||||
searchBar.txtSearch.setText(list.getSelectedValue());
|
||||
System.out.println(list.getSelectedValue());
|
||||
System.out.println(searchBar.txtSearch.getText());
|
||||
searchBar.finder.acceptedResult(list.getSelectedValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package nt.UI.control;
|
|||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Font;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
|
@ -16,6 +17,10 @@ import javax.swing.border.EmptyBorder;
|
|||
import javax.swing.border.LineBorder;
|
||||
|
||||
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{
|
||||
|
||||
|
@ -25,41 +30,60 @@ public class JSearchTextField extends JPanel{
|
|||
protected JTextField txtSearch;
|
||||
protected JButton btnCancel;
|
||||
private Component horizontalStrut;
|
||||
private Component horizontalStrut_1;
|
||||
|
||||
public JSearchTextField() {
|
||||
super();
|
||||
setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
|
||||
|
||||
Font symbols = NtUIHelper.getSymbolFont().deriveFont(18f);
|
||||
|
||||
horizontalStrut_1 = Box.createHorizontalStrut(20);
|
||||
add(horizontalStrut_1);
|
||||
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);
|
||||
lblLens = new JLabel("\uE116");
|
||||
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);
|
||||
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.setText("search");
|
||||
txtSearch.setBorder(new EmptyBorder(0, 0, 0, 0));
|
||||
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);
|
||||
|
||||
btnCancel = new JButton("\uE10f");
|
||||
btnCancel.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||
btnCancel.setBorderPainted(false);
|
||||
btnCancel.setFont(symbols);
|
||||
btnCancel.setOpaque(false);
|
||||
btnCancel.setVisible(false);
|
||||
add(btnCancel);
|
||||
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());
|
||||
|
||||
setBorder(new LineBorder(Color.LIGHT_GRAY));
|
||||
setPreferredSize(btnCancel.getPreferredSize());
|
||||
setMinimumSize(btnCancel.getMinimumSize());
|
||||
setPreferredSize(new Dimension(376, 56));
|
||||
}
|
||||
|
||||
public void addActionListener(ActionListener l) {
|
||||
|
@ -70,7 +94,6 @@ public class JSearchTextField extends JPanel{
|
|||
}
|
||||
public void showCancelButton(boolean b) {
|
||||
this.btnCancel.setVisible(b);
|
||||
System.out.println(b);
|
||||
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 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]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptedResult(String result) {
|
||||
}
|
||||
}));
|
||||
|
||||
DefaultTreeModel model = new DefaultTreeModel(new DefaultMutableTreeNode("root"));
|
||||
|
|
Loading…
Reference in New Issue