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;
}
}
This diff is collapsed.
This diff is collapsed.
......@@ -813,4 +813,13 @@ public class Slider extends Item implements ActionListener{
public boolean isInPlaytree() {
return inPlaytree;
}
@Override
public void resourceRenamed(String oldid, String newid) {
if(sbg!=null) sbg.resourceRenamed(oldid, newid);
if(up.equals(oldid)) up = newid;
if(over.equals(oldid)) over = newid;
if(down.equals(oldid)) down = newid;
}
}
......@@ -590,4 +590,10 @@ public class Text extends Item implements ActionListener{
public boolean uses(String id_) {
return (font.equals(id_));
}
@Override
public void resourceRenamed(String oldid, String newid) {
if(font.equals(oldid)) font = newid;
}
}
......@@ -207,7 +207,9 @@ public class Bitmap extends ImageResource implements ActionListener{
nbframes=Integer.parseInt(nbframes_tf.getText());
fps=Integer.parseInt(fps_tf.getText());
if(!id_tf.getText().equals(id)) {
String oldid = id;
id=id_tf.getText();
s.resourceRenamed(oldid, id);
s.updateResources();
s.expandResource(id);
}
......
......@@ -152,14 +152,18 @@ public class Font extends Resource implements ActionListener{
}
@Override
public void update() {
FontEditEvent fe = new FontEditEvent(this);
FontEditEvent fee = new FontEditEvent(this);
file=file_tf.getText();
size=Integer.parseInt(size_tf.getText());
id=id_tf.getText();
s.updateResources();
s.expandResource(id);
fe.setNew();
s.m.hist.addEvent(fe);
if(!id.equals(id_tf.getText())) {
String oldid = id;
id=id_tf.getText();
s.resourceRenamed(oldid, id);
s.updateResources();
s.expandResource(id);
}
fee.setNew();
s.m.hist.addEvent(fee);
}
@Override
public void showOptions() {
......
......@@ -135,7 +135,13 @@ public class SubBitmap extends ImageResource implements ActionListener{
created = true;
}
else {
id=id_tf.getText();
if(!id_tf.getText().equals(id)) {
String oldid = id;
id=id_tf.getText();
s.resourceRenamed(oldid, id);
s.updateResources();
s.expandResource(id);
}
x=Integer.parseInt(x_tf.getText());
y=Integer.parseInt(y_tf.getText());
width=Integer.parseInt(width_tf.getText());
......
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