1:package fr.limsi.dstour1; 2: 3:// Java standard library imports 4:import javax.swing.*; 5:import javax.swing.event.*; 6:import javax.swing.border.*; 7:import java.io.*; 8:import java.nio.*; 9:import java.awt.*; 10:import java.awt.geom.*; 11:import java.awt.event.*; 12:import java.awt.image.*; 13:import java.awt.color.*; 14:import java.util.*; 15:import java.net.*; 16: 17:// to make the link with diamondtouch and diamondSpin 18:import org.diamondspin.*; 19:import com.merl.diamondtouch.*; 20: 21:/** 22: * DSTour #1 demonstrate a simple dsframe 23: * 24: * @author vernier 25: * @version 1.0 26: */ 27:public class DSTApplication extends DSApplication { 28: protected Properties prop = new Properties(); 29: private DSDefaultView view = null; 30: private DSContainer cont = null; 31: 32: 33: /** 34: * Main entry point of a java application. args ar not used 35: * 36: * @param argv The command line arguments 37: */ 38: public static void main(String[] argv) { 39: new DSTApplication(argv); 40: } 41: 42: 43: // the object of this dstour 44: protected DSFrame dsFrame1 = null; 45: 46: 47: /** 48: * Constructor for the DSTApplication object 49: * 50: * @param argv Description of the Parameter 51: */ 52: protected DSTApplication(String[] argv) { 53: displayInfos(); 54: 55: loadProperties(); 56: 57: // create the DSContainer and initialize it with the standard DSApplication method 58: cont = new DSContainer(); 59: 60: // ... from my father ! 61: init(cont, false); 62: 63: // create a view to put the dsframe on something 64: view = new DSDefaultView(cont); 65: 66: // Change the default background 67: URL bgloc = cont.getClass().getResource("/images/Background5.jpg"); 68: if (bgloc != null) { 69: Image bg = cont.scaleImageForBackground((new ImageIcon(bgloc)).getImage()); 70: view.setBackground(bg); 71: } 72: 73: // Activate the view 74: cont.setActiveView(view); 75: 76: // get stuff to fill the dsframe like a turkey 77: JRadioButton centeredButton = new JRadioButton("CENTERED"); 78: JRadioButton rotatedButton = new JRadioButton("ROTATED"); 79: JRadioButton shiftedButton = new JRadioButton("SHIFTED", true); 80: ButtonGroup ButtonGroup1 = new ButtonGroup(); 81: ButtonGroup1.add(centeredButton); 82: ButtonGroup1.add(rotatedButton); 83: ButtonGroup1.add(shiftedButton); 84: centeredButton.addActionListener( 85: new ActionListener() { 86: public void actionPerformed(ActionEvent e) { 87: dsFrame1.setBehavior(DSFrame.CENTERED); 88: } 89: }); 90: rotatedButton.addActionListener( 91: new ActionListener() { 92: public void actionPerformed(ActionEvent e) { 93: dsFrame1.setBehavior(DSFrame.ROTATED); 94: } 95: }); 96: shiftedButton.addActionListener( 97: new ActionListener() { 98: public void actionPerformed(ActionEvent e) { 99: dsFrame1.setBehavior(DSFrame.SHIFTED); 100: } 101: }); 102: 103: JPanel jPanel1 = new JPanel(); 104: jPanel1.setLayout(new BorderLayout()); 105: jPanel1.add(rotatedButton, BorderLayout.WEST); 106: jPanel1.add(centeredButton, BorderLayout.CENTER); 107: jPanel1.add(shiftedButton, BorderLayout.EAST); 108: JTextField jTextField = new JTextField("DS Tour #1"); 109: jTextField.setEditable(false); 110: 111: JTextArea jTextArea = new JTextArea("DS Tour #1by Guillaume Besacier &\n" + 112: " Frederic Vernier (LIMSI-CNRS)\n\n Shows three drag behaviors of the elements"); 113: 114: jTextArea.setBorder(new EtchedBorder(Color.GREEN, Color.GRAY)); 115: 116: // make THE dsframe 117: dsFrame1 = new DSFrame("DSFrame", cont); 118: 119: // add it to the view (ds world addition) 120: view.addDSElement(dsFrame1); 121: 122: // add it to container (swing world addition) 123: cont.add(dsFrame1); 124: 125: // set parameters of the dsframe 126: dsFrame1.setAlpha(-(float)Math.PI / 2); 127: dsFrame1.getContentPane().add(jTextField, BorderLayout.NORTH); 128: dsFrame1.getContentPane().add(jTextArea, BorderLayout.CENTER); 129: dsFrame1.getContentPane().add(jPanel1, BorderLayout.SOUTH); 130: dsFrame1.setClosable(true); 131: dsFrame1.addInternalFrameListener( 132: new InternalFrameAdapter() { 133: public void internalFrameClosed(InternalFrameEvent e) { 134: super.internalFrameClosed(e); 135: System.exit(0); 136: } 137: }); 138: 139: dsFrame1.pack(); 140: dsFrame1.setVisible(true); 141: 142: // let's start a full resize to take into account all the changes 143: cont.repaintAll(); 144: } // Constructor 145: 146: 147: /** 148: * Load the properties of the application in a property file shared with the ant script 149: */ 150: protected void loadProperties() { 151: try { 152: File f = new File("properties/properties_dstour1"); 153: System.out.println("Using property file :" + f); 154: 155: if (f.exists()) { 156: FileInputStream fis = new FileInputStream(f); 157: prop.load(fis); 158: fis.close(); 159: } else { 160: prop.setProperty("Application.Name", "DSTour1"); 161: prop.setProperty("Application.Version", "1.0"); 162: prop.setProperty("Application.Build", "0001"); 163: FileOutputStream fos = new FileOutputStream(f); 164: prop.store(fos, "Values of the parameters of the application"); 165: fos.close(); 166: } 167: } catch (IOException e) { 168: e.printStackTrace(); 169: } 170: }// loadProperties() 171:} 172: 173: