⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 objectviewerthemepropertiesframe.java

📁 用于GIS(全球地理系统)的分析和处理的代码。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		themePropertiesPanel.add(outlineThemeColorButton);



		themePropertiesPanel.add(fillHighlightColorLabel);

		themePropertiesPanel.add(fillHighlightColorButton);

		themePropertiesPanel.add(outlineHighlightColorLabel);

		themePropertiesPanel.add(outlineHighlightColorButton);



		themePropertiesPanel.add(fillSelectionColorLabel);

		themePropertiesPanel.add(fillSelectionColorButton);

		themePropertiesPanel.add(outlineSelectionColorLabel);

		themePropertiesPanel.add(outlineSelectionColorButton);



	

		//Add the components to the themeShadersPanel

		final JComboBox shaderTypeComboBox ;

		final JComboBox attributeDoubleComboBox;

		final JComboBox attributeStringComboBox;



		if (getObjectViewerThemeProperties().getDataSourceType() == Utils.GEOXYGENE) {

		

			JLabel shaderLabel = new JLabel("Type of shader:");

			shaderTypeComboBox = new JComboBox( new String[] {"Mono", "Random", "Continuous", "Unique"} );

			shaderTypeComboBox.setSelectedItem( getShaderName(getObjectViewerThemeProperties().getShader()) );

			final JLabel attributeDoubleLabel = new JLabel("Attributes (double or int):");			

			attributeDoubleComboBox = new JComboBox();

			final JLabel attributeStringLabel = new JLabel("Attributes (String):");	

			attributeStringComboBox = new JComboBox();				

	

			String[] doubleFieldsNames = getDoubleOrIntFields();

			if (doubleFieldsNames.length > 0) {	

				for (int i=0; i<doubleFieldsNames.length; i++)	

					attributeDoubleComboBox.addItem(doubleFieldsNames[i]);

				if (getObjectViewerThemeProperties().getShadedBy() != null 

					&& getSelectedFieldClass(getObjectViewerThemeProperties().getShadedBy()).equals(double.class) )

					attributeDoubleComboBox.setSelectedItem( getObjectViewerThemeProperties().getShadedBy() );

				else 

					attributeDoubleComboBox.setSelectedItem(doubleFieldsNames[0]);

			}

					

			String[] stringFieldsNames = getStringFields();

			if (stringFieldsNames.length > 0) {		

				for (int i=0; i<stringFieldsNames.length; i++)		

					attributeStringComboBox.addItem(stringFieldsNames[i]);

				if (getObjectViewerThemeProperties().getShadedBy() != null

					&& getSelectedFieldClass(getObjectViewerThemeProperties().getShadedBy()).equals(String.class) )		

					attributeStringComboBox.setSelectedItem( getObjectViewerThemeProperties().getShadedBy() );

				else 

					attributeStringComboBox.setSelectedItem(stringFieldsNames[0]);		

			}

			

			themeShadersPanel.add(shaderLabel);

			themeShadersPanel.add(shaderTypeComboBox);

			themeShadersPanel.add(attributeDoubleLabel);		

			themeShadersPanel.add(attributeDoubleComboBox);		

			themeShadersPanel.add(attributeStringLabel);		

			themeShadersPanel.add(attributeStringComboBox);

			

			attributeDoubleLabel.setEnabled(false);

			attributeDoubleComboBox.setEnabled(false);

			attributeStringLabel.setEnabled(false);

			attributeStringComboBox.setEnabled(false);

			

			shaderTypeComboBox.addActionListener(new ActionListener() {

				public void actionPerformed(ActionEvent e) {

					if (shaderTypeComboBox.getSelectedItem().equals("Continuous")) {						

						attributeDoubleLabel.setEnabled(true);

						attributeDoubleComboBox.setEnabled(true);

						attributeStringLabel.setEnabled(false);

						attributeStringComboBox.setEnabled(false);

					} else if (shaderTypeComboBox.getSelectedItem().equals("Unique")) {

						attributeDoubleLabel.setEnabled(false);

						attributeDoubleComboBox.setEnabled(false);

						attributeStringLabel.setEnabled(true);

						attributeStringComboBox.setEnabled(true);

					} else {

						attributeDoubleLabel.setEnabled(false);

						attributeDoubleComboBox.setEnabled(false);

						attributeStringLabel.setEnabled(false);

						attributeStringComboBox.setEnabled(false);

					}

				}

			});

			

		} else {

			shaderTypeComboBox = null;

			attributeDoubleComboBox = null;

			attributeStringComboBox = null;	

		}

				

		

		//Add the control panel at the bottom of the window

		final JPanel controlPanel =

			new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 10));

		JButton okButton = new JButton("Ok");

		okButton.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {

				ObjectViewerThemePropertiesFrame.this.dispose();

				getObjectViewerThemeProperties().setFillInThemeColor(

					((RectIcon) (fillThemeColorButton.getIcon())).getColor());

				getObjectViewerThemeProperties().setOutlineThemeColor(

					((RectIcon) (outlineThemeColorButton.getIcon()))

						.getColor());

				getObjectViewerThemeProperties().setFillInHighlightColor(

					((RectIcon) (fillHighlightColorButton.getIcon()))

						.getColor());

				getObjectViewerThemeProperties().setOutlineHighlightColor(

					((RectIcon) (outlineHighlightColorButton.getIcon()))

						.getColor());

				getObjectViewerThemeProperties().setFillInSelectionColor(

					((RectIcon) (fillSelectionColorButton.getIcon()))

						.getColor());

				getObjectViewerThemeProperties().setOutlineSelectionColor(

					((RectIcon) (outlineSelectionColorButton.getIcon()))

						.getColor());	

						

				if (getObjectViewerThemeProperties().getDataSourceType() == Utils.GEOXYGENE) {	

										

					if (attributeDoubleComboBox.isEnabled() && !attributeStringComboBox.isEnabled())

						getObjectViewerThemeProperties().setShader( selectShader(( String) shaderTypeComboBox.getSelectedItem()) ,

																(String) attributeDoubleComboBox.getSelectedItem() );

					else if (!attributeDoubleComboBox.isEnabled() && attributeStringComboBox.isEnabled())

						getObjectViewerThemeProperties().setShader( selectShader(( String) shaderTypeComboBox.getSelectedItem()) ,

															(String) attributeStringComboBox.getSelectedItem() );

					else getObjectViewerThemeProperties().setShader( selectShader(( String) shaderTypeComboBox.getSelectedItem()));

					

				}

				

				getObjectViewerThemeProperties().setChanged();

			}

		});

		JButton cancelButton = new JButton("Cancel");

		cancelButton.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {

				ObjectViewerThemePropertiesFrame.this.dispose();

			}

		});

		controlPanel.add(okButton);

		controlPanel.add(cancelButton);





		//Add the components to the colorchooser frame

		Container contentPane = getContentPane();

		themePropertiesTabbedPanel.addTab("Colors", themePropertiesPanel);

		themePropertiesTabbedPanel.setToolTipTextAt(

			0,

			"Set the colors for the current theme.");

		themePropertiesTabbedPanel.setSelectedIndex(0);

		themePropertiesTabbedPanel.addTab("Shaders", themeShadersPanel);

		themePropertiesTabbedPanel.setToolTipTextAt(

			1,

			"Change the shader of the current theme.");

			

		contentPane.add(themePropertiesTabbedPanel, BorderLayout.CENTER);

		contentPane.add(controlPanel, BorderLayout.SOUTH);



	}





	private Shader selectShader(String type) {

		if (type.equals("Mono")) return new MonoShader();

		else if (type.equals("Random")) return new RandomShader();

		else if (type.equals("Continuous")) return new HSVShader();

		else if (type.equals("Unique")) return new UniqueShader();

		else System.out.println("### PROBLEM selecting shader ...");

			return null;

	}





	private String getShaderName(Shader shader) {

		if (shader instanceof MonoShader) return "Mono";

		else if (shader instanceof RandomShader) return "Random";

		else if (shader instanceof HSVShader) return "Continuous";

		else if (shader instanceof UniqueShader) return "Unique";

		else return "### PROBLEM selecting shader name !!";

	}





	private String[] getFieldNames() {

		String[] fieldsName = new String[0];

		if (getObjectViewerThemeProperties().getDataSourceType().equals(Utils.SHAPEFILE)) {

			ShapefileReader shpRd = (ShapefileReader) getObjectViewerThemeProperties().getDataSource();			

			Dbf dbf = shpRd.dbf;

			fieldsName = new String[dbf.getNumFields()];

			for (int i=0; i<fieldsName.length; i++)

				fieldsName[i] = dbf.getFieldName(i).toString();		

		}

			

		else if (getObjectViewerThemeProperties().getDataSourceType().equals(Utils.GEOXYGENE)) {

			GeOxygeneReader geOxyRd = (GeOxygeneReader) getObjectViewerThemeProperties().getDataSource();

			fieldsName = geOxyRd.getFieldsNames();

		}

		return fieldsName;

	}

	

	

	private String[] getDoubleOrIntFields() {

		Vector vector = new Vector();

		String[] allFields = getFieldNames();

		for (int i=0; i<allFields.length; i++) 

			if (getSelectedFieldClass(allFields[i]).equals(double.class) ||

				getSelectedFieldClass(allFields[i]).equals(int.class))

				vector.add(allFields[i]);

		String[] array = new String[vector.size()];

		for (int i=0; i<vector.size(); i++)

			array[i] = (String) vector.get(i);

		return array;

	}

	



	private String[] getStringFields() {

		Vector vector = new Vector();

		String[] allFields = getFieldNames();

		for (int i=0; i<allFields.length; i++) 

			if (getSelectedFieldClass(allFields[i]).equals(String.class))

				vector.add(allFields[i]);

		String[] array = new String[vector.size()];

		for (int i=0; i<vector.size(); i++)

			array[i] = (String) vector.get(i);

		return array;

	}

		

	

	private Class getSelectedFieldClass (String fieldName) {

		Class result = null;

		if (getObjectViewerThemeProperties().getDataSourceType().equals(Utils.GEOXYGENE)) {

			GeOxygeneReader geOxyRd = (GeOxygeneReader) getObjectViewerThemeProperties().getDataSource();

			result = geOxyRd.getFieldType(fieldName);

		}

		return result;

	}





	private ObjectViewerThemeProperties getObjectViewerThemeProperties() {

		return objectViewerThemeProperties;

	}



}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -