/*     */ package main;
/*     */ 
/*     */ import java.awt.Container;
/*     */ import java.awt.Dimension;
/*     */ import java.awt.event.ActionEvent;
/*     */ import java.awt.event.ActionListener;
/*     */ import java.util.ArrayList;
/*     */ import javax.swing.BorderFactory;
/*     */ import javax.swing.JButton;
/*     */ import javax.swing.JCheckBox;
/*     */ import javax.swing.JComboBox;
/*     */ import javax.swing.JDialog;
/*     */ import javax.swing.JFrame;
/*     */ import javax.swing.JPanel;
/*     */ import javax.swing.JSlider;
/*     */ import javax.swing.JTextField;
/*     */ import javax.swing.event.ChangeEvent;
/*     */ import javax.swing.event.ChangeListener;
/*     */ import signals.Signals;
/*     */ 
/*     */ public class DialogBox extends JDialog
/*     */ {
/*     */   private static final long serialVersionUID = 1L;
/*     */   private javax.swing.JLabel clockLabel;
/*     */   private JTextField nameField;
/*     */   private JTextField ratioField;
/*     */   private JTextField waveField;
/*     */   private JComboBox clockBox;
/*     */   private JComboBox clockForRatioBox;
/*     */   private JCheckBox displayRisingEdgesBox;
/*     */   private JCheckBox beginOnRisingEdgeBox;
/*     */   private JCheckBox setUpBox;
/*     */   private JCheckBox clkToQdelayBox;
/*     */   private JCheckBox clockDependencyBox;
/*     */   private JPanel content;
/*     */   private JPanel nameContent;
/*     */   private JPanel clockContent;
/*     */   private JPanel ratioContent;
/*     */   private JPanel sliderContent;
/*     */   private JPanel waveContent;
/*  41 */   public boolean valid = false;
/*     */   public boolean displayRisingEdges;
/*     */   public boolean beginOnRisingEdge;
/*  44 */   public String name; public int clockDomain = -1;
/*     */   public float ratio;
/*     */   public boolean clkDependency;
/*  47 */   public int freq = -1;
/*  48 */   public boolean setUp = false;
/*  49 */   public boolean clkToQdelay = false;
/*     */   
/*     */   public int[] waveSet;
/*     */   
/*  53 */   private boolean onlyName = false;
/*  54 */   private boolean clock = false; private boolean dependsOnClk = false;
/*  55 */   private int[] clockDomainId = new int[50];
/*  56 */   private int[] clockDomainForRatioId = new int[50];
/*     */   
/*     */   public DialogBox(JFrame parent, String title, Signals s)
/*     */   {
/*  60 */     super(parent, title, true);
/*  61 */     setSize(230, 300);
/*  62 */     setLocationRelativeTo(null);
/*  63 */     setResizable(false);
/*  64 */     setDefaultCloseOperation(2);
/*  65 */     initComponent(s);
/*     */   }
/*     */   
/*     */   public DialogBox(JFrame parent, String title)
/*     */   {
/*  70 */     super(parent, title, true);
/*  71 */     this.onlyName = true;
/*  72 */     setSize(250, 200);
/*  73 */     setLocationRelativeTo(null);
/*  74 */     setResizable(false);
/*  75 */     setDefaultCloseOperation(2);
/*  76 */     initComponent(new signals.Clock("", 20));
/*     */   }
/*     */   
/*     */   public DialogBox(JFrame parent, String title, Signals s, boolean values)
/*     */   {
/*  81 */     super(parent, title, true);
/*  82 */     setSize(400, 150);
/*  83 */     setLocationRelativeTo(null);
/*  84 */     setResizable(false);
/*  85 */     setDefaultCloseOperation(2);
/*  86 */     this.waveSet = new int['Ǵ'];
/*  87 */     displayValueField(s);
/*     */   }
/*     */   
/*     */   public void showDialog() {
/*  91 */     setVisible(true);
/*     */   }
/*     */   
/*     */   private void initComponent(Signals s)
/*     */   {
/*  96 */     this.content = new JPanel();
/*  97 */     this.nameContent = new JPanel();
/*  98 */     this.clockContent = new JPanel();
/*  99 */     this.ratioContent = new JPanel();
/* 100 */     this.sliderContent = new JPanel();
/*     */     
/* 102 */     this.clock = s.clock;
/* 103 */     this.dependsOnClk = s.dependsOnClk;
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 108 */     this.nameField = new JTextField(s.name);
/* 109 */     this.nameField.setPreferredSize(new Dimension(100, 25));
/* 110 */     this.nameContent.setBorder(BorderFactory.createTitledBorder("Set name"));
/* 111 */     this.nameContent.add(this.nameField);
/*     */     
/*     */ 
/* 114 */     this.displayRisingEdgesBox = new JCheckBox("Display Rising Edges");
/* 115 */     this.displayRisingEdgesBox.setSelected(s.displayRisingEdges);
/* 116 */     this.displayRisingEdges = s.displayRisingEdges;
/* 117 */     this.displayRisingEdgesBox.addChangeListener(new ChangeListener() {
/*     */       public void stateChanged(ChangeEvent event) {
/* 119 */         DialogBox.this.displayRisingEdges = DialogBox.this.displayRisingEdgesBox.isSelected();
/*     */       }
/*     */       
/*     */ 
/* 123 */     });
/* 124 */     this.beginOnRisingEdgeBox = new JCheckBox("Begin on Rising Edge");
/* 125 */     this.beginOnRisingEdgeBox.setSelected(s.wave[0] == 1);
/* 126 */     this.beginOnRisingEdge = (s.wave[0] == 1);
/* 127 */     this.beginOnRisingEdgeBox.addChangeListener(new ChangeListener() {
/*     */       public void stateChanged(ChangeEvent event) {
/* 129 */         DialogBox.this.beginOnRisingEdge = DialogBox.this.beginOnRisingEdgeBox.isSelected();
/*     */ 
/*     */       }
/*     */       
/*     */ 
/* 134 */     });
/* 135 */     JSlider slide = new JSlider();
/* 136 */     slide.setMaximum(105);
/* 137 */     slide.setMinimum(5);
/* 138 */     slide.setValue(s.widthUnit);
/* 139 */     this.freq = s.widthUnit;
/* 140 */     slide.setPaintTicks(true);
/* 141 */     slide.setPaintLabels(true);
/* 142 */     slide.setMinorTickSpacing(10);
/* 143 */     slide.setMajorTickSpacing(20);
/* 144 */     slide.addChangeListener(new ChangeListener() {
/*     */       public void stateChanged(ChangeEvent event) {
/* 146 */         DialogBox.this.freq = ((JSlider)event.getSource()).getValue();
/* 147 */         DialogBox.this.sliderContent.setBorder(BorderFactory.createTitledBorder("Period: " + DialogBox.this.freq));
/*     */       }
/* 149 */     });
/* 150 */     this.sliderContent.setBorder(BorderFactory.createTitledBorder("Period: " + s.widthUnit));
/* 151 */     this.sliderContent.add(slide);
/*     */     
/*     */ 
/* 154 */     this.clockDependencyBox = new JCheckBox("Create clock dependency");
/* 155 */     this.clockDependencyBox.setSelected(s.dependsOnClk);
/* 156 */     this.clockDependencyBox.addChangeListener(new ChangeListener() {
/*     */       public void stateChanged(ChangeEvent event) {
/* 158 */         DialogBox.this.sliderContent.setVisible(!DialogBox.this.clockDependencyBox.isSelected());
/* 159 */         DialogBox.this.ratioContent.setVisible(DialogBox.this.clockDependencyBox.isSelected());
/*     */       }
/*     */       
/*     */ 
/* 163 */     });
/* 164 */     int selectedIndex = 0;
/* 165 */     int selectedIndexForRatio = 0;
/* 166 */     int temp = 0;
/* 167 */     int tempForRatio = 0;
/* 168 */     boolean clkDomainEmpty = true;
/* 169 */     boolean clkDomainForRatioEmpty = true;
/* 170 */     this.clockBox = new JComboBox();
/* 171 */     this.clockForRatioBox = new JComboBox();
/* 172 */     for (int i = 0; i < ((ChronoPanel)ChronoWindow.chrono.get(ChronoWindow.active)).signals.size(); i++) {
/* 173 */       if (((Signals)((ChronoPanel)ChronoWindow.chrono.get(ChronoWindow.active)).signals.get(i)).clock)
/*     */       {
/* 175 */         this.clockBox.addItem(((Signals)((ChronoPanel)ChronoWindow.chrono.get(ChronoWindow.active)).signals.get(i)).name);
/* 176 */         this.clockDomainId[temp] = ((Signals)((ChronoPanel)ChronoWindow.chrono.get(ChronoWindow.active)).signals.get(i)).id;
/* 177 */         if (((Signals)((ChronoPanel)ChronoWindow.chrono.get(ChronoWindow.active)).signals.get(i)).id == s.clockDomainId) selectedIndex = temp;
/* 178 */         temp++;
/* 179 */         clkDomainEmpty = false;
/*     */         
/*     */ 
/* 182 */         if ((((Signals)((ChronoPanel)ChronoWindow.chrono.get(ChronoWindow.active)).signals.get(i)).id != s.id) && (!((Signals)((ChronoPanel)ChronoWindow.chrono.get(ChronoWindow.active)).signals.get(i)).dependsOnClk)) {
/* 183 */           this.clockForRatioBox.addItem(((Signals)((ChronoPanel)ChronoWindow.chrono.get(ChronoWindow.active)).signals.get(i)).name);
/* 184 */           this.clockDomainForRatioId[tempForRatio] = ((Signals)((ChronoPanel)ChronoWindow.chrono.get(ChronoWindow.active)).signals.get(i)).id;
/* 185 */           clkDomainForRatioEmpty = false;
/* 186 */           if (((Signals)((ChronoPanel)ChronoWindow.chrono.get(ChronoWindow.active)).signals.get(i)).id == s.clockDomainId) selectedIndexForRatio = tempForRatio;
/* 187 */           tempForRatio++;
/*     */         }
/*     */       }
/*     */     }
/*     */     
/*     */ 
/* 193 */     if (clkDomainEmpty) {
/* 194 */       this.clockBox.addItem(null);
/*     */     }
/*     */     else {
/* 197 */       this.clockBox.setSelectedIndex(selectedIndex);
/*     */     }
/* 199 */     if (clkDomainForRatioEmpty) {
/* 200 */       this.clockForRatioBox.addItem(null);
/*     */     }
/*     */     else {
/* 203 */       this.clockForRatioBox.setSelectedIndex(selectedIndexForRatio);
/*     */     }
/* 205 */     this.clockLabel = new javax.swing.JLabel("Select clock :");
/* 206 */     this.clockContent.setBorder(BorderFactory.createTitledBorder("Clock Domain"));
/* 207 */     this.clockContent.add(this.clockLabel);
/* 208 */     this.clockContent.add(this.clockBox);
/*     */     
/*     */ 
/* 211 */     this.ratioField = new JTextField(Float.toString(s.ratio));
/* 212 */     this.ratioField.setPreferredSize(new Dimension(100, 25));
/* 213 */     this.ratioContent.setBorder(BorderFactory.createTitledBorder("Clock Domain Ratio"));
/* 214 */     this.ratioContent.add(this.clockForRatioBox);
/* 215 */     this.ratioContent.add(this.ratioField);
/*     */     
/*     */ 
/*     */ 
/* 219 */     this.setUpBox = new JCheckBox("Add setup time");
/* 220 */     if (s.setUpTime > 0) {
/* 221 */       this.setUpBox.setSelected(true);
/* 222 */       this.setUp = true;
/*     */     }
/* 224 */     this.setUpBox.addChangeListener(new ChangeListener() {
/*     */       public void stateChanged(ChangeEvent event) {
/* 226 */         DialogBox.this.setUp = DialogBox.this.setUpBox.isSelected();
/*     */       }
/*     */       
/* 229 */     });
/* 230 */     this.clkToQdelayBox = new JCheckBox("Left shift");
/* 231 */     this.clkToQdelayBox.setSelected(s.clkToQdelay);
/* 232 */     this.clkToQdelay = s.clkToQdelay;
/* 233 */     this.clkToQdelayBox.addChangeListener(new ChangeListener() {
/*     */       public void stateChanged(ChangeEvent event) {
/* 235 */         DialogBox.this.clkToQdelay = DialogBox.this.clkToQdelayBox.isSelected();
/*     */       }
/*     */       
/*     */ 
/* 239 */     });
/* 240 */     JPanel control = new JPanel();
/* 241 */     JButton okButton = new JButton("Valid");
/* 242 */     getRootPane().setDefaultButton(okButton);
/* 243 */     okButton.addActionListener(new ActionListener() {
/*     */       public void actionPerformed(ActionEvent arg0) {
/* 245 */         DialogBox.this.name = DialogBox.this.nameField.getText();
/*     */         
/* 247 */         if (DialogBox.this.clock) {
/* 248 */           if (DialogBox.this.clockDependencyBox.isSelected()) {
/* 249 */             DialogBox.this.clockDomain = DialogBox.this.clockDomainForRatioId[DialogBox.this.clockForRatioBox.getSelectedIndex()];
/* 250 */             DialogBox.this.ratio = Float.parseFloat(DialogBox.this.ratioField.getText());
/* 251 */             DialogBox.this.clkDependency = true;
/*     */           }
/*     */           else {
/* 254 */             DialogBox.this.clkDependency = false;
/*     */           }
/*     */         }
/* 257 */         else if (DialogBox.this.dependsOnClk) {
/* 258 */           DialogBox.this.clockDomain = DialogBox.this.clockDomainId[DialogBox.this.clockBox.getSelectedIndex()];
/*     */         }
/* 260 */         DialogBox.this.valid = true;
/* 261 */         DialogBox.this.setVisible(false);
/*     */       }
/* 263 */     });
/* 264 */     JButton cancelBouton = new JButton("Cancel");
/* 265 */     cancelBouton.addActionListener(new ActionListener() {
/*     */       public void actionPerformed(ActionEvent arg0) {
/* 267 */         DialogBox.this.valid = false;
/* 268 */         DialogBox.this.setVisible(false);
/*     */       }
/*     */       
/*     */ 
/* 272 */     });
/* 273 */     this.content.add(this.nameContent);
/* 274 */     this.content.add(this.displayRisingEdgesBox);
/* 275 */     this.content.add(this.beginOnRisingEdgeBox);
/* 276 */     this.content.add(this.clockContent);
/* 277 */     this.content.add(this.clockDependencyBox);
/* 278 */     this.content.add(this.sliderContent);
/* 279 */     this.content.add(this.ratioContent);
/* 280 */     this.content.add(this.setUpBox);
/* 281 */     this.content.add(this.clkToQdelayBox);
/* 282 */     control.add(okButton);
/* 283 */     control.add(cancelBouton);
/* 284 */     getContentPane().add(this.content, "Center");
/* 285 */     getContentPane().add(control, "South");
/*     */     
/*     */ 
/* 288 */     this.nameContent.setVisible(true);
/* 289 */     this.displayRisingEdgesBox.setVisible((s.clock) && (!this.onlyName) && (s.id != -1));
/* 290 */     this.beginOnRisingEdgeBox.setVisible((s.clock) && (!this.onlyName) && (s.id != -1));
/* 291 */     this.clockContent.setVisible((!s.clock) && (s.dependsOnClk) && (!this.onlyName));
/* 292 */     this.clockDependencyBox.setVisible((s.clock) && (!this.onlyName) && (s.id != -1));
/* 293 */     this.clockDependencyBox.setEnabled((!clkDomainForRatioEmpty) && (s.id != -1));
/* 294 */     this.sliderContent.setVisible((!s.dependsOnClk) && (!this.onlyName));
/* 295 */     this.ratioContent.setVisible((s.clock) && (s.dependsOnClk) && (!clkDomainEmpty) && (!this.onlyName));
/* 296 */     this.setUpBox.setVisible((!s.clock) && (s.id != -1) && (!this.onlyName) && (!s.bus));
/* 297 */     this.clkToQdelayBox.setVisible((!s.clock) && (s.id != -1) && (!this.onlyName));
/*     */   }
/*     */   
/*     */   public void displayValueField(Signals s)
/*     */   {
/* 302 */     this.content = new JPanel();
/* 303 */     this.waveContent = new JPanel();
/*     */     
/*     */ 
/* 306 */     String wave = "";
/* 307 */     int tmp = s.wave[0];int index = 0;
/* 308 */     for (int i = 0; i < s.wave.length; i++) {
/* 309 */       if (s.wave[i] != tmp) {
/* 310 */         tmp = s.wave[i];
/* 311 */         index = i;
/*     */       }
/*     */     }
/* 314 */     for (int i = 0; i < index; i++) wave = wave + s.wave[i];
/* 315 */     this.waveField = new JTextField(wave);
/* 316 */     this.waveField.setPreferredSize(new Dimension(300, 25));
/* 317 */     this.waveContent.setBorder(BorderFactory.createTitledBorder("Wave values"));
/* 318 */     this.waveContent.add(this.waveField);
/*     */     
/*     */ 
/* 321 */     JPanel control = new JPanel();
/* 322 */     JButton okButton = new JButton("Valid");
/* 323 */     getRootPane().setDefaultButton(okButton);
/* 324 */     okButton.addActionListener(new ActionListener() {
/*     */       public void actionPerformed(ActionEvent arg0) {
/* 326 */         String tmp = DialogBox.this.waveField.getText();
/* 327 */         tmp = tmp.replaceAll(" ", "");
/* 328 */         int toFill = 0;
/* 329 */         for (int i = 0; i < DialogBox.this.waveSet.length; i++) {
/* 330 */           if (i < tmp.length()) {
/* 331 */             char c = tmp.charAt(i);
/* 332 */             String sTmp = String.valueOf(c);
/* 333 */             DialogBox.this.waveSet[i] = Integer.parseInt(sTmp);
/* 334 */             toFill = DialogBox.this.waveSet[i];
/*     */           }
/*     */           else {
/* 337 */             if (toFill == 0) DialogBox.this.waveSet[i] = 1;
/* 338 */             if (toFill == 1) DialogBox.this.waveSet[i] = 0;
/*     */           }
/*     */         }
/* 341 */         DialogBox.this.valid = true;
/* 342 */         DialogBox.this.setVisible(false);
/*     */       }
/* 344 */     });
/* 345 */     JButton cancelBouton = new JButton("Cancel");
/* 346 */     cancelBouton.addActionListener(new ActionListener() {
/*     */       public void actionPerformed(ActionEvent arg0) {
/* 348 */         DialogBox.this.valid = false;
/* 349 */         DialogBox.this.setVisible(false);
/*     */       }
/*     */       
/* 352 */     });
/* 353 */     this.content.add(this.waveContent);
/* 354 */     control.add(okButton);
/* 355 */     control.add(cancelBouton);
/* 356 */     getContentPane().add(this.content, "Center");
/* 357 */     getContentPane().add(control, "South");
/*     */   }
/*     */ }


/* Location:              F:\JAVA\WORKSPACE\chronoEditor_v2.3.jar!\main\DialogBox.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */