Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
apetit2 committed Nov 17, 2015
2 parents 36ad7d9 + 0ddf990 commit 9554d94
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 153 deletions.
Binary file removed src/localMapsForTest/map1.localmap
Binary file not shown.
10 changes: 7 additions & 3 deletions src/main/MapPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@

public class MapPanel extends JPanel implements ActionListener {
private Image bgImage;
int circleSize = 12; //Circle size determines size of nodes on map.

int circleSize = 10; //Circle size determines size of nodes on map.
static ArrayList<MapNode> mapPanelPoints = new ArrayList<MapNode>(); // currently loaded list of points

// Looks at the array of points, and creates graphical representation of what is currently stored.
private void renderMapPrivate(Graphics g) {
Graphics2D g2d = (Graphics2D) g;

Expand All @@ -66,7 +67,7 @@ private void renderMapPrivate(Graphics g) {
}
}


// paintComponent is what Swing calls to update the displayed graphics.
@Override
public void paintComponent(Graphics g) {

Expand All @@ -79,11 +80,14 @@ public void paintComponent(Graphics g) {
public void actionPerformed(ActionEvent e) {
repaint();
}

//Updates the points array to reflect a change, then calls the private method to render.
public void renderMapPublic(Graphics g, ArrayList<MapNode> points) {
mapPanelPoints = points;
renderMapPrivate(g);
}

//Sets the stored background image to the map image.
public void setBgImage(Image pic) {
bgImage = pic;
}
Expand Down
207 changes: 65 additions & 142 deletions src/main/gui/DevGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public class DevGUI extends JFrame {
private JTextField xPosField;
private JTextField yPosField;
private JTextField zPosField;
private JTextField nodeNameField;
private MapNode lastClicked;
private MapNode edgeStart;
private MapNode edgeRemove;
Expand Down Expand Up @@ -87,14 +86,16 @@ public void run() {
*/
public DevGUI() {

setExtendedState(Frame.MAXIMIZED_BOTH);
// setExtendedState(Frame.MAXIMIZED_BOTH); //This has the application automatically open maximized.

// This sets the size and behavior of the application window itself.
setPreferredSize(new Dimension(1380, 760));
setResizable(true);
setTitle("Map Editor");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setBounds(100, 100, 1380, 760);

setBounds(0, 0, 1300, 760);

// This defines the radio buttons that can be selected for the cursor options, because they are used in the following section of code.
JRadioButton rdbtnSelectNode = new JRadioButton("Select Node");
JRadioButton rdbtnRemoveEdge = new JRadioButton("Remove Edge");
JRadioButton rdbtnRemoveNode = new JRadioButton("Remove Node");
Expand All @@ -103,12 +104,15 @@ public DevGUI() {
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);

JMenu mnFile = new JMenu("File");
menuBar.add(mnFile);


MapPanel mapPanel = new MapPanel();
int threshold = 30; //threshold is a radius for selecting nodes on the map - they are very tiny otherwise and hard to click precisely

int threshold = 10; //threshold is a radius for selecting nodes on the map - they are very tiny otherwise and hard to click precisely


// This is code that determines what needs to happen on each mouse click in the map panel.

mapPanel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent me) {
Expand All @@ -124,7 +128,7 @@ public void mouseClicked(MouseEvent me) {
xPosField.setText(""+n.getXPos());
yPosField.setText(""+n.getYPos());
zPosField.setText(""+n.getZPos());
nodeNameField.setText(n.getnodeName());
//nodeNameField.setText(n.getnodeName());
lastClicked = n;
mapPanel.renderMapPublic(g, points);
} else if (rdbtnSelectNode.isSelected()){
Expand All @@ -137,7 +141,7 @@ public void mouseClicked(MouseEvent me) {
xPosField.setText(""+n.getXPos());
yPosField.setText(""+n.getYPos());
zPosField.setText(""+n.getZPos());
nodeNameField.setText(n.getnodeName());
//nodeNameField.setText(n.getnodeName());
lastClicked = n;
}
}
Expand Down Expand Up @@ -220,8 +224,11 @@ else if(rdbtnRemoveNode.isSelected()) {
mapPanel.setBackground(Color.WHITE);




// This is code for the file menu with the save map, load map, load new image, dropdown menu.

JMenu mnFile = new JMenu("File");
menuBar.add(mnFile);

JMenuItem mntmLoadMap = new JMenuItem("Load Map");
mnFile.add(mntmLoadMap);
mntmLoadMap.addActionListener(new ActionListener() {
Expand Down Expand Up @@ -257,7 +264,6 @@ public void actionPerformed(ActionEvent e) {
}
});


JMenuItem mntmSaveMap = new JMenuItem("Save Map");
mnFile.add(mntmSaveMap);
mntmSaveMap.addActionListener(new ActionListener() {
Expand Down Expand Up @@ -305,147 +311,53 @@ public void actionPerformed(ActionEvent e) {
mnFile.add(mntmNewMapImage);
mnFile.add(mntmExit);

JPanel panel = new JPanel();
panel.setPreferredSize(new Dimension(1000, 800));
panel.setSize(new Dimension(1000, 700));
panel.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
panel.setBackground(Color.WHITE);

JPanel cursorPanel = new JPanel();
cursorPanel.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));

// This is code for the panel showing information on the current selected node.

JPanel nodeInfoPanel = new JPanel();
nodeInfoPanel.setBounds(926, 214, 294, 108);
nodeInfoPanel.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));

GroupLayout groupLayout = new GroupLayout(getContentPane());
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addContainerGap()
.addComponent(panel, GroupLayout.PREFERRED_SIZE, 1192, GroupLayout.PREFERRED_SIZE)
.addGap(18)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addComponent(nodeInfoPanel, GroupLayout.PREFERRED_SIZE, 289, GroupLayout.PREFERRED_SIZE)
.addComponent(cursorPanel, GroupLayout.PREFERRED_SIZE, 130, GroupLayout.PREFERRED_SIZE))
.addGap(93))
);
groupLayout.setVerticalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addContainerGap()
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addComponent(panel, GroupLayout.PREFERRED_SIZE, 653, GroupLayout.PREFERRED_SIZE)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(cursorPanel, GroupLayout.PREFERRED_SIZE, 183, GroupLayout.PREFERRED_SIZE)
.addGap(18)
.addComponent(nodeInfoPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
.addGap(311))
);
GridBagLayout gbl_nodeInfoPanel = new GridBagLayout();
gbl_nodeInfoPanel.columnWidths = new int[]{95, 99, 0};
gbl_nodeInfoPanel.rowHeights = new int[]{16, 0, 0, 0, 0, 0, 0, 0, 0, 0};
gbl_nodeInfoPanel.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
gbl_nodeInfoPanel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
nodeInfoPanel.setLayout(gbl_nodeInfoPanel);

nodeInfoPanel.setLayout(null);

// Labels
JLabel lblNodeInformation = new JLabel("Node Information");
GridBagConstraints gbc_lblNodeInformation = new GridBagConstraints();
gbc_lblNodeInformation.insets = new Insets(0, 0, 5, 5);
gbc_lblNodeInformation.anchor = GridBagConstraints.NORTHWEST;
gbc_lblNodeInformation.gridx = 0;
gbc_lblNodeInformation.gridy = 0;
nodeInfoPanel.add(lblNodeInformation, gbc_lblNodeInformation);
lblNodeInformation.setBounds(2, 2, 99, 16);
nodeInfoPanel.add(lblNodeInformation);

JLabel lblXposition = new JLabel("x-position");
GridBagConstraints gbc_lblXposition = new GridBagConstraints();
gbc_lblXposition.anchor = GridBagConstraints.EAST;
gbc_lblXposition.insets = new Insets(0, 0, 5, 5);
gbc_lblXposition.gridx = 0;
gbc_lblXposition.gridy = 1;
nodeInfoPanel.add(lblXposition, gbc_lblXposition);
lblXposition.setBounds(2, 26, 67, 16);
nodeInfoPanel.add(lblXposition);

JLabel lblYposition = new JLabel("y-position");
lblYposition.setBounds(2, 53, 55, 16);
nodeInfoPanel.add(lblYposition);

JLabel lblZposition = new JLabel("z-position");
lblZposition.setBounds(2, 80, 55, 16);
nodeInfoPanel.add(lblZposition);

// Text fields
xPosField = new JTextField();
GridBagConstraints gbc_xPosField = new GridBagConstraints();
gbc_xPosField.insets = new Insets(0, 0, 5, 0);
gbc_xPosField.fill = GridBagConstraints.HORIZONTAL;
gbc_xPosField.gridx = 1;
gbc_xPosField.gridy = 1;
nodeInfoPanel.add(xPosField, gbc_xPosField);
xPosField.setBounds(122, 23, 165, 22);
nodeInfoPanel.add(xPosField);
xPosField.setColumns(10);

JLabel lblYposition = new JLabel("y-position");
GridBagConstraints gbc_lblYposition = new GridBagConstraints();
gbc_lblYposition.anchor = GridBagConstraints.EAST;
gbc_lblYposition.insets = new Insets(0, 0, 5, 5);
gbc_lblYposition.gridx = 0;
gbc_lblYposition.gridy = 2;
nodeInfoPanel.add(lblYposition, gbc_lblYposition);

yPosField = new JTextField();
GridBagConstraints gbc_yPosField = new GridBagConstraints();
gbc_yPosField.insets = new Insets(0, 0, 5, 0);
gbc_yPosField.fill = GridBagConstraints.HORIZONTAL;
gbc_yPosField.gridx = 1;
gbc_yPosField.gridy = 2;
nodeInfoPanel.add(yPosField, gbc_yPosField);
yPosField.setBounds(122, 50, 165, 22);
nodeInfoPanel.add(yPosField);
yPosField.setColumns(10);

JLabel lblZposition = new JLabel("z-position");
GridBagConstraints gbc_lblZposition = new GridBagConstraints();
gbc_lblZposition.anchor = GridBagConstraints.EAST;
gbc_lblZposition.insets = new Insets(0, 0, 5, 5);
gbc_lblZposition.gridx = 0;
gbc_lblZposition.gridy = 3;
nodeInfoPanel.add(lblZposition, gbc_lblZposition);

zPosField = new JTextField();
GridBagConstraints gbc_zPosField = new GridBagConstraints();
gbc_zPosField.insets = new Insets(0, 0, 5, 0);
gbc_zPosField.fill = GridBagConstraints.HORIZONTAL;
gbc_zPosField.gridx = 1;
gbc_zPosField.gridy = 3;
nodeInfoPanel.add(zPosField, gbc_zPosField);
zPosField.setBounds(122, 77, 165, 22);
nodeInfoPanel.add(zPosField);
zPosField.setColumns(10);

JLabel lblName = new JLabel("Name");
GridBagConstraints gbc_lblName = new GridBagConstraints();
gbc_lblName.anchor = GridBagConstraints.EAST;
gbc_lblName.insets = new Insets(0, 0, 5, 5);
gbc_lblName.gridx = 0;
gbc_lblName.gridy = 4;
nodeInfoPanel.add(lblName, gbc_lblName);

nodeNameField = new JTextField();
GridBagConstraints gbc_nodeNameField = new GridBagConstraints();
gbc_nodeNameField.insets = new Insets(0, 0, 5, 0);
gbc_nodeNameField.fill = GridBagConstraints.HORIZONTAL;
gbc_nodeNameField.gridx = 1;
gbc_nodeNameField.gridy = 4;
nodeInfoPanel.add(nodeNameField, gbc_nodeNameField);
nodeNameField.setColumns(10);

JButton btnMakeChanges = new JButton("Make Changes");
btnMakeChanges.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
}
});
GridBagConstraints gbc_btnMakeChanges = new GridBagConstraints();
gbc_btnMakeChanges.insets = new Insets(0, 0, 5, 5);
gbc_btnMakeChanges.gridx = 0;
gbc_btnMakeChanges.gridy = 5;
nodeInfoPanel.add(btnMakeChanges, gbc_btnMakeChanges);

btnMakeChanges.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
if(lastClicked != null) {
lastClicked.setnodeName(nodeNameField.getText());
lastClicked.setxPos( Double.parseDouble(xPosField.getText())); //TODO : Setting x pos doesn't work yet.
}
}

});

// This is code for the panel with the radio buttons for the cursor options

JPanel cursorPanel = new JPanel();
cursorPanel.setBounds(926, 13, 130, 183);
cursorPanel.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));

cursorPanel.setLayout(new GridLayout(0, 1, 0, 0));

JLabel lblNewLabel_1 = new JLabel(" Cursor Options");
Expand All @@ -459,19 +371,30 @@ public void actionPerformed(ActionEvent e) {
cursorPanel.add(rdbtnRemoveNode);
buttonGroup.add(rdbtnRemoveNode);


// Set up radio button group to determine cursor's function
cursorPanel.add(rdbtnSelectNode);
buttonGroup.add(rdbtnSelectNode);

cursorPanel.add(rdbtnMakeEdge);
buttonGroup.add(rdbtnMakeEdge);
cursorPanel.add(rdbtnRemoveEdge);
buttonGroup.add(rdbtnRemoveEdge);
getContentPane().setLayout(null);


// This is code pertaining to the panel holding the map panel.

JPanel panel = new JPanel();
panel.setLocation(12, 13);
panel.setPreferredSize(new Dimension(1000, 800));
panel.setSize(new Dimension(1192, 653));
panel.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
panel.setBackground(Color.WHITE);

panel.setLayout(new BorderLayout(0, 0));
panel.setBounds(13,13,900, 600);
panel.add(mapPanel);
getContentPane().setLayout(groupLayout);
getContentPane().add(panel);
getContentPane().add(cursorPanel);
getContentPane().add(nodeInfoPanel);
}

}
Loading

0 comments on commit 9554d94

Please sign in to comment.