Java Code Examples for javax.swing.AbstractButton#doClick()

The following examples show how to use javax.swing.AbstractButton#doClick() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UI.java    From Girinoscope with Apache License 2.0 7 votes vote down vote up
private JMenu createSerialMenu() {
    JMenu menu = new JMenu("Serial port");
    ButtonGroup group = new ButtonGroup();
    for (final SerialPort newPort : Serial.enumeratePorts()) {
        Action setSerialPort = new AbstractAction(newPort.getSystemPortName()) {

            @Override
            public void actionPerformed(ActionEvent event) {
                port = newPort;
            }
        };
        AbstractButton button = new JCheckBoxMenuItem(setSerialPort);
        if (port == null) {
            button.doClick();
        }
        group.add(button);
        menu.add(button);
    }
    return menu;
}
 
Example 2
Source File: UI.java    From Girinoscope with Apache License 2.0 6 votes vote down vote up
private JMenu createTriggerEventMenu() {
    JMenu menu = new JMenu("Trigger event mode");
    ButtonGroup group = new ButtonGroup();
    for (final TriggerEventMode mode : TriggerEventMode.values()) {
        Action setPrescaler = new AbstractAction(mode.description) {

            @Override
            public void actionPerformed(ActionEvent event) {
                synchronized (UI.this) {
                    parameters.put(Parameter.TRIGGER_EVENT, mode.value);
                }
            }
        };
        AbstractButton button = new JCheckBoxMenuItem(setPrescaler);
        if (mode.value == parameters.get(Parameter.TRIGGER_EVENT)) {
            button.doClick();
        }
        group.add(button);
        menu.add(button);
    }
    return menu;
}
 
Example 3
Source File: UI.java    From Girinoscope with Apache License 2.0 6 votes vote down vote up
private JMenu createVoltageReferenceMenu() {
    JMenu menu = new JMenu("Voltage reference");
    ButtonGroup group = new ButtonGroup();
    for (final VoltageReference reference : VoltageReference.values()) {
        Action setPrescaler = new AbstractAction(reference.description) {

            @Override
            public void actionPerformed(ActionEvent event) {
                synchronized (UI.this) {
                    parameters.put(Parameter.VOLTAGE_REFERENCE, reference.value);
                }
            }
        };
        AbstractButton button = new JCheckBoxMenuItem(setPrescaler);
        if (reference.value == parameters.get(Parameter.VOLTAGE_REFERENCE)) {
            button.doClick();
        }
        group.add(button);
        menu.add(button);
    }
    return menu;
}
 
Example 4
Source File: UI.java    From Girinoscope with Apache License 2.0 6 votes vote down vote up
private JMenu createDataStrokeWidthMenu() {
    JMenu menu = new JMenu("Data stroke width");
    ButtonGroup group = new ButtonGroup();
    for (final int width : new int[]{1, 2, 3}) {
        Action setStrokeWidth = new AbstractAction(width + " px") {

            @Override
            public void actionPerformed(ActionEvent event) {
                graphPane.setDataStrokeWidth(width);
            }
        };
        AbstractButton button = new JCheckBoxMenuItem(setStrokeWidth);
        if (width == 1) {
            button.doClick();
        }
        group.add(button);
        menu.add(button);
    }
    return menu;
}
 
Example 5
Source File: DoubleClickListener.java    From pumpernickel with MIT License 5 votes vote down vote up
/**
 * When a double-click is observed a button is clicked.
 * 
 * @param button
 *            when a double-click is observed this button's
 *            <code>doClick()</code> method is invoked if it is enabled.
 */
public DoubleClickListener(final AbstractButton button) {
	this(new Runnable() {
		public void run() {
			if (button.isEnabled())
				button.doClick();
		}
	});
	if (button == null)
		throw new NullPointerException();
}
 
Example 6
Source File: UI.java    From Girinoscope with Apache License 2.0 5 votes vote down vote up
private JMenu createPrescalerMenu(Device potentialDevice) {
    JMenu menu = new JMenu("Acquisition rate / Time frame");
    ButtonGroup group = new ButtonGroup();
    for (final PrescalerInfo info : potentialDevice.getPrescalerInfoValues()) {
        Action setPrescaler = new AbstractAction(format(info)) {

            @Override
            public void actionPerformed(ActionEvent event) {
                synchronized (UI.this) {
                    parameters.put(Parameter.PRESCALER, info.value);
                }
                String xFormat = info.timeframe > 0.005 ? "#,##0 ms" : "#,##0.0 ms";
                Axis xAxis = new Axis(0, info.timeframe * 1000, xFormat);
                graphPane.setXCoordinateSystem(xAxis);
            }
        };
        AbstractButton button = new JCheckBoxMenuItem(setPrescaler);
        if (info.reallyTooFast) {
            button.setForeground(Color.RED.darker());
        } else if (info.tooFast) {
            button.setForeground(Color.ORANGE.darker());
        }
        if (info.value == parameters.get(Parameter.PRESCALER)) {
            button.doClick();
        }
        group.add(button);
        menu.add(button);
    }
    return menu;
}
 
