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

📄 main.java

📁 基于applet来实现条形码的生成方案
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                gen.generateBarcode(bitmap, msg[0]);
                bitmap.finish();
            }
            
            out.close();
            log.info("done.");
            exitHandler.successfulExit(this);
        } catch (IOException ioe) {
            exitHandler.failureExit(this, 
                "Error writing output file: " + ioe.getMessage(), null, -5);
        } catch (ConfigurationException ce) {
            exitHandler.failureExit(this, 
                "Configuration problem: " + ce.getMessage(), ce, -6);
        } catch (BarcodeException be) {
            exitHandler.failureExit(this, 
                "Error generating the barcode", be, -3);
        }
    }
    
    private Options getOptions() {
        if (options == null) {
            this.options = new Options();
            Option opt;
            
            this.options.addOption(OptionBuilder
                .withLongOpt("verbose")
                .withDescription("enable debug output")
                .create('v'));
                
            //Group: file/stdout
            this.options.addOption(OptionBuilder
                .withLongOpt("output")
                .withArgName("file")
                .hasArg()
                .withDescription("the output filename")
                .create('o'));
            
            //Group: config file/barcode type
            OptionGroup group = new OptionGroup();
            group.setRequired(true);
            group.addOption(OptionBuilder
                .withArgName("file")
                .withLongOpt("config")
                .hasArg()
                .withDescription("the config file")
                .create('c'));
            group.addOption(OptionBuilder
                .withArgName("name")
                .withLongOpt("symbol")
                .hasArg()
                .withDescription("the barcode symbology to select "
                    + "(default settings, use -c if you want to customize)")
                .create('s'));
            this.options.addOptionGroup(group);

            //Output format type
            this.options.addOption(OptionBuilder
                .withArgName("format")
                .withLongOpt("format")
                .hasArg()
                .withDescription("the output format: MIME type or file "
                    + "extension\n"
                    + "Default: " + MimeTypes.MIME_SVG + " (SVG)")
                .create('f'));

            //Bitmap-specific options
            this.options.addOption(OptionBuilder
                .withArgName("integer")
                .withLongOpt("dpi")
                .hasArg()
                .withDescription("(for bitmaps) the image resolution in dpi\n"
                    + "Default: 300")
                .create('d'));
            this.options.addOption(OptionBuilder
                .withLongOpt("bw")
                .withDescription("(for bitmaps) create monochrome (1-bit) "
                    + "image instead of grayscale (8-bit)")
                .create());
        }
        return this.options;
    }

    private Configuration getConfiguration(CommandLine cl) {
        if (cl.hasOption("s")) {
            String sym = cl.getOptionValue("s");
            DefaultConfiguration cfg = new DefaultConfiguration("cfg");
            DefaultConfiguration child = new DefaultConfiguration(sym);
            cfg.addChild(child);
            return cfg;
        } 
        if (cl.hasOption("c")) {
            try {
                String filename = cl.getOptionValue("c");
                File cfgFile = new File(filename);
                if (!cfgFile.exists() || !cfgFile.isFile()) {
                    throw new FileNotFoundException(
                        "Config file not found: " + cfgFile);
                }
                log.info("Using configuration: " + cfgFile);
                
                DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
                return builder.buildFromFile(cfgFile);
            } catch (Exception e) {
                exitHandler.failureExit(this, 
                    "Error reading configuration file: " + e.getMessage(), null, -3);
            }
        }
        return new DefaultConfiguration("cfg");
    }

    /** @return the Barcode4J version */
    public static String getVersion() {
        String version = null;
        Package jarinfo = Main.class.getPackage();
        if (jarinfo != null) {
            version = jarinfo.getImplementationVersion();
        }
        if (version == null) {
            //Fallback if Barcode4J is used in a development environment
            version = "DEV";
        }
        return version;
    }
    
    /**
     * Prints the application header on the console. Ensures that this is only
     * done once.
     */
    public void printAppHeader() {
        if (!headerPrinted) {
            if (log != null) {
                for (int i = 0; i < APP_HEADER.length; i++) {
                    log.info(APP_HEADER[i]);
                }
            } else {
                for (int i = 0; i < APP_HEADER.length; i++) {
                    stdout.println(APP_HEADER[i]);
                }
            }
            headerPrinted = true;
        }
    }
    
    private void printHelp(PrintWriter writer) {
        printAppHeader();

        //Get a list of additional supported MIME types
        Set knownMimes = new java.util.HashSet();
        knownMimes.add(null);
        knownMimes.add("");
        knownMimes.add(MimeTypes.MIME_PNG);
        knownMimes.add("image/png");
        knownMimes.add(MimeTypes.MIME_JPEG);
        knownMimes.add(MimeTypes.MIME_TIFF);
        knownMimes.add(MimeTypes.MIME_GIF);
        Set additionalMimes = BitmapEncoderRegistry.getSupportedMIMETypes();
        additionalMimes.removeAll(knownMimes);

        HelpFormatter help = new HelpFormatter();
        final String unavailable = " (unavailable)";
        help.printHelp(writer, HelpFormatter.DEFAULT_WIDTH,
            "java -jar barcode4j.jar "
                + "[-v] [[-s <symbology>]|[-c <cfg-file>]] [-f <format>] "
                + "[-d <dpi>] [-bw] [-o <file>] <message>",
            null,
            getOptions(),
            HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD,
            "Valid output formats:"
                + "\nSVG: " + MimeTypes.MIME_SVG + ", svg"
                + "\nEPS: " + MimeTypes.MIME_EPS + ", eps"
                + "\nPNG: " + MimeTypes.MIME_PNG + ", png" 
                    + (BitmapEncoderRegistry.supports(MimeTypes.MIME_PNG) 
                        ? "" : unavailable)
                + "\nTIFF: " + MimeTypes.MIME_TIFF + ", tiff, tif"
                    + (BitmapEncoderRegistry.supports(MimeTypes.MIME_TIFF) 
                        ? "" : unavailable)
                + "\nJPEG: " + MimeTypes.MIME_JPEG + ", jpeg, jpg"
                    + (BitmapEncoderRegistry.supports(MimeTypes.MIME_JPEG) 
                        ? "" : unavailable)
                + "\nGIF: " + MimeTypes.MIME_GIF + ", gif"
                    + (BitmapEncoderRegistry.supports(MimeTypes.MIME_GIF) 
                        ? "" : unavailable)
                + (additionalMimes.size() > 0 
                    ? "\nAdditional supported formats:\n" + additionalMimes 
                    : "")
                + "\n"
                + "\nIf -o is omitted the output is written to stdout.");
        writer.flush();
        
    }

}

⌨️ 快捷键说明

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