Search in sources :

Example 51 with SuppressFBWarnings

use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project JMRI by JMRI.

the class ListedTableFrame method initComponents.

@Override
public void initComponents() {
    actionList = new ActionJList(this);
    detailpanel = new JPanel();
    detailpanel.setLayout(new CardLayout());
    tabbedTableArray = new ArrayList<TabbedTableItem>(TabbedTableItemListArrayArray.size());
    ArrayList<TabbedTableItemListArray> removeItem = new ArrayList<TabbedTableItemListArray>(5);
    for (int x = 0; x < TabbedTableItemListArrayArray.size(); x++) {
        /* Here we add all the tables into the panel*/
        TabbedTableItemListArray item = TabbedTableItemListArrayArray.get(x);
        try {
            TabbedTableItem itemModel = new TabbedTableItem(item.getClassAsString(), item.getItemString(), item.getStandardTableModel());
            itemBeingAdded = itemModel;
            detailpanel.add(itemModel.getPanel(), itemModel.getClassAsString());
            tabbedTableArray.add(itemModel);
            itemBeingAdded.getAAClass().addToFrame(this);
        } catch (Exception ex) {
            detailpanel.add(errorPanel(item.getItemString()), item.getClassAsString());
            log.error("Error when adding " + item.getClassAsString() + " to display\n" + ex);
            ex.printStackTrace();
            removeItem.add(item);
        }
    }
    for (TabbedTableItemListArray dead : removeItem) {
        TabbedTableItemListArrayArray.remove(dead);
    }
    list = new JList<String>(new Vector<String>(getChoices()));
    listScroller = new JScrollPane(list);
    list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    list.setLayoutOrientation(JList.VERTICAL);
    list.addMouseListener(actionList);
    buttonpanel = new JPanel();
    buttonpanel.setLayout(new BorderLayout(5, 0));
    buttonpanel.setLayout(new BoxLayout(buttonpanel, BoxLayout.Y_AXIS));
    buttonpanel.add(listScroller);
    buildMenus(tabbedTableArray.get(0));
    setTitle(tabbedTableArray.get(0).getItemString());
    cardHolder = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, buttonpanel, detailpanel);
    cardHolder.setDividerSize(8);
    if (lastdivider != 0) {
        cardHolder.setDividerLocation(lastdivider);
    } else {
        // if no specific size has been given we set it to the lists preferred width
        cardHolder.setDividerLocation(listScroller.getPreferredSize().width);
    }
    cardHolder.addPropertyChangeListener(new PropertyChangeListener() {

        @SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD", justification = "We only intend to use/save the last position of the Split frame")
        @Override
        public void propertyChange(PropertyChangeEvent e) {
            if (e.getPropertyName().equals("dividerLocation")) {
                lastdivider = (Integer) e.getNewValue();
            }
        }
    });
    cardHolder.setOneTouchExpandable(true);
    getContentPane().add(cardHolder);
    pack();
    actionList.selectListItem(0);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) CardLayout(java.awt.CardLayout) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) BoxLayout(javax.swing.BoxLayout) ArrayList(java.util.ArrayList) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) BorderLayout(java.awt.BorderLayout) JSplitPane(javax.swing.JSplitPane) Vector(java.util.Vector)

Example 52 with SuppressFBWarnings

use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project JMRI by JMRI.

the class InstallDecoderURLAction method copyfile.

@SuppressFBWarnings(value = "OBL_UNSATISFIED_OBLIGATION", justification = "Looks like false positive")
boolean copyfile(URL from, File toFile, JPanel who) {
    InputStream in = null;
    OutputStream out = null;
    try {
        in = from.openConnection().getInputStream();
        // open for overwrite
        out = new FileOutputStream(toFile);
        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
    // done - finally cleans up
    } catch (FileNotFoundException ex) {
        log.debug("" + ex);
        JOptionPane.showMessageDialog(who, Bundle.getMessage("CopyError1"));
        return false;
    } catch (IOException e) {
        log.debug("" + e);
        JOptionPane.showMessageDialog(who, Bundle.getMessage("CopyError2"));
        return false;
    } finally {
        try {
            if (in != null) {
                in.close();
            }
        } catch (IOException e1) {
            log.error("exception closing in stream", e1);
        }
        try {
            if (out != null) {
                out.close();
            }
        } catch (IOException e2) {
            log.error("exception closing out stream", e2);
        }
    }
    return true;
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 53 with SuppressFBWarnings

use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project JMRI by JMRI.

the class NXFrame method makeAutoRunPanel.

@SuppressFBWarnings(value = "DB_DUPLICATE_SWITCH_CLAUSES", justification = "Same code for both cases")
private JPanel makeAutoRunPanel(int interpretation) {
    JPanel p1 = new JPanel();
    p1.setLayout(new BoxLayout(p1, BoxLayout.PAGE_AXIS));
    float maxSpeed;
    float throttleIncr;
    String maxSpeedLabel;
    String throttleIncrLabel;
    switch(interpretation) {
        case SignalSpeedMap.PERCENT_NORMAL:
        case SignalSpeedMap.PERCENT_THROTTLE:
            maxSpeed = _maxThrottle;
            maxSpeedLabel = "MaxSpeed";
            throttleIncr = _minSpeed;
            throttleIncrLabel = "RampIncrement";
            break;
        case SignalSpeedMap.SPEED_MPH:
            // 2.2369363 is 3.6 converted by mile/km
            maxSpeed = _maxThrottle * _throttleFactor * 223.69363f;
            maxSpeedLabel = "MaxMph";
            throttleIncr = _minSpeed * _throttleFactor * 223.69363f;
            throttleIncrLabel = "MinMph";
            break;
        case SignalSpeedMap.SPEED_KMPH:
            maxSpeed = _maxThrottle * _throttleFactor * 360f;
            maxSpeedLabel = "MaxKMph";
            throttleIncr = _minSpeed * _throttleFactor * 360f;
            throttleIncrLabel = "MinKMph";
            break;
        default:
            maxSpeed = _maxThrottle;
            maxSpeedLabel = "MaxSpeed";
            throttleIncr = _minSpeed;
            throttleIncrLabel = "RampIncrement";
    }
    p1.add(makeTextBoxPanel(false, _maxSpeedBox, maxSpeedLabel, null));
    p1.add(makeTextBoxPanel(false, _rampInterval, "rampInterval", null));
    p1.add(makeTextBoxPanel(false, _rampIncre, throttleIncrLabel, "ToolTipRampIncrement"));
    p1.add(makeTextBoxPanel(false, _throttleFactorBox, "ThrottleScale", "ToolTipThrottleScale"));
    p1.add(makeTextBoxPanel(false, _shareRouteBox, "ShareRoute", "ToolTipShareRoute"));
    _maxSpeedBox.setText(Float.toString(maxSpeed));
    _rampInterval.setText(Float.toString(_intervalTime / 1000));
    _rampIncre.setText(Float.toString(throttleIncr));
    _throttleFactorBox.setText(Float.toString(_throttleFactor));
    JPanel p2 = new JPanel();
    p2.setLayout(new BoxLayout(p2, BoxLayout.PAGE_AXIS));
    //        JPanel trainPanel = makeTrainIdPanel(makeTextBoxPanel(
    //                false, _shareRouteBox, "ShareRoute", "ToolTipShareRoute"));
    JPanel trainPanel = makeTrainIdPanel(null);
    p2.add(trainPanel);
    JPanel autoRunPanel = new JPanel();
    autoRunPanel.setLayout(new BoxLayout(autoRunPanel, BoxLayout.PAGE_AXIS));
    JPanel pp = new JPanel();
    pp.setLayout(new BoxLayout(pp, BoxLayout.LINE_AXIS));
    pp.add(Box.createHorizontalStrut(STRUT_SIZE));
    pp.add(p1);
    pp.add(Box.createHorizontalStrut(STRUT_SIZE));
    pp.add(p2);
    pp.add(Box.createHorizontalStrut(STRUT_SIZE));
    autoRunPanel.add(pp);
    ButtonGroup bg = new ButtonGroup();
    bg.add(_forward);
    bg.add(_reverse);
    p1 = new JPanel();
    p1.setLayout(new BoxLayout(p1, BoxLayout.LINE_AXIS));
    p1.add(Box.createHorizontalGlue());
    p1.add(makeTextBoxPanel(false, _forward, "forward", null));
    p1.add(makeTextBoxPanel(false, _reverse, "reverse", null));
    p1.add(Box.createHorizontalGlue());
    pp = new JPanel();
    pp.setLayout(new BoxLayout(pp, BoxLayout.LINE_AXIS));
    pp.add(Box.createHorizontalStrut(STRUT_SIZE));
    pp.add(p1);
    pp.add(Box.createHorizontalStrut(STRUT_SIZE));
    pp.add(Box.createHorizontalStrut(2 * STRUT_SIZE));
    autoRunPanel.add(pp);
    JPanel ppp = new JPanel();
    ppp.setLayout(new BoxLayout(ppp, BoxLayout.LINE_AXIS));
    ppp.add(Box.createHorizontalStrut(STRUT_SIZE));
    ppp.add(makeTextBoxPanel(false, _stageEStop, "StageEStop", null));
    ppp.add(Box.createHorizontalStrut(STRUT_SIZE));
    ppp.add(makeTextBoxPanel(false, _haltStartBox, "HaltAtStart", null));
    ppp.add(Box.createHorizontalStrut(STRUT_SIZE));
    ppp.add(makeTextBoxPanel(false, _calibrateBox, "Calibrate", "calibBlockMessage"));
    ppp.add(Box.createHorizontalStrut(STRUT_SIZE));
    autoRunPanel.add(ppp);
    return autoRunPanel;
}
Also used : JPanel(javax.swing.JPanel) ButtonGroup(javax.swing.ButtonGroup) BoxLayout(javax.swing.BoxLayout) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 54 with SuppressFBWarnings

use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project JMRI by JMRI.

the class LocationCopyFrame method buttonActionPerformed.

@Override
@SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD", justification = "GUI ease of use")
protected void buttonActionPerformed(java.awt.event.ActionEvent ae) {
    if (ae.getSource() == copyButton) {
        log.debug("copy location button activated");
        if (!checkName()) {
            return;
        }
        if (locationBox.getSelectedItem() == null) {
            JOptionPane.showMessageDialog(this, Bundle.getMessage("SelectLocationToCopy"), MessageFormat.format(Bundle.getMessage("CanNotLocation"), new Object[] { Bundle.getMessage("ButtonCopy") }), JOptionPane.ERROR_MESSAGE);
            return;
        }
        Location location = (Location) locationBox.getSelectedItem();
        // check to see if there are cars scheduled for pickup or set out
        if (moveRollingStockCheckBox.isSelected()) {
            for (Track track : location.getTrackList()) {
                if (track.getPickupRS() > 0) {
                    JOptionPane.showMessageDialog(this, MessageFormat.format(Bundle.getMessage("FoundRollingStockPickUp"), new Object[] { track.getPickupRS() }), MessageFormat.format(Bundle.getMessage("TrainsServicingTrack"), new Object[] { track.getName() }), JOptionPane.WARNING_MESSAGE);
                    // can't move rolling stock, some are scheduled for a pick up
                    return;
                }
                if (track.getDropRS() > 0) {
                    JOptionPane.showMessageDialog(this, MessageFormat.format(Bundle.getMessage("FoundRollingStockDrop"), new Object[] { track.getDropRS() }), MessageFormat.format(Bundle.getMessage("TrainsServicingTrack"), new Object[] { track.getName() }), JOptionPane.WARNING_MESSAGE);
                    // can't move rolling stock, some are scheduled for drops
                    return;
                }
            }
        }
        // now copy all of the tracks
        Location newLocation = locationManager.newLocation(loctionNameTextField.getText());
        location.copyLocation(newLocation);
        // does the user want the cars to also move to the new tracks?
        if (moveRollingStockCheckBox.isSelected()) {
            for (Track track : location.getTrackList()) {
                moveRollingStock(track, newLocation.getTrackByName(track.getName(), null));
                if (deleteTrackCheckBox.isSelected()) {
                    location.deleteTrack(track);
                }
            }
        }
    }
    if (ae.getSource() == saveButton) {
        log.debug("save track button activated");
        // save checkbox states
        moveRollingStock = moveRollingStockCheckBox.isSelected();
        deleteTrack = deleteTrackCheckBox.isSelected();
        // save location file
        OperationsXml.save();
    }
}
Also used : Track(jmri.jmrit.operations.locations.Track) Location(jmri.jmrit.operations.locations.Location) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 55 with SuppressFBWarnings

use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project JMRI by JMRI.

the class CarsTableModel method toggleSelectVisible.

@SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD", // NOI18N
justification = "GUI ease of use")
public void toggleSelectVisible() {
    XTableColumnModel tcm = (XTableColumnModel) _table.getColumnModel();
    isSelectVisible = !tcm.isColumnVisible(tcm.getColumnByModelIndex(SELECT_COLUMN));
    tcm.setColumnVisible(tcm.getColumnByModelIndex(SELECT_COLUMN), isSelectVisible);
}
Also used : XTableColumnModel(jmri.util.swing.XTableColumnModel) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)142 IOException (java.io.IOException)23 File (java.io.File)22 ArrayList (java.util.ArrayList)20 JPanel (javax.swing.JPanel)14 RollingStock (jmri.jmrit.operations.rollingstock.RollingStock)13 ScriptException (org.jaggeryjs.scriptengine.exceptions.ScriptException)13 FlowLayout (java.awt.FlowLayout)8 BoxLayout (javax.swing.BoxLayout)7 Location (jmri.jmrit.operations.locations.Location)7 Dimension (java.awt.Dimension)5 FileOutputStream (java.io.FileOutputStream)5 Connection (java.sql.Connection)5 PreparedStatement (java.sql.PreparedStatement)5 Iterator (java.util.Iterator)5 JScrollPane (javax.swing.JScrollPane)5 RouteLocation (jmri.jmrit.operations.routes.RouteLocation)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 List (java.util.List)4 Entry (java.util.Map.Entry)4