001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.sql.framework.ui.zoom;
043:
044: import java.awt.Dimension;
045: import java.awt.FlowLayout;
046: import java.awt.event.ItemEvent;
047: import java.awt.event.ItemListener;
048: import java.beans.PropertyChangeEvent;
049: import java.beans.PropertyChangeListener;
050: import java.util.Vector;
051: import javax.swing.JComboBox;
052: import javax.swing.JPanel;
053: import org.netbeans.modules.etl.ui.DataObjectProvider;
054: import org.netbeans.modules.etl.ui.view.ETLCollaborationTopPanel;
055: import org.openide.windows.TopComponent;
056:
057: /**
058: * @author Ritesh Adval
059: */
060: public class ZoomComboBox extends JPanel implements
061: PropertyChangeListener {
062:
063: private ZoomSupport zoomableComponent;
064: private JComboBox zoomBox;
065: private double lastValue;
066: private static final Dimension COMBO_BOX_SIZE = new Dimension(60,
067: 20);
068: private static final Dimension ZOOM_PANEL_SIZE = new Dimension(70,
069: 25);
070:
071: /** Creates a new instance of ZoomComboBox */
072: public ZoomComboBox() {
073: this .setLayout(new FlowLayout(java.awt.FlowLayout.LEFT));
074:
075: zoomBox = new JComboBox(initializeValues());
076: zoomBox.setSelectedIndex(4);
077:
078: zoomBox.addItemListener(new ZoomFactorItemListener());
079:
080: zoomBox.setPreferredSize(COMBO_BOX_SIZE);
081: zoomBox.setSize(COMBO_BOX_SIZE);
082: this .add(zoomBox);
083: this .setMaximumSize(ZOOM_PANEL_SIZE);
084:
085: TopComponent.getRegistry().addPropertyChangeListener(this );
086: }
087:
088: private void createZoomValue(Vector<ZoomComboBox.ZoomValues> v,
089: String str, double val) {
090: ZoomValues zoomVal = new ZoomValues(str, val);
091: v.add(zoomVal);
092: }
093:
094: private Vector initializeValues() {
095: Vector<ZoomValues> vec = new Vector<ZoomValues>();
096: createZoomValue(vec, "400%", 4.0);
097: createZoomValue(vec, "300%", 3.0);
098: createZoomValue(vec, "200%", 2.0);
099: createZoomValue(vec, "150%", 1.5);
100: createZoomValue(vec, "100%", 1.0);
101: createZoomValue(vec, "75%", .75);
102: createZoomValue(vec, "66%", .66);
103: createZoomValue(vec, "50%", .50);
104: createZoomValue(vec, "33%", .33);
105: createZoomValue(vec, "25%", .25);
106: createZoomValue(vec, "Fit", 1.0);
107: return vec;
108: }
109:
110: /**
111: * This method gets called when a bound property is changed.
112: *
113: * @param evt A PropertyChangeEvent object describing the event source and the
114: * property that has changed.
115: */
116: public void propertyChange(PropertyChangeEvent evt) {
117: zoomBox.setEnabled(true);
118: }
119:
120: class ZoomFactorItemListener implements ItemListener {
121:
122: /**
123: * Invoked when an item has been selected or deselected by the user. The code
124: * written for this method performs the operations that need to occur when an item
125: * is selected (or deselected).
126: */
127: public void itemStateChanged(ItemEvent e) {
128: ZoomValues val = (ZoomValues) e.getItem();
129: if (zoomableComponent != null
130: && val.getValue() != lastValue) {
131: zoomableComponent.setZoomFactor(val.getValue());
132: }
133:
134: lastValue = val.getValue();
135: ETLCollaborationTopPanel topComp = null;
136: try {
137: topComp = DataObjectProvider.getProvider()
138: .getActiveDataObject().getETLEditorTopPanel();
139: topComp.setZoomFactor(lastValue);
140: } catch (Exception ex) {
141: // ignore
142: }
143: }
144: }
145:
146: class ZoomValues {
147:
148: private String displayValue;
149: private double value;
150:
151: ZoomValues(String displayValue, double value) {
152: this .displayValue = displayValue;
153: this .value = value;
154: }
155:
156: @Override
157: public String toString() {
158: return displayValue;
159: }
160:
161: public double getValue() {
162: return this.value;
163: }
164: }
165: }
|