-
Notifications
You must be signed in to change notification settings - Fork 0
/
Belka.java
104 lines (92 loc) · 2.72 KB
/
Belka.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
//--- Java imports ---
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
//--- Application imports ---
import belka.*;
import belka.mol.*;
import belka.draw.*;
import belka.menu.*;
/**
* Class containing main function to start Belka.
*
* @author Alexej Abyzov
*/
public class Belka
{
/**
* Starts the Belka. The following actions are performed:
* <ul>
* <li> Set system specific settings
* <li> Set look and feel
* <li> Create menus
* <li> Create main frame
* <li> Create {@link BelkaManager} object
* <li> Pass program control to {@link BelkaManager}
* </ul>
*/
public static void main(String[] args)
{
// To have apple menus in top bar and not in every window
System.setProperty("apple.laf.useScreenMenuBar","true");
// Processing input
boolean useGraphics = true;
ArrayList<String> arrListFileNames = new ArrayList<String>(4);
for (int i = 0;i < args.length;i++) {
String word = args[i];
if (word.startsWith("-")) {
if (word.equalsIgnoreCase("-nodisplay")) useGraphics = false;
} else {
arrListFileNames.add(word);
}
}
// Saving filenames in an array
int nFileNames = arrListFileNames.size();
String[] fileNames = new String[nFileNames];
for (int i = 0;i < nFileNames;i++)
fileNames[i] = arrListFileNames.get(i).toString();
BelkaManager manager = null;
// Trying open the application with graphics
if (useGraphics) try {
// Setting look and feel
try {
UIManager.
setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
// UIManager.
// setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
} catch (Exception e) {}
// Creating main frame
JFrame frame = new JFrame();
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event)
{
System.exit(0);
}
});
// Creating manager
manager = new BelkaManager(frame.getContentPane(),fileNames);
// Creating menus
JMenuBar menuBar = new JMenuBar();
menuBar.add(new MenuFile(manager));
menuBar.add(new MenuDisplay(manager));
menuBar.add(new MenuColor(manager));
menuBar.add(new MenuSelect(manager));
frame.setJMenuBar(menuBar);
// Making frame visible
frame.setBounds(new Rectangle(0,0,600,600));
frame.setVisible(true);
} catch (Exception e) {
System.err.println("Can't open display.");
System.err.println("Switching to the text mode.");
useGraphics = false;
}
// Open the application without graphics
if (!useGraphics) {
System.setProperty("java.awt.headless","true");
manager = new BelkaManager(null,fileNames);
}
// Processing user input commands
manager.run();
}
}