Commit 77f648b5 authored by Daniel Dreibrodt's avatar Daniel Dreibrodt

Release 0.4.0a finished

Trees automatically expand themselves to the changed element after being updated
parent 235703aa
VLC Skin Editor release 0.3.5b
VLC Skin Editor release 0.4.0a
-----------------------------------------------------------
Changelog:
-----------------------------------------------------------
0.4.0a - Items can be positioned with the mouse
- Trees don't collapse anymore completely when an
element in it is updated, they automatically
expand the path to the updated item and select it
0.3.5b - NullPointerException fix for Playtree rendering
- VLT files can be imported
0.3.5a - Preview of Layouts
......
......@@ -84,7 +84,11 @@ public abstract class Item {
else return null;
}
/** If an item contains a subitem of the given id the list containing the subitem is returned **/
public java.util.List<Item> getParentOf(String id_) {
public java.util.List<Item> getParentListOf(String id_) {
return null;
}
/** If an item contains a subitem of the given id the itemis returned **/
public Item getParentOf(String id_) {
return null;
}
/** Sets whether the item is selected in the tree or not **/
......
......@@ -74,6 +74,7 @@ public class Anchor extends Item implements ActionListener{
points=pts_;
range=r_;
s.updateItems();
s.expandItem(id);
}
public void showOptions() {
if(frame==null) {
......
......@@ -91,6 +91,7 @@ public class Button extends Item implements ActionListener{
tooltiptext = tooltiptext_tf.getText();
s.updateItems();
s.expandItem(id);
}
public void showOptions() {
if(frame==null) {
......
......@@ -116,7 +116,8 @@ public class Checkbox extends Item implements ActionListener{
tooltiptext2 = tooltiptext2_tf.getText();
state = state_tf.getText();
s.updateItems();
s.updateItems();
s.expandItem(id);
}
public void showOptions() {
if(frame==null) {
......
......@@ -102,10 +102,9 @@ public class Group extends Item implements ActionListener{
type="Group";
s=s_;
id = "Unnamed group #"+s.getNewId();
showOptions();
for(Item i:items) {
i.setOffset(x,y);
}
showOptions();
s.updateItems();
s.expandItem(id);
}
public void update(String id_, int x_, int y_) {
id=id_;
......@@ -115,6 +114,7 @@ public class Group extends Item implements ActionListener{
i.setOffset(x,y);
}
s.updateItems();
s.expandItem(id);
}
public void showOptions() {
if(frame==null) {
......@@ -241,18 +241,28 @@ public class Group extends Item implements ActionListener{
}
return null;
}
public java.util.List<Item> getParentOf(String id_) {
public java.util.List<Item> getParentListOf(String id_) {
for(int x=0;x<items.size();x++) {
Item i = items.get(x);
if(i.id.equals(id_)) {
System.out.println(id+": I is parent of "+id_);
if(i.id.equals(id_)) {
return items;
}
if (i.type.equals("Group")||i.type.equals("Panel")) {
java.util.List<Item> p = i.getParentOf(id_);
java.util.List<Item> p = i.getParentListOf(id_);
if (p!=null) return p;
}
}
return null;
}
public Item getParentOf(String id_) {
for(int x=0;x<items.size();x++) {
Item i = items.get(x);
if(i.id.equals(id_)) {
return this;
}
Item it = i.getParentOf(id_);
if (it!=null) return it;
}
return null;
}
}
......@@ -87,7 +87,8 @@ public class Image extends Item implements ActionListener{
action = action_cb.getSelectedItem().toString();
action2 = action2_tf.getText();
s.updateItems();
s.updateItems();
s.expandItem(id);
}
public void showOptions() {
if(frame==null) {
......
......@@ -116,9 +116,8 @@ public class Panel extends Item implements ActionListener{
height = 0;
id = "Unnamed panel #"+s.getNewId();
showOptions();
for(Item i:items) {
i.setOffset(x,y);
}
s.updateItems();
s.expandItem(id);
}
public void update() {
id = id_tf.getText();
......@@ -135,6 +134,7 @@ public class Panel extends Item implements ActionListener{
height = Integer.parseInt(height_tf.getText());
s.updateItems();
s.expandItem(id);
for(Item i:items) {
i.setOffset(x,y);
}
......@@ -346,18 +346,28 @@ public class Panel extends Item implements ActionListener{
}
return null;
}
public java.util.List<Item> getParentOf(String id_) {
public java.util.List<Item> getParentListOf(String id_) {
for(int x=0;x<items.size();x++) {
Item i = items.get(x);
if(i.id.equals(id_)) {
System.out.println(id+": I is parent of "+id_);
if(i.id.equals(id_)) {
return items;
}
if (i.type.equals("Group")||i.type.equals("Panel")) {
java.util.List<Item> p = i.getParentOf(id_);
java.util.List<Item> p = i.getParentListOf(id_);
if (p!=null) return p;
}
}
return null;
}
public Item getParentOf(String id_) {
for(int x=0;x<items.size();x++) {
Item i = items.get(x);
if(i.id.equals(id_)) {
return this;
}
Item it = i.getParentOf(id_);
if (it!=null) return it;
}
return null;
}
}
......@@ -30,8 +30,9 @@ import javax.swing.tree.*;
/**
* Playlist item
* @author Daniel Dreibrodt
* @Deprecated All Playlists are automatically converted to flat playtrees
*/
public class Playlist extends Item{
@Deprecated public class Playlist extends Item{
/** Creates a new instance of Playlist */
public Playlist(String xmlcode, Skin s_) {
......
......@@ -129,6 +129,7 @@ public class Playtree extends Item implements ActionListener{
slider = new Slider(s,true);
showOptions();
s.updateItems();
s.expandItem(id);
}
public void update() {
id = id_tf.getText();
......@@ -154,6 +155,9 @@ public class Playtree extends Item implements ActionListener{
bgcolor1 = bgcolor1_tf.getText();
bgcolor2 = bgcolor2_tf.getText();
flat = (Boolean)flat_cb.getSelectedItem();
s.updateItems();
s.expandItem(id);
}
public void showOptions() {
if(frame==null) {
......@@ -654,4 +658,11 @@ public class Playtree extends Item implements ActionListener{
if(id.equals(id_)) return this;
else return slider.getItem(id_);
}
public Item getParentOf(String id_) {
if(slider!=null) {
if(slider.id.equals(id_)) return this;
else return slider.getParentOf(id_);
}
else return null;
}
}
......@@ -125,6 +125,8 @@ public class Slider extends Item implements ActionListener{
up = "none";
id = "Unnamed slider #"+s.getNewId();
showOptions();
s.updateItems();
s.expandItem(id);
}
public Slider(Skin s_, boolean ipt) {
s = s_;
......@@ -152,7 +154,8 @@ public class Slider extends Item implements ActionListener{
if(!inPlaytree) value = (String)value_cb.getSelectedItem();
tooltiptext = tooltiptext_tf.getText();
s.updateItems();
s.updateItems();
s.expandItem(id);
}
public void showOptions() {
if(frame==null) {
......@@ -480,4 +483,11 @@ public class Slider extends Item implements ActionListener{
else if(sbg.id.equals(id_)) return sbg;
else return null;
}
public Item getParentOf(String id_) {
if(sbg!=null) {
if(sbg.id.equals(id_)) return this;
else return null;
}
else return null;
}
}
......@@ -150,6 +150,7 @@ public class Layout implements ActionListener{
maxwidth=maxw_;
maxheight=maxh_;
s.updateWindows();
s.expandLayout(id);
}
public void showOptions() {
if(frame==null) {
......@@ -318,18 +319,28 @@ public class Layout implements ActionListener{
}
return null;
}
public java.util.List<Item> getParentOf(String id_) {
public java.util.List<Item> getParentListOf(String id_) {
for(int x=0;x<items.size();x++) {
Item i = items.get(x);
if(i.id.equals(id_)) {
System.out.println(id+": I is parent of "+id_);
if(i.id.equals(id_)) {
return items;
}
if (i.type.equals("Group")||i.type.equals("Panel")) {
java.util.List<Item> p = i.getParentOf(id_);
java.util.List<Item> p = i.getParentListOf(id_);
if (p!=null) return p;
}
}
return null;
}
public Item getParentOf(String id_) {
for(int x=0;x<items.size();x++) {
Item i = items.get(x);
if(i.id.equals(id_)) {
return null;
}
Item it = i.getParentOf(id_);
if (it!=null) return it;
}
return null;
}
}
......@@ -921,6 +921,7 @@ public class Main extends javax.swing.JFrame implements ActionListener, TreeSele
if(index<=0) return;
w.layouts.set(index,w.layouts.set(index-1,l));
s.updateWindows();
s.expandLayout(l.id);
}
else if(e.getSource().equals(win_layout_down)) {
Window w = s.getWindow(selected_window);
......@@ -930,6 +931,7 @@ public class Main extends javax.swing.JFrame implements ActionListener, TreeSele
if(index>=w.layouts.size()-1) return;
w.layouts.set(index,w.layouts.set(index+1,l));
s.updateWindows();
s.expandLayout(l.id);
}
//</editor-fold>
// <editor-fold defaultstate="collapsed" desc="Window edit">
......@@ -992,20 +994,23 @@ public class Main extends javax.swing.JFrame implements ActionListener, TreeSele
else if(e.getSource().equals(items_up)) {
Item i = s.getItem(selected_item);
if(i==null) return;
java.util.List<Item> l = s.getParentOf(selected_item);
java.util.List<Item> l = s.getParentListOf(selected_item);
if(l==null) return;
int index = l.indexOf(i);
if(index<=0) return;
l.set(index,l.set(index-1,i));
s.updateItems();
s.updateItems();
s.expandItem(selected_item);
}
else if(e.getSource().equals(items_down)) {
Item i = s.getItem(selected_item);
if(i==null) return;
java.util.List<Item> l = s.getParentOf(selected_item);
java.util.List<Item> l = s.getParentListOf(selected_item);
int index = l.indexOf(i);
if(index>=l.size()-1) return;
l.set(index,l.set(index+1,i));
s.updateItems();
s.updateItems();
s.expandItem(selected_item);
}
//</editor-fold>
// <editor-fold defaultstate="collapsed" desc="Item edit">
......@@ -1019,55 +1024,55 @@ public class Main extends javax.swing.JFrame implements ActionListener, TreeSele
//<editor-fold defaultstate="collapsed" desc="Add Item popups">
else if(e.getSource().equals(items_add_pu_anchor)) {
java.util.List<Item> i;
if (selected_item!=null ) i = s.getParentOf(selected_item);
if (selected_item!=null ) i = s.getParentListOf(selected_item);
else i = s.getWindow(selected_window).getLayout(selected_layout).items;
i.add(new Anchor(s));
}
else if(e.getSource().equals(items_add_pu_button)) {
java.util.List<Item> i;
if (selected_item!=null ) i = s.getParentOf(selected_item);
if (selected_item!=null ) i = s.getParentListOf(selected_item);
else i = s.getWindow(selected_window).getLayout(selected_layout).items;
i.add(new vlcskineditor.Items.Button(s));
}
else if(e.getSource().equals(items_add_pu_checkbox)) {
java.util.List<Item> i;
if (selected_item!=null ) i = s.getParentOf(selected_item);
if (selected_item!=null ) i = s.getParentListOf(selected_item);
else i = s.getWindow(selected_window).getLayout(selected_layout).items;
i.add(new vlcskineditor.Items.Checkbox(s));
}
else if(e.getSource().equals(items_add_pu_panel)) {
java.util.List<Item> i;
if (selected_item!=null ) i = s.getParentOf(selected_item);
if (selected_item!=null ) i = s.getParentListOf(selected_item);
else i = s.getWindow(selected_window).getLayout(selected_layout).items;
i.add(new vlcskineditor.Items.Panel(s));
}
else if(e.getSource().equals(items_add_pu_image)) {
java.util.List<Item> i;
if (selected_item!=null ) i = s.getParentOf(selected_item);
if (selected_item!=null ) i = s.getParentListOf(selected_item);
else i = s.getWindow(selected_window).getLayout(selected_layout).items;
i.add(new vlcskineditor.Items.Image(s));
}
else if(e.getSource().equals(items_add_pu_playtree)) {
java.util.List<Item> i;
if (selected_item!=null ) i = s.getParentOf(selected_item);
if (selected_item!=null ) i = s.getParentListOf(selected_item);
else i = s.getWindow(selected_window).getLayout(selected_layout).items;
i.add(new Playtree(s));
}
else if(e.getSource().equals(items_add_pu_slider)) {
java.util.List<Item> i;
if (selected_item!=null ) i = s.getParentOf(selected_item);
if (selected_item!=null ) i = s.getParentListOf(selected_item);
else i = s.getWindow(selected_window).getLayout(selected_layout).items;
i.add(new Slider(s));
}
else if(e.getSource().equals(items_add_pu_text)) {
java.util.List<Item> i;
if (selected_item!=null ) i = s.getParentOf(selected_item);
if (selected_item!=null ) i = s.getParentListOf(selected_item);
else i = s.getWindow(selected_window).getLayout(selected_layout).items;
i.add(new Text(s));
}
else if(e.getSource().equals(items_add_pu_video)) {
java.util.List<Item> i;
if (selected_item!=null ) i = s.getParentOf(selected_item);
if (selected_item!=null ) i = s.getParentListOf(selected_item);
else i = s.getWindow(selected_window).getLayout(selected_layout).items;
i.add(new Video(s));
}
......@@ -1111,7 +1116,7 @@ public class Main extends javax.swing.JFrame implements ActionListener, TreeSele
// <editor-fold defaultstate="collapsed" desc="Item delete">
else if(e.getSource().equals(items_del)) {
if(selected_item!=null) {
java.util.List<Item> p = s.getParentOf(selected_item);
java.util.List<Item> p = s.getParentListOf(selected_item);
if(p!=null) {
Object[] options= {"Yes","No"};
int n = JOptionPane.showOptionDialog(this,"Do you really want to delete \""+selected_item+"\"?","Confirmation",
......
......@@ -43,4 +43,8 @@ public abstract class Resource {
public abstract String returnCode();
/** Creates a DefaultMutableTreeNode to be displayed in the resources tree */
public abstract DefaultMutableTreeNode getTreeNode();
/** If an Resource does contain another Resource of the given id (e.g. a SubBitmap) the containing Resource is returned **/
public Resource getParentOf(String id_) {
return null;
}
}
......@@ -95,7 +95,7 @@ public class Bitmap extends Resource implements ActionListener{
type = "Bitmap";
id = f_.getName().substring(0,f_.getName().lastIndexOf("."));
file = f_.getPath().replace(s.skinfolder,"");
s.updateResources();
s.updateResources();
update();
}
public Bitmap(Skin s_) {
......@@ -104,6 +104,7 @@ public class Bitmap extends Resource implements ActionListener{
id = "Unnamed bitmap #"+s.getNewId();
file = "";
s.updateResources();
s.expandResource(id);
showOptions();
}
public void update() {
......@@ -141,6 +142,7 @@ public class Bitmap extends Resource implements ActionListener{
if(!id_.equals(id)) {
id=id_;
s.updateResources();
s.expandResource(id);
}
update();
}
......@@ -322,5 +324,10 @@ public class Bitmap extends Resource implements ActionListener{
}
return node;
}
public Resource getParentOf(String id_) {
for(SubBitmap sbmp:SubBitmaps) {
if(sbmp.id.equals(id_)) return this;
}
return null;
}
}
......@@ -141,16 +141,17 @@ public class Font extends Resource implements ActionListener{
id = "Unnamed font #"+s.getNewId();
file="";
s.updateResources();
s.expandResource(id);
showOptions();
}
public void update() {
type="Font";
file=file_tf.getText();
size=Integer.parseInt(size_tf.getText());
s.updateResources();
size=Integer.parseInt(size_tf.getText());
if(!id_tf.getText().equals(id)) {
id=id_tf.getText();
s.updateResources();
s.expandResource(id);
}
try {
f = java.awt.Font.createFont(java.awt.Font.TRUETYPE_FONT,new File(s.skinfolder+file));
......
......@@ -74,6 +74,7 @@ public class SubBitmap extends Resource implements ActionListener{
public void update() {
image = parent.getSubimage(x,y,width,height);
s.updateResources();
s.expandResource(id);
}
public void update(BufferedImage parent_) {
parent = parent_;
......
......@@ -449,8 +449,8 @@ public class Skin implements ActionListener{
return false;
}
/** Returns the parent element that contains the item of the given id **/
public java.util.List<Item> getParentOf(String id_) {
return active_layout.getParentOf(id_);
public java.util.List<Item> getParentListOf(String id_) {
return active_layout.getParentListOf(id_);
}
/** Returns the list of the given Group/Panel that contains the items **/
public java.util.List<Item> getListOf(String id_) {
......@@ -558,32 +558,106 @@ public class Skin implements ActionListener{
return code;
}
/** Recreates the resource hierarchies **/
public void updateResources() {
m.res_tree_model.setRoot(getResourcesTree());
public void updateResources() {
m.res_tree_model.setRoot(getResourcesTree());
m.saved=false;
}
/** Make an Resource of the given id visible in the tree (expand the TreePath) **/
public void expandResource(String id) {
Resource r = getResource(id);
if(r==null) return;
if(r.type.equals("Bitmap")) {
TreePath tp = findInTree(m.res_tree,"Root: Bitmaps");
m.res_tree.expandPath(tp);
}
else if(r.type.equals("Font")) {
TreePath tp = findInTree(m.res_tree,"Root: Fonts");
m.res_tree.expandPath(tp);
}
else {
System.err.println("Resource of the given id is neither a Font nor a Bitmap its a "+r.type);
return;
}
java.util.List<String> parents = new ArrayList<String>();
Resource pr = r;
while(pr!=null) {
for(Resource res:resources) {
pr = res.getParentOf(r.id);
if(pr!=null) {
parents.add(pr.id);
break;
}
}
}
for(int i=parents.size()-1;i>=0;i--) {
TreePath tp = findInTree(m.res_tree,parents.get(i));
if(tp==null) {
System.err.println("Could not find Parent: "+parents.get(i));
return;
}
m.res_tree.expandPath(tp);
TreePath stp = findInTree(m.res_tree,id);
if(stp==null) return;
m.res_tree.setSelectionPath(stp);
}
}
/** Make a Layout of the given id visible **/
public void expandLayout(String id) {
TreePath wtp = findInTree(m.win_tree,active_window.id);
if(wtp==null) return;
m.win_tree.expandPath(wtp);
TreePath ltp = findInTree(m.win_tree,id);
if(ltp==null) return;
m.win_tree.setSelectionPath(ltp);
}
/** Recreates the window hierarchies **/
public void updateWindows() {
m.win_tree_model.setRoot(getWindowsTree());
m.saved=false;
}
/** Recreates the item hierarchies **/
public void updateItems() {
public void updateItems() {
m.items_tree_model.setRoot(getItemsTree());
m.saved=false;
}
/** Make an item of the given id visible in the tree (expand the TreePath) **/
public void expandItem(String id) {
java.util.List<String> parents = new ArrayList<String>();
Item p = getItem(id);
while((p=active_layout.getParentOf(p.id))!=null) {
parents.add(p.id);
}
for(int i=parents.size()-1;i>=0;i--) {
TreePath tp = findInTree(m.items_tree,parents.get(i));
if(tp==null) {
System.err.println("Could not find Parent: "+parents.get(i));
return;
}
m.items_tree.expandPath(tp);
TreePath stp = findInTree(m.items_tree,id);
if(stp==null) return;
m.items_tree.setSelectionPath(stp);
}
}
/** Redraws the preview window (deprecated already before it was used)
* @Deprecated useless! Preview is now planned to be updated automatically every 1000/25 ms
**/
@Deprecated public void updatePreview() {
/**empty*/
/** Finds the first occurence of id in the first expanded tree in the given JTree**/
public TreePath findInTree(JTree jt, String id) {
int max = jt.getRowCount();
int row = 0;
do {
TreePath path = jt.getPathForRow(row);
String text = path.getLastPathComponent().toString();
if (text.toUpperCase().indexOf(id.toUpperCase())!=-1) return path;
row = (row + 1 + max) % max;
} while (row != 0);
return null;
}
/** Updates everything **/
public void update() {
updateResources();
updateWindows();
updateItems();
updatePreview();
updateItems();
m.saved=false;
}
}
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