List of usage examples for javax.swing JLabel setBounds
public void setBounds(int x, int y, int width, int height)
From source file:App.java
/** * Initialize the contents of the frame. */// w ww .j a v a 2 s . co m private void initialize() { frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(1000, 750); frame.getContentPane().setLayout(null); FileNameExtensionFilter filter = new FileNameExtensionFilter("Image files", "jpg", "jpeg", "png"); fc = new JFileChooser(); fc.setFileFilter(filter); frame.getContentPane().add(fc); stepOne = new JLabel(""); stepOne.setToolTipText("here comes something"); stepOne.setIcon(new ImageIcon("img/stepOne.png")); stepOne.setBounds(266, -4, 67, 49); frame.getContentPane().add(stepOne); btnBrowse = new JButton("Browse"); btnBrowse.setBounds(66, 6, 117, 29); frame.getContentPane().add(btnBrowse); btnTurnWebcamOn = new JButton("Take a picture with webcam"); btnTurnWebcamOn.setBounds(66, 34, 212, 29); frame.getContentPane().add(btnTurnWebcamOn); JButton btnTakePictureWithWebcam = new JButton("Take a picture"); btnTakePictureWithWebcam.setBounds(430, 324, 117, 29); frame.getContentPane().add(btnTakePictureWithWebcam); btnTakePictureWithWebcam.setVisible(false); JButton btnCancel = new JButton("Cancel"); btnCancel.setBounds(542, 324, 117, 29); frame.getContentPane().add(btnCancel); btnCancel.setVisible(false); JButton btnSaveImage = new JButton("Save image"); btnSaveImage.setBounds(497, 357, 117, 29); frame.getContentPane().add(btnSaveImage); btnSaveImage.setVisible(false); urlField = new JTextField(); urlField.setBounds(66, 67, 220, 26); frame.getContentPane().add(urlField); urlField.setColumns(10); originalImageLabel = new JLabel(); originalImageLabel.setHorizontalAlignment(SwingConstants.CENTER); originalImageLabel.setBounds(33, 98, 300, 300); frame.getContentPane().add(originalImageLabel); stepTwo = new JLabel(""); stepTwo.setToolTipText("here comes something else"); stepTwo.setIcon(new ImageIcon("img/stepTwo.png")); stepTwo.setBounds(266, 413, 67, 49); frame.getContentPane().add(stepTwo); btnAnalyse = new JButton("Analyse image"); btnAnalyse.setBounds(68, 423, 196, 29); frame.getContentPane().add(btnAnalyse); tagsField = new JTextArea(); tagsField.setBounds(23, 479, 102, 89); tagsField.setLineWrap(true); tagsField.setWrapStyleWord(true); frame.getContentPane().add(tagsField); tagsField.setColumns(10); lblTags = new JLabel("Tags:"); lblTags.setBounds(46, 451, 61, 16); frame.getContentPane().add(lblTags); descriptionField = new JTextArea(); descriptionField.setLineWrap(true); descriptionField.setWrapStyleWord(true); descriptionField.setBounds(137, 479, 187, 89); frame.getContentPane().add(descriptionField); descriptionField.setColumns(10); lblDescription = new JLabel("Description:"); lblDescription.setBounds(163, 451, 77, 16); frame.getContentPane().add(lblDescription); stepThree = new JLabel(""); stepThree.setToolTipText("here comes something different"); stepThree.setIcon(new ImageIcon("img/stepThree.png")); stepThree.setBounds(266, 685, 67, 49); frame.getContentPane().add(stepThree); JLabel lblImageType = new JLabel("Image type"); lblImageType.setBounds(23, 580, 102, 16); frame.getContentPane().add(lblImageType); String[] imageTypes = { "unspecified", "AnimategGif", "Clipart", "Line", "Photo" }; JComboBox imageTypeBox = new JComboBox(imageTypes); imageTypeBox.setBounds(137, 580, 187, 23); frame.getContentPane().add(imageTypeBox); JLabel lblSizeType = new JLabel("Size"); lblSizeType.setBounds(23, 608, 102, 16); frame.getContentPane().add(lblSizeType); String[] sizeTypes = { "unspecified", "Small", "Medium", "Large", "Wallpaper" }; JComboBox sizeBox = new JComboBox(sizeTypes); sizeBox.setBounds(137, 608, 187, 23); frame.getContentPane().add(sizeBox); JLabel lblLicenseType = new JLabel("License"); lblLicenseType.setBounds(23, 636, 102, 16); frame.getContentPane().add(lblLicenseType); String[] licenseTypes = { "unspecified", "Public", "Share", "ShareCommercially", "Modify" }; JComboBox licenseBox = new JComboBox(licenseTypes); licenseBox.setBounds(137, 636, 187, 23); frame.getContentPane().add(licenseBox); JLabel lblSafeSearchType = new JLabel("Safe search"); lblSafeSearchType.setBounds(23, 664, 102, 16); frame.getContentPane().add(lblSafeSearchType); String[] safeSearchTypes = { "Strict", "Moderate", "Off" }; JComboBox safeSearchBox = new JComboBox(safeSearchTypes); safeSearchBox.setBounds(137, 664, 187, 23); frame.getContentPane().add(safeSearchBox); btnSearchForSimilar = new JButton("Search for similar images"); btnSearchForSimilar.setVisible(true); btnSearchForSimilar.setBounds(66, 695, 189, 29); frame.getContentPane().add(btnSearchForSimilar); // label to try urls to display images, not shown on the main frame labelTryLinks = new JLabel(); labelTryLinks.setBounds(0, 0, 100, 100); foundImagesLabel1 = new JLabel(); foundImagesLabel1.setHorizontalAlignment(SwingConstants.CENTER); foundImagesLabel1.setBounds(400, 49, 250, 250); frame.getContentPane().add(foundImagesLabel1); foundImagesLabel2 = new JLabel(); foundImagesLabel2.setHorizontalAlignment(SwingConstants.CENTER); foundImagesLabel2.setBounds(400, 313, 250, 250); frame.getContentPane().add(foundImagesLabel2); foundImagesLabel3 = new JLabel(); foundImagesLabel3.setHorizontalAlignment(SwingConstants.CENTER); foundImagesLabel3.setBounds(673, 49, 250, 250); frame.getContentPane().add(foundImagesLabel3); foundImagesLabel4 = new JLabel(); foundImagesLabel4.setHorizontalAlignment(SwingConstants.CENTER); foundImagesLabel4.setBounds(673, 313, 250, 250); frame.getContentPane().add(foundImagesLabel4); progressBar = new JProgressBar(); progressBar.setIndeterminate(true); progressBar.setStringPainted(true); progressBar.setBounds(440, 602, 440, 29); Border border = BorderFactory .createTitledBorder("We are checking every image, pixel by pixel, it may take a while..."); progressBar.setBorder(border); frame.getContentPane().add(progressBar); progressBar.setVisible(false); btnHelp = new JButton(""); btnHelp.setBorderPainted(false); ImageIcon btnIcon = new ImageIcon("img/helpRed.png"); btnHelp.setIcon(btnIcon); btnHelp.setBounds(917, 4, 77, 59); frame.getContentPane().add(btnHelp); // all action listeners btnBrowse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (fc.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) { openFilechooser(); } } }); btnTurnWebcamOn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setAllFoundImagesLabelsAndPreviewsToNull(); btnTakePictureWithWebcam.setVisible(true); btnCancel.setVisible(true); turnCameraOn(); } }); btnTakePictureWithWebcam.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { btnSaveImage.setVisible(true); // take a photo with web camera imageWebcam = webcam.getImage(); originalImage = imageWebcam; // to mirror the image we create a temporary file, flip it // horizontally and then delete // get user's name to store file in the user directory String user = System.getProperty("user.home"); String fileName = user + "/webCamPhoto.jpg"; File newFile = new File(fileName); try { ImageIO.write(originalImage, "jpg", newFile); } catch (IOException e1) { e1.printStackTrace(); } try { originalImage = (BufferedImage) ImageIO.read(newFile); } catch (IOException e1) { e1.printStackTrace(); } newFile.delete(); originalImage = mirrorImage(originalImage); icon = scaleBufferedImage(originalImage, originalImageLabel); originalImageLabel.setIcon(icon); } }); btnSaveImage.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) { try { file = fc.getSelectedFile(); File output = new File(file.toString()); // check if image already exists if (output.exists()) { int response = JOptionPane.showConfirmDialog(null, // "Do you want to replace the existing file?", // "Confirm", JOptionPane.YES_NO_OPTION, // JOptionPane.QUESTION_MESSAGE); if (response != JOptionPane.YES_OPTION) { return; } } ImageIO.write(toBufferedImage(originalImage), "jpg", output); System.out.println("Your image has been saved in the folder " + file.getPath()); } catch (IOException e1) { e1.printStackTrace(); } } } }); btnCancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { btnTakePictureWithWebcam.setVisible(false); btnCancel.setVisible(false); btnSaveImage.setVisible(false); webcam.close(); panel.setVisible(false); } }); urlField.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (urlField.getText().length() > 0) { String linkNew = urlField.getText(); getImageFromHttp(linkNew, originalImageLabel); originalImage = imageResponses; } } }); btnAnalyse.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Token computerVisionToken = new Token(); String computerVisionTokenFileName = "APIToken.txt"; try { computerVisionImageToken = computerVisionToken.getApiToken(computerVisionTokenFileName); try { analyse(); } catch (NullPointerException e1) { // if user clicks on "analyze" button without uploading // image or posts a broken link JOptionPane.showMessageDialog(null, "Please choose an image"); e1.printStackTrace(); } } catch (NullPointerException e1) { e1.printStackTrace(); } } }); btnSearchForSimilar.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // clear labels in case there were results of previous search setAllFoundImagesLabelsAndPreviewsToNull(); System.out.println("=========================================="); System.out.println("new search"); System.out.println("=========================================="); Token bingImageToken = new Token(); String bingImageTokenFileName = "SearchApiToken.txt"; bingToken = bingImageToken.getApiToken(bingImageTokenFileName); // in case user edited description or tags, update it and // replace new line character, spaces and breaks with %20 text = descriptionField.getText().replace(" ", "%20").replace("\r", "%20").replace("\n", "%20"); String tagsString = tagsField.getText().replace(" ", "%20").replace("\r", "%20").replace("\n", "%20"); imageTypeString = imageTypeBox.getSelectedItem().toString(); sizeTypeString = sizeBox.getSelectedItem().toString(); licenseTypeString = licenseBox.getSelectedItem().toString(); safeSearchTypeString = safeSearchBox.getSelectedItem().toString(); searchParameters = tagsString + text; System.out.println("search parameters: " + searchParameters); if (searchParameters.length() != 0) { // add new thread for searching, so that progress bar and // searching could run simultaneously Thread t1 = new Thread(new Runnable() { @Override public void run() { progressBar.setVisible(true); searchForSimilarImages(searchParameters, imageTypeString, sizeTypeString, licenseTypeString, safeSearchTypeString); } }); // start searching for similar images in a separate thread t1.start(); } else { JOptionPane.showMessageDialog(null, "Please choose first an image to analyse or insert search parameters"); } } }); foundImagesLabel1.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { if (foundImagesLabel1.getIcon() != null) { if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) { saveFileChooser(firstImageUrl); } } } }); foundImagesLabel2.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { if (foundImagesLabel2.getIcon() != null) { if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) { saveFileChooser(secondImageUrl); } } } }); foundImagesLabel3.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { if (foundImagesLabel3.getIcon() != null) { if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) { saveFileChooser(thirdImageUrl); } } } }); foundImagesLabel4.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { if (foundImagesLabel4.getIcon() != null) { if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) { saveFileChooser(fourthImageUrl); } } } }); btnHelp.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // TODO write help HelpFrame help = new HelpFrame(); } }); }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_1.CFAstSwing.CFAstSwingClusterAttrJPanel.java
public void doLayout() { JLabel label; JComponent compo;/*from w ww . ja va2s .c om*/ CFJReferenceEditor reference; Dimension dim; final int spacing = 5; int y = spacing; final int height = 25; final int textheight = 80; final int vspacing = height + spacing; final int textvspacing = textheight + spacing; final int labelx = spacing; final int labelwidth = 200; final int fieldx = labelx + labelwidth + spacing; final int fieldwidth = 1024; Dimension jpsz = getSize(); int usefieldwidth = jpsz.width - 215; label = getSwingLabelId(); label.setBounds(labelx, y, labelwidth, height); compo = getSwingEditorId(); dim = compo.getMaximumSize(); if (dim.width < usefieldwidth) { compo.setBounds(fieldx, y, dim.width, height); } else { compo.setBounds(fieldx, y, fieldwidth, height); } y = y + vspacing; label = getSwingLabelFullDomainName(); label.setBounds(labelx, y, labelwidth, height); compo = getSwingEditorFullDomainName(); dim = compo.getMaximumSize(); if (dim.width < usefieldwidth) { compo.setBounds(fieldx, y, dim.width, height); } else { compo.setBounds(fieldx, y, fieldwidth, height); } y = y + vspacing; label = getSwingLabelDescription(); label.setBounds(labelx, y, labelwidth, height); compo = getSwingEditorDescription(); dim = compo.getMaximumSize(); if (dim.width < usefieldwidth) { compo.setBounds(fieldx, y, dim.width, height); } else { compo.setBounds(fieldx, y, fieldwidth, height); } y = y + vspacing; }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccSwing.CFAccSwingISOCountryAttrJPanel.java
public void doLayout() { JLabel label; JComponent compo;/*from ww w . j av a2 s. c om*/ CFJReferenceEditor reference; Dimension dim; final int spacing = 5; int y = spacing; final int height = 25; final int textheight = 80; final int vspacing = height + spacing; final int textvspacing = textheight + spacing; final int labelx = spacing; final int labelwidth = 200; final int fieldx = labelx + labelwidth + spacing; final int fieldwidth = 1024; Dimension jpsz = getSize(); int usefieldwidth = jpsz.width - 215; label = getSwingLabelId(); label.setBounds(labelx, y, labelwidth, height); compo = getSwingEditorId(); dim = compo.getMaximumSize(); if (dim.width < usefieldwidth) { compo.setBounds(fieldx, y, dim.width, height); } else { compo.setBounds(fieldx, y, fieldwidth, height); } y = y + vspacing; label = getSwingLabelISOCode(); label.setBounds(labelx, y, labelwidth, height); compo = getSwingEditorISOCode(); dim = compo.getMaximumSize(); if (dim.width < usefieldwidth) { compo.setBounds(fieldx, y, dim.width, height); } else { compo.setBounds(fieldx, y, fieldwidth, height); } y = y + vspacing; label = getSwingLabelName(); label.setBounds(labelx, y, labelwidth, height); compo = getSwingEditorName(); dim = compo.getMaximumSize(); if (dim.width < usefieldwidth) { compo.setBounds(fieldx, y, dim.width, height); } else { compo.setBounds(fieldx, y, fieldwidth, height); } y = y + vspacing; }
From source file:net.sourceforge.msscodefactory.cfensyntax.v2_1.CFEnSyntaxSwing.CFEnSyntaxSwingEnAdverbialAttrJPanel.java
public void doLayout() { JLabel label; JComponent compo;//from www . ja va 2 s. c o m CFJReferenceEditor reference; Dimension dim; final int spacing = 5; int y = spacing; final int height = 25; final int textheight = 80; final int vspacing = height + spacing; final int textvspacing = textheight + spacing; final int labelx = spacing; final int labelwidth = 200; final int fieldx = labelx + labelwidth + spacing; final int fieldwidth = 1024; Dimension jpsz = getSize(); int usefieldwidth = jpsz.width - 215; label = getSwingLabelId(); label.setBounds(labelx, y, labelwidth, height); compo = getSwingEditorId(); dim = compo.getMaximumSize(); if (dim.width < usefieldwidth) { compo.setBounds(fieldx, y, dim.width, height); } else { compo.setBounds(fieldx, y, fieldwidth, height); } y = y + vspacing; label = getSwingLabelScopeId(); label.setBounds(labelx, y, labelwidth, height); compo = getSwingEditorScopeId(); dim = compo.getMaximumSize(); if (dim.width < usefieldwidth) { compo.setBounds(fieldx, y, dim.width, height); } else { compo.setBounds(fieldx, y, fieldwidth, height); } y = y + vspacing; label = getSwingLabelName(); label.setBounds(labelx, y, labelwidth, height); compo = getSwingEditorName(); dim = compo.getMaximumSize(); if (dim.width < usefieldwidth) { compo.setBounds(fieldx, y, dim.width, height); } else { compo.setBounds(fieldx, y, fieldwidth, height); } y = y + vspacing; }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccSwing.CFAccSwingMimeTypeAttrJPanel.java
public void doLayout() { JLabel label; JComponent compo;/* w ww . j av a2 s . c o m*/ CFJReferenceEditor reference; Dimension dim; final int spacing = 5; int y = spacing; final int height = 25; final int textheight = 80; final int vspacing = height + spacing; final int textvspacing = textheight + spacing; final int labelx = spacing; final int labelwidth = 200; final int fieldx = labelx + labelwidth + spacing; final int fieldwidth = 1024; Dimension jpsz = getSize(); int usefieldwidth = jpsz.width - 215; label = getSwingLabelMimeTypeId(); label.setBounds(labelx, y, labelwidth, height); compo = getSwingEditorMimeTypeId(); dim = compo.getMaximumSize(); if (dim.width < usefieldwidth) { compo.setBounds(fieldx, y, dim.width, height); } else { compo.setBounds(fieldx, y, fieldwidth, height); } y = y + vspacing; label = getSwingLabelName(); label.setBounds(labelx, y, labelwidth, height); compo = getSwingEditorName(); dim = compo.getMaximumSize(); if (dim.width < usefieldwidth) { compo.setBounds(fieldx, y, dim.width, height); } else { compo.setBounds(fieldx, y, fieldwidth, height); } y = y + vspacing; label = getSwingLabelDescription(); label.setBounds(labelx, y, labelwidth, height); compo = getSwingEditorDescription(); dim = compo.getMaximumSize(); if (dim.width < usefieldwidth) { compo.setBounds(fieldx, y, dim.width, height); } else { compo.setBounds(fieldx, y, fieldwidth, height); } y = y + vspacing; }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_2.CFAstSwing.CFAstSwingSysClusterAttrJPanel.java
public void doLayout() { JLabel label; JComponent compo;// w w w.j a v a 2 s . c om CFJReferenceEditor reference; Dimension dim; final int spacing = 5; int y = spacing; final int height = 25; final int textheight = 80; final int vspacing = height + spacing; final int textvspacing = textheight + spacing; final int labelx = spacing; final int labelwidth = 200; final int fieldx = labelx + labelwidth + spacing; final int fieldwidth = 1024; Dimension jpsz = getSize(); int usefieldwidth = jpsz.width - 215; label = getSwingLabelContainerCluster(); label.setBounds(labelx, y, labelwidth, height); reference = getSwingReferenceContainerCluster(); reference.setBounds(fieldx, y, usefieldwidth, height); y = y + vspacing; label = getSwingLabelSingletonId(); label.setBounds(labelx, y, labelwidth, height); compo = getSwingEditorSingletonId(); dim = compo.getMaximumSize(); if (dim.width < usefieldwidth) { compo.setBounds(fieldx, y, dim.width, height); } else { compo.setBounds(fieldx, y, fieldwidth, height); } y = y + vspacing; }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccSwing.CFAccSwingISOLanguageAttrJPanel.java
public void doLayout() { JLabel label; JComponent compo;//from w ww . j a va 2 s . c o m CFJReferenceEditor reference; Dimension dim; final int spacing = 5; int y = spacing; final int height = 25; final int textheight = 80; final int vspacing = height + spacing; final int textvspacing = textheight + spacing; final int labelx = spacing; final int labelwidth = 200; final int fieldx = labelx + labelwidth + spacing; final int fieldwidth = 1024; Dimension jpsz = getSize(); int usefieldwidth = jpsz.width - 215; label = getSwingLabelId(); label.setBounds(labelx, y, labelwidth, height); compo = getSwingEditorId(); dim = compo.getMaximumSize(); if (dim.width < usefieldwidth) { compo.setBounds(fieldx, y, dim.width, height); } else { compo.setBounds(fieldx, y, fieldwidth, height); } y = y + vspacing; label = getSwingLabelISOCode(); label.setBounds(labelx, y, labelwidth, height); compo = getSwingEditorISOCode(); dim = compo.getMaximumSize(); if (dim.width < usefieldwidth) { compo.setBounds(fieldx, y, dim.width, height); } else { compo.setBounds(fieldx, y, fieldwidth, height); } y = y + vspacing; label = getSwingLabelBaseLanguageCode(); label.setBounds(labelx, y, labelwidth, height); compo = getSwingEditorBaseLanguageCode(); dim = compo.getMaximumSize(); if (dim.width < usefieldwidth) { compo.setBounds(fieldx, y, dim.width, height); } else { compo.setBounds(fieldx, y, fieldwidth, height); } y = y + vspacing; label = getSwingLabelISOCountryId(); label.setBounds(labelx, y, labelwidth, height); compo = getSwingEditorISOCountryId(); dim = compo.getMaximumSize(); if (dim.width < usefieldwidth) { compo.setBounds(fieldx, y, dim.width, height); } else { compo.setBounds(fieldx, y, fieldwidth, height); } y = y + vspacing; }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccSwing.CFAccSwingURLProtocolAttrJPanel.java
public void doLayout() { JLabel label; JComponent compo;/*from w ww .j a v a 2 s .c om*/ CFJReferenceEditor reference; Dimension dim; final int spacing = 5; int y = spacing; final int height = 25; final int textheight = 80; final int vspacing = height + spacing; final int textvspacing = textheight + spacing; final int labelx = spacing; final int labelwidth = 200; final int fieldx = labelx + labelwidth + spacing; final int fieldwidth = 1024; Dimension jpsz = getSize(); int usefieldwidth = jpsz.width - 215; label = getSwingLabelURLProtocolId(); label.setBounds(labelx, y, labelwidth, height); compo = getSwingEditorURLProtocolId(); dim = compo.getMaximumSize(); if (dim.width < usefieldwidth) { compo.setBounds(fieldx, y, dim.width, height); } else { compo.setBounds(fieldx, y, fieldwidth, height); } y = y + vspacing; label = getSwingLabelName(); label.setBounds(labelx, y, labelwidth, height); compo = getSwingEditorName(); dim = compo.getMaximumSize(); if (dim.width < usefieldwidth) { compo.setBounds(fieldx, y, dim.width, height); } else { compo.setBounds(fieldx, y, fieldwidth, height); } y = y + vspacing; label = getSwingLabelDescription(); label.setBounds(labelx, y, labelwidth, height); compo = getSwingEditorDescription(); dim = compo.getMaximumSize(); if (dim.width < usefieldwidth) { compo.setBounds(fieldx, y, dim.width, height); } else { compo.setBounds(fieldx, y, fieldwidth, height); } y = y + vspacing; label = getSwingLabelIsSecure(); label.setBounds(labelx, y, labelwidth, height); compo = getSwingEditorIsSecure(); dim = compo.getMaximumSize(); if (dim.width < usefieldwidth) { compo.setBounds(fieldx, y, dim.width, height); } else { compo.setBounds(fieldx, y, fieldwidth, height); } y = y + vspacing; }
From source file:com.fratello.longevity.smooth.AppGUI.java
private void initialize() { LabelMaxSize = 0;// w w w . j av a2 s .com ActiveGUI = true; GUI_Start = false; GUI_Pause = true; GUI_Stop = false; ran_at_least_once = false; execute(); initializeFields(); frmFileSystemSearch = new JFrame(); frmFileSystemSearch.setTitle("Smooth Longevity Fratello"); frmFileSystemSearch.setBounds(100, 100, 450, 300); frmFileSystemSearch.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frmFileSystemSearch.setResizable(false); UIManager.put("PopupMenu.border", BorderFactory.createLineBorder(Color.black, 1)); JMenuBar menuBar = new JMenuBar(); frmFileSystemSearch.setJMenuBar(menuBar); JMenu mnNewMenu = new JMenu("File"); menuBar.add(mnNewMenu); JMenuItem mntmFirst = new JMenuItem("Open Directory"); mntmFirst.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { openFileChooserDir(mntmFirst); } }); mnNewMenu.add(mntmFirst); JMenuItem mntmExit = new JMenuItem("Exit"); mntmExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { frmFileSystemSearch.dispose(); } }); mnNewMenu.add(mntmExit); JMenu mnHelp = new JMenu("Help"); menuBar.add(mnHelp); JMenuItem mntmAbout = new JMenuItem("About"); mnHelp.add(mntmAbout); JMenuItem mntmTutorials = new JMenuItem("Tutorials"); mnHelp.add(mntmTutorials); JMenuItem mntmCheckForUpdates = new JMenuItem("Check for Updates"); mnHelp.add(mntmCheckForUpdates); String ppallink = "https://www.paypal.com/cgi-bin/webscr" + "?cmd=" + "_donations" + "&business=" + "8YUJNSN6KFV54" + "&lc=" + "US" + "&item_name=" + "Personal%20funds%20for%20programming%20at%20university" + "¤cy_code=" + "USD" + "&bn=" + "PP%2dDonationsBF" + "%3abtn_donateCC_LG%2egif%3aNonHosted"; JButton btnDonate = new JButton("Donate"); btnDonate.setToolTipText("<html>Open default Internet browser <br>(Chrome, FireFox, etc.)</html>"); btnDonate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { openWebPage(ppallink); } }); btnDonate.setBounds(159, 176, 90, 25); menuBar.add(btnDonate); JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP); frmFileSystemSearch.getContentPane().add(tabbedPane, BorderLayout.CENTER); // ---------------------------- JPanels ------------------------------ JPanel panel = new JPanel(); tabbedPane.addTab("Start Directory", null, panel, null); JPanel panel_1 = new JPanel(); tabbedPane.addTab("Search Setup", null, panel_1, null); panel_1.setLayout(null); JPanel panel_2 = new JPanel(); tabbedPane.addTab("Run Program", null, panel_2, null); panel_2.setLayout(null); JPanel panel_3 = new JPanel(); tabbedPane.addTab("Information", null, panel_3, null); panel_3.setBounds(10, 11, 409, 154); GridBagLayout gbl_panel_3 = new GridBagLayout(); gbl_panel_3.columnWidths = new int[] { 0, 0, 0 }; gbl_panel_3.rowHeights = new int[] { 0, 0, 0 }; gbl_panel_3.columnWeights = new double[] { 1.0, 1.0, 1.0 }; gbl_panel_3.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE }; panel_3.setLayout(gbl_panel_3); // ------------- Dynamic Update - Swingworker Components ------------- SentinelProgressBar = new JProgressBar(); SentinelProgressBar.setMaximumSize(new Dimension(146, 14)); SentinelProgressBar.setMaximum(1000); SentinelProgressBar.setBounds(74, 187, 146, 14); panel_2.add(SentinelProgressBar); SentinelProgressLabel = new JLabel(); SentinelProgressLabel.setToolTipText("Time needed to finish the program in progress"); SentinelProgressLabel.setBounds(333, 181, 86, 20); panel_2.add(SentinelProgressLabel); // ------------------------------------------------------------------- // ------------------------ JPanel Components ------------------------ JLabel lblCurrentDirectory = new JLabel("Current Directory"); panel.add(lblCurrentDirectory); userSelectedDirectories = new JTextField(); panel.add(userSelectedDirectories); userSelectedDirectories.setColumns(35); JButton btnBrowse = new JButton("Browse"); btnBrowse.setToolTipText("Locate directory in system"); btnBrowse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { openFileChooserDir(btnBrowse); } }); panel.add(btnBrowse); JButton btnClear = new JButton("Clear"); btnClear.setToolTipText("Deletes the current directory shown"); btnClear.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { userSelectedDirectories.setText(""); clearSourceDirectory(); } }); panel.add(btnClear); // ------------------------------------------------------------------- // ----------------------- JPanel_1 Components ----------------------- // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Extension :: [Check Box] chckbxExt = new JCheckBox("Extension"); chckbxExt.setToolTipText("Check to ignore file extensions"); chckbxExt.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) cf.setUse("Ext", true); else if (e.getStateChange() == ItemEvent.DESELECTED) cf.setUse("Ext", false); } }); chckbxExt.setBounds(8, 15, 97, 23); panel_1.add(chckbxExt); // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Hash :: [Check Box] chckbxHash = new JCheckBox("Hash"); chckbxHash.setToolTipText("Check to compare by hashing files (FAST)"); chckbxHash.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) cf.setUse("Hash", true); else if (e.getStateChange() == ItemEvent.DESELECTED) cf.setUse("Hash", false); } }); chckbxHash.setBounds(8, 45, 97, 23); panel_1.add(chckbxHash); // Hash :: [Combo Box] comboBoxHash = new JComboBox<String>(); comboBoxHash.setToolTipText( "<html>Hash algorithm to use in file hashing <br>(note - SHA-512 may not be <br>supported by your computer)</html>"); comboBoxHash.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { @SuppressWarnings("unchecked") JComboBox<String> cb = (JComboBox<String>) e.getSource(); String UIselect = (String) cb.getSelectedItem(); cf.setHashString(UIselect); } }); comboBoxHash .setModel(new DefaultComboBoxModel<String>(new String[] { "MD5", "SHA-1", "SHA-256", "SHA-512" })); comboBoxHash.setBounds(150, 44, 75, 25); panel_1.add(comboBoxHash); // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Name :: [Check Box] chckbxName = new JCheckBox("Name"); chckbxName.setToolTipText("Name tool-tip goes here"); chckbxName.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) cf.setUse("Name", true); else if (e.getStateChange() == ItemEvent.DESELECTED) cf.setUse("Name", false); } }); chckbxName.setBounds(8, 75, 97, 23); panel_1.add(chckbxName); // Name :: [Text Field] namePercentMatchTextField = new JFormattedTextField(new Double(0.0d)); namePercentMatchTextField.setFormatterFactory(new DoubleDocListener(namePercentMatchTextField)); namePercentMatchTextField.getDocument() .addDocumentListener(new DoubleDocListener(namePercentMatchTextField)); namePercentMatchTextField.setToolTipText("Match file names by percentage [00.00-100.00]"); namePercentMatchTextField.setBounds(150, 74, 110, 25); panel_1.add(namePercentMatchTextField); namePercentMatchTextField.setColumns(10); // Name :: [Combo Box] comboBoxNames = new JComboBox<String>(); comboBoxNames.setToolTipText("Algorithm to compare names"); comboBoxNames.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { @SuppressWarnings("unchecked") JComboBox<String> cb = (JComboBox<String>) e.getSource(); String UIselect = (String) cb.getSelectedItem(); cf.setMatchingAlgorithm(UIselect); } }); comboBoxNames.setModel(new DefaultComboBoxModel<String>(new String[] { "Bitap", "Cosine", "DamerauLevenshtein", "DynamicTimeWarpingStandard1", "DynamicTimeWarpingStandard2", "Hamming", "Hirschberg", "JaccardIndex", "JaroWinkler", "Levenshtein", "NeedlemanWunsch", "SmithWaterman", "SorensenSimilarityIndex", "WagnerFischer" })); comboBoxNames.setBounds(265, 74, 150, 25); panel_1.add(comboBoxNames); // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Size :: [Check Box] chckbxSize = new JCheckBox("Size"); chckbxSize.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) cf.setUse("Size", true); else if (e.getStateChange() == ItemEvent.DESELECTED) cf.setUse("Size", false); } }); chckbxSize.setBounds(8, 105, 97, 23); panel_1.add(chckbxSize); // Size :: [Text Field] sizePercentMatchTextField = new JFormattedTextField(new Double(0.0d)); sizePercentMatchTextField.setFormatterFactory(new DoubleDocListener(sizePercentMatchTextField)); sizePercentMatchTextField.getDocument() .addDocumentListener(new DoubleDocListener(sizePercentMatchTextField)); sizePercentMatchTextField.setToolTipText("Match file sizes by percentage [00.00-100.00]"); sizePercentMatchTextField.setBounds(150, 104, 110, 25); panel_1.add(sizePercentMatchTextField); sizePercentMatchTextField.setColumns(10); // Size :: [Combo Box] comboBoxSize = new JComboBox<String>(); comboBoxSize.setToolTipText("Specify byte grouping"); comboBoxSize.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { @SuppressWarnings("unchecked") JComboBox<String> cb = (JComboBox<String>) e.getSource(); String UIselect = (String) cb.getSelectedItem(); cf.setMetricSize(UIselect); } }); comboBoxSize.setModel( new DefaultComboBoxModel<String>(new String[] { "BYTE", "KILOBYTE", "MEGABYTE", "GIGABYTE" })); comboBoxSize.setBounds(265, 104, 150, 25); panel_1.add(comboBoxSize); // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Thorough :: [Check Box] chckbxThorough = new JCheckBox("Thorough"); chckbxThorough.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) cf.setUse("Thorough", true); else if (e.getStateChange() == ItemEvent.DESELECTED) cf.setUse("Thorough", false); } }); chckbxThorough.setToolTipText("Check byte by byte"); chckbxThorough.setBounds(8, 135, 97, 23); panel_1.add(chckbxThorough); // Thorough :: [Text Field] thoroughPercentMatchTextField = new JFormattedTextField(new Double(0.0d)); thoroughPercentMatchTextField.setFormatterFactory(new DoubleDocListener(thoroughPercentMatchTextField)); thoroughPercentMatchTextField.getDocument() .addDocumentListener(new DoubleDocListener(thoroughPercentMatchTextField)); thoroughPercentMatchTextField.setToolTipText("Match file sizes by percentage [00.00-100.00]"); thoroughPercentMatchTextField.setBounds(150, 134, 110, 25); panel_1.add(thoroughPercentMatchTextField); thoroughPercentMatchTextField.setColumns(10); // Thorough :: [Check Box] chckbxExitFast = new JCheckBox("Exit Fast"); chckbxExitFast.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) cf.setThoroughExitFirstByteMisMatch(true); else if (e.getStateChange() == ItemEvent.DESELECTED) cf.setThoroughExitFirstByteMisMatch(false); } }); chckbxExitFast.setToolTipText("<html>When the first byte comparison <br>is a mis-match then stop</html>"); chckbxExitFast.setBounds(265, 138, 105, 16); panel_1.add(chckbxExitFast); // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ JButton btnSaveSearchSettings = new JButton("Save Search Settings"); btnSaveSearchSettings.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { pollSearchSettings(); cf.saveObject(); // System.out.println(cf.toString()); // debug } }); btnSaveSearchSettings.setBounds(292, 181, 140, 25); panel_1.add(btnSaveSearchSettings); JButton btnLoadSettings = new JButton("Load Settings"); btnLoadSettings.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (!cf.loadObject()) cf.setDefaultSettings(); cacheUpdateGUISettings(); } }); btnLoadSettings.setBounds(148, 181, 140, 25); panel_1.add(btnLoadSettings); JButton btnDefaultSettings = new JButton("Use Default Settings"); btnDefaultSettings.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { cf.setDefaultSettings(); cacheUpdateGUISettings(); } }); btnDefaultSettings.setBounds(4, 181, 140, 25); panel_1.add(btnDefaultSettings); // ------------------------------------------------------------------- // ----------------------- JPanel_2 Components ----------------------- JLabel labelStatus = new JLabel("Progress"); labelStatus.setBounds(10, 187, 54, 14); panel_2.add(labelStatus); JButton btnStart = new JButton("Start"); btnStart.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { pollSearchSettings(); if (!ran_at_least_once) ran_at_least_once = true; else { SentinelProgressBar.setValue(0); SentinelProgressLabel.setText("Waiting..."); } try { if (multiSelection == null) { JOptionPane.showMessageDialog(btnStart, "Please enter at least one directory.", "Press OK to continue", JOptionPane.PLAIN_MESSAGE); return; } setSourceDirectory(multiSelection); GUI_Start = true; } catch (Exception err) { err.printStackTrace(); } } }); btnStart.setBounds(40, 153, 89, 23); panel_2.add(btnStart); JButton btnStop = new JButton("Stop"); btnStop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { GUI_Stop = true; } }); btnStop.setBounds(169, 153, 89, 23); panel_2.add(btnStop); JButton btnNewButton = new JButton("Pause"); btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { GUI_Pause = true; } }); btnNewButton.setBounds(298, 153, 89, 23); panel_2.add(btnNewButton); JCheckBox chckbxDeleteDuplicateFiles = new JCheckBox("Delete duplicate files"); chckbxDeleteDuplicateFiles.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { deleteCopyResults = true; } }); chckbxDeleteDuplicateFiles.setBounds(230, 10, 150, 16); panel_2.add(chckbxDeleteDuplicateFiles); JCheckBox chckbxLogDuplicateFiles = new JCheckBox("Save duplicates to file"); chckbxLogDuplicateFiles.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { saveCopyResults = true; } }); chckbxLogDuplicateFiles.setBounds(230, 36, 150, 16); panel_2.add(chckbxLogDuplicateFiles); // ------------------------------------------------------------------- // ----------------------- JPanel_3 Components ----------------------- JLabel lblAbout = new JLabel("About"); GridBagConstraints gbc_lblAbout = new GridBagConstraints(); gbc_lblAbout.insets = new Insets(0, 0, 5, 5); gbc_lblAbout.gridx = 0; gbc_lblAbout.gridy = 0; panel_3.add(lblAbout, gbc_lblAbout); JLabel lblTutorials = new JLabel("Tutorials"); GridBagConstraints gbc_lblTutorials = new GridBagConstraints(); gbc_lblTutorials.insets = new Insets(0, 0, 5, 5); gbc_lblTutorials.gridx = 1; gbc_lblTutorials.gridy = 0; panel_3.add(lblTutorials, gbc_lblTutorials); JLabel lblUpdates = new JLabel("Updates"); GridBagConstraints gbc_lblUpdates = new GridBagConstraints(); gbc_lblUpdates.insets = new Insets(0, 0, 5, 0); gbc_lblUpdates.gridx = 2; gbc_lblUpdates.gridy = 0; panel_3.add(lblUpdates, gbc_lblUpdates); JButton btnInformation = new JButton("Information"); btnInformation.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { openWebPage(ppallink); } }); GridBagConstraints gbc_btnInformation = new GridBagConstraints(); gbc_btnInformation.insets = new Insets(0, 0, 0, 5); gbc_btnInformation.gridx = 0; gbc_btnInformation.gridy = 1; panel_3.add(btnInformation, gbc_btnInformation); JButton btnExamples = new JButton("Examples"); btnExamples.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { openWebPage(ppallink); } }); GridBagConstraints gbc_btnExamples = new GridBagConstraints(); gbc_btnExamples.insets = new Insets(0, 0, 0, 5); gbc_btnExamples.gridx = 1; gbc_btnExamples.gridy = 1; panel_3.add(btnExamples, gbc_btnExamples); JButton btnCheckNow = new JButton("Check Now"); btnCheckNow.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { openWebPage(ppallink); } }); GridBagConstraints gbc_btnCheckNow = new GridBagConstraints(); gbc_btnCheckNow.gridx = 2; gbc_btnCheckNow.gridy = 1; panel_3.add(btnCheckNow, gbc_btnCheckNow); }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccSwing.CFAccSwingDomainBaseAttrJPanel.java
public void doLayout() { JLabel label; JComponent compo;/*from ww w. ja va 2 s. c om*/ CFJReferenceEditor reference; Dimension dim; final int spacing = 5; int y = spacing; final int height = 25; final int textheight = 80; final int vspacing = height + spacing; final int textvspacing = textheight + spacing; final int labelx = spacing; final int labelwidth = 200; final int fieldx = labelx + labelwidth + spacing; final int fieldwidth = 1024; Dimension jpsz = getSize(); int usefieldwidth = jpsz.width - 215; label = getSwingLabelOwnerTenant(); label.setBounds(labelx, y, labelwidth, height); reference = getSwingReferenceOwnerTenant(); reference.setBounds(fieldx, y, usefieldwidth, height); y = y + vspacing; label = getSwingLabelId(); label.setBounds(labelx, y, labelwidth, height); compo = getSwingEditorId(); dim = compo.getMaximumSize(); if (dim.width < usefieldwidth) { compo.setBounds(fieldx, y, dim.width, height); } else { compo.setBounds(fieldx, y, fieldwidth, height); } y = y + vspacing; label = getSwingLabelDescription(); label.setBounds(labelx, y, labelwidth, height); compo = getSwingEditorDescription(); dim = compo.getMaximumSize(); if (dim.width < usefieldwidth) { compo.setBounds(fieldx, y, dim.width, height); } else { compo.setBounds(fieldx, y, fieldwidth, height); } y = y + vspacing; }