PrinterAttributesPanel.java
上传用户:xiekaiwei
上传日期:2015-07-04
资源大小:620k
文件大小:11k
源码类别:

Telnet客户端

开发平台:

Java

  1. package org.tn5250j.settings;
  2. /**
  3.  * Title: PrinterAttributesPanel
  4.  * Copyright:   Copyright (c) 2001
  5.  * Company:
  6.  * @author  Kenneth J. Pouncey
  7.  * @version 0.5
  8.  *
  9.  * Description:
  10.  *
  11.  * This program is free software; you can redistribute it and/or modify
  12.  * it under the terms of the GNU General Public License as published by
  13.  * the Free Software Foundation; either version 2, or (at your option)
  14.  * any later version.
  15.  *
  16.  * This program is distributed in the hope that it will be useful,
  17.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  * GNU General Public License for more details.
  20.  *
  21.  * You should have received a copy of the GNU General Public License
  22.  * along with this software; see the file COPYING.  If not, write to
  23.  * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  24.  * Boston, MA 02111-1307 USA
  25.  *
  26.  */
  27. import java.awt.*;
  28. import java.awt.event.*;
  29. import javax.swing.*;
  30. import java.awt.print.*;
  31. import org.tn5250j.tools.*;
  32. import org.tn5250j.SessionConfig;
  33. import org.tn5250j.gui.*;
  34. public class PrinterAttributesPanel extends AttributesPanel {
  35.    JCheckBox defaultPrinter;
  36.    JButton setPortAttributes;
  37.    JButton setLandAttributes;
  38.    Paper pappyPort;
  39.    Paper pappyLand;
  40.    JComboBox fontsList;
  41.    TN5250jFontsSelection fs;
  42.    public PrinterAttributesPanel(SessionConfig config ) {
  43.       super(config,"Printer");
  44.    }
  45.    /**Component initialization*/
  46.    public void initPanel() throws Exception  {
  47.       setLayout(new BorderLayout());
  48.       contentPane = new JPanel();
  49.       contentPane.setLayout(new BoxLayout(contentPane,BoxLayout.Y_AXIS));
  50.       add(contentPane,BorderLayout.NORTH);
  51.       // define ppPanel panel
  52.       JPanel ppp = new JPanel();
  53.       ppp.setBorder(BorderFactory.createTitledBorder(LangTool.getString("sa.print")));
  54.       defaultPrinter = new JCheckBox(LangTool.getString("sa.defaultPrinter"));
  55.       if (getStringProperty("defaultPrinter").equals("Yes"))
  56.          defaultPrinter.setSelected(true);
  57.       ppp.add(defaultPrinter);
  58.       //--- Create a printerJob object
  59.       PrinterJob printJob = PrinterJob.getPrinterJob ();
  60.       // will have to remember this for the next time.
  61.       //   Always set a page format before call setPrintable to
  62.       //   set the orientation.
  63.       PageFormat pf = printJob.defaultPage();
  64.       pappyPort = pf.getPaper();
  65.       pappyLand = pf.getPaper();
  66.       // Portrait paper parameters
  67.       if (getStringProperty("print.portWidth").length() != 0 &&
  68.             getStringProperty("print.portHeight").length() != 0 &&
  69.             getStringProperty("print.portImageWidth").length() != 0 &&
  70.             getStringProperty("print.portImageHeight").length() != 0 &&
  71.             getStringProperty("print.portImage.X").length() != 0 &&
  72.             getStringProperty("print.portImage.Y").length() != 0) {
  73.          pappyPort.setSize(Double.parseDouble(getStringProperty("print.portWidth")),
  74.                            Double.parseDouble(getStringProperty("print.portHeight")));
  75.          pappyPort.setImageableArea(Double.parseDouble(getStringProperty("print.portImage.X")),
  76.                            Double.parseDouble(getStringProperty("print.portImage.Y")),
  77.                            Double.parseDouble(getStringProperty("print.portImageWidth")),
  78.                            Double.parseDouble(getStringProperty("print.portImageHeight")));
  79.       }
  80.       // Landscape paper parameters
  81.       if (getStringProperty("print.landWidth").length() != 0 &&
  82.             getStringProperty("print.landHeight").length() != 0 &&
  83.             getStringProperty("print.landImageWidth").length() != 0 &&
  84.             getStringProperty("print.landImageHeight").length() != 0 &&
  85.             getStringProperty("print.landImage.X").length() != 0 &&
  86.             getStringProperty("print.landImage.Y").length() != 0) {
  87.          pappyLand.setSize(Double.parseDouble(getStringProperty("print.landWidth")),
  88.                            Double.parseDouble(getStringProperty("print.landHeight")));
  89.          pappyLand.setImageableArea(Double.parseDouble(getStringProperty("print.landImage.X")),
  90.                            Double.parseDouble(getStringProperty("print.landImage.Y")),
  91.                            Double.parseDouble(getStringProperty("print.landImageWidth")),
  92.                            Double.parseDouble(getStringProperty("print.landImageHeight")));
  93.       }
  94.       // define page panel
  95.       JPanel page = new JPanel();
  96.       page.setBorder(BorderFactory.createTitledBorder(
  97.                            LangTool.getString("sa.pageParameters")));
  98.       page.setLayout(new BorderLayout());
  99.       setPortAttributes = new JButton(LangTool.getString("sa.columns24"));
  100. setPortAttributes.addActionListener(new java.awt.event.ActionListener() {
  101. public void actionPerformed(ActionEvent e) {
  102. getPortraitAttributes();
  103. }
  104. });
  105.       setLandAttributes = new JButton(LangTool.getString("sa.columns132"));
  106. setLandAttributes.addActionListener(new java.awt.event.ActionListener() {
  107. public void actionPerformed(ActionEvent e) {
  108. getLandscapeAttributes();
  109. }
  110. });
  111.       // now create page dialog holder panel
  112.       JPanel pagePage = new JPanel();
  113.       pagePage.add(setPortAttributes);
  114.       pagePage.add(setLandAttributes);
  115.       page.add(pagePage,BorderLayout.NORTH);
  116.       // now create fonts selection
  117.       JPanel pageFont = new JPanel();
  118.       fs = new TN5250jFontsSelection();
  119.       if (getStringProperty("print.font").length() != 0) {
  120.          fs.setSelectedItem(getStringProperty("print.font"));
  121.       }
  122.       pageFont.add(fs);
  123.       page.add(pageFont,BorderLayout.SOUTH);
  124.       contentPane.add(ppp);
  125.       contentPane.add(page);
  126.    }
  127.    private void getPortraitAttributes() {
  128.       PrinterJob printJob = PrinterJob.getPrinterJob ();
  129.       PageFormat documentPageFormat = new PageFormat ();
  130.       documentPageFormat.setOrientation(PageFormat.PORTRAIT);
  131.       documentPageFormat.setPaper(pappyPort);
  132.       documentPageFormat = printJob.pageDialog (documentPageFormat);
  133.       pappyPort = documentPageFormat.getPaper();
  134.    }
  135.    private void getLandscapeAttributes() {
  136.       PrinterJob printJob = PrinterJob.getPrinterJob ();
  137.       PageFormat documentPageFormat = new PageFormat ();
  138.       documentPageFormat.setOrientation(PageFormat.LANDSCAPE);
  139.       documentPageFormat.setPaper(pappyLand);
  140.       documentPageFormat = printJob.pageDialog (documentPageFormat);
  141.       pappyLand = documentPageFormat.getPaper();
  142.    }
  143.    public void save() {
  144.    }
  145.    public void applyAttributes() {
  146.       if (defaultPrinter.isSelected()) {
  147.          changes.firePropertyChange(this,"defaultPrinter",
  148.                            getStringProperty("defaultPrinter"),
  149.                            "Yes");
  150.          setProperty("defaultPrinter","Yes");
  151.       }
  152.       else {
  153.          changes.firePropertyChange(this,"defaultPrinter",
  154.                            getStringProperty("defaultPrinter"),
  155.                            "No");
  156.          setProperty("defaultPrinter","No");
  157.       }
  158.       // portrait parameters
  159.       changes.firePropertyChange(this,"print.portWidth",
  160.                         getStringProperty("print.portWidth"),
  161.                         new Double(pappyPort.getWidth()));
  162.       setProperty("print.portWidth",Double.toString(pappyPort.getWidth()));
  163.       changes.firePropertyChange(this,"print.portImageWidth",
  164.                         getStringProperty("print.portImageWidth"),
  165.                         new Double(pappyPort.getImageableWidth()));
  166.       setProperty("print.portImageWidth",Double.toString(pappyPort.getImageableWidth()));
  167.       changes.firePropertyChange(this,"print.portHeight",
  168.                         getStringProperty("print.portHeight"),
  169.                         new Double(pappyPort.getHeight()));
  170.       setProperty("print.portHeight",Double.toString(pappyPort.getHeight()));
  171.       changes.firePropertyChange(this,"print.portImageHeight",
  172.                         getStringProperty("print.portImageHeight"),
  173.                         new Double(pappyPort.getImageableHeight()));
  174.       setProperty("print.portImageHeight",Double.toString(pappyPort.getImageableHeight()));
  175.       changes.firePropertyChange(this,"print.portImage.X",
  176.                         getStringProperty("print.portImage.X"),
  177.                         new Double(pappyPort.getImageableX()));
  178.       setProperty("print.portImage.X",Double.toString(pappyPort.getImageableX()));
  179.       changes.firePropertyChange(this,"print.portImage.Y",
  180.                         getStringProperty("print.portImage.Y"),
  181.                         new Double(pappyPort.getImageableY()));
  182.       setProperty("print.portImage.Y",Double.toString(pappyPort.getImageableY()));
  183.       // landscape parameters
  184.       changes.firePropertyChange(this,"print.landWidth",
  185.                         getStringProperty("print.landWidth"),
  186.                         new Double(pappyLand.getWidth()));
  187.       setProperty("print.landWidth",Double.toString(pappyLand.getWidth()));
  188.       changes.firePropertyChange(this,"print.landImageWidth",
  189.                         getStringProperty("print.landImageWidth"),
  190.                         new Double(pappyLand.getImageableWidth()));
  191.       setProperty("print.landImageWidth",Double.toString(pappyLand.getImageableWidth()));
  192.       changes.firePropertyChange(this,"print.landHeight",
  193.                         getStringProperty("print.landHeight"),
  194.                         new Double(pappyLand.getHeight()));
  195.       setProperty("print.landHeight",Double.toString(pappyLand.getHeight()));
  196.       changes.firePropertyChange(this,"print.landImageHeight",
  197.                         getStringProperty("print.landImageHeight"),
  198.                         new Double(pappyLand.getImageableHeight()));
  199.       setProperty("print.landImageHeight",Double.toString(pappyLand.getImageableHeight()));
  200.       changes.firePropertyChange(this,"print.landImage.X",
  201.                         getStringProperty("print.landImage.X"),
  202.                         new Double(pappyLand.getImageableX()));
  203.       setProperty("print.landImage.X",Double.toString(pappyLand.getImageableX()));
  204.       changes.firePropertyChange(this,"print.landImage.Y",
  205.                         getStringProperty("print.landImage.Y"),
  206.                         new Double(pappyLand.getImageableY()));
  207.       setProperty("print.landImage.Y",Double.toString(pappyLand.getImageableY()));
  208.       if (fs.getSelectedItem() != null) {
  209.          changes.firePropertyChange(this,"print.font",
  210.                            getStringProperty("print.font"),
  211.                            (String)fs.getSelectedItem());
  212.          setProperty("print.font",(String)fs.getSelectedItem());
  213.       }
  214.    }
  215. }