Package tvbrowser.core.filters.filtercomponents

Source Code of tvbrowser.core.filters.filtercomponents.DateFilterComponent

* Copyright Michael Keppler
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <>.
package tvbrowser.core.filters.filtercomponents;

import java.awt.BorderLayout;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;

import util.ui.UiUtilities;

import com.jgoodies.forms.factories.Borders;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.RowSpec;

import devplugin.Date;
import devplugin.Program;

* filter component to filter for a relative date range (e.g. from current date
* to current date + 7 days)
* @author Bananeweizen
public class DateFilterComponent extends AbstractFilterComponent {

  private static final util.ui.Localizer mLocalizer = util.ui.Localizer
  private JSpinner mFromSpinner;
  private JSpinner mToSpinner;
  private int mStartDays = 0;
  private int mEndDays = 7;

  public DateFilterComponent(String name, String description) {
    super(name, description);

  public DateFilterComponent() {
    this("", "");

  public boolean accept(final Program program) {
    final Date progDate = program.getDate();
    Date currentDate = Date.getCurrentDate();
    Date mStartDate = currentDate.addDays(mStartDays);
    Date mEndDate = currentDate.addDays(mEndDays);
    return mStartDate.compareTo(progDate) <= 0
        && progDate.compareTo(mEndDate) <= 0;

  public JPanel getSettingsPanel() {

    FormLayout layout = new FormLayout(
        "pref, 3dlu, fill:pref:grow, 3dlu, pref", "");
    JPanel content = new JPanel(layout);

    CellConstraints cc = new CellConstraints();
    int currentRow = 1;

        .msg("description", "")), cc.xyw(1, currentRow, 5));


    content.add(new JLabel(mLocalizer.msg("from.1", "From today plus")), cc.xy(
        1, currentRow += 2));
    mFromSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 28, 1));
    content.add(mFromSpinner, cc.xy(3, currentRow));
    content.add(new JLabel(mLocalizer.msg("from.2", "days")), cc.xy(5,


    content.add(new JLabel(mLocalizer.msg("to.1", "Until today plus")), cc.xy(
        1, currentRow += 2));
    mToSpinner = new JSpinner(new SpinnerNumberModel(7, 0, 28, 1));
    content.add(mToSpinner, cc.xy(3, currentRow));
    content.add(new JLabel(mLocalizer.msg("to.2", "days")), cc
        .xy(5, currentRow));

    JPanel centerPanel = new JPanel(new BorderLayout());
    centerPanel.add(content, BorderLayout.NORTH);
    return centerPanel;

  public int getVersion() {
    return 1;

  public void read(ObjectInputStream in, int version) throws IOException,
      ClassNotFoundException {
    mStartDays = in.readInt();
    mEndDays = in.readInt();

  public void saveSettings() {
    mStartDays = (Integer) mFromSpinner.getValue();
    mEndDays = (Integer) mToSpinner.getValue();

  public void write(ObjectOutputStream out) throws IOException {

  public String toString() {
    return mLocalizer.msg("date", "Date");


Related Classes of tvbrowser.core.filters.filtercomponents.DateFilterComponent

Copyright © 2018 All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact