Commit 744ac278 authored by Daniel Dreibrodt's avatar Daniel Dreibrodt

Toolbar beginnings

parent 736e7ed3
......@@ -115,6 +115,7 @@ WIN_PREFS_TITLE|Preferències
WIN_PREFS_UPDATE_L|Habilita l'actualització automàtica
WIN_PREFS_LANG_L|Llengua:
WIN_PREFS_LAF_L|Programa d'aspecte i comportament:
WIN_PREFS_TBAR_L|Show toolbar:
WIN_PREFS_RESTART_L|<html><i>Alguns paràmetres només tenen efecte quan el programa es reinicia.</i></html>
#SubBitmap Edit and Skin Preview window
......
......@@ -115,6 +115,7 @@ WIN_PREFS_TITLE|Einstellungen
WIN_PREFS_UPDATE_L|Automatisches Update aktivieren:
WIN_PREFS_LANG_L|Sprache:
WIN_PREFS_LAF_L|Programm-Aussehen:
WIN_PREFS_TBAR_L|Toolbar anzeigen:
WIN_PREFS_RESTART_L|<html><i>Einige Einstellungen werden erst nach Programmneustart aktiv.</i></html>
#SubBitmap Edit and Skin Preview window
......
......@@ -115,6 +115,7 @@ WIN_PREFS_TITLE|Preferences
WIN_PREFS_UPDATE_L|Enable auto-update:
WIN_PREFS_LANG_L|Language:
WIN_PREFS_LAF_L|Program look-and-feel:
WIN_PREFS_TBAR_L|Show toolbar:
WIN_PREFS_RESTART_L|<html><i>Some settings only take effect when the program is restarted.</i></html>
#SubBitmap Edit and Skin Preview window
......
......@@ -115,6 +115,7 @@ WIN_PREFS_TITLE|Préférences
WIN_PREFS_UPDATE_L|Activer l'auto-update :
WIN_PREFS_LANG_L|Langage:
WIN_PREFS_LAF_L|Apparence du program :
WIN_PREFS_TBAR_L|Afficher la barre d'outils :
WIN_PREFS_RESTART_L|<html><i>Certaines options ne prennent effet qu'après redémarrage du programme.</i></html>
#SubBitmap Edit and Skin Preview window
......
......@@ -116,6 +116,7 @@ WIN_PREFS_TITLE|Voorkeuren
WIN_PREFS_UPDATE_L|Auto-update activeren:
WIN_PREFS_LANG_L|Taal:
WIN_PREFS_LAF_L|Programma-uiterlijk:
WIN_PREFS_TBAR_L|Toolbar activeren:
WIN_PREFS_RESTART_L|<html><i>Enkele instellingen worden pas van kracht na een herstart van het programma.</i></html>
#SubBitmap Edit and Skin Preview window
......
......@@ -115,6 +115,7 @@ WIN_PREFS_TITLE|Preferences
WIN_PREFS_UPDATE_L|Enable auto-update:
WIN_PREFS_LANG_L|Language:
WIN_PREFS_LAF_L|Program look-and-feel:
WIN_PREFS_TBAR_L|Show toolbar:
WIN_PREFS_RESTART_L|<html><i>Some settings only take effect when the program is restarted.</i></html>
#SubBitmap Edit and Skin Preview window
......
......@@ -115,6 +115,7 @@ WIN_PREFS_TITLE|Nastavenia
WIN_PREFS_UPDATE_L|Aktivovať automatické aktualizácie:
WIN_PREFS_LANG_L|Jazyk:
WIN_PREFS_LAF_L|Vzhľad programu:
WIN_PREFS_TBAR_L|Show toolbar:
WIN_PREFS_RESTART_L|<html><i>Niektoré nastavenia sa aktivujú až po reštartovaní programu.</i></html>
#SubBitmap Edit and Skin Preview window
......
......@@ -115,6 +115,7 @@ WIN_PREFS_TITLE|Inställningar
WIN_PREFS_UPDATE_L|Enable auto-update:
WIN_PREFS_LANG_L|Språk:
WIN_PREFS_LAF_L|Program look-and-feel:
WIN_PREFS_TBAR_L|Show toolbar:
WIN_PREFS_RESTART_L|<html><i>Some settings only take effect when the program is restarted.</i></html>
#SubBitmap Edit and Skin Preview window
......
......@@ -61,6 +61,7 @@ public class Config {
strings.put("win.items.width","190");
strings.put("win.items.height","200");
strings.put("swing.laf","System");
strings.put("toolbar","true");
//Locate the config file
if(System.getProperty("os.name").indexOf("Windows")!=-1) {
......@@ -181,6 +182,10 @@ public class Config {
final JComboBox laf_cb = new JComboBox(lafs);
laf_cb.setSelectedItem(Config.get("swing.laf"));
JLabel tbar_l = new JLabel(Language.get("WIN_PREFS_TBAR_L"));
final JCheckBox tbar_cb = new JCheckBox();
tbar_cb.setSelected(Boolean.parseBoolean(Config.get("toolbar")));
JLabel restart_l = new JLabel(Language.get("WIN_PREFS_RESTART_L"));
JButton ok_btn = new JButton(Language.get("BUTTON_OK"));
......@@ -190,6 +195,9 @@ public class Config {
strings.put("autoupdate", String.valueOf(update_cb.isSelected()));
strings.put("language", ((Language)lang_cb.getSelectedItem()).getCode());
strings.put("swing.laf", (String)laf_cb.getSelectedItem());
strings.put("toolbar", String.valueOf(update_cb.isSelected()));
frame.setVisible(false);
frame.dispose();
}
......@@ -210,6 +218,8 @@ public class Config {
frame.add(update_cb);
frame.add(laf_l);
frame.add(laf_cb);
frame.add(tbar_l);
frame.add(tbar_cb);
frame.add(restart_l);
frame.add(ok_btn);
frame.add(cancel_btn);
......@@ -241,7 +251,13 @@ public class Config {
layout.putConstraint(SpringLayout.WEST, laf_cb, tf_dx, SpringLayout.WEST, frame.getContentPane());
layout.putConstraint(SpringLayout.EAST, laf_cb, 0, SpringLayout.EAST, lang_cb);
layout.putConstraint(SpringLayout.NORTH, restart_l, 10, SpringLayout.SOUTH, laf_l);
layout.putConstraint(SpringLayout.NORTH, tbar_l, 10, SpringLayout.SOUTH, laf_l);
layout.putConstraint(SpringLayout.WEST, tbar_l, 5, SpringLayout.WEST, frame.getContentPane());
layout.putConstraint(SpringLayout.VERTICAL_CENTER, tbar_cb, 0, SpringLayout.VERTICAL_CENTER, tbar_l);
layout.putConstraint(SpringLayout.WEST, tbar_cb, tf_dx, SpringLayout.WEST, frame.getContentPane());
layout.putConstraint(SpringLayout.EAST, tbar_cb, 0, SpringLayout.EAST, lang_cb);
layout.putConstraint(SpringLayout.NORTH, restart_l, 10, SpringLayout.SOUTH, tbar_l);
layout.putConstraint(SpringLayout.WEST, restart_l, 5, SpringLayout.WEST, frame.getContentPane());
layout.putConstraint(SpringLayout.NORTH, ok_btn, 10, SpringLayout.SOUTH, restart_l);
......
......@@ -64,6 +64,9 @@ public class Main extends javax.swing.JFrame implements ActionListener, TreeSele
private JMenuItem m_edit_undo, m_edit_redo, m_edit_theme, m_edit_vars, m_edit_prefs, m_edit_up, m_edit_down, m_edit_right, m_edit_left;
private JMenuItem m_help_doc, m_help_about;
private JPanel tbar;
private JButton tbar_open_btn, tbar_save_btn, tbar_undo_btn, tbar_redo_btn;
private JDesktopPane jdesk;
private JInternalFrame resources,windows,items;
protected JTree res_tree,win_tree,items_tree;
......@@ -267,6 +270,49 @@ public class Main extends javax.swing.JFrame implements ActionListener, TreeSele
setJMenuBar(mbar);
//Toolbar
if(Boolean.parseBoolean(Config.get("toolbar"))) {
tbar = new JPanel();
//tbar.setLayout(new BoxLayout(tbar, BoxLayout.LINE_AXIS));
tbar_open_btn = new ToolbarButton(Toolkit.getDefaultToolkit().createImage(Main.class.getResource("icons/tbar_open.png")));
tbar_open_btn.setToolTipText(Language.get("TOOLBAR_OPEN"));
tbar_open_btn.addActionListener(this);
tbar.add(tbar_open_btn);
tbar_save_btn = new ToolbarButton(Toolkit.getDefaultToolkit().createImage(Main.class.getResource("icons/tbar_save.png")));
tbar_save_btn.setToolTipText(Language.get("TOOLBAR_SAVE"));
tbar_save_btn.addActionListener(this);
tbar.add(tbar_save_btn);
JToolBar.Separator tbar_sep_1 = new JToolBar.Separator(new Dimension(10,22));
tbar_sep_1.setOrientation(JSeparator.VERTICAL);
tbar.add(tbar_sep_1);
tbar_undo_btn = new ToolbarButton(Toolkit.getDefaultToolkit().createImage(Main.class.getResource("icons/tbar_undo.png")));
tbar_undo_btn.setToolTipText(Language.get("TOOLBAR_UNDO"));
tbar_undo_btn.addActionListener(this);
tbar.add(tbar_undo_btn);
tbar_redo_btn = new ToolbarButton(Toolkit.getDefaultToolkit().createImage(Main.class.getResource("icons/tbar_redo.png")));
tbar_redo_btn.setToolTipText(Language.get("TOOLBAR_REDO"));
tbar_redo_btn.addActionListener(this);
tbar.add(tbar_redo_btn);
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.setLayout(tbar_layout);
tbar.setPreferredSize(new Dimension(tbar.getPreferredSize().width,26));
tbar.setMaximumSize(new Dimension(tbar.getMaximumSize().width,26));
add(tbar);
}
//Resources, window and item windows
jdesk = new JDesktopPane();
s = new Skin(this);
......@@ -588,9 +634,23 @@ public class Main extends javax.swing.JFrame implements ActionListener, TreeSele
items_add_pu.add(items_add_pu_video);
jdesk.add(items_add_pu);
jdesk.setMinimumSize(new Dimension(800,600));
add(jdesk);
//Main window layout
if(Boolean.parseBoolean(Config.get("toolbar"))) {
SpringLayout layout = new SpringLayout();
layout.putConstraint(SpringLayout.NORTH, tbar, 0, SpringLayout.NORTH, getContentPane());
layout.putConstraint(SpringLayout.WEST, tbar, 0, SpringLayout.WEST, getContentPane());
layout.putConstraint(SpringLayout.EAST, tbar, 0, SpringLayout.EAST, getContentPane());
layout.putConstraint(SpringLayout.NORTH, jdesk, 0, SpringLayout.SOUTH, tbar);
layout.putConstraint(SpringLayout.WEST, jdesk, 0, SpringLayout.WEST, getContentPane());
layout.putConstraint(SpringLayout.EAST, getContentPane(), 0, SpringLayout.EAST, jdesk);
layout.putConstraint(SpringLayout.SOUTH, getContentPane(), 0, SpringLayout.SOUTH, jdesk);
setLayout(layout);
}
setMinimumSize(new Dimension(800,600));
setSize(Config.getInt("win.main.width"),Config.getInt("win.main.height"));
if(Config.get("win.main.x")==null) setLocationRelativeTo(null);
else {
......
/*****************************************************************************
* ToolbarButton.java
*****************************************************************************
* Copyright (C) 2009 Daniel Dreibrodt
*
* This file is part of VLC Skin Editor
*
* 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;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JButton;
/**
* A toolbar image button, with hover effects
* @author Daniel Dreibrodt
*/
public class ToolbarButton extends JButton implements MouseListener {
ImageIcon normal, over, down;
boolean hover = false;
boolean mac = System.getProperty("os.name").indexOf("Mac")!=-1;
public ToolbarButton(Image img) {
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++) {
Graphics g = ovbi.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(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++) {
Graphics g = dobi.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.92));
g.fillRect(x, y, 1, 1);
}
}
down = new ImageIcon(dobi);
}
setIcon(normal);
setBorderPainted(false);
setContentAreaFilled(false);
setFocusPainted(false);
addMouseListener(this);
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;
setIcon(down);
repaint();
}
public void mouseReleased(MouseEvent e) {
if(mac) return;
if(hover) setIcon(over);
else setIcon(normal);
repaint();
}
public void mouseEntered(MouseEvent e) {
if(mac) return;
hover = true;
setIcon(over);
repaint();
}
public void mouseExited(MouseEvent e) {
if(mac) return;
hover = false;
setIcon(normal);
repaint();
}
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);
}
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());
}
}
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