prepsano nacitani obrazku z resources
parent
1e7bc533b0
commit
c407cec1e5
|
|
@ -8,7 +8,9 @@ import java.awt.event.ActionListener;
|
|||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JOptionPane;
|
||||
|
|
@ -80,39 +82,43 @@ public class MapTree extends JTree {
|
|||
}
|
||||
|
||||
private static void getContextMenuMap(MouseEvent e, Map m) {
|
||||
JMenuItem mapAdd = new JMenuItem("Přidat mapu", new ImageIcon("img/add.png"));
|
||||
mapAdd.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
new AddMapDialog().setVisible(true);
|
||||
}
|
||||
});
|
||||
|
||||
JMenuItem mapDelete = new JMenuItem("Smazat mapu", new ImageIcon("img/trash.png"));
|
||||
mapDelete.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
int option = JOptionPane.showConfirmDialog(
|
||||
null,
|
||||
"Smazat mapu " + m.getName() + " a všechny její objekty ?",
|
||||
"Potvrzení akce",
|
||||
JOptionPane.YES_NO_OPTION
|
||||
);
|
||||
|
||||
if (option == JOptionPane.YES_OPTION) {
|
||||
NettyClient.send(Message.MAP_REMOVE, m.getId());
|
||||
try {
|
||||
JMenuItem mapAdd = new JMenuItem("Přidat mapu", new ImageIcon(ImageIO.read(MapTree.class.getResourceAsStream("/img/add.png"))));
|
||||
mapAdd.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
new AddMapDialog().setVisible(true);
|
||||
}
|
||||
});
|
||||
|
||||
JMenuItem mapDelete = new JMenuItem("Smazat mapu", new ImageIcon(ImageIO.read(MapTree.class.getResourceAsStream("/img/trash.png"))));
|
||||
mapDelete.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
int option = JOptionPane.showConfirmDialog(
|
||||
null,
|
||||
"Smazat mapu " + m.getName() + " a všechny její objekty ?",
|
||||
"Potvrzení akce",
|
||||
JOptionPane.YES_NO_OPTION
|
||||
);
|
||||
|
||||
if (option == JOptionPane.YES_OPTION) {
|
||||
NettyClient.send(Message.MAP_REMOVE, m.getId());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
JPopupMenu menu = new JPopupMenu();
|
||||
if (Client.user.isAddMap()) {
|
||||
menu.add(mapAdd);
|
||||
}
|
||||
});
|
||||
|
||||
JPopupMenu menu = new JPopupMenu();
|
||||
if (Client.user.isAddMap()) {
|
||||
menu.add(mapAdd);
|
||||
if (Client.user.isRemoveMap()) {
|
||||
menu.add(mapDelete);
|
||||
}
|
||||
menu.show(e.getComponent(), e.getX(), e.getY());
|
||||
} catch (IOException ex) {
|
||||
LogFile.printErr("MapTree error: " + ex.getMessage());
|
||||
}
|
||||
if (Client.user.isRemoveMap()) {
|
||||
menu.add(mapDelete);
|
||||
}
|
||||
menu.show(e.getComponent(), e.getX(), e.getY());
|
||||
}
|
||||
|
||||
private static void expandAllNodes(JTree tree, int startingIndex, int rowCount) {
|
||||
|
|
@ -126,13 +132,13 @@ public class MapTree extends JTree {
|
|||
}
|
||||
|
||||
public static void reload() {
|
||||
root.removeAllChildren();
|
||||
Collections.sort(Client.maps, new MapComparator());
|
||||
for (Map map : Client.maps) {
|
||||
DefaultMutableTreeNode node = new DefaultMutableTreeNode(map);
|
||||
root.add(node);
|
||||
}
|
||||
try {
|
||||
root.removeAllChildren();
|
||||
Collections.sort(Client.maps, new MapComparator());
|
||||
for (Map map : Client.maps) {
|
||||
DefaultMutableTreeNode node = new DefaultMutableTreeNode(map);
|
||||
root.add(node);
|
||||
}
|
||||
model.reload();
|
||||
expandAllNodes(tree, 0, tree.getRowCount());
|
||||
} catch (Exception e) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue