📄 jhylafax.java
字号:
public void exit() { if (addressBook != null) { try { addressBook.saveLayout(new SettingStore(Settings.backstore)); addressBook.store(addressBookFile); } catch (Exception e) { logger.debug("Error storing addressbook", e); ErrorDialog.showError(JHylaFAX.this, i18n.tr("Could not store addressbook"), i18n.tr("JHylaFAX Error"), e); } } saveLayout(); try { Settings.store(getSettingsFile()); } catch (IOException e) { logger.debug("Error storing settings", e); ErrorDialog.showError(JHylaFAX.this, i18n.tr("Could not store settings"), i18n.tr("JHylaFAX Error"), e); } System.exit(0); } private void initializeToolBar() { mainToolBar = new JToolBar(); //mainToolBar.setBorderPainted(false); //mainToolBar.setRollover(true); getContentPane().add(mainToolBar, BorderLayout.NORTH); mainToolBar.add(Builder.createToolBarButton(sendAction)); mainToolBar.addSeparator(); mainToolBar.add(Builder.createToolBarButton(updateStatusAction)); mainToolBar.addSeparator(); mainToolBar.add(Builder.createToolBarButton(addressBookAction)); mainToolBar.addSeparator(); mainToolBar.add(Builder.createToolBarButton(settingsDialogAction)); } private void initializeMenuBar() { JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); fileMenu = new JMenu(); menuBar.add(fileMenu); JComponent item = Builder.createMenuItem(sendAction); sendActionShortcut.setMenuItem((JMenuItem)item); fileMenu.add(item); fileMenu.add(Builder.createMenuItem(pollAction)); fileMenu.addSeparator(); item = Builder.createMenuItem(updateStatusAction); fileMenu.add(item); updateStatusActionShortcut.setMenuItem((JMenuItem)item); fileMenu.addSeparator(); fileMenu.add(Builder.createMenuItem(settingsDialogAction)); fileMenu.add(Builder.createMenuItem(settingsWizardAction)); fileMenu.addSeparator(); fileMenu.add(Builder.createMenuItem(addressBookAction)); fileMenu.addSeparator(); fileMenu.add(Builder.createMenuItem(exitAction)); helpMenu = new JMenu(); menuBar.add(helpMenu); helpMenu.add(Builder.createMenuItem(new WhatsThisAction())); helpMenu.addSeparator(); helpMenu.add(Builder.createMenuItem(aboutAction)); } private void initializeStatusBar() { statusBarPanel = new JPanel(new BorderLayout()); getContentPane().add(statusBarPanel, BorderLayout.SOUTH); statusLabel = new JLabel(); statusBarPanel.add(statusLabel, BorderLayout.CENTER); serverInfoLabel = new JLabel(); statusBarPanel.add(serverInfoLabel, BorderLayout.EAST); } public static JHylaFAX getInstance() { return app; } public HylaFAXClient getConnection(ProgressMonitor monitor) throws IOException, ServerResponseException { synchronized (connectionLock) { monitor.setText(i18n.tr("Connecting to {0}", Settings.HOSTNAME.getValue() + ":" + Settings.PORT.getValue())); if (connection == null) { connection = new HylaFAXClient(); connection.addConnectionListener(connectionHandler); connection.setPassive(Settings.USE_PASSIVE.getValue()); } logger.info("Connecting to HylaFAX server at " + Settings.HOSTNAME.getValue() + ":" + Settings.PORT.getValue()); connection.open(Settings.HOSTNAME.getValue(), Settings.PORT.getValue()); // authenticate until successful or aborted if (password == null) { password = Settings.PASSWORD.getValue(); } while (true) { if (connection.user(Settings.USERNAME.getValue())) { if (password.length() == 0) { password = requestPassword(monitor, false); if (password == null) { throw new UserAbortException(); } } try { connection.pass(password); } catch (ServerResponseException e) { // wrong password, try again password = ""; continue; } } break; } // establish admin mode if (adminPassword == null) { adminPassword = Settings.ADMIN_PASSWORD.getValue(); } if (Settings.ADMIN_MODE.getValue()) { while (true) { if (adminPassword.length() == 0) { adminPassword = requestPassword(monitor, true); if (adminPassword == null) { // just skip the admin command break; } } try { connection.admin(adminPassword); } catch (ServerResponseException e) { // wrong password, try again adminPassword = ""; continue; } break; } } return connection; } } private String requestPassword(final ProgressMonitor monitor, final boolean admin) throws ServerResponseException { final String[] password = new String[1]; Runnable runner = new Runnable() { public void run() { String host = Settings.USERNAME.getValue() + "@" + Settings.HOSTNAME.getValue(); password[0] = Dialogs.requestPassword(monitor.getComponent(), (admin) ? i18n.tr("Enter admin password for {0}:", host) : i18n.tr("Enter password for {0}:", host), i18n.tr("JHylaFAX Connection")); } }; try { SwingUtilities.invokeAndWait(runner); return password[0]; } catch (InterruptedException e) { logger.error("Unexpected exception while waiting for password", e); throw new ServerResponseException(i18n.tr("Abort by user.")); } catch (InvocationTargetException e) { logger.error("Unexpected exception while waiting for password", e); throw new ServerResponseException(i18n.tr("Abort by user.")); } } public static File getSettingsFile() throws IOException { return new File(FileHelper.getHomeDir("jhylafax"), "jhlafax.prefs"); } public static File getAddressBookFile() throws IOException { if (Settings.CUSTOMIZE_ADDRESS_BOOK_FILENAME.getValue()) { return new File(Settings.ADDRESS_BOOK_FILENAME.getValue()); } else { return new File(FileHelper.getHomeDir("jhylafax"), Settings.ADDRESS_BOOK_FILENAME.getDefaultValue()); } } public <T> T runJob(final Job<T> job) throws Exception { return jobQueue.runJob(null, job); } public <T> T runJob(JDialog owner, final Job<T> job) throws Exception { return jobQueue.runJob(owner, job); } public void updateServerInfo() { serverInfoLabel.setText( Settings.HOSTNAME.getValue() + ":" + Settings.PORT.getValue()); } public void updateLabels() { fileMenu.setText(i18n.tr("File")); helpMenu.setText(i18n.tr("Help")); for (int i = 0; i < mainTabbedPane.getTabCount(); i++) { AbstractQueuePanel panel = (AbstractQueuePanel)mainTabbedPane.getComponent(i); panel.updateLabels(); String queueName = panel.getQueueName(); if (queueName.equals("recvq")) { mainTabbedPane.setTitleAt(i, i18n.tr("Received")); } else if (queueName.equals("sendq")) { mainTabbedPane.setTitleAt(i, i18n.tr("Sending")); } else if (queueName.equals("pollq")) { mainTabbedPane.setTitleAt(i, i18n.tr("Pollable")); } else if (queueName.equals("doneq")) { mainTabbedPane.setTitleAt(i, i18n.tr("Done")); } else if (queueName.equals("docq")) { mainTabbedPane.setTitleAt(i, i18n.tr("Documents")); } } sendAction.putValue(Action.NAME, i18n.tr("Send Fax...")); sendAction.putValue(Action.SHORT_DESCRIPTION, i18n.tr("Opens a dialog for sending a fax")); pollAction.putValue(Action.NAME, i18n.tr("Poll Fax...")); pollAction.putValue(Action.SHORT_DESCRIPTION, i18n.tr("Opens a dialog for polling a fax")); addressBookAction.putValue(Action.NAME, i18n.tr("Address Book")); updateStatusAction.putValue(Action.NAME, i18n.tr("Update Status")); updateStatusAction.putValue(Action.SHORT_DESCRIPTION, i18n.tr("Queries the status from the server")); settingsDialogAction.putValue(Action.NAME, i18n.tr("Settings...")); settingsDialogAction.putValue(Action.SHORT_DESCRIPTION, i18n.tr("Displays the settings dialog")); settingsDialogAction.updateLabels(); settingsWizardAction.putValue(Action.NAME, i18n.tr("Setup Wizard...")); settingsWizardAction.putValue(Action.SHORT_DESCRIPTION, i18n.tr("Displays the settings wizard")); settingsWizardAction.updateLabels(); exitAction.putValue(Action.NAME, i18n.tr("Exit")); exitAction.putValue(Action.SHORT_DESCRIPTION, i18n.tr("Closes the application")); aboutAction.putValue(Action.NAME, i18n.tr("About...")); aboutAction.putValue(Action.SHORT_DESCRIPTION, i18n.tr("Opens a dialog that displays funny information")); GUIHelper.setMnemonics(getJMenuBar()); } /** * @param args */ public static void main(final String[] args) { final ArgsHandler handler = new ArgsHandler(); handler.evaluate(args); evaluateArgumentsPreVisible(handler); ThreadGroup tg = new ThreadGroup("JHylaFAXThreadGroup") { public void uncaughtException(Thread t,Throwable e) { e.printStackTrace(); } };// System.setProperty("sun.awt.exception.handler", // "xnap.util.XNapAWTExceptionHandler"); Thread mainRunner = new Thread(tg, "JHylaFAXMain") { public void run() { setContextClassLoader(JHylaFAX.class.getClassLoader()); JHylaFAX app = new JHylaFAX(); app.setVisible(true); app.evaluateArgumentsPostVisible(handler); } }; mainRunner.start(); } private static void evaluateArgumentsPreVisible(ArgsHandler handler) { // configure logging URL url = JHylaFAX.class.getResource(handler.getLogConfigFilename()); if (url != null) { PropertyConfigurator.configure(url); } else { System.err.println("Could not find logging configuration: " + handler.getLogConfigFilename()); BasicConfigurator.configure(); }// InputStream in = ClassLoader.getSystemResourceAsStream(handler.getLogConfigFilename());// if (in != null) {// try {// LogManager.getLogManager().readConfiguration(in);// }// catch (IOException e) {// logger.warn("Error reading logging configuration", e);// try {// in.close();// } catch (IOException e1) {}// }// }// else {// logger.warn("Could not find logging configuration: " + handler.getLogConfigFilename());// } } protected void evaluateArgumentsPostVisible(ArgsHandler handler) { if (!Settings.HAS_SEEN_WIZARD.getValue()) { SettingsWizard wizard = new SettingsWizard(JHylaFAX.this); wizard.setModal(true); wizard.setLocationRelativeTo(JHylaFAX.this); wizard.setVisible(true); } if (Settings.UPDATE_ON_STARTUP.getValue()) { updateTables(); } String[] filenames = handler.getFilenames(); String[] numbers = handler.getNumbers(); File tempFile = null; if (handler.getReadStdin()) { tempFile = saveStdInToFile(); if (tempFile != null) { // prepend path of temp file to filename array String[] newFilenames = new String[filenames.length + 1]; newFilenames[0] = tempFile.getAbsolutePath(); System.arraycopy(filenames, 0, newFilenames, 1, filenames.length); filenames = newFilenames; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -