private static Integer getMinSliderValue(JSlider slider) { Dictionary dictionary = slider.getLabelTable(); if (dictionary != null) { Enumeration keys = dictionary.keys(); int min = slider.getMaximum() + 1; while (keys.hasMoreElements()) { min = Math.min(min, ((Integer) keys.nextElement()).intValue()); } if (min == slider.getMaximum() + 1) { return null; } return new Integer(min); } return null; }
public void getPropertyComponents(List comps, final ObjectListener listener) { visibleCbx = new JCheckBox(getName(), visible); float[] rgb = color.get().getRGBComponents(null); slider = new JSlider(0, 100, (int) (rgb[0] * 100)); float[] xyz = new float[3]; direction.get(xyz); directionXFld = makeField("" + xyz[0], listener, "X Direction"); directionYFld = makeField("" + xyz[1], listener, "Y Direction"); directionZFld = makeField("" + xyz[2], listener, "Z Direction"); double[] pxyz = new double[3]; location.get(pxyz); locationXFld = makeField("" + pxyz[0], listener, ""); locationYFld = makeField("" + pxyz[1], listener, ""); locationZFld = makeField("" + pxyz[2], listener, ""); List fldComps = Misc.newList(GuiUtils.rLabel("Direction:"), directionXFld, directionYFld, directionZFld); // // fldComps.addAll(Misc.newList(GuiUtils.rLabel("Location:"),locationXFld,locationYFld,locationZFld)); comps.add(visibleCbx); GuiUtils.tmpInsets = new Insets(0, 2, 0, 0); comps.add( GuiUtils.vbox( slider, GuiUtils.left(GuiUtils.doLayout(fldComps, 4, GuiUtils.WT_N, GuiUtils.WT_N)))); if (listener != null) { visibleCbx.addActionListener(listener); slider.addChangeListener(listener); } }
public void setColor(Color3f value, boolean updateGui) { setColor(value); if (updateGui && slider != null) { float[] rgb = getColor().get().getRGBComponents(null); int sliderValue = (int) (100 * rgb[0]); slider.setValue(sliderValue); } }
public void applyProperties() { visible = visibleCbx.isSelected(); float f = (float) (slider.getValue() / 100.0f); color = new Color3f(f, f, f); location = new Point3d( new Double(locationXFld.getText()).doubleValue(), new Double(locationYFld.getText()).doubleValue(), new Double(locationZFld.getText()).doubleValue()); direction = new Vector3f( new Float(directionXFld.getText()).floatValue(), new Float(directionYFld.getText()).floatValue(), new Float(directionZFld.getText()).floatValue()); updateLight(); }
protected JPanel makeDetailHintControlPanel() { JPanel controlPanel = new JPanel(new BorderLayout(0, 10)); controlPanel.setBorder( new CompoundBorder( BorderFactory.createEmptyBorder(9, 9, 9, 9), new TitledBorder("Detail Hint"))); JPanel elevationSliderPanel = new JPanel(new BorderLayout(0, 5)); { int MIN = -10; int MAX = 10; int cur = 0; JSlider slider = new JSlider(MIN, MAX, cur); slider.setMajorTickSpacing(10); slider.setMinorTickSpacing(1); slider.setPaintTicks(true); Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>(); labelTable.put(-10, new JLabel("-1.0")); labelTable.put(0, new JLabel("0.0")); labelTable.put(10, new JLabel("1.0")); slider.setLabelTable(labelTable); slider.setPaintLabels(true); slider.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { double hint = ((JSlider) e.getSource()).getValue() / 10d; setWedgeDetailHint(hint); getWwd().redraw(); } }); elevationSliderPanel.add(slider, BorderLayout.SOUTH); } JPanel sliderPanel = new JPanel(new GridLayout(2, 0)); sliderPanel.add(elevationSliderPanel); controlPanel.add(sliderPanel, BorderLayout.SOUTH); return controlPanel; }
private void makeComponents() { this.getWwd().setPreferredSize(new Dimension(1024, 768)); JPanel panel = new JPanel(new BorderLayout()); { panel.setBorder(new EmptyBorder(10, 0, 10, 0)); JPanel controlPanel = new JPanel(new BorderLayout(0, 10)); controlPanel.setBorder(new EmptyBorder(20, 10, 20, 10)); JPanel btnPanel = new JPanel(new GridLayout(5, 1, 0, 5)); { JButton btn = new JButton("Zoom to Matterhorn"); btn.setActionCommand(ACTION_COMMAND_BUTTON1); btn.addActionListener(this.controller); btnPanel.add(btn); btn = new JButton("DEMO getElevations()"); btn.setActionCommand(ACTION_COMMAND_BUTTON2); btn.addActionListener(this.controller); btnPanel.add(btn); btn = new JButton("DEMO getElevation()"); btn.setActionCommand(ACTION_COMMAND_BUTTON3); btn.addActionListener(this.controller); btnPanel.add(btn); btn = new JButton("DEMO new getElevations"); btn.setActionCommand(ACTION_COMMAND_BUTTON4); btn.addActionListener(this.controller); btnPanel.add(btn); // btn = new JButton("Button 5"); // btn.setActionCommand(ACTION_COMMAND_BUTTON5); // btn.addActionListener(this.controller); // btnPanel.add(btn); } controlPanel.add(btnPanel, BorderLayout.NORTH); JPanel vePanel = new JPanel(new BorderLayout(0, 5)); { JLabel label = new JLabel("Vertical Exaggeration"); vePanel.add(label, BorderLayout.NORTH); int MIN_VE = 1; int MAX_VE = 8; int curVe = (int) this.getWwd().getSceneController().getVerticalExaggeration(); curVe = curVe < MIN_VE ? MIN_VE : (curVe > MAX_VE ? MAX_VE : curVe); JSlider slider = new JSlider(MIN_VE, MAX_VE, curVe); slider.setMajorTickSpacing(1); slider.setPaintTicks(true); slider.setSnapToTicks(true); Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>(); labelTable.put(1, new JLabel("1x")); labelTable.put(2, new JLabel("2x")); labelTable.put(4, new JLabel("4x")); labelTable.put(8, new JLabel("8x")); slider.setLabelTable(labelTable); slider.setPaintLabels(true); slider.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { double ve = ((JSlider) e.getSource()).getValue(); ActionEvent ae = new ActionEvent(ve, 0, ACTION_COMMAND_VERTICAL_EXAGGERATION); controller.actionPerformed(ae); } }); vePanel.add(slider, BorderLayout.SOUTH); } controlPanel.add(vePanel, BorderLayout.SOUTH); panel.add(controlPanel, BorderLayout.SOUTH); this.layerPanel = new LayerPanel(this.getWwd(), null); panel.add(this.layerPanel, BorderLayout.CENTER); } getContentPane().add(panel, BorderLayout.WEST); }
public ImageLabFrame() { // Set up menus JMenuBar menuBar = new JMenuBar(); JMenu imageLabMenu = new JMenu("imageLab"); menuBar.add(imageLabMenu); aboutItem = new JMenuItem("About imageLab"); imageLabMenu.add(aboutItem); quitItem = new JMenuItem("Quit"); imageLabMenu.add(quitItem); JMenu fileMenu = new JMenu("File"); menuBar.add(fileMenu); openItem = new JMenuItem("Open File..."); fileMenu.add(openItem); saveItem = new JMenuItem("Save As..."); fileMenu.add(saveItem); JMenu imageMenu = new JMenu("Images"); menuBar.add(imageMenu); addPictureGenerator(imageMenu, new Stripe()); JMenu filterMenu = new JMenu("Filters"); menuBar.add(filterMenu); addFilter(filterMenu, new BWFilter()); filterMenu.addSeparator(); addScalableFilter(filterMenu, new SwirlFilter()); // Listeners for filters are added in addScalableFilter aboutItem.addActionListener(this); quitItem.addActionListener(this); openItem.addActionListener(this); saveItem.addActionListener(this); // Set up rest of GUI lab = initialImage().getJLabel(); slider = new JSlider(0, 100); sliderPanel = new JPanel(); sliderPanel.add(slider); sliderPanel.setVisible(false); Border b1 = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED); border = BorderFactory.createTitledBorder(b1, ""); sliderPanel.setBorder(border); slider.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { double scale = (slider.getValue() - 50) / 50.0; currentFilter.apply(pic1, pic2, scale); lab.setIcon(pic2.getJLabel().getIcon()); repaint(); } }); JPanel panel = new JPanel(new BorderLayout()); getContentPane().add(panel); panel.add(lab, BorderLayout.NORTH); panel.add(sliderPanel, BorderLayout.SOUTH); setJMenuBar(menuBar); pack(); setTitle("imageLab"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Prepare file chooser chooser = new JFileChooser(new File(".")); FileNameExtensionFilter filter = new FileNameExtensionFilter("JPG Images", "jpg"); chooser.setFileFilter(filter); }
private static int getSliderBaseline(JSlider slider, int height) { // We don't handle GTK as too much is hidden to be able to calculate it if (slider.getPaintLabels() && !isGTK()) { boolean isAqua = isAqua(); FontMetrics metrics = slider.getFontMetrics(slider.getFont()); Insets insets = slider.getInsets(); Insets focusInsets = (Insets) UIManager.get("Slider.focusInsets"); if (slider.getOrientation() == JSlider.HORIZONTAL) { int tickLength = 8; int contentHeight = height - insets.top - insets.bottom - focusInsets.top - focusInsets.bottom; int thumbHeight = 20; if (isMetal()) { tickLength = ((Integer) UIManager.get("Slider.majorTickLength")).intValue() + 5; thumbHeight = UIManager.getIcon("Slider.horizontalThumbIcon").getIconHeight(); } else if (isWindows() && isXP()) { // NOTE: this is not correct, this should come from // the skin (in >= 1.5), but short of reflection // hacks we don't have access to the real value. thumbHeight++; } int centerSpacing = thumbHeight; if (isAqua || slider.getPaintTicks()) { // centerSpacing += getTickLength(); centerSpacing += tickLength; } // Assume uniform labels. centerSpacing += metrics.getAscent() + metrics.getDescent(); int trackY = insets.top + focusInsets.top + (contentHeight - centerSpacing - 1) / 2; if (isAqua) { if (slider.getPaintTicks()) { int prefHeight = slider.getUI().getPreferredSize(slider).height; int prefDelta = height - prefHeight; if (prefDelta > 0) { trackY -= Math.min(1, prefDelta); } } else { trackY--; } } int trackHeight = thumbHeight; int tickY = trackY + trackHeight; int tickHeight = tickLength; if (!isAqua && !slider.getPaintTicks()) { tickHeight = 0; } int labelY = tickY + tickHeight; return labelY + metrics.getAscent(); } else { // vertical boolean inverted = slider.getInverted(); Integer value = inverted ? getMinSliderValue(slider) : getMaxSliderValue(slider); if (value != null) { int thumbHeight = 11; if (isMetal()) { thumbHeight = UIManager.getIcon("Slider.verticalThumbIcon").getIconHeight(); } int trackBuffer = Math.max(metrics.getHeight() / 2, thumbHeight / 2); int contentY = focusInsets.top + insets.top; int trackY = contentY + trackBuffer; int trackHeight = height - focusInsets.top - focusInsets.bottom - insets.top - insets.bottom - trackBuffer - trackBuffer; int maxValue = getMaxSliderValue(slider).intValue(); int min = slider.getMinimum(); int max = slider.getMaximum(); double valueRange = (double) max - (double) min; double pixelsPerValue = (double) trackHeight / (double) valueRange; int trackBottom = trackY + (trackHeight - 1); if (isAqua) { trackY -= 3; trackBottom += 6; } int yPosition = trackY; double offset; if (!inverted) { offset = pixelsPerValue * ((double) max - value.intValue()); } else { offset = pixelsPerValue * ((double) value.intValue() - min); } if (isAqua) { yPosition += Math.floor(offset); } else { yPosition += Math.round(offset); } yPosition = Math.max(trackY, yPosition); yPosition = Math.min(trackBottom, yPosition); if (isAqua) { return yPosition + metrics.getAscent(); } return yPosition - metrics.getHeight() / 2 + metrics.getAscent(); } } } return -1; }