Example usage for javax.swing Box createHorizontalBox

List of usage examples for javax.swing Box createHorizontalBox

Introduction

In this page you can find the example usage for javax.swing Box createHorizontalBox.

Prototype

public static Box createHorizontalBox() 

Source Link

Document

Creates a Box that displays its components from left to right.

Usage

From source file:com.diversityarrays.dal.server.SqlDialog.java

SqlDialog(JFrame owner, SqlDalDatabase db) {
    super(owner, "SQL", ModalityType.MODELESS);

    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    this.database = db;

    runner = new DefaultBackgroundRunner("SQL Command", this);
    setGlassPane(runner.getBlockingPane());

    sqlCommands.setFont(GuiUtil.createMonospacedFont(12));

    includeHeadingsInCopy.addItemListener(new ItemListener() {
        @Override//from   w w  w  . j  a  v  a 2  s  .c om
        public void itemStateChanged(ItemEvent e) {
            boolean b = includeHeadingsInCopy.isSelected();
            for (int n = tabbedPane.getTabCount(); --n >= 0;) {
                Component c = tabbedPane.getComponentAt(n);
                if (c instanceof SqlResultsPanel) {
                    ((SqlResultsPanel) c).setIncludeHeadings(b);
                }
            }
        }
    });

    tabbedPane.addContainerListener(new ContainerListener() {
        @Override
        public void componentRemoved(ContainerEvent e) {
            updateClosePanelAction();
        }

        @Override
        public void componentAdded(ContainerEvent e) {
            updateClosePanelAction();
        }
    });
    updateClosePanelAction();

    Box buttons = Box.createHorizontalBox();
    buttons.add(Box.createHorizontalStrut(10));
    buttons.add(new JButton(runAction));
    buttons.add(Box.createHorizontalStrut(20));
    buttons.add(new JButton(closePanelAction));

    buttons.add(Box.createHorizontalGlue());
    buttons.add(includeHeadingsInCopy);
    buttons.add(Box.createHorizontalStrut(10));
    buttons.add(new JButton(helpAction));
    buttons.add(Box.createHorizontalStrut(10));

    JPanel top = new JPanel(new BorderLayout());
    top.add(BorderLayout.CENTER, new JScrollPane(sqlCommands));
    top.add(BorderLayout.SOUTH, buttons);

    final JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, top, tabbedPane);
    splitPane.setResizeWeight(0.25);

    setContentPane(splitPane);

    pack();

    setSize(800, 600);

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent e) {
            splitPane.setDividerLocation(0.25);
            removeWindowListener(this);
        }

    });
}

From source file:gda.gui.mca.McaGUI.java

/**
 * Constructor/* www.j  a v a  2 s .  c o  m*/
 */
public McaGUI()

{
    this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    Box vertBox = Box.createVerticalBox();
    vertBox.add(getTimePanel());
    vertBox.add(getAdcPanel());
    Box horiBox = Box.createHorizontalBox();
    horiBox.add(vertBox);
    horiBox.add(getRoiPanel());
    this.add(getNamePanel());

    this.add(horiBox);
    makePlotPanel();
    this.add(plotPanel);

    Thread plotThread = uk.ac.gda.util.ThreadManager.getThread(new PlotUpdateWorker(),
            "MCA Plot Update thread");
    plotThread.start();

    setLabel("Fluorescence Detector Control");
}

From source file:com.diversityarrays.kdxplore.field.FieldViewDialog.java

public FieldViewDialog(Window owner, String title, SampleGroupChoice sgcSamples, Trial trial,
        SampleGroupChoice sgcNewMedia, KDSmartDatabase db) throws IOException {
    super(owner, title, ModalityType.MODELESS);

    advanceRetreatControls = Box.createHorizontalBox();
    advanceRetreatControls.add(new JButton(retreatAction));
    advanceRetreatControls.add(new JButton(advanceAction));

    autoAdvanceControls = Box.createHorizontalBox();
    autoAdvanceControls.add(new JButton(autoAdvanceAction));

    autoAdvanceOption.addActionListener(new ActionListener() {
        @Override// w  w w  .j  a v  a  2  s.  co m
        public void actionPerformed(ActionEvent e) {
            updateMovementControls();
        }
    });

    this.database = db;
    this.sampleGroupChoiceForSamples = sgcSamples;
    this.sampleGroupChoiceForNewMedia = sgcNewMedia;

    NumberSpinner fontSpinner = new NumberSpinner(new SpinnerNumberModel(), "0.00");

    this.fieldViewPanel = FieldViewPanel.create(database, trial, SeparatorVisibilityOption.VISIBLE, null,
            Box.createHorizontalGlue(), new JButton(showInfoAction), Box.createHorizontalGlue(),
            new JLabel("Font Size:"), fontSpinner, Box.createHorizontalGlue(), advanceRetreatControls,
            autoAdvanceOption, autoAdvanceControls);

    initialiseAction(advanceAction, "ic_object_advance_black.png", "Auto-Advance");

    this.xyProvider = fieldViewPanel.getXYprovider();
    this.traitMap = fieldViewPanel.getTraitMap();

    fieldLayoutTable = fieldViewPanel.getFieldLayoutTable();

    JScrollPane scrollPane = fieldViewPanel.getFieldTableScrollPane();
    scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    fieldLayoutTable.setTransferHandler(flth);
    fieldLayoutTable.setDropMode(DropMode.ON);

    fieldLayoutTable.addMouseListener(new MouseAdapter() {
        JPopupMenu popupMenu;

        @Override
        public void mouseClicked(MouseEvent e) {
            if (!SwingUtilities.isRightMouseButton(e) || 1 != e.getClickCount()) {
                return;
            }
            Point pt = e.getPoint();
            int row = fieldLayoutTable.rowAtPoint(pt);
            if (row >= 0) {
                int col = fieldLayoutTable.columnAtPoint(pt);
                if (col >= 0) {
                    Plot plot = fieldViewPanel.getPlotAt(col, row);
                    if (plot != null) {
                        if (popupMenu == null) {
                            popupMenu = new JPopupMenu("View Attachments");
                        }
                        popupMenu.removeAll();

                        Set<File> set = plot.getMediaFiles();
                        if (Check.isEmpty(set)) {
                            popupMenu.add(new JMenuItem("No Attachments available"));
                        } else {
                            for (File file : set) {
                                Action a = new AbstractAction(file.getName()) {
                                    @Override
                                    public void actionPerformed(ActionEvent e) {
                                        try {
                                            Desktop.getDesktop().browse(file.toURI());
                                        } catch (IOException e1) {
                                            MsgBox.warn(FieldViewDialog.this, e1, file.getName());
                                        }
                                    }
                                };
                                popupMenu.add(new JMenuItem(a));
                            }
                        }
                        popupMenu.show(fieldLayoutTable, pt.x, pt.y);
                    }
                }
            }
        }

    });
    Font font = fieldLayoutTable.getFont();
    float fontSize = font.getSize2D();

    fontSizeModel = new SpinnerNumberModel(fontSize, fontSize, 50.0, 1.0);
    fontSpinner.setModel(fontSizeModel);
    fontSizeModel.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            float fsize = fontSizeModel.getNumber().floatValue();
            System.out.println("Using fontSize=" + fsize);
            Font font = fieldLayoutTable.getFont().deriveFont(fsize);
            fieldLayoutTable.setFont(font);
            FontMetrics fm = fieldLayoutTable.getFontMetrics(font);
            int lineHeight = fm.getMaxAscent() + fm.getMaxDescent();
            fieldLayoutTable.setRowHeight(4 * lineHeight);

            //                GuiUtil.initialiseTableColumnWidths(fieldLayoutTable, false);

            fieldLayoutTable.repaint();
        }
    });

    fieldLayoutTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    fieldLayoutTable.setResizable(true, true);
    fieldLayoutTable.getTableColumnResizer().setResizeAllColumns(true);

    advanceAction.setEnabled(false);
    fieldLayoutTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                handlePlotSelection();
            }
        }
    });
    TableColumnModel columnModel = fieldLayoutTable.getColumnModel();
    columnModel.addColumnModelListener(new TableColumnModelListener() {
        @Override
        public void columnSelectionChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                handlePlotSelection();
            }
        }

        @Override
        public void columnRemoved(TableColumnModelEvent e) {
        }

        @Override
        public void columnMoved(TableColumnModelEvent e) {
        }

        @Override
        public void columnMarginChanged(ChangeEvent e) {
        }

        @Override
        public void columnAdded(TableColumnModelEvent e) {
        }
    });

    PropertyChangeListener listener = new PropertyChangeListener() {
        // Use a timer and redisplay other columns when delay is GT 100 ms

        Timer timer = new Timer(true);
        TimerTask timerTask;
        long lastActive;
        boolean busy = false;
        private int eventColumnWidth;
        private TableColumn eventColumn;

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (busy) {
                return;
            }

            if (evt.getSource() instanceof TableColumn && "width".equals(evt.getPropertyName())) {

                eventColumn = (TableColumn) evt.getSource();
                eventColumnWidth = eventColumn.getWidth();

                lastActive = System.currentTimeMillis();
                if (timerTask == null) {
                    timerTask = new TimerTask() {
                        @Override
                        public void run() {
                            if (System.currentTimeMillis() - lastActive > 200) {
                                timerTask.cancel();
                                timerTask = null;

                                busy = true;
                                try {
                                    for (Enumeration<TableColumn> en = columnModel.getColumns(); en
                                            .hasMoreElements();) {
                                        TableColumn tc = en.nextElement();
                                        if (tc != eventColumn) {
                                            tc.setWidth(eventColumnWidth);
                                        }
                                    }
                                } finally {
                                    busy = false;
                                }
                            }
                        }
                    };
                    timer.scheduleAtFixedRate(timerTask, 100, 150);
                }
            }
        }
    };
    for (Enumeration<TableColumn> en = columnModel.getColumns(); en.hasMoreElements();) {
        TableColumn tc = en.nextElement();
        tc.addPropertyChangeListener(listener);
    }

    Map<Integer, Plot> plotById = new HashMap<>();
    for (Plot plot : fieldViewPanel.getFieldLayout()) {
        plotById.put(plot.getPlotId(), plot);
    }

    TrialItemVisitor<Sample> sampleVisitor = new TrialItemVisitor<Sample>() {
        @Override
        public void setExpectedItemCount(int count) {
        }

        @Override
        public boolean consumeItem(Sample sample) throws IOException {

            Plot plot = plotById.get(sample.getPlotId());
            if (plot == null) {
                throw new IOException("Missing plot for plotId=" + sample.getPlotId() + " sampleIdent="
                        + Util.createUniqueSampleKey(sample));
            }
            plot.addSample(sample);

            SampleCounts counts = countsByTraitId.get(sample.getTraitId());
            if (counts == null) {
                counts = new SampleCounts();
                countsByTraitId.put(sample.getTraitId(), counts);
            }
            if (sample.hasBeenScored()) {
                ++counts.scored;
            } else {
                ++counts.unscored;
            }
            return true;
        }
    };
    database.visitSamplesForTrial(sampleGroupChoiceForSamples, trial.getTrialId(),
            SampleOrder.ALL_BY_PLOT_ID_THEN_TRAIT_ID_THEN_INSTANCE_NUMBER_ORDER_THEN_SPECIMEN_NUMBER,
            sampleVisitor);

    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    this.trial = trial;

    KDClientUtils.initAction(ImageId.SETTINGS_24, showInfoAction, "Trial Summary");

    Action clear = new AbstractAction("Clear") {
        @Override
        public void actionPerformed(ActionEvent e) {
            infoTextArea.setText("");
        }
    };
    JPanel bottom = new JPanel(new BorderLayout());
    bottom.add(GuiUtil.createLabelSeparator("Plot Details", new JButton(clear)), BorderLayout.NORTH);
    bottom.add(new JScrollPane(infoTextArea), BorderLayout.CENTER);
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, fieldViewPanel,
            new JScrollPane(infoTextArea));
    splitPane.setResizeWeight(0.0);
    splitPane.setOneTouchExpandable(true);

    setContentPane(splitPane);

    updateMovementControls();
    pack();
}

From source file:org.jdal.swing.form.SimpleBoxFormBuilder.java

/**
 * Reset the form builder to reuse for creating a new panel
 *///from   w ww. jav  a 2  s.c o m
public void reset() {
    columns = new ArrayList<Box>();
    columnsWidth = new ArrayList<Integer>();
    rowsHeight = new ArrayList<Integer>();
    container = Box.createHorizontalBox();

    index = 0;
    rows = 0;

    focusTransversal = new FormFocusTransversalPolicy();
}

From source file:SoundPlayer.java

public SoundPlayer(File f, boolean isMidi) throws IOException, UnsupportedAudioFileException,
        LineUnavailableException, MidiUnavailableException, InvalidMidiDataException {
    if (isMidi) { // The file is a MIDI file
        midi = true;//ww  w . jav  a 2 s .  c  o  m
        // First, get a Sequencer to play sequences of MIDI events
        // That is, to send events to a Synthesizer at the right time.
        sequencer = MidiSystem.getSequencer(); // Used to play sequences
        sequencer.open(); // Turn it on.

        // Get a Synthesizer for the Sequencer to send notes to
        Synthesizer synth = MidiSystem.getSynthesizer();
        synth.open(); // acquire whatever resources it needs

        // The Sequencer obtained above may be connected to a Synthesizer
        // by default, or it may not. Therefore, we explicitly connect it.
        Transmitter transmitter = sequencer.getTransmitter();
        Receiver receiver = synth.getReceiver();
        transmitter.setReceiver(receiver);

        // Read the sequence from the file and tell the sequencer about it
        sequence = MidiSystem.getSequence(f);
        sequencer.setSequence(sequence);
        audioLength = (int) sequence.getTickLength(); // Get sequence length
    } else { // The file is sampled audio
        midi = false;
        // Getting a Clip object for a file of sampled audio data is kind
        // of cumbersome. The following lines do what we need.
        AudioInputStream ain = AudioSystem.getAudioInputStream(f);
        try {
            DataLine.Info info = new DataLine.Info(Clip.class, ain.getFormat());
            clip = (Clip) AudioSystem.getLine(info);
            clip.open(ain);
        } finally { // We're done with the input stream.
            ain.close();
        }
        // Get the clip length in microseconds and convert to milliseconds
        audioLength = (int) (clip.getMicrosecondLength() / 1000);
    }

    // Now create the basic GUI
    play = new JButton("Play"); // Play/stop button
    progress = new JSlider(0, audioLength, 0); // Shows position in sound
    time = new JLabel("0"); // Shows position as a #

    // When clicked, start or stop playing the sound
    play.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (playing)
                stop();
            else
                play();
        }
    });

    // Whenever the slider value changes, first update the time label.
    // Next, if we're not already at the new position, skip to it.
    progress.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            int value = progress.getValue();
            // Update the time label
            if (midi)
                time.setText(value + "");
            else
                time.setText(value / 1000 + "." + (value % 1000) / 100);
            // If we're not already there, skip there.
            if (value != audioPosition)
                skip(value);
        }
    });

    // This timer calls the tick() method 10 times a second to keep
    // our slider in sync with the music.
    timer = new javax.swing.Timer(100, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            tick();
        }
    });

    // put those controls in a row
    Box row = Box.createHorizontalBox();
    row.add(play);
    row.add(progress);
    row.add(time);

    // And add them to this component.
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    this.add(row);

    // Now add additional controls based on the type of the sound
    if (midi)
        addMidiControls();
    else
        addSampledControls();
}

From source file:de.mpg.mpi_inf.bioinf.netanalyzer.ui.SaveChartDialog.java

/**
 * Creates and lays out the controls inside this dialog's content pane.
 * <p>/*from   w w  w .j  a  v  a 2s  .com*/
 * This method is called upon initialization only.
 * </p>
 */
private void initControls() {
    JPanel sizePanel = new JPanel(new GridLayout(2, 3, 4, 4));
    sizePanel.setBorder(BorderFactory.createTitledBorder(Messages.DI_IMAGESIZE));

    // Add a spinner for choosing width
    sizePanel.add(new JLabel(Messages.DI_WIDTH, SwingConstants.RIGHT));
    int width = ChartPanel.DEFAULT_WIDTH;
    int minWidth = ChartPanel.DEFAULT_MINIMUM_DRAW_WIDTH;
    int maxWidth = ChartPanel.DEFAULT_MAXIMUM_DRAW_WIDTH;
    SpinnerModel widthSettings = new SpinnerNumberModel(width, minWidth, maxWidth, 1);
    sizePanel.add(widthSpinner = new JSpinner(widthSettings));
    sizePanel.add(new JLabel(Messages.DI_PIXELS));

    // Add a spinner for choosing height
    sizePanel.add(new JLabel(Messages.DI_HEIGHT, SwingConstants.RIGHT));
    int height = ChartPanel.DEFAULT_HEIGHT;
    int minHeight = ChartPanel.DEFAULT_MINIMUM_DRAW_HEIGHT;
    int maxHeight = ChartPanel.DEFAULT_MAXIMUM_DRAW_HEIGHT;
    SpinnerModel heightSettings = new SpinnerNumberModel(height, minHeight, maxHeight, 1);
    sizePanel.add(heightSpinner = new JSpinner(heightSettings));
    sizePanel.add(new JLabel(Messages.DI_PIXELS));

    // Add Save and Cancel buttons
    JPanel buttons = new JPanel(new GridLayout(1, 2, 4, 0));
    buttons.add(btnSave = Utils.createButton(Messages.DI_SAVE, null, this));
    buttons.add(btnCancel = Utils.createButton(Messages.DI_CANCEL, null, this));
    Box buttonsBox = Box.createHorizontalBox();
    buttonsBox.add(Box.createHorizontalGlue());
    buttonsBox.add(buttons);
    buttonsBox.add(Box.createHorizontalGlue());

    Container contentPane = getContentPane();
    contentPane.add(sizePanel, BorderLayout.NORTH);
    contentPane.add(Box.createVerticalStrut(Utils.BORDER_SIZE / 2));
    contentPane.add(buttonsBox, BorderLayout.PAGE_END);
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    Utils.setStandardBorder(getRootPane());
}

