Package org.apache.batik.apps.svgbrowser

Source Code of org.apache.batik.apps.svgbrowser.JPEGOptionPanel

/*

   Copyright 2001-2003  The Apache Software Foundation

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

*/
package org.apache.batik.apps.svgbrowser;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.Hashtable;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JSlider;

import org.apache.batik.util.gui.ExtendedGridBagConstraints;

/**
* This class represents a panel to control jpeg encoding quality.
*
* @author <a href="mailto:tkormann@apache.org">Thierry Kormann</a>
* @version $Id: JPEGOptionPanel.java,v 1.5 2004/08/18 07:12:27 vhardy Exp $
*/
public class JPEGOptionPanel extends OptionPanel {
    /**
     * The jpeg encoding quality.
     */
    protected JSlider quality;

    /**
     * Creates a new panel.
     */
    public JPEGOptionPanel() {
  super(new GridBagLayout());

  ExtendedGridBagConstraints constraints =
      new ExtendedGridBagConstraints();

 
  constraints.insets = new Insets(5, 5, 5, 5);

  constraints.weightx = 0;
  constraints.weighty = 0;
  constraints.fill = GridBagConstraints.NONE;
  constraints.setGridBounds(0, 0, 1, 1);
  add(new JLabel(resources.getString("JPEGOptionPanel.label")),
      constraints);

  quality = new JSlider();
  quality.setMinimum(0);
  quality.setMaximum(100);
  quality.setMajorTickSpacing(10);
  quality.setMinorTickSpacing(5);
  quality.setPaintTicks(true);
  quality.setPaintLabels(true);
  quality.setBorder(BorderFactory.createEmptyBorder(0,0,10,0));
  Hashtable labels = new Hashtable();
  for (int i=0; i < 100; i+=10) {
      labels.put(new Integer(i), new JLabel("0."+i/10));
  }
  labels.put(new Integer(100), new JLabel("1"));
  quality.setLabelTable(labels);

  Dimension dim = quality.getPreferredSize();
  quality.setPreferredSize(new Dimension(350, dim.height));

  constraints.weightx = 1.0;
  constraints.fill = GridBagConstraints.HORIZONTAL;
  constraints.setGridBounds(1, 0, 1, 1);
  add(quality, constraints);
    }

    /**
     * Returns the jpeg quality.
     */
    public float getQuality() {
  return quality.getValue()/100f;
    }

    /**
     * Shows a dialog to choose the jpeg encoding quality and return
     * the quality as a float. 
     */
    public static float showDialog(Component parent) {
        String title = resources.getString("JPEGOptionPanel.dialog.title");
        JPEGOptionPanel panel = new JPEGOptionPanel();
  Dialog dialog = new Dialog(parent, title, panel);
  dialog.pack();
  dialog.show();
  return panel.getQuality();
    }
}
TOP

Related Classes of org.apache.batik.apps.svgbrowser.JPEGOptionPanel

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.