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_libs/com/badlogic/gdx/tools/particleeditor/ImagePanel.java
| a62d533 | 1 | /******************************************************************************* |
| a62d533 | 2 | * Copyright 2011 See AUTHORS file. |
| a62d533 | 3 | * |
| a62d533 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| a62d533 | 5 | * you may not use this file except in compliance with the License. |
| a62d533 | 6 | * You may obtain a copy of the License at |
| a62d533 | 7 | * |
| a62d533 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| a62d533 | 9 | * |
| a62d533 | 10 | * Unless required by applicable law or agreed to in writing, software |
| a62d533 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| a62d533 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| a62d533 | 13 | * See the License for the specific language governing permissions and |
| a62d533 | 14 | * limitations under the License. |
| a62d533 | 15 | ******************************************************************************/ |
| a62d533 | 16 | |
| a62d533 | 17 | package com.badlogic.gdx.tools.particleeditor; |
| a62d533 | 18 | |
| a62d533 | 19 | |
| a62d533 | 20 | import java.awt.FileDialog; |
| a62d533 | 21 | import java.awt.Frame; |
| a62d533 | 22 | import java.awt.GridBagConstraints; |
| a62d533 | 23 | import java.awt.Insets; |
| a62d533 | 24 | import java.awt.event.ActionEvent; |
| a62d533 | 25 | import java.awt.event.ActionListener; |
| a62d533 | 26 | import java.io.File; |
| a62d533 | 27 | |
| a62d533 | 28 | import javax.swing.ImageIcon; |
| a62d533 | 29 | import javax.swing.JButton; |
| a62d533 | 30 | import javax.swing.JLabel; |
| a62d533 | 31 | import javax.swing.JPanel; |
| a62d533 | 32 | |
| a62d533 | 33 | import com.badlogic.gdx.graphics.g2d.ParticleEmitter; |
| a62d533 | 34 | |
| a62d533 | 35 | class ImagePanel extends EditorPanel {
|
| a62d533 | 36 | JLabel imageLabel; |
| a62d533 | 37 | JLabel widthLabel; |
| a62d533 | 38 | JLabel heightLabel; |
| a62d533 | 39 | String lastDir; |
| a62d533 | 40 | |
| a62d533 | 41 | public ImagePanel (final ParticlePanel editor, String name, String description) {
|
| a62d533 | 42 | super(null, name, description); |
| a62d533 | 43 | JPanel contentPanel = getContentPanel(); |
| a62d533 | 44 | {
|
| a62d533 | 45 | JButton openButton = new JButton("Open");
|
| a62d533 | 46 | contentPanel.add(openButton, new GridBagConstraints(2, 1, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, |
| a62d533 | 47 | GridBagConstraints.NONE, new Insets(0, 0, 6, 6), 0, 0)); |
| a62d533 | 48 | openButton.addActionListener(new ActionListener() {
|
| a62d533 | 49 | public void actionPerformed (ActionEvent event) {
|
| a62d533 | 50 | FileDialog dialog = new FileDialog((Frame)null, "Open Image", FileDialog.LOAD); |
| a62d533 | 51 | if (lastDir != null) dialog.setDirectory(lastDir); |
| a62d533 | 52 | dialog.setVisible(true); |
| a62d533 | 53 | final String file = dialog.getFile(); |
| a62d533 | 54 | final String dir = dialog.getDirectory(); |
| a62d533 | 55 | if (dir == null || file == null || file.trim().length() == 0) return; |
| a62d533 | 56 | lastDir = dir; |
| a62d533 | 57 | try {
|
| a62d533 | 58 | ImageIcon icon = new ImageIcon(new File(dir, file).toURI().toURL()); |
| a62d533 | 59 | final ParticleEmitter emitter = editor.getEmitter(); |
| a62d533 | 60 | editor.setIcon(emitter, icon); |
| a62d533 | 61 | imageLabel.setIcon(icon); |
| a62d533 | 62 | widthLabel.setText("Width: " + icon.getIconWidth());
|
| a62d533 | 63 | heightLabel.setText("Height: " + icon.getIconHeight());
|
| a62d533 | 64 | revalidate(); |
| a62d533 | 65 | emitter.setImagePath(new File(dir, file).getAbsolutePath()); |
| a62d533 | 66 | emitter.setSprite(null); |
| a62d533 | 67 | } catch (Exception ex) {
|
| a62d533 | 68 | ex.printStackTrace(); |
| a62d533 | 69 | } |
| a62d533 | 70 | } |
| a62d533 | 71 | }); |
| a62d533 | 72 | } |
| a62d533 | 73 | {
|
| a62d533 | 74 | widthLabel = new JLabel(); |
| a62d533 | 75 | contentPanel.add(widthLabel, new GridBagConstraints(2, 2, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, |
| a62d533 | 76 | GridBagConstraints.NONE, new Insets(0, 0, 6, 6), 0, 0)); |
| a62d533 | 77 | } |
| a62d533 | 78 | {
|
| a62d533 | 79 | heightLabel = new JLabel(); |
| a62d533 | 80 | contentPanel.add(heightLabel, new GridBagConstraints(2, 3, 1, 1, 0, 1, GridBagConstraints.NORTHWEST, |
| a62d533 | 81 | GridBagConstraints.NONE, new Insets(0, 0, 0, 6), 0, 0)); |
| a62d533 | 82 | } |
| a62d533 | 83 | {
|
| a62d533 | 84 | imageLabel = new JLabel(); |
| a62d533 | 85 | contentPanel.add(imageLabel, new GridBagConstraints(3, 1, 1, 3, 1, 0, GridBagConstraints.NORTHWEST, |
| a62d533 | 86 | GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0)); |
| a62d533 | 87 | } |
| a62d533 | 88 | ImageIcon icon = editor.getIcon(editor.getEmitter()); |
| a62d533 | 89 | if (icon != null) {
|
| a62d533 | 90 | imageLabel.setIcon(icon); |
| a62d533 | 91 | widthLabel.setText("Width: " + icon.getIconWidth());
|
| a62d533 | 92 | heightLabel.setText("Height: " + icon.getIconHeight());
|
| a62d533 | 93 | } |
| a62d533 | 94 | } |
| a62d533 | 95 | } |