⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 svgprint.java

📁 完全基于java开发的svg矢量绘图工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            }                        /*******************creating the dimension chooser panel**************/            			//setting the layout            GridBagLayout gridBag=new GridBagLayout();            GridBagConstraints c=new GridBagConstraints();            sizeChooserPanel.setLayout(gridBag);            c.fill=GridBagConstraints.HORIZONTAL;            c.insets=new Insets(3, 3, 3, 3);						//setting the listeners to the textfields			txtw.addCaretListener(new CaretListener(){	            public void caretUpdate(CaretEvent evt) {	                	                try{	                    printWidth=Double.parseDouble(txtw.getText());	                }catch (Exception ex){}	            }			});						txth.addCaretListener(new CaretListener(){	            public void caretUpdate(CaretEvent evt) {	                	                try{	                    printHeight=Double.parseDouble(txth.getText());	                }catch (Exception ex){}	            }			});						JPanel pw=new JPanel();			pw.setLayout(new BoxLayout(pw,BoxLayout.X_AXIS));			JLabel pxw=new JLabel("px");			pxw.setBorder(new EmptyBorder(0, 4, 0, 0));			pw.add(txtw);			pw.add(pxw);				JPanel ph=new JPanel();			ph.setLayout(new BoxLayout(ph,BoxLayout.X_AXIS));			JLabel pxh=new JLabel("px");			pxh.setBorder(new EmptyBorder(0, 4, 0, 0));			ph.add(txth);			ph.add(pxh);				JLabel lbw=new JLabel(widthLabel.concat(" :"));			JLabel lbh=new JLabel(heightLabel.concat(" :"));								//adding the widgets to the panel			c.anchor=GridBagConstraints.EAST;			c.gridwidth=1;			c.weightx=0;			gridBag.setConstraints(lbw, c);			sizeChooserPanel.add(lbw);						c.anchor=GridBagConstraints.WEST;			c.gridwidth=GridBagConstraints.REMAINDER;			c.weightx=50.0;			gridBag.setConstraints(pw, c);			sizeChooserPanel.add(pw);						c.anchor=GridBagConstraints.EAST;			c.gridwidth=1;			c.weightx=0;			gridBag.setConstraints(lbh, c);			sizeChooserPanel.add(lbh);						c.anchor=GridBagConstraints.WEST;			c.gridwidth=GridBagConstraints.REMAINDER;			c.weightx=50;			gridBag.setConstraints(ph, c);			sizeChooserPanel.add(ph);						//setting the border			TitledBorder border=new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED), printSizeLabel);			sizeChooserPanel.setBorder(border);                        /*******************the jpg case**********************/                        //the panel that will contain the slider and the label, the slider, and the initial value            final JPanel jpgDisplayAndSlider=new JPanel();            final JSlider jpgSlider=new JSlider(0, 100, 100);            final JLabel jpgDisplayedValue=new JLabel(100+" %");                        jpgDisplayedValue.setPreferredSize(new Dimension(50, 20));	                        //the listener to the slider            final MouseAdapter jpgSliderListener=new MouseAdapter(){                                public void mouseReleased(MouseEvent evt) {                                        jpgQuality=(float)((float)(jpgSlider.getValue())/100);                }            };                        //adds a listener to the slider            jpgSlider.addMouseListener(jpgSliderListener);                        ChangeListener jpgSliderChangeListener=new ChangeListener(){                                public void stateChanged(ChangeEvent arg0) {                                        jpgDisplayedValue.setText(jpgSlider.getValue()+" %");                }            };                        //adds a listener to the slider            jpgSlider.addChangeListener(jpgSliderChangeListener);                        jpgDisplayAndSlider.setLayout(new BorderLayout(3, 0));            jpgDisplayAndSlider.add(jpgSlider, BorderLayout.CENTER);            jpgDisplayAndSlider.add(jpgDisplayedValue, BorderLayout.EAST);                        //the label for the widgets            JLabel jpgLabel=new JLabel(jpgQualityLabel.concat(" :"));                        jpgPanel.setLayout(new BorderLayout(5, 0));            jpgPanel.add(jpgLabel, BorderLayout.WEST);            jpgPanel.add(jpgDisplayAndSlider, BorderLayout.CENTER);                        //setting the border for this panel            border=new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED), jpgPropertiesLabel);            jpgPanel.setBorder(border);                        /*******************the png case**********************/                        //the panel that will contain the slider and the label, the slider, and the initial value            final String fpngBestQualityLabel=pngBestQualityLabel;            final JPanel pngDisplayAndSlider=new JPanel();            final JSlider pngSlider=new JSlider(0, 100, 100);            final JLabel pngDisplayedValue=new JLabel(fpngBestQualityLabel);                        pngDisplayedValue.setPreferredSize(new Dimension(75, 20));	                        ChangeListener pngSliderChangeListener=new ChangeListener(){                                public void stateChanged(ChangeEvent evt) {                                        if(pngSlider.getValue()>=0 && pngSlider.getValue()<20){                                                pngBitDepths=1;                        pngSlider.setValue(0);                        pngDisplayedValue.setText("1 bit");                                            }else if(pngSlider.getValue()>=20 && pngSlider.getValue()<40){                                                pngBitDepths=2;                        pngDisplayedValue.setText("2 bit");                                            }else if(pngSlider.getValue()>=40 && pngSlider.getValue()<60){                                                pngBitDepths=4;                        pngSlider.setValue(40);                        pngDisplayedValue.setText("4 bit");                                            }else if(pngSlider.getValue()>=60 && pngSlider.getValue()<80){                                                pngBitDepths=8;                        pngSlider.setValue(60);                        pngDisplayedValue.setText("8 bit");                                            }else if(pngSlider.getValue()>=80 && pngSlider.getValue()<=100){                                                pngBitDepths=9;                        pngSlider.setValue(100);                        pngDisplayedValue.setText(fpngBestQualityLabel);                    }                }            };                        //adds a listener to the slider            pngSlider.addChangeListener(pngSliderChangeListener);                        //the label for the widgets            JLabel pngLabel=new JLabel(pngBitDepthsLabel.concat(" :"));                        pngDisplayAndSlider.setLayout(new BorderLayout(3, 0));            pngDisplayAndSlider.add(pngSlider, BorderLayout.CENTER);            pngDisplayAndSlider.add(pngDisplayedValue, BorderLayout.EAST);                        pngPanel.setLayout(new BorderLayout(5, 0));            pngPanel.add(pngLabel, BorderLayout.WEST);            pngPanel.add(pngDisplayAndSlider, BorderLayout.CENTER);                        //setting the border for this panel            border=new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED), pngPropertiesLabel);            pngPanel.setBorder(border);                        /*******************the tiff case**********************/                        //the panel containg the check box and the label            JPanel tiffCheckAndLabel=new JPanel();            tiffCheckAndLabel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 0));                        JCheckBox tiffCheckBox=new JCheckBox();            tiffCheckBox.setSelected(false);                        //the label for the widget            JLabel tiffLabel=new JLabel(tiffForceTransparentWhite);            tiffCheckAndLabel.add(tiffCheckBox);            tiffCheckAndLabel.add(tiffLabel);                        tiffPanel.setLayout(new BorderLayout(0, 0));            tiffPanel.add(tiffCheckAndLabel, BorderLayout.CENTER);                        //setting the border for this panel            border=new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED), tiffPropertiesLabel);            tiffPanel.setBorder(border);            /******************the buttons***********************/                        //the buttons            final JButton okButton=new JButton(okLabel), cancelButton=new JButton(cancelLabel);                        //the buttons panel            buttonsPanel=new JPanel();            buttonsPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));                        //the listener to the ok and cancel buttons            final ActionListener buttonListener=new ActionListener(){                                public void actionPerformed(ActionEvent evt) {                    if(evt.getSource().equals(okButton)){                                                currentActionState=OK_ACTION;                                            }else{                                                currentActionState=CANCEL_ACTION;                    }                                        setVisible(false);                }             };                        okButton.addActionListener(buttonListener);            cancelButton.addActionListener(buttonListener);            buttonsPanel.add(okButton);            buttonsPanel.add(cancelButton);                        //setting the layout for the content pane of the dialog            getContentPane().setLayout(new BorderLayout(0, 5));        }                /**         * shows the dialog box to configure the print action         * @param frame the frame whose document is to be printed         * @return the state of the action : OK_ACTION or CANCEL_ACTION         */        protected int showPrintDialog(SVGFrame frame){                        currentActionState=CANCEL_ACTION;                        if(frame!=null && frame.getScrollPane().getSVGCanvas().getGeometryCanvasSize()!=null){                                //setting the default size for the textfields                Point2D.Double imageSize=frame.getScrollPane().getSVGCanvas().getGeometryCanvasSize();                txtw.setText(imageSize.getX()+"");                txth.setText(imageSize.getY()+"");                                //the panel containing the size chooser and the panel linked with an print type                JPanel contentPanel=new JPanel();                contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));                contentPanel.add(sizeChooserPanel);                                //setting an empty border for the content panel                contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));                //fills the content panel                /*if(printType==JPEG_EXPORT){                                        contentPanel.add(jpgPanel);                    setTitle(labelJpgPrint);                }*/                                //filling the content pane                getContentPane().removeAll();                getContentPane().add(contentPanel, BorderLayout.CENTER);                getContentPane().add(buttonsPanel, BorderLayout.SOUTH);                                //packs the dialog box                pack();                    			//sets the location of the dialog box    			int 	x=(int)(getSVGEditor().getParent().getLocationOnScreen().getX()+getSVGEditor().getParent().getWidth()/2-getWidth()/2),     					y=(int)(getSVGEditor().getParent().getLocationOnScreen().getY()+getSVGEditor().getParent().getHeight()/2-getHeight()/2);    			    			setLocation(x,y);                    			//displays the dialog box                setVisible(true);                                //waits until the parameters are chosen and one of the buttons is clicked                while(isVisible()){                                        try{                        wait((long)100.0);                    }catch (Exception ex){}                }            }            return currentActionState;        }                /**         * @return Returns the forceTransparentWhite boolean         */        protected boolean isForceTransparentWhite() {            return forceTransparentWhite;        }                /**         * @return Returns the jpgQuality.         */        protected float getJpgQuality() {            return jpgQuality;        }                /**         * @return Returns the pngBitDepths.         */        protected int getPngBitDepths() {            return pngBitDepths;        }                /**         * @return Returns the printHeight.         */        protected double getPrintHeight() {            return printHeight;        }                /**         * @return Returns the printWidth.         */        protected double getPrintWidth() {            return printWidth;        }    }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -