sdmxdl.desktop.JValueAsText Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sdmx-dl-desktop Show documentation
Show all versions of sdmx-dl-desktop Show documentation
Easily download official statistics - Desktop
The newest version!
package sdmxdl.desktop;
import lombok.Getter;
import sdmxdl.HasPersistence;
import javax.swing.*;
import java.awt.*;
import java.beans.PropertyChangeEvent;
public final class JValueAsText extends JComponent implements HasModel {
@Getter
private T model = null;
public void setModel(T model) {
firePropertyChange(MODEL_PROPERTY, this.model, this.model = model);
}
private final JTextArea textArea = new JTextArea();
public JValueAsText() {
initComponents();
}
private void initComponents() {
textArea.setEditable(false);
setLayout(new BorderLayout());
add(new JScrollPane(textArea), BorderLayout.CENTER);
addPropertyChangeListener(MODEL_PROPERTY, this::onModelChange);
}
private void onModelChange(PropertyChangeEvent evt) {
updateText();
}
private void updateText() {
textArea.setText(getValueAsText());
textArea.setCaretPosition(0);
}
private String getValueAsText() {
return model != null ? Sdmxdl.INSTANCE.formatAsJson((Class) model.getClass(), model) : "No structure";
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy