Storing sprites in Entity objects now, moderate ListGUI refactoring to simplify list icons creation. See more in the task description https://trello.com/c/tkAjRpcG
This commit is contained in:
@ -43,7 +43,6 @@ public class ListGUI extends JPanel {
|
||||
JButton addListElementEntity;
|
||||
JButton removeListElementEntity;
|
||||
JButton addPicEntity;
|
||||
String pathImage;
|
||||
JList list;
|
||||
JScrollPane scroll;
|
||||
ActionListener removeEntity;
|
||||
@ -91,7 +90,7 @@ public class ListGUI extends JPanel {
|
||||
return (String) list.getSelectedValue();
|
||||
}
|
||||
|
||||
public void addListElement(String name,String solid) throws DuplicateEntryException {
|
||||
public void addListElement(String name, String solid) throws DuplicateEntryException {
|
||||
// плейсхолдеры для новых хитбоксов и дроубоксов, иначе всё валится с NPE
|
||||
List<Point> hitboxPoints = new LinkedList<Point>();
|
||||
List<Point> drawboxPoints = new LinkedList<Point>();
|
||||
@ -107,13 +106,15 @@ public class ListGUI extends JPanel {
|
||||
}
|
||||
|
||||
public void updateList() {
|
||||
String[] nameList = createNameList();
|
||||
testModel.removeAllElements();
|
||||
for (String name : nameList)
|
||||
testModel.addElement(name);
|
||||
|
||||
for (Entity e: Project.getInstance()) {
|
||||
testModel.addElement(e.getName());
|
||||
|
||||
pathImage = Project.getInstance().getXMLPath();
|
||||
createImageMap(nameList);
|
||||
// Create and store JList items icons in a map to prevent their unneccessary re-creation
|
||||
iconMap.put(e.getName(), createListIconFromSprite( e.getImage() ));
|
||||
}
|
||||
|
||||
list.updateUI();
|
||||
}
|
||||
|
||||
@ -136,7 +137,7 @@ public class ListGUI extends JPanel {
|
||||
}
|
||||
private final float iconMaxWidth = 40, iconMaxHeight = 40;
|
||||
|
||||
public Icon imageScaling(BufferedImage image) {
|
||||
private Icon createListIconFromSprite(BufferedImage image) {
|
||||
CustomIcon icon = null;
|
||||
try {
|
||||
int imageWidth = image.getWidth(), imageHeight = image.getHeight();
|
||||
@ -184,14 +185,6 @@ public class ListGUI extends JPanel {
|
||||
}
|
||||
}
|
||||
|
||||
private void createImageMap(String[] nameList) {
|
||||
for (int i = 0; i < nameList.length; i++) {
|
||||
String name = nameList[i];
|
||||
BufferedImage image = Project.getInstance().loadImageByName(name);
|
||||
iconMap.put(name, imageScaling(image));
|
||||
}
|
||||
}
|
||||
|
||||
private JButton createButton(int width,int height,ActionListener listener,String pathImage) {
|
||||
JButton button = new JButton(new ImageIcon(pathImage));
|
||||
button.setSize(110, 46);
|
||||
|
||||
Reference in New Issue
Block a user