?? j2kguiencoder.java
字號:
package gui;import jj2000.j2k.encoder.*;import jj2000.j2k.image.*;import jj2000.j2k.util.*;import cryptix.provider.rsa.*;import gui.rsa.*;import javax.swing.event.*;import java.awt.event.*;import javax.swing.*;import java.text.*;import java.awt.*;import java.io.*;/** Class to graphically collect JPEG 2000 encoding parameters before * launching the encoding process. */public class J2KGuiEncoder implements ChangeListener, ActionListener, ItemListener, MouseListener, MouseMotionListener { /** Reference to the main frame */ private Main mainFrame; /** Reference to the SaveImage instance that called this object */ private SaveImage si; /** Reference to the file containing the image to encode */ private File inputFile; /** Reference to the panel used to display the input image */ private JJImgPanel imgPan = null; /** Reference to the RSA support modules */ private RSASupport rsaSupport; /** Dimension of the input image (used to compute the maximum bit-rate) */ private Dimension inDim; /** Image offset in canvas */ private Coord imgOff = new Coord(0,0); /** Saved image offset before moving image with the mouse */ private Coord savedImgOff = new Coord(0,0); /** Image security */ private JRadioButton secNoShape, secWholeImage, secUserDef; private JTextField secUlxTF,secUlyTF,secWTF,secHTF, secSeedTF,secResStartTF,secBrStartTF; private JRadioButton secWavMeth,secBitMeth; /** Format of the displayed floats (3 fractional digits) */ private static final DecimalFormat f = new DecimalFormat("##0.000"); /** Initial point of the selection (Corner of a rectangular ROI, * center of a circular ROI,...). */ private Coord selectOrig = new Coord(0,0); /** No ROI is selected */ public final static int NONE = 0; /** A rectangular ROI is selected */ public final static int RECT_ROI = 1; /** A circular ROI is selected */ public final static int CIRC_ROI = 2; /** Set image offset in canvas */ public final static int MOVE_IMAGE = 3; /** Define tile partition with mouse */ public final static int TILE_PARTITION = 4; /** A rectangular area is selected for scrambling */ public final static int RECT_SECURE = 5; /** Type of the current selection tool */ private int selectType = NONE; private Rectangle rectSelect = new Rectangle(); private int cROIx, cROIy, cROIrad; private double zf; /** Simple encoding options */ private JDialog simpEncOptDialog; private JSlider encRateSlider; private JTextField encRateField; private JRadioButton lossyBut, losslessBut,mouseImgOff,mouseTile; public JButton encOptOkBut; private JButton encOptCancelBut, encOptAdvancedBut; /** Precision of the slider used to select the output bit-rate */ private static float encSliderPrec = 1000; private double maxRate; /** Advanced encoding options */ private JDialog advEncOptDialog; private JCheckBox mctCheckBox, cppCheckBox, ralignBox; private JRadioButton mctOn, mctOff; private JTextField qstepTf; private JComboBox gbCombo, qtypeCombo, rMaskComboBox, roiStartLvlComb; private JComboBox cLenCalcCombo, wLevCb; private JTextField rectLeftTf, rectTopTf, rectWidthTf, rectHeightTf; private JTextField circColTf, circRowTf, circRadTf, cppDimTf; private JButton maskBrowseButton; private JCheckBox cSegSymbBox,cCausalBox,cRegTermBox,cResetMQBox, cBypassBox; private JComboBox ctermCombo; private JCheckBox showEncInf; private JComboBox cblkSizHeightCb, cblkSizWidthCb; private JTextField aLayersTf; private JComboBox apTypeCombo; private JCheckBox pphMainBox, pphTileBox, pEphBox, pSopBox; private JRadioButton lossless, lossy; private JTextField tilePartsField, tileWidth, tileHeight; private JCheckBox tileBox; private JTextField refxTF, refyTF, trefxTF, trefyTF; private JRadioButton mouseRectROI, mouseCircROI; public JButton encOkBut; private JButton encDefBut, encCancelBut; private String roiMaskAbsName; private JLabel roiMaskNameLabel; private RawRSAPrivateKey rsaPrivKey = null; private JTextField selectedKeyTF; private JRadioButton useRSAEncryption; /** Class constructor */ public J2KGuiEncoder(Main mainFrame,SaveImage si,File inputFile, Dimension inDim, JJImgPanel imgPan) { this.mainFrame = mainFrame; this.inputFile = inputFile; this.si = si; this.inDim = inDim; this.imgPan = imgPan; zf = imgPan.getZoomFactor(); rsaSupport = mainFrame.getRSASupport(); imgPan.addMouseListener(this); imgPan.addMouseMotionListener(this); } /** Start the encoding operation by first displaying dialog box(es) in * order to collect parameters */ public void start() { mainFrame.enableZoom(false); createSimpleGUI(); simpEncOptDialog.setVisible(true); } /** Creates the dialog box used to collect simple encoding parameters */ private void createSimpleGUI() { simpEncOptDialog = new JDialog(mainFrame,"Encoding rate"); JPanel simpEncOptPan = new JPanel(new GridLayout(3,1)); // Lossy coding rate JPanel encLossyPan = new JPanel(); lossyBut = new JRadioButton("Lossy",true); lossyBut.addItemListener(this); encLossyPan.add(lossyBut); // Search maximum bit-depth maxRate = inputFile.length()*8d/inDim.width/inDim.height; encRateSlider = new JSlider(JSlider.HORIZONTAL,0, (int)(maxRate*encSliderPrec), (int)(maxRate*encSliderPrec)); encRateSlider.addChangeListener(this); encLossyPan.add(encRateSlider); encRateField = new JTextField(""+f.format(maxRate),5); encRateField.addActionListener(this); encLossyPan.add(encRateField); encLossyPan.add(new JLabel("bpp")); simpEncOptPan.add(encLossyPan); // Lossless mode JPanel encLosslessPan = new JPanel(); losslessBut = new JRadioButton("Lossless",false); losslessBut.addItemListener(this); encLosslessPan.add(losslessBut); simpEncOptPan.add(encLosslessPan); ButtonGroup lossButGrp = new ButtonGroup(); lossButGrp.add(lossyBut); lossButGrp.add(losslessBut); // Confirmation buttons JPanel encConfirmPan = new JPanel(); encOptOkBut = new JButton("OK"); encOptOkBut.addActionListener(si); encConfirmPan.add(encOptOkBut); encOptCancelBut = new JButton("Cancel"); encOptCancelBut.addActionListener(this); encConfirmPan.add(encOptCancelBut); encOptAdvancedBut = new JButton("Advanced..."); encOptAdvancedBut.addActionListener(this); encConfirmPan.add(encOptAdvancedBut); simpEncOptPan.add(encConfirmPan); simpEncOptDialog.getContentPane().add(simpEncOptPan); simpEncOptDialog.setModal(true); simpEncOptDialog.pack(); simpEncOptDialog.setLocationRelativeTo(mainFrame); } /** * Get parameters collected by the simple dialog box and build a * ParameterList instance from them. * */ public ParameterList getSimpParameters() { // Initialize default parameters ParameterList defpl = new ParameterList(); String[][] param = Encoder.getAllParameters(); for (int i=param.length-1; i>=0; i--) { if(param[i][3]!=null) defpl.put(param[i][0],param[i][3]); } // Create parameter list using defaults ParameterList pl = new ParameterList(defpl); // Put arguments in ParameterList if(losslessBut.isSelected()) { pl.put("lossless","on"); } else { double curRate = (new Double(encRateField.getText())). doubleValue(); if(Math.abs(curRate-maxRate)>0.001) { pl.put("rate",encRateField.getText()); } } pl.put("verbose","off"); simpEncOptDialog.setVisible(false); simpEncOptDialog = null; return pl; } /** * Creates a dialog box for collecting advanced encoding options * */ public void createAdvancedGui() { advEncOptDialog = new JDialog(mainFrame,"Encoding Parameters"); // ********************* General Tab ************************ JPanel genTab = new JPanel(); ButtonGroup lossButGrp = new ButtonGroup(); // Lossless mode JPanel losslessPan = new JPanel(); lossless = new JRadioButton("Lossless",false); lossButGrp.add(lossless); lossless.addItemListener(this); losslessPan.add(lossless); genTab.add(losslessPan); // Lossy mode JPanel genTab2 = new JPanel(); lossy = new JRadioButton("Lossy",true); lossButGrp.add(lossy); lossy.addItemListener(this); genTab2.add(lossy); genTab2.add(new JLabel("Rate:")); encRateField.addActionListener(this); genTab2.add(encRateField); genTab2.add(new JLabel("bpp")); genTab.add(genTab2); // Show encoding information showEncInf = new JCheckBox("Show encoding information",false); showEncInf.setToolTipText("Show information and warnings related "+ "to the encoding of the image"); genTab.add(showEncInf); genTab.setLayout(new BoxLayout(genTab,BoxLayout.Y_AXIS)); //******************* Canvas Tab ********************** JPanel canvasTab = new JPanel(new GridLayout(2,1)); // Image offset JPanel opt1 = new JPanel(); opt1.add(new JLabel("Image offset:")); // X-offset opt1.add(new JLabel("x:")); refxTF = new JTextField("0",5); refxTF.addActionListener(this); opt1.add(refxTF); // Y-offset opt1.add(new JLabel("y:")); refyTF = new JTextField("0",5); refyTF.addActionListener(this); opt1.add(refyTF); mouseImgOff = new JRadioButton("Mouse defined",false); mouseImgOff.addItemListener(this); opt1.add(mouseImgOff); canvasTab.add(opt1); // Tiles JPanel opt2 = new JPanel(new GridLayout(2,3)); opt2.setBorder(BorderFactory.createTitledBorder("Tiles")); // Enable/disable tileBox = new JCheckBox("Tiling",false); tileBox.addItemListener(this); opt2.add(tileBox); // Tile partition offset JPanel tpoxPan = new JPanel(); tpoxPan.add(new JLabel("x:")); trefxTF = new JTextField("0",5); trefxTF.setEditable(false); tpoxPan.add(trefxTF); opt2.add(tpoxPan); JPanel tpoyPan = new JPanel(); tpoyPan.add(new JLabel("y:")); trefyTF = new JTextField("0",5); trefyTF.setEditable(false); tpoyPan.add(trefyTF); opt2.add(tpoyPan); // mouse defined mouseTile = new JRadioButton("Mouse defined",false); mouseTile.addItemListener(this); opt2.add(mouseTile); // Tiles dimensions JPanel tdwPan = new JPanel(); tdwPan.add(new JLabel("width:")); tileWidth = new JTextField("0",5); tileWidth.setEditable(false); tdwPan.add(tileWidth); opt2.add(tdwPan); JPanel tdhPan = new JPanel(); tdhPan.add(new JLabel("height:")); tileHeight = new JTextField("0",5); tileHeight.setEditable(false); tdhPan.add(tileHeight); opt2.add(tdhPan); canvasTab.add(opt2); JPanel encTab = new JPanel(); encTab.add(canvasTab); //***** Multi-component transform Tab ******** JPanel mTab = new JPanel(); mctCheckBox = new JCheckBox("Component Transformation:",false); mctCheckBox.addItemListener(this); mTab.add(mctCheckBox); mctOn = new JRadioButton("on",false); mctOn.setEnabled(false); mTab.add(mctOn); mctOff = new JRadioButton("off",true); mctOff.setEnabled(false); mTab.add(mctOff); ButtonGroup mctButGrp = new ButtonGroup(); mctButGrp.add(mctOn); mctButGrp.add(mctOff); //****** Wavelet Transform Tab ******* JPanel wTab = new JPanel(); wLevCb = new JComboBox(); for(int i=0; i<=10; i++) { wLevCb.addItem(""+i); } wLevCb.setSelectedItem("5"); wTab.add(new JLabel("Number of decomposition levels:")); wTab.add(wLevCb); //***** Quantization Tab ********* JPanel qTab = new JPanel(new GridLayout(3,1)); JPanel qTab1 = new JPanel(); qTab1.add(new JLabel("Number of guard bits:")); gbCombo = new JComboBox(); for(int i=0; i<10; i++) { gbCombo.addItem(""+i); } gbCombo.setSelectedItem("2"); qTab1.add(gbCombo); qTab.add(qTab1);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -