Gui.panels.analyticsguipanels.CondencePanel.java Source code

Java tutorial

Introduction

Here is the source code for Gui.panels.analyticsguipanels.CondencePanel.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Gui.panels.analyticsguipanels;

import java.awt.Color;
import java.awt.event.ActionListener;
import java.util.Vector;
import org.joda.time.DateTime;

/**
 *
 * @author Paris
 */
public class CondencePanel extends javax.swing.JPanel {

    /**
     * Creates new form CondencePanel
     */
    public CondencePanel() {
        initComponents();
        setSize(getPreferredSize());

        all_button.setForeground(Color.green);
        setVisible(true);
    }

    private void resetbuttoncolours() {
        all_button.setForeground(Color.black);
        day_button.setForeground(Color.black);
        week_button.setForeground(Color.black);
        month_button.setForeground(Color.black);
    }

    public int condence_value = 1;

    Vector<ActionListener> changelisteners = new Vector<>();

    public void addChangeListener(ActionListener changelistener) {
        changelisteners.add(changelistener);

    }

    private void statechangedevent() {
        for (int i = 0; i < changelisteners.size(); i++) {
            changelisteners.get(i).actionPerformed(null);
        }
    }

    public boolean is_inside_period(DateTime startdate, DateTime testdate) {

        switch (condence_value) {
        case 1:
            return false;
        case 2:
            return startdate.plusDays(1).isAfter(testdate);
        case 3:
            return startdate.plusDays(7).isAfter(testdate);
        case 4:
            return startdate.plusMonths(1).isAfter(testdate);
        }
        return false;
    }

    /**
     * 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")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        sum_radio_button = new javax.swing.JRadioButton();
        average_radio_button = new javax.swing.JRadioButton();
        jLabel1 = new javax.swing.JLabel();
        day_button = new javax.swing.JButton();
        week_button = new javax.swing.JButton();
        month_button = new javax.swing.JButton();
        all_button = new javax.swing.JButton();

        sum_radio_button.setText("Sum");
        sum_radio_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sum_radio_buttonActionPerformed(evt);
            }
        });

        average_radio_button.setSelected(true);
        average_radio_button.setText("Average");
        average_radio_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                average_radio_buttonActionPerformed(evt);
            }
        });

        jLabel1.setText("Condence Values");

        day_button.setText("Day");
        day_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                day_buttonActionPerformed(evt);
            }
        });

        week_button.setText("Week");
        week_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                week_buttonActionPerformed(evt);
            }
        });

        month_button.setText("Month");
        month_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                month_buttonActionPerformed(evt);
            }
        });

        all_button.setText("All");
        all_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                all_buttonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup().addGap(26, 26, 26)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel1)
                                        .addGroup(layout.createSequentialGroup().addComponent(sum_radio_button)
                                                .addGap(32, 32, 32).addComponent(average_radio_button)))
                                .addGap(24, 24, 24)
                                .addGroup(
                                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                .addComponent(week_button, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(all_button, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(month_button).addComponent(day_button,
                                                javax.swing.GroupLayout.PREFERRED_SIZE, 58,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addContainerGap(20, Short.MAX_VALUE)));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel1).addComponent(all_button).addComponent(day_button))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(average_radio_button).addComponent(sum_radio_button)
                                .addComponent(week_button).addComponent(month_button))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
    }// </editor-fold>//GEN-END:initComponents

    private void sum_radio_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sum_radio_buttonActionPerformed
        average_radio_button.setSelected(false);
        sum_radio_button.setSelected(true);
        statechangedevent();
    }//GEN-LAST:event_sum_radio_buttonActionPerformed

    private void average_radio_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_average_radio_buttonActionPerformed
        average_radio_button.setSelected(true);
        sum_radio_button.setSelected(false);
        statechangedevent();
    }//GEN-LAST:event_average_radio_buttonActionPerformed

    private void day_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_day_buttonActionPerformed
        condence_value = 2;
        statechangedevent();
        resetbuttoncolours();
        day_button.setForeground(Color.green);
    }//GEN-LAST:event_day_buttonActionPerformed

    private void week_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_week_buttonActionPerformed
        condence_value = 3;
        statechangedevent();
        resetbuttoncolours();
        week_button.setForeground(Color.green);
    }//GEN-LAST:event_week_buttonActionPerformed

    private void month_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_month_buttonActionPerformed
        condence_value = 4;
        statechangedevent();
        resetbuttoncolours();
        month_button.setForeground(Color.green);
    }//GEN-LAST:event_month_buttonActionPerformed

    private void all_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_all_buttonActionPerformed
        condence_value = 1;
        statechangedevent();
        resetbuttoncolours();
        all_button.setForeground(Color.green);
    }//GEN-LAST:event_all_buttonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton all_button;
    public javax.swing.JRadioButton average_radio_button;
    private javax.swing.JButton day_button;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JButton month_button;
    public javax.swing.JRadioButton sum_radio_button;
    private javax.swing.JButton week_button;
    // End of variables declaration//GEN-END:variables
}