Example usage for javax.swing JLabel revalidate

List of usage examples for javax.swing JLabel revalidate

Introduction

In this page you can find the example usage for javax.swing JLabel revalidate.

Prototype

public void revalidate() 

Source Link

Document

Supports deferred automatic layout.

Usage

From source file:com.amazonaws.services.kinesis.leases.impl.LeaseCoordinatorExerciser.java

public static void main(String[] args) throws InterruptedException, DependencyException, InvalidStateException,
        ProvisionedThroughputException, IOException {

    int numCoordinators = 9;
    int numLeases = 73;
    int leaseDurationMillis = 10000;
    int epsilonMillis = 100;

    AWSCredentialsProvider creds = new DefaultAWSCredentialsProviderChain();
    AmazonDynamoDBClient ddb = new AmazonDynamoDBClient(creds);

    ILeaseManager<KinesisClientLease> leaseManager = new KinesisClientLeaseManager("nagl_ShardProgress", ddb);

    if (leaseManager.createLeaseTableIfNotExists(10L, 50L)) {
        LOG.info("Waiting for newly created lease table");
        if (!leaseManager.waitUntilLeaseTableExists(10, 300)) {
            LOG.error("Table was not created in time");
            return;
        }//  w  w w.j a v a  2 s . c om
    }

    CWMetricsFactory metricsFactory = new CWMetricsFactory(creds, "testNamespace", 30 * 1000, 1000);
    final List<LeaseCoordinator<KinesisClientLease>> coordinators = new ArrayList<LeaseCoordinator<KinesisClientLease>>();
    for (int i = 0; i < numCoordinators; i++) {
        String workerIdentifier = "worker-" + Integer.toString(i);

        LeaseCoordinator<KinesisClientLease> coord = new LeaseCoordinator<KinesisClientLease>(leaseManager,
                workerIdentifier, leaseDurationMillis, epsilonMillis, metricsFactory);

        coordinators.add(coord);
    }

    leaseManager.deleteAll();

    for (int i = 0; i < numLeases; i++) {
        KinesisClientLease lease = new KinesisClientLease();
        lease.setLeaseKey(Integer.toString(i));
        lease.setCheckpoint(new ExtendedSequenceNumber("checkpoint"));
        leaseManager.createLeaseIfNotExists(lease);
    }

    final JFrame frame = new JFrame("Test Visualizer");
    frame.setPreferredSize(new Dimension(800, 600));
    final JPanel panel = new JPanel(new GridLayout(coordinators.size() + 1, 0));
    final JLabel ticker = new JLabel("tick");
    panel.add(ticker);
    frame.getContentPane().add(panel);

    final Map<String, JLabel> labels = new HashMap<String, JLabel>();
    for (final LeaseCoordinator<KinesisClientLease> coord : coordinators) {
        JPanel coordPanel = new JPanel();
        coordPanel.setLayout(new BoxLayout(coordPanel, BoxLayout.X_AXIS));
        final Button button = new Button("Stop " + coord.getWorkerIdentifier());
        button.setMaximumSize(new Dimension(200, 50));
        button.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
                if (coord.isRunning()) {
                    coord.stop();
                    button.setLabel("Start " + coord.getWorkerIdentifier());
                } else {
                    try {
                        coord.start();
                    } catch (LeasingException e) {
                        LOG.error(e);
                    }
                    button.setLabel("Stop " + coord.getWorkerIdentifier());
                }
            }

        });
        coordPanel.add(button);

        JLabel label = new JLabel();
        coordPanel.add(label);
        labels.put(coord.getWorkerIdentifier(), label);
        panel.add(coordPanel);
    }

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    new Thread() {

        // Key is lease key, value is green-ness as a value from 0 to 255.
        // Great variable name, huh?
        private Map<String, Integer> greenNesses = new HashMap<String, Integer>();

        // Key is lease key, value is last owning worker
        private Map<String, String> lastOwners = new HashMap<String, String>();

        @Override
        public void run() {
            while (true) {
                for (LeaseCoordinator<KinesisClientLease> coord : coordinators) {
                    String workerIdentifier = coord.getWorkerIdentifier();

                    JLabel label = labels.get(workerIdentifier);

                    List<KinesisClientLease> asgn = new ArrayList<KinesisClientLease>(coord.getAssignments());
                    Collections.sort(asgn, new Comparator<KinesisClientLease>() {

                        @Override
                        public int compare(KinesisClientLease arg0, KinesisClientLease arg1) {
                            return arg0.getLeaseKey().compareTo(arg1.getLeaseKey());
                        }

                    });

                    StringBuilder builder = new StringBuilder();
                    builder.append("<html>");
                    builder.append(workerIdentifier).append(":").append(asgn.size()).append("          ");

                    for (KinesisClientLease lease : asgn) {
                        String leaseKey = lease.getLeaseKey();
                        String lastOwner = lastOwners.get(leaseKey);

                        // Color things green when they switch owners, decay the green-ness over time.
                        Integer greenNess = greenNesses.get(leaseKey);
                        if (greenNess == null || lastOwner == null
                                || !lastOwner.equals(lease.getLeaseOwner())) {
                            greenNess = 200;
                        } else {
                            greenNess = Math.max(0, greenNess - 20);
                        }
                        greenNesses.put(leaseKey, greenNess);
                        lastOwners.put(leaseKey, lease.getLeaseOwner());

                        builder.append(String.format("<font color=\"%s\">%03d</font>",
                                String.format("#00%02x00", greenNess), Integer.parseInt(leaseKey))).append(" ");
                    }
                    builder.append("</html>");

                    label.setText(builder.toString());
                    label.revalidate();
                    label.repaint();
                }

                if (ticker.getText().equals("tick")) {
                    ticker.setText("tock");
                } else {
                    ticker.setText("tick");
                }

                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                }
            }
        }

    }.start();

    frame.pack();
    frame.setVisible(true);

    for (LeaseCoordinator<KinesisClientLease> coord : coordinators) {
        coord.start();
    }
}

