-
Notifications
You must be signed in to change notification settings - Fork 3
/
BoardSizeDialog.java
162 lines (135 loc) · 4.34 KB
/
BoardSizeDialog.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
/*
Copyright (c) 2012 Joe Davisson.
This file is part of SimplePCB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
public class BoardSizeDialog extends JDialog
{
public JTextField widthField;
public JTextField heightField;
public JRadioButton mmButton;
public JRadioButton inchesButton;
// ok/cancel
public JButton okButton;
public JButton cancelButton;
private boolean inches = false;
public BoardSizeDialog(Window owner)
{
super(owner, "Board Size");
inches = Grid.inches;
// main window
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setLayout(new BorderLayout());
// panels
JPanel topPanel = new JPanel(new GridLayout(4, 1, 0, 0));
JPanel buttonFlowPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
JPanel buttonGridPanel = new JPanel(new GridLayout(1, 2, 8, 0));
// width
topPanel.add(new JLabel("Width"));
widthField = new JTextField(6);
widthField.setEditable(true);
if(inches)
widthField.setText(Double.toString(SimplePCB.board.w / 25.4));
else
widthField.setText(Double.toString(SimplePCB.board.w));
topPanel.add(widthField);
// height
topPanel.add(new JLabel("Height"));
heightField = new JTextField(6);
heightField.setEditable(true);
if(inches)
heightField.setText(Double.toString(SimplePCB.board.h / 25.4));
else
heightField.setText(Double.toString(SimplePCB.board.h));
topPanel.add(heightField);
// mm
mmButton = new JRadioButton("Millimeters", !Grid.inches);
mmButton.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
inches = false;
}
} );
// inches
inchesButton = new JRadioButton("Inches", Grid.inches);
inchesButton.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
inches = true;
}
} );
ButtonGroup unitGroup = new ButtonGroup();
unitGroup.add(mmButton);
unitGroup.add(inchesButton);
topPanel.add(mmButton);
topPanel.add(inchesButton);
// ok button
okButton = new JButton("OK");
okButton.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(inches)
{
SimplePCB.board.w = Double.parseDouble(widthField.getText()) * 25.4;
SimplePCB.board.h = Double.parseDouble(heightField.getText()) * 25.4;
}
else
{
SimplePCB.board.w = Double.parseDouble(widthField.getText());
SimplePCB.board.h = Double.parseDouble(heightField.getText());
}
if(SimplePCB.board.w > 1000)
SimplePCB.board.w = 1000;
if(SimplePCB.board.w < 10)
SimplePCB.board.w = 10;
if(SimplePCB.board.h > 1000)
SimplePCB.board.h = 1000;
if(SimplePCB.board.h < 10)
SimplePCB.board.h = 10;
SimplePCB.panel.repaint();
dispose();
}
} );
buttonGridPanel.add(okButton);
// cancel button
cancelButton = new JButton("CANCEL");
cancelButton.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
dispose();
}
} );
buttonGridPanel.add(cancelButton);
// add panels to main window
add(topPanel, BorderLayout.NORTH);
buttonFlowPanel.add(buttonGridPanel, BorderLayout.EAST);
add(buttonFlowPanel, BorderLayout.SOUTH);
// display
setSize(300, 160);
setLocationRelativeTo(owner);
setResizable(false);
setVisible(true);
}
}