1 package be
.nikiroo
.jvcard
.tui
.panes
;
4 import java
.util
.Base64
;
5 import java
.util
.LinkedList
;
8 import javax
.swing
.ImageIcon
;
10 import be
.nikiroo
.jvcard
.Contact
;
11 import be
.nikiroo
.jvcard
.Data
;
12 import be
.nikiroo
.jvcard
.TypeInfo
;
13 import be
.nikiroo
.jvcard
.i18n
.Trans
;
14 import be
.nikiroo
.jvcard
.tui
.ImageTextControl
;
15 import be
.nikiroo
.jvcard
.tui
.KeyAction
;
16 import be
.nikiroo
.jvcard
.tui
.KeyAction
.DataType
;
17 import be
.nikiroo
.jvcard
.tui
.KeyAction
.Mode
;
19 import com
.googlecode
.lanterna
.TerminalSize
;
20 import com
.googlecode
.lanterna
.gui2
.BorderLayout
;
21 import com
.googlecode
.lanterna
.gui2
.Panel
;
22 import com
.googlecode
.lanterna
.input
.KeyType
;
24 public class ContactDetails
extends MainContent
{
25 private Contact contact
;
27 private ImageTextControl txt
;
29 private boolean fullscreenImage
;
31 public ContactDetails(Contact contact
) {
32 this.contact
= contact
;
34 BorderLayout blayout
= new BorderLayout();
35 setLayoutManager(blayout
);
39 addComponent(top
, BorderLayout
.Location
.TOP
);
42 public void setContact(Contact contact
) {
44 this.contact
= contact
;
46 if (contact
!= null) {
47 Data photo
= contact
.getPreferredData("PHOTO");
49 TypeInfo encoding
= null;
51 for (int index
= 0; index
< photo
.size(); index
++) {
52 TypeInfo info
= photo
.get(index
);
53 if (info
.getName() != null) {
54 if (info
.getName().equalsIgnoreCase("ENCODING"))
56 if (info
.getName().equalsIgnoreCase("TYPE"))
61 if (encoding
!= null && encoding
.getValue() != null
62 && encoding
.getValue().equalsIgnoreCase("b")) {
64 img
= new ImageIcon(Base64
.getDecoder().decode(
65 photo
.getValue())).getImage();
74 public DataType
getDataType() {
79 public List
<KeyAction
> getKeyBindings() {
80 List
<KeyAction
> actions
= new LinkedList
<KeyAction
>();
83 actions
.add(new KeyAction(Mode
.NONE
, KeyType
.Tab
,
84 Trans
.StringId
.KEY_ACTION_SWITCH_FORMAT
) {
86 public boolean onAction() {
94 actions
.add(new KeyAction(Mode
.NONE
, 'i',
95 Trans
.StringId
.KEY_ACTION_INVERT
) {
97 public boolean onAction() {
105 actions
.add(new KeyAction(Mode
.NONE
, 'f',
106 Trans
.StringId
.KEY_ACTION_FULLSCREEN
) {
108 public boolean onAction() {
109 fullscreenImage
= !fullscreenImage
;
119 public synchronized Panel
setSize(TerminalSize size
) {
126 * Set the {@link Image} to render.
129 * the new {@link Image}
131 private void setImage(Image image
) {
134 TerminalSize size
= getTxtSize();
139 txt
= new ImageTextControl(image
, size
);
142 if (top
.getChildCount() > 0)
143 top
.removeAllComponents();
146 top
.addComponent(txt
);
150 * Compute the size to use for the {@link Image} text rendering. Return NULL
153 * @return the {@link TerminalSize} to use or NULL if it is not possible
155 private TerminalSize
getTxtSize() {
156 if (image
!= null && getSize() != null && getSize().getColumns() > 0
157 && getSize().getRows() > 0) {
158 if (fullscreenImage
) {
162 return new TerminalSize(40, 20);