Example usage for javax.swing JScrollPane getPreferredSize

List of usage examples for javax.swing JScrollPane getPreferredSize

Introduction

In this page you can find the example usage for javax.swing JScrollPane getPreferredSize.

Prototype

@Transient
public Dimension getPreferredSize() 

Source Link

Document

If the preferredSize has been set to a non-null value just returns it.

Usage

From source file:Main.java

public static void main(String[] args) {
    final StringBuilder sb = new StringBuilder();
    sb.append("<html>");
    sb.append("<body><ol>");
    Font[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
    for (Font font : fonts) {
        String name = font.getName();
        sb.append("<li style='font-family: " + name + "; font-size: 20px;'>");
        sb.append(name);//from   www . j  a  v a2s.c om
    }

    JScrollPane sp = new JScrollPane(new JLabel(sb.toString()));
    Dimension d = sp.getPreferredSize();
    sp.setPreferredSize(new Dimension(d.width, 150));
    JOptionPane.showMessageDialog(null, sp);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel gui = new JPanel(new BorderLayout(5, 5));

    JPanel plafComponents = new JPanel(new FlowLayout(FlowLayout.RIGHT, 3, 3));
    plafComponents.setBorder(new TitledBorder("FlowLayout(FlowLayout.RIGHT, 3,3)"));

    UIManager.LookAndFeelInfo[] plafInfos = UIManager.getInstalledLookAndFeels();
    String[] plafNames = new String[plafInfos.length];
    for (int ii = 0; ii < plafInfos.length; ii++) {
        plafNames[ii] = plafInfos[ii].getName();
    }// www . j  a  v  a2 s . c  o  m
    JComboBox plafChooser = new JComboBox(plafNames);
    plafComponents.add(plafChooser);

    JCheckBox pack = new JCheckBox("Pack on PLAF change", true);
    plafComponents.add(pack);

    plafChooser.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            int index = plafChooser.getSelectedIndex();
            try {
                UIManager.setLookAndFeel(plafInfos[index].getClassName());
                SwingUtilities.updateComponentTreeUI(frame);
                if (pack.isSelected()) {
                    frame.pack();
                    frame.setMinimumSize(frame.getSize());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    gui.add(plafComponents, BorderLayout.NORTH);

    JPanel dynamicLabels = new JPanel(new BorderLayout(4, 4));
    dynamicLabels.setBorder(new TitledBorder("BorderLayout(4,4)"));
    gui.add(dynamicLabels, BorderLayout.WEST);

    final JPanel labels = new JPanel(new GridLayout(0, 2, 3, 3));
    labels.setBorder(new TitledBorder("GridLayout(0,2,3,3)"));

    JButton addNew = new JButton("Add Another Label");
    dynamicLabels.add(addNew, BorderLayout.NORTH);
    addNew.addActionListener(new ActionListener() {

        private int labelCount = 0;

        public void actionPerformed(ActionEvent ae) {
            labels.add(new JLabel("Label " + ++labelCount));
            frame.validate();
        }
    });

    dynamicLabels.add(new JScrollPane(labels), BorderLayout.CENTER);

    String[] header = { "Name", "Value" };
    String[] a = new String[0];
    String[] names = System.getProperties().stringPropertyNames().toArray(a);
    String[][] data = new String[names.length][2];
    for (int ii = 0; ii < names.length; ii++) {
        data[ii][0] = names[ii];
        data[ii][1] = System.getProperty(names[ii]);
    }
    DefaultTableModel model = new DefaultTableModel(data, header);
    JTable table = new JTable(model);

    JScrollPane tableScroll = new JScrollPane(table);
    Dimension tablePreferred = tableScroll.getPreferredSize();
    tableScroll.setPreferredSize(new Dimension(tablePreferred.width, tablePreferred.height / 3));

    JPanel imagePanel = new JPanel(new GridBagLayout());
    JLabel imageLabel = new JLabel("test");
    imagePanel.add(imageLabel, null);

    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, tableScroll, new JScrollPane(imagePanel));
    gui.add(splitPane, BorderLayout.CENTER);

    frame.setContentPane(gui);
    frame.pack();
    frame.setVisible(true);
}

From source file:lu.lippmann.cdb.ext.hydviga.ui.SimilarCasesFrame.java

/**
 * Constructor.//w  ww  .j a v  a2  s.c  o  m
 */
SimilarCasesFrame(final Instances ds, final int dateIdx, final StationsDataProvider gcp, String attrname,
        final int gapsize, final int position, final double x, final double y, final int year,
        final String season, final boolean isDuringRising) throws Exception {
    LogoHelper.setLogo(this);
    this.setTitle("KnowledgeDB: Suggested configurations / similar cases");

    this.inputCaseTablePanel = new JXPanel();
    this.inputCaseTablePanel.setBorder(new TitledBorder("Present case"));
    this.inputCaseChartPanel = new JXPanel();
    this.inputCaseChartPanel.setBorder(new TitledBorder("Profile of the present case"));
    this.outputCasesTablePanel = new JXPanel();
    this.outputCasesTablePanel.setBorder(new TitledBorder("Suggested cases"));
    this.outputCasesChartPanel = new JXPanel();
    this.outputCasesChartPanel.setBorder(new TitledBorder("Profile of the selected suggested case"));

    getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.PAGE_AXIS));
    getContentPane().add(inputCaseTablePanel);
    getContentPane().add(inputCaseChartPanel);
    getContentPane().add(outputCasesTablePanel);
    getContentPane().add(outputCasesChartPanel);

    final Instances res = GapFillingKnowledgeDB.findSimilarCases(attrname, x, y, year, season, gapsize,
            position, isDuringRising, gcp.findDownstreamStation(attrname) != null,
            gcp.findUpstreamStation(attrname) != null,
            GapsUtil.measureHighMiddleLowInterval(ds, ds.attribute(attrname).index(), position - 1));

    final Instances inputCase = new Instances(res);
    while (inputCase.numInstances() > 1)
        inputCase.remove(1);
    final JXTable inputCaseTable = buidJXTable(inputCase);
    final JScrollPane inputScrollPane = new JScrollPane(inputCaseTable);
    //System.out.println(inputScrollPane.getPreferredSize());
    inputScrollPane.setPreferredSize(
            new Dimension(COMPONENT_WIDTH, (int) (50 + inputScrollPane.getPreferredSize().getHeight())));
    this.inputCaseTablePanel.add(inputScrollPane);

    final ChartPanel inputcp = GapsUIUtil.buildGapChartPanel(ds, dateIdx, ds.attribute(attrname), gapsize,
            position);
    inputcp.getChart().removeLegend();
    inputcp.setPreferredSize(CHART_DIMENSION);
    this.inputCaseChartPanel.add(inputcp);

    final Instances outputCases = new Instances(res);
    outputCases.remove(0);
    final JXTable outputCasesTable = buidJXTable(outputCases);
    final JScrollPane outputScrollPane = new JScrollPane(outputCasesTable);
    outputScrollPane.setPreferredSize(
            new Dimension(COMPONENT_WIDTH, (int) (50 + outputScrollPane.getPreferredSize().getHeight())));
    this.outputCasesTablePanel.add(outputScrollPane);

    outputCasesTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    outputCasesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                final int modelRow = outputCasesTable.getSelectedRow();

                final String attrname = outputCasesTable.getModel().getValueAt(modelRow, 1).toString();
                final int gapsize = (int) Double
                        .valueOf(outputCasesTable.getModel().getValueAt(modelRow, 4).toString()).doubleValue();
                final int position = (int) Double
                        .valueOf(outputCasesTable.getModel().getValueAt(modelRow, 5).toString()).doubleValue();

                try {
                    final ChartPanel cp = GapsUIUtil.buildGapChartPanel(ds, dateIdx, ds.attribute(attrname),
                            gapsize, position);
                    cp.getChart().removeLegend();
                    cp.setPreferredSize(CHART_DIMENSION);
                    outputCasesChartPanel.removeAll();
                    outputCasesChartPanel.add(cp);
                    getContentPane().repaint();
                    pack();
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
        }
    });

    outputCasesTable.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(final MouseEvent e) {
            final InstanceTableModel instanceTableModel = (InstanceTableModel) outputCasesTable.getModel();
            final int row = outputCasesTable.rowAtPoint(e.getPoint());
            final int modelRow = outputCasesTable.convertRowIndexToModel(row);

            final String attrname = instanceTableModel.getValueAt(modelRow, 1).toString();
            final int gapsize = (int) Double.valueOf(instanceTableModel.getValueAt(modelRow, 4).toString())
                    .doubleValue();
            final int position = (int) Double.valueOf(instanceTableModel.getValueAt(modelRow, 5).toString())
                    .doubleValue();

            if (e.isPopupTrigger()) {
                final JPopupMenu jPopupMenu = new JPopupMenu("feur");

                final JMenuItem mi = new JMenuItem("Use this configuration");
                mi.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(final ActionEvent e) {
                        System.out.println("not implemented!");
                    }
                });
                jPopupMenu.add(mi);
                jPopupMenu.show(outputCasesTable, e.getX(), e.getY());
            } else {
                // nothing?
            }
        }
    });

    setPreferredSize(new Dimension(FRAME_WIDTH, 900));

    pack();
    setVisible(true);

    /* select the first row */
    outputCasesTable.setRowSelectionInterval(0, 0);
}

From source file:ca.phon.app.session.editor.view.segmentation.SegmentationEditorView.java

private void init() {
    segmentWindowField = new JTextField();
    SegmentWindowDocument segDoc = new SegmentWindowDocument();
    segmentWindowField.setDocument(segDoc);
    segmentWindowField.setText(DEFAULT_SEGMENT_WINDOW + "");
    segDoc.addDocumentListener(new SegmentWindowListener());

    segmentLabel = new SegmentLabel();
    segmentLabel.setSegmentWindow(DEFAULT_SEGMENT_WINDOW);
    segmentLabel.setCurrentTime(0L);/*  w  ww  .  j ava 2  s  .  c  o m*/
    segmentLabel.lockSegmentStartTime(-1L);

    modeBox = new JComboBox(SegmentationMode.values());
    modeBox.setSelectedItem(SegmentationMode.INSERT_AFTER_CURRENT);

    JPanel topPanel = new JPanel();
    FormLayout topLayout = new FormLayout("right:pref, 3dlu, fill:default:grow, pref",
            "pref, pref, pref, pref");
    topPanel.setLayout(topLayout);
    CellConstraints cc = new CellConstraints();
    topPanel.add(new JLabel("Segment Window"), cc.xy(1, 1));
    topPanel.add(segmentWindowField, cc.xy(3, 1));
    topPanel.add(new JLabel("ms"), cc.xy(4, 1));

    JLabel infoLabel = new JLabel("Set to 0 for unlimited segment time");
    infoLabel.setFont(infoLabel.getFont().deriveFont(10.0f));

    topPanel.add(infoLabel, cc.xy(3, 2));
    topPanel.add(new JLabel("Current Window"), cc.xy(1, 3));
    topPanel.add(segmentLabel, cc.xy(3, 3));

    topPanel.add(new JLabel("Mode"), cc.xy(1, 4));
    topPanel.add(modeBox, cc.xyw(3, 4, 2));

    setLayout(new BorderLayout());
    add(topPanel, BorderLayout.NORTH);

    participantPanel = new JPanel();

    participantPanel.setBackground(Color.white);
    participantPanel.setOpaque(true);

    JScrollPane participantScroller = new JScrollPane(participantPanel);
    Dimension prefSize = participantScroller.getPreferredSize();
    prefSize.height = 150;
    participantScroller.setPreferredSize(prefSize);
    Dimension maxSize = participantScroller.getMaximumSize();
    maxSize.height = 200;
    participantScroller.setMaximumSize(maxSize);
    Dimension minSize = participantScroller.getMinimumSize();
    minSize.height = 100;
    participantScroller.setMinimumSize(minSize);
    participantScroller.setBorder(BorderFactory.createTitledBorder("Participants"));

    add(participantScroller, BorderLayout.CENTER);

    updateParticipantPanel();
    setupEditorActions();
}

