Example usage for org.apache.poi.util IOUtils readFully

List of usage examples for org.apache.poi.util IOUtils readFully

Introduction

In this page you can find the example usage for org.apache.poi.util IOUtils readFully.

Prototype

public static int readFully(ReadableByteChannel channel, ByteBuffer b) throws IOException 

Source Link

Document

Same as the normal channel.read(b), but tries to ensure that the buffer is filled completely if possible, i.e.

Usage

From source file:com.ssi.main.view.SetupView.java

License:Open Source License

public SetupView() {
    frameWidth = 1366;// ww  w . ja  v  a2 s. c  o  m
    frameHeight = 768;
    //        try {
    //            Dimension frameSize = Application.MAIN_FRAME.getSize();
    //            frameWidth = (int)frameSize.getWidth();
    //            frameHeight = (int)frameSize.getHeight();
    //        } catch (Exception e) {
    //        }
    //        
    this.setSize(frameWidth, frameHeight);

    ImageIcon imgHome = new ImageIcon("res/img/home.png");
    btnHome = DrawableUtils.createImageButton("", imgHome, null);
    btnHome.setBounds(20, 20, imgHome.getIconWidth(), imgHome.getIconHeight());
    DrawableUtils.setMouseListener(btnHome, "res/img/home");
    btnHome.addActionListener(this);
    this.add(btnHome);
    setLayout(new BorderLayout(0, 0));

    desktopPane = new JDesktopPane();
    desktopPane.setBackground(SystemColor.window);
    add(desktopPane);

    fileChooseiFrame = new JInternalFrame(I18NUtil.getInstance().getString("SetupView.fileChooseiFrame.title"));
    fileChooseiFrame.setBounds(300, 145, 573, 430);
    desktopPane.add(fileChooseiFrame);
    fileChooseiFrame.setClosable(true);
    fileChooseiFrame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
    fileChooseiFrame.addInternalFrameListener(new InternalFrameAdapter() {
        @Override
        public void internalFrameActivated(InternalFrameEvent e) {
            fileChooseiFrame.setBounds(300, 145, 573, 430);
        }
    });
    fileChooseiFrame.getContentPane().setLayout(new CardLayout(0, 0));

    jfcBgImg = new JFileChooser();
    jfcBgImg.setAcceptAllFileFilterUsed(true);
    jfcBgImg.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (e.getActionCommand().equals(JFileChooser.APPROVE_SELECTION)) {
                tfBgImg.setText(jfcBgImg.getSelectedFile().getPath());
                fileChooseiFrame.doDefaultCloseAction();
            } else if (e.getActionCommand().equals(JFileChooser.CANCEL_SELECTION)) {
                fileChooseiFrame.doDefaultCloseAction();
            }
        }
    });
    addFileChooserFilters(jfcBgImg);
    fileChooseiFrame.getContentPane().add(jfcBgImg, "name_267237042361245");
    fileChooseiFrame.pack();
    fileChooseiFrame.setVisible(true);

    JPanel mainPanel = new JPanel();
    mainPanel.setBounds(0, 0, frameWidth, frameHeight);
    desktopPane.add(mainPanel);
    mainPanel.setLayout(null);

    createVirtualKeyboard(mainPanel, "SetupView");

    JPanel panelUI = new JPanel();
    panelUI.setBorder(new TitledBorder(null, I18NUtil.getInstance().getString("SetupView.panelUI.borderTitle"), //$NON-NLS-1$
            TitledBorder.LEADING, TitledBorder.TOP, null, null));
    panelUI.setBounds(100, 100, 420, 185);
    mainPanel.add(panelUI);
    panelUI.setLayout(null);

    JLabel lbSysLang = new JLabel(I18NUtil.getInstance().getString("SetupView.lbSysLang.text")); //$NON-NLS-1$
    lbSysLang.setHorizontalAlignment(SwingConstants.RIGHT);
    lbSysLang.setBounds(0, 35, 180, 25);
    panelUI.add(lbSysLang);

    cbSysLang = new JComboBox();
    cbSysLang.setModel(new DefaultComboBoxModel(new String[] { "", "English" }));
    cbSysLang.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int idx = cbSysLang.getSelectedIndex();
            if (idx == 0) {
                SSIConfig.put("system.locale.language", "zh");
                SSIConfig.put("system.locale.country", "CN");
            } else if (idx == 1) {
                SSIConfig.put("system.locale.language", "en");
                SSIConfig.put("system.locale.country", "US");
            }
        }
    });
    cbSysLang.setBounds(190, 35, 200, 25);
    panelUI.add(cbSysLang);

    JLabel lbStartingView = new JLabel(I18NUtil.getInstance().getString("SetupView.lbStartingView.text")); //$NON-NLS-1$
    lbStartingView.setHorizontalAlignment(SwingConstants.RIGHT);
    lbStartingView.setBounds(0, 70, 180, 25);
    panelUI.add(lbStartingView);

    cbStartingView = new JComboBox();
    cbStartingView.setModel(new DefaultComboBoxModel(
            new String[] { "MainView", "SignInView", "SetupView", "RecordView", "StaffView" }));
    cbStartingView.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            SSIConfig.put("system.startup.view", (String) cbStartingView.getSelectedItem());
        }
    });
    cbStartingView.setBounds(190, 70, 200, 25);
    panelUI.add(cbStartingView);

    JLabel lbBgImg = new JLabel(I18NUtil.getInstance().getString("SetupView.lbBgImg.text")); //$NON-NLS-1$
    lbBgImg.setHorizontalAlignment(SwingConstants.RIGHT);
    lbBgImg.setBounds(0, 105, 180, 25);
    panelUI.add(lbBgImg);

    tfBgImg = new JTextField();
    tfBgImg.getDocument().addDocumentListener(new JValueChangedListener() {
        @Override
        void actionHandler() {
            SSIConfig.put("system.startup.background", tfBgImg.getText());
        }
    });
    tfBgImg.setEditable(false);
    tfBgImg.setBounds(190, 105, 120, 25);
    panelUI.add(tfBgImg);
    tfBgImg.setColumns(10);

    JButton btnChoose = new JButton(I18NUtil.getInstance().getString("SetupView.btnChoose.text")); //$NON-NLS-1$
    btnChoose.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            jfcBgImg.setSelectedFile(new File(tfBgImg.getText()));
            fileChooseiFrame.setVisible(true);
        }
    });
    btnChoose.setBounds(320, 105, 70, 25);
    panelUI.add(btnChoose);

    JLabel lbVerifyViews = new JLabel(I18NUtil.getInstance().getString("SetupView.lbVerifyViews.text")); //$NON-NLS-1$
    lbVerifyViews.setHorizontalAlignment(SwingConstants.RIGHT);
    lbVerifyViews.setBounds(0, 140, 180, 25);
    panelUI.add(lbVerifyViews);

    rdbtnYes_VerifyViews = new JRadioButton(
            I18NUtil.getInstance().getString("SetupView.rdbtnYes_VerifyViews.text"));
    rdbtnYes_VerifyViews.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            pwfVerifyViews.setEnabled(true);
            SSIConfig.put("system.verifyviews", "yes");

            char[] password = pwfVerifyViews.getPassword();
            if (password == null || password.length == 0) {
                JOptionPane.showInternalMessageDialog(Application.MAIN_FRAME.getContentPane(),
                        "?", "??", JOptionPane.INFORMATION_MESSAGE);
                pwfVerifyViews.requestFocusInWindow();
            } else {
                SSIConfig.put("system.password", new String(password));
            }
        }
    });
    rdbtnYes_VerifyViews.setSelected(true);
    rdbtnYes_VerifyViews.setBounds(190, 140, 50, 25);
    panelUI.add(rdbtnYes_VerifyViews);

    rdbtnNo_VerifyViews = new JRadioButton(
            I18NUtil.getInstance().getString("SetupView.rdbtnNo_VerifyViews.text"));
    rdbtnNo_VerifyViews.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            pwfVerifyViews.setText("");
            pwfVerifyViews.setEnabled(false);
            SSIConfig.put("system.verifyviews", "no");
        }
    });
    rdbtnNo_VerifyViews.setBounds(235, 140, 50, 25);
    panelUI.add(rdbtnNo_VerifyViews);

    ButtonGroup btg_VerifyViews = new ButtonGroup();
    btg_VerifyViews.add(rdbtnYes_VerifyViews);
    btg_VerifyViews.add(rdbtnNo_VerifyViews);

    pwfVerifyViews = new JPasswordField();
    pwfVerifyViews.getDocument().addDocumentListener(new JValueChangedListener() {
        @Override
        void actionHandler() {
            SSIConfig.put("system.password", new String(pwfVerifyViews.getPassword()));
        }
    });
    pwfVerifyViews.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            char[] password = pwfVerifyViews.getPassword();
            if (password == null || password.length == 0) {
                rdbtnNo_VerifyViews.doClick();
            }
        }
    });
    pwfVerifyViews.setBounds(290, 140, 100, 25);
    panelUI.add(pwfVerifyViews);

    JPanel panelSynth = new JPanel();
    panelSynth.setLayout(null);
    panelSynth.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"),
            I18NUtil.getInstance().getString("SetupView.panelSynth.borderTitle"), TitledBorder.LEADING, //$NON-NLS-1$
            TitledBorder.TOP, null, null));
    panelSynth.setBounds(100, 305, 420, 185);
    mainPanel.add(panelSynth);

    JLabel lbSynthVoice = new JLabel(I18NUtil.getInstance().getString("SetupView.lbSynthVoice.text")); //$NON-NLS-1$
    lbSynthVoice.setHorizontalAlignment(SwingConstants.RIGHT);
    lbSynthVoice.setBounds(0, 35, 180, 25);
    panelSynth.add(lbSynthVoice);

    cbSynthVoice = new JComboBox();
    String[] voiceList = model.getVoiceList();
    cbSynthVoice.setModel(new DefaultComboBoxModel(voiceList));
    cbSynthVoice.getModel().addListDataListener(new ListDataListener() {
        @Override
        public void intervalRemoved(ListDataEvent e) {
        }

        @Override
        public void intervalAdded(ListDataEvent e) {
        }

        @Override
        public void contentsChanged(ListDataEvent e) {
            String selectedItem = (String) ((DefaultComboBoxModel) e.getSource()).getSelectedItem();
            System.out.println("Conent Changed: " + selectedItem);
            SSIConfig.put("synth.voiceName", selectedItem.split("-")[1]);
        }
    });
    cbSynthVoice.setBounds(190, 35, 200, 25);
    panelSynth.add(cbSynthVoice);

    JLabel lbSynthSpeed = new JLabel(I18NUtil.getInstance().getString("SetupView.lbSynthSpeed.text")); //$NON-NLS-1$
    lbSynthSpeed.setHorizontalAlignment(SwingConstants.RIGHT);
    lbSynthSpeed.setBounds(0, 70, 180, 25);
    panelSynth.add(lbSynthSpeed);

    sdSynthSpeed = new JSlider();
    sdSynthSpeed.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            SSIConfig.put("synth.speed", sdSynthSpeed.getValue() + "");
        }
    });
    sdSynthSpeed.setSnapToTicks(true);
    sdSynthSpeed.setPaintTicks(true);
    sdSynthSpeed.setMinorTickSpacing(10);
    sdSynthSpeed.setMajorTickSpacing(20);
    sdSynthSpeed.setBounds(190, 70, 200, 25);
    panelSynth.add(sdSynthSpeed);

    JLabel lbSynthRate = new JLabel(I18NUtil.getInstance().getString("SetupView.lbSynthRate.text")); //$NON-NLS-1$
    lbSynthRate.setHorizontalAlignment(SwingConstants.RIGHT);
    lbSynthRate.setBounds(0, 105, 180, 25);
    panelSynth.add(lbSynthRate);

    sdSynthRate = new JSlider();
    sdSynthRate.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            SSIConfig.put("synth.sampleRate", sdSynthRate.getValue() + "");
        }
    });
    sdSynthRate.setSnapToTicks(true);
    sdSynthRate.setValue(80);
    sdSynthRate.setMaximum(120);
    sdSynthRate.setPaintTicks(true);
    sdSynthRate.setMajorTickSpacing(40);
    sdSynthRate.setBounds(190, 105, 200, 25);
    panelSynth.add(sdSynthRate);

    JLabel lbSynthVolume = new JLabel(I18NUtil.getInstance().getString("SetupView.lbSynthVolume.text")); //$NON-NLS-1$
    lbSynthVolume.setHorizontalAlignment(SwingConstants.RIGHT);
    lbSynthVolume.setBounds(0, 140, 180, 25);
    panelSynth.add(lbSynthVolume);

    sdSynthVolume = new JSlider();
    sdSynthVolume.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            SSIConfig.put("synth.volume", sdSynthVolume.getValue() + "");
        }
    });
    sdSynthVolume.setSnapToTicks(true);
    sdSynthVolume.setValue(80);
    sdSynthVolume.setPaintTicks(true);
    sdSynthVolume.setMinorTickSpacing(5);
    sdSynthVolume.setMajorTickSpacing(10);
    sdSynthVolume.setBounds(190, 140, 200, 25);
    panelSynth.add(sdSynthVolume);

    JPanel panelScanner = new JPanel();
    panelScanner.setLayout(null);
    panelScanner.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"),
            I18NUtil.getInstance().getString("SetupView.panelScanner.borderTitle"), TitledBorder.LEADING, //$NON-NLS-1$
            TitledBorder.TOP, null, null));
    panelScanner.setBounds(560, 100, 420, 290);
    mainPanel.add(panelScanner);

    JLabel lbCode = new JLabel(I18NUtil.getInstance().getString("SetupView.lbCode.text")); //$NON-NLS-1$
    lbCode.setHorizontalAlignment(SwingConstants.RIGHT);
    lbCode.setBounds(0, 35, 180, 25);
    panelScanner.add(lbCode);

    cbCodeQr = new JCheckBox(I18NUtil.getInstance().getString("SetupView.cbCodeQr.text"));
    cbCodeQr.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (cbCodeQr.isSelected()) {
                SSIConfig.put("SetupView.scanner.code.QR", "on");
            } else {
                SSIConfig.put("SetupView.scanner.code.QR", "off");
            }
        }
    });
    cbCodeQr.setBounds(190, 36, 50, 25);
    panelScanner.add(cbCodeQr);

    cbCodeDm = new JCheckBox(I18NUtil.getInstance().getString("SetupView.cbCodeDm.text"));
    cbCodeDm.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (cbCodeDm.isSelected()) {
                SSIConfig.put("SetupView.scanner.code.DM", "on");
            } else {
                SSIConfig.put("SetupView.scanner.code.DM", "off");
            }
        }
    });
    cbCodeDm.setBounds(235, 35, 50, 25);
    panelScanner.add(cbCodeDm);

    cbCodeBar = new JCheckBox(I18NUtil.getInstance().getString("SetupView.cbCodeBar.text"));
    cbCodeBar.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (cbCodeBar.isSelected()) {
                SSIConfig.put("SetupView.scanner.code.Bar", "on");
            } else {
                SSIConfig.put("SetupView.scanner.code.Bar", "off");
            }
        }
    });
    cbCodeBar.setBounds(280, 35, 55, 25);
    panelScanner.add(cbCodeBar);

    JLabel lbInterval = new JLabel(I18NUtil.getInstance().getString("SetupView.lbInterval.text")); //$NON-NLS-1$
    lbInterval.setHorizontalAlignment(SwingConstants.RIGHT);
    lbInterval.setBounds(0, 70, 180, 25);
    panelScanner.add(lbInterval);

    tfInterval = new JTextField();
    tfInterval.getDocument().addDocumentListener(new JValueChangedListener() {
        @Override
        void actionHandler() {
            SSIConfig.put("SetupView.scanner.interval", tfInterval.getText());
        }
    });
    tfInterval.setBounds(190, 70, 120, 25);
    panelScanner.add(tfInterval);
    tfInterval.setColumns(10);

    JLabel lbIntervalUnit = new JLabel(I18NUtil.getInstance().getString("SetupView.lbIntervalUnit.text")); //$NON-NLS-1$
    lbIntervalUnit.setBounds(320, 70, 50, 25);
    panelScanner.add(lbIntervalUnit);

    JLabel lbAi = new JLabel(I18NUtil.getInstance().getString("SetupView.lbAi.text")); //$NON-NLS-1$
    lbAi.setHorizontalAlignment(SwingConstants.RIGHT);
    lbAi.setBounds(0, 105, 180, 25);
    panelScanner.add(lbAi);

    rdbtnYes_Ai = new JRadioButton(I18NUtil.getInstance().getString("SetupView.rdbtnYes_Ai.text"));
    rdbtnYes_Ai.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            tfAiTime.setEnabled(true);
            SSIConfig.put("SetupView.scanner.ai", "yes");
        }
    });
    rdbtnYes_Ai.setBounds(190, 105, 50, 25);
    panelScanner.add(rdbtnYes_Ai);

    rdbtnNo_Ai = new JRadioButton(I18NUtil.getInstance().getString("SetupView.rdbtnNo_Ai.text"));
    rdbtnNo_Ai.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            tfAiTime.setEnabled(false);
            SSIConfig.put("SetupView.scanner.ai", "no");
        }
    });

    JLabel lbAiTimePrefix = new JLabel(I18NUtil.getInstance().getString("SetupView.lbAiTimePrefix.text")); //$NON-NLS-1$
    lbAiTimePrefix.setBounds(285, 105, 25, 25);
    panelScanner.add(lbAiTimePrefix);
    rdbtnNo_Ai.setBounds(235, 105, 50, 25);
    panelScanner.add(rdbtnNo_Ai);

    ButtonGroup btg_Ai = new ButtonGroup();
    btg_Ai.add(rdbtnYes_Ai);
    btg_Ai.add(rdbtnNo_Ai);

    tfAiTime = new JTextField();
    tfAiTime.getDocument().addDocumentListener(new JValueChangedListener() {
        @Override
        void actionHandler() {
            SSIConfig.put("SetupView.scanner.aitime", tfAiTime.getText());
        }
    });
    tfAiTime.setBounds(300, 105, 50, 25);
    panelScanner.add(tfAiTime);
    tfAiTime.setColumns(10);

    JLabel lbAiTimeSuffix = new JLabel(I18NUtil.getInstance().getString("SetupView.lbAiTimeSuffix.text")); //$NON-NLS-1$
    lbAiTimeSuffix.setBounds(355, 105, 50, 25);
    panelScanner.add(lbAiTimeSuffix);

    JLabel lbBeep = new JLabel(I18NUtil.getInstance().getString("SetupView.lbBeep.text")); //$NON-NLS-1$
    lbBeep.setHorizontalAlignment(SwingConstants.RIGHT);
    lbBeep.setBounds(0, 140, 180, 25);
    panelScanner.add(lbBeep);

    rdbtnYes_Beep = new JRadioButton(I18NUtil.getInstance().getString("SetupView.rdbtnYes_Beep.text"));
    rdbtnYes_Beep.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            tfBeepTimes.setEnabled(true);
            SSIConfig.put("SetupView.scanner.beep", "yes");
        }
    });
    rdbtnYes_Beep.setBounds(190, 140, 50, 25);
    panelScanner.add(rdbtnYes_Beep);

    rdbtnNo_Beep = new JRadioButton(I18NUtil.getInstance().getString("SetupView.rdbtnNo_Beep.text"));
    rdbtnNo_Beep.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            tfBeepTimes.setEnabled(false);
            SSIConfig.put("SetupView.scanner.beep", "no");
        }
    });
    rdbtnNo_Beep.setBounds(235, 140, 50, 25);
    panelScanner.add(rdbtnNo_Beep);

    ButtonGroup btg_Beep = new ButtonGroup();
    btg_Beep.add(rdbtnYes_Beep);
    btg_Beep.add(rdbtnNo_Beep);

    tfBeepTimes = new JComboBox();
    tfBeepTimes.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            SSIConfig.put("SetupView.scanner.beep.times", (String) tfBeepTimes.getSelectedItem());
        }
    });
    tfBeepTimes.setModel(new DefaultComboBoxModel(new String[] { "1", "2", "3" }));
    tfBeepTimes.setBounds(300, 142, 50, 21);
    panelScanner.add(tfBeepTimes);

    JLabel lbBeepTimes = new JLabel(I18NUtil.getInstance().getString("SetupView.lbBeepTimes.text")); //$NON-NLS-1$
    lbBeepTimes.setBounds(355, 140, 50, 25);
    panelScanner.add(lbBeepTimes);

    JLabel lbLight = new JLabel(I18NUtil.getInstance().getString("SetupView.lbLight.text")); //$NON-NLS-1$
    lbLight.setHorizontalAlignment(SwingConstants.RIGHT);
    lbLight.setBounds(0, 170, 180, 25);
    panelScanner.add(lbLight);

    JRadioButton rdbtnYes_Light = new JRadioButton(
            I18NUtil.getInstance().getString("SetupView.rdbtnYes_Light.text")); //$NON-NLS-1$
    rdbtnYes_Light.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            LOG.debug("??");
            VguangApi.lightOn();
        }
    });
    //        rdbtnYes_Light.setSelected(true);
    rdbtnYes_Light.setBounds(190, 170, 50, 25);
    panelScanner.add(rdbtnYes_Light);

    JRadioButton rdbtnNo_Light = new JRadioButton(
            I18NUtil.getInstance().getString("SetupView.rdbtnNo_Light.text")); //$NON-NLS-1$
    rdbtnNo_Light.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            LOG.debug("??");
            VguangApi.lightOff();
        }
    });
    rdbtnNo_Light.setBounds(235, 170, 50, 25);
    panelScanner.add(rdbtnNo_Light);

    ButtonGroup btng_Light = new ButtonGroup();
    btng_Light.add(rdbtnYes_Light);
    btng_Light.add(rdbtnNo_Light);

    JButton btnOpen = new JButton(I18NUtil.getInstance().getString("SetupView.btnOpen.text")); //$NON-NLS-1$
    btnOpen.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            VguangApi.openDevice();
        }
    });
    btnOpen.setBounds(20, 240, 120, 25);
    panelScanner.add(btnOpen);

    JButton btnClose = new JButton(I18NUtil.getInstance().getString("SetupView.btnClose.text")); //$NON-NLS-1$
    btnClose.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            VguangApi.closeDevice();
            lbDeviceState.setText(I18NUtil.getInstance().getString("SetupView.lbDeviceState.inactive.text"));
            lbDeviceState.setEnabled(false);
        }
    });
    btnClose.setBounds(150, 240, 120, 25);
    panelScanner.add(btnClose);

    JButton btnApply = new JButton(I18NUtil.getInstance().getString("SetupView.btnApply.text")); //$NON-NLS-1$
    btnApply.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            applySetting();
        }
    });
    btnApply.setBounds(280, 240, 120, 25);
    panelScanner.add(btnApply);

    JLabel lbDevice = new JLabel(I18NUtil.getInstance().getString("SetupView.lbDevice.text")); //$NON-NLS-1$
    lbDevice.setBounds(0, 205, 180, 25);
    panelScanner.add(lbDevice);
    lbDevice.setHorizontalAlignment(SwingConstants.RIGHT);

    lbDeviceState = new JLabel(I18NUtil.getInstance().getString("SetupView.lbDeviceState.active.text"));
    lbDeviceState.setBounds(190, 205, 80, 25);
    panelScanner.add(lbDeviceState);

    JPanel panelDecode = new JPanel();
    panelDecode.setLayout(null);
    panelDecode.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"),
            I18NUtil.getInstance().getString("SetupView.panelDecode.borderTitle"), TitledBorder.LEADING, //$NON-NLS-1$
            TitledBorder.TOP, null, null));
    panelDecode.setBounds(560, 410, 420, 280);
    mainPanel.add(panelDecode);

    JLabel lbScanResult = new JLabel(I18NUtil.getInstance().getString("SetupView.lbScanResult.text")); //$NON-NLS-1$
    lbScanResult.setHorizontalAlignment(SwingConstants.RIGHT);
    lbScanResult.setBounds(0, 35, 100, 25);
    panelDecode.add(lbScanResult);

    tpScanResult = new JTextPane();
    tpScanResult.setBounds(110, 35, 290, 100);
    panelDecode.add(tpScanResult);

    JLabel lbDecodeResult = new JLabel(I18NUtil.getInstance().getString("SetupView.lbDecodeResult.text")); //$NON-NLS-1$
    lbDecodeResult.setHorizontalAlignment(SwingConstants.RIGHT);
    lbDecodeResult.setBounds(0, 145, 100, 25);
    panelDecode.add(lbDecodeResult);

    tpDecodeResult = new JTextPane();
    tpDecodeResult.setBounds(110, 145, 290, 100);
    panelDecode.add(tpDecodeResult);

    JPanel panelReport = new JPanel();
    panelReport.setLayout(null);
    panelReport.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"),
            I18NUtil.getInstance().getString("SetupView.panelReport.borderTitle"), TitledBorder.LEADING, //$NON-NLS-1$
            TitledBorder.TOP, null, null));
    panelReport.setBounds(100, 510, 420, 180);
    mainPanel.add(panelReport);

    JLabel lbEmailSenderAddress = new JLabel(
            I18NUtil.getInstance().getString("SetupView.lbEmailSenderAddress.text")); //$NON-NLS-1$
    lbEmailSenderAddress.setHorizontalAlignment(SwingConstants.RIGHT);
    lbEmailSenderAddress.setBounds(0, 35, 180, 25);
    panelReport.add(lbEmailSenderAddress);

    tfEmailSenderAddress = new JTextField();
    tfEmailSenderAddress.getDocument().addDocumentListener(new JValueChangedListener() {
        @Override
        void actionHandler() {
            SSIConfig.put("email.address", tfEmailSenderAddress.getText());
        }
    });
    tfEmailSenderAddress.setBounds(190, 35, 200, 25);
    panelReport.add(tfEmailSenderAddress);
    tfEmailSenderAddress.setColumns(10);

    JLabel lbEmailSenderPwd = new JLabel(I18NUtil.getInstance().getString("SetupView.lbEmailMailBoxPwd.text")); //$NON-NLS-1$
    lbEmailSenderPwd.setHorizontalAlignment(SwingConstants.RIGHT);
    lbEmailSenderPwd.setBounds(0, 70, 180, 25);
    panelReport.add(lbEmailSenderPwd);

    pfEmailSenderPwd = new JPasswordField();
    pfEmailSenderPwd.setColumns(10);
    pfEmailSenderPwd.getDocument().addDocumentListener(new JValueChangedListener() {
        @Override
        void actionHandler() {
            SSIConfig.put("email.password", new String(pfEmailSenderPwd.getPassword()));
        }
    });
    pfEmailSenderPwd.setBounds(190, 70, 200, 25);
    panelReport.add(pfEmailSenderPwd);

    JLabel lbEmailSmtpServer = new JLabel(I18NUtil.getInstance().getString("SetupView.lbEmailSmtpServer.text")); //$NON-NLS-1$
    lbEmailSmtpServer.setHorizontalAlignment(SwingConstants.RIGHT);
    lbEmailSmtpServer.setBounds(0, 105, 180, 25);
    panelReport.add(lbEmailSmtpServer);

    tfEmailSmtpServer = new JTextField();
    tfEmailSmtpServer.setColumns(10);
    tfEmailSmtpServer.getDocument().addDocumentListener(new JValueChangedListener() {
        @Override
        void actionHandler() {
            SSIConfig.put("email.smtp", tfEmailSmtpServer.getText());
        }
    });
    tfEmailSmtpServer.setBounds(190, 105, 200, 25);
    panelReport.add(tfEmailSmtpServer);

    JLabel lbEmailRecipientAddress = new JLabel(
            I18NUtil.getInstance().getString("SetupView.lbEmailRecipientAddress.text")); //$NON-NLS-1$
    lbEmailRecipientAddress.setHorizontalAlignment(SwingConstants.RIGHT);
    lbEmailRecipientAddress.setBounds(0, 140, 180, 25);
    panelReport.add(lbEmailRecipientAddress);

    tfEmailRecipientAddress = new JTextField();
    tfEmailRecipientAddress.setColumns(10);
    tfEmailRecipientAddress.getDocument().addDocumentListener(new JValueChangedListener() {
        @Override
        void actionHandler() {
            SSIConfig.put("email.recipients", tfEmailRecipientAddress.getText());
        }

    });
    tfEmailRecipientAddress.setBounds(190, 140, 200, 25);
    panelReport.add(tfEmailRecipientAddress);

    JButton btnAboutSoftware = new JButton(I18NUtil.getInstance().getString("SetupView.btnAboutSoftware.text")); //$NON-NLS-1$
    btnAboutSoftware.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String message = "";
            FileInputStream fileInputStream = null;
            try {
                String sysDir = System.getProperty("user.dir");
                File readMe = new File(sysDir + "/README.txt");
                fileInputStream = new FileInputStream(readMe);
                byte[] data = new byte[fileInputStream.available()];
                IOUtils.readFully(fileInputStream, data);
                message = new String(data, "UTF-8");
            } catch (IOException ex) {
                ex.printStackTrace();
            } finally {
                if (fileInputStream != null) {
                    try {
                        fileInputStream.close();
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                }
            }
            JOptionPane.showInternalMessageDialog(Application.MAIN_FRAME.getContentPane(), message,
                    I18NUtil.getInstance().getString("SetupView.btnAboutSoftware.text"),
                    JOptionPane.INFORMATION_MESSAGE);
        }
    });
    btnAboutSoftware.setBounds(230, 65, 120, 25);
    mainPanel.add(btnAboutSoftware);

    JButton btnAboutThisVersion = new JButton(
            I18NUtil.getInstance().getString("SetupView.btnAboutThisVersion.text")); //$NON-NLS-1$
    btnAboutThisVersion.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String message = "";
            FileInputStream fileInputStream = null;
            try {
                String sysDir = System.getProperty("user.dir");
                File readMe = new File(sysDir + "/AboutThisVersion.txt");
                fileInputStream = new FileInputStream(readMe);
                byte[] data = new byte[fileInputStream.available()];
                IOUtils.readFully(fileInputStream, data);
                message = new String(data, "UTF-8");
            } catch (IOException ex) {
                ex.printStackTrace();
            } finally {
                if (fileInputStream != null) {
                    try {
                        fileInputStream.close();
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                }
            }
            JOptionPane.showInternalMessageDialog(Application.MAIN_FRAME.getContentPane(), message,
                    I18NUtil.getInstance().getString("SetupView.btnAboutThisVersion.text"),
                    JOptionPane.INFORMATION_MESSAGE);
        }
    });
    btnAboutThisVersion.setBounds(360, 65, 120, 25);
    mainPanel.add(btnAboutThisVersion);

    JButton btnRestart = new JButton(I18NUtil.getInstance().getString("SetupView.btnRestart.text"));
    btnRestart.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            SSIConfig.save();
            Runtime.getRuntime().addShutdownHook(new Thread() {
                public void run() {
                    try {
                        Runtime.getRuntime()
                                .exec("java -jar ssi.jar " + (Application.debugMode ? "-debug" : ""));
                    } catch (IOException e) {
                        LOG.error("ERROR!", e);
                    }
                }
            });
            System.exit(0);
        }
    });
    btnRestart.setBounds(100, 65, 120, 25);
    mainPanel.add(btnRestart);

    setDefaultValues();

    applyVirtualKeyboard(mainPanel, "SetupView");

}

From source file:mj.ocraptor.extraction.tika.parser.image.PSDParser.java

License:Apache License

public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context)
        throws IOException, SAXException, TikaException {
    // Check for the magic header signature
    byte[] signature = new byte[4];
    IOUtils.readFully(stream, signature);
    if (signature[0] == (byte) '8' && signature[1] == (byte) 'B' && signature[2] == (byte) 'P'
            && signature[3] == (byte) 'S') {
        // Good, signature found
    } else {//from  www.  ja v  a2s  .  co m
        throw new TikaException("PSD/PSB magic signature invalid");
    }

    // Check the version
    int version = EndianUtils.readUShortBE(stream);
    if (version == 1 || version == 2) {
        // Good, we support these two
    } else {
        throw new TikaException("Invalid PSD/PSB version " + version);
    }

    // Skip the reserved block
    IOUtils.readFully(stream, new byte[6]);

    // Number of channels in the image
    int numChannels = EndianUtils.readUShortBE(stream);
    // TODO Identify a suitable metadata key for this

    // Width and Height
    int height = EndianUtils.readIntBE(stream);
    int width = EndianUtils.readIntBE(stream);
    metadata.set(TIFF.IMAGE_LENGTH, height);
    metadata.set(TIFF.IMAGE_WIDTH, width);

    // Depth (bits per channel)
    int depth = EndianUtils.readUShortBE(stream);
    metadata.set(TIFF.BITS_PER_SAMPLE, Integer.toString(depth));

    // Colour mode
    // Bitmap = 0; Grayscale = 1; Indexed = 2; RGB = 3; CMYK = 4; Multichannel = 7; Duotone = 8; Lab = 9.
    int colorMode = EndianUtils.readUShortBE(stream);
    // TODO Identify a suitable metadata key for this

    // Next is the Color Mode section
    // We don't care about this bit
    long colorModeSectionSize = EndianUtils.readIntBE(stream);
    stream.skip(colorModeSectionSize);

    // Next is the Image Resources section
    // Check for certain interesting keys here
    long imageResourcesSectionSize = EndianUtils.readIntBE(stream);
    long read = 0;
    while (read < imageResourcesSectionSize) {
        ResourceBlock rb = new ResourceBlock(stream);
        read += rb.totalLength;

        // Is it one we can do something useful with?
        if (rb.id == ResourceBlock.ID_CAPTION) {
            metadata.add(TikaCoreProperties.DESCRIPTION, rb.getDataAsString());
        } else if (rb.id == ResourceBlock.ID_EXIF_1) {
            // TODO Parse the EXIF info
        } else if (rb.id == ResourceBlock.ID_EXIF_3) {
            // TODO Parse the EXIF info
        } else if (rb.id == ResourceBlock.ID_XMP) {
            // TODO Parse the XMP info
        }
    }

    // Next is the Layer and Mask Info
    // Finally we have Image Data
    // We can't do anything with these parts

    // We don't have any helpful text, sorry...
    XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
    xhtml.startDocument();
    xhtml.endDocument();
}

From source file:org.alfresco.repo.content.MimetypeMapContentTest.java

License:Open Source License

public void testGuessMimetypeForFile() throws Exception {
    // Correct ones
    assertEquals("application/msword",
            mimetypeService.guessMimetype("something.doc", openQuickTestFile("quick.doc")));
    assertEquals("application/msword",
            mimetypeService.guessMimetype("SOMETHING.DOC", openQuickTestFile("quick.doc")));

    // Incorrect ones, Tika spots the mistake
    assertEquals("application/msword",
            mimetypeService.guessMimetype("something.pdf", openQuickTestFile("quick.doc")));
    assertEquals("application/pdf",
            mimetypeService.guessMimetype("something.doc", openQuickTestFile("quick.pdf")));

    // Ones where we use a different mimetype to the canonical one
    assertEquals("image/bmp", // Officially image/x-ms-bmp 
            mimetypeService.guessMimetype("image.bmp", openQuickTestFile("quick.bmp")));

    // Ones where we know about the parent, and Tika knows about the details
    assertEquals("application/dita+xml", // Full version:  application/dita+xml;format=concept
            mimetypeService.guessMimetype("concept.dita", openQuickTestFile("quickConcept.dita")));

    // Alfresco Specific ones, that Tika doesn't know about
    assertEquals("application/acp",
            mimetypeService.guessMimetype("something.acp", openQuickTestFile("quick.acp")));

    // Where the file is corrupted
    File tmp = File.createTempFile("alfresco", ".tmp");
    ContentReader reader = openQuickTestFile("quick.doc");
    InputStream inp = reader.getContentInputStream();
    byte[] trunc = new byte[512 + 256];
    IOUtils.readFully(inp, trunc);
    inp.close();/*from   w  w w.  j  av  a  2  s.  com*/
    FileOutputStream out = new FileOutputStream(tmp);
    out.write(trunc);
    out.close();
    ContentReader truncReader = new FileContentReader(tmp);

    // Because the file is truncated, Tika won't be able to process the contents
    //  of the OLE2 structure
    // So, it'll fall back to just OLE2, but it won't fail
    assertEquals("application/x-tika-msoffice", mimetypeService.guessMimetype(null, truncReader));
    // But with the filename it'll be able to use the .doc extension
    //  to guess at it being a .Doc file
    assertEquals("application/msword", mimetypeService.guessMimetype("something.doc", truncReader));

    // Lotus notes EML files (ALF-16381 / TIKA-1042)
    assertEquals("message/rfc822",
            mimetypeService.guessMimetype("something.eml", openQuickTestFile("quickLotus.eml")));
}

From source file:org.alfresco.repo.content.TikaOfficeDetectParser.java

License:Open Source License

public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext parseContext)
        throws IOException, SAXException, TikaException {
    byte[] initial4 = new byte[4];
    InputStream wrapped;/*from  w w  w  .ja v a2 s . c  o  m*/
    // Preserve TikaInputStreams as TikaInputStreams as they require less memory to process
    if (stream.markSupported()) {
        stream.mark(initial4.length);
        IOUtils.readFully(stream, initial4);
        stream.reset();
        wrapped = stream;
    } else {
        PushbackInputStream inp = new PushbackInputStream(stream, 4);
        IOUtils.readFully(inp, initial4);
        inp.unread(initial4);
        wrapped = inp;
    }

    // Which is it?
    if (initial4[0] == POIFSConstants.OOXML_FILE_HEADER[0] && initial4[1] == POIFSConstants.OOXML_FILE_HEADER[1]
            && initial4[2] == POIFSConstants.OOXML_FILE_HEADER[2]
            && initial4[3] == POIFSConstants.OOXML_FILE_HEADER[3]) {
        ooxmlParser.parse(wrapped, handler, metadata, parseContext);
    } else {
        ole2Parser.parse(wrapped, handler, metadata, parseContext);
    }
}

From source file:org.apache.tika.parser.dwg.DWGParser.java

License:Apache License

public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context)
        throws IOException, TikaException, SAXException {
    // First up, which version of the format are we handling?
    byte[] header = new byte[128];
    IOUtils.readFully(stream, header);
    String version = new String(header, 0, 6, "US-ASCII");

    XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
    xhtml.startDocument();//from  ww  w  .j ava 2 s  .c om

    if (version.equals("AC1015")) {
        metadata.set(Metadata.CONTENT_TYPE, TYPE.toString());
        if (skipTo2000PropertyInfoSection(stream, header)) {
            get2000Props(stream, metadata, xhtml);
        }
    } else if (version.equals("AC1018")) {
        metadata.set(Metadata.CONTENT_TYPE, TYPE.toString());
        if (skipToPropertyInfoSection(stream, header)) {
            get2004Props(stream, metadata, xhtml);
        }
    } else if (version.equals("AC1021") || version.equals("AC1024")) {
        metadata.set(Metadata.CONTENT_TYPE, TYPE.toString());
        if (skipToPropertyInfoSection(stream, header)) {
            get2007and2010Props(stream, metadata, xhtml);
        }
    } else {
        throw new TikaException("Unsupported AutoCAD drawing version: " + version);
    }

    xhtml.endDocument();
}

From source file:org.apache.tika.parser.dwg.DWGParser.java

