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/SpawnPanel.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 | import java.awt.Dimension; |
| a62d533 | 20 | import java.awt.GridBagConstraints; |
| a62d533 | 21 | import java.awt.Insets; |
| a62d533 | 22 | import java.awt.event.ActionEvent; |
| a62d533 | 23 | import java.awt.event.ActionListener; |
| a62d533 | 24 | |
| a62d533 | 25 | import javax.swing.DefaultComboBoxModel; |
| a62d533 | 26 | import javax.swing.JCheckBox; |
| a62d533 | 27 | import javax.swing.JComboBox; |
| a62d533 | 28 | import javax.swing.JLabel; |
| a62d533 | 29 | import javax.swing.JPanel; |
| a62d533 | 30 | |
| a62d533 | 31 | import com.badlogic.gdx.graphics.g2d.ParticleEmitter.SpawnEllipseSide; |
| a62d533 | 32 | import com.badlogic.gdx.graphics.g2d.ParticleEmitter.SpawnShape; |
| a62d533 | 33 | import com.badlogic.gdx.graphics.g2d.ParticleEmitter.SpawnShapeValue; |
| a62d533 | 34 | |
| a62d533 | 35 | class SpawnPanel extends EditorPanel {
|
| a62d533 | 36 | JComboBox shapeCombo; |
| a62d533 | 37 | JCheckBox edgesCheckbox; |
| a62d533 | 38 | JLabel edgesLabel; |
| a62d533 | 39 | JComboBox sideCombo; |
| a62d533 | 40 | JLabel sideLabel; |
| a62d533 | 41 | |
| a62d533 | 42 | public SpawnPanel (final ParticlePanel editor, final SpawnShapeValue spawnShapeValue, String name, String description) {
|
| a62d533 | 43 | super(null, name, description); |
| a62d533 | 44 | |
| a62d533 | 45 | initializeComponents(); |
| a62d533 | 46 | |
| a62d533 | 47 | edgesCheckbox.setSelected(spawnShapeValue.isEdges()); |
| a62d533 | 48 | sideCombo.setSelectedItem(spawnShapeValue.getShape()); |
| a62d533 | 49 | |
| a62d533 | 50 | shapeCombo.addActionListener(new ActionListener() {
|
| a62d533 | 51 | public void actionPerformed (ActionEvent event) {
|
| a62d533 | 52 | SpawnShape shape = (SpawnShape)shapeCombo.getSelectedItem(); |
| a62d533 | 53 | spawnShapeValue.setShape(shape); |
| a62d533 | 54 | switch (shape) {
|
| a62d533 | 55 | case line: |
| a62d533 | 56 | case square: |
| a62d533 | 57 | setEdgesVisible(false); |
| a62d533 | 58 | editor.setVisible("Spawn Width", true);
|
| a62d533 | 59 | editor.setVisible("Spawn Height", true);
|
| a62d533 | 60 | break; |
| a62d533 | 61 | case ellipse: |
| a62d533 | 62 | setEdgesVisible(true); |
| a62d533 | 63 | editor.setVisible("Spawn Width", true);
|
| a62d533 | 64 | editor.setVisible("Spawn Height", true);
|
| a62d533 | 65 | break; |
| a62d533 | 66 | case point: |
| a62d533 | 67 | setEdgesVisible(false); |
| a62d533 | 68 | editor.setVisible("Spawn Width", false);
|
| a62d533 | 69 | editor.setVisible("Spawn Height", false);
|
| a62d533 | 70 | break; |
| a62d533 | 71 | } |
| a62d533 | 72 | } |
| a62d533 | 73 | }); |
| a62d533 | 74 | |
| a62d533 | 75 | edgesCheckbox.addActionListener(new ActionListener() {
|
| a62d533 | 76 | public void actionPerformed (ActionEvent event) {
|
| a62d533 | 77 | spawnShapeValue.setEdges(edgesCheckbox.isSelected()); |
| a62d533 | 78 | setEdgesVisible(true); |
| a62d533 | 79 | } |
| a62d533 | 80 | }); |
| a62d533 | 81 | |
| a62d533 | 82 | sideCombo.addActionListener(new ActionListener() {
|
| a62d533 | 83 | public void actionPerformed (ActionEvent event) {
|
| a62d533 | 84 | SpawnEllipseSide side = (SpawnEllipseSide)sideCombo.getSelectedItem(); |
| a62d533 | 85 | spawnShapeValue.setSide(side); |
| a62d533 | 86 | } |
| a62d533 | 87 | }); |
| a62d533 | 88 | |
| a62d533 | 89 | shapeCombo.setSelectedItem(spawnShapeValue.getShape()); |
| a62d533 | 90 | } |
| a62d533 | 91 | |
| a62d533 | 92 | public void update (ParticlePanel editor) {
|
| a62d533 | 93 | shapeCombo.setSelectedItem(editor.getEmitter().getSpawnShape().getShape()); |
| a62d533 | 94 | } |
| a62d533 | 95 | |
| a62d533 | 96 | void setEdgesVisible (boolean visible) {
|
| a62d533 | 97 | edgesCheckbox.setVisible(visible); |
| a62d533 | 98 | edgesLabel.setVisible(visible); |
| a62d533 | 99 | visible = visible && edgesCheckbox.isSelected(); |
| a62d533 | 100 | sideCombo.setVisible(visible); |
| a62d533 | 101 | sideLabel.setVisible(visible); |
| a62d533 | 102 | } |
| a62d533 | 103 | |
| a62d533 | 104 | private void initializeComponents () {
|
| a62d533 | 105 | JPanel contentPanel = getContentPanel(); |
| a62d533 | 106 | {
|
| a62d533 | 107 | JLabel label = new JLabel("Shape:");
|
| a62d533 | 108 | contentPanel.add(label, new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, |
| a62d533 | 109 | new Insets(0, 0, 0, 6), 0, 0)); |
| a62d533 | 110 | } |
| a62d533 | 111 | {
|
| a62d533 | 112 | shapeCombo = new JComboBox(); |
| a62d533 | 113 | shapeCombo.setModel(new DefaultComboBoxModel(SpawnShape.values())); |
| a62d533 | 114 | contentPanel.add(shapeCombo, new GridBagConstraints(1, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, |
| a62d533 | 115 | new Insets(0, 0, 0, 0), 0, 0)); |
| a62d533 | 116 | } |
| a62d533 | 117 | {
|
| a62d533 | 118 | edgesLabel = new JLabel("Edges:");
|
| a62d533 | 119 | contentPanel.add(edgesLabel, new GridBagConstraints(2, 1, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, |
| a62d533 | 120 | new Insets(0, 12, 0, 6), 0, 0)); |
| a62d533 | 121 | } |
| a62d533 | 122 | {
|
| a62d533 | 123 | edgesCheckbox = new JCheckBox(); |
| a62d533 | 124 | contentPanel.add(edgesCheckbox, new GridBagConstraints(3, 1, 1, 1, 0, 0, GridBagConstraints.WEST, |
| a62d533 | 125 | GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); |
| a62d533 | 126 | } |
| a62d533 | 127 | {
|
| a62d533 | 128 | sideLabel = new JLabel("Side:");
|
| a62d533 | 129 | contentPanel.add(sideLabel, new GridBagConstraints(4, 1, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, |
| a62d533 | 130 | new Insets(0, 12, 0, 6), 0, 0)); |
| a62d533 | 131 | } |
| a62d533 | 132 | {
|
| a62d533 | 133 | sideCombo = new JComboBox(); |
| a62d533 | 134 | sideCombo.setModel(new DefaultComboBoxModel(SpawnEllipseSide.values())); |
| a62d533 | 135 | contentPanel.add(sideCombo, new GridBagConstraints(5, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, |
| a62d533 | 136 | new Insets(0, 0, 0, 0), 0, 0)); |
| a62d533 | 137 | } |
| a62d533 | 138 | {
|
| a62d533 | 139 | JPanel spacer = new JPanel(); |
| a62d533 | 140 | spacer.setPreferredSize(new Dimension()); |
| a62d533 | 141 | contentPanel.add(spacer, new GridBagConstraints(6, 0, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, |
| a62d533 | 142 | new Insets(0, 0, 0, 0), 0, 0)); |
| a62d533 | 143 | } |
| a62d533 | 144 | } |
| a62d533 | 145 | } |