1 | package org.greenstone.gatherer.gui;
|
---|
2 |
|
---|
3 |
|
---|
4 | import java.awt.*;
|
---|
5 | import javax.swing.*;
|
---|
6 | import org.greenstone.gatherer.Configuration;
|
---|
7 | import org.greenstone.gatherer.metadata.MetadataElement;
|
---|
8 | import org.greenstone.gatherer.metadata.MetadataTools;
|
---|
9 |
|
---|
10 |
|
---|
11 | public 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 | }
|
---|