1 18 package org.apache.batik.apps.svgbrowser; 19 20 import java.awt.Component ; 21 import java.awt.Dimension ; 22 import java.awt.GridBagConstraints ; 23 import java.awt.GridBagLayout ; 24 import java.awt.Insets ; 25 import java.util.Hashtable ; 26 27 import javax.swing.BorderFactory ; 28 import javax.swing.JLabel ; 29 import javax.swing.JSlider ; 30 31 import org.apache.batik.util.gui.ExtendedGridBagConstraints; 32 33 39 public class JPEGOptionPanel extends OptionPanel { 40 43 protected JSlider quality; 44 45 48 public JPEGOptionPanel() { 49 super(new GridBagLayout ()); 50 51 ExtendedGridBagConstraints constraints = 52 new ExtendedGridBagConstraints(); 53 54 55 constraints.insets = new Insets (5, 5, 5, 5); 56 57 constraints.weightx = 0; 58 constraints.weighty = 0; 59 constraints.fill = GridBagConstraints.NONE; 60 constraints.setGridBounds(0, 0, 1, 1); 61 add(new JLabel (resources.getString("JPEGOptionPanel.label")), 62 constraints); 63 64 quality = new JSlider (); 65 quality.setMinimum(0); 66 quality.setMaximum(100); 67 quality.setMajorTickSpacing(10); 68 quality.setMinorTickSpacing(5); 69 quality.setPaintTicks(true); 70 quality.setPaintLabels(true); 71 quality.setBorder(BorderFactory.createEmptyBorder(0,0,10,0)); 72 Hashtable labels = new Hashtable (); 73 for (int i=0; i < 100; i+=10) { 74 labels.put(new Integer (i), new JLabel ("0."+i/10)); 75 } 76 labels.put(new Integer (100), new JLabel ("1")); 77 quality.setLabelTable(labels); 78 79 Dimension dim = quality.getPreferredSize(); 80 quality.setPreferredSize(new Dimension (350, dim.height)); 81 82 constraints.weightx = 1.0; 83 constraints.fill = GridBagConstraints.HORIZONTAL; 84 constraints.setGridBounds(1, 0, 1, 1); 85 add(quality, constraints); 86 } 87 88 91 public float getQuality() { 92 return quality.getValue()/100f; 93 } 94 95 99 public static float showDialog(Component parent) { 100 String title = resources.getString("JPEGOptionPanel.dialog.title"); 101 JPEGOptionPanel panel = new JPEGOptionPanel(); 102 Dialog dialog = new Dialog(parent, title, panel); 103 dialog.pack(); 104 dialog.show(); 105 return panel.getQuality(); 106 } 107 } 108 | Popular Tags |