001 /**
002 * Copyright (c) 2009, Piet Blok
003 * All rights reserved.
004 *
005 * Redistribution and use in source and binary forms, with or without
006 * modification, are permitted provided that the following conditions
007 * are met:
008 *
009 * * Redistributions of source code must retain the above copyright
010 * notice, this list of conditions and the following disclaimer.
011 * * Redistributions in binary form must reproduce the above
012 * copyright notice, this list of conditions and the following
013 * disclaimer in the documentation and/or other materials provided
014 * with the distribution.
015 * * Neither the name of the copyright holder nor the names of the
016 * contributors may be used to endorse or promote products derived
017 * from this software without specific prior written permission.
018 *
019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
020 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
021 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
022 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
023 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
024 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
025 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
026 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
027 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
028 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
029 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
030 */
031
032 package org.pbjar.jxlayer.demo;
033
034 import java.awt.RenderingHints;
035 import java.util.Map;
036
037 import javax.swing.JComponent;
038
039 import org.jdesktop.jxlayer.JXLayer;
040 import org.pbjar.jxlayer.plaf.ext.TransformUI;
041 import org.pbjar.jxlayer.plaf.ext.transform.DefaultTransformModel;
042 import org.pbjar.jxlayer.plaf.ext.transform.TransformModel;
043
044 /**
045 * Some convenience methods to create a populated transforming {@link JXLayer}.
046 *
047 * @author Piet Blok
048 */
049 public class TransformUtils {
050
051 public static JXLayer<JComponent> createTransformJXLayer(
052 JComponent component) {
053 return createTransformJXLayer(component, 1.0, null);
054 }
055
056 public static JXLayer<JComponent> createTransformJXLayer(
057 JComponent component, double scale) {
058 return createTransformJXLayer(component, scale, null);
059 }
060
061 public static JXLayer<JComponent> createTransformJXLayer(
062 JComponent component, double scale, Map<RenderingHints.Key, Object> hints) {
063 DefaultTransformModel model = new DefaultTransformModel();
064 model.setScale(scale);
065 return createTransformJXLayer(component, model, hints);
066 }
067
068 public static JXLayer<JComponent> createTransformJXLayer(
069 JComponent component, TransformModel model) {
070 return createTransformJXLayer(component, model, null);
071 }
072
073 public static JXLayer<JComponent> createTransformJXLayer(
074 JComponent component, TransformModel model,
075 Map<RenderingHints.Key, Object> hints) {
076 TransformUI ui = new TransformUI(model);
077 ui.setRenderingHints(hints);
078 return new JXLayer<JComponent>(component, ui);
079 }
080
081 private TransformUtils() {
082 }
083
084 }