From source file:net.sf.firemox.ui.component.SplashScreen.java

/**
 * Create a new instance of this class./*from   w w  w.  j a v  a2 s  .co  m*/
 * 
 * @param filename
 *          the picture filename.
 * @param parent
 *          the splash screen's parent.
 * @param waitTime
 *          the maximum time before the screen is hidden.
 */
public SplashScreen(String filename, Frame parent, int waitTime) {
    super(parent);
    getContentPane().setLayout(null);
    toFront();
    final JLabel l = new JLabel(new ImageIcon(filename));
    final Dimension labelSize = l.getPreferredSize();
    l.setLocation(0, 0);
    l.setSize(labelSize);
    setSize(labelSize);

    final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setLocation(screenSize.width / 2 - labelSize.width / 2, screenSize.height / 2 - labelSize.height / 2);

    final JLabel mp = new JLabel(IdConst.PROJECT_DISPLAY_NAME);
    mp.setLocation(30, 305);
    mp.setSize(new Dimension(300, 30));

    final JLabel version = new JLabel(IdConst.VERSION);
    version.setLocation(235, 418);
    version.setSize(new Dimension(300, 30));

    final JTextArea disclaimer = new JTextArea();
    disclaimer.setEditable(false);
    disclaimer.setLineWrap(true);
    disclaimer.setWrapStyleWord(true);
    disclaimer.setAutoscrolls(true);
    disclaimer.setFont(MToolKit.defaultFont);
    disclaimer.setTabSize(2);

    // Then try and read it locally
    Reader inGPL = null;
    try {
        inGPL = new BufferedReader(new InputStreamReader(MToolKit.getResourceAsStream(IdConst.FILE_LICENSE)));
        disclaimer.read(inGPL, "");
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(inGPL);
    }

    final JScrollPane disclaimerSPanel = new JScrollPane();
    disclaimerSPanel.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    disclaimerSPanel.setViewportView(disclaimer);
    disclaimerSPanel.setLocation(27, 340);
    disclaimerSPanel.setPreferredSize(new Dimension(283, 80));
    disclaimerSPanel.setSize(disclaimerSPanel.getPreferredSize());

    getContentPane().add(disclaimerSPanel);
    getContentPane().add(version);
    getContentPane().add(mp);
    getContentPane().add(l);

    final int pause = waitTime;
    final Runnable waitRunner = new Runnable() {
        public void run() {
            try {
                Thread.sleep(pause);
                while (!bKilled) {
                    Thread.sleep(200);
                }
            } catch (InterruptedException e) {
                // Ignore this error
            }
            setVisible(false);
            dispose();
            MagicUIComponents.magicForm.toFront();
        }
    };

    // setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            setVisible(false);
            dispose();
            if (MagicUIComponents.magicForm != null)
                MagicUIComponents.magicForm.toFront();
        }
    });
    addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_SPACE) {
                setVisible(false);
                dispose();
                MagicUIComponents.magicForm.toFront();
            }
        }
    });
    setVisible(true);
    start(waitRunner);
}

From source file:lu.lippmann.cdb.ext.hydviga.ui.GapFillingKnowledgeDBExplorerFrame.java

/**
 * Constructor.//from  www.java2 s  .com
 */
GapFillingKnowledgeDBExplorerFrame(final Instances ds, final int dateIdx, final StationsDataProvider gcp)
        throws Exception {
    LogoHelper.setLogo(this);
    this.setTitle("KnowledgeDB: explorer");

    this.gcp = gcp;

    this.tablePanel = new JXPanel();
    this.tablePanel.setBorder(new TitledBorder("Cases"));

    final JXPanel highPanel = new JXPanel();
    highPanel.setLayout(new BoxLayout(highPanel, BoxLayout.X_AXIS));
    highPanel.add(this.tablePanel);

    this.geomapPanel = new JXPanel();
    this.geomapPanel.add(buildGeoMapChart(new ArrayList<String>(), new ArrayList<String>()));
    highPanel.add(this.geomapPanel);

    this.caseChartPanel = new JXPanel();
    this.caseChartPanel.setBorder(new TitledBorder("Inspected fake gap"));

    this.mostSimilarChartPanel = new JXPanel();
    this.mostSimilarChartPanel.setBorder(new TitledBorder("Most similar"));
    this.nearestChartPanel = new JXPanel();
    this.nearestChartPanel.setBorder(new TitledBorder("Nearest"));
    this.downstreamChartPanel = new JXPanel();
    this.downstreamChartPanel.setBorder(new TitledBorder("Downstream"));
    this.upstreamChartPanel = new JXPanel();
    this.upstreamChartPanel.setBorder(new TitledBorder("Upstream"));

    getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.PAGE_AXIS));
    //getContentPane().add(new JCheckBox("Use incomplete series"));
    getContentPane().add(highPanel);
    //getContentPane().add(new JXButton("Export"));      
    getContentPane().add(caseChartPanel);
    getContentPane().add(mostSimilarChartPanel);
    getContentPane().add(nearestChartPanel);
    getContentPane().add(downstreamChartPanel);
    getContentPane().add(upstreamChartPanel);

    //final Instances kdbDS=GapFillingKnowledgeDB.getKnowledgeDBWithBestCasesOnly();      
    final Instances kdbDS = GapFillingKnowledgeDB.getKnowledgeDB();

    final JXTable gapsTable = buidJXTable(kdbDS);
    final JScrollPane tableScrollPane = new JScrollPane(gapsTable);
    tableScrollPane.setPreferredSize(
            new Dimension(COMPONENT_WIDTH - 100, 40 + (int) (tableScrollPane.getPreferredSize().getHeight())));
    this.tablePanel.add(tableScrollPane);

    gapsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    gapsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(final ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                final int modelRow = gapsTable.getSelectedRow();

                final String attrname = gapsTable.getModel().getValueAt(modelRow, 1).toString();
                final int gapsize = (int) Double
                        .valueOf(gapsTable.getModel().getValueAt(modelRow, 4).toString()).doubleValue();
                final int position = (int) Double
                        .valueOf(gapsTable.getModel().getValueAt(modelRow, 5).toString()).doubleValue();

                final String mostSimilarFlag = gapsTable.getModel().getValueAt(modelRow, 14).toString();
                final String nearestFlag = gapsTable.getModel().getValueAt(modelRow, 15).toString();
                final String downstreamFlag = gapsTable.getModel().getValueAt(modelRow, 16).toString();
                final String upstreamFlag = gapsTable.getModel().getValueAt(modelRow, 17).toString();

                final String algoname = gapsTable.getModel().getValueAt(modelRow, 12).toString();
                final boolean useDiscretizedTime = Boolean
                        .valueOf(gapsTable.getModel().getValueAt(modelRow, 13).toString());

                try {
                    geomapPanel.removeAll();

                    caseChartPanel.removeAll();

                    mostSimilarChartPanel.removeAll();
                    nearestChartPanel.removeAll();
                    downstreamChartPanel.removeAll();
                    upstreamChartPanel.removeAll();

                    final Set<String> selected = new HashSet<String>();

                    final Instances tmpds = WekaDataProcessingUtil.buildFilteredDataSet(ds, 0,
                            ds.numAttributes() - 1,
                            Math.max(0, position - GapsUtil.getCountOfValuesBeforeAndAfter(gapsize)),
                            Math.min(position + gapsize + GapsUtil.getCountOfValuesBeforeAndAfter(gapsize),
                                    ds.numInstances() - 1));

                    final List<String> attributeNames = WekaTimeSeriesUtil
                            .getNamesOfAttributesWithoutGap(tmpds);
                    //final List<String> attributeNames=WekaDataStatsUtil.getAttributeNames(ds);
                    attributeNames.remove(attrname);
                    attributeNames.remove("timestamp");

                    if (Boolean.valueOf(mostSimilarFlag)) {
                        final String mostSimilarStationName = WekaTimeSeriesSimilarityUtil
                                .findMostSimilarTimeSerie(tmpds, tmpds.attribute(attrname), attributeNames,
                                        false);
                        selected.add(mostSimilarStationName);
                        final Attribute mostSimilarStationAttr = tmpds.attribute(mostSimilarStationName);

                        final ChartPanel cp0 = GapsUIUtil.buildGapChartPanel(ds, dateIdx,
                                mostSimilarStationAttr, gapsize, position);
                        cp0.getChart().removeLegend();
                        cp0.setPreferredSize(CHART_DIMENSION);
                        mostSimilarChartPanel.add(cp0);
                    }

                    if (Boolean.valueOf(nearestFlag)) {
                        final String nearestStationName = gcp.findNearestStation(attrname, attributeNames);
                        selected.add(nearestStationName);
                        final Attribute nearestStationAttr = ds.attribute(nearestStationName);

                        final ChartPanel cp0 = GapsUIUtil.buildGapChartPanel(ds, dateIdx, nearestStationAttr,
                                gapsize, position);
                        cp0.getChart().removeLegend();
                        cp0.setPreferredSize(CHART_DIMENSION);
                        nearestChartPanel.add(cp0);
                    }

                    if (Boolean.valueOf(downstreamFlag)) {
                        final String downstreamStationName = gcp.findDownstreamStation(attrname,
                                attributeNames);
                        selected.add(downstreamStationName);
                        final Attribute downstreamStationAttr = ds.attribute(downstreamStationName);

                        final ChartPanel cp0 = GapsUIUtil.buildGapChartPanel(ds, dateIdx, downstreamStationAttr,
                                gapsize, position);
                        cp0.getChart().removeLegend();
                        cp0.setPreferredSize(CHART_DIMENSION);
                        downstreamChartPanel.add(cp0);
                    }

                    if (Boolean.valueOf(upstreamFlag)) {
                        final String upstreamStationName = gcp.findUpstreamStation(attrname, attributeNames);
                        selected.add(upstreamStationName);
                        final Attribute upstreamStationAttr = ds.attribute(upstreamStationName);

                        final ChartPanel cp0 = GapsUIUtil.buildGapChartPanel(ds, dateIdx, upstreamStationAttr,
                                gapsize, position);
                        cp0.getChart().removeLegend();
                        cp0.setPreferredSize(CHART_DIMENSION);
                        upstreamChartPanel.add(cp0);
                    }

                    final GapFiller gapFiller = GapFillerFactory.getGapFiller(algoname, useDiscretizedTime);
                    final ChartPanel cp = GapsUIUtil.buildGapChartPanelWithCorrection(ds, dateIdx,
                            ds.attribute(attrname), gapsize, position, gapFiller, selected);
                    cp.getChart().removeLegend();
                    cp.setPreferredSize(new Dimension((int) CHART_DIMENSION.getWidth(),
                            (int) (CHART_DIMENSION.getHeight() * 1.5)));
                    caseChartPanel.add(cp);

                    geomapPanel.add(buildGeoMapChart(Arrays.asList(attrname), selected));

                    getContentPane().repaint();
                    pack();
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
        }
    });

    gapsTable.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(final MouseEvent e) {
            if (!e.isPopupTrigger()) {
                // nothing?
            } else {
                final JPopupMenu jPopupMenu = new JPopupMenu("feur");

                final JMenuItem mExport = new JMenuItem("Export this table as CSV");
                mExport.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(final ActionEvent e) {
                        final JFileChooser fc = new JFileChooser();
                        fc.setAcceptAllFileFilterUsed(false);
                        final int returnVal = fc.showSaveDialog(gapsTable);
                        if (returnVal == JFileChooser.APPROVE_OPTION) {
                            try {
                                final File file = fc.getSelectedFile();
                                WekaDataAccessUtil.saveInstancesIntoCSVFile(kdbDS, file);
                            } catch (Exception ee) {
                                ee.printStackTrace();
                            }
                        }
                    }
                });
                jPopupMenu.add(mExport);

                jPopupMenu.show(gapsTable, e.getX(), e.getY());
            }
        }
    });

    setPreferredSize(new Dimension(FRAME_WIDTH, 1000));

    pack();
    setVisible(true);

    /* select the first row */
    gapsTable.setRowSelectionInterval(0, 0);
}

