
org.ardulink.gui.connectionpanel.GenericPanelBuilder Maven / Gradle / Ivy
The newest version!
/**
Copyright 2013 project Ardulink http://www.ardulink.org/
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.ardulink.gui.connectionpanel;
import static java.awt.GridBagConstraints.REMAINDER;
import static java.util.Arrays.asList;
import static org.ardulink.gui.connectionpanel.GridBagConstraintsBuilder.constraints;
import static org.ardulink.util.Numbers.numberType;
import static org.ardulink.util.Primitives.wrap;
import java.awt.Component;
import java.awt.GridBagLayout;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.net.URI;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.ListCellRenderer;
import javax.swing.SpinnerModel;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingConstants;
import org.ardulink.core.linkmanager.LinkManager.ConfigAttribute;
import org.ardulink.core.linkmanager.LinkManager.Configurer;
import org.ardulink.core.linkmanager.LinkManager.NumberValidationInfo;
import org.ardulink.core.linkmanager.LinkManager.ValidationInfo;
import org.ardulink.util.Numbers;
import org.ardulink.util.Primitives;
public class GenericPanelBuilder implements PanelBuilder {
@Override
public boolean canHandle(URI uri) {
// we can handle all URIs
return true;
}
@Override
public JPanel createPanel(Configurer configurer) {
JPanel panel = new JPanel(new GridBagLayout());
int row = 0;
for (String name : configurer.getAttributes()) {
int col = 0;
ConfigAttribute attribute = configurer.getAttribute(name);
String description = attribute.getDescription();
JLabel label = new JLabel(attribute.getName());
label.setToolTipText(description);
panel.add(label, constraints(row, col++).build());
boolean isDiscoverable = attribute.choiceDependsOn().length > 0;
JComponent component = createComponent(attribute);
component.setToolTipText(description);
panel.add(component,
constraints(row, col++).gridwidth(isDiscoverable ? 1 : REMAINDER).fillHorizontal().build());
@SuppressWarnings("unchecked")
Component comp = isDiscoverable ? createDiscoverButton(attribute, (JComboBox
© 2015 - 2025 Weber Informatics LLC | Privacy Policy