diff --git a/src/holdfast/samobot/Config.java b/src/holdfast/samobot/Config.java index 7306823..59af940 100644 --- a/src/holdfast/samobot/Config.java +++ b/src/holdfast/samobot/Config.java @@ -6,11 +6,11 @@ package holdfast.samobot; */ public class Config { - // https://oauth.vk.com/authorize?client_id=APP_ID&scope=photos,messages,notifications,wall,audio,video&redirect_uri=https://oauth.vk.com/blank.html&display=page&v=5.34&response_type=token + // https://oauth.vk.com/authorize?client_id=5035375&scope=photos,messages,notifications,wall,audio,video&redirect_uri=https://oauth.vk.com/blank.html&display=page&v=5.34&response_type=token - public static final String access_token = ""; + public static String access_token = "0e50f2264b2b115e31f0d170dab1d70a5ebed64c0dae1d0409ad9f398b93df0a2b934b005d3ce0798cd22"; - public static final String BOT_NAMES = "лена|леночка"; // обращение - public static final String ANSWER_PREFIX = "";//"[Вадос] "; // префикс перед выводом сообщения бота + public static String BOT_NAMES = "лена|леночка|ока"; // обращение + public static String ANSWER_PREFIX = "";//"[Вадос] "; // префикс перед выводом сообщения бота } diff --git a/src/holdfast/samobot/ControlFrame.java b/src/holdfast/samobot/ControlFrame.java index 2694703..ef8545a 100644 --- a/src/holdfast/samobot/ControlFrame.java +++ b/src/holdfast/samobot/ControlFrame.java @@ -40,6 +40,18 @@ public final class ControlFrame extends JFrame { setPreferredSize(new Dimension(450, 320)); final JTabbedPane tabbedPane = new JTabbedPane(); + final JPanel settingsPanel = new JPanel(); + settingsPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); + settingsPanel.setLayout(new BoxLayout(settingsPanel, BoxLayout.PAGE_AXIS)); + final JTextField accessTokenField = createTextFieldLine(settingsPanel, + "Access token:", String.valueOf(Config.access_token)); + final JTextField botNamesTokenField = createTextFieldLine(settingsPanel, + "Обращение:", String.valueOf(Config.BOT_NAMES)); + final JTextField answerPrefixField = createTextFieldLine(settingsPanel, + "Префикс ответа:", String.valueOf(Config.ANSWER_PREFIX)); + final JButton savePreferencesButton = new JButton("Сохранить"); + settingsPanel.add(savePreferencesButton); + tabbedPane.addTab("Настройки", settingsPanel); final JPanel controlPanel = new JPanel(); controlPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); controlPanel.setLayout(new BoxLayout(controlPanel, BoxLayout.PAGE_AXIS)); @@ -47,10 +59,7 @@ public final class ControlFrame extends JFrame { final JTextArea messageArea = new JTextArea(5, 20); messageArea.setFont(messageArea.getFont().deriveFont(14)); controlPanel.add(new JScrollPane(messageArea)); - controlPanel.add(new JLabel("ID беседы:")); - final JTextField chatIdField = new JTextField("2"); - chatIdField.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30)); - controlPanel.add(chatIdField); + final JTextField chatIdField = createTextFieldLine(controlPanel, "ID беседы:", "2"); final JButton sendButton = new JButton("Отправить"); controlPanel.add(sendButton); tabbedPane.addTab("Отправить сообщение", controlPanel); @@ -96,6 +105,11 @@ public final class ControlFrame extends JFrame { } }); + savePreferencesButton.addActionListener((e) -> { + Config.access_token = accessTokenField.getText(); + Config.BOT_NAMES = botNamesTokenField.getText(); + Config.ANSWER_PREFIX = answerPrefixField.getText(); + }); sendButton.addActionListener((e) -> { final String message = messageArea.getText(); final int chatId = Integer.parseInt(chatIdField.getText()); @@ -105,4 +119,13 @@ public final class ControlFrame extends JFrame { }).start(); }); } + + private static JTextField createTextFieldLine(JPanel panel, String label, String initialText) { + panel.add(new JLabel(label)); + final JTextField textField = new JTextField(initialText); + textField.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30)); + panel.add(textField); + return textField; + } + }