From source file:eu.lp0.cursus.ui.AboutDialog.java

private void initialise() {
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    setTitle(Messages.getString("about.title", Constants.APP_DESC)); //$NON-NLS-1$
    DefaultUnitConverter duc = DefaultUnitConverter.getInstance();

    FormLayout layout = new FormLayout("2dlu, pref, fill:pref:grow, max(30dlu;pref), 2dlu", //$NON-NLS-1$
            "2dlu, max(15dlu;pref), 2dlu, max(15dlu;pref), 2dlu, fill:max(100dlu;pref):grow, 2dlu, max(16dlu;pref), 2dlu"); //$NON-NLS-1$
    getContentPane().setLayout(layout);/*from www.  j  a  v  a 2s.c o m*/

    JLabel lblName = new JLabel(Constants.APP_NAME + ": " + Messages.getString("about.description")); //$NON-NLS-1$ //$NON-NLS-2$
    getContentPane().add(lblName, "2, 2, 3, 1"); //$NON-NLS-1$

    getContentPane().add(new LinkJButton(Constants.APP_URL), "2, 4"); //$NON-NLS-1$

    JScrollPane scrCopying = new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    getContentPane().add(scrCopying, "2, 6, 3, 1"); //$NON-NLS-1$

    JTextArea txtCopying = new JTextArea(loadResources("COPYRIGHT", "LICENCE")); //$NON-NLS-1$ //$NON-NLS-2$
    txtCopying.setFont(Font.decode(Font.MONOSPACED));
    txtCopying.setEditable(false);
    scrCopying.setViewportView(txtCopying);
    scrCopying.setPreferredSize(
            new Dimension(scrCopying.getPreferredSize().width, duc.dialogUnitYAsPixel(100, scrCopying)));

    Action actClose = new CloseDialogAction(this);
    JButton btnClose = new JButton(actClose);
    getContentPane().add(btnClose, "4, 8"); //$NON-NLS-1$

    getRootPane().setDefaultButton(btnClose);
    getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
            .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), CloseDialogAction.class.getName());
    getRootPane().getActionMap().put(CloseDialogAction.class.getName(), actClose);

    pack();
    setMinimumSize(getSize());
    setSize(getSize().width, getSize().height * 3 / 2);
    btnClose.requestFocusInWindow();
}

From source file:edu.ku.brc.specify.config.FixAttachments.java

/**
 * @param tableList/*from w  w w  .  ja  v a  2  s. c  om*/
 * @param tableIdList
 * @param resultsHashMap
 * @param tblTypeHash
 * @param tableHash
 * @param totalFiles
 */
private void displayBadAttachments(final ArrayList<JTable> tableList, final ArrayList<Integer> tableIdList,
        final HashMap<Integer, Vector<Object[]>> resultsHashMap, final HashMap<Integer, String> tblTypeHash,
        final HashMap<Integer, AttchTableModel> tableHash, final int totalFiles) {
    CellConstraints cc = new CellConstraints();

    int maxWidth = 200;
    int y = 1;
    String rowDef = tableList.size() == 1 ? "f:p:g"
            : UIHelper.createDuplicateJGoodiesDef("p", "10px", tableList.size());
    PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", rowDef));
    if (tableList.size() > 1) {
        int i = 0;
        for (JTable table : tableList) {
            Integer tblId = tableIdList.get(i++);
            int numRows = table.getModel().getRowCount();

            PanelBuilder pb2 = new PanelBuilder(new FormLayout("f:p:g", "p,2px,f:p:g"));
            if (resultsHashMap.size() > 1) {
                UIHelper.calcColumnWidths(table, numRows < 15 ? numRows + 1 : 15, maxWidth);
            } else {
                UIHelper.calcColumnWidths(table, 15, maxWidth);
            }
            pb2.addSeparator(tblTypeHash.get(tblId), cc.xy(1, 1));
            pb2.add(UIHelper.createScrollPane(table), cc.xy(1, 3));
            pb.add(pb2.getPanel(), cc.xy(1, y));
            y += 2;
        }
    } else {
        UIHelper.calcColumnWidths(tableList.get(0), 15, maxWidth);
        pb.add(UIHelper.createScrollPane(tableList.get(0)), cc.xy(1, 1));
    }
    tableList.clear();

    pb.setDefaultDialogBorder();

    JScrollPane panelSB = UIHelper.createScrollPane(pb.getPanel());
    panelSB.setBorder(BorderFactory.createEmptyBorder());
    Dimension dim = panelSB.getPreferredSize();
    panelSB.setPreferredSize(new Dimension(dim.width + 10, 600));

    final int totFiles = totalFiles;
    String title = String.format("Attachment Information - %d files to recover.", totalFiles);
    CustomDialog dlg = new CustomDialog((Dialog) null, title, true, CustomDialog.OKCANCELAPPLYHELP, panelSB) {
        @Override
        protected void helpButtonPressed() {
            File file = produceSummaryReport(resultsHashMap, tableHash, totFiles);
            try {
                AttachmentUtils.openURI(file.toURI());
            } catch (Exception e) {
            }
        }

        @Override
        protected void applyButtonPressed() {
            boolean isOK = UIRegistry.displayConfirm("Clean up",
                    "Are you sure you want to remove all references to the missing attachments?", "Remove",
                    "Cancel", JOptionPane.WARNING_MESSAGE);
            if (isOK) {
                super.applyButtonPressed();
            }
        }
    };

    dlg.setCloseOnApplyClk(true);
    dlg.setCancelLabel("Skip");
    dlg.setOkLabel("Recover Files");
    dlg.setHelpLabel("Show Summary");
    dlg.setApplyLabel("Delete References");
    dlg.createUI();
    dlg.pack();

    dlg.setVisible(true);

    if (dlg.getBtnPressed() == CustomDialog.OK_BTN) {
        reattachFiles(resultsHashMap, tableHash, totalFiles);

    } else if (dlg.getBtnPressed() == CustomDialog.APPLY_BTN) {
        doAttachmentRefCleanup(resultsHashMap, tableHash, totFiles);
    }

}

