Example usage for java.lang Thread MIN_PRIORITY

List of usage examples for java.lang Thread MIN_PRIORITY

Introduction

In this page you can find the example usage for java.lang Thread MIN_PRIORITY.

Prototype

int MIN_PRIORITY

To view the source code for java.lang Thread MIN_PRIORITY.

Click Source Link

Document

The minimum priority that a thread can have.

Usage

From source file:com.liferay.portal.plugin.PluginPackageUtil.java

private boolean _isUpdateAvailable() throws SystemException {
    if (!PrefsPropsUtil.getBoolean(PropsKeys.PLUGIN_NOTIFICATIONS_ENABLED,
            PropsValues.PLUGIN_NOTIFICATIONS_ENABLED)) {

        return false;
    }// w ww . j av a2 s . com

    if (_updateAvailable != null) {
        return _updateAvailable.booleanValue();
    } else if (!_settingUpdateAvailable) {
        _settingUpdateAvailable = true;

        Thread indexerThread = new Thread(new UpdateAvailableRunner(), PluginPackageUtil.class.getName());

        indexerThread.setPriority(Thread.MIN_PRIORITY);

        indexerThread.start();
    }

    return false;
}

From source file:org.opendedup.collections.ShardedProgressiveFileBasedCSMap.java

@Override
public synchronized long claimRecords(SDFSEvent evt, LargeBloomFilter bf) throws IOException {
    if (this.isClosed())
        throw new IOException("Hashtable " + this.fileName + " is close");
    executor = new ThreadPoolExecutor(Main.writeThreads + 1, Main.writeThreads + 1, 10, TimeUnit.SECONDS,
            worksQueue, new ProcessPriorityThreadFactory(Thread.MIN_PRIORITY), executionHandler);
    csz = new AtomicLong(0);

    try {//ww  w  . j ava2  s  .  co  m
        Lock l = this.gcLock.writeLock();
        l.lock();
        this.runningGC = true;
        try {
            File _fs = new File(fileName);
            lbf = null;
            lbf = new LargeBloomFilter(_fs.getParentFile(), maxSz, .001, true, true, false);
        } finally {
            l.unlock();
        }

        SDFSLogger.getLog().info("Claiming Records [" + this.getSize() + "] from [" + this.fileName + "]");
        SDFSEvent tEvt = SDFSEvent
                .claimInfoEvent("Claiming Records [" + this.getSize() + "] from [" + this.fileName + "]", evt);
        tEvt.maxCt = this.maps.size();
        Iterator<AbstractShard> iter = maps.iterator();
        ArrayList<ClaimShard> excs = new ArrayList<ClaimShard>();
        while (iter.hasNext()) {
            tEvt.curCt++;
            AbstractShard m = null;
            try {
                m = iter.next();
                ClaimShard cms = new ClaimShard(m, bf, lbf, csz);
                excs.add(cms);
                executor.execute(cms);
            } catch (Exception e) {
                tEvt.endEvent("Unable to claim records for " + m + " because : [" + e.toString() + "]",
                        SDFSEvent.ERROR);
                SDFSLogger.getLog().error("Unable to claim records for " + m, e);
                throw new IOException(e);
            }
        }
        executor.shutdown();
        try {
            while (!executor.awaitTermination(10, TimeUnit.SECONDS)) {
                SDFSLogger.getLog().debug("Awaiting fdisk completion of threads.");
            }
        } catch (InterruptedException e) {
            throw new IOException(e);
        }
        for (ClaimShard cms : excs) {
            if (cms.ex != null)
                throw new IOException(cms.ex);
        }
        this.kSz.getAndAdd(-1 * csz.get());
        tEvt.endEvent("removed [" + csz.get() + "] records");
        SDFSLogger.getLog().info("removed [" + csz.get() + "] records");
        iter = maps.iterator();
        while (iter.hasNext()) {
            AbstractShard m = null;
            try {
                m = iter.next();
                if (!m.isFull() && !m.isActive()) {

                    // SDFSLogger.getLog().info("deleting " +
                    // m.toString());
                    m.iterInit();
                    KVPair p = m.nextKeyValue();
                    while (p != null) {
                        AbstractShard _m = this.getWriteMap();
                        try {
                            _m.put(p.key, p.value, p.loc);
                            this.keyLookup.invalidate(new ByteArrayWrapper(p.key));
                            this.lbf.put(p.key);
                            p = m.nextKeyValue();
                        } catch (HashtableFullException e) {

                        }

                    }
                    int mapsz = maps.size();
                    l = this.gcLock.writeLock();
                    l.lock();
                    try {
                        maps.remove(m);
                    } finally {
                        l.unlock();
                    }
                    mapsz = mapsz - maps.size();
                    SDFSLogger.getLog()
                            .info("removing map " + m.toString() + " sz=" + maps.size() + " rm=" + mapsz);
                    m.vanish();

                    m = null;
                } else if (m.isMaxed()) {
                    SDFSLogger.getLog().info("deleting maxed " + m.toString());
                    m.iterInit();
                    KVPair p = m.nextKeyValue();
                    while (p != null) {
                        ShardedFileByteArrayLongMap _m = this.getWriteMap();
                        try {
                            _m.put(p.key, p.value);
                            p = m.nextKeyValue();
                        } catch (HashtableFullException e) {

                        }

                    }
                    int mapsz = maps.size();
                    l = this.gcLock.writeLock();
                    l.lock();
                    try {
                        maps.remove(m);
                    } finally {
                        l.unlock();
                    }
                    mapsz = mapsz - maps.size();
                    SDFSLogger.getLog()
                            .info("removing map " + m.toString() + " sz=" + maps.size() + " rm=" + mapsz);
                    m.vanish();

                    m = null;
                }
            } catch (Exception e) {
                tEvt.endEvent("Unable to compact " + m + " because : [" + e.toString() + "]", SDFSEvent.ERROR);
                SDFSLogger.getLog().error("to compact " + m, e);
                throw new IOException(e);
            }
        }
        l.lock();
        this.runningGC = false;
        l.unlock();
        return csz.get();
    } finally {
        executor = null;
    }
}

From source file:com.irccloud.android.activity.MainActivity.java

@SuppressLint("NewApi")
@SuppressWarnings({ "deprecation", "unchecked" })
@Override/*from w w  w.j  a v a  2s .c  o  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    suggestionsTimer = new Timer("suggestions-timer");
    countdownTimer = new Timer("messsage-countdown-timer");

    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    registerReceiver(screenReceiver, filter);

    if (Build.VERSION.SDK_INT >= 21) {
        Bitmap cloud = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
        if (cloud != null) {
            setTaskDescription(new ActivityManager.TaskDescription(getResources().getString(R.string.app_name),
                    cloud, 0xFFF2F7FC));
            cloud.recycle();
        }
    }
    setContentView(R.layout.activity_message);
    try {
        setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    } catch (Throwable t) {
    }

    suggestionsAdapter = new SuggestionsAdapter();
    progressBar = (ProgressBar) findViewById(R.id.progress);
    errorMsg = (TextView) findViewById(R.id.errorMsg);
    buffersListView = findViewById(R.id.BuffersList);
    messageContainer = (LinearLayout) findViewById(R.id.messageContainer);
    drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);

    redColor = getResources().getColor(R.color.highlight_red);
    blueColor = getResources().getColor(R.color.dark_blue);

    messageTxt = (ActionEditText) findViewById(R.id.messageTxt);
    messageTxt.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (sendBtn.isEnabled()
                    && NetworkConnection.getInstance().getState() == NetworkConnection.STATE_CONNECTED
                    && event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER
                    && messageTxt.getText() != null && messageTxt.getText().length() > 0) {
                sendBtn.setEnabled(false);
                new SendTask().execute((Void) null);
            } else if (keyCode == KeyEvent.KEYCODE_TAB) {
                if (event.getAction() == KeyEvent.ACTION_DOWN)
                    nextSuggestion();
                return true;
            }
            return false;
        }
    });
    messageTxt.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (drawerLayout != null && v == messageTxt && hasFocus) {
                drawerLayout.closeDrawers();
                update_suggestions(false);
            } else if (!hasFocus) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        suggestionsContainer.setVisibility(View.INVISIBLE);
                    }
                });
            }
        }
    });
    messageTxt.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (drawerLayout != null) {
                drawerLayout.closeDrawers();
            }
        }
    });
    messageTxt.setOnEditorActionListener(new OnEditorActionListener() {
        public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
            if (sendBtn.isEnabled()
                    && NetworkConnection.getInstance().getState() == NetworkConnection.STATE_CONNECTED
                    && actionId == EditorInfo.IME_ACTION_SEND && messageTxt.getText() != null
                    && messageTxt.getText().length() > 0) {
                sendBtn.setEnabled(false);
                new SendTask().execute((Void) null);
            }
            return true;
        }
    });
    textWatcher = new TextWatcher() {
        public void afterTextChanged(Editable s) {
            Object[] spans = s.getSpans(0, s.length(), Object.class);
            for (Object o : spans) {
                if (((s.getSpanFlags(o) & Spanned.SPAN_COMPOSING) != Spanned.SPAN_COMPOSING)
                        && (o.getClass() == StyleSpan.class || o.getClass() == ForegroundColorSpan.class
                                || o.getClass() == BackgroundColorSpan.class
                                || o.getClass() == UnderlineSpan.class || o.getClass() == URLSpan.class)) {
                    s.removeSpan(o);
                }
            }
            if (s.length() > 0
                    && NetworkConnection.getInstance().getState() == NetworkConnection.STATE_CONNECTED) {
                sendBtn.setEnabled(true);
                if (Build.VERSION.SDK_INT >= 11)
                    sendBtn.setAlpha(1);
            } else {
                sendBtn.setEnabled(false);
                if (Build.VERSION.SDK_INT >= 11)
                    sendBtn.setAlpha(0.5f);
            }
            String text = s.toString();
            if (text.endsWith("\t")) { //Workaround for Swype
                text = text.substring(0, text.length() - 1);
                messageTxt.setText(text);
                nextSuggestion();
            } else if (suggestionsContainer != null && suggestionsContainer.getVisibility() == View.VISIBLE) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        update_suggestions(false);
                    }
                });
            } else {
                if (suggestionsTimer != null) {
                    if (suggestionsTimerTask != null)
                        suggestionsTimerTask.cancel();
                    suggestionsTimerTask = new TimerTask() {
                        @Override
                        public void run() {
                            Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
                            update_suggestions(false);
                        }
                    };
                    suggestionsTimer.schedule(suggestionsTimerTask, 250);
                }
            }
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    };
    messageTxt.addTextChangedListener(textWatcher);
    sendBtn = findViewById(R.id.sendBtn);
    sendBtn.setFocusable(false);
    sendBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (NetworkConnection.getInstance().getState() == NetworkConnection.STATE_CONNECTED)
                new SendTask().execute((Void) null);
        }
    });

    photoBtn = findViewById(R.id.photoBtn);
    if (photoBtn != null) {
        photoBtn.setFocusable(false);
        photoBtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                insertPhoto();
            }
        });
    }
    userListView = findViewById(R.id.usersListFragment);

    View v = getLayoutInflater().inflate(R.layout.actionbar_messageview, null);
    v.findViewById(R.id.actionTitleArea).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            show_topic_popup();
        }
    });

    if (drawerLayout != null) {
        if (findViewById(R.id.usersListFragment2) == null) {
            upDrawable = new DrawerArrowDrawable(this);
            greyColor = upDrawable.getColor();
            ((Toolbar) findViewById(R.id.toolbar)).setNavigationIcon(upDrawable);
            ((Toolbar) findViewById(R.id.toolbar)).setNavigationContentDescription("Show navigation drawer");
            drawerLayout.setDrawerListener(mDrawerListener);
            if (refreshUpIndicatorTask != null)
                refreshUpIndicatorTask.cancel(true);
            refreshUpIndicatorTask = new RefreshUpIndicatorTask();
            refreshUpIndicatorTask.execute((Void) null);
        }
    }
    messageTxt.setDrawerLayout(drawerLayout);

    title = (TextView) v.findViewById(R.id.title);
    subtitle = (TextView) v.findViewById(R.id.subtitle);
    key = (ImageView) v.findViewById(R.id.key);
    getSupportActionBar().setCustomView(v);
    getSupportActionBar().setDisplayShowCustomEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(false);

    if (savedInstanceState != null && savedInstanceState.containsKey("cid")) {
        server = ServersDataSource.getInstance().getServer(savedInstanceState.getInt("cid"));
        buffer = BuffersDataSource.getInstance().getBuffer(savedInstanceState.getInt("bid"));
        backStack = (ArrayList<Integer>) savedInstanceState.getSerializable("backStack");
    }

    if (savedInstanceState != null && savedInstanceState.containsKey("imagecaptureuri"))
        imageCaptureURI = Uri.parse(savedInstanceState.getString("imagecaptureuri"));
    else
        imageCaptureURI = null;

    ConfigInstance config = (ConfigInstance) getLastCustomNonConfigurationInstance();
    if (config != null) {
        imgurTask = config.imgurUploadTask;
        fileUploadTask = config.fileUploadTask;
    }

    drawerLayout.setScrimColor(0);
    drawerLayout.closeDrawers();

    getSupportActionBar().setElevation(0);
}

From source file:org.proteomecommons.tranche.modules.advancedsearch.AdvancedSearchPanel.java

/**
 * Performs the search, updates the GUI//from  w w  w .  j a v  a 2 s .c  om
 */
public void search() {

    Thread t = new Thread() {

        public void run() {
            // For HTTP response
            BufferedReader reader = null;
            final IndeterminateProgressBar progress = new IndeterminateProgressBar("Connecting to database...");
            try {
                // Clear out all ephemeral components
                resetSearchView();

                progress.setDisposeAllowable(true);
                progress.setLocationRelativeTo(main);

                Thread pthread = new Thread() {

                    public void run() {
                        progress.start();
                    }
                };
                SwingUtilities.invokeLater(pthread);

                // Make the query string
                StringBuffer query = new StringBuffer();

                // "Any" refers to default query parameter
                String ionSelection = ionSourceDropDown.getSelectedItem().toString();
                if (ionSelection.equalsIgnoreCase("any")) {
                    ionSelection = "";
                }
                String journalSelection = journalDropDown.getSelectedItem().toString();
                if (journalSelection.equalsIgnoreCase("any")) {
                    journalSelection = "";
                }
                String instrumentSelection = instrumentDropDown.getSelectedItem().toString();
                if (instrumentSelection.equalsIgnoreCase("any")) {
                    instrumentSelection = "";
                }
                query.append("q=" + GUIUtil.createURLEncodedString(keywordText.getText()));
                query.append("&i=" + GUIUtil.createURLEncodedString(ionSelection));
                query.append("&j=" + GUIUtil.createURLEncodedString(journalSelection));
                query.append("&n=" + GUIUtil.createURLEncodedString(researcherText.getText()));
                query.append("&o=" + GUIUtil.createURLEncodedString(organismText.getText()));
                query.append("&m=" + GUIUtil.createURLEncodedString(instrumentSelection));
                if (onlineResultsOnlyBox.isSelected()) {
                    query.append("&t=on"); // HTTP request for results
                }
                HttpClient c = new HttpClient();
                GetMethod pm = new GetMethod(
                        "http://www.proteomecommons.org/data/tranche-advanced-search.jsp?" + query.toString());

                // execute the method
                if (c.executeMethod(pm) != 200) {
                    throw new Exception("Unsuccessfully registered hash.");
                }

                // Get response
                reader = new BufferedReader(new InputStreamReader(pm.getResponseBodyAsStream()));

                String line = null;
                // Buffer each entry separately
                StringBuffer buffer = new StringBuffer();

                while ((line = reader.readLine()) != null) {

                    printTracer("Reading next response line: " + line);

                    // Trim the line (to be safe)
                    line = line.trim() + " ";

                    // Skip blank lines
                    if (line.trim().equals("")) {
                        continue;
                    }
                    // If new entry
                    if (line.startsWith("TITLE")) {
                        // Add previous buffer to entry if not empty
                        if (!buffer.toString().trim().equals("")) {
                            // Add component
                            addEphemeralComponent(new SearchResult(buffer));
                            buffer = new StringBuffer();
                        }

                        buffer.append(line);
                    } else {
                        // Building up subsequent lines
                        buffer.append(line);
                    }
                }

                progress.stop();
                // If no results, notify user
                if (ephemeralComponents.size() == 0) {
                    JOptionPane.showMessageDialog(main, "You query didn't yield any matches.", "No results",
                            JOptionPane.INFORMATION_MESSAGE);
                } else {

                    String title = "Search results";
                    String message = "A total of ";

                    if (ephemeralComponents.size() == 1) {
                        message += "1 result was ";
                    } else {
                        message += (ephemeralComponents.size() + " results were ");
                    }
                    message += "found.";

                    JOptionPane.showMessageDialog(main, message, title, JOptionPane.INFORMATION_MESSAGE);
                }
            } catch (Exception ex) {
                progress.stop();
                ErrorFrame ef = new ErrorFrame();
                ef.show(ex, main);
            } finally {
                IOUtil.safeClose(reader);

                Thread updateThread = new Thread() {

                    public void run() {
                        updateUI();
                        // Request focus (scroll bar to top)
                        keywordText.select(0, 1);
                        keywordText.requestFocus();
                    }
                };
                SwingUtilities.invokeLater(updateThread);
            }

        } // run
    };
    t.setDaemon(true);
    t.setPriority(Thread.MIN_PRIORITY);
    t.start();
}

From source file:org.rhq.bundle.ant.AntMain.java

/** Handle the -nice argument. */
private int handleArgNice(String[] args, int pos) {
    try {/*w w  w .j  a  va2  s .c o m*/
        threadPriority = Integer.decode(args[++pos]);
    } catch (ArrayIndexOutOfBoundsException aioobe) {
        throw new BuildException("You must supply a niceness value (1-10)" + " after the -nice option");
    } catch (NumberFormatException e) {
        throw new BuildException("Unrecognized niceness value: " + args[pos]);
    }

    if (threadPriority.intValue() < Thread.MIN_PRIORITY || threadPriority.intValue() > Thread.MAX_PRIORITY) {
        throw new BuildException("Niceness value is out of the range 1-10");
    }
    return pos;
}

From source file:org.gtdfree.ApplicationHelper.java

public static synchronized void executeInBackground(Runnable r) {

    if (backgroundExecutor == null) {
        backgroundExecutor = new ThreadPoolExecutor(0, 1, 1, TimeUnit.SECONDS,
                new LinkedBlockingQueue<Runnable>(), new ThreadFactory() {

                    @Override/*  w  w  w  . j  av a2 s.  com*/
                    public Thread newThread(Runnable r) {
                        Thread t = new Thread(r);
                        t.setName("BackgroundExecutor"); //$NON-NLS-1$
                        t.setPriority(Thread.MIN_PRIORITY);
                        t.setDaemon(false);
                        return t;
                    }
                });
    }

    backgroundExecutor.execute(r);

}

From source file:com.googlecode.fascinator.indexer.SolrWrapperQueueConsumer.java

/**
 * Sets the priority level for the thread. Used by the OS.
 * /*from w  w  w  . j  a  v  a2  s.c  o m*/
 * @param newPriority The priority level to set the thread at
 */
@Override
public void setPriority(int newPriority) {
    if (newPriority >= Thread.MIN_PRIORITY && newPriority <= Thread.MAX_PRIORITY) {
        thread.setPriority(newPriority);
    }
}

From source file:tvbrowser.ui.mainframe.MainFrame.java

/**
 * Switch the fullscreen mode of TV-Browser
 */// ww w .  j ava 2s.c  o m
public void switchFullscreenMode() {
    dispose();

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();

            if (isFullScreenMode()) {
                // switch back from fullscreen
                device.setFullScreenWindow(null);
                setUndecorated(false);
                setBounds(mXPos, mYPos, mWidth, mHeight);

                if (mMenuBar != null) {
                    mMenuBar.setFullscreenItemChecked(false);
                    mMenuBar.setVisible(true);
                }

                if (mToolBarPanel != null) {
                    mToolBarPanel.setVisible(Settings.propIsToolbarVisible.getBoolean());
                }

                if (mStatusBar != null) {
                    mStatusBar.setVisible(Settings.propIsStatusbarVisible.getBoolean());
                }

                if (mChannelChooser != null) {
                    mChannelChooser.setVisible(Settings.propShowChannels.getBoolean());
                }

                if (mFinderPanel != null) {
                    mFinderPanel.getComponent().setVisible(Settings.propShowDatelist.getBoolean());
                }

                setVisible(true);

                setShowPluginOverview(Settings.propShowPluginView.getBoolean(), false);
                setShowTimeButtons(Settings.propShowTimeButtons.getBoolean(), false);
                setShowDatelist(Settings.propShowDatelist.getBoolean(), false);
                setShowChannellist(Settings.propShowChannels.getBoolean(), false);
            } else {
                // switch into fullscreen
                mXPos = getX();
                mYPos = getY();
                mWidth = getWidth();
                mHeight = getHeight();

                setShowPluginOverview(false, false);
                setShowTimeButtons(false, false);
                setShowDatelist(false, false);
                setShowChannellist(false, false);

                if (mStatusBar != null) {
                    mMenuBar.setFullscreenItemChecked(true);
                    mStatusBar.setVisible(false);
                }

                if (mChannelChooser != null) {
                    mChannelChooser.setVisible(false);
                }

                if (mMenuBar != null) {
                    mMenuBar.setVisible(false);
                }

                if (mToolBarPanel != null) {
                    mToolBarPanel.setVisible(false);
                }

                if (mFinderPanel != null) {
                    mFinderPanel.getComponent().setVisible(false);
                }

                setUndecorated(true);
                final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();

                if (device.isFullScreenSupported() && OperatingSystem.isMacOs()) {
                    device.setFullScreenWindow(MainFrame.getInstance());
                } else {
                    setLocation(0, 0);
                    setSize(screen);
                }

                setVisible(true);
                mProgramTableScrollPane.requestFocusInWindow();

                new Thread("Fullscreen border detection") {
                    public void run() {
                        setPriority(Thread.MIN_PRIORITY);

                        while (isFullScreenMode()) {
                            final Point p = MouseInfo.getPointerInfo().getLocation();
                            SwingUtilities.convertPointFromScreen(p, MainFrame.this);

                            if (isActive()) {

                                // mouse pointer is at top
                                if (p.y <= 10) {
                                    if (mToolBarPanel != null && mToolBar.getToolbarLocation()
                                            .compareTo(BorderLayout.NORTH) == 0) {
                                        if (!mToolBarPanel.isVisible()) {
                                            mToolBarPanel
                                                    .setVisible(Settings.propIsToolbarVisible.getBoolean());
                                        }
                                    }

                                    if (p.y <= 0) {
                                        mMenuBar.setVisible(true);
                                    }
                                } else if (p.y > (mMenuBar != null && mMenuBar.isVisible()
                                        ? mMenuBar.getHeight()
                                        : 0)
                                        + (Settings.propIsToolbarVisible.getBoolean()
                                                ? mToolBarPanel.getHeight()
                                                : 0)) {
                                    if (mMenuBar.isVisible()) {
                                        mMenuBar.setVisible(!isFullScreenMode());
                                    }

                                    if (mToolBarPanel != null && mToolBarPanel.isVisible() && mToolBar
                                            .getToolbarLocation().compareTo(BorderLayout.NORTH) == 0) {
                                        mToolBarPanel.setVisible(!isFullScreenMode());
                                    }
                                }

                                // mouse pointer is at the bottom
                                if (p.y >= screen.height - 1) {
                                    if (mStatusBar != null && !mStatusBar.isVisible()) {
                                        mStatusBar.setVisible(Settings.propIsStatusbarVisible.getBoolean());
                                    }
                                } else if (mStatusBar != null && mStatusBar.isVisible()
                                        && p.y < screen.height - mStatusBar.getHeight()) {
                                    mStatusBar.setVisible(!isFullScreenMode());
                                }

                                // mouse pointer is on the left side
                                if (p.x <= 5) {
                                    if (p.x == 0 && mToolBarPanel != null && mToolBar.getToolbarLocation()
                                            .compareTo(BorderLayout.WEST) == 0) {
                                        if (!mToolBarPanel.isVisible()) {
                                            mToolBarPanel
                                                    .setVisible(Settings.propIsToolbarVisible.getBoolean());
                                        }
                                    }

                                    if (Settings.propPluginViewIsLeft.getBoolean()) {
                                        if (Settings.propShowPluginView.getBoolean()) {
                                            SwingUtilities.invokeLater(new Runnable() {
                                                public void run() {
                                                    setShowPluginOverview(true, false);
                                                }
                                            });
                                        }
                                    } else {
                                        checkIfToShowTimeDateChannelList();
                                    }
                                } else {
                                    int toolBarWidth = (mToolBarPanel != null && mToolBarPanel.isVisible()
                                            && mToolBar.getToolbarLocation().compareTo(BorderLayout.WEST) == 0)
                                                    ? mToolBarPanel.getWidth()
                                                    : 0;

                                    if (p.x > toolBarWidth && toolBarWidth != 0) {
                                        mToolBarPanel.setVisible(!isFullScreenMode());
                                    }

                                    if (Settings.propPluginViewIsLeft.getBoolean()) {
                                        if (Settings.propShowPluginView.getBoolean() && mPluginView != null
                                                && mPluginView.isVisible()
                                                && p.x > mPluginView.getWidth() + toolBarWidth + 25) {
                                            SwingUtilities.invokeLater(new Runnable() {
                                                public void run() {
                                                    setShowPluginOverview(!isFullScreenMode(), false);
                                                }
                                            });
                                        }
                                    } else if (Settings.propShowChannels.getBoolean()
                                            || Settings.propShowDatelist.getBoolean()
                                            || Settings.propShowTimeButtons.getBoolean()) {
                                        SwingUtilities.invokeLater(new Runnable() {
                                            public void run() {
                                                if (mChannelChooser != null && mChannelChooser.isVisible()
                                                        && p.x > mChannelChooser.getWidth()) {
                                                    setShowChannellist(!isFullScreenMode(), false);
                                                }

                                                if (mFinderPanel != null
                                                        && mFinderPanel.getComponent().isVisible()
                                                        && p.x > mFinderPanel.getComponent().getWidth()) {
                                                    setShowDatelist(!isFullScreenMode(), false);
                                                }

                                                if (mTimeChooserPanel != null && mTimeChooserPanel.isVisible()
                                                        && p.x > mTimeChooserPanel.getWidth()) {
                                                    setShowTimeButtons(!isFullScreenMode(), false);
                                                }
                                            }
                                        });
                                    }
                                }

                                // mouse pointer is on the right side
                                if (p.x >= screen.width - 1) {
                                    if (!Settings.propPluginViewIsLeft.getBoolean()) {
                                        if (Settings.propShowPluginView.getBoolean()) {
                                            SwingUtilities.invokeLater(new Runnable() {
                                                public void run() {
                                                    setShowPluginOverview(true, false);
                                                }
                                            });
                                        }
                                    } else {
                                        checkIfToShowTimeDateChannelList();
                                    }
                                } else {
                                    if (!Settings.propPluginViewIsLeft.getBoolean()) {
                                        if (Settings.propShowPluginView.getBoolean() && mPluginView != null
                                                && mPluginView.isVisible()
                                                && p.x < screen.width - mPluginView.getWidth()) {
                                            SwingUtilities.invokeLater(new Runnable() {
                                                public void run() {
                                                    setShowPluginOverview(!isFullScreenMode(), false);
                                                }
                                            });
                                        }
                                    } else if (Settings.propShowChannels.getBoolean()
                                            || Settings.propShowDatelist.getBoolean()
                                            || Settings.propShowTimeButtons.getBoolean()) {
                                        SwingUtilities.invokeLater(new Runnable() {
                                            public void run() {
                                                if (mChannelChooser != null && mChannelChooser.isVisible()
                                                        && p.x < screen.width - mChannelChooser.getWidth()) {
                                                    setShowChannellist(!isFullScreenMode(), false);
                                                }

                                                if (mFinderPanel != null
                                                        && mFinderPanel.getComponent().isVisible()
                                                        && p.x < screen.width
                                                                - mFinderPanel.getComponent().getWidth()) {
                                                    setShowDatelist(!isFullScreenMode(), false);
                                                }

                                                if (mTimeChooserPanel != null && mTimeChooserPanel.isVisible()
                                                        && p.x < screen.width - mTimeChooserPanel.getWidth()) {
                                                    setShowTimeButtons(!isFullScreenMode(), false);
                                                }
                                            }
                                        });
                                    }
                                }
                            }
                            try {
                                Thread.sleep(200);
                            } catch (Exception e) {
                            }
                        }
                    }
                }.start();
            }
        }
    });
}

