Source code: ide/WaveViewFrame.java
1 /* **********************************
2 File: WaveView.java
3 Author: Lucian Ghita Felix(felix@ulise.cs.pub.ro)
4 Created on 16-IV-1999 3:40 pm
5 Comments: Part of the vIDE Project
6 Copyright 1999 the vIDE Team.
7 ***********************************/
8
9 package ide;
10
11 import java.awt.*;
12 import java.awt.event.*;
13 import java.beans.*;
14 import javax.swing.*;
15 import javax.swing.border.*;
16 import java.io.*;
17 import middle.*;
18
19 import javax.swing.plaf.metal.*;
20
21
22 /**
23 * This is the container frame for the WaveForm viewer and some buttons.
24 *
25 * @version 1.0
26 * @author Lucian Ghita Felix
27 *
28 *
29 */
30
31 public class WaveViewFrame extends JInternalFrame {
32 WaveView waveView;
33 Project theProject;
34
35 public ZoomInAction zoomInAction = new ZoomInAction();
36 public ZoomOutAction zoomOutAction = new ZoomOutAction();
37 public RemoveWaveAction removeWaveAction = new RemoveWaveAction();
38
39
40
41 public WaveViewFrame(Project theProject) {
42 super("vIDE WaveForm Viewer", true, false, true, true);
43 vide.spl.showStatus("Creating vIDE wave view frame..");
44 this.theProject = theProject;
45 //setBackground(UIManager.getColor("control"));
46 waveView = new WaveView(theProject);
47
48 final int inset = 100;
49 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
50 setBounds ( inset, inset, screenSize.width - inset*2, screenSize.height - inset*2 );
51
52
53 getContentPane().add(waveView, BorderLayout.CENTER);
54 getContentPane().add(buildToolbar(), BorderLayout.NORTH);
55 }
56
57 private void addB(JToolBar t, AbstractAction a) {
58 JButton b = t.add(a);
59 b.setText(null);
60 b.setToolTipText((String) a.getValue(AbstractAction.LONG_DESCRIPTION));
61 b.setMargin(new Insets(0,5,0,5));
62 b.setRolloverEnabled(true);
63 }
64 protected JToolBar buildToolbar() {
65
66 vide.spl.showStatus("Creating WaveFormView toolbar..");
67 JToolBar toolBar = new JToolBar();
68 toolBar.setFloatable(false);
69 toolBar.putClientProperty( "JToolBar.isRollover", Boolean.TRUE );
70
71 addB(toolBar, zoomInAction);
72 addB(toolBar, zoomOutAction);
73 toolBar.addSeparator();
74
75 addB(toolBar, removeWaveAction);
76 toolBar.addSeparator();
77
78 addB(toolBar, theProject.runAction);
79 addB(toolBar, theProject.goAction);
80 addB(toolBar, theProject.stepAction);
81 addB(toolBar, theProject.stopAction);
82 vide.spl.showStatus("Done creating toolbar..");
83 return toolBar;
84 }
85 public void saveWaveSet() {
86 try {
87 JFileChooser chooser = new JFileChooser(".");
88 VideFileFilter filter = new VideFileFilter("vws", "Wave Set file");
89 chooser.setFileFilter(filter);
90 int returnVal = chooser.showSaveDialog(theProject.god);
91 if(returnVal != JFileChooser.APPROVE_OPTION) return;
92 String name = chooser.getSelectedFile().getName();
93
94 FileOutputStream fostream = new FileOutputStream(name); // + "." + "vws");
95 ObjectOutputStream oostream = new ObjectOutputStream(fostream);
96 oostream.writeObject("qwerty");
97 oostream.writeObject(new Integer(((DefaultListModel) waveView.waveNameList.getModel()).getSize()));
98 for(int index = 0; index < ((DefaultListModel) waveView.waveNameList.getModel()).getSize();index++){
99 oostream.writeObject(((DefaultListModel) waveView.waveNameList.getModel()).getElementAt(index));
100 oostream.writeObject((VariableHistory)((DefaultListModel) waveView.waveList.getModel()).getElementAt(index));
101 }
102
103 oostream.flush();
104 fostream.close();
105 } catch (Exception e) {
106 //error("Failed saving project with reason:\n" + e.toString());
107 System.out.println("IOException : " + e);
108 }
109 }
110
111
112 public void openWaveSet() {
113
114 JFileChooser chooser = new JFileChooser(".");
115 VideFileFilter filter = new VideFileFilter("vws", "WaveSet file");
116 chooser.setFileFilter(filter);
117 int returnVal = chooser.showOpenDialog(theProject.god);
118 if(returnVal != JFileChooser.APPROVE_OPTION) return;
119 String file = chooser.getSelectedFile().getName();
120
121
122 if (file == null) return; //the user is bored by this enviroment and make mistakes
123 if (!(file.endsWith("." + "vwv"))) {
124 //error("Could not load wave data.\nA VeriSim wave data file must have \n " + "vwv" + " extension.");
125 return;
126 }
127
128 try {
129 FileInputStream fistream = new FileInputStream(file); //name + "." + "vwv");
130 ObjectInputStream oistream = new ObjectInputStream(fistream);
131 if (!(((String) oistream.readObject()).equals("qwerty"))) {
132 System.out.println("Could not load wave set : nBad signature.");
133 //error("Could not load project.\nBad signature.");
134 return;
135 }
136
137 waveView.clear();
138
139 int numar = ((Integer)oistream.readObject()).intValue();
140
141 for(int index = 0; index < numar;index++){
142 String nameVar = (String)oistream.readObject();
143 VariableHistory vh = (VariableHistory)oistream.readObject();
144 waveView.addWave(vh,nameVar);
145 }
146
147 fistream.close();
148
149 } catch (Exception e) {
150 System.out.println("Exception opening WaveSet:" + e.toString());
151
152 }
153
154 }
155
156
157 class ZoomInAction extends AbstractAction {
158 public ZoomInAction() {
159 super("ZoomIn");setEnabled(true);
160 putValue(SMALL_ICON, new ImageIcon(vide.baseDir + "images/zoomIn.gif"));
161 putValue(LONG_DESCRIPTION, "Zoom in");
162 }
163 public void actionPerformed(java.awt.event.ActionEvent event) {
164 zoomOutAction.setEnabled(true); //activeaza ZoomOut
165 setEnabled(waveView.ZoomIn()); //daca zoom == maximum ..
166 }
167 }
168
169 class ZoomOutAction extends AbstractAction {
170 public ZoomOutAction() {
171 super("ZoomOut");setEnabled(true);
172 putValue(SMALL_ICON, new ImageIcon(vide.baseDir + "images/zoomOut.gif"));
173 putValue(LONG_DESCRIPTION, "Zoom out");
174 }
175 public void actionPerformed(java.awt.event.ActionEvent event) {
176 zoomInAction.setEnabled(true); //activeaza ZoomIn
177 setEnabled(waveView.ZoomOut());
178 }
179 }
180
181 class RemoveWaveAction extends AbstractAction {
182 public RemoveWaveAction () {
183 super("RemoveWaveActionAction");setEnabled(true);
184 putValue(SMALL_ICON, new ImageIcon(vide.baseDir + "images/delWave.gif"));
185 putValue(LONG_DESCRIPTION, "Removes the selected wave");
186 }
187 public void actionPerformed(java.awt.event.ActionEvent event) {
188 waveView.removeWave();
189 }
190 }
191
192 Object[] reset(){
193 return waveView.reset();
194 }
195 }
196
197
198
199
200
201
202
203
204