Hi Everyone,
I have a question about PMIObjects. According to the Javadocs, PMIObjects like PMILabel inherit from Swing components—in this case, from JLabel.
I’m building some custom widgets and have noticed that my styles are ignored when I use PMIObjects. However, when I use Swing components, the styles work as expected. Am I using incorrect syntax for PMIObjects? Is it okay to use Swing components instead of PMIObjects? Are there any risks associated with using Swing components?
Additionally, I have a question about using the setStyles() method for any PMIObject.
I’m using a dataset builder, but I’m unsure how to define the column types. I don’t know which class to use for defining the column types. Can anyone help me create a styles dataset from inside the module? Here is a screenshot from Ignition Designer when using a style customizer:
public class DiscreteControlPane extends JPanel implements ActionListener {
private final Logger logger = LoggerFactory.getLogger(getClass());
private PMIButton autoOn = new PMIButton();
//private JLabel deviceState = new JLabel();
private PMILabel deviceState = new PMILabel();
private PMIButton manualOn = new PMIButton();
private PMIButton manualOff = new PMIButton();
private PMILabel deviceDescription = new PMILabel();
private DatasetBuilder styles = DatasetBuilder.newBuilder()
.colNames("Property","Value")
.colTypes(String.class, String.class)
.addRow("border", "border(line;color(0,0,0,255);2)")
.addRow("background", Color.blue);
private Dataset stylesDataset = styles.build();
private String tagPath;
private Color lightGrey = new Color(238, 236, 232, 255);
private Dimension buttonSize = new Dimension(150, 53);
public DiscreteControlPane() {
logger.info("Styles -> ",deviceDescription.getStyles());
logger.info("Inside Constructor for discrete pane -> Context: ");
this.setBackground(lightGrey);
this.setOpaque(true);
GridBagLayout layoutManager = new GridBagLayout();
this.setLayout(layoutManager);
setPreferredSize(new Dimension(520, 303));
GridBagConstraints layoutBehavior = new GridBagConstraints();
layoutBehavior.weighty = 1;
layoutBehavior.weightx = 1;
layoutManager.setConstraints(this, layoutBehavior);
autoOn.setText("AUTO ON");
manualOn.setText("MANUAL ON");
manualOff.setText("MANUAL OFF");
deviceState.setText("INSERT DYNAMIC TEXT");
deviceDescription.setText("INSERT DYNAMIC TEXT");
autoOn.addActionListener(this);
manualOn.addActionListener(this);
manualOff.addActionListener(this);
layoutBehavior.gridx = 0;
layoutBehavior.gridy = 0;
layoutBehavior.gridwidth = GridBagConstraints.REMAINDER;
layoutBehavior.fill = GridBagConstraints.CENTER;
layoutManager.setConstraints(deviceDescription, layoutBehavior);
add(deviceDescription);
//TODO: resize buttons - look into padding, why cant my elements retain their size....
deviceState.setStyles(stylesDataset);
//deviceState.setBackground(new Color(0x1F3D7C));
deviceState.setOpaque(true);
layoutBehavior.gridx = 0;
layoutBehavior.gridy = 1;
layoutBehavior.gridwidth = GridBagConstraints.REMAINDER;
layoutBehavior.fill = GridBagConstraints.CENTER;
layoutManager.setConstraints(deviceState, layoutBehavior);
add(deviceState);
layoutBehavior.insets = new Insets(10, 20, 20, 20);
autoOn.setPreferredSize(buttonSize);
layoutBehavior.gridx = 0;
layoutBehavior.gridy = 2;
layoutBehavior.gridwidth = 1;
layoutBehavior.fill = GridBagConstraints.BOTH;
layoutManager.setConstraints(autoOn, layoutBehavior);
add(autoOn);
layoutBehavior.insets = new Insets(0, 0, 20, 20);
manualOff.setPreferredSize(buttonSize);
layoutBehavior.gridx = 2;
layoutBehavior.gridy = 3;
layoutBehavior.gridwidth = 1;
layoutBehavior.fill = GridBagConstraints.BOTH;
layoutManager.setConstraints(manualOff, layoutBehavior);
add(manualOff);
layoutBehavior.insets = new Insets(10, 0, 20, 20);
manualOn.setPreferredSize(buttonSize);
layoutBehavior.gridx = 2;
layoutBehavior.gridy = 2;
layoutBehavior.gridwidth = 1;
layoutBehavior.fill = GridBagConstraints.BOTH;
layoutManager.setConstraints(manualOn, layoutBehavior);
add(manualOn);
}