Skip to content

Commit

Permalink
refactoring attributes removing m_
Browse files Browse the repository at this point in the history
  • Loading branch information
lokesh1990 committed Mar 17, 2016
1 parent 1c4288d commit bb3d8b8
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 70 deletions.
66 changes: 33 additions & 33 deletions src/code/map/MapMaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public class MapMaker extends JFrame {

// class attribute declarations
private JPanel contentPane; // main container panel
private MapModel m_currMap; // MapModel class to hold the map object
private Panel panel_1 = new Panel(); // panel to hold the map grid
private MapModel currMap; // MapModel class to hold the map object
private Panel mapPanel = new Panel(); // panel to hold the map grid
private JPanel[][] panelsHolder; // panel array to hold the cells in the grid
private JButton buttonStart = new JButton("Start Point");
private JButton buttonEnd = new JButton("End Point");
Expand All @@ -65,19 +65,19 @@ public class MapMaker extends JFrame {
public boolean saveToFile() {
try {
// validate the map for correctness before saving
if(m_currMap.validateMap()) {
if(currMap.validateMap()) {

JFileChooser fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(new File(DEFAULT_FILE_PATH));
fileChooser.setSelectedFile(new File(m_currMap.GetName() + ".map"));
fileChooser.setSelectedFile(new File(currMap.GetName() + ".map"));
if (fileChooser.showSaveDialog(MapMaker.this) == JFileChooser.APPROVE_OPTION) {

File file = fileChooser.getSelectedFile();
// save to file

FileOutputStream fos= new FileOutputStream(file);
ObjectOutputStream oos= new ObjectOutputStream(fos);
oos.writeObject(m_currMap.GetMapArray());
oos.writeObject(currMap.GetMapArray());
oos.close();
fos.close();
JOptionPane.showMessageDialog(null, "Your map is saved successfully.");
Expand Down Expand Up @@ -112,24 +112,24 @@ public void windowClosing(WindowEvent arg0) {
}
});

m_currMap = mMapModel;
currMap = mMapModel;
MigLayout myGrid = new MigLayout();

if(isExistingFile) {
for(int k=0;k < m_currMap.rSize;k++) {
for(int i=0;i < m_currMap.cSize;i++) {
if(pathTempValue < m_currMap.GetMapArray()[k][i] && m_currMap.GetMapArray()[k][i] != 9999)
pathTempValue = m_currMap.GetMapArray()[k][i];
for(int k=0;k < currMap.rSize;k++) {
for(int i=0;i < currMap.cSize;i++) {
if(pathTempValue < currMap.GetMapArray()[k][i] && currMap.GetMapArray()[k][i] != 9999)
pathTempValue = currMap.GetMapArray()[k][i];
}
}
pathTempValue++;
}

panel_1.setLayout(myGrid);
panel_1.setLayout(new MigLayout());
mapPanel.setLayout(myGrid);
mapPanel.setLayout(new MigLayout());

panelsHolder = new JPanel[m_currMap.rSize][m_currMap.cSize];
DrawMap(isExistingFile, panel_1);
panelsHolder = new JPanel[currMap.rSize][currMap.cSize];
DrawMap(isExistingFile, mapPanel);

setTitle("Tower Defence - Map Maker");
//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Expand Down Expand Up @@ -219,7 +219,7 @@ public void actionPerformed(ActionEvent e) {
ScrollPane sc_panel = new ScrollPane();
sc_panel.setBounds(10, 172, 914, 527);

sc_panel.add(panel_1,null);
sc_panel.add(mapPanel,null);
contentPane.add(sc_panel);

}
Expand All @@ -242,23 +242,23 @@ public void click(MouseEvent e, JPanel cell) {
//1=StartPoint, 9999=End, 2=Path, 3=Delete
// if the delete tool is selected
if(selectedTool== Util.TOOL_DELETE) {
if(m_currMap.GetMapArray()[x][y] == 1) {
if(currMap.GetMapArray()[x][y] == 1) {
isStartAdded = false;
buttonStart.setEnabled(true);
} else if(m_currMap.GetMapArray()[x][y] == Util.POINT_EXIT) {
} else if(currMap.GetMapArray()[x][y] == Util.POINT_EXIT) {
isEndAdded = false;
buttonEnd.setEnabled(true);
}
else if(m_currMap.GetMapArray()[x][y] > 1) {
else if(currMap.GetMapArray()[x][y] > 1) {
pathTempValue--;
}

m_currMap.DeleteFromMap(x, y);
currMap.DeleteFromMap(x, y);

cell.removeAll();
cell.setBackground(null);
panel_1.revalidate();
panel_1.repaint();
mapPanel.revalidate();
mapPanel.repaint();
} else {

// if the other tool is selected, it is handled here
Expand All @@ -269,7 +269,7 @@ else if(m_currMap.GetMapArray()[x][y] > 1) {
buttonStart.setEnabled(false);

} else if(selectedTool == Util.TOOL_POINT_PATH) {
if(m_currMap.GetMapArray()[x][y] != 1 && m_currMap.GetMapArray()[x][y] != Util.POINT_EXIT) {
if(currMap.GetMapArray()[x][y] != 1 && currMap.GetMapArray()[x][y] != Util.POINT_EXIT) {
DrawMapItem(2, cell);
// mapArray[x][y] = pathTempValue;
// pathTempValue++;
Expand All @@ -287,10 +287,10 @@ else if(m_currMap.GetMapArray()[x][y] > 1) {
// modifying the map model object based tool action performed above
if(selectedTool != 3 && !overideExisting) {
if(selectedTool==2) {
m_currMap.AddToMap(pathTempValue, x, y);
currMap.AddToMap(pathTempValue, x, y);
pathTempValue++;
} else {
m_currMap.AddToMap(selectedTool, x, y);
currMap.AddToMap(selectedTool, x, y);
}
}

Expand Down Expand Up @@ -336,11 +336,11 @@ private void DrawMapItem(int type, JPanel cell) {
*/
private void DrawMap(boolean isExisting, Panel parentPanel) {
if(isExisting) {
for(int k=0;k < m_currMap.rSize;k++) {
for(int i=0;i < m_currMap.cSize;i++) {
for(int k=0;k < currMap.rSize;k++) {
for(int i=0;i < currMap.cSize;i++) {

String _append = "";
if(i == m_currMap.cSize-1) {
if(i == currMap.cSize-1) {
_append = ", wrap";
} else {

Expand Down Expand Up @@ -375,17 +375,17 @@ public void mouseClicked(MouseEvent e) {
});

// drawing the current map model on the grid
if(m_currMap.GetMapArray()[k][i] == 1) {
if(currMap.GetMapArray()[k][i] == 1) {
DrawMapItem(1, temp);
isStartAdded = true;
buttonStart.setEnabled(false);

} else if(m_currMap.GetMapArray()[k][i] == 9999) {
} else if(currMap.GetMapArray()[k][i] == 9999) {
DrawMapItem(9999, temp);
isEndAdded = true;
buttonEnd.setEnabled(false);

} else if(m_currMap.GetMapArray()[k][i] == 0) {
} else if(currMap.GetMapArray()[k][i] == 0) {
DrawMapItem(0, temp);
} else {
DrawMapItem(2,temp);
Expand All @@ -397,10 +397,10 @@ public void mouseClicked(MouseEvent e) {
}

} else {
for(int k=0;k<m_currMap.rSize;k++) {
for(int i=0;i<m_currMap.cSize;i++) {
for(int k=0;k<currMap.rSize;k++) {
for(int i=0;i<currMap.cSize;i++) {
String _append = "";
if(i==m_currMap.cSize-1) {
if(i==currMap.cSize-1) {
_append = ", wrap";
} else {

Expand Down
58 changes: 29 additions & 29 deletions src/code/map/MyGuiFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
public class MyGuiFile extends JFrame {

// class variable declarations
private JPanel m_contentPane;
private JComboBox<String> m_comboBox;
private final String DEFAULTFILEPATH = System.getProperty("user.dir") + "/maps";
private MapModel m_mapObj;
private JPanel contentPane;
private JComboBox<String> comboBox;
private final String DEFAULT_FILE_PATH = System.getProperty("user.dir") + "/maps";
private MapModel mapObj;

public MapModel getMapModelObj() {return m_mapObj;}
public MapModel getMapModelObj() {return mapObj;}

/**
* Main method of the class where the execution begins. The applications is invoked from this main method. It takes command line arguments
Expand Down Expand Up @@ -85,7 +85,7 @@ public void readMapFrmFile(String filename, String path) {
ois.close();
fis.close();

m_mapObj = new MapModel(filename.substring(0, filename.length() - 4), maparray);
mapObj = new MapModel(filename.substring(0, filename.length() - 4), maparray);

}catch(IOException ioe){
ioe.printStackTrace();
Expand All @@ -102,17 +102,17 @@ public void readMapFrmFile(String filename, String path) {
*/
public void updateTxtPn() {
//m_comboBox
m_comboBox.removeAllItems();
m_comboBox.addItem(" ");
comboBox.removeAllItems();
comboBox.addItem(" ");

try{
File folder = new File(DEFAULTFILEPATH);
File folder = new File(DEFAULT_FILE_PATH);
File[] listOfFiles = folder.listFiles();

for (File file : listOfFiles) {
if (file.isFile() && file.getName().endsWith(".map")) {
// file in the default directory
m_comboBox.addItem(file.getName());
comboBox.addItem(file.getName());
}
}
}catch(Exception ex){}
Expand All @@ -126,14 +126,14 @@ private void createNewMap() {
NewMapDialog mapDialog = new NewMapDialog();
mapDialog.setVisible(true);

int rowNum = (int) mapDialog.row_input.getValue();
int colNum = (int) mapDialog.col_input.getValue();
int rowNum = (int) mapDialog.rowInput.getValue();
int colNum = (int) mapDialog.colInput.getValue();

if(rowNum>9 || colNum>9){
JOptionPane.showMessageDialog(rootPane, "Map's height of width cannot exceed 9 block. Please try again.");
}else if(mapDialog.isCompleted) {
m_mapObj = new MapModel(rowNum, colNum);
new MapMaker(m_mapObj, false, this).setVisible(true);
mapObj = new MapModel(rowNum, colNum);
new MapMaker(mapObj, false, this).setVisible(true);
}

}
Expand Down Expand Up @@ -169,12 +169,12 @@ public void actionPerformed(ActionEvent arg0) {
public void actionPerformed(ActionEvent e) {

JFileChooser fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(new File(DEFAULTFILEPATH));
fileChooser.setCurrentDirectory(new File(DEFAULT_FILE_PATH));
if (fileChooser.showOpenDialog(MyGuiFile.this) == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();

readMapFrmFile(file.getName(), file.getParent());
new MapMaker(m_mapObj ,true, MyGuiFile.this).setVisible(true);
new MapMaker(mapObj ,true, MyGuiFile.this).setVisible(true);
}
}
});
Expand All @@ -195,34 +195,34 @@ public void actionPerformed(ActionEvent e) {
});

mnHelp.add(mntmAbout);
m_contentPane = new JPanel();
m_contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(m_contentPane);
m_contentPane.setLayout(new BorderLayout(0, 0));
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(new BorderLayout(0, 0));

JLabel lblNewLabel = new JLabel("Please select a file from below or an option from the file menu.");
lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 18));
m_contentPane.add(lblNewLabel, BorderLayout.NORTH);
contentPane.add(lblNewLabel, BorderLayout.NORTH);

JPanel panel = new JPanel();
m_contentPane.add(panel, BorderLayout.CENTER);
contentPane.add(panel, BorderLayout.CENTER);
panel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

m_comboBox = new JComboBox<String>();
m_comboBox.setModel(new DefaultComboBoxModel<String>(new String[] {" "}));
panel.add(m_comboBox);
comboBox = new JComboBox<String>();
comboBox.setModel(new DefaultComboBoxModel<String>(new String[] {" "}));
panel.add(comboBox);

JButton btnNewButton = new JButton("Open File");
// action listener for open file button to open the file selected in the combo box.
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(m_comboBox.getItemCount() == 1 || m_comboBox.getSelectedItem() == null)
if(comboBox.getItemCount() == 1 || comboBox.getSelectedItem() == null)
return;
if(((String)m_comboBox.getSelectedItem()).trim().length() == 0)
if(((String)comboBox.getSelectedItem()).trim().length() == 0)
return;

readMapFrmFile((String)m_comboBox.getSelectedItem(), DEFAULTFILEPATH);
new MapMaker(m_mapObj ,true, MyGuiFile.this).setVisible(true);
readMapFrmFile((String)comboBox.getSelectedItem(), DEFAULT_FILE_PATH);
new MapMaker(mapObj ,true, MyGuiFile.this).setVisible(true);
}
});
panel.add(btnNewButton);
Expand Down
16 changes: 8 additions & 8 deletions src/code/map/NewMapDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public class NewMapDialog extends JDialog {

// attributes of the class goes here
private JPanel contentPanel = new JPanel();
public JSpinner col_input = new JSpinner();
public JSpinner row_input = new JSpinner();
public JSpinner colInput = new JSpinner();
public JSpinner rowInput = new JSpinner();
public boolean isCompleted = false;

/**
Expand Down Expand Up @@ -74,15 +74,15 @@ public NewMapDialog() {
JLabel lblColumn = new JLabel("Column");
lblColumn.setBounds(15, 174, 69, 20);
contentPanel.add(lblColumn);
row_input.setModel(new SpinnerNumberModel(4, 4, 9, 1));
rowInput.setModel(new SpinnerNumberModel(4, 4, 9, 1));

row_input.setBounds(120, 109, 83, 26);
contentPanel.add(row_input);
col_input.setModel(new SpinnerNumberModel(4, 4, 9, 1));
rowInput.setBounds(120, 109, 83, 26);
contentPanel.add(rowInput);
colInput.setModel(new SpinnerNumberModel(4, 4, 9, 1));


col_input.setBounds(120, 171, 83, 26);
contentPanel.add(col_input);
colInput.setBounds(120, 171, 83, 26);
contentPanel.add(colInput);

JPanel buttonPane = new JPanel();
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
Expand Down

0 comments on commit bb3d8b8

Please sign in to comment.