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 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); }
void init(String[] names1, float[][][] pch1, int psfflag1) { setLayout(null); names = names1; pch = pch1; psfflag = psfflag1; ncurves = pch.length; nparams = 11; xpts = pch[0].length; ypts = pch[0][0].length; checkarray = new Checkbox[ncurves]; include = new boolean[ncurves]; namearray = new TextField[ncurves + 1]; int1array = new TextField[ncurves + 1]; intensity1 = new double[ncurves + 1]; e1array = new TextField[ncurves + 1]; n1array = new TextField[ncurves + 1]; bright1 = new double[ncurves + 1]; number1 = new double[ncurves + 1]; int2array = new TextField[ncurves + 1]; intensity2 = new double[ncurves + 1]; e2array = new TextField[ncurves + 1]; n2array = new TextField[ncurves + 1]; bright2 = new double[ncurves + 1]; number2 = new double[ncurves + 1]; eccarray = new TextField[ncurves + 1]; brightcc = new double[ncurves + 1]; eminccarray = new TextField[ncurves + 1]; brightmincc = new double[ncurves + 1]; c2array = new TextField[ncurves + 1]; c2 = new double[ncurves + 1]; nmeas = new int[ncurves + 1]; avg = new float[xpts][ypts]; indices = new int[ncurves]; beta = 0.05; getintbright(); for (int i = 0; i < ncurves; i++) { include[i] = true; indices[i] = i; } updateavg(); int starty = 60; int startx = 10; int yinc = 25; for (int i = 0; i <= ncurves; i++) { if (i != ncurves) { checkarray[i] = new Checkbox("", include[i]); checkarray[i].setBounds(startx, starty + i * yinc, 20, 20); checkarray[i].addItemListener(this); add(checkarray[i]); } namearray[i] = new TextField(names[i]); namearray[i].setBounds(startx + 30, starty + i * yinc, 200, 20); add(namearray[i]); int1array[i] = new TextField("" + (float) intensity1[i]); int1array[i].setBounds(startx + 30 + 210, starty + i * yinc, 40, 20); add(int1array[i]); e1array[i] = new TextField("" + (float) bright1[i]); e1array[i].setBounds(startx + 30 + 210 + 50, starty + i * yinc, 40, 20); add(e1array[i]); n1array[i] = new TextField("" + (float) number1[i]); n1array[i].setBounds(startx + 30 + 210 + 50 + 50, starty + i * yinc, 40, 20); add(n1array[i]); int2array[i] = new TextField("" + (float) intensity2[i]); int2array[i].setBounds(startx + 30 + 210 + 50 + 50 + 50, starty + i * yinc, 40, 20); add(int2array[i]); e2array[i] = new TextField("" + (float) bright2[i]); e2array[i].setBounds(startx + 30 + 210 + 50 + 50 + 50 + 50, starty + i * yinc, 40, 20); add(e2array[i]); n2array[i] = new TextField("" + (float) number2[i]); n2array[i].setBounds(startx + 30 + 210 + 50 + 50 + 50 + 50 + 50, starty + i * yinc, 40, 20); add(n2array[i]); eccarray[i] = new TextField("" + (float) brightcc[i]); eccarray[i].setBounds( startx + 30 + 210 + 50 + 50 + 50 + 50 + 50 + 50, starty + i * yinc, 40, 20); add(eccarray[i]); eminccarray[i] = new TextField("" + (float) brightmincc[i]); eminccarray[i].setBounds( startx + 30 + 210 + 50 + 50 + 50 + 50 + 50 + 50 + 50, starty + i * yinc, 40, 20); add(eminccarray[i]); c2[i] = 0.0; c2array[i] = new TextField("" + (float) c2[i]); c2array[i].setBounds( startx + 30 + 210 + 50 + 50 + 50 + 50 + 50 + 50 + 50 + 50, starty + i * yinc, 80, 20); add(c2array[i]); } namelabel = new Label("Filename"); namelabel.setBounds(startx + 30, starty - 25, 100, 20); add(namelabel); intlabel = new Label("<Ig>"); intlabel.setBounds(startx + 30 + 210, starty - 25, 40, 20); add(intlabel); brightlabel = new Label("<eg>"); brightlabel.setBounds(startx + 30 + 210 + 50, starty - 25, 40, 20); add(brightlabel); nlabel = new Label("<Ng>"); nlabel.setBounds(startx + 30 + 210 + 50 + 50, starty - 25, 40, 20); add(nlabel); int2label = new Label("<Ir>"); int2label.setBounds(startx + 30 + 210 + 50 + 50 + 50, starty - 25, 40, 20); add(int2label); bright2label = new Label("<er>"); bright2label.setBounds(startx + 30 + 210 + 50 + 50 + 50 + 50, starty - 25, 40, 20); add(bright2label); n2label = new Label("<Nr>"); n2label.setBounds(startx + 30 + 210 + 50 + 50 + 50 + 50 + 50, starty - 25, 40, 20); add(n2label); brightcclabel = new Label("<ecc>"); brightcclabel.setBounds(startx + 30 + 210 + 50 + 50 + 50 + 50 + 50 + 50, starty - 25, 40, 20); add(brightcclabel); brightccminlabel = new Label("min"); brightccminlabel.setBounds( startx + 30 + 210 + 50 + 50 + 50 + 50 + 50 + 50 + 50, starty - 25, 40, 20); add(brightccminlabel); c2label = new Label("chi^2"); c2label.setBounds( startx + 30 + 210 + 50 + 50 + 50 + 50 + 50 + 50 + 50 + 50, starty - 25, 80, 20); add(c2label); int buttonsx = startx + 30 + 210 + 50 + 50 + 50 + 50 + 50 + 50 + 50 + 50 + 90; fitavgbutton = new Button("Fit Avg"); fitavgbutton.setBounds(buttonsx, starty - 25, 100, 40); fitavgbutton.addActionListener(this); add(fitavgbutton); fitglobalbutton = new Button("Fit Global"); fitglobalbutton.setBounds(buttonsx, starty - 25 + 50, 100, 40); fitglobalbutton.addActionListener(this); add(fitglobalbutton); clearparamsbutton = new Button("Reset Fit Params"); clearparamsbutton.setBounds(buttonsx, starty - 25 + 50 + 50, 100, 40); clearparamsbutton.addActionListener(this); add(clearparamsbutton); checkc2 = false; fitclass = new NLLSfit(this, 0.0001, 50, 0.1); globalfitclass = new NLLSglobalfit(this, 0.0001, 50, 0.1); pchfunc = new pch2D((int) ((double) xpts * 1.5), (int) ((double) ypts * 1.5), psfflag); avgfit = new float[xpts][ypts]; fit = new float[ncurves][xpts][ypts]; xvals = new float[ncurves][xpts][ypts]; for (int i = 0; i < ncurves; i++) { for (int j = 0; j < xpts; j++) { for (int k = 0; k < ypts; k++) { xvals[i][j][k] = (float) k; fit[i][j][k] = 1.0f; } } } globalc2label = new Label("Global chi^2 = " + (float) 0.0); globalc2label.setBounds(buttonsx, starty - 25 + 50 + 50 + 50, 140, 20); add(globalc2label); dispcurvelabel = new Label("Display Fit #"); dispcurvelabel.setBounds(buttonsx, starty - 25 + 50 + 50 + 50 + 30, 70, 20); add(dispcurvelabel); dispcurvechoice = new Choice(); for (int i = 0; i < ncurves; i++) { dispcurvechoice.add("" + (i + 1)); } dispcurve = 0; dispcurvechoice.select(0); dispcurvechoice.setBounds(buttonsx + 80, starty - 25 + 50 + 50 + 50 + 30, 40, 20); dispcurvechoice.addItemListener(this); add(dispcurvechoice); betalabel = new Label("Bleedthrough f"); betalabel.setBounds(buttonsx, starty - 25 + 50 + 50 + 50 + 30 + 30, 100, 20); add(betalabel); betaval = new TextField("" + (float) beta); betaval.setBounds(buttonsx + 110, starty - 25 + 50 + 50 + 50 + 30 + 30, 40, 20); betaval.addActionListener(this); add(betaval); beta = Double.parseDouble(betaval.getText()); updatebeta(); undobutton = new Button("Undo Global Fit"); undobutton.setBounds(buttonsx, starty - 25 + 50 + 50 + 50 + 30 + 30 + 50, 100, 40); undobutton.addActionListener(this); add(undobutton); geterrorsbutton = new Button("Get Errors"); geterrorsbutton.setBounds(buttonsx, starty - 25 + 50 + 50 + 50 + 30 + 30 + 50 + 50, 100, 40); geterrorsbutton.addActionListener(this); add(geterrorsbutton); copylabel = new Label("copyright 2009 Jay Unruh ([email protected]) non-profit use only"); copylabel.setBounds(10, 790, 400, 20); add(copylabel); n_b_label = new Label("N and B Analysis"); n_b_label.setBounds(250, 10, 100, 20); add(n_b_label); pwavg = new PlotWindow3D("Avg", "kg", "kr", "Frequency", avg, 0); pwavg.setLogAxes(false, false, true); pwavg.draw(); pwavg.addPoints(avgfit, true, 0); float[] temp = pwavg.getLimits(); temp[4] = 1.0f; pwavg.setLimits(temp); float[][] temppch = new float[xpts][ypts]; for (int i = 0; i < xpts; i++) { System.arraycopy(pch[dispcurve][i], 0, temppch[i], 0, ypts); } pwfit = new PlotWindow3D("Selected Curve", "kg", "kr", "Frequency", temppch, 0); pwfit.setLogAxes(false, false, true); pwfit.draw(); pwfit.addPoints(fit[dispcurve], true, 0); float[] temp2 = pwfit.getLimits(); temp2[4] = 1.0f; pwfit.setLimits(temp2); resetparams(); repaint(); }
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); }