public void actionPerformed(ActionEvent e) { // Interpreter.abort();//17.9.2010 -checks for null instance etc removed 11.8.2013 Editor ed = OJ.editor; String theText = ed.getText(); theText = UtilsOJ.fixLineFeeds(theText); // 7.9.2010 OJ.getData().setLinkedMacroText(theText); int caretPos = ed.getTextArea().getCaretPosition(); ed.getTextArea().setText(theText); ed.getTextArea().setCaretPosition(caretPos); doInstall(theText); setEditorUnchanged(ed); ij.IJ.getInstance().setVisible(true); }
/** Used by open() and IJ.open() to open text URLs. */ void openTextURL(String url) { if (url.endsWith(".pdf") || url.endsWith(".zip")) return; String text = IJ.openUrlAsString(url); if (text != null && text.startsWith("<Error: ")) { IJ.error("Open Text URL", text); return; } String name = url.substring(7); int index = name.lastIndexOf("/"); int len = name.length(); if (index == len - 1) name = name.substring(0, len - 1); else if (index != -1 && index < len - 1) name = name.substring(index + 1); name = name.replaceAll("%20", " "); Editor ed = new Editor(); ed.setSize(600, 300); ed.create(name, text); IJ.showStatus(""); }
public void run(String arg) { Frame[] niframes = WindowManager.getNonImageWindows(); String[] titles = new String[niframes.length + 1]; for (int i = 0; i < niframes.length; i++) { titles[i] = niframes[i].getTitle(); } titles[niframes.length] = "Clipboard"; GenericDialog gd = new GenericDialog("Windows"); boolean importfile = false; gd.addCheckbox("Import from file?", importfile); gd.addChoice("Windows", titles, titles[0]); boolean hasxvals = false; gd.addCheckbox("X Vals Column?", hasxvals); boolean multix = false; gd.addCheckbox("Multi_X_Columns?", multix); boolean skipendzeros = false; gd.addCheckbox("Skip_end_zeros?", skipendzeros); String[] delimiters = {"Tab", "Comma", "Space"}; gd.addChoice("Delimiter", delimiters, delimiters[0]); gd.showDialog(); if (gd.wasCanceled()) { return; } importfile = gd.getNextBoolean(); int index = gd.getNextChoiceIndex(); hasxvals = gd.getNextBoolean(); multix = gd.getNextBoolean(); skipendzeros = gd.getNextBoolean(); int delimindex = gd.getNextChoiceIndex(); if (multix) hasxvals = true; String textdata = ""; if (importfile) { OpenDialog od = new OpenDialog("Open File", "", ".txt"); String directory = od.getDirectory(); String name = od.getFileName(); if (name == null) { return; } try { File infile = new File(directory + name); BufferedReader b = new BufferedReader(new FileReader(infile)); textdata = (new jdataio()).readstringfile(b); b.close(); } catch (IOException e) { return; } } else { if (index == niframes.length) { // here we get the data from the clipboard Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null); try { if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) { textdata = (String) t.getTransferData(DataFlavor.stringFlavor); } } catch (UnsupportedFlavorException e) { } catch (IOException e) { } if (textdata.equals("")) { IJ.error("Error copying from clipboard."); return; } } else { if (niframes[index] instanceof Editor) { Editor tw = (Editor) niframes[index]; textdata = tw.getText(); } else { if (niframes[index] instanceof TextWindow) { TextWindow tw = (TextWindow) niframes[index]; textdata = tw.getTextPanel().getText(); } else { IJ.showMessage("Not a valid text window"); return; } } } } if (textdata == null) { IJ.showMessage("Error in Obtaining String"); return; } if (textdata.indexOf("\r") >= 0) { textdata = textdata.replace('\r', '\n'); } char[] delims = {'\t', ',', ' '}; delimit_string ds = new delimit_string(delims[delimindex]); String[] rows = ds.getrows(textdata); int lines = rows.length; int columns = ds.getnumcolumns(rows[0]); int ycolumns = columns; if (hasxvals) { if (multix) { ycolumns /= 2; } else { ycolumns--; } } if (multix) { float[][] ydata = new float[ycolumns][lines]; float[][] xdata = new float[ycolumns][lines]; for (int i = 0; i < lines; i++) { float[] temp = ds.delim2float(rows[i], columns); for (int j = 0; j < ycolumns; j++) { ydata[j][i] = temp[2 * j + 1]; xdata[j][i] = temp[2 * j]; } } int[] npts = new int[ycolumns]; for (int i = 0; i < ycolumns; i++) { npts[i] = lines; } if (skipendzeros) { for (int i = 0; i < ycolumns; i++) { int counter = lines - 1; while ((xdata[i][counter] == 0.0f || Float.isNaN(xdata[i][counter])) && counter > 0) { xdata[i][counter] = 0.0f; ydata[i][counter] = 0.0f; npts[i]--; counter--; } } } (new PlotWindow4("Text Plot", "x", "y", xdata, ydata, npts)).draw(); } else { float[][] tempydata = new float[ycolumns][lines]; float[] tempxdata = new float[lines]; float[][] xdata = null; float[][] ydata = null; int startcolumn = 0; if (hasxvals) startcolumn = 1; for (int i = 0; i < lines; i++) { float[] temp = ds.delim2float(rows[i], columns); if (hasxvals) { tempxdata[i] = temp[0]; } else { tempxdata[i] = (float) (i + 1); } for (int j = 0; j < ycolumns; j++) { tempydata[j][i] = temp[j + startcolumn]; } } int[] npts = new int[ycolumns]; npts[0] = lines; if (skipendzeros) { int maxpts = 0; for (int i = 0; i < ycolumns; i++) { int counter = lines - 1; npts[i] = lines; while ((tempydata[i][counter] == 0.0f || Float.isNaN(tempydata[i][counter])) && counter > 0) { npts[i]--; counter--; } if (npts[i] > maxpts) maxpts = npts[i]; IJ.log("" + npts[i]); } ydata = new float[ycolumns][maxpts]; xdata = new float[ycolumns][maxpts]; for (int i = 0; i < ycolumns; i++) { // npts[i]=npts[0]; System.arraycopy(tempxdata, 0, xdata[i], 0, npts[i]); System.arraycopy(tempydata[i], 0, ydata[i], 0, npts[i]); } } else { ydata = tempydata; xdata = new float[ycolumns][]; for (int i = 0; i < ycolumns; i++) { npts[i] = npts[0]; xdata[i] = tempxdata.clone(); } } (new PlotWindow4("Text Plot", "x", "y", xdata, ydata, npts)).draw(); } }
public void showEmbeddedMacros(int modifier) { showPopUp = ((modifier & KeyEvent.ALT_MASK) != 0); String macros_text = OJ.getData().getLinkedMacroText(); if (macros_text == null) { macros_text = ""; } Window theWindow = OJ.editorWindow; if (theWindow != null && theWindow.isShowing() && OJ.editor != null) { theWindow.setVisible(true); return; } String version = IJ.getFullVersion(); Editor ed; if (version.compareToIgnoreCase("1.49i03") >= 0) { ed = new EditorOJ(16, 60, 0, Editor.MONOSPACED + Editor.MENU_BAR); } else { ed = new Editor(16, 60, 0, Editor.MONOSPACED + Editor.MENU_BAR); } ed.create("Embedded Macros", macros_text); JButton loadButton = new JButton("Install in ObjectJ menu"); loadButton.addActionListener(LoadEmbeddedMacroAction); TextArea ta = ed.getTextArea(); ed.remove(ta); ed.setLayout(new BorderLayout()); JPanel panel1 = new JPanel(); panel1.setLayout(new FlowLayout()); loadButton.setFont(new Font("SansSerif", Font.PLAIN, 14)); panel1.add(loadButton); JLabel myLabel = new JLabel("Macros Overview"); if (showPopUp) { panel1.add(myLabel); } myLabel.setForeground(Color.blue); myLabel.setAutoscrolls(true); macrosPopup = new javax.swing.JPopupMenu(); myLabel.addMouseListener( new java.awt.event.MouseAdapter() { public void mouseEntered(java.awt.event.MouseEvent evt) { refreshPopupItems(); } public void mouseReleased(java.awt.event.MouseEvent evt) { if ((evt.getModifiers() & InputEvent.BUTTON1_MASK) != 0) { ij.IJ.showStatus("Right-Click to navigate through macros"); // + "\n-" // + "\nYou also can enter bookmark tags into the macro // text:" // + "\n //<< bookmarks left part of line" // + "\n //>> bookmarks right part of line"); } } }); myLabel.setComponentPopupMenu(macrosPopup); ed.add(BorderLayout.NORTH, panel1); ed.add(BorderLayout.CENTER, ta); Font monoFont = new Font("Monospaced", Font.PLAIN, 14); ta.setFont(monoFont); OJ.editor = ed; Frame[] frames = WindowManager.getNonImageWindows(); Frame frame = frames[frames.length - 1]; // ij.IJ.log(WindowManager.getFrontWindow().getTitle()); // ij.IJ.log(frame.getTitle());//"Embedded Macros" // ij.IJ.log("---");//"Embedded Macros" OJ.editorWindow = WindowManager.getFrontWindow(); refreshPopupItems(); loadButton.transferFocus(); }
/** * Opens and displays the specified tiff, dicom, fits, pgm, jpeg, bmp, gif, lut, roi, or text * file. Displays an error message if the file is not in a supported format. * * @see ij.IJ#open(String) * @see ij.IJ#openImage(String) */ public void open(String path) { boolean isURL = path.indexOf("://") > 0; if (isURL && isText(path)) { openTextURL(path); return; } if (path.endsWith(".jar") || path.endsWith(".class")) { (new PluginInstaller()).install(path); return; } boolean fullPath = path.startsWith("/") || path.startsWith("\\") || path.indexOf(":\\") == 1 || isURL; if (!fullPath) { String defaultDir = OpenDialog.getDefaultDirectory(); if (defaultDir != null) path = defaultDir + path; else path = (new File(path)).getAbsolutePath(); } if (!silentMode) IJ.showStatus("Opening: " + path); long start = System.currentTimeMillis(); ImagePlus imp = openImage(path); if (imp == null && isURL) return; if (imp != null) { WindowManager.checkForDuplicateName = true; if (isRGB48) openRGB48(imp); else imp.show(getLoadRate(start, imp)); } else { switch (fileType) { case LUT: imp = (ImagePlus) IJ.runPlugIn("ij.plugin.LutLoader", path); if (imp.getWidth() != 0) imp.show(); break; case ROI: IJ.runPlugIn("ij.plugin.RoiReader", path); break; case JAVA_OR_TEXT: case TEXT: if (IJ.altKeyDown()) { // open in TextWindow if alt key down new TextWindow(path, 400, 450); IJ.setKeyUp(KeyEvent.VK_ALT); break; } File file = new File(path); int maxSize = 250000; long size = file.length(); if (size >= 28000) { String osName = System.getProperty("os.name"); if (osName.equals("Windows 95") || osName.equals("Windows 98") || osName.equals("Windows Me")) maxSize = 60000; } if (size < maxSize) { Editor ed = (Editor) IJ.runPlugIn("ij.plugin.frame.Editor", ""); if (ed != null) ed.open(getDir(path), getName(path)); } else new TextWindow(path, 400, 450); break; case OJJ: // ObjectJ project IJ.runPlugIn("ObjectJ_", path); break; case TABLE: // ImageJ Results table openResultsTable(path); break; case RAW: IJ.runPlugIn("ij.plugin.Raw", path); break; case UNKNOWN: String msg = "File is not in a supported format, a reader\n" + "plugin is not available, or it was not found."; if (path != null) { if (path.length() > 64) path = (new File(path)).getName(); if (path.length() <= 64) { if (IJ.redirectingErrorMessages()) msg += " \n " + path; else msg += " \n \n" + path; } } if (openUsingPlugins) msg += "\n \nNOTE: The \"OpenUsingPlugins\" option is set."; IJ.wait(IJ.isMacro() ? 500 : 100); // work around for OS X thread deadlock problem IJ.error("Opener", msg); error = true; break; } } }