use of javax.swing.SpringLayout in project energy3d by concord-consortium.
the class PropertiesDialogForParabolicDish method getDialog.
static JDialog getDialog(final ParabolicDish trough) {
final JDialog dialog = new JDialog(MainFrame.getInstance(), "Parabolic Dish", true);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
final String info = trough.toString().substring(0, trough.toString().indexOf(')') + 1);
dialog.setTitle("Properties - " + info);
dialog.getContentPane().setLayout(new BorderLayout());
final JPanel panel = new JPanel(new SpringLayout());
panel.setBorder(new EmptyBorder(8, 8, 8, 8));
final JScrollPane scroller = new JScrollPane(panel);
scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scroller.setPreferredSize(new Dimension(320, 240));
dialog.getContentPane().add(scroller, BorderLayout.CENTER);
final double focalLength = trough.getFocalLength();
final double rimRadius = trough.getRimRadius();
int i = 0;
panel.add(new JLabel("Focal Length: "));
final JTextField focalLengthField = new JTextField(PopupMenuFactory.threeDecimalsFormat.format(focalLength) + " m");
focalLengthField.setEditable(false);
panel.add(focalLengthField);
i++;
panel.add(new JLabel("Rim Radius: "));
final JTextField rimRadiusField = new JTextField(PopupMenuFactory.threeDecimalsFormat.format(rimRadius) + " m");
rimRadiusField.setEditable(false);
panel.add(rimRadiusField);
i++;
panel.add(new JLabel("Parabola Height: "));
final JTextField parabolaHeightField = new JTextField(PopupMenuFactory.threeDecimalsFormat.format(rimRadius * rimRadius / (4 * focalLength)) + " m");
parabolaHeightField.setEditable(false);
panel.add(parabolaHeightField);
i++;
// http://www.powerfromthesun.net/Book/chapter08/chapter08.html
double r = rimRadius / (2 * focalLength);
r = r * r + 1;
final double s = 8.0 * Math.PI / 3.0 * focalLength * focalLength * (r * Math.sqrt(r) - 1);
panel.add(new JLabel("Total Surface Area: "));
final JTextField totalSurfaceAreaField = new JTextField(PopupMenuFactory.threeDecimalsFormat.format(s) + " m\u00B2");
totalSurfaceAreaField.setEditable(false);
panel.add(totalSurfaceAreaField);
i++;
panel.add(new JLabel("Total Aperture Area: "));
final JTextField totalApertureAreaField = new JTextField(PopupMenuFactory.threeDecimalsFormat.format(Math.PI * rimRadius * rimRadius) + " m\u00B2");
totalApertureAreaField.setEditable(false);
panel.add(totalApertureAreaField);
i++;
panel.add(new JLabel("Mirror Reflectance: "));
final JTextField reflectanceField = new JTextField(PopupMenuFactory.threeDecimalsFormat.format(trough.getReflectance() * 100) + "%");
reflectanceField.setEditable(false);
panel.add(reflectanceField);
i++;
panel.add(new JLabel("Receiver Absorptance: "));
final JTextField absorptanceField = new JTextField(PopupMenuFactory.threeDecimalsFormat.format(trough.getAbsorptance() * 100) + "%");
absorptanceField.setEditable(false);
panel.add(absorptanceField);
i++;
panel.add(new JLabel("Optical Efficiency: "));
final JTextField opticalEfficiencyField = new JTextField(PopupMenuFactory.threeDecimalsFormat.format(trough.getOpticalEfficiency() * 100) + "%");
opticalEfficiencyField.setEditable(false);
panel.add(opticalEfficiencyField);
i++;
panel.add(new JLabel("Thermal Efficiency: "));
final JTextField thermalEfficiencyField = new JTextField(PopupMenuFactory.threeDecimalsFormat.format(trough.getThermalEfficiency() * 100) + "%");
thermalEfficiencyField.setEditable(false);
panel.add(thermalEfficiencyField);
i++;
SpringUtilities.makeCompactGrid(panel, i, 2, 4, 4, 4, 4);
final JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
dialog.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
final JButton button = new JButton("Close");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
dialog.dispose();
}
});
buttonPanel.add(button);
dialog.pack();
return dialog;
}
use of javax.swing.SpringLayout in project energy3d by concord-consortium.
the class PopupMenuForLand method getPopupMenu.
static JPopupMenu getPopupMenu() {
if (popupMenuForLand == null) {
final JMenuItem miInfo = new JMenuItem("Land");
miInfo.setEnabled(false);
miInfo.setOpaque(true);
miInfo.setBackground(Config.isMac() ? Color.DARK_GRAY : Color.GRAY);
miInfo.setForeground(Color.WHITE);
final JMenuItem miPaste = new JMenuItem("Paste");
miPaste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, Config.isMac() ? KeyEvent.META_MASK : InputEvent.CTRL_MASK));
miPaste.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
SceneManager.getTaskManager().update(new Callable<Object>() {
@Override
public Object call() throws Exception {
Scene.getInstance().pasteToPickedLocationOnLand();
return null;
}
});
}
});
final JMenuItem miRemoveAllTrees = new JMenuItem("Remove All Trees");
miRemoveAllTrees.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
SceneManager.getTaskManager().update(new Callable<Object>() {
@Override
public Object call() throws Exception {
Scene.getInstance().removeAllTrees();
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
MainPanel.getInstance().getEnergyButton().setSelected(false);
Scene.getInstance().setEdited(true);
}
});
return null;
}
});
}
});
final JMenuItem miRemoveAllHumans = new JMenuItem("Remove All Humans");
miRemoveAllHumans.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
SceneManager.getTaskManager().update(new Callable<Object>() {
@Override
public Object call() throws Exception {
Scene.getInstance().removeAllHumans();
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
MainPanel.getInstance().getEnergyButton().setSelected(false);
Scene.getInstance().setEdited(true);
}
});
return null;
}
});
}
});
final JMenuItem miRemoveAllBuildings = new JMenuItem("Remove All Foundations");
miRemoveAllBuildings.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
SceneManager.getTaskManager().update(new Callable<Object>() {
@Override
public Object call() throws Exception {
Scene.getInstance().removeAllFoundations();
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
MainPanel.getInstance().getEnergyButton().setSelected(false);
Scene.getInstance().setEdited(true);
}
});
return null;
}
});
}
});
final JMenuItem miImportEnergy3D = new JMenuItem("Import...");
miImportEnergy3D.setToolTipText("Import the content in an existing Energy3D file into the clicked location on the land as the center");
miImportEnergy3D.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
MainFrame.getInstance().importFile();
}
});
final JMenuItem miImportCollada = new JMenuItem("Import Collada...");
miImportCollada.setToolTipText("Import the content in an existing Collada file into the clicked location on the land as the center");
miImportCollada.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
MainFrame.getInstance().importColladaFile();
}
});
final JMenu miImportPrefabMenu = new JMenu("Import a Prefab");
addPrefabMenuItem("Back Hip Roof Porch", "prefabs/back-hip-roof-porch.ng3", miImportPrefabMenu);
addPrefabMenuItem("Balcony", "prefabs/balcony1.ng3", miImportPrefabMenu);
addPrefabMenuItem("Bell Tower", "prefabs/bell-tower.ng3", miImportPrefabMenu);
addPrefabMenuItem("Box", "prefabs/box.ng3", miImportPrefabMenu);
addPrefabMenuItem("Chimney", "prefabs/chimney.ng3", miImportPrefabMenu);
addPrefabMenuItem("Connecting Porch", "prefabs/connecting-porch.ng3", miImportPrefabMenu);
addPrefabMenuItem("Cylinder Tower", "prefabs/cylinder-tower.ng3", miImportPrefabMenu);
addPrefabMenuItem("Fence", "prefabs/fence1.ng3", miImportPrefabMenu);
addPrefabMenuItem("Flat-Top Porch", "prefabs/flat-top-porch.ng3", miImportPrefabMenu);
addPrefabMenuItem("Fountain", "prefabs/fountain.ng3", miImportPrefabMenu);
addPrefabMenuItem("Front Door Overhang", "prefabs/front-door-overhang.ng3", miImportPrefabMenu);
addPrefabMenuItem("Gable Dormer", "prefabs/gable-dormer.ng3", miImportPrefabMenu);
addPrefabMenuItem("Hexagonal Gazebo", "prefabs/hexagonal-gazebo.ng3", miImportPrefabMenu);
addPrefabMenuItem("Hexagonal Tower", "prefabs/hexagonal-tower.ng3", miImportPrefabMenu);
addPrefabMenuItem("Lighthouse", "prefabs/lighthouse.ng3", miImportPrefabMenu);
addPrefabMenuItem("Octagonal Tower", "prefabs/octagonal-tower.ng3", miImportPrefabMenu);
addPrefabMenuItem("Round Tower", "prefabs/round-tower.ng3", miImportPrefabMenu);
addPrefabMenuItem("Shed Dormer", "prefabs/shed-dormer.ng3", miImportPrefabMenu);
addPrefabMenuItem("Solarium", "prefabs/solarium1.ng3", miImportPrefabMenu);
addPrefabMenuItem("Square Tower", "prefabs/square-tower.ng3", miImportPrefabMenu);
addPrefabMenuItem("Stair", "prefabs/stair1.ng3", miImportPrefabMenu);
addPrefabMenuItem("Tall Front Door Overhang", "prefabs/tall-front-door-overhang.ng3", miImportPrefabMenu);
addPrefabMenuItem("Temple Front", "prefabs/temple-front.ng3", miImportPrefabMenu);
addPrefabMenuItem("Waterfront Deck", "prefabs/waterfront-deck.ng3", miImportPrefabMenu);
final JMenuItem miAlbedo = new JMenuItem("Albedo...");
miAlbedo.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final String title = "<html>Background Albedo (dimensionless [0, 1])<hr><font size=2>Examples:<br>0.17 (soil), 0.25 (grass), 0.40 (sand), 0.55 (concrete), snow (0.9)</html>";
while (true) {
final String newValue = JOptionPane.showInputDialog(MainFrame.getInstance(), title, Scene.getInstance().getGround().getAlbedo());
if (newValue == null) {
break;
} else {
try {
final double val = Double.parseDouble(newValue);
if (val < 0 || val > 1) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Albedo value must be in 0-1.", "Range Error", JOptionPane.ERROR_MESSAGE);
} else {
if (val != Scene.getInstance().getGround().getAlbedo()) {
final ChangeBackgroundAlbedoCommand c = new ChangeBackgroundAlbedoCommand();
Scene.getInstance().getGround().setAlbedo(val);
updateAfterEdit();
SceneManager.getInstance().getUndoManager().addEdit(c);
}
break;
}
} catch (final NumberFormatException exception) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), newValue + " is an invalid value!", "Error", JOptionPane.ERROR_MESSAGE);
}
}
}
}
});
final JMenuItem miSnowReflection = new JMenuItem("Snow Reflection...");
miSnowReflection.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final JPanel gui = new JPanel(new BorderLayout());
final String title = "<html>Increase of indirect solar radiation due to snow reflection<br>(a dimensionless parameter within [0, 0.2])</html>";
gui.add(new JLabel(title), BorderLayout.NORTH);
final JPanel inputPanel = new JPanel(new SpringLayout());
inputPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
gui.add(inputPanel, BorderLayout.CENTER);
final JTextField[] fields = new JTextField[12];
for (int i = 0; i < 12; i++) {
final JLabel l = new JLabel(AnnualGraph.THREE_LETTER_MONTH[i] + ": ", JLabel.TRAILING);
inputPanel.add(l);
fields[i] = new JTextField(threeDecimalsFormat.format(Scene.getInstance().getGround().getSnowReflectionFactor(i)), 5);
l.setLabelFor(fields[i]);
inputPanel.add(fields[i]);
}
SpringUtilities.makeCompactGrid(inputPanel, 12, 2, 6, 6, 6, 6);
while (true) {
if (JOptionPane.showConfirmDialog(MainFrame.getInstance(), gui, "Snow reflection factor", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.CANCEL_OPTION) {
break;
}
boolean pass = true;
final double[] val = new double[12];
for (int i = 0; i < 12; i++) {
try {
val[i] = Double.parseDouble(fields[i].getText());
if (val[i] < 0 || val[i] > 0.2) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Snow reflection factor must be in 0-0.2.", "Range Error", JOptionPane.ERROR_MESSAGE);
pass = false;
}
} catch (final NumberFormatException exception) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), fields[i].getText() + " is an invalid value!", "Error", JOptionPane.ERROR_MESSAGE);
pass = false;
}
}
if (pass) {
final ChangeSnowReflectionFactorCommand c = new ChangeSnowReflectionFactorCommand();
for (int i = 0; i < 12; i++) {
Scene.getInstance().getGround().setSnowReflectionFactor(val[i], i);
}
updateAfterEdit();
SceneManager.getInstance().getUndoManager().addEdit(c);
break;
}
}
}
});
final JMenuItem miThermalDiffusivity = new JMenuItem("Ground Thermal Diffusivity...");
miThermalDiffusivity.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final String title = "<html>Ground Thermal Diffusivity (m<sup>2</sup>/s)<hr><font size=2>Examples:<br>0.039 (sand), 0.046 (clay), 0.05 (silt)</html>";
while (true) {
final String newValue = JOptionPane.showInputDialog(MainFrame.getInstance(), title, Scene.getInstance().getGround().getThermalDiffusivity());
if (newValue == null) {
break;
} else {
try {
final double val = Double.parseDouble(newValue);
if (val <= 0) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Ground thermal diffusivity must be positive.", "Range Error", JOptionPane.ERROR_MESSAGE);
} else {
if (val != Scene.getInstance().getGround().getThermalDiffusivity()) {
final ChangeGroundThermalDiffusivityCommand c = new ChangeGroundThermalDiffusivityCommand();
Scene.getInstance().getGround().setThermalDiffusivity(val);
updateAfterEdit();
SceneManager.getInstance().getUndoManager().addEdit(c);
}
break;
}
} catch (final NumberFormatException exception) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), newValue + " is an invalid value!", "Error", JOptionPane.ERROR_MESSAGE);
}
}
}
}
});
final JMenuItem miClearImage = new JMenuItem("Clear Image");
final JMenuItem miRescaleImage = new JMenuItem("Rescale Image...");
final JCheckBoxMenuItem miShowImage = new JCheckBoxMenuItem("Show Image");
final JMenu groundImageMenu = new JMenu("Ground Image");
groundImageMenu.addMenuListener(new MenuListener() {
@Override
public void menuCanceled(final MenuEvent e) {
miShowImage.setEnabled(true);
miClearImage.setEnabled(true);
}
@Override
public void menuDeselected(final MenuEvent e) {
miShowImage.setEnabled(true);
miClearImage.setEnabled(true);
}
@Override
public void menuSelected(final MenuEvent e) {
final boolean hasGroundImage = Scene.getInstance().isGroundImageEnabled();
miShowImage.setEnabled(hasGroundImage);
miClearImage.setEnabled(hasGroundImage);
Util.selectSilently(miShowImage, SceneManager.getInstance().getGroundImageLand().isVisible());
}
});
final JMenuItem miUseEarthView = new JMenuItem("Use Image from Earth View...");
miUseEarthView.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
new MapDialog(MainFrame.getInstance()).setVisible(true);
}
});
groundImageMenu.add(miUseEarthView);
final JMenuItem miUseImageFile = new JMenuItem("Use Image from File...");
miUseImageFile.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final File file = FileChooser.getInstance().showDialog(".png", FileChooser.pngFilter, false);
if (file == null) {
return;
}
try {
Scene.getInstance().setGroundImage(ImageIO.read(file), 1);
Scene.getInstance().setGroundImageEarthView(false);
} catch (final Throwable t) {
t.printStackTrace();
JOptionPane.showMessageDialog(MainFrame.getInstance(), t.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
Scene.getInstance().setEdited(true);
}
});
groundImageMenu.add(miUseImageFile);
groundImageMenu.addSeparator();
miRescaleImage.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final String title = "Scale the ground image";
while (true) {
final String newValue = JOptionPane.showInputDialog(MainFrame.getInstance(), title, Scene.getInstance().getGroundImageScale());
if (newValue == null) {
break;
} else {
try {
final double val = Double.parseDouble(newValue);
if (val <= 0) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "The scaling factor must be positive.", "Range Error", JOptionPane.ERROR_MESSAGE);
} else {
// final ChangeGroundThermalDiffusivityCommand c = new ChangeGroundThermalDiffusivityCommand();
Scene.getInstance().setGroundImageScale(val);
// SceneManager.getInstance().getUndoManager().addEdit(c);
break;
}
} catch (final NumberFormatException exception) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), newValue + " is an invalid value!", "Error", JOptionPane.ERROR_MESSAGE);
}
}
}
Scene.getInstance().setEdited(true);
}
});
groundImageMenu.add(miRescaleImage);
miClearImage.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
Scene.getInstance().setGroundImage(null, 1);
Scene.getInstance().setEdited(true);
}
});
groundImageMenu.add(miClearImage);
miShowImage.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
final boolean b = miShowImage.isSelected();
SceneManager.getInstance().getGroundImageLand().setVisible(b);
Scene.getInstance().setShowGroundImage(b);
Scene.getInstance().setEdited(true);
SceneManager.getInstance().refresh();
}
});
groundImageMenu.add(miShowImage);
popupMenuForLand = new JPopupMenu();
popupMenuForLand.setInvoker(MainPanel.getInstance().getCanvasPanel());
popupMenuForLand.addPopupMenuListener(new PopupMenuListener() {
@Override
public void popupMenuWillBecomeVisible(final PopupMenuEvent e) {
final HousePart copyBuffer = Scene.getInstance().getCopyBuffer();
miPaste.setEnabled(copyBuffer instanceof Tree || copyBuffer instanceof Human || copyBuffer instanceof Foundation);
}
@Override
public void popupMenuWillBecomeInvisible(final PopupMenuEvent e) {
}
@Override
public void popupMenuCanceled(final PopupMenuEvent e) {
}
});
popupMenuForLand.add(miInfo);
// popupMenuForLand.addSeparator();
popupMenuForLand.add(miPaste);
popupMenuForLand.add(miRemoveAllTrees);
popupMenuForLand.add(miRemoveAllHumans);
popupMenuForLand.add(miRemoveAllBuildings);
popupMenuForLand.addSeparator();
popupMenuForLand.add(miImportEnergy3D);
popupMenuForLand.add(miImportCollada);
popupMenuForLand.add(miImportPrefabMenu);
popupMenuForLand.addSeparator();
popupMenuForLand.add(groundImageMenu);
popupMenuForLand.add(colorAction);
popupMenuForLand.add(miAlbedo);
popupMenuForLand.add(miSnowReflection);
popupMenuForLand.add(miThermalDiffusivity);
}
return popupMenuForLand;
}
use of javax.swing.SpringLayout in project energy3d by concord-consortium.
the class PropertiesDialogForParabolicTrough method getDialog.
static JDialog getDialog(final ParabolicTrough trough) {
final JDialog dialog = new JDialog(MainFrame.getInstance(), "Parabolic Trough", true);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
final String info = trough.toString().substring(0, trough.toString().indexOf(')') + 1);
dialog.setTitle("Properties - " + info);
dialog.getContentPane().setLayout(new BorderLayout());
final JPanel panel = new JPanel(new SpringLayout());
panel.setBorder(new EmptyBorder(8, 8, 8, 8));
final JScrollPane scroller = new JScrollPane(panel);
scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scroller.setPreferredSize(new Dimension(320, 300));
dialog.getContentPane().add(scroller, BorderLayout.CENTER);
// http://www.powerfromthesun.net/Book/chapter08/chapter08.html
final double focalLength = trough.getSemilatusRectum() * 0.5;
final double d = trough.getApertureWidth();
final double h = d * d / (16 * focalLength);
final double rimAngle = Math.toDegrees(Math.atan(1.0 / (d / (8 * h) - (2 * h) / d)));
final double b = 4 * h / d;
final double c = Math.sqrt(b * b + 1);
final double s = 0.5 * d * c + 2 * focalLength * Math.log(b + c);
int i = 0;
panel.add(new JLabel("Total Length: "));
final JTextField totalLengthField = new JTextField(PopupMenuFactory.threeDecimalsFormat.format(trough.getTroughLength()) + " m (" + trough.getNumberOfModules() + "\u00D7" + PopupMenuFactory.threeDecimalsFormat.format(trough.getModuleLength()) + " m)");
totalLengthField.setEditable(false);
panel.add(totalLengthField);
i++;
panel.add(new JLabel("Aperture Width: "));
final JTextField apertureWidthField = new JTextField(PopupMenuFactory.threeDecimalsFormat.format(d) + " m");
apertureWidthField.setEditable(false);
panel.add(apertureWidthField);
i++;
panel.add(new JLabel("Parabola Height: "));
final JTextField parabolaHeightField = new JTextField(PopupMenuFactory.threeDecimalsFormat.format(h) + " m");
parabolaHeightField.setEditable(false);
panel.add(parabolaHeightField);
i++;
panel.add(new JLabel("Focal Length: "));
final JTextField focalLengthField = new JTextField(PopupMenuFactory.threeDecimalsFormat.format(focalLength) + " m");
focalLengthField.setEditable(false);
panel.add(focalLengthField);
i++;
panel.add(new JLabel("Rim Angle: "));
final JTextField rimAngleField = new JTextField(PopupMenuFactory.threeDecimalsFormat.format(rimAngle) + "\u00B0");
rimAngleField.setEditable(false);
panel.add(rimAngleField);
i++;
panel.add(new JLabel("Total Surface Area: "));
final JTextField totalSurfaceAreaField = new JTextField(PopupMenuFactory.threeDecimalsFormat.format(s * trough.getTroughLength()) + " m\u00B2");
totalSurfaceAreaField.setEditable(false);
panel.add(totalSurfaceAreaField);
i++;
panel.add(new JLabel("Total Aperture Area: "));
final JTextField totalApertureAreaField = new JTextField(PopupMenuFactory.threeDecimalsFormat.format(d * trough.getTroughLength()) + " m\u00B2");
totalApertureAreaField.setEditable(false);
panel.add(totalApertureAreaField);
i++;
panel.add(new JLabel("Mirror Reflectance: "));
final JTextField reflectanceField = new JTextField(PopupMenuFactory.threeDecimalsFormat.format(trough.getReflectance() * 100) + "%");
reflectanceField.setEditable(false);
panel.add(reflectanceField);
i++;
panel.add(new JLabel("Receiver Absorptance: "));
final JTextField absorptanceField = new JTextField(PopupMenuFactory.threeDecimalsFormat.format(trough.getAbsorptance() * 100) + "%");
absorptanceField.setEditable(false);
panel.add(absorptanceField);
i++;
panel.add(new JLabel("Optical Efficiency: "));
final JTextField opticalEfficiencyField = new JTextField(PopupMenuFactory.threeDecimalsFormat.format(trough.getOpticalEfficiency() * 100) + "%");
opticalEfficiencyField.setEditable(false);
panel.add(opticalEfficiencyField);
i++;
panel.add(new JLabel("Thermal Efficiency: "));
final JTextField thermalEfficiencyField = new JTextField(PopupMenuFactory.threeDecimalsFormat.format(trough.getThermalEfficiency() * 100) + "%");
thermalEfficiencyField.setEditable(false);
panel.add(thermalEfficiencyField);
i++;
SpringUtilities.makeCompactGrid(panel, i, 2, 4, 4, 4, 4);
final JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
dialog.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
final JButton button = new JButton("Close");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
dialog.dispose();
}
});
buttonPanel.add(button);
dialog.pack();
return dialog;
}
use of javax.swing.SpringLayout in project energy3d by concord-consortium.
the class PropertiesDialogForSolarPanel method getDialog.
static JDialog getDialog(final SolarPanel solarPanel) {
final JDialog dialog = new JDialog(MainFrame.getInstance(), "Solar Panel", true);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
final String info = solarPanel.toString().substring(0, solarPanel.toString().indexOf(')') + 1);
dialog.setTitle("Properties - " + info);
dialog.getContentPane().setLayout(new BorderLayout());
final JPanel panel = new JPanel(new SpringLayout());
panel.setBorder(new EmptyBorder(8, 8, 8, 8));
final JScrollPane scroller = new JScrollPane(panel);
scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scroller.setPreferredSize(new Dimension(400, 300));
dialog.getContentPane().add(scroller, BorderLayout.CENTER);
final PvModuleSpecs specs = solarPanel.getPvModuleSpecs();
int i = 0;
panel.add(new JLabel("Manufacturer: "));
final JTextField brandField = new JTextField(specs.getBrand());
brandField.setEditable(false);
panel.add(brandField);
i++;
panel.add(new JLabel("Model: "));
final JTextField modelField = new JTextField(specs.getModel());
modelField.setEditable(false);
panel.add(modelField);
i++;
panel.add(new JLabel("Color: "));
final JTextField colorField = new JTextField(specs.getColor());
colorField.setEditable(false);
panel.add(colorField);
i++;
panel.add(new JLabel("Cell Type: "));
final JTextField cellTypeField = new JTextField(specs.getCellType());
cellTypeField.setEditable(false);
panel.add(cellTypeField);
i++;
panel.add(new JLabel("Cell Efficiency: "));
final JTextField cellEfficiencyField = new JTextField(PopupMenuFactory.threeDecimalsFormat.format(specs.getCelLEfficiency() * 100) + "%");
cellEfficiencyField.setEditable(false);
panel.add(cellEfficiencyField);
i++;
panel.add(new JLabel("Dimension: "));
final JTextField dimensionField = new JTextField(PopupMenuFactory.threeDecimalsFormat.format(specs.getLength()) + "\u00D7" + PopupMenuFactory.threeDecimalsFormat.format(specs.getWidth()) + "\u00D7" + PopupMenuFactory.threeDecimalsFormat.format(specs.getThickness()) + " m");
dimensionField.setEditable(false);
panel.add(dimensionField);
i++;
panel.add(new JLabel("Cells: "));
final JTextField cellsField = new JTextField(specs.getLayout().width + "\u00D7" + specs.getLayout().height);
cellsField.setEditable(false);
panel.add(cellsField);
i++;
panel.add(new JLabel("Maximal Power (Pmax): "));
final JTextField pmaxField = new JTextField(PopupMenuFactory.threeDecimalsFormat.format(specs.getPmax()) + " W");
pmaxField.setEditable(false);
panel.add(pmaxField);
i++;
panel.add(new JLabel("Voltage at Maximal Power Point (Vmpp): "));
final JTextField vmppField = new JTextField(PopupMenuFactory.threeDecimalsFormat.format(specs.getVmpp()) + " V");
vmppField.setEditable(false);
panel.add(vmppField);
i++;
panel.add(new JLabel("Current at Maximal Power Point (Impp): "));
final JTextField imppField = new JTextField(PopupMenuFactory.threeDecimalsFormat.format(specs.getImpp()) + " A");
imppField.setEditable(false);
panel.add(imppField);
i++;
panel.add(new JLabel("Voltage at Open Circuit (Voc): "));
final JTextField vocField = new JTextField(PopupMenuFactory.threeDecimalsFormat.format(specs.getVoc()) + " V");
vocField.setEditable(false);
panel.add(vocField);
i++;
panel.add(new JLabel("Current at Short Circuit (Isc): "));
final JTextField iscField = new JTextField(PopupMenuFactory.threeDecimalsFormat.format(specs.getIsc()) + " A");
iscField.setEditable(false);
panel.add(iscField);
i++;
panel.add(new JLabel("Nominal Operating Cell Temperature (NOCT): "));
final JTextField noctField = new JTextField(PopupMenuFactory.threeDecimalsFormat.format(specs.getNoct()) + " \u00B0C");
noctField.setEditable(false);
panel.add(noctField);
i++;
panel.add(new JLabel("Temperature Coefficient of Power: "));
final JTextField pmaxTcField = new JTextField(PopupMenuFactory.sixDecimalsFormat.format(specs.getPmaxTc()) + "%/\u00B0C");
pmaxTcField.setEditable(false);
panel.add(pmaxTcField);
i++;
panel.add(new JLabel("Weight: "));
final JTextField weightField = new JTextField(PopupMenuFactory.threeDecimalsFormat.format(specs.getWeight()) + " kg");
weightField.setEditable(false);
panel.add(weightField);
i++;
panel.add(new JLabel("Tracker: "));
final JTextField trackerField = new JTextField(solarPanel.getTrackerName() == null ? "None" : solarPanel.getTrackerName());
trackerField.setEditable(false);
panel.add(trackerField);
i++;
SpringUtilities.makeCompactGrid(panel, i, 2, 4, 4, 4, 4);
final JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
dialog.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
final JButton button = new JButton("Close");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
dialog.dispose();
}
});
buttonPanel.add(button);
dialog.pack();
return dialog;
}
use of javax.swing.SpringLayout in project GenericKnimeNodes by genericworkflownodes.
the class DialogComponentMultiFileChooser method setupLayout.
/**
* Initializes the {@link SpringLayout} for the content of this pane.
*
* @param springLayout
* The used {@link SpringLayout}.
* @param listScroller
* The scroller containing the {@link #listbox}.
*/
private void setupLayout(SpringLayout springLayout, JScrollPane listScroller) {
// arrange all items in the spring layout
springLayout.putConstraint(SpringLayout.WEST, listScroller, 5, SpringLayout.WEST, getComponentPanel());
springLayout.putConstraint(SpringLayout.NORTH, listScroller, 5, SpringLayout.NORTH, getComponentPanel());
springLayout.putConstraint(SpringLayout.SOUTH, listScroller, -5, SpringLayout.SOUTH, getComponentPanel());
springLayout.putConstraint(SpringLayout.WEST, addButton, 10, SpringLayout.EAST, listScroller);
springLayout.putConstraint(SpringLayout.WEST, removeButton, 10, SpringLayout.EAST, listScroller);
springLayout.putConstraint(SpringLayout.WEST, clearButton, 10, SpringLayout.EAST, listScroller);
springLayout.putConstraint(SpringLayout.NORTH, addButton, 10, SpringLayout.NORTH, getComponentPanel());
springLayout.putConstraint(SpringLayout.NORTH, removeButton, 12 + springLayout.getConstraints(addButton).getHeight().getPreferredValue(), SpringLayout.NORTH, getComponentPanel());
springLayout.putConstraint(SpringLayout.NORTH, clearButton, 14 + 2 * springLayout.getConstraints(addButton).getHeight().getPreferredValue(), SpringLayout.NORTH, getComponentPanel());
SpringLayout.Constraints addCst = springLayout.getConstraints(addButton);
SpringLayout.Constraints removeCst = springLayout.getConstraints(removeButton);
SpringLayout.Constraints clearCst = springLayout.getConstraints(clearButton);
Spring maxSpring = Spring.max(addCst.getWidth(), Spring.max(removeCst.getWidth(), clearCst.getWidth()));
addCst.setWidth(maxSpring);
removeCst.setWidth(maxSpring);
clearCst.setWidth(maxSpring);
springLayout.putConstraint(SpringLayout.EAST, addButton, -10, SpringLayout.EAST, getComponentPanel());
springLayout.putConstraint(SpringLayout.EAST, removeButton, -10, SpringLayout.EAST, getComponentPanel());
springLayout.putConstraint(SpringLayout.EAST, clearButton, -10, SpringLayout.EAST, getComponentPanel());
springLayout.putConstraint(SpringLayout.EAST, listScroller, -20 - maxSpring.getMaximumValue(), SpringLayout.EAST, getComponentPanel());
}
Aggregations