Example usage for javax.swing JSlider createStandardLabels

List of usage examples for javax.swing JSlider createStandardLabels

Introduction

In this page you can find the example usage for javax.swing JSlider createStandardLabels.

Prototype

public Hashtable<Integer, JComponent> createStandardLabels(int increment) 

Source Link

Document

Creates a Hashtable of numerical text labels, starting at the slider minimum, and using the increment specified.

Usage

From source file:Presentation.MainWindow.java

private void addSlider() {
    JSlider sliderTemp = new JSlider(12, 26, 26);
    sliderTemp.setLabelTable(sliderTemp.createStandardLabels(14));
    sliderTemp.setMinorTickSpacing(1);/*from  w  ww.  ja v  a 2s.c  o  m*/
    sliderTemp.setPaintLabels(true);
    sliderTemp.setPaintTicks(true);
    this.tSlider = sliderTemp;
    Label labelConsigne = new Label("Temprature de consigne : " + tSlider.getValue() + " C");
    //Label labelOutdoorTemp = new Label(Singleton.getInstance().getAcquisition().getOutdoorTemp());
    this.tLabel = labelConsigne;
    mPanel.add(labelConsigne);
    mPanel.add(sliderTemp);
}

From source file:Main.java

public Main() {
    setLayout(new BorderLayout());
    JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 50, 25);

    slider.setMinorTickSpacing(2);/*www.  ja v a2s . c  o m*/
    slider.setMajorTickSpacing(10);
    slider.setPaintTicks(true);
    slider.setPaintLabels(true);

    slider.setInverted(false);

    // We'll just use the standard numeric labels for now...
    slider.setLabelTable(slider.createStandardLabels(10));

    add(slider, BorderLayout.CENTER);
}

From source file:Main.java

public Main() {
    setLayout(new BorderLayout());
    JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 50, 25);

    slider.setMinorTickSpacing(2);/*  w w  w  .  ja v a  2s  .c o  m*/
    slider.setMajorTickSpacing(10);
    slider.setPaintTicks(true);
    slider.setPaintLabels(true);

    slider.setOrientation(JSlider.VERTICAL);
    slider.setInverted(true);

    // We'll just use the standard numeric labels for now...
    slider.setLabelTable(slider.createStandardLabels(10));

    add(slider, BorderLayout.CENTER);
}

From source file:Main.java

public Main() {
    setLayout(new BorderLayout());
    JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 50, 25);

    slider.setMinorTickSpacing(2);//from   w w  w. j av a2s . c  om
    slider.setMajorTickSpacing(10);
    slider.setPaintTicks(true);
    slider.setPaintLabels(true);

    slider.setOrientation(JSlider.VERTICAL);
    slider.setInverted(false);

    // We'll just use the standard numeric labels for now...
    slider.setLabelTable(slider.createStandardLabels(10));

    add(slider, BorderLayout.CENTER);
}

From source file:com.imag.nespros.gui.plugin.GraphEditor.java

/**
 * create an instance of a simple graph with popup controls to create a
 * graph./*from  ww w  .ja  v  a 2s  .  c  om*/
 *
 */
