Package org.bric.gui.tabs

Source Code of org.bric.gui.tabs.OutputJPanel

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.bric.gui.tabs;

import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JSlider;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.SpinnerModel;
import javax.swing.SpinnerNumberModel;
import org.bric.gui.BricUI;
import org.bric.imageEditParameters.OutputParameters;
import org.bric.utils.Utils;

/**
*
* @author vasilis
*/
public class OutputJPanel extends javax.swing.JPanel implements ImageEditTab{
    /**
     * Creates new form OutputJPanel
     */
    public OutputJPanel() {
        initComponents();
       
        SpinnerModel numbering = new SpinnerNumberModel(1, null, null, 1);
        startIndexSpinner.setModel(numbering);
       
        SpinnerModel horizontal = new SpinnerNumberModel(300, 10, 1000, 1);
        SpinnerModel vertical = new SpinnerNumberModel(300, 10, 1000, 1);
        jSpinner2.setModel(horizontal);
        jSpinner3.setModel(vertical);
       
        jLabel6.setVisible(false);
        jLabel7.setVisible(false);
        jLabel8.setVisible(false);
        jSpinner2.setVisible(false);
        jSpinner3.setVisible(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        outputPathText = new javax.swing.JTextField();
        jButton4 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        fileTypeCombo = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        startIndexSpinner = new javax.swing.JSpinner();
        jLabel5 = new javax.swing.JLabel();
        qualitySlider = new javax.swing.JSlider();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTextPane2 = new javax.swing.JTextPane();
        jLabel6 = new javax.swing.JLabel();
        jSpinner2 = new javax.swing.JSpinner();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jSpinner3 = new javax.swing.JSpinner();

        outputPathText.setText(System.getProperty("user.home"));

        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("lang/gui/tabs/Bundle"); // NOI18N
        jButton4.setText(bundle.getString("OutputJPanel.jButton4.text")); // NOI18N
        jButton4.setToolTipText(bundle.getString("OutputJPanel.jButton4.toolTipText")); // NOI18N
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jLabel3.setText(bundle.getString("OutputJPanel.jLabel3.text")); // NOI18N

        fileTypeCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "SAME AS FIRST", "JPG", "JPEG", "PNG", "GIF", "BMP", "TIF", "TIFF", "PGM", "PBM", "PNM", "PPM", "PDF" }));
        fileTypeCombo.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                fileTypeComboItemStateChanged(evt);
            }
        });

        jLabel4.setText(bundle.getString("OutputJPanel.jLabel4.text")); // NOI18N

        jLabel5.setText(bundle.getString("OutputJPanel.jLabel5.text")); // NOI18N

        qualitySlider.setMajorTickSpacing(10);
        qualitySlider.setMinorTickSpacing(5);
        qualitySlider.setPaintLabels(true);
        qualitySlider.setPaintTicks(true);
        qualitySlider.setValue(100);
        qualitySlider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                qualitySliderStateChanged(evt);
            }
        });

        jTextPane2.setContentType("text/html"); // NOI18N
        jTextPane2.setEditable(false);
        java.util.ResourceBundle bundle1 = java.util.ResourceBundle.getBundle("lang/gui/Bundle"); // NOI18N
        jTextPane2.setText(bundle1.getString("OutputJPanel.jTextPane2.text")); // NOI18N
        jScrollPane3.setViewportView(jTextPane2);

        jLabel6.setText(bundle.getString("OutputJPanel.jLabel6.text")); // NOI18N

        jLabel7.setText(bundle.getString("OutputJPanel.jLabel7.text")); // NOI18N

        jLabel8.setText(bundle.getString("OutputJPanel.jLabel8.text")); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(outputPathText)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 191, Short.MAX_VALUE)
                        .addComponent(fileTypeCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(startIndexSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(qualitySlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 366, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jSpinner2, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jLabel8)
                        .addGap(18, 18, 18)
                        .addComponent(jSpinner3, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(outputPathText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(fileTypeCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(startIndexSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jSpinner2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jSpinner3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(qualitySlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        JFileChooser chooser = new JFileChooser(BricUI.lastOpenedDirectory);
        Utils.setFileChooserProperties(chooser);
        if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) {
            return;
        }
        outputPathText.setText(chooser.getSelectedFile().getPath() + Utils.FS);
        BricUI.lastOpenedDirectory = chooser.getSelectedFile().getPath();
    }//GEN-LAST:event_jButton4ActionPerformed

    private void fileTypeComboItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_fileTypeComboItemStateChanged
        boolean qualityEnable = fileTypeCombo.getSelectedIndex() <= 2 ? true : false;
        jLabel5.setEnabled(qualityEnable);
        qualitySlider.setEnabled(qualityEnable);
        jLabel6.setEnabled(qualityEnable);
        jLabel7.setEnabled(qualityEnable);
        jLabel8.setEnabled(qualityEnable);
        jSpinner2.setEnabled(qualityEnable);
        jSpinner3.setEnabled(qualityEnable);
    }//GEN-LAST:event_fileTypeComboItemStateChanged

    private void qualitySliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_qualitySliderStateChanged
        jLabel5.setText(String.format("Quality: %s%%", qualitySlider.getValue()));
    }//GEN-LAST:event_qualitySliderStateChanged

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox fileTypeCombo;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSpinner jSpinner2;
    private javax.swing.JSpinner jSpinner3;
    private javax.swing.JTextPane jTextPane2;
    private javax.swing.JTextField outputPathText;
    private javax.swing.JSlider qualitySlider;
    private javax.swing.JSpinner startIndexSpinner;
    // End of variables declaration//GEN-END:variables

    public int getFileTypeComboIndex() {
        return fileTypeCombo.getSelectedIndex();
    }

    public void setFileTypeComboIndex(String index) {
        this.fileTypeCombo.setSelectedIndex(Integer.parseInt(index));
    }

    public String getOutputPathText() {
        return outputPathText.getText();
    }

    public void setOutputPathText(String outputPathText) {
        this.outputPathText.setText(outputPathText);
    }

    public int getQualitySliderValue() {
        return qualitySlider.getValue();
    }

    public void setQualitySliderValue(String value) {
        this.qualitySlider.setValue(Integer.parseInt(value));
    }

    public int getStartIndexSpinnerValue() {
        return Integer.parseInt(startIndexSpinner.getValue().toString());
    }

    public void setStartIndexSpinnerValue(int startIndex) {
        this.startIndexSpinner.getModel().setValue(startIndex);
    }

    @Override
    public OutputParameters getImageEditParameters() {
        OutputParameters outputParameters = new OutputParameters();
        outputParameters.setOutputPath(outputPathText.getText());
        outputParameters.setQuality((float)qualitySlider.getValue()/100);
        outputParameters.setOutputFormat(fileTypeCombo.getSelectedItem().toString());
        outputParameters.setNumberingStartIndex((Integer)startIndexSpinner.getValue());
//        outputParameters.setDpiHorizontal((Integer) jSpinner2.getValue());
//        outputParameters.setDpiVertical((Integer) jSpinner3.getValue());
        return outputParameters;
    }
}
TOP

Related Classes of org.bric.gui.tabs.OutputJPanel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.