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/ScaledNumericPanel.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.GridBagLayout; |
| a62d533 | 22 | import java.awt.Insets; |
| a62d533 | 23 | import java.awt.event.ActionEvent; |
| a62d533 | 24 | import java.awt.event.ActionListener; |
| a62d533 | 25 | |
| a62d533 | 26 | import javax.swing.BorderFactory; |
| a62d533 | 27 | import javax.swing.JButton; |
| a62d533 | 28 | import javax.swing.JCheckBox; |
| a62d533 | 29 | import javax.swing.JLabel; |
| a62d533 | 30 | import javax.swing.JPanel; |
| a62d533 | 31 | import javax.swing.event.ChangeEvent; |
| a62d533 | 32 | import javax.swing.event.ChangeListener; |
| a62d533 | 33 | |
| a62d533 | 34 | import com.badlogic.gdx.graphics.g2d.ParticleEmitter.ScaledNumericValue; |
| a62d533 | 35 | |
| a62d533 | 36 | class ScaledNumericPanel extends EditorPanel {
|
| a62d533 | 37 | final ScaledNumericValue value; |
| a62d533 | 38 | Slider lowMinSlider, lowMaxSlider; |
| a62d533 | 39 | Slider highMinSlider, highMaxSlider; |
| a62d533 | 40 | JCheckBox relativeCheckBox; |
| a62d533 | 41 | Chart chart; |
| a62d533 | 42 | JPanel formPanel; |
| a62d533 | 43 | JButton expandButton; |
| a62d533 | 44 | JButton lowRangeButton; |
| a62d533 | 45 | JButton highRangeButton; |
| a62d533 | 46 | |
| a62d533 | 47 | public ScaledNumericPanel (final ScaledNumericValue value, String chartTitle, String name, String description) {
|
| a62d533 | 48 | super(value, name, description); |
| a62d533 | 49 | this.value = value; |
| a62d533 | 50 | |
| a62d533 | 51 | initializeComponents(chartTitle); |
| a62d533 | 52 | |
| a62d533 | 53 | lowMinSlider.setValue(value.getLowMin()); |
| a62d533 | 54 | lowMaxSlider.setValue(value.getLowMax()); |
| a62d533 | 55 | highMinSlider.setValue(value.getHighMin()); |
| a62d533 | 56 | highMaxSlider.setValue(value.getHighMax()); |
| a62d533 | 57 | chart.setValues(value.getTimeline(), value.getScaling()); |
| a62d533 | 58 | relativeCheckBox.setSelected(value.isRelative()); |
| a62d533 | 59 | |
| a62d533 | 60 | lowMinSlider.addChangeListener(new ChangeListener() {
|
| a62d533 | 61 | public void stateChanged (ChangeEvent event) {
|
| a62d533 | 62 | value.setLowMin((Float)lowMinSlider.getValue()); |
| a62d533 | 63 | if (!lowMaxSlider.isVisible()) value.setLowMax((Float)lowMinSlider.getValue()); |
| a62d533 | 64 | } |
| a62d533 | 65 | }); |
| a62d533 | 66 | lowMaxSlider.addChangeListener(new ChangeListener() {
|
| a62d533 | 67 | public void stateChanged (ChangeEvent event) {
|
| a62d533 | 68 | value.setLowMax((Float)lowMaxSlider.getValue()); |
| a62d533 | 69 | } |
| a62d533 | 70 | }); |
| a62d533 | 71 | highMinSlider.addChangeListener(new ChangeListener() {
|
| a62d533 | 72 | public void stateChanged (ChangeEvent event) {
|
| a62d533 | 73 | value.setHighMin((Float)highMinSlider.getValue()); |
| a62d533 | 74 | if (!highMaxSlider.isVisible()) value.setHighMax((Float)highMinSlider.getValue()); |
| a62d533 | 75 | } |
| a62d533 | 76 | }); |
| a62d533 | 77 | highMaxSlider.addChangeListener(new ChangeListener() {
|
| a62d533 | 78 | public void stateChanged (ChangeEvent event) {
|
| a62d533 | 79 | value.setHighMax((Float)highMaxSlider.getValue()); |
| a62d533 | 80 | } |
| a62d533 | 81 | }); |
| a62d533 | 82 | |
| a62d533 | 83 | relativeCheckBox.addActionListener(new ActionListener() {
|
| a62d533 | 84 | public void actionPerformed (ActionEvent event) {
|
| a62d533 | 85 | value.setRelative(relativeCheckBox.isSelected()); |
| a62d533 | 86 | } |
| a62d533 | 87 | }); |
| a62d533 | 88 | |
| a62d533 | 89 | lowRangeButton.addActionListener(new ActionListener() {
|
| a62d533 | 90 | public void actionPerformed (ActionEvent event) {
|
| a62d533 | 91 | boolean visible = !lowMaxSlider.isVisible(); |
| a62d533 | 92 | lowMaxSlider.setVisible(visible); |
| a62d533 | 93 | lowRangeButton.setText(visible ? "<" : ">"); |
| a62d533 | 94 | GridBagLayout layout = (GridBagLayout)formPanel.getLayout(); |
| a62d533 | 95 | GridBagConstraints constraints = layout.getConstraints(lowRangeButton); |
| a62d533 | 96 | constraints.gridx = visible ? 5 : 4; |
| a62d533 | 97 | layout.setConstraints(lowRangeButton, constraints); |
| a62d533 | 98 | Slider slider = visible ? lowMaxSlider : lowMinSlider; |
| a62d533 | 99 | value.setLowMax((Float)slider.getValue()); |
| a62d533 | 100 | } |
| a62d533 | 101 | }); |
| a62d533 | 102 | |
| a62d533 | 103 | highRangeButton.addActionListener(new ActionListener() {
|
| a62d533 | 104 | public void actionPerformed (ActionEvent event) {
|
| a62d533 | 105 | boolean visible = !highMaxSlider.isVisible(); |
| a62d533 | 106 | highMaxSlider.setVisible(visible); |
| a62d533 | 107 | highRangeButton.setText(visible ? "<" : ">"); |
| a62d533 | 108 | GridBagLayout layout = (GridBagLayout)formPanel.getLayout(); |
| a62d533 | 109 | GridBagConstraints constraints = layout.getConstraints(highRangeButton); |
| a62d533 | 110 | constraints.gridx = visible ? 5 : 4; |
| a62d533 | 111 | layout.setConstraints(highRangeButton, constraints); |
| a62d533 | 112 | Slider slider = visible ? highMaxSlider : highMinSlider; |
| a62d533 | 113 | value.setHighMax((Float)slider.getValue()); |
| a62d533 | 114 | } |
| a62d533 | 115 | }); |
| a62d533 | 116 | |
| a62d533 | 117 | expandButton.addActionListener(new ActionListener() {
|
| a62d533 | 118 | public void actionPerformed (ActionEvent event) {
|
| a62d533 | 119 | chart.setExpanded(!chart.isExpanded()); |
| a62d533 | 120 | boolean expanded = chart.isExpanded(); |
| a62d533 | 121 | GridBagLayout layout = (GridBagLayout)getContentPanel().getLayout(); |
| a62d533 | 122 | GridBagConstraints chartConstraints = layout.getConstraints(chart); |
| a62d533 | 123 | GridBagConstraints expandButtonConstraints = layout.getConstraints(expandButton); |
| a62d533 | 124 | if (expanded) {
|
| a62d533 | 125 | chart.setPreferredSize(new Dimension(150, 200)); |
| a62d533 | 126 | expandButton.setText("-");
|
| a62d533 | 127 | chartConstraints.weightx = 1; |
| a62d533 | 128 | expandButtonConstraints.weightx = 0; |
| a62d533 | 129 | } else {
|
| a62d533 | 130 | chart.setPreferredSize(new Dimension(150, 30)); |
| a62d533 | 131 | expandButton.setText("+");
|
| a62d533 | 132 | chartConstraints.weightx = 0; |
| a62d533 | 133 | expandButtonConstraints.weightx = 1; |
| a62d533 | 134 | } |
| a62d533 | 135 | layout.setConstraints(chart, chartConstraints); |
| a62d533 | 136 | layout.setConstraints(expandButton, expandButtonConstraints); |
| a62d533 | 137 | relativeCheckBox.setVisible(!expanded); |
| a62d533 | 138 | formPanel.setVisible(!expanded); |
| a62d533 | 139 | chart.revalidate(); |
| a62d533 | 140 | } |
| a62d533 | 141 | }); |
| a62d533 | 142 | |
| a62d533 | 143 | if (value.getLowMin() == value.getLowMax()) lowRangeButton.doClick(0); |
| a62d533 | 144 | if (value.getHighMin() == value.getHighMax()) highRangeButton.doClick(0); |
| a62d533 | 145 | } |
| a62d533 | 146 | |
| a62d533 | 147 | public JPanel getFormPanel () {
|
| a62d533 | 148 | return formPanel; |
| a62d533 | 149 | } |
| a62d533 | 150 | |
| a62d533 | 151 | private void initializeComponents (String chartTitle) {
|
| a62d533 | 152 | JPanel contentPanel = getContentPanel(); |
| a62d533 | 153 | {
|
| a62d533 | 154 | formPanel = new JPanel(new GridBagLayout()); |
| a62d533 | 155 | contentPanel.add(formPanel, new GridBagConstraints(5, 5, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, |
| a62d533 | 156 | new Insets(0, 0, 0, 6), 0, 0)); |
| a62d533 | 157 | {
|
| a62d533 | 158 | JLabel label = new JLabel("High:");
|
| a62d533 | 159 | formPanel.add(label, new GridBagConstraints(2, 1, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, |
| a62d533 | 160 | new Insets(0, 0, 0, 6), 0, 0)); |
| a62d533 | 161 | } |
| a62d533 | 162 | {
|
| a62d533 | 163 | highMinSlider = new Slider(0, -99999, 99999, 1f, -400, 400); |
| a62d533 | 164 | formPanel.add(highMinSlider, new GridBagConstraints(3, 1, 1, 1, 0, 0, GridBagConstraints.WEST, |
| a62d533 | 165 | GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); |
| a62d533 | 166 | } |
| a62d533 | 167 | {
|
| a62d533 | 168 | highMaxSlider = new Slider(0, -99999, 99999, 1f, -400, 400); |
| a62d533 | 169 | formPanel.add(highMaxSlider, new GridBagConstraints(4, 1, 1, 1, 0, 0, GridBagConstraints.WEST, |
| a62d533 | 170 | GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0)); |
| a62d533 | 171 | } |
| a62d533 | 172 | {
|
| a62d533 | 173 | highRangeButton = new JButton("<");
|
| a62d533 | 174 | highRangeButton.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); |
| a62d533 | 175 | formPanel.add(highRangeButton, new GridBagConstraints(5, 1, 1, 1, 0.0, 0, GridBagConstraints.WEST, |
| a62d533 | 176 | GridBagConstraints.NONE, new Insets(0, 1, 0, 0), 0, 0)); |
| a62d533 | 177 | } |
| a62d533 | 178 | {
|
| a62d533 | 179 | JLabel label = new JLabel("Low:");
|
| a62d533 | 180 | formPanel.add(label, new GridBagConstraints(2, 2, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, |
| a62d533 | 181 | new Insets(0, 0, 0, 6), 0, 0)); |
| a62d533 | 182 | } |
| a62d533 | 183 | {
|
| a62d533 | 184 | lowMinSlider = new Slider(0, -99999, 99999, 1f, -400, 400); |
| a62d533 | 185 | formPanel.add(lowMinSlider, new GridBagConstraints(3, 2, 1, 1, 0, 0, GridBagConstraints.WEST, |
| a62d533 | 186 | GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); |
| a62d533 | 187 | } |
| a62d533 | 188 | {
|
| a62d533 | 189 | lowMaxSlider = new Slider(0, -99999, 99999, 1f, -400, 400); |
| a62d533 | 190 | formPanel.add(lowMaxSlider, new GridBagConstraints(4, 2, 1, 1, 0, 0, GridBagConstraints.WEST, |
| a62d533 | 191 | GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0)); |
| a62d533 | 192 | } |
| a62d533 | 193 | {
|
| a62d533 | 194 | lowRangeButton = new JButton("<");
|
| a62d533 | 195 | lowRangeButton.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); |
| a62d533 | 196 | formPanel.add(lowRangeButton, new GridBagConstraints(5, 2, 1, 1, 0.0, 0, GridBagConstraints.WEST, |
| a62d533 | 197 | GridBagConstraints.NONE, new Insets(0, 1, 0, 0), 0, 0)); |
| a62d533 | 198 | } |
| a62d533 | 199 | } |
| a62d533 | 200 | {
|
| a62d533 | 201 | chart = new Chart(chartTitle) {
|
| a62d533 | 202 | public void pointsChanged () {
|
| a62d533 | 203 | value.setTimeline(chart.getValuesX()); |
| a62d533 | 204 | value.setScaling(chart.getValuesY()); |
| a62d533 | 205 | } |
| a62d533 | 206 | }; |
| a62d533 | 207 | contentPanel.add(chart, new GridBagConstraints(6, 5, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, |
| a62d533 | 208 | new Insets(0, 0, 0, 0), 0, 0)); |
| a62d533 | 209 | chart.setPreferredSize(new Dimension(150, 30)); |
| a62d533 | 210 | } |
| a62d533 | 211 | {
|
| a62d533 | 212 | expandButton = new JButton("+");
|
| a62d533 | 213 | contentPanel.add(expandButton, new GridBagConstraints(7, 5, 1, 1, 1, 0, GridBagConstraints.SOUTHWEST, |
| a62d533 | 214 | GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 0, 0)); |
| a62d533 | 215 | expandButton.setBorder(BorderFactory.createEmptyBorder(4, 8, 4, 8)); |
| a62d533 | 216 | } |
| a62d533 | 217 | {
|
| a62d533 | 218 | relativeCheckBox = new JCheckBox("Relative");
|
| a62d533 | 219 | contentPanel.add(relativeCheckBox, new GridBagConstraints(7, 5, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, |
| a62d533 | 220 | GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0)); |
| a62d533 | 221 | } |
| a62d533 | 222 | } |
| a62d533 | 223 | } |