
eu.agrosense.client.grid.impl.GridVisualElement Maven / Gradle / Ivy
The newest version!
/*
* Copyright (C) 2008-2012 AgroSense Foundation.
*
* AgroSense is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* There are special exceptions to the terms and conditions of the GPLv3 as it is applied to
* this software, see the FLOSS License Exception
* .
*
* AgroSense is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AgroSense. If not, see .
*
* Contributors:
* monezz - initial API and implementation and/or initial documentation
*/
package eu.agrosense.client.grid.impl;
import eu.agrosense.client.grid.Grid;
import java.awt.BorderLayout;
import javax.swing.Action;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import nl.cloudfarming.client.field.model.Field;
import nl.cloudfarming.client.geoviewer.render.GridCoverage2DPreviewPanel;
import nl.cloudfarming.client.util.swing.ASBodyPanel;
import org.netbeans.core.spi.multiview.CloseOperationState;
import org.netbeans.core.spi.multiview.MultiViewElement;
import org.netbeans.core.spi.multiview.MultiViewElementCallback;
import org.openide.awt.UndoRedo;
import org.openide.util.ImageUtilities;
import org.openide.util.Lookup;
import org.openide.util.NbBundle.Messages;
import org.openide.windows.TopComponent;
@MultiViewElement.Registration(
displayName = "#LBL_Grid_VISUAL",
iconBase = "eu/agrosense/client/grid/impl/grid.png",
mimeType = "application/x-agrosense-grid",
persistenceType = TopComponent.PERSISTENCE_NEVER,
preferredID = "GridVisual",
position = 2000)
@Messages("LBL_Grid_VISUAL=Visual")
public final class GridVisualElement extends JPanel implements MultiViewElement {
private GridDataObject obj;
private JToolBar toolbar = new JToolBar();
private transient MultiViewElementCallback callback;
private ASBodyPanel content;
public GridVisualElement(Lookup lkp) {
obj = lkp.lookup(GridDataObject.class);
assert obj != null;
initComponents();
setLayout(new BorderLayout());
//FieldVisualPanel fieldVisualPanel = new FieldVisualPanel(obj.getLookup().lookup(Field.class));
content = new ASBodyPanel(new GridCoverage2DPreviewPanel(obj.getLookup().lookup(Grid.class).getGrid()));
content.setIcon(ImageUtilities.loadImageIcon(GridDataObject.ICON_BASE, true));
content.setTitle(Bundle.LBL_Grid_VISUAL());
add(content);
}
@Override
public String getName() {
return "GridVisualElement";
}
/**
* 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.
*/
// //GEN-BEGIN:initComponents
private void initComponents() {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
}// //GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
@Override
public JComponent getVisualRepresentation() {
return this;
}
@Override
public JComponent getToolbarRepresentation() {
return toolbar;
}
@Override
public Action[] getActions() {
return new Action[0];
}
@Override
public Lookup getLookup() {
return obj.getLookup();
}
@Override
public void componentOpened() {
}
@Override
public void componentClosed() {
}
@Override
public void componentShowing() {
if (callback != null) {
updateName();
}
}
@Override
public void componentHidden() {
}
@Override
public void componentActivated() {
}
@Override
public void componentDeactivated() {
}
@Override
public UndoRedo getUndoRedo() {
return UndoRedo.NONE;
}
@Override
public void setMultiViewCallback(MultiViewElementCallback callback) {
this.callback = callback;
}
@Override
public CloseOperationState canCloseElement() {
return CloseOperationState.STATE_OK;
}
private void updateName() {
if (callback != null) {
Grid grid = obj.getLookup().lookup(Grid.class);
TopComponent tc = callback.getTopComponent();
tc.setHtmlDisplayName(grid.getName());
tc.setDisplayName(grid.getName());
tc.setName(getName());
tc.setToolTipText(getToolTipText());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy