Example usage for javax.swing SpringLayout VERTICAL_CENTER

List of usage examples for javax.swing SpringLayout VERTICAL_CENTER

Introduction

In this page you can find the example usage for javax.swing SpringLayout VERTICAL_CENTER.

Prototype

String VERTICAL_CENTER

To view the source code for javax.swing SpringLayout VERTICAL_CENTER.

Click Source Link

Document

Specifies the vertical center of a component's bounding rectangle.

Usage

From source file:org.angnysa.yaba.swing.BudgetFrame.java

private void buildSimulationPanel() {

    simulationPanel = new JPanel();
    SpringLayout springLayout = new SpringLayout();
    simulationPanel.setLayout(springLayout);

    // chart data
    simulationDataset = new SimulationDataset(service);
    simulationDataset.setInitial(0D);/*  w ww. j  av a2s.c  o m*/
    simulationDataset.setStart(new LocalDate());
    simulationDataset.setEnd(new LocalDate().plus(Years.ONE));
    simulationDataset.setPeriod(Period.months(1));
    simulationDataset.updateDataset();
    transactionModel.addTableModelListener(new TableModelListener() {

        @Override
        public void tableChanged(TableModelEvent e) {
            simulationDataset.updateDataset();
        }
    });
    reconciliationModel.addTableModelListener(new TableModelListener() {

        @Override
        public void tableChanged(TableModelEvent e) {
            simulationDataset.updateDataset();
        }
    });

    // initial amount label
    JLabel amountLbl = new JLabel(Messages.getString("simulation.field.initial-amount")); //$NON-NLS-1$
    springLayout.putConstraint(SpringLayout.WEST, amountLbl, 10, SpringLayout.WEST, simulationPanel);
    simulationPanel.add(amountLbl);

    // initial amount field
    amountFld = new JFormattedTextField(
            new DefaultFormatterFactory(new NumberFormatter(NumberFormat.getNumberInstance()),
                    new NumberFormatter(NumberFormat.getCurrencyInstance())));
    amountFld.setColumns(8);
    amountFld.setValue(simulationDataset.getInitial());
    amountFld.addPropertyChangeListener("value", new PropertyChangeListener() { //$NON-NLS-1$

        @Override
        public void propertyChange(PropertyChangeEvent e) {
            simulationDataset.setInitial(((Number) amountFld.getValue()).doubleValue());
            simulationDataset.updateDataset();
        }
    });
    springLayout.putConstraint(SpringLayout.VERTICAL_CENTER, amountLbl, 0, SpringLayout.VERTICAL_CENTER,
            amountFld);
    springLayout.putConstraint(SpringLayout.WEST, amountFld, 0, SpringLayout.EAST, amountLbl);
    springLayout.putConstraint(SpringLayout.NORTH, amountFld, 10, SpringLayout.NORTH, simulationPanel);
    simulationPanel.add(amountFld);

    // start date label
    JLabel fromLbl = new JLabel(Messages.getString("simulation.field.start-date")); //$NON-NLS-1$
    springLayout.putConstraint(SpringLayout.WEST, fromLbl, 10, SpringLayout.EAST, amountFld);
    simulationPanel.add(fromLbl);

    // start date field
    fromFld = new JFormattedTextField(new JodaLocalDateFormat());
    fromFld.setColumns(8);
    fromFld.setValue(simulationDataset.getStart());
    fromFld.addPropertyChangeListener("value", new PropertyChangeListener() { //$NON-NLS-1$

        @Override
        public void propertyChange(PropertyChangeEvent e) {
            simulationDataset.setStart((LocalDate) fromFld.getValue());
            simulationDataset.updateDataset();
        }
    });
    springLayout.putConstraint(SpringLayout.VERTICAL_CENTER, fromLbl, 0, SpringLayout.VERTICAL_CENTER, fromFld);
    springLayout.putConstraint(SpringLayout.WEST, fromFld, 0, SpringLayout.EAST, fromLbl);
    springLayout.putConstraint(SpringLayout.NORTH, fromFld, 10, SpringLayout.NORTH, simulationPanel);
    simulationPanel.add(fromFld);

    // end date label
    JLabel toLbl = new JLabel(Messages.getString("simulation.field.end-date")); //$NON-NLS-1$
    springLayout.putConstraint(SpringLayout.WEST, toLbl, 10, SpringLayout.EAST, fromFld);
    simulationPanel.add(toLbl);

    // end date field
    toFld = new JFormattedTextField(new JodaLocalDateFormat());
    toFld.setColumns(8);
    toFld.setValue(simulationDataset.getEnd());
    toFld.addPropertyChangeListener("value", new PropertyChangeListener() { //$NON-NLS-1$

        @Override
        public void propertyChange(PropertyChangeEvent e) {
            simulationDataset.setEnd((LocalDate) toFld.getValue());
            simulationDataset.updateDataset();
        }
    });
    springLayout.putConstraint(SpringLayout.VERTICAL_CENTER, toLbl, 0, SpringLayout.VERTICAL_CENTER, toFld);
    springLayout.putConstraint(SpringLayout.WEST, toFld, 0, SpringLayout.EAST, toLbl);
    springLayout.putConstraint(SpringLayout.NORTH, toFld, 10, SpringLayout.NORTH, simulationPanel);
    simulationPanel.add(toFld);

    // period label
    JLabel periodLbl = new JLabel(Messages.getString("simulation.field.period")); //$NON-NLS-1$
    springLayout.putConstraint(SpringLayout.WEST, periodLbl, 10, SpringLayout.EAST, toFld);
    simulationPanel.add(periodLbl);

    // period field
    periodFld = new JFormattedTextField(new JodaPeriodFormat());
    periodFld.setColumns(5);
    periodFld.setValue(simulationDataset.getPeriod());
    periodFld.addPropertyChangeListener("value", new PropertyChangeListener() { //$NON-NLS-1$

        @Override
        public void propertyChange(PropertyChangeEvent e) {
            simulationDataset.setPeriod((ReadablePeriod) periodFld.getValue());
            simulationDataset.updateDataset();
        }
    });
    springLayout.putConstraint(SpringLayout.VERTICAL_CENTER, periodLbl, 0, SpringLayout.VERTICAL_CENTER,
            periodFld);
    springLayout.putConstraint(SpringLayout.WEST, periodFld, 0, SpringLayout.EAST, periodLbl);
    springLayout.putConstraint(SpringLayout.NORTH, periodFld, 10, SpringLayout.NORTH, simulationPanel);
    simulationPanel.add(periodFld);

    // chart panel
    JFreeChart chart = ChartFactory.createLineChart("", Messages.getString("simulation.chart.date-axis-label"), //$NON-NLS-1$//$NON-NLS-2$
            Messages.getString("simulation.chart.amount-axis-label"), simulationDataset, //$NON-NLS-1$
            PlotOrientation.VERTICAL, false, true, false);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesFilled(true);
    renderer.setBaseShapesVisible(true);
    renderer.setBaseToolTipGenerator(new SimulationTooltipGenerator(service));
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setDismissDelay(3600000);
    chartPanel.setInitialDelay(0);
    springLayout.putConstraint(SpringLayout.NORTH, chartPanel, 15, SpringLayout.SOUTH, periodFld);
    springLayout.putConstraint(SpringLayout.WEST, chartPanel, 10, SpringLayout.WEST, simulationPanel);
    springLayout.putConstraint(SpringLayout.SOUTH, chartPanel, -10, SpringLayout.SOUTH, simulationPanel);
    springLayout.putConstraint(SpringLayout.EAST, chartPanel, -10, SpringLayout.EAST, simulationPanel);
    simulationPanel.add(chartPanel);
}