Ejemplo n.º 1
0
	/**
	 * Stores the values of the spinners in the {@link BookView model}.
	 * In order to do it
	 * <ul>
	 * <li>commits the edited values to all spinners,</li>
	 * <li>sets the {@link BookPlot#setZoom(double, double, double, double)
	 * zoom} in the {@link BookPlot book plot},</li>
	 * <li>sets the {@link ZoomBookTool#setPreserveRatio(boolean) preserve
	 * ratio} in the {@link ZoomBookTool}.</li></ul>
	 * @param view the model
	 */
	public void fillModelFromPanel(BookView view) {

		BookPlot plot = view.getPlot();
		StandardBookSegment segment = plot.getSegment();

		if (segment == null) {
			return;
		}

		// XXX update broken spinners...
		try {
			getMinPositionSpinner().commitEdit();
		} catch (ParseException ex) {
			JComponent editor = getMinPositionSpinner().getEditor();
			if (editor instanceof DefaultEditor) {
				((DefaultEditor) editor).getTextField().setValue(getMinPositionSpinner().getValue());
			}
		}

		try {
			getMaxPositionSpinner().commitEdit();
		} catch (ParseException ex) {
			JComponent editor = getMaxPositionSpinner().getEditor();
			if (editor instanceof DefaultEditor) {
				((DefaultEditor) editor).getTextField().setValue(getMaxPositionSpinner().getValue());
			}
		}

		try {
			getMinFrequencySpinner().commitEdit();
		} catch (ParseException ex) {
			JComponent editor = getMinFrequencySpinner().getEditor();
			if (editor instanceof DefaultEditor) {
				((DefaultEditor) editor).getTextField().setValue(getMinFrequencySpinner().getValue());
			}
		}

		try {
			getMaxFrequencySpinner().commitEdit();
		} catch (ParseException ex) {
			JComponent editor = getMaxFrequencySpinner().getEditor();
			if (editor instanceof DefaultEditor) {
				((DefaultEditor) editor).getTextField().setValue(getMaxFrequencySpinner().getValue());
			}
		}

		double minPosition = ((Number) getMinPositionSpinner().getValue()).doubleValue();
		double maxPosition = ((Number) getMaxPositionSpinner().getValue()).doubleValue();
		double minFrequency = ((Number) getMinFrequencySpinner().getValue()).doubleValue();
		double maxFrequency = ((Number) getMaxFrequencySpinner().getValue()).doubleValue();

		plot.setZoom(minPosition, maxPosition, minFrequency, maxFrequency);

		view.getZoomBookTool().setPreserveRatio(getPreserveRatioCheckBox().isSelected());

	}
Ejemplo n.º 2
0
	/**
	 * Using the given {@link BookView model} fills the fields of this panel:
	 * <ul>
	 * <li>the maximum of {@link #getMinPositionModel() minimum} and {@link
	 * #getMaxPositionModel() maximum} position model,</li>
	 * <li>the maximum of {@link #getMinFrequencyModel() minimum} and {@link
	 * #getMaxFrequencyModel() maximum} frequency model,</li>
	 * <li>the state of {@link #getPreserveRatioCheckBox() preserve zoom ratio
	 * check-box}.</li>
	 * </ul>
	 * @param view the model
	 */
	public void fillPanelFromModel(BookView view) {

		BookPlot plot = view.getPlot();
		StandardBookSegment segment = plot.getSegment();

		if (segment == null) {
			return;
		}

		positionLimit = segment.getSegmentLength();
		frequencyLimit = view.getDocument().getBook().getSamplingFrequency()/2;

		getMinPositionModel().setMaximum(positionLimit - 0.01);
		getMaxPositionModel().setMaximum(positionLimit);

		getMinFrequencyModel().setMaximum(frequencyLimit - 0.01);
		getMaxFrequencyModel().setMaximum(frequencyLimit);

		getMinPositionSpinner().setValue(plot.getMinPosition());
		getMaxPositionSpinner().setValue(plot.getMaxPosition());

		getMinFrequencySpinner().setValue(plot.getMinFrequency());
		getMaxFrequencySpinner().setValue(plot.getMaxFrequency());

		getPreserveRatioCheckBox().setSelected(view.getZoomBookTool().isPreserveRatio());

	}