From source file:org.jdal.swing.form.FormUtils.java

/**
 * Create a box with an aligned component using Component constants for right, center and left.
 * @param c component/*from  w ww  . j  a  v a2s  . com*/
 * @param alignment aligment.
 * @return Box with compoenent
 */
public static Component newBoxForComponent(Component c, float alignment) {
    Box box = Box.createHorizontalBox();
    if (Component.RIGHT_ALIGNMENT == alignment) {
        box.add(Box.createHorizontalGlue());
        box.add(c);
    } else if (Component.CENTER_ALIGNMENT == alignment) {
        box.add(Box.createHorizontalGlue());
        box.add(c);
        box.add(Box.createHorizontalGlue());
    } else {
        // default to left
        box.add(c);
        box.add(Box.createHorizontalGlue());
    }

    return box;
}

From source file:EdgeLabelDemo.java

/**
 * create an instance of a simple graph with controls to
 * demo the label positioning features/*  w  ww  .  ja va  2 s  .  c  o m*/
 * 
 */
@SuppressWarnings("serial")
public EdgeLabelDemo() {

    // create a simple graph for the demo
    graph = new SparseMultigraph<Integer, Number>();
    Integer[] v = createVertices(3);
    createEdges(v);

    Layout<Integer, Number> layout = new CircleLayout<Integer, Number>(graph);
    vv = new VisualizationViewer<Integer, Number>(layout, new Dimension(600, 400));
    vv.setBackground(Color.white);

    vertexLabelRenderer = vv.getRenderContext().getVertexLabelRenderer();
    edgeLabelRenderer = vv.getRenderContext().getEdgeLabelRenderer();

    Transformer<Number, String> stringer = new Transformer<Number, String>() {
        public String transform(Number e) {
            return "Edge:" + graph.getEndpoints(e).toString();
        }
    };
    vv.getRenderContext().setEdgeLabelTransformer(stringer);
    vv.getRenderContext().setEdgeDrawPaintTransformer(
            new PickableEdgePaintTransformer<Number>(vv.getPickedEdgeState(), Color.black, Color.cyan));
    vv.getRenderContext().setVertexFillPaintTransformer(
            new PickableVertexPaintTransformer<Integer>(vv.getPickedVertexState(), Color.red, Color.yellow));
    // add my listener for ToolTips
    vv.setVertexToolTipTransformer(new ToStringLabeller<Integer>());

    // create a frome to hold the graph
    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    Container content = getContentPane();
    content.add(panel);

    final DefaultModalGraphMouse<Integer, Number> graphMouse = new DefaultModalGraphMouse<Integer, Number>();
    vv.setGraphMouse(graphMouse);

    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());
        }
    });

    ButtonGroup radio = new ButtonGroup();
    JRadioButton lineButton = new JRadioButton("Line");
    lineButton.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line<Integer, Number>());
                vv.repaint();
            }
        }
    });

    JRadioButton quadButton = new JRadioButton("QuadCurve");
    quadButton.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.QuadCurve<Integer, Number>());
                vv.repaint();
            }
        }
    });

    JRadioButton cubicButton = new JRadioButton("CubicCurve");
    cubicButton.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.CubicCurve<Integer, Number>());
                vv.repaint();
            }
        }
    });
    radio.add(lineButton);
    radio.add(quadButton);
    radio.add(cubicButton);

    graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING);

    JCheckBox rotate = new JCheckBox("<html><center>EdgeType<p>Parallel</center></html>");
    rotate.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            AbstractButton b = (AbstractButton) e.getSource();
            edgeLabelRenderer.setRotateEdgeLabels(b.isSelected());
            vv.repaint();
        }
    });
    rotate.setSelected(true);
    MutableDirectionalEdgeValue mv = new MutableDirectionalEdgeValue(.5, .7);
    vv.getRenderContext().setEdgeLabelClosenessTransformer(mv);
    JSlider directedSlider = new JSlider(mv.getDirectedModel()) {
        public Dimension getPreferredSize() {
            Dimension d = super.getPreferredSize();
            d.width /= 2;
            return d;
        }
    };
    JSlider undirectedSlider = new JSlider(mv.getUndirectedModel()) {
        public Dimension getPreferredSize() {
            Dimension d = super.getPreferredSize();
            d.width /= 2;
            return d;
        }
    };

    JSlider edgeOffsetSlider = new JSlider(0, 50) {
        public Dimension getPreferredSize() {
            Dimension d = super.getPreferredSize();
            d.width /= 2;
            return d;
        }
    };
    edgeOffsetSlider.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            JSlider s = (JSlider) e.getSource();
            AbstractEdgeShapeTransformer<Integer, Number> aesf = (AbstractEdgeShapeTransformer<Integer, Number>) vv
                    .getRenderContext().getEdgeShapeTransformer();
            aesf.setControlOffsetIncrement(s.getValue());
            vv.repaint();
        }

    });

    Box controls = Box.createHorizontalBox();

    JPanel zoomPanel = new JPanel(new GridLayout(0, 1));
    zoomPanel.setBorder(BorderFactory.createTitledBorder("Scale"));
    zoomPanel.add(plus);
    zoomPanel.add(minus);

    JPanel edgePanel = new JPanel(new GridLayout(0, 1));
    edgePanel.setBorder(BorderFactory.createTitledBorder("EdgeType Type"));
    edgePanel.add(lineButton);
    edgePanel.add(quadButton);
    edgePanel.add(cubicButton);

    JPanel rotatePanel = new JPanel();
    rotatePanel.setBorder(BorderFactory.createTitledBorder("Alignment"));
    rotatePanel.add(rotate);

    JPanel labelPanel = new JPanel(new BorderLayout());
    JPanel sliderPanel = new JPanel(new GridLayout(3, 1));
    JPanel sliderLabelPanel = new JPanel(new GridLayout(3, 1));
    JPanel offsetPanel = new JPanel(new BorderLayout());
    offsetPanel.setBorder(BorderFactory.createTitledBorder("Offset"));
    sliderPanel.add(directedSlider);
    sliderPanel.add(undirectedSlider);
    sliderPanel.add(edgeOffsetSlider);
    sliderLabelPanel.add(new JLabel("Directed", JLabel.RIGHT));
    sliderLabelPanel.add(new JLabel("Undirected", JLabel.RIGHT));
    sliderLabelPanel.add(new JLabel("Edges", JLabel.RIGHT));
    offsetPanel.add(sliderLabelPanel, BorderLayout.WEST);
    offsetPanel.add(sliderPanel);
    labelPanel.add(offsetPanel);
    labelPanel.add(rotatePanel, BorderLayout.WEST);

    JPanel modePanel = new JPanel(new GridLayout(2, 1));
    modePanel.setBorder(BorderFactory.createTitledBorder("Mouse Mode"));
    modePanel.add(graphMouse.getModeComboBox());

    controls.add(zoomPanel);
    controls.add(edgePanel);
    controls.add(labelPanel);
    controls.add(modePanel);
    content.add(controls, BorderLayout.SOUTH);
    quadButton.setSelected(true);
}

