Ok, I searched and searched for searches, and that made me mad. (note that it started as a code from the University).
Any help would be appreciated by weight! Since I seem to have a mental block when it comes to java graphics: (.
The problem is marking the image, but I am having problems with half the lost image for various reasons, if I do not move around the frame and then return. Similarly, if I try to remove the βtagsβ that are written in BufferedImage, I need to navigate through the Jframe to see the result.
Finally, when a JOptionPane appears to request a label name, it does this when closing:
receiving image for publication https://docs.google.com/document/d/1I5rFH23a75IHB6twTu1dPRwmRt-By1sIUvDvI6FE_OY/edit
package hci; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class LabelToolGUI extends JPanel implements ActionListener { JButton newButton = new JButton("New"); JButton deleteButton = new JButton("Delete"); JButton editButton = new JButton("Edit"); JButton undoButton = new JButton("Undo"); JComboBox labelsBox = new JComboBox(); String saveIcon = "./images/icons/save.jpg"; String deleteIcon = "./images/icons/delete.jpg"; String openIcon = "./images/icons/open.jpg"; String newIcon = "./images/icons/new.jpg"; String helpIcon = "./images/icons/help.jpg"; String labelsIcon = "./images/icons/help.jpg"; String fname = ""; String fnameURL = ""; public LabelToolGUI() { super(); newButton.addActionListener(this); deleteButton.addActionListener(this); editButton.addActionListener(this); undoButton.addActionListener(this); setLayout(new BorderLayout()); setBorder(BorderFactory.createTitledBorder("Label tools")); add(newButton, BorderLayout.WEST); add(deleteButton, BorderLayout.EAST); add(editButton, BorderLayout.CENTER); add(labelsBox, BorderLayout.NORTH); add(undoButton, BorderLayout.SOUTH); } @Override public void actionPerformed(ActionEvent e) { Object src = e.getSource(); if(src == newButton) { String labelName = JOptionPane.showInputDialog("Please input a value"); ImageLabeller.addNewPolygon(labelName); labelsBox.addItem(labelName); } else if(src == deleteButton) { String toDelete = labelsBox.getSelectedItem().toString(); System.out.println("Deleting " + toDelete); labelsBox.removeItem(labelsBox.getSelectedItem()); ImageLabeller.removeLabel(toDelete); } else if(src == undoButton) { ImageLabeller.undo(); ImageLabeller.imagePanel.repaint(); } } }
package hci; import javax.swing.*; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; public class ImageLabeller extends JFrame implements ActionListener { private static final long serialVersionUID = 1L; JPanel appPanel = null; JPanel toolboxPanel = null; static ImagePanel imagePanel = null; public static void addNewPolygon(String labelName) { imagePanel.addNewPolygon(labelName); } public static void removeLabel(String labelName) { LabelHandler.deleteLabel(labelName); } public static void undo() { imagePanel.currentLabel.removeLast(); } public void setupGUI(String imageFilename) throws Exception { this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent event) {
package hci; import javax.imageio.ImageIO; import javax.swing.JPanel; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.image.BufferedImage; import java.io.File; import java.util.ArrayList; import hci.utils.*; public class ImagePanel extends JPanel implements MouseListener { private static final long serialVersionUID = 1L; BufferedImage image = null; Label currentLabel = null; public ImagePanel() { currentLabel = new Label(); this.setVisible(true); Dimension panelSize = new Dimension(800, 600); this.setSize(panelSize); this.setMinimumSize(panelSize); this.setPreferredSize(panelSize); this.setMaximumSize(panelSize); addMouseListener(this); } public ImagePanel(String imageName) throws Exception{ this(); image = ImageIO.read(new File(imageName)); if (image.getWidth() > 800 || image.getHeight() > 600) { int newWidth = image.getWidth() > 800 ? 800 : (image.getWidth() * 600)/image.getHeight(); int newHeight = image.getHeight() > 600 ? 600 : (image.getHeight() * 800)/image.getWidth(); System.out.println("SCALING TO " + newWidth + "x" + newHeight ); Image scaledImage = image.getScaledInstance(newWidth, newHeight, Image.SCALE_FAST); image = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_RGB); image.getGraphics().drawImage(scaledImage, 0, 0, this); } } public void ShowImage() { Graphics g = this.getGraphics(); if (image != null) { g.drawImage(image, 0, 0, null); } } public void paintComponent(Graphics g) { super.paintComponent(g);