Skip to content

Commit

Permalink
Added filter to the skins installation menu so you can search for a s…
Browse files Browse the repository at this point in the history
…pecific skin more easily.
  • Loading branch information
shannah committed Oct 11, 2019
1 parent ad1dbac commit 6dd5610
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions Ports/JavaSE/src/com/codename1/impl/javase/JavaSEPort.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@
import javax.swing.event.MenuListener;
import javax.swing.event.MouseInputAdapter;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
import javax.swing.text.DefaultCaret;
import javax.swing.text.JTextComponent;
import javax.xml.parsers.DocumentBuilder;
Expand Down Expand Up @@ -3723,7 +3725,7 @@ public void run() {
final JDialog d = new JDialog(frm, true);
d.setLocationRelativeTo(frm);
d.setTitle("Skins");
d.setLayout(new BorderLayout());
d.getContentPane().setLayout(new BorderLayout());
String userDir = System.getProperty("user.home");
final File skinDir = new File(userDir + "/.codenameone/");
if (!skinDir.exists()) {
Expand Down Expand Up @@ -3802,9 +3804,48 @@ public Class<?> getColumnClass(int column) {
return super.getColumnClass(column);
}
};



skinsTable.setRowHeight(112);
skinsTable.getTableHeader().setReorderingAllowed(false);
d.add(new JScrollPane(skinsTable), BorderLayout.CENTER);
final JTextField filter = new JTextField();
final TableRowSorter<DefaultTableModel> sorter = new TableRowSorter<>(((DefaultTableModel) skinsTable.getModel()));

filter.getDocument().addDocumentListener(new javax.swing.event.DocumentListener() {

private void updateFilter() {
try {

RowFilter rf = RowFilter.regexFilter("(?i)"+filter.getText(),2);
sorter.setRowFilter(rf);
} catch (java.util.regex.PatternSyntaxException e) {
return;
}

}

@Override
public void insertUpdate(javax.swing.event.DocumentEvent e) {
updateFilter();
}

@Override
public void removeUpdate(DocumentEvent e) {
updateFilter();
}

@Override
public void changedUpdate(DocumentEvent e) {
updateFilter();
}

});
skinsTable.setRowSorter(sorter);
d.getContentPane().add(filter, BorderLayout.NORTH);


d.getContentPane().add(new JScrollPane(skinsTable), BorderLayout.CENTER);
JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT));
JButton download = new JButton("Download");
download.addActionListener(new ActionListener() {
Expand Down Expand Up @@ -3879,7 +3920,7 @@ public void run() {
}
});
p.add(download);
d.add(p, BorderLayout.SOUTH);
d.getContentPane().add(p, BorderLayout.SOUTH);
d.pack();
pleaseWait.dispose();
d.setVisible(true);
Expand Down

0 comments on commit 6dd5610

Please sign in to comment.