📄 objectviewerinterface.java
字号:
objectViewerThemeProperties.getFillInSelectionColor());
themeSelectShadeStyle.setLineColor(
objectViewerThemeProperties.getOutlineSelectionColor());
t.setSelectionStyle(themeSelectShadeStyle);
themeSelectMgr.addSelectionChangedListener(new SelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent hce) {
System.out.println("Selection sur un theme ...");
selectedObjects = new Vector();
for (int i = 0; i < themesPropertiesList.size(); i++) {
Theme activetheme = ((ObjectViewerThemeProperties) (themesPropertiesList.get(i))).getObjectViewerTheme();
if (isActive(activetheme)) {
System.out.println("Themes: " + activetheme.getName());
GeoData activethemeGeoData = activetheme.getGeoData();
int[] selectedIdObjects = activetheme.getSelectionManager().getSelection();
Vector selectedIdObjectsNotNullVector = new Vector();
int nbselectedIdObjects = selectedIdObjects.length;
for (int j = 0; j < nbselectedIdObjects; j++) {
if (selectedIdObjects[j] != -1) {
System.out.println(" ObjectID: " + selectedIdObjects[j]);
selectedIdObjectsNotNullVector.add(new Integer (selectedIdObjects[j]));
}
}
int[] selectedIdObjectsNotNullArray = new int[selectedIdObjectsNotNullVector.size()];
for (int j=0; j < selectedIdObjectsNotNullArray.length; j++)
selectedIdObjectsNotNullArray[j] = ((Integer)selectedIdObjectsNotNullVector.get(j)).intValue();
selectedObjects.add (new ObjectsIDAndSource (selectedIdObjectsNotNullArray,
((ObjectViewerThemeProperties)themesPropertiesList.get(i)).getDataSource() ));
}
}
}
});
t.setSelectionManager(themeSelectMgr);
objectViewerThemeProperties.setThemeSelectionManager(t.getSelectionManager());
}
/** Display objects stored in the FeatureCollection, with a given name. */
protected void addAShapefileTheme(URL url) {
ShapefileReader sfr = new ShapefileReader(url);
final Theme t = sfr.getTheme();
String theme_name = t.getName();
String shapefile_name = theme_name.substring(theme_name.lastIndexOf("/") + 1);
t.setName(shapefile_name);
this.addTheme(t, Utils.SHAPEFILE, sfr);
}
/** Display objects stored in the FeatureCollection, in a Theme with the given name. */
protected void addAFeatureCollectionTheme(FT_FeatureCollection fColl, String themeName) {
GeOxygeneReader geOxyRead = new GeOxygeneReader (fColl);
final Theme t = geOxyRead.getTheme();
t.setName(themeName);
this.addTheme(t, Utils.GEOXYGENE, geOxyRead);
}
/** Refresh the FeatureCollection displayed in the viewer with this given name. */
protected void refreshAFeatureCollectionTheme (FT_FeatureCollection fColl, String themeName) {
// Get the GeOxygeneReader of this collection
if (themesPropertiesList.size() > 0) {
for (int i=0; i<themesPropertiesList.size(); i++) {
ObjectViewerThemeProperties oldThemeProp = (ObjectViewerThemeProperties) themesPropertiesList.get(i);
Theme oldTheme = oldThemeProp.getObjectViewerTheme();
// theme exists !!
if (oldThemeProp.getDataSourceType().equals (Utils.GEOXYGENE) && oldTheme.getName().equals(themeName)) {
GeOxygeneReader oldGeOxyRead = (GeOxygeneReader) oldThemeProp.getDataSource();
int index = themesPropertiesList.indexOf(oldThemeProp);
view.removeStaticTheme(oldTheme);
GeOxygeneReader newGeOxyRead = new GeOxygeneReader (fColl);
final Theme newTheme = newGeOxyRead.getTheme();
newTheme.setName(themeName);
this.setTheme(newTheme, Utils.GEOXYGENE, newGeOxyRead, index, oldThemeProp.isActive(), oldThemeProp.isVisible());
activeThemes.remove (oldTheme);
activeThemes.add(newTheme);
return;
}
}
}
// Theme doesn't exist yet
System.out.println(" ## REFRESH : the Theme doesn't exist yet ! ");
return;
}
/** Refresh the FeatureCollection displayed in the viewer with this given name with this feature.
* The feature must already belong to the collection. */
// ATTENTION apres un refresh, le highlight manager continue a etre active meme si le theme est deselectionne ...
public void refreshAFeatureCollectionTheme (FT_Feature feature, String themeName) {
// Get the GeOxygeneReader of this collection
if (themesPropertiesList.size() > 0) {
for (int i=0; i<themesPropertiesList.size(); i++) {
ObjectViewerThemeProperties themeProp = (ObjectViewerThemeProperties) themesPropertiesList.get(i);
Theme theme = themeProp.getObjectViewerTheme();
// theme exists !!
if (themeProp.getDataSourceType().equals (Utils.GEOXYGENE) && theme.getName().equals(themeName)) {
GeOxygeneReader geOxyRead = (GeOxygeneReader) themeProp.getDataSource();
FT_FeatureCollection fColl = geOxyRead.getFeatureCollection();
if (! fColl.getElements().contains(feature)) {
System.out.println(" ## REFRESH : the Feature Collection does not contain the Feature !");
return;
}
geOxyRead.refreshFeature(feature);
return;
}
}
}
// Theme doesn't exist yet
System.out.println(" ## REFRESH : the Theme doesn't exist yet ! ");
return;
}
/** Display a JPEG image */
protected void addAnImageTheme (String fileName, int x, int y, int width, int height) {
File fichier=new File(fileName);
System.out.println(fichier.getAbsolutePath());
try {
FileInputStream fis=new FileInputStream(fichier);
ImageLayer imageLayer = new ImageLayer( fis, new GeoRectangle(x,y,width,height));
Theme t = new Theme (imageLayer);
String theme_name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.lastIndexOf("."));
t.setName(theme_name);
this.addTheme(t, Utils.IMAGE, new ImageReader());
} catch (Exception e) {
e.printStackTrace();
}
}
protected Vector getSelectedObjects() {
return selectedObjects;
}
protected Vector getActiveThemes () {
return activeThemes;
}
private boolean isActive (Theme t) {
if (activeThemes.contains(t)) return true;
else return false;
}
private void setThemeButton (int index, ObjectViewerThemeProperties prop) {
// Init "theme button"
ObjectViewerThemeButton theme_chkbox = new ObjectViewerThemeButton(this, prop);
// Add a popup for the "theme button"
ObjectViewerThemePopupMenu ThemePopup = new ObjectViewerThemePopupMenu(this,theme_chkbox,prop);
// Add a listener for popups.
MouseListener popupListener = new PopupListener(ThemePopup);
theme_chkbox.addMouseListener(popupListener);
// Get "theme button" and remove it
panel_themes.add(theme_chkbox,index);
panel_themes.add(Box.createVerticalStrut(2));
theme_chkbox.setPreferredSize(new Dimension(177, 30));
theme_chkbox.setMaximumSize(new Dimension(177, 30));
}
/** Move up a theme */
protected void upTheme (Theme t) {
for (int k=1; k<themesPropertiesList.size(); k++) {
ObjectViewerThemeProperties thPr1 = (ObjectViewerThemeProperties) themesPropertiesList.get(k);
Theme t1 = thPr1.getObjectViewerTheme();
if ( t1.equals(t)) {
ObjectViewerThemeProperties thPr0 = (ObjectViewerThemeProperties) themesPropertiesList.get(k-1);
Theme t0 = thPr0.getObjectViewerTheme();
view.swapThemes(t0,t1);
themesPropertiesList.set(k-1,thPr1);
themesPropertiesList.set(k,thPr0);
panel_themes.remove(k-1);
setThemeButton(k-1,thPr1);
panel_themes.remove(k);
setThemeButton(k,thPr0);
panel_themes.revalidate();
panel_themes.repaint();
break;
}
}
}
/** Moves down a theme */
protected void downTheme (Theme t) {
for (int k=0; k<themesPropertiesList.size()-1; k++) {
ObjectViewerThemeProperties thPr1 = (ObjectViewerThemeProperties) themesPropertiesList.get(k);
Theme t1 = thPr1.getObjectViewerTheme();
if ( t1.equals(t)) {
ObjectViewerThemeProperties thPr0 = (ObjectViewerThemeProperties) themesPropertiesList.get(k+1);
Theme t0 = thPr0.getObjectViewerTheme();
view.swapThemes(t0,t1);
themesPropertiesList.set(k+1,thPr1);
themesPropertiesList.set(k,thPr0);
panel_themes.remove(k+1);
setThemeButton(k+1,thPr1);
panel_themes.remove(k);
setThemeButton(k,thPr0);
panel_themes.revalidate();
panel_themes.repaint();
break;
}
}
}
protected void removeTheme (ObjectViewerThemeProperties prop) {
int index = themesPropertiesList.indexOf(prop);
Theme t = prop.getObjectViewerTheme();
view.setThemeIsVisible(t,false,true);
panel_themes.remove(index);
panel_themes.revalidate();
panel_themes.repaint();
view.removeStaticTheme(t);
activeThemes.remove(t);
themesPropertiesList.remove(index);
}
/** Structure for IDs and DataSource */
protected class ObjectsIDAndSource {
public int[] objectsID;
public DataSource source;
public ObjectsIDAndSource (int[] ids, DataSource s) {
objectsID = ids;
source = s;
}
public int[] getObjectsID() {
return objectsID;
}
public DataSource getDataSource() {
return source;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -