private JPanel createTargetPanel() { JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); _tarOffsetPane = new PatternPaneTargetOffset(_simg, _imgBtn.getFilename(), _imgBtn.getTargetOffset()); createMarginBox(p, _tarOffsetPane); p.add(Box.createVerticalStrut(5)); p.add(_tarOffsetPane.createControls()); p.add(Box.createVerticalStrut(5)); p.add(msgApplied[tabSequence]); p.doLayout(); return p; }
private boolean replaceWithImage(int startOff, int endOff, Pattern ptn) throws BadLocationException { Document doc = getDocument(); String imgStr = doc.getText(startOff, endOff - startOff); JComponent comp = null; if (ptn == patPatternStr || ptn == patPngStr) { if (pref.getPrefMoreImageThumbs()) { comp = EditorPatternButton.createFromString(this, imgStr, null); } else { comp = EditorPatternLabel.labelFromString(this, imgStr); } } else if (ptn == patRegionStr) { if (pref.getPrefMoreImageThumbs()) { comp = EditorRegionButton.createFromString(this, imgStr); } else { comp = EditorRegionLabel.labelFromString(this, imgStr); } } else if (ptn == patCaptureBtn) { comp = EditorPatternLabel.labelFromString(this, ""); } if (comp != null) { this.select(startOff, endOff); this.insertComponent(comp); return true; } return false; }
private void init(EditorPatternButton imgBtn, boolean exact, float similarity, int numMatches) { setTitle(_I("winPatternSettings")); setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); _imgBtn = imgBtn; Point pos = imgBtn.getLocationOnScreen(); Debug.log(4, "pattern window: " + pos); setLocation(pos.x + imgBtn.getWidth(), pos.y); takeScreenshot(); Container c = getContentPane(); c.setLayout(new BorderLayout()); tabPane = new JTabbedPane(); tabPane.setPreferredSize(new Dimension(790, 700)); msgApplied = new JLabel[tabMax]; msgApplied[tabSequence] = new JLabel("..."); paneNaming = new PatternPaneNaming(_imgBtn, msgApplied[tabSequence++]); tabPane.addTab(_I("tabNaming"), paneNaming); msgApplied[tabSequence] = new JLabel("..."); panePreview = createPreviewPanel(); tabSequence++; tabPane.addTab(_I("tabMatchingPreview"), panePreview); msgApplied[tabSequence] = new JLabel("..."); paneTarget = createTargetPanel(); tabSequence++; tabPane.addTab(_I("tabTargetOffset"), paneTarget); c.add(tabPane, BorderLayout.CENTER); c.add(createButtons(), BorderLayout.SOUTH); c.doLayout(); pack(); try { _screenshot.setParameters(_imgBtn.getFilename(), exact, similarity, numMatches); } catch (Exception e) { Debug.error(me + "Problem while setting up pattern pane\n%s", e.getMessage()); } setDirty(false); setVisible(true); }
private void actionPerformedUpdates(Window _parent) { boolean tempDirty = isDirty(); if (paneNaming.isDirty()) { String filename = paneNaming.getAbsolutePath(); String oldFilename = _imgBtn.getFilename(); if (FileManager.exists(filename)) { String name = FileManager.getName(filename); int ret = JOptionPane.showConfirmDialog( _parent, SikuliIDEI18N._I("msgFileExists", name), SikuliIDEI18N._I("dlgFileExists"), JOptionPane.WARNING_MESSAGE, JOptionPane.YES_NO_OPTION); if (ret != JOptionPane.YES_OPTION) { return; } } try { FileManager.xcopy(oldFilename, filename, null); (new File(oldFilename)).delete(); _imgBtn.setFilename(filename); } catch (IOException ioe) { Debug.error("renaming failed: " + oldFilename + " " + filename); Debug.error(ioe.getMessage()); } paneNaming.updateFilename(); addDirty(true); } addDirty( _imgBtn.setParameters( _screenshot.isExact(), _screenshot.getSimilarity(), _screenshot.getNumMatches())); addDirty(_imgBtn.setTargetOffset(_tarOffsetPane.getTargetOffset())); Debug.log(2, "update: " + _imgBtn.toString()); if (isDirty() || tempDirty) { int i = _imgBtn.getWindow().getTabbedPane().getSelectedIndex(); _imgBtn.getWindow().setMessageApplied(i, true); _imgBtn.repaint(); } }
public void close() { _simg = null; _imgBtn.resetWindow(); }
private void init(EditorPatternButton imgBtn, JLabel msgApplied) { _imgBtn = imgBtn; JLabel lblPath = new JLabel(_I("lblPath")); JLabel lblFilename = new JLabel(_I("lblFilename")); String filename = _imgBtn.getFilename(); File f = new File(filename); String fullpath = f.getParent(); filename = getFilenameWithoutExt(f); _oldFilename = filename; BufferedImage thumb = _imgBtn.createThumbnailImage(THUMB_MAX_HEIGHT); Border border = LineBorder.createGrayLineBorder(); JLabel lblThumb = new JLabel(new ImageIcon(thumb)); lblThumb.setBorder(border); _txtPath = new JTextField(fullpath, TXT_FILENAME_LENGTH); _txtPath.setEditable(false); _txtPath.setEnabled(false); String[] candidates = new String[] {filename}; // <editor-fold defaultstate="collapsed" desc="OCR --- not used"> /* String ocrText = getFilenameFromImage(thumb); if(ocrText.length()>0 && !ocrText.equals(filename)) candidates = new String[] {filename, ocrText}; */ // </editor-fold> _txtFilename = new AutoCompleteCombo(candidates); _txtFileExt = new JTextField(getFileExt(f), TXT_FILE_EXT_LENGTH); _txtFileExt.setEditable(false); _txtFileExt.setEnabled(false); GridBagConstraints c = new GridBagConstraints(); c.gridy = 0; c.insets = new Insets(100, 0, 0, 0); this.add(new JLabel(""), c); c = new GridBagConstraints(); c.fill = 0; c.gridwidth = 3; c.gridy = 1; c.insets = new Insets(0, 10, 20, 10); this.add(lblThumb, c); c = new GridBagConstraints(); c.fill = 1; c.gridy = 2; this.add(lblPath, c); c.gridx = 1; c.gridwidth = 2; this.add(_txtPath, c); c = new GridBagConstraints(); c.gridy = 3; c.fill = 0; this.add(lblFilename, c); this.add(_txtFilename, c); this.add(_txtFileExt, c); c = new GridBagConstraints(); c.gridy = 4; c.gridx = 1; c.insets = new Insets(200, 0, 0, 0); this.add(msgApplied, c); }