001package jmri.jmrix.rps.swing; 002 003import java.awt.GridLayout; 004import java.awt.event.ActionEvent; 005import java.awt.event.ActionListener; 006import java.awt.geom.AffineTransform; 007import javax.swing.BoxLayout; 008import javax.swing.JButton; 009import javax.swing.JLabel; 010import javax.swing.JPanel; 011import javax.swing.JTextField; 012 013/** 014 * Panel for entry and modifiation of an Affine Transform. 015 * 016 * @author Bob Jacobsen Copyright (C) 2008 017 */ 018public class AffineEntryPanel extends javax.swing.JPanel { 019 020 JTextField m00 = new JTextField(8); 021 JTextField m01 = new JTextField(8); 022 JTextField m02 = new JTextField(8); 023 JTextField m10 = new JTextField(8); 024 JTextField m11 = new JTextField(8); 025 JTextField m12 = new JTextField(8); 026 027 public AffineEntryPanel() { 028 super(); 029 030 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); 031 032 JPanel p = new JPanel(); 033 p.setLayout(new GridLayout(3, 3)); 034 035 p.add(new JLabel("X")); 036 p.add(new JLabel("Y")); 037 p.add(new JLabel("Offset")); 038 039 p.add(m00); 040 p.add(m01); 041 p.add(m02); 042 043 p.add(m10); 044 p.add(m11); 045 p.add(m12); 046 047 add(p); 048 049 JButton b = new JButton("Set"); 050 b.addActionListener(new ActionListener() { 051 @Override 052 public void actionPerformed(ActionEvent event) { 053 update(); 054 } 055 }); 056 add(b); 057 058 // init transform 059 m00.setText("1."); 060 m11.setText("1."); 061 m01.setText("0."); 062 m02.setText("0."); 063 m10.setText("0."); 064 m12.setText("0."); 065 update(); 066 } 067 068 /** 069 * Load GIU to transform 070 */ 071 void update() { 072 AffineTransform oldt = t; 073 double v00 = Double.parseDouble(m00.getText()); 074 double v01 = Double.parseDouble(m01.getText()); 075 double v02 = Double.parseDouble(m02.getText()); 076 double v10 = Double.parseDouble(m10.getText()); 077 double v11 = Double.parseDouble(m11.getText()); 078 double v12 = Double.parseDouble(m12.getText()); 079 t = new AffineTransform(v00, v10, v01, v11, v02, v12); 080 firePropertyChange("value", oldt, t); 081 } 082 083 public AffineTransform getTransform() { 084 return t; 085 } 086 087 public void setTransform(AffineTransform tnew) { 088 m00.setText("" + tnew.getScaleX()); 089 m11.setText("" + tnew.getScaleY()); 090 091 m01.setText("" + tnew.getShearX()); 092 m10.setText("" + tnew.getShearY()); 093 094 m02.setText("" + tnew.getTranslateX()); 095 m12.setText("" + tnew.getTranslateY()); 096 update(); 097 } 098 099 AffineTransform t = new AffineTransform(); 100 101}