gdx-studio
git clone https://git.pyrossh.dev/gdx-studio
An IDE for creating Games using libgdx and Java supported on all platforms Android, iOS, Desktop
src/gdxstudio/ToolBar.java
| a9b2a64 | 1 | package gdxstudio; |
| a9b2a64 | 2 | import gdxstudio.panel.ConsolePanel; |
| a9b2a64 | 3 | import gdxstudio.panel.OptionsPanel; |
| a9b2a64 | 4 | import gdxstudio.panel.ProjectPanel; |
| a9b2a64 | 5 | |
| 7c84877 | 6 | import java.awt.BorderLayout; |
| a62d533 | 7 | import java.awt.Dimension; |
| a62d533 | 8 | import java.awt.FileDialog; |
| a62d533 | 9 | import java.awt.FlowLayout; |
| a62d533 | 10 | import java.awt.Graphics; |
| a62d533 | 11 | import java.awt.Insets; |
| 7c84877 | 12 | import java.awt.Toolkit; |
| a62d533 | 13 | import java.awt.event.ActionEvent; |
| a62d533 | 14 | import java.awt.event.ActionListener; |
| a62d533 | 15 | import java.io.File; |
| a62d533 | 16 | import java.io.IOException; |
| a62d533 | 17 | import java.lang.ProcessBuilder.Redirect; |
| a62d533 | 18 | |
| 7c84877 | 19 | import javax.swing.BorderFactory; |
| a62d533 | 20 | import javax.swing.JButton; |
| 7c84877 | 21 | import javax.swing.JDialog; |
| a62d533 | 22 | import javax.swing.JLabel; |
| a9b2a64 | 23 | import javax.swing.JOptionPane; |
| a62d533 | 24 | import javax.swing.JPanel; |
| a62d533 | 25 | import javax.swing.JSeparator; |
| a62d533 | 26 | import javax.swing.SwingConstants; |
| a62d533 | 27 | |
| a9b2a64 | 28 | import com.badlogic.gdx.tools.imagepacker.TexturePacker2; |
| a9b2a64 | 29 | import com.badlogic.gdx.tools.imagepacker.TexturePacker2.Settings; |
| a9b2a64 | 30 | |
| a62d533 | 31 | import web.laf.lite.layout.HorizontalFlowLayout; |
| a62d533 | 32 | import web.laf.lite.layout.ToolbarLayout; |
| a62d533 | 33 | import web.laf.lite.layout.VerticalFlowLayout; |
| a62d533 | 34 | import web.laf.lite.popup.ButtonPopup; |
| a62d533 | 35 | import web.laf.lite.popup.PopupWay; |
| a62d533 | 36 | import web.laf.lite.utils.UIUtils; |
| a62d533 | 37 | import web.laf.lite.widget.WebButtonGroup; |
| a62d533 | 38 | |
| a62d533 | 39 | final public class ToolBar extends JPanel {
|
| a62d533 | 40 | private static final long serialVersionUID = 1L; |
| a62d533 | 41 | SearchBar searchBar; |
| a62d533 | 42 | ProcessBuilder pb; |
| a62d533 | 43 | Process runningProcess; |
| 7c84877 | 44 | OptionsPanel optionsPanel; |
| a62d533 | 45 | |
| a62d533 | 46 | public ToolBar(){
|
| a62d533 | 47 | super(new ToolbarLayout()); |
| a62d533 | 48 | initAbout(); |
| a62d533 | 49 | initProject(); |
| a62d533 | 50 | initOpen(); |
| a9b2a64 | 51 | initPack(); |
| a62d533 | 52 | initExport(); |
| a62d533 | 53 | addSeparator(); |
| a62d533 | 54 | initOptions(); |
| a62d533 | 55 | addSeparator(); |
| a9b2a64 | 56 | add(Style.createToolPanel("Build", "esource", new ActionListener(){
|
| a9b2a64 | 57 | @Override |
| a9b2a64 | 58 | public void actionPerformed(ActionEvent arg0) {
|
| a9b2a64 | 59 | ConsolePanel.build(); |
| a9b2a64 | 60 | } |
| a9b2a64 | 61 | })); |
| a9b2a64 | 62 | add(Style.createToolPanel("Compile", "esource", new ActionListener(){
|
| a9b2a64 | 63 | @Override |
| a9b2a64 | 64 | public void actionPerformed(ActionEvent arg0) {
|
| a9b2a64 | 65 | Content.editor.save(); |
| a9b2a64 | 66 | } |
| a9b2a64 | 67 | })); |
| a62d533 | 68 | add(Style.createToolPanel("Run", "go", new ActionListener(){
|
| a62d533 | 69 | @Override |
| a62d533 | 70 | public void actionPerformed(ActionEvent arg0) {
|
| a62d533 | 71 | run(); |
| a62d533 | 72 | } |
| a62d533 | 73 | })); |
| a62d533 | 74 | add(Style.createToolPanel("Stop", "stop", new ActionListener(){
|
| a62d533 | 75 | @Override |
| a62d533 | 76 | public void actionPerformed(ActionEvent arg0) {
|
| a62d533 | 77 | stop(); |
| a62d533 | 78 | } |
| a62d533 | 79 | })); |
| a62d533 | 80 | Style.btnMap.get("stop").setEnabled(false);
|
| a62d533 | 81 | addSeparator(); |
| a62d533 | 82 | addSpace(); |
| a62d533 | 83 | addSpace(); |
| a62d533 | 84 | initSearch(); |
| a62d533 | 85 | addSpace(); |
| a62d533 | 86 | addSpace(); |
| a62d533 | 87 | addSeparator(); |
| a62d533 | 88 | initView(); |
| 7c84877 | 89 | setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Style.border)); |
| a62d533 | 90 | } |
| a62d533 | 91 | |
| a62d533 | 92 | @Override |
| a62d533 | 93 | public void paintComponent(Graphics g){
|
| a62d533 | 94 | Style.drawHorizontalBar(g, getWidth (), getHeight ()); |
| a62d533 | 95 | } |
| a62d533 | 96 | |
| a62d533 | 97 | void initSearch(){
|
| a62d533 | 98 | searchBar = new SearchBar(); |
| a62d533 | 99 | final JPanel pan = new JPanel(new VerticalFlowLayout(FlowLayout.CENTER)); |
| a62d533 | 100 | pan.setOpaque(false); |
| a62d533 | 101 | pan.add(searchBar); |
| a62d533 | 102 | add(pan); |
| a62d533 | 103 | } |
| a62d533 | 104 | |
| a62d533 | 105 | void initAbout(){
|
| 7c84877 | 106 | add(Style.createToolPanel("", "sabout", new ActionListener(){
|
| 7c84877 | 107 | @Override |
| 7c84877 | 108 | public void actionPerformed(ActionEvent arg0) {
|
| 7c84877 | 109 | JDialog dialog = new JDialog(Frame.getInstance(), "About", false); |
| 7c84877 | 110 | dialog.setResizable(false); |
| 7c84877 | 111 | dialog.getContentPane().setLayout(new BorderLayout()); |
| 7c84877 | 112 | final JPanel popupContent = new JPanel (new VerticalFlowLayout(5, 10)); |
| 7c84877 | 113 | final JButton licenseBtn = new JButton("Apache License v2.0");
|
| 7c84877 | 114 | final JPanel author = new JPanel(new HorizontalFlowLayout()); |
| 7c84877 | 115 | final JPanel hoz = new JPanel(new HorizontalFlowLayout()); |
| a9b2a64 | 116 | popupContent.add(UIUtils.setBoldFont(new JLabel("GdxStudio v"+GdxStudio.version)));
|
| 7c84877 | 117 | popupContent.add(new JSeparator(SwingConstants.HORIZONTAL)); |
| 7c84877 | 118 | author.setOpaque(false); |
| 7c84877 | 119 | author.add(new JLabel("Created by: pyros2097"));
|
| 7c84877 | 120 | author.add(licenseBtn); |
| 7c84877 | 121 | popupContent.add(author); |
| 7c84877 | 122 | popupContent.add(new JSeparator(SwingConstants.HORIZONTAL)); |
| 7c84877 | 123 | popupContent.add(new JLabel("", Icon.icon("slibGDX"), JLabel.LEADING));
|
| 7c84877 | 124 | popupContent.add(new JLabel("", Icon.icon("sweblaf"), JLabel.LEADING));
|
| 7c84877 | 125 | hoz.setOpaque(false); |
| 7c84877 | 126 | hoz.add(new JLabel("", Icon.icon("shierologo"), JLabel.LEADING));
|
| 7c84877 | 127 | hoz.add(new JLabel("", Icon.icon("stexturepacker"), JLabel.LEADING));
|
| 7c84877 | 128 | popupContent.add(hoz); |
| 7c84877 | 129 | UIUtils.setUndecorated(popupContent, false); |
| 7c84877 | 130 | UIUtils.setMargin(popupContent, new Insets(0,0,0,0)); |
| 7c84877 | 131 | UIUtils.setDrawSides(popupContent, false, false, false, false); |
| 7c84877 | 132 | dialog.getContentPane().add(popupContent); |
| 7c84877 | 133 | dialog.pack(); |
| 7c84877 | 134 | dialog.setSize(525, 500); |
| 7c84877 | 135 | Dimension Size = Toolkit.getDefaultToolkit().getScreenSize(); |
| 7c84877 | 136 | dialog.setLocation(new Double((Size.getWidth()/2) - (dialog.getWidth()/2)).intValue(), |
| 7c84877 | 137 | new Double((Size.getHeight()/2) - (dialog.getHeight()/2)).intValue()); |
| 7c84877 | 138 | dialog.setVisible(true); |
| 7c84877 | 139 | } |
| 7c84877 | 140 | })); |
| a62d533 | 141 | } |
| a62d533 | 142 | |
| a62d533 | 143 | void initFile(){
|
| a62d533 | 144 | final JButton menuBtn1 = Style.createMenuButton("File");
|
| a62d533 | 145 | final ButtonPopup menu = new ButtonPopup(menuBtn1,PopupWay.downRight); |
| a62d533 | 146 | menu.setRound(0); |
| a62d533 | 147 | JPanel popupContent = new JPanel ( new VerticalFlowLayout ( 5, 5 ) ); |
| a62d533 | 148 | popupContent.setPreferredSize(new Dimension(200, 200)); |
| a62d533 | 149 | popupContent.add(UIUtils.setBoldFont(new JLabel(" ToolBar")));
|
| a62d533 | 150 | popupContent.add(new JSeparator(SwingConstants.HORIZONTAL)); |
| a62d533 | 151 | popupContent.add(UIUtils.setBoldFont(new JLabel(" Explorer")));
|
| a62d533 | 152 | popupContent.add(new JSeparator(SwingConstants.HORIZONTAL)); |
| a62d533 | 153 | popupContent.setOpaque(false); |
| a62d533 | 154 | menu.setContent(popupContent); |
| a62d533 | 155 | add(menuBtn1); |
| a62d533 | 156 | } |
| a62d533 | 157 | |
| a62d533 | 158 | void initEdit(){
|
| a62d533 | 159 | final JButton menuBtn2 = Style.createMenuButton("Edit");
|
| a62d533 | 160 | final ButtonPopup menu2 = new ButtonPopup(menuBtn2,PopupWay.downRight); |
| a62d533 | 161 | menu2.setRound(0); |
| a62d533 | 162 | JPanel popupContent2 = new JPanel ( new VerticalFlowLayout ( 5, 5 ) ); |
| a62d533 | 163 | popupContent2.setPreferredSize(new Dimension(200, 200)); |
| a62d533 | 164 | popupContent2.add(UIUtils.setBoldFont(new JLabel(" ToolBar")));
|
| a62d533 | 165 | popupContent2.add(new JSeparator(SwingConstants.HORIZONTAL)); |
| a62d533 | 166 | popupContent2.add(UIUtils.setBoldFont(new JLabel(" Explorer")));
|
| a62d533 | 167 | popupContent2.add(new JSeparator(SwingConstants.HORIZONTAL)); |
| a62d533 | 168 | popupContent2.setOpaque(false); |
| a62d533 | 169 | menu2.setContent(popupContent2); |
| a62d533 | 170 | add(menuBtn2); |
| a62d533 | 171 | } |
| a62d533 | 172 | |
| a62d533 | 173 | void run(){
|
| a62d533 | 174 | if(!Style.btnMap.get("stop").isEnabled()){
|
| a62d533 | 175 | Style.btnMap.get("stop").setEnabled(true);
|
| a62d533 | 176 | Style.btnMap.get("go").setEnabled(false);
|
| a62d533 | 177 | } |
| a62d533 | 178 | if(!new File(Content.getProject()+new File(Content.getProject()).getName()+".jar").exists()) |
| a62d533 | 179 | Export.createJar(); |
| a62d533 | 180 | pb = new ProcessBuilder("java", "-jar", Content.getProject()+new File(Content.getProject()).getName()+".jar");
|
| a62d533 | 181 | pb.redirectOutput(Redirect.INHERIT); |
| a62d533 | 182 | pb.redirectError(Redirect.INHERIT); |
| a62d533 | 183 | pb.redirectInput(Redirect.INHERIT); |
| a62d533 | 184 | try {
|
| a62d533 | 185 | runningProcess = pb.start(); |
| a62d533 | 186 | } catch (IOException e) {
|
| a62d533 | 187 | e.printStackTrace(); |
| a62d533 | 188 | } |
| a62d533 | 189 | } |
| a62d533 | 190 | |
| a62d533 | 191 | void stop(){
|
| a62d533 | 192 | if(!Style.btnMap.get("go").isEnabled()){
|
| a62d533 | 193 | Style.btnMap.get("stop").setEnabled(false);
|
| a62d533 | 194 | Style.btnMap.get("go").setEnabled(true);
|
| a62d533 | 195 | } |
| a62d533 | 196 | if(runningProcess != null) |
| a62d533 | 197 | runningProcess.destroy(); |
| a62d533 | 198 | } |
| a62d533 | 199 | |
| a62d533 | 200 | void initProject(){
|
| a62d533 | 201 | JButton prj = Style.createMenuButton("Project");
|
| a62d533 | 202 | prj.setIcon(Icon.icon("newprj"));
|
| a62d533 | 203 | prj.addActionListener(new ActionListener(){
|
| a62d533 | 204 | @Override |
| a62d533 | 205 | public void actionPerformed(ActionEvent arg0) {
|
| a62d533 | 206 | FileDialog fd = new FileDialog((Frame)null, "New GdxStudio Project", FileDialog.SAVE); |
| a62d533 | 207 | fd.setVisible(true); |
| a62d533 | 208 | String filename = fd.getDirectory()+fd.getFile(); |
| a62d533 | 209 | if(filename != null && !filename.isEmpty()) |
| a62d533 | 210 | if(new File(filename).exists()) |
| a62d533 | 211 | Export.createProject(fd.getDirectory()); |
| a62d533 | 212 | } |
| a62d533 | 213 | }); |
| a62d533 | 214 | add(prj); |
| a62d533 | 215 | } |
| a62d533 | 216 | |
| a62d533 | 217 | void initOpen(){
|
| a62d533 | 218 | JButton open = Style.createMenuButton("Open");
|
| a62d533 | 219 | open.setIcon(Icon.icon("eopen"));
|
| a62d533 | 220 | open.addActionListener(new ActionListener(){
|
| a62d533 | 221 | @Override |
| a62d533 | 222 | public void actionPerformed(ActionEvent e) {
|
| a62d533 | 223 | FileDialog fd = new FileDialog((Frame)null, "Open GdxStudio Project", FileDialog.LOAD); |
| a62d533 | 224 | fd.setVisible(true); |
| a62d533 | 225 | String filename = fd.getDirectory()+fd.getFile(); |
| a62d533 | 226 | if(filename != null) |
| a62d533 | 227 | if(!filename.isEmpty() && filename.contains("config"))
|
| a62d533 | 228 | if(new File(filename).exists()) |
| a62d533 | 229 | Export.openProject(fd.getDirectory()); |
| a62d533 | 230 | } |
| a62d533 | 231 | }); |
| a62d533 | 232 | add(open); |
| a62d533 | 233 | } |
| a62d533 | 234 | |
| a9b2a64 | 235 | void initPack(){
|
| a9b2a64 | 236 | JButton packButton = Style.createMenuButton("Pack");
|
| a9b2a64 | 237 | packButton.setIcon(Icon.icon("epackage"));
|
| a9b2a64 | 238 | packButton.addActionListener(new ActionListener(){
|
| a9b2a64 | 239 | @Override |
| a9b2a64 | 240 | public void actionPerformed(ActionEvent arg0) {
|
| a9b2a64 | 241 | Settings settings = new Settings(); |
| a9b2a64 | 242 | settings.maxWidth = 2048; |
| a9b2a64 | 243 | settings.maxHeight = 2048; |
| a9b2a64 | 244 | settings.paddingX = 0; |
| a9b2a64 | 245 | settings.paddingY = 0; |
| a9b2a64 | 246 | TexturePacker2.process(settings, Content.getProject()+File.separator+"pack", |
| a9b2a64 | 247 | Content.getProject()+"atlas/", "pack.atlas"); |
| a9b2a64 | 248 | for(File f: new File(Content.getProject()+File.separator+"pack").listFiles()){
|
| a9b2a64 | 249 | if(f.isDirectory()){
|
| a9b2a64 | 250 | TexturePacker2.process(settings, f.getPath(), Content.getProject()+"atlas/", f.getName()); |
| a9b2a64 | 251 | JOptionPane.showMessageDialog(null, "Packed Texture: "+f.getName(), "Texture Packer", |
| a9b2a64 | 252 | JOptionPane.INFORMATION_MESSAGE); |
| a9b2a64 | 253 | } |
| a9b2a64 | 254 | } |
| a9b2a64 | 255 | } |
| a9b2a64 | 256 | }); |
| a9b2a64 | 257 | add(packButton); |
| a9b2a64 | 258 | } |
| a9b2a64 | 259 | |
| a62d533 | 260 | void initExport(){
|
| a62d533 | 261 | JButton export = Style.createMenuButton("Export");
|
| a62d533 | 262 | export.setIcon(Icon.icon("export"));
|
| a62d533 | 263 | export.addActionListener(new ActionListener(){
|
| a62d533 | 264 | @Override |
| a62d533 | 265 | public void actionPerformed(ActionEvent e) {
|
| a62d533 | 266 | if(ProjectPanel.targetComboBox.getSelectedIndex() == 0) |
| a62d533 | 267 | Export.createJar(); |
| a62d533 | 268 | else |
| a62d533 | 269 | Export.createDex(); |
| a62d533 | 270 | } |
| a62d533 | 271 | }); |
| a62d533 | 272 | add(export); |
| a62d533 | 273 | } |
| a62d533 | 274 | |
| a62d533 | 275 | void initOptions(){
|
| 7c84877 | 276 | optionsPanel = new OptionsPanel(); |
| a62d533 | 277 | add(Style.createToolPanel("Options", "options", new ActionListener(){
|
| a62d533 | 278 | @Override |
| a62d533 | 279 | public void actionPerformed(ActionEvent e) {
|
| 7c84877 | 280 | JDialog dialog = new JDialog(Frame.getInstance(), "Options", false); |
| 7c84877 | 281 | dialog.setResizable(false); |
| 7c84877 | 282 | dialog.getContentPane().setLayout(new BorderLayout()); |
| 7c84877 | 283 | dialog.getContentPane().add(optionsPanel); |
| 7c84877 | 284 | dialog.pack(); |
| a9b2a64 | 285 | dialog.setSize(525, 525); |
| 7c84877 | 286 | Dimension Size = Toolkit.getDefaultToolkit().getScreenSize(); |
| 7c84877 | 287 | dialog.setLocation(new Double((Size.getWidth()/2) - (dialog.getWidth()/2)).intValue(), |
| 7c84877 | 288 | new Double((Size.getHeight()/2) - (dialog.getHeight()/2)).intValue()); |
| 7c84877 | 289 | dialog.setVisible(true); |
| a62d533 | 290 | } |
| a62d533 | 291 | |
| a62d533 | 292 | })); |
| a62d533 | 293 | } |
| a62d533 | 294 | |
| a62d533 | 295 | void initView(){
|
| a62d533 | 296 | Style.viewButton("Editor", "editor");
|
| a62d533 | 297 | Style.viewButton("Studio", "studio");
|
| a62d533 | 298 | Style.viewButton("Hiero", "shiero");
|
| a62d533 | 299 | Style.viewButton("Particle", "sparticle");
|
| a9b2a64 | 300 | WebButtonGroup textGroup = new WebButtonGroup(true, Style.viewGroup.get(0), Style.viewGroup.get(1), |
| a9b2a64 | 301 | Style.viewGroup.get(2), Style.viewGroup.get(3)); |
| a62d533 | 302 | textGroup.setButtonsDrawFocus(false); |
| a62d533 | 303 | UIUtils.setUndecorated(textGroup, true); |
| a9b2a64 | 304 | UIUtils.setShadeWidth(textGroup, 0); |
| a9b2a64 | 305 | UIUtils.setMargin(textGroup, new Insets(0, 0, -1, 0)); |
| a62d533 | 306 | UIUtils.setRound(textGroup, 0); |
| a62d533 | 307 | UIUtils.setDrawSides(textGroup, false, false, false, false); |
| a9b2a64 | 308 | add(textGroup); |
| a62d533 | 309 | } |
| a62d533 | 310 | |
| a62d533 | 311 | public void addSpace(){
|
| a62d533 | 312 | add(new JLabel(" "), ToolbarLayout.START);
|
| a62d533 | 313 | } |
| a62d533 | 314 | |
| a62d533 | 315 | public void addSeparator(){
|
| a62d533 | 316 | add(new JSeparator(SwingConstants.VERTICAL), ToolbarLayout.START); |
| a62d533 | 317 | } |
| a62d533 | 318 | } |