📄 pdfexportdialog.java
字号:
package fr.itris.glips.svgeditor.svgfile.export;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.border.*;import javax.swing.event.*;import com.lowagie.text.*;import java.util.*;import fr.itris.glips.svgeditor.*;/** * the class of the dialog used to choose the parameters of the pdf export action * * @author Jordi SUC */public class PDFExportDialog extends ExportDialog{ /** * the size of the pages */ protected com.lowagie.text.Rectangle pageSize=null; /** * whether the orientation is "portrait" */ protected boolean isPortrait=true; /** * the margins */ protected Insets margins=new Insets(0, 0, 0, 0); /** * information on the pdf file */ protected String title="", author="", subject="", keywords="", creator=""; /** * the constructor of the class * @param editor the editor * @param parentContainer the parent container */ public PDFExportDialog(SVGEditor editor, JFrame parentContainer) { super(editor, parentContainer); if(bundle!=null){ try{ exportDialogTitle=bundle.getString("labelpdfexport"); }catch (Exception ex){ex.printStackTrace();} } //setting the title of the dialog setTitle(exportDialogTitle); //handling the parameters panel parametersPanel.setLayout(new BoxLayout(parametersPanel, BoxLayout.Y_AXIS)); //getting the page parameters panel parametersPanel.add(getTabbedPane()); } protected JTabbedPane getTabbedPane() { JTabbedPane tabbedPane=new JTabbedPane(); //getting the labels String pageTabLabel="", infoTabLabel=""; if(bundle!=null){ try{ pageTabLabel=bundle.getString("labelexportpdftabpage"); infoTabLabel=bundle.getString("labelexportpdftabinfo"); }catch (Exception ex){} } //adding the tabs JPanel pageTab=getPageParametersPanel(); tabbedPane.addTab(pageTabLabel, pageTab); JPanel infoTab=getPageInformationPanel(); tabbedPane.addTab(infoTabLabel, infoTab); return tabbedPane; } /** * @return Returns the author. */ public String getAuthor() { return author; } /** * @return Returns the creator. */ public String getCreator() { return creator; } /** * @return Returns the isPortrait. */ public boolean isPortrait() { return isPortrait; } /** * @return Returns the keywords. */ public String getKeywords() { return keywords; } /** * @return Returns the margins. */ public Insets getMargins() { return margins; } /** * @return Returns the pageSize. */ public com.lowagie.text.Rectangle getPageSize() { return pageSize; } /** * @return Returns the subject. */ public String getSubject() { return subject; } /** * @return Returns the title. */ public String getTitle() { return title; } /** * @return the panel containing the widgets used to modify the parameters of the page */ protected JPanel getPageParametersPanel() { /***********creating the size chooser panel***************/ //getting the labels String exportSizeLabel="", predefLabel="", customLabel="", widthLabel="", heightLabel=""; if(bundle!=null){ try{ predefLabel=bundle.getString("labelexportpredefinedsize"); customLabel=bundle.getString("labelexportcustomsize"); exportSizeLabel=bundle.getString("labelexportsize"); widthLabel=bundle.getString("labelwidth"); heightLabel=bundle.getString("labelheight"); }catch (Exception ex){} } //creating the spinners that will be used to choose the custom size chooser final JSpinner widthSpinner=new JSpinner(), heightSpinner=new JSpinner(); SpinnerNumberModel widthSpinnerModel=new SpinnerNumberModel(0, 0, Double.MAX_VALUE, 1); SpinnerNumberModel heightSpinnerModel=new SpinnerNumberModel(0, 0, Double.MAX_VALUE, 1); widthSpinner.setModel(widthSpinnerModel); heightSpinner.setModel(heightSpinnerModel); ((JSpinner.DefaultEditor)widthSpinner.getEditor()).getTextField().setColumns(5); ((JSpinner.DefaultEditor)heightSpinner.getEditor()).getTextField().setColumns(5); //setting the listeners to the spinners widthSpinner.addChangeListener(new ChangeListener(){ public void stateChanged(ChangeEvent evt) { if(pageSize==null) { pageSize=new com.lowagie.text.Rectangle((float)((Double)widthSpinner.getValue()).doubleValue(), 0.0f); }else { pageSize=new com.lowagie.text.Rectangle((float)((Double)widthSpinner.getValue()).doubleValue(), pageSize.height()); } } }); heightSpinner.addChangeListener(new ChangeListener(){ public void stateChanged(ChangeEvent evt) { if(pageSize==null) { pageSize=new com.lowagie.text.Rectangle(0.0f, (float)((Double)heightSpinner.getValue()).doubleValue()); }else { pageSize=new com.lowagie.text.Rectangle(pageSize.width(), (float)((Double)heightSpinner.getValue()).doubleValue()); } } }); //creating the labels JLabel lbw=new JLabel(widthLabel.concat(" : ")), lbh=new JLabel(heightLabel.concat(" : ")), pxw=new JLabel("px"), pxh=new JLabel("px"); lbw.setHorizontalAlignment(SwingConstants.RIGHT); lbh.setHorizontalAlignment(SwingConstants.RIGHT); //getting the items for the combo of the predefined sizes PredefinedPageSizeItem[] items=PredefinedPageSizeItem.getItems(); //creating the combo box that will display the predefined types final JComboBox combo=new JComboBox(items); //adding a listener to the combo combo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if(combo.getSelectedItem()!=null) { //setting the new size try { pageSize=((PredefinedPageSizeItem)combo.getSelectedItem()).getSize(); }catch (Exception ex) {} } } }); //creating the radio buttons used to choose between a predefined and a personnalized size chooser final JRadioButton predefinedRadioButton=new JRadioButton(predefLabel), customRadioButton=new JRadioButton(customLabel); ButtonGroup buttonGroup=new ButtonGroup(); buttonGroup.add(predefinedRadioButton); buttonGroup.add(customRadioButton); //adding the listeners to the radio buttons ChangeListener radioButtonsListener=new ChangeListener() { /** * the last selected button */ private Object lastSelectedButton=null; public void stateChanged(ChangeEvent evt) { if(lastSelectedButton==null || (lastSelectedButton!=null && ! lastSelectedButton.equals(evt.getSource()))) { if(evt.getSource().equals(predefinedRadioButton) && predefinedRadioButton.isSelected()) { //enabling the combo box and disabling the spinners combo.setEnabled(true); widthSpinner.setEnabled(false); heightSpinner.setEnabled(false); try { //setting the new value for the combo if(combo.getSelectedItem()!=null) { combo.setSelectedItem(combo.getSelectedItem()); }else { combo.setSelectedItem(PredefinedPageSizeItem.getItem(PageSize.A4)); } //setting the new size pageSize=((PredefinedPageSizeItem)combo.getSelectedItem()).getSize(); }catch (Exception ex) {} }else if(evt.getSource().equals(customRadioButton) && customRadioButton.isSelected()){ //disabling the combo box and enabling the spinners combo.setEnabled(false); widthSpinner.setEnabled(true); heightSpinner.setEnabled(true); //setting the new value for the spinners pageSize=new com.lowagie.text.Rectangle( (float)((Double)widthSpinner.getValue()).doubleValue(), (float)((Double)heightSpinner.getValue()).doubleValue()); } lastSelectedButton=evt.getSource(); } } }; //adding the runnable to initialize the size chooser panel initializers.add(new Runnable() { public void run() { if(pageSize!=null) { //getting the combo item corresponding to the page size PredefinedPageSizeItem item=PredefinedPageSizeItem.getItem(pageSize); if(item!=null) { //enabling the combo box and disabling the spinners predefinedRadioButton.setSelected(true); //setting the new value for the combo combo.setSelectedItem(combo.getSelectedItem()); return; } } //disabling the combo box and enabling the spinners
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -