List of usage examples for java.awt.image ImageObserver ImageObserver
ImageObserver
From source file:MainClass.java
public static void main(String[] args) { ImageObserver myObserver = new ImageObserver() { public boolean imageUpdate(Image image, int flags, int x, int y, int width, int height) { if ((flags & HEIGHT) != 0) System.out.println("Image height = " + height); if ((flags & WIDTH) != 0) System.out.println("Image width = " + width); if ((flags & FRAMEBITS) != 0) System.out.println("Another frame finished."); if ((flags & SOMEBITS) != 0) System.out.println("Image section :" + new Rectangle(x, y, width, height)); if ((flags & ALLBITS) != 0) System.out.println("Image finished!"); if ((flags & ABORT) != 0) System.out.println("Image load aborted..."); return true; }/* w w w . j a va2 s. com*/ }; Toolkit toolkit = Toolkit.getDefaultToolkit(); Image img = toolkit.getImage(args[0]); toolkit.prepareImage(img, -1, -1, myObserver); }
From source file:Main.java
static ImageIcon makeImageIcon(URL url, JComboBox combo, int row) { ImageIcon icon = new ImageIcon(url); icon.setImageObserver(new ImageObserver() { public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h) { if (combo.isShowing() && (infoflags & (FRAMEBITS | ALLBITS)) != 0) { if (combo.getSelectedIndex() == row) { combo.repaint();//from w ww .j a va 2 s .co m } BasicComboPopup p = (BasicComboPopup) combo.getAccessibleContext().getAccessibleChild(0); JList list = p.getList(); if (list.isShowing()) { list.repaint(list.getCellBounds(row, row)); } } return (infoflags & (ALLBITS | ABORT)) == 0; }; }); return icon; }
From source file:org.cloudml.ui.graph.Visu.java
public void createFrame() { final VisualizationViewer<Vertex, Edge> vv = v.getVisualisationViewer(); vv.getRenderContext().setVertexIconTransformer(new Transformer<Vertex, Icon>() { public Icon transform(final Vertex v) { return new Icon() { public int getIconHeight() { return 40; }// ww w . ja va 2s.c o m public int getIconWidth() { return 40; } public void paintIcon(java.awt.Component c, Graphics g, int x, int y) { ImageIcon img; if (v.getType() == "node") { img = new ImageIcon(this.getClass().getResource("/server.png")); } else if (v.getType() == "platform") { img = new ImageIcon(this.getClass().getResource("/dbms.png")); } else { img = new ImageIcon(this.getClass().getResource("/soft.png")); } ImageObserver io = new ImageObserver() { public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { // TODO Auto-generated method stub return false; } }; g.drawImage(img.getImage(), x, y, getIconHeight(), getIconWidth(), io); if (!vv.getPickedVertexState().isPicked(v)) { g.setColor(Color.black); } else { g.setColor(Color.red); properties.setModel(new CPIMTable(v)); runtimeProperties.setModel(new CPSMTable(v)); } g.drawString(v.getName(), x - 10, y + 50); } }; } }); // create a frame to hold the graph final JFrame frame = new JFrame(); Container content = frame.getContentPane(); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel, BorderLayout.CENTER); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final ModalGraphMouse gm = new DefaultModalGraphMouse<Integer, Number>(); vv.setGraphMouse(gm); 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 save = new JButton("save"); save.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(); int returnVal = fc.showDialog(frame, "save"); File result = fc.getSelectedFile(); JsonCodec codec = new JsonCodec(); OutputStream streamResult; try { streamResult = new FileOutputStream(result); codec.save(dmodel, streamResult); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); JButton saveImage = new JButton("save as image"); saveImage.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(); int returnVal = fc.showDialog(frame, "save"); File result = fc.getSelectedFile(); JsonCodec codec = new JsonCodec(); v.writeJPEGImage(result); } }); //WE NEED TO UPDATE THE FACADE AND THE GUI JButton load = new JButton("load"); load.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(); int returnVal = fc.showDialog(frame, "load"); File result = fc.getSelectedFile(); JsonCodec codec = new JsonCodec(); try { InputStream stream = new FileInputStream(result); Deployment model = (Deployment) codec.load(stream); dmodel = model; v.setDeploymentModel(dmodel); ArrayList<Vertex> V = v.drawFromDeploymentModel(); nodeTypes.removeAll(); nodeTypes.setModel(fillList()); properties.setModel(new CPIMTable(V.get(0))); runtimeProperties.setModel(new CPSMTable(V.get(0))); CommandFactory fcommand = new CommandFactory(); CloudMlCommand load = fcommand.loadDeployment(result.getPath()); cml.fireAndWait(load); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JButton deploy = new JButton("Deploy!"); deploy.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //cad.deploy(dmodel); System.out.println("deploy"); CommandFactory fcommand = new CommandFactory(); CloudMlCommand deploy = fcommand.deploy(); cml.fireAndWait(deploy); } }); //right panel JPanel intermediary = new JPanel(); intermediary.setLayout(new BoxLayout(intermediary, BoxLayout.PAGE_AXIS)); intermediary.setBorder(BorderFactory.createLineBorder(Color.black)); JLabel jlCPIM = new JLabel(); jlCPIM.setText("CPIM"); JLabel jlCPSM = new JLabel(); jlCPSM.setText("CPSM"); properties = new JTable(null); //properties.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); JTableHeader h = properties.getTableHeader(); JPanel props = new JPanel(); props.setLayout(new BorderLayout()); props.add(new JScrollPane(properties), BorderLayout.CENTER); props.add(h, BorderLayout.NORTH); runtimeProperties = new JTable(null); //runtimeProperties.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); JTableHeader h2 = runtimeProperties.getTableHeader(); JPanel runProps = new JPanel(); runProps.setLayout(new BorderLayout()); runProps.add(h2, BorderLayout.NORTH); runProps.add(new JScrollPane(runtimeProperties), BorderLayout.CENTER); intermediary.add(jlCPIM); intermediary.add(props); intermediary.add(jlCPSM); intermediary.add(runProps); content.add(intermediary, BorderLayout.EAST); //Left panel JPanel selection = new JPanel(); JLabel nodes = new JLabel(); nodes.setText("Types"); selection.setLayout(new BoxLayout(selection, BoxLayout.PAGE_AXIS)); nodeTypes = new JList(fillList()); nodeTypes.setLayoutOrientation(JList.VERTICAL); nodeTypes.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); nodeTypes.setVisibleRowCount(10); JScrollPane types = new JScrollPane(nodeTypes); types.setPreferredSize(new Dimension(150, 80)); selection.add(nodes); selection.add(types); content.add(selection, BorderLayout.WEST); ((DefaultModalGraphMouse<Integer, Number>) gm) .add(new MyEditingGraphMousePlugin(0, vv, v.getGraph(), nodeTypes, dmodel)); JPanel controls = new JPanel(); controls.add(plus); controls.add(minus); controls.add(save); controls.add(saveImage); controls.add(load); controls.add(deploy); controls.add(((DefaultModalGraphMouse<Integer, Number>) gm).getModeComboBox()); content.add(controls, BorderLayout.SOUTH); frame.pack(); frame.setVisible(true); }
From source file:org.jas.util.ImageUtils.java
public boolean is300Image(Image image) { int imageHeight = image.getHeight(new ImageObserver() { public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { return false; }//from w ww . j a va 2s.com }); log.info("Image height: " + imageHeight); return imageHeight == THREE_HUNDRED ? true : false; }