bf02e9ee54af22392eb6f35ab993ff070416e0e7
[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.util.MessageManager;
24
25 import java.awt.BorderLayout;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28 import java.awt.event.ItemEvent;
29 import java.awt.event.ItemListener;
30
31 import javax.swing.JButton;
32 import javax.swing.JCheckBox;
33 import javax.swing.JPanel;
34
35 @SuppressWarnings("serial")
36 public abstract class GAlignExportSettings extends JPanel
37 {
38   protected JPanel hiddenRegionConfPanel = new JPanel();
39
40   protected JPanel complexExportPanel = new JPanel();
41
42   protected JPanel optionsPanel = new JPanel();
43
44   protected JPanel actionPanel = new JPanel();
45
46   protected BorderLayout hiddenRegionLayout = new BorderLayout();
47
48   protected BorderLayout complexExportLayout = new BorderLayout();
49
50   protected BorderLayout mainLayout = new BorderLayout();
51
52   protected JCheckBox chkAll = new JCheckBox();
53
54   protected JCheckBox chkHiddenSeqs = new JCheckBox();
55
56   protected JCheckBox chkHiddenCols = new JCheckBox();
57
58   protected JCheckBox chkExportAnnots = new JCheckBox();
59
60   protected JCheckBox chkExportFeats = new JCheckBox();
61
62   protected JCheckBox chkExportGrps = new JCheckBox();
63
64   JButton btnOk = new JButton();
65
66   JButton btnCancel = new JButton();
67
68   private boolean hasHiddenSeq, hasHiddenCols, isComplexAlignFile,
69           showDialog;
70
71   public GAlignExportSettings(boolean hasHiddenSeq, boolean hasHiddenCols,
72           String alignFileFormat)
73   {
74     this.hasHiddenSeq = hasHiddenSeq;
75     this.hasHiddenCols = hasHiddenCols;
76     String[] complexFormats = { "JSON", "HTML" };
77
78     for (String format : complexFormats)
79     {
80       if (format.equalsIgnoreCase(alignFileFormat))
81       {
82         this.isComplexAlignFile = true;
83         break;
84       }
85     }
86     if (this.hasHiddenCols || this.hasHiddenSeq || this.isComplexAlignFile)
87     {
88       this.showDialog = true;
89     }
90     init();
91   }
92
93   public void init()
94   {
95     chkHiddenSeqs.setText(MessageManager
96             .getString("action.export_hidden_sequences"));
97     chkHiddenCols.setText(MessageManager
98             .getString("action.export_hidden_columns"));
99     chkExportAnnots.setText(MessageManager
100             .getString("action.export_annotations"));
101     chkExportFeats.setText(MessageManager
102             .getString("action.export_features"));
103     chkExportGrps.setText(MessageManager.getString("action.export_groups"));
104     btnOk.setText(MessageManager.getString("action.ok"));
105     btnCancel.setText(MessageManager.getString("action.cancel"));
106     chkAll.setText(MessageManager.getString("action.select_all"));
107
108     hiddenRegionConfPanel.setLayout(hiddenRegionLayout);
109     complexExportPanel.setLayout(complexExportLayout);
110     setLayout(mainLayout);
111
112     chkAll.addItemListener(new ItemListener()
113     {
114       public void itemStateChanged(ItemEvent e)
115       {
116         checkAllAction();
117       }
118     });
119
120     btnOk.addActionListener(new ActionListener()
121     {
122       public void actionPerformed(ActionEvent e)
123       {
124         ok_actionPerformed(e);
125       }
126     });
127
128     btnCancel.addActionListener(new ActionListener()
129     {
130       public void actionPerformed(ActionEvent e)
131       {
132         cancel_actionPerformed(e);
133       }
134     });
135
136     // hiddenRegionConfPanel.add(chkAll, BorderLayout.NORTH);
137     hiddenRegionConfPanel.add(chkHiddenSeqs, BorderLayout.CENTER);
138     hiddenRegionConfPanel.add(chkHiddenCols, BorderLayout.SOUTH);
139     chkHiddenSeqs.setEnabled(hasHiddenSeq);
140     chkHiddenCols.setEnabled(hasHiddenCols);
141
142     complexExportPanel.add(chkExportAnnots, BorderLayout.NORTH);
143     complexExportPanel.add(chkExportFeats, BorderLayout.CENTER);
144     complexExportPanel.add(chkExportGrps, BorderLayout.SOUTH);
145
146     actionPanel.add(chkAll);
147
148     if (this.isComplexAlignFile)
149     {
150       optionsPanel.add(complexExportPanel);
151     }
152
153     if (hasHiddenSeq || hasHiddenCols)
154     {
155       optionsPanel.add(hiddenRegionConfPanel);
156     }
157
158     actionPanel.add(btnCancel);
159     actionPanel.add(btnOk);
160
161     add(optionsPanel, BorderLayout.NORTH);
162     add(actionPanel, BorderLayout.SOUTH);
163
164   }
165
166   private void checkAllAction()
167   {
168     boolean isSelected = chkAll.isSelected();
169     chkHiddenSeqs.setSelected(chkHiddenSeqs.isEnabled() && isSelected);
170     chkHiddenCols.setSelected(chkHiddenCols.isEnabled() && isSelected);
171     chkExportAnnots.setSelected(isComplexAlignFile
172             && chkExportAnnots.isEnabled() && isSelected);
173     chkExportFeats.setSelected(isComplexAlignFile
174             && chkExportFeats.isEnabled() && isSelected);
175     chkExportGrps.setSelected(isComplexAlignFile
176             && chkExportGrps.isEnabled() && isSelected);
177   }
178
179   public boolean isShowDialog()
180   {
181     return showDialog;
182   }
183
184   public void setShowDialog(boolean showDialog)
185   {
186     this.showDialog = showDialog;
187   }
188
189   public abstract void ok_actionPerformed(ActionEvent e);
190
191   public abstract void cancel_actionPerformed(ActionEvent e);
192 }