From source file:com.josue.tileset.editor.Editor.java

private void mountButtons(List<Tile> tiles, int cols, int rows) {

    imagePanel.removeAll();/* ww w .  j a  v a2 s  . c  o m*/
    if (animatedPerformer != null) {
        animatedPerformer.stop();
        animatedPerformer = null;
    }

    imagePanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
    Dimension dimension = new Dimension(cols * TILE_SIZE, rows * TILE_SIZE);

    for (Tile tile : tiles) {
        final JLabel tileLabel = new JLabel();

        tileLabel.setIcon(new ImageIcon(tile.getImage()));
        Dimension labelDimension = new Dimension(TILE_SIZE, TILE_SIZE);
        tileLabel.setMinimumSize(labelDimension);
        tileLabel.setMaximumSize(labelDimension);
        tileLabel.setPreferredSize(labelDimension);
        tileLabel.setSize(labelDimension);
        tileLabel.addMouseListener(new java.awt.event.MouseAdapter() {
            @Override
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                if (SwingUtilities.isRightMouseButton(evt)) {//select animated sequence

                    if (animatedAction.isSelected()) {
                        addAnimatedTile(tile);
                    } else {
                        addLightSourceTile(tile);
                    }

                } else {

                    if (animatedPerformer != null) {
                        animatedPerformer.stop();
                    }
                    Iterator<JLabel> iterator = tileLabels.values().iterator();
                    while (iterator.hasNext()) {
                        JLabel next = iterator.next();
                        next.revalidate();
                    }
                    imagePanel.repaint();
                    for (Map.Entry<Tile, JLabel> entry : tileLabels.entrySet()) {
                        Tile key = entry.getKey();
                        JLabel value = entry.getValue();
                        value.setBorder(null); //clear borders
                    }

                    selectedTile = tile;//this isolate for the next operations
                    tileLabel.setBorder(new LineBorder(Color.RED, 2));

                    previewLabel.setIcon(new ImageIcon(tile.getImage()));
                    animatedTb.setSelected(selectedTile.isAnimated());
                    lightTb.setSelected(selectedTile.isLight());
                    solidTb.setSelected(selectedTile.isSolid());

                    if (tile.isAnimated()) {

                        for (Integer animatesTileOffset : selectedTile.getAnimation().getAnimatedSequence()) { //display animated borders
                            for (Map.Entry<Tile, JLabel> entry : tileLabels.entrySet()) {
                                Tile key = entry.getKey();
                                JLabel value = entry.getValue();
                                if (key.getId() == selectedTile.getId() + animatesTileOffset) {
                                    value.setBorder(new LineBorder(Color.BLUE, 2));
                                }
                            }

                        }

                        animatedPerformer = new Timer(
                                (int) (selectedTile.getAnimation().getAnimationInterval()),
                                new TileAnimator(selectedTile, previewLabel, loadedTiles));
                        animatedPerformer.start();
                    }
                    if (selectedTile.isLight()) {//light color has preference
                        for (Tile tile : tiles) {
                            if (tile.getId() == selectedTile.getLightTileId()) {
                                JLabel found = tileLabels.get(tile);
                                found.setBorder(new LineBorder(Color.YELLOW, 2));
                                break;
                            }
                        }

                    }
                }
            }

            @Override
            public void mouseExited(MouseEvent e) {
                if (selectedTile != null && selectedTile.getAnimation() != null && selectedTile.getAnimation()
                        .getAnimatedSequence().contains(tile.getId() - selectedTile.getId())) {
                    tileLabel.setBorder(new LineBorder(Color.BLUE, 2));
                } else if (selectedTile != null && selectedTile.isLight()
                        && selectedTile.getLightTileId() == tile.getId()) {
                    tileLabel.setBorder(new LineBorder(Color.YELLOW, 2));
                } else if (selectedTile != null) {
                    JLabel get = tileLabels.get(selectedTile);
                    if (!get.equals(tileLabel)) { //keep the red border if is the selected
                        tileLabel.setBorder(null);
                    }
                } else {
                    tileLabel.setBorder(null);
                }
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                if (selectedTile != null && selectedTile.getAnimation() != null
                        && !selectedTile.getAnimation().getAnimatedSequence()
                                .contains(tile.getId() - selectedTile.getId())
                        && tile.getLight() != null && tile.getLight().getLightTileOffset() != 0) {
                    tileLabel.setBorder(new LineBorder(Color.RED, 2));
                } else if (selectedTile == null) {
                    tileLabel.setBorder(new LineBorder(Color.RED, 2));
                }
            }
        });
        tileLabels.put(tile, tileLabel);
        imagePanel.add(tileLabel);
    }

    imagePanel.setMaximumSize(dimension);
    imagePanel.setMinimumSize(dimension);
    imagePanel.setPreferredSize(dimension);
    imagePanel.revalidate();
    imagePanel.repaint();
    this.pack();
}

