All Downloads are FREE. Search and download functionalities are using the official Maven repository.

uk.org.okapibarcode.gui.SaveSymbol Maven / Gradle / Ivy

Go to download

An open-source barcode generator written entirely in Java, supporting over 50 encoding standards including all ISO standards.

There is a newer version: 0.5.1
Show newest version
/*
 * Copyright 2014 Robin Stuart
 *
 * 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 uk.org.okapibarcode.gui;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;

import javax.swing.JPanel;

import uk.org.okapibarcode.output.Java2DRenderer;

/**
 * Draw symbol in "invisible" panel for saving to file.
 *
 * @author Robin Stuart
 */
public class SaveSymbol extends JPanel {

    /** Serial version UID. */
    private static final long serialVersionUID = 8948804628452979514L;

    private int magnification = 4;
    private int margin = 5 * magnification;

    public void setMagnification(int factor) {
        magnification = factor * 4;
    }

    public void setMargin(int margin) {
        this.margin = margin;
    }

    /** {@inheritDoc} */
    @Override
    public Dimension getPreferredSize() {
        final int w = (OkapiUI.symbol.getWidth() * magnification) + (2 * margin);
        final int h = (OkapiUI.symbol.getHeight() * magnification) + (2 * margin);
        return new Dimension(w, h);
    }

    /** {@inheritDoc} */
    @Override
    protected void paintComponent(Graphics g) {

        setBackground(OkapiUI.paperColour);
        super.paintComponent(g);

        Graphics2D g2d = (Graphics2D) g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        Java2DRenderer renderer = new Java2DRenderer(g2d, magnification, margin, OkapiUI.paperColour, OkapiUI.inkColour);
        renderer.render(OkapiUI.symbol);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy