コード例 #1
0
ファイル: WorldSelector.java プロジェクト: TOGoS/Chunky
  /**
   * Constructor
   *
   * @param chunky
   */
  public WorldSelector(Chunky chunky) {
    super(chunky.getFrame());
    this.chunky = chunky;

    setTitle(Messages.getString("WorldSelector.0")); // $NON-NLS-1$

    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    setModalityType(Dialog.ModalityType.MODELESS);

    initComponents();
    fillWorldList();

    pack();
    setLocationRelativeTo(chunky.getFrame());
    setVisible(true);
  }
コード例 #2
0
ファイル: WorldSelector.java プロジェクト: TOGoS/Chunky
  private void initComponents() {

    JLabel selectWorldLbl = new JLabel();
    JButton selectWorldDirBtn = new JButton("Select World Directory");
    selectWorldDirBtn.setToolTipText("Select the directory where your Minecraft worlds are saved");
    selectWorldDirBtn.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent arg0) {
            WorldDirectoryPicker dialog = new WorldDirectoryPicker(chunky.getFrame());
            dialog.setVisible(true);
            if (dialog.isAccepted()) {
              fillWorldList(dialog.getSelectedDirectory());
            }
          }
        });
    JButton browseBtn = new JButton();
    JSeparator sep1 = new JSeparator();

    worldTbl.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    worldTbl.getSelectionModel().addListSelectionListener(this);
    JScrollPane scrollPane = new JScrollPane(worldTbl);

    selectWorldLbl.setText(Messages.getString("WorldSelector.1")); // $NON-NLS-1$

    browseBtn.setText(Messages.getString("WorldSelector.2")); // $NON-NLS-1$
    browseBtn.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent arg0) {
            JFileChooser fileChooser = new JFileChooser(Chunky.getSavesDirectory());
            fileChooser.setDialogTitle(Messages.getString("WorldSelector.0")); // $NON-NLS-1$
            fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int result = fileChooser.showOpenDialog(null);
            if (result == JFileChooser.APPROVE_OPTION) {
              chunky.loadWorld(new World(fileChooser.getSelectedFile(), false));
              WorldSelector.this.dispose();
            }
          }
        });

    GroupLayout layout = new GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout
            .createParallelGroup()
            .addGroup(
                layout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addGroup(
                        layout
                            .createParallelGroup()
                            .addComponent(
                                selectWorldLbl, GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
                            .addComponent(
                                scrollPane, GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
                            .addComponent(browseBtn, GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
                            .addComponent(sep1)
                            .addComponent(
                                selectWorldDirBtn, GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE))
                    .addContainerGap()));
    layout.setVerticalGroup(
        layout
            .createParallelGroup()
            .addGroup(
                layout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addComponent(selectWorldLbl)
                    .addPreferredGap(ComponentPlacement.UNRELATED)
                    .addComponent(scrollPane)
                    .addPreferredGap(ComponentPlacement.UNRELATED)
                    .addComponent(
                        sep1,
                        GroupLayout.PREFERRED_SIZE,
                        GroupLayout.DEFAULT_SIZE,
                        GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(ComponentPlacement.RELATED)
                    .addComponent(browseBtn)
                    .addPreferredGap(ComponentPlacement.UNRELATED)
                    .addComponent(selectWorldDirBtn)
                    .addContainerGap()));

    pack();
  }