private void jButton4MouseClicked(java.awt.event.MouseEvent evt) { if (jCheckBox1.isSelected() || jCheckBox3.isSelected()) { return; } JFileChooser jfc = new JFileChooser(); jfc.setFont(new java.awt.Font("宋体", 0, 12)); jfc.setFileFilter(new FileSelectFilter("xml", "模板文件选择(*.xml)")); jfc.setDialogTitle("选择模板文件"); int result = jfc.showOpenDialog(null); if (result == JFileChooser.APPROVE_OPTION) { File file = jfc.getSelectedFile(); jTextField5.setText(file.getPath()); } }
/** * Create JPanel asking users to select the file or directory containing files to be mapped and an * existing mapping file if they have one. * * @return JPanel containing elements! */ private JLayeredPane createSelectFilesPanel() { // create overall panel final JPanel selectFilesContainer = new JPanel(); selectFilesContainer.setSize(new Dimension(400, 100)); selectFilesContainer.setLayout(new BoxLayout(selectFilesContainer, BoxLayout.PAGE_AXIS)); // create selector for mapping files final FileSelectionPanel fileToMapFSP = new FileSelectionPanel( "<html>please select file(s) to be mapped (txt, csv or xls (Excel). Please ensure " + "that this file has <b>no empty columns</b> and if possible, please remove any special characters, e.g. μ</html>", fileChooser); selectFilesContainer.add(fileToMapFSP); JPanel selectMappingPanel = new JPanel(); selectMappingPanel.setLayout(new BoxLayout(selectMappingPanel, BoxLayout.PAGE_AXIS)); selectMappingPanel.setOpaque(false); // need a jcheckbox to ask users if they wish to use a mapping JPanel useMappingContainer = new JPanel(new BorderLayout()); useMappingContainer.setOpaque(false); // need a file selection panel to select the file. JFileChooser mappingFileChooser = new JFileChooser(); mappingFileChooser.setDialogTitle("Choose mapping file (XML)"); mappingFileChooser.setApproveButtonText("select file"); mappingFileChooser.setFont(UIHelper.VER_11_PLAIN); mappingFileChooser.setFileFilter(new CustomizableFileFilter("xml")); final FileSelectionPanel savedMappingsFile = new FileSelectionPanel( "<html>please select saved mapping file (xml): </html>", mappingFileChooser); savedMappingsFile.setVisible(false); final JCheckBox useMapping = new JCheckBox("use a previous mapping?"); UIHelper.renderComponent(useMapping, UIHelper.VER_11_BOLD, UIHelper.GREY_COLOR, false); useMapping.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { savedMappingsFile.setVisible(useMapping.isSelected()); } }); useMappingContainer.add(useMapping, BorderLayout.WEST); selectMappingPanel.add(useMappingContainer); selectMappingPanel.add(savedMappingsFile); selectFilesContainer.add(selectMappingPanel); final RoundedJTextField rowOffset = new RoundedJTextField(3); rowOffset.setEnabled(false); rowOffset.setSize(new Dimension(20, 20)); rowOffset.setText("1"); final JCheckBox overrideRowPosition = new JCheckBox("override row start position?"); UIHelper.renderComponent(overrideRowPosition, UIHelper.VER_11_BOLD, UIHelper.GREY_COLOR, false); overrideRowPosition.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { rowOffset.setEnabled(overrideRowPosition.isSelected()); } }); Box fileInputPanel = Box.createHorizontalBox(); fileInputPanel.setSize(new Dimension(100, 20)); fileInputPanel.add(overrideRowPosition); fileInputPanel.add(Box.createHorizontalStrut(5)); fileInputPanel.add(rowOffset); selectFilesContainer.add(fileInputPanel); selectFilesContainer.add(selectMappingPanel); final JCheckBox mapToBlankFieldsCheckbox = new JCheckBox("Do not remove blank fields?", false); UIHelper.renderComponent( mapToBlankFieldsCheckbox, UIHelper.VER_11_BOLD, UIHelper.GREY_COLOR, false); mapToBlankFieldsCheckbox.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { mapToBlankFields = mapToBlankFieldsCheckbox.isSelected(); } }); JPanel removeBlanksContainer = new JPanel(new BorderLayout()); removeBlanksContainer.setOpaque(false); removeBlanksContainer.add(mapToBlankFieldsCheckbox, BorderLayout.WEST); selectFilesContainer.add(removeBlanksContainer); JPanel statusPanel = new JPanel(new GridLayout(1, 1)); statusPanel.setPreferredSize(new Dimension(400, 30)); final JLabel statusLab = UIHelper.createLabel("", UIHelper.VER_11_BOLD, UIHelper.RED_COLOR); statusPanel.add(statusLab); selectFilesContainer.add(statusPanel); final JLayeredPane finalLayout = getGeneralLayout(selectFilesHeader, breadcrumb1, "", selectFilesContainer, getHeight()); final MouseListener[] listeners = new MouseListener[2]; listeners[0] = new MouseAdapter() { public void mouseEntered(MouseEvent mouseEvent) { backButton.setIcon(backOver); } public void mouseExited(MouseEvent mouseEvent) { backButton.setIcon(back); } public void mousePressed(MouseEvent mouseEvent) { backButton.setIcon(back); SwingUtilities.invokeLater( new Runnable() { public void run() { ApplicationManager.getCurrentApplicationInstance().setCurrentPage(menuPanels); ApplicationManager.getCurrentApplicationInstance() .setGlassPanelContents(menuPanels.getCreateISAMenuGUI()); menuPanels.startAnimation(); } }); } }; assignListenerToLabel(backButton, listeners[0]); listeners[1] = new MouseAdapter() { public void mouseEntered(MouseEvent mouseEvent) { nextButton.setIcon(nextOver); } public void mouseExited(MouseEvent mouseEvent) { nextButton.setIcon(next); } public void mousePressed(MouseEvent mouseEvent) { nextButton.setIcon(next); Thread loadFile = new Thread( new Runnable() { public void run() { ISAcreatorProperties.setProperty( "isacreator.rowOffset", rowOffset.isEnabled() ? rowOffset.getText() : "1"); if (useMapping.isSelected()) { if (!savedMappingsFile.getSelectedFilePath().trim().equals("")) { MappingXMLLoader loader = new MappingXMLLoader(savedMappingsFile.getSelectedFilePath()); try { preExistingMapping = loader.loadMappings(); } catch (XmlException e) { log.error(e.getMessage()); statusLab.setText( "<html>problem found in xml for saved mapping: " + e.getMessage() + " </html>"); setCurrentPage(lastPage); return; } catch (IOException e) { log.error(e.getMessage()); statusLab.setText( "<html>problem found when resolving file for saved mapping: " + e.getMessage() + " </html>"); setCurrentPage(lastPage); return; } } else { statusLab.setText( "<html>please select a file containing previous mappings...</html>"); setCurrentPage(lastPage); return; } } else { log.info("Mapping is not selected"); statusLab.setText(""); } if (fileToMapFSP.notEmpty()) { previousPage.push(new HistoryComponent(finalLayout, listeners)); statusLab.setText(""); SwingUtilities.invokeLater( new Runnable() { public void run() { setCurrentPage( createAssayUsedPanel(fileToMapFSP.getSelectedFilePath())); } }); } else { statusLab.setText( "<html>please <strong>select</strong> a file to map!</html>"); setCurrentPage(lastPage); } } }); if (fileToMapFSP.notEmpty() && fileToMapFSP.checkFileExtensionValid("xls", "csv", "txt")) { statusLab.setText(""); lastPage = currentPage; setCurrentPage(workingProgressScreen); loadFile.start(); } else { statusLab.setText( "<html>please select a file with the extension <strong>.xls</strong>, <strong>.csv</strong> or <strong>.txt</strong>...</html>"); } } }; assignListenerToLabel(nextButton, listeners[1]); return finalLayout; }