List of usage examples for javax.swing JFileChooser addChoosableFileFilter
@BeanProperty(preferred = true, description = "Adds a filter to the list of user choosable file filters.") public void addChoosableFileFilter(FileFilter filter)
From source file:de.evaluationtool.gui.EvaluationFrameActionListener.java
private void saveReference(boolean mustSupportEvaluation, boolean includeEvaluation) throws FileNotFoundException { Set<ReferenceFormat> formats = mustSupportEvaluation ? ReferenceFormats.REFERENCE_FORMATS.evaluationIncludingFormats : ReferenceFormats.REFERENCE_FORMATS.formats; formats.retainAll(ReferenceFormats.REFERENCE_FORMATS.writeableFormats); ReferenceFormat format = formatChooser(formats); if (format == null) { return;//from w w w.j a v a 2 s . c o m } JFileChooser chooser = new JFileChooser("Save reference. Please choose a file."); chooser.setCurrentDirectory(frame.defaultDirectory); chooser.setFileSelectionMode( format.readsDirectory() ? JFileChooser.DIRECTORIES_ONLY : JFileChooser.FILES_ONLY); if (format.getFileExtension() != null) { chooser.addChoosableFileFilter( new FilesystemFilter(format.getFileExtension(), format.getDescription())); } else { chooser.setAcceptAllFileFilterUsed(true); } int returnVal = chooser.showSaveDialog(frame); if (returnVal != JFileChooser.APPROVE_OPTION) return; System.out.print("Saving..."); format.writeReference(frame.reference, chooser.getSelectedFile(), includeEvaluation); //frame.loadPositiveNegativeNT(chooser.getSelectedFile()); System.out.println("saving finished."); }
From source file:net.sf.jasperreports.swing.JRViewerToolbar.java
void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed // Add your handling code here: JFileChooser fileChooser = new JFileChooser(); fileChooser.setLocale(this.getLocale()); fileChooser.updateUI();/* w w w .j av a 2 s. c o m*/ for (int i = 0; i < saveContributors.size(); i++) { fileChooser.addChoosableFileFilter(saveContributors.get(i)); } if (saveContributors.contains(lastSaveContributor)) { fileChooser.setFileFilter(lastSaveContributor); } else if (saveContributors.size() > 0) { fileChooser.setFileFilter(saveContributors.get(0)); } if (lastFolder != null) { fileChooser.setCurrentDirectory(lastFolder); } int retValue = fileChooser.showSaveDialog(this); if (retValue == JFileChooser.APPROVE_OPTION) { FileFilter fileFilter = fileChooser.getFileFilter(); File file = fileChooser.getSelectedFile(); lastFolder = file.getParentFile(); JRSaveContributor contributor = null; if (fileFilter instanceof JRSaveContributor) { contributor = (JRSaveContributor) fileFilter; } else { int i = 0; while (contributor == null && i < saveContributors.size()) { contributor = saveContributors.get(i++); if (!contributor.accept(file)) { contributor = null; } } if (contributor == null) { contributor = new JRPrintSaveContributor(viewerContext.getJasperReportsContext(), getLocale(), viewerContext.getResourceBundle()); } } lastSaveContributor = contributor; try { contributor.save(viewerContext.getJasperPrint(), file); } catch (JRException e) { if (log.isErrorEnabled()) { log.error("Save error.", e); } JOptionPane.showMessageDialog(this, viewerContext.getBundleString("error.saving")); } } }
From source file:at.nhmwien.schema_mapping_tool.ProcessMappingWindow.java
/** * Save all settings to a given file//from ww w . j a va 2 s .co m * @param evt */ private void saveSettingsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveSettingsButtonActionPerformed // Save all configuration properties this.settings.setProperty("config.input-file-processor", this.inputFileFormatComboBox.getSelectedItem()); this.settings.setProperty("config.output-file-processor", this.outputFileFormatComboBox.getSelectedItem()); this.settings.setProperty("config.input-file-encoding", this.ifEncodingComboBox.getSelectedItem().toString()); this.settings.setProperty("config.output-file-encoding", this.ofEncodingComboBox.getSelectedItem().toString()); this.settings.setProperty("config.input-id-prefix", this.inputIDPrefixTextField.getText()); this.settings.setProperty("config.count-threshold", this.countThresholdTextField.getText()); this.settings.setProperty("config.input-field-order", MappingsHandler.Self().getInputOrder()); this.settings.setProperty("config.output-field-order", MappingsHandler.Self().getOutputOrder()); // Save File-Processor specific options FileProcessor fp = this.inputOptionsPanel.getProcessor(); String fpOptions[] = fp.getAvailableOptions(); for (String fpOption : fpOptions) { this.settings.setProperty("config.inputProcessor.options." + fpOption, fp.getOption(fpOption)); } fp = this.outputOptionsPanel.getProcessor(); fpOptions = fp.getAvailableOptions(); for (String fpOption : fpOptions) { this.settings.setProperty("config.outputProcessor.options." + fpOption, fp.getOption(fpOption)); } JFileChooser fc = new JFileChooser(); fc.setAcceptAllFileFilterUsed(false); FileNameExtensionFilter fnef = new FileNameExtensionFilter("SMT Processing Settings (*.sps)", "sps"); fc.addChoosableFileFilter(fnef); // Let the user chose a settings file if (fc.showDialog(this, "Save Processing Settings") == JFileChooser.APPROVE_OPTION) { try { this.settings.save(fc.getSelectedFile()); } catch (Exception e) { e.printStackTrace(); } } }
From source file:at.nhmwien.schema_mapping_tool.ProcessMappingWindow.java
private void loadSettingsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadSettingsButtonActionPerformed JFileChooser fc = new JFileChooser(); fc.setAcceptAllFileFilterUsed(false); FileNameExtensionFilter fnef = new FileNameExtensionFilter("SMT Processing Settings (*.sps)", "sps"); fc.addChoosableFileFilter(fnef); // Let the user chose a settings file if (fc.showDialog(this, "Load Processing Settings") == JFileChooser.APPROVE_OPTION) { try {/*from ww w.j a v a 2 s . co m*/ this.settings = new XMLConfiguration(fc.getSelectedFile()); // Update the interface to show all saved settings this.inputFileFormatComboBox .setSelectedItem(this.settings.getProperty("config.input-file-processor")); this.outputFileFormatComboBox .setSelectedItem(this.settings.getProperty("config.output-file-processor")); this.ifEncodingComboBox.setSelectedItem( Charset.forName((String) this.settings.getProperty("config.input-file-encoding"))); this.ofEncodingComboBox.setSelectedItem( Charset.forName((String) this.settings.getProperty("config.output-file-encoding"))); this.inputIDPrefixTextField.setText((String) this.settings.getProperty("config.input-id-prefix")); this.countThresholdTextField.setText((String) this.settings.getProperty("config.count-threshold")); MappingsHandler.Self() .setInputOrder((ArrayList<String>) this.settings.getProperty("config.input-field-order")); MappingsHandler.Self() .setOutputOrder((ArrayList<String>) this.settings.getProperty("config.output-field-order")); // Now load the processor specific settings FileProcessor fp = this.inputOptionsPanel.getProcessor(); String options[] = fp.getAvailableOptions(); for (String option : options) { if (this.settings.containsKey("config.inputProcessor.options." + option)) fp.setOption(option, this.settings.getProperty("config.inputProcessor.options." + option)); } fp = this.outputOptionsPanel.getProcessor(); options = fp.getAvailableOptions(); for (String option : options) { if (this.settings.containsKey("config.outputProcessor.options." + option)) fp.setOption(option, this.settings.getProperty("config.outputProcessor.options." + option)); } // Update options from processor for display this.inputOptionsPanel.loadOptions(); this.outputOptionsPanel.loadOptions(); /*Iterator it = this.settings.getKeys("config.inputProcessor.options"); while( it.hasNext() ) { System.out.println( it.next().toString() ); }*/ //this.settings.get } catch (Exception e) { e.printStackTrace(); } } }
From source file:de.juwimm.cms.content.panel.PanDocuments.java
private void upload(String prosa, Integer unit, Integer viewComponentId, Integer documentId) { this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); JFileChooser fc = new JFileChooser(); int ff = fc.getChoosableFileFilters().length; FileFilter[] fft = fc.getChoosableFileFilters(); for (int i = 0; i < ff; i++) { fc.removeChoosableFileFilter(fft[i]); }//from w w w . j a va 2s. c om fc.addChoosableFileFilter(new DocumentFilter()); fc.setAccessory(new ImagePreview(fc)); fc.setDialogTitle(prosa); fc.setMultiSelectionEnabled(true); fc.setCurrentDirectory(Constants.LAST_LOCAL_UPLOAD_DIR); int returnVal = fc.showDialog(this, Messages.getString("panel.content.documents.addDocument")); if (returnVal == JFileChooser.APPROVE_OPTION) { File[] files = fc.getSelectedFiles(); uploadFiles(files, unit, viewComponentId, documentId); Constants.LAST_LOCAL_UPLOAD_DIR = fc.getCurrentDirectory(); } this.setCursor(Cursor.getDefaultCursor()); }
From source file:org.pgptool.gui.ui.encryptone.EncryptOnePm.java
public SaveFileChooserDialog getTargetFileChooser() { if (targetFileChooser == null) { targetFileChooser = new SaveFileChooserDialog(findRegisteredWindowIfAny(), "action.chooseTargetFile", "action.choose", appProps, "EncryptionTargetChooser") { @Override/* w w w . j av a2 s . com*/ protected String onDialogClosed(String filePathName, JFileChooser ofd) { String ret = super.onDialogClosed(filePathName, ofd); if (ret != null) { targetFile.setValueByOwner(ret); } return ret; } @Override protected void onFileChooserPostConstrct(JFileChooser ofd) { ofd.setAcceptAllFileFilterUsed(false); ofd.addChoosableFileFilter(new FileNameExtensionFilter("GPG Files (.pgp)", "pgp")); // NOTE: Should we support other extensions?.... ofd.addChoosableFileFilter(ofd.getAcceptAllFileFilter()); ofd.setFileFilter(ofd.getChoosableFileFilters()[0]); } @Override protected void suggestTarget(JFileChooser ofd) { String sourceFileStr = sourceFile.getValue(); if (StringUtils.hasText(targetFile.getValue())) { use(ofd, targetFile.getValue()); } else if (encryptionDialogParameters != null && encryptionDialogParameters.getTargetFile() != null) { if (encryptionDialogParameters.getSourceFile().equals(sourceFile.getValue())) { use(ofd, encryptionDialogParameters.getTargetFile()); } else { use(ofd, madeUpTargetFileName(sourceFile.getValue(), FilenameUtils .getFullPathNoEndSeparator(encryptionDialogParameters.getTargetFile()))); } } else if (StringUtils.hasText(sourceFileStr) && new File(sourceFileStr).exists()) { String basePath = FilenameUtils.getFullPathNoEndSeparator(sourceFileStr); ofd.setCurrentDirectory(new File(basePath)); ofd.setSelectedFile(new File(madeUpTargetFileName(sourceFileStr, basePath))); } } private void use(JFileChooser ofd, String filePathName) { ofd.setCurrentDirectory(new File(FilenameUtils.getFullPathNoEndSeparator(filePathName))); ofd.setSelectedFile(new File(filePathName)); } }; } return targetFileChooser; }
From source file:io.heming.accountbook.ui.MainFrame.java
private void exportRecords() { final JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.addChoosableFileFilter(new AbbFileFilter()); chooser.setAcceptAllFileFilterUsed(false); int value = chooser.showSaveDialog(this); if (value == JFileChooser.APPROVE_OPTION) { final File file = chooser.getSelectedFile(); disableAllControls();/* w ww . j av a 2 s .c o m*/ new Thread() { @Override public void run() { try { statusLabel.setIcon(new ImageIcon(getClass().getResource("loader.gif"))); setStatusText("?..."); FacadeUtil.shutdown(); // .abb? setStatusText("?..."); List<String> exclusion = Arrays.asList(); if (!file.getName().endsWith(".abb")) { ZIPUtil.compress(new File(Constants.DATA_DIR), new File(file.getAbsolutePath() + ".abb"), exclusion); } else { ZIPUtil.compress(new File(Constants.DATA_DIR), file, exclusion); } setStatusText("??..."); FacadeUtil.restart(); enableAllControls(); setStatusText(""); statusLabel.setIcon(new ImageIcon(getClass().getResource("stopped-loader.png"))); JOptionPane.showMessageDialog(MainFrame.this, String.format("?"), "?", JOptionPane.INFORMATION_MESSAGE); } catch (IOException e) { JOptionPane.showMessageDialog(MainFrame.this, String.format(""), "", JOptionPane.ERROR_MESSAGE); } } }.start(); } }
From source file:io.heming.accountbook.ui.MainFrame.java
private void importRecords() { final JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.addChoosableFileFilter(new AbbFileFilter()); chooser.setAcceptAllFileFilterUsed(false); int value = chooser.showOpenDialog(this); if (value == JFileChooser.APPROVE_OPTION) { // ?// w w w . j ava2s .c om disableAllControls(); new Thread() { @Override public void run() { try { statusLabel.setIcon(new ImageIcon(getClass().getResource("loader.gif"))); setStatusText("?..."); FacadeUtil.shutdown(); File file = chooser.getSelectedFile(); setStatusText("??..."); FileUtils.cleanDirectory(new File(Constants.DATA_DIR)); setStatusText("??..."); ZIPUtil.decompress(file, new File(Constants.HOME_DIR)); setStatusText("?..."); FacadeUtil.restart(); // ?? setStatusText("????..."); categories = categoryFacade.listBySale(); // ???? setStatusText("?..."); searchRecords(); enableAllControls(); setStatusText(""); statusLabel.setIcon(new ImageIcon(getClass().getResource("stopped-loader.png"))); JOptionPane.showMessageDialog(MainFrame.this, "???", "?", JOptionPane.INFORMATION_MESSAGE); } catch (Exception e) { JOptionPane.showMessageDialog(MainFrame.this, e.getMessage(), "", JOptionPane.ERROR_MESSAGE); } } }.start(); } }
From source file:de.evaluationtool.gui.EvaluationFrameActionListener.java
private void loadReference() throws Exception { JFileChooser chooser = new JFileChooser("Please choose a reference file or directory."); chooser.setCurrentDirectory(frame.defaultDirectory); // TODO: detect if all directory formats are not readable and in this case dont allow directory opening chooser.setFileSelectionMode(//from w w w .j av a 2s .c o m ReferenceFormats.REFERENCE_FORMATS.directoryFormats.isEmpty() ? JFileChooser.FILES_ONLY : JFileChooser.FILES_AND_DIRECTORIES); for (ReferenceFormat format : ReferenceFormats.REFERENCE_FORMATS.readableFormats) { chooser.addChoosableFileFilter( new FilesystemFilter(format.getFileExtension(), format.getDescription())); } chooser.setAcceptAllFileFilterUsed(true); int returnVal = chooser.showOpenDialog(frame); if (returnVal != JFileChooser.APPROVE_OPTION) { return; } ReferenceFormat format = null; System.out.print("Loading..."); frame.setTitle("Loading..."); File f = chooser.getSelectedFile(); Collection<ReferenceFormat> formats; if (f.isDirectory()) { formats = ReferenceFormats.REFERENCE_FORMATS.directoryFormats; } else { formats = ReferenceFormats.REFERENCE_FORMATS.extensionToFormats .get(f.getName().substring(f.getName().lastIndexOf(".") + 1)); } if (formats == null || formats.isEmpty()) { throw new Exception("No format available that can read files with the " + f.getName().substring(f.getName().lastIndexOf(".") + 1) + " extension."); } if (formats.size() == 1) { format = formats.iterator().next(); } else { format = formatChooser(formats); } if (format == null) { return; } Reference reference = format.readReference(chooser.getSelectedFile(), true, frame.loadLimit); if (!reference.links.isEmpty()) { Link firstLink = reference.links.iterator().next(); frame.dataSourceName1 = EvaluationFrame.getProbableDatasourceName(firstLink.uris.first); frame.dataSourceName2 = EvaluationFrame.getProbableDatasourceName(firstLink.uris.second); } frame.setReference(reference); //frame.loadPositiveNegativeNT(chooser.getSelectedFile()); System.out.println("loading finished, " + reference.links.size() + " links loaded."); }
From source file:com.raddle.tools.MergeMain.java
private void initGUI() { try {/*from www . ja va2s . c o m*/ { this.setBounds(0, 0, 1050, 600); getContentPane().setLayout(null); this.setTitle("\u5c5e\u6027\u6587\u4ef6\u6bd4\u8f83"); { sourceTxt = new JTextField(); getContentPane().add(sourceTxt); sourceTxt.setBounds(12, 12, 373, 22); } { sourceBtn = new JButton(); getContentPane().add(sourceBtn); sourceBtn.setText("\u6253\u5f00"); sourceBtn.setBounds(406, 12, 74, 22); sourceBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { JFileChooser fileChooser = new JFileChooser(); // fileChooser.addChoosableFileFilter( new FileNameExtensionFilter("", "properties")); File curFile = new File(sourceTxt.getText()); if (curFile.exists()) { fileChooser.setCurrentDirectory(curFile.getParentFile()); } int result = fileChooser.showOpenDialog(MergeMain.this); if (result == JFileChooser.APPROVE_OPTION) { File selected = fileChooser.getSelectedFile(); source = new PropertyHolder(selected, "utf-8"); sourceTxt.setText(selected.getAbsolutePath()); properties.setProperty("left.file", selected.getAbsolutePath()); savePropMergeFile(); compare(); } } }); } { targetTxt = new JTextField(); getContentPane().add(targetTxt); targetTxt.setBounds(496, 12, 419, 22); } { targetBtn = new JButton(); getContentPane().add(targetBtn); targetBtn.setText("\u6253\u5f00"); targetBtn.setBounds(935, 12, 81, 22); targetBtn.setSize(74, 22); targetBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { JFileChooser fileChooser = new JFileChooser(); // fileChooser.addChoosableFileFilter( new FileNameExtensionFilter("", "properties")); File curFile = new File(targetTxt.getText()); if (curFile.exists()) { fileChooser.setCurrentDirectory(curFile.getParentFile()); } int result = fileChooser.showOpenDialog(MergeMain.this); if (result == JFileChooser.APPROVE_OPTION) { File selected = fileChooser.getSelectedFile(); target = new PropertyHolder(selected, "utf-8"); targetTxt.setText(selected.getAbsolutePath()); properties.setProperty("right.file", selected.getAbsolutePath()); savePropMergeFile(); compare(); } } }); } { jScrollPane1 = new JScrollPane(); getContentPane().add(jScrollPane1); jScrollPane1.setBounds(12, 127, 373, 413); { ListModel sourceListModel = new DefaultComboBoxModel(new String[] {}); sourceList = new JList(); jScrollPane1.setViewportView(sourceList); sourceList.setAutoscrolls(true); sourceList.setModel(sourceListModel); sourceList.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent evt) { if (evt.getKeyCode() == KeyEvent.VK_DELETE) { PropertyLine v = (PropertyLine) sourceList.getSelectedValue(); if (v != null) { int ret = JOptionPane.showConfirmDialog(MergeMain.this, "?" + v.getKey() + "?"); if (ret == JOptionPane.YES_OPTION) { v.setState(LineState.deleted); compare(); sourceList.setSelectedValue(v, true); } } } } }); sourceList.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent evt) { if (evt.getClickCount() == 2) { Object v = sourceList.getSelectedValue(); updatePropertyLine((PropertyLine) v); sourceList.setSelectedValue(v, true); } } }); sourceList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent evt) { if (sourceList.getSelectedValue() != null) { PropertyLine pl = (PropertyLine) sourceList.getSelectedValue(); if (target != null) { PropertyLine p = target.getLine(pl.getKey()); if (p != null) { TextDiffResult rt = TextdiffUtil.getDifferResult(p.toString(), pl.toString()); diffResultPane.setText("" + rt.getTargetHtml() + "<br/>?" + rt.getSrcHtml()); selectLine(targetList, p); return; } } TextDiffResult rt = TextdiffUtil.getDifferResult("", pl.toString()); diffResultPane.setText( "" + rt.getTargetHtml() + "<br/>?" + rt.getSrcHtml()); } } }); } } { jScrollPane2 = new JScrollPane(); getContentPane().add(jScrollPane2); jScrollPane2.setBounds(496, 127, 419, 413); { ListModel targetListModel = new DefaultComboBoxModel(new String[] {}); targetList = new JList(); jScrollPane2.setViewportView(targetList); targetList.setAutoscrolls(true); targetList.setModel(targetListModel); targetList.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent evt) { if (evt.getKeyCode() == KeyEvent.VK_DELETE) { PropertyLine v = (PropertyLine) targetList.getSelectedValue(); if (v != null) { int ret = JOptionPane.showConfirmDialog(MergeMain.this, "?" + v.getKey() + "?"); if (ret == JOptionPane.YES_OPTION) { v.setState(LineState.deleted); compare(); targetList.setSelectedValue(v, true); } } } } }); targetList.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent evt) { if (evt.getClickCount() == 2) { Object v = targetList.getSelectedValue(); updatePropertyLine((PropertyLine) v); targetList.setSelectedValue(v, true); } } }); targetList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent evt) { if (targetList.getSelectedValue() != null) { PropertyLine pl = (PropertyLine) targetList.getSelectedValue(); if (source != null) { PropertyLine s = source.getLine(pl.getKey()); if (s != null) { TextDiffResult rt = TextdiffUtil.getDifferResult(pl.toString(), s.toString()); diffResultPane.setText("" + rt.getTargetHtml() + "<br/>?" + rt.getSrcHtml()); selectLine(sourceList, s); return; } } TextDiffResult rt = TextdiffUtil.getDifferResult(pl.toString(), ""); diffResultPane.setText( "" + rt.getTargetHtml() + "<br/>?" + rt.getSrcHtml()); } } }); } } { sourceSaveBtn = new JButton(); getContentPane().add(sourceSaveBtn); sourceSaveBtn.setText("\u4fdd\u5b58"); sourceSaveBtn.setBounds(406, 45, 74, 22); sourceSaveBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { int result = JOptionPane.showConfirmDialog(MergeMain.this, "???\n" + source.getPropertyFile().getAbsolutePath()); if (result == JOptionPane.YES_OPTION) { source.saveFile(); JOptionPane.showMessageDialog(MergeMain.this, "??"); clearState(source); compare(); } } }); } { targetSaveBtn = new JButton(); getContentPane().add(targetSaveBtn); targetSaveBtn.setText("\u4fdd\u5b58"); targetSaveBtn.setBounds(935, 45, 81, 22); targetSaveBtn.setSize(74, 22); targetSaveBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { int result = JOptionPane.showConfirmDialog(MergeMain.this, "????\n" + target.getPropertyFile().getAbsolutePath()); if (result == JOptionPane.YES_OPTION) { target.saveFile(); JOptionPane.showMessageDialog(MergeMain.this, "??"); clearState(target); compare(); } } }); } { toTargetBtn = new JButton(); getContentPane().add(toTargetBtn); toTargetBtn.setText("->"); toTargetBtn.setBounds(406, 221, 74, 22); toTargetBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { Object[] oo = sourceList.getSelectedValues(); for (Object selected : oo) { PropertyLine s = (PropertyLine) selected; if (s != null && target != null) { PropertyLine t = target.getLine(s.getKey()); if (t == null) { PropertyLine n = s.clone(); n.setState(LineState.added); target.addPropertyLineAtSuitedPosition(n); } else if (!t.getValue().equals(s.getValue())) { t.setState(LineState.updated); t.setValue(s.getValue()); } else if (t.getState() == LineState.deleted) { if (t.getValue().equals(t.getOriginalValue())) { t.setState(LineState.original); } else { t.setState(LineState.updated); } } compare(); } } } }); } { toSourceBtn = new JButton(); getContentPane().add(toSourceBtn); toSourceBtn.setText("<-"); toSourceBtn.setBounds(406, 255, 74, 22); toSourceBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { Object[] oo = targetList.getSelectedValues(); for (Object selected : oo) { PropertyLine t = (PropertyLine) selected; if (t != null && source != null) { PropertyLine s = source.getLine(t.getKey()); if (s == null) { PropertyLine n = t.clone(); n.setState(LineState.added); source.addPropertyLineAtSuitedPosition(n); } else if (!s.getValue().equals(t.getValue())) { s.setState(LineState.updated); s.setValue(t.getValue()); } else if (s.getState() == LineState.deleted) { if (s.getValue().equals(s.getOriginalValue())) { s.setState(LineState.original); } else { s.setState(LineState.updated); } } compare(); } } } }); } { jScrollPane3 = new JScrollPane(); getContentPane().add(jScrollPane3); jScrollPane3.setBounds(12, 73, 903, 42); { diffResultPane = new JTextPane(); jScrollPane3.setViewportView(diffResultPane); diffResultPane.setBounds(12, 439, 903, 63); diffResultPane.setContentType("text/html"); diffResultPane.setPreferredSize(new java.awt.Dimension(901, 42)); } } { compareBtn = new JButton(); getContentPane().add(compareBtn); compareBtn.setText("\u6bd4\u8f83"); compareBtn.setBounds(406, 139, 74, 22); compareBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { compare(); } }); } { sourceReloadBtn = new JButton(); getContentPane().add(sourceReloadBtn); sourceReloadBtn.setText("\u91cd\u65b0\u8f7d\u5165"); sourceReloadBtn.setBounds(12, 40, 64, 29); sourceReloadBtn.setSize(90, 22); sourceReloadBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { if (sourceTxt.getText().length() > 0) { File curFile = new File(sourceTxt.getText().trim()); if (curFile.exists()) { source = new PropertyHolder(curFile, "utf-8"); sourceTxt.setText(curFile.getAbsolutePath()); properties.setProperty("left.file", curFile.getAbsolutePath()); savePropMergeFile(); compare(); } else { JOptionPane.showMessageDialog(MergeMain.this, "" + curFile.getAbsolutePath() + "?"); } } } }); } { targetReloadBtn = new JButton(); getContentPane().add(targetReloadBtn); targetReloadBtn.setText("\u91cd\u65b0\u8f7d\u5165"); targetReloadBtn.setBounds(839, 45, 90, 22); targetReloadBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { if (targetTxt.getText().length() > 0) { File curFile = new File(targetTxt.getText().trim()); if (curFile.exists()) { target = new PropertyHolder(curFile, "utf-8"); targetTxt.setText(curFile.getAbsolutePath()); properties.setProperty("right.file", curFile.getAbsolutePath()); savePropMergeFile(); compare(); } else { JOptionPane.showMessageDialog(MergeMain.this, "" + curFile.getAbsolutePath() + "?"); } } } }); } { helpBtn = new JButton(); getContentPane().add(helpBtn); helpBtn.setText("\u5e2e\u52a9"); helpBtn.setBounds(405, 338, 38, 29); helpBtn.setSize(74, 22); helpBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { StringBuilder sb = new StringBuilder(); sb.append("?").append("\n"); sb.append("del").append("\n"); sb.append("??").append("\n"); sb.append(": /.prop-merge/prop-merge.properties").append("\n"); JOptionPane.showMessageDialog(MergeMain.this, sb.toString()); } }); } { sourceEditBtn = new JButton(); getContentPane().add(sourceEditBtn); sourceEditBtn.setText("\u7f16\u8f91\u6587\u4ef6"); sourceEditBtn.setBounds(108, 40, 90, 22); sourceEditBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { if (sourceTxt.getText().length() > 0) { File curFile = new File(sourceTxt.getText()); editFile(curFile); } } }); } { targetEditBtn = new JButton(); getContentPane().add(targetEditBtn); targetEditBtn.setText("\u7f16\u8f91\u6587\u4ef6"); targetEditBtn.setBounds(743, 45, 90, 22); targetEditBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { if (targetTxt.getText().length() > 0) { File curFile = new File(targetTxt.getText()); editFile(curFile); } } }); } } pack(); } catch (Exception e) { e.printStackTrace(); } }