List of usage examples for java.awt Dimension getWidth
public double getWidth()
From source file:de.bfs.radon.omsimulation.gui.OMPanelTesting.java
/** * Initialises the interface of the results panel. *///from www .j a v a2s . c o m protected void initialize() { setLayout(null); isSimulated = false; lblExportChartTo = new JLabel("Export chart to ..."); lblExportChartTo.setBounds(436, 479, 144, 14); lblExportChartTo.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); lblExportChartTo.setVisible(false); add(lblExportChartTo); btnCsv = new JButton("CSV"); btnCsv.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fileDialog = new JFileChooser(); fileDialog.setFileFilter(new FileNameExtensionFilter("*.csv", "csv")); fileDialog.showSaveDialog(getParent()); final File file = fileDialog.getSelectedFile(); if (file != null) { String csv; String[] tmpFileName = file.getAbsolutePath().split("\\."); if (tmpFileName[tmpFileName.length - 1].equals("csv")) { csv = ""; } else { csv = ".csv"; } String csvPath = file.getAbsolutePath() + csv; double[] selectedValues; OMRoom[] rooms = new OMRoom[7]; rooms[0] = (OMRoom) comboBoxRoom1.getSelectedItem(); rooms[1] = (OMRoom) comboBoxRoom2.getSelectedItem(); rooms[2] = (OMRoom) comboBoxRoom3.getSelectedItem(); rooms[3] = (OMRoom) comboBoxRoom4.getSelectedItem(); rooms[4] = (OMRoom) comboBoxRoom5.getSelectedItem(); rooms[5] = (OMRoom) comboBoxRoom6.getSelectedItem(); rooms[6] = (OMRoom) comboBoxRoom7.getSelectedItem(); int start = sliderStartTime.getValue(); final int day = 24; File csvFile = new File(csvPath); try { OMCampaign campaign; if (isResult) { campaign = getResultCampaign(); } else { campaign = new OMCampaign(start, rooms, 0); } FileWriter logWriter = new FileWriter(csvFile); BufferedWriter csvOutput = new BufferedWriter(logWriter); csvOutput.write("\"ID\";\"Room\";\"Radon\""); csvOutput.newLine(); selectedValues = campaign.getValueChain(); int x = 0; for (int i = start; i < start + day; i++) { csvOutput.write("\"" + i + "\";\"" + rooms[0].getId() + "\";\"" + (int) selectedValues[x] + "\""); csvOutput.newLine(); x++; } start = start + day; for (int i = start; i < start + day; i++) { csvOutput.write("\"" + i + "\";\"" + rooms[1].getId() + "\";\"" + (int) selectedValues[x] + "\""); csvOutput.newLine(); x++; } start = start + day; for (int i = start; i < start + day; i++) { csvOutput.write("\"" + i + "\";\"" + rooms[2].getId() + "\";\"" + (int) selectedValues[x] + "\""); csvOutput.newLine(); x++; } start = start + day; for (int i = start; i < start + day; i++) { csvOutput.write("\"" + i + "\";\"" + rooms[3].getId() + "\";\"" + (int) selectedValues[x] + "\""); csvOutput.newLine(); x++; } start = start + day; for (int i = start; i < start + day; i++) { csvOutput.write("\"" + i + "\";\"" + rooms[4].getId() + "\";\"" + (int) selectedValues[x] + "\""); csvOutput.newLine(); x++; } start = start + day; for (int i = start; i < start + day; i++) { csvOutput.write("\"" + i + "\";\"" + rooms[5].getId() + "\";\"" + (int) selectedValues[x] + "\""); csvOutput.newLine(); x++; } start = start + day; for (int i = start; i < start + day; i++) { csvOutput.write("\"" + i + "\";\"" + rooms[6].getId() + "\";\"" + (int) selectedValues[x] + "\""); csvOutput.newLine(); x++; } JOptionPane.showMessageDialog(null, "CSV saved successfully!\n" + csvPath, "Success", JOptionPane.INFORMATION_MESSAGE); csvOutput.close(); } catch (IOException ioe) { JOptionPane.showMessageDialog(null, "Failed to write CSV. Please check permissions!\n" + ioe.getMessage(), "Failed", JOptionPane.ERROR_MESSAGE); ioe.printStackTrace(); } } else { JOptionPane.showMessageDialog(null, "Failed to write CSV. Please check the file path!", "Failed", JOptionPane.ERROR_MESSAGE); } } }); btnCsv.setBounds(590, 475, 70, 23); btnCsv.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); btnCsv.setVisible(false); add(btnCsv); btnPdf = new JButton("PDF"); btnPdf.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fileDialog = new JFileChooser(); fileDialog.setFileFilter(new FileNameExtensionFilter("*.pdf", "pdf")); fileDialog.showSaveDialog(getParent()); final File file = fileDialog.getSelectedFile(); if (file != null) { String pdf; String[] tmpFileName = file.getAbsolutePath().split("\\."); if (tmpFileName[tmpFileName.length - 1].equals("pdf")) { pdf = ""; } else { pdf = ".pdf"; } String pdfPath = file.getAbsolutePath() + pdf; OMRoom[] rooms = new OMRoom[7]; rooms[0] = (OMRoom) comboBoxRoom1.getSelectedItem(); rooms[1] = (OMRoom) comboBoxRoom2.getSelectedItem(); rooms[2] = (OMRoom) comboBoxRoom3.getSelectedItem(); rooms[3] = (OMRoom) comboBoxRoom4.getSelectedItem(); rooms[4] = (OMRoom) comboBoxRoom5.getSelectedItem(); rooms[5] = (OMRoom) comboBoxRoom6.getSelectedItem(); rooms[6] = (OMRoom) comboBoxRoom7.getSelectedItem(); int start = sliderStartTime.getValue(); OMCampaign campaign; try { if (isResult) { campaign = getResultCampaign(); } else { campaign = new OMCampaign(start, rooms, 0); } JFreeChart chart = OMCharts.createCampaignChart(campaign, false); String title = "Campaign: " + rooms[0].getId() + rooms[1].getId() + rooms[2].getId() + rooms[3].getId() + rooms[4].getId() + rooms[5].getId() + rooms[6].getId() + ", Start: " + start; int height = (int) PageSize.A4.getWidth(); int width = (int) PageSize.A4.getHeight(); try { OMExports.exportPdf(pdfPath, chart, width, height, new DefaultFontMapper(), title); JOptionPane.showMessageDialog(null, "PDF saved successfully!\n" + pdfPath, "Success", JOptionPane.INFORMATION_MESSAGE); } catch (IOException ioe) { JOptionPane.showMessageDialog(null, "Failed to write PDF. Please check permissions!\n" + ioe.getMessage(), "Failed", JOptionPane.ERROR_MESSAGE); ioe.printStackTrace(); } } catch (IOException ioe) { JOptionPane.showMessageDialog(null, "Failed to create chart!\n" + ioe.getMessage(), "Failed", JOptionPane.ERROR_MESSAGE); ioe.printStackTrace(); } } else { JOptionPane.showMessageDialog(null, "Failed to write PDF. Please check the file path!", "Failed", JOptionPane.ERROR_MESSAGE); } } }); btnPdf.setBounds(670, 475, 70, 23); btnPdf.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); btnPdf.setVisible(false); add(btnPdf); lblSelectProject = new JLabel("Select Project"); lblSelectProject.setBounds(10, 65, 132, 14); lblSelectProject.setFont(new Font("SansSerif", Font.PLAIN, 11)); add(lblSelectProject); lblSelectRooms = new JLabel("Select Rooms"); lblSelectRooms.setBounds(10, 94, 132, 14); lblSelectRooms.setFont(new Font("SansSerif", Font.PLAIN, 11)); add(lblSelectRooms); lblStartTime = new JLabel("Start Time"); lblStartTime.setBounds(10, 123, 132, 14); lblStartTime.setFont(new Font("SansSerif", Font.PLAIN, 11)); add(lblStartTime); lblWarning = new JLabel("Select 6 rooms and 1 cellar!"); lblWarning.setForeground(Color.RED); lblWarning.setBounds(565, 123, 175, 14); lblWarning.setFont(new Font("SansSerif", Font.PLAIN, 11)); lblWarning.setVisible(false); add(lblWarning); sliderStartTime = new JSlider(); sliderStartTime.setMaximum(0); sliderStartTime.setBounds(152, 119, 285, 24); sliderStartTime.setFont(new Font("SansSerif", Font.PLAIN, 11)); add(sliderStartTime); spnrStartTime = new JSpinner(); spnrStartTime.setModel(new SpinnerNumberModel(0, 0, 0, 1)); spnrStartTime.setBounds(447, 120, 108, 22); spnrStartTime.setFont(new Font("SansSerif", Font.PLAIN, 11)); add(spnrStartTime); btnRefresh = new JButton("Load"); btnRefresh.setBounds(616, 61, 124, 23); btnRefresh.setFont(new Font("SansSerif", Font.PLAIN, 11)); add(btnRefresh); btnMaximize = new JButton("Fullscreen"); btnMaximize.setBounds(10, 475, 124, 23); btnMaximize.setFont(new Font("SansSerif", Font.PLAIN, 11)); add(btnMaximize); panelCampaign = new JPanel(); panelCampaign.setBounds(10, 150, 730, 315); panelCampaign.setFont(new Font("SansSerif", Font.PLAIN, 11)); add(panelCampaign); progressBar = new JProgressBar(); progressBar.setBounds(10, 475, 730, 23); progressBar.setFont(new Font("SansSerif", Font.PLAIN, 11)); progressBar.setVisible(false); add(progressBar); lblOpenOmbfile = new JLabel("Open OMB-File"); lblOpenOmbfile.setFont(new Font("SansSerif", Font.PLAIN, 11)); lblOpenOmbfile.setBounds(10, 36, 132, 14); add(lblOpenOmbfile); lblHelp = new JLabel("Select an OMB-Object file to manually simulate virtual campaigns."); lblHelp.setForeground(Color.GRAY); lblHelp.setFont(new Font("SansSerif", Font.PLAIN, 11)); lblHelp.setBounds(10, 10, 730, 14); add(lblHelp); txtOmbFile = new JTextField(); txtOmbFile.setFont(new Font("SansSerif", Font.PLAIN, 11)); txtOmbFile.setColumns(10); txtOmbFile.setBounds(152, 33, 454, 20); add(txtOmbFile); btnBrowse = new JButton("Browse"); btnBrowse.setFont(new Font("SansSerif", Font.PLAIN, 11)); btnBrowse.setBounds(616, 32, 124, 23); add(btnBrowse); comboBoxRoom1 = new JComboBox<OMRoom>(); comboBoxRoom1.setBounds(152, 90, 75, 22); comboBoxRoom1.setFont(new Font("SansSerif", Font.PLAIN, 11)); add(comboBoxRoom1); comboBoxRoom2 = new JComboBox<OMRoom>(); comboBoxRoom2.setBounds(237, 90, 75, 22); comboBoxRoom2.setFont(new Font("SansSerif", Font.PLAIN, 11)); add(comboBoxRoom2); comboBoxRoom3 = new JComboBox<OMRoom>(); comboBoxRoom3.setBounds(323, 90, 75, 22); comboBoxRoom3.setFont(new Font("SansSerif", Font.PLAIN, 11)); add(comboBoxRoom3); comboBoxRoom4 = new JComboBox<OMRoom>(); comboBoxRoom4.setBounds(408, 90, 75, 22); comboBoxRoom4.setFont(new Font("SansSerif", Font.PLAIN, 11)); add(comboBoxRoom4); comboBoxRoom5 = new JComboBox<OMRoom>(); comboBoxRoom5.setBounds(494, 90, 75, 22); comboBoxRoom5.setFont(new Font("SansSerif", Font.PLAIN, 11)); add(comboBoxRoom5); comboBoxRoom6 = new JComboBox<OMRoom>(); comboBoxRoom6.setBounds(579, 90, 75, 22); comboBoxRoom6.setFont(new Font("SansSerif", Font.PLAIN, 11)); add(comboBoxRoom6); comboBoxRoom7 = new JComboBox<OMRoom>(); comboBoxRoom7.setBounds(665, 90, 75, 22); comboBoxRoom7.setFont(new Font("SansSerif", Font.PLAIN, 11)); add(comboBoxRoom7); comboBoxProjects = new JComboBox<OMBuilding>(); comboBoxProjects.setBounds(152, 61, 454, 22); comboBoxProjects.setFont(new Font("SansSerif", Font.PLAIN, 11)); add(comboBoxProjects); comboBoxRoom1.addActionListener(this); comboBoxRoom1.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { validateCampaign(); } }); comboBoxRoom2.addActionListener(this); comboBoxRoom2.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { validateCampaign(); } }); comboBoxRoom3.addActionListener(this); comboBoxRoom3.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { validateCampaign(); } }); comboBoxRoom4.addActionListener(this); comboBoxRoom4.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { validateCampaign(); } }); comboBoxRoom5.addActionListener(this); comboBoxRoom5.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { validateCampaign(); } }); comboBoxRoom6.addActionListener(this); comboBoxRoom6.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { validateCampaign(); } }); comboBoxRoom7.addActionListener(this); comboBoxRoom7.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { validateCampaign(); } }); sliderStartTime.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (comboBoxProjects.isEnabled() || isResult) { if (comboBoxProjects.getSelectedItem() != null) { spnrStartTime.setValue((int) sliderStartTime.getValue()); updateChart(); } } } }); spnrStartTime.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent arg0) { if (comboBoxProjects.isEnabled() || isResult) { if (comboBoxProjects.getSelectedItem() != null) { sliderStartTime.setValue((Integer) spnrStartTime.getValue()); updateChart(); } } } }); btnRefresh.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (txtOmbFile.getText() != null && !txtOmbFile.getText().equals("") && !txtOmbFile.getText().equals(" ")) { txtOmbFile.setBackground(Color.WHITE); String ombPath = txtOmbFile.getText(); String omb; String[] tmpFileName = ombPath.split("\\."); if (tmpFileName[tmpFileName.length - 1].equals("omb")) { omb = ""; } else { omb = ".omb"; } txtOmbFile.setText(ombPath + omb); setOmbFile(ombPath + omb); File ombFile = new File(ombPath + omb); if (ombFile.exists()) { txtOmbFile.setBackground(Color.WHITE); btnRefresh.setEnabled(false); comboBoxProjects.setEnabled(false); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); progressBar.setVisible(true); btnPdf.setVisible(false); btnCsv.setVisible(false); btnMaximize.setVisible(false); lblExportChartTo.setVisible(false); progressBar.setIndeterminate(true); progressBar.setStringPainted(true); refreshTask = new Refresh(); refreshTask.execute(); } else { txtOmbFile.setBackground(new Color(255, 222, 222, 128)); JOptionPane.showMessageDialog(null, "OMB-file not found, please check the file path!", "Error", JOptionPane.ERROR_MESSAGE); } } else { txtOmbFile.setBackground(new Color(255, 222, 222, 128)); JOptionPane.showMessageDialog(null, "Please select an OMB-file!", "Warning", JOptionPane.WARNING_MESSAGE); } } }); btnMaximize.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { try { OMRoom[] rooms = new OMRoom[7]; rooms[0] = (OMRoom) comboBoxRoom1.getSelectedItem(); rooms[1] = (OMRoom) comboBoxRoom2.getSelectedItem(); rooms[2] = (OMRoom) comboBoxRoom3.getSelectedItem(); rooms[3] = (OMRoom) comboBoxRoom4.getSelectedItem(); rooms[4] = (OMRoom) comboBoxRoom5.getSelectedItem(); rooms[5] = (OMRoom) comboBoxRoom6.getSelectedItem(); rooms[6] = (OMRoom) comboBoxRoom7.getSelectedItem(); int start = sliderStartTime.getValue(); String title = "Campaign: " + rooms[0].getId() + rooms[1].getId() + rooms[2].getId() + rooms[3].getId() + rooms[4].getId() + rooms[5].getId() + rooms[6].getId() + ", Start: " + start; OMCampaign campaign; if (isResult) { campaign = getResultCampaign(); } else { campaign = new OMCampaign(start, rooms, 0); } JPanel campaignChart = createCampaignPanel(campaign, false, true); JFrame chartFrame = new JFrame(); chartFrame.getContentPane().add(campaignChart); chartFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); chartFrame.setBounds(0, 0, (int) dim.getWidth(), (int) dim.getHeight()); chartFrame.setTitle(title); chartFrame.setResizable(true); chartFrame.setExtendedState(JFrame.MAXIMIZED_BOTH); chartFrame.setVisible(true); } catch (IOException ioe) { ioe.printStackTrace(); } } }); txtOmbFile.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent arg0) { setOmbFile(txtOmbFile.getText()); } }); btnBrowse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { JFileChooser fileDialog = new JFileChooser(); fileDialog.setFileFilter(new FileNameExtensionFilter("*.omb", "omb")); fileDialog.showOpenDialog(getParent()); final File file = fileDialog.getSelectedFile(); if (file != null) { String omb; String[] tmpFileName = file.getAbsolutePath().split("\\."); if (tmpFileName[tmpFileName.length - 1].equals("omb")) { omb = ""; } else { omb = ".omb"; } txtOmbFile.setText(file.getAbsolutePath() + omb); setOmbFile(file.getAbsolutePath() + omb); } } }); }
From source file:org.kalypsodeegree_impl.graphics.displayelements.LabelFactory.java
/** * Determines positions on the given <tt>GM_Curve</tt> where a caption could be drawn. For each of this positons, * three candidates are produced; one on the line, one above of it and one below. * /* w w w . j a v a 2 s . com*/ * @param curve * @param element * @param g * @param projection * @return ArrayList containing Arrays of Label-objects * @throws FilterEvaluationException */ private Label[] createCurveLabels(final Feature feature, final String caption, final GM_Curve curve, final Font font, final Color color, final LineMetrics metrics, final Dimension size) throws FilterEvaluationException, GM_Exception { final double radius = getLineRadius(feature); // determine the placement type and parameters from the TextSymbolizer final double perpendicularOffset; final PlacementType placementType; final double lineWidth; final int gap; final LinePlacement linePlacement = getLinePlacement(); if (linePlacement != null) { placementType = linePlacement.getPlacementType(feature); perpendicularOffset = linePlacement.getPerpendicularOffset(feature); lineWidth = linePlacement.getLineWidth(feature); gap = linePlacement.getGap(feature); } else { placementType = PlacementType.absolute; perpendicularOffset = 0.0; lineWidth = 3.0; gap = 6; } // get screen coordinates of the line final int[][] pos = LabelUtils.calcScreenCoordinates(m_projection, curve); // get width & height of the caption final double labelWidth = size.getWidth() + 2 * radius; final double labelHeight = size.getHeight() + 2 * radius; // ideal distance from the line final double delta = labelHeight / 2.0 + lineWidth / 2.0; // walk along the linestring and "collect" possible placement positions final int w = (int) labelWidth; int lastX = pos[0][0]; int lastY = pos[1][0]; int boxStartX = lastX; int boxStartY = lastY; final List<Label> labels = new ArrayList<>(MAX_CURVE_LABELS_COUNT); final List<int[]> eCandidates = new ArrayList<>(MAX_CURVE_LABELS_COUNT); int i = 0; for (int kk = 0; kk < MAX_CURVE_LABELS_COUNT && kk < pos[2][0]; kk++) { final int screenX = pos[0][i]; final int screenY = pos[1][i]; // segment found where endpoint of box should be located? if (getDistance(boxStartX, boxStartY, screenX, screenY) >= w) { final int[] boxStart = new int[] { boxStartX, boxStartY }; final int[] last = new int[] { lastX, lastY }; final int[] current = new int[] { screenX, screenY }; final int[] p = findPointWithDistance(boxStart, last, current, w); lastX = p[0]; lastY = p[1]; int boxEndX = p[0]; int boxEndY = p[1]; // does the linesegment run from right to left? if (boxEndX < boxStartX) { final int helpX = boxStartX; final int helpY = boxStartY; boxStartX = boxEndX; boxStartY = boxEndY; boxEndX = helpX; boxEndY = helpY; } final double rotation = getRotation(boxStartX, boxStartY, boxEndX, boxEndY); final double[] deviation = calcDeviation(new int[] { boxStartX, boxStartY }, new int[] { boxEndX, boxEndY }, eCandidates); final double[] displacement = calculateDisplacement(placementType, 0.0, perpendicularOffset, delta, deviation); final double[] anchorPoint = DEFAULT_POINT_ANCHOR; final Label label = createLabel(caption, font, color, metrics, feature, (int) (boxStartX + radius), boxStartY, size, rotation, anchorPoint, displacement); labels.add(label); boxStartX = lastX; boxStartY = lastY; eCandidates.clear(); } else { eCandidates.add(new int[] { screenX, screenY }); lastX = screenX; lastY = screenY; i++; } } // pick lists of boxes on the linestring // FIXME: strange: is the gap really the number of labels? shouldn't it be the minimum gap in pixels betwen to // labels? final List<Label> pick = new ArrayList<>(100); final int n = labels.size(); for (int j = n / 2; j < n; j += gap + 1) pick.add(labels.get(j)); for (int j = n / 2 - (gap + 1); j > 0; j -= gap + 1) pick.add(labels.get(j)); return pick.toArray(new Label[pick.size()]); }
From source file:net.sourceforge.entrainer.gui.EntrainerFX.java
private void setJFXSize(Dimension size) { double width = size.getWidth(); hiddenSidesPane.setPrefSize(width, size.getHeight()); setTitledPaneWidth(sliderControlPane, width); setTitledPaneWidth(animations, width); setTitledPaneWidth(shimmerOptions, width); setTitledPaneWidth(neuralizer, width); setTitledPaneWidth(pictures, width); setShimmerSizes();// w w w. j a v a2 s . com background.setDimension(size.getWidth(), size.getHeight()); }
From source file:org.photovault.imginfo.PhotoInfo.java
/** Find instance that is preferred for use in particular situation. This function seeks for an image that has at least a given resolution, has certain operations already applied and is available. @param requiredOpers Set of operations that must be applied correctly in the returned image (but not that the operations need not be applied if this photo does not specify some operation. So even if this is non-empty it is possible that the method returns original image! @param allowedOpers Set of operations that may be applied to the returned image/*from w w w .j a v a 2s. c o m*/ @param minWidth Minimum width of the returned image in pixels @param minHeight Minimum height of the returned image in pixels @param maxWidth Maximum width of the returned image in pixels @param maxHeight Maximum height of the returned image in pixels @return Image that best matches the given criteria or <code>null</code> if no suct image exists or is not available. */ public ImageDescriptorBase getPreferredImage(Set<ImageOperations> requiredOpers, Set<ImageOperations> allowedOpers, int minWidth, int minHeight, int maxWidth, int maxHeight) { ImageDescriptorBase preferred = null; EnumSet<ImageOperations> appliedPreferred = null; // We are not interested in operations that are not specified for this photo EnumSet<ImageOperations> specifiedOpers = getAppliedOperations(); requiredOpers = EnumSet.copyOf(requiredOpers); requiredOpers.removeAll(EnumSet.complementOf(specifiedOpers)); /* Would the original be OK? */ if (requiredOpers.size() == 0 && original.getWidth() <= maxWidth && original.getHeight() <= maxHeight && original.getFile().findAvailableCopy() != null) { preferred = original; appliedPreferred = EnumSet.noneOf(ImageOperations.class); } // Calculate minimum & maimum scaling of resolution compared to original double minScale = ((double) minWidth) / ((double) original.getWidth()); double maxScale = ((double) maxHeight) / ((double) original.getHeight()); if (allowedOpers.contains(ImageOperations.CROP)) { Dimension croppedSize = getCroppedSize(); double aspectRatio = croppedSize.getWidth() / croppedSize.getHeight(); double miw = minWidth; double mih = minHeight; double maw = maxWidth; double mah = maxHeight; if (mih == 0.0 || (miw / mih) > aspectRatio) { mih = miw / aspectRatio; } if (mih > 0.0 && (miw / mih) < aspectRatio) { miw = mih * aspectRatio; } if (maw / mah > aspectRatio) { maw = mah * aspectRatio; } if (maw / mah < aspectRatio) { mah = maw / aspectRatio; } miw = Math.floor(miw); mih = Math.floor(mih); maw = Math.ceil(maw); mah = Math.ceil(mah); minScale = ((double) miw) / ((double) croppedSize.getWidth()); maxScale = ((double) maw) / ((double) croppedSize.getWidth()); } // Check the copies Set<CopyImageDescriptor> copies = original.getCopies(); for (CopyImageDescriptor copy : copies) { double scale = ((double) copy.getWidth()) / ((double) original.getWidth()); if (copy.getAppliedOperations().contains(ImageOperations.CROP)) { scale = ((double) copy.getWidth()) / ((double) getCroppedSize().getWidth()); } if (scale >= minScale && scale <= maxScale && copy.getFile().findAvailableCopy() != null) { EnumSet<ImageOperations> applied = copy.getAppliedOperations(); if (applied.containsAll(requiredOpers) && allowedOpers.containsAll(applied) && isConsistentWithCurrentSettings(copy)) { // This is a potential one if (preferred == null || !appliedPreferred.containsAll(applied)) { preferred = copy; appliedPreferred = applied; } } } } return preferred; }
From source file:org.processmining.analysis.performance.dottedchart.ui.DottedChartPanel.java
/** * adjusts the viewable are of the log (zoom) *//* www .j a v a2 s.com*/ public void setViewportZoomIn() { Dimension d = dca.getViewportSize(); int width = Math.abs(p1.x - p2.x); int height = Math.abs(p1.y - p2.y); int value = (int) (Math.log10( (double) this.getWidth() * (d.getWidth() / width) / (double) dca.getViewportSize().getWidth()) * 1000.0); if (value > 3000) return; value = (int) (Math.log10( (double) this.getHeight() * (d.getHeight() / height) / (double) dca.getViewportSize().getHeight()) * 1000.0); if (value > 3000) return; updWidth = (int) ((double) this.getWidth() * (d.getWidth() / width)); updHight = (int) ((double) this.getHeight() * (d.getHeight() / height)); Dimension dim = new Dimension(updWidth, updHight); int pos_x = Math.min(p1.x, p2.x); int pos_y = Math.min(p1.y, p2.y); Point p = new Point((int) (pos_x * d.getWidth() / width), (int) (pos_y * d.getHeight() / height)); this.setPreferredSize(dim); updateMilli2pixelsRatio(); this.revalidate(); dca.setScrollBarPosition(p); p1 = null; p2 = null; adjustSlideBar(); }
From source file:org.processmining.analysis.performance.dottedchart.ui.DottedChartPanel.java
/** * adjusts the viewable are of the log (zoom) *//*from w ww.j a v a 2s.c o m*/ public Point zoomInViewPort() { if (p1 == null || p2 == null) return null; Dimension d = dca.getViewportSize(); int width = Math.abs(p1.x - p2.x); int height = Math.abs(p1.y - p2.y); int value = (int) (Math.log10( (double) this.getWidth() * (d.getWidth() / width) / (double) dca.getViewportSize().getWidth()) * 1000.0); if (value > 3000) return null; value = (int) (Math.log10( (double) this.getHeight() * (d.getHeight() / height) / (double) dca.getViewportSize().getHeight()) * 1000.0); if (value > 3000) return null; updWidth = (int) ((double) this.getWidth() * (d.getWidth() / width)); updHight = (int) ((double) this.getHeight() * (d.getHeight() / height)); Dimension dim = new Dimension(updWidth, updHight); int pos_x = Math.min(p1.x, p2.x); int pos_y = Math.min(p1.y, p2.y); this.setPreferredSize(dim); updateMilli2pixelsRatio(); this.revalidate(); p1 = null; p2 = null; adjustSlideBar(); return new Point((int) (pos_x * d.getWidth() / width), (int) (pos_y * d.getHeight() / height)); }
From source file:ome.services.RenderingBean.java
@RolesAllowed("user") public int[] getTileSize() { rwl.writeLock().lock();// www.ja va2 s . c o m try { errorIfInvalidState(); Dimension tileSize = renderer.getTileSize(); return new int[] { (int) tileSize.getWidth(), (int) tileSize.getHeight() }; } finally { rwl.writeLock().unlock(); } }
From source file:display.containers.FileManager.java
public Container getPane() { //if (gui==null) { fileSystemView = FileSystemView.getFileSystemView(); desktop = Desktop.getDesktop(); JPanel detailView = new JPanel(new BorderLayout(3, 3)); //fileTableModel = new FileTableModel(); table = new JTable(); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.setAutoCreateRowSorter(true);/*from w w w .j ava2 s . c om*/ table.setShowVerticalLines(false); table.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { if (e.getClickCount() >= 2) { Point p = e.getPoint(); int row = table.convertRowIndexToModel(table.rowAtPoint(p)); int column = table.convertColumnIndexToModel(table.columnAtPoint(p)); if (row >= 0 && column >= 0) { mouseDblClicked(row, column); } } } }); table.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent arg0) { } @Override public void keyReleased(KeyEvent arg0) { if (KeyEvent.VK_DELETE == arg0.getKeyCode()) { if (mode != 2) { parentFrame.setLock(true); parentFrame.getProgressBarPanel().setVisible(true); Thread t = new Thread(new Runnable() { @Override public void run() { try { deleteSelectedFiles(); } catch (IOException e) { JOptionPane.showMessageDialog(parentFrame, "Error during the deletion.", "Deletion error", JOptionPane.ERROR_MESSAGE); WindowManager.mwLogger.log(Level.SEVERE, "Error during the deletion.", e); } finally { parentFrame.setLock(false); refresh(); parentFrame.getProgressBarPanel().setVisible(false); } } }); t.start(); } else { if (UserProfile.CURRENT_USER.getLevel() == 3) { parentFrame.setLock(true); parentFrame.getProgressBarPanel().setVisible(true); Thread delThread = new Thread(new Runnable() { @Override public void run() { int[] rows = table.getSelectedRows(); int[] columns = table.getSelectedColumns(); for (int i = 0; i < rows.length; i++) { if (!continueAction) { continueAction = true; return; } int row = table.convertRowIndexToModel(rows[i]); try { deleteServerFile(row); } catch (Exception e) { WindowManager.mwLogger.log(Level.SEVERE, "Error during the deletion.", e); } } refresh(); parentFrame.setLock(false); parentFrame.getProgressBarPanel().setVisible(false); } }); delThread.start(); } } } } @Override public void keyPressed(KeyEvent arg0) { // TODO Auto-generated method stub } }); table.getSelectionModel().addListSelectionListener(listSelectionListener); JScrollPane tableScroll = new JScrollPane(table); Dimension d = tableScroll.getPreferredSize(); tableScroll.setPreferredSize(new Dimension((int) d.getWidth(), (int) d.getHeight() / 2)); detailView.add(tableScroll, BorderLayout.CENTER); // the File tree DefaultMutableTreeNode root = new DefaultMutableTreeNode(); treeModel = new DefaultTreeModel(root); table.getRowSorter().addRowSorterListener(new RowSorterListener() { @Override public void sorterChanged(RowSorterEvent e) { ((FileTableModel) table.getModel()).fireTableDataChanged(); } }); // show the file system roots. File[] roots = fileSystemView.getRoots(); for (File fileSystemRoot : roots) { DefaultMutableTreeNode node = new DefaultMutableTreeNode(fileSystemRoot); root.add(node); //showChildren(node); // File[] files = fileSystemView.getFiles(fileSystemRoot, true); for (File file : files) { if (file.isDirectory()) { node.add(new DefaultMutableTreeNode(file)); } } // } JScrollPane treeScroll = new JScrollPane(); Dimension preferredSize = treeScroll.getPreferredSize(); Dimension widePreferred = new Dimension(200, (int) preferredSize.getHeight()); treeScroll.setPreferredSize(widePreferred); JPanel fileView = new JPanel(new BorderLayout(3, 3)); detailView.add(fileView, BorderLayout.SOUTH); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, treeScroll, detailView); JPanel simpleOutput = new JPanel(new BorderLayout(3, 3)); progressBar = new JProgressBar(); simpleOutput.add(progressBar, BorderLayout.EAST); progressBar.setVisible(false); showChildren(getCurrentDir().toPath()); //table.setDragEnabled(true); table.setColumnSelectionAllowed(false); // Menu popup Pmenu = new JPopupMenu(); changeProjectitem = new JMenuItem("Reassign"); renameProjectitem = new JMenuItem("Rename"); twitem = new JMenuItem("To workspace"); tlitem = new JMenuItem("To local"); processitem = new JMenuItem("Select for process"); switch (mode) { case 0: Pmenu.add(twitem); twitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { parentFrame.getBtnlocalTowork().doClick(); } }); break; case 1: Pmenu.add(tlitem); Pmenu.add(processitem); tlitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { parentFrame.getBtnWorkTolocal().doClick(); } }); processitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { SwingUtilities.invokeLater(new Runnable() { public void run() { // Recupere les lignes selectionnees int[] indices = table.getSelectedRows(); // On recupere les fichiers correspondants ArrayList<File> files = new ArrayList<File>(); for (int i = 0; i < indices.length; i++) { int row = table.convertRowIndexToModel(indices[i]); File fi = ((FileTableModel) table.getModel()).getFile(row); if (fi.isDirectory()) files.add(fi); } ImageProcessingFrame imf = new ImageProcessingFrame(files); } }); } }); break; case 2: if (UserProfile.CURRENT_USER.getLevel() == 3) { Pmenu.add(changeProjectitem); Pmenu.add(renameProjectitem); } Pmenu.add(twitem); twitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { parentFrame.getBtndistToWorkspace().doClick(); } }); Pmenu.add(tlitem); tlitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { parentFrame.getBtndistToLocal().doClick(); } }); break; } changeProjectitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { table.setEnabled(false); File from = ((FileTableModel) table.getModel()) .getFile(table.convertRowIndexToModel(table.getSelectedRows()[0])); ReassignProjectPanel reas = new ReassignProjectPanel(from.toPath()); // mode creation de liens Popup popup = PopupFactory.getSharedInstance().getPopup(WindowManager.MAINWINDOW, reas, (int) WindowManager.MAINWINDOW.getX() + 200, (int) WindowManager.MAINWINDOW.getY() + 150); reas.setPopupWindow(popup); popup.show(); table.setEnabled(true); } }); renameProjectitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { table.setEnabled(false); final File from = ((FileTableModel) table.getModel()) .getFile(table.convertRowIndexToModel(table.getSelectedRows()[0])); JDialog.setDefaultLookAndFeelDecorated(true); String s = (String) JOptionPane.showInputDialog(WindowManager.MAINWINDOW, "New project name ?", "Rename project", JOptionPane.PLAIN_MESSAGE, null, null, from.getName()); //If a string was returned, say so. if ((s != null) && (s.length() > 0)) { ProjectDAO pdao = new MySQLProjectDAO(); if (new File(from.getParent() + File.separator + s).exists()) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JDialog.setDefaultLookAndFeelDecorated(true); JOptionPane.showMessageDialog(WindowManager.MAINWINDOW, "Couldn't rename " + from.getName() + " (A file with this filename already exists)", "Renaming error", JOptionPane.ERROR_MESSAGE); } }); WindowManager.mwLogger.log(Level.SEVERE, "Error during file project renaming (" + from.getName() + "). [Duplication error]"); } else { try { boolean succeed = pdao.renameProject(from.getName(), s); if (!succeed) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JDialog.setDefaultLookAndFeelDecorated(true); JOptionPane.showMessageDialog(WindowManager.MAINWINDOW, "Couldn't rename " + from.getName() + " (no project with this name)", "Renaming error", JOptionPane.ERROR_MESSAGE); } }); } else { from.renameTo(new File(from.getParent() + File.separator + s)); // on renomme le repertoire nifti ou dicom correspondant si il existe switch (from.getParentFile().getName()) { case ServerInfo.NRI_ANALYSE_NAME: if (new File(from.getAbsolutePath().replaceAll(ServerInfo.NRI_ANALYSE_NAME, ServerInfo.NRI_DICOM_NAME)).exists()) try { Files.move(Paths.get(from.getAbsolutePath().replaceAll( ServerInfo.NRI_ANALYSE_NAME, ServerInfo.NRI_DICOM_NAME)), Paths.get(from.getParent().replaceAll( ServerInfo.NRI_ANALYSE_NAME, ServerInfo.NRI_DICOM_NAME) + File.separator + s)); } catch (IOException e) { e.printStackTrace(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JDialog.setDefaultLookAndFeelDecorated(true); JOptionPane.showMessageDialog(WindowManager.MAINWINDOW, "Couldn't rename " + from.getName() + " (error with file system)", "Renaming error", JOptionPane.ERROR_MESSAGE); } }); WindowManager.mwLogger.log(Level.SEVERE, "Error during file project renaming (" + from.getName() + ")", e); } //from.renameTo(new File(from.getParent().replaceAll(ServerInfo.NRI_ANALYSE_NAME, ServerInfo.NRI_DICOM_NAME)+File.separator+s)); break; case ServerInfo.NRI_DICOM_NAME: if (new File(from.getAbsolutePath().replaceAll(ServerInfo.NRI_DICOM_NAME, ServerInfo.NRI_ANALYSE_NAME)).exists()) try { Files.move(Paths.get(from.getAbsolutePath().replaceAll( ServerInfo.NRI_DICOM_NAME, ServerInfo.NRI_ANALYSE_NAME)), Paths.get(from.getParent().replaceAll(ServerInfo.NRI_DICOM_NAME, ServerInfo.NRI_ANALYSE_NAME) + File.separator + s)); } catch (IOException e) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JDialog.setDefaultLookAndFeelDecorated(true); JOptionPane.showMessageDialog(WindowManager.MAINWINDOW, "Couldn't rename " + from.getName() + " (error with file system)", "Renaming error", JOptionPane.ERROR_MESSAGE); } }); e.printStackTrace(); WindowManager.mwLogger.log(Level.SEVERE, "Error during file project renaming (" + from.getName() + ")", e); } //from.renameTo(new File(from.getParent().replaceAll(ServerInfo.NRI_DICOM_NAME, ServerInfo.NRI_ANALYSE_NAME)+File.separator+s)); break; } refresh(); } } catch (final SQLException e) { WindowManager.mwLogger.log(Level.SEVERE, "Error during SQL project renaming", e); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JDialog.setDefaultLookAndFeelDecorated(true); JOptionPane.showMessageDialog(WindowManager.MAINWINDOW, "Exception : " + e.toString(), "Openning error", JOptionPane.ERROR_MESSAGE); } }); } } } table.setEnabled(true); } }); table.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent me) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent me) { if (me.getButton() == 3 && table.getSelectedRowCount() > 0) { int row = table.convertRowIndexToModel(table.rowAtPoint(me.getPoint())); changeProjectitem.setVisible(isPatient(((FileTableModel) table.getModel()).getFile(row))); renameProjectitem.setVisible(isProject(((FileTableModel) table.getModel()).getFile(row))); Pmenu.show(me.getComponent(), me.getX(), me.getY()); } } }); // //} return tableScroll; }
From source file:mondrian.gui.Workbench.java
private void tileMenuItemActionPerformed(ActionEvent evt) { final Dimension dsize = desktopPane.getSize(); final int desktopW = (int) dsize.getWidth(); final int desktopH = (int) dsize.getHeight(); final int darea = desktopW * desktopH; final double eacharea = darea / (schemaWindowMap.size() + mdxWindows.size() + jdbcWindows.size()); final int wh = (int) Math.sqrt(eacharea); try {/* w ww.j ava2s . c o m*/ int x = 0, y = 0; for (JInternalFrame sf : getAllFrames()) { if (sf != null && !sf.isIcon()) { sf.setMaximum(false); sf.moveToFront(); if (x >= desktopW || (desktopW - x) * wh < eacharea / 2) { // move to next row of windows y += wh; x = 0; } int sfwidth = ((x + wh) < desktopW ? wh : desktopW - x); int sfheight = ((y + wh) < desktopH ? wh : desktopH - y); sf.setBounds(x, y, sfwidth, sfheight); x += sfwidth; } } } catch (Exception ex) { LOGGER.error("tileMenuItemActionPerformed", ex); // do nothing } }
From source file:org.mwc.cmap.xyplot.views.XYPlotView.java
private void rtfToClipboard(final String fName, final Dimension dim) { // Issue #520 - Copy WMF embedded in RTF ByteArrayOutputStream os = null; DataInputStream dis = null;/*from w w w . j a v a 2 s. com*/ try { os = new ByteArrayOutputStream(); RTFWriter writer = new RTFWriter(os); File file = new File(fName); byte[] data = new byte[(int) file.length()]; dis = new DataInputStream(new FileInputStream(file)); dis.readFully(data); writer.writeHeader(); writer.writeEmfPicture(data, dim.getWidth(), dim.getHeight()); writer.writeTail(); RTFTransfer rtfTransfer = RTFTransfer.getInstance(); Clipboard clipboard = new Clipboard(Display.getDefault()); Object[] rtfData = new Object[] { os.toString() }; clipboard.setContents(rtfData, new Transfer[] { rtfTransfer }); } catch (final Exception e1) { IStatus status = new Status(IStatus.ERROR, PlotViewerPlugin.PLUGIN_ID, e1.getLocalizedMessage(), e1); XYPlotPlugin.getDefault().getLog().log(status); } finally { if (os != null) { try { os.close(); } catch (IOException e1) { // ignore } } if (dis != null) { try { dis.close(); } catch (IOException e1) { // ignore } } } }