-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisplayWindow.java
300 lines (267 loc) · 12.2 KB
/
DisplayWindow.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import java.util.*;
import static java.lang.Math.*;
import java.text.DecimalFormat;
class CenDisplayPanel extends JPanel implements MouseListener, MouseMotionListener{
Insets ins;
private int mouseX,mouseY,mousedown=0;
private Dim dim= new Dim();
CenDisplayPanel(Dim idim){
dim=idim;
//setBorder(BorderFactory.createLineBorder(Color.RED,5));
addMouseMotionListener(this);
addMouseListener(this);
}
protected void paintComponent(Graphics g){
int tmpx,tmpy;
double tmpp,tmp,tmph,tmpph;
double addmelist[]={-1d, 0d, 1d};
super.paintComponent(g);
g.setColor(Color.black);
//all black lines side to side
for(int i=0;i<dim.ppm.size();i++){
g.setColor(Color.black);
tmpp=(dim.hoffset-0.5d*(dim.hppm1.get(i)+dim.hppm2.get(i)))/dim.hwidth; // 0-1 units
tmpp=tmpp*(double)getWidth();
tmp=abs(dim.hppm1.get(i)-dim.hppm2.get(i))/dim.hwidth;//full width
tmp=tmp*(double)getWidth();
if(mouseX>=(int)(tmpp-0.5d*tmp))
if(mouseX<=(int)(tmpp-0.5d*tmp)+ (int)(tmp))
if(mouseY>= (int)((dim.pos01.get(i)-0.5d*dim.width01.get(i))*(double)getHeight()))
if(mouseY<= (int)((dim.pos01.get(i)-0.5d*dim.width01.get(i))*(double)getHeight())+ (int)( dim.width01.get(i)*(double)getHeight())) {
g.setColor(Color.red);
// dim.SetSheet_number(dim.Val_n.get(i).intValue());
}
g.drawLine(0,(int)(dim.pos01.get(i)*(double)getHeight()),getWidth(),(int)(dim.pos01.get(i)*(double)getHeight()));
}
//signals
for(double addme : addmelist) //to see signals also at top and bottom when at the edge
for(int i=0;i<dim.ppm.size();i++){
// proton dimension
tmpp=(dim.hoffset-0.5d*(dim.hppm1.get(i)+dim.hppm2.get(i)))/dim.hwidth; // 0-1 units
tmpp=tmpp*(double)getWidth();
tmp=abs(dim.hppm1.get(i)-dim.hppm2.get(i))/dim.hwidth;//full width
tmp=tmp*(double)getWidth();
g.setColor(Color.yellow);
g.fillRect((int)(tmpp-0.5d*tmp),(int)((addme+dim.pos01.get(i)-0.5d*dim.width01.get(i))*(double)getHeight()),(int)(tmp),(int)(addme+dim.width01.get(i)*(double)getHeight()));
g.setColor(Color.green);
g.fillRect((int)(tmpp-0.5d*tmp),(int)((addme+dim.pos01.get(i)-0.5d*dim.width01n.get(i))*(double)getHeight()),(int)(tmp),(int)(addme+dim.width01n.get(i)*(double)getHeight()));
g.setColor(Color.black);
if(mouseX>=(int)(tmpp-0.5d*tmp))
if(mouseX<=(int)(tmpp-0.5d*tmp)+ (int)(tmp))
if(mouseY>= (int)((addme+dim.pos01.get(i)-0.5d*dim.width01.get(i))*(double)getHeight()))
if(mouseY<= (int)((addme+dim.pos01.get(i)-0.5d*dim.width01.get(i))*(double)getHeight())+ (int)(addme+dim.width01.get(i)*(double)getHeight())) {
g.setColor(Color.red);
// dim.SetSheet_number(dim.Val_n.get(i).intValue());
}
g.drawRect((int)(tmpp-0.5d*tmp),(int)((addme+dim.pos01.get(i)-0.5d*dim.width01.get(i))*(double)getHeight()),(int)(tmp),(int)(addme+dim.width01.get(i)*(double)getHeight()));
if(mouseX>=(int)(tmpp-0.5d*tmp))
if(mouseX<=(int)(tmpp-0.5d*tmp)+ (int)(tmp))
if(mouseY>= (int)((addme+dim.pos01.get(i)-0.5d*dim.width01.get(i))*(double)getHeight()))
if(mouseY<= (int)((addme+dim.pos01.get(i)-0.5d*dim.width01.get(i))*(double)getHeight())+ (int)(addme+dim.width01.get(i)*(double)getHeight())) {
g.setColor(Color.red);
tmpx=(int)(tmpp-0.5d*tmp);
tmpy=(int)((addme+dim.pos01.get(i)-0.5d*dim.width01.get(i))*(double)getHeight());
if(tmpy<20){tmpy=20;tmpx+=20;}
if((getWidth()-tmpx)<250)tmpx=getWidth()-250;
// done below for text to be above g.drawString(dim.Val_n.get(i),tmpx,tmpy);
}
//g.drawString(""+dim.Val_n.get(i).intValue(),(int)(tmpp-0.5d*tmp),(int)((addme+dim.pos01.get(i)-0.5d*dim.width01.get(i))*(double)getHeight()));
}
for(int i=0;i<dim.overlappos.size();i++){
//overalp
//if(i==0) g.drawString(""+(dim.overlapwidth.get(i))+" "+(dim.overlappos.get(i))+" "+ (dim.overlapwidth_h.get(i))+" "+(dim.overlappos_h.get(i)) , getWidth()/2, getHeight()/2);
tmp=dim.overlapwidth.get(i);//full widths
tmp=tmp*(double)getHeight();
tmpp=dim.overlappos.get(i);
tmpp=tmpp*(double)getHeight()-0.5d*tmp;
tmph=dim.overlapwidth_h.get(i);// full widths
tmph=tmph*(double)getWidth();
tmpph=dim.overlappos_h.get(i)-0.5d*dim.overlapwidth_h.get(i);
tmpph=tmpph*(double)getWidth();
g.setColor(Color.red);
g.fillRect((int)(tmpph),(int)(tmpp), (int)(tmph),(int)(tmp) );
g.setColor(Color.black);
g.drawRect((int)(tmpph),(int)(tmpp), (int)(tmph),(int)(tmp) );
g.setColor(Color.blue);
//g.drawString(dim.overlaptext.get(i),(int)(tmpph+tmph),(int)(tmpp-1));
}
//g.drawString("mid wind "+ getWidth()+" "+ getHeight()+" : "+dim.ppm.get(0)+" >"+dim.ppm.size(), getWidth()/2, getHeight()/2);
//g.drawString("md wind "+ getWidth()+" "+ getHeight()+" : > "+dim.pos01+" "+dim.ppm.size(), getWidth()/2, getHeight()/2);
g.setColor(Color.red);
// g.setColor(Color.red); g.drawString(":"+dim.ticks_labels+".", 10, 10);
if(mousedown==1) {
g.setColor(Color.red);
//g.drawString(""+mouseX+" "+mouseY,mouseX,mouseY);
g.setColor(Color.gray);
g.drawLine(0,mouseY,getWidth(),mouseY);
g.drawLine(mouseX,0,mouseX,getHeight());
}
//signals second time for lables to be on top...
for(double addme : addmelist) //to see signals also at top and bottom when at the edge
for(int i=0;i<dim.ppm.size();i++){
// proton dimension
tmpp=(dim.hoffset-0.5d*(dim.hppm1.get(i)+dim.hppm2.get(i)))/dim.hwidth; // 0-1 units
tmpp=tmpp*(double)getWidth();
tmp=abs(dim.hppm1.get(i)-dim.hppm2.get(i))/dim.hwidth;//full width
tmp=tmp*(double)getWidth();
if(mouseX>=(int)(tmpp-0.5d*tmp) &
mouseX<=(int)(tmpp-0.5d*tmp)+ (int)(tmp) &
mouseY>= (int)((addme+dim.pos01.get(i)-0.5d*dim.width01.get(i))*(double)getHeight()) &
mouseY<= (int)((addme+dim.pos01.get(i)-0.5d*dim.width01.get(i))*(double)getHeight())+ (int)(addme+dim.width01.get(i)*(double)getHeight())) {
g.setColor(Color.red);
tmpx=(int)(tmpp-0.5d*tmp);
tmpy=(int)((addme+dim.pos01.get(i)-0.5d*dim.width01.get(i))*(double)getHeight());
if(tmpy<20){tmpy=20;tmpx+=20;}
if((getWidth()-tmpx)<250)tmpx=getWidth()-250;
g.drawString(dim.Val_n.get(i),tmpx,tmpy);
}else{
tmpx=(int)(tmpp-0.5d*tmp);
tmpy=(int)((addme+dim.pos01.get(i)-0.5d*dim.width01.get(i))*(double)getHeight());
g.setColor(Color.black);
g.drawString(dim.Lab.get(i),tmpx,tmpy);
}
}
}
public void mouseMoved(MouseEvent me){mouseX=me.getX();mouseY=me.getY();repaint();}
public void mouseDragged(MouseEvent me){mouseX=me.getX();mouseY=me.getY();repaint();}
public void mouseExited(MouseEvent me){;}
public void mouseEntered(MouseEvent me){;}
public void mouseClicked(MouseEvent me){;}
public void mousePressed(MouseEvent me){mousedown=1;repaint();}
public void mouseReleased(MouseEvent me){mousedown=0;repaint();}
}
class RightDisplayPanel extends JPanel{
Insets ins;
private Dim dim= new Dim();
RightDisplayPanel(Dim idim){
dim=idim;
//setBorder(BorderFactory.createLineBorder(Color.RED,5));
}
protected void paintComponent(Graphics g){
super.paintComponent(g);
g.setColor(Color.black);
g.drawString("F1", 120, getHeight()/2);
g.setColor(Color.blue);
g.drawLine(0,0,0,getHeight());
g.setColor(Color.BLACK);
/* for(int i=0;i<dim.ppm.size();i++){
g.drawLine(0,(int)(dim.pos01.get(i)*(double)getHeight()),getWidth(),(int)(dim.pos01.get(i)*(double)getHeight()));
}*/
g.setColor(Color.blue);
for(int i=0;i<dim.broad_ticks.size();i++){
g.drawLine(0,(int)(dim.broad_ticks.get(i)*(double)getHeight()),6,(int)(dim.broad_ticks.get(i)*(double)getHeight()));
g.drawString(dim.ticks_labels.get(i), 7, (int)(dim.broad_ticks.get(i)*(double)getHeight()) + 4 );
}
for(int i=0;i<dim.narrow_ticks.size();i++){
g.drawLine(0,(int)(dim.narrow_ticks.get(i)*(double)getHeight()),3,(int)(dim.narrow_ticks.get(i)*(double)getHeight()));
}
}
}
class BottomDisplayPanel extends JPanel{
Insets ins;
private Dim dim= new Dim();
double spaceBetweekTicks=1000,tmpd;
DecimalFormat formatter = new DecimalFormat("#");
int usablewidth;
int width_right_panel;
BottomDisplayPanel(Dim idim,int iwidth_right_panel){
dim=idim;
width_right_panel=iwidth_right_panel;
//setBorder(BorderFactory.createLineBorder(Color.RED,5));
}
protected void paintComponent(Graphics g){
usablewidth=getWidth()-width_right_panel;
super.paintComponent(g);
g.setColor(Color.black);
g.drawString("F2", usablewidth/2,29);
g.setColor(Color.blue);
g.drawLine(0,0,usablewidth,0);
if(dim.hwidth < 2000d) {spaceBetweekTicks=100d;formatter.setMinimumFractionDigits(0);}
if(dim.hwidth < 200d) {spaceBetweekTicks=10d;formatter.setMinimumFractionDigits(0);}
if(dim.hwidth < 20d) {spaceBetweekTicks=1d;formatter.setMinimumFractionDigits(0);}
if(dim.hwidth< 2d) {spaceBetweekTicks=0.1d;formatter.setMinimumFractionDigits(1);}
if(dim.hwidth < .2d) {spaceBetweekTicks=0.01d;formatter.setMinimumFractionDigits(2);}
if(dim.hwidth < .20d) {spaceBetweekTicks=0.001d;formatter.setMinimumFractionDigits(3);}
// tmpp=(dim.hoffset-0.5d*(dim.hppm1.get(i)+dim.hppm2.get(i)))/dim.hwidth; // 0-1 units
// tmpp=tmpp*(double)getWidth();
for(double here=(dim.hoffset) - ((dim.hoffset) % spaceBetweekTicks);here > dim.hoffset-dim.hwidth; here-=spaceBetweekTicks ) {
tmpd=(-here+dim.hoffset) / dim.hwidth;
g.drawLine((int)(tmpd*usablewidth),0,(int)(tmpd*usablewidth),6);
g.drawString(formatter.format(here),(int)(tmpd*usablewidth)-4,18);
}
spaceBetweekTicks/=10d;
for(double here=(dim.hoffset) - ((dim.hoffset) % spaceBetweekTicks);here > dim.hoffset-dim.hwidth; here-=spaceBetweekTicks ) {
tmpd=(-here+dim.hoffset) / dim.hwidth;
g.drawLine((int)(tmpd*usablewidth),0,(int)(tmpd*usablewidth),3);
}
}
}
class TopDisplayPanel extends JPanel{
int width_right_panel;
TopDisplayPanel(int iwidth_right_panel){
width_right_panel=iwidth_right_panel;
}
protected void paintComponent(Graphics g){
super.paintComponent(g);
g.setColor(Color.blue);
g.drawLine(0,0,getWidth()-width_right_panel,0);
}
}
class LeftDisplayPanel extends JPanel{
LeftDisplayPanel(){
}
protected void paintComponent(Graphics g){
super.paintComponent(g);
g.setColor(Color.blue);
g.drawLine(0,0,0,getHeight());
}
}
public class DisplayWindow extends JFrame {
//private Dim dim;
public CenDisplayPanel canc;
public RightDisplayPanel canr;
public LeftDisplayPanel canl;
// public TopDisplayPanel cant;
public BottomDisplayPanel canb;
public TopDisplayPanel cant;
public int i;
public int width_right_panel=150;
public DisplayWindow(Dim idim) {
setTitle("bnumber of elements"+idim.ppm.size());
// dim = new Dim();
// dim=idim;
JPanel wholepanel = new JPanel();
wholepanel.setLayout(new BorderLayout());
JPanel drawpanel = new JPanel();
drawpanel.setLayout(new BorderLayout());
canc = new CenDisplayPanel(idim);
//can.setBackground(Color.white);
drawpanel.add(BorderLayout.CENTER,canc);
canr = new RightDisplayPanel(idim);
canr.setPreferredSize(new Dimension(width_right_panel, 1));
//can.setBackground(Color.white);
drawpanel.add(BorderLayout.EAST,canr);
canb = new BottomDisplayPanel(idim,width_right_panel);
canb.setPreferredSize(new Dimension(1, 30));
//canb.setBackground(Color.white);
drawpanel.add(BorderLayout.SOUTH,canb);
cant = new TopDisplayPanel(width_right_panel);
cant.setPreferredSize(new Dimension(1, 1));
//canb.setBackground(Color.white);
drawpanel.add(BorderLayout.NORTH,cant);
canl = new LeftDisplayPanel();
canl.setPreferredSize(new Dimension(1, 1));
//canb.setBackground(Color.white);
drawpanel.add(BorderLayout.WEST,canl);
wholepanel.add(BorderLayout.CENTER,drawpanel);
getContentPane().add(wholepanel);
repaint();
}
public void update(){
repaint();
}
}