📄 pdfexportdialog.java
字号:
customRadioButton.setSelected(true); widthSpinner.setValue(exportSize.x); heightSpinner.setValue(exportSize.y); } }); //adding the listener to the radio button predefinedRadioButton.addChangeListener(radioButtonsListener); customRadioButton.addChangeListener(radioButtonsListener); //creating and filling the panel of the size chooser JPanel sizeChooserPanel=new JPanel(); JPanel spinnerWidthPanel=new JPanel(); spinnerWidthPanel.setLayout(new BorderLayout(2, 0)); spinnerWidthPanel.add(widthSpinner, BorderLayout.CENTER); spinnerWidthPanel.add(pxw, BorderLayout.EAST); JPanel spinnerHeightPanel=new JPanel(); spinnerHeightPanel.setLayout(new BorderLayout(2, 0)); spinnerHeightPanel.add(heightSpinner, BorderLayout.CENTER); spinnerHeightPanel.add(pxh, BorderLayout.EAST); //setting the layout GridBagLayout gridBag=new GridBagLayout(); GridBagConstraints c=new GridBagConstraints(); sizeChooserPanel.setLayout(gridBag); c.fill=GridBagConstraints.HORIZONTAL; //adding the radio buttons c.insets=new Insets(0, 0, 0, 10); c.anchor=GridBagConstraints.WEST; c.gridwidth=2; gridBag.setConstraints(customRadioButton, c); sizeChooserPanel.add(customRadioButton); c.insets=new Insets(0, 10, 0, 0); c.anchor=GridBagConstraints.WEST; c.gridwidth=GridBagConstraints.REMAINDER; gridBag.setConstraints(predefinedRadioButton, c); sizeChooserPanel.add(predefinedRadioButton); //adding the custom size chooser widgets c.insets=new Insets(0, 25, 0, 0); c.anchor=GridBagConstraints.EAST; c.gridwidth=1; gridBag.setConstraints(lbw, c); sizeChooserPanel.add(lbw); c.insets=new Insets(0, 0, 0, 0); c.anchor=GridBagConstraints.WEST; c.gridwidth=1; gridBag.setConstraints(spinnerWidthPanel, c); sizeChooserPanel.add(spinnerWidthPanel); //adding the combo box c.insets=new Insets(0, 35, 0, 0); c.gridwidth=GridBagConstraints.REMAINDER; gridBag.setConstraints(combo, c); sizeChooserPanel.add(combo); //adding the predefined size chooser widgets c.insets=new Insets(0, 25, 0, 0); c.anchor=GridBagConstraints.EAST; c.gridwidth=1; gridBag.setConstraints(lbh, c); sizeChooserPanel.add(lbh); c.insets=new Insets(0, 0, 0, 0); c.anchor=GridBagConstraints.WEST; c.gridwidth=1; gridBag.setConstraints(spinnerHeightPanel, c); sizeChooserPanel.add(spinnerHeightPanel); //adding an empty panel JPanel emptyPanel=new JPanel(); c.insets=new Insets(0, 35, 0, 0); c.gridwidth=GridBagConstraints.REMAINDER; gridBag.setConstraints(emptyPanel, c); sizeChooserPanel.add(emptyPanel); //setting the border of the size chooser panel sizeChooserPanel.setBorder(new CompoundBorder( new TitledBorder(exportSizeLabel), new EmptyBorder(0, 0, 4, 0))); /***********creating the orientation panel***************/ //getting the labels String orientationLabel="", portraitLabel="", landscapeLabel=""; if(bundle!=null){ try{ orientationLabel=bundle.getString("labelexportorientation"); portraitLabel=bundle.getString("labelexportportrait"); landscapeLabel=bundle.getString("labelexportlandscape"); }catch (Exception ex){} } //creating the radio buttons ButtonGroup orientButtonGroup=new ButtonGroup(); final JRadioButton portraitRadioButton=new JRadioButton(portraitLabel), landscapeRadioButton=new JRadioButton(landscapeLabel); orientButtonGroup.add(portraitRadioButton); orientButtonGroup.add(landscapeRadioButton); portraitRadioButton.setSelected(true); //adding the listener to the radio buttons ActionListener orientationRadioButtonListener=new ActionListener() { public void actionPerformed(ActionEvent evt) { isPortrait=evt.equals(portraitRadioButton); } }; portraitRadioButton.addActionListener(orientationRadioButtonListener); landscapeRadioButton.addActionListener(orientationRadioButtonListener); //creating the orientation panel JPanel orientationPanel=new JPanel(); orientationPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); //the panel containing the radio buttons JPanel radioButtonsPanel=new JPanel(); radioButtonsPanel.setLayout(new BoxLayout(radioButtonsPanel, BoxLayout.Y_AXIS)); radioButtonsPanel.add(portraitRadioButton); radioButtonsPanel.add(landscapeRadioButton); orientationPanel.add(radioButtonsPanel); //setting the border of the orientation panel orientationPanel.setBorder(new TitledBorder(orientationLabel)); /***********creating the margin panel***************/ //getting the labels String marginLabel="", topLabel="", bottomLabel="", leftLabel="", rightLabel=""; if(bundle!=null){ try{ marginLabel=bundle.getString("labelexportmargin"); topLabel=bundle.getString("labelexportmargintop"); bottomLabel=bundle.getString("labelexportmarginbottom"); leftLabel=bundle.getString("labelexportmarginleft"); rightLabel=bundle.getString("labelexportmarginright"); }catch (Exception ex){} } //creating the spinners that will be used to choose the margins final JSpinner topSpinner=new JSpinner(), bottomSpinner=new JSpinner(), leftSpinner=new JSpinner(), rightSpinner=new JSpinner(); SpinnerNumberModel topSpinnerModel=new SpinnerNumberModel(0, 0, Double.MAX_VALUE, 1), bottomSpinnerModel=new SpinnerNumberModel(0, 0, Double.MAX_VALUE, 1), leftSpinnerModel=new SpinnerNumberModel(0, 0, Double.MAX_VALUE, 1), rightSpinnerModel=new SpinnerNumberModel(0, 0, Double.MAX_VALUE, 1); topSpinner.setModel(topSpinnerModel); bottomSpinner.setModel(bottomSpinnerModel); leftSpinner.setModel(leftSpinnerModel); rightSpinner.setModel(rightSpinnerModel); ((JSpinner.DefaultEditor)topSpinner.getEditor()).getTextField().setColumns(3); ((JSpinner.DefaultEditor)bottomSpinner.getEditor()).getTextField().setColumns(3); ((JSpinner.DefaultEditor)leftSpinner.getEditor()).getTextField().setColumns(3); ((JSpinner.DefaultEditor)rightSpinner.getEditor()).getTextField().setColumns(3); //setting the listeners to the spinners ChangeListener changeListener=new ChangeListener(){ public void stateChanged(ChangeEvent evt) { int value=(int)((Double)widthSpinner.getValue()).doubleValue(); if(evt.getSource().equals(topSpinner)) { margins.top=value; }else if(evt.getSource().equals(bottomSpinner)) { margins.bottom=value; }else if(evt.getSource().equals(leftSpinner)) { margins.left=value; }else if(evt.getSource().equals(rightSpinner)) { margins.right=value; } } }; topSpinner.addChangeListener(changeListener); bottomSpinner.addChangeListener(changeListener); leftSpinner.addChangeListener(changeListener); rightSpinner.addChangeListener(changeListener); //creating the jlabels for each spinner JLabel topLbl=new JLabel(topLabel+" : "), bottomLbl=new JLabel(bottomLabel+" : "), leftLbl=new JLabel(leftLabel+" : "), rightLbl=new JLabel(rightLabel+" : "), topPx=new JLabel("px"), bottomPx=new JLabel("px"), leftPx=new JLabel("px"), rightPx=new JLabel("px"); topLbl.setHorizontalAlignment(SwingConstants.RIGHT); bottomLbl.setHorizontalAlignment(SwingConstants.RIGHT); leftLbl.setHorizontalAlignment(SwingConstants.RIGHT); rightLbl.setHorizontalAlignment(SwingConstants.RIGHT); //creating the margins panel JPanel marginsPanel=new JPanel(); GridBagLayout mgGridBag=new GridBagLayout(); marginsPanel.setLayout(mgGridBag); GridBagConstraints cs=new GridBagConstraints(); cs.fill=GridBagConstraints.HORIZONTAL; cs.gridwidth=1; cs.insets=new Insets(0, 0, 2, 0); cs.anchor=GridBagConstraints.EAST; mgGridBag.setConstraints(topLbl, cs); marginsPanel.add(topLbl); cs.anchor=GridBagConstraints.WEST; mgGridBag.setConstraints(topSpinner, cs); marginsPanel.add(topSpinner); cs.anchor=GridBagConstraints.WEST; cs.insets=new Insets(0, 2, 2, 5); mgGridBag.setConstraints(topPx, cs); marginsPanel.add(topPx); cs.anchor=GridBagConstraints.EAST; cs.insets=new Insets(0, 5, 2, 0); mgGridBag.setConstraints(bottomLbl, cs); marginsPanel.add(bottomLbl); cs.anchor=GridBagConstraints.WEST; cs.insets=new Insets(0, 0, 2, 0); mgGridBag.setConstraints(bottomSpinner, cs); marginsPanel.add(bottomSpinner); cs.gridwidth=GridBagConstraints.REMAINDER; cs.insets=new Insets(0, 2, 2, 0); cs.anchor=GridBagConstraints.WEST; mgGridBag.setConstraints(bottomPx, cs); marginsPanel.add(bottomPx); cs.gridwidth=1; cs.insets=new Insets(2, 0, 0, 0); cs.anchor=GridBagConstraints.EAST; mgGridBag.setConstraints(leftLbl, cs); marginsPanel.add(leftLbl); cs.anchor=GridBagConstraints.WEST; mgGridBag.setConstraints(leftSpinner, cs); marginsPanel.add(leftSpinner); cs.anchor=GridBagConstraints.WEST; cs.insets=new Insets(2, 2, 0, 5); mgGridBag.setConstraints(leftPx, cs); marginsPanel.add(leftPx); cs.anchor=GridBagConstraints.EAST; cs.insets=new Insets(2, 5, 0, 0); mgGridBag.setConstraints(rightLbl, cs); marginsPanel.add(rightLbl); cs.anchor=GridBagConstraints.WEST; cs.insets=new Insets(2, 0, 0, 0); mgGridBag.setConstraints(rightSpinner, cs); marginsPanel.add(rightSpinner); cs.gridwidth=GridBagConstraints.REMAINDER; cs.insets=new Insets(2, 0, 0, 0); cs.anchor=GridBagConstraints.WEST; mgGridBag.setConstraints(rightPx, cs); marginsPanel.add(rightPx); //setting the border to the margins panel marginsPanel.setBorder(new TitledBorder(marginLabel)); //the panel that will be returned JPanel pagePanel=new JPanel(); GridBagLayout pageGridBag=new GridBagLayout(); pagePanel.setLayout(pageGridBag); GridBagConstraints pc=new GridBagConstraints(); pc.fill=GridBagConstraints.BOTH; pc.insets=new Insets(3, 3, 3, 3); pc.gridwidth=GridBagConstraints.REMAINDER; pageGridBag.setConstraints(sizeChooserPanel, pc); pagePanel.add(sizeChooserPanel); pc.gridwidth=1; pageGridBag.setConstraints(orientationPanel, pc); pagePanel.add(orientationPanel); pc.gridwidth=GridBagConstraints.REMAINDER; pageGridBag.setConstraints(marginsPanel, pc); pagePanel.add(marginsPanel); return pagePanel; } /** * @return the panel containing the widgets for entering information on the page */ protected JPanel getPageInformationPanel() { JPanel pageInfoPanel=new JPanel(); //getting the labels String titleLabel="", authorLabel="", subjectLabel="", keywordsLabel="", creatorLabel="";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -