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/RangedNumericPanel.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.GridBagConstraints; |
| a62d533 | 20 | import java.awt.Insets; |
| a62d533 | 21 | import java.awt.event.ActionEvent; |
| a62d533 | 22 | import java.awt.event.ActionListener; |
| a62d533 | 23 | |
| a62d533 | 24 | import javax.swing.BorderFactory; |
| a62d533 | 25 | import javax.swing.JButton; |
| a62d533 | 26 | import javax.swing.JLabel; |
| a62d533 | 27 | import javax.swing.JPanel; |
| a62d533 | 28 | import javax.swing.event.ChangeEvent; |
| a62d533 | 29 | import javax.swing.event.ChangeListener; |
| a62d533 | 30 | |
| a62d533 | 31 | import com.badlogic.gdx.graphics.g2d.ParticleEmitter.RangedNumericValue; |
| a62d533 | 32 | |
| a62d533 | 33 | class RangedNumericPanel extends EditorPanel {
|
| a62d533 | 34 | private final RangedNumericValue value; |
| a62d533 | 35 | Slider minSlider, maxSlider; |
| a62d533 | 36 | JButton rangeButton; |
| a62d533 | 37 | JLabel label; |
| a62d533 | 38 | |
| a62d533 | 39 | public RangedNumericPanel (final RangedNumericValue value, String name, String description) {
|
| a62d533 | 40 | super(value, name, description); |
| a62d533 | 41 | this.value = value; |
| a62d533 | 42 | |
| a62d533 | 43 | initializeComponents(); |
| a62d533 | 44 | |
| a62d533 | 45 | minSlider.setValue(value.getLowMin()); |
| a62d533 | 46 | maxSlider.setValue(value.getLowMax()); |
| a62d533 | 47 | |
| a62d533 | 48 | minSlider.addChangeListener(new ChangeListener() {
|
| a62d533 | 49 | public void stateChanged (ChangeEvent event) {
|
| a62d533 | 50 | value.setLowMin((Float)minSlider.getValue()); |
| a62d533 | 51 | if (!maxSlider.isVisible()) value.setLowMax((Float)minSlider.getValue()); |
| a62d533 | 52 | } |
| a62d533 | 53 | }); |
| a62d533 | 54 | |
| a62d533 | 55 | maxSlider.addChangeListener(new ChangeListener() {
|
| a62d533 | 56 | public void stateChanged (ChangeEvent event) {
|
| a62d533 | 57 | value.setLowMax((Float)maxSlider.getValue()); |
| a62d533 | 58 | } |
| a62d533 | 59 | }); |
| a62d533 | 60 | |
| a62d533 | 61 | rangeButton.addActionListener(new ActionListener() {
|
| a62d533 | 62 | public void actionPerformed (ActionEvent event) {
|
| a62d533 | 63 | boolean visible = !maxSlider.isVisible(); |
| a62d533 | 64 | maxSlider.setVisible(visible); |
| a62d533 | 65 | rangeButton.setText(visible ? "<" : ">"); |
| a62d533 | 66 | Slider slider = visible ? maxSlider : minSlider; |
| a62d533 | 67 | value.setLowMax((Float)slider.getValue()); |
| a62d533 | 68 | } |
| a62d533 | 69 | }); |
| a62d533 | 70 | |
| a62d533 | 71 | if (value.getLowMin() == value.getLowMax()) rangeButton.doClick(0); |
| a62d533 | 72 | } |
| a62d533 | 73 | |
| a62d533 | 74 | private void initializeComponents () {
|
| a62d533 | 75 | JPanel contentPanel = getContentPanel(); |
| a62d533 | 76 | {
|
| a62d533 | 77 | label = new JLabel("Value:");
|
| a62d533 | 78 | contentPanel.add(label, new GridBagConstraints(2, 2, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, |
| a62d533 | 79 | new Insets(0, 0, 0, 6), 0, 0)); |
| a62d533 | 80 | } |
| a62d533 | 81 | {
|
| a62d533 | 82 | minSlider = new Slider(0, -99999, 99999, 1, -400, 400); |
| a62d533 | 83 | contentPanel.add(minSlider, new GridBagConstraints(3, 2, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, |
| a62d533 | 84 | new Insets(0, 0, 0, 0), 0, 0)); |
| a62d533 | 85 | } |
| a62d533 | 86 | {
|
| a62d533 | 87 | maxSlider = new Slider(0, -99999, 99999, 1, -400, 400); |
| a62d533 | 88 | contentPanel.add(maxSlider, new GridBagConstraints(4, 2, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, |
| a62d533 | 89 | new Insets(0, 6, 0, 0), 0, 0)); |
| a62d533 | 90 | } |
| a62d533 | 91 | {
|
| a62d533 | 92 | rangeButton = new JButton("<");
|
| a62d533 | 93 | rangeButton.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); |
| a62d533 | 94 | contentPanel.add(rangeButton, new GridBagConstraints(5, 2, 1, 1, 1.0, 0, GridBagConstraints.WEST, |
| a62d533 | 95 | GridBagConstraints.NONE, new Insets(0, 1, 0, 0), 0, 0)); |
| a62d533 | 96 | } |
| a62d533 | 97 | } |
| a62d533 | 98 | } |