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.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.MouseListener;
|
import java.awt.event.MouseListener;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.JMenuItem;
|
import javax.swing.JMenuItem;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
|
|
@ -80,7 +82,8 @@ public class MapTree extends JTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void getContextMenuMap(MouseEvent e, Map m) {
|
private static void getContextMenuMap(MouseEvent e, Map m) {
|
||||||
JMenuItem mapAdd = new JMenuItem("Přidat mapu", new ImageIcon("img/add.png"));
|
try {
|
||||||
|
JMenuItem mapAdd = new JMenuItem("Přidat mapu", new ImageIcon(ImageIO.read(MapTree.class.getResourceAsStream("/img/add.png"))));
|
||||||
mapAdd.addActionListener(new ActionListener() {
|
mapAdd.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
|
@ -88,7 +91,7 @@ public class MapTree extends JTree {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
JMenuItem mapDelete = new JMenuItem("Smazat mapu", new ImageIcon("img/trash.png"));
|
JMenuItem mapDelete = new JMenuItem("Smazat mapu", new ImageIcon(ImageIO.read(MapTree.class.getResourceAsStream("/img/trash.png"))));
|
||||||
mapDelete.addActionListener(new ActionListener() {
|
mapDelete.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
|
@ -113,6 +116,9 @@ public class MapTree extends JTree {
|
||||||
menu.add(mapDelete);
|
menu.add(mapDelete);
|
||||||
}
|
}
|
||||||
menu.show(e.getComponent(), e.getX(), e.getY());
|
menu.show(e.getComponent(), e.getX(), e.getY());
|
||||||
|
} catch (IOException ex) {
|
||||||
|
LogFile.printErr("MapTree error: " + ex.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void expandAllNodes(JTree tree, int startingIndex, int rowCount) {
|
private static void expandAllNodes(JTree tree, int startingIndex, int rowCount) {
|
||||||
|
|
@ -126,13 +132,13 @@ public class MapTree extends JTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reload() {
|
public static void reload() {
|
||||||
|
try {
|
||||||
root.removeAllChildren();
|
root.removeAllChildren();
|
||||||
Collections.sort(Client.maps, new MapComparator());
|
Collections.sort(Client.maps, new MapComparator());
|
||||||
for (Map map : Client.maps) {
|
for (Map map : Client.maps) {
|
||||||
DefaultMutableTreeNode node = new DefaultMutableTreeNode(map);
|
DefaultMutableTreeNode node = new DefaultMutableTreeNode(map);
|
||||||
root.add(node);
|
root.add(node);
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
model.reload();
|
model.reload();
|
||||||
expandAllNodes(tree, 0, tree.getRowCount());
|
expandAllNodes(tree, 0, tree.getRowCount());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue