Commit ba87a97a authored by Daniel Dreibrodt's avatar Daniel Dreibrodt

New toolbar buttons, groundwork for slider edting

parent 9898fae8
......@@ -395,8 +395,8 @@ public class ActionEditor extends JFrame implements ActionListener{
img = Toolkit.getDefaultToolkit().createImage(this.getClass().getResource(filename));
//img = ImageIO.read(file);
return new ImageIcon(img);
} catch (Exception e) {
System.out.println(e);
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
......
......@@ -122,7 +122,7 @@ public class Helper {
while( (entry=zin.getNextEntry()) !=null ) {
if(!(System.getProperty("os.name").indexOf("Windows")==-1 && (entry.getName().endsWith("exe")||entry.getName().endsWith("dll")))){
File outf = new File(entry.getName());
System.out.println(outf.getAbsoluteFile());
System.out.println("Unzipping: "+outf.getAbsoluteFile());
if(entry.isDirectory()) outf.mkdirs();
else {
outf.createNewFile();
......
......@@ -74,7 +74,7 @@ public class Main extends JFrame implements ActionListener, TreeSelectionListene
/** The toolbar */
private JPanel tbar;
/** The toolbar buttons */
private JButton tbar_open_btn, tbar_save_btn, tbar_undo_btn, tbar_redo_btn;
private ToolbarButton tbar_open_btn, tbar_save_btn, tbar_undo_btn, tbar_redo_btn, tbar_move_btn, tbar_path_btn;
/** The desktop pane holding the resources, windows/layouts and items windows */
private JDesktopPane jdesk;
......@@ -326,18 +326,41 @@ public class Main extends JFrame implements ActionListener, TreeSelectionListene
tbar_redo_btn.setToolTipText(Language.get("TOOLBAR_REDO"));
tbar_redo_btn.addActionListener(this);
tbar.add(tbar_redo_btn);
JToolBar.Separator tbar_sep_2 = new JToolBar.Separator(new Dimension(10,22));
tbar_sep_2.setOrientation(JSeparator.VERTICAL);
tbar.add(tbar_sep_2);
tbar_move_btn = new ToolbarButton(Toolkit.getDefaultToolkit().createImage(Main.class.getResource("icons/tbar_move.png")));
tbar_move_btn.setToolTipText(Language.get("TOOLBAR_MOVE"));
tbar_move_btn.addActionListener(this);
tbar_move_btn.setPressed(true);
tbar.add(tbar_move_btn);
tbar_path_btn = new ToolbarButton(Toolkit.getDefaultToolkit().createImage(Main.class.getResource("icons/tbar_path.png")));
tbar_path_btn.setToolTipText(Language.get("TOOLBAR_PATH"));
tbar_path_btn.addActionListener(this);
tbar.add(tbar_path_btn);
//Toolbar layout
SpringLayout tbar_layout = new SpringLayout();
tbar_layout.putConstraint(SpringLayout.VERTICAL_CENTER, tbar_open_btn, 0, SpringLayout.VERTICAL_CENTER, tbar);
tbar_layout.putConstraint(SpringLayout.WEST, tbar_open_btn, 2, SpringLayout.WEST, tbar);
tbar_layout.putConstraint(SpringLayout.VERTICAL_CENTER, tbar_save_btn, 0, SpringLayout.VERTICAL_CENTER, tbar);
tbar_layout.putConstraint(SpringLayout.WEST, tbar_save_btn, 2, SpringLayout.EAST, tbar_open_btn);
tbar_layout.putConstraint(SpringLayout.VERTICAL_CENTER, tbar_sep_1, 0, SpringLayout.VERTICAL_CENTER, tbar);
tbar_layout.putConstraint(SpringLayout.WEST, tbar_sep_1, 2, SpringLayout.EAST, tbar_save_btn);
tbar_layout.putConstraint(SpringLayout.VERTICAL_CENTER, tbar_undo_btn, 0, SpringLayout.VERTICAL_CENTER, tbar);
tbar_layout.putConstraint(SpringLayout.WEST, tbar_undo_btn, 2, SpringLayout.EAST, tbar_sep_1);
tbar_layout.putConstraint(SpringLayout.VERTICAL_CENTER, tbar_redo_btn, 0, SpringLayout.VERTICAL_CENTER, tbar);
tbar_layout.putConstraint(SpringLayout.WEST, tbar_redo_btn, 2, SpringLayout.EAST, tbar_undo_btn);
tbar_layout.putConstraint(SpringLayout.VERTICAL_CENTER, tbar_sep_2, 0, SpringLayout.VERTICAL_CENTER, tbar);
tbar_layout.putConstraint(SpringLayout.WEST, tbar_sep_2, 2, SpringLayout.EAST, tbar_redo_btn);
tbar_layout.putConstraint(SpringLayout.VERTICAL_CENTER, tbar_move_btn, 0, SpringLayout.VERTICAL_CENTER, tbar);
tbar_layout.putConstraint(SpringLayout.WEST, tbar_move_btn, 2, SpringLayout.EAST, tbar_sep_2);
tbar_layout.putConstraint(SpringLayout.VERTICAL_CENTER, tbar_path_btn, 0, SpringLayout.VERTICAL_CENTER, tbar);
tbar_layout.putConstraint(SpringLayout.WEST, tbar_path_btn, 2, SpringLayout.EAST, tbar_move_btn);
tbar.setLayout(tbar_layout);
tbar.setPreferredSize(new Dimension(tbar.getPreferredSize().width,26));
tbar.setMaximumSize(new Dimension(tbar.getMaximumSize().width,26));
......@@ -1565,7 +1588,17 @@ public class Main extends JFrame implements ActionListener, TreeSelectionListene
}
else if(e.getSource().equals(m_edit_redo)||e.getSource().equals(tbar_redo_btn)) {
if(hist!=null) hist.redo();
}
}
else if(e.getSource().equals(tbar_move_btn)) {
tbar_move_btn.setPressed(true);
tbar_path_btn.setPressed(false);
if(pvwin!=null) pvwin.setCursorMode(PreviewWindow.CURSOR_MOVE);
}
else if(e.getSource().equals(tbar_path_btn)) {
tbar_move_btn.setPressed(false);
tbar_path_btn.setPressed(true);
if(pvwin!=null) pvwin.setCursorMode(PreviewWindow.CURSOR_PATH);
}
}
private void deleteSelectedItem() {
......@@ -1814,8 +1847,8 @@ public class Main extends JFrame implements ActionListener, TreeSelectionListene
img = Toolkit.getDefaultToolkit().createImage(Main.class.getResource(filename));
//img = ImageIO.read(file);
return new ImageIcon(img);
} catch (Exception e) {
System.out.println(e);
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
......@@ -2058,7 +2091,6 @@ public class Main extends JFrame implements ActionListener, TreeSelectionListene
* @return the selected item in the items window
*/
public String getSelectedItem() {
System.out.println(selected_item);
return selected_item;
}
}
......@@ -39,25 +39,40 @@ public class PreviewWindow extends JPanel implements MouseListener, MouseMotionL
public static final long serialVersionUID = 071;
/**
* The JFrame in which a Layout of a Skin will be shown.
*/
/** The JFrame in which a Layout of a Skin will be shown. */
public JInternalFrame frame;
JScrollPane scroll_pane;
JPanel zoom_panel;
JButton zoom_more, zoom_less;
JLabel zoom_label;
int z = 1;
Layout l;
FrameUpdater fu;
Item selected_item;
boolean starteddragging = false;
int dragstartx, dragstarty, dragstartitemx, dragstartitemy;
JMenuItem up, down, right, left;
ItemMoveEvent ime = null;
Main m;
/** The scroll pane holding the preview rendering */
private JScrollPane scroll_pane;
/** The panel holding the zoom controls */
private JPanel zoom_panel;
/** The zoom control buttons */
private JButton zoom_more, zoom_less;
/** The label showing the zoom factor */
private JLabel zoom_label;
/** The zoom factor */
private int z = 1;
/** The currently rendered layout */
private Layout l;
/** The frame updater who is responsible for updating the preview rendering */
protected FrameUpdater fu;
/** The currently selected item in the items window's tree */
private Item selected_item;
/** Indicates whether the cursors is in a drag action */
private boolean starteddragging = false;
/** The starting coordinates of the drag action */
private int dragstartx, dragstarty, dragstartitemx, dragstartitemy;
/** The move event added to the history when the dragging action has finished */
private ItemMoveEvent ime = null;
/** The main program */
private Main m;
/** The cursor mode constant indicating that the cursor should move the selected item */
public static final int CURSOR_MOVE = 1;
/** The cursor mode constant indicating that the cursor should edit the path of the selected item */
public static final int CURSOR_PATH = 2;
/** The current cursor mode */
private int mode = CURSOR_MOVE;
/**
* Creates a new PreviewWindow that is initially hidden.
* @param m_ the Main instance of the running Skin Editor
......@@ -182,58 +197,81 @@ public class PreviewWindow extends JPanel implements MouseListener, MouseMotionL
setPreferredSize(new Dimension(l.width*z, l.height*z));
}
}
public void mouseClicked(MouseEvent e) {
public void mouseClicked(MouseEvent e) {
if(mode==CURSOR_PATH) {
//TODO path editing mouseClicked
}
}
public void mouseDragged(MouseEvent e) {
if(selected_item==null) return;
if(!starteddragging && selected_item.contains(e.getX()/z,e.getY()/z)) {
dragstartx=e.getX()/z;
dragstarty=e.getY()/z;
ime = new ItemMoveEvent(selected_item);
dragstartitemx=selected_item.x;
dragstartitemy=selected_item.y;
starteddragging=true;
}
else if(starteddragging) {
selected_item.x=dragstartitemx+e.getX()/z-dragstartx;
selected_item.y=dragstartitemy+e.getY()/z-dragstarty;
if(mode==CURSOR_MOVE) {
if(!starteddragging && selected_item.contains(e.getX()/z,e.getY()/z)) {
dragstartx=e.getX()/z;
dragstarty=e.getY()/z;
ime = new ItemMoveEvent(selected_item);
dragstartitemx=selected_item.x;
dragstartitemy=selected_item.y;
starteddragging=true;
}
else if(starteddragging) {
selected_item.x=dragstartitemx+e.getX()/z-dragstartx;
selected_item.y=dragstartitemy+e.getY()/z-dragstarty;
}
} else {
//TODO path editing mouseDragged
}
}
public void mouseEntered(MouseEvent e) {
if(mode==CURSOR_PATH) {
setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
}
}
public void mouseExited(MouseEvent e) {
if(mode==CURSOR_PATH) {
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
}
public void mouseMoved(MouseEvent e) {
if(selected_item==null) return;
if(selected_item.contains(e.getX()/z,e.getY()/z)) {
selected_item.setHover(true);
setCursor(new Cursor(Cursor.MOVE_CURSOR));
}
else {
selected_item.setHover(false);
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
if(mode==CURSOR_MOVE) {
if(selected_item.contains(e.getX()/z,e.getY()/z)) {
selected_item.setHover(true);
setCursor(new Cursor(Cursor.MOVE_CURSOR));
}
else {
selected_item.setHover(false);
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
} else {
//TODO path editing mouseMoved
}
}
public void mousePressed(MouseEvent e) {
fu.fps=25;
if(selected_item!=null) selected_item.setClicked(true);
if(mode==CURSOR_MOVE) {
if(selected_item!=null) selected_item.setClicked(true);
} else {
//TODO path editing mousePressed
}
}
public void mouseReleased(MouseEvent e) {
fu.fps=5;
if(starteddragging) {
ime.setNew();
m.hist.addEvent(ime);
ime = null;
fu.fps=5;
if(mode==CURSOR_MOVE) {
if(starteddragging) {
ime.setNew();
m.hist.addEvent(ime);
ime = null;
}
starteddragging=false;
if(selected_item!=null) selected_item.setClicked(false);
else return;
dragstartx=selected_item.x+selected_item.offsetx;
dragstarty=selected_item.y+selected_item.offsety;
dragstartitemx=selected_item.x;
dragstartitemy=selected_item.y;
} else {
//TODO path editing mouseReleased
}
starteddragging=false;
if(selected_item!=null) selected_item.setClicked(false);
else return;
dragstartx=selected_item.x+selected_item.offsetx;
dragstarty=selected_item.y+selected_item.offsety;
dragstartitemx=selected_item.x;
dragstartitemy=selected_item.y;
}
/**
* Moves the currently selected item about the given distance.
......@@ -271,5 +309,21 @@ public class PreviewWindow extends JPanel implements MouseListener, MouseMotionL
JOptionPane.showMessageDialog(m,Language.get("ERROR_SAVEPNG_MSG")+"\n"+e.toString(),Language.get("ERROR_SAVEPNG_TITLE"),JOptionPane.ERROR_MESSAGE);
return;
}
}
}
/**
* Sets the cursor mode
* @param c One of the cursor mode constants
*/
public void setCursorMode(int c) {
mode = c;
}
/**
* Gets the current cursor mode
* @return The cursor mode constants indicating the current cursor mode
*/
public int getCursorMode() {
return mode;
}
}
......@@ -700,7 +700,7 @@ public class Skin implements ActionListener{
l = g.items;
}
catch(Exception ex2) {
System.out.println(ex2);
ex2.printStackTrace();
}
}
return l;
......
......@@ -497,8 +497,8 @@ public class SliderBGGen extends JFrame implements ActionListener{
img = Toolkit.getDefaultToolkit().createImage(this.getClass().getResource(filename));
//img = ImageIO.read(file);
return new ImageIcon(img);
} catch (Exception e) {
System.out.println(e);
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
......
......@@ -19,8 +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;
import java.awt.Color;
......@@ -38,51 +36,79 @@ import javax.swing.JButton;
* @author Daniel Dreibrodt
*/
public class ToolbarButton extends JButton implements MouseListener {
ImageIcon normal, over, down;
/** The normal state image */
ImageIcon normal;
/** The mouse-over state image */
ImageIcon over;
/** The mouse-clicked state image */
ImageIcon down;
/** The isPressed state image */
ImageIcon pressed;
/** Indicates whether the mouse is currently hovering the button */
boolean hover = false;
boolean mac = System.getProperty("os.name").indexOf("Mac")!=-1;
/** Indicates whether this button is running under a Mac system, which implements its own hovering and clicking effects */
boolean mac = System.getProperty("os.name").indexOf("Mac") != -1;
/** Indicates that this button is in a isPressed state, e.g. a button setting a certain mode, if the mode is set than the button is in a isPressed state */
boolean isPressed = false;
/**
* Creates a new toolbar button
* @param img The button's icon
*/
public ToolbarButton(Image img) {
try {
try {
normal = new ImageIcon(img);
BufferedImage icon = new BufferedImage(normal.getIconWidth(), normal.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
icon.getGraphics().drawImage(normal.getImage(), 0, 0, this);
if(!mac) {
BufferedImage ovbi = new BufferedImage(icon.getWidth(this),icon.getHeight(this),BufferedImage.TYPE_INT_ARGB);
for(int x=0;x<icon.getWidth(this);x++) {
for(int y=0;y<icon.getHeight(this);y++) {
BufferedImage ovbi = new BufferedImage(icon.getWidth(this), icon.getHeight(this), BufferedImage.TYPE_INT_ARGB);
for(int x = 0; x < icon.getWidth(this); x++) {
for(int y = 0; y < icon.getHeight(this); y++) {
Graphics g = ovbi.getGraphics();
int argb = icon.getRGB(x,y);
int argb = icon.getRGB(x, y);
int red = (argb >> 16) & 0xff;
int green = (argb >> 8) & 0xff;
int blue = argb & 0xff;
int alpha = (argb >> 24) & 0xff;
g.setColor(brighter(new Color(red,green,blue,alpha),0.92));
g.setColor(brighter(new Color(red, green, blue, alpha), 0.92));
g.fillRect(x, y, 1, 1);
}
}
over = new ImageIcon(ovbi);
BufferedImage dobi = new BufferedImage(icon.getWidth(this),icon.getHeight(this),BufferedImage.TYPE_INT_ARGB);
for(int x=0;x<icon.getWidth(this);x++) {
for(int y=0;y<icon.getHeight(this);y++) {
BufferedImage dobi = new BufferedImage(icon.getWidth(this), icon.getHeight(this), BufferedImage.TYPE_INT_ARGB);
for(int x = 0; x < icon.getWidth(this); x++) {
for(int y = 0; y < icon.getHeight(this); y++) {
Graphics g = dobi.getGraphics();
int argb = icon.getRGB(x,y);
int argb = icon.getRGB(x, y);
int red = (argb >> 16) & 0xff;
int green = (argb >> 8) & 0xff;
int blue = argb & 0xff;
int alpha = (argb >> 24) & 0xff;
g.setColor(darker(new Color(red,green,blue,alpha),0.92));
g.setColor(darker(new Color(red, green, blue, alpha), 0.92));
g.fillRect(x, y, 1, 1);
}
}
down = new ImageIcon(dobi);
BufferedImage prbi = new BufferedImage(icon.getWidth(this), icon.getHeight(this), BufferedImage.TYPE_INT_ARGB);
for(int x = 0; x < icon.getWidth(this); x++) {
for(int y = 0; y < icon.getHeight(this); y++) {
Graphics g = prbi.getGraphics();
int argb = icon.getRGB(x, y);
int red = (argb >> 16) & 0xff;
int green = (argb >> 8) & 0xff;
int blue = argb & 0xff;
int alpha = (argb >> 24) & 0xff;
g.setColor(darker(new Color(red, green, blue, alpha), 0.7));
g.fillRect(x, y, 1, 1);
}
}
pressed = new ImageIcon(prbi);
}
setIcon(normal);
......@@ -90,73 +116,123 @@ public class ToolbarButton extends JButton implements MouseListener {
setContentAreaFilled(false);
setFocusPainted(false);
addMouseListener(this);
setPreferredSize(new Dimension(normal.getIconWidth()+8,normal.getIconHeight()+8));
setPreferredSize(new Dimension(normal.getIconWidth() + 8, normal.getIconHeight() + 8));
} catch(Exception ex) {
ex.printStackTrace();
setText(" ");
}
}
}
public void mouseClicked(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
if(mac) return;
if(mac||isPressed) {
return;
}
setIcon(down);
repaint();
}
public void mouseReleased(MouseEvent e) {
if(mac) return;
if(hover) setIcon(over);
else setIcon(normal);
public void mouseReleased(MouseEvent e) {
if(mac||isPressed) {
return;
}
if(hover) {
setIcon(over);
} else {
setIcon(normal);
}
repaint();
}
public void mouseEntered(MouseEvent e) {
if(mac) return;
if(mac||isPressed) {
return;
}
hover = true;
setIcon(over);
repaint();
}
public void mouseExited(MouseEvent e) {
if(mac) return;
if(mac||isPressed) {
return;
}
hover = false;
setIcon(normal);
repaint();
}
/**
* Calculates a brighter color which also supports alpha values
* Based upon java.awt.Color.brighter()
* @param c The source color
* @param factor The brightening factor
* @return The brighter color
*/
public Color brighter(Color c, double factor) {
int r = c.getRed();
int g = c.getGreen();
int b = c.getBlue();
int a = c.getAlpha();
/* From 2D group:
* 1. black.brighter() should return grey
* 2. applying brighter to blue will always return blue, brighter
* 3. non pure color (non zero rgb) will eventually return white
*/
int i = (int)(1.0/(1.0-factor));
if ( r == 0 && g == 0 && b == 0) {
return new Color(i, i, i, a);
}
if ( r > 0 && r < i ) r = i;
if ( g > 0 && g < i ) g = i;
if ( b > 0 && b < i ) b = i;
return new Color(Math.min((int)(r/factor), 255),
Math.min((int)(g/factor), 255),
Math.min((int)(b/factor), 255),
a);
int r = c.getRed();
int g = c.getGreen();
int b = c.getBlue();
int a = c.getAlpha();
/* From 2D group:
* 1. black.brighter() should return grey
* 2. applying brighter to blue will always return blue, brighter
* 3. non pure color (non zero rgb) will eventually return white
*/
int i = (int) (1.0 / (1.0 - factor));
if(r == 0 && g == 0 && b == 0) {
return new Color(i, i, i, a);
}
public Color darker(Color c, double factor) {
return new Color(Math.max((int)(c.getRed() *factor), 0),
Math.max((int)(c.getGreen()*factor), 0),
Math.max((int)(c.getBlue() *factor), 0),
c.getAlpha());
if(r > 0 && r < i) {
r = i;
}
if(g > 0 && g < i) {
g = i;
}
if(b > 0 && b < i) {
b = i;
}
return new Color(Math.min((int) (r / factor), 255),
Math.min((int) (g / factor), 255),
Math.min((int) (b / factor), 255),
a);
}
/**
* Calculates a darker color which also supports alpha values
* Based upon java.awt.Color.darker()
* @param c The source color
* @param factor The darkening factor (0-1), the closer to zero, the darker
* @return The darker color
*/
public Color darker(Color c, double factor) {
return new Color(Math.max((int) (c.getRed() * factor), 0),
Math.max((int) (c.getGreen() * factor), 0),
Math.max((int) (c.getBlue() * factor), 0),
c.getAlpha());
}
public void setPressed(boolean p) {
isPressed = p;
if(isPressed) setIcon(pressed);
else {
if(hover) setIcon(over);
else setIcon(normal);
}
repaint();
}
public boolean isPressed() {
return isPressed;
}
}
......@@ -100,8 +100,8 @@ public class TreeRenderer extends DefaultTreeCellRenderer {
try {
img = Toolkit.getDefaultToolkit().createImage(this.getClass().getResource(filename));
return new ImageIcon(img);
} catch (Exception e) {
System.out.println(e);
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
......
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