Added search bar adn some bug fiexs
This commit is contained in:
parent
26ec570637
commit
de0ae85918
3 changed files with 43 additions and 12 deletions
|
@ -117,6 +117,7 @@ public class Article {
|
||||||
|
|
||||||
|
|
||||||
public void open(){
|
public void open(){
|
||||||
|
if(getURL() == null) return;
|
||||||
Desktop desktop;
|
Desktop desktop;
|
||||||
if(Desktop.isDesktopSupported() && (desktop = Desktop.getDesktop()).isSupported(Desktop.Action.BROWSE)){
|
if(Desktop.isDesktopSupported() && (desktop = Desktop.getDesktop()).isSupported(Desktop.Action.BROWSE)){
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
package eu.toldi.rss;
|
package eu.toldi.rss;
|
||||||
|
|
||||||
import org.xml.sax.helpers.DefaultHandler;
|
|
||||||
|
|
||||||
import javax.naming.ldap.SortKey;
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.event.TreeSelectionEvent;
|
import javax.swing.event.DocumentEvent;
|
||||||
import javax.swing.event.TreeSelectionListener;
|
import javax.swing.event.DocumentListener;
|
||||||
import javax.swing.table.TableRowSorter;
|
import javax.swing.table.TableRowSorter;
|
||||||
import javax.swing.tree.*;
|
import javax.swing.tree.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
@ -34,12 +31,13 @@ public class FeedFrame extends JFrame {
|
||||||
private DefaultMutableTreeNode treeRoot;
|
private DefaultMutableTreeNode treeRoot;
|
||||||
|
|
||||||
public FeedFrame() {
|
public FeedFrame() {
|
||||||
|
|
||||||
setTitle("RSS Feed reader");
|
setTitle("RSS Feed reader");
|
||||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||||
setMinimumSize(new Dimension(900, 600));
|
setMinimumSize(new Dimension(900, 600));
|
||||||
initData();
|
initData();
|
||||||
initComponents();
|
initComponents();
|
||||||
|
UpdaterThread updater = new UpdaterThread(data,table);
|
||||||
|
updater.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initData() {
|
private void initData() {
|
||||||
|
@ -65,7 +63,36 @@ public class FeedFrame extends JFrame {
|
||||||
|
|
||||||
table.setRowSorter(sorter);
|
table.setRowSorter(sorter);
|
||||||
add(scrollPane, BorderLayout.CENTER);
|
add(scrollPane, BorderLayout.CENTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initSearchBar(){
|
||||||
|
JTextField searchBox = new JTextField();
|
||||||
|
searchBox.setColumns(50);
|
||||||
|
searchBox.getDocument().addDocumentListener(new DocumentListener() {
|
||||||
|
public void changedUpdate(DocumentEvent e) {
|
||||||
|
search();
|
||||||
|
}
|
||||||
|
public void removeUpdate(DocumentEvent e) {
|
||||||
|
search();
|
||||||
|
}
|
||||||
|
public void insertUpdate(DocumentEvent e) {
|
||||||
|
search();
|
||||||
|
}
|
||||||
|
public void search(){
|
||||||
|
String text = searchBox.getText();
|
||||||
|
if (text.trim().length() == 0) {
|
||||||
|
sorter.setRowFilter(null);
|
||||||
|
} else {
|
||||||
|
sorter.setRowFilter(RowFilter.regexFilter("(?i)" + text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
JPanel searchPanel = new JPanel(new BorderLayout());
|
||||||
|
JLabel searchText = new JLabel("Search:",JLabel.LEFT);
|
||||||
|
searchPanel.setLayout(new FlowLayout());
|
||||||
|
searchPanel.add(searchText);
|
||||||
|
searchPanel.add(searchBox);
|
||||||
|
add(searchPanel, BorderLayout.NORTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initMenuBar() {
|
private void initMenuBar() {
|
||||||
|
@ -116,6 +143,7 @@ public class FeedFrame extends JFrame {
|
||||||
ImageIcon icon = new ImageIcon(this.getClass().getResource("/icon.png"));
|
ImageIcon icon = new ImageIcon(this.getClass().getResource("/icon.png"));
|
||||||
this.setIconImage(icon.getImage());
|
this.setIconImage(icon.getImage());
|
||||||
initTable();
|
initTable();
|
||||||
|
initSearchBar();
|
||||||
initMenuBar();
|
initMenuBar();
|
||||||
initTree();
|
initTree();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package eu.toldi.rss;
|
package eu.toldi.rss;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
import javax.swing.table.TableRowSorter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class UpdaterThread extends Thread{
|
public class UpdaterThread extends Thread{
|
||||||
|
@ -15,6 +16,11 @@ public class UpdaterThread extends Thread{
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while (true) {
|
while (true) {
|
||||||
|
try {
|
||||||
|
sleep(60 * 1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
for (Feed f : data.getFeeds()) {
|
for (Feed f : data.getFeeds()) {
|
||||||
try {
|
try {
|
||||||
f.updateFeed();
|
f.updateFeed();
|
||||||
|
@ -22,14 +28,10 @@ public class UpdaterThread extends Thread{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RowSorter sorter = table.getRowSorter();
|
TableRowSorter<FeedData> sorter = (TableRowSorter<FeedData>) table.getRowSorter();
|
||||||
table.setModel(data);
|
table.setModel(data);
|
||||||
|
table.setRowSorter(sorter);
|
||||||
table.updateUI();
|
table.updateUI();
|
||||||
try {
|
|
||||||
sleep(60 * 1000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue