Search in sources :

Example 11 with AstroImageJ

use of ij.astro.AstroImageJ in project astroimagej by keastrid.

the class Opener method openUsingImageIO.

@AstroImageJ(reason = "Open pngs in zip as folder", modified = true)
ImagePlus openUsingImageIO(String path) {
    ImagePlus imp = null;
    BufferedImage img = null;
    File f = new File(path);
    try {
        img = getImageFromPath(path);
    } catch (Exception e) {
        IJ.error("Open Using ImageIO", "" + e);
    }
    if (img == null)
        return null;
    if (img.getColorModel().hasAlpha()) {
        int width = img.getWidth();
        int height = img.getHeight();
        BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        Graphics g = bi.getGraphics();
        g.setColor(Color.white);
        g.fillRect(0, 0, width, height);
        g.drawImage(img, 0, 0, null);
        img = bi;
    }
    imp = new ImagePlus(f.getName(), img);
    FileInfo fi = new FileInfo();
    fi.fileFormat = fi.IMAGEIO;
    fi.fileName = f.getName();
    String parent = f.getParent();
    if (parent != null)
        fi.directory = parent + File.separator;
    imp.setFileInfo(fi);
    return imp;
}
Also used : ZipFile(java.util.zip.ZipFile) BufferedImage(java.awt.image.BufferedImage) MalformedURLException(java.net.MalformedURLException) AstroImageJ(ij.astro.AstroImageJ)

Example 12 with AstroImageJ

use of ij.astro.AstroImageJ in project astroimagej by keastrid.

the class TextPanel method select.

@AstroImageJ(reason = "Add opening of astro windows", modified = true)
void select(int x, int y) {
    Dimension d = tc.getSize();
    if (iRowHeight == 0 || x > d.width || y > d.height)
        return;
    int r = (y / iRowHeight) - 1 + iFirstRow;
    int lineWidth = iGridWidth;
    if (iColCount == 1 && tc.fMetrics != null && r >= 0 && r < iRowCount) {
        char[] chars = (char[]) vData.elementAt(r);
        lineWidth = Math.max(tc.fMetrics.charsWidth(chars, 0, chars.length), iGridWidth);
    }
    if (r >= 0 && r < iRowCount && x < lineWidth) {
        selOrigin = r;
        selStart = r;
        selEnd = r;
    } else {
        resetSelection();
        selOrigin = r;
        if (r >= iRowCount)
            selOrigin = iRowCount - 1;
    }
    tc.repaint();
    selLine = r;
    IJ.runPlugIn("Astronomy.UpdateAstroWindows", "");
    Interpreter interp = Interpreter.getInstance();
    if (interp != null && title.equals("Debug"))
        interp.showArrayInspector(r);
}
Also used : Interpreter(ij.macro.Interpreter) AstroImageJ(ij.astro.AstroImageJ)

Example 13 with AstroImageJ

use of ij.astro.AstroImageJ in project astroimagej by keastrid.

the class ImageJ method setIcon.

@AstroImageJ(reason = "Use astronomy icon instead of microscope", modified = true)
void setIcon() throws Exception {
    URL url = this.getClass().getClassLoader().getResource("astronomy_icon.png");
    if (url == null)
        return;
    Image img = createImage((ImageProducer) url.getContent());
    if (img != null)
        setIconImage(img);
}
Also used : URL(java.net.URL) AstroImageJ(ij.astro.AstroImageJ)

Example 14 with AstroImageJ

use of ij.astro.AstroImageJ in project astroimagej by keastrid.

the class Prefs method savePreferences.

/**
 * Saves user preferences in the IJ_Prefs.txt properties file.
 */
@AstroImageJ(reason = "Rename for AIJ", modified = true)
public static void savePreferences() {
    String path = null;
    commandLineMacro = false;
    try {
        Properties prefs = new Properties();
        String dir = OpenDialog.getDefaultDirectory();
        if (dir != null)
            prefs.put(DIR_IMAGE, dir);
        prefs.put(ROICOLOR, Tools.c2hex(Roi.getColor()));
        prefs.put(SHOW_ALL_COLOR, Tools.c2hex(ImageCanvas.getShowAllColor()));
        prefs.put(FCOLOR, Tools.c2hex(Toolbar.getForegroundColor()));
        prefs.put(BCOLOR, Tools.c2hex(Toolbar.getBackgroundColor()));
        prefs.put(JPEG, Integer.toString(FileSaver.getJpegQuality()));
        prefs.put(FPS, Double.toString(Animator.getFrameRate()));
        prefs.put(DIV_BY_ZERO_VALUE, Double.toString(FloatBlitter.divideByZeroValue));
        prefs.put(NOISE_SD, Double.toString(Filters.getSD()));
        if (threads > 1)
            prefs.put(THREADS, Integer.toString(threads));
        if (IJ.isMacOSX())
            useJFileChooser = false;
        if (!IJ.isLinux())
            dialogCancelButtonOnRight = false;
        saveOptions(prefs);
        savePluginPrefs(prefs);
        ImageJ ij = IJ.getInstance();
        if (ij != null)
            ij.savePreferences(prefs);
        Menus.savePreferences(prefs);
        ParticleAnalyzer.savePreferences(prefs);
        Analyzer.savePreferences(prefs);
        ImportDialog.savePreferences(prefs);
        PlotWindow.savePreferences(prefs);
        NewImage.savePreferences(prefs);
        String prefsDir = getPrefsDir();
        path = prefsDir + separator + PREFS_NAME;
        if (prefsDir.endsWith(".astroimagej")) {
            File f = new File(prefsDir);
            // create .imagej directory
            if (!f.exists())
                f.mkdir();
        }
        if (resetPreferences) {
            File f = new File(path);
            if (!f.exists())
                IJ.error("Edit>Options>Reset", "Unable to reset preferences. File not found at\n" + path);
            boolean rtn = f.delete();
            resetPreferences = false;
        } else
            savePrefs(prefs, path);
    } catch (Throwable t) {
        String msg = t.getMessage();
        if (msg == null)
            msg = "" + t;
        int delay = 4000;
        try {
            new TextWindow("Error Saving Preferences:\n" + path, msg, 500, 200);
            IJ.wait(delay);
        } catch (Throwable t2) {
        }
    }
}
Also used : AstroImageJ(ij.astro.AstroImageJ) TextWindow(ij.text.TextWindow) AstroImageJ(ij.astro.AstroImageJ)

Example 15 with AstroImageJ

use of ij.astro.AstroImageJ in project astroimagej by keastrid.

the class PlotWindow method actionPerformed.

/**
 * Called if user has activated a button or popup menu item
 */
@AstroImageJ(reason = "Handle saving of various AIJ data", modified = true)
public void actionPerformed(ActionEvent e) {
    try {
        Object b = e.getSource();
        if (b == live)
            toggleLiveProfiling();
        else if (b == list) {
            String fileName = getTitle().replace("Plot of ", "").replace("Measurements in ", "");
            SaveDialog sf = new SaveDialog("Save plot as vector PDF", fileName, ".pdf");
            if (sf.getDirectory() == null || sf.getFileName() == null)
                return;
            PdfPlotOutput.savePlot(imp.getPlot(), sf.getDirectory() + sf.getFileName());
        // showList(/*useLabels=*/true);
        } else if (b == data) {
            // enableDisableMenuItems();
            // dataPopupMenu.show((Component)b, 1, 1);
            String fileName = getTitle().replace("Plot of ", "").replace("Measurements in ", "");
            SaveDialog sf = new SaveDialog("Save plot as PNG", fileName, ".png");
            if (sf.getDirectory() == null || sf.getFileName() == null)
                return;
            IJ.runPlugIn(imp, "ij.plugin.PNG_Writer", sf.getDirectory() + sf.getFileName());
        } else if (b == more) {
            enableDisableMenuItems();
            morePopupMenu.show((Component) b, 1, 1);
        } else if (b == menuItems[SAVE]) {
            String fileName = getTitle().replace("Plot of ", "").replace("Measurements in ", "");
            SaveDialog sf = new SaveDialog("Save plot as PNG", fileName, ".png");
            if (sf.getDirectory() == null || sf.getFileName() == null)
                return;
            IJ.runPlugIn(imp, "ij.plugin.PNG_Writer", sf.getDirectory() + sf.getFileName());
        } else if (b == copy) {
            if (getTitle().startsWith("Seeing Profile")) {
                Prefs.set("aperture.radius", Prefs.get("seeingprofile.radius", 20));
                Prefs.set("aperture.rback1", Prefs.get("seeingprofile.rback1", 30));
                Prefs.set("aperture.rback2", Prefs.get("seeingprofile.rback2", 40));
                Prefs.set("setaperture.aperturechanged", true);
            } else {
                copyToClipboard(false);
            }
        } else if (b == menuItems[COPY])
            copyToClipboard(false);
        else if (b == menuItems[COPY_ALL])
            copyToClipboard(true);
        else if (b == menuItems[LIST_SIMPLE])
            showList(/*useLabels=*/
            false);
        else if (b == menuItems[ADD_FROM_TABLE])
            new PlotContentsDialog(plot, PlotContentsDialog.ADD_FROM_TABLE).showDialog(this);
        else if (b == menuItems[ADD_FROM_PLOT])
            new PlotContentsDialog(plot, PlotContentsDialog.ADD_FROM_PLOT).showDialog(this);
        else if (b == menuItems[ADD_FIT])
            new PlotContentsDialog(plot, PlotContentsDialog.ADD_FIT).showDialog(this);
        else if (b == menuItems[ZOOM_SELECTION]) {
            if (imp != null && imp.getRoi() != null && imp.getRoi().isArea())
                plot.zoomToRect(imp.getRoi().getBounds());
        } else if (b == menuItems[SET_RANGE])
            new PlotDialog(plot, PlotDialog.SET_RANGE).showDialog(this);
        else if (b == menuItems[PREV_RANGE])
            plot.setPreviousMinMax();
        else if (b == menuItems[RESET_RANGE])
            plot.setLimitsToDefaults(true);
        else if (b == menuItems[FIT_RANGE])
            plot.setLimitsToFit(true);
        else if (b == menuItems[AXIS_OPTIONS])
            new PlotDialog(plot, PlotDialog.AXIS_OPTIONS).showDialog(this);
        else if (b == menuItems[LEGEND])
            new PlotDialog(plot, PlotDialog.LEGEND).showDialog(this);
        else if (b == menuItems[STYLE])
            new PlotContentsDialog(plot, PlotContentsDialog.STYLE).showDialog(this);
        else if (b == menuItems[TEMPLATE])
            new PlotDialog(plot, PlotDialog.TEMPLATE).showDialog(this);
        else if (b == menuItems[RESET_PLOT]) {
            plot.setFont(Font.PLAIN, fontSize);
            plot.setAxisLabelFont(Font.PLAIN, fontSize);
            plot.setFormatFlags(Plot.getDefaultFlags());
            // updates the image only when size changed
            plot.setFrameSize(plotWidth, plotHeight);
            plot.updateImage();
        } else if (b == menuItems[HI_RESOLUTION])
            new PlotDialog(plot, PlotDialog.HI_RESOLUTION).showDialog(this);
        else if (b == menuItems[PROFILE_PLOT_OPTIONS])
            IJ.doCommand("Plots...");
        // have focus on the canvas, not the button, so that pressing the space bar allows panning
        ic.requestFocus();
    } catch (Exception ex) {
        IJ.handleException(ex);
    }
}
Also used : SaveDialog(ij.io.SaveDialog) IOException(java.io.IOException) AstroImageJ(ij.astro.AstroImageJ)

Aggregations

AstroImageJ (ij.astro.AstroImageJ)28 File (java.io.File)4 ZipFile (java.util.zip.ZipFile)4 SaveDialog (ij.io.SaveDialog)3 ResultsTable (ij.measure.ResultsTable)3 ImageProcessor (ij.process.ImageProcessor)3 URL (java.net.URL)3 GenericDialog (ij.gui.GenericDialog)2 Opener (ij.io.Opener)2 TextWindow (ij.text.TextWindow)2 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 ZipInputStream (java.util.zip.ZipInputStream)2 ZipOpenerUtil (ij.astro.util.ZipOpenerUtil)1 ImageWindow (ij.gui.ImageWindow)1 Overlay (ij.gui.Overlay)1 Roi (ij.gui.Roi)1 FileInfo (ij.io.FileInfo)1