License:Apache License

private String read2004String(InputStream stream) throws IOException, TikaException {
    int stringLen = EndianUtils.readUShortLE(stream);

    byte[] stringData = new byte[stringLen];
    IOUtils.readFully(stream, stringData);

    // Often but not always null terminated
    if (stringData[stringLen - 1] == 0) {
        stringLen--;/* w w  w.ja  va  2 s.  co m*/
    }
    String value = StringUtil.getFromCompressedUnicode(stringData, 0, stringLen);
    return value;
}

From source file:org.apache.tika.parser.dwg.DWGParser.java

License:Apache License

private String read2007and2010String(InputStream stream) throws IOException, TikaException {
    int stringLen = EndianUtils.readUShortLE(stream);

    byte[] stringData = new byte[stringLen * 2];
    IOUtils.readFully(stream, stringData);
    String value = StringUtil.getFromUnicodeLE(stringData);

    // Some strings are null terminated
    if (value.charAt(value.length() - 1) == 0) {
        value = value.substring(0, value.length() - 1);
    }/*from  ww  w  .ja va2 s .c o m*/

    return value;
}

From source file:org.apache.tika.parser.dwg.DWGParser.java

License:Apache License

private void get2000Props(InputStream stream, Metadata metadata, XHTMLContentHandler xhtml)
        throws IOException, TikaException, SAXException {
    int propCount = 0;
    while (propCount < 30) {
        int propIdx = EndianUtils.readUShortLE(stream);
        int length = EndianUtils.readUShortLE(stream);
        int valueType = stream.read();

        if (propIdx == 0x28) {
            // This one seems not to follow the pattern
            length = 0x19;/*from   ww  w  . jav  a  2 s.co m*/
        } else if (propIdx == 90) {
            // We think this means the end of properties
            break;
        }

        byte[] value = new byte[length];
        IOUtils.readFully(stream, value);
        if (valueType == 0x1e) {
            // Normal string, good
            String val = StringUtil.getFromCompressedUnicode(value, 0, length);

            // Is it one we can look up by index?
            if (propIdx < HEADER_2000_PROPERTIES_ENTRIES.length) {
                metadata.add(HEADER_2000_PROPERTIES_ENTRIES[propIdx], val);
                xhtml.element("p", val);
            } else if (propIdx == 0x012c) {
                int splitAt = val.indexOf('=');
                if (splitAt > -1) {
                    String propName = val.substring(0, splitAt);
                    String propVal = val.substring(splitAt + 1);
                    metadata.add(propName, propVal);
                }
            }
        } else {
            // No idea...
        }

        propCount++;
    }
}

