KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > apps > svgbrowser > JPEGOptionPanel


1 /*
2
3    Copyright 2001-2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.apps.svgbrowser;
19
20 import java.awt.Component JavaDoc;
21 import java.awt.Dimension JavaDoc;
22 import java.awt.GridBagConstraints JavaDoc;
23 import java.awt.GridBagLayout JavaDoc;
24 import java.awt.Insets JavaDoc;
25 import java.util.Hashtable JavaDoc;
26
27 import javax.swing.BorderFactory JavaDoc;
28 import javax.swing.JLabel JavaDoc;
29 import javax.swing.JSlider JavaDoc;
30
31 import org.apache.batik.util.gui.ExtendedGridBagConstraints;
32
33 /**
34  * This class represents a panel to control jpeg encoding quality.
35  *
36  * @author <a HREF="mailto:tkormann@apache.org">Thierry Kormann</a>
37  * @version $Id: JPEGOptionPanel.java,v 1.5 2004/08/18 07:12:27 vhardy Exp $
38  */

39 public class JPEGOptionPanel extends OptionPanel {
40     /**
41      * The jpeg encoding quality.
42      */

43     protected JSlider JavaDoc quality;
44
45     /**
46      * Creates a new panel.
47      */

48     public JPEGOptionPanel() {
49     super(new GridBagLayout JavaDoc());
50
51     ExtendedGridBagConstraints constraints =
52         new ExtendedGridBagConstraints();
53
54     
55     constraints.insets = new Insets JavaDoc(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 JavaDoc(resources.getString("JPEGOptionPanel.label")),
62         constraints);
63
64     quality = new JSlider JavaDoc();
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 JavaDoc labels = new Hashtable JavaDoc();
73     for (int i=0; i < 100; i+=10) {
74         labels.put(new Integer JavaDoc(i), new JLabel JavaDoc("0."+i/10));
75     }
76     labels.put(new Integer JavaDoc(100), new JLabel JavaDoc("1"));
77     quality.setLabelTable(labels);
78
79     Dimension JavaDoc dim = quality.getPreferredSize();
80     quality.setPreferredSize(new Dimension JavaDoc(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     /**
89      * Returns the jpeg quality.
90      */

91     public float getQuality() {
92     return quality.getValue()/100f;
93     }
94
95     /**
96      * Shows a dialog to choose the jpeg encoding quality and return
97      * the quality as a float.
98      */

99     public static float showDialog(Component JavaDoc parent) {
100         String JavaDoc 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