From 257a139c7a9fbcb108c33cc6c8ef7b0e4302e6b2 Mon Sep 17 00:00:00 2001 From: Victor Date: Tue, 26 Nov 2013 10:13:43 +0200 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=20=D1=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BF=D0=B8=D1=81=D0=B5=D0=B9=20=D0=B5=D0=B6=D0=B5?= =?UTF-8?q?=D0=B4=D0=BD=D0=B5=D0=B2=D0=BD=D0=B8=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tse/lr4/FilterPanel.form | 140 +++++++++++++++++++++++++++++++ src/tse/lr4/FilterPanel.java | 154 +++++++++++++++++++++++++++++++++++ 2 files changed, 294 insertions(+) create mode 100644 src/tse/lr4/FilterPanel.form create mode 100644 src/tse/lr4/FilterPanel.java diff --git a/src/tse/lr4/FilterPanel.form b/src/tse/lr4/FilterPanel.form new file mode 100644 index 0000000..5437eca --- /dev/null +++ b/src/tse/lr4/FilterPanel.form @@ -0,0 +1,140 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/tse/lr4/FilterPanel.java b/src/tse/lr4/FilterPanel.java new file mode 100644 index 0000000..4656293 --- /dev/null +++ b/src/tse/lr4/FilterPanel.java @@ -0,0 +1,154 @@ +/* + */ + +package tse.lr4; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Date; +import java.util.Vector; +import javax.swing.GroupLayout; +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JScrollPane; +import javax.swing.JSpinner; +import javax.swing.JTextField; +import javax.swing.LayoutStyle; +import javax.swing.SpinnerDateModel; + +/** + * + * @author aNNiMON + */ +public class FilterPanel extends javax.swing.JPanel { + + /** + * Creates new form FilterPanel + */ + public FilterPanel() { + initComponents(); + } + + /** + * This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + private void initComponents() {//GEN-BEGIN:initComponents + + JLabel jLabel1 = new JLabel(); + dateFromSpinner = new JSpinner(); + dateToSpinner = new JSpinner(); + JLabel jLabel2 = new JLabel(); + searchTextField = new JTextField(); + JScrollPane jScrollPane1 = new JScrollPane(); + noteList = new JList(); + JButton filterButton = new JButton(); + + jLabel1.setText("Фильтр по дате:"); + + dateFromSpinner.setModel(new SpinnerDateModel()); + + dateToSpinner.setModel(new SpinnerDateModel()); + + jLabel2.setText("Фильтр по фразе:"); + + noteList.setModel(new NotePadModel()); + jScrollPane1.setViewportView(noteList); + + filterButton.setText("Фильтр"); + filterButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + filterButtonActionPerformed(evt); + } + }); + + GroupLayout layout = new GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel2) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(searchTextField, GroupLayout.PREFERRED_SIZE, 230, GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel1) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(dateFromSpinner, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(dateToSpinner, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(filterButton, GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(jLabel1) + .addComponent(dateFromSpinner, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(dateToSpinner, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(jLabel2) + .addComponent(searchTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))) + .addComponent(filterButton, GroupLayout.DEFAULT_SIZE, 54, Short.MAX_VALUE)) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jScrollPane1, GroupLayout.DEFAULT_SIZE, 213, Short.MAX_VALUE) + .addContainerGap()) + ); + }//GEN-END:initComponents + + private void filterButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_filterButtonActionPerformed + String keyword = searchTextField.getText(); + Date from = (Date) dateFromSpinner.getValue(); + Date to = (Date) dateToSpinner.getValue(); + if (from.after(to)) { + Date temp = to; + to = from; + from = temp; + } + + Vector vector = new Vector<>(); + for (NotePad notePad : NotePadManager.getInstance().getNotepads()) { + boolean isFilterSuccess = false; + if (!keyword.isEmpty()) { + // Фильтр по значению + if (notePad.getDescription().indexOf(keyword) >= 0) { + isFilterSuccess = true; + } + if (notePad.getName().indexOf(keyword) >= 0) { + isFilterSuccess = true; + } + } + // Фильтр по дате + Date current = notePad.getDate(); + if (from.before(current) && to.after(current)) { + isFilterSuccess = true; + } + + if (isFilterSuccess) vector.add(notePad); + } + noteList.setListData(vector); + }//GEN-LAST:event_filterButtonActionPerformed + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private JSpinner dateFromSpinner; + private JSpinner dateToSpinner; + private JList noteList; + private JTextField searchTextField; + // End of variables declaration//GEN-END:variables +}