private GraphEditor(Simulation s) {
    simu = s;
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception ex) {
        Logger.getLogger(GraphEditor.class.getName()).log(Level.SEVERE, null, ex);
    }
    // create a simple graph for the demo
    graph = Topology.getInstance().getGraph();
    this.layout = new StaticLayout<Device, ComLink>(graph, new Transformer<Device, Point2D>() {
        @Override
        public Point2D transform(Device v) {
            Point2D p = new Point2D.Double(v.getX(), v.getY());
            return p;
        }
    }, new Dimension(600, 600));

    vv = new VisualizationViewer<Device, ComLink>(layout);
    vv.setBackground(Color.white);

    final Transformer<Device, String> vertexLabelTransformer = new Transformer<Device, String>() {
        @Override
        public String transform(Device d) {
            return d.getDeviceName();
        }
    };

    //vv.getRenderContext().setVertexLabelTransformer(MapTransformer.<Device, String>getInstance(
    //      LazyMap.<Device, String>decorate(new HashMap<Device, String>(), new ToStringLabeller<Device>())));
    vv.getRenderContext().setVertexLabelTransformer(vertexLabelTransformer);
    vv.getRenderContext().setEdgeLabelTransformer(new Transformer<ComLink, String>() {
        @Override
        public String transform(ComLink link) {
            return (link.getID() + ", " + link.getLatency());
        }
    });
    //float dash[] = {0.1f};
    //final Stroke edgeStroke = new BasicStroke(3.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 1.0f);
    final Stroke edgeStroke = new BasicStroke(3.0f);
    final Transformer<ComLink, Stroke> edgeStrokeTransformer = new Transformer<ComLink, Stroke>() {
        @Override
        public Stroke transform(ComLink l) {
            return edgeStroke;
        }
    };
    Transformer<ComLink, Paint> edgePaint = new Transformer<ComLink, Paint>() {
        public Paint transform(ComLink l) {
            if (l.isDown()) {
                return Color.RED;
            } else {
                return Color.BLACK;
            }
        }
    };
    vv.getRenderContext().setEdgeDrawPaintTransformer(edgePaint);
    vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
    vv.setVertexToolTipTransformer(vv.getRenderContext().getVertexLabelTransformer());
    vv.getRenderContext().setVertexIconTransformer(new CustomVertexIconTransformer());
    vv.getRenderContext().setVertexShapeTransformer(new CustomVertexShapeTransformer());

    vv.addPreRenderPaintable(new VisualizationViewer.Paintable() {

        @Override
        public void paint(Graphics grphcs) {

            for (Device d : Topology.getInstance().getGraph().getVertices()) {
                int size = d.getOperators().size();
                MyLayeredIcon icon = d.getIcon();
                //if(icon == null) continue;
                icon.removeAll();
                if (size > 0) {
                    // the vertex icon                        
                    // Let's create the annotation image to be added to icon..
                    BufferedImage image = new BufferedImage(20, 20, BufferedImage.TYPE_INT_ARGB);
                    Graphics2D g = image.createGraphics();
                    g.setColor(Color.ORANGE);
                    g.fillOval(0, 0, 20, 20);
                    g.setColor(Color.BLACK);
                    g.drawString(size + "", 5, 13);
                    g.dispose();
                    ImageIcon img = new ImageIcon(image);
                    //Dimension id = new Dimension(icon.getIconWidth(), icon.getIconHeight());
                    //double x = vv.getModel().getGraphLayout().transform(d).getX();
                    //x -= (icon.getIconWidth() / 2);
                    //double y = vv.getModel().getGraphLayout().transform(d).getY();
                    //y -= (icon.getIconHeight() / 2);
                    //grphcs.drawImage(image, (int) Math.round(x), (int) Math.round(y), null);
                    icon.add(img);
                }
            }
        }

        @Override
        public boolean useTransform() {
            return false;
        }
    });

    Container content = getContentPane();
    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    content.add(panel);
    Factory<Device> vertexFactory = DeviceFactory.getInstance();
    Factory<ComLink> edgeFactory = ComLinkFactory.getInstance();

    final EditingModalGraphMouse<Device, ComLink> graphMouse = new EditingModalGraphMouse<>(
            vv.getRenderContext(), vertexFactory, edgeFactory);

    // Trying out our new popup menu mouse plugin...
    PopupVertexEdgeMenuMousePlugin myPlugin = new PopupVertexEdgeMenuMousePlugin();
    // Add some popup menus for the edges and vertices to our mouse plugin.
    JPopupMenu edgeMenu = new MyMouseMenus.EdgeMenu(frame);
    JPopupMenu vertexMenu = new MyMouseMenus.VertexMenu(frame);
    myPlugin.setEdgePopup(edgeMenu);
    myPlugin.setVertexPopup(vertexMenu);
    graphMouse.remove(graphMouse.getPopupEditingPlugin()); // Removes the existing popup editing plugin

    graphMouse.add(myPlugin); // Add our new plugin to the mouse  
    // AnnotatingGraphMousePlugin<Device,ComLink> annotatingPlugin =
    //   new AnnotatingGraphMousePlugin<>(vv.getRenderContext());
    //graphMouse.add(annotatingPlugin);
    // the EditingGraphMouse will pass mouse event coordinates to the
    // vertexLocations function to set the locations of the vertices as
    // they are created
    //        graphMouse.setVertexLocations(vertexLocations);
    vv.setGraphMouse(graphMouse);
    vv.addKeyListener(graphMouse.getModeKeyListener());

    graphMouse.setMode(ModalGraphMouse.Mode.PICKING);

    //final ImageAtEdgePainter<String, String> imageAtEdgePainter = 
    //  new ImageAtEdgePainter<String, String>(vv, edge, image);
    final ScalingControl scaler = new CrossoverScalingControl();
    JButton plus = new JButton("+");
    plus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    JButton minus = new JButton("-");
    minus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
        }
    });

    JButton help = new JButton("Help");
    help.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(vv, instructions);
        }
    });
    JButton deploy = new JButton("Deploy");
    deploy.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // OPMapping algo here
            if (simu == null) {
                return;
            }
            GraphUtil<Device, ComLink> util = new GraphUtil<>();
            for (EventProducer p : simu.getProducers()) {
                if (!p.isMapped()) {
                    JOptionPane.showMessageDialog(frame,
                            "Cannot map operators. Please deploy the producer: " + p.getName());
                    return;
                }
            }
            for (EventConsumer c : simu.getConsumers()) {
                if (!c.isMapped()) {
                    JOptionPane.showMessageDialog(frame,
                            "Cannot map operators. Please deploy the consumer: " + c.getName());
                    return;
                }
                System.out.println("-- Operator placement algorithm Greedy: " + c.getName() + " --");
                Solution init = util.initialMapping(c.getGraph());
                System.out.println(c.getGraph() + "\nInitial Mapping: " + init);
                OperatorMapping mapper = new OperatorMapping();
                long T1, T2;
                System.out.println("--- OpMapping Algo Greedy --- ");
                T1 = System.currentTimeMillis();
                Solution solution = mapper.opMapping(c.getGraph(), Topology.getInstance().getGraph(), init);
                T2 = System.currentTimeMillis();
                System.out.println(solution);
                System.out.println("Solution founded in: " + (T2 - T1) + " ms");
            }
            //                Solution init = util.initialMapping(EPGraph.getInstance().getGraph());
            //                System.out.println("Initial Mapping: " + init);
            //                OperatorMapping mapper = new OperatorMapping();
            //                long T1, T2;
            //                System.out.println("--- OpMapping Algo Greedy --- ");
            //                T1 = System.currentTimeMillis();
            //                Solution solution = mapper.opMapping(EPGraph.getInstance().getGraph(),
            //                        Topology.getInstance().getGraph(), init);
            //                T2 = System.currentTimeMillis();
            //                System.out.println(solution);
            //                System.out.println("Solution founded in: " + (T2 - T1) + " ms");
            vv.repaint();
        }
    });
    JButton run = new JButton("Run");
    run.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // run the simulation here
            System.out.println("Setting the simulation...");
            for (EventConsumer c : simu.getConsumers()) {

                for (EPUnit op : c.getGraph().getVertices()) {
                    if (op.isMapped()) {
                        op.openIOchannels();
                    } else {
                        JOptionPane.showMessageDialog(frame, "Cannot run, undeployed operators founded.");
                        return;
                    }
                }
            }
            //ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
            System.out.println("Running the simulation...");
            //scheduledExecutorService.execute(runner);
            for (Device device : Topology.getInstance().getGraph().getVertices()) {
                if (!device.isAlive()) {
                    device.start();
                }
            }
            for (ComLink link : Topology.getInstance().getGraph().getEdges()) {
                if (!link.isAlive()) {
                    link.start();
                }
            }
            for (EventConsumer c : simu.getConsumers()) {
                for (EPUnit op : c.getGraph().getVertices()) {
                    if (op.isMapped() && op.getDevice() != null && !op.isAlive()) {
                        op.start();
                    }
                }
            }

        }
    });
    AnnotationControls<Device, ComLink> annotationControls = new AnnotationControls<Device, ComLink>(
            graphMouse.getAnnotatingPlugin());
    JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 30, 0);
    slider.setMinorTickSpacing(5);
    slider.setMajorTickSpacing(30);
    slider.setPaintTicks(true);
    slider.setPaintLabels(true);
    slider.setLabelTable(slider.createStandardLabels(15));
    slider.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            JSlider slider = (JSlider) e.getSource();
            if (!slider.getValueIsAdjusting()) {
                speedSimulation(slider.getValue());
            }
        }
    });
    JPanel controls = new JPanel();
    controls.add(plus);
    controls.add(minus);
    JComboBox modeBox = graphMouse.getModeComboBox();
    controls.add(modeBox);
    controls.add(annotationControls.getAnnotationsToolBar());
    controls.add(slider);
    controls.add(deploy);
    controls.add(run);
    controls.add(help);
    content.add(controls, BorderLayout.SOUTH);
    /* Custom JPanels can be added here  */
    //
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //final GraphEditor demo = new GraphEditor();

}