Commit 13b9a120 authored by firegnom's avatar firegnom
Browse files

changed ArrayList to List

parent 2141e902
......@@ -24,19 +24,22 @@
package mvplan.datamodel;
import javax.swing.table.*;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import mvplan.gas.Gas;
import mvplan.main.MvplanInstance;
import mvplan.segments.SegmentAbstract;
import mvplan.main.*;
public class DiveSegmentModel extends AbstractTableModel
{
String [] headings;
ArrayList knownSegments;
List <SegmentAbstract> knownSegments;
public static int COLUMN_COUNT=5;
public DiveSegmentModel(ArrayList knownSegments)
public DiveSegmentModel(List knownSegments)
{
this.knownSegments=knownSegments;
......@@ -51,7 +54,7 @@ public class DiveSegmentModel extends AbstractTableModel
}
// Accessors
public ArrayList<SegmentAbstract> getKnownSegments() { return knownSegments;}
public List<SegmentAbstract> getKnownSegments() { return knownSegments;}
public int getRowCount() { return knownSegments.size();}
public int getColumnCount() { return COLUMN_COUNT; }
public String getColumnName(int col) { return headings[col]; }
......
......@@ -24,8 +24,10 @@
package mvplan.datamodel;
import javax.swing.table.*;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import mvplan.gas.Gas;
import mvplan.main.MvplanInstance;
......@@ -33,10 +35,10 @@ import mvplan.main.MvplanInstance;
public class GasModel extends AbstractTableModel
{
String [] headings;
ArrayList<Gas> gasList;
List<Gas> gasList;
public static int COLUMN_COUNT=3;
public GasModel(ArrayList gasList) {
public GasModel(List gasList) {
this.gasList=gasList;
// Set up headings
headings = new String[] {
......@@ -46,7 +48,7 @@ public class GasModel extends AbstractTableModel
}
// Accessors
public ArrayList<Gas> getGasList() { return gasList;}
public List<Gas> getGasList() { return gasList;}
public int getRowCount() { return gasList.size();}
public int getColumnCount() { return COLUMN_COUNT; }
public String getColumnName(int col) { return headings[col]; }
......
......@@ -24,40 +24,80 @@
package mvplan.gui;
import mvplan.dive.printer.TextTablePrinter;
import mvplan.dive.printer.TextProfilePrinter;
import mvplan.util.MyFileFilter;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.InputEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.print.PageFormat;
import java.io.File;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Locale;
import mvplan.main.Mvplan;
import mvplan.datamodel.GasModel;
import java.util.MissingResourceException;
import javax.swing.BorderFactory;
import javax.swing.DefaultCellEditor;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.ListSelectionModel;
import javax.swing.border.Border;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.TableColumn;
import mvplan.datamodel.DiveSegmentModel;
import mvplan.dive.*;
import mvplan.datamodel.GasModel;
import mvplan.dive.Profile;
import mvplan.dive.TableGeneratorModel;
import mvplan.gas.Gas;
import mvplan.gui.components.ModelDisplayComponent;
import mvplan.gui.components.ProgressIndicator;
import mvplan.gui.text.JTextAreaProfilePrinter;
import mvplan.gui.text.JTextAreaTablePrinter;
import mvplan.main.Mvplan;
import mvplan.main.MvplanInstance;
import mvplan.model.AbstractModel;
import mvplan.model.ModelDAO;
import mvplan.prefs.PrefsXMLDAO;
import mvplan.prefs.PrefsXStreamDAO;
import mvplan.segments.SegmentDive;
import mvplan.segments.SegmentAbstract;
import mvplan.updater.*;
import mvplan.util.*;
import mvplan.gui.text.*;
import mvplan.gui.components.*;
import java.awt.*;
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.print.*;
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.border.*;
import javax.swing.table.*;
import javax.swing.event.*;
import java.util.MissingResourceException;
import mvplan.main.MvplanInstance;
import mvplan.segments.SegmentDive;
import mvplan.updater.VersionManager;
import mvplan.util.MyFileFilter;
public class MainFrame extends JFrame
{
......@@ -70,9 +110,9 @@ public class MainFrame extends JFrame
Profile currentProfile=null; // Current Profile (Single Dive) model
AbstractModel currentModel=null; // Current tissue model
TableGeneratorModel currentTable=null; // Current multi-profile table model.
ArrayList knownGases; // Maintains known gases
java.util.List <Gas> knownGases; // Maintains known gases
GasModel knownGasModel; // For Gas table
ArrayList knownSegments; // Maintains known Dive Segments
java.util.List <SegmentAbstract> knownSegments; // Maintains known Dive Segments
DiveSegmentModel knownSegmentsModel; // For Dive Profile Table
// State fields
......
......@@ -24,21 +24,27 @@
package mvplan.gui;
import java.awt.*;
import java.awt.font.*;
import java.util.ArrayList;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.font.FontRenderContext;
import java.awt.font.LineMetrics;
import java.util.List;
import mvplan.main.Mvplan;
import mvplan.segments.SegmentAbstract;
public class ProfileDisplayComponent extends AbstractDisplayComponent
{
private ArrayList segments;
private List segments;
/**
* Constructor for objects of class profileDisplayComponent
*/
public ProfileDisplayComponent(ArrayList outputSegments, String heading)
public ProfileDisplayComponent(List <SegmentAbstract> outputSegments, String heading)
{
this.segments=outputSegments;
this.heading=heading;
......
......@@ -34,6 +34,7 @@ import java.awt.Frame;
import javax.swing.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Iterator;
public class TableGeneratorDialog extends JDialog implements FocusListener {
......@@ -68,16 +69,12 @@ public class TableGeneratorDialog extends JDialog implements FocusListener {
}
public boolean showDialog() {
int cs = mp.getControlSegmentIndex();
SegmentAbstract s;
//String str;
ArrayList knownSegments, modifiableSegments=new ArrayList();
List<SegmentAbstract> knownSegments, modifiableSegments=new ArrayList<SegmentAbstract>();
if (cs>=0) {
// New multi segment code
knownSegments = mp.getKnownSegments();
Iterator it=knownSegments.iterator();
while(it.hasNext()){
s = (SegmentAbstract)it.next();
for (SegmentAbstract s :mp.getKnownSegments()){
if(s.getTime()>0.0)
// Add to arraylist, but reverse order so it comes up on in spinner
modifiableSegments.add(0,s);
......
......@@ -25,19 +25,46 @@
package mvplan.gui;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.util.ArrayList;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.print.PageFormat;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.awt.print.PageFormat;
import java.lang.reflect.*;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JColorChooser;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.KeyStroke;
import javax.swing.border.Border;
import mvplan.main.Mvplan;
import mvplan.dive.TableGeneratorModel;
import mvplan.main.Mvplan;
import mvplan.main.MvplanInstance;
import mvplan.segments.SegmentAbstract;
public class TablePreviewDialog extends JDialog implements ActionListener {
......@@ -62,7 +89,7 @@ public class TablePreviewDialog extends JDialog implements ActionListener {
JComboBox printFontSizeCombo = new JComboBox(new Object [] {new Integer(9),new Integer(10), new Integer(12),new Integer(14)});
Insets displayComponentInsets=new Insets(0,0,0,0);
TableGeneratorModel model;
ArrayList segments;
List <SegmentAbstract> segments;
String heading;
Frame parent;
AbstractDisplayComponent displayComponent;
......@@ -87,7 +114,7 @@ public class TablePreviewDialog extends JDialog implements ActionListener {
/**
* Constructor for simple ArrayLists of Segments == singe dive plans
*/
public TablePreviewDialog(Frame frame, ArrayList segments, String heading) {
public TablePreviewDialog(Frame frame, List<SegmentAbstract> segments, String heading) {
super(frame,false);
this.setTitle(MvplanInstance.getMvplan().getResource("mvplan.gui.TablePreviewDialog.title.text"));
this.heading=heading;
......
......@@ -21,13 +21,15 @@
package mvplan.gui.text;
import mvplan.dive.Profile;
import mvplan.gas.Gas;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JTextArea;
import java.util.ArrayList;
import mvplan.dive.Profile;
import mvplan.dive.printer.ProfilePrinter;
import mvplan.dive.printer.TextProfilePrinter;
import mvplan.gas.Gas;
//import java.util.MissingResourceException;
public class JTextAreaProfilePrinter extends ProfilePrinter <JTextArea> {
......@@ -35,11 +37,11 @@ public class JTextAreaProfilePrinter extends ProfilePrinter <JTextArea> {
private JTextArea textArea;
private Profile profile;
//private boolean showStopTime = Mvplan.prefs.isShowStopTime();
private ArrayList<Gas> knownGases;
private List<Gas> knownGases;
StringBuffer result = new StringBuffer();
/** Creates a new instance of ProfileTextAreaPrinter */
public JTextAreaProfilePrinter(Profile p, JTextArea text, ArrayList<Gas> knownGases) {
public JTextAreaProfilePrinter(Profile p, JTextArea text, List<Gas> knownGases) {
super(p, text, knownGases);
this.profile=p;
this.textArea=text;
......
......@@ -37,6 +37,8 @@ package mvplan.dive;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import mvplan.gas.Gas;
import mvplan.main.MvplanInstance;
import mvplan.model.*;
......@@ -54,9 +56,9 @@ public class Profile
private final int debug = MvplanInstance.getMvplan().getDebug();
private Prefs prefs = MvplanInstance.getMvplan().getPrefs();
private ArrayList<SegmentAbstract> inputSegments; // Stores input dive segment objects passed from GUI and enabled
private ArrayList<SegmentAbstract> outputSegments; // Stores output segments produced by theis class
private ArrayList<Gas> gases; // Stores dive gas objects passed from GUI and enabled
private List<SegmentAbstract> inputSegments; // Stores input dive segment objects passed from GUI and enabled
private List<SegmentAbstract> outputSegments; // Stores output segments produced by theis class
private List<Gas> gases; // Stores dive gas objects passed from GUI and enabled
private int currentGasIndex; // Points to current gas
private double currentDepth; // Currend dive depth (msw/fsw)
//private double pAmb; // Ambient pressure (msw/fsw)
......@@ -79,7 +81,7 @@ public class Profile
public static final int INFINITE_DECO=4;
/** Constructor for objects of class Profile */
public Profile(ArrayList <SegmentAbstract> knownSegments, ArrayList <Gas> knownGases, AbstractModel m)
public Profile(List<SegmentAbstract> list, List<Gas> list2, AbstractModel m)
{
Gas g; // Used for constructing arraylists of gases and segments
SegmentAbstract s; // as above
......@@ -118,7 +120,7 @@ public class Profile
}
// Construct list of dive segments from known segments
Iterator<SegmentAbstract> is=knownSegments.iterator();
Iterator<SegmentAbstract> is=list.iterator();
while(is.hasNext()) {
s=is.next();
// Add enabled dive segments only to input segments
......@@ -126,7 +128,7 @@ public class Profile
inputSegments.add(s);
}
// construct list of dive gases from known gases
Iterator<Gas> ig=knownGases.iterator();
Iterator<Gas> ig=list2.iterator();
while(ig.hasNext()) {
g=ig.next();
g.setVolume(0.0); // Reset the gas volume to zero
......@@ -139,8 +141,8 @@ public class Profile
}
// Accessor methods for profile
public ArrayList<SegmentAbstract> getProfile() { return outputSegments; }
public ArrayList<Gas> getGases() { return gases; }
public List<SegmentAbstract> getProfile(){ return outputSegments; }
public List<Gas> getGases() { return gases; }
public AbstractModel getModel() { return model; }
public boolean getIsRepetitiveDive() {return isRepetativeDive;}
public int getSurfaceInterval() { return surfaceInterval; }
......
......@@ -28,18 +28,19 @@
package mvplan.dive;
import mvplan.main.*;
import mvplan.segments.SegmentAbstract;
import mvplan.gas.Gas;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import mvplan.gas.Gas;
import mvplan.main.MvplanInstance;
import mvplan.segments.SegmentAbstract;
public class TableGeneratorModel {
Profile [] multiProfile; // Holds collection of dive profiles created
private ArrayList<SegmentAbstract> knownSegments; // Input dive segments and gases
private ArrayList<Gas> knownGases;
private List<SegmentAbstract> knownSegments; // Input dive segments and gases
private List<Gas> knownGases;
private int[] modifiers; // Holds the segment time modifiers. These alter the controlling segment
private double maxCNS; // Records maximum oxygen numbers only
private double maxPO2;
......@@ -58,7 +59,7 @@ public class TableGeneratorModel {
* @param g ArrayList of known gases
* @param modifiers int[] of profile time modifiers
*/
public TableGeneratorModel(ArrayList<SegmentAbstract> s, ArrayList<Gas> g, int[] modifiers) {
public TableGeneratorModel(List<SegmentAbstract> s, List<Gas> g, int[] modifiers) {
// Create new clean ArrayLists
knownSegments = new ArrayList<SegmentAbstract>();
knownGases = new ArrayList<Gas>();
......@@ -196,7 +197,7 @@ public class TableGeneratorModel {
* @return returnCodes as defined in Profile()
*/
public int doMultiDive() {
ArrayList<SegmentAbstract> a; // Working arraylist
List<SegmentAbstract> a; // Working arraylist
SegmentAbstract s; // Working segment
int i,j; // Counters
......@@ -332,7 +333,7 @@ public class TableGeneratorModel {
* getKnownSegments - gets the KnownSegments ArrayList
* @return (SegmentAbstract)ArrayList KnownSegments
*/
public ArrayList<SegmentAbstract> getKnownSegments() {
public List<SegmentAbstract> getKnownSegments() {
return knownSegments;
}
}
......@@ -5,7 +5,8 @@
package mvplan.dive.printer;
import java.util.ArrayList;
import java.util.List;
import mvplan.dive.Profile;
import mvplan.gas.Gas;
......@@ -14,7 +15,7 @@ import mvplan.gas.Gas;
* @author Maciej Kaniewski
*/
public abstract class ProfilePrinter <T> {
public ProfilePrinter(Profile p , T data ,ArrayList<Gas> knownGases){
public ProfilePrinter(Profile p , T data ,List<Gas> knownGases){
}
public abstract T print();
......
......@@ -22,14 +22,15 @@
package mvplan.dive.printer;
import java.math.BigDecimal;
import mvplan.main.IMvplan;
import mvplan.segments.SegmentAbstract;
import mvplan.dive.Profile;
import mvplan.gas.Gas;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import mvplan.dive.Profile;
import mvplan.gas.Gas;
import mvplan.main.IMvplan;
import mvplan.main.MvplanInstance;
import mvplan.segments.SegmentAbstract;
//import java.util.MissingResourceException;
public class TextProfilePrinter extends ProfilePrinter <StringBuffer>{
......@@ -39,10 +40,10 @@ public class TextProfilePrinter extends ProfilePrinter <StringBuffer>{
private Profile profile;
//private boolean showStopTime = MvplanInstance.getPrefs().isShowStopTime();
private String disclaimer;
private ArrayList knownGases;
private List<Gas> knownGases;
/** Creates a new instance of ProfilePrinter */
public TextProfilePrinter(Profile p, StringBuffer text, ArrayList knownGases) {
public TextProfilePrinter(Profile p, StringBuffer text, List<Gas> knownGases) {
super(p, text, knownGases);
this.profile=p;
this.textArea=text;
......@@ -72,8 +73,6 @@ public class TextProfilePrinter extends ProfilePrinter <StringBuffer>{
* Prints an extended dive table to the textArea
*/
private void doPrintExtendedTable() {
ArrayList segments;
SegmentAbstract s;
if(profile.getIsRepetitiveDive()) {
// Print repetitive dive heading
......@@ -97,10 +96,7 @@ public class TextProfilePrinter extends ProfilePrinter <StringBuffer>{
printAltitude();
textArea.append("========================================================="+'\n');
segments = profile.getProfile();
Iterator i = segments.iterator();
while(i.hasNext()) {
s=(SegmentAbstract)i.next();
for(SegmentAbstract s : profile.getProfile()) {
textArea.append(s.toStringLong()+'\n');
}
doGasUsage();
......@@ -113,16 +109,14 @@ public class TextProfilePrinter extends ProfilePrinter <StringBuffer>{
//TODO - use String formatter for these so as to display localisations properly
// Display gas usage
// GW - Modified Mar-2009 to display all knaown gases with volumes > 0 so as to pick up open circuit bottom gas
ArrayList gases=knownGases; //profile.getGases();
Iterator i2 = gases.iterator();
List<Gas> gases=knownGases; //profile.getGases();
String volumeUnits = MvplanInstance.getPrefs().getVolumeShortString();
// Gas usage heading
textArea.append('\n'+mvplan.getResource("mvplan.gui.text.ProfilePrinter.gasEstimate.text")+" ="+
MvplanInstance.getPrefs().getDiveRMV()+", "+mvplan.getResource("mvplan.gui.text.ProfilePrinter.decoRmv.text")+
" ="+MvplanInstance.getPrefs().getDecoRMV()+volumeUnits+"/"+ mvplan.getResource("mvplan.minutes.shortText") + '\n');
while(i2.hasNext()) {
Gas g=(Gas)i2.next();
for (Gas g : gases){
if(g.getVolume()> 0.0d)
textArea.append(g+" : "+ roundDouble(1, g.getVolume())+volumeUnits+'\n');
}
......@@ -139,8 +133,7 @@ public class TextProfilePrinter extends ProfilePrinter <StringBuffer>{
* Prints a short text dive table to the textArea
*/
private void doPrintShortTable() {
ArrayList segments;
SegmentAbstract s;
int segTimeMins,segTimeSeconds;
......@@ -165,10 +158,8 @@ public class TextProfilePrinter extends ProfilePrinter <StringBuffer>{
textArea.append(" "+MvplanInstance.getPrefs().getDepthShortString()+" "+mvplan.getResource("mvplan.gui.text.ProfilePrinter.heading.text")+'\n');
textArea.append("=============================="+'\n');
// "- 120 00:00 000 88/88 1.30
segments = profile.getProfile();
Iterator i = segments.iterator();
while(i.hasNext()) {
s=(SegmentAbstract)i.next();
for (SegmentAbstract s: profile.getProfile()){
segTimeMins=(int)s.getTime();
segTimeSeconds = (int)((s.getTime() - (double)segTimeMins)*60.0);
......
......@@ -29,6 +29,7 @@ package mvplan.prefs;
import java.io.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import mvplan.gas.Gas;
import mvplan.segments.SegmentAbstract;
......@@ -86,8 +87,8 @@ public class Prefs implements Serializable
private int frameSizeY;
private int frameSplit;
private boolean gfMultilevelMode; // On multilevel mode the gf does not get set until final ascent.
private ArrayList <Gas> prefGases; // Stores known gas list
private ArrayList <SegmentAbstract> prefSegments; // Stores dive segments
private List <Gas> prefGases; // Stores known gas list
private List <SegmentAbstract> prefSegments; // Stores dive segments
private String lastModelFile; // Stores last model filename used
private boolean agreedToTerms;
public static final int BRIEF=0;
......@@ -399,9 +400,9 @@ public class Prefs implements Serializable