Search in sources :

Example 86 with Cursor

use of java.awt.Cursor in project zencash-swing-wallet-ui by ZencashOfficial.

the class IPFSWrapper method startIPFS.

// true if started OK
private boolean startIPFS() throws IOException, InterruptedException {
    // Warn user if executable and dir are missing!
    File dir = new File(this.getIPFSDirectory());
    if ((!dir.exists()) || (!dir.isDirectory())) {
        JOptionPane.showMessageDialog(this.parentFrame, "The IPFS executables are expected to be found in directory:\n" + dir.getCanonicalPath() + "\n" + "However this directory is missing! IPFS cannot be started!", "IPFS directory is not available", JOptionPane.ERROR_MESSAGE);
        return false;
    }
    File ipfsCmd = new File(this.getIPFSFullExecutablePath());
    if ((!ipfsCmd.exists()) || (!ipfsCmd.isFile())) {
        JOptionPane.showMessageDialog(this.parentFrame, "The IPFS command executable:\n" + ipfsCmd.getCanonicalPath() + "\n" + "needs to be available in order to start an IPFS Server on this PC." + "However this executable file is missing! IPFS cannot be started!", "IPFS executable is not available", JOptionPane.ERROR_MESSAGE);
        return false;
    }
    // Check IPFS config and possibly initialize it
    File userhome = OSUtil.getUserHomeDirectory();
    File ipfsConfig = new File(userhome, ".ipfs" + File.separator + "config");
    if (!ipfsConfig.exists()) {
        Log.info("IPFS configuration file {0} does not exist. IPFS will be initilaized!", ipfsConfig.getCanonicalPath());
        CommandExecutor initilaizer = new CommandExecutor(new String[] { this.getIPFSFullExecutablePath(), "init" });
        String initResponse = initilaizer.execute();
        Log.info("IPFS initilaization messages: {0}", initResponse);
    }
    // Finally start IPFS
    CommandExecutor starter = new CommandExecutor(new String[] { this.getIPFSFullExecutablePath(), "daemon" });
    this.IPFSProcess = starter.startChildProcess();
    // Wait 20 sec to make sure the daemon is started
    // TODO: better way to find out if it is started
    Cursor oldCursor = this.parentFrame.getCursor();
    this.parentFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    Thread.sleep(20 * 1000);
    this.parentFrame.setCursor(oldCursor);
    Runtime.getRuntime().addShutdownHook(new Thread() {

        public void run() {
            Log.info("Stopping IPFS...");
            try {
                IPFSWrapper.this.IPFSProcess.destroy();
            } catch (Exception bad) {
                Log.error("Couldn't stop IPFS!", bad);
            }
        }
    });
    return true;
}
Also used : CommandExecutor(com.vaklinov.zcashui.CommandExecutor) Cursor(java.awt.Cursor) File(java.io.File) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ProtocolException(java.net.ProtocolException)

Example 87 with Cursor

use of java.awt.Cursor in project com.revolsys.open by revolsys.

the class AbstractRunnable method run.

@Override
public final void run() {
    try {
        if (isShowWaitCursor() && isEventDispatchThread()) {
            final Window activeWindow = getActiveWindow();
            if (activeWindow == null) {
                runDo();
            } else {
                Component component;
                Component glassPane = null;
                if (activeWindow instanceof RootPaneContainer) {
                    final RootPaneContainer container = (RootPaneContainer) activeWindow;
                    glassPane = container.getGlassPane();
                    glassPane.setVisible(true);
                    component = glassPane;
                } else {
                    component = activeWindow;
                }
                final Cursor cursor = activeWindow.getCursor();
                try {
                    component.setCursor(WAIT_CURSOR);
                    runDo();
                } finally {
                    if (glassPane != null) {
                        glassPane.setVisible(false);
                    }
                    component.setCursor(cursor);
                }
            }
        } else {
            runDo();
        }
    } catch (final Throwable t) {
        Logs.error(this, t);
    }
}
Also used : Window(java.awt.Window) RootPaneContainer(javax.swing.RootPaneContainer) Component(java.awt.Component) Cursor(java.awt.Cursor)

Example 88 with Cursor

use of java.awt.Cursor in project com.revolsys.open by revolsys.

the class EditGeoreferencedImageOverlay method moveCornerMove.