Example 7
Source File: ImprovedFileChooser.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public ImprovedFileChooser(File currentDirectory, FileSystemView fsv) {
  super(currentDirectory, fsv);

  AbstractButton detailsViewButton = getDetailsViewButton(this);
  if (detailsViewButton == null) {
    // mac osx does not have a details button. It is recommended to use
    // a java.awt.FileDialog box on MacOSX for the proper look and feel.
    // so, don't warn if on a mac.
    // https://developer.apple.com/library/mac/documentation/Java/Conceptual/Java14Development/07-NativePlatformIntegration/NativePlatformIntegration.html
    if (!isMacOs) {
      logger.warn("Couldn't find Details button!");
    }
    return;
  }

  detailsViewButton.doClick(); // Programmatically switch to the Details View.

  List<JTable> tables = SwingUtils.getDescendantsOfType(JTable.class, this);
  JTable detailsTable;

  if (tables.size() != 1) {
    logger.warn("Expected to find 1 JTable in the file chooser, but found " + tables.size());
    return;
  } else if ((detailsTable = tables.get(0)) == null) {
    logger.warn("The details view table was null!");
    return;
  }

  // Set the preferred column widths so that they're big enough to display all data without truncation.
  ColumnWidthsResizer resizer = new ColumnWidthsResizer(detailsTable);
  detailsTable.getModel().addTableModelListener(resizer);
  detailsTable.getColumnModel().addColumnModelListener(resizer);

  // Left-align every cell, including header cells.
  TableAligner aligner = new TableAligner(detailsTable, SwingConstants.LEADING);
  detailsTable.getColumnModel().addColumnModelListener(aligner);

  // Every time the directory is changed in a JFileChooser dialog, a new TableColumnModel is created.
  // This is bad, because it discards the alignment decorators that we installed on the old model.
  // So, we 're going to listen for the creation of new TableColumnModels so that we can reinstall the decorators.
  detailsTable.addPropertyChangeListener(new NewColumnModelListener(detailsTable, SwingConstants.LEADING));

  // It's quite likely that the total width of the table is NOT EQUAL to the sum of the preferred column widths
  // that our TableModelListener calculated. In that case, resize all of the columns an equal percentage.
  // This will ensure that the relative ratios of the *actual* widths match those of the *preferred* widths.
  detailsTable.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
}
 
Example 8
Source File: UI.java    From Girinoscope with Apache License 2.0 4 votes vote down vote up
private void createDynamicDeviceMenu(final JMenu girinoMenu) {
    Device selectedDevice = null;
    String deviceName = settings.get("device", null);
    for (final Device otherDevice : Device.DEVICES) {
        if (Objects.equals(deviceName, otherDevice.id)) {
            selectedDevice = otherDevice;
            break;
        }
    }

    final JMenu menu = new JMenu("Device");
    ButtonGroup group = new ButtonGroup();
    for (final Device newDevice : Device.DEVICES) {
        Action setDevice = new AbstractAction(newDevice.description) {

            @Override
            public void actionPerformed(ActionEvent event) {
                synchronized (UI.this) {
                    device = newDevice;
                    parameters = newDevice.getDefaultParameters(new EnumMap<Parameter, Integer>(Parameter.class));
                }
                graphPane.setFrameFormat(device.getFrameFormat());
                graphPane.setThreshold(parameters.get(Parameter.THRESHOLD));
                graphPane.setWaitDuration(parameters.get(Parameter.WAIT_DURATION));

                yAxisBuilder.load(settings, device.id + ".");
                graphPane.setYCoordinateSystem(yAxisBuilder.build());

                girinoMenu.removeAll();
                girinoMenu.add(menu);
                girinoMenu.add(createSerialMenu());
                if (device.isUserConfigurable(Parameter.PRESCALER)) {
                    girinoMenu.add(createPrescalerMenu(device));
                }
                if (device.isUserConfigurable(Parameter.TRIGGER_EVENT)) {
                    girinoMenu.add(createTriggerEventMenu());
                }
                if (device.isUserConfigurable(Parameter.VOLTAGE_REFERENCE)) {
                    girinoMenu.add(createVoltageReferenceMenu());
                }

                settings.put("device", device.id);
            }
        };
        AbstractButton button = new JCheckBoxMenuItem(setDevice);
        if (selectedDevice == null && device == null || newDevice == selectedDevice) {
            button.doClick();
        }

        group.add(button);

        menu.add(button);
    }
}