/* (non-Javadoc) * @see org.eclipse.swt.widgets.Layout#computeSize(org.eclipse.swt.widgets.Composite, int, int, boolean) */ @Override protected Point computeSize(Composite composite, int whint, int hhint, boolean flushCache) { int minX = Integer.MAX_VALUE; int minY = Integer.MAX_VALUE; int maxX = Integer.MIN_VALUE; int maxY = Integer.MIN_VALUE; for (Control kid : composite.getChildren()) { Point kidSize = kid.computeSize(-1, -1); Point kidOffs = kid.getLocation(); if (kidOffs.x < minX) minX = kidOffs.x; if (kidOffs.y < minY) minY = kidOffs.y; if (kidOffs.x + kidSize.x > maxX) maxX = kidOffs.x + kidSize.x; if (kidOffs.y + kidSize.y > maxY) maxY = kidOffs.y + kidSize.y; } if (whint > 0) { if (whint + minX > maxX) maxX = whint + minX; } if (hhint > 0) { if (hhint + minY > maxY) maxY = hhint + minY; } return new Point(maxX - minX, maxY - minY); }
public static boolean isVisible(Control c) { if (c.getParent() == null) return true; Rectangle displayRect = c.getDisplay().getBounds(); Point loc = c.getLocation(); loc = c.getParent().toDisplay(loc); Point size = c.getSize(); if (!displayRect.intersects(loc.x, loc.y, size.x, size.y)) return false; if (c.getParent() == null) return true; Rectangle r = getVisibleRectangleInParent(c); return r != null; }
/* * (non-Javadoc) * * @see org.eclipse.jface.dialogs.PopupDialog.adjustBounds() */ protected void adjustBounds() { // Get our control's location in display coordinates. Point location = control.getDisplay().map(control.getParent(), null, control.getLocation()); int initialX = location.x + POPUP_OFFSET; int initialY = location.y + control.getSize().y + POPUP_OFFSET; // If we are inserting content, use the cursor position to // position the control. if (adapter.getProposalAcceptanceStyle() == ContentProposalAdapter.PROPOSAL_INSERT) { Rectangle insertionBounds = adapter.getControlContentAdapter().getInsertionBounds(control); initialX = initialX + insertionBounds.x; initialY = location.y + insertionBounds.y + insertionBounds.height; } // If there is no specified size, force it by setting // up a layout on the table. if (popupSize == null) { GridData data = new GridData(GridData.FILL_BOTH); data.heightHint = proposalTable.getItemHeight() * POPUP_CHAR_HEIGHT; data.widthHint = Math.max(control.getSize().x, POPUP_MINIMUM_WIDTH); proposalTable.setLayoutData(data); getShell().pack(); popupSize = getShell().getSize(); } // Constrain to the display Rectangle constrainedBounds = getConstrainedShellBounds(new Rectangle(initialX, initialY, popupSize.x, popupSize.y)); // If there has been an adjustment causing the popup to overlap // with the control, then put the popup above the control. if (constrainedBounds.y < initialY) getShell().setBounds(initialX, location.y - popupSize.y, popupSize.x, popupSize.y); else getShell().setBounds(initialX, initialY, popupSize.x, popupSize.y); // Now set up a listener to monitor any changes in size. getShell() .addListener( SWT.Resize, new Listener() { public void handleEvent(Event e) { popupSize = getShell().getSize(); if (infoPopup != null) { infoPopup.adjustBounds(); } } }); }
@Override public Point getLocation(Point tipSize, Event event) { Point location = control.getLocation(); return control.getParent().toDisplay(location.x, location.y + control.getSize().y + 5); }
@Override public void run() { // Get the last-used directory for polygon region models from the preferences. final String directory = _preferencesStore.get(_preferencesString, Utilities.getWorkingDirectory()); // Create the file selection dialog. Shell shell = new Shell(Display.getCurrent()); FileDialog dialog = new FileDialog(shell, SWT.OPEN); dialog.setFilterPath(directory); dialog.setFilterNames( new String[] { "ABAVO Polygon Model (*." + PolygonRegionsModel.FILE_EXTENSION + ")", "Old ABAVO Polygon Model (*." + PolygonRegionsModel.FILE_EXTENSION_OLD + ")" }); dialog.setFilterExtensions( new String[] { "*." + PolygonRegionsModel.FILE_EXTENSION, "*." + PolygonRegionsModel.FILE_EXTENSION_OLD }); dialog.setText("Load Polygon Model"); shell.setLocation(_parent.getLocation()); // Open the file selection dialog and get the result. String result = dialog.open(); if (result != null && result.length() > 0) { File file = new File(result); // Check the file extension. boolean validFile = file.getAbsolutePath().endsWith("." + PolygonRegionsModel.FILE_EXTENSION); boolean validFileOld = file.getAbsolutePath().endsWith("." + PolygonRegionsModel.FILE_EXTENSION_OLD); if (!validFile && !validFileOld) { // Show the user an error message. UserAssistMessageBuilder message = new UserAssistMessageBuilder(); message.setDescription("Unable to read polygon model file."); message.addReason("Invalid file type."); message.addSolution( "Select a valid polygon model file (*." + PolygonRegionsModel.FILE_EXTENSION + ")."); MessageDialog.openError(shell, "File I/O Error", message.toString()); } else { boolean rescalePolygons = MessageDialog.openQuestion( shell, "Rescale Polygons", "Rescale polygons to plot maximum?"); try { // Store the directory location in the preferences. _preferencesStore.put(_preferencesString, file.getParent()); PreferencesUtil.saveInstanceScopePreferences(ServiceComponent.PLUGIN_ID); // Read the model from the file. if (validFile) { _model.readSession(file, rescalePolygons); } else if (validFileOld) { _model.readSessionOld(file, rescalePolygons); } String message = "Polygon regions model loaded:\n\'" + file.getAbsolutePath() + "\'"; MessageDialog.openInformation(shell, "File I/O", message); } catch (Exception ex) { // Show the user an error message. UserAssistMessageBuilder message = new UserAssistMessageBuilder(); message.setDescription("Unable to read polygon model file."); message.addReason(ex.toString()); MessageDialog.openError(shell, "File I/O Error", message.toString()); } } } shell.dispose(); }