List of usage examples for java.awt.event MouseEvent getY
public int getY()
From source file:lu.lippmann.cdb.graph.mouse.CadralEditingGraphMousePlugin.java
/** * {@inheritDoc}//from w w w. java2s . c o m */ @Override public void mouseDragged(MouseEvent e) { if (checkModifiers(e)) { @SuppressWarnings("unchecked") final VisualizationViewer<CNode, CEdge> vv = (VisualizationViewer<CNode, CEdge>) e.getSource(); final Layout<CNode, CEdge> layout = vv.getModel().getGraphLayout(); final GraphElementAccessor<CNode, CEdge> pickSupport = vv.getPickSupport(); if (startVertex != null) { transformEdgeShape(down, e.getPoint()); if (edgeIsDirected == EdgeType.DIRECTED) { transformArrowShape(down, e.getPoint()); final CNode pointedVertex = pickSupport.getVertex(layout, e.getX(), e.getY()); if (pointedVertex != null && pointedVertex != startVertex) { if (!pointedVertices.containsKey(pointedVertex)) { pointedVertices.put(pointedVertex, pointedVertex.getColor()); //save original color } Color prevColor = pointedVertex.getColor(); if (pointedVertex.getColor().equals(pointedVertices.get(pointedVertex))) { if (pointedVertex != this.lastDragVertex && this.lastDragVertex != null) { lastDragVertex.setColor(pointedVertices.get(lastDragVertex)); } //Don't change color if there is an existing edge if (layout.getGraph().findEdge(startVertex, pointedVertex) == null) { if (GraphUtil.isDarkNode(pointedVertex)) { if (prevColor.darker().equals(prevColor)) { pointedVertex.setColor(Color.GRAY); } else { if (prevColor.brighter().equals(prevColor)) { pointedVertex.setColor(Color.GRAY); } else { pointedVertex.setColor(pointedVertices.get(pointedVertex).brighter()); } } } else { pointedVertex.setColor(pointedVertices.get(pointedVertex).darker()); } } } this.lastDragVertex = this.dragVertex; this.dragVertex = pointedVertex; } else if (dragVertex != null) { dragVertex.setColor(pointedVertices.get(dragVertex)); } } } vv.repaint(); } }
From source file:hermes.browser.dialog.HermesAdminFactoryConfigPanel.java
public void init() { final Border border = BorderFactory.createBevelBorder(BevelBorder.RAISED); setLayout(new BorderLayout()); setBorder(BorderFactory.createTitledBorder(border, ADMIN_FACTORY)); afCombo.setModel(cfComboModel);//from www .ja v a 2s. c om propertyTableSP.setViewportView(propertyTable); propertyTable.setSortable(true); add(afCombo, BorderLayout.NORTH); add(propertyTableSP, BorderLayout.CENTER); popupMenu.add(addItem); popupMenu.add(removeItem); addItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { try { propertyTableModel.insertRow(); } catch (Exception ex) { cat.error(ex.getMessage(), ex); } } }); removeItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (propertyTable.getSelectedRow() != -1) { propertyTableModel.removeRow(propertyTable.getSelectedRow()); } } }); final MouseAdapter m = new MouseAdapter() { public void mousePressed(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { if (e.getComponent() == propertyTableSP) { removeItem.setEnabled(false); } else { removeItem.setEnabled(true); } if (propertySelectionComboBox.getModel().getSize() == 0) { addItem.setEnabled(false); } else { addItem.setEnabled(true); } popupMenu.show(e.getComponent(), e.getX(), e.getY()); } } }; propertyTableSP.addMouseListener(m); propertyTable.addMouseListener(m); propertyTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); cfComboModel.addListDataListener(new ListDataListener() { public void contentsChanged(ListDataEvent arg0) { final String className = HermesBrowser.getConfigDAO() .getAdminClassForPlugIn((String) cfComboModel.getSelectedItem()); final ClassLoaderManager classLoaderManager = (ClassLoaderManager) SingletonManager .get(ClassLoaderManager.class); try { if (propertyTableModel != null) { final ClassLoader classLoader = classLoaderManager .getClassLoader(dialog.getSelectedLoader()); Thread.currentThread().setContextClassLoader(classLoader); bean = (HermesAdminFactory) classLoader.loadClass(className).newInstance(); propertyTableModel.setBean(bean); updateCellEditor(); dialog.setDirty(); } } catch (Throwable e) { HermesBrowser.getBrowser().showErrorDialog( "Unable to locate this plugin.\nSelect the loader the JMS provider classes are in before choosing the plugin."); cfComboModel.setSelectedItem(ConfigDAO.DEFAULT_PLUGIN); } } public void intervalAdded(ListDataEvent arg0) { // NOP } public void intervalRemoved(ListDataEvent arg0) { // NOP } }); }
From source file:es.emergya.ui.gis.FleetControlMapViewer.java
@Override public void actionPerformed(final ActionEvent e) { final CustomMapView mapViewLocal = this.mapView; SwingWorker<Object, Object> sw = new SwingWorker<Object, Object>() { @Override// www.j a v a 2 s. c o m protected Object doInBackground() throws Exception { try { final MouseEvent mouseEvent = FleetControlMapViewer.this.eventOriginal; if (e.getActionCommand().equals(// Centrar aqui i18n.getString(Locale.ROOT, "map.menu.centerHere"))) { mapViewLocal.zoomToFactor(mapViewLocal.getEastNorth(mouseEvent.getX(), mouseEvent.getY()), mapViewLocal.zoomFactor); } else if (e.getActionCommand().equals(// nueva incidencia i18n.getString("map.menu.newIncidence"))) { Incidencia f = new Incidencia(); f.setCreador(Authentication.getUsuario()); LatLon from = mapViewLocal.getLatLon(mouseEvent.getX(), mouseEvent.getY()); GeometryFactory gf = new GeometryFactory(); f.setGeometria(gf.createPoint(new Coordinate(from.lon(), from.lat()))); IncidenceDialog id = new IncidenceDialog(f, i18n.getString("Incidences.summary.title") + " " + i18n.getString("Incidences.nuevaIncidencia"), "tittleficha_icon_recurso"); id.setVisible(true); } else if (e.getActionCommand().equals(// ruta desde i18n.getString("map.menu.route.from"))) { routeDialog.showRouteDialog(mapViewLocal.getLatLon(mouseEvent.getX(), mouseEvent.getY()), null, mapViewLocal); } else if (e.getActionCommand().equals(// ruta hasta i18n.getString("map.menu.route.to"))) { routeDialog.showRouteDialog(null, mapViewLocal.getLatLon(mouseEvent.getX(), mouseEvent.getY()), mapViewLocal); } else if (e.getActionCommand().equals(// Actualizar gps i18n.getString("map.menu.gps"))) { if (!(menuObjective instanceof Recurso)) { return null; } GPSDialog sdsDialog = null; for (Frame f : Frame.getFrames()) { if (f instanceof GPSDialog) if (((GPSDialog) f).getRecurso().equals(menuObjective)) sdsDialog = (GPSDialog) f; } if (sdsDialog == null) sdsDialog = new GPSDialog((Recurso) menuObjective); sdsDialog.setVisible(true); sdsDialog.setExtendedState(JFrame.NORMAL); } else if (e.getActionCommand().equals(// Ficha i18n.getString("map.menu.summary"))) { if (log.isTraceEnabled()) { log.trace("Mostramos la ficha del objetivo del menu"); } if (menuObjective instanceof Recurso) { log.trace(">recurso"); SwingWorker<Object, Object> sw = new SwingWorker<Object, Object>() { @Override protected Object doInBackground() throws Exception { for (Frame f : JFrame.getFrames()) { if (f.getName().equals(((Recurso) menuObjective).getIdentificador()) && f instanceof SummaryDialog) { if (f.isShowing()) { f.toFront(); f.setExtendedState(JFrame.NORMAL); return null; } } } new SummaryDialog((Recurso) menuObjective).setVisible(true); return null; } }; sw.execute(); } else if (menuObjective instanceof Incidencia) { if (log.isTraceEnabled()) { log.trace(">incidencia"); } SwingWorker<Object, Object> sw = new SwingWorker<Object, Object>() { @Override protected Object doInBackground() throws Exception { for (Frame f : JFrame.getFrames()) { if (f.getName().equals(((Incidencia) menuObjective).getTitulo()) && f instanceof IncidenceDialog) { if (log.isTraceEnabled()) { log.trace("Ya lo tenemos abierto"); } if (f.isShowing()) { f.toFront(); f.setExtendedState(JFrame.NORMAL); } else { f.setVisible(true); f.setExtendedState(JFrame.NORMAL); } return null; } } if (log.isTraceEnabled()) { log.trace("Abrimos uno nuevo"); } new IncidenceDialog((Incidencia) menuObjective, i18n.getString("Incidences.summary.title") + " " + ((Incidencia) menuObjective).getTitulo(), "tittleficha_icon_recurso").setVisible(true); return null; } }; sw.execute(); } else { return null; } } else if (e.getActionCommand().equals( // Mas cercanos i18n.getString("map.menu.showNearest"))) { if (log.isTraceEnabled()) { log.trace("showNearest"); } if (menuObjective != null) { for (Frame f : JFrame.getFrames()) { String identificador = menuObjective.toString(); if (menuObjective instanceof Recurso) { identificador = ((Recurso) menuObjective).getIdentificador(); } if (menuObjective != null && f.getName().equals(identificador) && f instanceof NearestResourcesDialog && f.isDisplayable()) { if (log.isTraceEnabled()) { log.trace("Encontrado " + f); } if (f.isShowing()) { f.toFront(); f.setExtendedState(JFrame.NORMAL); } else { f.setVisible(true); f.setExtendedState(JFrame.NORMAL); } return null; } } } NearestResourcesDialog d; if (menuObjective instanceof Recurso) { d = new NearestResourcesDialog((Recurso) menuObjective, mapViewLocal); } else if (menuObjective instanceof Incidencia) { d = new NearestResourcesDialog((Incidencia) menuObjective, mapViewLocal.getLatLon(mouseEvent.getX(), mouseEvent.getY()), mapViewLocal); } else { d = new NearestResourcesDialog( mapViewLocal.getLatLon(mouseEvent.getX(), mouseEvent.getY()), mapViewLocal); } d.setVisible(true); } else { log.error("ActionCommand desconocido: " + e.getActionCommand()); } } catch (Throwable t) { log.error("Error al ejecutar la accion del menu contextual", t); } return null; } }; sw.execute(); }
From source file:ucar.unidata.idv.control.chart.ChartHolder.java
/** * show popup//from w ww. j a v a 2s .c o m * * @param event event */ private void showPopupMenu(MouseEvent event) { List items = new ArrayList(); getMenuItems(items); JPopupMenu popupMenu = GuiUtils.makePopupMenu(items); popupMenu.show(chartPanel, event.getX(), event.getY()); }
From source file:canreg.client.gui.analysis.FrequenciesByYearInternalFrame.java
/** * * @param offset/*from w w w. j a v a2s . c om*/ * @param evt */ public void showPopUpMenu(int offset, java.awt.event.MouseEvent evt) { JTable target = (JTable) evt.getSource(); int rowNumber = target.rowAtPoint(new Point(evt.getX(), evt.getY())); rowNumber = target.convertRowIndexToModel(rowNumber); JPopupMenu jpm = new JPopupMenu(); jpm.add(java.util.ResourceBundle .getBundle("canreg/client/gui/analysis/resources/FrequenciesByYearInternalFrame") .getString("SHOW_IN_BROWSER")); TableModel tableModel = target.getModel(); // resultTable.get // jpm.add("Column " + rowNumber +" " + tableColumnModel.getColumn(tableColumnModel.getColumnIndexAtX(evt.getX())).getHeaderValue()); int year = Integer.parseInt((String) tableModel.getValueAt(rowNumber, 0)); String filterString = "INCID >= '" + year * 10000 + "' AND INCID <'" + (year + 1) * 10000 + "'"; for (DatabaseVariablesListElement dvle : chosenVariables) { int columnNumber = tableColumnModel .getColumnIndex(canreg.common.Tools.toUpperCaseStandardized(dvle.getDatabaseVariableName())); String value = tableModel.getValueAt(rowNumber, columnNumber).toString(); filterString += " AND " + canreg.common.Tools.toUpperCaseStandardized(dvle.getDatabaseVariableName()) + " = " + dvle.getSQLqueryFormat(value); } DatabaseFilter filter = new DatabaseFilter(); filter.setFilterString(filterString); Logger.getLogger(FrequenciesByYearInternalFrame.class.getName()).log(Level.INFO, "FilterString: {0}", filterString); try { tableDatadescriptionPopUp = canreg.client.CanRegClientApp.getApplication() .getDistributedTableDescription(filter, rangeFilterPanel.getSelectedTable()); Object[][] rows = canreg.client.CanRegClientApp.getApplication().retrieveRows( tableDatadescriptionPopUp.getResultSetID(), 0, MAX_ENTRIES_DISPLAYED_ON_RIGHT_CLICK); String[] variableNames = tableDatadescriptionPopUp.getColumnNames(); for (Object[] row : rows) { String line = ""; int i = 0; for (Object obj : row) { if (obj != null) { line += variableNames[i] + ": " + obj.toString() + ", "; } i++; } jpm.add(line); } } catch (SQLException ex) { Logger.getLogger(FrequenciesByYearInternalFrame.class.getName()).log(Level.SEVERE, null, ex); } catch (RemoteException ex) { Logger.getLogger(FrequenciesByYearInternalFrame.class.getName()).log(Level.SEVERE, null, ex); } catch (SecurityException ex) { Logger.getLogger(FrequenciesByYearInternalFrame.class.getName()).log(Level.SEVERE, null, ex); } catch (DistributedTableDescriptionException ex) { Logger.getLogger(FrequenciesByYearInternalFrame.class.getName()).log(Level.SEVERE, null, ex); } catch (UnknownTableException ex) { Logger.getLogger(FrequenciesByYearInternalFrame.class.getName()).log(Level.SEVERE, null, ex); } int cases = (Integer) tableModel.getValueAt(rowNumber, tableColumnModel.getColumnIndex("CASES")); if (MAX_ENTRIES_DISPLAYED_ON_RIGHT_CLICK < cases) { jpm.add("..."); } MenuItem menuItem = new MenuItem(); jpm.show(target, evt.getX(), evt.getY()); }
From source file:pipeline.parameter_cell_views.FloatRangeSlider.java
/** * Translates MouseEvent screen coordinates to coordinates in chart units * /* w ww . j ava 2s .c om*/ * @param e * MouseEvent containing coordinates of interest * @return Chart coordinates (evaluated as double) */ private @Nullable Point2D getChartCoordinates(MouseEvent e) { if (chartPanel.getChartRenderingInfo().getChartArea().getHeight() == 0) { Utils.log("Cannot translate to chart coordinates", LogLevel.DEBUG); return null; } int mouseX = e.getX(); int mouseY = e.getY(); Utils.log("x = " + mouseX + ", y = " + mouseY, LogLevel.DEBUG); Point2D p = chartPanel.translateScreenToJava2D(new Point(mouseX, mouseY)); XYPlot plot = (XYPlot) chart.getPlot(); Rectangle2D plotArea = this.chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea(); ValueAxis domainAxis = plot.getDomainAxis(); RectangleEdge domainAxisEdge = plot.getDomainAxisEdge(); ValueAxis rangeAxis = plot.getRangeAxis(); RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge(); double chartX = domainAxis.java2DToValue(p.getX(), plotArea, domainAxisEdge); double chartY = rangeAxis.java2DToValue(p.getY(), plotArea, rangeAxisEdge); return new Point2D.Double(chartX, chartY); }
From source file:burlov.ultracipher.swing.MainPanel.java
public MainPanel(Translator translator) { editDataPanel = new EditDataPanel(translator); translator.addToComponent(searchField); listPopup.add(getNewEntryAction());/*from w ww . ja v a2 s. c o m*/ listPopup.add(getDeleteEntryAction()); setLayout(new BorderLayout()); add(splitPane); /* * Suchpanel initialisieren */ JPanel panel = new JPanel(new BorderLayout()); JPanel searchPanel = new JPanel(new BorderLayout()); searchPanel.add(new JLabel(new ImageIcon(getClass().getResource("find.png"))), BorderLayout.WEST); searchPanel.add(searchField, BorderLayout.CENTER); searchField.setToolTipText("Search"); panel.add(searchPanel, BorderLayout.NORTH); panel.add(new JScrollPane(searchResults), BorderLayout.CENTER); splitPane.setLeftComponent(panel); /* * Anzeigepanel initialisieren */ panel = new JPanel(new BorderLayout()); panel.add(editDataPanel, BorderLayout.CENTER); panel.add(new PassGeneratorPanel(), BorderLayout.SOUTH); splitPane.setRightComponent(panel); searchResults.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { showDeletePopup(e); } @Override public void mouseReleased(MouseEvent e) { showDeletePopup(e); } private void showDeletePopup(MouseEvent e) { if (!e.isPopupTrigger()) { return; } int index = searchResults.locationToIndex(e.getPoint()); if (index > -1) { searchResults.setSelectedIndex(index); } listPopup.show(e.getComponent(), e.getX(), e.getY()); } }); searchResults.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { editDataPanel.editData((DataEntry) searchResults.getSelectedValue(), false); } }); searchField.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { initResultList(); } @Override public void insertUpdate(DocumentEvent e) { initResultList(); } @Override public void changedUpdate(DocumentEvent e) { initResultList(); } }); editDataPanel.addNameChangeListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { int index = searchResultModel.indexOf(editDataPanel.getData()); if (index >= 0) { searchResultModel.set(index, editDataPanel.getData()); } } @Override public void insertUpdate(DocumentEvent e) { int index = searchResultModel.indexOf(editDataPanel.getData()); if (index >= 0) { searchResultModel.set(index, editDataPanel.getData()); } } @Override public void changedUpdate(DocumentEvent e) { int index = searchResultModel.indexOf(editDataPanel.getData()); if (index >= 0) { searchResultModel.set(index, editDataPanel.getData()); } } }); searchField.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { showTextPopup(e); } else { // searchField.selectAll(); } } @Override public void mouseReleased(MouseEvent e) { showTextPopup(e); } }); // searchField.addFocusListener(new FocusListener() { // @Override // public void focusLost(FocusEvent e) { // System.out.println("MainPanel.MainPanel().new FocusListener() {...}.focusLost()"); // } // // @Override // public void focusGained(FocusEvent e) { // System.out.println("MainPanel.MainPanel().new FocusListener() {...}.focusGained()"); // //searchField.selectAll(); // } // }); }
From source file:org.apache.jmeter.gui.MainFrame.java
/** * Create and initialize the GUI representation of the test tree. * * @param treeModel//from www. j a v a 2 s. c om * the test tree model * @param treeListener * the test tree listener * * @return the initialized test tree GUI */ private JTree makeTree(TreeModel treeModel, JMeterTreeListener treeListener) { JTree treevar = new JTree(treeModel) { private static final long serialVersionUID = 240L; @Override public String getToolTipText(MouseEvent event) { TreePath path = this.getPathForLocation(event.getX(), event.getY()); if (path != null) { Object treeNode = path.getLastPathComponent(); if (treeNode instanceof DefaultMutableTreeNode) { Object testElement = ((DefaultMutableTreeNode) treeNode).getUserObject(); if (testElement instanceof TestElement) { String comment = ((TestElement) testElement).getComment(); if (comment != null && comment.length() > 0) { return comment; } } } } return null; } }; treevar.setToolTipText(""); treevar.setCellRenderer(getCellRenderer()); treevar.setRootVisible(false); treevar.setShowsRootHandles(true); treeListener.setJTree(treevar); treevar.addTreeSelectionListener(treeListener); treevar.addMouseListener(treeListener); treevar.addKeyListener(treeListener); // enable drag&drop, install a custom transfer handler treevar.setDragEnabled(true); treevar.setDropMode(DropMode.ON_OR_INSERT); treevar.setTransferHandler(new JMeterTreeTransferHandler()); addQuickComponentHotkeys(treevar); return treevar; }
From source file:net.bioclipse.model.ScatterPlotMouseHandler.java
@Override public void mouseDragged(MouseEvent e) { super.mouseDragged(e); ChartPanel chartPanel = getChartPanel(e); JFreeChart selectedChart = chartPanel.getChart(); ChartDescriptor cd = ChartUtils.getChartDescriptor(selectedChart); int[] indices = cd.getSourceIndices(); XYPlot plot = (XYPlot) chartPanel.getChart().getPlot(); //Create double buffer Image buffer = chartPanel.createImage(chartPanel.getWidth(), chartPanel.getHeight()); Graphics bufferGraphics = buffer.getGraphics(); chartPanel.paint(bufferGraphics);//from ww w. ja v a2s.c om if (lastX == 0 && lastY == 0) { lastX = e.getX(); lastY = e.getY(); } drawRect = new Rectangle(); int x1 = Math.min(Math.min(e.getX(), lastX), startX); int y1 = Math.min(Math.min(e.getY(), lastY), startY); int x2 = Math.max(Math.max(e.getX(), lastX), startX); int y2 = Math.max(Math.max(e.getY(), lastY), startY); drawRect.x = x1; drawRect.y = y1; drawRect.width = x2 - drawRect.x; drawRect.height = y2 - drawRect.y; //Create a clipping rectangle Rectangle clipRect = new Rectangle(drawRect.x - 100, drawRect.y - 100, drawRect.width + 200, drawRect.height + 200); //Check for selected points for (int j = 0; j < plot.getDataset().getItemCount(plot.getDataset().getSeriesCount() - 1); j++) { for (int i = 0; i < plot.getDataset().getSeriesCount(); i++) { Number xK = plot.getDataset().getX(i, j); Number yK = plot.getDataset().getY(i, j); Point2D datasetPoint2D = new Point2D.Double(domainValueTo2D(chartPanel, plot, xK.doubleValue()), rangeValueTo2D(chartPanel, plot, yK.doubleValue())); if (drawRect.contains(datasetPoint2D)) { PlotPointData cp = new PlotPointData(indices[j], cd.getXLabel(), cd.getYLabel()); boolean pointAdded = mouseDragSelection.addPoint(cp); if (pointAdded) { ((ScatterPlotRenderer) plot.getRenderer()).addMarkedPoint(j, i); selectedChart.plotChanged(new PlotChangeEvent(plot)); } } else if (!mouseDragSelection.isEmpty()) { PlotPointData cp = new PlotPointData(indices[j], cd.getXLabel(), cd.getYLabel()); boolean pointRemoved = mouseDragSelection.removePoint(cp); if (pointRemoved) { ((ScatterPlotRenderer) plot.getRenderer()).removeMarkedPoint(new Point(j, i)); selectedChart.plotChanged(new PlotChangeEvent(plot)); } } } } Iterator<PlotPointData> iterator = currentSelection.iterator(); while (iterator.hasNext()) { PlotPointData next = iterator.next(); Point dataPoint = next.getDataPoint(); ((ScatterPlotRenderer) plot.getRenderer()).addMarkedPoint(dataPoint); } lastX = e.getX(); lastY = e.getY(); Graphics graphics = chartPanel.getGraphics(); graphics.setClip(clipRect); //Draw selection rectangle bufferGraphics.drawRect(drawRect.x, drawRect.y, drawRect.width, drawRect.height); graphics.drawImage(buffer, 0, 0, chartPanel.getWidth(), chartPanel.getHeight(), null); }
From source file:com.hexidec.ekit.component.RelativeImageView.java
/** Resize image if initial click was in grow-box: */ public void mouseDragged(MouseEvent e) { if (fGrowBase != null) { Point loc = fComponent.getLocationOnScreen(); int width = Math.max(2, loc.x + e.getX() - fGrowBase.x); int height = Math.max(2, loc.y + e.getY() - fGrowBase.y); if (e.isShiftDown() && fImage != null) { // Make sure size is proportional to actual image size float imgWidth = fImage.getWidth(this); float imgHeight = fImage.getHeight(this); if ((imgWidth > 0) && (imgHeight > 0)) { float prop = imgHeight / imgWidth; float pwidth = height / prop; float pheight = width * prop; if (pwidth > width) { width = (int) pwidth; } else { height = (int) pheight; }//w w w . j a v a 2 s .c om } } resize(width, height); } }