From source file:de.interactive_instruments.ShapeChange.UI.DefaultDialog.java

private JPanel createTab2() {
    final JPanel reportPanel = new JPanel(new GridLayout(3, 1));
    reportGroup = new ButtonGroup();
    String param = options.parameter("reportLevel");
    addRadioButton(reportPanel, reportGroup, "Error", "ERROR", param);
    addRadioButton(reportPanel, reportGroup, "Warning", "WARNING", param);
    addRadioButton(reportPanel, reportGroup, "Info", "INFO", param);
    reportPanel.setBorder(new TitledBorder(new LineBorder(Color.black), "Report options", TitledBorder.LEFT,
            TitledBorder.TOP));//from   w w  w  . jav a2 s.com

    final JPanel rulePanel = new JPanel(new GridLayout(3, 1));
    ruleGroup = new ButtonGroup();
    param = options.parameter(Options.TargetXmlSchemaClass, "defaultEncodingRule");
    addRadioButton(rulePanel, ruleGroup, "GML 3.2", "iso19136_2007", param);
    addRadioButton(rulePanel, ruleGroup, "GML 3.3", "gml33", param);
    addRadioButton(rulePanel, ruleGroup, "ISO/TS 19139", "iso19139_2007", param);
    addRadioButton(rulePanel, ruleGroup, "GML 3.2 (ShapeChange extensions)",
            "iso19136_2007_ShapeChange_1.0_extensions", param);
    addRadioButton(rulePanel, ruleGroup, "GML 3.3 (INSPIRE extensions)", "iso19136_2007_INSPIRE_Extensions",
            param);
    rulePanel.setBorder(new TitledBorder(new LineBorder(Color.black), "Default encoding rule",
            TitledBorder.LEFT, TitledBorder.TOP));

    final JPanel otherPanel = new JPanel(new GridLayout(2, 1));
    docCB = new JCheckBox("Include documentation", true);
    boolean b = true;
    String s = options.parameter(Options.TargetXmlSchemaClass, "includeDocumentation");
    if (s != null && s.equals("false"))
        b = false;
    docCB.setSelected(b);
    otherPanel.add(docCB);
    visCB = new JCheckBox("Ignore visibility");
    b = true;
    s = options.parameter("publicOnly");
    if (s != null && s.equals("false"))
        b = false;
    visCB.setSelected(!b);
    otherPanel.add(visCB);
    otherPanel.setBorder(new TitledBorder(new LineBorder(Color.black), "Other options", TitledBorder.LEFT,
            TitledBorder.TOP));

    Box innerBox = Box.createHorizontalBox();
    innerBox.add(reportPanel);
    innerBox.add(otherPanel);

    Box mainBox = Box.createVerticalBox();
    mainBox.add(innerBox);
    mainBox.add(rulePanel);

    JPanel panel = new JPanel(new BorderLayout());
    panel.add(mainBox, BorderLayout.CENTER);

    return panel;
}

