Working version of the refactoring DrawboxEditor. Added ToolBar in Editor
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
<objecttypes>
|
||||
<objecttype color="#a0a0a4" name="misato">
|
||||
<property default="Solid" name="class" type="string"/>
|
||||
<property default="22 10 232 3 264 199 5 198 " name="drawbox" type="string"/>
|
||||
<property default="15 4 217 0 209 197 30 180 " name="drawbox" type="string"/>
|
||||
<property default="Circle 4 6 24" name="hitbox" type="string"/>
|
||||
</objecttype>
|
||||
<objecttype color="#a0a0a4" name="starlight">
|
||||
@ -22,7 +22,7 @@
|
||||
</objecttype>
|
||||
<objecttype color="000000" name="newtest">
|
||||
<property default="solid" name="class" type="string"/>
|
||||
<property default="0 0 0 0 0 0 0 0" name="drawbox" type="string"/>
|
||||
<property default="93 15 404 57 389 162 207 164 " name="drawbox" type="string"/>
|
||||
<property default="Rectangle 0 0 0 0" name="hitbox" type="string"/>
|
||||
</objecttype>
|
||||
</objecttypes>
|
||||
|
||||
@ -28,12 +28,21 @@ public class DrawboxEditor extends Editable {
|
||||
|
||||
DrawboxEditor(ListGUI listGUI) {
|
||||
super(listGUI);
|
||||
//Если будет ошибка, попробовать в Editable прокинуть canvas, как сделано с ListGUI
|
||||
canvas = new EditableCanvas(entity, image);
|
||||
add(canvas,BorderLayout.CENTER);
|
||||
canvas.setBackground(Color.GRAY);
|
||||
|
||||
canvas = new EditableCanvas();
|
||||
add(canvas);
|
||||
//canvas.setBackground(Color.GRAY);
|
||||
canvas.setDrawboxRectengleRenderingFunction();
|
||||
canvas.setVisible(true);
|
||||
|
||||
clearLinesJButton.addActionListener((e)->{
|
||||
if(entity != null) {
|
||||
entity.getDrawbox().getDrawboxlistPoints().clear();
|
||||
entity.getDrawbox().getbaseListPoints().clear();
|
||||
canvas.repaint();
|
||||
}});
|
||||
|
||||
|
||||
logger.setLevel(Level.CONFIG);
|
||||
}
|
||||
|
||||
@ -53,22 +62,4 @@ public class DrawboxEditor extends Editable {
|
||||
|
||||
|
||||
|
||||
public void clearPoints(){
|
||||
|
||||
}
|
||||
// эта штука очищает точки при нажатии универскальной кнопки очистки в Main GUI. Это следует рефакторнуть и вместо передачи события сюда,
|
||||
// обрабатывать его прямо в Main GUI(лямбдой) вызывая отсюда только метод в духе clearPoints()
|
||||
/*@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JTabbedPane parent = (JTabbedPane) getParent();
|
||||
if(parent.getSelectedComponent() == this){
|
||||
if(entity != null) {
|
||||
entity.getDrawbox().getDrawboxlistPoints().clear();
|
||||
entity.getDrawbox().getbaseListPoints().clear();
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
package gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
@ -11,10 +10,12 @@ import java.awt.image.BufferedImage;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JToolBar;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
@ -28,15 +29,22 @@ public abstract class Editable extends JPanel implements MouseListener, MouseMot
|
||||
protected String selectedEntityName;
|
||||
protected BufferedImage image;
|
||||
EditableCanvas canvas;
|
||||
JToolBar toolbar = new JToolBar("Toolbar",JToolBar.VERTICAL);
|
||||
JButton clearLinesJButton;
|
||||
|
||||
private static Logger logger = Logger.getLogger("gui.Editable");
|
||||
|
||||
|
||||
Editable(ListGUI listGUI){
|
||||
this.listGUI = listGUI;
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
addMouseListener(this);
|
||||
addMouseMotionListener(this);
|
||||
clearLinesJButton = createButton("Clear lines",null,"res/destroy.png");
|
||||
|
||||
toolbar.setBorder(BorderFactory.createLoweredBevelBorder());
|
||||
toolbar.addSeparator();
|
||||
toolbar.add(clearLinesJButton);
|
||||
this.add(toolbar,BorderLayout.EAST);
|
||||
|
||||
// РАСКОММЕНТИТЬ ЕСЛИ НУЖНО ВЫВОДИТЬ ПОДРОБНЫЕ ЛОГИ
|
||||
logger.setLevel(Level.ALL);
|
||||
@ -90,11 +98,13 @@ public abstract class Editable extends JPanel implements MouseListener, MouseMot
|
||||
}
|
||||
image = Project.getInstance().loadImageByName(selectedEntityName);
|
||||
//TODO: if(image == null) вызов FileChooser'a и выбор изображения
|
||||
this.repaint();
|
||||
//canvas.repaint();
|
||||
System.out.println(" Edit image = " + image);
|
||||
System.out.println("---");
|
||||
System.out.println(" Canvas image = " + image);
|
||||
canvas.setEntity(entity);
|
||||
canvas.setImage(image);
|
||||
canvas.repaint();
|
||||
// System.out.println(" Canvas image = " + canvas.image);
|
||||
// System.out.println(" Canvas entity = " + canvas.entity);
|
||||
// System.out.println(" Editable image = " + image);
|
||||
// System.out.println(" Editable entity = " + entity);
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,7 +113,7 @@ public abstract class Editable extends JPanel implements MouseListener, MouseMot
|
||||
button.addActionListener(listener);
|
||||
button.setContentAreaFilled(false);
|
||||
button.setFocusPainted(false);
|
||||
button.setPreferredSize(new Dimension(72, 38));
|
||||
button.setPreferredSize(new Dimension(38, 38));
|
||||
return button;
|
||||
}
|
||||
|
||||
|
||||
@ -8,34 +8,38 @@ import java.awt.event.MouseMotionListener;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
import gui.render.DrawboxRectengleRenderingFunction;
|
||||
import gui.render.HitboxCircleRenderingFunction;
|
||||
import gui.render.HitboxRectengleRenderingFunction;
|
||||
import gui.render.ShapeRenderingFunction;
|
||||
import model.Entity;
|
||||
import repository.Project;
|
||||
|
||||
public class EditableCanvas extends JPanel implements MouseListener, MouseMotionListener, ListSelectionListener {
|
||||
public class EditableCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
||||
|
||||
DrawboxRectengleRenderingFunction drawboxRectengleRenderFunct;
|
||||
HitboxRectengleRenderingFunction hitboxRectengleRenderFunct;
|
||||
HitboxCircleRenderingFunction hitboxCircleRenderFunct;
|
||||
ShapeRenderingFunction renderingFunction;
|
||||
Entity entity;
|
||||
BufferedImage image;
|
||||
|
||||
|
||||
public EditableCanvas(Entity entity, BufferedImage image) {
|
||||
this.entity = entity;
|
||||
this.image = image;
|
||||
drawboxRectengleRenderFunct = new DrawboxRectengleRenderingFunction(entity);
|
||||
public EditableCanvas() {
|
||||
drawboxRectengleRenderFunct = new DrawboxRectengleRenderingFunction();
|
||||
hitboxRectengleRenderFunct = new HitboxRectengleRenderingFunction();
|
||||
hitboxCircleRenderFunct = new HitboxCircleRenderingFunction();
|
||||
drawboxRectengleRenderFunct.subscribe(Project.getInstance()); // подписка: Project получит данные ввиде обьекта Event, содержащий данные drawbox при отрисовке последней точки из 4-х.
|
||||
//hitboxPanel.subscribe(Project.getInstance());
|
||||
addMouseListener(this);
|
||||
addMouseMotionListener(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void drawing(Graphics2D g) {
|
||||
if(renderingFunction!=null) {
|
||||
if(renderingFunction!=null&&entity!=null) {
|
||||
renderingFunction.drawing(g);
|
||||
}
|
||||
}
|
||||
@ -43,25 +47,38 @@ public class EditableCanvas extends JPanel implements MouseListener, MouseMotion
|
||||
public void setDrawboxRectengleRenderingFunction() {
|
||||
renderingFunction = drawboxRectengleRenderFunct;
|
||||
}
|
||||
public void setHitboxRectengleRenderingFunction() {
|
||||
renderingFunction = hitboxRectengleRenderFunct;
|
||||
}
|
||||
public void setHitboxCircleRenderingFunction() {
|
||||
renderingFunction = hitboxCircleRenderFunct;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
if(renderingFunction!=null) {
|
||||
//System.out.println("moved");
|
||||
if(renderingFunction!=null&&entity!=null) {
|
||||
System.out.println("x="+e.getX()+"y="+e.getY());
|
||||
renderingFunction.mouseMoved(e);
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if(renderingFunction!=null) {
|
||||
//System.out.println("Clicked");
|
||||
if(renderingFunction!=null&&entity!=null) {
|
||||
renderingFunction.mouseClicked(e);
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if(renderingFunction!=null) {
|
||||
//System.out.println("mousePressed");
|
||||
if(renderingFunction!=null&&entity!=null) {
|
||||
renderingFunction.mousePressed(e);
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,6 +92,14 @@ public class EditableCanvas extends JPanel implements MouseListener, MouseMotion
|
||||
}
|
||||
}
|
||||
|
||||
public void setEntity(Entity e) {
|
||||
entity = e;
|
||||
drawboxRectengleRenderFunct.setEntity(e);
|
||||
}
|
||||
|
||||
public void setImage(BufferedImage image) {
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -86,11 +111,7 @@ public class EditableCanvas extends JPanel implements MouseListener, MouseMotion
|
||||
public void mouseEntered(MouseEvent e) {}
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {}
|
||||
@Override
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
//this.repaint();
|
||||
//System.out.println(" Canvas image = " + image);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
|
||||
import events.EntityDrawboxChangedEvent;
|
||||
import events.EntityDrawboxChangedListener;
|
||||
@ -117,6 +118,10 @@ public class HitboxEditor extends Editable {
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
//super.valueChanged(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ public class MainGUI extends JFrame{
|
||||
ActionListener OpenXMLFileButtonListener;
|
||||
JButton openXMLJButton;
|
||||
JButton saveXMLJButton;
|
||||
JButton clearLinesJButton;
|
||||
|
||||
public static JTabbedPane editorPane;
|
||||
DrawboxEditor drawBoxPanel;
|
||||
HitboxEditor hitboxPanel;
|
||||
@ -50,7 +50,6 @@ public class MainGUI extends JFrame{
|
||||
|
||||
openXMLJButton = createButton("XML", OpenXMLFileButtonListener,"res/xml.png");
|
||||
saveXMLJButton = createButton("Save",(e)-> Project.getInstance().writeXML(),"res/download.png");
|
||||
clearLinesJButton = createButton("Clear lines",null,"res/destroy.png");
|
||||
|
||||
gridButtonBar.add(openXMLJButton);
|
||||
gridButtonBar.add(saveXMLJButton);
|
||||
@ -67,8 +66,8 @@ public class MainGUI extends JFrame{
|
||||
editorPane.setVisible(true);
|
||||
add(editorPane,BorderLayout.CENTER);
|
||||
|
||||
editorPane.addTab("Hitbox", hitboxPanel);
|
||||
editorPane.addTab("Drawbox", drawBoxPanel);
|
||||
editorPane.addTab("Hitbox", hitboxPanel);
|
||||
repaint();
|
||||
|
||||
}
|
||||
|
||||
@ -21,8 +21,8 @@ public class DrawboxRectengleRenderingFunction implements ShapeRenderingFunction
|
||||
private List<EntityDrawboxChangedListener> listeners = new ArrayList<>();
|
||||
Entity entity;
|
||||
Logger logger = Logger.getLogger("gui.DrawboxRectangleEditor");
|
||||
public DrawboxRectengleRenderingFunction(Entity entity) {
|
||||
this.entity = entity;
|
||||
public DrawboxRectengleRenderingFunction() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -147,4 +147,8 @@ public class DrawboxRectengleRenderingFunction implements ShapeRenderingFunction
|
||||
entity.setDrawbox(new Drawbox(drawboxPoints));
|
||||
}
|
||||
|
||||
public void setEntity(Entity e) {
|
||||
entity = e;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user