From source file:org.apache.tika.parser.dwg.DWGParser.java

License:Apache License

/**
 * Grab the offset, then skip there//  www. j  a va  2  s  . com
 */
private boolean skipToPropertyInfoSection(InputStream stream, byte[] header) throws IOException, TikaException {
    // The offset is stored in the header from 0x20 onwards
    long offsetToSection = EndianUtils.getLongLE(header, 0x20);

    // Sanity check the offset. Some files seem to use a different format,
    //  and the offset isn't available at 0x20. Until we can work out how
    //  to find the offset in those files, skip them if detected
    if (offsetToSection > 0xa00000l) {
        // Header should never be more than 10mb into the file, something is wrong
        offsetToSection = 0;
    }

    // Work out how far to skip, and sanity check
    long toSkip = offsetToSection - header.length;
    if (offsetToSection == 0) {
        return false;
    }
    while (toSkip > 0) {
        byte[] skip = new byte[Math.min((int) toSkip, 0x4000)];
        IOUtils.readFully(stream, skip);
        toSkip -= skip.length;
    }
    return true;
}

From source file:org.apache.tika.parser.dwg.DWGParser.java

License:Apache License

private int skipToCustomProperties(InputStream stream) throws IOException, TikaException {
    // There should be 4 zero bytes or CUSTOM_PROPERTIES_ALT_PADDING_VALUES next
    byte[] padding = new byte[4];
    IOUtils.readFully(stream, padding);
    if ((padding[0] == 0 && padding[1] == 0 && padding[2] == 0 && padding[3] == 0)
            || (padding[0] == CUSTOM_PROPERTIES_ALT_PADDING_VALUES[0]
                    && padding[1] == CUSTOM_PROPERTIES_ALT_PADDING_VALUES[1]
                    && padding[2] == CUSTOM_PROPERTIES_ALT_PADDING_VALUES[2]
                    && padding[3] == CUSTOM_PROPERTIES_ALT_PADDING_VALUES[3])) {

        // Looks hopeful, skip on
        padding = new byte[CUSTOM_PROPERTIES_SKIP];
        IOUtils.readFully(stream, padding);

        // We should now have the count
        int count = EndianUtils.readUShortLE(stream);

        // Sanity check it
        if (count > 0 && count < 0x7f) {
            // Looks plausible
            return count;
        } else {//from  ww  w . j a v  a 2  s.  c o  m
            // No properties / count is too high to trust
            return 0;
        }
    } else {
        // No padding. That probably means no custom props
        return 0;
    }
}