List of usage examples for javax.swing ImageIcon getImage
@Transient
public Image getImage()
Image
. From source file:net.sourceforge.atunes.kernel.modules.tags.PropertiesFileTagAdapter.java
@Override public ImageIcon getImage(final ILocalAudioObject audioObject, final int width, final int height) { String coverFileName = getFileNameForCover(audioObject); ImageIcon image = null; if (coverFileName != null && new File(coverFileName).exists()) { image = new ImageIcon(coverFileName); }/*from ww w. j a v a2 s . c o m*/ if (image != null) { if (width == -1 || height == -1) { return image; } int maxSize = (image.getIconWidth() > image.getIconHeight()) ? image.getIconWidth() : image.getIconHeight(); int newWidth = (int) ((float) image.getIconWidth() / (float) maxSize * width); int newHeight = (int) ((float) image.getIconHeight() / (float) maxSize * height); return ImageUtils.scaleImageBicubic(image.getImage(), newWidth, newHeight); } return image; }
From source file:JDAC.JDAC.java
public JDAC() { setTitle("JDAC"); ImageIcon img = new ImageIcon("logo.png"); setIconImage(img.getImage()); //setLayout(new FlowLayout()); mDataset = createDataset("A"); mChart = ChartFactory.createXYLineChart("Preview", "Time (ms)", "Value", mDataset, PlotOrientation.VERTICAL, false, true, false);/*from w w w. ja v a 2 s . co m*/ mLastChart = ChartFactory.createXYLineChart("Last n values", "Time (ms)", "Value", createLastDataset("B"), PlotOrientation.VERTICAL, false, true, false); mChart.getXYPlot().getDomainAxis().setLowerMargin(0); mChart.getXYPlot().getDomainAxis().setUpperMargin(0); mLastChart.getXYPlot().getDomainAxis().setLowerMargin(0); mLastChart.getXYPlot().getDomainAxis().setUpperMargin(0); ChartPanel chartPanel = new ChartPanel(mChart); ChartPanel chartLastPanel = new ChartPanel(mLastChart); //chartPanel.setPreferredSize( new java.awt.Dimension( 560 , 367 ) ); XYPlot plot = mChart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesPaint(0, Color.GREEN); renderer.setSeriesStroke(0, new BasicStroke(1.0f)); plot.setRenderer(renderer); XYPlot lastPlot = mLastChart.getXYPlot(); XYLineAndShapeRenderer lastRenderer = new XYLineAndShapeRenderer(); lastRenderer.setSeriesPaint(0, Color.RED); lastRenderer.setSeriesStroke(0, new BasicStroke(1.0f)); lastPlot.setRenderer(lastRenderer); resetChartButton = new JButton("Reset"); resetChartButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { resetChart(); } }); mMenuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); JMenu sensorMenu = new JMenu("Sensor"); JMenu deviceMenu = new JMenu("Device"); portSubMenu = new JMenu("Port"); JMenu helpMenu = new JMenu("Help"); serialStatusLabel = new JLabel("Disconnected"); statusLabel = new JLabel("Ready"); clearStatus = new LabelClear(statusLabel); clearStatus.resetTime(); connectButton = new JMenuItem("Connect"); disconnectButton = new JMenuItem("Disconnect"); startButton = new JButton("Start"); stopButton = new JButton("Stop"); scanButton = new JMenuItem("Refresh port list"); exportCSVButton = new JMenuItem("Export data to CSV"); exportCSVButton.setAccelerator(KeyStroke.getKeyStroke("control S")); exportCSVButton.setMnemonic(KeyEvent.VK_S); exportPNGButton = new JMenuItem("Export chart to PNG"); JPanel optionsPanel = new JPanel(new BorderLayout()); JMenuItem exitItem = new JMenuItem("Exit"); exitItem.setAccelerator(KeyStroke.getKeyStroke("control X")); exitItem.setMnemonic(KeyEvent.VK_X); JMenuItem aboutItem = new JMenuItem("About"); JMenuItem helpItem = new JMenuItem("Help"); JMenuItem quickStartItem = new JMenuItem("Quick start"); lastSpinner = new JSpinner(new SpinnerNumberModel(10, 0, 1000, 1)); ActionListener mSensorListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setSensor(e.getActionCommand()); } }; ButtonGroup sensorGroup = new ButtonGroup(); JRadioButtonMenuItem tmpRadioButton = new JRadioButtonMenuItem("Temperature"); sensorGroup.add(tmpRadioButton); sensorMenu.add(tmpRadioButton); tmpRadioButton.addActionListener(mSensorListener); tmpRadioButton = new JRadioButtonMenuItem("Distance"); sensorGroup.add(tmpRadioButton); sensorMenu.add(tmpRadioButton); tmpRadioButton.addActionListener(mSensorListener); tmpRadioButton = new JRadioButtonMenuItem("Voltage"); sensorGroup.add(tmpRadioButton); sensorMenu.add(tmpRadioButton); tmpRadioButton.addActionListener(mSensorListener); tmpRadioButton = new JRadioButtonMenuItem("Generic"); tmpRadioButton.setSelected(true); setSensor("Generic"); sensorGroup.add(tmpRadioButton); sensorMenu.add(tmpRadioButton); tmpRadioButton.addActionListener(mSensorListener); connectButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (selectedPortName == null) { setStatus("No port selected"); return; } connect(selectedPortName); } }); disconnectButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { serialStatusLabel.setText("Disconnecting..."); if (serialPort == null) { serialStatusLabel.setText("Disconnected"); serialConnected = false; return; } stopCollect(); disconnect(); } }); scanButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { searchForPorts(); } }); exportCSVButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { saveData(); } }); exportPNGButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { exportPNG(); } }); startButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { startCollect(); } }); stopButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { stopCollect(); } }); lastSpinner.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { numLastValues = (Integer) lastSpinner.getValue(); updateLastTitle(); } }); updateLastTitle(); exitItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); helpItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new HelpFrame(); } }); aboutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new AboutFrame(); } }); quickStartItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new StartFrame(); } }); fileMenu.add(exportCSVButton); fileMenu.add(exportPNGButton); fileMenu.addSeparator(); fileMenu.add(exitItem); deviceMenu.add(connectButton); deviceMenu.add(disconnectButton); deviceMenu.addSeparator(); deviceMenu.add(portSubMenu); deviceMenu.add(scanButton); helpMenu.add(quickStartItem); helpMenu.add(helpItem); helpMenu.add(aboutItem); mMenuBar.add(fileMenu); mMenuBar.add(sensorMenu); mMenuBar.add(deviceMenu); mMenuBar.add(helpMenu); JPanel controlsPanel = new JPanel(); controlsPanel.add(startButton); controlsPanel.add(stopButton); controlsPanel.add(resetChartButton); optionsPanel.add(controlsPanel, BorderLayout.LINE_START); JPanel lastPanel = new JPanel(new FlowLayout()); lastPanel.add(new JLabel("Shown values: ")); lastPanel.add(lastSpinner); optionsPanel.add(lastPanel); JPanel serialPanel = new JPanel(new FlowLayout()); serialPanel.add(serialStatusLabel); optionsPanel.add(serialPanel, BorderLayout.LINE_END); add(optionsPanel, BorderLayout.PAGE_START); JPanel mainPanel = new JPanel(new GridLayout(0, 2)); mainPanel.add(chartPanel); mainPanel.add(chartLastPanel); add(mainPanel); add(statusLabel, BorderLayout.PAGE_END); setJMenuBar(mMenuBar); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { dispose(); } }); setSize(800, 800); pack(); new StartFrame(); //center on screen Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); int x = (int) ((dimension.getWidth() - getWidth()) / 2); int y = (int) ((dimension.getHeight() - getHeight()) / 2); setLocation(x, y); setVisible(true); }
From source file:com.akman.excel.view.frmExportExcel.java
private void btnSelectImageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelectImageActionPerformed JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Image files", "jpg", "png", "gif", "bmp"); chooser.setFileFilter(filter);//www . j av a 2 s . c om chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setDialogTitle("Select The Image"); chooser.setMultiSelectionEnabled(false); int res = chooser.showOpenDialog(null); if (res == JFileChooser.APPROVE_OPTION) { //Saving file inside the file File file = chooser.getSelectedFile(); // if(!file.equals(filter)) // { // JOptionPane.showMessageDialog(null, "Wrong File Selected","ERROR",JOptionPane.ERROR_MESSAGE); // return; // } //System.out.println(file.getAbsolutePath()); ImageIcon image = new ImageIcon(file.getAbsolutePath()); fileNameSignature = file.getAbsolutePath(); // Get Width And Height of PicLabel Rectangle rect = lblImage.getBounds(); //System.out.println(lblImage.getBounds()); //Scaling the image to fit in the picLabel Image scaledimage = image.getImage().getScaledInstance(rect.width, rect.height, Image.SCALE_DEFAULT); //converting the image back to image icon to make an acceptable picLabel image = new ImageIcon(scaledimage); lblImage.setIcon(image); txtPathSig.setText(fileNameSignature); try { File images = new File(fileNameSignature); FileInputStream fis = new FileInputStream(images); ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; for (int readNum; (readNum = fis.read(buf)) != -1;) { bos.write(buf, 0, readNum); } person_image = bos.toByteArray(); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } }
From source file:edu.ku.brc.specify.rstools.GoogleEarthExporter.java
/** * @param outputFile// w w w . ja v a 2 s . co m * @param defaultIconFile */ protected void createKMZ(final File outputFile, final File defaultIconFile) throws IOException { // now we have the KML in outputFile // we need to create a KMZ (zip file containing doc.kml and other files) // create a buffer for reading the files byte[] buf = new byte[1024]; int len; // create the KMZ file File outputKMZ = File.createTempFile("sp6-export-", ".kmz"); ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outputKMZ)); // add the doc.kml file to the ZIP FileInputStream in = new FileInputStream(outputFile); // add ZIP entry to output stream out.putNextEntry(new ZipEntry("doc.kml")); // copy the bytes while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } // complete the entry out.closeEntry(); in.close(); // add a "files" directory to the KMZ file ZipEntry filesDir = new ZipEntry("files/"); out.putNextEntry(filesDir); out.closeEntry(); if (defaultIconFile != null) { File iconTmpFile = defaultIconFile; if (false) { // Shrink File ImageIcon icon = new ImageIcon(defaultIconFile.getAbsolutePath()); BufferedImage bimage = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); Graphics g = bimage.createGraphics(); g.drawImage(icon.getImage(), 0, 0, null); g.dispose(); BufferedImage scaledBI = GraphicsUtils.getScaledInstance(bimage, 16, 16, true); iconTmpFile = File.createTempFile("sp6-export-icon-scaled", ".png"); ImageIO.write(scaledBI, "PNG", iconTmpFile); } // add the specify32.png file (default icon file) to the ZIP (in the "files" directory) in = new FileInputStream(iconTmpFile); // add ZIP entry to output stream out.putNextEntry(new ZipEntry("files/specify32.png")); // copy the bytes while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } // complete the entry out.closeEntry(); in.close(); } // complete the ZIP file out.close(); // now put the KMZ file where the KML output was FileUtils.copyFile(outputKMZ, outputFile); outputKMZ.delete(); }
From source file:gdt.jgui.entity.webset.JWeblinkEditor.java
/** * Create the context./*from w w w.j a v a2s. c om*/ * @param console the main console. * @param locator$ the locator string. * @return the procedure context. */ @Override public JContext instantiate(JMainConsole console, String locator$) { try { // System.out.println("WeblinkEditor.instantiate:locator="+locator$); this.console = console; Properties locator = Locator.toProperties(locator$); entihome$ = locator.getProperty(Entigrator.ENTIHOME); entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY); webLinkKey$ = locator.getProperty(JWeblinksPanel.WEB_LINK_KEY); System.out.println("WeblinkEditor.instantiate:1"); Entigrator entigrator = console.getEntigrator(entihome$); entityLabel$ = entigrator.indx_getLabel(entityKey$); Sack webset = entigrator.getEntityAtKey(entityKey$); Core address = webset.getElementItem("web", webLinkKey$); addressField.setText(address.value); nameField.setText(address.type); Core login = webset.getElementItem("web.login", webLinkKey$); if (login != null) { loginField.setText(login.type); passwordField.setText(login.value); } Core iconCore = webset.getElementItem("web.icon", webLinkKey$); if (iconCore != null && iconCore.value != null) { try { String icon$ = iconCore.value; byte[] ba = Base64.decodeBase64(icon$); ImageIcon icon = new ImageIcon(ba); Image image = icon.getImage().getScaledInstance(24, 24, 0); icon.setImage(image); iconIcon.setIcon(icon); } catch (Exception ee) { } } requesterResponseLocator$ = locator.getProperty(JRequester.REQUESTER_RESPONSE_LOCATOR); } catch (Exception e) { Logger.getLogger(getClass().getName()).severe(e.toString()); } return this; }
From source file:com.vgi.mafscaling.MafCompare.java
/** * Initialize the contents of the frame. */// w w w. j a va 2 s. co m private void initialize() { try { ImageIcon tableImage = new ImageIcon(getClass().getResource("/table.jpg")); setTitle(Title); setIconImage(tableImage.getImage()); setBounds(100, 100, 621, 372); setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); setSize(Config.getCompWindowSize()); setLocation(Config.getCompWindowLocation()); setLocationRelativeTo(null); setVisible(false); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { Utils.clearTable(origMafTable); Utils.clearTable(newMafTable); Utils.clearTable(compMafTable); Config.setCompWindowSize(getSize()); Config.setCompWindowLocation(getLocation()); origMafData.clear(); newMafData.clear(); } }); JPanel dataPanel = new JPanel(); GridBagLayout gbl_dataPanel = new GridBagLayout(); gbl_dataPanel.columnWidths = new int[] { 0, 0, 0 }; gbl_dataPanel.rowHeights = new int[] { RowHeight, RowHeight, RowHeight, RowHeight, RowHeight, 0 }; gbl_dataPanel.columnWeights = new double[] { 0.0, 0.0, 0.0 }; gbl_dataPanel.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 }; dataPanel.setLayout(gbl_dataPanel); getContentPane().add(dataPanel); JLabel origLabel = new JLabel(origMaf); GridBagConstraints gbc_origLabel = new GridBagConstraints(); gbc_origLabel.anchor = GridBagConstraints.PAGE_START; gbc_origLabel.insets = new Insets(1, 1, 1, 5); gbc_origLabel.weightx = 0; gbc_origLabel.weighty = 0; gbc_origLabel.gridx = 0; gbc_origLabel.gridy = 0; gbc_origLabel.gridheight = 2; dataPanel.add(origLabel, gbc_origLabel); JLabel newLabel = new JLabel(newMaf); GridBagConstraints gbc_newLabel = new GridBagConstraints(); gbc_newLabel.anchor = GridBagConstraints.PAGE_START; gbc_newLabel.insets = new Insets(1, 1, 1, 5); gbc_newLabel.weightx = 0; gbc_newLabel.weighty = 0; gbc_newLabel.gridx = 0; gbc_newLabel.gridy = 2; gbc_newLabel.gridheight = 2; dataPanel.add(newLabel, gbc_newLabel); JLabel compLabel = new JLabel("Change"); GridBagConstraints gbc_compLabel = new GridBagConstraints(); gbc_compLabel.anchor = GridBagConstraints.PAGE_START; gbc_compLabel.insets = new Insets(1, 1, 1, 5); gbc_compLabel.weightx = 0; gbc_compLabel.weighty = 0; gbc_compLabel.gridx = 0; gbc_compLabel.gridy = 4; dataPanel.add(compLabel, gbc_compLabel); JLabel origVoltLabel = new JLabel("volt"); GridBagConstraints gbc_origVoltLabel = new GridBagConstraints(); gbc_origVoltLabel.anchor = GridBagConstraints.PAGE_START; gbc_origVoltLabel.insets = new Insets(1, 1, 1, 5); gbc_origVoltLabel.weightx = 0; gbc_origVoltLabel.weighty = 0; gbc_origVoltLabel.gridx = 1; gbc_origVoltLabel.gridy = 0; dataPanel.add(origVoltLabel, gbc_origVoltLabel); JLabel origGsLabel = new JLabel(" g/s"); GridBagConstraints gbc_origGsLabel = new GridBagConstraints(); gbc_origGsLabel.anchor = GridBagConstraints.PAGE_START; gbc_origGsLabel.insets = new Insets(1, 1, 1, 5); gbc_origGsLabel.weightx = 0; gbc_origGsLabel.weighty = 0; gbc_origGsLabel.gridx = 1; gbc_origGsLabel.gridy = 1; dataPanel.add(origGsLabel, gbc_origGsLabel); JLabel newVoltLabel = new JLabel("volt"); GridBagConstraints gbc_newVoltLabel = new GridBagConstraints(); gbc_newVoltLabel.anchor = GridBagConstraints.PAGE_START; gbc_newVoltLabel.insets = new Insets(1, 1, 1, 5); gbc_newVoltLabel.weightx = 0; gbc_newVoltLabel.weighty = 0; gbc_newVoltLabel.gridx = 1; gbc_newVoltLabel.gridy = 2; dataPanel.add(newVoltLabel, gbc_newVoltLabel); JLabel newGsLabel = new JLabel(" g/s"); GridBagConstraints gbc_newGsLabel = new GridBagConstraints(); gbc_newGsLabel.anchor = GridBagConstraints.PAGE_START; gbc_newGsLabel.insets = new Insets(1, 1, 1, 5); gbc_newGsLabel.weightx = 0; gbc_newGsLabel.weighty = 0; gbc_newGsLabel.gridx = 1; gbc_newGsLabel.gridy = 3; dataPanel.add(newGsLabel, gbc_newGsLabel); JLabel compPctLabel = new JLabel(" % "); GridBagConstraints gbc_compPctLabel = new GridBagConstraints(); gbc_compPctLabel.anchor = GridBagConstraints.PAGE_START; gbc_compPctLabel.insets = new Insets(1, 1, 1, 5); gbc_compPctLabel.weightx = 0; gbc_compPctLabel.weighty = 0; gbc_compPctLabel.gridx = 1; gbc_compPctLabel.gridy = 4; dataPanel.add(compPctLabel, gbc_compPctLabel); JPanel tablesPanel = new JPanel(); GridBagLayout gbl_tablesPanel = new GridBagLayout(); gbl_tablesPanel.columnWidths = new int[] { 0 }; gbl_tablesPanel.rowHeights = new int[] { 0, 0, 0 }; gbl_tablesPanel.columnWeights = new double[] { 0.0 }; gbl_tablesPanel.rowWeights = new double[] { 0.0, 0.0, 1.0 }; tablesPanel.setLayout(gbl_tablesPanel); JScrollPane mafScrollPane = new JScrollPane(tablesPanel); mafScrollPane.setMinimumSize(new Dimension(1600, 107)); mafScrollPane.getHorizontalScrollBar().setMaximumSize(new Dimension(20, 20)); mafScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); mafScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); GridBagConstraints gbc_mafScrollPane = new GridBagConstraints(); gbc_mafScrollPane.weightx = 1.0; gbc_mafScrollPane.anchor = GridBagConstraints.PAGE_START; gbc_mafScrollPane.fill = GridBagConstraints.HORIZONTAL; gbc_mafScrollPane.gridx = 2; gbc_mafScrollPane.gridy = 0; gbc_mafScrollPane.gridheight = 5; dataPanel.add(mafScrollPane, gbc_mafScrollPane); origMafTable = new JTable(); origMafTable.setColumnSelectionAllowed(true); origMafTable.setCellSelectionEnabled(true); origMafTable.setBorder(new LineBorder(new Color(0, 0, 0))); origMafTable.setRowHeight(RowHeight); origMafTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); origMafTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); origMafTable.setModel(new DefaultTableModel(2, MafTableColumnCount)); origMafTable.setTableHeader(null); Utils.initializeTable(origMafTable, ColumnWidth); GridBagConstraints gbc_origMafTable = new GridBagConstraints(); gbc_origMafTable.anchor = GridBagConstraints.PAGE_START; gbc_origMafTable.insets = new Insets(0, 0, 0, 0); gbc_origMafTable.fill = GridBagConstraints.HORIZONTAL; gbc_origMafTable.weightx = 1.0; gbc_origMafTable.weighty = 0; gbc_origMafTable.gridx = 0; gbc_origMafTable.gridy = 0; tablesPanel.add(origMafTable, gbc_origMafTable); excelAdapter.addTable(origMafTable, false, false, false, false, true, false, true, false, true); newMafTable = new JTable(); newMafTable.setColumnSelectionAllowed(true); newMafTable.setCellSelectionEnabled(true); newMafTable.setBorder(new LineBorder(new Color(0, 0, 0))); newMafTable.setRowHeight(RowHeight); newMafTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); newMafTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); newMafTable.setModel(new DefaultTableModel(2, MafTableColumnCount)); newMafTable.setTableHeader(null); Utils.initializeTable(newMafTable, ColumnWidth); GridBagConstraints gbc_newMafTable = new GridBagConstraints(); gbc_newMafTable.anchor = GridBagConstraints.PAGE_START; gbc_newMafTable.insets = new Insets(0, 0, 0, 0); gbc_newMafTable.fill = GridBagConstraints.HORIZONTAL; gbc_newMafTable.weightx = 1.0; gbc_newMafTable.weighty = 0; gbc_newMafTable.gridx = 0; gbc_newMafTable.gridy = 1; tablesPanel.add(newMafTable, gbc_newMafTable); excelAdapter.addTable(newMafTable, false, false, false, false, false, false, false, false, true); compMafTable = new JTable(); compMafTable.setColumnSelectionAllowed(true); compMafTable.setCellSelectionEnabled(true); compMafTable.setBorder(new LineBorder(new Color(0, 0, 0))); compMafTable.setRowHeight(RowHeight); compMafTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); compMafTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); compMafTable.setModel(new DefaultTableModel(1, MafTableColumnCount)); compMafTable.setTableHeader(null); Utils.initializeTable(compMafTable, ColumnWidth); NumberFormatRenderer numericRenderer = new NumberFormatRenderer(); numericRenderer.setFormatter(new DecimalFormat("0.000")); compMafTable.setDefaultRenderer(Object.class, numericRenderer); GridBagConstraints gbc_compMafTable = new GridBagConstraints(); gbc_compMafTable.anchor = GridBagConstraints.PAGE_START; gbc_compMafTable.insets = new Insets(0, 0, 0, 0); gbc_compMafTable.fill = GridBagConstraints.HORIZONTAL; gbc_compMafTable.weightx = 1.0; gbc_compMafTable.weighty = 0; gbc_compMafTable.gridx = 0; gbc_compMafTable.gridy = 2; tablesPanel.add(compMafTable, gbc_compMafTable); compExcelAdapter.addTable(compMafTable, false, true, false, false, false, true, true, false, true); TableModelListener origTableListener = new TableModelListener() { public void tableChanged(TableModelEvent tme) { if (tme.getType() == TableModelEvent.UPDATE) { int colCount = origMafTable.getColumnCount(); Utils.ensureColumnCount(colCount, newMafTable); Utils.ensureColumnCount(colCount, compMafTable); origMafData.clear(); String origY, origX, newY; for (int i = 0; i < colCount; ++i) { origY = origMafTable.getValueAt(1, i).toString(); if (Pattern.matches(Utils.fpRegex, origY)) { origX = origMafTable.getValueAt(0, i).toString(); if (Pattern.matches(Utils.fpRegex, origX)) origMafData.add(Double.valueOf(origX), Double.valueOf(origY), false); newY = newMafTable.getValueAt(1, i).toString(); if (Pattern.matches(Utils.fpRegex, newY)) compMafTable.setValueAt( ((Double.valueOf(newY) / Double.valueOf(origY)) - 1.0) * 100.0, 0, i); } else break; } origMafData.fireSeriesChanged(); } } }; TableModelListener newTableListener = new TableModelListener() { public void tableChanged(TableModelEvent tme) { if (tme.getType() == TableModelEvent.UPDATE) { int colCount = newMafTable.getColumnCount(); Utils.ensureColumnCount(colCount, origMafTable); Utils.ensureColumnCount(colCount, compMafTable); newMafData.clear(); String newY, newX, origY; for (int i = 0; i < colCount; ++i) { newY = newMafTable.getValueAt(1, i).toString(); if (Pattern.matches(Utils.fpRegex, newY)) { newX = newMafTable.getValueAt(0, i).toString(); if (Pattern.matches(Utils.fpRegex, newX)) newMafData.add(Double.valueOf(newX), Double.valueOf(newY), false); origY = origMafTable.getValueAt(1, i).toString(); if (Pattern.matches(Utils.fpRegex, origY)) compMafTable.setValueAt( ((Double.valueOf(newY) / Double.valueOf(origY)) - 1.0) * 100.0, 0, i); } else break; } newMafData.fireSeriesChanged(); } } }; origMafTable.getModel().addTableModelListener(origTableListener); newMafTable.getModel().addTableModelListener(newTableListener); Action action = new AbstractAction() { private static final long serialVersionUID = 8148393537657380215L; public void actionPerformed(ActionEvent e) { TableCellListener tcl = (TableCellListener) e.getSource(); if (Pattern.matches(Utils.fpRegex, compMafTable.getValueAt(0, tcl.getColumn()).toString())) { if (Pattern.matches(Utils.fpRegex, origMafTable.getValueAt(1, tcl.getColumn()).toString())) { double corr = Double.valueOf(compMafTable.getValueAt(0, tcl.getColumn()).toString()) / 100.0 + 1.0; newMafTable.setValueAt( Double.valueOf(origMafTable.getValueAt(1, tcl.getColumn()).toString()) * corr, 1, tcl.getColumn()); } } else compMafTable.setValueAt(tcl.getOldValue(), 0, tcl.getColumn()); } }; setCompMafCellListener(new TableCellListener(compMafTable, action)); // CHART JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, null, PlotOrientation.VERTICAL, false, true, false); chart.setBorderVisible(true); chartPanel = new ChartPanel(chart, true, true, true, true, true); chartPanel.setAutoscrolls(true); GridBagConstraints gbl_chartPanel = new GridBagConstraints(); gbl_chartPanel.anchor = GridBagConstraints.PAGE_START; gbl_chartPanel.fill = GridBagConstraints.BOTH; gbl_chartPanel.insets = new Insets(1, 1, 1, 1); gbl_chartPanel.weightx = 1.0; gbl_chartPanel.weighty = 1.0; gbl_chartPanel.gridx = 0; gbl_chartPanel.gridy = 5; gbl_chartPanel.gridheight = 1; gbl_chartPanel.gridwidth = 3; dataPanel.add(chartPanel, gbl_chartPanel); XYSplineRenderer lineRenderer = new XYSplineRenderer(3); lineRenderer.setUseFillPaint(true); lineRenderer.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new DecimalFormat("0.00"), new DecimalFormat("0.00"))); Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f); lineRenderer.setSeriesStroke(0, stroke); lineRenderer.setSeriesStroke(1, stroke); lineRenderer.setSeriesPaint(0, new Color(201, 0, 0)); lineRenderer.setSeriesPaint(1, new Color(0, 0, 255)); lineRenderer.setSeriesShape(0, ShapeUtilities.createDiamond((float) 2.5)); lineRenderer.setSeriesShape(1, ShapeUtilities.createDownTriangle((float) 2.5)); lineRenderer.setLegendItemLabelGenerator(new StandardXYSeriesLabelGenerator() { private static final long serialVersionUID = -4045338273187150888L; public String generateLabel(XYDataset dataset, int series) { XYSeries xys = ((XYSeriesCollection) dataset).getSeries(series); return xys.getDescription(); } }); NumberAxis mafvDomain = new NumberAxis(XAxisName); mafvDomain.setAutoRangeIncludesZero(false); mafvDomain.setAutoRange(true); mafvDomain.setAutoRangeStickyZero(false); NumberAxis mafgsRange = new NumberAxis(YAxisName); mafgsRange.setAutoRangeIncludesZero(false); mafgsRange.setAutoRange(true); mafgsRange.setAutoRangeStickyZero(false); XYSeriesCollection lineDataset = new XYSeriesCollection(); origMafData.setDescription(origMaf); newMafData.setDescription(newMaf); lineDataset.addSeries(origMafData); lineDataset.addSeries(newMafData); XYPlot plot = chart.getXYPlot(); plot.setRangePannable(true); plot.setDomainPannable(true); plot.setDomainGridlinePaint(Color.DARK_GRAY); plot.setRangeGridlinePaint(Color.DARK_GRAY); plot.setBackgroundPaint(new Color(224, 224, 224)); plot.setDataset(0, lineDataset); plot.setRenderer(0, lineRenderer); plot.setDomainAxis(0, mafvDomain); plot.setRangeAxis(0, mafgsRange); plot.mapDatasetToDomainAxis(0, 0); plot.mapDatasetToRangeAxis(0, 0); LegendTitle legend = new LegendTitle(plot.getRenderer()); legend.setItemFont(new Font("Arial", 0, 10)); legend.setPosition(RectangleEdge.TOP); chart.addLegend(legend); } catch (Exception e) { logger.error(e); } }
From source file:be.ac.ua.comp.scarletnebula.gui.windows.GUI.java
public GUI() { chooseLookAndFeel();//w w w . j a va2 s . c om setTitle("Scarlet Nebula"); setSize(700, 400); setDefaultCloseOperation(EXIT_ON_CLOSE); final ImageIcon icon = new ImageIcon(getClass().getResource("/images/icon48.png")); setIconImage(icon.getImage()); addToolbar(); final JPanel mainPanel = getMainPanel(); add(mainPanel); addMenubar(); setKeyboardAccelerators(); setLocationRelativeTo(null); setLocationByPlatform(true); setVisible(true); // Last but not least, we construct a cloudmanager object, which will // cause it to load all providers and thus servers. // We also register ourselves as an observer for linking and unlinking // servers so we can update the serverlist. CloudManager.get().addServerLinkUnlinkObserver(this); (new SwingWorkerWithThrobber<Object, Object>(newThrobber("Loading servers...")) { @Override protected Object doInBackground() throws Exception { try { CloudManager.get().loadAllLinkedServers(); // now start refreshing all servers if necessary for (final CloudProvider cloudprovider : CloudManager.get().getLinkedCloudProviders()) { { for (final Server server : cloudprovider.listLinkedServers()) { if (server.getStatus() == VmState.PENDING) { server.refreshUntilServerHasState(VmState.RUNNING); } if (server.getStatus() == VmState.REBOOTING) { server.refreshUntilServerHasState(VmState.RUNNING); } if (server.getStatus() == VmState.STOPPING) { server.refreshUntilServerHasState(VmState.TERMINATED); } } } } } catch (final Exception e) { log.error("Error while getting servers", e); } return null; } }).execute(); // If there are no linked cloudproviders, start the new provider wizard if (CloudManager.get().getLinkedCloudProviders().size() == 0) { final SwingWorker<Object, Object> welcomeWizardWorker = new SwingWorker<Object, Object>() { @Override protected Object doInBackground() throws Exception { new WelcomeWizard(GUI.this); return null; } }; welcomeWizardWorker.execute(); } }
From source file:com.moteiv.trawler.Trawler.java
public Trawler(String[] args) { init(args);// www.jav a2 s . c om // Install a different look and feel; specifically, the Windows look and feel try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); //"com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (InstantiationException e) { } catch (ClassNotFoundException e) { } catch (UnsupportedLookAndFeelException e) { } catch (IllegalAccessException e) { } jf = new JFrame("Trawler"); jf.setJMenuBar(getMainMenuBar()); g = new SparseGraph(); layout = new FRLayout(g); indexer = Indexer.newIndexer(g, 0); // layout.initialize(new Dimension(100, 100)); mif = new MoteInterface(g, Trawler.GROUPID, layout); uartDetect = new UartDetect(mif.getMoteIF()); Thread th = new Thread(uartDetect); th.start(); pr = new myPluggableRenderer(); vv = new VisualizationViewer(layout, pr); vv.init(); vv.setPickSupport(new ShapePickSupport()); vv.setBackground(Color.white); vv.setToolTipListener(new NodeTips(vv)); myVertexShapeFunction vsf = new myVertexShapeFunction(uartDetect); pr.setVertexShapeFunction(vsf); pr.setVertexIconFunction(vsf);//new myVertexShapeFunction()); m_vs = new VertexLabel(); java.awt.Font f = new java.awt.Font("Arial", Font.PLAIN, 12); pr.setEdgeFontFunction(new ConstantEdgeFontFunction(f)); pr.setVertexStringer(m_vs); m_es = new myEdgeLabel(); pr.setEdgeStringer(m_es); ((AbstractEdgeShapeFunction) pr.getEdgeShapeFunction()).setControlOffsetIncrement(-50.f); // pr.setVertexColorFunction(new myVertexColorFunction(Color.RED.darker().darker(), Color.RED, 500l)); pr.setEdgeStrokeFunction(new EdgeWeightStrokeFunction()); pr.setEdgeLabelClosenessFunction(new ConstantDirectionalEdgeValue(0.5, 0.5)); pr.setEdgePaintFunction(new myEdgeColorFunction()); scrollPane = new GraphZoomScrollPane(vv); jf.getContentPane().setLayout(new BoxLayout(jf.getContentPane(), BoxLayout.LINE_AXIS)); JTabbedPane pane = new JTabbedPane(); pane.addTab("Network Topology", scrollPane); pane.addTab("Sensor readings", createOscopePanel(mif.getMoteIF(), "ADC Readings", -33, -456, 300, 4100, "Time (seconds)", "ADC counts")); pane.addTab("Link Quality", createOscopePanel(mif.getMoteIF(), "LinkQualityPanel", -33, -15, 300, 135, "Time (seconds)", "Link Quality Indicator")); ImageIcon trawlerIcon = new ImageIcon(Trawler.class.getResource("images/trawler-icon.gif")); Image imageTrawler = trawlerIcon.getImage(); jf.getContentPane().add(pane); controlBoxFrame = new JFrame("Vizualization Control"); controlBoxFrame.getContentPane().add(getControls()); controlBoxFrame.setIconImage(imageTrawler); controlBoxFrame.pack(); // jf.getContentPane().add(getControls()); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); layout.initialize(vv.getSize()); layout.resize(vv.getSize()); layout.update(); loadPrefs(); GraphIO.loadGraph(g, layout, mif, Trawler.NODEFILE); // need this mouse model to keep the mouse clicks // aligned with the nodes DefaultModalGraphMouse gm = new DefaultModalGraphMouse(); gm.setMode(ModalGraphMouse.Mode.PICKING); vv.setGraphMouse(gm); jf.setIconImage(imageTrawler); jf.pack(); jf.show(); controlBoxFrame.setVisible(true); timer = new Timer(); timer.schedule(new UpdateTask(), 500, 500); }
From source file:de.quadrillenschule.azocamsyncd.gui.ExploreWifiSDPanel.java
private void updateSingleView() { try {/* w w w . j a v a 2 s . c o m*/ if (remotejTree.getSelectionPaths().length > 0) { TreePath tp = remotejTree.getSelectionPaths()[0]; String mynode = tp.getLastPathComponent().toString(); AZoFTPFile myaffilea = null; for (AZoFTPFile af : afs) { if (new String(af.dir + af.ftpFile.getName()).equals(mynode)) { myaffilea = af; // GlobalProperties gp=new GlobalProperties(); // gp.setProperty(GlobalProperties.CamSyncProperties.LATESTIMAGEPATH, af.dir+af.ftpFile.getName()); break; } } final AZoFTPFile myaffile = myaffilea; Thread imageUpdater = new Thread(new Runnable() { @Override public void run() { try { File localFile; localFile = localStorage.getLocalFile(myaffile); localFileNamejTextField1.setText(localFile.getAbsolutePath()); ImageIcon ii = new ImageIcon(localFile.toURI().toURL()); int mywidth = imagejLabel.getWidth(); int width = ii.getIconWidth(); int height = ii.getIconHeight(); if (width <= 0) { imagejLabel.setText("No image to view."); } else { imagejLabel.setText(""); } double factor = (double) height / (double) width; Image image = ii.getImage().getScaledInstance(mywidth, (int) ((double) mywidth * factor), Image.SCALE_FAST); imagejLabel.setIcon(new ImageIcon(image)); } catch (Exception ex) { imagejLabel.setText("No image to view."); } } }); imageUpdater.start(); } } catch (Exception e) { } }
From source file:edu.ku.brc.af.prefs.PrefsToolbar.java
/** * Loads a Section or grouping of Prefs. * @param sectionElement the section elemnent * @param altName the localized title/*from w w w .j a v a 2 s . c o m*/ */ protected void loadSectionPrefs(final Element sectionElement, final ResourceBundle resBundle) { RolloverCommand.setVertGap(2); //List<NavBoxButton> btns = new Vector<NavBoxButton>(); //int totalWidth = 0; try { List<?> prefs = sectionElement.selectNodes("pref"); //$NON-NLS-1$ //numPrefs = prefs.size(); for (Iterator<?> iterPrefs = prefs.iterator(); iterPrefs.hasNext();) { org.dom4j.Element pref = (org.dom4j.Element) iterPrefs.next(); String prefName = pref.attributeValue("name"); //$NON-NLS-1$ String prefTitle = pref.attributeValue("title"); //$NON-NLS-1$ String iconPath = pref.attributeValue("icon"); //$NON-NLS-1$ String panelClass = pref.attributeValue("panelClass"); //$NON-NLS-1$ String viewSetName = pref.attributeValue("viewsetname"); //$NON-NLS-1$ String viewName = pref.attributeValue("viewname"); //$NON-NLS-1$ String hContext = pref.attributeValue("help"); //$NON-NLS-1$ if (AppContextMgr.isSecurityOn()) { PermissionSettings perm = SecurityMgr.getInstance().getPermission("Prefs." + prefName); //PermissionSettings.dumpPermissions("Prefs: "+prefName, perm.getOptions()); if (!perm.canView()) // this means Enabled { continue; } } if (StringUtils.isNotEmpty(prefTitle) && StringUtils.isNotEmpty(iconPath) && StringUtils.isNotEmpty(panelClass)) { if (resBundle != null) { try { prefTitle = resBundle.getString(prefTitle); } catch (MissingResourceException ex) { log.error("Couldn't find key[" + prefTitle + "]"); edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(PrefsToolbar.class, ex); } } ImageIcon icon; if (iconPath.startsWith("http") || iconPath.startsWith("file")) //$NON-NLS-1$ //$NON-NLS-2$ { icon = new ImageIcon(new URL(iconPath)); } else { icon = IconManager.getImage(iconPath); } if (icon != null) { if (icon.getIconWidth() > iconSize || icon.getIconHeight() > iconSize) { icon = new ImageIcon( icon.getImage().getScaledInstance(iconSize, iconSize, Image.SCALE_SMOOTH)); } } if (icon == null) { log.error("Icon was created - path[" + iconPath + "]"); //$NON-NLS-1$ //$NON-NLS-2$ } NavBoxButton btn = new NavBoxButton(getResourceString(prefTitle), icon); btn.setOpaque(false); btn.setVerticalLayout(true); btn.setBorder(BorderFactory.createEmptyBorder(4, 4, 2, 4)); try { Class<?> panelClassObj = Class.forName(panelClass); Component comp = (Component) panelClassObj.newInstance(); if (comp instanceof PrefsPanelIFace) { PrefsPanelIFace prefPanel = (PrefsPanelIFace) comp; prefPanel.setName(prefName); prefPanel.setTitle(prefTitle); prefPanel.setHelpContext(hContext); if (!prefPanel.isOKToLoad() || (AppContextMgr.isSecurityOn() && !prefPanel.getPermissions().canView())) { continue; } prefPanel.setPrefsPanelMgr(prefsPanelMgr); } if (panelClassObj == GenericPrefsPanel.class) { if (StringUtils.isNotEmpty(viewSetName) && StringUtils.isNotEmpty(viewName)) { GenericPrefsPanel genericPrefsPanel = (GenericPrefsPanel) comp; genericPrefsPanel.createForm(viewSetName, viewName); } else { log.error( "ViewSetName[" + viewSetName + "] or ViewName[" + viewName + "] is empty!"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } } prefsPanelMgr.addPanel(prefTitle, comp); add(btn.getUIComponent()); } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(PrefsToolbar.class, ex); log.error(ex); // XXX FIXME ex.printStackTrace(); } btn.addActionListener(new ShowAction(prefTitle, btn)); } } if (getComponentCount() > 0) { prevBtn = (RolloverCommand) getComponent(0); prevBtn.setActive(true); } /*int aveWidth = totalWidth / btns.size(); for (NavBoxButton nbb : btns) { Dimension size = nbb.getPreferredSize(); if (size.width < aveWidth) { size.width = aveWidth; } nbb.setPreferredSize(size); nbb.setSize(size); } */ } catch (Exception ex) { ex.printStackTrace(); edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(PrefsToolbar.class, ex); throw new RuntimeException(ex); } finally { RolloverCommand.setVertGap(0); } }