-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathConfigureChartWindow.java
More file actions
60 lines (49 loc) · 2.02 KB
/
ConfigureChartWindow.java
File metadata and controls
60 lines (49 loc) · 2.02 KB
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
import java.awt.GridLayout;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
@SuppressWarnings("serial")
public class ConfigureChartWindow extends JDialog {
/**
* A dialog box where the user can configure an existing chart's settings.
*
* @param parentWindow The JFrame that this dialog box should be tied to (and centered over.)
* @param chart The chart to configure.
*/
public ConfigureChartWindow(JFrame parentWindow, PositionedChart chart) {
setTitle("Configure Chart");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel windowContents = new JPanel();
windowContents.setBorder(new EmptyBorder(10, 10, 10, 10));
windowContents.setLayout(new BoxLayout(windowContents, BoxLayout.Y_AXIS));
JScrollPane scrollPane = new JScrollPane(windowContents, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); //Let all scrollPanel has scroll bars
add(scrollPane);
JPanel doneButtonPanel = new JPanel();
JButton doneButton = new JButton("Done");
doneButton.addActionListener(event -> dispose());
doneButtonPanel.setLayout(new GridLayout(1, 3, 10, 10));
doneButtonPanel.add(new JLabel(""));
doneButtonPanel.add(new JLabel(""));
doneButtonPanel.add(doneButton);
// show the control widgets
for(JPanel widget : chart.getWidgets()) {
windowContents.add(widget != null ? widget : Box.createVerticalStrut(10));
windowContents.add(Box.createVerticalStrut(10));
}
// leave some room, then show the done button
windowContents.add(Box.createVerticalStrut(40));
windowContents.add(doneButtonPanel);
// size and position the window
setResizable(true);
pack();
setSize((int) (getWidth() * 1.3), (int) (getWidth() * 1.3));
setLocationRelativeTo(parentWindow);
setModal(true);
setVisible(true);
}
}