Advertisement
Guest User

Untitled

a guest
Oct 21st, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.87 KB | None | 0 0
  1. import javax.swing.*;
  2. import javax.swing.event.*;
  3. import javax.swing.filechooser.*;
  4. import java.awt.*;
  5. import java.awt.List;
  6. import java.awt.event.*;
  7. import java.io.*;
  8. import java.util.*;
  9. import java.io.*;
  10.  
  11. class MapArea extends JPanel {
  12.  
  13. private ImageIcon mapPicture;
  14.  
  15. public MapArea(String fileName) {
  16. mapPicture = new ImageIcon(fileName);
  17. setLayout(null);
  18. int mapPictureWidth = mapPicture.getIconWidth();
  19. int mapPictureHeight = mapPicture.getIconHeight();
  20. setPreferredSize(new Dimension(mapPictureWidth, mapPictureHeight));
  21. setMaximumSize(new Dimension(mapPictureWidth, mapPictureHeight));
  22. setMinimumSize(new Dimension(mapPictureWidth, mapPictureHeight));
  23. }
  24.  
  25. public void updateMap(String fileName) {
  26. mapPicture = new ImageIcon(fileName);
  27. int mapPictureWidth = mapPicture.getIconWidth();
  28. int mapPictureHeight = mapPicture.getIconHeight();
  29. setPreferredSize(new Dimension(mapPictureWidth, mapPictureHeight));
  30. setMaximumSize(new Dimension(mapPictureWidth, mapPictureHeight));
  31. setMinimumSize(new Dimension(mapPictureWidth, mapPictureHeight));
  32. }
  33.  
  34.  
  35.  
  36. protected void paintComponent(Graphics g) {
  37. super.paintComponent(g);
  38.  
  39. g.drawImage(mapPicture.getImage(), 0, 0, this);
  40.  
  41. }
  42.  
  43. }
  44.  
  45. public class MapProgram extends JFrame {
  46.  
  47. private ArrayList<Place> listOfSavePlaces = new ArrayList<Place>();
  48. private HashMap<Position, Place> listOfPlaces = new HashMap<Position, Place>();
  49. private Set<Place> listOfSelectedPlaces = new HashSet<Place>();
  50.  
  51. private HashMap<String, ArrayList<Place>> listOfNameSortedPlaces = new HashMap<String, ArrayList<Place>>();
  52. private HashMap<String, ArrayList<Place>> listOfCathegorySortedPlaces = new HashMap<String, ArrayList<Place>>();
  53.  
  54. private final String[] categories = { "Bus", "Underground", "Train" };
  55. private JMenuBar menuBar;
  56. private JRadioButton namedPlaceButton;
  57. private JRadioButton describedPlaceButton;
  58. private JTextField searchBox;
  59. private JButton searchButton;
  60. private JButton hideButton;
  61. private JButton removeButton;
  62. private JButton coordinatesButton;
  63. private JButton newPlaceButton;
  64. private JList<String> categoryList;
  65. private JButton hideCategoryButton;
  66. private String lastLoadedFile = null;
  67. private MapArea picArea;
  68. private boolean checkSave = false;
  69. public File fileChoser(Boolean save) {
  70. JFileChooser fileChooser = new JFileChooser();
  71. int answer;
  72. if (save == true) {
  73. answer = fileChooser.showSaveDialog(MapProgram.this);
  74. } else {
  75. answer = fileChooser.showOpenDialog(MapProgram.this);
  76. }
  77. if (answer == fileChooser.APPROVE_OPTION) {
  78. File f = fileChooser.getSelectedFile();
  79.  
  80. return f;
  81. }
  82. return null;
  83. }
  84.  
  85. public MapProgram() {
  86.  
  87. JPanel eastPanel = new JPanel();
  88. JPanel northPanel = new JPanel();
  89.  
  90. setLayout(new BorderLayout());
  91. menuBar = new JMenuBar();
  92. northPanel.add(menuBar);
  93.  
  94. JMenu archiveMenu = new JMenu("Archive");
  95. menuBar.add(archiveMenu);
  96.  
  97. JMenuItem newMapItem = new JMenuItem("New map");
  98. archiveMenu.add(newMapItem);
  99. newMapItem.addActionListener(new ArchiveChoice());
  100.  
  101. JMenuItem loadPlaceItem = new JMenuItem("Load places");
  102. archiveMenu.add(loadPlaceItem);
  103. loadPlaceItem.addActionListener(new ArchiveChoice());
  104.  
  105. JMenuItem saveItem = new JMenuItem("Save");
  106. archiveMenu.add(saveItem);
  107. saveItem.addActionListener(new ArchiveChoice());
  108.  
  109. JMenuItem exitItem = new JMenuItem("Exit");
  110. archiveMenu.add(exitItem);
  111. exitItem.addActionListener(new ArchiveChoice());
  112.  
  113. northPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
  114. add(northPanel, BorderLayout.NORTH);
  115.  
  116. newPlaceButton = new JButton("new");
  117. northPanel.add(newPlaceButton);
  118. newPlaceButton.addActionListener(new NewPlace());
  119.  
  120. namedPlaceButton = new JRadioButton("Name", true);
  121. northPanel.add(namedPlaceButton);
  122.  
  123. describedPlaceButton = new JRadioButton("Described");
  124. northPanel.add(describedPlaceButton);
  125.  
  126. ButtonGroup buttonGroup = new ButtonGroup();
  127.  
  128. buttonGroup.add(namedPlaceButton);
  129. buttonGroup.add(describedPlaceButton);
  130.  
  131. searchBox = new JTextField("Search");
  132. northPanel.add(searchBox);
  133.  
  134. searchButton = new JButton("search");
  135. searchButton.addActionListener(new SearchListener());
  136. northPanel.add(searchButton);
  137.  
  138. hideButton = new JButton("hide");
  139. hideButton.addActionListener(new HideListener());
  140. northPanel.add(hideButton);
  141.  
  142. removeButton = new JButton("remove");
  143. removeButton.addActionListener(new RemoveListener());
  144. northPanel.add(removeButton);
  145.  
  146. coordinatesButton = new JButton("coordinates");
  147. coordinatesButton.addActionListener(new CoordListener());
  148. northPanel.add(coordinatesButton);
  149.  
  150. eastPanel.setLayout(new BoxLayout(eastPanel, BoxLayout.Y_AXIS));
  151. add(eastPanel, BorderLayout.EAST);
  152.  
  153. categoryList = new JList<String>(categories);
  154. categoryList.addListSelectionListener(new ListListener());
  155. //notis
  156. categoryList.addMouseListener(new MouseAdapter() {
  157. int lastInList;
  158. public void mouseClicked(MouseEvent e) {
  159. int i = categoryList.locationToIndex(e.getPoint());
  160.  
  161. if (i != -1 && i == lastInList) {
  162. categoryList.clearSelection();
  163. }
  164. lastInList = categoryList.getSelectedIndex();
  165.  
  166. }
  167. });
  168. eastPanel.add(new JLabel("Cathegories"));
  169. eastPanel.add(categoryList);
  170.  
  171. hideCategoryButton = new JButton("Hide Category");
  172. hideCategoryButton.addActionListener(new HideCathegoryListener());
  173. eastPanel.add(hideCategoryButton);
  174. setJMenuBar(menuBar);
  175. setSize(550, 400);
  176. setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
  177. addWindowListener(new WindowAdapter() {
  178. public void windowClosing(WindowEvent e) {
  179. confirmClose();
  180. }
  181. });
  182.  
  183. setLocationRelativeTo(null);
  184. setVisible(true);
  185.  
  186. }
  187.  
  188. class ArchiveChoice implements ActionListener {
  189. public void actionPerformed(ActionEvent ave) {
  190.  
  191. System.out.println(ave.getActionCommand());
  192. String choice = ave.getActionCommand();
  193.  
  194. switch (choice) {
  195.  
  196. case "New map":
  197. newMap();
  198.  
  199. break;
  200.  
  201. case "Load places":
  202. loadPlacesToMap();
  203. break;
  204.  
  205. case "Save":
  206.  
  207. savePlaces();
  208.  
  209. break;
  210.  
  211. case "Exit":
  212.  
  213. confirmClose();
  214. break;
  215.  
  216. }
  217.  
  218. }
  219. }
  220.  
  221. // nytt
  222. private boolean saveWindow(boolean exit) {
  223. JPanel formPanel = new JPanel();
  224.  
  225. int formAnswer = JOptionPane.showConfirmDialog(MapProgram.this, formPanel, "Do you want to save? ",
  226. JOptionPane.YES_NO_CANCEL_OPTION);
  227.  
  228. if (formAnswer == JOptionPane.YES_OPTION) {
  229. if (savePlaces()) {
  230. return true;
  231. }
  232. return false;
  233.  
  234. } else if (formAnswer == JOptionPane.NO_OPTION) {
  235. if(exit==true){
  236. System.exit(0);
  237. }
  238. } else if (formAnswer == JOptionPane.CANCEL_OPTION) {
  239. return false;
  240. }
  241. return true;
  242. }
  243.  
  244. private void confirmClose() {
  245. if (lastLoadedFile == null && listOfPlaces.isEmpty()) {
  246. System.exit(0);
  247. } else if (lastLoadedFile == null && !listOfPlaces.isEmpty()) {
  248. if(saveWindow(true)) {
  249. System.exit(0);
  250. }
  251. }
  252.  
  253. else if (checkSave == true) {
  254. if(saveWindow(true)) {
  255. System.exit(0);
  256. }
  257.  
  258. } else {
  259. System.exit(0);
  260. }
  261. }
  262.  
  263. private boolean checkSave() {
  264. HashMap<Position, Place> saveListOfPlaces = new HashMap<Position, Place>();
  265. FileReader infile = null;
  266.  
  267. try {
  268. infile = new FileReader(lastLoadedFile);
  269.  
  270. BufferedReader in = new BufferedReader(infile);
  271. String line;
  272.  
  273. while ((line = in.readLine()) != null) {
  274. String[] data = line.split(",");
  275.  
  276. String sort = data[0];
  277. String cath = data[1];
  278. int X = Integer.parseInt(data[2]);
  279. int Y = Integer.parseInt(data[3]);
  280. String name = data[4];
  281. String desc = null;
  282. if (data.length == 6) {
  283. desc = data[5];
  284. }
  285. if (sort.equals("Named")) {
  286. Position p = new Position(X, Y);
  287. NamedPlace n = new NamedPlace(name, cath, p);
  288. saveListOfPlaces.put(p, n);
  289.  
  290. }
  291.  
  292. else if (sort.equals("Described")) {
  293. Position p = new Position(X, Y);
  294. DescribedPlace d = new DescribedPlace(name, cath, p, desc);
  295. saveListOfPlaces.put(p, d);
  296.  
  297. }
  298. }
  299. infile.close();
  300. in.close();
  301.  
  302. } catch (FileNotFoundException e) {
  303.  
  304. e.printStackTrace();
  305. errorMessage("File not found");
  306. } catch (IOException e) {
  307. e.printStackTrace();
  308. errorMessage("Error ");
  309.  
  310. }
  311. boolean b = false;
  312. /*Place p;
  313. Byt till en boolsk variabel för om något ändrats
  314. for (Map.Entry<Position, Place> entry : listOfPlaces.entrySet()) {
  315. p = entry.getValue();
  316. Position po = new Position(p.returnX(), p.returnY());
  317. if (saveListOfPlaces.get(po) == null) {
  318. b = true;
  319. return b;
  320. }
  321. }
  322. for (Map.Entry<Position, Place> entry : saveListOfPlaces.entrySet()) {
  323. p = entry.getValue();
  324. Position po = new Position(p.returnX(), p.returnY());
  325. if (listOfPlaces.get(po) == null) {
  326. b = true;
  327. return b;
  328. }
  329. }*/
  330. return b;
  331. }
  332.  
  333. // nytt, fixa duplicerad/dålig kod
  334. private void newMap() {
  335. boolean b = true;
  336. if (lastLoadedFile == null && listOfPlaces.isEmpty()) {
  337.  
  338. } else if (lastLoadedFile == null && !listOfPlaces.isEmpty()) {
  339. b = saveWindow(false);
  340. } else if (checkSave) {
  341. b = saveWindow(false);
  342. }
  343. if (b == true) {
  344. File f = fileChoser(false);
  345. if (f != null) {
  346. emptyMaps();
  347. if (picArea == null) {
  348. picArea = new MapArea(f.getAbsolutePath());
  349. add(picArea, BorderLayout.CENTER);
  350. JScrollPane scroll = new JScrollPane(picArea);
  351. add(scroll, BorderLayout.CENTER);
  352. pack();
  353. validate();
  354. } else {
  355. picArea.updateMap(f.getAbsolutePath());
  356. lastLoadedFile = null;
  357. repaint();
  358. pack();
  359. validate();
  360. }
  361. }
  362. }
  363.  
  364. }
  365.  
  366. // ny funktion
  367. private void emptyMaps() {
  368. listOfSavePlaces.clear();
  369. listOfPlaces.clear();
  370. if (picArea != null) {
  371. picArea.removeAll();
  372. }
  373. listOfSelectedPlaces.clear();
  374. listOfNameSortedPlaces.clear();
  375. listOfCathegorySortedPlaces.clear();
  376. }
  377.  
  378. private void loadPlacesToMap() {
  379. // duplicerat till inläsning av ny map
  380. boolean checkSave = true;
  381. boolean b = true;
  382. if (lastLoadedFile == null && listOfPlaces.isEmpty()) {
  383.  
  384. } else if (lastLoadedFile == null && !listOfPlaces.isEmpty()) {
  385. b = saveWindow(false);
  386. } else if (checkSave) {
  387. b = saveWindow(false);
  388. }
  389.  
  390. if (b == true) {
  391. File l = fileChoser(false);
  392. if (l != null) {
  393. lastLoadedFile = l.getAbsolutePath();
  394. FileReader infile = null;
  395.  
  396. try {
  397.  
  398. emptyMaps();
  399. infile = new FileReader(l.getAbsolutePath());
  400.  
  401. BufferedReader in = new BufferedReader(infile);
  402. String line;
  403.  
  404. while ((line = in.readLine()) != null) {
  405. String[] data = line.split(",");
  406.  
  407. String sort = data[0];
  408. String category = data[1];
  409. int x = Integer.parseInt(data[2]);
  410. int y = Integer.parseInt(data[3]);
  411. String name = data[4];
  412. String description = null;
  413. if (data.length == 6) {
  414. description = data[5];
  415. }
  416. if (sort.equals("Named")) {
  417. Position p = new Position(x, y);
  418. NamedPlace n = new NamedPlace(name, category, p);
  419.  
  420. addToLists(n);
  421.  
  422. }
  423.  
  424. else if (sort.equals("Described")) {
  425. Position p = new Position(x, y);
  426. DescribedPlace d = new DescribedPlace(name, category, p, description);
  427.  
  428. addToLists(d);
  429. }
  430. }
  431. infile.close();
  432. in.close();
  433. }
  434.  
  435. catch (FileNotFoundException e) {
  436. errorMessage("File not found ");
  437. e.printStackTrace();
  438.  
  439. } catch (IOException e) {
  440. errorMessage("Error ");
  441. e.printStackTrace();
  442.  
  443. }
  444. }
  445. }
  446. }
  447.  
  448. private boolean savePlaces() {
  449. File l = fileChoser(true);
  450. if (l != null) {
  451. lastLoadedFile = l.getAbsolutePath();
  452.  
  453. try {
  454.  
  455. FileWriter utfil = new FileWriter(l.getAbsolutePath());
  456. PrintWriter out = new PrintWriter(utfil);
  457.  
  458. for(int i = 0; i < listOfSavePlaces.size(); i++){
  459. String add = "";
  460. Place tmp = listOfSavePlaces.get(i);
  461. DescribedPlace d = null;
  462. if (tmp instanceof DescribedPlace) {
  463. d = (DescribedPlace) tmp;
  464. add += "Described";
  465. add += ",";
  466. add += d.returnCath();
  467. add += ",";
  468. add += d.returnX();
  469. add += ",";
  470. add += d.returnY();
  471. add += ",";
  472. add += d.returnName();
  473. add += ",";
  474. add += d.returnDesc();
  475. out.println(add);
  476. } else if (tmp instanceof NamedPlace) {
  477. add += "Named";
  478. add += ",";
  479. add += tmp.returnCath();
  480. add += ",";
  481. add += tmp.returnX();
  482. add += ",";
  483. add += tmp.returnY();
  484. add += ",";
  485. add += tmp.returnName();
  486. out.println(add);
  487. }
  488. }
  489.  
  490.  
  491. out.close();
  492. checkSave = false;
  493. return true;
  494.  
  495. } catch (FileNotFoundException e) {
  496.  
  497. e.printStackTrace();
  498. errorMessage("File not found ");
  499. } catch (IOException e) {
  500.  
  501. e.printStackTrace();
  502. errorMessage("Error ");
  503. }
  504. }
  505. return false;
  506. }
  507.  
  508. // annat namn?
  509. class NewPlace implements ActionListener {
  510. public void actionPerformed(ActionEvent ave) {
  511. if (picArea != null) {
  512. MouseListener mouseListener = new MouseListener();
  513.  
  514. picArea.addMouseListener(mouseListener);
  515. picArea.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
  516. }
  517. }
  518.  
  519. }
  520.  
  521. class MouseListener extends MouseAdapter {
  522. @Override
  523. public void mouseClicked(MouseEvent mev) {
  524. picArea.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  525. openPlaceForm(categoryList.getSelectedValue(), mev.getX(), mev.getY());
  526.  
  527. picArea.removeMouseListener(this);
  528.  
  529. }
  530. }
  531.  
  532. class GlobalListener extends MouseAdapter {
  533. @Override
  534. public void mouseClicked(MouseEvent mev) {
  535.  
  536. if(mev.getSource() instanceof Place){
  537. Place p = (Place)mev.getSource();
  538. if(mev.getButton() == 1){
  539. if (p.returnSelected()) {
  540. p.setSelected(false);
  541. } else if (p.returnSelected() == false) {
  542. p.setSelected(true);
  543. }
  544. }
  545. if(mev.getButton() == 3 && p.returnVisible()){
  546. if (p instanceof NamedPlace) {
  547. String displayMessage = "X: " + p.returnX() + "Y: " + p.returnY();
  548. JOptionPane.showMessageDialog(MapProgram.this, displayMessage);
  549. } else {
  550. String displayMessage = "X: " + p.returnX() + "Y: " + p.returnY() + "\n"
  551. + ((DescribedPlace) p).returnDesc();
  552. JOptionPane.showMessageDialog(MapProgram.this, displayMessage);
  553.  
  554. }
  555. }
  556. }
  557.  
  558. repaint();
  559. }
  560. }
  561. class ClickListner implements ActionListener{
  562. public void actionPerformed(ActionEvent ave){
  563.  
  564. }
  565. }
  566.  
  567. class HideListener implements ActionListener {
  568. public void actionPerformed(ActionEvent ave) {
  569. for(Place p: listOfSelectedPlaces){
  570. if (p.returnSelected()) {
  571. p.setVisible(false);
  572. p.setSelected(false);
  573. listOfPlaces.put(p.getPosition(), p);
  574. listOfSelectedPlaces.add(p);
  575. listOfSavePlaces.add(p);
  576. }
  577.  
  578.  
  579. }
  580.  
  581. repaint();
  582. }
  583.  
  584. }
  585.  
  586. class HideCathegoryListener implements ActionListener {
  587. public void actionPerformed(ActionEvent ave) {
  588. String choice = "";
  589.  
  590. if (listOfCathegorySortedPlaces.get(categoryList.getSelectedValue()) != null) {
  591. choice = categoryList.getSelectedValue();
  592. setVisible(choice);
  593. repaint();
  594. }
  595. }
  596.  
  597. }
  598.  
  599. public void setVisible(String nyckelNamn){
  600. listOfCathegorySortedPlaces.get(nyckelNamn).forEach(Place -> Place.setVisible(false));
  601. }
  602.  
  603.  
  604. class RemoveListener implements ActionListener {
  605. public void actionPerformed(ActionEvent ave) {
  606. checkSave = true;
  607. ArrayList<Place> tempList = new ArrayList<Place>();
  608. for(Place p: listOfSelectedPlaces){
  609. if(p.returnSelected()==true){
  610. listOfNameSortedPlaces.get(p.returnName()).remove(p);
  611. listOfCathegorySortedPlaces.get(p.returnCath()).remove(p);
  612. picArea.remove(p);
  613. tempList.add(p);
  614. }
  615. }
  616. listOfSelectedPlaces.removeAll(tempList);
  617. tempList.clear();
  618. repaint();
  619. }
  620. }
  621.  
  622. class CoordListener implements ActionListener {
  623. public void actionPerformed(ActionEvent ave) {
  624. openCoordForm();
  625. }
  626. }
  627.  
  628. class SearchListener implements ActionListener {
  629. public void actionPerformed(ActionEvent ave) {
  630.  
  631. if (listOfNameSortedPlaces.get(searchBox.getText()) != null) {
  632. for (Place p : listOfNameSortedPlaces.get(searchBox.getText())) {
  633. p.setVisible(true);
  634. p.setSelected(true);
  635. listOfPlaces.put(p.getPosition(), p);
  636. listOfSavePlaces.add(p);
  637.  
  638.  
  639. listOfSelectedPlaces.add(p);
  640. }
  641. }
  642. repaint();
  643. }
  644. }
  645.  
  646. class ListListener implements ListSelectionListener {
  647. public void valueChanged(ListSelectionEvent event) {
  648. if (!event.getValueIsAdjusting()) {
  649. if (picArea != null) {
  650.  
  651. String selected = "";
  652.  
  653. if (listOfCathegorySortedPlaces.get(categoryList.getSelectedValue()) != null) {
  654. selected = categoryList.getSelectedValue().toString();
  655.  
  656. for (Place p : listOfCathegorySortedPlaces.get(selected)) {
  657. //kolla
  658. p.setVisible(true);
  659. listOfPlaces.put(p.getPosition(), p);
  660. listOfSavePlaces.add(p);
  661. listOfSelectedPlaces.add(p);
  662.  
  663.  
  664. }
  665. repaint();
  666. }
  667. }
  668. }
  669. }
  670. }
  671.  
  672. private void openCoordForm() {
  673. try {
  674. CoordForm form = new CoordForm();
  675. int formsAnswer = JOptionPane.showConfirmDialog(MapProgram.this, form, "Input",
  676. JOptionPane.OK_CANCEL_OPTION);
  677.  
  678. boolean notFound = true;
  679.  
  680. if (formsAnswer != JOptionPane.OK_OPTION) {
  681. return;
  682. } else {
  683. Position po = new Position(form.returnX(), form.returnY());
  684. if (listOfPlaces.containsKey(po)) {
  685. Place p = listOfPlaces.get(po);
  686. p.setSelected(true);
  687. p.setVisible(true);
  688. listOfPlaces.put(po, p);
  689. listOfSavePlaces.add(p);
  690. listOfSelectedPlaces.add(p);
  691. notFound = false;
  692. repaint();
  693. }
  694. }
  695. if (notFound) {
  696. JOptionPane.showMessageDialog(MapProgram.this, "There is nothing on the entered coordinates");
  697.  
  698. }
  699.  
  700. } catch (NumberFormatException e) {
  701. errorMessage("Error, wrong type of data entered ");
  702. }
  703. }
  704.  
  705. private void openPlaceForm(String category, int musX, int musY) {
  706. try {
  707. boolean descB = false;
  708. descB = describedPlaceButton.isSelected();
  709. PlaceForm form = new PlaceForm(descB);
  710. int formAnswer = JOptionPane.showConfirmDialog(MapProgram.this, form, "Input",
  711. JOptionPane.OK_CANCEL_OPTION);
  712. String placeName;
  713. String description;
  714.  
  715. if (formAnswer != JOptionPane.OK_OPTION) {
  716. return;
  717.  
  718. } else {
  719. placeName = form.getName();
  720.  
  721. }
  722. Position coord = new Position(musX, musY);
  723. if(category == null){
  724. category="None";
  725. }
  726. if (describedPlaceButton.isSelected()) {
  727. description = form.getDesc();
  728. DescribedPlace d = new DescribedPlace(placeName, category, coord, description);
  729. addToLists(d);
  730. }
  731.  
  732. else {
  733. NamedPlace n = new NamedPlace(placeName, category, coord);
  734. addToLists(n);
  735. }
  736. repaint();
  737. } catch (NumberFormatException e) {
  738. errorMessage("Error, wrong type of data entered ");
  739. }
  740. }
  741.  
  742. private void addToLists(Place p) {
  743. checkSave = true;
  744. GlobalListener g = new GlobalListener();
  745. picArea.add(p);
  746. p.addMouseListener(g);
  747. listOfPlaces.put(p.getPosition(), p);
  748. listOfSavePlaces.add(p);
  749. listOfSelectedPlaces.add(p);
  750.  
  751. if (listOfNameSortedPlaces.containsKey(p.returnName())) {
  752. listOfNameSortedPlaces.get(p.returnName()).add(p);
  753.  
  754. } else {
  755. ArrayList<Place> h = new ArrayList<Place>();
  756. h.add(p);
  757. listOfNameSortedPlaces.put(p.returnName(), h);
  758.  
  759. }
  760.  
  761. if (listOfCathegorySortedPlaces.containsKey(p.returnCath())) {
  762. listOfCathegorySortedPlaces.get(p.returnCath()).add(p);
  763.  
  764.  
  765. } else {
  766. ArrayList<Place> h = new ArrayList<Place>();
  767. h.add(p);
  768. listOfCathegorySortedPlaces.put(p.returnCath(), h);
  769.  
  770. }
  771. repaint();
  772. }
  773.  
  774. private void errorMessage(String msg) {
  775.  
  776. JOptionPane.showMessageDialog(MapProgram.this, msg);
  777.  
  778. }
  779.  
  780. public static void main(String[] args) {
  781.  
  782. MapProgram m = new MapProgram();
  783. m.pack();
  784.  
  785. }
  786. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement