public void addClient() { client = new Canvas() { public void paint(Graphics g) { super.paint(g); } }; client.setBackground(new Color(30, 220, 40)); clientCont.add(client); clientCont.validate(); final ComponentAccessor acc = AWTAccessor.getComponentAccessor(); WindowIDProvider pid = (WindowIDProvider) acc.getPeer(client); log.fine("Added XEmbed server(Canvas) with X window ID " + pid.getWindow()); Rectangle toFocusBounds = toFocus.getBounds(); toFocusBounds.setLocation(toFocus.getLocationOnScreen()); f.validate(); // KDE doesn't accept clicks on title as activation - click below title Rectangle fbounds = f.getBounds(); fbounds.y += f.getInsets().top; fbounds.height -= f.getInsets().top; Process proc = startClient( new Rectangle[] { fbounds, dummy.getBounds(), toFocusBounds, new Rectangle(b_modal.getLocationOnScreen(), b_modal.getSize()), new Rectangle(10, 130, 20, 20) }, pid.getWindow()); new ClientWatcher(client, proc, clientCont).start(); }
public void dispose() { f.dispose(); f = null; dummy.dispose(); dummy = null; if (modal_d != null) { modal_d.dispose(); modal_d = null; } }
public void init() { Panel p = new Panel(); p.add(btCopy); p.add(btPaste); btCopy.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { // 将一个多行文本域里的字符串封装成StringSelection对象 StringSelection contents = new StringSelection(jtaCopyTo.getText()); // 将StringSelection对象放入剪贴板 clipboard.setContents(contents, null); } }); btPaste.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { // 如果剪贴板中包含stringFlavor内容 if (clipboard.isDataFlavorAvailable(DataFlavor.stringFlavor)) { try { // 取出剪贴板中stringFlavor内容 String content = (String) clipboard.getData(DataFlavor.stringFlavor); jtaPaste.append(content); } catch (Exception e) { e.printStackTrace(); } } } }); // 创建一个水平排列的Box容器 Box box = new Box(BoxLayout.X_AXIS); // 将两个多行文本域放在Box容器中 box.add(jtaCopyTo); box.add(jtaPaste); // 将按钮所在Panel、Box容器添加到Frame窗口中 f.add(p, BorderLayout.SOUTH); f.add(box, BorderLayout.CENTER); f.pack(); f.setVisible(true); }
public void run(String arg) { GenericDialog gd = new GenericDialog("Options"); double sfreq = 20000.0; gd.addNumericField("Sampling Frequency?", sfreq, 1, 10, null); String[] psfchoice = {"3D Gaussian", "Gaus-Lorentz^2", "2D Gaussian"}; gd.addChoice("PSF Type?", psfchoice, psfchoice[0]); String[] filetypechoice = { "Confocor 3 raw", "Short binary trajectory", "PlotWindow trajectory", "Ascii Text File" }; gd.addChoice("File Type?", filetypechoice, filetypechoice[0]); boolean ch2green = true; gd.addCheckbox("Ch2 is green?", ch2green); gd.showDialog(); if (gd.wasCanceled()) { return; } sfreq = gd.getNextNumber(); int psfflag = gd.getNextChoiceIndex(); int fileflag = gd.getNextChoiceIndex(); ch2green = gd.getNextBoolean(); int nfiles = 0; Object[] histograms = null; int xmax = 0; int ymax = 0; String[] names = null; if (fileflag < 2) { jdataio ioclass = new jdataio(); File[] filearray = ioclass.openfiles(OpenDialog.getDefaultDirectory(), IJ.getInstance()); if (filearray.length == 0) { return; } String dir = filearray[0].getAbsolutePath(); int sepindex = dir.lastIndexOf(File.separator); String newdir = dir.substring(0, sepindex + 1); OpenDialog.setDefaultDirectory(newdir); nfiles = filearray.length / 2; if (nfiles > 25) { nfiles = 25; } histograms = new Object[nfiles]; names = organize_c3_files(filearray); for (int i = 0; i < nfiles; i++) { try { int length1 = (int) (((double) filearray[2 * i].length() - 128.0) / 4.0); int length2 = (int) (((double) filearray[2 * i + 1].length() - 128.0) / 4.0); int length3 = (int) (((double) filearray[2 * i].length()) / 2.0); int length4 = (int) (((double) filearray[2 * i + 1].length()) / 2.0); InputStream instream = new BufferedInputStream(new FileInputStream(filearray[2 * i])); InputStream instream2 = new BufferedInputStream(new FileInputStream(filearray[2 * i + 1])); if (fileflag == 0) { int[] pmdata = new int[length1]; int[] pmdata2 = new int[length2]; if (!ioclass.skipstreambytes(instream, 128)) { showioerror(); instream.close(); return; } if (!ioclass.skipstreambytes(instream2, 128)) { showioerror(); instream2.close(); return; } if (!ioclass.readintelintfile(instream, length1, pmdata)) { showioerror(); instream.close(); return; } if (!ioclass.readintelintfile(instream2, length2, pmdata2)) { showioerror(); instream2.close(); return; } if (ch2green) { histograms[i] = (new pmodeconvert()).pm2pch(pmdata2, pmdata, sfreq, 20000000); } else { histograms[i] = (new pmodeconvert()).pm2pch(pmdata, pmdata2, sfreq, 20000000); } } else { float[] tmdata = new float[length3]; float[] tmdata2 = new float[length4]; if (!ioclass.readintelshortfile(instream, length3, tmdata)) { showioerror(); instream.close(); return; } if (!ioclass.readintelshortfile(instream2, length4, tmdata2)) { showioerror(); instream2.close(); return; } if (ch2green) { histograms[i] = (new pmodeconvert()).create_2Dhistogram(tmdata2, tmdata); } else { histograms[i] = (new pmodeconvert()).create_2Dhistogram(tmdata, tmdata2); } } if (((float[][]) histograms[i]).length > xmax) { xmax = ((float[][]) histograms[i]).length; } if (((float[][]) histograms[i])[0].length > ymax) { ymax = ((float[][]) histograms[i])[0].length; } instream.close(); instream2.close(); } catch (IOException e) { showioerror(); return; } } } else { if (fileflag == 2) { ImageWindow iw = WindowManager.getCurrentWindow(); float[][] trajectories = (float[][]) jutils.runPW4VoidMethod(iw, "getYValues"); float[][] tempxvals = (float[][]) jutils.runPW4VoidMethod(iw, "getXValues"); sfreq = 1.0 / ((double) tempxvals[0][1]); nfiles = trajectories.length / 2; if (nfiles > 25) { nfiles = 25; } names = new String[nfiles + 1]; names[nfiles] = "avg"; histograms = new Object[nfiles]; for (int i = 0; i < nfiles; i++) { names[i] = "trajectory " + (i + 1); if (ch2green) { histograms[i] = (new pmodeconvert()) .create_2Dhistogram(trajectories[2 * i + 1], trajectories[2 * i]); } else { histograms[i] = (new pmodeconvert()) .create_2Dhistogram(trajectories[2 * i], trajectories[2 * i + 1]); } if (((float[][]) histograms[i]).length > xmax) { xmax = ((float[][]) histograms[i]).length; } if (((float[][]) histograms[i])[0].length > ymax) { ymax = ((float[][]) histograms[i])[0].length; } } } else { // here we read tab delimited lines from files jdataio ioclass = new jdataio(); File[] filearray = ioclass.openfiles(OpenDialog.getDefaultDirectory(), IJ.getInstance()); if (filearray.length == 0) { return; } String dir = filearray[0].getAbsolutePath(); int sepindex = dir.lastIndexOf(File.separator); String newdir = dir.substring(0, sepindex + 1); OpenDialog.setDefaultDirectory(newdir); nfiles = filearray.length; if (nfiles > 25) { nfiles = 25; } histograms = new Object[nfiles]; names = new String[nfiles + 1]; names[nfiles] = "avg"; for (int i = 0; i < nfiles; i++) { try { names[i] = filearray[i].getName(); BufferedReader d = new BufferedReader(new FileReader(filearray[i])); String[] lines = new String[256]; int counter = 0; do { lines[counter] = d.readLine(); counter++; } while ((lines[counter - 1] != null && lines[counter - 1] != "") && counter < 256); int numcolumns = 0; for (int j = 0; j < counter - 1; j++) { int temp = getncolumns(lines[j]); if (temp > numcolumns) { numcolumns = temp; } } float[][] temphist2 = null; if (ch2green) { temphist2 = new float[numcolumns][counter - 1]; } else { temphist2 = new float[counter - 1][numcolumns]; } for (int k = 0; k < counter - 1; k++) { float[] temp = tab_delim2float(lines[k]); for (int j = 0; j < numcolumns; j++) { if (ch2green) { temphist2[j][k] = temp[j]; } else { temphist2[k][j] = temp[j]; } } } histograms[i] = temphist2; d.close(); } catch (IOException e) { showioerror(); return; } } for (int i = 0; i < nfiles; i++) { if (((float[][]) histograms[i]).length > xmax) { xmax = ((float[][]) histograms[i]).length; } if (((float[][]) histograms[i])[0].length > ymax) { ymax = ((float[][]) histograms[i])[0].length; } } } } // note that here x is green and y is red float[][][] pch = new float[nfiles][xmax][ymax]; for (int i = 0; i < nfiles; i++) { for (int j = 0; j < ((float[][]) histograms[i]).length; j++) { for (int k = 0; k < ((float[][]) histograms[i])[j].length; k++) { pch[i][j][k] = ((float[][]) histograms[i])[j][k]; } } } final PCH2DFitWindow cw = new PCH2DFitWindow(); cw.init(names, pch, psfflag); final Frame f = new Frame("PCH 2D Analysis"); f.setLocation(10, 10); f.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { f.dispose(); } }); f.add(cw); f.pack(); f.setResizable(false); Insets ins = f.getInsets(); cw.totalSize.height = PCH2DFitWindow.H + ins.bottom + ins.top + 65; cw.totalSize.width = PCH2DFitWindow.WR + ins.left + ins.right; f.setSize(cw.totalSize); f.setVisible(true); cw.requestFocus(); }
public TestXEmbedServer(boolean manual) { // Enable testing extensions in XEmbed server System.setProperty("sun.awt.xembed.testing", "true"); f = new Frame("Main frame"); f.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { synchronized (TestXEmbedServer.this) { TestXEmbedServer.this.notifyAll(); } dummy.dispose(); f.dispose(); } }); f.setLayout(new BorderLayout()); Container bcont = new Container(); toFocus = new Button("Click to focus server"); final TextField tf = new TextField(20); tf.setName("0"); DragSource ds = new DragSource(); final DragSourceListener dsl = new DragSourceAdapter() { public void dragDropEnd(DragSourceDropEvent dsde) {} }; final DragGestureListener dgl = new DragGestureListener() { public void dragGestureRecognized(DragGestureEvent dge) { dge.startDrag(null, new StringSelection(tf.getText()), dsl); } }; ds.createDefaultDragGestureRecognizer(tf, DnDConstants.ACTION_COPY, dgl); final DropTargetListener dtl = new DropTargetAdapter() { public void drop(DropTargetDropEvent dtde) { dtde.acceptDrop(DnDConstants.ACTION_COPY); try { tf.setText( tf.getText() + (String) dtde.getTransferable().getTransferData(DataFlavor.stringFlavor)); } catch (Exception e) { } } }; final DropTarget dt = new DropTarget(tf, dtl); Button b_add = new Button("Add client"); b_add.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { addClient(); } }); Button b_remove = new Button("Remove client"); b_remove.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (clientCont.getComponentCount() != 0) { clientCont.remove(clientCont.getComponentCount() - 1); } } }); b_close = new JButton("Close modal dialog"); b_close.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { modal_d.dispose(); } }); b_modal = new Button("Show modal dialog"); b_modal.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { modal_d = new JDialog(f, "Modal dialog", true); modal_d.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); modal_d.setBounds(0, 100, 200, 50); modal_d.getContentPane().add(b_close); modal_d.validate(); modal_d.show(); } }); bcont.add(tf); bcont.add(toFocus); bcont.add(b_add); bcont.add(b_remove); bcont.add(b_modal); if (manual) { Button pass = new Button("Pass"); pass.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { passed = true; synchronized (TestXEmbedServer.this) { TestXEmbedServer.this.notifyAll(); } } }); bcont.add(pass); Button fail = new Button("Fail"); fail.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { passed = false; synchronized (TestXEmbedServer.this) { TestXEmbedServer.this.notifyAll(); } } }); bcont.add(fail); } b_modal.setName("2"); bcont.setLayout(new FlowLayout()); f.add(bcont, BorderLayout.NORTH); clientCont = Box.createVerticalBox(); f.add(clientCont, BorderLayout.CENTER); dummy = new JFrame("Dummy"); dummy.getContentPane().add(new JButton("Button")); dummy.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); dummy.setBounds(0, VERTICAL_POSITION, 100, 100); dummy.setVisible(true); f.setBounds(300, VERTICAL_POSITION, 800, 300); f.setVisible(true); }