blob_id
stringlengths
40
40
directory_id
stringlengths
40
40
path
stringlengths
7
332
content_id
stringlengths
40
40
detected_licenses
sequencelengths
0
50
license_type
stringclasses
2 values
repo_name
stringlengths
7
115
snapshot_id
stringlengths
40
40
revision_id
stringlengths
40
40
branch_name
stringclasses
557 values
visit_date
timestamp[us]
revision_date
timestamp[us]
committer_date
timestamp[us]
github_id
int64
5.85k
684M
star_events_count
int64
0
77.7k
fork_events_count
int64
0
48k
gha_license_id
stringclasses
17 values
gha_event_created_at
timestamp[us]
gha_created_at
timestamp[us]
gha_language
stringclasses
82 values
src_encoding
stringclasses
28 values
language
stringclasses
1 value
is_vendor
bool
1 class
is_generated
bool
2 classes
length_bytes
int64
7
5.41M
extension
stringclasses
11 values
content
stringlengths
7
5.41M
authors
sequencelengths
1
1
author
stringlengths
0
161
a9e9d1129e0d81a65fd44902a7647e6477d0c770
4e01469cc355c7ed56fa9f2cf6a728e33c0b9ac6
/Reception/reception/src/test/java/com/example/reception/ReceptionApplicationTests.java
7ea41d7e269f9cc674e44e1d44057dc1d5a602d8
[]
no_license
AyshaHamna/Hotel-Reservation
69a4908ba13a2b502e4e833101b1e84a49b4d930
64cfd9c0478851b469d4502a637c50e89d8260f1
refs/heads/master
2022-12-26T16:05:16.006472
2020-10-07T06:49:53
2020-10-07T06:49:53
301,936,116
0
0
null
null
null
null
UTF-8
Java
false
false
216
java
package com.example.reception; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest class ReceptionApplicationTests { @Test void contextLoads() { } }
a5f6cf131bbed6b883e8e92d335776a97dc1b0e5
95ffa7649dde1e9fdda8bedd22063d3dac73ebab
/src/com/sfb/schedulerWeblogicDemo/Email.java
17d9a66beef0a2cb52017c58602fddd20c3eb409
[]
no_license
abhidabas/practice
8fc4806446322fe4eda8b15b8b5d95da985aa887
3b3d2e1c42fbe1ed4644d54bc079f58d5c11a9d9
refs/heads/master
2021-06-26T01:03:46.829893
2017-09-12T05:45:44
2017-09-12T05:45:44
103,225,881
0
0
null
null
null
null
UTF-8
Java
false
false
475
java
package com.sfb.schedulerWeblogicDemo; public class Email { String to = "[email protected]"; String subject = "subject"; String body = "body"; public String getTo() { return to; } public void setTo(String to) { this.to = to; } public String getSubject() { return subject; } public void setSubject(String subject) { this.subject = subject; } public String getBody() { return body; } public void setBody(String body) { this.body = body; } }
1be44d63300f9eb380adb48c2a3ec68e5b80f932
8d77181692e07d2a5b0bb48b91aa1e8bbdae1232
/builder/src/main/java/com/github/ftfetter/oopdesignpatterns/builder/product/YellowBankCustomer.java
b7672e2900a7227be2fbb1161114f530e606b328
[ "MIT" ]
permissive
ftfetter/oop-design-patterns
fd507ef5f538b6c3c3a1394b19e50d22904f1eb6
05be9d5b55c84c429a193da76b1b25fe56ffe5f4
refs/heads/master
2022-07-07T00:52:26.128795
2022-06-23T14:54:18
2022-06-23T14:54:18
206,670,571
6
0
null
null
null
null
UTF-8
Java
false
false
1,322
java
package com.github.ftfetter.oopdesignpatterns.builder.product; public class YellowBankCustomer { private String name; private YellowBankCurrentAccount currentAccount; private YellowBankCardAccount cardAccount; public YellowBankCustomer() { } public YellowBankCustomer(String name, YellowBankCurrentAccount currentAccount, YellowBankCardAccount cardAccount) { this.name = name; this.currentAccount = currentAccount; this.cardAccount = cardAccount; } public String getName() { return name; } public void setName(String name) { this.name = name; } public YellowBankCurrentAccount getCurrentAccount() { return currentAccount; } public void setCurrentAccount(YellowBankCurrentAccount currentAccount) { this.currentAccount = currentAccount; } public YellowBankCardAccount getCardAccount() { return cardAccount; } public void setCardAccount(YellowBankCardAccount cardAccount) { this.cardAccount = cardAccount; } @Override public String toString() { return "YellowBankCustomer{" + "name='" + name + '\'' + ", currentAccount=" + currentAccount + ", cardAccount=" + cardAccount + '}'; } }
92f1d658bf84251a93b89535ba8aff8a272ca027
b20845774027f73188bb3bf06bb5c8509e362370
/src/main/java/com/github/sunnysuperman/pim/util/BeanUtils.java
84d3a5f6d36779c0c625a9ef04bb3115f9b6d024
[ "Apache-2.0" ]
permissive
sunnysuperman/pim-server
2e174c2eba41e23dae5434d73db34488cfd65303
8e21e4cb30afbe6e3fdb0007f141776e20521544
refs/heads/master
2021-01-22T18:01:39.767144
2017-10-16T03:07:55
2017-10-16T03:07:55
85,052,340
0
1
null
null
null
null
UTF-8
Java
false
false
2,566
java
package com.github.sunnysuperman.pim.util; import java.util.Date; import com.github.sunnysuperman.commons.utils.FormatUtil; public class BeanUtils { public static Object parseSimpleType(Object raw, Class<?> destClass) { if (raw == null) { return null; } if (raw.getClass().equals(destClass)) { return raw; } // most case if (destClass.equals(String.class)) { return raw.toString(); } if (destClass.equals(Boolean.class)) { return FormatUtil.parseBooleanStrictly(raw); } if (destClass.equals(boolean.class)) { return FormatUtil.parseBoolean(raw, Boolean.FALSE); } if (destClass.equals(Integer.class)) { return FormatUtil.parseInteger(raw); } if (destClass.equals(int.class)) { Integer integer = FormatUtil.parseInteger(raw); return integer == null ? 0 : integer.intValue(); } if (destClass.equals(Long.class)) { return FormatUtil.parseLong(raw); } if (destClass.equals(long.class)) { Long l = FormatUtil.parseLong(raw); return l == null ? 0L : l.longValue(); } if (destClass.equals(Double.class)) { return FormatUtil.parseDouble(raw); } if (destClass.equals(double.class)) { Double d = FormatUtil.parseDouble(raw); return d == null ? 0d : d.doubleValue(); } if (destClass.equals(Float.class)) { return FormatUtil.parseFloat(raw); } if (destClass.equals(float.class)) { Float f = FormatUtil.parseFloat(raw); return f == null ? 0f : f.floatValue(); } if (destClass.equals(Date.class)) { return FormatUtil.parseDate(raw); } if (destClass.equals(Short.class)) { return FormatUtil.parseShort(raw); } if (destClass.equals(short.class)) { Short s = FormatUtil.parseShort(raw); return s == null ? (short) 0 : s.shortValue(); } if (destClass.equals(Byte.class)) { return FormatUtil.parseByte(raw); } if (destClass.equals(byte.class)) { Byte s = FormatUtil.parseByte(raw); return s == null ? (byte) 0 : s.byteValue(); } if (destClass.equals(Character.class) || destClass.equals(char.class)) { return raw.toString().charAt(0); } return raw; } }
adfee5a2e73a3bdea31902ed6985143f25499d39
883d0cd75c2fc65c36211c758375cfcf139823a2
/src/test/java/com/example/chat3/Chat3ApplicationTests.java
1464df4590cce001117bb0df11ef12134a5483b2
[]
no_license
mmilak197/spring-chat
0b073e257adc3e5d2fbb14a846145b9cd575a054
5ac8b276afe328b4cee681dd0558d1655ed0ae97
refs/heads/master
2022-02-23T07:29:17.380443
2019-09-17T08:52:31
2019-09-17T08:52:31
208,979,580
0
0
null
null
null
null
UTF-8
Java
false
false
342
java
package com.example.chat3; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest public class Chat3ApplicationTests { @Test public void contextLoads() { } }
e4d059cd8172cfbc77ad7002af23be69baa0f788
df8b40a0c72e4e7bfb9ddf0cf105641659b8224e
/bos_management02/bos_management02_dao/src/main/java/com/itgg/bos/dao/take_delivery/WaybillRepository.java
6347c2ebf758e1b92764e3951807e326fa471de9
[]
no_license
xinwing/boss2
e73f19ece5eaa9acfcf295127e48e986cd893e4d
ede6e8454889d70d88cba9804ab6b1cee47f9278
refs/heads/master
2021-04-03T09:03:50.279114
2018-04-01T06:35:39
2018-04-01T06:35:39
124,736,629
0
0
null
null
null
null
UTF-8
Java
false
false
525
java
package com.itgg.bos.dao.take_delivery; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import com.itgg.bos.domain.take_delivery.WayBill; /** * ClassName:WaybillRepository <br/> * Function: <br/> * Date: 2018年3月25日 下午5:24:54 <br/> */ public interface WaybillRepository extends JpaRepository<WayBill, Long> { WayBill findByWayBillNum(String wayBillNum); }
73b86fa6fbdf2dc8834332cb5892f71ed8f94baf
2b57f3c5a38600b6fa2137c86b7c45181cadd0d3
/hw-02/src/main/java/ru/otus/mezgin/domain/Answer.java
f1dfb24431dcbc63d685d514e53bf13c2ab64383
[]
no_license
amezgin/2021-03-otus-spring-mezgin
9729954db293610e3e4f1cc1fce046dcfc83333d
ff7d1efc2a5515505b5858fd3fa171c6bb1876e2
refs/heads/master
2023-08-08T01:12:19.778007
2021-09-07T18:37:19
2021-09-07T18:37:19
352,103,118
0
0
null
null
null
null
UTF-8
Java
false
false
310
java
package ru.otus.mezgin.domain; public class Answer extends Item { private String personAnswer; public Answer() { } public String getPersonAnswer() { return personAnswer; } public void setPersonAnswer(String personAnswer) { this.personAnswer = personAnswer; } }
37c112b75955f54b1560166e055be755bc0a0b30
92a333d1283c5da89efdbd308af6300e7f72245f
/coilliaux-thibault-client/src/main/java/coilliaux/thibault/generated/GetIdentifiantClient.java
8ec34b58c5fa727cf9683a41d10b13f2065fda1c
[]
no_license
Crastchet/IOS_exam
2653082b2309b87c1be5fc828bc4063891ade615
8dc8a188755331adddea372c927540233e77351e
refs/heads/master
2021-08-22T07:14:54.607929
2017-11-29T15:26:32
2017-11-29T15:26:32
112,493,408
0
0
null
null
null
null
UTF-8
Java
false
false
1,982
java
package coilliaux.thibault.generated; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlType; /** * <p>Classe Java pour getIdentifiantClient complex type. * * <p>Le fragment de schéma suivant indique le contenu attendu figurant dans cette classe. * * <pre> * &lt;complexType name="getIdentifiantClient"&gt; * &lt;complexContent&gt; * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt; * &lt;sequence&gt; * &lt;element name="arg0" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt; * &lt;element name="arg1" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt; * &lt;/sequence&gt; * &lt;/restriction&gt; * &lt;/complexContent&gt; * &lt;/complexType&gt; * </pre> * * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "getIdentifiantClient", propOrder = { "arg0", "arg1" }) public class GetIdentifiantClient { protected String arg0; protected String arg1; /** * Obtient la valeur de la propriété arg0. * * @return * possible object is * {@link String } * */ public String getArg0() { return arg0; } /** * Définit la valeur de la propriété arg0. * * @param value * allowed object is * {@link String } * */ public void setArg0(String value) { this.arg0 = value; } /** * Obtient la valeur de la propriété arg1. * * @return * possible object is * {@link String } * */ public String getArg1() { return arg1; } /** * Définit la valeur de la propriété arg1. * * @param value * allowed object is * {@link String } * */ public void setArg1(String value) { this.arg1 = value; } }
084208bc4433f4bd87dd3f2a6f5a4d855c9849e2
65172009415eee54f209f16d1d66946f187aa774
/Working_Solution/backend/spring-web-service-consumer/src/main/java/com/spring/app/soap/configs/AgreementsListClientConfig.java
c13082a7c92df2203ed3f06e7d67083197683627
[ "MIT" ]
permissive
marest94/example
4676874289aa62e23f62d25e36feaac03f2a47f8
89659fa80ed57d7ff1278819a199f8e8a5f06b11
refs/heads/master
2021-09-09T09:08:53.903022
2018-03-14T15:18:46
2018-03-14T15:18:46
124,065,301
0
0
null
null
null
null
UTF-8
Java
false
false
687
java
package com.spring.app.soap.configs; import org.springframework.context.annotation.Bean; import org.springframework.oxm.jaxb.Jaxb2Marshaller; import com.spring.app.soap.clients.Client; public class AgreementsListClientConfig { @Bean public Jaxb2Marshaller marshaller() { Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); marshaller.setContextPath("com.spring.app.soap.wsdl"); return marshaller; } @Bean public Client service1Client(Jaxb2Marshaller marshaller) { Client client = new Client(); client.setDefaultUri("http://localhost:8080/soapws/agreementsList.wsdl"); client.setMarshaller(marshaller); client.setUnmarshaller(marshaller); return client; } }
848a61ed69cc03c476bdb19783a6b6a51e91a96c
53a1052d79b23d1b488268bb9dbf6dd5a63cbe97
/src/main/java/com/stan/sellwechat/utils/ResultVOUtil.java
7a0cdafcd8c04d3b332c2af71f552b6efefc1ab9
[]
no_license
WitnessStan/MyWrok
c6a1451b4182ec8804fb7534be550e375db16039
977d0e16d17f3830166bbd36c509a8a90c95b5ae
refs/heads/master
2020-04-08T20:18:35.515904
2018-12-09T12:06:26
2018-12-09T12:06:26
159,693,577
0
0
null
null
null
null
UTF-8
Java
false
false
623
java
package com.stan.sellwechat.utils; import com.stan.sellwechat.VO.ResultVO; public class ResultVOUtil { public static ResultVO success(Object object){ ResultVO resultVO = new ResultVO(); resultVO.setCode(0); resultVO.setMessage("成功"); resultVO.setData(object); return resultVO; } public static ResultVO success() { return success(null); } public static ResultVO error(Integer code, String message) { ResultVO resultVO = new ResultVO(); resultVO.setCode(code); resultVO.setMessage(message); return resultVO; } }
018fd8fac48393b96098c53ff1da8d61a769eeb9
cb1e674766ed5b30231fd5dfcced799b33f1473b
/src/main/java/com/obs/eggplant/ServletInitializer.java
73407a4f7b6f33959e76a3924758ecadeba06d34
[]
no_license
stanleyw2014/springbootsample
7ee5bd7d9b342de0cbed85aa3a9c25421fdcf8c4
0696c951e8da0c4f19769886be17b41e64955635
refs/heads/master
2020-05-08T23:07:26.923737
2019-07-07T14:11:57
2019-07-07T14:11:57
180,971,656
0
0
null
null
null
null
UTF-8
Java
false
false
408
java
package com.obs.eggplant; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; public class ServletInitializer extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(EggplantApplication.class); } }
bc67d2f5069bb80dc20d658b419ab3c7d302cebd
cb993d3b277904efe46e4dfbd9942c3d685dcb09
/request_processor/src/main/java/nl/hetcak/dms/ia/web/infoarchive/searchComposition/SearchComposition.java
31193322025f2f37266e370d2a422f3666a2ec33
[]
no_license
anoordover/dms
43aa4f752600250849dae3ee35c7430817ec9a32
1f06ed3ddeeb3c48d83c0dd8a1bdbb76333978b9
refs/heads/master
2021-01-12T06:56:13.596610
2016-12-06T09:11:25
2016-12-06T09:11:25
76,865,987
0
0
null
null
null
null
UTF-8
Java
false
false
1,161
java
package nl.hetcak.dms.ia.web.infoarchive.searchComposition; import org.apache.commons.lang3.StringUtils; /** * (c) 2016 AMPLEXOR International S.A., All rights reserved. * * @author [email protected] */ public class SearchComposition { private String id; private String name; private String searchName; private int version; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getSearchName() { return searchName; } public void setSearchName(String searchName) { this.searchName = searchName; } public int getVersion() { return version; } public void setVersion(int version) { this.version = version; } public boolean isNotBlank() { if(StringUtils.isNotBlank(id) && StringUtils.isNotBlank(name) && StringUtils.isNotBlank(searchName)) { return true; } return false; } }
17a2dea871db39c29539a866ec15f1f86af7058d
25f32b0df9366cabe32f93cf3723f9245dd2b229
/app/src/main/java/com/example/top10downloadedapp/FeedEntry.java
20cc5dea9e7708ed8ee718c8f89fe3e5e1026030
[]
no_license
10-kapilkori/top_10_download_apps
dd90343cf95385f9d6d0cf45ce60dfa08c96b16a
b7cafc59153f81cbd07b249c8825bf0731709806
refs/heads/master
2023-01-31T20:38:37.078008
2020-12-08T17:42:40
2020-12-08T17:42:40
319,714,975
0
0
null
null
null
null
UTF-8
Java
false
false
976
java
package com.example.top10downloadedapp; public class FeedEntry { String title; String description; String link; String publishDate; public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String getLink() { return link; } public void setLink(String link) { this.link = link; } public String getPublishDate() { return publishDate; } public void setPublishDate(String publishDate) { this.publishDate = publishDate; } @Override public String toString() { return "\n" + "Title= " + title + "\n" + "Link= " + link + "\n" + "Publish Date= " + publishDate + "\n" ; } }
cffdc3e313bf43fffae160f2420541342b4570f6
9c3c3bc10057d49a6ccbdcc1336cf0b72757fe2b
/app/src/main/java/com/example/sharetest/event/EmptyEvent.java
9a944688c2fe0597239ab9a0bc143c85729a5096
[]
no_license
jinhuizxc/ShareTest
4138086d54266e45237173018d37fdcac2a4af9b
c5dfedf300401bb517fc14b3b30c3f536af9fc3d
refs/heads/master
2020-08-03T02:42:51.315476
2019-10-10T01:18:24
2019-10-10T01:18:24
211,600,613
0
0
null
null
null
null
UTF-8
Java
false
false
66
java
package com.example.sharetest.event; public class EmptyEvent { }
[ "13113017500" ]
13113017500
28b38e920f45844d7c5fef7eb1118ed9b245144d
faf1a14a4637ccff99c922bed80c3f10b2c1b008
/src/main/java/com/skm/study/designpattern/signleton/hungry/HungrySignleton.java
1b1cdde0df00a32d12c0632f134ac32a3fef7a3f
[]
no_license
skm-cike/designpattern-signleton
95b0a29605bf2ba3de27aa70ca87c6c5f04d5bae
4b5af4945832b2960ed96843b0d3c0ebb02c132a
refs/heads/master
2020-05-03T20:19:52.526347
2019-04-01T09:17:37
2019-04-01T09:17:37
178,800,544
0
0
null
null
null
null
UTF-8
Java
false
false
751
java
package com.skm.study.designpattern.signleton.hungry; import java.io.Serializable; /** * @描述: 饿式单例 * @作者: 陆华 * @日期: 14:50 2019-04-01 0001 * @修改人: **/ public class HungrySignleton implements Serializable { private final static HungrySignleton INSTANCE = new HungrySignleton(); private HungrySignleton() { if (null != INSTANCE) { throw new RuntimeException("防止反射破坏单例"); } } public final static HungrySignleton getInstance() { return INSTANCE; } /** * @描述: 饿汉式单例同样会被反序列化破坏,使用readResolve解决反序列化破坏 * @return */ private Object readResolve() { return INSTANCE; } }
4a255c6257e527afcda518c10ea9cff13e67f8dd
9f37af5bcccb1c44ec149b0365108e167bc50bc3
/gmall-oms/src/main/java/com/atguigu/gmall/oms/dao/RefundInfoDao.java
2c55ccc01226f0bf9bd7cad2346d747de8468f4b
[ "Apache-2.0" ]
permissive
xlf784679405/gmall-0615
67ab7387990123209a3891c76b9e23f9b630b087
8b084815edcbcee19544e5237c1fc251a0fd5d5e
refs/heads/master
2022-12-23T17:13:58.735000
2019-11-16T08:42:51
2019-11-16T08:42:51
217,997,035
0
0
Apache-2.0
2022-12-16T14:50:53
2019-10-28T08:16:05
JavaScript
UTF-8
Java
false
false
379
java
package com.atguigu.gmall.oms.dao; import com.atguigu.gmall.oms.entity.RefundInfoEntity; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Mapper; /** * 退款信息 * * @author xinlongfei * @email [email protected] * @date 2019-10-29 16:36:30 */ @Mapper public interface RefundInfoDao extends BaseMapper<RefundInfoEntity> { }
b48d21f9544be125dead5fa1fe820fd1d78d65a7
7cfe6b60968c5bb849a0245d88d7a63694f63c64
/kh-spring/src/di_step2/Database.java
97257bb0a4defb6b0b4e963eec509a998b20fc00
[]
no_license
pk6407/kh_spring
068ec721e02f4377560fab9120692bf0008857a2
ed353b7a09fa6bf8e228cbb3cc4fe659a07cdcea
refs/heads/master
2023-02-17T02:56:32.636072
2021-01-14T14:08:13
2021-01-14T14:08:13
null
0
0
null
null
null
null
UTF-8
Java
false
false
654
java
package di_step2; import java.util.ArrayList; import java.util.List; //개발자 박씨 public class Database implements DB{ @Override public List<String> select(String findStr) { List<String> aaa = new ArrayList<String>(); aaa.add("오라클에서 처리된 결과."); return aaa; } @Override public String insert(String mid, String pwd) { // TODO Auto-generated method stub return null; } @Override public String update(String mid, int serial) { // TODO Auto-generated method stub return null; } @Override public int delete(String mid, String pwd, int serial) { // TODO Auto-generated method stub return 0; } }
4bb6ce8929f96457723e6ff49e0819acf31a0f77
92485b21d670fc452b949e3eee8e8181c11ff9e6
/podescoin-core/src/main/java/ch/sourcepond/utils/podescoin/internal/UnserializableClassWarning.java
33282156c0561c18392b04db3fbcb522022cd156
[ "Apache-2.0" ]
permissive
SourcePond/podescoin
96a402b3c153c342eeac481dda33a277406c941e
ddb4c630b783d78eb1947a0f6e4fb913dba58519
refs/heads/master
2021-05-02T16:00:28.274828
2016-12-19T12:44:00
2016-12-19T12:44:00
72,567,945
0
0
null
null
null
null
UTF-8
Java
false
false
924
java
/*Copyright (C) 2016 Roland Hauser, <[email protected]> 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 ch.sourcepond.utils.podescoin.internal; import static java.lang.String.format; final class UnserializableClassWarning extends RuntimeException { /** * */ private static final long serialVersionUID = 1L; public UnserializableClassWarning(final Class<?> cl) { super(format("%s is not serializable!", cl.getName())); } }
fa5d69efa6ffc8aff954a92d1366257717d2571e
ebc55c0c171a2033590fa1f39225d4a54333211c
/mylibrary/src/main/java/com/dian/zxing/ViewfinderView.java
cdc649c0149c80c7a68d78197a2c8e066baf2d42
[]
no_license
YDianZi/DianKotlinUtil
97f8d9cd388ba2e23984aa85c09344bea8d89d8e
f8b51f4048c81cfb95896bc7f7442532227ae027
refs/heads/master
2023-01-09T18:52:25.154596
2020-11-10T08:00:47
2020-11-10T08:00:47
309,844,450
0
0
null
null
null
null
UTF-8
Java
false
false
21,063
java
package com.dian.zxing; /* * Copyright (C) 2008 ZXing authors * * 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. */ import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.LinearGradient; import android.graphics.Paint; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.Shader; import android.text.Layout; import android.text.StaticLayout; import android.text.TextPaint; import android.text.TextUtils; import android.util.AttributeSet; import android.util.DisplayMetrics; import android.util.TypedValue; import android.view.View; import androidx.annotation.ColorInt; import androidx.annotation.ColorRes; import androidx.annotation.Nullable; import androidx.core.content.ContextCompat; import com.dian.mylibrary.R; import com.google.zxing.ResultPoint; import java.util.ArrayList; import java.util.List; /** * This view is overlaid on top of the camera preview. It adds the viewfinder rectangle and partial * transparency outside it, as well as the laser scanner animation and result points. * * @author [email protected] (Daniel Switkin) */ public final class ViewfinderView extends View { private static final int CURRENT_POINT_OPACITY = 0xA0; private static final int MAX_RESULT_POINTS = 20; private static final int POINT_SIZE = 20; /** * 画笔 */ private Paint paint; /** * 文本画笔 */ private TextPaint textPaint; /** * 扫码框外面遮罩颜色 */ private int maskColor; /** * 扫描区域边框颜色 */ private int frameColor; /** * 扫描线颜色 */ private int laserColor; /** * 扫码框四角颜色 */ private int cornerColor; /** * 结果点颜色 */ private int resultPointColor; /** * 提示文本与扫码框的边距 */ private float labelTextPadding; /** * 提示文本的位置 */ private TextLocation labelTextLocation; /** * 扫描区域提示文本 */ private String labelText; /** * 扫描区域提示文本颜色 */ private int labelTextColor; /** * 提示文本字体大小 */ private float labelTextSize; /** * 扫描线开始位置 */ public int scannerStart = 0; /** * 扫描线结束位置 */ public int scannerEnd = 0; /** * 是否显示结果点 */ private boolean isShowResultPoint; /** * 屏幕宽 */ private int screenWidth; /** * 屏幕高 */ private int screenHeight; /** * 扫码框宽 */ private int frameWidth; /** * 扫码框高 */ private int frameHeight; /** * 扫描激光线风格 */ private LaserStyle laserStyle; /** * 网格列数 */ private int gridColumn; /** * 网格高度 */ private int gridHeight; /** * 扫码框 */ private Rect frame; /** * 扫描区边角的宽 */ private int cornerRectWidth; /** * 扫描区边角的高 */ private int cornerRectHeight; /** * 扫描线每次移动距离 */ private int scannerLineMoveDistance; /** * 扫描线高度 */ private int scannerLineHeight; /** * 边框线宽度 */ private int frameLineWidth; /** * 扫描动画延迟间隔时间 默认15毫秒 */ private int scannerAnimationDelay; /** * 扫码框占比 */ private float frameRatio; private List<ResultPoint> possibleResultPoints; private List<ResultPoint> lastPossibleResultPoints; public enum LaserStyle{ NONE(0),LINE(1),GRID(2); private int mValue; LaserStyle(int value){ mValue = value; } private static LaserStyle getFromInt(int value){ for(LaserStyle style : LaserStyle.values()){ if(style.mValue == value){ return style; } } return LaserStyle.LINE; } } public enum TextLocation { TOP(0),BOTTOM(1); private int mValue; TextLocation(int value){ mValue = value; } private static TextLocation getFromInt(int value){ for(TextLocation location : TextLocation.values()){ if(location.mValue == value){ return location; } } return TextLocation.TOP; } } public ViewfinderView(Context context) { this(context,null); } public ViewfinderView(Context context, @Nullable AttributeSet attrs) { this(context, attrs,0); } public ViewfinderView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(context,attrs); } private void init(Context context, AttributeSet attrs) { //初始化自定义属性信息 TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.ViewfinderView); maskColor = array.getColor(R.styleable.ViewfinderView_maskColor, ContextCompat.getColor(context, R.color.viewfinder_mask)); frameColor = array.getColor(R.styleable.ViewfinderView_frameColor, ContextCompat.getColor(context, R.color.viewfinder_frame)); cornerColor = array.getColor(R.styleable.ViewfinderView_cornerColor, ContextCompat.getColor(context, R.color.viewfinder_corner)); laserColor = array.getColor(R.styleable.ViewfinderView_laserColor, ContextCompat.getColor(context, R.color.viewfinder_laser)); resultPointColor = array.getColor(R.styleable.ViewfinderView_resultPointColor, ContextCompat.getColor(context, R.color.viewfinder_result_point_color)); labelText = array.getString(R.styleable.ViewfinderView_labelText); labelTextColor = array.getColor(R.styleable.ViewfinderView_labelTextColor, ContextCompat.getColor(context, R.color.viewfinder_text_color)); labelTextSize = array.getDimension(R.styleable.ViewfinderView_labelTextSize, TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,14f,getResources().getDisplayMetrics())); labelTextPadding = array.getDimension(R.styleable.ViewfinderView_labelTextPadding, TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,24,getResources().getDisplayMetrics())); labelTextLocation = TextLocation.getFromInt(array.getInt(R.styleable.ViewfinderView_labelTextLocation,0)); isShowResultPoint = array.getBoolean(R.styleable.ViewfinderView_showResultPoint,false); frameWidth = array.getDimensionPixelSize(R.styleable.ViewfinderView_frameWidth,0); frameHeight = array.getDimensionPixelSize(R.styleable.ViewfinderView_frameHeight,0); laserStyle = LaserStyle.getFromInt(array.getInt(R.styleable.ViewfinderView_laserStyle, LaserStyle.LINE.mValue)); gridColumn = array.getInt(R.styleable.ViewfinderView_gridColumn,20); gridHeight = (int)array.getDimension(R.styleable.ViewfinderView_gridHeight, TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,40,getResources().getDisplayMetrics())); cornerRectWidth = (int)array.getDimension(R.styleable.ViewfinderView_cornerRectWidth, TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,4,getResources().getDisplayMetrics())); cornerRectHeight = (int)array.getDimension(R.styleable.ViewfinderView_cornerRectHeight, TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,16,getResources().getDisplayMetrics())); scannerLineMoveDistance = (int)array.getDimension(R.styleable.ViewfinderView_scannerLineMoveDistance, TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,2,getResources().getDisplayMetrics())); scannerLineHeight = (int)array.getDimension(R.styleable.ViewfinderView_scannerLineHeight, TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,5,getResources().getDisplayMetrics())); frameLineWidth = (int)array.getDimension(R.styleable.ViewfinderView_frameLineWidth, TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,1,getResources().getDisplayMetrics())); scannerAnimationDelay = array.getInteger(R.styleable.ViewfinderView_scannerAnimationDelay,15); frameRatio = array.getFloat(R.styleable.ViewfinderView_frameRatio,0.625f); array.recycle(); paint = new Paint(Paint.ANTI_ALIAS_FLAG); textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); possibleResultPoints = new ArrayList<>(5); lastPossibleResultPoints = null; screenWidth = getDisplayMetrics().widthPixels; screenHeight = getDisplayMetrics().heightPixels; int size = (int)(Math.min(screenWidth,screenHeight) * frameRatio); if(frameWidth<=0 || frameWidth > screenWidth){ frameWidth = size; } if(frameHeight<=0 || frameHeight > screenHeight){ frameHeight = size; } } private DisplayMetrics getDisplayMetrics(){ return getResources().getDisplayMetrics(); } public void setLabelText(String labelText) { this.labelText = labelText; } public void setLabelTextColor(@ColorInt int color) { this.labelTextColor = color; } public void setLabelTextColorResource(@ColorRes int id){ this.labelTextColor = ContextCompat.getColor(getContext(),id); } public void setLabelTextSize(float textSize) { this.labelTextSize = textSize; } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); //扫码框默认居中,支持利用内距偏移扫码框 int leftOffset = (screenWidth - frameWidth) / 2 + getPaddingLeft() - getPaddingRight(); int topOffset = (screenHeight - frameHeight) / 2 + getPaddingTop() - getPaddingBottom(); frame = new Rect(leftOffset, topOffset, leftOffset + frameWidth, topOffset + frameHeight); } @Override public void onDraw(Canvas canvas) { if (frame == null) { return; } if(scannerStart == 0 || scannerEnd == 0) { scannerStart = frame.top; scannerEnd = frame.bottom - scannerLineHeight; } int width = canvas.getWidth(); int height = canvas.getHeight(); // Draw the exterior (i.e. outside the framing rect) darkened drawExterior(canvas,frame,width,height); // Draw a red "laser scanner" line through the middle to show decoding is active drawLaserScanner(canvas,frame); // Draw a two pixel solid black border inside the framing rect drawFrame(canvas, frame); // 绘制边角 drawCorner(canvas, frame); //绘制提示信息 drawTextInfo(canvas, frame); //绘制扫码结果点 drawResultPoint(canvas,frame); // Request another update at the animation interval, but only repaint the laser line, // not the entire viewfinder mask. postInvalidateDelayed(scannerAnimationDelay, frame.left - POINT_SIZE, frame.top - POINT_SIZE, frame.right + POINT_SIZE, frame.bottom + POINT_SIZE); } /** * 绘制文本 * @param canvas * @param frame */ private void drawTextInfo(Canvas canvas, Rect frame) { if(!TextUtils.isEmpty(labelText)){ textPaint.setColor(labelTextColor); textPaint.setTextSize(labelTextSize); textPaint.setTextAlign(Paint.Align.CENTER); StaticLayout staticLayout = new StaticLayout(labelText,textPaint,canvas.getWidth(), Layout.Alignment.ALIGN_NORMAL,1.0f,0.0f,true); if(labelTextLocation == TextLocation.BOTTOM){ canvas.translate(frame.left + frame.width() / 2,frame.bottom + labelTextPadding); staticLayout.draw(canvas); }else{ canvas.translate(frame.left + frame.width() / 2,frame.top - labelTextPadding - staticLayout.getHeight()); staticLayout.draw(canvas); } } } /** * 绘制边角 * @param canvas * @param frame */ private void drawCorner(Canvas canvas, Rect frame) { paint.setColor(cornerColor); //左上 canvas.drawRect(frame.left, frame.top, frame.left + cornerRectWidth, frame.top + cornerRectHeight, paint); canvas.drawRect(frame.left, frame.top, frame.left + cornerRectHeight, frame.top + cornerRectWidth, paint); //右上 canvas.drawRect(frame.right - cornerRectWidth, frame.top, frame.right, frame.top + cornerRectHeight, paint); canvas.drawRect(frame.right - cornerRectHeight, frame.top, frame.right, frame.top + cornerRectWidth, paint); //左下 canvas.drawRect(frame.left, frame.bottom - cornerRectWidth, frame.left + cornerRectHeight, frame.bottom, paint); canvas.drawRect(frame.left, frame.bottom - cornerRectHeight, frame.left + cornerRectWidth, frame.bottom, paint); //右下 canvas.drawRect(frame.right - cornerRectWidth, frame.bottom - cornerRectHeight, frame.right, frame.bottom, paint); canvas.drawRect(frame.right - cornerRectHeight, frame.bottom - cornerRectWidth, frame.right, frame.bottom, paint); } /** * 绘制激光扫描线 * @param canvas * @param frame */ private void drawLaserScanner(Canvas canvas, Rect frame) { if(laserStyle!=null){ paint.setColor(laserColor); switch (laserStyle){ case LINE://线 drawLineScanner(canvas,frame); break; case GRID://网格 drawGridScanner(canvas,frame); break; } paint.setShader(null); } } /** * 绘制线性式扫描 * @param canvas * @param frame */ private void drawLineScanner(Canvas canvas, Rect frame){ //线性渐变 LinearGradient linearGradient = new LinearGradient( frame.left, scannerStart, frame.left, scannerStart + scannerLineHeight, shadeColor(laserColor), laserColor, Shader.TileMode.MIRROR); paint.setShader(linearGradient); if(scannerStart <= scannerEnd) { //椭圆 RectF rectF = new RectF(frame.left + 2 * scannerLineHeight, scannerStart, frame.right - 2 * scannerLineHeight, scannerStart + scannerLineHeight); canvas.drawOval(rectF, paint); scannerStart += scannerLineMoveDistance; } else { scannerStart = frame.top; } } /** * 绘制网格式扫描 * @param canvas * @param frame */ private void drawGridScanner(Canvas canvas, Rect frame){ int stroke = 2; paint.setStrokeWidth(stroke); //计算Y轴开始位置 int startY = gridHeight > 0 && scannerStart - frame.top > gridHeight ? scannerStart - gridHeight : frame.top; LinearGradient linearGradient = new LinearGradient(frame.left + frame.width()/2, startY, frame.left + frame.width()/2, scannerStart, new int[]{shadeColor(laserColor), laserColor}, new float[]{0,1f}, LinearGradient.TileMode.CLAMP); //给画笔设置着色器 paint.setShader(linearGradient); float wUnit = frame.width() * 1.0f/ gridColumn; float hUnit = wUnit; //遍历绘制网格纵线 for (int i = 1; i < gridColumn; i++) { canvas.drawLine(frame.left + i * wUnit, startY,frame.left + i * wUnit, scannerStart,paint); } int height = gridHeight > 0 && scannerStart - frame.top > gridHeight ? gridHeight : scannerStart - frame.top; //遍历绘制网格横线 for (int i = 0; i <= height/hUnit; i++) { canvas.drawLine(frame.left, scannerStart - i * hUnit,frame.right, scannerStart - i * hUnit,paint); } if(scannerStart<scannerEnd){ scannerStart += scannerLineMoveDistance; } else { scannerStart = frame.top; } } /** * 处理颜色模糊 * @param color * @return */ public int shadeColor(int color) { String hax = Integer.toHexString(color); String result = "01"+hax.substring(2); return Integer.valueOf(result, 16); } /** * 绘制扫描区边框 * @param canvas * @param frame */ private void drawFrame(Canvas canvas, Rect frame) { paint.setColor(frameColor); canvas.drawRect(frame.left, frame.top, frame.right, frame.top + frameLineWidth, paint); canvas.drawRect(frame.left, frame.top, frame.left + frameLineWidth, frame.bottom, paint); canvas.drawRect(frame.right - frameLineWidth, frame.top, frame.right, frame.bottom, paint); canvas.drawRect(frame.left, frame.bottom - frameLineWidth, frame.right, frame.bottom, paint); } /** * 绘制模糊区域 * @param canvas * @param frame * @param width * @param height */ private void drawExterior(Canvas canvas, Rect frame, int width, int height) { paint.setColor(maskColor); canvas.drawRect(0, 0, width, frame.top, paint); canvas.drawRect(0, frame.top, frame.left, frame.bottom, paint); canvas.drawRect(frame.right, frame.top, width, frame.bottom, paint); canvas.drawRect(0, frame.bottom, width, height, paint); } /** * 绘制扫码结果点 * @param canvas * @param frame */ private void drawResultPoint(Canvas canvas, Rect frame){ if(!isShowResultPoint){ return; } List<ResultPoint> currentPossible = possibleResultPoints; List<ResultPoint> currentLast = lastPossibleResultPoints; if (currentPossible.isEmpty()) { lastPossibleResultPoints = null; } else { possibleResultPoints = new ArrayList<>(5); lastPossibleResultPoints = currentPossible; paint.setAlpha(CURRENT_POINT_OPACITY); paint.setColor(resultPointColor); synchronized (currentPossible) { float radius = POINT_SIZE / 2.0f; for (ResultPoint point : currentPossible) { canvas.drawCircle( point.getX(),point.getY(), radius, paint); } } } if (currentLast != null) { paint.setAlpha(CURRENT_POINT_OPACITY / 2); paint.setColor(resultPointColor); synchronized (currentLast) { float radius = POINT_SIZE / 2.0f; for (ResultPoint point : currentLast) { canvas.drawCircle( point.getX(),point.getY(), radius, paint); } } } } public void drawViewfinder() { invalidate(); } public boolean isShowResultPoint() { return isShowResultPoint; } public void setLaserStyle(LaserStyle laserStyle) { this.laserStyle = laserStyle; } /** * 设置显示结果点 * @param showResultPoint 是否显示结果点 */ public void setShowResultPoint(boolean showResultPoint) { isShowResultPoint = showResultPoint; } public void addPossibleResultPoint(ResultPoint point) { if(isShowResultPoint){ List<ResultPoint> points = possibleResultPoints; synchronized (points) { points.add(point); int size = points.size(); if (size > MAX_RESULT_POINTS) { // trim it points.subList(0, size - MAX_RESULT_POINTS / 2).clear(); } } } } }
3b76c693f6ed566d73d3213a9ee87c5be4b6fc3c
d116c326d035a2d375ab9ef941473edddaa036e6
/Java_08/src/com/biz/classes/ClassEx_01.java
180837f795f7856c13225f4f746a38df01b3cae5
[]
no_license
kol2005/JAVAWORKSS
537716a8f30498fbb8ed167dc0b7f8a39d89c35d
fffae5fd6827af96b56404211eed99d63b3e2190
refs/heads/master
2020-09-04T00:24:46.817028
2019-11-04T23:35:31
2019-11-04T23:35:31
219,616,377
0
0
null
null
null
null
UHC
Java
false
false
958
java
package com.biz.classes; import java.util.Scanner; public class ClassEx_01 { public static void main(String[] args) { /* * 변수 * 메모리 어딘가에 값을 저장할 공간을 확보하고 * 그곳에 알기 쉽도록 이름을 부여하는 것 */ // 변수의 형을 지정하는 Kye word 라고 한다 // 첫글자가 소문자로 시작하는 key word // primitive(기본형) 변수 int intNum1 = 0; // 변수를 선언하고 초기화 한다 long longNum1 = 0L; float floatNum1 = 3.0f; double doubleNum = 3.0; char cA = 'A'; boolean bYes = true; boolean bNo = 3 != 3; // type 형 // referance(참조형) 변수 // 클래스(String)를 사용하여 생성한 변수 // 객체, Object, Instance라고 한다 String strName = "대한민국"; //참조형 변수 //Scanner 라는 클래스를 사용하여 생성한 변수 Scanner scanner = new Scanner(System.in); } }
ea2493c0e1b37ff4620c36e3fff578159e21e83e
760153837b96ec4d0db75fef4520a25ee791487b
/wp-signle-page-starter/wp-starter-core/src/main/java/mk/ukim/finki/wp/web/errors/ErrorHandler.java
afbc70f8059a8a5245079355cf13033c5027b3ec
[]
no_license
gambleros/wp-2015
ccc91ea0c8e71e4f2075690e5b54bf0169c00b2e
e06d36e80bac1e062ddb9bfdc698eacaee7419af
refs/heads/master
2021-01-18T07:06:15.462957
2016-01-10T22:45:02
2016-01-10T22:45:02
null
0
0
null
null
null
null
UTF-8
Java
false
false
836
java
package mk.ukim.finki.wp.web.errors; import ch.qos.logback.classic.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseStatus; import java.io.PrintWriter; import java.io.StringWriter; /** * Created by ristes on 11/9/15. */ @ControllerAdvice public class ErrorHandler { Logger logger = (Logger) LoggerFactory.getLogger(ErrorHandler.class); @ExceptionHandler @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) @ResponseBody public ErrorDto handleException(Exception e) { logger.error(e.getMessage(), e); return new ErrorDto(e); } }
3ea5ad0113fa8969a260bb1957768200dd0d6cd2
8e5fc8afa76aceb652ed9c3dc35575b80d31d99f
/nutz-plugins-multiview/src/main/java/org/nutz/plugins/view/FreemarkerView.java
ebef597f77b655516909796646545a4c7f505bf7
[ "Apache-2.0" ]
permissive
zjlwmz/nutzmore
54438318ca3d4fe8c4369dbed396e0f34682e9cd
f9372745a1bda496dd15ba55412ac49d036a9c14
refs/heads/master
2021-09-01T08:49:07.953805
2017-12-26T02:58:11
2017-12-26T02:58:11
115,727,708
0
1
null
2017-12-29T14:14:12
2017-12-29T14:14:12
null
UTF-8
Java
false
false
6,141
java
package org.nutz.plugins.view; import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Enumeration; import java.util.Map; import java.util.Properties; import javax.servlet.GenericServlet; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.nutz.lang.Files; import org.nutz.mvc.Mvcs; import freemarker.ext.jsp.TaglibFactory; import freemarker.ext.servlet.HttpRequestHashModel; import freemarker.ext.servlet.HttpRequestParametersHashModel; import freemarker.ext.servlet.HttpSessionHashModel; import freemarker.ext.servlet.ServletContextHashModel; import freemarker.template.Configuration; import freemarker.template.ObjectWrapper; import freemarker.template.Template; import freemarker.template.TemplateException; import freemarker.template.TemplateExceptionHandler; import freemarker.template.TemplateModel; public class FreemarkerView extends AbstractTemplateViewResolver { private static final String CONFIG_SERVLET_CONTEXT_KEY = "freemarker.Configuration"; private static final String ATTR_APPLICATION_MODEL = ".freemarker.Application"; private static final String ATTR_JSP_TAGLIBS_MODEL = ".freemarker.JspTaglibs"; private static final String ATTR_REQUEST_MODEL = ".freemarker.Request"; private static final String ATTR_REQUEST_PARAMETERS_MODEL = ".freemarker.RequestParameters"; private static final String KEY_APPLICATION = "Application"; private static final String KEY_REQUEST_MODEL = "Request"; private static final String KEY_SESSION_MODEL = "Session"; private static final String KEY_REQUEST_PARAMETER_MODEL = "Parameters"; private static final String KEY_EXCEPTION = "exception"; private static final String KEY_JSP_TAGLIBS = "JspTaglibs"; private Configuration cfg; public FreemarkerView(String dest) { super(dest); } @Override protected void init(String appRoot,ServletContext sc) { cfg = (Configuration) sc.getAttribute(CONFIG_SERVLET_CONTEXT_KEY); if (cfg == null) { cfg = new Configuration(Configuration.VERSION_2_3_23); cfg.setServletContextForTemplateLoading(sc, "/"); cfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER); // 读取freemarker配置文件 loadSettings(cfg); sc.setAttribute(CONFIG_SERVLET_CONTEXT_KEY, cfg); } cfg.setWhitespaceStripping(true); } @SuppressWarnings("unchecked") @Override public void render(HttpServletRequest request, HttpServletResponse response, String evalPath, Map<String, Object> vars) throws Throwable { // 添加数据模型 // root.put(BASE, request.getContextPath()); Enumeration<String> reqs = request.getAttributeNames(); while (reqs.hasMoreElements()) { String strKey = (String) reqs.nextElement(); vars.put(strKey, request.getAttribute(strKey)); } // 让freemarker支持jsp 标签 jspTaglibs(Mvcs.getServletContext(), request, response, vars, cfg.getObjectWrapper()); // 模版路径 Template t = cfg.getTemplate(evalPath); response.setContentType("text/html; charset=" + t.getEncoding()); t.process(vars, response.getWriter()); } protected void loadSettings(Configuration config) { InputStream in = null; try { in = new BufferedInputStream(new FileInputStream( Files.findFile("freemarker.properties"))); if (in != null) { Properties p = new Properties(); p.load(in); config.setSettings(p); } } catch (IOException e) { e.printStackTrace(); } catch (TemplateException e) { e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (IOException io) { io.printStackTrace(); } } } } protected void jspTaglibs(ServletContext servletContext, HttpServletRequest request, HttpServletResponse response, Map<String, Object> model, ObjectWrapper wrapper) { synchronized (servletContext) { ServletContextHashModel servletContextModel = (ServletContextHashModel) servletContext .getAttribute(ATTR_APPLICATION_MODEL); if (servletContextModel == null) { GenericServlet servlet = JspSupportServlet.jspSupportServlet; // TODO if the jsp support servlet isn't load-on-startup then it // won't exist // if it hasn't been accessed, and a JSP page is accessed if (servlet != null) { servletContextModel = new ServletContextHashModel(servlet, wrapper); servletContext.setAttribute(ATTR_APPLICATION_MODEL, servletContextModel); TaglibFactory taglibs = new TaglibFactory(servletContext); servletContext .setAttribute(ATTR_JSP_TAGLIBS_MODEL, taglibs); } } model.put(KEY_APPLICATION, servletContextModel); model.put(KEY_JSP_TAGLIBS, (TemplateModel) servletContext .getAttribute(ATTR_JSP_TAGLIBS_MODEL)); } HttpSession session = request.getSession(false); if (session != null) { model.put(KEY_SESSION_MODEL, new HttpSessionHashModel(session, wrapper)); } HttpRequestHashModel requestModel = (HttpRequestHashModel) request .getAttribute(ATTR_REQUEST_MODEL); if ((requestModel == null) || (requestModel.getRequest() != request)) { requestModel = new HttpRequestHashModel(request, response, wrapper); request.setAttribute(ATTR_REQUEST_MODEL, requestModel); } model.put(KEY_REQUEST_MODEL, requestModel); HttpRequestParametersHashModel reqParametersModel = (HttpRequestParametersHashModel) request .getAttribute(ATTR_REQUEST_PARAMETERS_MODEL); if (reqParametersModel == null || requestModel.getRequest() != request) { reqParametersModel = new HttpRequestParametersHashModel(request); request.setAttribute(ATTR_REQUEST_PARAMETERS_MODEL, reqParametersModel); } model.put(KEY_REQUEST_PARAMETER_MODEL, reqParametersModel); Throwable exception = (Throwable) request .getAttribute("javax.servlet.error.exception"); if (exception == null) { exception = (Throwable) request .getAttribute("javax.servlet.error.JspException"); } if (exception != null) { model.put(KEY_EXCEPTION, exception); } } }
6bede2fa5331625584d7536d325c4a9ae857d5b4
c21ddc5a2b1c0358620a2750fe936fdbf2e126f8
/core/src/main/java/com/yztc/core/App.java
0270a837d5d7a5e1a81bf2ea50f8e2d6df4319f5
[]
no_license
Brenda1017/damai
298b2f7905d18a2e606afa851c86578a9e28c804
f6b4d21c60351c8198bf6a3c3c4bafa22c2ebb91
refs/heads/master
2021-01-12T02:46:25.357039
2017-01-03T09:36:27
2017-01-03T09:36:27
null
0
0
null
null
null
null
UTF-8
Java
false
false
5,321
java
package com.yztc.core; import android.app.ActivityManager; import android.app.Application; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.ApplicationInfo; import android.os.Build; import android.support.multidex.MultiDex; import android.text.TextUtils; import com.yztc.core.base.LoadResActivity; import com.yztc.core.image.ImageLoader; import com.yztc.core.manager.ActivityStackManager; import com.yztc.core.manager.DownLoadFileManager; import com.yztc.core.manager.LimitCacheManager; import com.yztc.core.utils.AppUtils; import com.yztc.core.utils.LogUtils; import java.util.Map; import java.util.jar.Attributes; import java.util.jar.JarFile; import java.util.jar.Manifest; /** * Created by wanggang on 2016/12/12. */ public class App extends Application { //App Context //Activity、Service Context //1 全局 //2 生命周期长 private static App context; @Override public void onCreate() { super.onCreate(); if (quickStart()) { return; } context=this; } public static App getContext(){ return context; } //结束 public void onDestory(){ ActivityStackManager.getInstance().onDestory(); ImageLoader.getInstance().onDestroy(); LimitCacheManager.getInstance().onDestroy(); DownLoadFileManager.getInstance().onDestroy(); } public static final String KEY_DEX2_SHA1 = "dex2-SHA1-Digest"; @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); LogUtils.d("loadDex", "App attachBaseContext "); if (!quickStart() && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {//>=5.0的系统默认对dex进行oat优化 if (needWait(base)) { waitForDexopt(base); } MultiDex.install(this); } else { return; } } public boolean quickStart() { if (getCurProcessName(this).contains(":mini")) { LogUtils.d("loadDex", ":mini start!"); return true; } return false; } //neead wait for dexopt ? private boolean needWait(Context context) { String flag = get2thDexSHA1(context); if (TextUtils.isEmpty(flag)) { return false; } LogUtils.d("loadDex", "dex2-sha1 " + flag); SharedPreferences sp = context.getSharedPreferences( AppUtils.getPackageInfo(context).versionName, MODE_MULTI_PROCESS); String saveValue = sp.getString(KEY_DEX2_SHA1, ""); return !flag.equals(saveValue); } /** * Get classes.dex file signature * * @param context * @return */ private String get2thDexSHA1(Context context) { ApplicationInfo ai = context.getApplicationInfo(); String source = ai.sourceDir; try { JarFile jar = new JarFile(source); Manifest mf = jar.getManifest(); Map<String, Attributes> map = mf.getEntries(); Attributes a = map.get("classes2.dex"); return a.getValue("SHA1-Digest"); } catch (Exception e) { e.printStackTrace(); } return null; } // optDex finish public void installFinish(Context context) { SharedPreferences sp = context.getSharedPreferences( AppUtils.getPackageInfo(context).versionName, MODE_MULTI_PROCESS); sp.edit().putString(KEY_DEX2_SHA1, get2thDexSHA1(context)).apply(); } public static String getCurProcessName(Context context) { try { int pid = android.os.Process.myPid(); ActivityManager mActivityManager = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningAppProcessInfo appProcess : mActivityManager .getRunningAppProcesses()) { if (appProcess.pid == pid) { return appProcess.processName; } } } catch (Exception e) { // ignore } return null; } public void waitForDexopt(Context base) { Intent intent = new Intent(); ComponentName componentName = new ComponentName("com.yztc.core.base", LoadResActivity.class.getName()); intent.setComponent(componentName); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); base.startActivity(intent); long startWait = System.currentTimeMillis(); long waitTime = 10 * 1000; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1) { waitTime = 20 * 1000;//实测发现某些场景下有些2.3版本有可能10s都不能完成optdex } while (needWait(base)) { try { long nowWait = System.currentTimeMillis() - startWait; LogUtils.d("loadDex", "wait ms :" + nowWait); if (nowWait >= waitTime) { return; } Thread.sleep(200); } catch (InterruptedException e) { e.printStackTrace(); } } } }
bda2570bc8ce6c3c125723b8ebc9e43b38be9ba6
64ff683b3ae65daf5b30ceb0a71b94315c42f6ab
/Ficheros/Relación Ficheros 3/src/com/company/Main.java
c42bfb6898b3e8935b47f0b46b46a95160b54d59
[]
no_license
beltenebror/Java-exercises
93770f4f7b6c1debb11f97d755afad90040b79f5
c1ed2f83d7bb19015009208edbbdf3c6f3e9ec32
refs/heads/main
2023-02-22T00:21:11.092224
2021-01-25T17:37:36
2021-01-25T17:37:36
332,827,714
0
0
null
null
null
null
UTF-8
Java
false
false
13,214
java
package com.company; import javax.xml.crypto.Data; import java.io.*; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { int opcion=-1; List<FichaAlumno> listaAlumnos = new ArrayList<FichaAlumno>(); while(opcion!=0) { Scanner sc = new Scanner(System.in); System.out.println("Menú"); System.out.println(); System.out.println("1. Ejercicio 1"); System.out.println("2. Ejercicio 2"); System.out.println("3. Ejercicio 3"); System.out.println("4. Ejercicio 4"); System.out.println("5. Ejercicio 5"); System.out.println("6. Ejercicio 6"); System.out.println("7. Ejercicio 7"); System.out.println("8. Ejercicio 8"); System.out.println(); System.out.print("Elige una opción, 0 para salir: "); opcion = sc.nextInt(); sc.nextLine(); switch (opcion) { case 1: { //Escribe una función leeAlumnoLista a la que le pasas la lista de alumnos y te pide un //nuevo alumno desde el teclado, cuyos datos se añadirán a la lista. leeAlumnoLista(listaAlumnos); } break; case 2: { //Escribe una función imprimeListaAlumnos a la que la pasas la lista de alumnos y te la //imprime por pantalla. imprimeListaAlumnos(listaAlumnos); } break; case 3: { //Escribe una función escribeFicheroAlumnosBinario a la que le pasas la lista y el //nombre del fichero y te escribe la lista en el fichero. La estructura del fichero será la //siguiente: //- Al principio habrá un entero que será el número de alumnos que hay en la //lista. //- Después irán los registros, escribiéndose un String para el nombre, un int //para la edad y un double para la nota. //- Iremos escribiendo todos los registros uno a uno hasta el final escribeFicheroAlumnosBinario(listaAlumnos,"alumnos.bin"); } break; case 4: { //Escribe una función leeFicheroAlumnosBinario a la que le pasas una lista y el nombre //del fichero y leerá la lista desde el fichero. El fichero tendrá la misma estructura que el //del ejercicio anterior (evidentemente). La lista que nos pasen la borraremos antes de //leer los datos del fichero. //Para poder meter el alumno en la lista primero tendremos que crear un registro de //tipo FichaAlumno: //FichaAlumno fa = new FichaAlumno(); //Guardaremos los tres valores que hemos leído en el registro y lo añadiremos a la lista leeFicheroAlumnosBinario("alumnos.bin",listaAlumnos); } break; case 5: { //Escribe la función escribeFicheroAlumnosTexto similar a la función del ejercicio 3 pero //usando un fichero de texto. La estructura del fichero será similar, pero ahora //guardaremos un valor en cada línea. Ejemplo: //2 //Pedro //23 //7,2 //Juan //15 //2,1 escribeFicheroAlumnosTexto(listaAlumnos,"alumnos.txt"); } break; case 6: { //Escribe la función leeFicheroAlumnosTexto similar a la función del ejercicio 4 pero que //funciona con los ficheros de texto del ejercicio anterior. leeFicheroAlumnosTexto("alumnos.txt",listaAlumnos); } break; case 7: { //Los ficheros CSV (Comma Separated Values) (Valores Separados por Comas) son la //forma más simple de guardar una tabla de una base de datos. Cada registro va en una línea y //los valores de cada registro van separados por comas u otro valor de separación (por ejemplo, //punto y coma). //7. Escribe la función escribeFicheroAlumnosCSV. En este caso, no vamos a guardar el //número de registros en la primera línea, ya que los ficheros CSV estándar no lo hacen. //Como carácter separador usaremos el punto y coma, ya que uno de los datos que //usamos ya contiene comas. //Un ejemplo del fichero sería: //Pedro;23;7,2 //Juan;15;2,1 escribeFicheroAlumnosCSV(listaAlumnos,"alumnos.csv"); } break; case 8: { //Escribe la función leeFicheroAlumnosCSV que lee los datos del fichero anterior en una //lista. Para separar los datos, lo más fácil es usar la función Split de las cadenas. Con //esto conseguiremos un array de cadenas compuesto por tres cadenas: “Nombre”, //“Edad”, “Calificación”, que tendremos que convertir al tipo de dato adecuado y meter //en un registro FichaAlumno y luego en la lista. leeFicheroAlumnosCSV("alumnos.csv",listaAlumnos); } break; default: System.out.println("Ese ejercicio no existe"); } } } public static void leeFicheroAlumnosCSV(String s, List<FichaAlumno> listaAlumnos) { listaAlumnos.clear(); String linea; String [] lineaAlumno; int i; try { FileReader fr = new FileReader(s); BufferedReader br = new BufferedReader(fr); linea=br.readLine(); while(linea!=null) { lineaAlumno=linea.split(";"); FichaAlumno fa = new FichaAlumno(); fa.nombre=lineaAlumno[0]; fa.edad=Integer.valueOf(lineaAlumno[1]); fa.calificacion=Double.valueOf(lineaAlumno[2]); listaAlumnos.add(fa); linea=br.readLine(); } br.close(); fr.close(); } catch(IOException e) { e.printStackTrace(); } } public static void escribeFicheroAlumnosCSV(List<FichaAlumno> listaAlumnos, String nombre) { try { FileWriter fw = new FileWriter(nombre); BufferedWriter bw = new BufferedWriter(fw); for(int i=0;i<listaAlumnos.size();i++) { bw.write(listaAlumnos.get(i).nombre +";"); bw.write(listaAlumnos.get(i).edad + ";"); bw.write(String.valueOf(listaAlumnos.get(i).calificacion)+ System.lineSeparator()); } bw.close(); fw.close(); } catch (IOException e) { e.printStackTrace(); } } public static void leeFicheroAlumnosTexto(String s, List<FichaAlumno> listaAlumnos) { listaAlumnos.clear(); try { FileReader fr = new FileReader(s); BufferedReader br = new BufferedReader(fr); int numeroAlumnos=Integer.valueOf(br.readLine()); for(int i=0;i<numeroAlumnos;i++) { FichaAlumno fa = new FichaAlumno(); fa.nombre=br.readLine(); fa.edad=Integer.valueOf(br.readLine()); fa.calificacion=Double.valueOf(br.readLine()); listaAlumnos.add(fa); } br.close(); fr.close(); } catch (IOException e) { e.printStackTrace(); } } public static void escribeFicheroAlumnosTexto(List<FichaAlumno> listaAlumnos, String nombre) { try { FileWriter fw = new FileWriter(nombre); BufferedWriter bw = new BufferedWriter(fw); bw.write(listaAlumnos.size() + System.lineSeparator()); for(int i=0;i<listaAlumnos.size();i++) { bw.write(listaAlumnos.get(i).nombre + System.lineSeparator()); bw.write(listaAlumnos.get(i).edad + System.lineSeparator()); bw.write(String.valueOf(listaAlumnos.get(i).calificacion)+ System.lineSeparator()); } bw.close(); fw.close(); } catch (IOException e) { e.printStackTrace(); } } public static void leeFicheroAlumnosBinario(String s, List<FichaAlumno> listaAlumnos) { listaAlumnos.clear(); try { FileInputStream fis = new FileInputStream(s); DataInputStream dis = new DataInputStream(fis); int numeroAlumnos=dis.readInt(); for(int i=0;i<numeroAlumnos;i++) { FichaAlumno fa = new FichaAlumno(); fa.nombre=dis.readUTF(); fa.edad=dis.readInt(); fa.calificacion=dis.readDouble(); listaAlumnos.add(fa); } dis.close(); fis.close(); } catch (IOException e) { e.printStackTrace(); } } public static void escribeFicheroAlumnosBinario(List<FichaAlumno> listaAlumnos, String s) { int numeroAlumnos=listaAlumnos.size(); try { FileOutputStream fos = new FileOutputStream(s); DataOutputStream dos = new DataOutputStream(fos); dos.writeInt(numeroAlumnos); for(int i=0;i<numeroAlumnos;i++) { dos.writeUTF(listaAlumnos.get(i).nombre); dos.writeInt(listaAlumnos.get(i).edad); dos.writeDouble(listaAlumnos.get(i).calificacion); } dos.close(); fos.close(); } catch (IOException e) { e.printStackTrace(); } } public static void imprimeListaAlumnos(List<FichaAlumno> listaAlumnos) { System.out.println(); int i,j; for(j=0;j<82;j++) { System.out.print("-"); } System.out.println(); String nombre="Nombre:"; String edad="Edad:"; String calificacin="Calificación:"; nombre=padRight(nombre,50); edad=padRight(edad,10); calificacin= padRight(calificacin,15); System.out.println("| " + nombre+"| " + edad + "| " + calificacin+ "|"); //la for(i=0;i<82;i++) //primera { System.out.print("-"); //linea } System.out.println(); //raya separadora for(i=0;i<listaAlumnos.size();i++) //añade cada alumno { nombre=listaAlumnos.get(i).nombre; nombre=padRight(nombre,50); edad=String.valueOf(listaAlumnos.get(i).edad); edad=padRight(edad,10); calificacin=String.valueOf(listaAlumnos.get(i).calificacion); calificacin=padRight(calificacin,15); System.out.println("| " + nombre+"| " + edad + "| " + calificacin+ "|"); for(j=0;j<82;j++) { System.out.print("-"); } System.out.println(); } System.out.println(); } public static void leeAlumnoLista(List<FichaAlumno> listaAlumnos) { Scanner sc = new Scanner(System.in); FichaAlumno fa = new FichaAlumno(); System.out.println("Nombre:"); fa.nombre=sc.nextLine(); System.out.println("Edad:"); fa.edad=sc.nextInt(); System.out.println("Calificación:"); fa.calificacion=sc.nextDouble(); listaAlumnos.add(fa); } public static String padLeft(String a, int longitud) { int numeroespacios=longitud-a.length(); for(int i=0; i<numeroespacios; i++) { a= ' ' + a ; } return a; } public static String padRight(String a, int longitud) { int numeroespacios=longitud-a.length(); for(int i=0; i<numeroespacios; i++) { a= a + ' '; } return a; } }
0e43bc89bb2e3db978ee873f9e256132424b75a8
ab93497aad6018484cf8e31ad08c0910435761f5
/src/workbench/gui/dbobjects/TableDefinitionPanel.java
ab522dbd2e1f1fbf15950cb8218465445a446336
[]
no_license
anieruddha/sqlworkbench
33ca0289d4bb5e613853f74e9a96e5dc3900c717
058a44b0de0194732f68c52cc0815a9b27ec57e3
refs/heads/master
2020-08-05T21:05:16.706354
2019-10-06T01:32:18
2019-10-06T01:32:18
212,709,628
2
1
null
null
null
null
UTF-8
Java
false
false
21,319
java
/* * TableDefinitionPanel.java * * This file is part of SQL Workbench/J, https://www.sql-workbench.eu * * Copyright 2002-2019, Thomas Kellerer * * Licensed under a modified Apache License, Version 2.0 * that restricts the use for certain governments. * You may not use this file except in compliance with the License. * You may obtain a copy of the License at. * * https://www.sql-workbench.eu/manual/license.html * * 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. * * To contact the author please send an email to: [email protected] * */ package workbench.gui.dbobjects; import java.awt.BorderLayout; import java.awt.Component; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.sql.SQLException; import java.util.ArrayList; import java.util.Collections; import java.util.List; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import javax.swing.table.TableColumn; import javax.swing.table.TableColumnModel; import javax.swing.table.TableModel; import workbench.interfaces.DbData; import workbench.interfaces.IndexChangeListener; import workbench.interfaces.Resettable; import workbench.log.LogMgr; import workbench.resource.DbExplorerSettings; import workbench.resource.GuiSettings; import workbench.resource.ResourceMgr; import workbench.resource.Settings; import workbench.db.ColumnDropper; import workbench.db.ColumnIdentifier; import workbench.db.DbMetadata; import workbench.db.DbObject; import workbench.db.TableColumnsDatastore; import workbench.db.TableDefinition; import workbench.db.TableIdentifier; import workbench.db.WbConnection; import workbench.gui.WbSwingUtilities; import workbench.gui.actions.ColumnAlterAction; import workbench.gui.actions.CreateDummySqlAction; import workbench.gui.actions.CreateIndexAction; import workbench.gui.actions.CreatePKAction; import workbench.gui.actions.DeleteRowAction; import workbench.gui.actions.DropDbObjectAction; import workbench.gui.actions.DropPKAction; import workbench.gui.actions.InsertRowAction; import workbench.gui.actions.ReloadAction; import workbench.gui.actions.WbAction; import workbench.gui.components.DataStoreTableModel; import workbench.gui.components.EmptyTableModel; import workbench.gui.components.FlatButton; import workbench.gui.components.QuickFilterPanel; import workbench.gui.components.WbLabelField; import workbench.gui.components.WbScrollPane; import workbench.gui.components.WbTable; import workbench.gui.components.WbTraversalPolicy; import workbench.gui.renderer.RendererSetup; import workbench.gui.renderer.SqlTypeRenderer; import workbench.storage.DataStore; import workbench.sql.wbcommands.ObjectInfo; import workbench.util.ExceptionUtil; import workbench.util.StringUtil; import workbench.util.WbThread; /** * A panel to display the table definition information inside the DbExplorer. * * @see workbench.db.DbMetadata#getTableDefinition(TableIdentifier) * * @author Thomas Kellerer */ public class TableDefinitionPanel extends JPanel implements PropertyChangeListener, ListSelectionListener, Resettable, DbObjectList, IndexChangeListener { public static final String INDEX_PROP = "index"; public static final String DEFINITION_PROP = "tableDefinition"; private final Object connectionLock = new Object(); private final Object busyLock = new Object(); private WbTable tableDefinition; private WbLabelField tableNameLabel; private QuickFilterPanel columnFilter; private CreateIndexAction createIndexAction; private CreatePKAction createPKAction; private DropPKAction dropPKAction; private ColumnAlterAction alterColumnsAction; private TableIdentifier currentTable; private InsertRowAction addColumn; private DeleteRowAction deleteColumn; private WbConnection dbConnection; private WbAction reloadAction; private DropDbObjectAction dropColumnsAction; private JPanel toolbar; private boolean busy; private FlatButton alterButton; private ColumnChangeValidator validator = new ColumnChangeValidator(); private boolean doRestore; private boolean initialized; public TableDefinitionPanel() { super(); } private void initGui() { if (initialized) return; WbSwingUtilities.invoke(this::_initGui); } private void _initGui() { if (initialized) return; this.tableDefinition = new WbTable(true, false, false); this.tableDefinition.setAdjustToColumnLabel(false); this.tableDefinition.setSelectOnRightButtonClick(true); this.tableDefinition.getExportAction().setEnabled(true); this.tableDefinition.setRendererSetup(RendererSetup.getBaseSetup()); updateReadOnlyState(); Settings.getInstance().addPropertyChangeListener(this, DbExplorerSettings.PROP_ALLOW_ALTER_TABLE); this.reloadAction = new ReloadAction(this); this.reloadAction.setEnabled(false); this.reloadAction.addToInputMap(this.tableDefinition); toolbar = new JPanel(new GridBagLayout()); alterColumnsAction = new ColumnAlterAction(tableDefinition); alterColumnsAction.setReloader(this); columnFilter = new QuickFilterPanel(this.tableDefinition, true, "columnlist"); // Setting the column list now, ensures that the dropdown will be displayed (=sized) // properly in the QuickFilterPanel, although it wouldn't be necessary // as the column list will be updated automatically when the model of the table changes columnFilter.setColumnList(TableColumnsDatastore.TABLE_DEFINITION_COLS); columnFilter.setFilterOnType(DbExplorerSettings.getFilterDuringTyping()); columnFilter.setAlwaysUseContainsFilter(DbExplorerSettings.getUsePartialMatch()); DbData db = new DbData() { @Override public int addRow() { return tableDefinition.addRow(); } @Override public void deleteRow() { tableDefinition.deleteRow(); } @Override public void deleteRowWithDependencies() { } @Override public boolean startEdit() { return true; } @Override public int duplicateRow() { return -1; } @Override public void endEdit() { } }; addColumn = new InsertRowAction(db); addColumn.initMenuDefinition("MnuTxtAddCol"); deleteColumn = new DeleteRowAction(db); deleteColumn.initMenuDefinition("MnuTxtDropColumn"); columnFilter.addToToolbar(addColumn, true, true); columnFilter.addToToolbar(deleteColumn, 1); columnFilter.addToToolbar(reloadAction, 0); GridBagConstraints cc = new GridBagConstraints(); cc.anchor = GridBagConstraints.LINE_START; cc.fill = GridBagConstraints.NONE; cc.gridx = 0; cc.weightx = 0.0; cc.weighty = 0.0; cc.ipadx = 0; cc.ipady = 0; cc.insets = new Insets(0, 0, 0, 5); toolbar.add(columnFilter, cc); JLabel l = new JLabel(ResourceMgr.getString("LblTable") + ":"); cc.fill = GridBagConstraints.NONE; cc.gridx ++; cc.weightx = 0.0; cc.insets = new Insets(0, 5, 0, 0); toolbar.add(l, cc); tableNameLabel = new WbLabelField(); tableNameLabel.useBoldFont(); cc.fill = GridBagConstraints.HORIZONTAL; cc.gridx ++; cc.weightx = 1.0; cc.insets = WbSwingUtilities.getEmptyInsets(); toolbar.add(tableNameLabel, cc); cc.fill = GridBagConstraints.HORIZONTAL; cc.gridx ++; cc.weightx = 0; cc.fill = GridBagConstraints.NONE; cc.anchor = GridBagConstraints.EAST; cc.insets = new Insets(0, 15, 0, 0); alterButton = new FlatButton(alterColumnsAction); alterButton.showMessageOnEnable("MsgApplyDDLHint"); alterButton.setIcon(null); alterButton.setUseDefaultMargin(false); toolbar.add(alterButton, cc); WbScrollPane scroll = new WbScrollPane(this.tableDefinition); this.setLayout(new BorderLayout()); this.add(toolbar, BorderLayout.NORTH); this.add(scroll, BorderLayout.CENTER); createIndexAction = new CreateIndexAction(this, this); createPKAction = new CreatePKAction(this); dropPKAction = new DropPKAction(this); tableDefinition.addPopupAction(CreateDummySqlAction.createDummyInsertAction(this, tableDefinition.getSelectionModel()), true); tableDefinition.addPopupAction(CreateDummySqlAction.createDummyUpdateAction(this, tableDefinition.getSelectionModel()), false); tableDefinition.addPopupAction(CreateDummySqlAction.createDummySelectAction(this, tableDefinition.getSelectionModel()), false); tableDefinition.getSelectionModel().addListSelectionListener(this); tableDefinition.addPopupAction(this.createPKAction, true); tableDefinition.addPopupAction(this.dropPKAction, false); tableDefinition.addPopupAction(this.createIndexAction, false); WbTraversalPolicy policy = new WbTraversalPolicy(); policy.addComponent(tableDefinition); policy.setDefaultComponent(tableDefinition); setFocusCycleRoot(false); setFocusTraversalPolicy(policy); if (DbExplorerSettings.showFocusInDbExplorer()) { tableDefinition.showFocusBorder(); } if (doRestore) { restoreSettings(); } initialized = true; } protected void fireTableDefinitionChanged() { firePropertyChange(DEFINITION_PROP, null, this.currentTable.getTableName()); } @Override public void indexChanged(TableIdentifier table, String indexName) { firePropertyChange(INDEX_PROP, null, indexName); } public boolean isBusy() { synchronized (this.busyLock) { return busy; } } private void setBusy(boolean flag) { synchronized (this.busyLock) { busy = flag; } } public void dispose() { if (tableDefinition != null) tableDefinition.dispose(); if (columnFilter != null) columnFilter.dispose(); WbAction.dispose( this.addColumn,this.deleteColumn,this.reloadAction,this.alterColumnsAction,this.createIndexAction, this.createPKAction,this.dropColumnsAction,this.dropPKAction ); Settings.getInstance().removePropertyChangeListener(this); WbSwingUtilities.removeAllListeners(this); } /** * Retrieve the definition of the given table. */ public void retrieve(TableIdentifier table) throws SQLException { this.currentTable = table; initGui(); retrieveTableDefinition(); } protected void retrieveTableDefinition() throws SQLException { if (this.isBusy()) return; synchronized (connectionLock) { if (currentTable == null) return; try { WbSwingUtilities.invoke(() -> { tableDefinition.reset(); reloadAction.setEnabled(false); String msg = " " + ResourceMgr.getString("TxtRetrieveTableDef") + " " + currentTable.getTableName(); tableNameLabel.setText(msg); }); DbMetadata meta = this.dbConnection.getMetadata(); DataStore def = null; if (dbConnection.getDbSettings().isSynonymType(currentTable.getType()) && !GuiSettings.showSynonymTargetInDbExplorer()) { def = ObjectInfo.getPlainSynonymInfo(dbConnection, currentTable); } else { def = meta.getObjectDetails(currentTable); } final TableModel model = def == null ? EmptyTableModel.EMPTY_MODEL : new DataStoreTableModel(def) ; if (def instanceof TableColumnsDatastore) { DataStoreTableModel dsModel = (DataStoreTableModel)model; // Make sure some columns are not modified by the user // to avoid the impression that e.g. the column's position // can be changed by editing that column dsModel.setValidator(validator); int typeIndex = dsModel.findColumn(TableColumnsDatastore.JAVA_SQL_TYPE_COL_NAME); int posIndex = dsModel.findColumn("POSITION"); int pkIndex = dsModel.findColumn("PK"); dsModel.setNonEditableColums(typeIndex, posIndex, pkIndex); if (meta.isTableType(currentTable.getType()) || meta.isViewType(currentTable.getType())) { List<ColumnIdentifier> cols = TableColumnsDatastore.createColumnIdentifiers(meta, def); TableDefinition tbl = new TableDefinition(currentTable, cols); dbConnection.getObjectCache().addTable(tbl); } } alterButton.setVisible(dbConnection.getDbSettings().columnCommentAllowed(currentTable.getType())); WbSwingUtilities.invoke(() -> { applyTableModel(model); tableDefinition.adjustColumns(); }); alterColumnsAction.setSourceTable(dbConnection, currentTable); alterColumnsAction.setEnabled(false); boolean canAddColumn = dbConnection.getDbSettings().getAddColumnSql() != null && DbExplorerSettings.allowAlterInDbExplorer(); addColumn.setEnabled(canAddColumn && isTable()); } catch (SQLException e) { tableNameLabel.setText(ExceptionUtil.getDisplay(e)); throw e; } finally { reloadAction.setEnabled(true); setBusy(false); } } } protected void applyTableModel(TableModel model) { tableDefinition.setPrintHeader(this.currentTable.getTableName()); tableDefinition.setAutoCreateColumnsFromModel(true); tableDefinition.setModel(model, true); TableIdentifier displayTable = currentTable; if (model instanceof DataStoreTableModel) { DataStore ds = ((DataStoreTableModel)model).getDataStore(); if (ds instanceof TableColumnsDatastore) { TableIdentifier realTbl = ((TableColumnsDatastore)ds).getSourceTable(); if (realTbl != null) { displayTable = realTbl; } } } String displayName; if (DbExplorerSettings.getDbExplorerTableDetailFullyQualified()) { displayName = displayTable.getFullyQualifiedName(dbConnection); } else { displayName = displayTable.getTableExpression(dbConnection); } if (model instanceof EmptyTableModel) { tableNameLabel.setText(""); } else { tableNameLabel.setText(displayName); } TableColumnModel colmod = tableDefinition.getColumnModel(); // Assign the correct renderer to display java.sql.Types values // should only appear for table definitions try { int typeIndex = colmod.getColumnIndex(TableColumnsDatastore.JAVA_SQL_TYPE_COL_NAME); TableColumn col = colmod.getColumn(typeIndex); col.setCellRenderer(new SqlTypeRenderer()); } catch (IllegalArgumentException e) { // The IllegalArgumentException will be thrown by getColumnIndex() // rather than returning a -1 as other methods do. // If the Types column is not present, we can simply return as the // other columns will then not be there as well. return; } // hide the the columns "SCALE/SIZE", "PRECISION" // they don't need to be displayed as this is "included" in the // displayed (DBMS) data type already // Columns may not be removed from the underlying DataStore because // that is also used to retrieve the table source and DbMetadata // relies on all columns being present when that datastore is passed // to getTableSource() // So we need to remove those columns from the view String[] columns = new String[] { "SCALE/SIZE", "PRECISION" }; for (String name : columns) { try { int index = colmod.getColumnIndex(name); TableColumn col = colmod.getColumn(index); colmod.removeColumn(col); } catch (IllegalArgumentException e) { // ignore, this is expected for some table types } } } @Override public void reset() { if (!initialized) return; currentTable = null; tableDefinition.reset(); reloadAction.setEnabled(false); } private DropDbObjectAction getDropColumnAction() { if (this.dropColumnsAction == null) { dropColumnsAction = new DropDbObjectAction("MnuTxtDropColumn", this, tableDefinition.getSelectionModel(), this); dropColumnsAction.setDropper(new ColumnDropper()); } return dropColumnsAction; } public void setConnection(WbConnection conn) { initGui(); this.dbConnection = conn; this.createIndexAction.setConnection(dbConnection); this.reloadAction.setEnabled(dbConnection != null); validator.setConnection(dbConnection); if (dbConnection != null && dbConnection.getDbSettings().canDropType("column")) { DropDbObjectAction action = getDropColumnAction(); action.setAvailable(true); this.tableDefinition.addPopupAction(action, false); } else if (this.dropColumnsAction != null) { dropColumnsAction.setAvailable(false); } addColumn.setEnabled(false); } /** * Implement the Reloadable interface for the reload action. * This method should not be called directly, use {@link #retrieve(workbench.db.TableIdentifier) } * instead. */ @Override public void reload() { if (this.currentTable == null) return; if (this.dbConnection == null) return; initGui(); WbThread t = new WbThread("TableDefinition Retrieve") { @Override public void run() { try { retrieveTableDefinition(); fireTableDefinitionChanged(); } catch (SQLException ex) { LogMgr.logError("TableDefinitionPanel.reload()", "Error loading table definition", ex); } } }; t.start(); } @Override public List<TableIdentifier> getSelectedTables() { return Collections.emptyList(); } @Override public List<DbObject> getSelectedObjects() { if (this.tableDefinition.getSelectedRowCount() <= 0) return null; int[] rows = this.tableDefinition.getSelectedRows(); List<DbObject> columns = new ArrayList<>(rows.length); for (int i=0; i < rows.length; i++) { String column = this.tableDefinition.getValueAsString(rows[i], TableColumnsDatastore.COLUMN_IDX_TABLE_DEFINITION_COL_NAME); // the column name can be empty if a new column has just been inserted in the definition display if (StringUtil.isNonBlank(column)) { columns.add(new ColumnIdentifier(column)); } } return columns; } @Override public Component getComponent() { return this; } @Override public WbConnection getConnection() { return this.dbConnection; } @Override public TableIdentifier getObjectTable() { return this.currentTable; } @Override public int getSelectionCount() { return tableDefinition.getSelectedRowCount(); } @Override public TableDefinition getCurrentTableDefinition() { return null; } protected boolean isTable() { if (currentTable == null) return false; if (dbConnection == null) return false; String type = currentTable.getType(); return dbConnection.getMetadata().isExtendedTableType(type); } protected boolean isMview() { if (currentTable == null) return false; if (dbConnection == null) return false; String type = currentTable.getType(); return dbConnection.getDbSettings().isMview(type); } protected boolean hasIndex() { if (currentTable == null) return false; if (dbConnection == null) return false; if (isTable()) return true; if (isMview()) return true; String type = currentTable.getType(); return dbConnection.getMetadata().isViewType(type) && dbConnection.getDbSettings().supportsIndexedViews(); } protected boolean hasPkColumn() { if (!isTable()) return false; for (int row = 0; row < this.tableDefinition.getRowCount(); row++) { String flag = tableDefinition.getValueAsString(row, TableColumnsDatastore.COLUMN_IDX_TABLE_DEFINITION_PK_FLAG); boolean isPk = StringUtil.stringToBool(flag); if (isPk) return true; } return false; } /** * Invoked when the selection in the table list has changed */ @Override public void valueChanged(ListSelectionEvent e) { if (!initialized) return; if (e.getValueIsAdjusting()) return; if (e.getSource() == this.tableDefinition.getSelectionModel()) { boolean rowsSelected = (this.tableDefinition.getSelectedRowCount() > 0); boolean isTable = isTable(); boolean isMview = isMview(); boolean hasPk = hasPkColumn(); createPKAction.setEnabled(rowsSelected && isTable && !hasPk); dropPKAction.setEnabled(isTable && hasPk); createIndexAction.setEnabled(rowsSelected && hasIndex()); deleteColumn.setEnabled(rowsSelected && (isTable || isMview) && DbExplorerSettings.allowAlterInDbExplorer()); } } public List<ColumnIdentifier> getColumns() { return TableColumnsDatastore.createColumnIdentifiers(this.dbConnection.getMetadata(), this.tableDefinition.getDataStore()); } public int getRowCount() { if (tableDefinition == null) return 0; return this.tableDefinition.getRowCount(); } public DataStore getDataStore() { if (tableDefinition == null) return null; return this.tableDefinition.getDataStore(); } public void restoreSettings() { if (columnFilter != null) { this.columnFilter.restoreSettings(); doRestore = false; } else { doRestore = true; } } public void saveSettings() { if (columnFilter != null) { this.columnFilter.saveSettings(); doRestore = false; } else { doRestore = true; } } private void updateReadOnlyState() { tableDefinition.setReadOnly(!DbExplorerSettings.allowAlterInDbExplorer()); tableDefinition.setAllowEditMode(true); } @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals(DbExplorerSettings.PROP_ALLOW_ALTER_TABLE)) { updateReadOnlyState(); } } }
4d2e8794d22c8aa76230b8670214857a783733ea
98d696b424083b435db6385af41b62882a977ad8
/src/simpleGa/JApplet1.java
db016112b3e83280f466715508fae6c20ddf27bc
[]
no_license
ysharma17/GeneticAlgoTool
23507baa8fc2bfa621dc60d48ff769992e2cf2b0
9a747fb10a1f9421537ed3ccd39a0b418cf76ba6
refs/heads/master
2021-01-09T21:48:12.134305
2016-03-15T21:08:33
2016-03-15T21:08:33
53,977,942
0
0
null
null
null
null
UTF-8
Java
false
false
35,110
java
package simpleGa; import java.applet.Applet; import java.applet.AppletStub; import java.awt.Color; import java.awt.Container; import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JOptionPane; import org.openide.util.Exceptions; import simpleGa.Algorithm.*; import simpleGa.FitnessCalc.*; import simpleGa.GA.*; import simpleGa.Individual.*; import simpleGa.Population.*; /** * * @author NEHA */ public class JApplet1 extends javax.swing.JApplet { private Container con=getContentPane(); private JButton button=new JButton ("Button"); private JButton button1=new JButton ("Button1"); private JButton button2=new JButton ("Button2"); private JButton button3=new JButton ("Button3"); private JButton button4=new JButton ("Button4"); ImageIcon icon=new ImageIcon("C:\\Users\\ADMIN\\Documents\\NetBeansProjects\\geneticAlgoDemo\\build\\classes\\images\\DNA.png"); // ImageIcon icon=new ImageIcon("C:\\Users\\ADMIN\\Documents\\NetBeansProjects\\geneticAlgoDemo\\build\\classes\\images\\red and purple animated button.jpg"); ImageIcon icon1=new ImageIcon("C:\\Users\\ADMIN\\Documents\\NetBeansProjects\\geneticAlgoDemo\\build\\classes\\images\\Ind2.png");; ImageIcon icon2=new ImageIcon("C:\\Users\\ADMIN\\Documents\\NetBeansProjects\\geneticAlgoDemo\\build\\classes\\images\\crossover.png"); ImageIcon icon4=new ImageIcon("C:\\Users\\ADMIN\\Documents\\NetBeansProjects\\geneticAlgoDemo\\build\\classes\\images\\red and purple animated button.jpg"); ImageIcon icon3=new ImageIcon("C:\\Users\\ADMIN\\Documents\\NetBeansProjects\\geneticAlgoDemo\\build\\classes\\images\\Ind1.png"); static int a,c; static double b,d; static String sol; int check; double param1; int param2; double param3; String param4="incorrect"; int allSet=0; @Override public void init() { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(JApplet1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(JApplet1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(JApplet1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(JApplet1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the applet */ try { java.awt.EventQueue.invokeAndWait(new Runnable() { public void run() { initComponents(); } }); } catch (Exception ex) { ex.printStackTrace(); } } @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new javax.swing.JLabel(); jTextField1 = new javax.swing.JTextField(); jPanel1 = new javax.swing.JPanel(); InitializeButton = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); CrossoverTextbox = new javax.swing.JTextField(); TourSizeTextbox = new javax.swing.JTextField(); MutationTextbox = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); SelectionButton = new javax.swing.JButton(); CrossoverButton = new javax.swing.JButton(); LookSolutionButton = new javax.swing.JButton(); jPanel2 = new javax.swing.JPanel(); jPanel3 = new javax.swing.JPanel(); jLabel6 = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); geneSrquenceTextbox = new javax.swing.JTextField(); SetParameterButton = new javax.swing.JButton(); jLabel8 = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); jPanel4 = new javax.swing.JPanel(); MutationButton = new javax.swing.JButton(); jLabel10 = new javax.swing.JLabel(); jLabel11 = new javax.swing.JLabel(); setBackground(new java.awt.Color(240, 240, 240)); setFont(new java.awt.Font("Times New Roman", 3, 12)); // NOI18N setForeground(new java.awt.Color(255, 204, 204)); getContentPane().setLayout(null); jLabel1.setForeground(new java.awt.Color(102, 102, 255)); jLabel1.setText(org.openide.util.NbBundle.getMessage(JApplet1.class, "JApplet1.jLabel1.text")); // NOI18N getContentPane().add(jLabel1); jLabel1.setBounds(0, 34, 230, 29); jTextField1.setText(org.openide.util.NbBundle.getMessage(JApplet1.class, "JApplet1.jTextField1.text")); // NOI18N jTextField1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jTextField1MouseClicked(evt); } public void mouseExited(java.awt.event.MouseEvent evt) { jTextField1MouseExited(evt); } }); getContentPane().add(jTextField1); jTextField1.setBounds(240, 30, 86, 29); jPanel1.setAutoscrolls(true); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 470, Short.MAX_VALUE) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 590, Short.MAX_VALUE) ); getContentPane().add(jPanel1); jPanel1.setBounds(0, 75, 470, 590); InitializeButton.setBackground(new java.awt.Color(204, 204, 255)); InitializeButton.setForeground(new java.awt.Color(102, 102, 255)); InitializeButton.setText(org.openide.util.NbBundle.getMessage(JApplet1.class, "JApplet1.InitializeButton.text")); // NOI18N InitializeButton.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { InitializeButtonMouseClicked(evt); } }); InitializeButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { InitializeButtonActionPerformed(evt); } }); getContentPane().add(InitializeButton); InitializeButton.setBounds(340, 20, 170, 50); jLabel2.setForeground(new java.awt.Color(102, 102, 255)); jLabel2.setText(org.openide.util.NbBundle.getMessage(JApplet1.class, "JApplet1.jLabel2.text")); // NOI18N getContentPane().add(jLabel2); jLabel2.setBounds(530, 20, 110, 29); jLabel3.setForeground(new java.awt.Color(102, 102, 255)); jLabel3.setText(org.openide.util.NbBundle.getMessage(JApplet1.class, "JApplet1.jLabel3.text")); // NOI18N getContentPane().add(jLabel3); jLabel3.setBounds(530, 60, 140, 29); jLabel4.setForeground(new java.awt.Color(102, 102, 255)); jLabel4.setText(org.openide.util.NbBundle.getMessage(JApplet1.class, "JApplet1.jLabel4.text")); // NOI18N getContentPane().add(jLabel4); jLabel4.setBounds(530, 90, 130, 35); CrossoverTextbox.setText(org.openide.util.NbBundle.getMessage(JApplet1.class, "JApplet1.CrossoverTextbox.text")); // NOI18N CrossoverTextbox.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { CrossoverTextboxMouseClicked(evt); } public void mouseExited(java.awt.event.MouseEvent evt) { CrossoverTextboxMouseExited(evt); } }); getContentPane().add(CrossoverTextbox); CrossoverTextbox.setBounds(670, 20, 77, 29); TourSizeTextbox.setText(org.openide.util.NbBundle.getMessage(JApplet1.class, "JApplet1.TourSizeTextbox.text")); // NOI18N TourSizeTextbox.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { TourSizeTextboxMouseClicked(evt); } public void mouseExited(java.awt.event.MouseEvent evt) { TourSizeTextboxMouseExited(evt); } }); getContentPane().add(TourSizeTextbox); TourSizeTextbox.setBounds(670, 60, 77, 29); MutationTextbox.setText(org.openide.util.NbBundle.getMessage(JApplet1.class, "JApplet1.MutationTextbox.text")); // NOI18N MutationTextbox.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { MutationTextboxMouseClicked(evt); } public void mouseExited(java.awt.event.MouseEvent evt) { MutationTextboxMouseExited(evt); } }); getContentPane().add(MutationTextbox); MutationTextbox.setBounds(670, 100, 80, 30); jLabel5.setForeground(new java.awt.Color(102, 102, 255)); jLabel5.setText(org.openide.util.NbBundle.getMessage(JApplet1.class, "JApplet1.jLabel5.text")); // NOI18N getContentPane().add(jLabel5); jLabel5.setBounds(480, 160, 520, 46); SelectionButton.setBackground(new java.awt.Color(204, 204, 255)); SelectionButton.setForeground(new java.awt.Color(102, 102, 255)); SelectionButton.setText(org.openide.util.NbBundle.getMessage(JApplet1.class, "JApplet1.SelectionButton.text")); // NOI18N SelectionButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { SelectionButtonActionPerformed(evt); } }); getContentPane().add(SelectionButton); SelectionButton.setBounds(490, 210, 144, 50); CrossoverButton.setBackground(new java.awt.Color(204, 204, 255)); CrossoverButton.setForeground(new java.awt.Color(102, 102, 255)); CrossoverButton.setText(org.openide.util.NbBundle.getMessage(JApplet1.class, "JApplet1.CrossoverButton.text")); // NOI18N CrossoverButton.setActionCommand(org.openide.util.NbBundle.getMessage(JApplet1.class, "JApplet1.CrossoverButton.actionCommand")); // NOI18N CrossoverButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { CrossoverButtonActionPerformed(evt); } }); getContentPane().add(CrossoverButton); CrossoverButton.setBounds(650, 210, 100, 50); LookSolutionButton.setBackground(new java.awt.Color(204, 204, 255)); LookSolutionButton.setForeground(new java.awt.Color(102, 102, 255)); LookSolutionButton.setText(org.openide.util.NbBundle.getMessage(JApplet1.class, "JApplet1.LookSolutionButton.text")); // NOI18N LookSolutionButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { LookSolutionButtonActionPerformed(evt); } }); getContentPane().add(LookSolutionButton); LookSolutionButton.setBounds(920, 210, 144, 50); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 130, Short.MAX_VALUE) ); jPanel2Layout.setVerticalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 130, Short.MAX_VALUE) ); getContentPane().add(jPanel2); jPanel2.setBounds(500, 270, 130, 130); javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel3Layout.setHorizontalGroup( jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 130, Short.MAX_VALUE) ); jPanel3Layout.setVerticalGroup( jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 130, Short.MAX_VALUE) ); getContentPane().add(jPanel3); jPanel3.setBounds(640, 270, 130, 130); jLabel6.setForeground(new java.awt.Color(102, 102, 255)); jLabel6.setText(org.openide.util.NbBundle.getMessage(JApplet1.class, "JApplet1.jLabel6.text")); // NOI18N getContentPane().add(jLabel6); jLabel6.setBounds(920, 270, 340, 50); jLabel7.setForeground(new java.awt.Color(102, 102, 255)); jLabel7.setText(org.openide.util.NbBundle.getMessage(JApplet1.class, "JApplet1.jLabel7.text")); // NOI18N getContentPane().add(jLabel7); jLabel7.setBounds(770, 20, 407, 29); geneSrquenceTextbox.setText(org.openide.util.NbBundle.getMessage(JApplet1.class, "JApplet1.geneSrquenceTextbox.text")); // NOI18N geneSrquenceTextbox.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { geneSrquenceTextboxMouseClicked(evt); } public void mouseExited(java.awt.event.MouseEvent evt) { geneSrquenceTextboxMouseExited(evt); } }); getContentPane().add(geneSrquenceTextbox); geneSrquenceTextbox.setBounds(770, 60, 513, 29); SetParameterButton.setBackground(new java.awt.Color(204, 204, 255)); SetParameterButton.setForeground(new java.awt.Color(102, 102, 255)); SetParameterButton.setText(org.openide.util.NbBundle.getMessage(JApplet1.class, "JApplet1.SetParameterButton.text")); // NOI18N SetParameterButton.setActionCommand(org.openide.util.NbBundle.getMessage(JApplet1.class, "JApplet1.SetParameterButton.actionCommand")); // NOI18N SetParameterButton.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseReleased(java.awt.event.MouseEvent evt) { SetParameterButtonMouseReleased(evt); } }); SetParameterButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { SetParameterButtonActionPerformed(evt); } }); getContentPane().add(SetParameterButton); SetParameterButton.setBounds(770, 110, 220, 49); jLabel8.setBackground(new java.awt.Color(255, 204, 204)); jLabel8.setForeground(new java.awt.Color(102, 102, 255)); jLabel8.setText(org.openide.util.NbBundle.getMessage(JApplet1.class, "JApplet1.jLabel8.text")); // NOI18N getContentPane().add(jLabel8); jLabel8.setBounds(640, 400, 630, 60); jLabel9.setBackground(new java.awt.Color(255, 204, 204)); jLabel9.setForeground(new java.awt.Color(102, 102, 255)); jLabel9.setText(org.openide.util.NbBundle.getMessage(JApplet1.class, "JApplet1.jLabel9.text")); // NOI18N getContentPane().add(jLabel9); jLabel9.setBounds(500, 470, 790, 40); javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4); jPanel4.setLayout(jPanel4Layout); jPanel4Layout.setHorizontalGroup( jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 130, Short.MAX_VALUE) ); jPanel4Layout.setVerticalGroup( jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 130, Short.MAX_VALUE) ); getContentPane().add(jPanel4); jPanel4.setBounds(780, 270, 130, 130); MutationButton.setBackground(new java.awt.Color(204, 204, 255)); MutationButton.setForeground(new java.awt.Color(102, 102, 255)); MutationButton.setText(org.openide.util.NbBundle.getMessage(JApplet1.class, "JApplet1.MutationButton.text")); // NOI18N MutationButton.setActionCommand(org.openide.util.NbBundle.getMessage(JApplet1.class, "JApplet1.MutationButton.actionCommand")); // NOI18N MutationButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { MutationButtonActionPerformed(evt); } }); getContentPane().add(MutationButton); MutationButton.setBounds(770, 210, 100, 50); jLabel10.setForeground(new java.awt.Color(102, 102, 255)); jLabel10.setText(org.openide.util.NbBundle.getMessage(JApplet1.class, "JApplet1.jLabel10.text")); // NOI18N getContentPane().add(jLabel10); jLabel10.setBounds(500, 530, 780, 40); jLabel11.setForeground(new java.awt.Color(102, 102, 255)); jLabel11.setText(org.openide.util.NbBundle.getMessage(JApplet1.class, "JApplet1.jLabel11.text")); // NOI18N getContentPane().add(jLabel11); jLabel11.setBounds(920, 330, 330, 50); }// </editor-fold>//GEN-END:initComponents private void InitializeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_InitializeButtonActionPerformed // Initialize(create)polulation....................................................... if(jTextField1.getText()==""){ JOptionPane.showMessageDialog(this, "Please enter value first","Missing parameter alert" ,JOptionPane.INFORMATION_MESSAGE); } else{ a=Integer.parseInt(jTextField1.getText()); for (int i = 0; i < a; i++) { jPanel1.setLayout(new FlowLayout() ); button=new JButton("Indiv"+i,icon); button.setName("Button"+i); button.setSize(10, 10); button.setText("Indiv"+(i+1)); button.setForeground(Color.red); button.setBackground(Color.green); jPanel1.add(button); //to print gene sequences of created buttons........................................ button.addActionListener(new JApplet1.ButtonClickListener()); jPanel1.revalidate(); } } } private class ButtonClickListener implements ActionListener{ // int A= JApplet1.a; public void actionPerformed(ActionEvent e) { int A=JApplet1.a; Individual newIndividual = new Individual(); newIndividual.generateIndividual(); jLabel9.setText("Gene Sequence of the Indiv:"+newIndividual.toString()); } }//GEN-LAST:event_InitializeButtonActionPerformed private void SetParameterButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SetParameterButtonActionPerformed //check for any empty or invalid fields................................................. if(param1==1 & param2==1 & param3==1){ //Set parameters dynamically............................................................ b=Double.parseDouble(CrossoverTextbox.getText()); c=Integer.parseInt(TourSizeTextbox.getText()); d=Double.parseDouble(MutationTextbox.getText()); sol=geneSrquenceTextbox.getText(); allSet=1; if(allSet==1){ // System.out.println("param1="+param1+"param2="+param2+"param3="+param3+"param4="+param4); JOptionPane.showMessageDialog(this,"All input Parameters are set!!!"); } else{ //System.out.println("parameters are not set!!!"); JOptionPane.showMessageDialog(this,"Please set the Input Parameters first!!!"); } } }//GEN-LAST:event_SetParameterButtonActionPerformed private void LookSolutionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LookSolutionButtonActionPerformed // Calculate and display final solution by applying GA algorithm....................... // if(allSet==1){ String Solution=JApplet1.sol; FitnessCalc.setSolution(Solution); // Create an initial population int A= JApplet1.a; Population myPop = new Population(A, true); // Evolve our population until we reach an optimum solution int generationCount = 0; while (myPop.getFittest().getFitness() < FitnessCalc.getMaxFitness()) { generationCount++; myPop = Algorithm.evolvePopulation(myPop); } jLabel6.setText("Solution Found in Generation: " + generationCount); jLabel8.setText("Genes:"+(myPop.getFittest())); jLabel11.setText("The Genes found below in generation"+ generationCount+"are same as gene sequence set before!!! "); //} // else // { // JOptionPane.showMessageDialog(this, "Please set Input Variables first","Missing parameter alert" ,JOptionPane.INFORMATION_MESSAGE); //} }//GEN-LAST:event_LookSolutionButtonActionPerformed private void SelectionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SelectionButtonActionPerformed // Show Selection Function of GA Algorithm............................................. // if(allSet==1){ String Solution=JApplet1.sol; FitnessCalc.setSolution(Solution); // Create an initial population int A= JApplet1.a; Population myPop = new Population(A, true); while (myPop.getFittest().getFitness()<FitnessCalc.getMaxFitness()){ myPop=Algorithm.evolvePopulation(myPop); } jPanel2.setLayout(new GridLayout(4, 2)); button1=new JButton("parent1",icon1); button1.setName("PButton"); button1.setForeground(Color.red); button1.setBackground(Color.green); jPanel2.add(button1); button4=new JButton("parent2",icon3); button4.setName("PButton"); button4.setForeground(Color.red); button4.setBackground(Color.green); jPanel2.add(button4); button1.addActionListener(new FirstActionListener()); button4.addActionListener(new SecondActionListener()); jPanel2.revalidate(); // } //else //{ // JOptionPane.showMessageDialog(this, "Please set Input Variables first","Missing parameter alert" ,JOptionPane.INFORMATION_MESSAGE); //} }//GEN-LAST:event_SelectionButtonActionPerformed private void CrossoverButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CrossoverButtonActionPerformed // Show Crossover Function of GA Algorithm............................................. //if(allSet==1){ String Solution=JApplet1.sol; // Byte Solution=JApplet1.sol; FitnessCalc.setSolution(Solution); // Create an initial population int A= JApplet1.a; Population myPop = new Population(A, true); int generationCount = 0; while (myPop.getFittest().getFitness() < FitnessCalc.getMaxFitness()) { myPop = Algorithm.evolvePopulation(myPop); } jPanel3.setLayout(new GridLayout(4,2)); button2=new JButton("crossed",icon2); button2.setName("CButton"); button2.setForeground(Color.green); button2.setBackground(Color.pink); button2.addActionListener(new ThirdActionListener()); jPanel3.add(button2); jPanel3.revalidate(); //} //else //{ // JOptionPane.showMessageDialog(this, "Please set Input Variables first","Missing parameter alert" ,JOptionPane.INFORMATION_MESSAGE); // } }//GEN-LAST:event_CrossoverButtonActionPerformed private class FirstActionListener implements ActionListener{ public void actionPerformed(ActionEvent e){ String Solution=JApplet1.sol; FitnessCalc.setSolution(Solution); // Create an initial population int A= JApplet1.a; Population pop = new Population(A, true); int generationCount = 0; while (pop.getFittest().getFitness() < FitnessCalc.getMaxFitness()) { pop = Algorithm.evolvePopulation(pop); } jLabel10.setText("Gene Sequence of Parent1:"+(Algorithm.indiv1.toString())); } } private class SecondActionListener implements ActionListener{ public void actionPerformed(ActionEvent e){ String Solution=JApplet1.sol; FitnessCalc.setSolution(Solution); // Create an initial population int A= JApplet1.a; Population pop = new Population(A, true); int generationCount = 0; while (pop.getFittest().getFitness() < FitnessCalc.getMaxFitness()) { pop = Algorithm.evolvePopulation(pop); } jLabel10.setText("Gene Sequence of Parent2:"+(Algorithm.indiv2.toString())); } } private class ThirdActionListener implements ActionListener{ public void actionPerformed(ActionEvent e){ jLabel10.setText("Gene sequence of Crossed Indiv:"+(Algorithm.newIndiv.toString())); } } private class FourthActionListener implements ActionListener{ public void actionPerformed(ActionEvent e){ String Solution=JApplet1.sol; FitnessCalc.setSolution(Solution); // Create an initial population int A= JApplet1.a; Population pop = new Population(A, true); int generationCount = 0; while (pop.getFittest().getFitness() < FitnessCalc.getMaxFitness()) { pop = Algorithm.evolvePopulation(pop); } jLabel10.setText("Gene sequence of Mutated Indiv:"+(Algorithm.mIndiv.toString())); } } private void MutationButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MutationButtonActionPerformed // Show Mutation Function of GA Algorithm.............................................. // if(allSet==1){ String Solution=JApplet1.sol; FitnessCalc.setSolution(Solution); // Create an initial population int A= JApplet1.a; Population myPop = new Population(A, true); while (myPop.getFittest().getFitness()<FitnessCalc.getMaxFitness()){ myPop=Algorithm.evolvePopulation(myPop); } jPanel4.setLayout(new GridLayout(4,2)); button3=new JButton("mutated",icon4); button3.setName("MButton"); button3.setForeground(Color.pink); button3.setBackground(Color.green); jPanel4.add(button3); button3.addActionListener(new FourthActionListener()); jPanel4.revalidate(); // } //else //{ // JOptionPane.showMessageDialog(this, "Please set Input Variables first","Missing parameter alert" ,JOptionPane.INFORMATION_MESSAGE); //} }//GEN-LAST:event_MutationButtonActionPerformed private void InitializeButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_InitializeButtonMouseClicked // TODO add your handling code here: }//GEN-LAST:event_InitializeButtonMouseClicked private void CrossoverTextboxMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_CrossoverTextboxMouseClicked // TODO add your handling code here: JOptionPane.showMessageDialog(this,"This field determines the extent of the traits of the parents inherited by children.So enter a decimal value between range of 0-1!!!"); }//GEN-LAST:event_CrossoverTextboxMouseClicked private void TourSizeTextboxMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TourSizeTextboxMouseClicked // TODO add your handling code here: JOptionPane.showMessageDialog(this,"This field determines the no. of times the popoulation of selected individuals will be created .So enter an integer value between range of 0-10!!!"); }//GEN-LAST:event_TourSizeTextboxMouseClicked private void MutationTextboxMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_MutationTextboxMouseClicked // TODO add your handling code here: JOptionPane.showMessageDialog(this,"This field determines how slightly children will be different from their parents.It should be not more than 0.015!!!"); }//GEN-LAST:event_MutationTextboxMouseClicked private void geneSrquenceTextboxMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_geneSrquenceTextboxMouseClicked // TODO add your handling code here: JOptionPane.showMessageDialog(this,"Please enter a gene sequence(string of 0 and 1)that you want to see in the solution of fittest individual!!!"); }//GEN-LAST:event_geneSrquenceTextboxMouseClicked private void geneSrquenceTextboxMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_geneSrquenceTextboxMouseExited // TODO add your handling code here: // if((jTextField5.getText())==""){ // JOptionPane.showMessageDialog(this,"Please enter value!!!"); // } // else{ // for (int i = 0; i <((jTextField5.getText()).length()); i++) { // if(jTextField5.getText().charAt(i)==0 || jTextField5.getText().charAt(i)==1){ // param4=null; // param4="correct"; // } // else{ // param4="incorret"; // } // } // } }//GEN-LAST:event_geneSrquenceTextboxMouseExited private void jTextField1MouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTextField1MouseExited // TODO add your handling code here: // if(check==0){ // JOptionPane.showMessageDialog(this,"Please enter an integer within valid range!!!"); //} }//GEN-LAST:event_jTextField1MouseExited private void jTextField1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTextField1MouseClicked // TODO add your handling code here: // JOptionPane.showMessageDialog(this,"This field determines the no. of individuals you want in one population!!!"); // check=Integer.parseInt(jTextField1.getText()); // if((check==0)||(check <1 || check >100)){ // check=0; // } // else // { // check=1; // } }//GEN-LAST:event_jTextField1MouseClicked private void CrossoverTextboxMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_CrossoverTextboxMouseExited // TODO add your handling code here: if((CrossoverTextbox.getText())==""){ JOptionPane.showMessageDialog(this,"Please enter a decimal value within valid range!!!"); } else if((Double.parseDouble(CrossoverTextbox.getText()))<=0.0||(Double.parseDouble(CrossoverTextbox.getText()))>=1.0){ param1=0; } else { param1=1; } }//GEN-LAST:event_CrossoverTextboxMouseExited private void MutationTextboxMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_MutationTextboxMouseExited // TODO add your handling code here: if((MutationTextbox.getText())==""){ JOptionPane.showMessageDialog(this,"Please enter a decimal value within valid range!!!"); } else if((Double.parseDouble(MutationTextbox.getText()))<=0.0|| (Double.parseDouble(MutationTextbox.getText()))>0.015){ param3=0; } else { param3=1; } }//GEN-LAST:event_MutationTextboxMouseExited private void TourSizeTextboxMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TourSizeTextboxMouseExited // TODO add your handling code here: if((TourSizeTextbox.getText())==""){ JOptionPane.showMessageDialog(this,"Please enter an integer value within valid range!!!"); } else if((Integer.parseInt(TourSizeTextbox.getText()))<=0){ param2=0; } else { param2=1; } }//GEN-LAST:event_TourSizeTextboxMouseExited private void SetParameterButtonMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_SetParameterButtonMouseReleased // TODO add your handling code here: // JOptionPane.showMessageDialog(this,"All input Parameters are set!!!"); }//GEN-LAST:event_SetParameterButtonMouseReleased // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton CrossoverButton; private javax.swing.JTextField CrossoverTextbox; private javax.swing.JButton InitializeButton; private javax.swing.JButton LookSolutionButton; private javax.swing.JButton MutationButton; private javax.swing.JTextField MutationTextbox; private javax.swing.JButton SelectionButton; private javax.swing.JButton SetParameterButton; private javax.swing.JTextField TourSizeTextbox; private javax.swing.JTextField geneSrquenceTextbox; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JLabel jLabel9; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JPanel jPanel4; private javax.swing.JTextField jTextField1; // End of variables declaration//GEN-END:variables } //1111000000000000000000000000000000000000000000000000000000001111......(DESIRED GENE SEQUENCE TO BE ENTERED WHILE RUNNING THIS CODE!!!)