From source file:display.containers.FileManager.java

public Container getPane() {
    //if (gui==null) {

    fileSystemView = FileSystemView.getFileSystemView();
    desktop = Desktop.getDesktop();

    JPanel detailView = new JPanel(new BorderLayout(3, 3));
    //fileTableModel = new FileTableModel();

    table = new JTable();
    table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    table.setAutoCreateRowSorter(true);//from  w  w w  .j  a  v  a  2  s . c o m
    table.setShowVerticalLines(false);
    table.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            if (e.getClickCount() >= 2) {
                Point p = e.getPoint();
                int row = table.convertRowIndexToModel(table.rowAtPoint(p));
                int column = table.convertColumnIndexToModel(table.columnAtPoint(p));
                if (row >= 0 && column >= 0) {
                    mouseDblClicked(row, column);
                }
            }
        }
    });
    table.addKeyListener(new KeyListener() {

        @Override
        public void keyTyped(KeyEvent arg0) {

        }

        @Override
        public void keyReleased(KeyEvent arg0) {
            if (KeyEvent.VK_DELETE == arg0.getKeyCode()) {
                if (mode != 2) {
                    parentFrame.setLock(true);
                    parentFrame.getProgressBarPanel().setVisible(true);
                    Thread t = new Thread(new Runnable() {

                        @Override
                        public void run() {
                            try {
                                deleteSelectedFiles();
                            } catch (IOException e) {
                                JOptionPane.showMessageDialog(parentFrame, "Error during the deletion.",
                                        "Deletion error", JOptionPane.ERROR_MESSAGE);
                                WindowManager.mwLogger.log(Level.SEVERE, "Error during the deletion.", e);
                            } finally {
                                parentFrame.setLock(false);
                                refresh();
                                parentFrame.getProgressBarPanel().setVisible(false);
                            }
                        }
                    });
                    t.start();

                } else {
                    if (UserProfile.CURRENT_USER.getLevel() == 3) {
                        parentFrame.setLock(true);
                        parentFrame.getProgressBarPanel().setVisible(true);
                        Thread delThread = new Thread(new Runnable() {

                            @Override
                            public void run() {
                                int[] rows = table.getSelectedRows();
                                int[] columns = table.getSelectedColumns();
                                for (int i = 0; i < rows.length; i++) {
                                    if (!continueAction) {
                                        continueAction = true;
                                        return;
                                    }
                                    int row = table.convertRowIndexToModel(rows[i]);
                                    try {
                                        deleteServerFile(row);
                                    } catch (Exception e) {
                                        WindowManager.mwLogger.log(Level.SEVERE, "Error during the deletion.",
                                                e);
                                    }
                                }
                                refresh();
                                parentFrame.setLock(false);
                                parentFrame.getProgressBarPanel().setVisible(false);
                            }
                        });
                        delThread.start();

                    }
                }
            }
        }

        @Override
        public void keyPressed(KeyEvent arg0) {
            // TODO Auto-generated method stub

        }
    });
    table.getSelectionModel().addListSelectionListener(listSelectionListener);
    JScrollPane tableScroll = new JScrollPane(table);
    Dimension d = tableScroll.getPreferredSize();
    tableScroll.setPreferredSize(new Dimension((int) d.getWidth(), (int) d.getHeight() / 2));
    detailView.add(tableScroll, BorderLayout.CENTER);

    // the File tree
    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    treeModel = new DefaultTreeModel(root);
    table.getRowSorter().addRowSorterListener(new RowSorterListener() {

        @Override
        public void sorterChanged(RowSorterEvent e) {
            ((FileTableModel) table.getModel()).fireTableDataChanged();
        }
    });

    // show the file system roots.
    File[] roots = fileSystemView.getRoots();
    for (File fileSystemRoot : roots) {
        DefaultMutableTreeNode node = new DefaultMutableTreeNode(fileSystemRoot);
        root.add(node);
        //showChildren(node);
        //
        File[] files = fileSystemView.getFiles(fileSystemRoot, true);
        for (File file : files) {
            if (file.isDirectory()) {
                node.add(new DefaultMutableTreeNode(file));
            }
        }
        //
    }
    JScrollPane treeScroll = new JScrollPane();

    Dimension preferredSize = treeScroll.getPreferredSize();
    Dimension widePreferred = new Dimension(200, (int) preferredSize.getHeight());
    treeScroll.setPreferredSize(widePreferred);

    JPanel fileView = new JPanel(new BorderLayout(3, 3));

    detailView.add(fileView, BorderLayout.SOUTH);

    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, treeScroll, detailView);

    JPanel simpleOutput = new JPanel(new BorderLayout(3, 3));
    progressBar = new JProgressBar();
    simpleOutput.add(progressBar, BorderLayout.EAST);
    progressBar.setVisible(false);
    showChildren(getCurrentDir().toPath());
    //table.setDragEnabled(true);
    table.setColumnSelectionAllowed(false);

    // Menu popup
    Pmenu = new JPopupMenu();
    changeProjectitem = new JMenuItem("Reassign");
    renameProjectitem = new JMenuItem("Rename");
    twitem = new JMenuItem("To workspace");
    tlitem = new JMenuItem("To local");
    processitem = new JMenuItem("Select for process");
    switch (mode) {
    case 0:
        Pmenu.add(twitem);
        twitem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                parentFrame.getBtnlocalTowork().doClick();
            }
        });
        break;
    case 1:
        Pmenu.add(tlitem);
        Pmenu.add(processitem);
        tlitem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                parentFrame.getBtnWorkTolocal().doClick();
            }
        });
        processitem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        // Recupere les lignes selectionnees
                        int[] indices = table.getSelectedRows();
                        // On recupere les fichiers correspondants
                        ArrayList<File> files = new ArrayList<File>();
                        for (int i = 0; i < indices.length; i++) {
                            int row = table.convertRowIndexToModel(indices[i]);
                            File fi = ((FileTableModel) table.getModel()).getFile(row);
                            if (fi.isDirectory())
                                files.add(fi);
                        }
                        ImageProcessingFrame imf = new ImageProcessingFrame(files);
                    }
                });

            }
        });
        break;
    case 2:
        if (UserProfile.CURRENT_USER.getLevel() == 3) {
            Pmenu.add(changeProjectitem);
            Pmenu.add(renameProjectitem);
        }
        Pmenu.add(twitem);
        twitem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                parentFrame.getBtndistToWorkspace().doClick();
            }
        });
        Pmenu.add(tlitem);
        tlitem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                parentFrame.getBtndistToLocal().doClick();
            }
        });
        break;
    }
    changeProjectitem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            table.setEnabled(false);
            File from = ((FileTableModel) table.getModel())
                    .getFile(table.convertRowIndexToModel(table.getSelectedRows()[0]));

            ReassignProjectPanel reas = new ReassignProjectPanel(from.toPath()); // mode creation de liens
            Popup popup = PopupFactory.getSharedInstance().getPopup(WindowManager.MAINWINDOW, reas,
                    (int) WindowManager.MAINWINDOW.getX() + 200, (int) WindowManager.MAINWINDOW.getY() + 150);
            reas.setPopupWindow(popup);
            popup.show();
            table.setEnabled(true);
        }
    });
    renameProjectitem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            table.setEnabled(false);
            final File from = ((FileTableModel) table.getModel())
                    .getFile(table.convertRowIndexToModel(table.getSelectedRows()[0]));
            JDialog.setDefaultLookAndFeelDecorated(true);
            String s = (String) JOptionPane.showInputDialog(WindowManager.MAINWINDOW, "New project name ?",
                    "Rename project", JOptionPane.PLAIN_MESSAGE, null, null, from.getName());

            //If a string was returned, say so.
            if ((s != null) && (s.length() > 0)) {
                ProjectDAO pdao = new MySQLProjectDAO();
                if (new File(from.getParent() + File.separator + s).exists()) {
                    SwingUtilities.invokeLater(new Runnable() {

                        @Override
                        public void run() {
                            JDialog.setDefaultLookAndFeelDecorated(true);
                            JOptionPane.showMessageDialog(WindowManager.MAINWINDOW,
                                    "Couldn't rename " + from.getName()
                                            + " (A file with this filename already exists)",
                                    "Renaming error", JOptionPane.ERROR_MESSAGE);
                        }
                    });
                    WindowManager.mwLogger.log(Level.SEVERE,
                            "Error during file project renaming (" + from.getName() + "). [Duplication error]");
                } else {
                    try {
                        boolean succeed = pdao.renameProject(from.getName(), s);
                        if (!succeed) {
                            SwingUtilities.invokeLater(new Runnable() {

                                @Override
                                public void run() {
                                    JDialog.setDefaultLookAndFeelDecorated(true);
                                    JOptionPane.showMessageDialog(WindowManager.MAINWINDOW,
                                            "Couldn't rename " + from.getName()
                                                    + " (no project with this name)",
                                            "Renaming error", JOptionPane.ERROR_MESSAGE);
                                }
                            });
                        } else {
                            from.renameTo(new File(from.getParent() + File.separator + s));
                            // on renomme le repertoire nifti ou dicom correspondant si il existe
                            switch (from.getParentFile().getName()) {
                            case ServerInfo.NRI_ANALYSE_NAME:
                                if (new File(from.getAbsolutePath().replaceAll(ServerInfo.NRI_ANALYSE_NAME,
                                        ServerInfo.NRI_DICOM_NAME)).exists())
                                    try {
                                        Files.move(Paths.get(from.getAbsolutePath().replaceAll(
                                                ServerInfo.NRI_ANALYSE_NAME, ServerInfo.NRI_DICOM_NAME)),
                                                Paths.get(from.getParent().replaceAll(
                                                        ServerInfo.NRI_ANALYSE_NAME, ServerInfo.NRI_DICOM_NAME)
                                                        + File.separator + s));
                                    } catch (IOException e) {
                                        e.printStackTrace();
                                        SwingUtilities.invokeLater(new Runnable() {

                                            @Override
                                            public void run() {
                                                JDialog.setDefaultLookAndFeelDecorated(true);
                                                JOptionPane.showMessageDialog(WindowManager.MAINWINDOW,
                                                        "Couldn't rename " + from.getName()
                                                                + " (error with file system)",
                                                        "Renaming error", JOptionPane.ERROR_MESSAGE);
                                            }
                                        });
                                        WindowManager.mwLogger.log(Level.SEVERE,
                                                "Error during file project renaming (" + from.getName() + ")",
                                                e);
                                    } //from.renameTo(new File(from.getParent().replaceAll(ServerInfo.NRI_ANALYSE_NAME, ServerInfo.NRI_DICOM_NAME)+File.separator+s));
                                break;
                            case ServerInfo.NRI_DICOM_NAME:
                                if (new File(from.getAbsolutePath().replaceAll(ServerInfo.NRI_DICOM_NAME,
                                        ServerInfo.NRI_ANALYSE_NAME)).exists())
                                    try {
                                        Files.move(Paths.get(from.getAbsolutePath().replaceAll(
                                                ServerInfo.NRI_DICOM_NAME, ServerInfo.NRI_ANALYSE_NAME)),
                                                Paths.get(from.getParent().replaceAll(ServerInfo.NRI_DICOM_NAME,
                                                        ServerInfo.NRI_ANALYSE_NAME) + File.separator + s));
                                    } catch (IOException e) {
                                        SwingUtilities.invokeLater(new Runnable() {

                                            @Override
                                            public void run() {
                                                JDialog.setDefaultLookAndFeelDecorated(true);
                                                JOptionPane.showMessageDialog(WindowManager.MAINWINDOW,
                                                        "Couldn't rename " + from.getName()
                                                                + " (error with file system)",
                                                        "Renaming error", JOptionPane.ERROR_MESSAGE);
                                            }
                                        });
                                        e.printStackTrace();
                                        WindowManager.mwLogger.log(Level.SEVERE,
                                                "Error during file project renaming (" + from.getName() + ")",
                                                e);
                                    } //from.renameTo(new File(from.getParent().replaceAll(ServerInfo.NRI_DICOM_NAME, ServerInfo.NRI_ANALYSE_NAME)+File.separator+s));
                                break;
                            }
                            refresh();
                        }
                    } catch (final SQLException e) {
                        WindowManager.mwLogger.log(Level.SEVERE, "Error during SQL project renaming", e);
                        SwingUtilities.invokeLater(new Runnable() {

                            @Override
                            public void run() {
                                JDialog.setDefaultLookAndFeelDecorated(true);
                                JOptionPane.showMessageDialog(WindowManager.MAINWINDOW,
                                        "Exception : " + e.toString(), "Openning error",
                                        JOptionPane.ERROR_MESSAGE);
                            }
                        });
                    }
                }
            }
            table.setEnabled(true);
        }
    });
    table.addMouseListener(new MouseListener() {

        public void mouseClicked(MouseEvent me) {

        }

        public void mouseEntered(MouseEvent e) {
        }

        public void mouseExited(MouseEvent e) {
        }

        public void mousePressed(MouseEvent e) {
        }

        public void mouseReleased(MouseEvent me) {
            if (me.getButton() == 3 && table.getSelectedRowCount() > 0) {
                int row = table.convertRowIndexToModel(table.rowAtPoint(me.getPoint()));
                changeProjectitem.setVisible(isPatient(((FileTableModel) table.getModel()).getFile(row)));
                renameProjectitem.setVisible(isProject(((FileTableModel) table.getModel()).getFile(row)));
                Pmenu.show(me.getComponent(), me.getX(), me.getY());
            }
        }
    });
    //

    //}
    return tableScroll;
}

