org.xtce.apps.editor.ui.XTCEViewerAuthorSet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xtcetools Show documentation
Show all versions of xtcetools Show documentation
This project contains software to support the Object Management Group (OMG) Space Domain Task Force (SDTF) maintained XML Telemetry and Command Exchange (XTCE) specification.
/* Copyright 2015 David Overeem ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.xtce.apps.editor.ui;
import java.awt.Component;
import java.util.ArrayList;
import java.util.List;
import javax.swing.BoxLayout;
import javax.swing.JPanel;
import org.omg.space.xtce.HeaderType;
import org.xtce.toolkit.XTCESpaceSystem;
/**
*
* @author David Overeem
*
*/
public class XTCEViewerAuthorSet extends javax.swing.JPanel {
/**
* Creates new form XTCEViewerAuthorSet
*/
public XTCEViewerAuthorSet() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// //GEN-BEGIN:initComponents
private void initComponents() {
authorListScrollPane = new javax.swing.JScrollPane();
addAuthorButton = new javax.swing.JButton();
authorListLabel = new javax.swing.JLabel();
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/xtce/toolkit/MessagesBundle"); // NOI18N
addAuthorButton.setText(bundle.getString("tab_ssdetail_addauthor_text")); // NOI18N
addAuthorButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addAuthorButtonActionPerformed(evt);
}
});
authorListLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
authorListLabel.setText(bundle.getString("tab_ssdetail_authorlist_text")); // NOI18N
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(authorListScrollPane)
.addGroup(layout.createSequentialGroup()
.addGap(0, 174, Short.MAX_VALUE)
.addComponent(addAuthorButton)
.addGap(0, 175, Short.MAX_VALUE))
.addComponent(authorListLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(authorListLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(authorListScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 141, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(addAuthorButton)
.addGap(4, 4, 4))
);
}// //GEN-END:initComponents
private void addAuthorButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addAuthorButtonActionPerformed
addAuthor( "New Author" );
}//GEN-LAST:event_addAuthorButtonActionPerformed
public void setSpaceSystem( XTCESpaceSystem spaceSystem ) {
spaceSystem_ = spaceSystem;
HeaderType header = spaceSystem_.getReference().getHeader();
if ( header != null ) {
HeaderType.AuthorSet notes = header.getAuthorSet();
if ( notes != null ) {
noteItemText_.clear();
noteItemText_.addAll( notes.getAuthor() );
makeContentPanel( noteItemText_ );
}
}
}
public void setEditable( boolean editEnabled ) {
addAuthorButton.setEnabled( editEnabled );
JPanel notePanel = (JPanel)authorListScrollPane.getViewport().getView();
if ( notePanel == null ) {
return;
}
Component[] components = notePanel.getComponents();
for ( Component component : components ) {
if ( component.getClass() == XTCEViewerAuthor.class ) {
((XTCEViewerAuthor)component).setEditable( editEnabled );
}
}
}
public void removeAuthor( int idx ) {
noteItemText_.remove( idx );
makeContentPanel( noteItemText_ );
updateDocument();
}
public void addAuthor( String newNoteText ) {
noteItemText_.add( newNoteText );
makeContentPanel( noteItemText_ );
updateDocument();
}
public void editAuthor( String newNoteText, int idx ) {
noteItemText_.set( idx, newNoteText );
updateDocument();
}
private void makeContentPanel( List notes ) {
JPanel notePanel = new JPanel();
notePanel.setLayout( new BoxLayout( notePanel, BoxLayout.Y_AXIS ) );
int idx = 0;
for ( String note : notes ) {
XTCEViewerAuthor noteEntry = new XTCEViewerAuthor( this, note, idx++ );
notePanel.add( noteEntry );
}
authorListScrollPane.setViewportView( notePanel );
authorListScrollPane.revalidate();
authorListScrollPane.repaint();
}
private void updateDocument() {
// ensure that the Header element exists
HeaderType header = spaceSystem_.getReference().getHeader();
if ( header == null ) {
header = new HeaderType();
spaceSystem_.getReference().setHeader( header );
}
// first clear the NoteSet element if there are no notes
HeaderType.AuthorSet notes = header.getAuthorSet();
if ( noteItemText_.isEmpty() == true ) {
if ( notes != null ) {
header.setAuthorSet( null );
}
return;
}
// add a Note element for each one
if ( notes == null ) {
notes = new HeaderType.AuthorSet();
header.setAuthorSet( notes );
}
notes.getAuthor().clear();
notes.getAuthor().addAll( noteItemText_ );
}
// Private Data Members
private XTCESpaceSystem spaceSystem_ = null;
private ArrayList noteItemText_ = new ArrayList<>();
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton addAuthorButton;
private javax.swing.JLabel authorListLabel;
private javax.swing.JScrollPane authorListScrollPane;
// End of variables declaration//GEN-END:variables
}