1:package fr.limsi.dstour2;
   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: * DS Tour #2 demonstrate dsView1 capabilities
  23: * 
  24: * 
  25: * @author vernier
  26: * @version 1.0
  27: */
  28:public class DSTApplication extends DSApplication {
  29:
  30:  protected       Properties      props         = new Properties();
  31:  protected       DSContainer     dsContainer1  = null;
  32:
  33:  // the object of this ds tour
  34:  protected       DSFrame         dsFrame1      = null;
  35:  protected       DSDefaultView   dsView1       = null; 
  36:
  37:  
  38:  /**
  39:   * Main entry point of a java application. args are not used
  40:   *
  41:   * @param argv  The command line arguments
  42:   */
  43:  public static void main(String[] argv) {
  44:    new DSTApplication(argv);
  45:  }
  46: 
  47:  
  48:  /**
  49:   * Constructor for the DSTApplication object
  50:   *
  51:   * @param argv  Description of the Parameter
  52:   */
  53:  protected DSTApplication(String[] argv) {
  54:    displayInfos();
  55:    loadProperties();
  56:
  57:    // create the DSContainer and initialize it with the standard DSApplication method
  58:    dsContainer1 = new DSContainer();
  59:
  60:    // ... from my father !
  61:    init(dsContainer1, false);
  62:
  63:    // create a dsView1 to put the dsframe on something
  64:    dsView1 = new DSDefaultView(dsContainer1);
  65:
  66:    // Change the default background with a very big image (not resized)
  67:    URL           bgloc             = dsContainer1.getClass().getResource("/images/Background5.jpg");
  68:    if (bgloc != null) {
  69:      dsView1.setBackground(new ImageIcon(bgloc).getImage());
  70:    }
  71:    
  72:    // Activate the dsView1
  73:    dsContainer1.setActiveView(dsView1); 
  74:
  75:    JRadioButton  nothingdButton    = new JRadioButton("NOTHING", true);
  76:    JRadioButton  demodeButton      = new JRadioButton("DEMOTE");
  77:    JRadioButton  panbckgrndButton  = new JRadioButton("PAN BACKGROUND");
  78:    JRadioButton  panviewButton     = new JRadioButton("PAN VIEW");
  79:    JRadioButton  rotateButton      = new JRadioButton("ROTATE");
  80:    JRadioButton  drawButton        = new JRadioButton("DRAW");
  81:    JRadioButton  annotateButton    = new JRadioButton("ANNOTATE");
  82:
  83:    ButtonGroup   buttonGroup1      = new ButtonGroup();
  84:    buttonGroup1.add(nothingdButton);
  85:    buttonGroup1.add(demodeButton);
  86:    buttonGroup1.add(panbckgrndButton);
  87:    buttonGroup1.add(panviewButton);
  88:    buttonGroup1.add(rotateButton);
  89:    buttonGroup1.add(drawButton);
  90:    buttonGroup1.add(annotateButton);
  91:
  92:    nothingdButton.addActionListener(
  93:      new ActionListener() {
  94:        public void actionPerformed(ActionEvent e) {
  95:          dsView1.setDragMode(DSDefaultView.NOTHING_MODE);
  96:        }
  97:      });
  98:    demodeButton.addActionListener(
  99:      new ActionListener() {
 100:        public void actionPerformed(ActionEvent e) {
 101:          dsView1.setDragMode(DSDefaultView.DEMOTE_MODE);
 102:        }
 103:      });
 104:    panbckgrndButton.addActionListener(
 105:      new ActionListener() {
 106:        public void actionPerformed(ActionEvent e) {
 107:          dsView1.setDragMode(DSDefaultView.PANBCKGRND_MODE);
 108:        }
 109:      });
 110:    panviewButton.addActionListener(
 111:      new ActionListener() {
 112:        public void actionPerformed(ActionEvent e) {
 113:          dsView1.setDragMode(DSDefaultView.PANVIEW_MODE);
 114:        }
 115:      });
 116:    rotateButton.addActionListener(
 117:      new ActionListener() {
 118:        public void actionPerformed(ActionEvent e) {
 119:          dsView1.setDragMode(DSDefaultView.ROTATE_MODE);
 120:        }
 121:      });
 122:    drawButton.addActionListener(
 123:      new ActionListener() {
 124:        public void actionPerformed(ActionEvent e) {
 125:          dsView1.setDragMode(DSDefaultView.DRAW_MODE);
 126:        }
 127:      });
 128:    annotateButton.addActionListener(
 129:      new ActionListener() {
 130:        public void actionPerformed(ActionEvent e) {
 131:          dsView1.setDragMode(DSDefaultView.ANNOTATE_MODE);
 132:        }
 133:      });
 134:
 135:    JPanel        jPanel1           = new JPanel();
 136:    jPanel1.setLayout(new GridLayout(3, 3));
 137:    jPanel1.add(nothingdButton);
 138:    jPanel1.add(demodeButton);
 139:    jPanel1.add(panbckgrndButton);
 140:    jPanel1.add(panviewButton);
 141:    jPanel1.add(rotateButton);
 142:    jPanel1.add(drawButton);
 143:    jPanel1.add(annotateButton);
 144:    JTextField    jTextField        = new JTextField("DS Tour #2");
 145:    jTextField.setEditable(false);
 146:
 147:    JTextArea     jTextArea         = new JTextArea("DS Tour #2 by Guillaume Besacier &\n" +
 148:      " Frederic Vernier (LIMSI-CNRS)\n\n Shows all the drag behaviors of the views");
 149:
 150:    jTextArea.setBorder(new EtchedBorder(Color.GREEN, Color.GRAY));
 151:
 152:    // make THE dsframe
 153:    dsFrame1 = new DSFrame("DSFrame", dsContainer1);
 154:    
 155:    // add it to the dsView1 (ds world addition)
 156:    dsView1.addDSElement(dsFrame1);
 157:    
 158:    // add it to container (swing world addition)
 159:    dsContainer1.add(dsFrame1);
 160:    
 161:    // set parameters of the dsframe
 162:    dsFrame1.setAlpha(-(float)Math.PI / 2);
 163:    dsFrame1.getContentPane().add(jTextField, BorderLayout.NORTH);
 164:    dsFrame1.getContentPane().add(jTextArea, BorderLayout.CENTER);
 165:    dsFrame1.getContentPane().add(jPanel1, BorderLayout.SOUTH);
 166:    dsFrame1.setVisible(true);
 167:    dsFrame1.setAlpha(-(float)Math.PI / 2);
 168:    dsFrame1.setClosable(true);
 169:    dsFrame1.addInternalFrameListener(
 170:      new InternalFrameAdapter() {
 171:        public void internalFrameClosed(InternalFrameEvent e) {
 172:          super.internalFrameClosed(e);
 173:          System.exit(0);
 174:        }
 175:      });
 176:
 177:    dsFrame1.pack();
 178:    // center point will stick to the center when it get close to it. Center point in the middle of the
 179:    // title bar will be more intuitive
 180:    dsFrame1.setCenter(new Point(dsFrame1.getWidth() / 2, dsFrame1.getHeight()));
 181:
 182:    dsContainer1.repaintAll();
 183:  } // Constructor
 184:
 185:
 186:  /**
 187:   * Load the properties of the application in a property file shared with the ant script
 188:   */
 189:  protected void loadProperties() {
 190:    try {
 191:      File  f  = new File("properties/properties_dstour2");
 192:      System.out.println("Using property file :" + f);
 193:
 194:      if (f.exists()) {
 195:        FileInputStream  fis  = new FileInputStream(f);
 196:        props.load(fis);
 197:        fis.close();
 198:      } else {
 199:        props.setProperty("Application.Name",    "DSTour2");
 200:        props.setProperty("Application.Version", "1.0");
 201:        props.setProperty("Application.Build",   "0001");
 202:        FileOutputStream  fos  = new FileOutputStream(f);
 203:        props.store(fos, "Values of the parameters of the application");
 204:        fos.close();
 205:      }
 206:    } catch (IOException e) {
 207:      e.printStackTrace();
 208:    }
 209:  }// loadProperties()
 210:}
 211:
 212: