Пример #1
0
  /** Constructor for the dialog that prepares the display of the loading screen correctly. */
  @SuppressWarnings("nls")
  public MapLoader() {
    super(MapEditor.getMainFrame(), "Load map", true);

    final Panel content = new Panel(new BorderLayout(5, 5));
    content.add(
        new Label("Select the maps you want to load. " + "Selecting multiple entries is possible."),
        BorderLayout.NORTH);

    mapList = new List(10, true);
    content.add(mapList, BorderLayout.CENTER);

    final Panel buttonPanel = new Panel(new FlowLayout(FlowLayout.CENTER, 10, 0));
    final Button okButton = new Button("Load maps");
    final Button cancelButton = new Button("Cancel");
    buttonPanel.add(okButton);
    buttonPanel.add(cancelButton);
    content.add(buttonPanel, BorderLayout.SOUTH);
    add(content);

    pack();
    validate();

    setLocation(100, 100);

    final Dimension prefSize = getPreferredSize();
    prefSize.width = 300;
    setPreferredSize(prefSize);

    cancelButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            setVisible(false);
          }
        });

    okButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            final String[] selectedMaps = getMapList().getSelectedItems();
            setVisible(false);

            for (final String selectedMap : selectedMaps) {
              MapStorage.getInstance().loadMap(selectedMap);
            }
          }
        });

    addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(final WindowEvent e) {
            setVisible(false);
          }
        });

    mapFileSearchFilter =
        new FilenameFilter() {
          private final String itemFile = ".items.txt";
          private final String tileFile = ".tiles.txt";

          @Override
          public boolean accept(final File dir, final String name) {
            return name.endsWith(itemFile) || name.endsWith(tileFile);
          }
        };
  }