List of usage examples for javax.swing SpringLayout SpringLayout
public SpringLayout()
SpringLayout
. From source file:jchrest.gui.VisualSearchPane.java
private JPanel constructTrainingOptions() { _maxTrainingCycles = new JSpinner(new SpinnerNumberModel(5, 1, 1000, 1)); _numFixations = new JSpinner(new SpinnerNumberModel(20, 1, 1000, 1)); _maxNetworkSize = new JSpinner(new SpinnerNumberModel(100000, 1, 10000000, 1)); JPanel panel = new JPanel(); panel.setLayout(new SpringLayout()); Utilities.addLabel(panel, "Domain of scenes:", _domainSelector); Utilities.addLabel(panel, "Number of scenes:", new JLabel("" + _scenes.size())); Utilities.addLabel(panel, "Maximum training cycles:", _maxTrainingCycles); Utilities.addLabel(panel, "Number of fixations per scene:", _numFixations); Utilities.addLabel(panel, "Maximum network size:", _maxNetworkSize); Utilities.makeCompactGrid(panel, 5, 2, 3, 3, 10, 5); panel.setMaximumSize(panel.getPreferredSize()); JPanel ePanel = new JPanel(); ePanel.setLayout(new GridLayout(1, 1)); ePanel.add(panel);//from ww w. j av a 2s . c om return ePanel; }
From source file:es.emergya.ui.plugins.forms.FormGeneric.java
protected void generateMiddle() { mid = new JPanel(new SpringLayout()); mid.setBackground(Color.WHITE); initializeFields();/*from w w w.java 2s. co m*/ SpringUtilities.makeCompactGrid(mid, rows, cols, initialX, initialY, xPad, yPad); }
From source file:es.emergya.ui.gis.popups.SummaryDialog.java
public SummaryDialog(Recurso r) { super();//from w ww . j a va 2s . c o m r = (r == null) ? null : RecursoConsultas.getByIdentificador(r.getIdentificador()); setAlwaysOnTop(true); setResizable(false); setName(r.getIdentificador()); setBackground(Color.WHITE); setSize(600, 400); setTitle(i18n.getString("Resources.summary.titleWindow") + " " + r.getIdentificador()); try { setIconImage(((BasicWindow) GoClassLoader.getGoClassLoader().load(BasicWindow.class)).getFrame() .getIconImage()); } catch (Throwable e) { LOG.error("There is no icon image", e); } JPanel base = new JPanel(); base.setLayout(new BoxLayout(base, BoxLayout.Y_AXIS)); base.setBackground(Color.WHITE); r = RecursoConsultas.getByIdentificador(r.getIdentificador()); // Icono del titulo JPanel title = new JPanel(new FlowLayout(FlowLayout.LEADING)); final JLabel labelTitle = new JLabel(i18n.getString("Resources.summary.title") + " " + r.getIdentificador(), LogicConstants.getIcon("tittleficha_icon_recurso"), JLabel.LEFT); labelTitle.setFont(LogicConstants.deriveBoldFont(12f)); title.setBackground(Color.WHITE); title.add(labelTitle); base.add(title); // Nombre JPanel mid = new JPanel(new SpringLayout()); mid.setBackground(Color.WHITE); mid.add(new JLabel(i18n.getString("Resources.name"), JLabel.RIGHT)); JTextField name = new JTextField(25); if (r != null) name.setText(r.getIdentificador()); name.setEditable(false); mid.add(name); // Patrulla mid.add(new JLabel(i18n.getString("Resources.squad"), JLabel.RIGHT)); // JComboBox squads = new // JComboBox(PatrullaConsultas.getAll().toArray()); JTextField squads = new JTextField(r.getPatrullas() == null ? null : r.getPatrullas().getNombre()); // squads.setSelectedItem(r.getPatrullas()); squads.setEditable(false); squads.setColumns(21); // squads.setEnabled(false); mid.add(squads); // Tipo mid.add(new JLabel(i18n.getString("Resources.type"), JLabel.RIGHT)); JTextField types = new JTextField(r.getTipo()); types.setEditable(false); mid.add(types); // Estado Eurocop mid.add(new JLabel(i18n.getString("Resources.status"), JLabel.RIGHT)); JTextField status = new JTextField(); if (r.getEstadoEurocop() != null) status.setText(r.getEstadoEurocop().getIdentificador()); status.setEditable(false); mid.add(status); // Subflota mid.add(new JLabel(i18n.getString("Resources.subfleet"), JLabel.RIGHT)); JTextField subfleets = new JTextField(r.getFlotas() == null ? null : r.getFlotas().getNombre()); subfleets.setEditable(false); mid.add(subfleets); // Referencia Humana mid.add(new JLabel(i18n.getString("Resources.incidences"), JLabel.RIGHT)); JTextField rHumana = new JTextField(); // if (r.getIncidencias() != null) // rHumana.setText(r.getIncidencias().getReferenciaHumana()); rHumana.setEditable(false); mid.add(rHumana); // dispositivo mid.add(new JLabel(i18n.getString("Resources.device"), JLabel.RIGHT)); JTextField issi = new JTextField(); issi.setEditable(false); mid.add(issi); mid.add(new JLabel(i18n.getString("Resources.enabled"), JLabel.RIGHT)); JCheckBox enabled = new JCheckBox("", true); enabled.setEnabled(false); enabled.setOpaque(false); if (r.getDispositivo() != null) { final String valueOf = String.valueOf(r.getDispositivo()); try { issi.setText(String.format(FORMAT, r.getDispositivo())); } catch (Throwable t) { issi.setText(valueOf); } enabled.setSelected(r.getHabilitado()); } mid.add(enabled); // Fecha ultimo gps mid.add(new JLabel(i18n.getString("Resources.lastPosition"), JLabel.RIGHT)); JTextField lastGPS = new JTextField(); final Date lastGPSDateForRecurso = HistoricoGPSConsultas.lastGPSDateForRecurso(r); if (lastGPSDateForRecurso != null) { lastGPS.setText(SimpleDateFormat.getDateTimeInstance().format(lastGPSDateForRecurso)); } lastGPS.setEditable(false); mid.add(lastGPS); // Espacio en blanco mid.add(Box.createHorizontalGlue()); mid.add(Box.createHorizontalGlue()); // Espacio en blanco mid.add(Box.createHorizontalGlue()); mid.add(Box.createHorizontalGlue()); SpringUtilities.makeCompactGrid(mid, 5, 4, 6, 6, 6, 18); base.add(mid); // informacion adicional JPanel infoPanel = new JPanel(new SpringLayout()); JTextField info = new JTextField(25); info.setText(r.getInfoAdicional()); info.setEditable(false); infoPanel.setOpaque(false); infoPanel.add(new JLabel(i18n.getString("Resources.info"))); infoPanel.add(info); SpringUtilities.makeCompactGrid(infoPanel, 1, 2, 6, 6, 6, 18); base.add(infoPanel); JPanel buttons = new JPanel(); buttons.setBackground(Color.WHITE); JButton accept = new JButton(i18n.getString("Buttons.ok"), LogicConstants.getIcon("button_accept")); accept.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dispose(); } }); buttons.add(accept); base.add(buttons); getContentPane().add(base); pack(); int x; int y; Container myParent; try { myParent = ((BasicWindow) GoClassLoader.getGoClassLoader().load(BasicWindow.class)).getFrame() .getContentPane(); java.awt.Point topLeft = myParent.getLocationOnScreen(); Dimension parentSize = myParent.getSize(); Dimension mySize = getSize(); if (parentSize.width > mySize.width) x = ((parentSize.width - mySize.width) / 2) + topLeft.x; else x = topLeft.x; if (parentSize.height > mySize.height) y = ((parentSize.height - mySize.height) / 2) + topLeft.y; else y = topLeft.y; setLocation(x, y); } catch (Throwable e1) { LOG.error("There is no basic window!", e1); } }
From source file:TableFilterDemo.java
public TableFilterDemo() { super();/*from w w w.ja va 2 s . c om*/ setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); // Create a table with a sorter. MyTableModel model = new MyTableModel(); sorter = new TableRowSorter<MyTableModel>(model); table = new JTable(model); table.setRowSorter(sorter); table.setPreferredScrollableViewportSize(new Dimension(500, 70)); table.setFillsViewportHeight(true); // For the purposes of this example, better to have a single // selection. table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // When selection changes, provide user with row numbers for // both view and model. table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent event) { int viewRow = table.getSelectedRow(); if (viewRow < 0) { // Selection got filtered away. statusText.setText(""); } else { int modelRow = table.convertRowIndexToModel(viewRow); statusText.setText(String.format("Selected Row in view: %d. " + "Selected Row in model: %d.", viewRow, modelRow)); } } }); // Create the scroll pane and add the table to it. JScrollPane scrollPane = new JScrollPane(table); // Add the scroll pane to this panel. add(scrollPane); // Create a separate form for filterText and statusText JPanel form = new JPanel(new SpringLayout()); JLabel l1 = new JLabel("Filter Text:", SwingConstants.TRAILING); form.add(l1); filterText = new JTextField(); // Whenever filterText changes, invoke newFilter. filterText.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent e) { newFilter(); } public void insertUpdate(DocumentEvent e) { newFilter(); } public void removeUpdate(DocumentEvent e) { newFilter(); } }); l1.setLabelFor(filterText); form.add(filterText); JLabel l2 = new JLabel("Status:", SwingConstants.TRAILING); form.add(l2); statusText = new JTextField(); l2.setLabelFor(statusText); form.add(statusText); SpringUtilities.makeCompactGrid(form, 2, 2, 6, 6, 6, 6); add(form); }
From source file:com.romraider.logger.ecu.ui.tab.dyno.DynoChartPanel.java
public DynoChartPanel(String labelX, String labelY1, String labelY2) { super(new SpringLayout()); checkNotNull(labelX, labelY1, labelY2); this.labelX = labelX; this.labelY1 = labelY1; this.labelY2 = labelY2; addChart();/* w w w . j av a 2 s .co m*/ }
From source file:de.tbuchloh.kiskis.gui.dialogs.PropertyEditor.java
/** * Overridden!/*from ww w .j a va 2 s . c o m*/ * * @see de.tbuchloh.kiskis.gui.dialogs.KisKisDialog#createMainPanel() */ @Override protected Component createMainPanel() { final JPanel p = new JPanel(new SpringLayout()); p.setBorder(LnFHelper.createDefaultBorder()); p.add(new JLabel(M.getString("nameBox.label"))); p.add(_nameBox); p.add(new JLabel(M.getString("typeBox.label"))); p.add(_typeBox); SpringUtilities.makeCompactGrid(p, 2, 2, 0, 0, 5, 5); return p; }
From source file:es.emergya.ui.gis.popups.GenericDialog.java
public GenericDialog(T i, final String titulo, final String icon) { super();//from w w w . ja va2 s.c o m log.trace("GenericDialog(" + i + ")"); setAlwaysOnTop(true); setResizable(false); setBackground(Color.WHITE); setPreferredSize(new Dimension(500, 500)); setTitle(titulo); try { setIconImage(((BasicWindow) GoClassLoader.getGoClassLoader().load(BasicWindow.class)).getFrame() .getIconImage()); } catch (Throwable e) { LOG.error("There is no icon image", e); } JPanel base = new JPanel(); base.setLayout(new BoxLayout(base, BoxLayout.Y_AXIS)); base.setBackground(Color.WHITE); JPanel title = new JPanel(new FlowLayout(FlowLayout.LEADING)); final JLabel labelTitle = new JLabel(titulo, LogicConstants.getIcon(icon), JLabel.LEFT); labelTitle.setFont(LogicConstants.deriveBoldFont(12f)); title.setBackground(Color.WHITE); title.add(labelTitle); base.add(title); mid = new JPanel(new SpringLayout()); mid.setBackground(Color.WHITE); loadDialog(i); SpringUtilities.makeCompactGrid(mid, rows, cols, initialX, initialY, xPad, yPad); base.add(mid); JPanel buttons = new JPanel(); buttons.setBackground(Color.WHITE); JButton accept = new JButton(i18n.getString("Buttons.ok"), LogicConstants.getIcon("button_accept")); accept.addActionListener(closeListener); accept.addActionListener(saveListener); buttons.add(accept); JButton cancel = new JButton(i18n.getString("Buttons.cancel"), LogicConstants.getIcon("button_cancel")); cancel.addActionListener(closeListener); buttons.add(cancel); base.add(buttons); getContentPane().add(base); pack(); int x; int y; Container myParent; try { myParent = ((BasicWindow) GoClassLoader.getGoClassLoader().load(BasicWindow.class)).getFrame() .getContentPane(); java.awt.Point topLeft = myParent.getLocationOnScreen(); Dimension parentSize = myParent.getSize(); Dimension mySize = getSize(); if (parentSize.width > mySize.width) x = ((parentSize.width - mySize.width) / 2) + topLeft.x; else x = topLeft.x; if (parentSize.height > mySize.height) y = ((parentSize.height - mySize.height) / 2) + topLeft.y; else y = topLeft.y; setLocation(x, y); } catch (Throwable e1) { LOG.error("There is no basic window!", e1); } }
From source file:AppSpringLayout.java
/** * Initialize the contents of the frame. *//*from ww w .j ava2 s .c o m*/ private void initialize() { frame = new JFrame(); frame.setBounds(0, 0, 850, 750); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); springLayout = new SpringLayout(); frame.getContentPane().setLayout(springLayout); frame.setLocationRelativeTo(null); FileNameExtensionFilter filter = new FileNameExtensionFilter("Image files", "jpg", "jpeg", "png"); fc = new JFileChooser(); fc.setFileFilter(filter); // frame.getContentPane().add(fc); btnTurnCameraOn = new JButton("Turn camera on"); springLayout.putConstraint(SpringLayout.WEST, btnTurnCameraOn, 51, SpringLayout.WEST, frame.getContentPane()); springLayout.putConstraint(SpringLayout.EAST, btnTurnCameraOn, -581, SpringLayout.EAST, frame.getContentPane()); frame.getContentPane().add(btnTurnCameraOn); urlTextField = new JTextField(); springLayout.putConstraint(SpringLayout.SOUTH, btnTurnCameraOn, -6, SpringLayout.NORTH, urlTextField); springLayout.putConstraint(SpringLayout.WEST, urlTextField, 0, SpringLayout.WEST, btnTurnCameraOn); springLayout.putConstraint(SpringLayout.EAST, urlTextField, 274, SpringLayout.WEST, frame.getContentPane()); frame.getContentPane().add(urlTextField); urlTextField.setColumns(10); originalImageLabel = new JLabel(""); springLayout.putConstraint(SpringLayout.NORTH, originalImageLabel, 102, SpringLayout.NORTH, frame.getContentPane()); springLayout.putConstraint(SpringLayout.WEST, originalImageLabel, 34, SpringLayout.WEST, frame.getContentPane()); springLayout.putConstraint(SpringLayout.SOUTH, originalImageLabel, -326, SpringLayout.SOUTH, frame.getContentPane()); springLayout.putConstraint(SpringLayout.EAST, originalImageLabel, -566, SpringLayout.EAST, frame.getContentPane()); springLayout.putConstraint(SpringLayout.SOUTH, urlTextField, -6, SpringLayout.NORTH, originalImageLabel); frame.getContentPane().add(originalImageLabel); btnAnalyseImage = new JButton("Analyse image"); springLayout.putConstraint(SpringLayout.NORTH, btnAnalyseImage, 6, SpringLayout.SOUTH, originalImageLabel); springLayout.putConstraint(SpringLayout.WEST, btnAnalyseImage, 58, SpringLayout.WEST, frame.getContentPane()); springLayout.putConstraint(SpringLayout.EAST, btnAnalyseImage, 252, SpringLayout.WEST, frame.getContentPane()); frame.getContentPane().add(btnAnalyseImage); lblTags = new JLabel("Tags:"); frame.getContentPane().add(lblTags); lblDescription = new JLabel("Description:"); springLayout.putConstraint(SpringLayout.WEST, lblDescription, 84, SpringLayout.EAST, lblTags); springLayout.putConstraint(SpringLayout.NORTH, lblTags, 0, SpringLayout.NORTH, lblDescription); springLayout.putConstraint(SpringLayout.NORTH, lblDescription, 6, SpringLayout.SOUTH, btnAnalyseImage); springLayout.putConstraint(SpringLayout.SOUTH, lblDescription, -269, SpringLayout.SOUTH, frame.getContentPane()); frame.getContentPane().add(lblDescription); tagsTextArea = new JTextArea(); springLayout.putConstraint(SpringLayout.NORTH, tagsTextArea, 459, SpringLayout.NORTH, frame.getContentPane()); springLayout.putConstraint(SpringLayout.WEST, tagsTextArea, 10, SpringLayout.WEST, frame.getContentPane()); springLayout.putConstraint(SpringLayout.EAST, tagsTextArea, -727, SpringLayout.EAST, frame.getContentPane()); frame.getContentPane().add(tagsTextArea); descriptionTextArea = new JTextArea(); springLayout.putConstraint(SpringLayout.NORTH, descriptionTextArea, 0, SpringLayout.SOUTH, lblDescription); springLayout.putConstraint(SpringLayout.WEST, descriptionTextArea, 18, SpringLayout.EAST, tagsTextArea); descriptionTextArea.setLineWrap(true); descriptionTextArea.setWrapStyleWord(true); frame.getContentPane().add(descriptionTextArea); lblImageType = new JLabel("Image type"); springLayout.putConstraint(SpringLayout.WEST, lblTags, 0, SpringLayout.WEST, lblImageType); springLayout.putConstraint(SpringLayout.NORTH, lblImageType, 10, SpringLayout.SOUTH, tagsTextArea); springLayout.putConstraint(SpringLayout.WEST, lblImageType, 20, SpringLayout.WEST, frame.getContentPane()); frame.getContentPane().add(lblImageType); lblSize = new JLabel("Size"); springLayout.putConstraint(SpringLayout.NORTH, lblSize, 21, SpringLayout.SOUTH, lblImageType); springLayout.putConstraint(SpringLayout.WEST, lblSize, 20, SpringLayout.WEST, frame.getContentPane()); frame.getContentPane().add(lblSize); lblLicense = new JLabel("License"); springLayout.putConstraint(SpringLayout.WEST, lblLicense, 20, SpringLayout.WEST, frame.getContentPane()); frame.getContentPane().add(lblLicense); lblSafeSearch = new JLabel("Safe search"); springLayout.putConstraint(SpringLayout.WEST, lblSafeSearch, 10, SpringLayout.WEST, frame.getContentPane()); springLayout.putConstraint(SpringLayout.SOUTH, lblSafeSearch, 139, SpringLayout.SOUTH, frame.getContentPane()); frame.getContentPane().add(lblSafeSearch); String[] licenseTypes = { "unspecified", "Public", "Share", "ShareCommercially", "Modify" }; licenseBox = new JComboBox(licenseTypes); springLayout.putConstraint(SpringLayout.WEST, licenseBox, 28, SpringLayout.EAST, lblLicense); frame.getContentPane().add(licenseBox); String[] sizeTypes = { "unspecified", "Small", "Medium", "Large", "Wallpaper" }; sizeBox = new JComboBox(sizeTypes); springLayout.putConstraint(SpringLayout.WEST, sizeBox, 50, SpringLayout.EAST, lblSize); springLayout.putConstraint(SpringLayout.EAST, sizeBox, -556, SpringLayout.EAST, frame.getContentPane()); springLayout.putConstraint(SpringLayout.EAST, licenseBox, 0, SpringLayout.EAST, sizeBox); frame.getContentPane().add(sizeBox); String[] imageTypes = { "unspecified", "AnimategGif", "Clipart", "Line", "Photo" }; imageTypeBox = new JComboBox(imageTypes); springLayout.putConstraint(SpringLayout.SOUTH, descriptionTextArea, -6, SpringLayout.NORTH, imageTypeBox); springLayout.putConstraint(SpringLayout.NORTH, imageTypeBox, 547, SpringLayout.NORTH, frame.getContentPane()); springLayout.putConstraint(SpringLayout.SOUTH, tagsTextArea, -6, SpringLayout.NORTH, imageTypeBox); springLayout.putConstraint(SpringLayout.WEST, imageTypeBox, 6, SpringLayout.EAST, lblImageType); springLayout.putConstraint(SpringLayout.EAST, imageTypeBox, -556, SpringLayout.EAST, frame.getContentPane()); springLayout.putConstraint(SpringLayout.NORTH, sizeBox, 10, SpringLayout.SOUTH, imageTypeBox); frame.getContentPane().add(imageTypeBox); btnBrowse = new JButton("Browse"); springLayout.putConstraint(SpringLayout.WEST, btnBrowse, 0, SpringLayout.WEST, btnTurnCameraOn); springLayout.putConstraint(SpringLayout.EAST, btnBrowse, -583, SpringLayout.EAST, frame.getContentPane()); frame.getContentPane().add(btnBrowse); lblSafeSearch_1 = new JLabel("Safe search"); springLayout.putConstraint(SpringLayout.WEST, lblSafeSearch_1, 20, SpringLayout.WEST, frame.getContentPane()); springLayout.putConstraint(SpringLayout.SOUTH, lblLicense, -17, SpringLayout.NORTH, lblSafeSearch_1); frame.getContentPane().add(lblSafeSearch_1); String[] safeSearchTypes = { "Strict", "Moderate", "Off" }; safeSearchBox = new JComboBox(safeSearchTypes); springLayout.putConstraint(SpringLayout.SOUTH, licenseBox, -6, SpringLayout.NORTH, safeSearchBox); springLayout.putConstraint(SpringLayout.WEST, safeSearchBox, 4, SpringLayout.EAST, lblSafeSearch_1); springLayout.putConstraint(SpringLayout.EAST, safeSearchBox, 0, SpringLayout.EAST, licenseBox); frame.getContentPane().add(safeSearchBox); btnSearchForSimilar = new JButton("Search for similar images"); springLayout.putConstraint(SpringLayout.SOUTH, lblSafeSearch_1, -13, SpringLayout.NORTH, btnSearchForSimilar); springLayout.putConstraint(SpringLayout.SOUTH, safeSearchBox, -6, SpringLayout.NORTH, btnSearchForSimilar); springLayout.putConstraint(SpringLayout.NORTH, btnSearchForSimilar, 689, SpringLayout.NORTH, frame.getContentPane()); springLayout.putConstraint(SpringLayout.WEST, btnSearchForSimilar, 36, SpringLayout.WEST, frame.getContentPane()); frame.getContentPane().add(btnSearchForSimilar); btnCancel = new JButton("Cancel"); springLayout.putConstraint(SpringLayout.NORTH, btnCancel, 0, SpringLayout.NORTH, btnBrowse); btnCancel.setVisible(false); frame.getContentPane().add(btnCancel); btnSave = new JButton("Save"); springLayout.putConstraint(SpringLayout.WEST, btnCancel, 6, SpringLayout.EAST, btnSave); springLayout.putConstraint(SpringLayout.NORTH, btnSave, 0, SpringLayout.NORTH, btnBrowse); btnSave.setVisible(false); frame.getContentPane().add(btnSave); btnTakeAPicture = new JButton("Take a picture"); springLayout.putConstraint(SpringLayout.WEST, btnTakeAPicture, 114, SpringLayout.EAST, btnBrowse); springLayout.putConstraint(SpringLayout.WEST, btnSave, 6, SpringLayout.EAST, btnTakeAPicture); springLayout.putConstraint(SpringLayout.NORTH, btnTakeAPicture, 0, SpringLayout.NORTH, btnBrowse); btnTakeAPicture.setVisible(false); frame.getContentPane().add(btnTakeAPicture); //// JScrollPane scroll = new JScrollPane(list); // Constraints c = springLayout.getConstraints(list); // frame.getContentPane().add(scroll, c); list = new JList(); JScrollPane scroll = new JScrollPane(list); springLayout.putConstraint(SpringLayout.EAST, descriptionTextArea, -89, SpringLayout.WEST, list); springLayout.putConstraint(SpringLayout.EAST, list, -128, SpringLayout.EAST, frame.getContentPane()); springLayout.putConstraint(SpringLayout.WEST, list, 64, SpringLayout.EAST, licenseBox); springLayout.putConstraint(SpringLayout.NORTH, list, 0, SpringLayout.NORTH, btnTurnCameraOn); springLayout.putConstraint(SpringLayout.SOUTH, list, -35, SpringLayout.SOUTH, lblSafeSearch_1); Constraints c = springLayout.getConstraints(list); frame.getContentPane().add(scroll, c); // frame.getContentPane().add(list); progressBar = new JProgressBar(); springLayout.putConstraint(SpringLayout.NORTH, progressBar, 15, SpringLayout.SOUTH, list); springLayout.putConstraint(SpringLayout.WEST, progressBar, 24, SpringLayout.EAST, safeSearchBox); springLayout.putConstraint(SpringLayout.EAST, progressBar, 389, SpringLayout.WEST, btnTakeAPicture); progressBar.setIndeterminate(true); progressBar.setStringPainted(true); progressBar.setVisible(false); Border border = BorderFactory .createTitledBorder("We are checking every image, pixel by pixel, it may take a while..."); progressBar.setBorder(border); frame.getContentPane().add(progressBar); labelTryLinks = new JLabel(); labelTryLinks.setVisible(false); springLayout.putConstraint(SpringLayout.NORTH, labelTryLinks, -16, SpringLayout.SOUTH, btnSearchForSimilar); springLayout.putConstraint(SpringLayout.WEST, labelTryLinks, -61, SpringLayout.EAST, licenseBox); springLayout.putConstraint(SpringLayout.SOUTH, labelTryLinks, 0, SpringLayout.SOUTH, btnSearchForSimilar); springLayout.putConstraint(SpringLayout.EAST, labelTryLinks, 0, SpringLayout.EAST, licenseBox); frame.getContentPane().add(labelTryLinks); lblFoundLinks = new JLabel(""); springLayout.putConstraint(SpringLayout.NORTH, lblFoundLinks, -29, SpringLayout.NORTH, progressBar); springLayout.putConstraint(SpringLayout.WEST, lblFoundLinks, 6, SpringLayout.EAST, scroll); springLayout.putConstraint(SpringLayout.SOUTH, lblFoundLinks, -13, SpringLayout.NORTH, progressBar); springLayout.putConstraint(SpringLayout.EAST, lblFoundLinks, -10, SpringLayout.EAST, frame.getContentPane()); frame.getContentPane().add(lblFoundLinks); numberOfImagesToSearchFor = new JTextField(); springLayout.putConstraint(SpringLayout.NORTH, numberOfImagesToSearchFor, 0, SpringLayout.NORTH, tagsTextArea); springLayout.putConstraint(SpringLayout.WEST, numberOfImagesToSearchFor, 6, SpringLayout.EAST, descriptionTextArea); springLayout.putConstraint(SpringLayout.EAST, numberOfImagesToSearchFor, -36, SpringLayout.WEST, scroll); frame.getContentPane().add(numberOfImagesToSearchFor); numberOfImagesToSearchFor.setColumns(10); JLabel lblNumberOfImages = new JLabel("Number"); springLayout.putConstraint(SpringLayout.NORTH, lblNumberOfImages, 0, SpringLayout.NORTH, lblTags); springLayout.putConstraint(SpringLayout.WEST, lblNumberOfImages, 31, SpringLayout.EAST, btnAnalyseImage); springLayout.putConstraint(SpringLayout.EAST, lblNumberOfImages, -6, SpringLayout.WEST, scroll); frame.getContentPane().add(lblNumberOfImages); // label to get coordinates for web camera panel // lblNewLabel_1 = new JLabel("New label"); // springLayout.putConstraint(SpringLayout.NORTH, lblNewLabel_1, 0, // SpringLayout.NORTH, btnTurnCameraOn); // springLayout.putConstraint(SpringLayout.WEST, lblNewLabel_1, 98, // SpringLayout.EAST, originalImagesLabel); // springLayout.putConstraint(SpringLayout.SOUTH, lblNewLabel_1, -430, // SpringLayout.SOUTH, lblSafeSearch_1); // springLayout.putConstraint(SpringLayout.EAST, lblNewLabel_1, 0, // SpringLayout.EAST, btnCancel); // frame.getContentPane().add(lblNewLabel_1); btnBrowse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (fc.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) { openFilechooser(); } } }); btnTurnCameraOn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("turn camera on"); turnCameraOn(); btnCancel.setVisible(true); btnTakeAPicture.setVisible(true); } }); btnTakeAPicture.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { btnSave.setVisible(true); 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); } }); btnSave.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() { public void actionPerformed(ActionEvent e) { btnTakeAPicture.setVisible(false); btnCancel.setVisible(false); btnSave.setVisible(false); webcam.close(); panel.setVisible(false); } }); urlTextField.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (urlTextField.getText().length() > 0) { String linkNew = urlTextField.getText(); displayImage(linkNew, originalImageLabel); originalImage = imageResponses; } } }); btnAnalyseImage.addActionListener(new ActionListener() { 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) { listModel.clear(); 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 = descriptionTextArea.getText().replace(" ", "%20").replace("\r", "%20").replace("\n", "%20"); String tagsString = tagsTextArea.getText().replace(" ", "%20").replace("\r", "%20").replace("\n", "%20"); String numberOfImages = numberOfImagesToSearchFor.getText(); try { int numberOfImagesTry = Integer.parseInt(numberOfImages); System.out.println(numberOfImagesTry); 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); workingUrls = searchToDisplayOnJList(searchParameters, imageTypeString, sizeTypeString, licenseTypeString, safeSearchTypeString, numberOfImages); } }); // start searching in a separate thread t1.start(); } else { JOptionPane.showMessageDialog(null, "Please choose first an image to analyse or insert search parameters"); } } catch (NumberFormatException e1) { JOptionPane.showMessageDialog(null, "Please insert a valid number of images to search for"); e1.printStackTrace(); } } }); list.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { int i = list.getSelectedIndex(); if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) { try { file = fc.getSelectedFile(); File output = new File(file.toString()); // check if file already exists, ask user if they // wish to overwrite it 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; } } try { URL fileNameAsUrl = new URL(linksResponse[i]); originalImage = ImageIO.read(fileNameAsUrl); ImageIO.write(toBufferedImage(originalImage), "jpeg", output); System.out.println("image saved, in the folder: " + output.getAbsolutePath()); } catch (MalformedURLException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } } catch (NullPointerException e2) { e2.getMessage(); } } } }); }
From source file:uk.co.petertribble.solview.explorer.ArcStatPanel.java
/** * Craete a new ArcStatPanel, to display ZFS ARC statistics graphically. * * @param jkstat a JKstat object/*from w w w . j ava2 s. c om*/ * @param interval the desired display update interval in seconds */ public ArcStatPanel(JKstat jkstat, int interval) { this.jkstat = jkstat; setDelay(interval); // FIXME all labels need to be localized // create a main panel setLayout(new SpringLayout()); // initialise the datasets totalCacheHitsDataset = new DefaultPieDataset(); currentCacheHitsDataset = new DefaultPieDataset(); totalCacheHitsByTypeDataset = new DefaultPieDataset(); currentCacheHitsByTypeDataset = new DefaultPieDataset(); totalCacheMissesByTypeDataset = new DefaultPieDataset(); currentCacheMissesByTypeDataset = new DefaultPieDataset(); // initialise the pie charts // args: title, dataset, legend?, tooltips?, urls? JFreeChart totalCacheChart = ChartFactory.createPieChart("Total Cache Hits By List", totalCacheHitsDataset, false, true, false); JFreeChart currentCacheChart = ChartFactory.createPieChart("Current Cache Hits By List", currentCacheHitsDataset, false, true, false); JFreeChart totalCacheHitsByTypeChart = ChartFactory.createPieChart("Total Cache Hits By Type", totalCacheHitsByTypeDataset, false, true, false); JFreeChart currentCacheHitsByTypeChart = ChartFactory.createPieChart("Current Cache Hits By Type", currentCacheHitsByTypeDataset, false, true, false); JFreeChart totalCacheMissesByTypeChart = ChartFactory.createPieChart("Total Cache Misses By Type", totalCacheMissesByTypeDataset, false, true, false); JFreeChart currentCacheMissesByTypeChart = ChartFactory.createPieChart("Current Cache Misses By Type", currentCacheMissesByTypeDataset, false, true, false); /* * The overall layout is simple: at the top are the overall size * statistics. Then the percentages for hits/misses/types for the * cache are shown below. */ JPanel infoPanel = new JPanel(new GridLayout(0, 2)); JPanel hitPanel = new JPanel(new GridLayout(0, 2)); JPanel cacheByListPanel = new JPanel(new GridLayout(1, 2)); JPanel cacheHitByTypePanel = new JPanel(new GridLayout(1, 2)); JPanel cacheMissByTypePanel = new JPanel(new GridLayout(1, 2)); // cache hit rates, in a separate panel with bars. arc_hit_bar = new JProgressBar(0, 100); arc_hit_bar.setStringPainted(true); demand_hit_bar = new JProgressBar(0, 100); demand_hit_bar.setStringPainted(true); pf_hit_bar = new JProgressBar(0, 100); pf_hit_bar.setStringPainted(true); mdemand_hit_bar = new JProgressBar(0, 100); mdemand_hit_bar.setStringPainted(true); mpf_hit_bar = new JProgressBar(0, 100); mpf_hit_bar.setStringPainted(true); hitPanel.add(new JLabel("ARC hit rate")); hitPanel.add(arc_hit_bar); hitPanel.add(new JLabel("Demand data hit rate")); hitPanel.add(demand_hit_bar); hitPanel.add(new JLabel("Prefetch data hit rate")); hitPanel.add(pf_hit_bar); hitPanel.add(new JLabel("Demand metadata hit rate")); hitPanel.add(mdemand_hit_bar); hitPanel.add(new JLabel("Prefetch metadata hit rate")); hitPanel.add(mpf_hit_bar); hitPanel.setBorder(BorderFactory.createTitledBorder("Cache Hit Rates")); Dimension dchart = new Dimension(320, 240); ChartPanel cp1a = new ChartPanel(totalCacheChart); cp1a.setPreferredSize(dchart); ChartPanel cp1b = new ChartPanel(currentCacheChart); cp1b.setPreferredSize(dchart); ChartPanel cp2a = new ChartPanel(totalCacheHitsByTypeChart); cp2a.setPreferredSize(dchart); ChartPanel cp2b = new ChartPanel(currentCacheHitsByTypeChart); cp2b.setPreferredSize(dchart); ChartPanel cp3a = new ChartPanel(totalCacheMissesByTypeChart); cp3a.setPreferredSize(dchart); ChartPanel cp3b = new ChartPanel(currentCacheMissesByTypeChart); cp3b.setPreferredSize(dchart); infoPanel.add(new JLabel("Current size")); arc_size_label = new JLabel(); infoPanel.add(arc_size_label); infoPanel.add(new JLabel("Target size")); target_size_label = new JLabel(); infoPanel.add(target_size_label); infoPanel.add(new JLabel("Min size")); arc_min_size_label = new JLabel(); infoPanel.add(arc_min_size_label); infoPanel.add(new JLabel("Max size")); arc_max_size_label = new JLabel(); infoPanel.add(arc_max_size_label); infoPanel.add(new JLabel("MRU size")); mru_size_label = new JLabel(); infoPanel.add(mru_size_label); infoPanel.add(new JLabel("MFU size")); mfu_size_label = new JLabel(); infoPanel.add(mfu_size_label); infoPanel.setBorder(BorderFactory.createTitledBorder("Statistics")); cacheByListPanel.add(cp1a); cacheByListPanel.add(cp1b); cacheHitByTypePanel.add(cp2a); cacheHitByTypePanel.add(cp2b); cacheMissByTypePanel.add(cp3a); cacheMissByTypePanel.add(cp3b); add(infoPanel); add(hitPanel); add(cacheByListPanel); add(cacheHitByTypePanel); add(cacheMissByTypePanel); SpringUtilities.makeCompactGrid(this, 5, 1, 3, 3, 3, 3); update(); startLoop(); }
From source file:de.tbuchloh.kiskis.gui.SecuredElementView.java
private Component createStatisticTab() { final JPanel panel = new JPanel(new SpringLayout()); // Creation and last change panel.add(createLabel(M.getString("created_label"))); //$NON-NLS-1$ Date time = _element.getCreationDate().getTime(); panel.add(new JLabel(LONG_DATE.format(time))); panel.add(createLabel(M.getString("changed_label"))); //$NON-NLS-1$ time = _element.getLastChangeDate().getTime(); panel.add(new JLabel(LONG_DATE.format(time))); panel.add(createLabel(M.getString("lastViewed.label"))); //$NON-NLS-1$ time = _element.getLastViewedDate().getTime(); final Object[] p = { LONG_DATE.format(time), new Integer(_element.getViewCounter()) }; panel.add(new JLabel(M.format("lastViewed.text", p))); //$NON-NLS-1$ SpringUtilities.makeCompactGrid(panel, 3, 2, 25, 25, 25, 25); return panel; }