import gdxstudio.panel.ConsolePanel;
import gdxstudio.panel.OptionsPanel;
import gdxstudio.panel.ProjectPanel;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FileDialog;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.lang.ProcessBuilder.Redirect;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.SwingConstants;
import com.badlogic.gdx.tools.imagepacker.TexturePacker2;
import com.badlogic.gdx.tools.imagepacker.TexturePacker2.Settings;
import web.laf.lite.layout.HorizontalFlowLayout;
import web.laf.lite.layout.ToolbarLayout;
import web.laf.lite.layout.VerticalFlowLayout;
import web.laf.lite.popup.ButtonPopup;
import web.laf.lite.popup.PopupWay;
import web.laf.lite.utils.UIUtils;
import web.laf.lite.widget.WebButtonGroup;
final public class ToolBar extends JPanel {
private static final long serialVersionUID = 1L;
OptionsPanel optionsPanel;
super(new ToolbarLayout());
add(Style.createToolPanel("Build", "esource", new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
add(Style.createToolPanel("Compile", "esource", new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
add(Style.createToolPanel("Run", "go", new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
add(Style.createToolPanel("Stop", "stop", new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
Style.btnMap.get("stop").setEnabled(false);
setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Style.border));
public void paintComponent(Graphics g){
Style.drawHorizontalBar(g, getWidth (), getHeight ());
searchBar = new SearchBar();
final JPanel pan = new JPanel(new VerticalFlowLayout(FlowLayout.CENTER));
add(Style.createToolPanel("", "sabout", new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
JDialog dialog = new JDialog(Frame.getInstance(), "About", false);
dialog.setResizable(false);
dialog.getContentPane().setLayout(new BorderLayout());
final JPanel popupContent = new JPanel (new VerticalFlowLayout(5, 10));
final JButton licenseBtn = new JButton("Apache License v2.0");
final JPanel author = new JPanel(new HorizontalFlowLayout());
final JPanel hoz = new JPanel(new HorizontalFlowLayout());
popupContent.add(UIUtils.setBoldFont(new JLabel("GdxStudio v"+GdxStudio.version)));
popupContent.add(new JSeparator(SwingConstants.HORIZONTAL));
author.add(new JLabel("Created by: pyros2097"));
popupContent.add(author);
popupContent.add(new JSeparator(SwingConstants.HORIZONTAL));
popupContent.add(new JLabel("", Icon.icon("slibGDX"), JLabel.LEADING));
popupContent.add(new JLabel("", Icon.icon("sweblaf"), JLabel.LEADING));
hoz.add(new JLabel("", Icon.icon("shierologo"), JLabel.LEADING));
hoz.add(new JLabel("", Icon.icon("stexturepacker"), JLabel.LEADING));
UIUtils.setUndecorated(popupContent, false);
UIUtils.setMargin(popupContent, new Insets(0,0,0,0));
UIUtils.setDrawSides(popupContent, false, false, false, false);
dialog.getContentPane().add(popupContent);
dialog.setSize(525, 500);
Dimension Size = Toolkit.getDefaultToolkit().getScreenSize();
dialog.setLocation(new Double((Size.getWidth()/2) - (dialog.getWidth()/2)).intValue(),
new Double((Size.getHeight()/2) - (dialog.getHeight()/2)).intValue());
final JButton menuBtn1 = Style.createMenuButton("File");
final ButtonPopup menu = new ButtonPopup(menuBtn1,PopupWay.downRight);
JPanel popupContent = new JPanel ( new VerticalFlowLayout ( 5, 5 ) );
popupContent.setPreferredSize(new Dimension(200, 200));
popupContent.add(UIUtils.setBoldFont(new JLabel(" ToolBar")));
popupContent.add(new JSeparator(SwingConstants.HORIZONTAL));
popupContent.add(UIUtils.setBoldFont(new JLabel(" Explorer")));
popupContent.add(new JSeparator(SwingConstants.HORIZONTAL));
popupContent.setOpaque(false);
menu.setContent(popupContent);
final JButton menuBtn2 = Style.createMenuButton("Edit");
final ButtonPopup menu2 = new ButtonPopup(menuBtn2,PopupWay.downRight);
JPanel popupContent2 = new JPanel ( new VerticalFlowLayout ( 5, 5 ) );
popupContent2.setPreferredSize(new Dimension(200, 200));
popupContent2.add(UIUtils.setBoldFont(new JLabel(" ToolBar")));
popupContent2.add(new JSeparator(SwingConstants.HORIZONTAL));
popupContent2.add(UIUtils.setBoldFont(new JLabel(" Explorer")));
popupContent2.add(new JSeparator(SwingConstants.HORIZONTAL));
popupContent2.setOpaque(false);
menu2.setContent(popupContent2);
if(!Style.btnMap.get("stop").isEnabled()){
Style.btnMap.get("stop").setEnabled(true);
Style.btnMap.get("go").setEnabled(false);
if(!new File(Content.getProject()+new File(Content.getProject()).getName()+".jar").exists())
pb = new ProcessBuilder("java", "-jar", Content.getProject()+new File(Content.getProject()).getName()+".jar");
pb.redirectOutput(Redirect.INHERIT);
pb.redirectError(Redirect.INHERIT);
pb.redirectInput(Redirect.INHERIT);
runningProcess = pb.start();
} catch (IOException e) {
if(!Style.btnMap.get("go").isEnabled()){
Style.btnMap.get("stop").setEnabled(false);
Style.btnMap.get("go").setEnabled(true);
if(runningProcess != null)
runningProcess.destroy();
JButton prj = Style.createMenuButton("Project");
prj.setIcon(Icon.icon("newprj"));
prj.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
FileDialog fd = new FileDialog((Frame)null, "New GdxStudio Project", FileDialog.SAVE);
String filename = fd.getDirectory()+fd.getFile();
if(filename != null && !filename.isEmpty())
if(new File(filename).exists())
Export.createProject(fd.getDirectory());
JButton open = Style.createMenuButton("Open");
open.setIcon(Icon.icon("eopen"));
open.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
FileDialog fd = new FileDialog((Frame)null, "Open GdxStudio Project", FileDialog.LOAD);
String filename = fd.getDirectory()+fd.getFile();
if(!filename.isEmpty() && filename.contains("config"))
if(new File(filename).exists())
Export.openProject(fd.getDirectory());
JButton packButton = Style.createMenuButton("Pack");
packButton.setIcon(Icon.icon("epackage"));
packButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
Settings settings = new Settings();
settings.maxWidth = 2048;
settings.maxHeight = 2048;
TexturePacker2.process(settings, Content.getProject()+File.separator+"pack",
Content.getProject()+"atlas/", "pack.atlas");
for(File f: new File(Content.getProject()+File.separator+"pack").listFiles()){
TexturePacker2.process(settings, f.getPath(), Content.getProject()+"atlas/", f.getName());
JOptionPane.showMessageDialog(null, "Packed Texture: "+f.getName(), "Texture Packer",
JOptionPane.INFORMATION_MESSAGE);
JButton export = Style.createMenuButton("Export");
export.setIcon(Icon.icon("export"));
export.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if(ProjectPanel.targetComboBox.getSelectedIndex() == 0)
optionsPanel = new OptionsPanel();
add(Style.createToolPanel("Options", "options", new ActionListener(){
public void actionPerformed(ActionEvent e) {
JDialog dialog = new JDialog(Frame.getInstance(), "Options", false);
dialog.setResizable(false);
dialog.getContentPane().setLayout(new BorderLayout());
dialog.getContentPane().add(optionsPanel);
dialog.setSize(525, 525);
Dimension Size = Toolkit.getDefaultToolkit().getScreenSize();
dialog.setLocation(new Double((Size.getWidth()/2) - (dialog.getWidth()/2)).intValue(),
new Double((Size.getHeight()/2) - (dialog.getHeight()/2)).intValue());
Style.viewButton("Editor", "editor");
Style.viewButton("Studio", "studio");
Style.viewButton("Hiero", "shiero");
Style.viewButton("Particle", "sparticle");
WebButtonGroup textGroup = new WebButtonGroup(true, Style.viewGroup.get(0), Style.viewGroup.get(1),
Style.viewGroup.get(2), Style.viewGroup.get(3));
textGroup.setButtonsDrawFocus(false);
UIUtils.setUndecorated(textGroup, true);
UIUtils.setShadeWidth(textGroup, 0);
UIUtils.setMargin(textGroup, new Insets(0, 0, -1, 0));
UIUtils.setRound(textGroup, 0);
UIUtils.setDrawSides(textGroup, false, false, false, false);
add(new JLabel(" "), ToolbarLayout.START);
public void addSeparator(){
add(new JSeparator(SwingConstants.VERTICAL), ToolbarLayout.START);