ij.gui.DialogListener Java Examples
The following examples show how to use
ij.gui.DialogListener.
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: Define_Multi_View_Dataset.java From SPIM_Registration with GNU General Public License v2.0 | 6 votes |
protected void addListeners( final GenericDialog gd, final Choice choice, final MyMultiLineLabel label, final ArrayList< MultiViewDatasetDefinition > datasetDefinitions ) { gd.addDialogListener( new DialogListener() { @Override public boolean dialogItemChanged( final GenericDialog dialog, final AWTEvent e ) { if ( e instanceof ItemEvent && e.getID() == ItemEvent.ITEM_STATE_CHANGED && e.getSource() == choice ) { label.setText( formatEntry( datasetDefinitions.get( choice.getSelectedIndex() ).getExtendedDescription(), numCharacters, numLinesDocumentation ) ); } return true; } } ); }
Example #2
Source File: InteractivePlotter.java From Scripts with GNU General Public License v3.0 | 4 votes |
private void setPlotOptions() { if (plot == null) return; final int DEF_LINE_WIDTH = 1; final int DEF_MAX_INTERVALS = 12; final int DEF_TICK_LENGTH = 7; final int DEF_MINOR_TICK_LENGTH = 3; final int[] NUM_DEFAULTS = { DEF_LINE_WIDTH, DEF_MAX_INTERVALS, DEF_TICK_LENGTH, DEF_MINOR_TICK_LENGTH }; final String DEF_BACKGROUND_COLOR = "white"; final String title = plot.getTitle(); final GenericDialog ogd = new GenericDialog("Options for " + title); ogd.setInsets(0, 10, 10); ogd.addMessage("This prompt allows you access customizations that\n" + "are not accessible through the plot's \"More \u00bb\" menu"); if (!pwClosed) ogd.addStringField("Plot title:", title, 27); ogd.addSlider("Line width:", 1, 20, 1); ogd.addSlider("Max. n. of intervals:", 1, 40, 12); ogd.addSlider("Major ticks length:", 1, 14, 7); ogd.addSlider("Minor ticks length:", 1, 14, 3); ogd.addChoice("Backgrond color:", Colors.colors, DEF_BACKGROUND_COLOR); final Panel buttonPanel = new Panel(); final Button fontButton = new Button(" Text & Font... "); fontButton.addActionListener(ogd); buttonPanel.add(fontButton); final Button templateButton = new Button("Apply Template..."); templateButton.addActionListener(ogd); buttonPanel.add(templateButton); ogd.addPanel(buttonPanel, GridBagConstraints.EAST, new Insets(0, 0, 0, 0)); ogd.hideCancelButton(); ogd.addHelp(""); ogd.setHelpLabel("Apply Defaults"); ogd.addDialogListener(new DialogListener() { @Override public boolean dialogItemChanged(final GenericDialog gd, final AWTEvent e) { if (e != null && e.toString().contains("Apply Defaults")) { @SuppressWarnings("unchecked") final Vector<TextField> nFields = gd.getNumericFields(); for (final TextField field : nFields) field.setText(Integer.toString(NUM_DEFAULTS[nFields.indexOf(field)])); @SuppressWarnings("unchecked") final Vector<Choice> nChoices = gd.getChoices(); nChoices.firstElement().select(DEF_BACKGROUND_COLOR); } else if (e != null && e.toString().contains("Font")) { setPlotFont(); return true; } else if (e != null && e.toString().contains("Template")) { setTemplate(); return true; } plot.setLineWidth((int) ogd.getNextNumber()); plot.setMaxIntervals((int) ogd.getNextNumber()); plot.setTickLength((int) ogd.getNextNumber()); plot.setBackgroundColor(Colors.colors[ogd.getNextChoiceIndex()]); plot.updateImage(); return true; } }); showAsSubDialog(ogd); if (!ogd.wasOKed()) return; if (!pwClosed) plot.getImagePlus().setTitle(WindowManager.makeUniqueName(ogd.getNextString())); }
Example #3
Source File: InteractivePlotter.java From Scripts with GNU General Public License v3.0 | 4 votes |
private void setPlotFont() { if (plot == null) return; final String[] FONTS = new String[] { Font.SANS_SERIF, Font.MONOSPACED, Font.SERIF }; final String[] STYLES = { "Plain", "Bold", "Italic", "Bold+Italic" }; final String[] JUSTIFICATIONS = { "Left", "Center", "Right" }; final String[] SCOPES = { "Plot", "Both Axes Titles", "X-axis Title", "Y-axis Title" }; final String[] CHOICE_DEFAULTS = { FONTS[0], STYLES[0], JUSTIFICATIONS[0], SCOPES[0] }; final int[] INT_STYLES = { Font.PLAIN, Font.BOLD, Font.ITALIC, Font.BOLD + Font.ITALIC }; final int[] INT_JUSTIFICATIONS = { Plot.LEFT, Plot.CENTER, Plot.RIGHT }; final int DEF_SIZE = 12; final boolean DEF_ANTIALISED = true; final GenericDialog fgd = new GenericDialog("Font Options"); fgd.addChoice("Type:", FONTS, CHOICE_DEFAULTS[0]); fgd.addChoice("Style:", STYLES, CHOICE_DEFAULTS[1]); fgd.addChoice("Justification:", JUSTIFICATIONS, CHOICE_DEFAULTS[2]); fgd.addSlider("Size:", 9, 24, DEF_SIZE); fgd.setInsets(0, 20, 15); fgd.addCheckbox("Antialiased text", DEF_ANTIALISED); fgd.addChoice("Apply to:", SCOPES, CHOICE_DEFAULTS[3]); fgd.hideCancelButton(); fgd.addHelp(""); fgd.setHelpLabel("Apply Defaults"); fgd.addDialogListener(new DialogListener() { @Override public boolean dialogItemChanged(final GenericDialog gd, final AWTEvent e) { if (e != null && e.toString().contains("Apply Defaults")) { @SuppressWarnings("unchecked") final Vector<Choice> nChoices = gd.getChoices(); for (final Choice choice : nChoices) choice.select(CHOICE_DEFAULTS[nChoices.indexOf(choice)]); ((TextField) gd.getNumericFields().get(0)).setText(Integer.toString(DEF_SIZE)); ((Checkbox) gd.getCheckboxes().get(0)).setState(DEF_ANTIALISED); } final String type = FONTS[fgd.getNextChoiceIndex()]; final int style = INT_STYLES[fgd.getNextChoiceIndex()]; final int justification = INT_JUSTIFICATIONS[fgd.getNextChoiceIndex()]; final int size = (int) fgd.getNextNumber(); final int scopeIdx = fgd.getNextChoiceIndex(); plot.setJustification(justification); plot.setAntialiasedText(fgd.getNextBoolean()); final Font font = new Font(type, style, size); switch (scopeIdx) { case 1: // SCOPES[1] plot.setXLabelFont(font); plot.setYLabelFont(font); break; case 2: // SCOPES[2] plot.setXLabelFont(font); break; case 3: // SCOPES[3] plot.setYLabelFont(font); break; default: plot.setFont(font); plot.setXLabelFont(font); plot.setYLabelFont(font); break; } plot.updateImage(); return true; } }); showAsSubDialog(fgd); if (!fgd.wasOKed()) return; }