fr.ird.observe.dto.ProgressionModel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of common-dto Show documentation
Show all versions of common-dto Show documentation
ObServe Toolkit Common Dto module
package fr.ird.observe.dto;
/*-
* #%L
* ObServe Toolkit :: Common Dto
* %%
* Copyright (C) 2017 - 2020 IRD, Ultreia.io
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* .
* #L%
*/
import io.ultreia.java4all.bean.AbstractJavaBean;
import io.ultreia.java4all.bean.spi.GenerateJavaBeanDefinition;
import javax.swing.BoundedRangeModel;
import javax.swing.DefaultBoundedRangeModel;
import javax.swing.JProgressBar;
import javax.swing.event.ChangeListener;
/**
* @author Tony Chemit - [email protected]
* @since 4
*/
@GenerateJavaBeanDefinition
public class ProgressionModel extends AbstractJavaBean implements BoundedRangeModel {
public static final String PROPERTY_MESSAGE = "message";
private final DefaultBoundedRangeModel delegate;
private String message;
public void installUI(JProgressBar progressBar) {
progressBar.putClientProperty("oldModel", progressBar.getModel());
progressBar.putClientProperty("oldIndeterminate", progressBar.isIndeterminate());
progressBar.putClientProperty("oldVisible", progressBar.isVisible());
progressBar.setVisible(true);
progressBar.setModel(this);
progressBar.setIndeterminate(false);
addPropertyChangeListener(PROPERTY_MESSAGE, evt -> {
progressBar.setString(null);
String message = String.format("%s %s", evt.getNewValue(), progressBar.getString());
progressBar.setString(message);
});
}
public void uninstallUI(JProgressBar progressBar) {
progressBar.setModel((BoundedRangeModel) progressBar.getClientProperty("oldModel"));
progressBar.setVisible((Boolean) progressBar.getClientProperty("oldVisible"));
progressBar.setIndeterminate((Boolean) progressBar.getClientProperty("oldIndeterminate"));
progressBar.setString(null);
}
public ProgressionModel() {
delegate = new DefaultBoundedRangeModel();
}
@Override
public int getValue() {
return delegate.getValue();
}
@Override
public int getExtent() {
return delegate.getExtent();
}
@Override
public int getMinimum() {
return delegate.getMinimum();
}
@Override
public int getMaximum() {
return delegate.getMaximum();
}
@Override
public void setValue(int n) {
delegate.setValue(n);
}
@Override
public void setExtent(int n) {
delegate.setExtent(n);
}
@Override
public void setMinimum(int n) {
delegate.setMinimum(n);
}
@Override
public void setMaximum(int n) {
delegate.setMaximum(n);
}
@Override
public void setValueIsAdjusting(boolean b) {
delegate.setValueIsAdjusting(b);
}
@Override
public boolean getValueIsAdjusting() {
return delegate.getValueIsAdjusting();
}
@Override
public void setRangeProperties(int newValue, int newExtent, int newMin, int newMax, boolean adjusting) {
delegate.setRangeProperties(newValue, newExtent, newMin, newMax, adjusting);
}
@Override
public void addChangeListener(ChangeListener l) {
delegate.addChangeListener(l);
}
@Override
public void removeChangeListener(ChangeListener l) {
delegate.removeChangeListener(l);
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
setValue(getValue() + 1);
String oldValue = getMessage();
this.message = message;
firePropertyChange(PROPERTY_MESSAGE, oldValue, message);
}
}