Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 11

Discussione: [java]JEditorPane

  1. #1

    [java]JEditorPane

    Salve...dopo estenuanti ricerche, grazie ad articoli e codice trovato e studiato, sono riuscito a creare un'applicazione che utilizza JEditorPane e visualizza una pagina web. Adesso dovrei stamparla e ho studiato anchecome si realizza. Il problema è che non stampa nulla.
    Creo il metodo print(Graphics g, PageFormat pf, int pi) che deve contenere il codice che è soggetto alla renderizzazione, dopo ciò dovrei vedere la pagina inizale di google su carta ma non succede nulla.
    Volevo sapere: che metodo chiamo di JeditorPane, all'interno di print, per far capire che è il contenuto di questo ultimo da renderizare e stampare????????


  2. #2
    Io ho avuto un problema simile e sono riuscito a stampare il contenuto html passando a print il valore ritornato da getGraphics() richiamato sul editorpane (o su uno dei suoi componenti interni ora non ricordo),il problema è che l'impaginazione del documento su un foglio A4 in questo modo fa schifo (me ne tagliava quasi metà sulla destra) e non c'è stato modo di farlo collaborare (ho anche postato sul forum per chiedere consigli) quindi ho abbandonato alla fine.
    Ciao
    Il centro dell'attenzione non è sempre un buon posto in cui trovarsi

    Mai discutere con uno stupido, la gente potrebbe non capire la differenza. (O. W.)

  3. #3
    esattamente cosa hai fatto.
    perchè ho provato anche io, ma il foglio esce bianco. la cartuccia è piena..forse non faccio bene qualcosa.

  4. #4
    Ora ricordo,per prova avevo usato il codice scritto dall'autore di un'articolo su mokabyte,che stampa il graphics di qualsiasi Component gli passi,si chiama Mario Fusco.Vai sul sito www.mokabyte .it e te lo cerchi.
    Il centro dell'attenzione non è sempre un buon posto in cui trovarsi

    Mai discutere con uno stupido, la gente potrebbe non capire la differenza. (O. W.)

  5. #5
    QuìPer l'esattezza
    Il centro dell'attenzione non è sempre un buon posto in cui trovarsi

    Mai discutere con uno stupido, la gente potrebbe non capire la differenza. (O. W.)

  6. #6
    No perdonami era questo il codice lascia perdere i miei ultimi due post.

    codice:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.print.*;
    
    /** A simple utility class that lets you very simply print
     *  an arbitrary component. Just pass the component to the
     *  PrintUtilities.printComponent. The component you want to
     *  print doesn't need a print method and doesn't have to
     *  implement any interface or do anything special at all.
     *  
    
    
     *  If you are going to be printing many times, it is marginally more 
     *  efficient to first do the following:
     *  <PRE>
     *    PrintUtilities printHelper = new PrintUtilities(theComponent);
     *  </PRE>
     *  then later do printHelper.print(). But this is a very tiny
     *  difference, so in most cases just do the simpler
     *  PrintUtilities.printComponent(componentToBePrinted).
     *
     *  7/99 Marty Hall, http://www.apl.jhu.edu/~hall/java/
     *  May be freely used or adapted.
     */
    
    public class PrintUtilities implements Printable {
      private Component componentToBePrinted;
    
      public static void printComponent(Component c) {
        new PrintUtilities(c).print();
      }
      
      public PrintUtilities(Component componentToBePrinted) {
        this.componentToBePrinted = componentToBePrinted;
      }
      
      public void print() {
        PrinterJob printJob = PrinterJob.getPrinterJob();
        printJob.setPrintable(this);
        if (printJob.printDialog())
          try {
            printJob.print();
          } catch(PrinterException pe) {
            System.out.println("Error printing: " + pe);
          }
      }
    
      public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
        if (pageIndex > 0) {
          return(NO_SUCH_PAGE);
        } else {
          Graphics2D g2d = (Graphics2D)g;
          g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
          disableDoubleBuffering(componentToBePrinted);
          componentToBePrinted.paint(g2d);
          enableDoubleBuffering(componentToBePrinted);
          return(PAGE_EXISTS);
        }
      }
    
      /** The speed and quality of printing suffers dramatically if
       *  any of the containers have double buffering turned on.
       *  So this turns if off globally.
       *  @see enableDoubleBuffering
       */
      public static void disableDoubleBuffering(Component c) {
        RepaintManager currentManager = RepaintManager.currentManager(c);
        currentManager.setDoubleBufferingEnabled(false);
      }
    
      /** Re-enables double buffering globally. */
      
      public static void enableDoubleBuffering(Component c) {
        RepaintManager currentManager = RepaintManager.currentManager(c);
        currentManager.setDoubleBufferingEnabled(true);
      }
    }
    Il centro dell'attenzione non è sempre un buon posto in cui trovarsi

    Mai discutere con uno stupido, la gente potrebbe non capire la differenza. (O. W.)

  7. #7
    Grazie cmq ho trovato penso qualcosa di serio e devi provarlo.....forse risolve sia i miei che i tuoi problemi

    è un browser che visualizza perfettamente l'HTML e stampa....il problema e che mi sn accorto pure che la stampante non ha più inchiostro(mi sento uno stupido) è sn pure convinto cmq che il mio codice nn vada.

    Il link:
    http://java.sun.com/products/java-me....html#pageable


    C'è qualche fesseria di errore.

    il prossimo post contiene il codice da me sistemato.

  8. #8
    Se puoi provalo è fammi sapere

    CLASSE VISTA


    /*
    * Vista.java
    *
    * Created on 24 ottobre 2004, 11.21
    */

    package javaapplication4;


    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.geom.Point2D;
    import java.awt.print.Pageable;
    import java.awt.print.PageFormat;
    import java.awt.print.Printable;
    import java.awt.print.PrinterException;
    /**
    * A simple Pageable class that can
    * split a large drawing canvas over multiple
    * pages.
    *
    * The pages in a canvas are laid out on
    * pages going left to right and then top
    * to bottom.
    */
    public class Vista implements Pageable {


    private int mNumPagesX;
    private int mNumPagesY;
    private int mNumPages;
    private Printable mPainter;
    private PageFormat mFormat;
    /**
    * Create a java.awt.Pageable that will print
    * a canvas over as many pages as are needed.
    * A Vista can be passed to PrinterJob.setPageable.
    *
    * @param width The width, in 1/72nds of an inch,
    * of the vist's canvas.
    *
    * @param height The height, in 1/72nds of an inch,
    * of the vista's canvas.
    *
    * @param painter The object that will drawn the contents
    * of the canvas.
    *
    * @param format The description of the pages on to which
    * the canvas will be drawn.
    */
    public Vista(float width, float height, Printable painter, PageFormat format) {


    setPrintable(painter);
    setPageFormat(format);
    setSize(width, height);

    }
    /**
    * Create a vista over a canvas whose width and height
    * are zero and whose Printable and PageFormat are null.
    */

    protected Vista() {
    }
    /**
    * Set the object responsible for drawing the canvas.
    */

    protected void setPrintable(Printable painter) {


    mPainter = painter;

    }
    /**
    * Set the page format for the pages over which the
    * canvas will be drawn.
    */

    protected void setPageFormat(PageFormat pageFormat) {


    mFormat = pageFormat;

    }
    /**
    * Set the size of the canvas to be drawn.
    *
    * @param width The width, in 1/72nds of an inch, of
    * the vist's canvas.
    *
    * @param height The height, in 1/72nds of an inch, of
    * the vista's canvas.
    */

    protected void setSize(float width, float height) {


    mNumPagesX = (int) ((width + mFormat.getImageableWidth() - 1)/ mFormat.getImageableWidth());
    mNumPagesY = (int) ((height + mFormat.getImageableHeight() - 1)/ mFormat.getImageableHeight());
    mNumPages = mNumPagesX * mNumPagesY;

    }
    /**
    * Returns the number of pages over which the canvas
    * will be drawn.
    */
    public int getNumberOfPages() {

    return mNumPages;

    }
    protected PageFormat getPageFormat() {

    return mFormat;

    }
    /**
    * Returns the PageFormat of the page specified by
    * pageIndex. For a Vista the PageFormat
    * is the same for all pages.
    *
    * @param pageIndex the zero based index of the page whose
    * PageFormat is being requested
    * @return the PageFormat describing the size and
    * orientation.
    * @exception IndexOutOfBoundsException
    * the Pageable does not contain the requested
    * page.
    */
    public PageFormat getPageFormat(int pageIndex) throws IndexOutOfBoundsException {


    if (pageIndex >= mNumPages) {

    throw new IndexOutOfBoundsException();

    }
    return getPageFormat();

    }
    /**
    * Returns the <code>Printable</code> instance responsible for
    * rendering the page specified by <code>pageIndex</code>.
    * In a Vista, all of the pages are drawn with the same
    * Printable. This method however creates
    * a Printable which calls the canvas's
    * Printable. This new Printable
    * is responsible for translating the coordinate system
    * so that the desired part of the canvas hits the page.
    *
    * The Vista's pages cover the canvas by going left to
    * right and then top to bottom. In order to change this
    * behavior, override this method.
    *
    * @param pageIndex the zero based index of the page whose
    * Printable is being requested
    * @return the Printable that renders the page.
    * @exception IndexOutOfBoundsException
    * the Pageable does not contain the requested
    * page.
    */
    public Printable getPrintable(int pageIndex) throws IndexOutOfBoundsException {


    if (pageIndex >= mNumPages) {

    throw new IndexOutOfBoundsException();

    }
    double originX = (pageIndex % mNumPagesX) * mFormat.getImageableWidth();
    double originY = (pageIndex / mNumPagesX) * mFormat.getImageableHeight();
    Point2D.Double origin = new Point2D.Double(originX, originY);
    return new TranslatedPrintable(mPainter, origin);

    }
    /**
    * This inner class's sole responsibility is to translate
    * the coordinate system before invoking a canvas's
    * painter. The coordinate system is translated in order
    * to get the desired portion of a canvas to line up with
    * the top of a page.
    */
    public static final class TranslatedPrintable implements Printable {


    /**
    * The object that will draw the canvas.
    */
    private Printable mPainter;
    /**
    * The upper-left corner of the part of the canvas
    * that will be displayed on this page. This corner
    * is lined up with the upper-left of the imageable
    * area of the page.
    */
    private Point2D mOrigin;
    /**
    * Create a new Printable that will translate
    * the drawing done by painter on to the
    * imageable area of a page.
    *
    * @param painter The object responsible for drawing
    * the canvas
    *
    * @param origin The point in the canvas that will be
    * mapped to the upper-left corner of
    * the page's imageable area.
    */
    public TranslatedPrintable(Printable painter, Point2D origin) {


    mPainter = painter;
    mOrigin = origin;

    }
    /**
    * Prints the page at the specified index into the specified
    * {@link Graphics} context in the specified
    * format. A PrinterJob calls the
    * Printableinterface to request that a page be
    * rendered into the context specified by
    * graphics. The format of the page to be drawn is
    * specified by pageFormat. The zero based index
    * of the requested page is specified by pageIndex.
    * If the requested page does not exist then this method returns
    * NO_SUCH_PAGE; otherwise PAGE_EXISTS is returned.
    * The Graphics class or subclass implements the
    * {@link PrinterGraphics} interface to provide additional
    * information. If the Printable object
    * aborts the print job then it throws a {@link PrinterException}.
    * @param graphics the context into which the page is drawn
    * @param pageFormat the size and orientation of the page being drawn
    * @param pageIndex the zero based index of the page to be drawn
    * @return PAGE_EXISTS if the page is rendered successfully
    * or NO_SUCH_PAGE if pageIndex specifies a
    * non-existent page.
    * @exception java.awt.print.PrinterException
    * thrown when the print job is terminated.
    */
    public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {


    Graphics2D g2 = (Graphics2D) graphics;
    g2.translate(-mOrigin.getX(), -mOrigin.getY());
    mPainter.print(g2, pageFormat, 1);
    return PAGE_EXISTS;

    }

    }

    }

  9. #9
    CLASSE JComponentVista

    /*
    * JComponentVista.java
    *
    * Created on 24 ottobre 2004, 11.20
    */

    package javaapplication4;



    import java.awt.*;
    import java.awt.print.*;
    import javax.swing.*;
    public class JComponentVista extends Vista implements Printable {

    private static final boolean SYMMETRIC_SCALING = true;
    private static final boolean ASYMMETRIC_SCALING = false;
    private double mScaleX;
    private double mScaleY;
    /**
    * The Swing component to print.
    */
    private JComponent mComponent;
    /**
    * Create a Pageable that can print a
    * Swing JComponent over multiple pages.
    *
    * @param c The swing JComponent to be printed.
    *
    * @param format The size of the pages over which
    * the componenent will be printed.
    */
    public JComponentVista(JComponent c, PageFormat format) {
    setPageFormat(format);
    setPrintable(this);
    setComponent(c);
    /* Tell the Vista we subclassed the size of the canvas.
    */
    Rectangle componentBounds = c.getBounds(null);
    setSize(componentBounds.width, componentBounds.height);
    setScale(1, 1);
    }

    protected void setComponent(JComponent c) {
    mComponent = c;
    }

    protected void setScale(double scaleX, double scaleY) {
    mScaleX = scaleX;
    mScaleY = scaleY;
    }

    public void scaleToFitX() {
    PageFormat format = getPageFormat();
    Rectangle componentBounds = mComponent.getBounds(null);
    double scaleX = format.getImageableWidth() /componentBounds.width;
    double scaleY = scaleX;
    if (scaleX < 1) {
    setSize( (float) format.getImageableWidth(),
    (float) (componentBounds.height * scaleY));
    setScale(scaleX, scaleY);
    }
    }

    public void scaleToFitY() {
    PageFormat format = getPageFormat();
    Rectangle componentBounds = mComponent.getBounds(null);
    double scaleY = format.getImageableHeight() /componentBounds.height;
    double scaleX = scaleY;
    if (scaleY < 1) {
    setSize( (float) (componentBounds.width * scaleX),(float) format.getImageableHeight());
    setScale(scaleX, scaleY);
    }
    }

    public void scaleToFit(boolean useSymmetricScaling) {
    PageFormat format = getPageFormat();
    Rectangle componentBounds = mComponent.getBounds(null);
    double scaleX = format.getImageableWidth() /componentBounds.width;
    double scaleY = format.getImageableHeight() /componentBounds.height;
    System.out.println("Scale: " + scaleX + " " + scaleY);
    if (scaleX < 1 || scaleY < 1) {
    if (useSymmetricScaling) {
    if (scaleX < scaleY) {
    scaleY = scaleX;
    } else {
    scaleX = scaleY;
    }
    }
    setSize( (float) (componentBounds.width * scaleX), (float) (componentBounds.height * scaleY) );
    setScale(scaleX, scaleY);
    }
    }

    public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
    Graphics2D g2 = (Graphics2D) graphics;
    g2.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
    Rectangle componentBounds = mComponent.getBounds(null);
    g2.translate(-componentBounds.x, -componentBounds.y);
    g2.scale(mScaleX, mScaleY);
    boolean wasBuffered = mComponent.isDoubleBuffered();
    mComponent.paint(g2);
    mComponent.setDoubleBuffered(wasBuffered);
    return PAGE_EXISTS;
    }

    }

  10. #10
    CLASSE JBrowser

    /*
    * JBrowser.java
    *
    * Created on 24 ottobre 2004, 11.19
    */

    package javaapplication4;


    import java.awt.*;
    import java.awt.event.*;
    import java.awt.print.*;
    import java.awt.Window;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javaapplication4.JComponentVista;

    /**
    * Uses JFrame to create a simple browser with printing.
    * User passes String URL (e.g., http://www.rbi.com)
    * to set opening location. User then may follow
    * hyperlinks or type new preferred location into
    * provided JTextField.
    *
    * Scaling options are demonstrated in this
    * example. Scaling options may be set from a
    * submenu in the File menu or by specified KeyStroke.
    * A second menu track nn websites, which user can
    * reselect as destination using mouse.
    */



    public class JBrowser extends JFrame {
    private static final int kNumSites = 20; //number of sites listed in JMenu "Last 20"
    private static final int kDefaultX = 640;
    private static final int kDefaultY = 480;
    private static final int prefScale = 0;

    private static final String kScale2Label = "2X Scale";
    private static final String kScaleFitLabel = "Scale to Fit";
    private static final String kScaleHalfLabel = "1/2 Scale";
    private static final String kScaleOffLabel = "Scaling Off";
    private static final String kScaleXLabel = "Scale by Width";
    private static final String kScaleYLabel = "Scale by Length";

    private JEditorPane mainPane;
    private String path;
    private JButton goButton = new JButton("Go");
    private JComponentVista vista;
    private JMenu fileMenu = new JMenu("File", true);
    private JMenu prefMenu = new JMenu("Print Preferences", true);
    private JMenu siteMenu = new JMenu("Last 20", true);
    private JRadioButtonMenuItem scale2RadioBut = new JRadioButtonMenuItem(kScale2Label);
    private JRadioButtonMenuItem scaleFitRadioBut = new JRadioButtonMenuItem(kScaleFitLabel);
    private JRadioButtonMenuItem scaleHalfRadioBut = new JRadioButtonMenuItem(kScaleHalfLabel);
    private JRadioButtonMenuItem scaleOffRadioBut = new JRadioButtonMenuItem(kScaleOffLabel, true);
    private JRadioButtonMenuItem scaleXRadioBut = new JRadioButtonMenuItem(kScaleXLabel);
    private JRadioButtonMenuItem scaleYRadioBut = new JRadioButtonMenuItem(kScaleYLabel);
    private JTextField pathField = new JTextField(30);
    private Vector siteMIVector = new Vector();

    public static void main(String[] args) {
    new JBrowser("http://www.google.it");
    }

    public JBrowser(String url) {
    super("JBrowser HTML Printing Demo");
    path = url;
    addSite(path);

    try {
    mainPane = new JEditorPane(path);
    } catch (IOException ex) {
    ex.printStackTrace(System.err);
    System.exit(1);
    }

    JMenuBar menuBar = new JMenuBar();
    JPanel navPanel = new JPanel();
    JMenuItem printMI = new JMenuItem("Print");
    JMenuItem exitMI = new JMenuItem("Exit");

    printMI.setAccelerator(KeyStroke.getKeyStroke(KeyE vent.VK_P, Event.CTRL_MASK));
    exitMI.setAccelerator(KeyStroke.getKeyStroke(KeyEv ent.VK_X, Event.CTRL_MASK));

    scale2RadioBut.setAccelerator(KeyStroke.getKeyStro ke(KeyEvent.VK_D, Event.CTRL_MASK));
    scaleFitRadioBut.setAccelerator(KeyStroke.getKeySt roke(KeyEvent.VK_F, Event.CTRL_MASK));
    scaleHalfRadioBut.setAccelerator(KeyStroke.getKeyS troke(KeyEvent.VK_H, Event.CTRL_MASK));
    scaleOffRadioBut.setAccelerator(KeyStroke.getKeySt roke(KeyEvent.VK_O, Event.CTRL_MASK));
    scaleXRadioBut.setAccelerator(KeyStroke.getKeyStro ke(KeyEvent.VK_W, Event.CTRL_MASK));
    scaleYRadioBut.setAccelerator(KeyStroke.getKeyStro ke(KeyEvent.VK_L, Event.CTRL_MASK));

    printMI.addActionListener(new printMIListener());
    exitMI.addActionListener(new exitMIListener());

    scaleXRadioBut.addActionListener(new scaleXListener());
    scaleYRadioBut.addActionListener(new scaleYListener());
    scaleFitRadioBut.addActionListener(new scaleFitListener());
    scaleHalfRadioBut.addActionListener(new scaleHalfListener());

    scale2RadioBut.addActionListener(new scale2Listener());

    pathField.addActionListener(new pathFieldListener());
    pathField.setText(path);
    goButton.addActionListener(new pathFieldListener());

    ButtonGroup scaleSetGroup = new ButtonGroup();
    scaleSetGroup.add(scale2RadioBut);
    scaleSetGroup.add(scaleFitRadioBut);
    scaleSetGroup.add(scaleHalfRadioBut);
    scaleSetGroup.add(scaleOffRadioBut);
    scaleSetGroup.add(scaleXRadioBut);
    scaleSetGroup.add(scaleYRadioBut);

    prefMenu.add(scaleXRadioBut);
    prefMenu.add(scaleYRadioBut);
    prefMenu.add(scaleFitRadioBut);
    prefMenu.add(scaleHalfRadioBut);
    prefMenu.add(scale2RadioBut);
    prefMenu.addSeparator();
    prefMenu.add(scaleOffRadioBut);

    fileMenu.add(prefMenu);
    fileMenu.add(printMI);
    fileMenu.addSeparator();
    fileMenu.add(exitMI);

    menuBar.add(fileMenu);
    menuBar.add(siteMenu);
    menuBar.add(pathField);
    menuBar.add(goButton);


    mainPane.setEditable(false);
    mainPane.addHyperlinkListener(new linkListener());

    vista = new JComponentVista(mainPane, new PageFormat());

    //addWindowListener(new BasicWindowMonitor());
    setContentPane(new JScrollPane(mainPane));
    setVisible(true);

    setJMenuBar(menuBar);
    setSize(kDefaultX, kDefaultY);
    setVisible(true);
    }

    /*
    * addSite method takes the String url and adds it to the
    * Vector siteMIVector and the JMenu siteMenu.
    */
    public void addSite(String url) {
    boolean beenThere = false;

    /*
    * Cycle through the contents of the siteMenu, comparing
    * their labels to the string to determine if there is
    * redundancy.
    */
    for(int i=0; i<siteMenu.getItemCount() && !beenThere; i++) {
    JMenuItem site = siteMenu.getItem(i);
    /*
    * The String url, is compared to the labels of the
    * JMenuItems in already stored in siteMIVector. If
    * the string matches an existing label, the older
    * redundant element, at i, is removed. The new JMenuItem
    * site is inserted in the Vector at 0. The updateMenu
    * method is called to update the "Last nn" menu accordingly
    * and the "beenThere" boolean trigger is set TRUE.
    */
    if (site.getText().equals(url)) {
    siteMIVector.removeElementAt(i);
    siteMIVector.insertElementAt(site, 0);
    updateMenu(siteMenu);
    beenThere = true;
    }
    }
    /*
    * If the new JMenuItem site has a unique string, then the
    * addSite method handles it as follows.
    */
    if (!beenThere) {
    /*
    * If the "Last nn" menu has reached kNumSites capacity,
    * the oldest JMenuItem is removed from the vector, enabling
    * storage for the new menu item and maintaining the specified
    * capacity of the "Last nn" menu.
    */
    if (siteMenu.getItemCount() >= kNumSites){
    siteMIVector.removeElementAt(siteMIVector.size()-1);
    }

    /*
    * A new JMenuItem is created and a siteMenuListener added.
    * It is added to the vector then the menu is updated.
    */
    JMenuItem site = new JMenuItem(url);
    site.addActionListener(new siteMenuListener(url));
    siteMIVector.insertElementAt(site, 0);
    System.out.println("\n Connected to "+ url);
    updateMenu(siteMenu);
    }
    }

    public void updateMenu(JMenu menu) {
    menu.removeAll();
    for(int i=0; i<siteMIVector.size(); i++) {
    JMenuItem mi = (JMenuItem)siteMIVector.elementAt(i);
    menu.add(mi);
    }
    }

    /*
    *
    * The ActionListener methods
    *
    */
    public class exitMIListener implements ActionListener {
    public void actionPerformed(ActionEvent evt) {
    System.out.println("\n Killing JBrowser...");
    System.out.println(" ...AHHHHHHHHHhhhhhhh...ya got me...ugh");
    System.exit(0);
    }
    }

    public class linkListener implements HyperlinkListener {
    public void hyperlinkUpdate(HyperlinkEvent ev) {
    try {
    if (ev.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
    mainPane.setPage(ev.getURL());
    path = ev.getURL().toString();
    pathField.setText(path);
    addSite(path);
    }
    } catch (IOException ex) {
    ex.printStackTrace(System.err);
    }
    }
    }

    public class pathFieldListener implements ActionListener {
    public void actionPerformed(ActionEvent evt) {
    System.out.println("\n Switching from "+path+" to "+pathField.getText()+".");
    path = pathField.getText();
    try {
    mainPane.setPage(path);
    } catch (IOException ex){
    ex.printStackTrace(System.err);
    }

    if (!path.equals("")) {
    addSite(path);
    }
    }
    }

    public class printMIListener implements ActionListener {
    public void actionPerformed(ActionEvent evt) {
    PrinterJob pj = PrinterJob.getPrinterJob();
    pj.setPageable(vista);
    try {
    if (pj.printDialog()) {
    pj.print();
    }
    } catch (PrinterException e) {
    System.out.println(e);
    }
    }
    }

    public class scale2Listener implements ActionListener {
    public void actionPerformed(ActionEvent evt) {
    vista = new JComponentVista(mainPane, new PageFormat());
    vista.setScale(2.0, 2.0);
    }
    }

    public class scaleFitListener implements ActionListener {
    public void actionPerformed(ActionEvent evt) {
    vista = new JComponentVista(mainPane, new PageFormat());
    vista.scaleToFit(false);
    }
    }

    public class scaleHalfListener implements ActionListener {
    public void actionPerformed(ActionEvent evt) {
    vista = new JComponentVista(mainPane, new PageFormat());
    vista.setScale(0.5, 0.5);
    }
    }

    public class scaleOffListener implements ActionListener {
    public void actionPerformed(ActionEvent evt) {
    vista = new JComponentVista(mainPane, new PageFormat());
    }
    }

    public class scaleXListener implements ActionListener {
    public void actionPerformed(ActionEvent evt) {
    vista = new JComponentVista(mainPane, new PageFormat());
    vista.scaleToFitX();
    }
    }

    public class scaleYListener implements ActionListener {
    public void actionPerformed(ActionEvent evt) {
    vista = new JComponentVista(mainPane, new PageFormat());
    vista.scaleToFitY();
    }
    }

    public class siteMenuListener implements ActionListener {
    private String site;

    public siteMenuListener(String url) {
    site = url;
    }

    public void actionPerformed(ActionEvent evt) {
    System.out.println("\n Switching from "+path+" to "+site+".");
    path = site;
    try {
    mainPane.setPage(path);
    } catch (IOException ex){
    ex.printStackTrace(System.err);
    }

    if (!path.equals("")) {
    addSite(path);
    }

    pathField.setText(path);
    }
    }
    }



Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.