/** * Called to set the URL to browse, and reset the scrollbars. * * @param url indicates document to view. * @throws IOException if an error occures */ public void setURL(final URL url) throws IOException { final URL old = getURL(); super.setURL(url); if (old == null) { // bcr getImageWait().setBufferMode(DjVuImage.COMPLETE_BUFFER); setScrollbar(Scrollbar.HORIZONTAL, new Scrollbar(Scrollbar.HORIZONTAL)); setScrollbar(Scrollbar.VERTICAL, new Scrollbar(Scrollbar.VERTICAL)); hScroll.setUnitIncrement(16); vScroll.setUnitIncrement(16); } }
/** * Adds a slider (scroll bar) to the dialog box. Floating point values will be used if * (maxValue-minValue)<=5.0 and either minValue or maxValue are non-integer. * * @param label the label * @param minValue the minimum value of the slider * @param maxValue the maximum value of the slider * @param defaultValue the initial value of the slider */ public void addSlider(String label, double minValue, double maxValue, double defaultValue) { if (defaultValue < minValue) defaultValue = minValue; if (defaultValue > maxValue) defaultValue = maxValue; int columns = 4; int digits = 0; double scale = 1.0; if ((maxValue - minValue) <= 5.0 && (minValue != (int) minValue || maxValue != (int) maxValue || defaultValue != (int) defaultValue)) { scale = 20.0; minValue *= scale; maxValue *= scale; defaultValue *= scale; digits = 2; } String label2 = label; if (label2.indexOf('_') != -1) label2 = label2.replace('_', ' '); Label theLabel = makeLabel(label2); c.gridx = 0; c.gridy = y; c.anchor = GridBagConstraints.EAST; c.gridwidth = 1; c.insets = new Insets(0, 0, 3, 0); grid.setConstraints(theLabel, c); add(theLabel); if (slider == null) { slider = new Vector(5); sliderIndexes = new int[MAX_SLIDERS]; sliderScales = new double[MAX_SLIDERS]; } Scrollbar s = new Scrollbar( Scrollbar.HORIZONTAL, (int) defaultValue, 1, (int) minValue, (int) maxValue + 1); GUI.fix(s); slider.addElement(s); s.addAdjustmentListener(this); s.setUnitIncrement(1); if (numberField == null) { numberField = new Vector(5); defaultValues = new Vector(5); defaultText = new Vector(5); } if (IJ.isWindows()) columns -= 2; if (columns < 1) columns = 1; TextField tf = new TextField(IJ.d2s(defaultValue / scale, digits), columns); if (IJ.isLinux()) tf.setBackground(Color.white); tf.addActionListener(this); tf.addTextListener(this); tf.addFocusListener(this); tf.addKeyListener(this); numberField.addElement(tf); sliderIndexes[slider.size() - 1] = numberField.size() - 1; sliderScales[slider.size() - 1] = scale; defaultValues.addElement(new Double(defaultValue / scale)); defaultText.addElement(tf.getText()); tf.setEditable(true); firstSlider = false; Panel panel = new Panel(); GridBagLayout pgrid = new GridBagLayout(); GridBagConstraints pc = new GridBagConstraints(); panel.setLayout(pgrid); pc.gridx = 0; pc.gridy = 0; pc.gridwidth = 1; pc.ipadx = 85; pc.anchor = GridBagConstraints.WEST; pgrid.setConstraints(s, pc); panel.add(s); pc.ipadx = 0; // reset // text field pc.gridx = 1; pc.insets = new Insets(5, 5, 0, 0); pc.anchor = GridBagConstraints.EAST; pgrid.setConstraints(tf, pc); panel.add(tf); grid.setConstraints(panel, c); c.gridx = 1; c.gridy = y; c.gridwidth = 1; c.anchor = GridBagConstraints.WEST; c.insets = new Insets(0, 0, 0, 0); grid.setConstraints(panel, c); add(panel); y++; if (Recorder.record || macro) saveLabel(tf, label); }
/** Création de l'intérieur de la fenêtre */ private void initConteneur() { // le fond fond = getToolkit().getImage("./images/preference/bomber_fond.gif"); tracker = new MediaTracker(this); tracker.addImage(fond, 0); try { tracker.waitForID(0); } catch (Exception a) { System.out.println("Erreur lors chargement de l'image: initConteneur() Preference"); a.printStackTrace(); } // le layout manager GridBagLayout layout = new GridBagLayout(); setLayout(layout); GridBagConstraints c = new GridBagConstraints(); c.weightx = 10; c.weighty = 10; c.ipadx = 10; c.ipady = 10; c.fill = GridBagConstraints.BOTH; // label "Joueurs:" Label lbl_joueurs = new Label("Joueurs:"); lbl_joueurs.setAlignment(Label.CENTER); lbl_joueurs.setFont(new Font("SansSerif", Font.BOLD, 16)); lbl_joueurs.setBackground(Color.black); lbl_joueurs.setForeground(Color.red); c.gridx = 0; c.gridy = 0; c.gridwidth = 6; c.gridheight = 1; c.insets = new Insets(20, 10, 10, 10); c.anchor = GridBagConstraints.SOUTH; layout.setConstraints(lbl_joueurs, c); add(lbl_joueurs); // choix de couleur du joueur ayant l'identifiant 0 choix_couleur0 = new Choice(); choix_couleur0.addItem("rouge"); choix_couleur0.addItem("bleu"); choix_couleur0.addItemListener(this); choix_couleur0.setBackground(Color.red); choix_couleur0.setForeground(Color.black); c.gridx = 0; c.gridy = 1; c.gridwidth = 2; c.gridheight = 1; c.insets = new Insets(10, 10, 5, 20); c.anchor = GridBagConstraints.EAST; layout.setConstraints(choix_couleur0, c); add(choix_couleur0); // nom du joueur ayant l'identifiant 0 txt_joueur0 = new TextField(noms[0]); c.gridx = 2; c.gridy = 1; c.gridwidth = 4; c.gridheight = 1; c.insets = new Insets(10, 10, 5, 20); c.anchor = GridBagConstraints.WEST; layout.setConstraints(txt_joueur0, c); add(txt_joueur0); // choix de couleur du joueur ayant l'identifiant 1 choix_couleur1 = new Choice(); choix_couleur1.addItem("bleu"); choix_couleur1.addItem("rouge"); choix_couleur1.addItemListener(this); choix_couleur1.setBackground(Color.blue); choix_couleur1.setForeground(Color.black); c.gridx = 0; c.gridy = 2; c.gridwidth = 2; c.gridheight = 1; c.insets = new Insets(10, 10, 20, 20); c.anchor = GridBagConstraints.EAST; layout.setConstraints(choix_couleur1, c); add(choix_couleur1); // nom du joueur ayant l'identifiant 1 txt_joueur1 = new TextField(noms[1]); c.gridx = 2; c.gridy = 2; c.gridwidth = 4; c.gridheight = 1; c.insets = new Insets(10, 10, 30, 20); c.anchor = GridBagConstraints.WEST; layout.setConstraints(txt_joueur1, c); add(txt_joueur1); // label "Nombre De Vies:" Label lbl_nbvies = new Label("Nombre De Vies:"); lbl_nbvies.setAlignment(Label.CENTER); lbl_nbvies.setFont(new Font("SansSerif", Font.BOLD, 14)); lbl_nbvies.setBackground(Color.black); lbl_nbvies.setForeground(Color.yellow); c.gridx = 0; c.gridy = 4; c.gridwidth = 1; c.gridheight = 1; c.insets = new Insets(20, 10, 5, 10); c.anchor = GridBagConstraints.CENTER; layout.setConstraints(lbl_nbvies, c); add(lbl_nbvies); // un choix possible cbg_vies = new CheckboxGroup(); Checkbox cb; for (int i = 1; i <= 5; i++) { if (i == nb_vies) cb = new Checkbox("" + i, cbg_vies, true); else cb = new Checkbox("" + i, cbg_vies, false); c.gridx = i; c.gridy = 4; c.gridwidth = 1; c.gridheight = 1; c.insets = new Insets(20, 10, 5, 10); c.anchor = GridBagConstraints.CENTER; layout.setConstraints(cb, c); add(cb); } // for // label "Nombre De Victoires:" lbl_victoires = new Label(); lbl_victoires.setAlignment(Label.CENTER); lbl_victoires.setFont(new Font("SansSerif", Font.BOLD, 14)); lbl_victoires.setText("Nombre De Victoires: " + nb_victoires); lbl_victoires.setBackground(Color.black); lbl_victoires.setForeground(Color.green); c.gridx = 0; c.gridy = 6; c.gridwidth = 1; c.gridheight = 1; c.insets = new Insets(20, 10, 5, 10); c.anchor = GridBagConstraints.CENTER; layout.setConstraints(lbl_victoires, c); add(lbl_victoires); // choix du nombre de victoires entre un 1 et 9 sb_victoires = new Scrollbar(Scrollbar.HORIZONTAL, 1, 1, 1, 10); sb_victoires.setUnitIncrement(1); sb_victoires.setBlockIncrement(2); sb_victoires.addAdjustmentListener(this); sb_victoires.setValue(nb_victoires); c.gridx = 1; c.gridy = 6; c.gridwidth = 5; c.gridheight = 1; c.insets = new Insets(20, 10, 5, 10); c.anchor = GridBagConstraints.CENTER; layout.setConstraints(sb_victoires, c); add(sb_victoires); // tirage aléatoire des niveaux cb_aleatoire = new Checkbox("Niveaux Aléatoires", aleatoire); cb_aleatoire.setFont(new Font("SansSerif", Font.BOLD, 14)); cb_aleatoire.setBackground(Color.black); cb_aleatoire.setForeground(Color.magenta); c.gridx = 0; c.gridy = 8; c.gridwidth = 1; c.gridheight = 1; c.insets = new Insets(20, 12, 5, 10); c.anchor = GridBagConstraints.EAST; layout.setConstraints(cb_aleatoire, c); add(cb_aleatoire); // label "FPS:" nombre de frames par seconde lbl_fps = new Label(); lbl_fps.setAlignment(Label.CENTER); lbl_fps.setFont(new Font("SansSerif", Font.BOLD, 14)); lbl_fps.setText("FPS: " + fps); lbl_fps.setBackground(Color.black); lbl_fps.setForeground(Color.orange); c.gridx = 0; c.gridy = 10; c.gridwidth = 1; c.gridheight = 1; c.insets = new Insets(20, 10, 5, 10); c.anchor = GridBagConstraints.CENTER; layout.setConstraints(lbl_fps, c); add(lbl_fps); // choix du nombre de frames par seconde sb_fps = new Scrollbar(Scrollbar.HORIZONTAL, 1, 1, 1, 51); sb_fps.setUnitIncrement(1); sb_fps.setBlockIncrement(10); sb_fps.addAdjustmentListener(this); sb_fps.setValue(fps); c.gridx = 1; c.gridy = 10; c.gridwidth = 5; c.gridheight = 1; c.insets = new Insets(20, 10, 5, 10); c.anchor = GridBagConstraints.CENTER; layout.setConstraints(sb_fps, c); add(sb_fps); // bouton de confirmation button_ok = new Button("Ok"); c.gridx = 0; c.gridy = 12; c.gridwidth = 6; c.gridheight = 1; c.insets = new Insets(20, 5, 20, 5); c.anchor = GridBagConstraints.CENTER; layout.setConstraints(button_ok, c); add(button_ok); button_ok.addActionListener(this); } // initConteneur()
public BandAdjuster() { super("Threshold Colour"); if (instance != null) { instance.toFront(); return; } imp = WindowManager.getCurrentImage(); if (imp == null) { IJ.beep(); IJ.showStatus("No image"); return; } IJ.run("Select None"); thread = new Thread(this, "BandAdjuster"); WindowManager.addWindow(this); instance = this; IJ.register(PasteController.class); ij = IJ.getInstance(); Font font = new Font("SansSerif", Font.PLAIN, 10); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); setLayout(gridbag); int y = 0; c.gridx = 0; c.gridy = y; c.gridwidth = 1; c.weightx = 0; c.insets = new Insets(5, 0, 0, 0); labelh = new Label("Hue", Label.CENTER); add(labelh, c); c.gridx = 1; c.gridy = y++; c.gridwidth = 1; c.weightx = 0; c.insets = new Insets(7, 0, 0, 0); labelf = new Label("Filter type", Label.RIGHT); add(labelf, c); // plot c.gridx = 0; c.gridy = y; c.gridwidth = 1; c.fill = c.BOTH; c.anchor = c.CENTER; c.insets = new Insets(0, 5, 0, 0); add(plot, c); // checkboxes panelh = new Panel(); filterTypeH = new CheckboxGroup(); bandPassH = new Checkbox("Pass"); bandPassH.setCheckboxGroup(filterTypeH); bandPassH.addItemListener(this); panelh.add(bandPassH); bandStopH = new Checkbox("Stop"); bandStopH.setCheckboxGroup(filterTypeH); bandStopH.addItemListener(this); panelh.add(bandStopH); bandPassH.setState(true); c.gridx = 1; c.gridy = y++; c.gridwidth = 2; c.insets = new Insets(5, 0, 0, 0); add(panelh, c); // minHue slider minSlider = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, sliderRange); c.gridx = 0; c.gridy = y++; c.gridwidth = 1; c.weightx = IJ.isMacintosh() ? 90 : 100; c.fill = c.HORIZONTAL; c.insets = new Insets(5, 5, 0, 0); add(minSlider, c); minSlider.addAdjustmentListener(this); minSlider.setUnitIncrement(1); // minHue slider label c.gridx = 1; c.gridwidth = 1; c.weightx = IJ.isMacintosh() ? 10 : 0; c.insets = new Insets(5, 0, 0, 0); label1 = new Label(" ", Label.LEFT); label1.setFont(font); add(label1, c); // maxHue sliderHue maxSlider = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, sliderRange); c.gridx = 0; c.gridy = y; c.gridwidth = 1; c.weightx = 100; c.insets = new Insets(5, 5, 0, 0); add(maxSlider, c); maxSlider.addAdjustmentListener(this); maxSlider.setUnitIncrement(1); // maxHue slider label c.gridx = 1; c.gridwidth = 1; c.gridy = y++; c.weightx = 0; c.insets = new Insets(5, 0, 0, 0); label2 = new Label(" ", Label.LEFT); label2.setFont(font); add(label2, c); // ===== c.gridx = 0; c.gridy = y++; c.gridwidth = 1; c.weightx = 0; c.insets = new Insets(10, 0, 0, 0); labels = new Label("Saturation", Label.CENTER); add(labels, c); // plot c.gridx = 0; c.gridy = y; c.gridwidth = 1; c.fill = c.BOTH; c.anchor = c.CENTER; c.insets = new Insets(0, 5, 0, 0); add(splot, c); // checkboxes panels = new Panel(); filterTypeS = new CheckboxGroup(); bandPassS = new Checkbox("Pass"); bandPassS.setCheckboxGroup(filterTypeS); bandPassS.addItemListener(this); panels.add(bandPassS); bandStopS = new Checkbox("Stop"); bandStopS.setCheckboxGroup(filterTypeS); bandStopS.addItemListener(this); panels.add(bandStopS); bandPassS.setState(true); c.gridx = 1; c.gridy = y++; c.gridwidth = 2; c.insets = new Insets(5, 0, 0, 0); add(panels, c); // minSat slider minSlider2 = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, sliderRange); c.gridx = 0; c.gridy = y++; c.gridwidth = 1; c.weightx = IJ.isMacintosh() ? 90 : 100; c.fill = c.HORIZONTAL; c.insets = new Insets(5, 5, 0, 0); add(minSlider2, c); minSlider2.addAdjustmentListener(this); minSlider2.setUnitIncrement(1); // minSat slider label c.gridx = 1; c.gridwidth = 1; c.weightx = IJ.isMacintosh() ? 10 : 0; c.insets = new Insets(5, 0, 0, 0); label3 = new Label(" ", Label.LEFT); label3.setFont(font); add(label3, c); // maxSat slider maxSlider2 = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, sliderRange); c.gridx = 0; c.gridy = y++; c.gridwidth = 1; c.weightx = 100; c.insets = new Insets(5, 5, 0, 0); add(maxSlider2, c); maxSlider2.addAdjustmentListener(this); maxSlider2.setUnitIncrement(1); // maxSat slider label c.gridx = 1; c.gridwidth = 1; c.weightx = 0; c.insets = new Insets(5, 0, 0, 0); label4 = new Label(" ", Label.LEFT); label4.setFont(font); add(label4, c); // ===== c.gridx = 0; c.gridwidth = 1; c.gridy = y++; c.weightx = 0; c.insets = new Insets(10, 0, 0, 0); labelb = new Label("Brightness", Label.CENTER); add(labelb, c); c.gridx = 0; c.gridwidth = 1; c.gridy = y; c.fill = c.BOTH; c.anchor = c.CENTER; c.insets = new Insets(0, 5, 0, 0); add(bplot, c); // checkboxes panelb = new Panel(); filterTypeB = new CheckboxGroup(); bandPassB = new Checkbox("Pass"); bandPassB.setCheckboxGroup(filterTypeB); bandPassB.addItemListener(this); panelb.add(bandPassB); bandStopB = new Checkbox("Stop"); bandStopB.setCheckboxGroup(filterTypeB); bandStopB.addItemListener(this); panelb.add(bandStopB); bandPassB.setState(true); c.gridx = 1; c.gridy = y++; c.gridwidth = 2; c.insets = new Insets(5, 0, 0, 0); add(panelb, c); // minBri slider minSlider3 = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, sliderRange); c.gridx = 0; c.gridy = y++; c.gridwidth = 1; c.weightx = IJ.isMacintosh() ? 90 : 100; c.fill = c.HORIZONTAL; c.insets = new Insets(5, 5, 0, 0); add(minSlider3, c); minSlider3.addAdjustmentListener(this); minSlider3.setUnitIncrement(1); // minBri slider label c.gridx = 1; c.gridwidth = 1; c.weightx = IJ.isMacintosh() ? 10 : 0; c.insets = new Insets(5, 0, 0, 0); label5 = new Label(" ", Label.LEFT); label5.setFont(font); add(label5, c); // maxBri slider maxSlider3 = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, sliderRange); c.gridx = 0; c.gridy = y++; c.gridwidth = 1; c.weightx = 100; c.insets = new Insets(5, 5, 0, 0); add(maxSlider3, c); maxSlider3.addAdjustmentListener(this); maxSlider3.setUnitIncrement(1); // maxBri slider label c.gridx = 1; c.gridwidth = 1; c.weightx = 0; c.insets = new Insets(5, 0, 0, 0); label6 = new Label(" ", Label.LEFT); label6.setFont(font); add(label6, c); // ===== panelt = new Panel(); threshold = new Checkbox("Threshold"); threshold.addItemListener(this); panelt.add(threshold); invert = new Checkbox("Invert"); invert.addItemListener(this); panelt.add(invert); c.gridx = 0; c.gridy = y++; c.gridwidth = 2; c.insets = new Insets(0, 0, 0, 0); add(panelt, c); // buttons panel = new Panel(); // panel.setLayout(new GridLayout(2, 2, 0, 0)); originalB = new Button("Original"); originalB.setEnabled(false); originalB.addActionListener(this); originalB.addKeyListener(ij); panel.add(originalB); filteredB = new Button("Filtered"); filteredB.setEnabled(false); filteredB.addActionListener(this); filteredB.addKeyListener(ij); panel.add(filteredB); stackB = new Button("Stack"); stackB.addActionListener(this); stackB.addKeyListener(ij); panel.add(stackB); helpB = new Button("Help"); helpB.addActionListener(this); helpB.addKeyListener(ij); panel.add(helpB); c.gridx = 0; c.gridy = y++; c.gridwidth = 2; c.insets = new Insets(0, 0, 0, 0); add(panel, c); panelMode = new Panel(); sampleB = new Button("Sample"); sampleB.addActionListener(this); sampleB.addKeyListener(ij); panelMode.add(sampleB); colourMode = new CheckboxGroup(); hsb = new Checkbox("HSB"); hsb.setCheckboxGroup(colourMode); hsb.addItemListener(this); panelMode.add(hsb); hsb.setState(true); rgb = new Checkbox("RGB"); rgb.setCheckboxGroup(colourMode); rgb.addItemListener(this); panelMode.add(rgb); c.gridx = 0; c.gridy = y++; c.gridwidth = 2; c.insets = new Insets(0, 0, 0, 0); add(panelMode, c); addKeyListener(ij); // ImageJ handles keyboard shortcuts pack(); GUI.center(this); setVisible(true); ip = setup(imp); if (ip == null) { imp.unlock(); IJ.beep(); IJ.showStatus("RGB image cannot be thresholded"); return; } thread.start(); }