Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.event.WindowEvent;
- import java.io.FileNotFoundException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import org.jdesktop.application.Action;
- import org.jdesktop.application.ResourceMap;
- import org.jdesktop.application.SingleFrameApplication;
- import org.jdesktop.application.FrameView;
- import org.jdesktop.application.TaskMonitor;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.WindowListener;
- import java.io.File;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Calendar;
- import java.util.Scanner;
- import javax.swing.Timer;
- import javax.swing.Icon;
- import javax.swing.JButton;
- import javax.swing.JDialog;
- import javax.swing.JFileChooser;
- import javax.swing.JFrame;
- import javax.swing.JOptionPane;
- import javax.swing.table.DefaultTableModel;
- /**
- * The application's main frame.
- */
- public class NMRLogView extends FrameView {
- String warningLog = "";
- SimpleDateFormat shortForm = new SimpleDateFormat("MMM d, yyyy");
- File prefs = new File("sub.txt");
- ArrayList<User> users = new ArrayList<User>();
- public NMRLogView(SingleFrameApplication app) {
- super(app);
- initComponents();
- this.getFrame().addWindowListener(new WindowListener() {
- public void windowOpened(WindowEvent e) {
- }
- public void windowClosing(WindowEvent e) {
- FileWriter fw = null;
- try {
- fw = new FileWriter(prefs);
- fw.write(startMonth.getSelectedIndex() + "," + startYear.getText() + ","
- + endMonth.getSelectedIndex() + "," + endYear.getText() + "," +
- moneyField.getText());
- fw.flush();
- fw.close();
- } catch (IOException ex) {
- Logger.getLogger(NMRLogView.class.getName()).log(Level.SEVERE, null, ex);
- } finally {
- try {
- fw.close();
- } catch (IOException ex) {
- Logger.getLogger(NMRLogView.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
- public void windowClosed(WindowEvent e) {
- }
- public void windowIconified(WindowEvent e) {
- }
- public void windowDeiconified(WindowEvent e) {
- }
- public void windowActivated(WindowEvent e) {
- }
- public void windowDeactivated(WindowEvent e) {
- }
- });
- boolean prefsLoaded = false;
- if(prefs.exists()) {
- try {
- Scanner sc = new Scanner(new FileReader(prefs));
- sc.useDelimiter(",");
- startMonth.setSelectedIndex(Integer.parseInt(sc.next()));
- startYear.setText(sc.next());
- endMonth.setSelectedIndex(Integer.parseInt(sc.next()));
- endYear.setText(sc.next());
- moneyField.setText(sc.next());
- prefsLoaded = true;
- } catch (FileNotFoundException ex) {
- Logger.getLogger(NMRLogView.class.getName()).log(Level.SEVERE, null, ex);
- } catch (NumberFormatException e) {
- System.out.println("Preferences file not formatted correctly, resetting it.");
- }
- }
- else if(!prefsLoaded) {
- try {
- prefs.createNewFile();
- FileWriter fw = new FileWriter(prefs);
- fw.write(startMonth.getSelectedIndex() + "," + startYear.getText() + ","
- + endMonth.getSelectedIndex() + "," + endYear.getText() + "," +
- moneyField.getText());
- fw.flush();
- fw.close();
- } catch (IOException ex) {
- Logger.getLogger(NMRLogView.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- logButton.setVisible(false);
- // status bar initialization - message timeout, idle icon and busy animation, etc
- ResourceMap resourceMap = getResourceMap();
- int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
- messageTimer = new Timer(messageTimeout, new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- }
- });
- messageTimer.setRepeats(false);
- int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
- for (int i = 0; i < busyIcons.length; i++) {
- busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
- }
- busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
- }
- });
- idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
- // connecting action tasks to status bar via TaskMonitor
- TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
- }
- @Action
- public void showAboutBox() {
- if (aboutBox == null) {
- JFrame mainFrame = NMRLogApp.getApplication().getMainFrame();
- aboutBox = new NMRLogAboutBox(mainFrame);
- aboutBox.setLocationRelativeTo(mainFrame);
- }
- NMRLogApp.getApplication().show(aboutBox);
- }
- /** 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">
- private void initComponents() {
- mainPanel = new javax.swing.JPanel();
- startMonth = new javax.swing.JComboBox();
- startYear = new javax.swing.JTextField();
- endMonth = new javax.swing.JComboBox();
- endYear = new javax.swing.JTextField();
- runButton = new javax.swing.JToggleButton();
- jLabel1 = new javax.swing.JLabel();
- moneyField = new javax.swing.JTextField();
- logButton = new javax.swing.JButton();
- jScrollPane1 = new javax.swing.JScrollPane();
- table = new javax.swing.JTable();
- jLabel2 = new javax.swing.JLabel();
- menuBar = new javax.swing.JMenuBar();
- javax.swing.JMenu fileMenu = new javax.swing.JMenu();
- jMenuItem1 = new javax.swing.JMenuItem();
- jMenuItem2 = new javax.swing.JMenuItem();
- javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
- javax.swing.JMenu helpMenu = new javax.swing.JMenu();
- javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
- mainPanel.setName("mainPanel"); // NOI18N
- startMonth.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }));
- startMonth.setName("startMonth"); // NOI18N
- startMonth.addComponentListener(new java.awt.event.ComponentAdapter() {
- public void componentHidden(java.awt.event.ComponentEvent evt) {
- startMonthComponentHidden(evt);
- }
- });
- org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(nmrlog.NMRLogApp.class).getContext().getResourceMap(NMRLogView.class);
- startYear.setText(resourceMap.getString("startYear.text")); // NOI18N
- startYear.setName("startYear"); // NOI18N
- endMonth.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }));
- endMonth.setName("endMonth"); // NOI18N
- endYear.setText(resourceMap.getString("endYear.text")); // NOI18N
- endYear.setName("endYear"); // NOI18N
- runButton.setText(resourceMap.getString("runButton.text")); // NOI18N
- runButton.setName("runButton"); // NOI18N
- runButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- runButtonActionPerformed(evt);
- }
- });
- jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
- jLabel1.setName("jLabel1"); // NOI18N
- moneyField.setText(resourceMap.getString("moneyField.text")); // NOI18N
- moneyField.setName("moneyField"); // NOI18N
- logButton.setText(resourceMap.getString("logButton.text")); // NOI18N
- logButton.setName("logButton"); // NOI18N
- logButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- logButtonActionPerformed(evt);
- }
- });
- jScrollPane1.setName("jScrollPane1"); // NOI18N
- table.setAutoCreateRowSorter(true);
- table.setModel(new javax.swing.table.DefaultTableModel(
- new Object [][] {
- },
- new String [] {
- "User", "Time", "Cost"
- }
- ));
- table.setName("table"); // NOI18N
- table.setShowHorizontalLines(false);
- table.setShowVerticalLines(false);
- jScrollPane1.setViewportView(table);
- table.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("table.columnModel.title0")); // NOI18N
- table.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("table.columnModel.title1")); // NOI18N
- table.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("table.columnModel.title2")); // NOI18N
- jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
- jLabel2.setName("jLabel2"); // NOI18N
- javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
- mainPanel.setLayout(mainPanelLayout);
- mainPanelLayout.setHorizontalGroup(
- mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(mainPanelLayout.createSequentialGroup()
- .addContainerGap()
- .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 414, Short.MAX_VALUE)
- .addGroup(mainPanelLayout.createSequentialGroup()
- .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(logButton)
- .addComponent(startMonth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(startYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(mainPanelLayout.createSequentialGroup()
- .addComponent(jLabel1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(endMonth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(endYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
- .addComponent(jLabel2)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(moneyField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(runButton, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addGap(143, 143, 143)))
- .addContainerGap())
- );
- mainPanelLayout.setVerticalGroup(
- mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(mainPanelLayout.createSequentialGroup()
- .addContainerGap()
- .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(startMonth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(startYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel1)
- .addComponent(endMonth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(endYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(logButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(runButton)
- .addComponent(moneyField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel2))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 392, Short.MAX_VALUE)
- .addContainerGap())
- );
- menuBar.setName("menuBar"); // NOI18N
- fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
- fileMenu.setName("fileMenu"); // NOI18N
- javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(nmrlog.NMRLogApp.class).getContext().getActionMap(NMRLogView.class, this);
- jMenuItem1.setAction(actionMap.get("save")); // NOI18N
- jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
- jMenuItem1.setText(resourceMap.getString("jMenuItem1.text")); // NOI18N
- jMenuItem1.setName("jMenuItem1"); // NOI18N
- jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jMenuItem1ActionPerformed(evt);
- }
- });
- fileMenu.add(jMenuItem1);
- jMenuItem2.setAction(actionMap.get("inspect")); // NOI18N
- jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_I, java.awt.event.InputEvent.CTRL_MASK));
- jMenuItem2.setText(resourceMap.getString("jMenuItem2.text")); // NOI18N
- jMenuItem2.setName("jMenuItem2"); // NOI18N
- fileMenu.add(jMenuItem2);
- exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
- exitMenuItem.setName("exitMenuItem"); // NOI18N
- fileMenu.add(exitMenuItem);
- menuBar.add(fileMenu);
- helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
- helpMenu.setName("helpMenu"); // NOI18N
- aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
- aboutMenuItem.setName("aboutMenuItem"); // NOI18N
- helpMenu.add(aboutMenuItem);
- menuBar.add(helpMenu);
- setComponent(mainPanel);
- setMenuBar(menuBar);
- }// </editor-fold>
- private void startMonthComponentHidden(java.awt.event.ComponentEvent evt) {
- // TODO add your handling code here:
- }
- //When you run!
- private void runButtonActionPerformed(java.awt.event.ActionEvent evt) {
- int sMonth = startMonth.getSelectedIndex();
- int eMonth = endMonth.getSelectedIndex();
- int sYear;
- int eYear;
- double money;
- warningLog = "";
- DefaultTableModel dm = (DefaultTableModel) table.getModel();
- int rowCount = dm.getRowCount();
- //Remove rows one by one from the end of the table
- for (int i = rowCount - 1; i >= 0; i--) {
- dm.removeRow(i);
- }
- boolean warning = false;
- File logFile = new File("log.txt");
- try {
- //Read the starting and ending conditions from the JComboBox and JTextBox
- sYear = Integer.parseInt(startYear.getText());
- eYear = Integer.parseInt(endYear.getText());
- money = Double.parseDouble(moneyField.getText());
- //instantiates start and end calendars, processes year and month
- Calendar entryStartCal = Calendar.getInstance();
- Calendar entryEndCal = Calendar.getInstance();
- entryStartCal.set(sYear,sMonth,1);
- entryEndCal.set(eYear,eMonth,1);
- entryStartCal.set(Calendar.HOUR_OF_DAY,0);
- entryEndCal.set(Calendar.HOUR_OF_DAY,0);
- entryStartCal.set(Calendar.MINUTE,0);
- entryEndCal.set(Calendar.MINUTE,0);
- entryStartCal.set(Calendar.SECOND,0);
- entryEndCal.set(Calendar.SECOND,0);
- System.out.println(entryEndCal.getTime());
- //verifies start date is before end date
- if(entryEndCal.before(entryStartCal)) {
- JOptionPane.showMessageDialog(this.mainPanel, "The beginning date (left) must be before the end date (right). \r\n log file will not be read.");
- return;
- }
- //Begin reading entries from logFile.
- ArrayList<Entry> entries = new ArrayList<Entry>();
- int entryCount = 0;
- String temp = "";
- try {
- Scanner sc = new Scanner(new FileReader(new File("log.txt")));
- sc.useDelimiter("\n");
- SimpleDateFormat form = new SimpleDateFormat("yyyy");
- int year = Integer.parseInt(form.format(Calendar.getInstance().getTime()));
- entryCount = 0;
- int lastMonth = -1;
- while(sc.hasNext()) {
- temp = sc.next();
- if(temp.contains("console") && !temp.contains("still logged in")) {
- int thisMonth = Entry.getMonth(temp);
- if(thisMonth == 11 && lastMonth == 0)
- year--;
- entries.add(new Entry(temp,entryCount,year));
- entryCount++;
- lastMonth = Entry.getMonth(temp);
- }
- }
- } catch (IOException e) { e.printStackTrace();}
- catch (ParseException e) { warning = true; String warningString = "Parse error on entry" + entryCount + "\r\n" +
- "String: " + temp;
- warningLog += warningString;}
- catch (NumberFormatException e) { warning = true; String warningString = "Number format exception caught on entry " + entryCount + "\r\n" +
- "String: " + temp;
- warningLog += warningString; }
- catch(StringIndexOutOfBoundsException e) {warning = true; String warningString = "Parse error on entry " + entryCount + "\r\n" +
- "String: " + temp;
- warningLog += warningString;
- }
- warningLog += entryCount + " entries processed.\r\n\r\n";
- //Begin processing entries that start on entryStartCal and end on entryEndCal
- users = new ArrayList<User>();
- int entriesInRange = 0;
- for(int i=0;i<entries.size();i++) {
- Entry entry = entries.get(i);
- Calendar loginCalendar = Calendar.getInstance();
- loginCalendar.setTime(entry.getDate());
- //Check if it's in the right date range
- if(entryStartCal.before(loginCalendar) && entryEndCal.after(loginCalendar)){
- boolean foundUser = false;
- //Go through the users...
- for(User user : users) {
- //If the user is already in the list of users, add the minutes
- if(entry.getUser().equals(user.getName())) {
- foundUser = true;
- user.addMinutes(entry.getMinutes());
- if(entry.getMinutes() > 2880) {
- warning = true;
- int dayNum = entry.getMinutes() / 1440;
- String warningString = "Entry longer than " + dayNum + " days detected for user " + user.getName() +
- "." + "\r\n" + " Details: Entry line " + i + " on " + shortForm.format(loginCalendar.getTime()) + "\r\n";
- warningLog += warningString;
- }
- entriesInRange++;
- user.addEntry(entry.getMinutes() + " m on " + shortForm.format(entry.getDate()));
- break;
- }
- }
- //If it didn't find the user, add a new user with those minutes
- if(!foundUser) {
- int minutes = entry.getMinutes();
- if(minutes > 2880) {
- warning = true;
- int dayNum = entry.getMinutes() / 1440;
- String warningString = "Entry longer than " + dayNum + " days detected for user " + entry.getUser() +
- "." + "\r\n" + " Details: Entry line " + i + " on " + shortForm.format(loginCalendar.getTime()) + "\r\n";
- warningLog += warningString;
- }
- User newUser = new User(entry.getUser(),minutes);
- users.add(newUser);
- entriesInRange++;
- newUser.addEntry(minutes + " m on " + shortForm.format(entry.getDate()));
- }
- }
- }
- warningLog += entriesInRange + " entries processed in the time range.\r\n\r\n";
- //Print out what we've found by processing the entries
- String toPrint = "";
- for(User user : users) {
- Double cost = (double) user.getMinutes();
- cost = cost / 60.0;
- cost = cost * money;
- String costString = String.format("%.2f",cost);
- toPrint += user + " $" + costString + "\r\n";
- DefaultTableModel model = (DefaultTableModel) table.getModel();
- model.addRow(new String[]{user.getName(),user.getTime(),"$" + costString});
- }
- if(warning) {
- logButton.setBackground(Color.red);
- logButton.setVisible(true);
- }
- else {
- logButton.setVisible(true);
- warningLog += "NMRLog ran without errors.";
- }
- } catch (NumberFormatException e) {
- JOptionPane.showMessageDialog(this.mainPanel, "Subs funning");
- }
- }
- @Action
- public void save() {
- JFileChooser jfc = new JFileChooser(new File("output.txt"));
- int returnVal = jfc.showSaveDialog(this.getFrame());
- if(returnVal == JFileChooser.APPROVE_OPTION) {
- File outputFile = jfc.getSelectedFile();
- if(outputFile.toString().contains("log.txt")) {
- JOptionPane.showMessageDialog(this.mainPanel, "Subs.txt init");
- }
- else {
- try {
- if(!outputFile.getName().contains(".txt"))
- outputFile = new File(outputFile.getPath() + ".txt");
- if(outputFile.toString().contains("log.txt")) {
- JOptionPane.showMessageDialog(this.mainPanel, "subs.txt");
- }
- if(!outputFile.exists())
- outputFile.createNewFile();
- FileWriter fw = new FileWriter(outputFile);
- fw.write("Run on: " + (Calendar.getInstance().getTime())+"\r\n");
- int sYear;
- int eYear;
- int sMonth = startMonth.getSelectedIndex();
- int eMonth = endMonth.getSelectedIndex();
- sYear = Integer.parseInt(startYear.getText());
- eYear = Integer.parseInt(endYear.getText());
- //instantiates start and end calendars, processes year and month
- Calendar entryStartCal = Calendar.getInstance();
- Calendar entryEndCal = Calendar.getInstance();
- entryStartCal.set(sYear,sMonth,1);
- entryEndCal.set(eYear,eMonth,1);
- fw.write("From " + shortForm.format(entryStartCal.getTime()) + " to " +
- shortForm.format(entryEndCal.getTime()) + "\r\n\r\n");
- DefaultTableModel dm = (DefaultTableModel) table.getModel();
- int rowCount = dm.getRowCount();
- //Remove rows one by one from the end of the table
- for (int i = rowCount - 1; i >= 0; i--) {
- fw.write(dm.getValueAt(i, 0)+" " + dm.getValueAt(i, 1) + " " + dm.getValueAt(i, 2) + "\r\n");
- }
- fw.flush();
- fw.close();
- } catch (IOException ex) {
- JOptionPane.showMessageDialog(this.mainPanel, "Failed to write save file.");
- Logger.getLogger(NMRLogView.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
- }
- @Action
- public void inspect() {
- int rowIndex=table.getSelectedRow();
- String userSelected = (String) table.getValueAt(rowIndex,0);
- for(User user : users) {
- if(user.getName().contains(userSelected)) {
- JOptionPane.showMessageDialog(this.mainPanel, user.getEntrySummary());
- break;
- }
- }
- }
- private void logButtonActionPerformed(java.awt.event.ActionEvent evt) {
- logButton.setBackground(new JButton().getBackground());
- logButton.setVisible(false);
- JOptionPane.showMessageDialog(this.mainPanel, warningLog);
- }
- private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
- }
- // Variables declaration - do not modify
- private javax.swing.JComboBox endMonth;
- private javax.swing.JTextField endYear;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JMenuItem jMenuItem1;
- private javax.swing.JMenuItem jMenuItem2;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JButton logButton;
- private javax.swing.JPanel mainPanel;
- private javax.swing.JMenuBar menuBar;
- private javax.swing.JTextField moneyField;
- private javax.swing.JToggleButton runButton;
- private javax.swing.JComboBox startMonth;
- private javax.swing.JTextField startYear;
- private javax.swing.JTable table;
- // End of variables declaration
- private final Timer messageTimer;
- private final Timer busyIconTimer;
- private final Icon idleIcon;
- private final Icon[] busyIcons = new Icon[15];
- private int busyIconIndex = 0;
- private JDialog aboutBox;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement