Search in sources :

Example 46 with SpringLayout

use of javax.swing.SpringLayout in project energy3d by concord-consortium.

the class PropertiesDialogForRack method getDialog.

static JDialog getDialog(final Rack rack) {
    final SolarPanel solarPanel = rack.getSolarPanel();
    final JDialog dialog = new JDialog(MainFrame.getInstance(), "Solar Panel", true);
    dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    final String info = rack.toString().substring(0, rack.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("Solar Panel Manufacturer: "));
    final JTextField brandField = new JTextField(specs.getBrand());
    brandField.setEditable(false);
    panel.add(brandField);
    i++;
    panel.add(new JLabel("Solar Panel Model: "));
    final JTextField modelField = new JTextField(specs.getModel());
    modelField.setEditable(false);
    panel.add(modelField);
    i++;
    panel.add(new JLabel("Solar Panels: "));
    final int[] nxny = rack.getSolarPanelRowAndColumnNumbers();
    final JTextField layoutField = new JTextField(nxny[0] + "\u00D7" + nxny[1] + " = " + rack.getNumberOfSolarPanels());
    layoutField.setEditable(false);
    panel.add(layoutField);
    i++;
    panel.add(new JLabel("Solar Panel Color: "));
    final JTextField colorField = new JTextField(specs.getColor());
    colorField.setEditable(false);
    panel.add(colorField);
    i++;
    panel.add(new JLabel("Solar Cell Type: "));
    final JTextField cellTypeField = new JTextField(specs.getCellType());
    cellTypeField.setEditable(false);
    panel.add(cellTypeField);
    i++;
    panel.add(new JLabel("Solar Cell Efficiency: "));
    final JTextField cellEfficiencyField = new JTextField(PopupMenuFactory.threeDecimalsFormat.format(specs.getCelLEfficiency() * 100) + "%");
    cellEfficiencyField.setEditable(false);
    panel.add(cellEfficiencyField);
    i++;
    panel.add(new JLabel("Solar Panel 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("Solar Cells on Each Panel: "));
    final JTextField cellsField = new JTextField(specs.getLayout().width + "\u00D7" + specs.getLayout().height);
    cellsField.setEditable(false);
    panel.add(cellsField);
    i++;
    panel.add(new JLabel("Solar Panel 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("Single Solar Panel 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(rack.getTrackerName() == null ? "None" : rack.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;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField) BorderLayout(java.awt.BorderLayout) ActionListener(java.awt.event.ActionListener) SolarPanel(org.concord.energy3d.model.SolarPanel) SpringLayout(javax.swing.SpringLayout) EmptyBorder(javax.swing.border.EmptyBorder) PvModuleSpecs(org.concord.energy3d.simulation.PvModuleSpecs) JDialog(javax.swing.JDialog)

Example 47 with SpringLayout

use of javax.swing.SpringLayout in project megameklab by MegaMek.

the class SpringUtilities method getConstraintsForCell.

private static Constraints getConstraintsForCell(int row, int col, Container parent, int cols) {
    SpringLayout layout = (SpringLayout) parent.getLayout();
    Component c = parent.getComponent(row * cols + col);
    return layout.getConstraints(c);
}
Also used : SpringLayout(javax.swing.SpringLayout)

Example 48 with SpringLayout

use of javax.swing.SpringLayout in project megameklab by MegaMek.

the class SpringLayoutHelper method setupSpringGrid.

public static void setupSpringGrid(JPanel panel, int rows, int columns) {
    // setup new layout.
    SpringLayout layout = (SpringLayout) panel.getLayout();
    // add padding so that the count matches
    if (panel.getComponentCount() < (rows * columns)) {
        for (int x = panel.getComponentCount(); x < (rows * columns); x++) {
            panel.add(new JLabel(" "));
        }
    }
    // make all cells in each row same height.
    Spring y = Spring.constant(4);
    for (int r = 0; r < rows; r++) {
        Spring height = Spring.constant(0);
        for (int c = 0; c < columns; c++) {
            height = Spring.max(height, layout.getConstraints(panel.getComponent(r * columns + c)).getHeight());
        }
        for (int c = 0; c < columns; c++) {
            SpringLayout.Constraints constraints = layout.getConstraints(panel.getComponent(r * columns + c));
            constraints.setY(y);
            constraints.setHeight(height);
        }
        y = Spring.sum(y, Spring.sum(height, Spring.constant(4)));
    }
    // make all cells in each column the same width.
    Spring x = Spring.constant(4);
    for (int c = 0; c < columns; c++) {
        Spring width = Spring.constant(0);
        for (int r = 0; r < rows; r++) {
            width = Spring.max(width, layout.getConstraints(panel.getComponent(r * columns + c)).getWidth());
        }
        for (int r = 0; r < rows; r++) {
            SpringLayout.Constraints constraints = layout.getConstraints(panel.getComponent(r * columns + c));
            constraints.setX(x);
            constraints.setWidth(width);
        }
        x = Spring.sum(x, Spring.sum(width, Spring.constant(4)));
    }
    // Set the parent's size.
    SpringLayout.Constraints panelConstraints = layout.getConstraints(panel);
    panelConstraints.setConstraint(SpringLayout.SOUTH, y);
    panelConstraints.setConstraint(SpringLayout.EAST, x);
}
Also used : SpringLayout(javax.swing.SpringLayout) JLabel(javax.swing.JLabel) Spring(javax.swing.Spring)

Example 49 with SpringLayout

use of javax.swing.SpringLayout in project airavata by apache.

the class SwingUtil method makeSpringCompactGrid.

/**
 * Aligns the first <code>rows</code> * <code>cols</code> components of <code>parent</code> in a grid. Each
 * component in a column is as wide as the maximum preferred width of the components in that column; height is
 * similarly determined for each row. The parent is made just big enough to fit them all.
 *
 * @param parent
 *
 * @param rows
 *            number of rows
 * @param cols
 *            number of columns
 * @param initialX
 *            x location to start the grid at
 * @param initialY
 *            y location to start the grid at
 * @param xPad
 *            x padding between cells
 * @param yPad
 *            y padding between cells
 */
private static void makeSpringCompactGrid(Container parent, int rows, int cols, int initialX, int initialY, int xPad, int yPad) {
    SpringLayout layout = new SpringLayout();
    parent.setLayout(layout);
    // Align all cells in each column and make them the same width.
    Spring x = Spring.constant(initialX);
    for (int c = 0; c < cols; c++) {
        Spring width = Spring.constant(0);
        for (int r = 0; r < rows; r++) {
            width = Spring.max(width, getConstraintsForCell(r, c, parent, cols).getWidth());
        }
        for (int r = 0; r < rows; r++) {
            SpringLayout.Constraints constraints = getConstraintsForCell(r, c, parent, cols);
            constraints.setX(x);
            constraints.setWidth(width);
        }
        x = Spring.sum(x, Spring.sum(width, Spring.constant(xPad)));
    }
    // Align all cells in each row and make them the same height.
    Spring y = Spring.constant(initialY);
    for (int r = 0; r < rows; r++) {
        Spring height = Spring.constant(0);
        for (int c = 0; c < cols; c++) {
            height = Spring.max(height, getConstraintsForCell(r, c, parent, cols).getHeight());
        }
        for (int c = 0; c < cols; c++) {
            SpringLayout.Constraints constraints = getConstraintsForCell(r, c, parent, cols);
            constraints.setY(y);
            constraints.setHeight(height);
        }
        y = Spring.sum(y, Spring.sum(height, Spring.constant(yPad)));
    }
    // Set the parent's size.
    SpringLayout.Constraints pCons = layout.getConstraints(parent);
    pCons.setConstraint(SpringLayout.SOUTH, y);
    pCons.setConstraint(SpringLayout.EAST, x);
}
Also used : SpringLayout(javax.swing.SpringLayout) Spring(javax.swing.Spring)

Example 50 with SpringLayout

use of javax.swing.SpringLayout in project airavata by apache.

the class SwingUtil method getConstraintsForCell.

/* Used by makeCompactGrid. */
private static SpringLayout.Constraints getConstraintsForCell(int row, int col, Container parent, int cols) {
    SpringLayout layout = (SpringLayout) parent.getLayout();
    Component c = parent.getComponent(row * cols + col);
    return layout.getConstraints(c);
}
Also used : SpringLayout(javax.swing.SpringLayout) Component(java.awt.Component)

Aggregations

SpringLayout (javax.swing.SpringLayout)57 JLabel (javax.swing.JLabel)21 JPanel (javax.swing.JPanel)21 Spring (javax.swing.Spring)21 BorderLayout (java.awt.BorderLayout)18 JTextField (javax.swing.JTextField)17 ActionEvent (java.awt.event.ActionEvent)15 ActionListener (java.awt.event.ActionListener)15 Component (java.awt.Component)12 JDialog (javax.swing.JDialog)12 Dimension (java.awt.Dimension)11 JButton (javax.swing.JButton)10 JScrollPane (javax.swing.JScrollPane)10 EmptyBorder (javax.swing.border.EmptyBorder)9 FlowLayout (java.awt.FlowLayout)8 JMenuItem (javax.swing.JMenuItem)7 Constraints (javax.swing.SpringLayout.Constraints)6 ItemEvent (java.awt.event.ItemEvent)5 Callable (java.util.concurrent.Callable)5 JMenu (javax.swing.JMenu)5