source: gli/branches/rtl-gli/src/org/greenstone/gatherer/gui/MetadataImportMappingPrompt.java@ 18297

Last change on this file since 18297 was 18297, checked in by kjdon, 15 years ago

interface updated to display right to left for rtl languages. This code is thanks to Amin Hejazi. It seems to be only partially complete. Amin was working with Greenstone 3 so might have missed some panels

  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 KB
Line 
1package org.greenstone.gatherer.gui;
2
3
4import java.awt.*;
5import java.awt.event.*;
6import java.util.*;
7import javax.swing.*;
8import org.greenstone.gatherer.Configuration;
9import org.greenstone.gatherer.Dictionary;
10import org.greenstone.gatherer.Gatherer;
11import org.greenstone.gatherer.metadata.MetadataElement;
12import org.greenstone.gatherer.metadata.MetadataSet;
13import org.greenstone.gatherer.metadata.MetadataSetManager;
14import org.greenstone.gatherer.metadata.MetadataTools;
15
16
17public class MetadataImportMappingPrompt
18 implements ActionListener
19{
20 final static public int ADD_BUTTON_PRESSED = 0;
21 final static public int MERGE_BUTTON_PRESSED = 1;
22 final static public int IGNORE_BUTTON_PRESSED = 2;
23 final static private Dimension DIALOG_SIZE = new Dimension(640, 180);
24
25 private int result;
26 private String metadata_element_name_full = null;
27 private GComboBox metadata_sets_combobox = null;
28 private GComboBox metadata_elements_combobox = null;
29 private JButton add_button = null;
30 private JButton merge_button = null;
31 private JButton ignore_button = null;
32 private JDialog on_screen = null;
33
34
35 public MetadataImportMappingPrompt(String metadata_element_name_full)
36 {
37 this.metadata_element_name_full = metadata_element_name_full;
38
39 // Construction and configuration
40 JDialog dialog = new ModalDialog(Gatherer.g_man);
41 dialog.setComponentOrientation(Dictionary.getOrientation());
42 dialog.setModal(true);
43 dialog.setSize(DIALOG_SIZE);
44 dialog.setJMenuBar(new SimpleMenuBar("importingpreviouslyassignedmetadata"));
45 dialog.setTitle(Dictionary.get("MIMP.Title"));
46
47 // All the loaded metadata sets except the extracted metadata set are applicable
48 ArrayList metadata_sets = MetadataSetManager.getMetadataSets();
49 for (int i = metadata_sets.size() - 1; i >= 0; i--) {
50 if (((MetadataSet) metadata_sets.get(i)).getNamespace().equals(MetadataSetManager.EXTRACTED_METADATA_NAMESPACE)) {
51 metadata_sets.remove(i);
52 }
53 }
54
55 add_button = new GLIButton(Dictionary.get("MIMP.Add"), Dictionary.get("MIMP.Add_Tooltip"));
56 add_button.addActionListener(this);
57
58 merge_button = new GLIButton(Dictionary.get("MIMP.Merge"), Dictionary.get("MIMP.Merge_Tooltip"));
59 merge_button.addActionListener(this);
60 merge_button.setEnabled(true);
61
62 ignore_button = new GLIButton(Dictionary.get("MIMP.Ignore"), Dictionary.get("MIMP.Ignore_Tooltip"));
63 ignore_button.addActionListener(this);
64 ignore_button.setEnabled(true);
65
66 // !! Need to add instructions: "MIMP.Instructions", args: source elem
67 metadata_elements_combobox = new GComboBox();
68
69 metadata_sets_combobox = new GComboBox(metadata_sets);
70 metadata_sets_combobox.addActionListener(new MetadataSetListSelectionListener());
71 metadata_sets_combobox.setSelectedIndex(0);
72
73 // Layout
74 JPanel left_pane = new JPanel();
75 left_pane.setComponentOrientation(Dictionary.getOrientation());
76 left_pane.setLayout(new GridLayout(3,1));
77
78 JLabel tmp_lable;
79
80 tmp_lable = new JLabel(Dictionary.get("MIMP.Source_Element"));
81 tmp_lable.setComponentOrientation(Dictionary.getOrientation());
82 left_pane.add(tmp_lable);
83
84 tmp_lable = new JLabel(Dictionary.get("MIMP.Target_Set"));
85 tmp_lable.setComponentOrientation(Dictionary.getOrientation());
86 left_pane.add(tmp_lable);
87
88 tmp_lable = new JLabel(Dictionary.get("MIMP.Target_Element"));
89 tmp_lable.setComponentOrientation(Dictionary.getOrientation());
90 left_pane.add(tmp_lable);
91
92 JPanel right_pane = new JPanel();
93 right_pane.setComponentOrientation(Dictionary.getOrientation());
94
95 right_pane.setLayout(new GridLayout(3,1));
96 tmp_lable = new JLabel(metadata_element_name_full);
97 tmp_lable.setComponentOrientation(Dictionary.getOrientation());
98 right_pane.add(tmp_lable);
99 right_pane.add(metadata_sets_combobox);
100 right_pane.add(metadata_elements_combobox);
101
102 JPanel button_pane = new JPanel();
103 button_pane.setComponentOrientation(Dictionary.getOrientation());
104 button_pane.setBorder(BorderFactory.createEmptyBorder(0,5,5,5));
105 button_pane.setLayout(new GridLayout(1,3));
106 button_pane.add(add_button);
107 button_pane.add(merge_button);
108 button_pane.add(ignore_button);
109
110 JPanel content_pane = (JPanel) dialog.getContentPane();
111 content_pane.setComponentOrientation(Dictionary.getOrientation());
112 content_pane.setLayout(new BorderLayout());
113 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
114 content_pane.add(left_pane, BorderLayout.LINE_START);
115 content_pane.add(right_pane, BorderLayout.CENTER);
116 content_pane.add(button_pane, BorderLayout.SOUTH);
117
118 // Display
119 Dimension screen_size = Configuration.screen_size;
120 dialog.setLocation((screen_size.width - DIALOG_SIZE.width) / 2, (screen_size.height - DIALOG_SIZE.height) / 2);
121 on_screen = dialog;
122 on_screen.setVisible(true); // Blocks until hidden.
123 on_screen.dispose();
124 on_screen = null;
125 }
126
127
128 /** Any implementation of <i>ActionListener</i> must include this method so that we can be informed when an action has occured.
129 * @param event An <strong>ActionEvent</strong> containing information gatherer when this event occured.
130 */
131 public void actionPerformed(ActionEvent event)
132 {
133 Object esrc = event.getSource();
134
135 if (esrc == add_button) {
136 result = ADD_BUTTON_PRESSED;
137 }
138 if (esrc == merge_button) {
139 result = MERGE_BUTTON_PRESSED;
140 }
141 if (esrc == ignore_button) {
142 result = IGNORE_BUTTON_PRESSED;
143 }
144
145 on_screen.setVisible(false);
146 }
147
148
149 public MetadataElement getSelectedMetadataElement()
150 {
151 return (MetadataElement) metadata_elements_combobox.getSelectedItem();
152 }
153
154
155 public MetadataSet getSelectedMetadataSet()
156 {
157 return (MetadataSet) metadata_sets_combobox.getSelectedItem();
158 }
159
160
161 public int getResult()
162 {
163 return result;
164 }
165
166
167 private class MetadataSetListSelectionListener
168 implements ActionListener
169 {
170 public void actionPerformed(ActionEvent event)
171 {
172 boolean enable_add_button = true;
173 String metadata_element_name = MetadataTools.getMetadataElementName(metadata_element_name_full);
174
175 MetadataSet metadata_set = (MetadataSet) metadata_sets_combobox.getSelectedItem();
176 ArrayList metadata_elements = metadata_set.getMetadataSetElements();
177
178 metadata_elements_combobox.removeAllItems();
179 for (int i = 0; i < metadata_elements.size(); i++) {
180 MetadataElement metadata_element = (MetadataElement) metadata_elements.get(i);
181 metadata_elements_combobox.addItem(metadata_element);
182 if (metadata_element.getName().equals(metadata_element_name)) {
183 metadata_elements_combobox.setSelectedIndex(i);
184 enable_add_button = false;
185 }
186 }
187
188 add_button.setEnabled(enable_add_button);
189
190 // are there any elements in the set? if not (e.g. with exp set),
191 // disable merge
192 if (metadata_elements.size()==0) {
193 merge_button.setEnabled(false);
194 }
195 }
196 }
197}
Note: See TracBrowser for help on using the repository browser.