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

📄 main.java

📁 jpeg2000编解码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	    if((ext.equalsIgnoreCase(".pgm") && fa.nc!=1) ||	       (ext.equalsIgnoreCase(".pgx") && fa.nc!=1)) {		for(int c=1; c<=fa.nc; c++) {		    (new File(prefix+"-"+c+ext)).delete();		}	    } else {		fa.srcFile.delete();	    }	}        intFrameHt.remove(f);	menuWindow.remove((JCheckBoxMenuItem)windowHt.get(f));	windowHt.remove(f);	rulesItem.setEnabled(false);    }    public void internalFrameDeactivated(InternalFrameEvent e) {}    public void internalFrameDeiconified(InternalFrameEvent e) {}    public void internalFrameIconified(InternalFrameEvent e) {}    public void internalFrameOpened(InternalFrameEvent e) {}    /** An internal frame is activated when selected by the mouse or     * the menu or when an other one has been closed. */    public void internalFrameActivated(InternalFrameEvent e) {        JInternalFrame f = desktop.getSelectedFrame();        FrameAttribute fA = (FrameAttribute)intFrameHt.get(f);        if(fA==null) return;	// Enable image saving operation.	saveFile.setEnabled(true);	// Enable display of information	infoFile.setEnabled(true);	// Update rules check box	rulesItem.setEnabled(true);	if(fA.scrollPane!=null) {	    rulesItem.setEnabled(true);	    if(fA.scrollPane.getRowHeader()==null) {		rulesItem.setSelected(false);		enableZoom(true);	    } else {		rulesItem.setSelected(true);		enableZoom(false);	    }	} else {	    rulesItem.setSelected(false);	    rulesItem.setEnabled(false);	}		// Update window Menu	JCheckBoxMenuItem fcb = (JCheckBoxMenuItem)windowHt.get(f);	fcb.setSelected(true);	if(f.isIcon()) {	    try {		f.setMaximum(true);	    } catch (java.beans.PropertyVetoException pve) {}	}	// Display number of components and image dimension in the status bar        if(fA.nc==1) {            statusLbl.setText("1 component, "+fA.imgCo.width+			      "x"+fA.imgCo.height);        } else if(fA.nc>1) {            statusLbl.setText(fA.nc+" components, "+fA.imgCo.width+			      "x"+fA.imgCo.height);        }    }    /** Create the menuBar of the application */    private JMenuBar createMenuBar() {        ///// File /////        JMenu file = new JMenu("File");        file.add(openFile);        file.add(saveFile);        file.add(infoFile);        file.addSeparator();	//// Encryption keys ////	JMenu encryptKey = new JMenu("Encryption keys");	genKey = new JMenuItem("Generate RSA keys pair...");	encryptKey.add(genKey);	saveKey = new JMenuItem("Save RSA key...");	encryptKey.add(saveKey);	JMenuItem mngKey = new JMenuItem("Manage RSA key...");	encryptKey.add(mngKey);	file.add(encryptKey);	//// Last Opened files ////	file.add(mOpenedFile);	for(int i=0; i<lastOpenedFiles.length; i++) {	    if(lastOpenedFiles[i]==null) {		continue;	    }	    lofItem[i] = new JMenuItem(lastOpenedFiles[i].getPath());	    lofItem[i].addActionListener(new ActionListener() {		    public void actionPerformed(ActionEvent e) {			OpenImage oi = new OpenImage(Main.this,desktop,						     e.getActionCommand());			if(oi.isFileSelected()) {			    oi.run();			}		    }		});	    mOpenedFile.add(lofItem[i]);	}	//// Exit ////	file.addSeparator();        JMenuItem exit = new JMenuItem("Exit");        file.add(exit);        ///// Image /////        JMenu imageMenu = new JMenu("Image");        ///// Zoom /////        JMenu zoomMenu = new JMenu("Zoom");        zoomIn = new JMenuItem("Zoom in");        zoomMenu.add(zoomIn);        zoomOut = new JMenuItem("Zoom out");        zoomMenu.add(zoomOut);        zoomOrig = new JMenuItem("Full resolution");        zoomMenu.add(zoomOrig);        enableZoom(false);        imageMenu.add(zoomMenu);	///// Tools /////	JMenu toolMenu = new JMenu("Tools");        rulesItem = new JCheckBoxMenuItem("Ruler",false);	rulesItem.setEnabled(false);        toolMenu.add(rulesItem);	///// Window /////	menuWindow = new JMenu("Window");	JMenuItem reorgWin = new JMenuItem("Reorganize windows");	menuWindow.add(reorgWin);	menuWindow.addSeparator();        ///// Help /////        JMenu menuHelp = new JMenu("Help");        JMenuItem aboutGuiMenu = new JMenuItem("About GUI");        menuHelp.add(aboutGuiMenu);	JMenuItem aboutCryptix = new JMenuItem("About Cryptix");	menuHelp.add(aboutCryptix);        // Accelerators        exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q,0));        zoomIn.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I,0));        zoomOut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,0));        zoomOrig.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,0));        // Listener's	mngKey.addActionListener(new ActionListener() {		public void actionPerformed(ActionEvent e) {		    rsaSupport.createMngKeyUI(Main.this,RSASupport.					      DISPLAY_BOTH);		}	    });	saveKey.addActionListener(new ActionListener() {		public void actionPerformed(ActionEvent e) {		    rsaSupport.createSaveKeyUI(Main.this);		}	    });	genKey.addActionListener(new ActionListener() {		public void actionPerformed(ActionEvent e) {		    rsaSupport.createKeyGenUI(Main.this);		}	    });        exit.addActionListener(new ActionListener() {                public void actionPerformed(ActionEvent e) { 		    terminateApplication();		}            });	reorgWin.addActionListener(new ActionListener() {		public void actionPerformed(ActionEvent e) {                    JInternalFrame[] frames = desktop.getAllFrames();		    numOpenedFrame = 0;                    for(int i=0; i<frames.length; i++) {			frames[i].setLocation(FRAME_INCR*numOpenedFrame,					      FRAME_INCR*numOpenedFrame);			numOpenedFrame++;			try {			    frames[i].setSelected(true);			} catch(java.beans.PropertyVetoException pve) {}		    }		    		}	    });        zoomOrig.addActionListener(new ActionListener() {                public void actionPerformed(ActionEvent e) {                    zoomOriginal();                }            });        zoomIn.addActionListener(new ActionListener() {                public void actionPerformed(ActionEvent e) {                    zoomInImage();                }            });        zoomOut.addActionListener(new ActionListener() {                public void actionPerformed(ActionEvent e) {                    zoomOutImage();                }            });        aboutGuiMenu.addActionListener(new ActionListener() {                public void actionPerformed(ActionEvent e) {//                     JOptionPane.//                         showMessageDialog(null,aboutMessage,"About GUI",//                                           JOptionPane.INFORMATION_MESSAGE,//                                           new ImageIcon("gui/icons/"+// 							"2kancolor.jpg"));                    JOptionPane.                        showMessageDialog(null,aboutMessage,"About",                                          JOptionPane.INFORMATION_MESSAGE,                                          new ImageIcon(this.getClass().							getResource("icons/"+							"2kancolor.jpg")));                }            });// 	aboutCryptix.addActionListener(new ActionListener() {// 		public void actionPerformed(ActionEvent e) {// 		    JOptionPane.// 			showMessageDialog(null,"Cryptix 3.2.0\n"+// 					  "Copyright(c) 1995, 1996, 1997,\n"+// 					  "1998, 1999, 2000 The Cryptix "+// 					  "Foundation Limited.\nAll rights "+// 					  "reserved.", "About Cryptix",// 					  JOptionPane.INFORMATION_MESSAGE,// 					  new ImageIcon("gui/icons/"+// 							"cryptix.gif"));// 		}// 	    });	aboutCryptix.addActionListener(new ActionListener() {		public void actionPerformed(ActionEvent e) {		    JOptionPane.			showMessageDialog(null,"Cryptix 3.2.0\n"+					  "Copyright(c) 1995, 1996, 1997,\n"+					  "1998, 1999, 2000 The Cryptix "+					  "Foundation Limited.\nAll rights "+					  "reserved.", "About Cryptix",					  JOptionPane.INFORMATION_MESSAGE,					  new ImageIcon(this.getClass().							getResource("icons/"+							"cryptix.gif")));		}	    });	rulesItem.addItemListener(new ItemListener() {		public void itemStateChanged(ItemEvent e) {                    JInternalFrame f = desktop.getSelectedFrame();		    FrameAttribute fA = (FrameAttribute)intFrameHt.get(f);		    if(fA==null) return;		    if(fA.scrollPane==null) return;		     		    if(rulesItem.isSelected()) {			Rule columnView = new Rule(Rule.HORIZONTAL,fA.imgPan,						   fA.imgCo,fA.scrollPane);			columnView.setPreferredWidth(20);			Rule rowView = new Rule(Rule.VERTICAL,fA.imgPan,						fA.imgCo,fA.scrollPane);			rowView.setPreferredHeight(20);			fA.scrollPane.setRowHeaderView(rowView);			fA.scrollPane.setColumnHeaderView(columnView);		    } else {			fA.scrollPane.setRowHeaderView(null);			fA.scrollPane.setColumnHeaderView(null);		    }		}	    });	JMenuBar menuBar = new JMenuBar();        menuBar.add(file);        menuBar.add(imageMenu);        menuBar.add(toolMenu);	menuBar.add(menuWindow);        menuBar.add(menuHelp);	return menuBar;    }    /** Zoom out of the current image and update the frame title */    private void zoomOutImage() {        JInternalFrame f = desktop.getSelectedFrame();        FrameAttribute fA = (FrameAttribute)intFrameHt.get(f);        if(fA==null) return;        fA.imgPan.zoomOut();        double zf = fA.imgPan.getZoomFactor();        if(zf==1) {            f.setTitle(fA.title+" (100%)");        } else {            f.setTitle(fA.title+" ("+(1/zf*100)+"%)");        }     }    /** Zoom in the current image and update the frame title */    private void zoomInImage() {        JInternalFrame f = desktop.getSelectedFrame();        FrameAttribute fA = (FrameAttribute)intFrameHt.get(f);        if(fA==null) return;        fA.imgPan.zoomIn();        double zf = fA.imgPan.getZoomFactor();        if(zf==1) {            f.setTitle(fA.title+" (100%)");        } else {            f.setTitle(fA.title+" ("+(1/zf*100)+"%)");        }     }    /** Display the current image at its full resolution and update     * the title */    private void zoomOriginal() {        JInternalFrame f = desktop.getSelectedFrame();        FrameAttribute fA = (FrameAttribute)intFrameHt.get(f);        if(fA==null) return;        fA.imgPan.zoomFull();        f.setTitle(fA.title+" (100%)");    }    /** Create the toolBar of the application */    private JToolBar createToolBar() {	JToolBar toolBar = new JToolBar();	toolBar.setBackground(Color.lightGray);		// Open Button        toolBar.add(openFile);	toolBar.add(saveFile);	toolBar.addSeparator();        toolBar.add(infoFile);        return toolBar;    }    /**      * Method called to add an internal frame (containing a decoded image) to     * the main application      *     * @param f JInternalFrame containing the displayed image.     * @param fa FrameAttribute instance     * */    public void addInternalFrame(JInternalFrame f,FrameAttribute fA) {        // Terminate frame initialization        f.addInternalFrameListener(this);	if(desktop.getSelectedFrame()!=null) {	    Point pt = desktop.getSelectedFrame().getLocation();	    f.setLocation(pt.x+FRAME_INCR,pt.y+FRAME_INCR);	} else {	    f.setLocation(FRAME_INCR*numOpenedFrame,FRAME_INCR*numOpenedFrame);	}	numOpenedFrame++;	// Add a border around the Viewport 	if(fA.scrollPane!=null) {	    fA.scrollPane.		setViewportBorder(BorderFactory.				  createBevelBorder(BevelBorder.LOWERED));	}	f.pack();	        // Add the frame in the frame hash table        intFrameHt.put(f,fA);	// Add zoom percentage to the title	if(fA.imgPan!=null) {	    double zf = fA.imgPan.getZoomFactor();	    if(zf==1) {		f.setTitle(fA.title+" (100%)");	    } else {		f.setTitle(fA.title+" ("+(1/zf*100)+"%)");	    } 	}        f.setFrameIcon(null);	f.setVisible(true);	// Add frame in the window hash table and in the window menu	JCheckBoxMenuItem fcb = new JCheckBoxMenuItem(fA.title,true);	menuWindow.add(fcb);	windowGroup.add(fcb);	windowHt.put(f,fcb);	fcb.addItemListener(new ItemListener() {		public void itemStateChanged(ItemEvent e) {		    if(e.getStateChange()==ItemEvent.SELECTED) {			JInternalFrame frame = null;			Enumeration keys = windowHt.keys();			while(keys.hasMoreElements()) {			    JInternalFrame fTmp = 				(JInternalFrame)keys.nextElement();			    if(((JCheckBoxMenuItem)windowHt.get(fTmp))==			       ((JCheckBoxMenuItem)e.getItem())) {				frame = fTmp;				try {				    frame.setSelected(true);				} catch(java.beans.PropertyVetoException pve)				    {}			    }			}		    }		}	    });	// Finally add the frame to the desktop and give it the focus        desktop.add(f);        try {            f.setSelected(true);        } catch(java.beans.PropertyVetoException e) {}    }    /**      * Rename the internal frame and modify the value in the     * Hashtable. This is normally called when the current image is     * saved to a file. Then the old file is deleted if it was     * temporary and the new file is no more considered as     * temporary. */    public void renameFrame(File newFile) {        JInternalFrame f = desktop.getSelectedFrame();        FrameAttribute fA = (FrameAttribute)intFrameHt.get(f);	if(fA.isTemporaryFile) {	    String name = fA.srcFile.getPath();	    String ext = name.substring(name.lastIndexOf('.'),name.length());	    String prefix = name.substring(0,name.lastIndexOf('.'));	    if((ext.equalsIgnoreCase(".pgm") && fA.nc!=1) ||	       (ext.equalsIgnoreCase(".pgx") && fA.nc!=1)) {		for(int c=1; c<=fA.nc; c++) {		    (new File(prefix+"-"+c+ext)).delete();		}	    } else {		fA.srcFile.delete();	    }	}        fA.srcFile = newFile;	fA.isTemporaryFile = false;        f.setTitle(newFile.getName());    }    /** Enable or disable all zooming operations */    public void enableZoom(boolean status) {        zoomIn.setEnabled(status);        zoomOut.setEnabled(status);        zoomOrig.setEnabled(status);    }    /** Main method */    public static void main(String[] argv) {        Main frame = new Main();        frame.setVisible(true);    }}

⌨️ 快捷键说明

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