1:package fr.limsi.dstour3;
   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:public class DSTApplication extends DSApplication {
  22:  protected Properties          props         = new Properties();
  23:  protected DSDefaultView       dsView1       = null;
  24:  protected DSContainer         dsContainer1  = null;
  25:  
  26:  
  27:  /**
  28:   * Main entry point of a java application. args ar not used
  29:   *
  30:   * @param args  The command line arguments
  31:   */
  32:  public static void main(String[] argv){
  33:    new DSTApplication(argv);
  34:  }
  35:
  36:  
  37:  // the objects of this ds tour
  38:  protected DSFrame dsFrame1 = null;
  39:  protected DSImage dsImage1 = null;
  40:  protected DSImage dsImage2 = null;
  41:  
  42:  protected DSTApplication(String[] argv){
  43:    displayInfos();
  44:    loadProperties();
  45:
  46:    // create the DSContainer and initialize it with the standard DSApplication method
  47:    dsContainer1 = new DSContainer();
  48:    
  49:    // from my father !
  50:    init(dsContainer1, false);
  51:    
  52:    // create a dsView1 to put the dsframe on something    
  53:    dsView1 = new DSDefaultView(dsContainer1);
  54:    
  55:    // Change the default background    
  56:    URL bgloc = dsContainer1.getClass().getResource("/images/Background4.jpg");
  57:    if (bgloc != null) {
  58:      dsView1.setBackground(new ImageIcon(bgloc).getImage());
  59:    } else {
  60:      System.out.println("ERROR: can't find background image");
  61:    }
  62:    
  63:    // Activate the dsView1    
  64:    dsContainer1.setActiveView(dsView1);
  65:    
  66:    JRadioButton topButton         = new JRadioButton("Top", true);
  67:    JRadioButton noTBButton        = new JRadioButton("None");
  68:    JRadioButton bottomButton      = new JRadioButton("Bottom");
  69:    JCheckBox resizableCheckbox    = new JCheckBox("Resizable");
  70:    JCheckBox rotatableCheckbox    = new JCheckBox("Rotatable");
  71:    JRadioButton noTransButton     = new JRadioButton("None", true);
  72:    JRadioButton glassButton       = new JRadioButton("Glass");
  73:    JRadioButton uColorButton      = new JRadioButton("User");
  74:    
  75:    JCheckBox closableCheckbox     = new JCheckBox("Closable", true);
  76:    JCheckBox zoomableCheckbox     = new JCheckBox("Zoomable");
  77:    JCheckBox borderButton         = new JCheckBox("Border", true);
  78:
  79:    resizableCheckbox.setFocusable(false);
  80:    rotatableCheckbox.setFocusable(false);
  81:    closableCheckbox.setFocusable(false);
  82:    zoomableCheckbox.setFocusable(false);
  83:    borderButton.setFocusable(false);
  84:    
  85:    ButtonGroup  buttonGroup1      = new ButtonGroup();
  86:    buttonGroup1.add(topButton);
  87:    buttonGroup1.add(noTBButton);
  88:    buttonGroup1.add(bottomButton);  
  89:    
  90:    ButtonGroup  buttonGroup2      = new ButtonGroup();
  91:    buttonGroup2.add(noTransButton);
  92:    buttonGroup2.add(glassButton);
  93:    buttonGroup2.add(uColorButton);      
  94:    
  95:    topButton.addActionListener(new ActionListener(){
  96:      public void actionPerformed(ActionEvent e) {
  97:        dsFrame1.setTitleBar(DSFrame.TOP);
  98:      }
  99:    });
 100:    noTBButton.addActionListener(new ActionListener(){
 101:      public void actionPerformed(ActionEvent e) {
 102:        dsFrame1.setTitleBar(DSFrame.NONE);
 103:      }
 104:    });
 105:    bottomButton.addActionListener(new ActionListener(){
 106:      public void actionPerformed(ActionEvent e) {
 107:        dsFrame1.setTitleBar(DSFrame.BOTTOM);
 108:      }
 109:    });
 110:    
 111:    noTransButton.addActionListener(new ActionListener(){
 112:      public void actionPerformed(ActionEvent e) {
 113:        dsFrame1.setTransparency(DSFrame.NONE);
 114:      }
 115:    });
 116:    glassButton.addActionListener(new ActionListener(){
 117:      public void actionPerformed(ActionEvent e) {
 118:        dsFrame1.setTransparency(DSFrame.GLASS);
 119:      }
 120:    });
 121:    uColorButton.addActionListener(new ActionListener(){
 122:      public void actionPerformed(ActionEvent e) {
 123:        dsFrame1.setTransparency(DSFrame.USER_COLOR);
 124:      }
 125:    });
 126:    
 127:    borderButton.addItemListener(new ItemListener(){
 128:      public void itemStateChanged(ItemEvent e) {
 129:        if (e.getStateChange() == ItemEvent.SELECTED)
 130:          LookAndFeel.installBorder(dsFrame1, "InternalFrame.border"); 
 131:        else 
 132:          dsFrame1.setBorder(null);
 133:      }
 134:    });
 135:    
 136:    resizableCheckbox.addItemListener(new ItemListener(){
 137:      public void itemStateChanged(ItemEvent e) {
 138:        dsFrame1.setResizable(e.getStateChange() == ItemEvent.SELECTED);
 139:      }
 140:    });
 141:    
 142:    rotatableCheckbox.addItemListener(new ItemListener(){
 143:      public void itemStateChanged(ItemEvent e) {
 144:        dsFrame1.setRotatable(e.getStateChange() == ItemEvent.SELECTED);
 145:      }
 146:    });    
 147:    
 148:    zoomableCheckbox.addItemListener(new ItemListener(){
 149:      public void itemStateChanged(ItemEvent e) {
 150:        dsFrame1.setZoomable(e.getStateChange() == ItemEvent.SELECTED);
 151:      }
 152:    });    
 153:    
 154:    closableCheckbox.addItemListener(new ItemListener(){
 155:      public void itemStateChanged(ItemEvent e) {
 156:        dsFrame1.setClosable(e.getStateChange() == ItemEvent.SELECTED);
 157:      }
 158:    });  
 159:    
 160:    JPanel jPanel1 = new JPanel();
 161:    jPanel1.setOpaque(false);
 162:    jPanel1.setLayout(new GridLayout(4, 3));
 163:    jPanel1.add(topButton);
 164:    jPanel1.add(resizableCheckbox);    
 165:    jPanel1.add(noTransButton);    
 166:
 167:    jPanel1.add(noTBButton);
 168:    jPanel1.add(rotatableCheckbox);
 169:    jPanel1.add(glassButton);
 170:    
 171:    jPanel1.add(bottomButton);
 172:    jPanel1.add(zoomableCheckbox);
 173:    jPanel1.add(uColorButton);
 174:    
 175:    jPanel1.add(borderButton);
 176:    jPanel1.add(closableCheckbox);
 177:         
 178:    JTextField jTextField = new JTextField("DS Tour #3");
 179:    jTextField.setEditable(false);
 180:    
 181:    JTextArea jTextArea = new JTextArea("DS Tour #3 by \n"+
 182:      "* Guillaume Besacier &\n"+
 183:      "* Frederic Vernier (LIMSI-CNRS)\n\n"+
 184:      "Demonstrate\n"+
 185:      "* DSFrame decorations\n"+
 186:      "* DSImage\n"+      
 187:      "* DSFrame TitleBar position\n"+
 188:      "* DSFrame Transparency\n");
 189:    jTextArea.setOpaque(false);
 190:
 191:    JScrollPane jScrollPane = new JScrollPane(jTextArea);
 192:    jScrollPane.setOpaque(false);
 193:    jScrollPane.getViewport().setOpaque(false);
 194:    jScrollPane.setPreferredSize(new Dimension(100, 80));
 195:    
 196:    // make THE dsframe
 197:    dsFrame1 = new DSFrame("DSFrame", dsContainer1);
 198:    
 199:    // add it to the dsView1 (ds world addition)
 200:    dsView1.addDSElement(dsFrame1);
 201:    
 202:    // add it to container (swing world addition)
 203:    dsContainer1.add(dsFrame1);
 204:    
 205:    // set parameters of the dsframe
 206:    dsFrame1.getContentPane().add(jTextField, BorderLayout.NORTH);    
 207:    dsFrame1.getContentPane().add(jScrollPane, BorderLayout.CENTER);    
 208:    dsFrame1.getContentPane().add(jPanel1, BorderLayout.SOUTH);
 209:    dsFrame1.setAlpha(-(float)Math.PI/2);
 210:    
 211:    dsFrame1.setClosable(true);
 212:    dsFrame1.setCorners(true);
 213:    dsFrame1.addInternalFrameListener(new InternalFrameAdapter(){
 214:      public void internalFrameClosed(InternalFrameEvent e) {
 215:        super.internalFrameClosed(e);
 216:        System.exit(0);
 217:      }
 218:    });
 219:    
 220:    dsFrame1.pack();
 221:    // center point will stick to the center when it get close to it. Center point in the middle of the
 222:    // title bar will be more intuitive
 223:    dsFrame1.setCenter(new Point(dsFrame1.getWidth()/2, dsFrame1.getHeight()/2));    
 224:    
 225:    dsView1.addDSElement(dsFrame1);
 226:    try {
 227:      dsImage1 = new DSImage(dsContainer1, "images/FiCell.jpg",          0.5f, -(float)Math.PI/2-0.5f, 1, DSImage.MAXIMUM_SIDE_THN, false);
 228:      dsView1.addDSElement(dsImage1);
 229:      dsContainer1.add(dsImage1);
 230:      
 231:      dsImage2 = new DSImage(dsContainer1, "images/BiSliderPrecise.png", 0.5f, -(float)Math.PI/2+0.5f, 1, DSImage.MAXIMUM_SIDE_THN, false);
 232:      dsView1.addDSElement(dsImage2);
 233:      dsContainer1.add(dsImage2);
 234:    } catch (Exception e) {
 235:      e.printStackTrace();
 236:    }
 237:    dsView1.addDSElement(dsImage1);
 238:    dsView1.addDSElement(dsImage2);
 239:    dsImage1.setCorners(true);
 240:    dsImage2.setCorners(true);
 241:    dsImage1.setResizable(true);
 242:    dsImage2.setResizable(true);
 243:    dsImage2.setBorder(null);
 244:    dsImage2.setTransparency(DSFrame.GLASS);
 245:
 246:    dsImage1.setVisible(true);
 247:    dsImage2.setVisible(true);
 248:    dsFrame1.setVisible(true);    
 249:
 250:    dsContainer1.repaintAll();
 251:  }// Constructor
 252:  
 253:
 254:  /**
 255:   * Load the properties of the application in a property file shared with the ant script
 256:   */  
 257:  protected void loadProperties(){
 258:    try {
 259:      File f = new File("properties/properties_dstour3");
 260:      System.out.println("Using property file :" + f);
 261:      
 262:      if(f.exists()) {
 263:        FileInputStream  fis  = new FileInputStream(f);
 264:        props.load(fis);
 265:        fis.close();
 266:      } else {
 267:        props.setProperty("Application.Name", "DSTour3");
 268:        props.setProperty("Application.Version", "1.0");
 269:        props.setProperty("Application.Build", "0001");
 270:        FileOutputStream fos = new FileOutputStream(f);
 271:        props.store(fos, "Values of the parameters of the application");
 272:        fos.close();
 273:      }
 274:    } catch (IOException e) {
 275:      e.printStackTrace();
 276:    }
 277:  }// loadProperties()
 278:}
 279:
 280: