private boolean findEntry() { Cursor waitCursor = shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT); shell.setCursor(waitCursor); boolean matchCase = searchDialog.getMatchCase(); boolean matchWord = searchDialog.getMatchWord(); String searchString = searchDialog.getSearchString(); int column = searchDialog.getSelectedSearchArea(); searchString = matchCase ? searchString : searchString.toLowerCase(); boolean found = false; if (searchDialog.getSearchDown()) { for (int i = table.getSelectionIndex() + 1; i < table.getItemCount(); i++) { if (found = findMatch(searchString, table.getItem(i), column, matchWord, matchCase)) { table.setSelection(i); break; } } } else { for (int i = table.getSelectionIndex() - 1; i > -1; i--) { if (found = findMatch(searchString, table.getItem(i), column, matchWord, matchCase)) { table.setSelection(i); break; } } } shell.setCursor(null); return found; }
public void mouseMove(MouseEvent e) { Cursor cur = mShell.getCursor(); if (isInside(e.x, e.y, mToolbar.getBounds())) { if (mToolbar.mouseMove(e)) redrawToolbar(); } else { if (mToolbar.dehover()) redrawToolbar(); } if (mArrowButtonBounds != null) { if (mArrowButtonState != AbstractButtonPaintManager.STATE_SELECTED) { if (isInside(e.x, e.y, mArrowButtonBounds)) { if (mArrowButtonState == AbstractButtonPaintManager.STATE_NONE) { mArrowButtonState = AbstractButtonPaintManager.STATE_HOVER; redrawArrowButton(); } } else { if (mArrowButtonState != AbstractButtonPaintManager.STATE_NONE) { mArrowButtonState = AbstractButtonPaintManager.STATE_NONE; redrawArrowButton(); } } } } if (getMaximized()) { if (cur != null) mShell.setCursor(null); return; } if (!mShellMaximized) { int side = getResizeSide(e.x, e.y); doResize(side, e); } }
private boolean save() { if (file == null) return saveAs(); Cursor waitCursor = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT); shell.setCursor(waitCursor); TableItem[] items = table.getItems(); String[] lines = new String[items.length]; for (int i = 0; i < items.length; i++) { String[] itemText = new String[table.getColumnCount()]; for (int j = 0; j < itemText.length; j++) { itemText[j] = items[i].getText(j); } lines[i] = encodeLine(itemText); } FileWriter fileWriter = null; try { fileWriter = new FileWriter(file.getAbsolutePath(), false); for (int i = 0; i < lines.length; i++) { fileWriter.write(lines[i]); } } catch (FileNotFoundException e) { displayError(resMessages.getString("File_not_found") + "\n" + file.getName()); return false; } catch (IOException e) { displayError(resMessages.getString("IO_error_write") + "\n" + file.getName()); return false; } finally { shell.setCursor(null); waitCursor.dispose(); if (fileWriter != null) { try { fileWriter.close(); } catch (IOException e) { displayError(resMessages.getString("IO_error_close") + "\n" + file.getName()); return false; } } } shell.setText(resMessages.getString("Title_bar") + file.getName()); isModified = false; return true; }
@Override public void run() { Display display = Display.getCurrent(); Shell shell = display.getActiveShell(); Cursor cursor = shell == null ? null : shell.getCursor(); try { if (shell != null) { shell.setCursor(display.getSystemCursor(SWT.CURSOR_WAIT)); } setEnabled(false); if (installButton != null) { installButton.setEnabled(false); } DiscoveryUi.install(discoveryViewer.getInstallableConnectors(), SoftwarePage.this); } finally { if (shell != null) { shell.setCursor(cursor); } setEnabled(true); if (installButton != null) { installButton.setEnabled(true); } } }
private void doResize(int side, MouseEvent e) { if (sideCurrentlyResizing == SIDE_NONE) { Cursor cursor = null; switch (side) { case SIDE_TOP_LEFT: case SIDE_BOTTOM_RIGHT: cursor = CursorCache.getCursor(SWT.CURSOR_SIZENWSE); break; case SIDE_LEFT: case SIDE_RIGHT: cursor = CursorCache.getCursor(SWT.CURSOR_SIZEWE); break; case SIDE_BOTTOM_LEFT: case SIDE_TOP_RIGHT: cursor = CursorCache.getCursor(SWT.CURSOR_SIZENESW); break; case SIDE_TOP: case SIDE_BOTTOM: cursor = CursorCache.getCursor(SWT.CURSOR_SIZENS); break; } mShell.setCursor(cursor); } // this clause deals with shell resizing as our shell has no borders but we still need to mimic // it // it's all just location and size pushing to simulate a mouse resize if (sideCurrentlyResizing != SIDE_NONE) { // do shell resize Point point = Display.getDefault().map(mShell, null, e.x, e.y); int deltaX = e.x - mMouseDownLoc.x; int deltaY = e.y - mMouseDownLoc.y; switch (sideCurrentlyResizing) { case SIDE_LEFT: mShell.setLocation(point.x - mMouseDownLoc.x, mShell.getLocation().y); mShell.setSize(mShell.getSize().x - deltaX, mShell.getSize().y); break; case SIDE_BOTTOM: mShell.setSize(mShell.getSize().x, mShellSizeBeforeResize.y + deltaY); break; case SIDE_RIGHT: mShell.setSize(mShellSizeBeforeResize.x + deltaX, mShell.getSize().y); break; case SIDE_TOP: mShell.setSize(mShellSizeBeforeResize.x, mShell.getSize().y - deltaY); mShell.setLocation(mShell.getLocation().x, point.y - mMouseDownLoc.y); break; case SIDE_TOP_LEFT: mShell.setLocation(point.x - mMouseDownLoc.x, point.y - mMouseDownLoc.y); mShell.setSize(mShell.getSize().x - deltaX, mShell.getSize().y - deltaY); break; case SIDE_BOTTOM_LEFT: mShell.setLocation(point.x - mMouseDownLoc.x, mShell.getLocation().y); mShell.setSize(mShell.getSize().x - deltaX, mShellSizeBeforeResize.y + deltaY); break; case SIDE_BOTTOM_RIGHT: mShell.setSize(mShellSizeBeforeResize.x + deltaX, mShellSizeBeforeResize.y + deltaY); break; case SIDE_TOP_RIGHT: mShell.setLocation(mShell.getLocation().x, point.y - mMouseDownLoc.y); mShell.setSize(mShellSizeBeforeResize.x + deltaX, mShell.getSize().y - deltaY); break; } /* // TODO: Make this pretty and flicker-less if (mShell.getSize().x < 40) mShell.setSize(40, mShell.getSize().y); if (mShell.getSize().y < 40); mShell.setSize(mShell.getSize().y, 40);*/ } }
private void openAddressBook() { FileDialog fileDialog = new FileDialog(shell, SWT.OPEN); fileDialog.setFilterExtensions(new String[] {"*.adr;", "*.*"}); fileDialog.setFilterNames( new String[] { resAddressBook.getString("Book_filter_name") + " (*.adr)", resAddressBook.getString("All_filter_name") + " (*.*)" }); String name = fileDialog.open(); if (name == null) return; File file = new File(name); if (!file.exists()) { displayError( resAddressBook.getString("File") + file.getName() + " " + resAddressBook.getString("Does_not_exist")); return; } Cursor waitCursor = shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT); shell.setCursor(waitCursor); FileReader fileReader = null; BufferedReader bufferedReader = null; String[] data = new String[0]; try { fileReader = new FileReader(file.getAbsolutePath()); bufferedReader = new BufferedReader(fileReader); String nextLine = bufferedReader.readLine(); while (nextLine != null) { String[] newData = new String[data.length + 1]; System.arraycopy(data, 0, newData, 0, data.length); newData[data.length] = nextLine; data = newData; nextLine = bufferedReader.readLine(); } } catch (FileNotFoundException e) { displayError(resAddressBook.getString("File_not_found") + "\n" + file.getName()); return; } catch (IOException e) { displayError(resAddressBook.getString("IO_error_read") + "\n" + file.getName()); return; } finally { shell.setCursor(null); if (fileReader != null) { try { fileReader.close(); } catch (IOException e) { displayError(resAddressBook.getString("IO_error_close") + "\n" + file.getName()); return; } } } String[][] tableInfo = new String[data.length][table.getColumnCount()]; int writeIndex = 0; for (int i = 0; i < data.length; i++) { String[] line = decodeLine(data[i]); if (line != null) tableInfo[writeIndex++] = line; } if (writeIndex != data.length) { String[][] result = new String[writeIndex][table.getColumnCount()]; System.arraycopy(tableInfo, 0, result, 0, writeIndex); tableInfo = result; } Arrays.sort(tableInfo, new RowComparator(0)); for (int i = 0; i < tableInfo.length; i++) { TableItem item = new TableItem(table, SWT.NONE); item.setText(tableInfo[i]); } shell.setText(resAddressBook.getString("Title_bar") + fileDialog.getFileName()); isModified = false; this.file = file; }
private void openAddressBook(String name) { if (name == null) return; File file = new File(name); if (!file.exists()) { displayError( resMessages.getString("File") + file.getName() + " " + resMessages.getString("Does_not_exist")); return; } Cursor waitCursor = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT); shell.setCursor(waitCursor); FileReader fileReader = null; BufferedReader bufferedReader = null; String[] data = new String[0]; try { fileReader = new FileReader(file.getAbsolutePath()); bufferedReader = new BufferedReader(fileReader); String nextLine = bufferedReader.readLine(); while (nextLine != null) { String[] newData = new String[data.length + 1]; System.arraycopy(data, 0, newData, 0, data.length); newData[data.length] = nextLine; data = newData; nextLine = bufferedReader.readLine(); } } catch (FileNotFoundException e) { displayError(resMessages.getString("File_not_found") + "\n" + file.getName()); return; } catch (IOException e) { displayError(resMessages.getString("IO_error_read") + "\n" + file.getName()); return; } finally { shell.setCursor(null); waitCursor.dispose(); if (fileReader != null) { try { fileReader.close(); } catch (IOException e) { displayError(resMessages.getString("IO_error_close") + "\n" + file.getName()); return; } } } String[][] tableInfo = new String[data.length][table.getColumnCount()]; for (int i = 0; i < data.length; i++) { tableInfo[i] = decodeLine(data[i]); } Arrays.sort(tableInfo, new RowComparator(0)); for (int i = 0; i < tableInfo.length; i++) { TableItem item = new TableItem(table, SWT.NONE); item.setText(tableInfo[i]); } shell.setText(resMessages.getString("Title_bar") + file.getName()); isModified = false; this.file = file; }