View Javadoc
1 /* 2 * Created on Nov 20, 2003 3 */ 4 package portaview.view; 5 6 import java.awt.Dimension; 7 import java.awt.Graphics; 8 import java.awt.Graphics2D; 9 import java.awt.Image; 10 import java.awt.image.BufferedImage; 11 12 import javax.swing.JButton; 13 import javax.swing.JPanel; 14 import javax.swing.JSlider; 15 import javax.swing.event.ChangeEvent; 16 import javax.swing.event.ChangeListener; 17 18 import portaview.util.ImageUtils; 19 20 /*** 21 * Simple panel that shows preview for the settings used in the SettingsDialog. 22 * @author William Lee 23 */ 24 public class SettingsPreview extends JPanel implements ChangeListener 25 { 26 private BufferedImage image = null; 27 private JSlider borderSlider = null; 28 private JSlider transSlider = null; 29 private JButton colorButton = null; 30 31 private BufferedImage origImage = null; 32 private static final int PREVIEW_WIDTH = 160; 33 private static final int PREVIEW_HEIGHT = 128; 34 35 public SettingsPreview( 36 Image img, 37 JSlider bs, 38 JSlider ts, 39 JButton cbut) 40 { 41 this.borderSlider = bs; 42 this.transSlider = ts; 43 this.colorButton = cbut; 44 try 45 { 46 image = 47 ImageUtils.getBufferedImageInFrame( 48 ImageUtils.getBufferedImage(img, this), 49 PREVIEW_WIDTH, 50 PREVIEW_HEIGHT, 51 this); 52 } 53 catch (Exception e) 54 { 55 e.printStackTrace(); 56 } 57 setPreferredSize(new Dimension(image.getWidth(), image.getHeight())); 58 } 59 60 /*** 61 * Draws the preview graphics with all the effects. 62 */ 63 public void paintComponent(Graphics g) 64 { 65 super.paintComponent(g); 66 Graphics2D g2 = (Graphics2D) g; 67 image.createGraphics(); 68 g2.drawImage(image, 0, 0, this); 69 // tries to draw the border 70 ImageUtils.drawBorderRatio( 71 g2, 72 (transSlider.getValue() / 10.0F), 73 borderSlider.getValue(), 74 image.getWidth(), 75 image.getHeight(), 76 colorButton.getBackground()); 77 } 78 79 /*** 80 * Should update myself when things have changed. 81 * @see javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent) 82 */ 83 public void stateChanged(ChangeEvent e) 84 { 85 repaint(); 86 } 87 88 }

This page was automatically generated by Maven