file format enum wip changes
[jalview.git] / src / jalview / jbgui / GAlignExportSettings.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.jbgui;
22
23 import jalview.io.FileFormatI;
24 import jalview.util.MessageManager;
25
26 import java.awt.BorderLayout;
27 import java.awt.event.ActionEvent;
28 import java.awt.event.ActionListener;
29 import java.awt.event.ItemEvent;
30 import java.awt.event.ItemListener;
31
32 import javax.swing.JButton;
33 import javax.swing.JCheckBox;
34 import javax.swing.JPanel;
35
36 @SuppressWarnings("serial")
37 public abstract class GAlignExportSettings extends JPanel
38 {
39   protected JPanel hiddenRegionConfPanel = new JPanel();
40
41   protected JPanel complexExportPanel = new JPanel();
42
43   protected JPanel optionsPanel = new JPanel();
44
45   protected JPanel actionPanel = new JPanel();
46
47   protected BorderLayout hiddenRegionLayout = new BorderLayout();
48
49   protected BorderLayout complexExportLayout = new BorderLayout();
50
51   protected BorderLayout mainLayout = new BorderLayout();
52
53   protected JCheckBox chkAll = new JCheckBox();
54
55   protected JCheckBox chkHiddenSeqs = new JCheckBox();
56
57   protected JCheckBox chkHiddenCols = new JCheckBox();
58
59   protected JCheckBox chkExportAnnots = new JCheckBox();
60
61   protected JCheckBox chkExportFeats = new JCheckBox();
62
63   protected JCheckBox chkExportGrps = new JCheckBox();
64
65   JButton btnOk = new JButton();
66
67   JButton btnCancel = new JButton();
68
69   private boolean hasHiddenSeq, hasHiddenCols, isComplexAlignFile,
70           showDialog;
71
72   public GAlignExportSettings(boolean hasHiddenSeq, boolean hasHiddenCols,
73           FileFormatI format)
74   {
75     this.hasHiddenSeq = hasHiddenSeq;
76     this.hasHiddenCols = hasHiddenCols;
77     this.isComplexAlignFile = format.isComplexAlignFile();
78     if (this.hasHiddenCols || this.hasHiddenSeq || this.isComplexAlignFile)
79     {
80       this.showDialog = true;
81     }
82     init();
83   }
84
85   public void init()
86   {
87     chkHiddenSeqs.setText(MessageManager
88             .getString("action.export_hidden_sequences"));
89     chkHiddenCols.setText(MessageManager
90             .getString("action.export_hidden_columns"));
91     chkExportAnnots.setText(MessageManager
92             .getString("action.export_annotations"));
93     chkExportFeats.setText(MessageManager
94             .getString("action.export_features"));
95     chkExportGrps.setText(MessageManager.getString("action.export_groups"));
96     btnOk.setText(MessageManager.getString("action.ok"));
97     btnCancel.setText(MessageManager.getString("action.cancel"));
98     chkAll.setText(MessageManager.getString("action.select_all"));
99
100     hiddenRegionConfPanel.setLayout(hiddenRegionLayout);
101     complexExportPanel.setLayout(complexExportLayout);
102     setLayout(mainLayout);
103
104     chkAll.addItemListener(new ItemListener()
105     {
106       @Override
107       public void itemStateChanged(ItemEvent e)
108       {
109         checkAllAction();
110       }
111     });
112
113     btnOk.addActionListener(new ActionListener()
114     {
115       @Override
116       public void actionPerformed(ActionEvent e)
117       {
118         ok_actionPerformed(e);
119       }
120     });
121
122     btnCancel.addActionListener(new ActionListener()
123     {
124       @Override
125       public void actionPerformed(ActionEvent e)
126       {
127         cancel_actionPerformed(e);
128       }
129     });
130
131     // hiddenRegionConfPanel.add(chkAll, BorderLayout.NORTH);
132     hiddenRegionConfPanel.add(chkHiddenSeqs, BorderLayout.CENTER);
133     hiddenRegionConfPanel.add(chkHiddenCols, BorderLayout.SOUTH);
134     chkHiddenSeqs.setEnabled(hasHiddenSeq);
135     chkHiddenCols.setEnabled(hasHiddenCols);
136
137     complexExportPanel.add(chkExportAnnots, BorderLayout.NORTH);
138     complexExportPanel.add(chkExportFeats, BorderLayout.CENTER);
139     complexExportPanel.add(chkExportGrps, BorderLayout.SOUTH);
140
141     actionPanel.add(chkAll);
142
143     if (this.isComplexAlignFile)
144     {
145       optionsPanel.add(complexExportPanel);
146     }
147
148     if (hasHiddenSeq || hasHiddenCols)
149     {
150       optionsPanel.add(hiddenRegionConfPanel);
151     }
152
153     actionPanel.add(btnCancel);
154     actionPanel.add(btnOk);
155
156     add(optionsPanel, BorderLayout.NORTH);
157     add(actionPanel, BorderLayout.SOUTH);
158
159   }
160
161   private void checkAllAction()
162   {
163     boolean isSelected = chkAll.isSelected();
164     chkHiddenSeqs.setSelected(chkHiddenSeqs.isEnabled() && isSelected);
165     chkHiddenCols.setSelected(chkHiddenCols.isEnabled() && isSelected);
166     chkExportAnnots.setSelected(isComplexAlignFile
167             && chkExportAnnots.isEnabled() && isSelected);
168     chkExportFeats.setSelected(isComplexAlignFile
169             && chkExportFeats.isEnabled() && isSelected);
170     chkExportGrps.setSelected(isComplexAlignFile
171             && chkExportGrps.isEnabled() && isSelected);
172   }
173
174   public boolean isShowDialog()
175   {
176     return showDialog;
177   }
178
179   public void setShowDialog(boolean showDialog)
180   {
181     this.showDialog = showDialog;
182   }
183
184   public abstract void ok_actionPerformed(ActionEvent e);
185
186   public abstract void cancel_actionPerformed(ActionEvent e);
187 }