source: other-projects/FileTransfer-WebSocketPair/testGXTWithGreenstone/src/org/greenstone/gatherer/gui/MetadataElementListCellRenderer.java@ 33053

Last change on this file since 33053 was 33053, checked in by ak19, 5 years ago

I still had some stuff of Nathan Kelly's (FileTransfer-WebSocketPair) sitting on my USB. Had already commited the Themes folder at the time, 2 years back. Not sure if he wanted this additional folder commited. But I didn't want to delete it and decided it will be better off on SVN. When we use his project, if we find we didn't need this test folder, we can remove it from svn then.

File size: 3.2 KB
Line 
1package org.greenstone.gatherer.gui;
2
3
4import java.awt.*;
5import javax.swing.*;
6import org.greenstone.gatherer.Configuration;
7import org.greenstone.gatherer.metadata.MetadataElement;
8import org.greenstone.gatherer.metadata.MetadataTools;
9
10
11public class MetadataElementListCellRenderer
12 extends JLabel
13 implements ListCellRenderer
14{
15 private byte previous_directionality = Character.DIRECTIONALITY_UNDEFINED;
16
17
18 public byte getDirectionality()
19 {
20 if (previous_directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT || previous_directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC || previous_directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING || previous_directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE) {
21 return Character.DIRECTIONALITY_RIGHT_TO_LEFT;
22 }
23 else {
24 return Character.DIRECTIONALITY_LEFT_TO_RIGHT;
25 }
26 }
27
28
29 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
30 {
31 if (value instanceof MetadataElement) {
32 MetadataElement metadata_element = (MetadataElement) value;
33
34 String interface_language_code = Configuration.getLanguage();
35 String metadata_element_display = "";
36
37 String metadata_element_display_name = metadata_element.getDisplayName();
38 if (metadata_element_display_name != null) {
39 metadata_element_display += metadata_element_display_name + ":";
40 }
41 else {
42 metadata_element_display += metadata_element.getName() + ":";
43 }
44
45 String metadata_element_definition = MetadataTools.getMetadataElementAttribute(metadata_element, "definition", interface_language_code, "en");
46 if (metadata_element_definition != null) {
47 metadata_element_display += " " + metadata_element_definition;
48 }
49
50// String metadata_element_comment = MetadataTools.getMetadataElementAttribute(metadata_element, "comment", interface_language_code, "en");
51// if (metadata_element_comment != null) {
52// metadata_element_display += " " + metadata_element_comment;
53// }
54
55 setText(metadata_element_display);
56
57// // Determine if the text should be left aligned or right aligned
58// String text = metadata_element_display;
59// int text_index = 0;
60// byte directionality = Character.DIRECTIONALITY_UNDEFINED;
61// while (directionality == Character.DIRECTIONALITY_UNDEFINED && text_index < text.length()) {
62// directionality = Character.getDirectionality(text.charAt(text_index));
63// text_index++;
64// }
65// if (directionality != previous_directionality) {
66// previous_directionality = directionality;
67// if (directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT || directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC || directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING || directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE) {
68// setHorizontalAlignment(JLabel.TRAILING);
69// setHorizontalTextPosition(JLabel.TRAILING);
70// setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
71// }
72// else {
73// setHorizontalAlignment(JLabel.LEADING);
74// setHorizontalTextPosition(JLabel.LEADING);
75// setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
76// }
77// }
78 }
79
80 return this;
81 }
82}
Note: See TracBrowser for help on using the repository browser.