⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 particleappearancepanel.java

📁 java 3d game jme 工程开发源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*
 * Copyright (c) 2003-2009 jMonkeyEngine
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 * * Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 *
 * * Neither the name of 'jMonkeyEngine' nor the names of its contributors 
 *   may be used to endorse or promote products derived from this software 
 *   without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package com.jmex.editors.swing.particles;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.prefs.Preferences;

import javax.swing.AbstractAction;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import com.jme.image.Texture;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.state.BlendState;
import com.jme.scene.state.RenderState;
import com.jme.scene.state.TextureState;
import com.jme.system.DisplaySystem;
import com.jme.util.GameTaskQueue;
import com.jme.util.GameTaskQueueManager;
import com.jme.util.TextureManager;
import com.jmex.editors.swing.widget.ValuePanel;
import com.jmex.effects.particles.AnimationEntry;
import com.jmex.effects.particles.ParticleFactory;
import com.jmex.effects.particles.ParticleSystem;
import com.jmex.effects.particles.ParticleInfluence;
import com.jmex.effects.particles.ParticlePoints;
import com.jmex.effects.particles.RampEntry;
import com.jmex.effects.particles.ParticleSystem.ParticleType;

public abstract class ParticleAppearancePanel extends ParticleEditPanel {
    private static final Logger logger = Logger
            .getLogger(ParticleAppearancePanel.class.getName());
    
    private static final long serialVersionUID = 1L;
    private static File newTexture = null;

    private JCheckBox additiveBlendingBox;
    private JComboBox geomTypeBox;
    private JCheckBox velocityAlignedBox;
    private JLabel imageLabel = new JLabel();

    private JList rampList = null;
    private DefaultListModel rampModel = new DefaultListModel();
    private JButton rampAddButton = makeListButton("Add");
    private JButton rampRemoveButton = makeListButton("Remove");
    private JButton rampEditButton = makeListButton("Edit");
    private JButton rampMoveUpButton = makeListButton("/\\");
    private JButton rampMoveDownButton = makeListButton("\\/");

    private JList animList = null;
    private DefaultListModel animModel = new DefaultListModel();
    private JButton animAddButton = makeListButton("Add");
    private JButton animRemoveButton = makeListButton("Remove");
    private JButton animEditButton = makeListButton("Edit");
    private JButton animMoveUpButton = makeListButton("/\\");
    private JButton animMoveDownButton = makeListButton("\\/");

    private Preferences prefs;
    private JFileChooser textureChooser = new JFileChooser();
    private JPanel texturePanel;

    private ValuePanel texPanel, startTexPanel;

    public ParticleAppearancePanel(Preferences prefs) {
        super();
        this.prefs = prefs;
        setLayout(new GridBagLayout());
        initPanel();
        initTextureChooser();
    }

    private JButton makeListButton(String text) {
        JButton button = new JButton(text);
        button.setMargin(new Insets(2, 2, 2, 2));
        return button;
    }

    private void initPanel() {

        geomTypeBox = new JComboBox(ParticleType.values());
        geomTypeBox.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                changeParticleType((ParticleType) geomTypeBox.getSelectedItem());
            }
        });

        velocityAlignedBox = new JCheckBox(new AbstractAction(
                "Align with Velocity") {
            private static final long serialVersionUID = 1L;
            public void actionPerformed(ActionEvent e) {
                getEdittedParticles().setVelocityAligned(
                        velocityAlignedBox.isSelected());
            }
        });
        velocityAlignedBox.setFont(new Font("Arial", Font.BOLD, 13));

        rampList = new JList(rampModel);
        rampList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        rampList.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                int selected = rampList.getSelectedIndex();
                rampRemoveButton.setEnabled(selected > 0 && selected < rampModel.getSize()-1);
                rampEditButton.setEnabled(selected != -1);
                rampMoveUpButton.setEnabled(selected > 1 && selected < rampModel.getSize()-1);
                rampMoveDownButton.setEnabled(selected < rampModel.getSize()-2 && selected > 0);
            }
        });
        rampList.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() > 1) {
                    rampEditButton.doClick();
                    e.consume();
                }
            }
        });

        rampAddButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                new Thread() {
                    public void run() {
                        RampEntry entry = new RampEntry();
                        getEdittedParticles().getRamp().addEntry(entry);
                        showEditWindow(entry);
                        updateRampModel();
                        rampList.setSelectedValue(entry, true);
                    }
                }.start();
            }
        });

        rampEditButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                new Thread() {
                    public void run() {
                        int index = rampList.getSelectedIndex();
                        RampEntry entry = (RampEntry) rampList
                                .getSelectedValue();
                        showEditWindow(entry);
                        updateRampModel();
                        rampList.setSelectedIndex(index);
                    };
                }.start();
            }
        });

        rampRemoveButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                RampEntry entry = (RampEntry)rampList.getSelectedValue();
                getEdittedParticles().getRamp().removeEntry(entry);
                updateRampModel();
            }
        });

        rampMoveUpButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                int index = rampList.getSelectedIndex();
                RampEntry entry = (RampEntry)rampList.getSelectedValue();
                getEdittedParticles().getRamp().removeEntry(entry);
                getEdittedParticles().getRamp().addEntry(index-2, entry);
                updateRampModel();
                rampList.setSelectedValue(entry, true);
            }
        });

        rampMoveDownButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                int index = rampList.getSelectedIndex();
                RampEntry entry = (RampEntry)rampList.getSelectedValue();
                getEdittedParticles().getRamp().removeEntry(entry);
                getEdittedParticles().getRamp().addEntry(index, entry);
                updateRampModel();
                rampList.setSelectedValue(entry, true);
            }
        });
        
        rampRemoveButton.setEnabled(false);
        rampEditButton.setEnabled(false);
        rampMoveUpButton.setEnabled(false);
        rampMoveDownButton.setEnabled(false);
        
        
        JPanel geomPanel = new JPanel(new GridBagLayout());
        geomPanel.setBorder(createTitledBorder("PARTICLE GEOMETRY"));
        geomPanel.add(createBoldLabel("Type:"), new GridBagConstraints(0, 0, 1,
                1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE,
                new Insets(5, 5, 5, 5), 0, 0));
        geomPanel.add(geomTypeBox, new GridBagConstraints(1, 0, 1, 1, 0, 0,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                new Insets(5, 5, 5, 5), 0, 0));
        geomPanel.add(velocityAlignedBox, new GridBagConstraints(0, 1, 2, 1,
                1.0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE,
                new Insets(5, 5, 5, 5), 0, 0));

        JPanel rampPanel = new JPanel(new GridBagLayout());
        rampPanel.setBorder(createTitledBorder("APPEARANCE TIMELINE"));
        rampPanel.add(new JScrollPane(rampList,
                JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED),
                new GridBagConstraints(1, 0, 1, 6, 1.0, 1.0,
                        GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH,
                        new Insets(5, 5, 5, 5), 0, 0));
        rampPanel.add(rampAddButton, new GridBagConstraints(0, 0, 1,
                1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL,
                new Insets(5, 5, 0, 5), 0, 0));
        rampPanel.add(rampRemoveButton, new GridBagConstraints(0, 1, 1,
                1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -