List of usage examples for javax.swing ImageIcon getImage
@Transient
public Image getImage()
Image
. From source file:edu.ku.brc.specify.tasks.StartUpTask.java
@Override public JPanel createSplashPanel() { AppPreferences ap = AppPreferences.getLocalPrefs(); int width = ap.getInt("Startup.Image.width", 400); int height = ap.getInt("Startup.Image.height", 700); Image img = null;//from ww w .j a va2 s . c o m ImageIcon bgImg = IconManager.getIcon(SPECIFY_SPLASH); if (bgImg.getIconWidth() > width || bgImg.getIconHeight() > height) { img = GraphicsUtils.getScaledImage(bgImg, width, height, true); } else { img = bgImg.getImage(); } JPanel splashPanel = new JPanel(new BorderLayout()); //splashPanel.setBackground(Color.WHITE); splashPanel.setOpaque(false); splashPanel.add(new JLabel(new ImageIcon(img)), BorderLayout.CENTER); return splashPanel; }
From source file:ffx.Main.java
/** * Main does some window initializations. * * @param commandLineFile a {@link java.io.File} object. * @param argList a {@link java.util.List} object. *//* ww w. jav a2 s. c o m*/ public Main(File commandLineFile, List<String> argList) { super("Force Field X"); // Start the clock. stopWatch.start(); setVisible(false); // Create the MainPanel and MainMenu, then add them to the JFrame java.awt.Toolkit.getDefaultToolkit().setDynamicLayout(true); mainPanel = new MainPanel(this); logHandler.setMainPanel(mainPanel); add(mainPanel); mainPanel.initialize(); setJMenuBar(mainPanel.getMainMenu()); // Set the Title and Icon setTitle("Force Field X"); URL iconURL = getClass().getClassLoader().getResource("ffx/ui/icons/icon64.png"); ImageIcon icon = new ImageIcon(iconURL); setIconImage(icon.getImage()); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { if (mainPanel != null) { mainPanel.exit(); } System.exit(0); } }); // This is a hack to get GraphicsCanvis to initialize on some // platform/Java3D combinations. mainPanel.setPanel(MainPanel.KEYWORDS); setVisible(true); mainPanel.setPanel(MainPanel.GRAPHICS); // Mac OS X specific features that help Force Field X look native // on Macs. This needs to be done after the MainPanel is created. if (SystemUtils.IS_OS_MAC_OSX) { osxAdapter = new OSXAdapter(mainPanel); } // Finally, open the supplied file if necessary. if (commandLineFile != null && !commandLineFile.exists()) { /** * See if the commandLineFile is an embedded script. */ String name = commandLineFile.getName(); name = name.replace('.', '/'); String pathName = "ffx/scripts/" + name; ClassLoader loader = getClass().getClassLoader(); URL embeddedScript = loader.getResource(pathName + ".ffx"); if (embeddedScript == null) { embeddedScript = loader.getResource(pathName + ".groovy"); } if (embeddedScript != null) { try { commandLineFile = new File(FFXClassLoader.copyInputStreamToTmpFile(embeddedScript.openStream(), commandLineFile.getName(), ".ffx")); } catch (Exception e) { logger.info(String.format(" The embedded script %s could not be extracted.", embeddedScript)); } } } if (commandLineFile != null) { if (commandLineFile.exists()) { mainPanel.getModelingShell().setArgList(argList); mainPanel.open(commandLineFile, null); } else { logger.warning(format("%s was not found.", commandLineFile.toString())); } } if (logger.isLoggable(Level.FINE)) { StringBuilder sb = new StringBuilder(); sb.append(format("\n Start-up Time (msec): %s.", stopWatch.getTime())); Runtime runtime = Runtime.getRuntime(); runtime.runFinalization(); runtime.gc(); long occupiedMemory = runtime.totalMemory() - runtime.freeMemory(); long KB = 1024; sb.append(format("\n In-Use Memory (Kb): %d", occupiedMemory / KB)); sb.append(format("\n Free Memory (Kb): %d", runtime.freeMemory() / KB)); sb.append(format("\n Total Memory (Kb): %d", runtime.totalMemory() / KB)); logger.fine(sb.toString()); } }
From source file:edu.ku.brc.ui.GraphicsUtils.java
/** * Gets a scaled icon and if it doesn't exist it creates one and scales it * @param icon image to be scaled//from w w w .j a va 2 s.c om * @param iconSize the icon size (Std) * @param scaledIconSize the new scaled size in pixels * @return the scaled icon */ public static Image getScaledImage(final ImageIcon icon, final int newMaxWidth, final int newMaxHeight, final boolean maintainRatio) { if (icon != null) { int dstWidth = newMaxWidth; int dstHeight = newMaxHeight; int srcWidth = icon.getIconWidth(); int srcHeight = icon.getIconHeight(); if ((dstWidth < 0) || (dstHeight < 0)) { //image is nonstd, revert to original size dstWidth = icon.getIconWidth(); dstHeight = icon.getIconHeight(); } if (maintainRatio) { double longSideForSource = Math.max(srcWidth, srcHeight); double longSideForDest = Math.max(dstWidth, dstHeight); double multiplier = longSideForDest / longSideForSource; dstWidth = (int) (srcWidth * multiplier); dstHeight = (int) (srcHeight * multiplier); } Image imgMemory = icon.getImage(); //make sure all pixels in the image were loaded imgMemory = new ImageIcon(imgMemory).getImage(); BufferedImage thumbImage = new BufferedImage(dstWidth, dstHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics2D = thumbImage.createGraphics(); graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); graphics2D.drawImage(imgMemory, 0, 0, dstWidth, dstHeight, 0, 0, srcWidth, srcHeight, null); graphics2D.dispose(); return thumbImage; } return null; }
From source file:com.net2plan.gui.GUINet2Plan.java
private void start() { setExtendedState(JFrame.MAXIMIZED_BOTH); setMinimumSize(new Dimension(800, 600)); itemObject = new DualHashBidiMap<JMenuItem, Object>(); URL iconURL = GUINet2Plan.class.getResource("/resources/gui/icon.png"); ImageIcon icon = new ImageIcon(iconURL); setIconImage(icon.getImage()); setTitle("Net2Plan"); setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); addWindowListener(CLOSE_NET2PLAN);/*from w ww .j a v a 2 s . c o m*/ getContentPane().setLayout(new MigLayout("insets 0 0 0 0", "[grow]", "[grow]")); container = new JPanel(new MigLayout("", "[]", "[]")); container.setBorder(new LineBorder(Color.BLACK)); container.setLayout(new MigLayout("fill")); getContentPane().add(container, "grow"); /* Create menu bar */ menu = new JMenuBar(); setJMenuBar(menu); /* File menu */ JMenu file = new JMenu("File"); file.setMnemonic('F'); menu.add(file); optionsItem = new JMenuItem("Options"); optionsItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.ALT_DOWN_MASK)); optionsItem.addActionListener(this); file.add(optionsItem); classPathEditorItem = new JMenuItem("Classpath editor"); classPathEditorItem.addActionListener(this); file.add(classPathEditorItem); errorConsoleItem = new JMenuItem("Show Java console"); errorConsoleItem.addActionListener(this); errorConsoleItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F12, InputEvent.ALT_DOWN_MASK)); file.add(errorConsoleItem); exitItem = new JMenuItem("Exit"); exitItem.addActionListener(this); exitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.ALT_DOWN_MASK)); file.add(exitItem); /* Help menu */ JMenu help = new JMenu("Help"); help.setMnemonic('H'); menu.add(help); aboutItem = new JMenuItem("About"); aboutItem.addActionListener(this); help.add(aboutItem); itemObject.put(aboutItem, showAbout()); helpItem = new JMenuItem("User's guide"); helpItem.addActionListener(this); helpItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, KeyEvent.VK_UNDEFINED)); help.add(helpItem); javadocItem = new JMenuItem("Library API Javadoc"); javadocItem.addActionListener(this); help.add(javadocItem); javadocExamplesItem = new JMenuItem("Built-in Examples Javadoc"); javadocExamplesItem.addActionListener(this); help.add(javadocExamplesItem); keyCombinationItem = new JMenuItem("Show tool key combinations"); keyCombinationItem.addActionListener(this); keyCombinationItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_K, KeyEvent.ALT_DOWN_MASK)); help.add(keyCombinationItem); usedKeyStrokes = new LinkedHashSet<KeyStroke>(); refreshMenu(); container.add(showAbout(), "align center"); container.revalidate(); new JFileChooser(); /* Do not remove! It is used to avoid slow JFileChooser first-time loading once Net2Plan is shown to the user */ setVisible(true); }
From source file:ds.monte.carlo.Application.java
public Application() { initComponents();/*from w w w .j ava 2 s . c o m*/ initProgressBar(); this.setTitle("Monte Carlo"); ImageIcon img = new ImageIcon("img.png"); this.setIconImage(img.getImage()); numberOfReplications = 1000; initSeed = 0; jLabel3.setVisible(false); }
From source file:ds.monte.carlo.Application.java
private void jLabel4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel4MouseClicked ImageIcon img = new ImageIcon("go.png"); this.setIconImage(img.getImage()); monteCarlo = new Simulation(numberOfReplications, initSeed); monteCarlo.addPropertyChangeListener(this); System.out.println("Simulacia vytvorena"); try {//from w w w . j a va 2 s . c om monteCarlo.execute(); } catch (Exception ex) { Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:ds.monte.carlo.Application.java
@Override public void propertyChange(PropertyChangeEvent evt) { if ("progress".equals(evt.getPropertyName())) { int progress = (Integer) evt.getNewValue(); jProgressBar1.setValue(progress); if (progress == 100) { createFrequencyGraph(monteCarlo.getDictionary()); createGrowthGraph(monteCarlo.getGrowthMap()); createLengthGraph(monteCarlo.findProbability()); ImageIcon img = new ImageIcon("img.png"); this.setIconImage(img.getImage()); jLabel13.setText(((double) monteCarlo.getSuccessful() / numberOfReplications) * 100 + "%"); jLabel16.setText(monteCarlo.getAvg() + ""); jLabel18.setText(monteCarlo.getP80() + ""); }//ww w. j a v a 2 s .com } }
From source file:gg.msn.ui.panel.MainPanel.java
@Override public void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g; super.paintComponent(g2d); g2d.setRenderingHints(/*from ww w. ja v a 2 s. co m*/ new RenderingHints(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR)); try { ImageIcon icon = ThemeManager.getTheme().get(ThemeManager.MAIN_BACKGROUND); if (icon != null) { Image image = icon.getImage(); g2d.drawImage(image, 0, 0, getWidth(), getHeight(), this); } else { log.warn("image " + icon.getDescription() + " not Found"); } icon = ThemeManager.getTheme().get(ThemeManager.MAIN_IMAGE); if (icon != null) { Image cartel = icon.getImage(); g2d.drawImage(cartel, 0 - cartel.getWidth(this) / 10, getHeight() - cartel.getHeight(this), this); } else { log.warn("image " + icon.getDescription() + " not Found"); } } catch (Exception e) { // log.error(e); } }
From source file:bigdata.explorer.nutch.grapview.WebGraphZoomScrollPane.java
/** * create an instance of a simple graph with controls to * demo the zoom features./*from www. j a v a2 s . c o m*/ * */ public WebGraphZoomScrollPane() throws IOException { // create a simple graph for the demo graph = NutchGraphLoader.loadFullGraph("/home/kamir/ANALYSIS/Nutch/YellowMED_CORE"); ImageIcon sandstoneIcon = null; String imageLocation = "/images/Sandstone.jpg"; try { sandstoneIcon = new ImageIcon(getClass().getResource(imageLocation)); } catch (Exception ex) { System.err.println("Can't load \"" + imageLocation + "\""); } final ImageIcon icon = sandstoneIcon; vv = new VisualizationViewer<String, Number>(new KKLayout<String, Number>(graph)); if (icon != null) { vv.addPreRenderPaintable(new VisualizationViewer.Paintable() { public void paint(Graphics g) { Dimension d = vv.getSize(); g.drawImage(icon.getImage(), 0, 0, d.width, d.height, vv); } public boolean useTransform() { return false; } }); } vv.addPostRenderPaintable(new VisualizationViewer.Paintable() { int x; int y; Font font; FontMetrics metrics; int swidth; int sheight; String str = "WebGraph Zoomer : Version 1.0.0"; public void paint(Graphics g) { Dimension d = vv.getSize(); if (font == null) { font = new Font(g.getFont().getName(), Font.BOLD, 30); metrics = g.getFontMetrics(font); swidth = metrics.stringWidth(str); sheight = metrics.getMaxAscent() + metrics.getMaxDescent(); x = (d.width - swidth) / 2; y = (int) (d.height - sheight * 1.5); } g.setFont(font); Color oldColor = g.getColor(); g.setColor(Color.lightGray); g.drawString(str, x, y); g.setColor(oldColor); } public boolean useTransform() { return false; } }); vv.addGraphMouseListener(new TestGraphMouseListener<String>()); vv.getRenderer().setVertexRenderer(new GradientVertexRenderer<String, Number>(Color.white, Color.red, Color.white, Color.blue, vv.getPickedVertexState(), false)); vv.getRenderContext().setEdgeDrawPaintTransformer(new ConstantTransformer(Color.lightGray)); vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray)); vv.getRenderContext().setArrowDrawPaintTransformer(new ConstantTransformer(Color.lightGray)); // add my listeners for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller<String>()); vv.setEdgeToolTipTransformer(new Transformer<Number, String>() { public String transform(Number edge) { return "E" + graph.getEndpoints(edge).toString(); } }); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<String>()); vv.getRenderer().getVertexLabelRenderer().setPositioner(new InsidePositioner()); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.AUTO); vv.setForeground(Color.lightGray); // create a frome to hold the graph final JFrame frame = new JFrame(); Container content = frame.getContentPane(); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final AbstractModalGraphMouse graphMouse = new DefaultModalGraphMouse<String, Number>(); vv.setGraphMouse(graphMouse); vv.addKeyListener(graphMouse.getModeKeyListener()); vv.setToolTipText("<html><center>Type 'p' for Pick mode<p>Type 't' for Transform mode"); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JButton reset = new JButton("reset"); reset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).setToIdentity(); vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW).setToIdentity(); } }); JPanel controls = new JPanel(); controls.add(plus); controls.add(minus); controls.add(reset); content.add(controls, BorderLayout.SOUTH); frame.pack(); frame.setVisible(true); }
From source file:com.floreantpos.main.SetUpWindow.java
public SetUpWindow() throws HeadlessException { setLookAndFeel();//from w ww. j av a2 s.c o m ImageIcon applicationIcon = new ImageIcon(getClass().getResource("/icons/icon.png")); //$NON-NLS-1$ setIconImage(applicationIcon.getImage()); initUI(); setFieldValues(); addUIListeners(); updateView(); }