Search in sources :

Example 26 with AstroImageJ

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

the class TextPanel method duplicate.

@AstroImageJ(reason = "Add check for AIJ windows", modified = true)
void duplicate() {
    ResultsTable rt2 = getOrCreateResultsTable();
    if (rt2 == null)
        return;
    rt2 = (ResultsTable) rt2.clone();
    String title2 = IJ.getString("Title:", ((TextWindow) (getParent())).getTitle() + "_2");
    if (!title2.equals("")) {
        if (title2.equals("Measurements"))
            title2 = "Measurements in Measurements2";
        rt2.show(title2);
    }
}
Also used : ResultsTable(ij.measure.ResultsTable) AstroImageJ(ij.astro.AstroImageJ)

Example 27 with AstroImageJ

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

the class TextPanel method saveAs.

/**
 * Saves the text in this TextPanel to a file. Set 'path' to "" to
 * display a "save as" dialog. Returns 'false' if the user cancels
 * the dialog.
 */
@AstroImageJ(reason = "Add check for AIJ window; Save table with 16 decimal places, not 6", modified = true)
public boolean saveAs(String path) {
    boolean isResults = IJ.isResultsWindow() && IJ.getTextPanel() == this;
    boolean summarized = false;
    if (isResults) {
        String lastLine = iRowCount >= 2 ? getLine(iRowCount - 2) : null;
        summarized = lastLine != null && lastLine.startsWith("Max");
    }
    String fileName = null;
    if (rt != null && rt.size() > 0 && !summarized) {
        if (path == null || path.equals("")) {
            IJ.wait(10);
            String name = isResults ? "Results" : title.replace("Measurements in ", "");
            SaveDialog sd = new SaveDialog("Save Table", name, Prefs.defaultResultsExtension());
            fileName = sd.getFileName();
            if (fileName == null)
                return false;
            path = sd.getDirectory() + fileName;
        }
        var oldPrecision = rt.getPrecision();
        rt.setPrecision(16);
        rt.saveAndRename(path);
        rt.setPrecision(oldPrecision);
        TextWindow tw = getTextWindow();
        String title2 = rt.getTitle();
        if (tw != null && !"Results".equals(title)) {
            tw.setTitle(title2);
            Menus.updateWindowMenuItem(title, title2);
            title = title2;
        }
    } else {
        if (path.equals("")) {
            IJ.wait(10);
            boolean hasHeadings = !getColumnHeadings().equals("");
            String ext = isResults || hasHeadings ? Prefs.defaultResultsExtension() : ".txt";
            SaveDialog sd = new SaveDialog("Save as Text", title, ext);
            String file = sd.getFileName();
            if (file == null)
                return false;
            path = sd.getDirectory() + file;
        }
        PrintWriter pw = null;
        try {
            FileOutputStream fos = new FileOutputStream(path);
            BufferedOutputStream bos = new BufferedOutputStream(fos);
            pw = new PrintWriter(bos);
        } catch (IOException e) {
            IJ.error("Save As>Text", e.getMessage());
            return true;
        }
        saveAsCSV = path.endsWith(".csv");
        save(pw);
        saveAsCSV = false;
        pw.close();
    }
    if (isResults) {
        Analyzer.setUnsavedMeasurements(false);
        if (Recorder.record && !IJ.isMacro())
            Recorder.record("saveAs", "Results", path);
    } else if (rt != null) {
        if (Recorder.record && !IJ.isMacro())
            Recorder.record("saveAs", "Results", path);
    } else {
        if (Recorder.record && !IJ.isMacro())
            Recorder.record("saveAs", "Text", path);
    }
    IJ.showStatus("");
    return true;
}
Also used : SaveDialog(ij.io.SaveDialog) AstroImageJ(ij.astro.AstroImageJ)

Example 28 with AstroImageJ

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

the class TextWindow method create.

@AstroImageJ(reason = "Add check for AIJ windows", modified = true)
private void create(String title, TextPanel textPanel, int width, int height) {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    if (IJ.isLinux())
        setBackground(ImageJ.backgroundColor);
    add("Center", textPanel);
    addKeyListener(textPanel);
    ImageJ ij = IJ.getInstance();
    if (ij != null) {
        textPanel.addKeyListener(ij);
        if (!IJ.isMacOSX()) {
            Image img = ij.getIconImage();
            if (img != null)
                try {
                    setIconImage(img);
                } catch (Exception e) {
                }
        }
    }
    addFocusListener(this);
    addMenuBar();
    setFont();
    WindowManager.addWindow(this);
    Point loc = null;
    int w = 0, h = 0;
    if (title.contains("Results") || title.contains("Measure")) {
        loc = Prefs.getLocation(LOC_KEY);
        w = (int) Prefs.get(WIDTH_KEY, 0.0);
        h = (int) Prefs.get(HEIGHT_KEY, 0.0);
    } else if (title.equals("Log")) {
        loc = Prefs.getLocation(LOG_LOC_KEY);
        w = (int) Prefs.get(LOG_WIDTH_KEY, 0.0);
        h = (int) Prefs.get(LOG_HEIGHT_KEY, 0.0);
    } else if (title.equals("Debug")) {
        loc = Prefs.getLocation(DEBUG_LOC_KEY);
        w = width;
        h = height;
    }
    if (loc != null && w > 0 && h > 0) {
        setSize(w, h);
        setLocation(loc);
    } else {
        setSize(width, height);
        if (!IJ.debugMode)
            GUI.centerOnImageJScreen(this);
    }
    show();
    WindowManager.setWindow(this);
}
Also used : AstroImageJ(ij.astro.AstroImageJ) 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