Podpięty logger do UI.

Poprawione drobne błędy w loggerze.
This commit is contained in:
Tomasz Piechucki 2011-04-17 14:55:22 +00:00
parent 80ce2e4c00
commit de8ab17135
4 changed files with 25 additions and 3 deletions

View file

@ -758,6 +758,9 @@
<Property name="text" type="java.lang.String" resourceKey="jMenuItem3.text"/>
<Property name="name" type="java.lang.String" value="jMenuItem3" noResource="true"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jMenuItem3ActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="exitMenuItem">
<Properties>

View file

@ -699,6 +699,11 @@ public class WindaView extends FrameView{
jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem3.setText(resourceMap.getString("jMenuItem3.text")); // NOI18N
jMenuItem3.setName("jMenuItem3"); // NOI18N
jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem3ActionPerformed(evt);
}
});
fileMenu.add(jMenuItem3);
javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(winda.gui.WindaApp.class).getContext().getActionMap(WindaView.class, this);
@ -811,6 +816,12 @@ public class WindaView extends FrameView{
// TODO add your handling code here:
}//GEN-LAST:event_jSlider1StateChanged
private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
JFileChooser fc = new JFileChooser();
if(fc.showSaveDialog(this.mainPanel) == JFileChooser.APPROVE_OPTION)
w.ZapiszLog(fc.getSelectedFile().getPath());
}//GEN-LAST:event_jMenuItem3ActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.ButtonGroup buttonGroup2;

View file

@ -17,11 +17,12 @@ import java.util.List;
public class Logger {
public Logger (List<Pietro> trasa){
for(Pietro pietro : trasa)
{
for(Pasazer pasazer : pietro.pasazerowieWysiadajacy)
log.add("Na Piętrze " + pietro.numerPietra + " wysiadł pasażer " + pasazer.GetName());
for(Pietro pietro : trasa)
for(Pasazer pasazer : pietro.pasazerowieWsiadający)
log.add("Na Piętrze " + pietro.numerPietra + " wsiadł pasażer " + pasazer.GetName());
}
}
public void SaveLog(String filename){
@ -29,7 +30,8 @@ public class Logger {
try {
fw = new FileWriter(filename);
for (String s : log)
fw.write(s+'\n');
fw.write(s+'\r'+'\n');
fw.close();
} catch (IOException ex) {
java.util.logging.Logger.getLogger(Parser.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}

View file

@ -24,6 +24,7 @@ public class Winda {
private List<Pasazer> pasazerowieCollection = new ArrayList<Pasazer>();
private Parser parser = new Parser();
private List<Pietro> Trasa;
private Logger log;
public Winda(){
AlgorytmWindy = new AlgorytmGoraDol();
@ -88,18 +89,23 @@ public class Winda {
IloscPasazerow = pasazerowieCollection.size();
}
public void ZapiszLog(String filename){
log.SaveLog(filename);
}
public void Start(){
AlgorytmWindy.SetMaxPietro(IloscPieter);
Trasa.clear();
Trasa = AlgorytmWindy.Trasa(pasazerowieCollection);
CzasJazdy = Trasa.size()*CzasJazdyPietro+IloscPasazerow*CzasWeWyOsoby*2;
CzasSredniObslugi = CzasJazdy / IloscPasazerow;
log = new Logger(this.Trasa);
}
public static void main(String[] args) {
Winda w = new Winda();
w.SetNajblizszeWzwanie();
//w.SetNajblizszeWzwanie();
w.Start();
List<Pietro> trasa = w.GetTrasa();
for(int i = 0;i<trasa.size();i++)