use of java.awt.Panel in project GDSC-SMLM by aherbert.
the class SpotAnalysis method createChoicePanel.
private static Panel createChoicePanel(Choice list, String label) {
final Panel panel = new Panel();
panel.setLayout(new BorderLayout());
final Label listLabel = new Label(label, 0);
panel.add(listLabel, BorderLayout.WEST);
panel.add(list, BorderLayout.CENTER);
return panel;
}
use of java.awt.Panel in project GDSC-SMLM by aherbert.
the class SpotAnalysis method createLabelPanel.
private static Panel createLabelPanel(Label field, String label, String value) {
final Panel panel = new Panel();
panel.setLayout(new BorderLayout());
final Label listLabel = new Label(label, 0);
field.setText(value);
panel.add(listLabel, BorderLayout.WEST);
panel.add(field, BorderLayout.CENTER);
return panel;
}
use of java.awt.Panel in project GDSC-SMLM by aherbert.
the class SmlmTools method createFrame.
private boolean createFrame() {
final ArrayList<String[]> configPlugins = new ArrayList<>();
// Locate all the GDSC SMLM plugins using the plugins.config:
try (InputStream readmeStream = getToolsPluginsConfig()) {
// Read into memory
int gaps = 0;
try (BufferedReader input = new BufferedReader(new UnicodeReader(readmeStream, null))) {
String line;
while ((line = input.readLine()) != null) {
if (line.startsWith("#")) {
continue;
}
final String[] tokens = line.split(",");
if (tokens.length == 3) {
// Only copy the entries from the Plugins menu
if (!ignore(tokens)) {
if (!configPlugins.isEmpty() && // Multiple gaps indicates a new column
gaps > 1) {
configPlugins.add(new String[] { "next", "" });
}
gaps = 0;
configPlugins.add(new String[] { tokens[1].trim(), tokens[2].trim() });
}
} else {
gaps++;
}
// Put a spacer between plugins if specified
if ((tokens.length == 2 && tokens[0].startsWith("Plugins") && tokens[1].trim().equals("\"-\"")) || line.length() == 0) {
configPlugins.add(new String[] { "spacer", "" });
}
}
}
} catch (final IOException ex) {
// Ignore
}
if (configPlugins.isEmpty()) {
return false;
}
// Put a spacer on the menu
ij.Menus.installPlugin("", ij.Menus.PLUGINS_MENU, "-", "", IJ.getInstance());
// Arrange on a grid.
final Panel mainPanel = new Panel();
final GridBagLayout grid = new GridBagLayout();
mainPanel.setLayout(grid);
addSpacer = false;
int col = 0;
int row = 0;
for (final String[] plugin : configPlugins) {
if (plugin[0].equals("next")) {
col++;
row = 0;
} else if (plugin[0].equals("spacer")) {
addSpacer = true;
} else {
row = addPlugin(mainPanel, grid, plugin[0], plugin[1], col, row);
}
}
// Allow scrollbars to handle small screens.
// Appropriately size the scrollpane from the default of 100x100.
// The preferred size is only obtained if the panel is packed.
add(mainPanel);
pack();
final Dimension d = mainPanel.getPreferredSize();
// Assume this is the only component
remove(0);
final ScrollPane scroll = new ScrollPane();
scroll.getHAdjustable().setUnitIncrement(16);
scroll.getVAdjustable().setUnitIncrement(16);
scroll.add(mainPanel);
add(scroll, BorderLayout.CENTER);
// Scale to the screen size
d.width = Math.min(d.width, screenDimension.width - 100);
d.height = Math.min(d.height, screenDimension.height - 150);
final Insets insets = scroll.getInsets();
d.width += insets.left + insets.right;
d.height += insets.top + insets.bottom;
if (IJ.isMacintosh()) {
// This is needed as the OSX scroll pane adds scrollbars when the panel
// is close in size to the scroll pane
final int padding = 15;
d.width += padding;
d.height += padding;
}
scroll.setPreferredSize(d);
scroll.setSize(d);
return true;
}
use of java.awt.Panel in project GDSC-SMLM by aherbert.
the class SmlmTools method addPlugin.
@SuppressWarnings("unused")
private int addPlugin(Panel mainPanel, GridBagLayout grid, String commandName, final String command, int col, int row) {
// Disect the ImageJ plugins.config string, e.g.:
// Plugins>GDSC SMLM, "Peak Fit", uk.ac.sussex.gdsc.smlm.ij.plugins.PeakFit
commandName = commandName.replaceAll("\"", "");
final Button button = new Button(commandName);
String className = command;
String arg = "";
final int index = command.indexOf('(');
if (index > 0) {
className = command.substring(0, index);
final int argStart = command.indexOf('"');
if (argStart > 0) {
final int argEnd = command.lastIndexOf('"');
arg = command.substring(argStart + 1, argEnd);
}
}
// Add to Plugins menu so that the macros/toolset will work
if (!ij.Menus.commandInUse(commandName)) {
if (addSpacer) {
try {
ij.Menus.getImageJMenu("Plugins").addSeparator();
} catch (final NoSuchMethodError ex) {
// Ignore. This ImageJ method is from IJ 1.48+
}
}
ij.Menus.installPlugin(command, ij.Menus.PLUGINS_MENU, commandName, "", IJ.getInstance());
}
// Store the command to be invoked when the button is clicked
plugins.put(commandName, new String[] { className, arg });
button.addActionListener(event -> {
// Get the plugin from the button label and run it
final Button source = (Button) event.getSource();
final String label = source.getLabel();
// Use the IJ executer to run in a background thread
new Executer(label, null);
});
if (addSpacer) {
addSpacer = false;
if (row != 0) {
row = add(mainPanel, grid, new Panel(), col, row);
}
}
row = add(mainPanel, grid, button, col, row);
return row;
}
use of java.awt.Panel in project GDSC-SMLM by aherbert.
the class SpotAnalysis method createTextPanel.
private Panel createTextPanel(TextField textField, String label, String value) {
Panel panel = new Panel();
panel.setLayout(new BorderLayout());
Label listLabel = new Label(label, 0);
//listLabel.setFont(monoFont);
//textField.setSize(fontWidth * 3, fontWidth);
textField.setText(value);
panel.add(listLabel, BorderLayout.WEST);
panel.add(textField, BorderLayout.CENTER);
return panel;
}
Aggregations