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/PercentagePanel.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.JPanel; |
| a62d533 | 29 | |
| a62d533 | 30 | import com.badlogic.gdx.graphics.g2d.ParticleEmitter.ScaledNumericValue; |
| a62d533 | 31 | |
| a62d533 | 32 | class PercentagePanel extends EditorPanel {
|
| a62d533 | 33 | final ScaledNumericValue value; |
| a62d533 | 34 | JButton expandButton; |
| a62d533 | 35 | Chart chart; |
| a62d533 | 36 | |
| a62d533 | 37 | public PercentagePanel (final ScaledNumericValue value, String chartTitle, String name, String description) {
|
| a62d533 | 38 | super(value, name, description); |
| a62d533 | 39 | this.value = value; |
| a62d533 | 40 | |
| a62d533 | 41 | initializeComponents(chartTitle); |
| a62d533 | 42 | |
| a62d533 | 43 | chart.setValues(value.getTimeline(), value.getScaling()); |
| a62d533 | 44 | |
| a62d533 | 45 | expandButton.addActionListener(new ActionListener() {
|
| a62d533 | 46 | public void actionPerformed (ActionEvent event) {
|
| a62d533 | 47 | chart.setExpanded(!chart.isExpanded()); |
| a62d533 | 48 | boolean expanded = chart.isExpanded(); |
| a62d533 | 49 | GridBagLayout layout = (GridBagLayout)getContentPanel().getLayout(); |
| a62d533 | 50 | GridBagConstraints chartConstraints = layout.getConstraints(chart); |
| a62d533 | 51 | GridBagConstraints expandButtonConstraints = layout.getConstraints(expandButton); |
| a62d533 | 52 | if (expanded) {
|
| a62d533 | 53 | chart.setPreferredSize(new Dimension(150, 200)); |
| a62d533 | 54 | expandButton.setText("-");
|
| a62d533 | 55 | chartConstraints.weightx = 1; |
| a62d533 | 56 | expandButtonConstraints.weightx = 0; |
| a62d533 | 57 | } else {
|
| a62d533 | 58 | chart.setPreferredSize(new Dimension(150, 62)); |
| a62d533 | 59 | expandButton.setText("+");
|
| a62d533 | 60 | chartConstraints.weightx = 0; |
| a62d533 | 61 | expandButtonConstraints.weightx = 1; |
| a62d533 | 62 | } |
| a62d533 | 63 | layout.setConstraints(chart, chartConstraints); |
| a62d533 | 64 | layout.setConstraints(expandButton, expandButtonConstraints); |
| a62d533 | 65 | chart.revalidate(); |
| a62d533 | 66 | } |
| a62d533 | 67 | }); |
| a62d533 | 68 | } |
| a62d533 | 69 | |
| a62d533 | 70 | private void initializeComponents (String chartTitle) {
|
| a62d533 | 71 | JPanel contentPanel = getContentPanel(); |
| a62d533 | 72 | {
|
| a62d533 | 73 | chart = new Chart(chartTitle) {
|
| a62d533 | 74 | public void pointsChanged () {
|
| a62d533 | 75 | value.setTimeline(chart.getValuesX()); |
| a62d533 | 76 | value.setScaling(chart.getValuesY()); |
| a62d533 | 77 | } |
| a62d533 | 78 | }; |
| a62d533 | 79 | chart.setPreferredSize(new Dimension(150, 62)); |
| a62d533 | 80 | contentPanel.add(chart, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.BOTH, |
| a62d533 | 81 | new Insets(0, 0, 0, 0), 0, 0)); |
| a62d533 | 82 | } |
| a62d533 | 83 | {
|
| a62d533 | 84 | expandButton = new JButton("+");
|
| a62d533 | 85 | expandButton.setBorder(BorderFactory.createEmptyBorder(4, 10, 4, 10)); |
| a62d533 | 86 | contentPanel.add(expandButton, new GridBagConstraints(1, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, |
| a62d533 | 87 | GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0)); |
| a62d533 | 88 | } |
| a62d533 | 89 | } |
| a62d533 | 90 | } |