Example usage for javax.swing.text DefaultFormatter setAllowsInvalid

List of usage examples for javax.swing.text DefaultFormatter setAllowsInvalid

Introduction

In this page you can find the example usage for javax.swing.text DefaultFormatter setAllowsInvalid.

Prototype

public void setAllowsInvalid(boolean allowsInvalid) 

Source Link

Document

Sets whether or not the value being edited is allowed to be invalid for a length of time (that is, stringToValue throws a ParseException).

Usage

From source file:gui.GW2EventerGui.java

/**
 * Creates new form GW2EventerGui//from   ww  w. j  a  va 2s  . c o m
 */
public GW2EventerGui() {

    this.guiIcon = new ImageIcon(ClassLoader.getSystemResource("media/icon.png")).getImage();

    if (System.getProperty("os.name").startsWith("Windows")) {
        this.OS = "Windows";
        this.isWindows = true;
    } else {
        this.OS = "Other";
        this.isWindows = false;
    }

    if (this.isWindows == true) {
        this.checkIniDir();
    }

    initComponents();

    this.speakQueue = new LinkedList();

    this.speakRunnable = new Runnable() {

        @Override
        public void run() {

            String path = System.getProperty("user.home") + "\\.gw2eventer";
            File f;
            String sentence;

            while (!speakQueue.isEmpty()) {

                f = new File(path + "\\tts.vbs");

                if (!f.exists() && !f.isDirectory()) {

                    sentence = (String) speakQueue.poll();

                    try {

                        Writer writer = new OutputStreamWriter(
                                new FileOutputStream(
                                        System.getProperty("user.home") + "\\.gw2eventer\\tts.vbs"),
                                "ISO-8859-15");
                        BufferedWriter fout = new BufferedWriter(writer);

                        fout.write("Dim Speak");
                        fout.newLine();
                        fout.write("Set Speak=CreateObject(\"sapi.spvoice\")");
                        fout.newLine();
                        fout.write("Speak.Speak \"" + sentence + "\"");

                        fout.close();

                        Runtime rt = Runtime.getRuntime();

                        try {
                            if (sentence.length() > 0) {
                                Process p = rt.exec(System.getProperty("user.home") + "\\.gw2eventer\\tts.bat");
                            }
                        } catch (IOException ex) {
                            Logger.getLogger(GW2EventerGui.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    } catch (FileNotFoundException ex) {
                        Logger.getLogger(GW2EventerGui.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (IOException ex) {
                        Logger.getLogger(GW2EventerGui.class.getName()).log(Level.SEVERE, null, ex);
                    }

                    try {
                        Thread.sleep(3000);
                    } catch (InterruptedException ex) {
                        Logger.getLogger(GW2EventerGui.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } else {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException ex) {
                        Logger.getLogger(GW2EventerGui.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        }
    };

    this.matchIds = new HashMap();
    this.matchId = "2-6";
    this.matchIdColor = "green";

    this.jLabelNewVersion.setVisible(false);
    this.updateInformed = false;

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    this.setLocation(screenSize.width / 2 - this.getSize().width / 2,
            (screenSize.height / 2 - this.getSize().height / 2) - 20);

    double width = screenSize.getWidth();
    double height = screenSize.getHeight();

    if ((width == 1280) && (height == 720 || height == 768 || height == 800)) {
        this.setExtendedState(this.MAXIMIZED_BOTH);
        //this.setLocation(0, 0);
    }

    JSpinner.NumberEditor jsEditor = (JSpinner.NumberEditor) this.jSpinnerRefreshTime.getEditor();
    DefaultFormatter formatter = (DefaultFormatter) jsEditor.getTextField().getFormatter();
    formatter.setAllowsInvalid(false);

    /*
     jsEditor = (JSpinner.NumberEditor)this.jSpinnerOverlayX.getEditor();
     formatter = (DefaultFormatter) jsEditor.getTextField().getFormatter();
     formatter.setAllowsInvalid(false);
            
     jsEditor = (JSpinner.NumberEditor)this.jSpinnerOverlayY.getEditor();
     formatter = (DefaultFormatter) jsEditor.getTextField().getFormatter();
     formatter.setAllowsInvalid(false);
     */
    this.workingButton = this.jButtonRefresh;
    this.refreshSelector = this.jCheckBoxAutoRefresh;

    this.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {

            apiManager.saveSettingstoFile();
            System.exit(0);
        }
    });

    this.pushGui = new PushGui(this, true, "", "");
    this.pushGui.setIconImage(guiIcon);

    this.donateGui = new DonateGui(this, true);
    this.donateGui.setIconImage(guiIcon);

    this.infoGui = new InfoGui(this, true);
    this.infoGui.setIconImage(guiIcon);

    this.feedbackGui = new FeedbackGui(this, true);
    this.feedbackGui.setIconImage(guiIcon);

    this.overlayGui = new OverlayGui(this);
    this.initOverlayGui();

    this.settingsOverlayGui = new SettingsOverlayGui(this);
    this.initSettingsOverlayGui();

    this.wvwOverlayGui = new WvWOverlayGui(this);
    this.initWvwOverlayGui();

    this.language = "en";
    this.worldID = "2206"; //Millersund [DE]

    this.setTranslations();

    this.eventLabels = new ArrayList();
    this.eventLabelsTimer = new ArrayList();

    this.homeWorlds = new HashMap();

    this.preventSystemSleep = true;

    for (int i = 1; i <= EVENT_COUNT; i++) {

        try {

            Field f = getClass().getDeclaredField("labelEvent" + i);
            JLabel l = (JLabel) f.get(this);
            l.setPreferredSize(new Dimension(70, 28));
            //l.setToolTipText("");

            //int width2 = l.getX();
            //int height2 = l.getY();
            //System.out.println("$coords .= \"{\\\"x\\\": \\\""+ width2 + "\\\", \\\"y\\\": \\\""+ height2 + "\\\"},\\n\";");
            this.eventLabels.add(l);

            final int ii = i;

            l.addMouseListener(new java.awt.event.MouseAdapter() {
                @Override
                public void mousePressed(java.awt.event.MouseEvent evt) {
                    showSoundSelector(ii);
                }
            });

            f = getClass().getDeclaredField("labelTimer" + i);
            l = (JLabel) f.get(this);
            l.setEnabled(true);
            l.setVisible(false);
            l.setForeground(Color.green);

            //int width2 = l.getX();
            //int height2 = l.getY();
            //System.out.println("$coords2 .= \"{\\\"x\\\": \\\""+ width2 + "\\\", \\\"y\\\": \\\""+ height2 + "\\\"},\\n\";");
            this.eventLabelsTimer.add(l);

        } catch (NoSuchFieldException | SecurityException | IllegalArgumentException
                | IllegalAccessException ex) {
            Logger.getLogger(GW2EventerGui.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    int[] disabledEvents = { 6, 8, 11, 12, 17, 18, 19, 20, 21, 22 };

    for (int i = 0; i < disabledEvents.length; i++) {

        Field f;
        JLabel l;

        try {
            f = getClass().getDeclaredField("labelEvent" + disabledEvents[i]);
            l = (JLabel) f.get(this);
            l.setEnabled(false);
            l.setVisible(false);

            f = getClass().getDeclaredField("labelTimer" + disabledEvents[i]);
            l = (JLabel) f.get(this);
            l.setEnabled(false);
            l.setVisible(false);
        } catch (NoSuchFieldException | SecurityException | IllegalArgumentException
                | IllegalAccessException ex) {
            Logger.getLogger(GW2EventerGui.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    this.lastPush = new Date();

    if (this.apiManager == null) {

        this.apiManager = new ApiManager(this, this.jSpinnerRefreshTime, this.jCheckBoxAutoRefresh.isSelected(),
                this.eventLabels, this.language, this.worldID, this.homeWorlds, this.jComboBoxHomeWorld,
                this.jLabelServer, this.jLabelWorking, this.jCheckBoxPlaySounds.isSelected(),
                this.workingButton, this.refreshSelector, this.eventLabelsTimer, this.jComboBoxLanguage,
                this.overlayGui, this.jCheckBoxWvWOverlay);
    }

    //this.wvwMatchReader = new WvWMatchReader(this.matchIds, this.jCheckBoxWvW);
    //this.wvwMatchReader.start();
    this.preventSleepMode();
    this.runUpdateService();
    this.runPushService();
    this.runTips();
    //this.runTest();
}