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 {
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{
s.updateWindows();
s.expandLayout(id);
created = true;
frame.setDefaultCloseOperation(frame.HIDE_ON_CLOSE);
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
s.m.hist.addEvent(lae);
}
else {
......@@ -204,7 +204,7 @@ public class Layout implements ActionListener{
frame = new JFrame("Layout settings");
frame.setResizable(false);
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*:");
id_tf = new JTextField();
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{
}
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{
}
/** 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_) {
//TODO: Maybe or maybe not
for(Window w:windows) {
for(Layout l:w.layouts) {
if(l.uses(id_)) return true;
}
}
return false;
}
/** Returns the parent element that contains the item of the given id **/
......
......@@ -103,7 +103,7 @@ public class Button extends Item implements ActionListener{
s.updateItems();
s.expandItem(id);
frame.setDefaultCloseOperation(frame.HIDE_ON_CLOSE);
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
created = true;
}
else {
......@@ -136,7 +136,7 @@ public class Button extends Item implements ActionListener{
frame = new JFrame("Button settings");
frame.setResizable(false);
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*:");
id_tf = new JTextField();
JLabel x_l = new JLabel("X:");
......@@ -400,6 +400,7 @@ public class Button extends Item implements ActionListener{
g.drawRect(x+x_,y+y_,bi.getWidth()-1,bi.getHeight()-1);
}
}
@Override
public boolean contains(int x_, int y_) {
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);
......@@ -408,4 +409,8 @@ public class Button extends Item implements ActionListener{
DefaultMutableTreeNode node = new DefaultMutableTreeNode("Button: "+id);
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{
s.updateItems();
s.expandItem(id);
frame.setDefaultCloseOperation(frame.HIDE_ON_CLOSE);
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
created = true;
}
else {
......@@ -170,7 +170,7 @@ public class Checkbox extends Item implements ActionListener{
frame = new JFrame("Checkbox settings");
frame.setResizable(false);
frame.setLayout(new FlowLayout());
frame.setDefaultCloseOperation(frame.DO_NOTHING_ON_CLOSE);
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
JLabel id_l = new JLabel("ID*:");
id_tf = new JTextField();
JLabel x_l = new JLabel("X:");
......@@ -287,18 +287,18 @@ public class Checkbox extends Item implements ActionListener{
general.setMaximumSize(new Dimension(495,165));
frame.add(general);
JPanel state = new JPanel(null);
state.add(state_l);
state.add(state_tf);
state.add(state_btn);
JPanel state_panel = new JPanel(null);
state_panel.add(state_l);
state_panel.add(state_tf);
state_panel.add(state_btn);
state_l.setBounds(5,15,75,24);
state_tf.setBounds(85,15,120,24);
state_btn.setBounds(210,15,24,24);
state.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Checkbox state"));
state.setMinimumSize(new Dimension(495,45));
state.setPreferredSize(new Dimension(495,45));
state.setMaximumSize(new Dimension(495,45));
frame.add(state);
state_panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Checkbox state"));
state_panel.setMinimumSize(new Dimension(495,45));
state_panel.setPreferredSize(new Dimension(495,45));
state_panel.setMaximumSize(new Dimension(495,45));
frame.add(state_panel);
JPanel state1 = new JPanel(null);
state1.add(up1_l);
......@@ -406,7 +406,7 @@ public class Checkbox extends Item implements ActionListener{
return;
}
}
if(state_tf.getText()=="") {
if(state_tf.getText().equals("")) {
JOptionPane.showMessageDialog(frame,"Please provide the state condition!","State not valid",JOptionPane.INFORMATION_MESSAGE);
return;
}
......@@ -498,6 +498,7 @@ public class Checkbox extends Item implements ActionListener{
frame.setVisible(false);
}
}
@Override
public void actionWasEdited(ActionEditor ae) {
if(ae==action1_ae) action1_tf.setText(action1_ae.getCode());
else if(ae==action2_ae) action2_tf.setText(action2_ae.getCode());
......@@ -547,6 +548,7 @@ public class Checkbox extends Item implements ActionListener{
g.drawRect(x+x_,y+y_,bi.getWidth()-1,bi.getHeight()-1);
}
}
@Override
public boolean contains(int x_, int y_) {
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);
......@@ -555,5 +557,8 @@ public class Checkbox extends Item implements ActionListener{
DefaultMutableTreeNode node = new DefaultMutableTreeNode("Checkbox: "+id);
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{
i.setOffset(x+offsetx,y+offsety);
}
}
@Override
public boolean contains(int x_, int y_) {
return (x_>=x+offsetx && y_>=y+offsety);
}
......@@ -272,19 +273,17 @@ public class Group extends Item implements ActionListener{
}
return node;
}
@Override
public Item getItem(String id_) {
if(id.equals(id_)) return this;
else {
for(int x=0;x<items.size();x++) {
Item i = items.get(x).getItem(id_);
if (i!=null) return i;
}
for(Item i:items) if(i.getItem(id_)!=null) return i.getItem(id_);
}
return null;
}
@Override
public java.util.List<Item> getParentListOf(String id_) {
for(int x=0;x<items.size();x++) {
Item i = items.get(x);
for(Item i:items) {
if(i.id.equals(id_)) {
return items;
}
......@@ -295,9 +294,9 @@ public class Group extends Item implements ActionListener{
}
return null;
}
@Override
public Item getParentOf(String id_) {
for(int x=0;x<items.size();x++) {
Item i = items.get(x);
for(Item i:items) {
if(i.id.equals(id_)) {
return this;
}
......@@ -306,4 +305,11 @@ public class Group extends Item implements ActionListener{
}
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{
frame.setVisible(false);
}
}
@Override
public void actionWasEdited(ActionEditor ae) {
if(ae==action2_ae) action2_tf.setText(action2_ae.getCode());
}
......@@ -378,6 +379,7 @@ public class Image extends Item implements ActionListener{
g.drawRect(x+x_,y+y_,bi.getWidth()-1,bi.getHeight()-1);
}
}
@Override
public boolean contains(int x_, int y_) {
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);
......@@ -386,4 +388,8 @@ public class Image extends Item implements ActionListener{
DefaultMutableTreeNode node = new DefaultMutableTreeNode("Image: "+id);
return node;
}
@Override
public boolean uses(String id_) {
return (image.equals(id_));
}
}
......@@ -146,7 +146,7 @@ public class Panel extends Item implements ActionListener{
for(Item i:items) {
i.setOffset(x,y);
}
frame.setDefaultCloseOperation(frame.HIDE_ON_CLOSE);
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
created = true;
ItemAddEvent paa = new ItemAddEvent(s.getParentListOf(id),this);
......@@ -183,7 +183,7 @@ public class Panel extends Item implements ActionListener{
frame = new JFrame("Panel settings");
frame.setResizable(false);
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*:");
id_tf = new JTextField();
JLabel x_l = new JLabel("X:");
......@@ -378,7 +378,8 @@ public class Panel extends Item implements ActionListener{
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);
}
public DefaultMutableTreeNode getTreeNode() {
......@@ -388,19 +389,19 @@ public class Panel extends Item implements ActionListener{
}
return node;
}
@Override
public Item getItem(String id_) {
if(id.equals(id_)) return this;
else {
for(int x=0;x<items.size();x++) {
Item i = items.get(x).getItem(id_);
if (i!=null) return i;
for(Item i:items) {
if (i.getItem(id_)!=null) return i.getItem(id_);
}
}
return null;
}
@Override
public java.util.List<Item> getParentListOf(String id_) {
for(int x=0;x<items.size();x++) {
Item i = items.get(x);
for(Item i:items) {
if(i.id.equals(id_)) {
return items;
}
......@@ -411,9 +412,9 @@ public class Panel extends Item implements ActionListener{
}
return null;
}
@Override
public Item getParentOf(String id_) {
for(int x=0;x<items.size();x++) {
Item i = items.get(x);
for(Item i:items) {
if(i.id.equals(id_)) {
return this;
}
......@@ -422,4 +423,11 @@ public class Panel extends Item implements ActionListener{
}
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{
}
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{
}
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{
DefaultMutableTreeNode node = new DefaultMutableTreeNode("SliderBackground: "+id);
return node;
}
@Override
public boolean uses(String id_) {
return (image.equals(id_));
}
}
......@@ -452,4 +452,8 @@ public class Text extends Item implements ActionListener{
DefaultMutableTreeNode node = new DefaultMutableTreeNode("Text: "+id);
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