source: trunk/gli/src/org/greenstone/gatherer/cdm/TranslationView.java@ 11038

Last change on this file since 11038 was 11038, checked in by mdewsnip, 18 years ago

Tidied up the look of the Design pane. Each Design pane screen now has consistent borders, and vertical spacing between elements has been improved.

  • Property svn:keywords set to Author Date Id Revision
File size: 27.5 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * Author: John Thompson, Greenstone Digital Library, University of Waikato
9 *
10 * Copyright (C) 1999 New Zealand Digital Library Project
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *########################################################################
26 */
27package org.greenstone.gatherer.cdm;
28
29import java.awt.*;
30import java.awt.event.*;
31import java.util.*;
32import javax.swing.*;
33import javax.swing.event.*;
34import javax.swing.table.*;
35import org.greenstone.gatherer.Configuration;
36import org.greenstone.gatherer.DebugStream;
37import org.greenstone.gatherer.Dictionary;
38import org.greenstone.gatherer.Gatherer;
39import org.greenstone.gatherer.gui.DesignPaneHeader;
40import org.greenstone.gatherer.gui.GLIButton;
41
42/** This class provides a graphical interface to allow a user to quickly and conviently (ie all in one place) translate the text fragments associated with general metadata and indexes into each of the assigned languages in the collection. It should provide clear controls for the editing of these text fragments, plus clear indicate what languages still need further translation, which it will do through a combination of coloring and other visual indicators.
43 * @author John Thompson, Greenstone Digital Library, University of Waikato
44 * @version 2.3
45 */
46public class TranslationView {
47
48 private Control controls;
49
50 static final private Dimension COMPONENT_SIZE = new Dimension(225,25);
51 static final private int LANGUAGE_WIDTH = 75;
52 static final private String GENERAL_STR = "General:";
53 static final private String INDEX_STR = "Index:";
54 static final private String PARTITION_STR = "Partitions:";
55
56 public TranslationView() {
57 DebugStream.println("TranslationView: Initialized.");
58 }
59
60 public void destroy() {
61 if(controls != null) {
62 controls.destroy();
63 controls = null;
64 }
65 }
66
67 public Control getControls() {
68 if(controls == null) {
69 controls = new TranslationControl();
70 }
71 return controls;
72 }
73
74 private Object[] getFeaturesList() {
75 ArrayList features_model = new ArrayList();
76
77 // Add the indexes
78 ArrayList indexes = CollectionDesignManager.index_manager.getIndexes();
79 int indexes_size = indexes.size();
80 for(int j = 0; j < indexes_size; j++) {
81 Object bob = new BobTheMagicalComparableWrapper(indexes.get(j));
82 if(!features_model.contains(bob)) {
83 features_model.add(bob);
84 }
85 }
86
87 // We also add subindexes.
88 ArrayList subindexes = CollectionDesignManager.subcollectionindex_manager.getSubcollectionIndexes();
89 int subindexes_size = subindexes.size();
90 for(int j = 0; j < subindexes_size; j++) {
91 Object bob = new BobTheMagicalComparableWrapper(subindexes.get(j));
92 if(!features_model.contains(bob)) {
93 features_model.add(bob);
94 }
95 }
96
97 // Finally we add any remaining metadata as general
98 ArrayList general_metadata = CollectionDesignManager.collectionmeta_manager.getMetadata();
99 for(int i = 0; i < general_metadata.size(); i++) {
100 CollectionMeta metadata = (CollectionMeta) general_metadata.get(i);
101 if(!metadata.isSpecial()) {
102 Object bob = new BobTheMagicalComparableWrapper(metadata.getName());
103 if(!features_model.contains(bob)) {
104 features_model.add(bob);
105 }
106 }
107 }
108
109 Collections.sort(features_model);
110
111 return features_model.toArray();
112 }
113
114 private class BobTheMagicalComparableWrapper
115 implements Comparable {
116 private Object content;
117 private String text;
118 BobTheMagicalComparableWrapper(Object content) {
119 this.content = content;
120 }
121 public int compareTo(Object object) {
122 if(object == null) {
123 object = "";
124 }
125 if(text == null) {
126 toString();
127 }
128 return text.compareTo(object.toString());
129 }
130
131 /** Equals is used by contains and since we want to prevent double up of metadata we compare differently than in compareTo. */
132 public boolean equals(Object object) {
133 return (object != null && content.toString().equals(((BobTheMagicalComparableWrapper)object).getContent().toString()));
134 }
135
136 public Object getContent() {
137 return content;
138 }
139
140 public String getName() {
141 if(content instanceof Index) {
142 return CollectionConfiguration.STOP_CHARACTER + ((Index)content).getID();
143 }
144 else if (content instanceof SubcollectionIndex) {
145 return CollectionConfiguration.STOP_CHARACTER + ((SubcollectionIndex)content).getID();
146 }
147 else {
148 return content.toString();
149 }
150 }
151
152 public String toString() {
153 if(text == null) {
154 String temp = content.toString();
155 if(temp.indexOf(CollectionConfiguration.SPACE_CHARACTER) != -1) {
156 temp = temp.substring(0, temp.indexOf(CollectionConfiguration.SPACE_CHARACTER));
157 }
158 if(content instanceof Index) {
159 text = INDEX_STR + temp;
160 }
161 else if(content instanceof SubcollectionIndex) {
162 text = PARTITION_STR + temp;
163 }
164 else {
165 text = GENERAL_STR + temp;
166 }
167 }
168 return text;
169 }
170 }
171
172 private class TranslationControl
173 extends JPanel
174 implements Control {
175
176 private boolean ignore_event = false;
177 private FragmentTableModel fragment_table_model;
178 private JButton add_button;
179 private JButton remove_button;
180 private JButton replace_button;
181 private JComboBox language_combobox;
182 private JList features_list;
183 private JTable fragment_table;
184 private JTextArea default_area;
185 private JTextArea translation_area;
186
187 TranslationControl() {
188 fragment_table_model = new FragmentTableModel("", new TreeSet(), new ArrayList());
189 // Creation
190 JPanel header_panel = new DesignPaneHeader("CDM.GUI.Translation", "translatetext");
191
192 JPanel center_panel = new JPanel();
193
194 JPanel selection_panel = new JPanel();
195
196 JPanel component_selection_panel = new JPanel();
197 JLabel component_label = new JLabel();
198 Dictionary.registerText(component_label, "CDM.TranslationManager.Affected_Features");
199 features_list = new JList(getFeaturesList());
200 features_list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
201
202 JPanel fragment_selection_panel = new JPanel();
203 JLabel fragment_label = new JLabel();
204 Dictionary.registerText(fragment_label, "CDM.TranslationManager.Assigned_Fragments");
205
206 fragment_table = new JTable(fragment_table_model);
207 fragment_table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
208 fragment_table.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
209 fragment_table.setColumnSelectionAllowed(false);
210 fragment_table.setDefaultRenderer(Object.class, new FragmentTableRenderer());
211 fragment_table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
212
213 JScrollPane table_scroll = new JScrollPane(fragment_table);
214 table_scroll.getViewport().setBackground(Configuration.getColor("coloring.collection_tree_background", false));
215 table_scroll.setOpaque(true);
216
217 JPanel south_panel = new JPanel();
218
219 JPanel text_panel = new JPanel();
220
221 JPanel language_panel = new JPanel();
222 JLabel language_label = new JLabel();
223 Dictionary.registerText(language_label, "CDM.TranslationManager.Language");
224 language_combobox = new JComboBox(CollectionDesignManager.language_manager.getLanguageCodes().toArray());
225 language_combobox.setPreferredSize(COMPONENT_SIZE);
226 language_combobox.setRenderer(new LanguageListCellRenderer());
227 Dictionary.registerTooltip(language_combobox, "CDM.TranslationManager.Language_Tooltip");
228
229 JPanel default_text_panel = new JPanel();
230 JLabel default_label = new JLabel();
231 Dictionary.registerText(default_label, "CDM.TranslationManager.Default_Text");
232 default_area = new JTextArea();
233 default_area.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
234 default_area.setEditable(false);
235 default_area.setLineWrap(true);
236 default_area.setWrapStyleWord(true);
237
238 JPanel translated_text_panel = new JPanel();
239 JLabel translation_label = new JLabel();
240 Dictionary.registerText(translation_label, "CDM.TranslationManager.Translation");
241 translation_area = new JTextArea();
242 translation_area.setBackground(Configuration.getColor("coloring.disabled", false));
243 translation_area.setEnabled(false);
244 translation_area.setLineWrap(true);
245 translation_area.setWrapStyleWord(true);
246 Dictionary.registerTooltip(translation_area, "CDM.TranslationManager.Translation_Tooltip");
247
248 JPanel button_pane = new JPanel();
249 add_button = new GLIButton();
250 add_button.setEnabled(false);
251 add_button.setMnemonic(KeyEvent.VK_A);
252 Dictionary.registerBoth(add_button, "CDM.TranslationManager.Add", "CDM.TranslationManager.Add_Tooltip");
253 replace_button = new GLIButton();
254 replace_button.setEnabled(false);
255 replace_button.setMnemonic(KeyEvent.VK_C);
256 Dictionary.registerBoth(replace_button, "CDM.TranslationManager.Replace", "CDM.TranslationManager.Replace_Tooltip");
257 remove_button = new GLIButton();
258 remove_button.setEnabled(false);
259 remove_button.setMnemonic(KeyEvent.VK_R);
260 Dictionary.registerBoth(remove_button, "CDM.TranslationManager.Remove", "CDM.TranslationManager.Remove_Tooltip");
261
262 // Connection
263 add_button.addActionListener(new AddListener());
264 add_button.addActionListener(CollectionDesignManager.buildcol_change_listener);
265 remove_button.addActionListener(new RemoveListener());
266 remove_button.addActionListener(CollectionDesignManager.buildcol_change_listener);
267 replace_button.addActionListener(new ReplaceListener());
268 replace_button.addActionListener(CollectionDesignManager.buildcol_change_listener);
269 language_combobox.addActionListener(new LanguageActionListener());
270 translation_area.getDocument().addDocumentListener(new TranslationDocumentListener());
271 features_list.addListSelectionListener(new FeaturesListSelectionListener());
272 fragment_table.getSelectionModel().addListSelectionListener(new FragmentListSelectionListener());
273
274 // Layout
275 component_selection_panel.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
276 component_selection_panel.setLayout(new BorderLayout());
277 component_selection_panel.add(component_label, BorderLayout.NORTH);
278 component_selection_panel.add(new JScrollPane(features_list), BorderLayout.CENTER);
279
280 fragment_selection_panel.setLayout(new BorderLayout());
281 fragment_selection_panel.add(fragment_label, BorderLayout.NORTH);
282 fragment_selection_panel.add(table_scroll, BorderLayout.CENTER);
283
284 selection_panel.setLayout(new GridLayout(2,1,0,5));
285 selection_panel.add(component_selection_panel);
286 selection_panel.add(fragment_selection_panel);
287
288 default_text_panel.setLayout(new BorderLayout());
289 default_text_panel.add(default_label, BorderLayout.NORTH);
290 default_text_panel.add(new JScrollPane(default_area), BorderLayout.CENTER);
291
292 translated_text_panel.setLayout(new BorderLayout());
293 translated_text_panel.add(translation_label, BorderLayout.NORTH);
294 translated_text_panel.add(new JScrollPane(translation_area), BorderLayout.CENTER);
295
296 text_panel.setLayout(new GridLayout(1,2,5,0));
297 text_panel.add(default_text_panel);
298 text_panel.add(translated_text_panel);
299
300 language_panel.setLayout(new BorderLayout(5,0));
301 language_panel.add(language_label, BorderLayout.WEST);
302 language_panel.add(language_combobox, BorderLayout.CENTER);
303
304 south_panel.setLayout(new BorderLayout());
305 south_panel.add(language_panel, BorderLayout.NORTH);
306 south_panel.add(text_panel, BorderLayout.CENTER);
307
308 center_panel.setLayout(new GridLayout(2,1,0,5));
309 center_panel.add(selection_panel);
310 center_panel.add(south_panel);
311
312 button_pane.setBorder(BorderFactory.createEmptyBorder(2,0,0,0));
313 button_pane.setLayout(new GridLayout(1,3));
314 button_pane.add(add_button);
315 button_pane.add(replace_button);
316 button_pane.add(remove_button);
317
318 setBorder(BorderFactory.createEmptyBorder(0,5,0,0));
319 setLayout(new BorderLayout());
320 add(header_panel, BorderLayout.NORTH);
321 add(center_panel, BorderLayout.CENTER);
322 add(button_pane, BorderLayout.SOUTH);
323 }
324
325 public void destroy() {
326 }
327
328 public void gainFocus() {
329 // Rebuild the features model, just incase features have been added or removed.
330 if(features_list != null) {
331 Object selected_feature = features_list.getSelectedValue();
332 features_list.setListData(getFeaturesList());
333 if(selected_feature != null) {
334 features_list.setSelectedValue(selected_feature, true);
335 }
336 }
337 }
338
339 public void loseFocus() {
340 }
341
342
343 private class AddListener
344 implements ActionListener {
345
346 public void actionPerformed(ActionEvent event) {
347 ignore_event = true;
348 String translation_text = translation_area.getText();
349 if(translation_text.length() > 0) {
350 // If there is no current fragment table selection, but translation text is not an empty string, then this is a new fragment. Create new collection metadata, refresh the fragment table, then ensure that the new metadata is selected. Remember that it is the selected metadata to which changes will be applied.
351 BobTheMagicalComparableWrapper selected_feature = (BobTheMagicalComparableWrapper)features_list.getSelectedValue();
352 String language = (String) language_combobox.getSelectedItem();
353 CollectionMeta metadatum = new CollectionMeta(selected_feature.getName(), language);
354 metadatum.setValue(translation_text);
355 CollectionDesignManager.collectionmeta_manager.addMetadatum(metadatum);
356 fragment_table.clearSelection();
357 ArrayList metadata = CollectionDesignManager.collectionmeta_manager.getMetadata(selected_feature.getName());
358 fragment_table_model.setData(selected_feature.getName(), CollectionDesignManager.collectionmeta_manager.getLanguages(), metadata);
359 int index = fragment_table_model.getMetadataIndexByLanguage(language);
360 ///ystem.err.println("I want to select the row " + index + " out of " + metadata.size());
361 fragment_table.setRowSelectionInterval(index, index);
362 metadatum = null;
363 language = null;
364 selected_feature = null;
365 translation_text = null;
366 remove_button.setEnabled(true);
367 Gatherer.c_man.configurationChanged();
368 }
369 add_button.setEnabled(false);
370 replace_button.setEnabled(false);
371 ignore_event = false;
372 }
373 }
374
375 private class RemoveListener
376 implements ActionListener {
377
378 public void actionPerformed(ActionEvent event) {
379 ignore_event = true;
380 int index = -1;
381 if((index = fragment_table.getSelectedRow()) != -1) {
382 CollectionMeta metadata = fragment_table_model.getMetadata(index);
383 CollectionDesignManager.collectionmeta_manager.removeMetadata(metadata);
384 fragment_table_model.remove(index);
385 // If a remove occured then enable add
386 add_button.setEnabled(true);
387 Gatherer.c_man.configurationChanged();
388 }
389 // Either way disable replace and remove
390 replace_button.setEnabled(false);
391 remove_button.setEnabled(false);
392 ignore_event = false;
393 }
394 }
395
396 private class ReplaceListener
397 implements ActionListener {
398
399 public void actionPerformed(ActionEvent event) {
400 ignore_event = true;
401 int index = -1;
402 if((index = fragment_table.getSelectedRow()) != -1) {
403 String translation_text = translation_area.getText();
404 // Get the selected collection metadata
405 CollectionMeta metadata = fragment_table_model.getMetadata(index);
406 // Update the fragment metadata and ask the table to repaint the appropriate row
407 metadata.setValue(translation_text);
408 fragment_table_model.fireTableRowsUpdated(index, index);
409 metadata = null;
410 remove_button.setEnabled(true);
411 Gatherer.c_man.configurationChanged();
412 }
413 // Either way disable replace
414 add_button.setEnabled(false);
415 replace_button.setEnabled(false);
416 ignore_event = false;
417 }
418 }
419
420 private class FeaturesListSelectionListener
421 implements ListSelectionListener {
422 public void valueChanged(ListSelectionEvent event) {
423 if(!event.getValueIsAdjusting() && !ignore_event) {
424 ///ystem.err.println("FeaturesListSelectionListener");
425 if(!features_list.isSelectionEmpty()) {
426 // Determine the features name. Remember to remove our helpful source prefix (delimited by ':').
427 BobTheMagicalComparableWrapper selected_feature = (BobTheMagicalComparableWrapper)features_list.getSelectedValue();
428 // Retrieve the default language translation, or otherwise the first match, to be default text.
429 CollectionMeta default_metadata = CollectionDesignManager.collectionmeta_manager.getMetadatum(selected_feature.getName());
430 if(default_metadata != null) {
431 default_area.setText(default_metadata.getValue(CollectionMeta.TEXT));
432 }
433 // Update the text fragment table.
434 fragment_table.clearSelection();
435 fragment_table_model.setData(selected_feature.getName(), CollectionDesignManager.collectionmeta_manager.getLanguages(), CollectionDesignManager.collectionmeta_manager.getMetadata(selected_feature.getName()));
436 selected_feature = null;
437 // Now we check whatever value is currently selected in the combobox to see if it is valid to add.
438 String language_name = (String) language_combobox.getSelectedItem();
439 int index = fragment_table_model.getMetadataIndexByLanguage(language_name);
440 if(index != -1) {
441 CollectionMeta metadata = fragment_table_model.getMetadata(index);
442 fragment_table.setRowSelectionInterval(index, index);
443 if(metadata != null) {
444 translation_area.setText(metadata.getValue(CollectionMeta.TEXT));
445 }
446 else {
447 translation_area.setText("");
448 }
449 metadata = null;
450 }
451 else {
452 translation_area.setText("");
453 }
454 // Update and enable the text area
455 translation_area.setEnabled(true);
456 translation_area.setBackground(Configuration.getColor("coloring.editable_background", false));
457 }
458 else {
459 default_area.setText("");
460 fragment_table.clearSelection();
461 fragment_table_model.setData("", new TreeSet(), new ArrayList());
462 translation_area.setText("");
463 // Update and disable the text area
464 translation_area.setText("");
465 translation_area.setEnabled(false);
466 translation_area.setBackground(Configuration.getColor("coloring.disabled", false));
467 }
468 }
469 }
470 }
471
472 private class FragmentListSelectionListener
473 implements ListSelectionListener {
474 public void valueChanged(ListSelectionEvent event) {
475 if(!event.getValueIsAdjusting() && !ignore_event) {
476 ignore_event = true;
477 ///ystem.err.println("FragmentListSelectionListener");
478 int index = -1;
479 if((index = fragment_table.getSelectedRow()) != -1) {
480 // A row has been selected. Retrieve the collection metadata.
481 CollectionMeta metadatum = fragment_table_model.getMetadata(index);
482 if(metadatum != null) {
483 // Update the combobox to show the current language.
484 String language = metadatum.getLanguage();
485 ///ystem.err.println("Searching for the language: " + language_name);
486 for(int i = 0; i < language_combobox.getItemCount(); i++) {
487 if(language_combobox.getItemAt(i).toString().equals(language)) {
488 language_combobox.setSelectedIndex(i);
489 }
490 }
491 translation_area.setText(metadatum.getValue(CollectionMeta.TEXT));
492 remove_button.setEnabled(!metadatum.isDummy());
493 }
494 else {
495 remove_button.setEnabled(false);
496 }
497 }
498 else {
499 translation_area.setText("");
500 remove_button.setEnabled(false);
501 }
502 ignore_event = false;
503 }
504 }
505 }
506
507 private class FragmentTableModel
508 extends AbstractTableModel {
509
510 private ArrayList metadata;
511 private String feature_name;
512 private TreeSet languages;
513
514 FragmentTableModel(String feature_name, TreeSet languages, ArrayList metadata) {
515 this.feature_name = feature_name;
516 this.languages = languages;
517 this.metadata = metadata;
518 }
519 public int getRowCount() {
520 // The row count is equal to the maximum number of languages currently assigned in the collection.
521 return languages.size();
522 }
523 public int getColumnCount() {
524 return 2;
525 }
526
527 public String getColumnName(int column) {
528 if (column == 0) {
529 return Dictionary.get("CDM.TranslationManager.Language_Column");
530 }
531 if (column == 1) {
532 return Dictionary.get("CDM.TranslationManager.Fragment_Column");
533 }
534 return "";
535 }
536
537 /** Attempt to retrieve the metadata associated with a certain row - however not all rows actually have metadata with them (say the French row where no metadata has been set).
538 * @param row the row number as an int
539 * @return the CollectionMeta requested, which may be a dummy metadata pair
540 */
541 public CollectionMeta getMetadata(int row) {
542 // Determine what language we are talking about
543 String language = null;
544 Iterator language_iterator = languages.iterator();
545 int current_row = 0;
546 while(current_row != row && language_iterator.hasNext()) {
547 language_iterator.next();
548 current_row++;
549 }
550 if(current_row == row) {
551 language = (String) language_iterator.next();
552 return getMetadata(language);
553 }
554 language_iterator = null;
555 return null;
556 }
557
558 public CollectionMeta getMetadata(String language) {
559 // Attempt to retrieve metadata with that language
560 for(int i = 0; i < metadata.size(); i++) {
561 CollectionMeta metadatum = (CollectionMeta) metadata.get(i);
562 if(metadatum.getLanguage().equals(language)) {
563 return metadatum;
564 }
565 }
566 return new CollectionMeta(feature_name, language, true);
567 }
568
569 public int getMetadataIndexByLanguage(String language) {
570 ///ystem.err.println("Find the index for the language " + language + " (out of " + languages.size() + ")");
571 // First we have to iterate to the correct place
572 Iterator language_iterator = languages.iterator();
573 int current_row = 0;
574 while(language_iterator.hasNext()) {
575 String target = (String)language_iterator.next();
576 if(language.equals(target)) {
577 ///ystem.err.println("Matches " + target);
578 return current_row;
579 }
580 else {
581 ///ystem.err.println("Doesn't match " + target);
582 current_row++;
583 }
584 }
585 ///ystem.err.println("No such language in model: -1");
586 return -1;
587 }
588
589 public Object getValueAt(int row, int column) {
590 if(0 <= row && row < languages.size()) {
591 // First we have to iterate to the correct place
592 Iterator language_iterator = languages.iterator();
593 int current_row = 0;
594 while(current_row != row && language_iterator.hasNext()) {
595 language_iterator.next();
596 current_row++;
597 }
598 if(current_row == row) {
599 String language = (String)language_iterator.next();
600 if(column == 0) {
601 return CollectionDesignManager.language_manager.getLanguageName(language);
602 }
603 else {
604 CollectionMeta metadatum = getMetadata(language);
605 return metadatum.getValue(CollectionMeta.TEXT);
606 }
607 }
608 language_iterator = null;
609 }
610 return "#Error";
611 }
612
613 public void remove(int index) {
614 metadata.remove(index);
615 fireTableRowsDeleted(index, index);
616 }
617
618 public void setData(String feature_name, TreeSet languages, ArrayList metadata) {
619 this.feature_name = feature_name;
620 this.languages = languages;
621 this.metadata = metadata;
622 fireTableDataChanged();
623 }
624
625 public int size() {
626 return metadata.size();
627 }
628 }
629
630 private class FragmentTableRenderer
631 extends DefaultTableCellRenderer {
632 /** Retrieve the component used to rubberstamp the table based on the given parameters.
633 * @param table The <strong>JTable</strong> to rendered.
634 * @param value The <strong>Object</strong> whose representation will be shown in the table row.
635 * @param isSelected <i>true</i> iff the column/row is selected.
636 * @param hasFocus <i>true</i> iff the column/row is in focus.
637 * @param row An <i>int</i> specifying the target row.
638 * @param column An <i>int</i> specifying the target column.
639 * @see org.greenstone.gatherer.cdm.Language
640 */
641 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
642 JComponent component = (JComponent) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
643 if(isSelected) {
644 component.setBackground(Configuration.getColor("coloring.workspace_heading_background", false));
645 }
646 else {
647 component.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
648 }
649 return component;
650 }
651 }
652
653 private class LanguageActionListener
654 implements ActionListener {
655 public void actionPerformed(ActionEvent event) {
656 if(!ignore_event) {
657 ignore_event = true;
658 ///ystem.err.println("LanguageActionListener");
659 // If the newly selected language value already exists in the fragment table, and that row isn't the one selected, then select that row the text area.
660 String language_name = language_combobox.getSelectedItem().toString();
661 int index = fragment_table_model.getMetadataIndexByLanguage(language_name);
662 if(index != -1) {
663 CollectionMeta metadata = fragment_table_model.getMetadata(index);
664 fragment_table.setRowSelectionInterval(index, index);
665 translation_area.setText(metadata.getValue(CollectionMeta.TEXT));
666 }
667 else {
668 fragment_table.clearSelection();
669 translation_area.setText("");
670 }
671 // Ready the text area
672 translation_area.setEnabled(true);
673 translation_area.setBackground(Configuration.getColor("coloring.editable_background", false));
674 ignore_event = false;
675 }
676 }
677 }
678
679 private class TranslationDocumentListener
680 implements DocumentListener {
681 /** Gives notification that an attribute or set of attributes changed. */
682 public void changedUpdate(DocumentEvent e) {
683 update();
684 }
685 /** Gives notification that there was an insert into the document. */
686 public void insertUpdate(DocumentEvent e) {
687 update();
688 }
689 /** Gives notification that a portion of the document has been removed. */
690 public void removeUpdate(DocumentEvent e) {
691 update();
692 }
693 /** The text area has changed in some way. Given that this can only happed when we are editing or adding a text fragment we better respond appropriately. */
694 private void update() {
695 String translation_text = translation_area.getText();
696 // Determine if add should be enabled. You can only add if the current text fragment doesn't already exist in the fragment table for the given language
697 String language = (String) language_combobox.getSelectedItem();
698 CollectionMeta metadatum = fragment_table_model.getMetadata(language);
699 add_button.setEnabled(translation_text.length() > 0 && (metadatum.isDummy() || fragment_table_model.getMetadataIndexByLanguage(language) == -1));
700 language = null;
701 // Determine if replace should be enabled. Replace is only enabled it the text fragment is different from the one in the current fragment table selection.
702 if(fragment_table.getSelectedRowCount() > 0) {
703 replace_button.setEnabled(!metadatum.isDummy() && !translation_text.equals(fragment_table.getValueAt(fragment_table.getSelectedRow(), 1)));
704 }
705 // Nothing selected, nothing to replace
706 else {
707 replace_button.setEnabled(false);
708 }
709 translation_text = null;
710 }
711 }
712 }
713}
Note: See TracBrowser for help on using the repository browser.