X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FCutAndPasteTransfer.java;h=142dd757c55d46960316c781b2af225fa0d4be41;hb=7534e6f358b2bba0db179cb2f496bd2e5a4da43d;hp=c0e59a49b9e126143e217c0f8c4818df09b752ae;hpb=d9c02118b8e03e6f102a46d316b6e52a41c41a27;p=jalview.git diff --git a/src/jalview/gui/CutAndPasteTransfer.java b/src/jalview/gui/CutAndPasteTransfer.java index c0e59a4..142dd75 100644 --- a/src/jalview/gui/CutAndPasteTransfer.java +++ b/src/jalview/gui/CutAndPasteTransfer.java @@ -23,14 +23,18 @@ package jalview.gui; import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; import jalview.api.ComplexAlignFile; +import jalview.api.FeatureSettingsModelI; import jalview.api.FeaturesDisplayedI; import jalview.api.FeaturesSourceI; import jalview.bin.Jalview; import jalview.datamodel.AlignmentI; -import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SequenceI; +import jalview.io.AlignmentFileReaderI; import jalview.io.AppletFormatAdapter; -import jalview.io.FileParse; +import jalview.io.DataSourceType; +import jalview.io.FileFormatException; +import jalview.io.FileFormatI; import jalview.io.FormatAdapter; import jalview.io.IdentifyFile; import jalview.io.JalviewFileChooser; @@ -48,9 +52,11 @@ import java.awt.datatransfer.Transferable; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; import javax.swing.JMenuItem; -import javax.swing.JOptionPane; import javax.swing.JPopupMenu; import javax.swing.SwingUtilities; @@ -67,7 +73,7 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer AlignViewportI viewport; - FileParse source = null; + AlignmentFileReaderI source = null; public CutAndPasteTransfer() { @@ -129,13 +135,15 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer @Override public void save_actionPerformed(ActionEvent e) { + // TODO: JAL-3048 JalviewFileChooser - Save option + JalviewFileChooser chooser = new JalviewFileChooser( jalview.bin.Cache.getProperty("LAST_DIRECTORY")); chooser.setAcceptAllFileFilterUsed(false); chooser.setFileView(new JalviewFileView()); - chooser.setDialogTitle(MessageManager - .getString("label.save_text_to_file")); + chooser.setDialogTitle( + MessageManager.getString("label.save_text_to_file")); chooser.setToolTipText(MessageManager.getString("action.save")); int value = chooser.showSaveDialog(this); @@ -144,8 +152,8 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer { try { - java.io.PrintWriter out = new java.io.PrintWriter( - new java.io.FileWriter(chooser.getSelectedFile())); + PrintWriter out = new PrintWriter( + new FileWriter(chooser.getSelectedFile())); out.print(getText()); out.close(); @@ -190,8 +198,8 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer try { - textarea.append((String) contents - .getTransferData(DataFlavor.stringFlavor)); + textarea.append( + (String) contents.getTransferData(DataFlavor.stringFlavor)); } catch (Exception ex) { } @@ -212,17 +220,24 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer return; } - String format = new IdentifyFile().identify(text, "Paste"); - if (format == null || format.equalsIgnoreCase("EMPTY DATA FILE")) + FileFormatI format = null; + try + { + format = new IdentifyFile().identify(text, DataSourceType.PASTE); + } catch (FileFormatException e1) + { + // leave as null + } + if (format == null) { - System.err.println(MessageManager - .getString("label.couldnt_read_data")); + System.err + .println(MessageManager.getString("label.couldnt_read_data")); if (!Jalview.isHeadlessMode()) { - javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop, - AppletFormatAdapter.SUPPORTED_FORMATS, + JvOptionPane.showInternalMessageDialog(Desktop.desktop, + AppletFormatAdapter.getSupportedFormats(), MessageManager.getString("label.couldnt_read_data"), - JOptionPane.WARNING_MESSAGE); + JvOptionPane.WARNING_MESSAGE); } return; } @@ -230,35 +245,39 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer // TODO: identify feature, annotation or tree file and parse appropriately. AlignmentI al = null; - if (FormatAdapter.isValidFormat(format)) + try { - try - { - FormatAdapter fa = new FormatAdapter(alignpanel); - al = fa.readFile(getText(), "Paste", format); - source = fa.getAlignFile(); + FormatAdapter fa = new FormatAdapter(alignpanel); + al = fa.readFile(getText(), DataSourceType.PASTE, format); + source = fa.getAlignFile(); - } catch (java.io.IOException ex) - { - JOptionPane.showInternalMessageDialog(Desktop.desktop, - MessageManager.formatMessage( - "label.couldnt_read_pasted_text", - new String[] { ex.toString() }), MessageManager - .getString("label.error_parsing_text"), - JOptionPane.WARNING_MESSAGE); - } + } catch (IOException ex) + { + JvOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager + .formatMessage("label.couldnt_read_pasted_text", new String[] + { ex.toString() }), + MessageManager.getString("label.error_parsing_text"), + JvOptionPane.WARNING_MESSAGE); } if (al != null && al.hasValidSequence()) { - String title = MessageManager.formatMessage( - "label.input_cut_paste_params", new String[] { format }); + String title = MessageManager + .formatMessage("label.input_cut_paste_params", new String[] + { format.getName() }); + FeatureSettingsModelI proxyColourScheme = source + .getFeatureColourScheme(); + /* * if the view panel was closed its alignment is nulled * and this is an orphaned cut and paste window */ if (viewport != null && viewport.getAlignment() != null) { + if (proxyColourScheme != null) + { + viewport.applyFeaturesStyle(proxyColourScheme); + } ((AlignViewport) viewport).addAlignment(al, title); } else @@ -267,8 +286,8 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer AlignFrame af; if (source instanceof ComplexAlignFile) { - ColumnSelection colSel = ((ComplexAlignFile) source) - .getColumnSelection(); + HiddenColumns hidden = ((ComplexAlignFile) source) + .getHiddenColumns(); SequenceI[] hiddenSeqs = ((ComplexAlignFile) source) .getHiddenSequences(); boolean showSeqFeatures = ((ComplexAlignFile) source) @@ -277,10 +296,11 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer .getGlobalColourScheme(); FeaturesDisplayedI fd = ((ComplexAlignFile) source) .getDisplayedFeatures(); - af = new AlignFrame(al, hiddenSeqs, colSel, + af = new AlignFrame(al, hiddenSeqs, hidden, AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); af.getViewport().setShowSequenceFeatures(showSeqFeatures); af.getViewport().setFeaturesDisplayed(fd); + af.setMenusForViewport(); ColourSchemeI cs = ColourSchemeMapper.getJalviewColourScheme( colourSchemeName, al); if (cs != null) @@ -297,7 +317,10 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer af.getViewport().setShowSequenceFeatures(true); } } - + if (proxyColourScheme != null) + { + af.getViewport().applyFeaturesStyle(proxyColourScheme); + } af.currentFileFormat = format; Desktop.addInternalFrame(af, title, AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); @@ -306,8 +329,8 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer try { - af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN", - false)); + af.setMaximum( + jalview.bin.Cache.getDefault("SHOW_FULLSCREEN", false)); } catch (Exception ex) { } @@ -315,14 +338,14 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer } else { - System.err.println(MessageManager - .getString("label.couldnt_read_data")); + System.err + .println(MessageManager.getString("label.couldnt_read_data")); if (!Jalview.isHeadlessMode()) { - javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop, - AppletFormatAdapter.SUPPORTED_FORMATS, + JvOptionPane.showInternalMessageDialog(Desktop.desktop, + AppletFormatAdapter.getSupportedFormats(), MessageManager.getString("label.couldnt_read_data"), - JOptionPane.WARNING_MESSAGE); + JvOptionPane.WARNING_MESSAGE); } } } @@ -347,7 +370,11 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer @Override public void textarea_mousePressed(MouseEvent e) { - if (SwingUtilities.isRightMouseButton(e)) + /* + * isPopupTrigger is checked in mousePressed on Mac, + * in mouseReleased on Windows + */ + if (e.isPopupTrigger()) { JPopupMenu popup = new JPopupMenu( MessageManager.getString("action.edit"));