Возможность работы в консольном режиме

This commit is contained in:
Victor 2016-04-29 16:54:25 +03:00
parent e8b0acfcde
commit fad24bf8bd
2 changed files with 49 additions and 14 deletions

View File

@ -15,8 +15,42 @@ public final class ControlFrame extends JFrame {
private static final String TITLE = "Лена-бот"; private static final String TITLE = "Лена-бот";
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); boolean noGUI = false;
EventQueue.invokeLater(() -> new ControlFrame().setVisible(true)); for (int i = 0; i < args.length; i++) {
switch (args[i]) {
case "-nogui":
case "-cli":
noGUI = true;
break;
case "-prefix":
if (i + 1 >= args.length) break;
i++;
Config.ANSWER_PREFIX = args[i];
break;
case "-name":
case "-names":
if (i + 1 >= args.length) break;
i++;
Config.BOT_NAMES = args[i];
break;
case "-token":
if (i + 1 >= args.length) break;
i++;
Config.access_token = args[i];
break;
case "-gettoken":
return;
}
}
if (noGUI) {
StatisticsProcessor.init();
new Thread(new MainThread(true)).start();
} else {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
EventQueue.invokeLater(() -> new ControlFrame().setVisible(true));
}
} }
public ControlFrame() { public ControlFrame() {
@ -44,7 +78,7 @@ public final class ControlFrame extends JFrame {
settingsPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); settingsPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
settingsPanel.setLayout(new BoxLayout(settingsPanel, BoxLayout.PAGE_AXIS)); settingsPanel.setLayout(new BoxLayout(settingsPanel, BoxLayout.PAGE_AXIS));
final JTextField accessTokenField = createTextFieldLine(settingsPanel, final JTextField accessTokenField = createTextFieldLine(settingsPanel,
"Access token:", String.valueOf(Config.access_token)); "Access token:", Config.access_token);
final JTextField botNamesTokenField = createTextFieldLine(settingsPanel, final JTextField botNamesTokenField = createTextFieldLine(settingsPanel,
"Обращение:", String.valueOf(Config.BOT_NAMES)); "Обращение:", String.valueOf(Config.BOT_NAMES));
final JTextField answerPrefixField = createTextFieldLine(settingsPanel, final JTextField answerPrefixField = createTextFieldLine(settingsPanel,

View File

@ -77,6 +77,7 @@ public final class Log {
} }
public static void insertTo(StyledDocument doc, String text, String style) { public static void insertTo(StyledDocument doc, String text, String style) {
if (doc == null) return;
try { try {
doc.insertString(doc.getLength(), text, doc.getStyle(style)); doc.insertString(doc.getLength(), text, doc.getStyle(style));
} catch (BadLocationException ex) { } } catch (BadLocationException ex) { }