View Javadoc
1   /*
2    * Copyright (c) 2020 bahlef.
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the Eclipse Public License v2.0
5    * which accompanies this distribution, and is available at
6    * http://www.eclipse.org/legal/epl-v20.html
7    * Contributors:
8    * bahlef - initial API and implementation and/or initial documentation
9    */
10  
11  package de.funfried.netbeans.plugins.external.formatter.ui.options;
12  
13  import javax.swing.JPanel;
14  import javax.swing.event.ChangeListener;
15  
16  import org.netbeans.api.project.Project;
17  import org.openide.util.ChangeSupport;
18  
19  /**
20   * Abstract base implementation of {@link FormatterOptionsPanel}.
21   *
22   * @author bahlef
23   */
24  public abstract class AbstractFormatterOptionsPanel extends JPanel implements FormatterOptionsPanel {
25  	/** {@link ChangeSupport} to notify about changed preference components. */
26  	protected final ChangeSupport changeSupport;
27  
28  	/** The {@link Project} which this panel is used to change the settings for or {@code null} if this panel is used to change the global settings. */
29  	protected final Project project;
30  
31  	/**
32  	 * Default constructor of {@link AbstractFormatterOptionsPanel}.
33  	 *
34  	 * @param project the {@link Project} if the panel is used to modify project
35  	 *                specific settings, otherwise {@code null}
36  	 */
37  	public AbstractFormatterOptionsPanel(Project project) {
38  		this.project = project;
39  
40  		this.changeSupport = new ChangeSupport(this);
41  	}
42  
43  	/**
44  	 * {@inheritDoc}
45  	 */
46  	@Override
47  	public JPanel getComponent() {
48  		return this;
49  	}
50  
51  	/**
52  	 * {@inheritDoc}
53  	 */
54  	@Override
55  	public void addChangeListener(ChangeListener listener) {
56  		changeSupport.addChangeListener(listener);
57  	}
58  
59  	/**
60  	 * Fires a change event to all registered {@link ChangeListener}s.
61  	 */
62  	protected void fireChangedListener() {
63  		changeSupport.fireChange();
64  	}
65  
66  	/**
67  	 * {@inheritDoc}
68  	 */
69  	@Override
70  	public void removeChangeListener(ChangeListener listener) {
71  		changeSupport.removeChangeListener(listener);
72  	}
73  
74  	/**
75  	 * {@inheritDoc}
76  	 */
77  	@Override
78  	public boolean valid() {
79  		return true;
80  	}
81  }