Programming/Java2011. 10. 29. 22:20
File 클래스에서 원하는 경로를 넣고
list() 메소드를 이용하면 그 경로상의 목록을 얻어올수 있다.

만약 원하는 확장자의 파일만을 원한다면
FilenameFilter 클래스를 등록해서 빼내면 되는데 Win32와 차이점은
*.ext 가 아닌 .ext로 해야 한다는 점이다.

import java.io.File;
import java.io.FilenameFilter;
 
    public class FileUtil {
        public void listFiles(String dir) {
            File directory = new File(dir);
            if (!directory.isDirectory()) {
                System.out.println("No directory provided");
                return;
            }
            //create a FilenameFilter and override its accept-method
            FilenameFilter filefilter_java = new FilenameFilter() {
                public boolean accept(File dir, String name) { //if the file extension is .txt return true, else false
                    return name.endsWith(".java");
                }
            };

            String[] filenames = directory.list(filefilter_java);
            for (String name : filenames) {
                System.out.println(name);
            }
        }
    } 

[링크 : http://www.javadb.com/list-files-of-a-certain-type]
[링크 : http://www.roseindia.net/java/java-get-example/get-file-list.shtml]
Posted by 구차니
Programming/Java2011. 10. 29. 21:53
영역을 선택하고 Alt+Shift+F 를 누르면 자동으로 코드를 정렬한다.


[링크 : http://stackoverflow.com/questions/1311912/how-do-i-autoindent-in-netbeans]

'Programming > Java' 카테고리의 다른 글

JList 에 원하는 목록 추가하기  (4) 2011.10.29
Java 에서 파일 목록 엳어오기  (0) 2011.10.29
Java용 폴더 다이얼로그  (0) 2011.10.28
netbeans IDE  (0) 2010.08.23
unit test - 단위 테스트  (0) 2010.08.18
Posted by 구차니
Programming/Java2011. 10. 28. 14:37
집에가서 해보고 업데이트

JFileChooser는 다음과 같은 유형의 다이얼로그 창을 열어준다.
JFileChooser.DIRECTORIES_ONLY 옵션을 주어도 윈도우의 폴더 탐색 다이얼로그 처럼 열리지는 않는
아쉬움이 있지만 조금더 찾아보면 나오려나.. 아니면 다른게 있으려나?


JFileChooser chooser = new JFileChooser();
    // Note: source for ExampleFileFilter can be found in FileChooserDemo,
    // under the demo/jfc directory in the JDK.
    ExampleFileFilter filter = new ExampleFileFilter();
    filter.addExtension("jpg");
    filter.addExtension("gif");
    filter.setDescription("JPG & GIF Images");
    chooser.setFileFilter(filter);
    int returnVal = chooser.showOpenDialog(parent);
    if(returnVal == JFileChooser.APPROVE_OPTION) {
       System.out.println("You chose to open this file: " +
            chooser.getSelectedFile().getName());
    }
[링크 : http://download.oracle.com/javase/1.5.0/docs/api/javax/swing/JFileChooser.html

JFileChooser chooser = new JFileChooser("C:\example");
chooser.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY);

[링크 : http://stackoverflow.com/questions/4779360/browse-for-folder-dialog]


아래의 코드는 netbeans에서 버튼을 클릭시 특정 TextFiled에 값을 넣어주도록 하는 예제이다.
import나 패키지 의존성 때문인지 코드가 길어진 느낌 -_-
javax.swing.JFileChooser chooser = new javax.swing.JFileChooser("C:\\");
chooser.setFileSelectionMode( javax.swing.JFileChooser.DIRECTORIES_ONLY);
chooser.showOpenDialog(NewJDialog.this);
jTextField1.setText(chooser.getSelectedFile().getPath()); 
 
2011/10/22 - [Programming/C / Win32 / MFC] - CFileDialog 말고 폴더 다이얼로그 없나?

'Programming > Java' 카테고리의 다른 글

Java 에서 파일 목록 엳어오기  (0) 2011.10.29
netbeans 에서 코드 자동정렬  (0) 2011.10.29
netbeans IDE  (0) 2010.08.23
unit test - 단위 테스트  (0) 2010.08.18
java에는 unsigned가 없다고?!  (0) 2009.09.03
Posted by 구차니
Programming/C Win32 MFC2011. 10. 24. 11:39
GetTempFileName () 라는 함수로 임시파일이름을 생성할수 있다.
덤으로, 리눅스에서는 mktemp()

[링크 : http://linux.die.net/man/3/mktemp]
[링크 : http://linux.die.net/man/3/tmpfile]]

[링크 : http://www.codeproject.com/Messages/2942050/Creating-and-deleting-a-temp-file.aspx]
    [링크 : http://msdn.microsoft.com/en-us/library/windows/desktop/aa364991(v=vs.85).aspx]

'Programming > C Win32 MFC' 카테고리의 다른 글

함수 포인터 배열  (0) 2012.03.07
헐 # include 이게 되는거였다니!  (0) 2012.02.15
CFileFind Class  (0) 2011.10.23
CFileDialog 말고 폴더 다이얼로그 없나?  (0) 2011.10.22
ctime()  (2) 2011.07.06
Posted by 구차니
Programming/C Win32 MFC2011. 10. 23. 23:53
특정 디렉토리의 파일목록이나 특정 확장자 / 파일이름 등으로 검색한 목록을 얻어낼수 있는 클래스이다.
하지만 "목록"은 얻을지 언정 몇개인지는 while 루프를 돌려야만 하니 조금 불편할수도 있다.

void main()
{
   CFileFind finder;
   BOOL bWorking = finder.FindFile("*.*");

   while (bWorking)
   {
      bWorking = finder.FindNextFile();

         if(!finder.IsDirectory())
            cout << (LPCTSTR) finder.GetFileName() << endl;
   }
}

[링크 : http://msdn.microsoft.com/ko-kr/library/f33e1618(v=vs.80).aspx]
[링크 : http://mnlt.tistory.com/7]
[링크 : http://www.gungume.com/37]
Posted by 구차니
Programming/C Win32 MFC2011. 10. 22. 20:55
가끔보면 폴더만 선택이 가능한 다이얼로그가 있는데
CFileDialog에 옵션줘서 하는줄 알았더니 -_-
SHBrowseForFolder() 라는 Win32API를 이용하는 것이었다!


void CtracerDlg::OnBnClickedButton1()
{
	// TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다.
	ITEMIDLIST*  pildBrowse;
	TCHAR   pszPathname[MAX_PATH];
	BROWSEINFO  bInfo;
	memset(&bInfo, 0, sizeof(bInfo));
	bInfo.hwndOwner   = GetSafeHwnd();
	bInfo.pidlRoot   = NULL;
	bInfo.pszDisplayName = pszPathname;
	bInfo.lpszTitle   = _T("디렉토리를 선택하세요");
	bInfo.ulFlags   = BIF_RETURNONLYFSDIRS; 
	bInfo.lpfn    = NULL;
	bInfo.lParam  = (LPARAM)(LPCTSTR)"C:\\";
	bInfo.lParam  = (LPARAM)NULL;
	pildBrowse    = ::SHBrowseForFolder(&bInfo);
	if(pildBrowse)
	{
		SHGetPathFromIDList(pildBrowse, pszPathname);
		m_editPath.SetWindowTextW(pszPathname);
	}

}

[링크 : http://jeylee1031.tistory.com/entry/MFC-폴더-dialog-띄우기]
[링크 : http://softk.tistory.com/entry/SHBrowseForFolder-UI를-수정하자]
[링크 : http://msdn.microsoft.com/en-us/library/windows/desktop/bb762115(v=vs.85).aspx]

'Programming > C Win32 MFC' 카테고리의 다른 글

윈도우에서 사용할 임시파일이름 만들기  (0) 2011.10.24
CFileFind Class  (0) 2011.10.23
ctime()  (2) 2011.07.06
선언과 정의(Declaration & Definition)  (10) 2010.10.04
ini 파일 내용 파싱하기  (2) 2010.09.27
Posted by 구차니
Programming/openGL2011. 10. 19. 11:10
테스트해보지 못한 사항이지만..

gluUnProject()는 모델/투영행렬의 역행렬을 구해 화면상에 보이는 좌표의 원본 좌표를 구해주는 역활을 한다고 한다.
glRenderMode()의 경우 GL_SELECT 모드에서 모델링시에 추가한 glLoadName 을 리턴해 준다.

어떻게 보면 개체나 점(vertex)를 선택하는 방법론이지만
좌표를 얻어야 한다면 gluUnProject를 정해놓은 개체를 얻어야 한다면 glLoadName과 glRenderMode를 조합하는 것이
적정한 접근방법으로 보인다.

[링크 : http://www.opengl.org/sdk/docs/man/xhtml/glReadPixels.xml]
[링크 : http://www.opengl.org/sdk/docs/man/xhtml/gluUnProject.xml]
    [링크 : http://blog.naver.com/nowcome/130035713309
    [링크 : http://www.gpgstudy.com/gpgiki/알려진 평면의 피킹]
 
[링크 : http://www.opengl.org/sdk/docs/man/xhtml/glRenderMode.xml]
    [링크 : http://www.opengl.org/resources/code/samples/glut_examples/examples/examples.html]
    [링크 : http://www.gpgstudy.com/forum/viewtopic.php?p=117646]
    [링크 : http://dis.dankook.ac.kr/lectures/cg11/entry/OpenGL-Picking

[링크 : http://www.opengl.org/sdk/docs/man/xhtml/glLoadName.xml]
    [링크 : http://www.opengl.org/sdk/docs/man/xhtml/glInitNames.xml]
    [링크 : http://www.opengl.org/sdk/docs/man/xhtml/glPushName.xml]

'Programming > openGL' 카테고리의 다른 글

GLSL 은.. intel 내장형으로는 무리?  (0) 2011.11.19
GLSL 관련 링크  (0) 2011.11.12
glNormal()  (0) 2011.10.18
glut Menu 관련 함수들  (0) 2011.10.10
glutAttachMenu()의 Linux용 버그  (2) 2011.10.10
Posted by 구차니
Programming/openGL2011. 10. 18. 23:14
glNormal()은 점이나 면에 대해서 법선 벡터를 정하는 함수이다.
이러한 법선 벡터는 빛의 반사를 계산하는데 쓰이는데 설정하지 않았을 경우 기본값은 (0,0,1)로 지정이 된다.
nomalize는 단위벡터로 입력을 받는 기능인데 기본적으로 꺼져 있으나 과도하게 큰 값이 들어가면
흰색이나 검은색으로 보이기도 하니, 되도록이면 평준화 시켜서 사용하는 것이 좋을듯 하다.

void glNormal3b( GLbyte   nx,  GLbyte   ny,  GLbyte   nz);
void glNormal3d( GLdouble  nx,  GLdouble ny,  GLdouble  nz);
void glNormal3f( GLfloat   nx,  GLfloat   ny,  GLfloat   nz);
void glNormal3i( GLint   nx,  GLint   ny,  GLint   nz);
void glNormal3s( GLshort   nx,  GLshort   ny,  GLshort   nz);

void glNormal3bv( const GLbyte *   v);
void glNormal3dv( const GLdouble *   v);
void glNormal3fv( const GLfloat *   v);
void glNormal3iv( const GLint *   v);
void glNormal3sv( const GLshort *   v);

nx, ny, nz
Specify the x, y, and z coordinates of the new current normal.
The initial value of the current normal is the unit vector, (0, 0, 1).

Description

The current normal is set to the given coordinates whenever glNormal is issued. Byte, short, or integer arguments are converted to floating-point format with a linear mapping that maps the most positive representable integer value to 1.0 and the most negative representable integer value to -1.0 .

Normals specified with glNormal need not have unit length. If GL_NORMALIZE is enabled, then normals of any length specified with glNormal are normalized after transformation. If GL_RESCALE_NORMAL is enabled, normals are scaled by a scaling factor derived from the modelview matrix. GL_RESCALE_NORMAL requires that the originally specified normals were of unit length, and that the modelview matrix contain only uniform scales for proper results. To enable and disable normalization, call glEnable and glDisable with either GL_NORMALIZE or GL_RESCALE_NORMAL. Normalization is initially disabled.
 
[링크 : http://www.opengl.org/sdk/docs/man/xhtml/glNormal.xml

glNormal()은 쉐이더와 조명의 영향을 받는다.
glEnable(GL_LIGHTING)
glEnable(GL_NORMALIZE)

GL_LIGHTi
If enabled, include light i in the evaluation of the lighting equation. See glLightModel and glLight.

GL_LIGHTING
If enabled and no vertex shader is active, use the current lighting parameters to compute the vertex color or index. Otherwise, simply associate the current color or index with each vertex. See glMaterial, glLightModel, and glLight.

GL_NORMALIZE
If enabled and no vertex shader is active, normal vectors are normalized to unit length after transformation and before lighting. This method is generally less efficient than GL_RESCALE_NORMAL. See glNormal and glNormalPointer.
[링크 : http://www.opengl.org/sdk/docs/man/xhtml/glEnable.xml

glShadeModel(GL_FLAT)
glShadeModel(GL_SMOOTH)

[링크 : http://www.opengl.org/sdk/docs/man/xhtml/glShadeModel.xml

[링크 : http://www.codeguru.com/cpp/g-m/opengl/article.php/c2681]
2011/10/13 - [이론 관련/3D 그래픽 관련] - vertex normal - 버텍스 노말

'Programming > openGL' 카테고리의 다른 글

GLSL 관련 링크  (0) 2011.11.12
gluUnProject / glRenderMode(GL_SELECT)  (0) 2011.10.19
glut Menu 관련 함수들  (0) 2011.10.10
glutAttachMenu()의 Linux용 버그  (2) 2011.10.10
GLUT에서 더블클릭은 음..  (0) 2011.10.10
Posted by 구차니
Programming/C++ STL2011. 10. 13. 22:12
두줄 넣으면 해결!

#include <cstring>
using namespace std;

[링크 : http://stackoverflow.com/questions/2220795/error-strcpy-was-not-declared-in-this-scope]

'Programming > C++ STL' 카테고리의 다른 글

템플릿 메타프로그래밍  (0) 2013.01.06
c++ template  (0) 2012.05.12
new / new[] / delete / delete[]  (4) 2010.09.16
cout 그리고 namespace  (0) 2010.09.16
C++ 레퍼런스 변수(reference variable)  (4) 2010.09.15
Posted by 구차니
Programming/openGL2011. 10. 10. 22:29
glut의 메뉴는 context-menu용으로 우클릭을 등록해서 많이 사용하는 타입의 메뉴이다.

아래는 glut의 메뉴관련 함수들의 목록이다.
$ vi /usr/include/GL/freeglut_std.h 
443 /*
444  * Menu stuff, see freeglut_menu.c
445  */
446 FGAPI int     FGAPIENTRY glutCreateMenu( void (* callback)( int menu ) );
447 FGAPI void    FGAPIENTRY glutDestroyMenu( int menu );
448 FGAPI int     FGAPIENTRY glutGetMenu( void );
449 FGAPI void    FGAPIENTRY glutSetMenu( int menu );
450 FGAPI void    FGAPIENTRY glutAddMenuEntry( const char* label, int value );
451 FGAPI void    FGAPIENTRY glutAddSubMenu( const char* label, int subMenu );
452 FGAPI void    FGAPIENTRY glutChangeToMenuEntry( int item, const char* label, int value );
453 FGAPI void    FGAPIENTRY glutChangeToSubMenu( int item, const char* label, int value );
454 FGAPI void    FGAPIENTRY glutRemoveMenuItem( int item );
455 FGAPI void    FGAPIENTRY glutAttachMenu( int button );
456 FGAPI void    FGAPIENTRY glutDetachMenu( int button ); 

사용예는 아래와 같이
menuid = glutCreateMenu(callback); 로 생성을 하고 콜백함수를 등록하며
생성된 메뉴에  glutAdd*() 함수들을 이용해 항목이나 하위 메뉴를 추가하는 형식으로 구성된다.
submenu의 경우에는 생성이 완료된 하나의 메뉴를 현재의 메뉴 아래에 추가하는 것이기 때문에
예제처럼 하위 메뉴를 먼저 생성하고 메인 메뉴를 생성한뒤 하위 메뉴를 추가해주어야 한다.
static int mainMenu, displayMenu;

void MenuCallback(int value)
{
	switch (value)
	{
		case 99:
			exit(0);
			break;

		default: 
			break;
	}
}
 
void glutinit_contextmenu()
{
	displayMenu = glutCreateMenu(MenuCallback);
		glutAddMenuEntry("Wireframe", 0);

	mainMenu = glutCreateMenu(MenuCallback);
		glutAddSubMenu("Display", displayMenu);
		glutAddMenuEntry("Exit", 99);
		glutAttachMenu(GLUT_RIGHT_BUTTON);
}
[링크 : http://linux.die.net/man/3/glutcreatemenu]
[링크 : http://linux.die.net/man/3/glutattachmenu]
[링크 : http://linux.die.net/man/3/glutaddmenuentry]
[링크 : http://linux.die.net/man/3/glutaddsubmenu]

'Programming > openGL' 카테고리의 다른 글

gluUnProject / glRenderMode(GL_SELECT)  (0) 2011.10.19
glNormal()  (0) 2011.10.18
glutAttachMenu()의 Linux용 버그  (2) 2011.10.10
GLUT에서 더블클릭은 음..  (0) 2011.10.10
openglut / freeglut 무슨 사이야?  (0) 2011.10.09
Posted by 구차니