Сделано задание 2 ЛР4. Осталось доработать.

This commit is contained in:
Victor 2013-11-26 00:54:49 +02:00
parent 851eca861b
commit ac8136ab85
3 changed files with 41 additions and 11 deletions

View File

@ -45,7 +45,7 @@ public class DailyPad extends JFrame {
fileMenu.add(new JMenuItem("Open"));
JMenuItem saveMenuItem = new JMenuItem("Save");
saveMenuItem.setMnemonic(KeyEvent.VK_S);
saveMenuItem.addActionListener(openActionListener);
saveMenuItem.addActionListener(saveActionListener);
fileMenu.add(saveMenuItem);
fileMenu.add(new JMenuItem("Save As"));
JMenuItem exitMenuItem = new JMenuItem("Exit");
@ -66,9 +66,9 @@ public class DailyPad extends JFrame {
JButton newButton = new JButton(UIManager.getIcon("Tree.collapsedIcon"));
newButton.addActionListener(newActionListener);
toolbar.add(newButton);
JButton openButton = new JButton(UIManager.getIcon("Tree.openIcon"));
openButton.addActionListener(openActionListener);
toolbar.add(openButton);
JButton saveButton = new JButton(UIManager.getIcon("Tree.openIcon"));
saveButton.addActionListener(saveActionListener);
toolbar.add(saveButton);
JButton exitButton = new JButton(UIManager.getIcon("FileChooser.upFolderIcon"));
exitButton.addActionListener(exitActionListener);
toolbar.add(exitButton);
@ -78,12 +78,14 @@ public class DailyPad extends JFrame {
private final ActionListener newActionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
panel.onNewMenuItemSelected();
}
};
private final ActionListener openActionListener = new ActionListener() {
private final ActionListener saveActionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
panel.onSaveMenuItemSelected();
}
};

View File

@ -58,9 +58,12 @@ public class NotePadManager {
pad.setDescription(desc);
pad.setDate(date);
pad.setImportant(important);
saveToCSV(FILENAME, notepads);
return;
}
}
saveToCSV(FILENAME, notepads);
// Не нашли что обновлять - добавляем
createNewEntry(name, desc, date, important);
}
private void saveToCSV(String filename, ArrayList<NotePad> list) {

View File

@ -12,6 +12,7 @@ import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
@ -29,8 +30,9 @@ public class PadPanel extends JPanel {
private int padIndex;
public PadPanel() {
padIndex = 0;
initComponents();
padIndex = -1;
selectNextNotePad();
}
@SuppressWarnings("unchecked")
@ -138,20 +140,42 @@ public class PadPanel extends JPanel {
}//GEN-END:initComponents
private void applyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyButtonActionPerformed
// TODO add your handling code here:
String name = eventName.getText();
String description = descriptionTextArea.getText();
Date date = (Date) dateSpinner.getValue();
boolean important = importantCheckBox.isSelected();
NotePadManager.getInstance().updateEntry(name, description, date, important);
}//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
public void onNewMenuItemSelected() {
eventName.setText("");
descriptionTextArea.setText("");
dateSpinner.setValue(new Date(System.currentTimeMillis()));
importantCheckBox.setSelected(false);
}
public void onSaveMenuItemSelected() {
String name = eventName.getText();
if (NotePadManager.getInstance().isNotePadExists(name)) {
JOptionPane.showMessageDialog(this, "Такая запись уже была. Нажмите применить"
+ " для обновления данных или введите другое имя", "Ошибка", JOptionPane.ERROR_MESSAGE);
return;
}
String description = descriptionTextArea.getText();
Date date = (Date) dateSpinner.getValue();
boolean important = importantCheckBox.isSelected();
NotePadManager.getInstance().createNewEntry(name, description, date, important);
}
private void selectPreviousNotePad() {
if (padIndex <= 0) return;
padIndex--;
@ -173,6 +197,7 @@ public class PadPanel extends JPanel {
}
private NotePad getNotePad() {
System.out.println(padIndex);
return NotePadManager.getInstance().getNotepads().get(padIndex);
}