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

📄 waterpasseditor.java

📁 java 3d game jme 工程开发源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        gridBagConstraints_23.gridy = 2;
        gridBagConstraints_23.gridx = 2;
        wavesPanel.add(falloffSpeedLabel, gridBagConstraints_23);

        falloffSpeedField = new ValueSpinner(-1000, 1000, .1f);
        falloffSpeedField.setValue(pass.getHeightFalloffSpeed());
        falloffSpeedField.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent e) {
                pass.setHeightFalloffSpeed(((Number) falloffSpeedField
                        .getValue()).floatValue());
            }
        });
        final GridBagConstraints gridBagConstraints_26 = new GridBagConstraints();
        gridBagConstraints_26.insets = new Insets(0, 0, 2, 0);
        gridBagConstraints_26.gridy = 2;
        gridBagConstraints_26.gridx = 3;
        wavesPanel.add(falloffSpeedField, gridBagConstraints_26);

        final JLabel clipBiasLabel = new JLabel();
        clipBiasLabel.setText("Clip Bias:");
        final GridBagConstraints gridBagConstraints_22 = new GridBagConstraints();
        gridBagConstraints_22.insets = new Insets(0, 0, 0, 0);
        gridBagConstraints_22.anchor = GridBagConstraints.EAST;
        gridBagConstraints_22.gridy = 3;
        gridBagConstraints_22.gridx = 0;
        wavesPanel.add(clipBiasLabel, gridBagConstraints_22);

        clipBiasField = new ValueSpinner(-1000, 1000, .1f);
        clipBiasField.setValue(pass.getClipBias());
        clipBiasField.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent e) {
                pass.setClipBias(((Number) clipBiasField.getValue())
                        .floatValue());
            }
        });
        final GridBagConstraints gridBagConstraints_25 = new GridBagConstraints();
        gridBagConstraints_25.gridy = 3;
        gridBagConstraints_25.gridx = 1;
        wavesPanel.add(clipBiasField, gridBagConstraints_25);

        final JPanel buttonPanel = new JPanel();
        buttonPanel.setLayout(new GridBagLayout());
        final GridBagConstraints buttonBagConstraints = new GridBagConstraints();
        buttonBagConstraints.gridwidth = 2;
        buttonBagConstraints.gridy = 5;
        buttonBagConstraints.gridx = 0;
        add(buttonPanel, buttonBagConstraints);

        final JButton saveButton = new JButton();
        saveButton.addActionListener(new ActionListener() {

            public void actionPerformed(final ActionEvent e) {
                // find out what file to save to:
                JFileChooser chooser;
                if (lastDir != null)
                    chooser = new JFileChooser(lastDir);
                else
                    chooser = new JFileChooser();

                chooser.setMultiSelectionEnabled(false);
                int result = chooser.showSaveDialog(WaterPassEditor.this);
                if (result == JFileChooser.CANCEL_OPTION)
                    return;

                // save this dir as last opened
                lastDir = chooser.getCurrentDirectory();

                // store current as our new "go back" values.
                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.isUseProjectedShader();
                origWaterFog = pass.isUseFadeToFogColor();

                File file = chooser.getSelectedFile();
                Properties p = new Properties();
                p.put("clipBias", "" + origClipBias);
                p.put("heightFalloffSpeed", "" + origHeightFalloffSpeed);
                p.put("heightFalloffStart", "" + origHeightFalloffStart);
                p.put("speedReflection", "" + origSpeedReflection);
                p.put("speedRefraction", "" + origSpeedRefraction);
                p.put("waterColorEnd", "" + origWaterColorEnd.asIntARGB());
                p.put("waterColorStart", "" + origWaterColorStart.asIntARGB());
                p.put("waterHeight", "" + origWaterHeight);
                p.put("waterMaxAmplitude", "" + origWaterMaxAmplitude);
                p.put("useReflection", "" + origUseReflection);
                p.put("useRefraction", "" + origUseRefraction);
                p.put("useProjection", "" + origUseProjection);
                p.put("useWaterFog", "" + origWaterFog);
                try {
                    p.storeToXML(new FileOutputStream(file),
                            "Water properties.");
                } catch (Exception e1) {
                    logger.logp(Level.SEVERE, this.getClass().toString(),
                            "WaterPassEditor(pass)", "Exception", e1);
                }
            }
        });
        saveButton.setText("Export...");
        final GridBagConstraints gridBagConstraints_5 = new GridBagConstraints();
        gridBagConstraints_5.insets = new Insets(2, 2, 0, 4);
        gridBagConstraints_5.gridx = 0;
        gridBagConstraints_5.gridy = 0;
        buttonPanel.add(saveButton, gridBagConstraints_5);

        final JButton importButton = new JButton();
        importButton.addActionListener(new ActionListener() {
            public void actionPerformed(final ActionEvent e) {
                // find out what file to save to:
                JFileChooser chooser;
                if (lastDir != null)
                    chooser = new JFileChooser(lastDir);
                else
                    chooser = new JFileChooser();

                chooser.setMultiSelectionEnabled(false);
                int result = chooser.showOpenDialog(WaterPassEditor.this);
                if (result == JFileChooser.CANCEL_OPTION)
                    return;

                // save this dir as last opened
                lastDir = chooser.getCurrentDirectory();

                File file = chooser.getSelectedFile();
                Properties p = new Properties();
                try {
                    p.loadFromXML(new BufferedInputStream(new FileInputStream(
                            file)));
                } catch (Exception ex) {
                    logger.logp(Level.SEVERE, this.getClass().toString(),
                            "actionPerformed(ActionEvent e)", "Exception", ex);
                    return;
                }

                // read in our new values
                origClipBias = Float.parseFloat(p
                        .getProperty("clipBias", "0.0"));
                origHeightFalloffSpeed = Float.parseFloat(p.getProperty(
                        "heightFalloffSpeed", "0.0"));
                origHeightFalloffStart = Float.parseFloat(p.getProperty(
                        "heightFalloffStart", "0.0"));
                origSpeedReflection = Float.parseFloat(p.getProperty(
                        "speedReflection", "0.0"));
                origSpeedRefraction = Float.parseFloat(p.getProperty(
                        "speedRefraction", "0.0"));
                origWaterColorEnd.fromIntARGB(Integer.parseInt(p.getProperty(
                        "waterColorEnd", "0.0")));
                origWaterColorStart.fromIntARGB(Integer.parseInt(p.getProperty(
                        "waterColorStart", "0.0")));
                origWaterHeight = Float.parseFloat(p.getProperty("waterHeight",
                        "0.0"));
                origWaterMaxAmplitude = Float.parseFloat(p.getProperty(
                        "waterMaxAmplitude", "0.0"));
                origUseReflection = Boolean.parseBoolean(p.getProperty(
                        "useReflection", "true"));
                origUseRefraction = Boolean.parseBoolean(p.getProperty(
                        "useRefraction", "true"));
                origUseProjection = Boolean.parseBoolean(p.getProperty(
                        "useProjection", "true"));
                origWaterFog = Boolean.parseBoolean(p.getProperty(
                        "useWaterFog", "true"));

                // reapply to editor and in turn, to our pass
                revert(pass);
            }
        });
        importButton.setText("Import...");
        final GridBagConstraints gridBagConstraints_7 = new GridBagConstraints();
        gridBagConstraints_7.insets = new Insets(2, 4, 0, 2);
        gridBagConstraints_7.gridx = 1;
        gridBagConstraints_7.gridy = 0;
        buttonPanel.add(importButton, gridBagConstraints_7);

        final JButton resetButton = new JButton();
        final GridBagConstraints gridBagConstraints_6 = new GridBagConstraints();
        gridBagConstraints_6.insets = new Insets(2, 2, 2, 2);
        gridBagConstraints_6.gridwidth = 2;
        gridBagConstraints_6.gridx = 0;
        gridBagConstraints_6.gridy = 1;
        buttonPanel.add(resetButton, gridBagConstraints_6);
        resetButton.addActionListener(new ActionListener() {
            public void actionPerformed(final ActionEvent e) {
                revert(pass);
            }
        });
        resetButton.setText("Reset");
    }

    private void revert(final WaterRenderPass pass) {
        clipBiasField.setValue(origClipBias);
        falloffSpeedField.setValue(origHeightFalloffSpeed);
        falloffStartField.setValue(origHeightFalloffStart);
        reflectField.setValue(origSpeedReflection);
        refractField.setValue(origSpeedRefraction);
        baseHeightField.setValue(origWaterHeight);
        maxAmplitudeField.setValue(origWaterMaxAmplitude);
        enableReflectionBox.setSelected(origUseReflection);
        enableRefractionBox.setSelected(origUseRefraction);
        enableProjectionCheckBox.setSelected(origUseProjection);
        waterFoggingBox.setSelected(origWaterFog);
        startColorButton.updateColor();
        endColorButton.updateColor();
    }

    public static JFrame makeFrame(WaterRenderPass pass) {
        JFrame rVal = new JFrame("Water Settings");
        WaterPassEditor edit = new WaterPassEditor(pass);
        rVal.getContentPane().setLayout(new BorderLayout());
        rVal.getContentPane().add(edit, BorderLayout.CENTER);
        rVal.pack();
        return rVal;
    }
}

⌨️ 快捷键说明

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