private boolean moveCornerMove(final MouseEvent event) {
    Cursor moveCornerCursor = null;
    final Point oldPoint = this.moveCornerPoint;
    this.moveCornerPoint = null;
    this.moveCornerOppositePoint = null;
    final int modifiers = event.getModifiersEx();
    if (modifiers == 0 || modifiers == InputEvent.SHIFT_DOWN_MASK) {
        if (this.layer != null) {
            final Point mousePoint = getEventPoint();
            final GeometryFactory viewportGeometryFactory = getViewportGeometryFactory();
            Point closestPoint = null;
            final double maxDistance = getDistance(event);
            double closestDistance = Double.MAX_VALUE;
            if (oldPoint != null) {
                final double distance = oldPoint.distancePoint(mousePoint);
                if (distance < maxDistance) {
                    closestPoint = oldPoint;
                    closestDistance = distance;
                }
            }
            int closestIndex = -1;
            BoundingBox imageBoundingBox = getImageBoundingBox();
            if (!imageBoundingBox.isEmpty()) {
                imageBoundingBox = imageBoundingBox.convert(viewportGeometryFactory);
                for (int i = 0; i < 4; i++) {
                    final Point point = imageBoundingBox.getCornerPoint(i);
                    final Point mapPoint = point.convertPoint2d(viewportGeometryFactory);
                    final double distance = mapPoint.distancePoint(mousePoint);
                    if (distance < maxDistance && distance < closestDistance) {
                        closestPoint = point;
                        closestDistance = distance;
                        closestIndex = i;
                    }
                }
                if (closestPoint == oldPoint) {
                    if (oldPoint != null) {
                        return true;
                    }
                } else {
                    this.moveCornerPoint = closestPoint;
                    if (closestIndex == -1) {
                        this.moveCornerOppositePoint = null;
                    } else {
                        this.moveCornerOppositePoint = imageBoundingBox.getCornerPoint(closestIndex + 2).convertGeometry(viewportGeometryFactory);
                    }
                    switch(closestIndex) {
                        case 0:
                            moveCornerCursor = Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR);
                            break;
                        case 1:
                            moveCornerCursor = Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR);
                            break;
                        case 2:
                            moveCornerCursor = Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR);
                            break;
                        case 3:
                            moveCornerCursor = Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR);
                            break;
                    }
                }
            }
        }
    }
    if (this.moveCornerPoint == null) {
        moveCornerClear();
        return false;
    } else {
        if (setOverlayAction(ACTION_MOVE_IMAGE_CORNER)) {
            setMapCursor(moveCornerCursor);
        }
        return true;
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BoundingBox(com.revolsys.geometry.model.BoundingBox) Point(com.revolsys.geometry.model.Point) Cursor(java.awt.Cursor) Point(com.revolsys.geometry.model.Point)

Example 89 with Cursor

use of java.awt.Cursor in project com.revolsys.open by revolsys.

the class AbstractSwingWorker method done.

@Override
protected final void done() {
    final Window activeWindow = SwingUtil.getActiveWindow();
    if (isShowBusyCursor() && activeWindow != null) {
        Component component;
        Component glassPane = null;
        if (activeWindow instanceof RootPaneContainer) {
            final RootPaneContainer container = (RootPaneContainer) activeWindow;
            glassPane = container.getGlassPane();
            SwingUtil.setVisible(glassPane, true);
            component = glassPane;
        } else {
            component = activeWindow;
        }
        final Cursor cursor = activeWindow.getCursor();
        try {
            component.setCursor(WAIT_CURSOR);
            doDoneTask();
        } finally {
            if (glassPane != null) {
                SwingUtil.setVisible(glassPane, false);
            }
            component.setCursor(cursor);
        }
    } else {
        doDoneTask();
    }
}
Also used : Window(java.awt.Window) RootPaneContainer(javax.swing.RootPaneContainer) Component(java.awt.Component) Cursor(java.awt.Cursor)

Example 90 with Cursor

use of java.awt.Cursor in project zencash-swing-wallet-ui by ZencashOfficial.

the class MessagingPanel method openOwnIdentityDialog.

/**
 * Shows the UI dialog to edit+save one's own identity.
 *
 * @return true if new identity was created.
 */
public boolean openOwnIdentityDialog() {
    try {
        MessagingIdentity ownIdentity = this.messagingStorage.getOwnIdentity();
        boolean identityIsBeingCreated = false;
        if (ownIdentity == null) {
            identityIsBeingCreated = true;
            ownIdentity = new MessagingIdentity();
            Cursor oldCursor = this.getCursor();
            try {
                this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                // Create the T/Z addresses to be used for messaging - sometimes the wallet returns old
                // T addresses, so we iterate
                String TAddress = null;
                for (int i = 0; i < 10; i++) {
                    TAddress = this.clientCaller.createNewAddress(false);
                    String balance = this.clientCaller.getBalanceForAddress(TAddress);
                    if (Double.valueOf(balance) <= 0) {
                        break;
                    }
                }
                String ZAddress = this.clientCaller.createNewAddress(true);
                // Update the labels for the two addresses
                this.labelStorage.setLabel(TAddress, "Own Messaging ID T address");
                this.labelStorage.setLabel(ZAddress, "Own Messaging ID Z address");
                ownIdentity.setSenderidaddress(TAddress);
                ownIdentity.setSendreceiveaddress(ZAddress);
            } finally {
                this.setCursor(oldCursor);
            }
        }
        // Dialog will automatically save the identity if the user chooses so
        OwnIdentityEditDialog ownIdentityDialog = new OwnIdentityEditDialog(this.parentFrame, ownIdentity, this.messagingStorage, this.errorReporter, identityIsBeingCreated);
        ownIdentityDialog.setVisible(true);
        return identityIsBeingCreated;
    } catch (Exception ex) {
        Log.error("Unexpected error in editing own messaging identity!", ex);
        this.errorReporter.reportError(ex, false);
        return false;
    }
}
Also used : Cursor(java.awt.Cursor) URISyntaxException(java.net.URISyntaxException) WalletCallException(com.vaklinov.zcashui.ZCashClientCaller.WalletCallException) IOException(java.io.IOException)

Aggregations

Cursor (java.awt.Cursor)136 IOException (java.io.IOException)34 File (java.io.File)27 Point (java.awt.Point)19 MouseEvent (java.awt.event.MouseEvent)16 MouseAdapter (java.awt.event.MouseAdapter)13 Component (java.awt.Component)12 BufferedReader (java.io.BufferedReader)10 FileInputStream (java.io.FileInputStream)10 InputStreamReader (java.io.InputStreamReader)10 JLabel (javax.swing.JLabel)10 ArrayList (java.util.ArrayList)8 URISyntaxException (java.net.URISyntaxException)7 Color (java.awt.Color)6 Insets (java.awt.Insets)6 WalletCallException (com.vaklinov.zcashui.ZCashClientCaller.WalletCallException)5 Dimension (java.awt.Dimension)5 GridBagConstraints (java.awt.GridBagConstraints)5 Rectangle (java.awt.Rectangle)5 JPanel (javax.swing.JPanel)5