TIMPaletteCheck.java :  » Media » jpsxdec » jpsxdec » Java Open Source

Java Open Source » Media » jpsxdec 
jpsxdec » jpsxdec » TIMPaletteCheck.java
/*
 * jPSXdec: Playstation 1 Media Decoder/Converter in Java
 * Copyright (C) 2007-2008  Michael Sabin
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor,   
 * Boston, MA  02110-1301, USA.
 *
 */

/*
 * TIMPaletteCheck.java
 */

package jpsxdec;

import java.awt.Graphics;
import java.awt.image.BufferedImage;

public class TIMPaletteCheck extends javax.swing.JPanel {
    
    BufferedImage m_obi;
    
    /** Creates new form TIMPaletteCheck */
    public TIMPaletteCheck(BufferedImage bi, int i) {
        initComponents();
        
        m_obi = bi;
        chkNum.setText(Integer.toString(i));
    }

    @Override
    protected void paintChildren(Graphics g) {
        int iWidth = this.getWidth() - 4;
        int iHeight = this.getHeight() - 4;
        
        double dblHScale = iWidth / (double)m_obi.getWidth();
        double dblVScale = iHeight / (double)m_obi.getHeight();
        
        double dblScale;
        if (dblHScale < dblVScale)
            dblScale = dblHScale;
        else
            dblScale = dblVScale;
        
        if (dblScale > 2) dblScale = 2;
        
        iWidth = (int)(m_obi.getWidth() * dblScale);
        iHeight = (int)(m_obi.getHeight() * dblScale);
        
        g.drawImage(m_obi, 1, 1, iWidth, iHeight, null);
        
        super.paintChildren(g);
    }

    void setChecked(boolean b) {
        chkNum.getModel().setSelected(b);
    }
    
    public boolean getChecked() {
        return chkNum.getModel().isSelected();
    }
    
    
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        chkNum = new javax.swing.JCheckBox();

        setBorder(javax.swing.BorderFactory.createEtchedBorder());
        setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        chkNum.setSelected(true);
        chkNum.setText("##");
        chkNum.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        chkNum.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
        chkNum.setMargin(new java.awt.Insets(0, 0, 0, 0));
        add(chkNum);
    }// </editor-fold>//GEN-END:initComponents
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox chkNum;
    // End of variables declaration//GEN-END:variables
    
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.