Re: Plugin Development Issue
Code: Select all
package com.eteks.test;
import java.awt.Component;
import java.util.Iterator;
import javax.swing.JOptionPane;
import com.eteks.sweethome3d.model.PieceOfFurniture;
import com.eteks.sweethome3d.plugin.Plugin;
import com.eteks.sweethome3d.plugin.PluginAction;
public class VolumePlugin extends Plugin {
public PluginAction[] getActions() {
return new PluginAction[]{new VolumePlugin.VolumeAction()};
}
public class VolumeAction extends PluginAction {
public VolumeAction() {
this.putPropertyValue(Property.NAME, "Compute volume");
this.putPropertyValue(Property.MENU, "Tools");
this.setEnabled(true);
}
public void execute() {
float volumeInCm3 = 0.0F;
Iterator var3 = VolumePlugin.this.getHome().getFurniture().iterator();
while(var3.hasNext()) {
PieceOfFurniture piece = (PieceOfFurniture)var3.next();
if (piece.isMovable()) {
volumeInCm3 += piece.getWidth() * piece.getDepth() * piece.getHeight();
}
}
String message = String.format("The maximum volume of the movable furniture in home is %.2f m³.", volumeInCm3 / 1000000.0F);
JOptionPane.showMessageDialog((Component)null, message);
}
}
}