Commit 29e30275 authored by Daniel Dreibrodt's avatar Daniel Dreibrodt

History for adds/edits of Windows and Layouts

parent b13c40cb
......@@ -23,6 +23,7 @@
package vlcskineditor;
import vlcskineditor.items.*;
import vlcskineditor.history.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
......@@ -48,6 +49,7 @@ public class Layout implements ActionListener{
public int maxheight = MAXHEIGHT_DEFAULT;
public int width, height;
Skin s;
Window parent;
JFrame frame = null;
JTextField id_tf, width_tf, height_tf, minwidth_tf, minheight_tf, maxwidth_tf, maxheight_tf;
......@@ -64,8 +66,9 @@ public class Layout implements ActionListener{
* @param xmlcode The XML code from which the Layout should be created.
* @param s_ The Skin in which the Layout is used.
*/
public Layout(String xmlcode, Skin s_) {
public Layout(String xmlcode, Window w_, Skin s_) {
s=s_;
parent=w_;
String[] code = xmlcode.split("\n");
width = XML.getIntValue(code[0],"width");
height = XML.getIntValue(code[0],"height");
......@@ -151,8 +154,9 @@ public class Layout implements ActionListener{
* Creates a new Layout from user input.
* @param s_ The Skin in which the Layout is used.
*/
public Layout(Skin s_) {
public Layout(Window w_, Skin s_) {
s=s_;
parent=w_;
id = "Unnamed layout #"+s.getNewId();
width=0;
height=0;
......@@ -162,17 +166,35 @@ public class Layout implements ActionListener{
* Updates the Layout's attributes according to the user input.
*/
public void update() {
id=id_tf.getText();
width=Integer.parseInt(width_tf.getText());
height=Integer.parseInt(height_tf.getText());
minwidth=Integer.parseInt(minwidth_tf.getText());
minheight=Integer.parseInt(minheight_tf.getText());
maxwidth=Integer.parseInt(maxwidth_tf.getText());
maxheight=Integer.parseInt(maxheight_tf.getText());
s.updateWindows();
s.expandLayout(id);
created = true;
frame.setDefaultCloseOperation(frame.HIDE_ON_CLOSE);
if(!created) {
LayoutAddEvent lae = new LayoutAddEvent(parent,this);
id=id_tf.getText();
width=Integer.parseInt(width_tf.getText());
height=Integer.parseInt(height_tf.getText());
minwidth=Integer.parseInt(minwidth_tf.getText());
minheight=Integer.parseInt(minheight_tf.getText());
maxwidth=Integer.parseInt(maxwidth_tf.getText());
maxheight=Integer.parseInt(maxheight_tf.getText());
s.updateWindows();
s.expandLayout(id);
created = true;
frame.setDefaultCloseOperation(frame.HIDE_ON_CLOSE);
s.m.hist.addEvent(lae);
}
else {
LayoutEditEvent lee = new LayoutEditEvent(this);
id=id_tf.getText();
width=Integer.parseInt(width_tf.getText());
height=Integer.parseInt(height_tf.getText());
minwidth=Integer.parseInt(minwidth_tf.getText());
minheight=Integer.parseInt(minheight_tf.getText());
maxwidth=Integer.parseInt(maxwidth_tf.getText());
maxheight=Integer.parseInt(maxheight_tf.getText());
s.updateWindows();
s.expandLayout(id);
lee.setNew();
s.m.hist.addEvent(lee);
}
}
/**
* Shows a dialog to edit this Layout's attributes.
......
......@@ -39,8 +39,8 @@ import java.util.*;
*/
public class Skin implements ActionListener{
java.util.List<Resource> resources = new LinkedList<Resource>();
java.util.List<Window> windows = new LinkedList<Window>();
public java.util.List<Resource> resources = new LinkedList<Resource>();
public java.util.List<Window> windows = new LinkedList<Window>();
final String HEADER = "<!DOCTYPE Theme PUBLIC \"-//VideoLAN//DTD VLC Skins V2.0//EN\" \"skin.dtd\">";
final String THEME_VERSION_DEFAULT = "2.0";
final String THEME_TOOLTIPFONT_DEFAULT = "defaultfont";
......
......@@ -22,6 +22,7 @@
package vlcskineditor;
import vlcskineditor.history.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
......@@ -35,7 +36,6 @@ import javax.swing.border.*;
*/
public class Window implements ActionListener{
/** Creates a new instance of Window */
final String ID_DEFAULT="none";
final String VISIBLE_DEFAULT = "true";
final int X_DEFAULT = 0;
......@@ -43,22 +43,23 @@ public class Window implements ActionListener{
final boolean DRAGDROP_DEFAULT=true;
final boolean PLAYONDROP_DEFAULT=true;
String id=ID_DEFAULT;
String visible = VISIBLE_DEFAULT;
int x = X_DEFAULT;
int y = Y_DEFAULT;
boolean dragdrop = DRAGDROP_DEFAULT;
boolean playondrop = PLAYONDROP_DEFAULT;
public String id=ID_DEFAULT;
public String visible = VISIBLE_DEFAULT;
public int x = X_DEFAULT;
public int y = Y_DEFAULT;
public boolean dragdrop = DRAGDROP_DEFAULT;
public boolean playondrop = PLAYONDROP_DEFAULT;
java.util.List<Layout> layouts = new LinkedList<Layout>();
public java.util.List<Layout> layouts = new LinkedList<Layout>();
Skin s;
public Skin s;
JFrame frame = null;
JTextField id_tf, x_tf, y_tf, visible_tf, dragdrop_tf, playondrop_tf;
JButton ok_btn, cancel_btn, help_btn;
boolean created = false;
/** Creates a new instance of Window */
public Window(String xmlcode, Skin s_) {
s = s_;
String[] code = xmlcode.split("\n");
......@@ -81,7 +82,7 @@ public class Window implements ActionListener{
}
else if(code[i].startsWith("</Layout>")) {
layoutcode+="\n"+code[i];
layouts.add(new Layout(layoutcode,s));
layouts.add(new Layout(layoutcode,this,s));
layoutcode = "";
}
else {
......@@ -96,16 +97,32 @@ public class Window implements ActionListener{
s.updateWindows();
showOptions();
}
public void update(String id_, int x_, int y_, String v_, boolean dd_, boolean pod_) {
id=id_;
x=x_;
y=y_;
visible=v_;
dragdrop=dd_;
playondrop=pod_;
s.updateWindows();
created = true;
frame.setDefaultCloseOperation(frame.HIDE_ON_CLOSE);
public void update() {
if(!created) {
WindowAddEvent wae = new WindowAddEvent(s,this);
id=id_tf.getText();
x=Integer.parseInt(x_tf.getText());
y=Integer.parseInt(y_tf.getText());
visible=visible_tf.getText();
dragdrop=Boolean.parseBoolean(dragdrop_tf.getText());
playondrop=Boolean.parseBoolean(playondrop_tf.getText());
s.updateWindows();
created = true;
frame.setDefaultCloseOperation(frame.HIDE_ON_CLOSE);
s.m.hist.addEvent(wae);
}
else {
WindowEditEvent wee = new WindowEditEvent(this);
id=id_tf.getText();
x=Integer.parseInt(x_tf.getText());
y=Integer.parseInt(y_tf.getText());
visible=visible_tf.getText();
dragdrop=Boolean.parseBoolean(dragdrop_tf.getText());
playondrop=Boolean.parseBoolean(playondrop_tf.getText());
s.updateWindows();
wee.setNew();
s.m.hist.addEvent(wee);
}
}
public void showOptions() {
if(frame==null) {
......@@ -214,7 +231,7 @@ public class Window implements ActionListener{
}
}
frame.setVisible(false);
update(id_tf.getText(),Integer.parseInt(x_tf.getText()),Integer.parseInt(y_tf.getText()),visible_tf.getText(),Boolean.parseBoolean(dragdrop_tf.getText()),Boolean.parseBoolean(playondrop_tf.getText()));
update();
}
else if(e.getSource().equals(help_btn)) {
Desktop desktop;
......@@ -237,7 +254,7 @@ public class Window implements ActionListener{
}
}
public void addLayout() {
layouts.add(new Layout(s));
layouts.add(new Layout(this,s));
}
public String returnCode() {
String code = "<Window";
......
......@@ -43,13 +43,14 @@ public class History {
main = new DummyEvent();
current = main;
}
/** Adds an Event to the history */
/** Adds an Event at the current point in the history list and removes any actions that could be redone*/
public void addEvent(HistoryEvent h) {
current.setNext(h);
h.setPrevious(current);
current = current.getNext();
m.setRedoEnabled(false);
m.setUndoEnabled(true);
m.setUndoString(current.getDescription());
}
/** Redoes the action that is next in the history list */
public void redo() {
......
/*****************************************************************************
* LayoutAddEvent.java
*****************************************************************************
* Copyright (C) 2007 Daniel Dreibrodt
*
* This file is part of vlcskineditor.history
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* 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.history;
import vlcskineditor.Window;
import vlcskineditor.Layout;
/**
* Represents the action of adding a Layout
* @author Daniel Dreibrodt
*/
public class LayoutAddEvent extends HistoryEvent{
private Window w;
private Layout l;
/** Creates a new instance of LayoutAddEvent */
public LayoutAddEvent(Window win, Layout lay) {
w = win;
l = lay;
}
public void undo() {
w.layouts.remove(l);
w.s.updateWindows();
}
public void redo() {
w.layouts.add(l);
w.s.updateWindows();
w.s.expandLayout(l.id);
}
public String getDescription() {
return "Add Layout";
}
}
/*****************************************************************************
* LayoutEditEvent.java
*****************************************************************************
* Copyright (C) 2007 Daniel Dreibrodt
*
* This file is part of vlcskineditor.history
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* 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.history;
import vlcskineditor.Layout;
/**
* Represents the action of editing a Layout
* @author Daniel Dreibrodt
*/
public class LayoutEditEvent extends HistoryEvent {
private Layout l;
private String id_old, id_new;
private int width_old, width_new;
private int height_old, height_new;
private int minwidth_old, minwidth_new;
private int minheight_old, minheight_new;
private int maxwidth_old, maxwidth_new;
private int maxheight_old, maxheight_new;
/** Creates a new instance of LayoutEditEvent */
public LayoutEditEvent(Layout lay) {
l = lay;
id_old = l.id;
width_old = l.width;
height_old = l.height;
minwidth_old = l.minwidth;
minheight_old = l.minheight;
maxwidth_old = l.maxwidth;
maxheight_old = l.maxwidth;
}
public void setNew() {
id_new = l.id;
width_new = l.width;
height_new = l.height;
minwidth_new = l.minwidth;
minheight_new = l.minheight;
maxwidth_new = l.maxwidth;
maxheight_new = l.maxwidth;
}
public void undo() {
l.id = id_old;
l.width = width_old;
l.height = height_old;
l.minwidth = minwidth_old;
l.minheight = minheight_old;
l.maxwidth = maxwidth_old;
l.maxheight = maxheight_old;
}
public void redo() {
l.id = id_new;
l.width = width_new;
l.height = height_new;
l.minwidth = minwidth_new;
l.minheight = minheight_new;
l.maxwidth = maxwidth_new;
l.maxheight = maxheight_new;
}
public String getDescription() {
return "Edit Layout";
}
}
/*****************************************************************************
* WindowAddEvent.java
*****************************************************************************
* Copyright (C) 2007 Daniel Dreibrodt
*
* This file is part of vlcskineditor.history
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* 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.history;
import vlcskineditor.Skin;
import vlcskineditor.Window;
/**
* Represents the action of adding a Window
* @author Daniel Dreibrodt
*/
public class WindowAddEvent extends HistoryEvent{
private Skin s;
private Window w;
/** Creates a new instance of WindowAddEvent */
public WindowAddEvent(Skin ski, Window win) {
s = ski;
w = win;
}
public void undo() {
s.windows.remove(w);
s.updateWindows();
}
public void redo() {
s.windows.add(w);
s.updateWindows();
}
public String getDescription() {
return "Add Window";
}
}
/*****************************************************************************
* WindowEditEvent.java
*****************************************************************************
* Copyright (C) 2007 Daniel Dreibrodt
*
* This file is part of vlcskineditor.history
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* 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.history;
import vlcskineditor.Window;
/**
* Represents the action of editing a Window
* @author Daniel Dreibrodt
*/
public class WindowEditEvent extends HistoryEvent{
private Window w;
private String id_old, id_new;
private int x_old, x_new;
private int y_old, y_new;
private boolean dragdrop_old, dragdrop_new;
private boolean playondrop_old, playondrop_new;
/** Creates a new instance of WindowEditEvent */
public WindowEditEvent(Window win) {
w = win;
id_old = w.id;
x_old = w.x;
y_old = w.y;
dragdrop_old = w.dragdrop;
playondrop_old = w.playondrop;
}
public void setNew() {
id_new = w.id;
x_new = w.x;
y_new = w.y;
dragdrop_new = w.dragdrop;
playondrop_new = w.playondrop;
}
public void undo() {
w.id = id_old;
w.x = x_old;
w.y = y_old;
w.dragdrop = dragdrop_old;
w.playondrop = playondrop_old;
}
public void redo() {
w.id = id_new;
w.x = x_new;
w.y = y_new;
w.dragdrop = dragdrop_new;
w.playondrop = playondrop_new;
}
public String getDescription() {
return "Edit Window";
}
}
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