From source file:it.imtech.metadata.MetaUtility.java

/**
 * Metodo che setta il TreeMap oefos_path con i valori del nodo selezionato
 * e aggiorna il label che descrive il path dei nodi selezionati
 *
 * @param e L'albero sul quale ricercare il path selezionato
 *///from   w w w . j  a va2 s  . c o  m
private void setOEFOS(JTree e, String sequence, String panelname) throws Exception {
    try {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getLastSelectedPathComponent();
        String completePath = "";
        //OefosPaths path = new OefosPaths(panelname, sequence);

        BookImporter.getInstance()
                .createComponentMap(BookImporter.getInstance().metadatapanels.get(panelname).getPanel());
        Component controls = BookImporter.getInstance().getComponentByName("classification_path---" + sequence);

        //Se e' una foglia aggiorna il path nell'interfaccia e oefos_path
        if (node != null) {
            TreePath selpath = new TreePath(node.getPath());
            e.setSelectionPath(selpath);

            Object[] nodes = selpath.getPath();

            TreeMap<Integer, Integer> single_path = new TreeMap<Integer, Integer>();

            for (int i = 1; i < nodes.length; i++) {
                Object nodeInfo = nodes[i];
                DefaultMutableTreeNode nodeC = (DefaultMutableTreeNode) nodeInfo;
                ClassNode c = (ClassNode) nodeC.getUserObject();
                single_path.put(i, Integer.parseInt(c.getKey().toString()));

                completePath += nodes[i].toString();
                completePath += (i != nodes.length - 1) ? "/" : "";
            }

            this.oefos_path.put(panelname + "----" + sequence, single_path);
        } else {
            this.oefos_path.put(panelname + "----" + sequence, null);
        }

        JLabel label = (JLabel) controls;
        if (completePath.length() > 120) {
            label.setText(completePath.substring(0, 120));
        } else {
            label.setText(completePath);
        }

        label.revalidate();
    } catch (Exception ex) {
        throw new Exception("Exception in setOEFOS: " + ex.getStackTrace() + "\n");
    }
}

From source file:org.apache.oodt.cas.workflow.gui.perspective.view.impl.DefaultPropView.java

private JPanel getPriorityPanel(final ViewState state) {
    JPanel panel = new JPanel();
    panel.setBorder(new EtchedBorder());
    panel.setLayout(new BorderLayout());
    panel.add(new JLabel("Priority:  "), BorderLayout.WEST);
    final JLabel priorityLabel = new JLabel(String.valueOf(DEFAULT_PRIORITY));
    panel.add(priorityLabel, BorderLayout.CENTER);
    JSlider slider = new JSlider(0, 100, (int) 5 * 10);
    slider.setMajorTickSpacing(10);/*  w  ww. ja  va 2 s  .c  om*/
    slider.setMinorTickSpacing(1);
    slider.setPaintLabels(true);
    slider.setPaintTicks(true);
    slider.setSnapToTicks(false);
    Format f = new DecimalFormat("0.0");
    Hashtable<Integer, JComponent> labels = new Hashtable<Integer, JComponent>();
    for (int i = 0; i <= 10; i += 2) {
        JLabel label = new JLabel(f.format(i));
        label.setFont(label.getFont().deriveFont(Font.PLAIN));
        labels.put(i * 10, label);
    }
    slider.setLabelTable(labels);
    slider.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            double value = ((JSlider) e.getSource()).getValue() / 10.0;
            priorityLabel.setText(value + "");
            priorityLabel.revalidate();
            if (!((JSlider) e.getSource()).getValueIsAdjusting()) {
                // FIXME: deal with priorities
                DefaultPropView.this.notifyListeners();
            }
        }

    });

    panel.add(slider, BorderLayout.SOUTH);
    return panel;
}