Commit 0399979a authored by Daniel Dreibrodt's avatar Daniel Dreibrodt

Resources in use cannot be deleted any longer

parent 70ed848a
...@@ -121,4 +121,11 @@ public abstract class Item { ...@@ -121,4 +121,11 @@ public abstract class Item {
public void actionWasEdited(ActionEditor ae) { public void actionWasEdited(ActionEditor ae) {
} }
/**
* Checks whether the resource with the given ID is used by this item or one of its subitems
* @param id_ The resource's id
*/
public boolean uses(String id_) {
return false;
}
} }
...@@ -178,7 +178,7 @@ public class Layout implements ActionListener{ ...@@ -178,7 +178,7 @@ public class Layout implements ActionListener{
s.updateWindows(); s.updateWindows();
s.expandLayout(id); s.expandLayout(id);
created = true; created = true;
frame.setDefaultCloseOperation(frame.HIDE_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
s.m.hist.addEvent(lae); s.m.hist.addEvent(lae);
} }
else { else {
...@@ -204,7 +204,7 @@ public class Layout implements ActionListener{ ...@@ -204,7 +204,7 @@ public class Layout implements ActionListener{
frame = new JFrame("Layout settings"); frame = new JFrame("Layout settings");
frame.setResizable(false); frame.setResizable(false);
frame.setLayout(new FlowLayout()); frame.setLayout(new FlowLayout());
if(!created) frame.setDefaultCloseOperation(frame.DO_NOTHING_ON_CLOSE); if(!created) frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
JLabel id_l = new JLabel("ID*:"); JLabel id_l = new JLabel("ID*:");
id_tf = new JTextField(); id_tf = new JTextField();
id_tf.setToolTipText("Name of the layout (it may be used for actions). Two layouts cannot have the same id."); id_tf.setToolTipText("Name of the layout (it may be used for actions). Two layouts cannot have the same id.");
...@@ -435,4 +435,14 @@ public class Layout implements ActionListener{ ...@@ -435,4 +435,14 @@ public class Layout implements ActionListener{
} }
return null; return null;
} }
/**
* Checks whether an item in this layout uses the resource of the given ID
* @param id_ The ID of the resource
*/
public boolean uses(String id_) {
for(Item i:items) {
if(i.uses(id_)) return true;
}
return false;
}
} }
...@@ -455,7 +455,11 @@ public class Skin implements ActionListener{ ...@@ -455,7 +455,11 @@ public class Skin implements ActionListener{
} }
/** Returns <b>true</b> if the resource with the given id is in use by any item of the skin **/ /** Returns <b>true</b> if the resource with the given id is in use by any item of the skin **/
public boolean isUsed(String id_) { public boolean isUsed(String id_) {
//TODO: Maybe or maybe not for(Window w:windows) {
for(Layout l:w.layouts) {
if(l.uses(id_)) return true;
}
}
return false; return false;
} }
/** Returns the parent element that contains the item of the given id **/ /** Returns the parent element that contains the item of the given id **/
......
...@@ -103,7 +103,7 @@ public class Button extends Item implements ActionListener{ ...@@ -103,7 +103,7 @@ public class Button extends Item implements ActionListener{
s.updateItems(); s.updateItems();
s.expandItem(id); s.expandItem(id);
frame.setDefaultCloseOperation(frame.HIDE_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
created = true; created = true;
} }
else { else {
...@@ -136,7 +136,7 @@ public class Button extends Item implements ActionListener{ ...@@ -136,7 +136,7 @@ public class Button extends Item implements ActionListener{
frame = new JFrame("Button settings"); frame = new JFrame("Button settings");
frame.setResizable(false); frame.setResizable(false);
frame.setLayout(new FlowLayout()); frame.setLayout(new FlowLayout());
if(!created) frame.setDefaultCloseOperation(frame.DO_NOTHING_ON_CLOSE); if(!created) frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
JLabel id_l = new JLabel("ID*:"); JLabel id_l = new JLabel("ID*:");
id_tf = new JTextField(); id_tf = new JTextField();
JLabel x_l = new JLabel("X:"); JLabel x_l = new JLabel("X:");
...@@ -400,6 +400,7 @@ public class Button extends Item implements ActionListener{ ...@@ -400,6 +400,7 @@ public class Button extends Item implements ActionListener{
g.drawRect(x+x_,y+y_,bi.getWidth()-1,bi.getHeight()-1); g.drawRect(x+x_,y+y_,bi.getWidth()-1,bi.getHeight()-1);
} }
} }
@Override
public boolean contains(int x_, int y_) { public boolean contains(int x_, int y_) {
java.awt.image.BufferedImage bi = s.getBitmapImage(up); java.awt.image.BufferedImage bi = s.getBitmapImage(up);
return (x_>=x+offsetx && x_<=x+bi.getWidth()+offsetx && y_>=y+offsety && y_<=y+bi.getHeight()+offsety); return (x_>=x+offsetx && x_<=x+bi.getWidth()+offsetx && y_>=y+offsety && y_<=y+bi.getHeight()+offsety);
...@@ -408,4 +409,8 @@ public class Button extends Item implements ActionListener{ ...@@ -408,4 +409,8 @@ public class Button extends Item implements ActionListener{
DefaultMutableTreeNode node = new DefaultMutableTreeNode("Button: "+id); DefaultMutableTreeNode node = new DefaultMutableTreeNode("Button: "+id);
return node; return node;
} }
@Override
public boolean uses(String id_) {
return (up.equals(id_)||over.equals(id_)||down.equals(id_));
}
} }
...@@ -130,7 +130,7 @@ public class Checkbox extends Item implements ActionListener{ ...@@ -130,7 +130,7 @@ public class Checkbox extends Item implements ActionListener{
s.updateItems(); s.updateItems();
s.expandItem(id); s.expandItem(id);
frame.setDefaultCloseOperation(frame.HIDE_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
created = true; created = true;
} }
else { else {
...@@ -170,7 +170,7 @@ public class Checkbox extends Item implements ActionListener{ ...@@ -170,7 +170,7 @@ public class Checkbox extends Item implements ActionListener{
frame = new JFrame("Checkbox settings"); frame = new JFrame("Checkbox settings");
frame.setResizable(false); frame.setResizable(false);
frame.setLayout(new FlowLayout()); frame.setLayout(new FlowLayout());
frame.setDefaultCloseOperation(frame.DO_NOTHING_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
JLabel id_l = new JLabel("ID*:"); JLabel id_l = new JLabel("ID*:");
id_tf = new JTextField(); id_tf = new JTextField();
JLabel x_l = new JLabel("X:"); JLabel x_l = new JLabel("X:");
...@@ -287,18 +287,18 @@ public class Checkbox extends Item implements ActionListener{ ...@@ -287,18 +287,18 @@ public class Checkbox extends Item implements ActionListener{
general.setMaximumSize(new Dimension(495,165)); general.setMaximumSize(new Dimension(495,165));
frame.add(general); frame.add(general);
JPanel state = new JPanel(null); JPanel state_panel = new JPanel(null);
state.add(state_l); state_panel.add(state_l);
state.add(state_tf); state_panel.add(state_tf);
state.add(state_btn); state_panel.add(state_btn);
state_l.setBounds(5,15,75,24); state_l.setBounds(5,15,75,24);
state_tf.setBounds(85,15,120,24); state_tf.setBounds(85,15,120,24);
state_btn.setBounds(210,15,24,24); state_btn.setBounds(210,15,24,24);
state.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Checkbox state")); state_panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Checkbox state"));
state.setMinimumSize(new Dimension(495,45)); state_panel.setMinimumSize(new Dimension(495,45));
state.setPreferredSize(new Dimension(495,45)); state_panel.setPreferredSize(new Dimension(495,45));
state.setMaximumSize(new Dimension(495,45)); state_panel.setMaximumSize(new Dimension(495,45));
frame.add(state); frame.add(state_panel);
JPanel state1 = new JPanel(null); JPanel state1 = new JPanel(null);
state1.add(up1_l); state1.add(up1_l);
...@@ -406,7 +406,7 @@ public class Checkbox extends Item implements ActionListener{ ...@@ -406,7 +406,7 @@ public class Checkbox extends Item implements ActionListener{
return; return;
} }
} }
if(state_tf.getText()=="") { if(state_tf.getText().equals("")) {
JOptionPane.showMessageDialog(frame,"Please provide the state condition!","State not valid",JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(frame,"Please provide the state condition!","State not valid",JOptionPane.INFORMATION_MESSAGE);
return; return;
} }
...@@ -498,6 +498,7 @@ public class Checkbox extends Item implements ActionListener{ ...@@ -498,6 +498,7 @@ public class Checkbox extends Item implements ActionListener{
frame.setVisible(false); frame.setVisible(false);
} }
} }
@Override
public void actionWasEdited(ActionEditor ae) { public void actionWasEdited(ActionEditor ae) {
if(ae==action1_ae) action1_tf.setText(action1_ae.getCode()); if(ae==action1_ae) action1_tf.setText(action1_ae.getCode());
else if(ae==action2_ae) action2_tf.setText(action2_ae.getCode()); else if(ae==action2_ae) action2_tf.setText(action2_ae.getCode());
...@@ -547,6 +548,7 @@ public class Checkbox extends Item implements ActionListener{ ...@@ -547,6 +548,7 @@ public class Checkbox extends Item implements ActionListener{
g.drawRect(x+x_,y+y_,bi.getWidth()-1,bi.getHeight()-1); g.drawRect(x+x_,y+y_,bi.getWidth()-1,bi.getHeight()-1);
} }
} }
@Override
public boolean contains(int x_, int y_) { public boolean contains(int x_, int y_) {
java.awt.image.BufferedImage bi = s.getBitmapImage(up1); java.awt.image.BufferedImage bi = s.getBitmapImage(up1);
return (x_>=x+offsetx && x_<=x+bi.getWidth()+offsetx && y_>=y+offsety && y_<=y+bi.getHeight()+offsety); return (x_>=x+offsetx && x_<=x+bi.getWidth()+offsetx && y_>=y+offsety && y_<=y+bi.getHeight()+offsety);
...@@ -555,5 +557,8 @@ public class Checkbox extends Item implements ActionListener{ ...@@ -555,5 +557,8 @@ public class Checkbox extends Item implements ActionListener{
DefaultMutableTreeNode node = new DefaultMutableTreeNode("Checkbox: "+id); DefaultMutableTreeNode node = new DefaultMutableTreeNode("Checkbox: "+id);
return node; return node;
} }
@Override
public boolean uses(String id_) {
return (up1.equals(id_)||up2.equals(id_)||over1.equals(id_)||over2.equals(id_)||down1.equals(id_)||down2.equals(id_));
}
} }
...@@ -262,6 +262,7 @@ public class Group extends Item implements ActionListener{ ...@@ -262,6 +262,7 @@ public class Group extends Item implements ActionListener{
i.setOffset(x+offsetx,y+offsety); i.setOffset(x+offsetx,y+offsety);
} }
} }
@Override
public boolean contains(int x_, int y_) { public boolean contains(int x_, int y_) {
return (x_>=x+offsetx && y_>=y+offsety); return (x_>=x+offsetx && y_>=y+offsety);
} }
...@@ -272,19 +273,17 @@ public class Group extends Item implements ActionListener{ ...@@ -272,19 +273,17 @@ public class Group extends Item implements ActionListener{
} }
return node; return node;
} }
@Override
public Item getItem(String id_) { public Item getItem(String id_) {
if(id.equals(id_)) return this; if(id.equals(id_)) return this;
else { else {
for(int x=0;x<items.size();x++) { for(Item i:items) if(i.getItem(id_)!=null) return i.getItem(id_);
Item i = items.get(x).getItem(id_);
if (i!=null) return i;
}
} }
return null; return null;
} }
@Override
public java.util.List<Item> getParentListOf(String id_) { public java.util.List<Item> getParentListOf(String id_) {
for(int x=0;x<items.size();x++) { for(Item i:items) {
Item i = items.get(x);
if(i.id.equals(id_)) { if(i.id.equals(id_)) {
return items; return items;
} }
...@@ -295,9 +294,9 @@ public class Group extends Item implements ActionListener{ ...@@ -295,9 +294,9 @@ public class Group extends Item implements ActionListener{
} }
return null; return null;
} }
@Override
public Item getParentOf(String id_) { public Item getParentOf(String id_) {
for(int x=0;x<items.size();x++) { for(Item i:items) {
Item i = items.get(x);
if(i.id.equals(id_)) { if(i.id.equals(id_)) {
return this; return this;
} }
...@@ -306,4 +305,11 @@ public class Group extends Item implements ActionListener{ ...@@ -306,4 +305,11 @@ public class Group extends Item implements ActionListener{
} }
return null; return null;
} }
@Override
public boolean uses(String id_) {
for(Item i:items) {
if(i.uses(id_)) return true;
}
return false;
}
} }
...@@ -346,6 +346,7 @@ public class Image extends Item implements ActionListener{ ...@@ -346,6 +346,7 @@ public class Image extends Item implements ActionListener{
frame.setVisible(false); frame.setVisible(false);
} }
} }
@Override
public void actionWasEdited(ActionEditor ae) { public void actionWasEdited(ActionEditor ae) {
if(ae==action2_ae) action2_tf.setText(action2_ae.getCode()); if(ae==action2_ae) action2_tf.setText(action2_ae.getCode());
} }
...@@ -378,6 +379,7 @@ public class Image extends Item implements ActionListener{ ...@@ -378,6 +379,7 @@ public class Image extends Item implements ActionListener{
g.drawRect(x+x_,y+y_,bi.getWidth()-1,bi.getHeight()-1); g.drawRect(x+x_,y+y_,bi.getWidth()-1,bi.getHeight()-1);
} }
} }
@Override
public boolean contains(int x_, int y_) { public boolean contains(int x_, int y_) {
java.awt.image.BufferedImage bi = s.getBitmapImage(image); java.awt.image.BufferedImage bi = s.getBitmapImage(image);
return (x_>=x+offsetx && x_<=x+bi.getWidth()+offsetx && y_>=y+offsety && y_<=y+bi.getHeight()+offsety); return (x_>=x+offsetx && x_<=x+bi.getWidth()+offsetx && y_>=y+offsety && y_<=y+bi.getHeight()+offsety);
...@@ -386,4 +388,8 @@ public class Image extends Item implements ActionListener{ ...@@ -386,4 +388,8 @@ public class Image extends Item implements ActionListener{
DefaultMutableTreeNode node = new DefaultMutableTreeNode("Image: "+id); DefaultMutableTreeNode node = new DefaultMutableTreeNode("Image: "+id);
return node; return node;
} }
@Override
public boolean uses(String id_) {
return (image.equals(id_));
}
} }
...@@ -146,7 +146,7 @@ public class Panel extends Item implements ActionListener{ ...@@ -146,7 +146,7 @@ public class Panel extends Item implements ActionListener{
for(Item i:items) { for(Item i:items) {
i.setOffset(x,y); i.setOffset(x,y);
} }
frame.setDefaultCloseOperation(frame.HIDE_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
created = true; created = true;
ItemAddEvent paa = new ItemAddEvent(s.getParentListOf(id),this); ItemAddEvent paa = new ItemAddEvent(s.getParentListOf(id),this);
...@@ -183,7 +183,7 @@ public class Panel extends Item implements ActionListener{ ...@@ -183,7 +183,7 @@ public class Panel extends Item implements ActionListener{
frame = new JFrame("Panel settings"); frame = new JFrame("Panel settings");
frame.setResizable(false); frame.setResizable(false);
frame.setLayout(new FlowLayout()); frame.setLayout(new FlowLayout());
if(!created) frame.setDefaultCloseOperation(frame.DO_NOTHING_ON_CLOSE); if(!created) frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
JLabel id_l = new JLabel("ID*:"); JLabel id_l = new JLabel("ID*:");
id_tf = new JTextField(); id_tf = new JTextField();
JLabel x_l = new JLabel("X:"); JLabel x_l = new JLabel("X:");
...@@ -378,7 +378,8 @@ public class Panel extends Item implements ActionListener{ ...@@ -378,7 +378,8 @@ public class Panel extends Item implements ActionListener{
g.drawRect(x+x_,y+y_,width-1,height-1); g.drawRect(x+x_,y+y_,width-1,height-1);
} }
} }
public boolean contains(int x_, int y_) { @Override
public boolean contains(int x_, int y_) {
return (x_>=x+offsetx && x_<=x+width+offsetx && y_>=y+offsety && y_<=y+height+offsety); return (x_>=x+offsetx && x_<=x+width+offsetx && y_>=y+offsety && y_<=y+height+offsety);
} }
public DefaultMutableTreeNode getTreeNode() { public DefaultMutableTreeNode getTreeNode() {
...@@ -388,19 +389,19 @@ public class Panel extends Item implements ActionListener{ ...@@ -388,19 +389,19 @@ public class Panel extends Item implements ActionListener{
} }
return node; return node;
} }
@Override
public Item getItem(String id_) { public Item getItem(String id_) {
if(id.equals(id_)) return this; if(id.equals(id_)) return this;
else { else {
for(int x=0;x<items.size();x++) { for(Item i:items) {
Item i = items.get(x).getItem(id_); if (i.getItem(id_)!=null) return i.getItem(id_);
if (i!=null) return i;
} }
} }
return null; return null;
} }
@Override
public java.util.List<Item> getParentListOf(String id_) { public java.util.List<Item> getParentListOf(String id_) {
for(int x=0;x<items.size();x++) { for(Item i:items) {
Item i = items.get(x);
if(i.id.equals(id_)) { if(i.id.equals(id_)) {
return items; return items;
} }
...@@ -411,9 +412,9 @@ public class Panel extends Item implements ActionListener{ ...@@ -411,9 +412,9 @@ public class Panel extends Item implements ActionListener{
} }
return null; return null;
} }
@Override
public Item getParentOf(String id_) { public Item getParentOf(String id_) {
for(int x=0;x<items.size();x++) { for(Item i:items) {
Item i = items.get(x);
if(i.id.equals(id_)) { if(i.id.equals(id_)) {
return this; return this;
} }
...@@ -422,4 +423,11 @@ public class Panel extends Item implements ActionListener{ ...@@ -422,4 +423,11 @@ public class Panel extends Item implements ActionListener{
} }
return null; return null;
} }
@Override
public boolean uses(String id_) {
for(Item i:items) {
if(i.uses(id_)) return true;
}
return false;
}
} }
...@@ -754,4 +754,8 @@ public class Playtree extends Item implements ActionListener{ ...@@ -754,4 +754,8 @@ public class Playtree extends Item implements ActionListener{
} }
else return null; else return null;
} }
@Override
public boolean uses(String id_) {
return (((slider!=null)?slider.uses(id_):false)||bgimage.equals(id_)||openimage.equals(id_)||closedimage.equals(id_)||itemimage.equals(id_)||font.equals(id_));
}
} }
...@@ -592,4 +592,8 @@ public class Slider extends Item implements ActionListener{ ...@@ -592,4 +592,8 @@ public class Slider extends Item implements ActionListener{
} }
else return null; else return null;
} }
@Override
public boolean uses(String id_) {
return(((sbg!=null)?sbg.uses(id_):false)||up.equals(id_)||over.equals(id_)||down.equals(id_));
}
} }
...@@ -286,5 +286,8 @@ public class SliderBackground extends Item implements ActionListener{ ...@@ -286,5 +286,8 @@ public class SliderBackground extends Item implements ActionListener{
DefaultMutableTreeNode node = new DefaultMutableTreeNode("SliderBackground: "+id); DefaultMutableTreeNode node = new DefaultMutableTreeNode("SliderBackground: "+id);
return node; return node;
} }
@Override
public boolean uses(String id_) {
return (image.equals(id_));
}
} }
...@@ -452,4 +452,8 @@ public class Text extends Item implements ActionListener{ ...@@ -452,4 +452,8 @@ public class Text extends Item implements ActionListener{
DefaultMutableTreeNode node = new DefaultMutableTreeNode("Text: "+id); DefaultMutableTreeNode node = new DefaultMutableTreeNode("Text: "+id);
return node; return node;
} }
@Override
public boolean uses(String id_) {
return (font.equals(id_));
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment