Commit d60b32b1 authored by Daniel Dreibrodt's avatar Daniel Dreibrodt

improvement: resources can be renamed while in use and all references to it will be updated

fix: language system has problems with some special characters
parent 18b3e5e6
......@@ -89,6 +89,8 @@ public class Helper {
/**
* Taken from http://www.rgagnon.com/javadetails/java-0064.html
* Licensed under Creative Commons BY-NC-SA 2.5
* @author Real Gagnon
* @param in Source File
* @param out Destination File
* @throws java.io.IOException
......
......@@ -235,4 +235,13 @@ public abstract class Item {
vis = s.gvars.parseBoolean(visible);
}
/**
* Changes all references to the resource formerly identfied by <i>oldid</i> to the resources <i>newid</id>
* @param oldid The former ID of the renamed resource
* @param newid The new ID of the renamed resource
*/
public void resourceRenamed(String oldid, String newid) {
}
}
......@@ -108,12 +108,18 @@ public class Language {
*/
private static void load(File f) {
try {
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
//FileReader fr = new FileReader(f);
FileInputStream fis = new FileInputStream(f);
String line = "";
while((line = br.readLine()) != null) {
line = new String(line.getBytes(), "UTF-8");
String text = "";
byte[] chars = new byte[1024];
while(fis.read(chars)!=-1) text+=new String(chars, "UTF-8");
String[] lines = text.split("\\n");
for(String line:lines) {
line = line.trim();
if(line.startsWith("@include")) {
String file = line.substring(9);
load(new File(f.getParent() + File.separator + file));
......@@ -125,8 +131,7 @@ public class Language {
}
}
br.close();
fr.close();
fis.close();
} catch(FileNotFoundException ex) {
ex.printStackTrace();
} catch(IOException ex) {
......
......@@ -543,6 +543,15 @@ public class Layout implements ActionListener{
}
return false;
}
/**
* Changes all references to the resource formerly identfied by <i>oldid</i> to the resources <i>newid</id>
* @param oldid The former ID of the renamed resource
* @param newid The new ID of the renamed resource
*/
public void resourceRenamed(String oldid, String newid) {
for(Item i:items) i.resourceRenamed(oldid, newid);
}
/**
* Renames the Layout and all its content after the copy process
* @param p The renaming pattern, %oldid% will be replaced by the Layout's/Item's old ID
......
......@@ -1098,10 +1098,12 @@ public class Main extends javax.swing.JFrame implements ActionListener, TreeSele
int returnVal = bitmap_adder.showOpenDialog(this);
if(returnVal == JFileChooser.APPROVE_OPTION) {
File[] files = bitmap_adder.getSelectedFiles();
vlcskineditor.resources.Bitmap last_added = null;
for(int i=0;i<files.length;i++) {
s.resources.add(new vlcskineditor.resources.Bitmap(s,files[i]));
s.resources.add(last_added = new vlcskineditor.resources.Bitmap(s,files[i]));
}
s.updateResources();
if(last_added!=null) s.expandItem(last_added.id);
}
}
// </editor-fold>
......@@ -1145,10 +1147,12 @@ public class Main extends javax.swing.JFrame implements ActionListener, TreeSele
int returnVal = font_adder.showOpenDialog(this);
if(returnVal == JFileChooser.APPROVE_OPTION) {
File[] files = font_adder.getSelectedFiles();
vlcskineditor.resources.Font last_added = null;
for(int i=0;i<files.length;i++) {
s.resources.add(new vlcskineditor.resources.Font(s,files[i]));
s.resources.add(last_added = new vlcskineditor.resources.Font(s,files[i]));
}
s.updateResources();
if(last_added!=null) s.expandItem(last_added.id);
}
}
// </editor-fold>
......
......@@ -668,6 +668,20 @@ public class Skin implements ActionListener{
}
return false;
}
/**
* Changes all references to the resource formerly identfied by <i>oldid</i> to the resources <i>newid</id>
* @param oldid The former ID of the renamed resource
* @param newid The new ID of the renamed resource
*/
public void resourceRenamed(String oldid, String newid) {
for(Window w:windows) {
for(Layout l:w.layouts) {
l.resourceRenamed(oldid, newid);
}
}
}
/** Returns the parent element that contains the item of the given id **/
public java.util.List<Item> getParentListOf(String id_) {
return active_layout.getParentListOf(id_);
......
......@@ -570,4 +570,12 @@ public class Button extends Item implements ActionListener{
public boolean uses(String id_) {
return (up.equals(id_)||over.equals(id_)||down.equals(id_));
}
@Override
public void resourceRenamed(String oldid, String newid) {
if(up.equals(oldid)) up = newid;
if(over.equals(oldid)) over = newid;
if(down.equals(oldid)) down = newid;
}
}
......@@ -773,4 +773,15 @@ public class Checkbox extends Item implements ActionListener{
vis = s.gvars.parseBoolean(visible);
state_bool = s.gvars.parseBoolean(state);
}
@Override
public void resourceRenamed(String oldid, String newid) {
if(up1.equals(oldid)) up1 = newid;
if(over1.equals(oldid)) over1 = newid;
if(down1.equals(oldid)) down1 = newid;
if(up2.equals(oldid)) up2 = newid;
if(over2.equals(oldid)) over2 = newid;
if(down2.equals(oldid)) down2 = newid;
}
}
......@@ -19,7 +19,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
package vlcskineditor.items;
import vlcskineditor.*;
......@@ -37,8 +36,8 @@ import vlcskineditor.resources.ImageResource;
* Image item
* @author Daniel Dreibrodt
*/
public class Image extends Item implements ActionListener{
public class Image extends Item implements ActionListener {
public final String RESIZE_DEFAULT = "mosaic";
public final String ACTION_DEFAULT = "none";
public final String ACTION2_DEFAULT = "none";
......@@ -46,16 +45,14 @@ public class Image extends Item implements ActionListener{
public String resize = RESIZE_DEFAULT;
public String action = ACTION_DEFAULT;
public String action2 = ACTION2_DEFAULT;
JFrame frame = null;
JTextField id_tf, x_tf, y_tf, help_tf, visible_tf, image_tf, action2_tf;
JComboBox lefttop_cb, rightbottom_cb, xkeepratio_cb, ykeepratio_cb, resize_cb, action_cb;
JButton visible_btn, action2_btn, ok_btn, cancel_btn, help_btn;
ActionEditor action2_ae;
ImageResource image_res;
{
type = Language.get("IMAGE");
}
......@@ -67,10 +64,10 @@ public class Image extends Item implements ActionListener{
*/
public Image(Node n, Skin s_) {
s = s_;
id = XML.getStringAttributeValue(n, "id", Language.get("UNNAMED").replaceAll("%t",type).replaceAll("%i",String.valueOf(s.getNewId())));
image = XML.getStringAttributeValue(n, "image", image);
id = XML.getStringAttributeValue(n, "id", Language.get("UNNAMED").replaceAll("%t", type).replaceAll("%i", String.valueOf(s.getNewId())));
image = XML.getStringAttributeValue(n, "image", image);
action = XML.getStringAttributeValue(n, "action", action);
action2 = XML.getStringAttributeValue(n, "action2", action2);
resize = XML.getStringAttributeValue(n, "resize", resize);
......@@ -89,37 +86,62 @@ public class Image extends Item implements ActionListener{
created = true;
}
/** Creates a new instance of Image
* @param xmlcode The XML code
* @param s_ The parent skin
*/
public Image(String xmlcode, Skin s_) {
s=s_;
image = XML.getValue(xmlcode,"image");
s = s_;
image = XML.getValue(xmlcode, "image");
image_res = s.getImageResource(image);
if(xmlcode.indexOf("resize=\"")!=-1) resize = XML.getValue(xmlcode,"resize");
if(xmlcode.indexOf("action=\"")!=-1) action = XML.getValue(xmlcode,"action");
if(xmlcode.indexOf("action2=\"")!=-1) action2 = XML.getValue(xmlcode,"action2");
if(xmlcode.indexOf("x=\"")!=-1) x = XML.getIntValue(xmlcode,"x");
if(xmlcode.indexOf("y=\"")!=-1) y = XML.getIntValue(xmlcode,"y");
if(xmlcode.indexOf("id=\"")!=-1) id = XML.getValue(xmlcode,"id");
else id = Language.get("UNNAMED").replaceAll("%t",type).replaceAll("%i",String.valueOf(s.getNewId()));
if(xmlcode.indexOf("lefttop=\"")!=-1) lefttop = XML.getValue(xmlcode,"lefttop");
if(xmlcode.indexOf("rightbottom=\"")!=-1) rightbottom = XML.getValue(xmlcode,"rightbottom");
if(xmlcode.indexOf("xkeepratio=\"")!=-1) xkeepratio = XML.getBoolValue(xmlcode,"xkeepratio");
if(xmlcode.indexOf("ykeepratio=\"")!=-1) ykeepratio = XML.getBoolValue(xmlcode,"ykeepratio");
if(xmlcode.indexOf(" visible=\"")!=-1) visible = XML.getValue(xmlcode,"visible");
if(xmlcode.indexOf("resize=\"") != -1) {
resize = XML.getValue(xmlcode, "resize");
}
if(xmlcode.indexOf("action=\"") != -1) {
action = XML.getValue(xmlcode, "action");
}
if(xmlcode.indexOf("action2=\"") != -1) {
action2 = XML.getValue(xmlcode, "action2");
}
if(xmlcode.indexOf("x=\"") != -1) {
x = XML.getIntValue(xmlcode, "x");
}
if(xmlcode.indexOf("y=\"") != -1) {
y = XML.getIntValue(xmlcode, "y");
}
if(xmlcode.indexOf("id=\"") != -1) {
id = XML.getValue(xmlcode, "id");
} else {
id = Language.get("UNNAMED").replaceAll("%t", type).replaceAll("%i", String.valueOf(s.getNewId()));
}
if(xmlcode.indexOf("lefttop=\"") != -1) {
lefttop = XML.getValue(xmlcode, "lefttop");
}
if(xmlcode.indexOf("rightbottom=\"") != -1) {
rightbottom = XML.getValue(xmlcode, "rightbottom");
}
if(xmlcode.indexOf("xkeepratio=\"") != -1) {
xkeepratio = XML.getBoolValue(xmlcode, "xkeepratio");
}
if(xmlcode.indexOf("ykeepratio=\"") != -1) {
ykeepratio = XML.getBoolValue(xmlcode, "ykeepratio");
}
if(xmlcode.indexOf(" visible=\"") != -1) {
visible = XML.getValue(xmlcode, "visible");
}
created = true;
}
public Image(Skin s_) {
s = s_;
image = "";
id = Language.get("UNNAMED").replaceAll("%t",type).replaceAll("%i",String.valueOf(s.getNewId()));
id = Language.get("UNNAMED").replaceAll("%t", type).replaceAll("%i", String.valueOf(s.getNewId()));
showOptions();
}
public void update() {
if(!created) {
id = id_tf.getText();
......@@ -135,19 +157,18 @@ public class Image extends Item implements ActionListener{
image = image_tf.getText();
resize = resize_cb.getSelectedItem().toString();
action = action_cb.getSelectedItem().toString();
action2 = action2_tf.getText();
action2 = action2_tf.getText();
s.updateItems();
s.updateItems();
s.expandItem(id);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
created = true;
ItemAddEvent iae = new ItemAddEvent(s.getParentListOf(id),this);
ItemAddEvent iae = new ItemAddEvent(s.getParentListOf(id), this);
s.m.hist.addEvent(iae);
}
else {
} else {
ImageEditEvent iee = new ImageEditEvent(this);
id = id_tf.getText();
x = Integer.parseInt(x_tf.getText());
y = Integer.parseInt(y_tf.getText());
......@@ -161,30 +182,33 @@ public class Image extends Item implements ActionListener{
image = image_tf.getText();
resize = resize_cb.getSelectedItem().toString();
action = action_cb.getSelectedItem().toString();
action2 = action2_tf.getText();
s.updateItems();
action2 = action2_tf.getText();
s.updateItems();
s.expandItem(id);
iee.setNew();
s.m.hist.addEvent(iee);
}
updateToGlobalVariables();
}
@Override
public void showOptions() {
if(frame==null) {
if(frame == null) {
frame = new JFrame(Language.get("WIN_IMAGE_TITLE"));
frame.setIconImage(Main.edit_icon.getImage());
frame.setResizable(false);
if(!created) frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
if(!created) {
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
}
JLabel id_l = new JLabel(Language.get("WIN_ITEM_ID"));
id_tf = new JTextField();
id_tf = new JTextField();
JLabel x_l = new JLabel(Language.get("WIN_ITEM_X"));
x_tf = new JTextField();
x_tf = new JTextField();
x_tf.setDocument(new NumbersOnlyDocument());
JLabel y_l = new JLabel(Language.get("WIN_ITEM_Y"));
y_tf = new JTextField();
y_tf = new JTextField();
y_tf.setDocument(new NumbersOnlyDocument());
String[] align_values = {"lefttop", "leftbottom", "righttop", "rightbottom"};
JLabel lefttop_l = new JLabel(Language.get("WIN_ITEM_LEFTTOP"));
......@@ -193,7 +217,7 @@ public class Image extends Item implements ActionListener{
JLabel rightbottom_l = new JLabel(Language.get("WIN_ITEM_RIGHTBOTTOM"));
rightbottom_cb = new JComboBox(align_values);
rightbottom_cb.setToolTipText(Language.get("WIN_ITEM_RIGHTBOTTOM_TIP"));
Object[] bool_values = { true, false };
Object[] bool_values = {true, false};
JLabel xkeepratio_l = new JLabel(Language.get("WIN_ITEM_XKEEPRATIO"));
xkeepratio_cb = new JComboBox(bool_values);
xkeepratio_cb.setToolTipText(Language.get("WIN_ITEM_XKEEPRATIO_TIP"));
......@@ -202,29 +226,29 @@ public class Image extends Item implements ActionListener{
ykeepratio_cb.setToolTipText(Language.get("WIN_ITEM_YKEEPRATIO_TIP"));
JLabel visible_l = new JLabel(Language.get("WIN_ITEM_VISIBLE"));
visible_tf = new JTextField();
visible_btn = new JButton("",Main.help_icon);
visible_btn = new JButton("", Main.help_icon);
visible_btn.addActionListener(this);
JLabel help_l = new JLabel(Language.get("WIN_ITEM_HELP"));
help_tf = new JTextField();
help_tf.setToolTipText(Language.get("WIN_ITEM_HELP_TIP"));
JLabel image_l = new JLabel(Language.get("WIN_IMAGE_IMAGE"));
image_tf = new JTextField();
image_tf.setToolTipText(Language.get("WIN_IMAGE_IMAGE_TIP"));
JLabel resize_l = new JLabel(Language.get("WIN_IMAGE_RESIZE"));
String[] resize_values = { "mosaic" , "scale" };
String[] resize_values = {"mosaic", "scale"};
resize_cb = new JComboBox(resize_values);
resize_cb.setToolTipText(Language.get("WIN_IMAGE_RESIZE_TIP"));
JLabel action_l = new JLabel(Language.get("WIN_IMAGE_ACTION"));
String[] action_values = { "none", "move","resizeE","resizeS","resizeSE" };
String[] action_values = {"none", "move", "resizeE", "resizeS", "resizeSE"};
action_cb = new JComboBox(action_values);
action_cb.setToolTipText(Language.get("WIN_IMAGE_ACTION_TIP"));
JLabel action2_l = new JLabel(Language.get("WIN_IMAGE_ACTION2"));
action2_tf = new JTextField();
action2_tf.setToolTipText(Language.get("WIN_IMAGE_ACTION2_TIP"));
action2_btn = new JButton("",Main.editor_icon);
action2_btn = new JButton("", Main.editor_icon);
action2_btn.addActionListener(this);
ok_btn = new JButton(Language.get("BUTTON_OK"));
ok_btn.addActionListener(this);
cancel_btn = new JButton(Language.get("BUTTON_CANCEL"));
......@@ -235,19 +259,19 @@ public class Image extends Item implements ActionListener{
JLabel attr_l = new JLabel(Language.get("NOTE_STARRED"));
//Distance of textfields to WEST edge of container
Component[] labels = { id_l, x_l, y_l, lefttop_l, rightbottom_l, xkeepratio_l, ykeepratio_l, visible_l, help_l, image_l, resize_l, action_l, action2_l};
int tf_dx = Helper.maxWidth(labels)+10;
Component[] labels = {id_l, x_l, y_l, lefttop_l, rightbottom_l, xkeepratio_l, ykeepratio_l, visible_l, help_l, image_l, resize_l, action_l, action2_l};
int tf_dx = Helper.maxWidth(labels) + 10;
//Max. textfield width
int tf_wd = Main.TEXTFIELD_WIDTH;
JPanel general = new JPanel(null);
general.add(id_l);
general.add(id_tf);
id_tf.setPreferredSize(new Dimension(tf_wd,id_tf.getPreferredSize().height));
id_tf.setPreferredSize(new Dimension(tf_wd, id_tf.getPreferredSize().height));
general.add(x_l);
general.add(x_tf);
general.add(y_l);
general.add(y_tf);
general.add(y_tf);
general.add(lefttop_l);
general.add(lefttop_cb);
general.add(rightbottom_l);
......@@ -335,11 +359,11 @@ public class Image extends Item implements ActionListener{
general_layout.putConstraint(SpringLayout.SOUTH, general, 10, SpringLayout.SOUTH, help_tf);
frame.add(general);
JPanel image_panel = new JPanel(null);
image_panel.add(image_l);
image_panel.add(image_tf);
image_tf.setPreferredSize(new Dimension(tf_wd,image_tf.getPreferredSize().height));
image_tf.setPreferredSize(new Dimension(tf_wd, image_tf.getPreferredSize().height));
image_panel.add(resize_l);
image_panel.add(resize_cb);
image_panel.add(action_l);
......@@ -350,7 +374,7 @@ public class Image extends Item implements ActionListener{
image_panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), Language.get("WIN_IMAGE_ATTR")));
SpringLayout image_layout = new SpringLayout();
image_layout.putConstraint(SpringLayout.NORTH, image_l, 5, SpringLayout.NORTH, image_panel);
image_layout.putConstraint(SpringLayout.WEST, image_l, 5, SpringLayout.WEST, image_panel);
......@@ -363,14 +387,14 @@ public class Image extends Item implements ActionListener{
image_layout.putConstraint(SpringLayout.VERTICAL_CENTER, resize_cb, 0, SpringLayout.VERTICAL_CENTER, resize_l);
image_layout.putConstraint(SpringLayout.WEST, resize_cb, tf_dx, SpringLayout.WEST, image_panel);
image_layout.putConstraint(SpringLayout.EAST, resize_cb, 0, SpringLayout.EAST, image_tf);
image_layout.putConstraint(SpringLayout.NORTH, action_l, 10, SpringLayout.SOUTH, resize_cb);
image_layout.putConstraint(SpringLayout.WEST, action_l, 5, SpringLayout.WEST, image_panel);
image_layout.putConstraint(SpringLayout.VERTICAL_CENTER, action_cb, 0, SpringLayout.VERTICAL_CENTER, action_l);
image_layout.putConstraint(SpringLayout.WEST, action_cb, tf_dx, SpringLayout.WEST, image_panel);
image_layout.putConstraint(SpringLayout.EAST, action_cb, 0, SpringLayout.EAST, image_tf);
image_layout.putConstraint(SpringLayout.NORTH, action2_l, 10, SpringLayout.SOUTH, action_cb);
image_layout.putConstraint(SpringLayout.WEST, action2_l, 5, SpringLayout.WEST, image_panel);
......@@ -384,15 +408,15 @@ public class Image extends Item implements ActionListener{
image_layout.putConstraint(SpringLayout.EAST, image_panel, 5, SpringLayout.EAST, image_tf);
image_layout.putConstraint(SpringLayout.SOUTH, image_panel, 10, SpringLayout.SOUTH, action2_btn);
image_panel.setLayout(image_layout);
image_panel.setLayout(image_layout);
frame.add(image_panel);
frame.add(ok_btn);
frame.add(cancel_btn);
frame.add(help_btn);
frame.add(help_btn);
frame.add(attr_l);
SpringLayout layout = new SpringLayout();
layout.putConstraint(SpringLayout.NORTH, general, 5, SpringLayout.NORTH, frame.getContentPane());
......@@ -419,10 +443,10 @@ public class Image extends Item implements ActionListener{
frame.setLayout(layout);
frame.pack();
frame.getRootPane().setDefaultButton(ok_btn);
}
id_tf.setText(id);
id_tf.setText(id);
x_tf.setText(String.valueOf(x));
y_tf.setText(String.valueOf(y));
lefttop_cb.setSelectedItem(lefttop);
......@@ -431,30 +455,30 @@ public class Image extends Item implements ActionListener{
ykeepratio_cb.setSelectedItem(ykeepratio);
visible_tf.setText(visible);
help_tf.setText(help);
image_tf.setText(image);
resize_cb.setSelectedItem(resize);
action_cb.setSelectedItem(action);
action2_tf.setText(action2);
frame.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource().equals(ok_btn)) {
if(id_tf.getText().equals("")) {
JOptionPane.showMessageDialog(frame,Language.get("ERROR_ID_INVALID_MSG"),Language.get("ERROR_ID_INVALID_TITLE"),JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(frame, Language.get("ERROR_ID_INVALID_MSG"), Language.get("ERROR_ID_INVALID_TITLE"), JOptionPane.INFORMATION_MESSAGE);
return;
}
else if(!id_tf.getText().equals(id)) {
} else if(!id_tf.getText().equals(id)) {
if(s.idExists(id_tf.getText())) {
JOptionPane.showMessageDialog(frame,Language.get("ERROR_ID_EXISTS_MSG").replaceAll("%i", id_tf.getText()),Language.get("ERROR_ID_INVALID_TITLE"),JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(frame, Language.get("ERROR_ID_EXISTS_MSG").replaceAll("%i", id_tf.getText()), Language.get("ERROR_ID_INVALID_TITLE"), JOptionPane.INFORMATION_MESSAGE);
return;
}
}
image_res = s.getImageResource(image_tf.getText());
if(image_res==null) {
JOptionPane.showMessageDialog(frame,"The bitmap \""+image_tf.getText()+"\" does not exist!","Image not valid",JOptionPane.INFORMATION_MESSAGE);
if(image_res == null) {
JOptionPane.showMessageDialog(frame, "The bitmap \"" + image_tf.getText() + "\" does not exist!", "Image not valid", JOptionPane.INFORMATION_MESSAGE);
image_res = s.getImageResource(image);
return;
}
......@@ -462,79 +486,124 @@ public class Image extends Item implements ActionListener{
frame.setVisible(false);
frame.dispose();
frame = null;
}
else if(e.getSource().equals(help_btn)) {
} else if(e.getSource().equals(help_btn)) {
Helper.browse("http://www.videolan.org/vlc/skinedhlp/i-image.html");
}
else if(e.getSource().equals(action2_btn)) {
if(action2_ae==null) action2_ae = new ActionEditor(this);
} else if(e.getSource().equals(action2_btn)) {
if(action2_ae == null) {
action2_ae = new ActionEditor(this);
}
action2_ae.editAction(action2_tf.getText());
}
else if(e.getSource().equals(visible_btn)) {
} else if(e.getSource().equals(visible_btn)) {
Helper.browse("http://www.videolan.org/vlc/skinedhlp/boolexpr.html");
}
else if(e.getSource().equals(cancel_btn)) {
} else if(e.getSource().equals(cancel_btn)) {
if(!created) {
java.util.List<Item> l = s.getParentListOf(id);
if(l!=null) l.remove(this);
if(l != null) {
l.remove(this);
}
}
frame.setVisible(false);
frame.dispose();
frame = null;
}
}
@Override
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());
}
}
@Override
public String returnCode(String indent) {
String code = indent+"<Image";
if (!id.equals(ID_DEFAULT)) code+=" id=\""+id+"\"";
if (x!=X_DEFAULT) code+=" x=\""+String.valueOf(x)+"\"";
if (y!=Y_DEFAULT) code+=" y=\""+String.valueOf(y)+"\"";
code+=" image=\""+image+"\"";
if (!action.equals(ACTION_DEFAULT)) code+=" action=\""+action+"\"";
if (!action2.equals(ACTION2_DEFAULT)) code+=" action2=\""+action2+"\"";
if (!resize.equals(RESIZE_DEFAULT)) code+=" resize=\""+resize+"\"";
if (!lefttop.equals(LEFTTOP_DEFAULT)) code+=" lefttop=\""+lefttop+"\"";
if (!rightbottom.equals(RIGHTBOTTOM_DEFAULT)) code+=" rightbottom=\""+rightbottom+"\"";
if (xkeepratio!=XKEEPRATIO_DEFAULT) code+=" xkeepratio=\""+String.valueOf(xkeepratio)+"\"";
if (ykeepratio!=YKEEPRATIO_DEFAULT) code+=" ykeepratio=\""+String.valueOf(ykeepratio)+"\"";
if (!help.equals(HELP_DEFAULT)) code+=" help=\""+help+"\"";
if (!visible.equals(VISIBLE_DEFAULT)) code+=" visible=\""+visible+"\"";
code+="/>";
String code = indent + "<Image";
if(!id.equals(ID_DEFAULT)) {
code += " id=\"" + id + "\"";
}
if(x != X_DEFAULT) {
code += " x=\"" + String.valueOf(x) + "\"";
}
if(y != Y_DEFAULT) {
code += " y=\"" + String.valueOf(y) + "\"";
}
code += " image=\"" + image + "\"";
if(!action.equals(ACTION_DEFAULT)) {
code += " action=\"" + action + "\"";
}
if(!action2.equals(ACTION2_DEFAULT)) {
code += " action2=\"" + action2 + "\"";
}
if(!resize.equals(RESIZE_DEFAULT)) {
code += " resize=\"" + resize + "\"";
}
if(!lefttop.equals(LEFTTOP_DEFAULT)) {
code += " lefttop=\"" + lefttop + "\"";
}
if(!rightbottom.equals(RIGHTBOTTOM_DEFAULT)) {
code += " rightbottom=\"" + rightbottom + "\"";
}
if(xkeepratio != XKEEPRATIO_DEFAULT) {
code += " xkeepratio=\"" + String.valueOf(xkeepratio) + "\"";
}
if(ykeepratio != YKEEPRATIO_DEFAULT) {
code += " ykeepratio=\"" + String.valueOf(ykeepratio) + "\"";
}
if(!help.equals(HELP_DEFAULT)) {
code += " help=\"" + help + "\"";
}
if(!visible.equals(VISIBLE_DEFAULT)) {
code += " visible=\"" + visible + "\"";
}
code += "/>";
return code;
}
@Override
public void draw(Graphics2D g, int z) {
draw(g,offsetx,offsety, z);
draw(g, offsetx, offsety, z);
}
@Override
public void draw(Graphics2D g,int x_, int y_, int z) {
if(!created) return;
public void draw(Graphics2D g, int x_, int y_, int z) {
if(!created) {
return;
}
BufferedImage bi = image_res.image;
if(bi==null) return;
if(vis) g.drawImage(bi,(x+x_)*z,(y+y_)*z,bi.getWidth()*z,bi.getHeight()*z,null);
if(bi == null) {
return;
}
if(vis) {
g.drawImage(bi, (x + x_) * z, (y + y_) * z, bi.getWidth() * z, bi.getHeight() * z, null);
}
if(selected) {
g.setColor(Color.RED);
g.drawRect((x+x_)*z,(y+y_)*z,bi.getWidth()*z-1,bi.getHeight()*z-1);
g.drawRect((x + x_) * z, (y + y_) * z, bi.getWidth() * z - 1, bi.getHeight() * z - 1);
}
}
@Override
public boolean contains(int x_, int y_) {
BufferedImage bi = image_res.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);
}
@Override
public DefaultMutableTreeNode getTreeNode() {
DefaultMutableTreeNode node = new DefaultMutableTreeNode("Image: "+id);
DefaultMutableTreeNode node = new DefaultMutableTreeNode("Image: " + id);
return node;
}
@Override
public boolean uses(String id_) {
return (image.equals(id_));
}