From source file:com.diversityarrays.kdxplore.heatmap.HeatMapPanel.java

public HeatMapPanel(VisualisationTool vtool, int unique, SelectedValueStore svs, PlotInfoProvider pip,
        String title,//from  w w  w. ja  va2s  . c  o m

        HeatMapModelData<T> heatMapModelData, SuppressionHandler suppressionHandler) {
    super(title, svs, vtool.getVisualisationToolId(), unique, Arrays.asList(heatMapModelData.zTraitInstance),
            suppressionHandler);

    context = heatMapModelData.context;
    xValueRetriever = heatMapModelData.xValueRetriever;
    yValueRetriever = heatMapModelData.yValueRetriever;

    askAboutValueForUnscored = !ValueRetriever.isEitherOneXorY(xValueRetriever, yValueRetriever);

    traitInstanceValueRetriever = heatMapModelData.traitInstanceValueRetriever;
    this.zTraitInstance = heatMapModelData.zTraitInstance;
    //      this.plotSpecimensByPoint = heatMapModelData.model.getCellLegend();

    this.plotInfoProvider = pip;
    this.title = title;

    if (heatMapModelData.plotPointsByMark.isEmpty()) {
        markInfo = null;
    } else {
        markInfo = new MarkInfo(Msg.LABEL_MARK_INFO_PLOT_TYPE(), heatMapModelData.plotPointsByMark);
    }

    this.heatMap = createHeatMap(heatMapModelData);

    this.heatMap.addPropertyChangeListener(HeatMapPane.PROPERTY_SELECTION_CHANGE,
            heatMapPaneSelectionChangeListener);

    messagesTextArea.setEditable(false);
    tabbedPane.addTab(TAB_MESSAGES, new JScrollPane(messagesTextArea));
    tabbedPane.addTab(TAB_CURATION, createCurationControls());

    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, tabbedPane, heatMap);

    splitPane.setOneTouchExpandable(true);
    splitPane.setResizeWeight(0.0);
    add(splitPane, BorderLayout.CENTER);

    int cellValueCount = heatMap.getValueModel().getUniqueCellValueCount();
    Gradient[] gradients = Gradient.createBuiltins(cellValueCount);
    Gradient initial = null;
    for (Gradient g : gradients) {
        if (Gradient.RAINBOW_NAME.equals(g.getName())) {
            initial = g;
            break;
        }
    }

    gradientComboBox = new JComboBox<Gradient>(gradients);
    gradientComboBox.setRenderer(new GradientComboBoxRenderer());
    gradientComboBox.addItemListener(gradientItemListener);

    // gradientItemListener will to model.setGradient()
    gradientComboBox.setSelectedItem(initial);

    Box box = Box.createHorizontalBox();
    box.add(syncedOption);
    box.add(gradientComboBox);
    box.add(Box.createHorizontalGlue());
    //      if (RunMode.getRunMode().isDeveloper()) {
    //           box.add(useBlankTilesOption);
    //      }
    box.add(new JSeparator(JSeparator.VERTICAL));
    box.add(opacityLabel);
    box.add(unselectedOpacitySpinner);

    add(box, BorderLayout.SOUTH);

    opacityLabel.setToolTipText("Sets the opacity of unselected cells");
    unselectedOpacitySpinner.setToolTipText("Sets the opacity of unselected cells");

    //      useBlankTilesOption.setSelected(heatMap.getUseBlankTiles());
    unselectedOpacityModel.setValue(heatMap.getUnselectedOpacity());

    //      useBlankTilesOption.addActionListener(new ActionListener() {
    //            @Override
    //            public void actionPerformed(ActionEvent e) {
    //                handleUseBlankTilesChanged();
    //            }
    //        });

    unselectedOpacityModel.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            handleOpacityChange();
        }
    });

    updateMessagesWithMissingOrBad(null, heatMapModelData);

    applyDecoratorsToHeatMap(heatMapModelData);
}