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/EditorPanel.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.Cursor; |
| a62d533 | 20 | import java.awt.Font; |
| a62d533 | 21 | import java.awt.GridBagConstraints; |
| a62d533 | 22 | import java.awt.GridBagLayout; |
| a62d533 | 23 | import java.awt.Insets; |
| a62d533 | 24 | import java.awt.event.ActionEvent; |
| a62d533 | 25 | import java.awt.event.ActionListener; |
| a62d533 | 26 | import java.awt.event.MouseAdapter; |
| a62d533 | 27 | import java.awt.event.MouseEvent; |
| a62d533 | 28 | |
| a62d533 | 29 | import javax.swing.JLabel; |
| a62d533 | 30 | import javax.swing.JPanel; |
| a62d533 | 31 | import javax.swing.JToggleButton; |
| a62d533 | 32 | |
| a62d533 | 33 | import com.badlogic.gdx.graphics.g2d.ParticleEmitter.ParticleValue; |
| a62d533 | 34 | |
| a62d533 | 35 | class EditorPanel extends JPanel {
|
| a62d533 | 36 | private final String name; |
| a62d533 | 37 | private final String description; |
| a62d533 | 38 | private final ParticleValue value; |
| a62d533 | 39 | private JPanel titlePanel; |
| a62d533 | 40 | JToggleButton activeButton; |
| a62d533 | 41 | private JPanel contentPanel; |
| a62d533 | 42 | JToggleButton advancedButton; |
| a62d533 | 43 | JPanel advancedPanel; |
| a62d533 | 44 | private boolean hasAdvanced; |
| a62d533 | 45 | JLabel descriptionLabel; |
| a62d533 | 46 | |
| a62d533 | 47 | public EditorPanel (ParticleValue value, String name, String description) {
|
| a62d533 | 48 | this.name = name; |
| a62d533 | 49 | this.value = value; |
| a62d533 | 50 | this.description = description; |
| a62d533 | 51 | |
| a62d533 | 52 | initializeComponents(); |
| a62d533 | 53 | |
| a62d533 | 54 | titlePanel.addMouseListener(new MouseAdapter() {
|
| a62d533 | 55 | public void mouseClicked (MouseEvent event) {
|
| a62d533 | 56 | if (!activeButton.isVisible()) return; |
| a62d533 | 57 | activeButton.setSelected(!activeButton.isSelected()); |
| a62d533 | 58 | updateActive(); |
| a62d533 | 59 | } |
| a62d533 | 60 | }); |
| a62d533 | 61 | activeButton.addActionListener(new ActionListener() {
|
| a62d533 | 62 | public void actionPerformed (ActionEvent event) {
|
| a62d533 | 63 | updateActive(); |
| a62d533 | 64 | } |
| a62d533 | 65 | }); |
| a62d533 | 66 | advancedButton.addActionListener(new ActionListener() {
|
| a62d533 | 67 | public void actionPerformed (ActionEvent event) {
|
| a62d533 | 68 | advancedPanel.setVisible(advancedButton.isSelected()); |
| a62d533 | 69 | } |
| a62d533 | 70 | }); |
| a62d533 | 71 | |
| a62d533 | 72 | if (value != null) {
|
| a62d533 | 73 | activeButton.setSelected(value.isActive()); |
| a62d533 | 74 | updateActive(); |
| a62d533 | 75 | } |
| a62d533 | 76 | |
| a62d533 | 77 | boolean alwaysActive = value == null ? true : value.isAlwaysActive(); |
| a62d533 | 78 | activeButton.setVisible(!alwaysActive); |
| a62d533 | 79 | if (alwaysActive) contentPanel.setVisible(true); |
| a62d533 | 80 | if (alwaysActive) titlePanel.setCursor(null); |
| a62d533 | 81 | } |
| a62d533 | 82 | |
| a62d533 | 83 | void updateActive () {
|
| a62d533 | 84 | contentPanel.setVisible(activeButton.isSelected()); |
| a62d533 | 85 | advancedPanel.setVisible(activeButton.isSelected() && advancedButton.isSelected()); |
| a62d533 | 86 | advancedButton.setVisible(activeButton.isSelected() && hasAdvanced); |
| a62d533 | 87 | descriptionLabel.setText(activeButton.isSelected() ? description : ""); |
| a62d533 | 88 | if (value != null) value.setActive(activeButton.isSelected()); |
| a62d533 | 89 | } |
| a62d533 | 90 | |
| a62d533 | 91 | public void update (ParticlePanel editor) {
|
| a62d533 | 92 | } |
| a62d533 | 93 | |
| a62d533 | 94 | public void setHasAdvanced (boolean hasAdvanced) {
|
| a62d533 | 95 | this.hasAdvanced = hasAdvanced; |
| a62d533 | 96 | advancedButton.setVisible(hasAdvanced && (value.isActive() || value.isAlwaysActive())); |
| a62d533 | 97 | } |
| a62d533 | 98 | |
| a62d533 | 99 | public JPanel getContentPanel () {
|
| a62d533 | 100 | return contentPanel; |
| a62d533 | 101 | } |
| a62d533 | 102 | |
| a62d533 | 103 | public JPanel getAdvancedPanel () {
|
| a62d533 | 104 | return advancedPanel; |
| a62d533 | 105 | } |
| a62d533 | 106 | |
| a62d533 | 107 | public String getName () {
|
| a62d533 | 108 | return name; |
| a62d533 | 109 | } |
| a62d533 | 110 | |
| a62d533 | 111 | public void setEmbedded () {
|
| a62d533 | 112 | GridBagLayout layout = (GridBagLayout)getLayout(); |
| a62d533 | 113 | GridBagConstraints constraints = layout.getConstraints(contentPanel); |
| a62d533 | 114 | constraints.insets = new Insets(0, 0, 0, 0); |
| a62d533 | 115 | layout.setConstraints(contentPanel, constraints); |
| a62d533 | 116 | |
| a62d533 | 117 | titlePanel.setVisible(false); |
| a62d533 | 118 | } |
| a62d533 | 119 | |
| a62d533 | 120 | private void initializeComponents () {
|
| a62d533 | 121 | setLayout(new GridBagLayout()); |
| a62d533 | 122 | {
|
| a62d533 | 123 | titlePanel = new JPanel(new GridBagLayout()); |
| a62d533 | 124 | add(titlePanel, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, |
| a62d533 | 125 | new Insets(3, 0, 3, 0), 0, 0)); |
| a62d533 | 126 | titlePanel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
| a62d533 | 127 | {
|
| a62d533 | 128 | JLabel label = new JLabel(name); |
| a62d533 | 129 | titlePanel.add(label, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, |
| a62d533 | 130 | new Insets(3, 6, 3, 6), 0, 0)); |
| a62d533 | 131 | label.setFont(label.getFont().deriveFont(Font.BOLD)); |
| a62d533 | 132 | } |
| a62d533 | 133 | {
|
| a62d533 | 134 | descriptionLabel = new JLabel(description); |
| a62d533 | 135 | titlePanel.add(descriptionLabel, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, |
| a62d533 | 136 | GridBagConstraints.NONE, new Insets(3, 6, 3, 6), 0, 0)); |
| a62d533 | 137 | } |
| a62d533 | 138 | {
|
| a62d533 | 139 | advancedButton = new JToggleButton("Advanced");
|
| a62d533 | 140 | titlePanel.add(advancedButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, |
| a62d533 | 141 | GridBagConstraints.NONE, new Insets(0, 0, 0, 6), 0, 0)); |
| a62d533 | 142 | advancedButton.setVisible(false); |
| a62d533 | 143 | } |
| a62d533 | 144 | {
|
| a62d533 | 145 | activeButton = new JToggleButton("Active");
|
| a62d533 | 146 | titlePanel.add(activeButton, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, |
| a62d533 | 147 | GridBagConstraints.NONE, new Insets(0, 0, 0, 6), 0, 0)); |
| a62d533 | 148 | } |
| a62d533 | 149 | } |
| a62d533 | 150 | {
|
| a62d533 | 151 | contentPanel = new JPanel(new GridBagLayout()); |
| a62d533 | 152 | add(contentPanel, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, |
| a62d533 | 153 | new Insets(0, 6, 6, 6), 0, 0)); |
| a62d533 | 154 | contentPanel.setVisible(false); |
| a62d533 | 155 | } |
| a62d533 | 156 | {
|
| a62d533 | 157 | advancedPanel = new JPanel(new GridBagLayout()); |
| a62d533 | 158 | add(advancedPanel, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, |
| a62d533 | 159 | new Insets(0, 6, 6, 6), 0, 0)); |
| a62d533 | 160 | advancedPanel.setVisible(false); |
| a62d533 | 161 | } |
| a62d533 | 162 | } |
| a62d533 | 163 | } |