diff --git a/src/tse/lr4/PadPanel.form b/src/tse/lr4/PadPanel.form index 0c84ca6..11459fc 100644 --- a/src/tse/lr4/PadPanel.form +++ b/src/tse/lr4/PadPanel.form @@ -85,6 +85,10 @@ + + + + @@ -103,6 +107,10 @@ + + + + @@ -117,26 +125,43 @@ + + + + + + + + + + + + + + + + + diff --git a/src/tse/lr4/PadPanel.java b/src/tse/lr4/PadPanel.java index be39a23..c40a214 100644 --- a/src/tse/lr4/PadPanel.java +++ b/src/tse/lr4/PadPanel.java @@ -3,12 +3,16 @@ package tse.lr4; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import javax.swing.GroupLayout; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JLabel; +import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JSpinner; import javax.swing.JTextArea; @@ -20,32 +24,26 @@ import javax.swing.SpinnerDateModel; * * @author aNNiMON */ -public class PadPanel extends javax.swing.JPanel { - - /** - * Creates new form PadPanel - */ +public class PadPanel extends JPanel { + + private int padIndex; + public PadPanel() { + padIndex = 0; 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 eventLabel = new JLabel(); - JTextField eventName = new JTextField(); + eventName = new JTextField(); JLabel descriptionLabel = new JLabel(); JScrollPane jScrollPane1 = new JScrollPane(); - JTextArea descriptionTextArea = new JTextArea(); + descriptionTextArea = new JTextArea(); JLabel dateTimeLabel = new JLabel(); - JSpinner dateSpinner = new JSpinner(); - JCheckBox importantCheckBox = new JCheckBox(); + dateSpinner = new JSpinner(); + importantCheckBox = new JCheckBox(); JButton applyButton = new JButton(); JButton prevButton = new JButton(); JButton nextButton = new JButton(); @@ -65,10 +63,25 @@ public class PadPanel extends javax.swing.JPanel { importantCheckBox.setText("Важное"); applyButton.setText("Применить"); + applyButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + applyButtonActionPerformed(evt); + } + }); prevButton.setText("<<"); + prevButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + prevButtonActionPerformed(evt); + } + }); nextButton.setText(">>"); + nextButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + nextButtonActionPerformed(evt); + } + }); GroupLayout layout = new GroupLayout(this); this.setLayout(layout); @@ -124,7 +137,53 @@ public class PadPanel extends javax.swing.JPanel { ); }//GEN-END:initComponents + private void applyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyButtonActionPerformed + // TODO add your handling code here: + + }//GEN-LAST:event_applyButtonActionPerformed + + private void prevButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_prevButtonActionPerformed + // TODO add your handling code here: + selectPreviousNotePad(); + }//GEN-LAST:event_prevButtonActionPerformed + + private void nextButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_nextButtonActionPerformed + // TODO add your handling code here: + selectNextNotePad(); + }//GEN-LAST:event_nextButtonActionPerformed + + private void selectPreviousNotePad() { + if (padIndex <= 0) return; + padIndex--; + selectNotePad(getNotePad()); + } + + private void selectNextNotePad() { + if (padIndex >= getNotepads().size() - 1) return; + padIndex++; + selectNotePad(getNotePad()); + } + + private void selectNotePad(NotePad pad) { + if (pad == null) return; + eventName.setText(pad.getName()); + descriptionTextArea.setText(pad.getDescription()); + dateSpinner.setValue(pad.getDate()); + importantCheckBox.setSelected(pad.isImportant()); + } + + private NotePad getNotePad() { + return NotePadManager.getInstance().getNotepads().get(padIndex); + } + + private ArrayList getNotepads() { + return NotePadManager.getInstance().getNotepads(); + } // Variables declaration - do not modify//GEN-BEGIN:variables + private JSpinner dateSpinner; + private JTextArea descriptionTextArea; + private JTextField eventName; + private JCheckBox importantCheckBox; // End of variables declaration//GEN-END:variables }