From source file:com.xilinx.virtex7.MainScreen.java

private JPanel messageBox() {
    JPanel tstats3 = new JPanel(new BorderLayout());
    /*tstats3.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createTitledBorder("Message Log"),
                BorderFactory.createRaisedBevelBorder()));*/
    JPanel trnPanel = new JPanel(new GridLayout(1, 1));
    trnPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("PCIe Statistics"),
            BorderFactory.createRaisedBevelBorder()));
    JPanel trn1 = new JPanel(new FlowLayout());
    trn1.add(new JLabel("Transmit (writes in Gbps): "));
    trnLTX = new JTextField("0.0", 5);
    trnLTX.setEditable(false);/*w  w w.  j  a v a2s  . c  o m*/
    trn1.add(trnLTX);
    trn1.add(new JLabel("Receive (reads in Gbps): "));
    trnLRX = new JTextField("0.0", 5);
    trnLRX.setEditable(false);
    trn1.add(trnLRX);
    trnPanel.add(trn1);

    textArea = new CustomTextPane();

    final JScrollPane scrollPane = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Message Log"),
            BorderFactory.createRaisedBevelBorder()));
    scrollPane.setPreferredSize(new Dimension(scrollPane.getPreferredSize().width, 100));
    //scrollPane.setMaximumSize(new Dimension(scrollPane.getPreferredSize().width, 100));  
    // keep scrollbar at end showing latest messages
    /*scrollPane.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {
    BoundedRangeModel brm = scrollPane.getVerticalScrollBar().getModel();
    boolean wasAtBottom = true;
    @Override
    public void adjustmentValueChanged(AdjustmentEvent ae) {
        if (!brm.getValueIsAdjusting() &&
                 (scrollPane.) == brm.getMaximum()) {
            if (wasAtBottom)
                brm.setValue(brm.getMaximum());
                       
         } else
                wasAtBottom = ((brm.getValue() + brm.getExtent()) == brm.getMaximum());
            
        }
    });*/

    textArea.setEditable(false);

    tstats3.add(scrollPane, BorderLayout.CENTER);

    tstats3.add(trnPanel, BorderLayout.PAGE_START);
    return tstats3;
    // testPanel.add(tstats3, BorderLayout.PAGE_END);
}