@Override public void actionPerformed(ActionEvent e) { final List<String> choice = list.getSelectedValues(); if (choice == null) { return; } // OK name final String trailS = (choice.size() > 1 ? "s" : ""); // @formatter:off final boolean yes = Alerts.askYesNo( DialogManageMcPacks.this, "Deleting Installed Pack" + trailS, "Do you really want to delete the selected\n" + "resource pack" + trailS + " from your Minecraft folder?"); // @formatter:on if (!yes) return; for (final String s : choice) { final File f = new File(OsUtils.getMcDir("resourcepacks"), s + ".zip"); f.delete(); } reloadOptions(); }
@Override protected JComponent buildGui() { final VBox vbox = new VBox(); vbox.windowPadding(); vbox.heading("Manage MC resource packs"); vbox.titsep("Installed Packs"); vbox.gap(); list = new SimpleStringList(mcPacks, true); list.setMultiSelect(true); list.getList() .addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { final int[] selected = list.getSelectedIndices(); buttonDelete.setEnabled(selected != null); } }); // buttons buttonDelete = Gui.sidebarButton("Delete", "Delete pack from library", Icons.MENU_DELETE); buttonDelete.setEnabled(false); buttonClose = Gui.sidebarButton("Close", "Close dialog", Icons.MENU_EXIT); final ManagerLayout ml = new ManagerLayout(); ml.setMainComponent(list); ml.setTopButtons(buttonDelete); ml.setBottomButtons(buttonClose); ml.build(); vbox.add(ml); return vbox; }
@Override protected void addActions() { list.addKeyListener( new KeyPressListener() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_DELETE) { deleteListener.actionPerformed(null); } } }); setEnterButton(buttonClose); buttonClose.addActionListener(closeListener); buttonDelete.addActionListener(deleteListener); }
private void reloadOptions() { list.setItems(mcPacks = getOptions()); }