public static void main(String[] args) { try { if (args.length != 1) throw new IllegalArgumentException("Wrong number of arguments"); FileReader in = new FileReader(args[0]); HardcopyWriter out = null; Frame f = new Frame("PrintFile: " + args[0]); f.setSize(200, 50); f.show(); try { out = new HardcopyWriter(f, args[0], 10, .75, .75, .75, .75); } catch (HardcopyWriter.PrintCanceledException e) { System.exit(0); } f.setVisible(false); char[] buffer = new char[4096]; int numchars; while ((numchars = in.read(buffer)) != -1) out.write(buffer, 0, numchars); out.close(); } catch (Exception e) { System.err.println(e); System.err.println("Usage: java HardcopyWriter$PrintFile <filename>"); System.exit(1); } System.exit(0); }
public void mouseClicked(MouseEvent ev) { Window w = (Window) ev.getSource(); Frame f = null; if (w instanceof Frame) { f = (Frame) w; } else { return; } Point convertedPoint = SwingUtilities.convertPoint(w, ev.getPoint(), getTitlePane()); int state = f.getExtendedState(); if (getTitlePane() != null && getTitlePane().contains(convertedPoint)) { if ((ev.getClickCount() % 2) == 0 && ((ev.getModifiers() & InputEvent.BUTTON1_MASK) != 0)) { if (f.isResizable()) { if ((state & Frame.MAXIMIZED_BOTH) != 0) { f.setExtendedState(state & ~Frame.MAXIMIZED_BOTH); } else { f.setExtendedState(state | Frame.MAXIMIZED_BOTH); } return; } } } }
/** * Creates a new connection to the specified host of specified type. <br> * <br> * type: Type of connection to create <br> * destination: Host to connect to (in "host:port" or "host" syntax) */ public Connection(java.net.InetAddress host, int port, PluginContext ctx) throws MessagingNetworkException, java.io.IOException { if (TRAKTOR_USED) { if (traktorConnectionDown) throw new IOException("network is down"); traktor = new Frame("" + host + ":" + port + " - Traktor"); final Checkbox c = new Checkbox("break this & ALL future connections"); c.setState(traktorConnectionDown); c.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { traktorConnectionDown = c.getState(); try { if (traktorConnectionDown) closeSocket(); } catch (Exception ex) { } } }); traktor.add(c); traktor.setSize(100, 50); traktor.setLocation(230, 450); traktor.setVisible(true); } else { traktor = null; } }
@Override public void actionPerformed(ActionEvent e) { Frame frame = getFrame(); JFileChooser chooser = new JFileChooser(); int ret = chooser.showOpenDialog(frame); if (ret != JFileChooser.APPROVE_OPTION) { return; } File f = chooser.getSelectedFile(); if (f.isFile() && f.canRead()) { Document oldDoc = getEditor().getDocument(); if (oldDoc != null) { oldDoc.removeUndoableEditListener(undoHandler); } if (elementTreePanel != null) { elementTreePanel.setEditor(null); } getEditor().setDocument(new PlainDocument()); frame.setTitle(f.getName()); Thread loader = new FileLoader(f, editor.getDocument()); loader.start(); } else { JOptionPane.showMessageDialog( getFrame(), "Could not open file: " + f, "Error opening file", JOptionPane.ERROR_MESSAGE); } }
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 mouseMoved(MouseEvent ev) { JRootPane root = getRootPane(); if (root.getWindowDecorationStyle() == JRootPane.NONE) { return; } Window w = (Window) ev.getSource(); Frame f = null; Dialog d = null; if (w instanceof Frame) { f = (Frame) w; } else if (w instanceof Dialog) { d = (Dialog) w; } // Update the cursor int cursor = getCursor(calculateCorner(w, ev.getX(), ev.getY())); if (cursor != 0 && ((f != null && (f.isResizable() && (f.getExtendedState() & Frame.MAXIMIZED_BOTH) == 0)) || (d != null && d.isResizable()))) { w.setCursor(Cursor.getPredefinedCursor(cursor)); } else { w.setCursor(lastCursor); } }
private boolean ignoreArrowKeys(ImagePlus imp) { Frame frame = WindowManager.getFrontWindow(); String title = frame.getTitle(); if (title != null && title.equals("ROI Manager")) return true; // Control Panel? if (frame != null && frame instanceof javax.swing.JFrame) return true; ImageWindow win = imp.getWindow(); // LOCI Data Browser window? if (imp.getStackSize() > 1 && win != null && win.getClass().getName().startsWith("loci")) return true; return false; }
public void actionPerformed(ActionEvent e) { Frame frame = getFrame(); JFileChooser chooser = new JFileChooser(); int ret = chooser.showSaveDialog(frame); if (ret != JFileChooser.APPROVE_OPTION) { return; } File f = chooser.getSelectedFile(); frame.setTitle(f.getName()); Thread saver = new FileSaver(f, editor.getDocument()); saver.start(); }
public void start() { Toolkit.getDefaultToolkit() .addAWTEventListener( new AWTEventListener() { public void eventDispatched(AWTEvent e) { System.out.println(e.toString()); } }, FocusEvent.FOCUS_EVENT_MASK | WindowEvent.WINDOW_FOCUS_EVENT_MASK | WindowEvent.WINDOW_EVENT_MASK); frame = new Frame("Frame"); frame.setName("Frame-owner"); frame.setBounds(100, 0, 100, 100); dialog = new Dialog(frame, "Dialog"); dialog.setName("Dialog-owner"); dialog.setBounds(100, 0, 100, 100); window1 = new Window(frame); window1.setName("1st child"); window1.setBounds(100, 300, 100, 100); window2 = new Window(window1); window2.setName("2nd child"); window2.setBounds(100, 500, 100, 100); test1(frame, window1); test2(frame, window1, window2); test3(frame, window1, window2); window1 = new Window(dialog); window1.setBounds(100, 300, 100, 100); window1.setName("1st child"); window2 = new Window(window1); window2.setName("2nd child"); window2.setBounds(100, 500, 100, 100); test1(dialog, window1); test2(dialog, window1, window2); test3(dialog, window1, window2); System.out.println("Test passed."); }
public void dispose() { f.dispose(); f = null; dummy.dispose(); dummy = null; if (modal_d != null) { modal_d.dispose(); modal_d = null; } }
/** * main entrypoint - starts the part when it is run as an application * * @param args java.lang.String[] */ public static void main(java.lang.String[] args) { try { Frame frame = new java.awt.Frame(); AddressBookSelectionUI aAddressBookSelectionUI; aAddressBookSelectionUI = new AddressBookSelectionUI(); frame.add("Center", aAddressBookSelectionUI); frame.setSize(aAddressBookSelectionUI.getSize()); frame.addWindowListener( new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { System.exit(0); }; }); frame.setVisible(true); } catch (Throwable exception) { System.err.println("Exception occurred in main() of java.awt.Panel"); exception.printStackTrace(System.out); } }
public void mousePressed(MouseEvent ev) { JRootPane rootPane = getRootPane(); if (rootPane.getWindowDecorationStyle() == JRootPane.NONE) { return; } Point dragWindowOffset = ev.getPoint(); Window w = (Window) ev.getSource(); if (w != null) { w.toFront(); } Point convertedDragWindowOffset = SwingUtilities.convertPoint(w, dragWindowOffset, getTitlePane()); Frame f = null; Dialog d = null; if (w instanceof Frame) { f = (Frame) w; } else if (w instanceof Dialog) { d = (Dialog) w; } int frameState = (f != null) ? f.getExtendedState() : 0; if (getTitlePane() != null && getTitlePane().contains(convertedDragWindowOffset)) { if ((f != null && ((frameState & Frame.MAXIMIZED_BOTH) == 0) || (d != null)) && dragWindowOffset.y >= BORDER_DRAG_THICKNESS && dragWindowOffset.x >= BORDER_DRAG_THICKNESS && dragWindowOffset.x < w.getWidth() - BORDER_DRAG_THICKNESS) { isMovingWindow = true; dragOffsetX = dragWindowOffset.x; dragOffsetY = dragWindowOffset.y; } } else if (f != null && f.isResizable() && ((frameState & Frame.MAXIMIZED_BOTH) == 0) || (d != null && d.isResizable())) { dragOffsetX = dragWindowOffset.x; dragOffsetY = dragWindowOffset.y; dragWidth = w.getWidth(); dragHeight = w.getHeight(); dragCursor = getCursor(calculateCorner(w, dragWindowOffset.x, dragWindowOffset.y)); } }
protected final java.io.OutputStream getOutputStream() throws IOException { if (isClosed()) { if (TRAKTOR_USED && traktor != null && !traktorConnectionDown) { traktor.dispose(); traktor = null; } throw new IOException("connection closed"); } OutputStream os = getOutputStream0(); if (os == null) throw new IOException("connection closed"); return os; }
/** * Get the next file available in the tree. * * @return the next file available, or null if no file is available, indicating the end of the * arboreal perambulation. */ public File getNextFile() { while (currentFrame != null) { File file = currentFrame.getNextFile(); if (file == null) { try { currentFrame = stack.pop(); } catch (Exception empty) { currentFrame = null; } } else if (file.isDirectory()) { stack.push(currentFrame); currentFrame = new Frame(file); } else { fileCount++; return file; } } return null; }
void saveWindowLocations() { Frame frame = WindowManager.getFrame("B&C"); if (frame != null) Prefs.saveLocation(ContrastAdjuster.LOC_KEY, frame.getLocation()); frame = WindowManager.getFrame("Threshold"); if (frame != null) Prefs.saveLocation(ThresholdAdjuster.LOC_KEY, frame.getLocation()); frame = WindowManager.getFrame("Results"); if (frame != null) { Prefs.saveLocation(TextWindow.LOC_KEY, frame.getLocation()); Dimension d = frame.getSize(); Prefs.set(TextWindow.WIDTH_KEY, d.width); Prefs.set(TextWindow.HEIGHT_KEY, d.height); } frame = WindowManager.getFrame("Log"); if (frame != null) { Prefs.saveLocation(TextWindow.LOG_LOC_KEY, frame.getLocation()); Dimension d = frame.getSize(); Prefs.set(TextWindow.LOG_WIDTH_KEY, d.width); Prefs.set(TextWindow.LOG_HEIGHT_KEY, d.height); } }
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); }
private static void updateLookAndFeel() { for (Window window : Frame.getWindows()) { SwingUtilities.updateComponentTreeUI(window); } }
public void run() { frame.setVisible(true); }
/** * The constructor for this class has a bunch of arguments: The frame argument is required for all * printing in Java. The jobname appears left justified at the top of each printed page. The font * size is specified in points, as on-screen font sizes are. The margins are specified in inches * (or fractions of inches). */ public HardcopyWriter( Frame frame, String jobname, int fontsize, double leftmargin, double rightmargin, double topmargin, double bottommargin) throws HardcopyWriter.PrintCanceledException { // Get the PrintJob object with which we'll do all the printing. // The call is synchronized on the static printprops object, which // means that only one print dialog can be popped up at a time. // If the user clicks Cancel in the print dialog, throw an exception. Toolkit toolkit = frame.getToolkit(); // get Toolkit from Frame synchronized (printprops) { job = toolkit.getPrintJob(frame, jobname, printprops); } if (job == null) throw new PrintCanceledException("User cancelled print request"); pagesize = job.getPageDimension(); // query the page size pagedpi = job.getPageResolution(); // query the page resolution // Bug Workaround: // On windows, getPageDimension() and getPageResolution don't work, so // we've got to fake them. if (System.getProperty("os.name").regionMatches(true, 0, "windows", 0, 7)) { // Use screen dpi, which is what the PrintJob tries to emulate, anyway pagedpi = toolkit.getScreenResolution(); System.out.println(pagedpi); // Assume a 8.5" x 11" page size. A4 paper users have to change this. pagesize = new Dimension((int) (8.5 * pagedpi), 11 * pagedpi); System.out.println(pagesize); // We also have to adjust the fontsize. It is specified in points, // (1 point = 1/72 of an inch) but Windows measures it in pixels. fontsize = fontsize * pagedpi / 72; System.out.println(fontsize); System.out.flush(); } // Compute coordinates of the upper-left corner of the page. // I.e. the coordinates of (leftmargin, topmargin). Also compute // the width and height inside of the margins. x0 = (int) (leftmargin * pagedpi); y0 = (int) (topmargin * pagedpi); width = pagesize.width - (int) ((leftmargin + rightmargin) * pagedpi); height = pagesize.height - (int) ((topmargin + bottommargin) * pagedpi); // Get body font and font size font = new Font("Monospaced", Font.PLAIN, fontsize); metrics = toolkit.getFontMetrics(font); lineheight = metrics.getHeight(); lineascent = metrics.getAscent(); charwidth = metrics.charWidth('0'); // Assumes a monospaced font! // Now compute columns and lines will fit inside the margins chars_per_line = width / charwidth; lines_per_page = height / lineheight; // Get header font information // And compute baseline of page header: 1/8" above the top margin headerfont = new Font("SansSerif", Font.ITALIC, fontsize); headermetrics = toolkit.getFontMetrics(headerfont); headery = y0 - (int) (0.125 * pagedpi) - headermetrics.getHeight() + headermetrics.getAscent(); // Compute the date/time string to display in the page header DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT); df.setTimeZone(TimeZone.getDefault()); time = df.format(new Date()); this.jobname = jobname; // save name this.fontsize = fontsize; // save font size }
public int compareTo(Frame f) { return (this.id - f.id()); }
@Override public void run() { this.emuRunning = true; while (this.emuRunning) { try { /* * Pruefen, ob ein Programm geladen oder der Emulator * tatsaechlich zurueckgesetzt werden soll */ LoadData loadData = null; synchronized (this.monitor) { loadData = this.loadData; if (loadData != null) { this.loadData = null; } else { if (this.resetLevel == ResetLevel.POWER_ON) { Arrays.fill(this.ram, (byte) 0); } } } if (loadData != null) { loadData.loadIntoMemory(this); this.z80cpu.setRegPC(loadData.getStartAddr()); if (this.emuSys != null) { int spInitValue = this.emuSys.getAppStartStackInitValue(); if (spInitValue > 0) { this.z80cpu.setRegSP(spInitValue); } } } else { if ((this.resetLevel == ResetLevel.COLD_RESET) || (this.resetLevel == ResetLevel.POWER_ON)) { this.z80cpu.resetCPU(true); } else { this.z80cpu.resetCPU(false); } if (this.emuSys != null) { this.emuSys.reset(this.resetLevel, Main.getProperties()); this.z80cpu.setRegPC(this.emuSys.getResetStartAddress(this.resetLevel)); } } // RAM-Floppies und Druckmanager zuruecksetzen this.printMngr.reset(); this.ramFloppy1.reset(); this.ramFloppy2.reset(); if ((this.emuSys != null) && (this.resetLevel == ResetLevel.POWER_ON) && Main.getBooleanProperty("jkcemu.ramfloppy.clear_on_power_on", false)) { if (this.emuSys.supportsRAMFloppy1() && (this.ramFloppy1.getUsedSize() > 0)) { this.ramFloppy1.clear(); } if (this.emuSys.supportsRAMFloppy2() && (this.ramFloppy2.getUsedSize() > 0)) { this.ramFloppy2.clear(); } } // Fenster informieren final Frame[] frms = Frame.getFrames(); if (frms != null) { EventQueue.invokeLater( new Runnable() { @Override public void run() { for (Frame f : frms) { if (f instanceof BasicFrm) { ((BasicFrm) f).resetFired(); } } } }); } // in die Z80-Emulation verzweigen this.resetLevel = ResetLevel.NO_RESET; this.z80cpu.run(); } catch (Z80ExternalException ex) { } catch (Exception ex) { this.emuRunning = false; EventQueue.invokeLater(new ErrorMsg(this.screenFrm, ex)); } } }
private String getRequestURL() { return SERVLETPATH + "?" + MasterServlet.WINDOW_ID + "=" + Frame.getCurrent().getID(); }
/** @param tmpTickList */ private static List<Sequence> structureCreator(List<Tick> tmpTickList) { /* * transform List of Ticks to Frames */ List<Tick> tickList = new ArrayList<Tick>(); List<Frame> frameList = new ArrayList<Frame>(); List<Sequence> sequenceList = new ArrayList<Sequence>(); for (int i = 0; i < tmpTickList.size(); i++) { Tick currentTick = tmpTickList.get(i); if (currentTick.getType().compareTo("########") == 0) { // currentTick equal to ######## /* * add Frames to frameList */ Tick[] tickArray = new Tick[tickList.size()]; tickArray = tickList.toArray(tickArray); tickList.clear(); Frame tmpFrame = new Frame(tickArray); frameList.add(tmpFrame); } else { tickList.add(currentTick); } } /* * Arrange Frames into Sequences and create a Scene with them */ List<Frame> listOfFrames = new ArrayList<Frame>(); Frame stopFrame = new Frame(); listOfFrames.add(frameList.get(0)); // always start the listOfFrames with first frame for (int i = 0; i < frameList.size(); i++) { Frame frameA = frameList.get(i); Frame frameB; if (frameList.size() - 1 == i) { frameB = stopFrame; } else { frameB = frameList.get(i + 1); } if (frameA.equalTo(frameB)) { listOfFrames.add(frameB); // add duplicate frames to listOfFrames } else { int frameSize = frameA.getArrayLength(); int sequenceLength = listOfFrames.size(); int[][] timestampArray = new int[sequenceLength][frameSize]; String[] typeArray = frameA.getConcatenatedTypes(); for (int j = 0; j < sequenceLength; j++) { // for every Frame on the listOfFrames Frame tmpFrame = listOfFrames.get(j); // get the Frame timestampArray[j] = tmpFrame.getTimestamps(); // add every Timestamp in this Frame } Sequence prevSequence; if (sequenceList.isEmpty()) { prevSequence = new Sequence(); } else { prevSequence = sequenceList.get(sequenceList.size() - 1); } Sequence tmpSequence = new Sequence( typeArray, timestampArray, prevSequence); // create Sequence out of Types and Times sequenceList.add(tmpSequence); // add Sequence to List listOfFrames.clear(); // rinse and repeat listOfFrames.add(frameB); // but add FrameB as a startingpoint for the next iteration } } return sequenceList; }
// Main public static void main(String params[]) { // get input file if (params.length < 1) { System.out.println("No File Specified"); return; } // open file File infile = new File(params[0]); BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(infile)); } catch (Exception e) { System.out.println(e.toString()); return; } // read file try { String line = null; while ((line = reader.readLine()) != null) { String parts[] = line.split(" ", 2); int frames = Integer.valueOf(parts[0]); String actions[] = parts[1].replaceAll("\\}|\\{", "").split(","); // System.out.println(line); ArrayList<Frame> buffer = new ArrayList<Frame>(frames); int faults = 0; int index = 0; // SCR System.out.println("Second-Chance replacement (" + frames + " frames):"); System.out.println("\tReference Page\tFrames\tReplaced Page"); int scrtime = 0; for (int i = 0; i < actions.length; i++) { String act = actions[i]; Frame newframe = null; Frame victim = null; // process new action if (act.contains("m")) { newframe = new Frame(Integer.valueOf(act.replace("m", ""))); newframe.setMod(true); } else { newframe = new Frame(Integer.valueOf(act)); } newframe.setRef(true); // search buffer for (Frame f : buffer) { if (f.id() == newframe.id()) { buffer.set(buffer.indexOf(f), newframe); break; } } // if not found, add to buffer if (!buffer.contains(newframe)) { scrtime += 1; if (buffer.size() < frames) { buffer.add(newframe); } else { while (!buffer.contains(newframe)) { Frame f = buffer.get(index); if (f.getRef()) { f.setRef(false); } else { victim = f; buffer.set(index, newframe); } index = (index + 1) % frames; } } } // update faults faults += (victim == null ? 0 : 1); scrtime += (victim == null ? 0 : 10); // print action String framelist = ""; for (int j = 0; j < frames; j++) { if (buffer.size() > j) { framelist += buffer.get(j); } framelist += ","; } framelist = framelist.replaceFirst(",$", ""); System.out.println( "\t\t" + newframe + "\t" + framelist + "\t\t" + (victim == null ? "" : victim)); } System.out.println("Total Number of Page Faults = " + faults); System.out.println("Total I/O Time Units = " + scrtime); // Cleanup System.out.println(""); buffer = new ArrayList<Frame>(frames); faults = 0; index = 0; // SCE1 System.out.println("Second-Chance replacement extension 1 (" + frames + " frames):"); System.out.println("\tReference Page\tFrames\tReplaced Page"); int scetime = 0; for (int i = 0; i < actions.length; i++) { String act = actions[i]; Frame newframe = null; Frame victim = null; // process new action if (act.contains("m")) { newframe = new Frame(Integer.valueOf(act.replace("m", ""))); newframe.setMod(true); } else { newframe = new Frame(Integer.valueOf(act)); } newframe.setRef(true); // search buffer for (Frame f : buffer) { if (f.id() == newframe.id()) { if (f.getMod()) { newframe.setMod(true); } buffer.set(buffer.indexOf(f), newframe); break; } } // if not found, add to buffer if (!buffer.contains(newframe)) { scetime += 1; if (buffer.size() < frames) { buffer.add(newframe); } else { Boolean modpass = false; int init = index; int count = 0; while (!buffer.contains(newframe)) { Frame f = buffer.get(index); if (!f.getRef() && !f.getMod()) { victim = f; buffer.set(index, newframe); scetime += (victim.getMod() ? 10 : 0); faults += 1; } else if (!f.getRef() && f.getMod() && count == 1) { victim = f; buffer.set(index, newframe); scetime += (victim.getMod() ? 10 : 0); faults += 1; } else if (count == 1) { f.setRef(false); } index = (index + 1) % frames; if (index == init) { if (count == 1) { count = 0; } else { count = 1; } } } } } // print action String framelist = ""; for (int j = 0; j < frames; j++) { if (j < buffer.size()) { framelist += buffer.get(j); } framelist += ","; } framelist = framelist.replaceFirst(",$", ""); System.out.println( "\t\t" + newframe + "\t" + framelist + "\t\t" + (victim == null ? "" : victim)); } System.out.println("Total Number of Page Faults = " + faults); System.out.println("Total I/O Time Units = " + scetime); System.out.format("SC/SCE1 I/O Time Ratio = %.2f\n", ((float) scetime / (float) scrtime)); // Cleanup System.out.println(""); buffer = new ArrayList<Frame>(frames); faults = 0; index = 0; // SCE2 System.out.println("Second-Chance replacement extension 2 (" + frames + " frames):"); System.out.println("\tReference Page\tFrames\tReplaced Page"); scetime = 0; for (int i = 0; i < actions.length; i++) { String act = actions[i]; Frame newframe = null; Frame victim = null; // process new action if (act.contains("m")) { newframe = new Frame(Integer.valueOf(act.replace("m", ""))); newframe.setMod(true); } else { newframe = new Frame(Integer.valueOf(act)); } newframe.setRef(true); // search buffer for (Frame f : buffer) { if (f.id() == newframe.id()) { if (f.getMod()) { newframe.setMod(true); } buffer.set(buffer.indexOf(f), newframe); break; } } // if not found, add to buffer if (!buffer.contains(newframe)) { scetime += 1; if (buffer.size() < frames) { buffer.add(newframe); } else { boolean refpass = false; boolean modpass = false; int init = index; int count = 0; while (!buffer.contains(newframe)) { Frame f = buffer.get(index); if (!f.getRef() && !f.getMod()) { victim = f; buffer.set(index, newframe); scetime += (victim.getMod() ? 10 : 0); faults += 1; } else if (f.getRef() && !f.getMod() && count == 1) { victim = f; buffer.set(index, newframe); scetime += (victim.getMod() ? 10 : 0); faults += 1; } else if (!f.getRef() && f.getMod() && count == 2) { victim = f; buffer.set(index, newframe); scetime += (victim.getMod() ? 10 : 0); faults += 1; } else if (count >= 1) { f.setRef(false); } index = (index + 1) % frames; if (index == init) { if (count == 1) { count = 2; } else if (count == 2) { count = 0; } else { count = 1; } } } } } // print action String framelist = ""; for (int j = 0; j < frames; j++) { if (j < buffer.size()) { framelist += buffer.get(j); } framelist += ","; } framelist = framelist.replaceFirst(",$", ""); System.out.println( "\t\t" + newframe + "\t" + framelist + "\t\t" + (victim == null ? "" : victim)); } System.out.println("Total Number Of Page Faults = " + faults); System.out.println("Total I/O Time Units = " + scetime); System.out.format("SC/SCE2 I/O Time Ratio = %.2f\n", ((float) scetime / (float) scrtime)); System.out.println(""); } } catch (Exception e) { System.out.println(e.toString()); } }
/** The main method of the program. Create a test window and display it */ public static void main(String[] args) { Frame f = new Demo(); f.show(); }
RootWindow(Container container, Screen screen, Format[] format, Client c) { super(screen.rootId); rootwindow = container; client = c; screen.setRoot((Window) this); this.width = (short) (screen.width); this.height = (short) (screen.height); this.screen = screen; depth = screen.rootDepth; id = screen.rootId; type = DRAWABLE_WINDOW; x = y = 0; origin.x = 0; origin.y = 0; clss = (byte) InputOutput; for (int i = 0; i < format.length; i++) { if (format[i].depth == screen.rootDepth) { this.bitsPerPixel = format[i].bpp; } } setVisual(screen.rootVisual); setBackgroundIsPixel(); background.pixel = screen.white; setBorderIsPixel(); border.pixel = screen.black; borderWidth = 0; Resource.add(this); makeOptional(); attr &= ~(1 << 3); // cursorIsNone optional.cursor = Cursor.rootCursor; setColormap(screen.defaultColormap); // if(rootwindow instanceof JFrame){ // rootwindow.setSize(this.width+10, this.height+30); // ?? // } // else{ rootwindow.setSize(this.width, this.height); // } try { ddxwindow = (DDXWindow) (Window.dDXWindow.newInstance()); } catch (Exception e) { System.err.println(e); /*ddxwindow=new DDXWindowImp();*/ } ddxwindow.init(this); ddxwindow.setLocation(0, 0); if (rootwindow instanceof Frame) { // ((Frame)rootwindow).setLayout(null); ((Frame) rootwindow).setResizable(false); ((Frame) rootwindow).setMenuBar(null); ((Frame) rootwindow).add((java.awt.Component) ddxwindow); } else if (rootwindow instanceof Applet) { ((Applet) rootwindow).add((java.awt.Component) ddxwindow); } /* else if(rootwindow instanceof JFrame){ ((JFrame)rootwindow).getContentPane().setLayout(null); ((JFrame)rootwindow).setResizable(false); ((JFrame)rootwindow).setJMenuBar(null); ((JFrame)rootwindow).getContentPane().add((java.awt.Component)ddxwindow); } else if(rootwindow instanceof JWindow){ ((JWindow)rootwindow).getContentPane().setLayout(null); ((JWindow)rootwindow).getContentPane().add((java.awt.Component)ddxwindow); } else if (rootwindow instanceof JApplet){ ((JApplet)rootwindow).setJMenuBar(null); ((JApplet)rootwindow).getContentPane().add((java.awt.Component)ddxwindow); } */ else { rootwindow.add((java.awt.Component) ddxwindow); } if (screen.windowmode != WeirdX.InBrowser) { rootwindow.addNotify(); } else { rootwindow.setVisible(true); } ddxwindow.setVisible(true); { rootwindow.validate(); Insets insets = rootwindow.getInsets(); rootwindow.setSize( this.width + insets.left + insets.right, this.height + insets.top + insets.bottom); ddxwindow.setLocation(insets.left, insets.top); rootwindow.validate(); } ddxwindow.requestFocus(); Window.focus.win = id; Window.LOCK = rootwindow.getTreeLock(); Client.LOCK = rootwindow.getTreeLock(); Resource.LOCK = rootwindow.getTreeLock(); spriteTrace[0] = this; sprite.win = this; }
public boolean equals(Frame f) { return (this.id == f.id()); }