set path of the FileChooser to current project XML location and started saving features development, removed formatter
This commit is contained in:
23
res/objecttypes - Copy.xml
Normal file
23
res/objecttypes - Copy.xml
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<objecttypes>
|
||||
<objecttype name="misato" color="#a0a0a4">
|
||||
<property name="class" type="string" default="Solid"/>
|
||||
<property name="drawbox" type="string" default="2 1 254 1 254 338 2 336"/>
|
||||
<property name="hitbox" type="string" default="Circle 4 6 24"/>
|
||||
</objecttype>
|
||||
<objecttype name="starlight" color="#a0a0a4">
|
||||
<property name="class" type="string" default="Solid"/>
|
||||
<property name="drawbox" type="string" default="2 1 253 1 254 468 2 490"/>
|
||||
<property name="hitbox" type="string" default="Rectangle 0 0 76 119"/>
|
||||
</objecttype>
|
||||
<objecttype name="tavern" color="#a0a0a4">
|
||||
<property name="class" type="string" default="Solid"/>
|
||||
<property name="drawbox" type="string" default="3 2 252 1 253 605 6 608"/>
|
||||
<property name="hitbox" type="string" default="Rectangle 0 0 96 98"/>
|
||||
</objecttype>
|
||||
<objecttype name="TopHome" color="#a0a0a4">
|
||||
<property name="class" type="string" default="Solid"/>
|
||||
<property name="drawbox" type="string" default="3 2 252 1 253 605 6 608"/>
|
||||
<property name="hitbox" type="string" default="Rectangle 0 0 96 98"/>
|
||||
</objecttype>
|
||||
</objecttypes>
|
||||
5
src/events/EntityDrawboxChangedEvent.java
Normal file
5
src/events/EntityDrawboxChangedEvent.java
Normal file
@ -0,0 +1,5 @@
|
||||
package events;
|
||||
|
||||
public class EntityDrawboxChangedEvent {
|
||||
|
||||
}
|
||||
5
src/events/EntityDrawboxChangedListener.java
Normal file
5
src/events/EntityDrawboxChangedListener.java
Normal file
@ -0,0 +1,5 @@
|
||||
package events;
|
||||
|
||||
public interface EntityDrawboxChangedListener {
|
||||
|
||||
}
|
||||
@ -4,6 +4,7 @@ import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@ -27,8 +28,6 @@ public class DrawboxEditor extends Editable {
|
||||
logger.setLevel(Level.CONFIG);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void drawing(Graphics2D g) {
|
||||
Drawbox drawbox = entity.getDrawbox();
|
||||
@ -71,7 +70,9 @@ public class DrawboxEditor extends Editable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveDataInEntity() { }
|
||||
public void saveDataInEntity() {
|
||||
entity.setDrawbox(new Drawbox(drawboxPoints));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@ -92,6 +93,8 @@ public class DrawboxEditor extends Editable {
|
||||
}
|
||||
basePoints.add(baseStart);
|
||||
basePoints.add(baseEnd);
|
||||
|
||||
saveDataInEntity();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -103,6 +106,9 @@ public class DrawboxEditor extends Editable {
|
||||
repaint();
|
||||
}
|
||||
|
||||
|
||||
// эта штука очищает точки при нажатии универскальной кнопки очистки в Main GUI. Это следует рефакторнуть и вместо передачи события сюда,
|
||||
// обрабатывать его прямо в Main GUI(лямбдой) вызывая отсюда только метод в духе clearPoints()
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JTabbedPane parent = (JTabbedPane) getParent();
|
||||
|
||||
@ -22,7 +22,7 @@ public abstract class Editable extends JPanel implements MouseListener, MouseMot
|
||||
|
||||
protected ListGUI listGUI;
|
||||
protected Entity entity;
|
||||
protected String name;
|
||||
protected String selectedEntityName;
|
||||
protected BufferedImage image;
|
||||
JPanel drawPanel;
|
||||
|
||||
@ -51,11 +51,11 @@ public abstract class Editable extends JPanel implements MouseListener, MouseMot
|
||||
|
||||
//get,set для name
|
||||
public String getName() {
|
||||
return name;
|
||||
return selectedEntityName;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
this.selectedEntityName = name;
|
||||
}
|
||||
|
||||
//заполнить текущую сущность по имени.
|
||||
@ -96,13 +96,13 @@ public abstract class Editable extends JPanel implements MouseListener, MouseMot
|
||||
//TODO: надо бы элегантнее пробросить сюда ListGUI - просто передача его в аргументах немножко громоздкая
|
||||
// как-то обыграть это через события?
|
||||
// ps. попытки обратиться к eventSource проваливаются - ListGUI это панель, уже внутри которой лежит JList
|
||||
name = listGUI.getSelectedName();
|
||||
selectedEntityName = listGUI.getSelectedName();
|
||||
try {
|
||||
entity = Project.getInstance().getEntityByName(name);
|
||||
entity = Project.getInstance().getEntityByName(selectedEntityName);
|
||||
} catch (Exception e1) {
|
||||
logger.severe("Entity with name '"+name+"' was not found! Cannot display it on panel!");
|
||||
logger.severe("Entity with name '"+selectedEntityName+"' was not found! Cannot display it on panel!");
|
||||
}
|
||||
image = Project.getInstance().loadImageByName(name);
|
||||
image = Project.getInstance().loadImageByName(selectedEntityName);
|
||||
//TODO: if(image == null) вызов FileChooser'a и выбор изображения
|
||||
|
||||
this.repaint();
|
||||
|
||||
@ -16,6 +16,7 @@ import javax.swing.JScrollPane;
|
||||
import javax.swing.JTabbedPane;
|
||||
|
||||
import listeners.OpenXMLFileButtonListener;
|
||||
import repository.Project;
|
||||
|
||||
public class MainGUI extends JFrame{
|
||||
ListGUI list;
|
||||
@ -67,7 +68,7 @@ public class MainGUI extends JFrame{
|
||||
OpenXMLFileButtonListener = new OpenXMLFileButtonListener(list);
|
||||
|
||||
openXMLJButton = createButton("XML",5,5, OpenXMLFileButtonListener,"res/xml.png");
|
||||
saveXMLJButton = createButton("Save",80,5,null,"res/download.png");
|
||||
saveXMLJButton = createButton("Save",80,5,(e)-> Project.getInstance().printXMlToConsole(),"res/download.png");
|
||||
clearLinesJButton = createButton("Clear lines",155,5,null,"res/destroy.png");
|
||||
|
||||
clearLinesJButton.addActionListener(drawBoxPanel);
|
||||
|
||||
@ -13,6 +13,8 @@ import org.xml.sax.SAXException;
|
||||
import gui.MainGUI;
|
||||
|
||||
public class Launcher {
|
||||
|
||||
private static MainGUI mainGUI;
|
||||
|
||||
public static void main(String[] args) throws SAXException, IOException, ParserConfigurationException {
|
||||
// Настройка системы логгирования
|
||||
@ -31,7 +33,12 @@ public class Launcher {
|
||||
rootLogger.info("Root Handler Logging level is "+lv.getName());
|
||||
|
||||
MainGUI gui = new MainGUI();
|
||||
mainGUI = gui;
|
||||
gui.setVisible(true);
|
||||
}
|
||||
|
||||
public static MainGUI getMainGUI() {
|
||||
return mainGUI;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -2,21 +2,25 @@ package listeners;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
|
||||
import gui.ListGUI;
|
||||
import launch.Launcher;
|
||||
import repository.Project;
|
||||
|
||||
public class OpenXMLFileButtonListener extends JFileChooser implements ActionListener
|
||||
{
|
||||
//public String directory = "C:\\Users\\sivan\\Desktop\\Диплом\\GUI-Collision&Drawing-Metadata-Editor\\res\\";
|
||||
public String directory = "res/";
|
||||
public String file = "objecttypes.xml";
|
||||
|
||||
ListGUI listGUI;
|
||||
|
||||
public OpenXMLFileButtonListener(ListGUI listGUI) {
|
||||
super(Project.getInstance().getXMLPath()
|
||||
+ Project.getInstance().getXMLFileName());// Create file chooser at the current project file directory
|
||||
this.listGUI = listGUI;
|
||||
}
|
||||
|
||||
@ -30,11 +34,11 @@ public class OpenXMLFileButtonListener extends JFileChooser implements ActionLis
|
||||
int result = this.showOpenDialog(OpenXMLFileButtonListener.this);
|
||||
if (result == JFileChooser.APPROVE_OPTION )
|
||||
{
|
||||
directory = this.getCurrentDirectory().toString()+'/';
|
||||
directory = this.getCurrentDirectory().toString()+File.separator;
|
||||
file = this.getName(getSelectedFile()).toString();
|
||||
Project.getInstance().load(directory, file);
|
||||
listGUI.updateList();
|
||||
|
||||
|
||||
//Debug
|
||||
System.out.println(directory + file);
|
||||
}
|
||||
|
||||
@ -4,8 +4,6 @@ public class Entity {
|
||||
private String thisName;
|
||||
private Drawbox thisDrawbox;
|
||||
private Hitbox thisHitbox;
|
||||
private Formatter formaterHitbox;
|
||||
private Formatter formaterDrawbox;
|
||||
private String type;
|
||||
|
||||
public Entity(String name,String drawbox,String hitbox) {
|
||||
@ -40,14 +38,6 @@ public class Entity {
|
||||
thisHitbox = outHitbox;
|
||||
};
|
||||
|
||||
public void setFormaterHitbox(Formatter outFormaterHitbox) {
|
||||
formaterHitbox = outFormaterHitbox;
|
||||
};
|
||||
|
||||
public void setFormaterDrawbox(Formatter outFormaterDrawbox) {
|
||||
formaterDrawbox = outFormaterDrawbox;
|
||||
};
|
||||
|
||||
public String getName() {
|
||||
return thisName;
|
||||
};
|
||||
@ -60,13 +50,6 @@ public class Entity {
|
||||
return thisHitbox;
|
||||
};
|
||||
|
||||
public Formatter getFormaterHitbox() {
|
||||
return formaterHitbox;
|
||||
};
|
||||
|
||||
public Formatter getFormaterDrawbox() {
|
||||
return formaterDrawbox;
|
||||
};
|
||||
public void PrintEntity() {
|
||||
System.out.println("---------------------");
|
||||
System.out.println("Name: "+thisName);
|
||||
|
||||
@ -1,5 +0,0 @@
|
||||
package model;
|
||||
|
||||
public interface Formatter {
|
||||
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
package model;
|
||||
|
||||
public class FormatterCircle implements Formatter {
|
||||
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
package model;
|
||||
|
||||
public class FormatterRectangle implements Formatter {
|
||||
|
||||
}
|
||||
25
src/model/IsometricCoordsConverter.java
Normal file
25
src/model/IsometricCoordsConverter.java
Normal file
@ -0,0 +1,25 @@
|
||||
package model;
|
||||
|
||||
public class IsometricCoordsConverter {
|
||||
|
||||
/**
|
||||
* @param result - Point object to store the result
|
||||
* @return x and y converted to isometic coords
|
||||
* */
|
||||
public static Point cartesianToIsometric(float cartX, float cartY, Point result) {
|
||||
result.x = cartX - cartY;
|
||||
result.y = (cartX + cartY) / 2;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param result - Point object to store the result
|
||||
* @return x and y converted to cartesian coords
|
||||
* */
|
||||
public static Point isometricToCartesian(float x, float y, Point result) {
|
||||
result.x = (2 * y + x) / 2;
|
||||
result.y = (2 * y - x) / 2;
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -29,14 +29,12 @@ import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import exception.DuplicateEntryException;
|
||||
import launch.Launcher;
|
||||
import model.Entity;
|
||||
|
||||
|
||||
/**
|
||||
* Класс данных, который оперирует их сохранением, загрузкой, и хранением в памяти.
|
||||
* Он нужен для отделения Модели от Представления (см. <a href="https://ru.wikipedia.org/wiki/Model-View-Controller">MVC</a>), чтобы их можно было менять независимо друг от друга.
|
||||
* Например, при добавлении новой кнопки данные можно будет получить через существующий интерфейс класса не меняя код.
|
||||
*
|
||||
* ВАЖНО: данный класс хранит так же актуальную копию XML-представления файла
|
||||
* */
|
||||
public class Project implements Iterable<Entity> {
|
||||
@ -133,6 +131,8 @@ public class Project implements Iterable<Entity> {
|
||||
factory = DocumentBuilderFactory.newInstance();
|
||||
builder = factory.newDocumentBuilder();
|
||||
document = builder.parse(new File(path+fileName));
|
||||
if(Launcher.getMainGUI() != null) // at the first program launch, main gui creates list gui before static link to main gui is set
|
||||
Launcher.getMainGUI().setTitle("Hitbox/Drawbox Editor: " + path + fileName);
|
||||
// Получение списка всех элементов objecttype внутри корневого элемента (getDocumentElement возвращает ROOT элемент XML файла).
|
||||
NodeList objecttypeElements = document.getDocumentElement().getElementsByTagName("objecttype");
|
||||
for(int i = 0; i < objecttypeElements.getLength(); i++) {
|
||||
|
||||
Reference in New Issue
Block a user