/*
* Copyright 2013 Serdar.
*
* 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 de.fub.maps.project.detector.model.inference.ui;
import de.fub.maps.project.detector.model.inference.processhandler.InferenceModelProcessHandler;
import de.fub.maps.project.detector.model.xmls.ProcessHandlerDescriptor;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Collection;
import javax.swing.JTextArea;
import org.openide.explorer.ExplorerManager;
import org.openide.nodes.Node;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
/**
*
* @author Serdar
*/
public final class ProcessHandlerPanel extends javax.swing.JPanel implements MouseListener {
private static final long serialVersionUID = 1L;
/**
* Creates new form ProcessHandlerPanel
*/
public ProcessHandlerPanel() {
initComponents();
Collection<? extends InferenceModelProcessHandler> processHandlerList = Lookup.getDefault().lookupResult(InferenceModelProcessHandler.class).allInstances();
for (InferenceModelProcessHandler processHandler : processHandlerList) {
ProcessHandlerDescriptor descriptor = processHandler.getDescriptor();
if (descriptor != null) {
switch (descriptor.getInferenceMode()) {
case TRAININGS_MODE:
getTrainingProcessSelectionComponent().getProcessHandlerList().add(processHandler);
break;
case INFERENCE_MODE:
getInferenceProcessSelectionComponent().getProcessHandlerList().add(processHandler);
break;
case CROSS_VALIDATION_MODE:
getCrossvalidationProcessSelectionComponent().getProcessHandlerList().add(processHandler);
break;
default:
throw new AssertionError();
}
}
}
getTrainingProcessSelectionComponent().getTitle().setText(NbBundle.getMessage(ProcessHandlerPanel.class, "ProcessHandlerPanel.trainings.title"));
getCrossvalidationProcessSelectionComponent().getTitle().setText(NbBundle.getMessage(ProcessHandlerPanel.class, "ProcessHandlerPanel.crossvalidation.title"));
getInferenceProcessSelectionComponent().getTitle().setText(NbBundle.getMessage(ProcessHandlerPanel.class, "ProcessHandlerPanel.inference.title"));
getCrossvalidationProcessSelectionComponent().getListView().getViewport().getView().addMouseListener(ProcessHandlerPanel.this);
getInferenceProcessSelectionComponent().getListView().getViewport().getView().addMouseListener(ProcessHandlerPanel.this);
getTrainingProcessSelectionComponent().getListView().getViewport().getView().addMouseListener(ProcessHandlerPanel.this);
}
public ProcessSelectionComponent getCrossvalidationProcessSelectionComponent() {
return crossValidationProcessSelectionComponent;
}
public ProcessSelectionComponent getInferenceProcessSelectionComponent() {
return inferenceProcessSelectionComponent;
}
public ProcessSelectionComponent getTrainingProcessSelectionComponent() {
return trainingProcessSelectionComponent;
}
public JTextArea getDescription() {
return description;
}
/**
* 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")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
trainingProcessSelectionComponent = new de.fub.maps.project.detector.model.inference.ui.ProcessSelectionComponent();
crossValidationProcessSelectionComponent = new de.fub.maps.project.detector.model.inference.ui.ProcessSelectionComponent();
inferenceProcessSelectionComponent = new de.fub.maps.project.detector.model.inference.ui.ProcessSelectionComponent();
jPanel6 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
description = new javax.swing.JTextArea();
setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.LINE_AXIS));
jPanel1.setBorder(javax.swing.BorderFactory.createEmptyBorder(4, 4, 4, 4));
jPanel1.setLayout(new java.awt.BorderLayout());
jPanel2.setMaximumSize(new java.awt.Dimension(32767, 120));
jPanel2.setLayout(new java.awt.GridLayout(1, 3, 4, 0));
jPanel2.add(trainingProcessSelectionComponent);
jPanel2.add(crossValidationProcessSelectionComponent);
jPanel2.add(inferenceProcessSelectionComponent);
jPanel1.add(jPanel2, java.awt.BorderLayout.CENTER);
jPanel6.setPreferredSize(new java.awt.Dimension(10, 92));
org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(ProcessHandlerPanel.class, "ProcessHandlerPanel.jLabel1.text")); // NOI18N
jScrollPane1.setBorder(null);
description.setEditable(false);
description.setColumns(20);
description.setRows(3);
description.setOpaque(false);
jScrollPane1.setViewportView(description);
javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
jPanel6.setLayout(jPanel6Layout);
jPanel6Layout.setHorizontalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 600, Short.MAX_VALUE)
);
jPanel6Layout.setVerticalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel6Layout.createSequentialGroup()
.addGap(8, 8, 8)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 64, Short.MAX_VALUE))
);
jPanel1.add(jPanel6, java.awt.BorderLayout.SOUTH);
add(jPanel1);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private de.fub.maps.project.detector.model.inference.ui.ProcessSelectionComponent crossValidationProcessSelectionComponent;
private javax.swing.JTextArea description;
private de.fub.maps.project.detector.model.inference.ui.ProcessSelectionComponent inferenceProcessSelectionComponent;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel6;
private javax.swing.JScrollPane jScrollPane1;
private de.fub.maps.project.detector.model.inference.ui.ProcessSelectionComponent trainingProcessSelectionComponent;
// End of variables declaration//GEN-END:variables
@Override
public void mouseClicked(MouseEvent e) {
ExplorerManager explorerManager = null;
if (e.getSource().equals(getTrainingProcessSelectionComponent().getListView().getViewport().getView())) {
explorerManager = getTrainingProcessSelectionComponent().getExplorerManager();
} else if (e.getSource().equals(getInferenceProcessSelectionComponent().getListView().getViewport().getView())) {
explorerManager = getInferenceProcessSelectionComponent().getExplorerManager();
} else if (e.getSource().equals(getCrossvalidationProcessSelectionComponent().getListView().getViewport().getView())) {
explorerManager = getCrossvalidationProcessSelectionComponent().getExplorerManager();
}
if (explorerManager != null) {
Node[] selectedNodes = explorerManager.getSelectedNodes();
if (selectedNodes.length == 1) {
InferenceModelProcessHandler processHandler = selectedNodes[0].getLookup().lookup(InferenceModelProcessHandler.class);
if (processHandler != null) {
getDescription().setText(processHandler.getDescriptor().getName());
}
} else {
getDescription().setText(null);
}
} else {
getDescription().setText(null);
}
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
}