📄 waterpasseditor.java
字号:
/*
* 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.pass;
import java.awt.BorderLayout;
import java.awt.ComponentOrientation;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties;
import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import com.jme.renderer.ColorRGBA;
import com.jme.util.GameTaskQueue;
import com.jme.util.GameTaskQueueManager;
import com.jmex.editors.swing.widget.RGBAChooserPanel;
import com.jmex.editors.swing.widget.ValueSpinner;
import com.jmex.effects.water.WaterRenderPass;
public class WaterPassEditor extends JPanel {
private static final Logger logger = Logger.getLogger(WaterPassEditor.class
.getName());
private RGBAChooserPanel endColorButton;
private RGBAChooserPanel startColorButton;
private JCheckBox enabledCheckBox;
private JCheckBox waterFoggingBox;
private JCheckBox enableReflectionBox;
private JCheckBox enableRefractionBox;
private JCheckBox enableProjectionCheckBox;
private ValueSpinner falloffSpeedField;
private ValueSpinner clipBiasField;
private ValueSpinner maxAmplitudeField;
private ValueSpinner falloffStartField;
private ValueSpinner baseHeightField;
private ValueSpinner refractField;
private ValueSpinner reflectField;
private static final long serialVersionUID = 1L;
private float origClipBias, origHeightFalloffSpeed, origHeightFalloffStart,
origSpeedReflection;
private float origSpeedRefraction, origWaterHeight, origWaterMaxAmplitude;
private ColorRGBA origWaterColorEnd = new ColorRGBA();
private ColorRGBA origWaterColorStart = new ColorRGBA();
private boolean origUseReflection, origUseRefraction, origUseProjection, origWaterFog;
protected File lastDir;
public WaterPassEditor(final WaterRenderPass pass) {
super();
origClipBias = pass.getClipBias();
origHeightFalloffSpeed = pass.getHeightFalloffSpeed();
origHeightFalloffStart = pass.getHeightFalloffStart();
origSpeedReflection = pass.getSpeedReflection();
origSpeedRefraction = pass.getSpeedRefraction();
origWaterColorEnd.set(pass.getWaterColorEnd());
origWaterColorStart.set(pass.getWaterColorStart());
origWaterHeight = pass.getWaterHeight();
origWaterMaxAmplitude = pass.getWaterMaxAmplitude();
origUseReflection = pass.isUseReflection();
origUseRefraction = pass.isUseRefraction();
origUseProjection = pass.isUseRefraction();
origWaterFog = pass.isUseFadeToFogColor();
setLayout(new GridBagLayout());
enabledCheckBox = new JCheckBox("Water Enabled");
enabledCheckBox.setSelected(pass.isEnabled());
enabledCheckBox.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
pass.setEnabled(enabledCheckBox.isSelected());
}
});
final GridBagConstraints enabledBagConstraints = new GridBagConstraints();
enabledBagConstraints.gridwidth = 2;
enabledBagConstraints.gridy = 0;
enabledBagConstraints.gridx = 0;
add(enabledCheckBox, enabledBagConstraints);
final JPanel colorPanel = new JPanel();
colorPanel.setLayout(new GridBagLayout());
colorPanel.setBorder(new TitledBorder(null, "Water Color",
TitledBorder.DEFAULT_JUSTIFICATION,
TitledBorder.DEFAULT_POSITION, null, null));
final GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridwidth = 2;
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
gridBagConstraints.gridy = 1;
gridBagConstraints.gridx = 0;
add(colorPanel, gridBagConstraints);
final JLabel startLabel = new JLabel();
startLabel.setText("Start");
final GridBagConstraints gridBagConstraints_1 = new GridBagConstraints();
gridBagConstraints_1.insets = new Insets(0, 2, 0, 4);
gridBagConstraints_1.gridy = 0;
gridBagConstraints_1.gridx = 0;
colorPanel.add(startLabel, gridBagConstraints_1);
final JLabel endLabel = new JLabel();
endLabel.setText("End");
final GridBagConstraints gridBagConstraints_2 = new GridBagConstraints();
gridBagConstraints_2.insets = new Insets(0, 4, 0, 2);
gridBagConstraints_2.gridy = 0;
gridBagConstraints_2.gridx = 1;
colorPanel.add(endLabel, gridBagConstraints_2);
startColorButton = new RGBAChooserPanel() {
private static final long serialVersionUID = 1L;
@Override
protected ColorRGBA getColor() {
return origWaterColorStart.clone();
}
@Override
protected void setColor(ColorRGBA color) {
pass.getWaterColorStart().set(color);
}
};
final GridBagConstraints gridBagConstraints_3 = new GridBagConstraints();
gridBagConstraints_3.insets = new Insets(2, 2, 0, 4);
gridBagConstraints_3.gridy = 1;
gridBagConstraints_3.gridx = 0;
colorPanel.add(startColorButton, gridBagConstraints_3);
endColorButton = new RGBAChooserPanel() {
private static final long serialVersionUID = 1L;
@Override
protected ColorRGBA getColor() {
return origWaterColorEnd.clone();
}
@Override
protected void setColor(ColorRGBA color) {
pass.getWaterColorEnd().set(color);
}
};
final GridBagConstraints gridBagConstraints_4 = new GridBagConstraints();
gridBagConstraints_4.insets = new Insets(2, 4, 0, 2);
gridBagConstraints_4.gridy = 1;
gridBagConstraints_4.gridx = 1;
colorPanel.add(endColorButton, gridBagConstraints_4);
waterFoggingBox = new JCheckBox();
waterFoggingBox.setSelected(pass.isUseFadeToFogColor());
waterFoggingBox.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
pass.useFadeToFogColor(waterFoggingBox.isSelected());
}
});
waterFoggingBox.setText("Water Fogging");
final GridBagConstraints gridBagConstraints_27 = new GridBagConstraints();
gridBagConstraints_27.gridwidth = 2;
gridBagConstraints_27.gridy = 2;
gridBagConstraints_27.gridx = 0;
colorPanel.add(waterFoggingBox, gridBagConstraints_27);
final JPanel reflectPanel = new JPanel();
reflectPanel.setLayout(new GridBagLayout());
reflectPanel.setBorder(new TitledBorder(null, "Reflection",
TitledBorder.DEFAULT_JUSTIFICATION,
TitledBorder.DEFAULT_POSITION, null, null));
final GridBagConstraints gridBagConstraints_8 = new GridBagConstraints();
gridBagConstraints_8.fill = GridBagConstraints.HORIZONTAL;
gridBagConstraints_8.gridy = 2;
gridBagConstraints_8.gridx = 0;
add(reflectPanel, gridBagConstraints_8);
enableReflectionBox = new JCheckBox();
enableReflectionBox.setSelected(pass.isUseReflection());
enableReflectionBox.addActionListener(new ActionListener() {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -