Commit d0faefa2 authored by Daniel Dreibrodt's avatar Daniel Dreibrodt

Little performance improvement

parent f7003340
......@@ -32,17 +32,23 @@ public class FrameUpdater extends Thread{
JPanel c;
int fps = 1;
/** causes the thread to stop when set to true */
boolean run = false;
/** Creates a new instance of FrameUpdater */
/** Creates a new instance of FrameUpdater
* @param c_ The panel to redraw
* @param fps_ Frames per second
*/
public FrameUpdater(JPanel c_, int fps_) {
setName("FrameUpdater");
c=c_;
fps=fps_;
}
/** Starts the repainting loop **/
@Override
public void run () {
run = true;
while(true) {
while(run) {
try {
c.repaint();
sleep(1000/fps);
......@@ -51,5 +57,6 @@ public class FrameUpdater extends Thread{
e.printStackTrace();
}
}
return;
}
}
......@@ -51,7 +51,7 @@ public class Main extends javax.swing.JFrame implements ActionListener, TreeSele
private final String updateURL_s = "http://www.videolan.org/vlc/skineditor_update.php";
//The version identification of the current build.
public final String VERSION = "0.7";
public final String VERSION = "0.7.x.dev";
//The directory in which the VLC executable is found
String vlc_dir = "";
//The directory from which VLC loads its skins
......@@ -1575,12 +1575,15 @@ public class Main extends javax.swing.JFrame implements ActionListener, TreeSele
}
public void windowClosed(WindowEvent e) {}
public void windowActivated(WindowEvent e) {
if(pvwin==null) return;
if(pvwin.fu==null) {
pvwin.fu = new FrameUpdater(pvwin,5);
pvwin.fu.start();
}
}
public void windowDeactivated(WindowEvent e) {
if(pvwin==null || pvwin.fu==null) return;
pvwin.fu.run = false;
pvwin.fu = null;
}
public void windowDeiconified(WindowEvent e) {
......@@ -1590,6 +1593,8 @@ public class Main extends javax.swing.JFrame implements ActionListener, TreeSele
}
}
public void windowIconified(WindowEvent e) {
if(pvwin==null || pvwin.fu==null) return;
pvwin.fu.run = false;
pvwin.fu = null;
}
public void windowOpened(WindowEvent e) {}
......
......@@ -96,6 +96,7 @@ public class PreviewWindow extends JPanel implements MouseListener, MouseMotionL
if(selected_item!=null) selected_item.setSelected(false);
selected_item=null;
frame.setVisible(false);
if(fu!=null) fu.run = false;
fu=null;
}
/**
......@@ -163,7 +164,7 @@ public class PreviewWindow extends JPanel implements MouseListener, MouseMotionL
@Override
public void update(Graphics g) {
//Needs to be overriden so that repainting is smooth
paint(g);
//paint(g);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource().equals(zoom_less)) {
......
......@@ -55,6 +55,7 @@ import vlcskineditor.history.ThemeEditEvent;
import vlcskineditor.resources.Bitmap;
import vlcskineditor.resources.BitmapFont;
import vlcskineditor.resources.Font;
import vlcskineditor.resources.ImageResource;
import vlcskineditor.resources.SubBitmap;
/**
......@@ -472,6 +473,19 @@ public class Skin implements ActionListener{
}
return false;
}
public ImageResource getImageResource(String id) {
for (Resource r:resources) {
if(r.getClass()==Bitmap.class) {
if(r.id.equals(id)) return (ImageResource)r;
Bitmap bmp = (Bitmap)r;
for(SubBitmap s:bmp.SubBitmaps) {
if(s.id.equals(id)) return (ImageResource)s;
}
}
}
return null;
}
/** Returns the resource represented by the given id **/
public Resource getResource(String id) {
for (Resource r:resources) {
......@@ -485,7 +499,12 @@ public class Skin implements ActionListener{
}
return null;
}
/** Returns the image object of a bitmap **/
/**
* Returns the image object of a bitmap
* @deprecated Use getImageResource instead
* @param id The id of the Bitmap resource
* @return the BufferedImage represented by the resource looked for
*/
public BufferedImage getBitmapImage(String id) {
Resource r = getResource(id);
if(r==null) {
......
......@@ -29,6 +29,7 @@ import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.border.*;
import vlcskineditor.resources.ImageResource;
/**
* Button item
......@@ -52,8 +53,13 @@ public class Button extends Item implements ActionListener{
JButton visible_btn, action_btn, ok_btn, cancel_btn, help_btn;
ActionEditor action_ae;
ImageResource up_res, over_res, down_res;
/** Creates a new instance of Button */
/** Creates a new instance of Button
* @param xmlcode The XML code
* @param s_ The parent skin
*/
public Button(String xmlcode, Skin s_) {
type = "Button";
s = s_;
......@@ -72,6 +78,10 @@ public class Button extends Item implements ActionListener{
if(xmlcode.indexOf("tooltiptext=\"")!=-1) tooltiptext = XML.getValue(xmlcode,"tooltiptext");
if(xmlcode.indexOf(" visible=\"")!=-1) visible = XML.getValue(xmlcode,"visible");
created = true;
up_res = s.getImageResource(up);
over_res = s.getImageResource(over);
down_res = s.getImageResource(down);
}
public Button(Skin s_) {
type = "Button";
......@@ -308,16 +318,22 @@ public class Button extends Item implements ActionListener{
return;
}
}
if(s.getResource(up_tf.getText())==null) {
up_res = s.getImageResource(up_tf.getText());
if(up_res==null) {
JOptionPane.showMessageDialog(frame,"The bitmap \""+up_tf.getText()+"\" does not exist!","Image not valid",JOptionPane.INFORMATION_MESSAGE);
up_res = s.getImageResource(up);
return;
}
if(!over_tf.getText().equals("none") && s.getResource(over_tf.getText())==null) {
over_res = s.getImageResource(over_tf.getText());
if(!over_tf.getText().equals("none") && over_res==null) {
JOptionPane.showMessageDialog(frame,"The bitmap \""+over_tf.getText()+"\" does not exist!","Image not valid",JOptionPane.INFORMATION_MESSAGE);
over_res = s.getImageResource(over);
return;
}
if(!down_tf.getText().equals("none") && s.getResource(down_tf.getText())==null) {
down_res = s.getImageResource(down_tf.getText());
if(!down_tf.getText().equals("none") && down_res==null) {
JOptionPane.showMessageDialog(frame,"The bitmap \""+down_tf.getText()+"\" does not exist!","Image not valid",JOptionPane.INFORMATION_MESSAGE);
down_res = s.getImageResource(down);
return;
}
update();
......@@ -399,13 +415,13 @@ public class Button extends Item implements ActionListener{
if(!created) return;
java.awt.image.BufferedImage bi;
if(!hovered || ( (over.equals("none") && !clicked)||(clicked && down.equals("none")) ) ) {
bi = s.getBitmapImage(up);
bi = up_res.image;
}
else if(!clicked || down.equals("none")) {
bi = s.getBitmapImage(over);
bi = over_res.image;
}
else {
bi = s.getBitmapImage(down);
bi = down_res.image;
}
if(s.gvars.parseBoolean(visible)==true) g.drawImage(bi,(x+x_)*z,(y+y_)*z,bi.getWidth()*z,bi.getHeight()*z,null);
if(selected) {
......@@ -415,7 +431,7 @@ public class Button extends Item implements ActionListener{
}
@Override
public boolean contains(int x_, int y_) {
java.awt.image.BufferedImage bi = s.getBitmapImage(up);
java.awt.image.BufferedImage bi = up_res.image;
return (x_>=x+offsetx && x_<=x+bi.getWidth()+offsetx && y_>=y+offsety && y_<=y+bi.getHeight()+offsety);
}
public DefaultMutableTreeNode getTreeNode() {
......
......@@ -29,6 +29,7 @@ import java.awt.*;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.border.*;
import vlcskineditor.resources.ImageResource;
/**
* Checkbox item
......@@ -61,22 +62,39 @@ public class Checkbox extends Item implements ActionListener{
JTextField up2_tf, down2_tf, over2_tf, action2_tf, tooltiptext2_tf, state_tf;
JComboBox lefttop_cb, rightbottom_cb, xkeepratio_cb, ykeepratio_cb;
JButton visible_btn, action1_btn, action2_btn, state_btn, ok_btn, cancel_btn, help_btn;
ImageResource up1_res, over1_res, down1_res, up2_res, over2_res, down2_res;
ActionEditor action1_ae, action2_ae;
/** Creates a new instance of Checkbox */
/** Creates a new instance of Checkbox
* @param xmlcode The XML code
* @param s_ The parent skin
*/
public Checkbox(String xmlcode, Skin s_) {
type = "Checkbox";
s = s_;
up1 = XML.getValue(xmlcode,"up1");
up1_res = s.getImageResource(up1);
up2 = XML.getValue(xmlcode,"up2");
up2_res = s.getImageResource(up2);
state = XML.getValue(xmlcode,"state");
if(xmlcode.indexOf(" over1=\"")!=-1) over1 = XML.getValue(xmlcode,"over1");
if(xmlcode.indexOf(" over2=\"")!=-1) over2 = XML.getValue(xmlcode,"over2");
if(xmlcode.indexOf(" down1=\"")!=-1) down1 = XML.getValue(xmlcode,"down1");
if(xmlcode.indexOf(" down2=\"")!=-1) down2 = XML.getValue(xmlcode,"down2");
if(xmlcode.indexOf(" up1=\"")!=-1) up1 = XML.getValue(xmlcode,"up1");
if(xmlcode.indexOf(" up2=\"")!=-1) up2 = XML.getValue(xmlcode,"up2");
if(xmlcode.indexOf(" over1=\"")!=-1) {
over1 = XML.getValue(xmlcode,"over1");
over1_res = s.getImageResource(over1);
}
if(xmlcode.indexOf(" over2=\"")!=-1) {
over2 = XML.getValue(xmlcode,"over2");
over2_res = s.getImageResource(over2);
}
if(xmlcode.indexOf(" down1=\"")!=-1) {
down1 = XML.getValue(xmlcode,"down1");
down1_res = s.getImageResource(down1);
}
if(xmlcode.indexOf(" down2=\"")!=-1) {
down2 = XML.getValue(xmlcode,"down2");
down2_res = s.getImageResource(down2);
}
if(xmlcode.indexOf(" action1=\"")!=-1) action1 = XML.getValue(xmlcode,"action1");
if(xmlcode.indexOf(" action2=\"")!=-1) action2 = XML.getValue(xmlcode,"action2");
if(xmlcode.indexOf(" tooltiptext1=\"")!=-1) tooltiptext1 = XML.getValue(xmlcode,"tooltiptext1");
......@@ -412,28 +430,40 @@ public class Checkbox extends Item implements ActionListener{
JOptionPane.showMessageDialog(frame,"Please provide the state condition!","State not valid",JOptionPane.INFORMATION_MESSAGE);
return;
}
if(s.getResource(up1_tf.getText())==null) {
up1_res = s.getImageResource(up1_tf.getText());
if(up1_res==null) {
JOptionPane.showMessageDialog(frame,"The bitmap \""+up1_tf.getText()+"\" does not exist!","Image not valid",JOptionPane.INFORMATION_MESSAGE);
up1_res = s.getImageResource(up1);
return;
}
if(!over1_tf.getText().equals("none") && s.getResource(over1_tf.getText())==null) {
over1_res = s.getImageResource(over1_tf.getText());
if(!over1_tf.getText().equals("none") && over1_res==null) {
JOptionPane.showMessageDialog(frame,"The bitmap \""+over1_tf.getText()+"\" does not exist!","Image not valid",JOptionPane.INFORMATION_MESSAGE);
over1_res = s.getImageResource(over1);
return;
}
if(!down1_tf.getText().equals("none") && s.getResource(down1_tf.getText())==null) {
down1_res = s.getImageResource(down1_tf.getText());
if(!down1_tf.getText().equals("none") && down1_res==null) {
JOptionPane.showMessageDialog(frame,"The bitmap \""+down1_tf.getText()+"\" does not exist!","Image not valid",JOptionPane.INFORMATION_MESSAGE);
down1_res = s.getImageResource(down1);
return;
}
if(s.getResource(up2_tf.getText())==null) {
up2_res = s.getImageResource(up2_tf.getText());
if(up2_res==null) {
JOptionPane.showMessageDialog(frame,"The bitmap \""+up2_tf.getText()+"\" does not exist!","Image not valid",JOptionPane.INFORMATION_MESSAGE);
up2_res = s.getImageResource(up2);
return;
}
over2_res = s.getImageResource(over2_tf.getText());
if(!over2_tf.getText().equals("none") && s.getResource(over2_tf.getText())==null) {
JOptionPane.showMessageDialog(frame,"The bitmap \""+over2_tf.getText()+"\" does not exist!","Image not valid",JOptionPane.INFORMATION_MESSAGE);
over2_res = s.getImageResource(over2);
return;
}
if(!down2_tf.getText().equals("none") && s.getResource(down2_tf.getText())==null) {
down2_res = s.getImageResource(down2_tf.getText());
if(!down2_tf.getText().equals("none") && down2_res==null) {
JOptionPane.showMessageDialog(frame,"The bitmap \""+down2_tf.getText()+"\" does not exist!","Image not valid",JOptionPane.INFORMATION_MESSAGE);
down2_res = s.getImageResource(down2);
return;
}
update();
......@@ -539,14 +569,14 @@ public class Checkbox extends Item implements ActionListener{
if(!created) return;
java.awt.image.BufferedImage bi = null;
if(s.gvars.parseBoolean(state)) {
if(!hovered || ( (over2.equals("none") && !clicked)||(clicked && down2.equals("none")) )) bi = s.getBitmapImage(up2);
else if(!clicked || down2.equals("none")) bi = s.getBitmapImage(over2);
else bi = s.getBitmapImage(down2);
if(!hovered || ( (over2.equals("none") && !clicked)||(clicked && down2.equals("none")) )) bi = up2_res.image;
else if(!clicked || down2.equals("none")) bi = over2_res.image;
else bi = down2_res.image;
}
else {
if(!hovered || ( (over1.equals("none") && !clicked)||(clicked && down1.equals("none")) )) bi = s.getBitmapImage(up1);
else if(!clicked || down1.equals("none")) bi = s.getBitmapImage(over2);
else bi = s.getBitmapImage(down2);
if(!hovered || ( (over1.equals("none") && !clicked)||(clicked && down1.equals("none")) )) bi = up1_res.image;
else if(!clicked || down1.equals("none")) bi = over1_res.image;
else bi = down1_res.image;
}
if(s.gvars.parseBoolean(visible)==true )g.drawImage(bi,(x+x_)*z,(y+y_)*z,bi.getWidth()*z,bi.getHeight()*z,null);
if(selected) {
......@@ -556,7 +586,7 @@ public class Checkbox extends Item implements ActionListener{
}
@Override
public boolean contains(int x_, int y_) {
java.awt.image.BufferedImage bi = s.getBitmapImage(up1);
java.awt.image.BufferedImage bi = up1_res.image;
return (x_>=x+offsetx && x_<=x+bi.getWidth()+offsetx && y_>=y+offsety && y_<=y+bi.getHeight()+offsety);
}
public DefaultMutableTreeNode getTreeNode() {
......
......@@ -26,9 +26,11 @@ import vlcskineditor.*;
import vlcskineditor.history.*;
import java.awt.event.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.border.*;
import vlcskineditor.resources.ImageResource;
/**
* Image item
......@@ -50,12 +52,18 @@ public class Image extends Item implements ActionListener{
JButton visible_btn, action2_btn, ok_btn, cancel_btn, help_btn;
ActionEditor action2_ae;
ImageResource image_res;
/** Creates a new instance of Image */
/** Creates a new instance of Image
* @param xmlcode The XML code
* @param s_ The parent skin
*/
public Image(String xmlcode, Skin s_) {
type = "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");
......@@ -302,8 +310,10 @@ public class Image extends Item implements ActionListener{
return;
}
}
if(s.getResource(image_tf.getText())==null) {
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);
image_res = s.getImageResource(image);
return;
}
update();
......@@ -380,7 +390,7 @@ public class Image extends Item implements ActionListener{
}
public void draw(Graphics2D g,int x_, int y_, int z) {
if(!created) return;
java.awt.image.BufferedImage bi = s.getBitmapImage(image);
BufferedImage bi = image_res.image;
if(s.gvars.parseBoolean(visible)==true) g.drawImage(bi,(x+x_)*z,(y+y_)*z,bi.getWidth()*z,bi.getHeight()*z,null);
if(selected) {
g.setColor(Color.RED);
......@@ -389,7 +399,7 @@ public class Image extends Item implements ActionListener{
}
@Override
public boolean contains(int x_, int y_) {
java.awt.image.BufferedImage bi = s.getBitmapImage(image);
BufferedImage bi = image_res.image;
return (x_>=x+offsetx && x_<=x+bi.getWidth()+offsetx && y_>=y+offsety && y_<=y+bi.getHeight()+offsety);
}
public DefaultMutableTreeNode getTreeNode() {
......
......@@ -30,6 +30,7 @@ import java.awt.image.*;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.border.*;
import vlcskineditor.resources.ImageResource;
/**
* Playtree item
......@@ -76,8 +77,13 @@ public class Playtree extends Item implements ActionListener{
JComboBox lefttop_cb, rightbottom_cb, xkeepratio_cb, ykeepratio_cb, flat_cb;
JButton visible_btn, bgcolor1_btn, bgcolor2_btn, fgcolor_btn, playcolor_btn, selcolor_btn, slider_btn, ok_btn, help_btn;
JButton cancel_btn;
ImageResource bgimage_res, itemimage_res, openimage_res, closedimage_res;
/** Creates a new instance of Playtree */
/** Creates a new instance of Playtree
* @param xmlcode The XML code
* @param s_ The parent skin
*/
public Playtree(String xmlcode, Skin s_) {
type = "Playtree";
s = s_;
......@@ -87,10 +93,22 @@ public class Playtree extends Item implements ActionListener{
if(xmllines[0].indexOf("width=\"")!=-1) width = XML.getIntValue(xmllines[0],"width");
if(xmllines[0].indexOf("height=\"")!=-1) height = XML.getIntValue(xmllines[0],"height");
if(xmllines[0].indexOf("var=\"")!=-1) var = XML.getValue(xmllines[0],"var");
if(xmllines[0].indexOf("bgimage=\"")!=-1) bgimage = XML.getValue(xmllines[0],"bgimage");
if(xmllines[0].indexOf("openimage=\"")!=-1) openimage = XML.getValue(xmllines[0],"openimage");
if(xmllines[0].indexOf("closedimage=\"")!=-1) closedimage = XML.getValue(xmllines[0],"closedimage");
if(xmllines[0].indexOf("itemimage=\"")!=-1) itemimage = XML.getValue(xmllines[0],"itemimage");
if(xmllines[0].indexOf("bgimage=\"")!=-1) {
bgimage = XML.getValue(xmllines[0],"bgimage");
bgimage_res = s.getImageResource(bgimage);
}
if(xmllines[0].indexOf("openimage=\"")!=-1) {
openimage = XML.getValue(xmllines[0],"openimage");
openimage_res = s.getImageResource(openimage);
}
if(xmllines[0].indexOf("closedimage=\"")!=-1) {
closedimage = XML.getValue(xmllines[0],"closedimage");
closedimage_res = s.getImageResource(closedimage);
}
if(xmllines[0].indexOf("itemimage=\"")!=-1) {
itemimage = XML.getValue(xmllines[0],"itemimage");
itemimage_res = s.getImageResource(itemimage);
}
if(xmllines[0].indexOf("fgcolor=\"")!=-1) fgcolor = XML.getValue(xmllines[0],"fgcolor");
if(xmllines[0].indexOf("playcolor=\"")!=-1) playcolor = XML.getValue(xmllines[0],"playcolor");
if(xmllines[0].indexOf("selcolor=\"")!=-1) selcolor = XML.getValue(xmllines[0],"selcolor");
......@@ -471,20 +489,28 @@ public class Playtree extends Item implements ActionListener{
return;
}
}
if(!bgimage_tf.getText().equals("none")&&s.getResource(bgimage_tf.getText())==null) {
bgimage_res = s.getImageResource(bgimage_tf.getText());
if(!bgimage_tf.getText().equals("none")&&bgimage_res==null) {
JOptionPane.showMessageDialog(frame,"Please choose an existing background image!","Bgimage does not exist",JOptionPane.INFORMATION_MESSAGE);
bgimage_res = s.getImageResource(bgimage);
return;
}
if(!itemimage_tf.getText().equals("none")&&s.getResource(itemimage_tf.getText())==null) {
itemimage_res = s.getImageResource(itemimage_tf.getText());
if(!itemimage_tf.getText().equals("none")&&itemimage_res==null) {
JOptionPane.showMessageDialog(frame,"Please choose an existing item icon!","Itemimage does not exist",JOptionPane.INFORMATION_MESSAGE);
itemimage_res = s.getImageResource(itemimage);
return;
}
if(!openimage_tf.getText().equals("none")&&s.getResource(openimage_tf.getText())==null) {
openimage_res = s.getImageResource(openimage_tf.getText());
if(!openimage_tf.getText().equals("none")&&openimage_res==null) {
JOptionPane.showMessageDialog(frame,"Please choose an existing open folder icon!","Openimage does not exist",JOptionPane.INFORMATION_MESSAGE);
openimage_res = s.getImageResource(openimage);
return;
}
if(!closedimage_tf.getText().equals("none")&&s.getResource(closedimage_tf.getText())==null) {
closedimage_res = s.getImageResource(closedimage_tf.getText());
if(!closedimage_tf.getText().equals("none")&&closedimage_res==null) {
JOptionPane.showMessageDialog(frame,"Please choose an existing closed folder icon!","Closedimage does not exist",JOptionPane.INFORMATION_MESSAGE);
closedimage_res = s.getImageResource(closedimage);
return;
}
if(!font_tf.getText().equals("defaultfont")&&s.getResource(font_tf.getText())==null) {
......@@ -647,7 +673,7 @@ public class Playtree extends Item implements ActionListener{
g.setFont(f);
FontMetrics fm = g.getFontMetrics();
if(!bgimage.equals("none")) {
g.drawImage(s.getBitmapImage(bgimage).getSubimage(0, 0, width, height),0,0,null);
g.drawImage(bgimage_res.image.getSubimage(0, 0, width, height),0,0,null);
}
else {
g.setColor(Color.decode(bgcolor1));
......@@ -658,9 +684,9 @@ public class Playtree extends Item implements ActionListener{
}
}
int liney = 0;
BufferedImage cfi = s.getBitmapImage(closedimage);
BufferedImage ofi = s.getBitmapImage(openimage);
BufferedImage iti = s.getBitmapImage(itemimage);
BufferedImage cfi = closedimage_res.image;
BufferedImage ofi = openimage_res.image;
BufferedImage iti = itemimage_res.image;
int lineheight = fm.getHeight();
int cfi_offset=0,ofi_offset=0,iti_offset=0;
if(cfi!=null) {
......
......@@ -30,6 +30,7 @@ import java.awt.geom.*;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.border.*;
import vlcskineditor.resources.ImageResource;
/**
* Slider item
......@@ -60,18 +61,30 @@ public class Slider extends Item implements ActionListener{
JComboBox lefttop_cb, rightbottom_cb, xkeepratio_cb, ykeepratio_cb, resize_cb, action_cb, value_cb;
JCheckBox sbg_chb;
JButton visible_btn, ok_btn, cancel_btn, help_btn, sbg_btn;
ImageResource up_res, over_res, down_res;
Bezier b;
int[] xpos,ypos;
/** Creates a new instance of Slider */
/** Creates a new instance of Slider
* @param xmlcode The XML code
* @param s_ The parent skin
*/
public Slider(String xmlcode, Skin s_) {
type = "Slider";
s = s_;
String[] code = xmlcode.split("\n");
up = XML.getValue(code[0],"up");
if(code[0].indexOf(" down=\"")!=-1) down = XML.getValue(code[0],"down");
if(code[0].indexOf(" over=\"")!=-1) over = XML.getValue(code[0],"over");
up_res = s.getImageResource(up);
if(code[0].indexOf(" down=\"")!=-1) {
down = XML.getValue(code[0],"down");
down_res = s.getImageResource(down);
}
if(code[0].indexOf(" over=\"")!=-1) {
over = XML.getValue(code[0],"over");
over_res = s.getImageResource(over);
}
points = XML.getValue(code[0],"points");
updateBezier();
if(code[0].indexOf(" thickness=\"")!=-1) thickness = XML.getIntValue(code[0],"thickness");
......@@ -108,6 +121,7 @@ public class Slider extends Item implements ActionListener{
String[] code = xmlcode.split("\n");
inPlaytree = ipt;
up = XML.getValue(code[0],"up");
up_res = s.getImageResource(up);
if(code[0].indexOf("down=\"")!=-1) down = XML.getValue(code[0],"down");
if(code[0].indexOf("over=\"")!=-1) over = XML.getValue(code[0],"over");
points = XML.getValue(code[0],"points");
......@@ -438,16 +452,22 @@ public class Slider extends Item implements ActionListener{
return;
}
}
if(s.getResource(up_tf.getText())==null) {
up_res = s.getImageResource(up_tf.getText());
if(up_res==null) {
JOptionPane.showMessageDialog(frame,"The bitmap \""+up_tf.getText()+"\" does not exist!","Image not valid",JOptionPane.INFORMATION_MESSAGE);
up_res = s.getImageResource(up);
return;
}
if(!over_tf.getText().equals("none") && s.getResource(over_tf.getText())==null) {
over_res = s.getImageResource(over_tf.getText());
if(!over_tf.getText().equals("none") && over_res==null) {
JOptionPane.showMessageDialog(frame,"The bitmap \""+over_tf.getText()+"\" does not exist!","Image not valid",JOptionPane.INFORMATION_MESSAGE);
over_res = s.getImageResource(over);
return;
}
if(!down_tf.getText().equals("none") && s.getResource(down_tf.getText())==null) {
down_res = s.getImageResource(down_tf.getText());
if(!down_tf.getText().equals("none") && down_res==null) {
JOptionPane.showMessageDialog(frame,"The bitmap \""+down_tf.getText()+"\" does not exist!","Image not valid",JOptionPane.INFORMATION_MESSAGE);
down_res = s.getImageResource(down);
return;
}
if(points_tf.getText().equals("")) {
......@@ -557,7 +577,7 @@ public class Slider extends Item implements ActionListener{
sbg.draw(g,x+x_,y+y_,z);
sbg.setOffset(x+offsetx,y+offsety);
}
java.awt.image.BufferedImage si = s.getBitmapImage(up);
java.awt.image.BufferedImage si = up_res.image;
Point2D.Float p = b.getPoint(s.gvars.getSliderValue());
if(vis && si!=null) g.drawImage(si,(int)(p.getX()+x+x_-si.getWidth()/2)*z,(int)(p.getY()+y+y_-si.getHeight()/2)*z,si.getWidth()*z,si.getHeight()*z,null);
if(selected) {
......
......@@ -30,6 +30,7 @@ import java.awt.image.*;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.border.*;
import vlcskineditor.resources.ImageResource;
/**
* SliderBackground item
......@@ -51,16 +52,21 @@ public class SliderBackground extends Item implements ActionListener{
JFrame frame;
public JTextField id_tf, image_tf, nbhoriz_tf, nbvert_tf, padhoriz_tf, padvert_tf;
JButton gen_btn, ok_btn, cancel_btn, help_btn;
ImageResource image_res;
BufferedImage bi = null;
String bitmap_str = "";
Slider sl;
/** Creates a new instance of SliderBackground */
/** Creates a new instance of SliderBackground
* @param xmlcode The XML code
* @param s_ The parent skin
*/
public SliderBackground(String xmlcode, Skin s_) {
type = "SliderBackground";
s = s_;
image = XML.getValue(xmlcode,"image");
image_res = s.getImageResource(image);
if(xmlcode.indexOf("nbhoriz=\"")!=-1) nbhoriz = XML.getIntValue(xmlcode,"nbhoriz");
if(xmlcode.indexOf("nbvert=\"")!=-1) nbvert = XML.getIntValue(xmlcode,"nbvert");
if(xmlcode.indexOf("padhoriz=\"")!=-1) padhoriz = XML.getIntValue(xmlcode,"padhoriz");
......@@ -214,8 +220,10 @@ public class SliderBackground extends Item implements ActionListener{
return;
}
}
if(s.getResource(image_tf.getText())==null) {
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);
image_res = s.getImageResource(image);
return;
}
update();
......@@ -268,7 +276,7 @@ public class SliderBackground extends Item implements ActionListener{
}
public void draw(Graphics2D g, int x_, int y_, int z) {
if(!created) return;
bi = s.getBitmapImage(image);
bi = image_res.image;
if(bi==null) return;
int fwidth = (bi.getWidth()-padhoriz*(nbhoriz-1))/nbhoriz;
int fheight = (bi.getHeight()-padvert*(nbvert-1))/nbvert;
......
......@@ -39,7 +39,7 @@ import org.w3c.dom.Element;
* Handles Bitmap resources
* @author Daniel
*/
public class Bitmap extends Resource implements ActionListener{
public class Bitmap extends ImageResource implements ActionListener{
public String file;
public final String ALPHACOLOR_DEFAULT = "#FF00FF";
......@@ -49,9 +49,7 @@ public class Bitmap extends Resource implements ActionListener{
public final int FPS_DEFAULT = 0;
public int fps = FPS_DEFAULT;
//The list containing the bitmap's SubBitmaps
public java.util.List<SubBitmap> SubBitmaps = new LinkedList<SubBitmap>();
//The image represented by the Bitmap item
public BufferedImage image;
public java.util.List<SubBitmap> SubBitmaps = new LinkedList<SubBitmap>();
private JFrame frame = null;
private JTextField id_tf, file_tf, alphacolor_tf, nbframes_tf, fps_tf;
......
/*****************************************************************************
* ImageResource.java
*****************************************************************************
* Copyright (C) 2007 Daniel Dreibrodt
*
* This file is part of vlcskineditor.resources
*
* 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.resources;
import java.awt.image.BufferedImage;
import vlcskineditor.Resource;