From source file:Animator.java

/**
 * Run the animation. This method is called by class Thread.
 * // ww w  . j  a v a 2  s.c  o m
 * @see java.lang.Thread
 */
public void run() {
    Thread me = Thread.currentThread();
    URL badURL;

    me.setPriority(Thread.MIN_PRIORITY);

    if (!loaded) {
        try {
            // ... to do a bunch of loading.
            if (startUpImageURL != null) {
                tellLoadingMsg(startUpImageURL, imageLabel);
                startUpImage = getImage(startUpImageURL);
                tracker.addImage(startUpImage, STARTUP_ID);
                tracker.waitForID(STARTUP_ID);
                if (tracker.isErrorID(STARTUP_ID)) {
                    loadError(startUpImageURL, "start-up image");
                }
                Dimension size = getImageDimensions(startUpImage);
                resize(size.width, size.height);
                repaint();
            }

            if (backgroundImageURL != null) {
                tellLoadingMsg(backgroundImageURL, imageLabel);
                backgroundImage = getImage(backgroundImageURL);
                tracker.addImage(backgroundImage, BACKGROUND_ID);
                tracker.waitForID(BACKGROUND_ID);
                if (tracker.isErrorID(BACKGROUND_ID)) {
                    loadError(backgroundImageURL, "background image");
                }
                updateMaxDims(getImageDimensions(backgroundImage));
                repaint();
            }

            // Fetch the animation frames
            if (!fetchImages(images)) {
                // Need to add method to MediaTracker to return
                // files that caused errors during loading.
                loadError("an image", imageLabel);
                return;
            }

            if (soundtrackURL != null && soundtrack == null) {
                tellLoadingMsg(soundtrackURL, imageLabel);
                soundtrack = getAudioClip(soundtrackURL);
                if (soundtrack == null) {
                    loadError(soundtrackURL, "soundtrack");
                    return;
                }
            }

            if (sounds != null) {
                badURL = fetchSounds(sounds);
                if (badURL != null) {
                    loadError(badURL, soundLabel);
                    return;
                }
            }

            clearLoadingMessage();

            offScrImage = createImage(maxWidth, maxHeight);
            offScrGC = offScrImage.getGraphics();
            offScrGC.setColor(Color.white);

            resize(maxWidth, maxHeight);
            loaded = true;
            error = false;
        } catch (Exception e) {
            error = true;
            e.printStackTrace();
        }
    }

    if (userPause) {
        return;
    }

    if (repeat || frameNum < images.size()) {
        startPlaying();
    }

    try {
        if (images.size() > 1) {
            while (maxWidth > 0 && maxHeight > 0 && engine == me) {
                if (frameNum >= images.size()) {
                    if (!repeat) {
                        return;
                    }
                    setFrameNum(0);
                }
                repaint();

                if (sounds != null) {
                    AudioClip clip = (AudioClip) sounds.get(frameNumKey);
                    if (clip != null) {
                        clip.play();
                    }
                }

                try {
                    Integer pause = null;
                    if (durations != null) {
                        pause = (Integer) durations.get(frameNumKey);
                    }
                    if (pause == null) {
                        Thread.sleep(globalPause);
                    } else {
                        Thread.sleep(pause.intValue());
                    }
                } catch (InterruptedException e) {
                    // Should we do anything?
                }
                setFrameNum(frameNum + 1);
            }
        }
    } finally {
        stopPlaying();
    }
}

From source file:MyJava3D.java

public void start() {
    if (thread == null) {
        thread = new Thread(this);
        thread.setPriority(Thread.MIN_PRIORITY);
        thread.start();/*w  w w .ja v  a  2 s  .  c  o  m*/
    }
}